dvadura@watdragon.waterloo.edu (Dennis Vadura) (05/11/91)
Submitted-by: Dennis Vadura <dvadura@watdragon.waterloo.edu> Posting-number: Volume 19, Issue 32 Archive-name: dmake/part11 Supersedes: dmake-3.6: Volume 15, Issue 52-77 ---- Cut Here and feed the following to sh ---- #!/bin/sh # this is dmake.shar.11 (part 11 of a multipart archive) # do not concatenate these parts, unpack them in order with /bin/sh # file dmake/macparse.c continued # if test ! -r _shar_seq_.tmp; then echo 'Please unpack part 1 first!' exit 1 fi (read Scheck if test "$Scheck" != 11; then echo Please unpack part "$Scheck" next! exit 1 else exit 0 fi ) < _shar_seq_.tmp || exit 1 if test -f _shar_wnt_.tmp; then sed 's/^X//' << 'SHAR_EOF' >> 'dmake/macparse.c' && X * dmake Release Version 3.7 X * */ X #include "extern.h" X PUBLIC int Parse_macro( buffer, flag )/* ============================= X Parse the string in buffer and define it as a macro if it is a valid macro. X Note especially the string .SETDIR= since it is an attribute, but looks a X lot like a macro definition. This would not be a problem if make used X white space as token separators, since this is not the case we must do X something about it. */ char *buffer; int flag; { X register char *tok1; /* temporary place to keep a token */ X register char *tok2; /* temporary place to keep a token */ X char *result; /* temporary pointer for strings */ X TKSTR input; /* place to scan the buffer from */ X HASHPTR hv; /* pointer to hash table value */ X int operator; /* what macro operator do we have */ X X DB_ENTER( "Parse_macro" ); X X SET_TOKEN( &input, buffer ); X tok1 = Get_token( &input, "=+:*", -1 ); X X if( Macro_op( tok1 ) ) { X Error( "No macro name" ); X CLEAR_TOKEN( &input ); X DB_RETURN( 1 ); X } X X tok1 = _strdup( tok1 ); X tok2 = Get_token( &input, "=+:*", -1 ); X if( !(operator = Macro_op(tok2)) || X (!strcmp(tok1, ".SETDIR") && X ((operator != M_OP_CL) || (operator != M_OP_PLCL) || X (operator != M_OP_DFCL))) ) { X CLEAR_TOKEN( &input ); X FREE( tok1 ); X DB_RETURN( 0 ); X } X X tok2 = Expand(tok1); FREE(tok1); tok1 = tok2; X tok2 = Get_token( &input, NIL( char ), FALSE ); X X switch( operator ) { X case M_OP_PLCL: X tok2 = Expand( tok2 ); X /* Fall thru */ X X case M_OP_PL: X /* Add to an existing macro, if it is not defined, though, then X * just define a new macro */ X X if( (hv = GET_MACRO(tok1)) == NIL(HASH) || hv->ht_value == NIL(char) ) X Def_macro( tok1, tok2, flag ); X else { X result = _stradd( hv->ht_value, tok2, FALSE ); X Def_macro( tok1, result, flag ); X FREE( result ); X } X if( operator == M_OP_PLCL ) FREE(tok2); X break; X X case M_OP_DF: X if( (hv = GET_MACRO(tok1)) != NIL(HASH) ) X break; X /* else FALLTHRU */ X X case M_OP_EQ: X Def_macro( tok1, tok2, flag ); X break; X X case M_OP_DFCL: X if( (hv = GET_MACRO(tok1)) != NIL(HASH) ) X break; X /* else FALLTHRU */ X X case M_OP_CL: X /* If the macro we are assigning from is a single control X * macro with nothing else, then we propagate the M_MULTI X * flag to the macro we are assigning the value to so that X * the same macro can be used to do this over and over. */ X If_multi = 0; X tok2 = Expand( tok2 ); X Def_macro( tok1, tok2, M_EXPANDED | flag | If_multi ); X FREE( tok2 ); X break; X } X X FREE( tok1 ); X X DB_RETURN( 1 ); } X X X PUBLIC int Macro_op( op )/* ================ X Check the passed in op string and map it to one of the macro operators */ char *op; { X int ret = 0; X X DB_ENTER( "macro_op" ); X X switch( *op ) { X case '=': ret = M_OP_EQ; break; X case ':': ret = M_OP_CL; op++; break; X X case '+': X ret = M_OP_PL; op++; X if( *op == ':' ) { ret = M_OP_PLCL; op++; } X break; X X case '*': X ret = M_OP_DF; op++; X if( *op == ':' ) { ret = M_OP_DFCL; op++; } X break; X } X X if( *op++ != '=' ) X ret = 0; X else if( *op != '\0' ) X ret = 0; X X DB_RETURN( ret ); } X SHAR_EOF chmod 0640 dmake/macparse.c || echo 'restore of dmake/macparse.c failed' Wc_c="`wc -c < 'dmake/macparse.c'`" test 4771 -eq "$Wc_c" || echo 'dmake/macparse.c: original size 4771, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= dmake/make.bat ============== if test -f 'dmake/make.bat' -a X"$1" != X"-c"; then echo 'x - skipping dmake/make.bat (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp sed 's/^X//' << 'SHAR_EOF' > 'dmake/make.bat' && echo off cls rem *** This is the make batchfile that is used under MSDOS to make the rem *** first version of dmake. It isn't pretty but it does work, assuming rem *** the compilers have been correctly setup. See the warning below rem *** concerning tlink, if you are making the Turbo C version. rem X if %0%1 == %0 goto error if %1 == tcc goto mktcc if %1 == tccswp goto mktccswp if %1 == bcc goto mkbcc if %1 == bccswp goto mkbccswp if %1 == msc40 goto mkmsc40 if %1 == msc40swp goto mkmsc40swp if %1 == msc50 goto mkmsc50 if %1 == msc50swp goto mkmsc50swp if %1 == msc51 goto mkmsc51 if %1 == msc51swp goto mkmsc51swp if %1 == msc60 goto mkmsc60 if %1 == msc60swp goto mkmsc60swp X rem label the possible DOS variations for dmake here. :error echo MSDOS: You must specify 'make target' where target is one of: echo ------------- echo tcc - Turbo C 2.0 compile. echo tccswp - Turbo C 2.0 compile of swapping dmake. echo bcc - Borland C++ 2.0 compile. echo bccswp - Borland C++ 2.0 compile of swapping dmake. echo msc40 - Microsoft C 4.0 compile. echo msc50 - Microsoft C 5.0 compile. echo msc51 - Microsoft C 5.1 compile. echo msc60 - Microsoft C 6.0 compile. echo msc40swp - Microsoft C 4.0, MASM 5.1 compile of swapping dmake. echo msc50swp - Microsoft C 5.0, MASM 5.1 compile of swapping dmake. echo msc51swp - Microsoft C 5.1, MASM 5.1 compile of swapping dmake. echo msc60swp - Microsoft C 6.0, MASM 5.1 compile of swapping dmake. goto end X rem This is the script that makes dmake using Microsoft C 4.0 :mkmsc40 msdos\mscdos\mk40.bat goto end X :mkmsc40swp msdos\mscdos\mk40swp.bat goto end X rem This is the script that makes dmake using Microsoft C 5.0 :mkmsc50 msdos\mscdos\mk50.bat goto end X :mkmsc50swp msdos\mscdos\mk50swp.bat goto end X rem This is the script that makes dmake using Microsoft C 5.1 :mkmsc51 msdos\mscdos\mk51.bat goto end X :mkmsc51swp msdos\mscdos\mk51swp.bat goto end X rem This is the script that makes dmake using Microsoft C 6.0 :mkmsc60 msdos\mscdos\mk60.bat goto end X :mkmsc60swp msdos\mscdos\mk60swp.bat goto end X rem This is the script that makes dmake using Turbo C 2.0 or higher. :mktcc cls echo WARNING: echo The default response files: echo msdos\tccdos\obj.rsp echo msdos\tccdos\lib.rsp echo contain absolute paths to TURBO-C runtime startup objects, and to echo the standard libraries. You should check that these files contain echo the correct path names for your installation of Turbo-C before echo proceeding further. Also check that the mkdir command at the start echo of the response file and the copy command at the end of the response echo file will work on your system. echo -- echo Continue if ok, or abort and edit the response files. pause msdos\tccdos\mk.bat goto end X :mktccswp cls echo WARNING: echo The default response files: echo msdos\tccdos\objswp.rsp echo msdos\tccdos\libswp.rsp echo contain absolute paths to TURBO-C runtime startup objects, and to echo the standard libraries. You should check that these files contain echo the correct path names for your installation of Turbo-C before echo proceeding further. Also check that the mkdir command at the start echo of the response file and the copy command at the end of the response echo file will work on your system. echo -- echo Continue if ok, or abort and edit the response files. pause msdos\tccdos\mkswp.bat goto end X rem This is the script that makes dmake using Turbo C++ 2.0. :mkbcc cls echo WARNING: echo The default response files: echo msdos\bccdos\obj.rsp echo msdos\bccdos\lib.rsp echo contain absolute paths to Borland C++ runtime startup objects, and to echo the standard libraries. You should check that these files contain echo the correct path names for your installation of Borland C++ before echo proceeding further. Also check that the mkdir command at the start echo of the response file and the copy command at the end of the response echo file will work on your system. echo -- echo Continue if ok, or abort and edit the response files. pause msdos\bccdos\mk.bat goto end X :mkbccswp cls echo WARNING: echo proceeding further. Also check that the mkdir command at the start echo of the response file and the copy command at the end of the response echo file will work on your system. echo The default response files: echo msdos\bccdos\objswp.rsp echo msdos\bccdos\libswp.rsp echo contain absolute paths to Borland C++ runtime startup objects, and to echo the standard libraries. You should check that these files contain echo the correct path names for your installation of Borland C++ before echo proceeding further. Also check that the mkdir command at the start echo of the response file and the copy command at the end of the response echo file will work on your system. echo -- echo Continue if ok, or abort and edit the response files. pause msdos\bccdos\mkswp.bat goto end X rem All done! :end SHAR_EOF chmod 0640 dmake/make.bat || echo 'restore of dmake/make.bat failed' Wc_c="`wc -c < 'dmake/make.bat'`" test 5076 -eq "$Wc_c" || echo 'dmake/make.bat: original size 5076, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= dmake/make.c ============== if test -f 'dmake/make.c' -a X"$1" != X"-c"; then echo 'x - skipping dmake/make.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp sed 's/^X//' << 'SHAR_EOF' > 'dmake/make.c' && /* RCS -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/make.c,v 1.1 91/05/06 15:23:19 dvadura Exp $ -- SYNOPSIS -- perform the update of all outdated targets. -- -- DESCRIPTION -- This is where we traverse the make graph looking for targets that -- are out of date, and we try to infer how to make them if we can. -- The usual make macros are understood, as well as some new ones: -- -- $$ - expands to $ -- $@ - full target name -- $* - target name with no suffix, same as $(@:db) -- or, the value of % in % meta rule recipes -- $? - list of out of date prerequisites -- $< - all prerequisites associated with rules line -- $& - all prerequisites associated with target -- $> - library name for target (if any) -- $^ - out of date prerequisites taken from value of $< -- {{ - expands to { -- }} - expands to } -- \# - expands to # -- -- AUTHOR -- Dennis Vadura, dvadura@watdragon.uwaterloo.ca -- CS DEPT, University of Waterloo, Waterloo, Ont., Canada -- -- COPYRIGHT -- Copyright (c) 1990 by Dennis Vadura. All rights reserved. -- -- This program is free software; you can redistribute it and/or -- modify it under the terms of the GNU General Public License -- (version 1), as published by the Free Software Foundation, and -- found in the file 'LICENSE' included with this distribution. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warrant of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -- -- LOG -- $Log: make.c,v $ X * Revision 1.1 91/05/06 15:23:19 dvadura X * dmake Release Version 3.7 X * */ X #include "extern.h" X static void _drop_mac ANSI((HASHPTR)); static void _print_cmnd ANSI((char*, int, int)); static void _set_recipe ANSI((char*, int)); static void _set_tmd ANSI(()); static void _append_file ANSI((STRINGPTR, FILE*, char*, int)); static LINKPTR _dup_prq ANSI((LINKPTR)); static char* _prefix ANSI((char *, char *)); static char* _pool_lookup ANSI((char *)); X #define RP_GPPROLOG 0 #define RP_RECIPE 1 #define RP_GPEPILOG 2 #define NUM_RECIPES 3 X static STRINGPTR _recipes[ NUM_RECIPES ]; X X PUBLIC int Make_targets()/* ================ X Actually go and make the targets on the target list */ { X LINKPTR lp; X int done = 0; X X DB_ENTER( "Make_targets" ); X X Read_state(); X _set_recipe( ".GROUPPROLOG", RP_GPPROLOG ); X _set_recipe( ".GROUPEPILOG", RP_GPEPILOG ); X X Root->ce_flag |= F_RULES|F_TARGET|F_STAT; X Root->ce_attr |= A_NOSTATE; X Root->ce_time = Do_time(); X TALLOC( Root->ce_recipe, 1, STRING ); X Root->ce_recipe->st_string = ""; X X for( lp = Root->ce_prq; lp != NIL(LINK); lp = lp->cl_next ) X lp->cl_prq->ce_attr |= A_ROOT; X X while( !done ) { X int rval; X X if( (rval = Make(Root, NIL(LINK), NIL(CELL))) == -1 ) X DB_RETURN(1); X else X done = Root->ce_flag & F_MADE; X X if( !rval && !done ) Wait_for_child( FALSE, -1 ); X } X X for( lp = Root->ce_prq; lp != NIL(LINK); lp = lp->cl_next ) { X CELLPTR root = lp->cl_prq; X if( !(root->ce_attr & A_UPDATED) ) X printf( "`%s' is up to date\n", root->CE_NAME ); X } X X DB_RETURN( 0 ); } X X X int Make( cp, parent, setdirroot )/* ================================ Make a specified target */ CELLPTR cp; LINKPTR parent; CELLPTR setdirroot; { X register LINKPTR dp; X register CELLPTR tcp; X CELLPTR nsetdirroot; X char *name, *lib; X HASHPTR m_at, m_q, m_b, m_g, m_l, m_bb, m_up; X char *all = NIL(char); X char *inf = NIL(char); X char *outall = NIL(char); X char *imm = NIL(char); X int rval = 0; X int push = 0; X int ignore; X time_t otime = (time_t) 1L; X time_t ttime = (time_t) 1L; X int mark_made = FALSE; X X DB_ENTER( "Make" ); X DB_PRINT( "mem", ("%s:-> mem %ld", cp->CE_NAME, (long) coreleft()) ); X X m_q = m_b = m_g = m_l = m_bb = m_up = m_at = NIL(HASH); X X /* Check to see if we have made the node already. If so then don't do X * it again, except if the cell's ce_setdir field is set to something other X * than the value of setdirroot. If they differ then, and we have made it X * already, then make it again and set the cell's stat bit to off so that X * we do the stat again. */ X X if( cp->ce_flag & F_VISITED ) { X /* we may return if we made it already from the same setdir location, X * or if it is not a library member whose lib field is non NULL. (if X * it is such a member then we have a line of the form: X * lib1 lib2 .LIBRARY : member_list... X * and we have to make sure all members are up to date in both libs. */ X X if( cp->ce_setdir == setdirroot && X !((cp->ce_attr & A_LIBRARYM) && (cp->ce_lib != NIL(char))) ) X DB_RETURN( 0 ); X X X /* We check to make sure that we are comming from a truly different X * directory, ie. ".SETDIR=joe : a.c b.c d.c" are all assumed to come X * from the same directory, even though setdirroot is different when X * making dependents of each of these targets. */ X X if( cp->ce_setdir != NIL(CELL) && setdirroot != NIL(CELL) && X !strcmp(cp->ce_dir, setdirroot->ce_dir) ) X DB_RETURN( 0 ); X X if( Max_proc > 1 ) { X if( parent == NIL(LINK) ) X Fatal( "Internal Error: NIL parent in Make()" ); X X TALLOC(parent->cl_prq, 1, CELL); X *parent->cl_prq = *cp; X cp = parent->cl_prq; X cp->ce_prq = _dup_prq(cp->ce_prq); X } X cp->ce_flag &= ~(F_STAT|F_VISITED|F_MADE); X } X X X /* If we are supposed to change directories for this target then do so. X * If we do change dir, then modify the setdirroot variable to reflect X * that fact for all of the prerequisites that we will be making. */ X X nsetdirroot = setdirroot; X ignore = (((cp->ce_attr|Glob_attr)&A_IGNORE) != 0); X X if( cp->ce_attr & A_SETDIR ) { X /* Change directory only if the previous .SETDIR is a different X /* directory from the current one. ie. all cells with the same .SETDIR X /* attribute are assumed to come from the same directory. */ X X if( (setdirroot == NIL(CELL) || setdirroot->ce_dir != cp->ce_dir) && X (push = Push_dir(cp->ce_dir,cp->CE_NAME,ignore)) ) X setdirroot = cp; X } X X DB_PRINT( "mem", ("%s:-A mem %ld", cp->CE_NAME, (long) coreleft()) ); X if( (cp->ce_recipe == NIL(STRING) && !(cp->ce_flag & F_INFER)) ) { X char *dir = cp->ce_dir; X X if( Verbose & V_MAKE ) X printf( "%s: Infering prerequisite(s) and recipe for [%s]\n", Pname, X cp->CE_NAME ); X X Infer_recipe( cp, setdirroot ); X X /* See if the directory has changed, if it has then make sure we X * push it. */ X if( dir != cp->ce_dir ) { X if( push ) Pop_dir(FALSE); X push = Push_dir( cp->ce_dir, cp->CE_NAME, ignore ); X setdirroot = cp; X } X } X X tcp = cp; X do { X if( push ) { X if( tcp->ce_dir ) FREE( tcp->ce_dir ); X tcp->ce_dir = _pool_lookup(Pwd); X tcp->ce_attr |= A_SETDIR; X } X tcp->ce_setdir = nsetdirroot; X tcp = tcp->ce_all; X } X while( tcp != NIL(CELL) && tcp != cp ); X X DB_PRINT( "mem", ("%s:-A mem %ld", cp->CE_NAME, (long) coreleft()) ); X /* If we have not yet statted the target then do so. */ X if( !(cp->ce_flag & F_STAT) && !(cp->ce_attr&A_PHONY) ) { X time_t itime = cp->ce_time; X Stat_target( cp, TRUE ); X X if( cp->ce_time == (time_t)0L ) { X if( cp->ce_flag & F_INFER ) X cp->ce_time = itime; X } X else X cp->ce_attr |= A_PRECIOUS; /* File exists so don't remove it later. */ X X if( Verbose & V_MAKE ) X printf("%s: Time stamp of [%s] is %ld\n",Pname,cp->CE_NAME, X cp->ce_time); X } X X DB_PRINT( "make", ("(%s, %ld, 0x%08x, 0x%04x)", cp->CE_NAME, X cp->ce_time, cp->ce_attr, cp->ce_flag) ); X X if( !(cp->ce_flag & F_TARGET) && (cp->ce_time == (time_t) 0L) ) X if( Makemkf ) { X rval = -1; X goto stop_making_it; X } X else if(cp->ce_prq != NIL(LINK)||(Augmake && (cp->ce_flag&F_EXPLICIT))) X /* Assume an empty recipe for a target that we have run inference on X * but do not have a set of rules for but for which we have inferred X * a list of prerequisites. */ X cp->ce_flag |= F_RULES; X else X Fatal( "`%s' not found, and can't be made", cp->CE_NAME ); X X DB_PRINT( "mem", ("%s:-A mem %ld", cp->CE_NAME, (long) coreleft()) ); X X /* set value of $* if we have not infered a recipe, in this case $* is X * the same as $(@:db), this allows us to be compatible with BSD make */ X if( cp->ce_per == NIL(char) ) cp->ce_per = "$(@:db)"; X X for( dp = cp->ce_prq; dp != NIL(LINK); dp = dp->cl_next ) { X int seq; X X /* Make the prerequisite, note that if the current target has the X * .LIBRARY attribute set we pass on to the prerequisite the .LIBRARYM X * attribute and pass on the name of the current target as the library X * name, and we take it away when we are done. */ X X tcp = dp->cl_prq; X seq = (((cp->ce_attr | Glob_attr) & A_SEQ) != 0); X X if( tcp->ce_flag & F_VISITED ) X if( tcp->ce_flag & F_MADE ) { X if( tcp->ce_time > ttime ) ttime = tcp->ce_time; X continue; X } X else X goto stop_making_it; X X if( strchr(tcp->CE_NAME, '$') ) { X /* Make this prerequisite link point at the real prerequisite we X * are after, ie figure out what the dynamic one is and point at it. */ X X m_at = Def_macro( "@", cp->ce_fname, M_MULTI ); X name = Expand( tcp->CE_NAME ); X X tcp = dp->cl_prq = Def_cell( name ); X FREE( name ); X } X X if( cp->ce_attr & A_LIBRARY ) { X tcp->ce_attr |= A_LIBRARYM; X tcp->ce_lib = cp->ce_fname; X } X X if( (tcp->ce_flag & (F_INFER|F_STAT))==F_INFER && cp->ce_time >= ttime ) X tcp->ce_time = cp->ce_time; X X /* Propagate parents F_REMOVE and F_INFER attribute to children. X * Make certain you do this AFTER propagating the time, since the X * time propagation test above uses the F_INFER flag to decide if X * it should do so. */ X tcp->ce_flag |= cp->ce_flag & (F_REMOVE|F_INFER); X X rval |= Make(tcp, dp, setdirroot); X X if( cp->ce_attr & A_LIBRARY ) X tcp->ce_attr ^= A_LIBRARYM; X X if( rval == -1 || (seq && (rval == 1)) ) X goto stop_making_it; X X if( tcp->ce_time > ttime ) ttime = tcp->ce_time; X } X X X /* Do the loop again. We are most definitely going to make the current X * cell now. NOTE: doing this loop here also results in a reduction X * in peak memory usage by the algorithm. */ X X for( dp = cp->ce_prq; dp != NIL(LINK); dp = dp->cl_next ) { X int tgflg; X tcp = dp->cl_prq; X name = tcp->ce_fname; X X /* make certain that all prerequisites are made prior to advancing. */ X if( !(tcp->ce_flag & F_MADE) ) goto stop_making_it; X X /* If the target is a library, then check to make certain that a member X * is newer than an object file sitting on disk. If the disk version X * is newer then set the time stamps so that the archived member is X * replaced. */ X if( cp->ce_attr & A_LIBRARY ) X if( tcp->ce_time < cp->ce_time ) { X time_t mtime = Do_stat( name, tcp->ce_lib, NIL(char *) ); X if( mtime < tcp->ce_time ) tcp->ce_time = cp->ce_time+1L; X } X X if( tcp->ce_time > otime ) otime = tcp->ce_time; X X all = _strapp( all, name ); X if( tgflg = (dp->cl_flag & F_TARGET) ) inf = _strapp( inf, name ); X X if((cp->ce_time<tcp->ce_time) || ((tcp->ce_flag & F_TARGET) && Force)) { X outall = _strapp( outall, name ); X if( tgflg ) imm = _strapp( imm, name ); X } X } X X DB_PRINT( "mem", ("%s:-C mem %ld", cp->CE_NAME, (long) coreleft()) ); X DB_PRINT( "make", ("I make '%s' if %ld > %ld", cp->CE_NAME, otime, X cp->ce_time) ); X X if( Verbose & V_MAKE ) X printf( "%s: >>>> Making [%s]\n", Pname, cp->CE_NAME ); X X m_at = Def_macro( "@", cp->ce_fname, M_MULTI ); X m_g = Def_macro( ">", cp->ce_lib, M_MULTI ); X m_q = Def_macro( "?", outall, M_MULTI ); X m_b = Def_macro( "<", inf, M_MULTI ); X m_l = Def_macro( "&", all, M_MULTI ); X m_bb = Def_macro( "*", cp->ce_per, M_MULTI ); X m_up = Def_macro( "^", imm, M_MULTI ); X X _recipes[ RP_RECIPE ] = cp->ce_recipe; X X /* We attempt to make the target if X * 1. it has a newer prerequisite X * 2. It is a target and Force is set X * 3. It's set of recipe lines has changed. X */ X if( Check_state(cp, _recipes, NUM_RECIPES ) X || (cp->ce_time < otime) X || ((cp->ce_flag & F_TARGET) && Force) X ) { X X /* Only checking so stop as soon as we determine we will make something */ X if( Check ) { X rval = -1; X goto stop_making_it; X } X X if( Verbose & V_MAKE ) X printf( "%s: Updating [%s], (%ld > %ld)\n", Pname, X cp->CE_NAME, otime, cp->ce_time ); X X if( Touch ) { X name = cp->ce_fname; X lib = cp->ce_lib; X X if( !(Glob_attr & A_SILENT) || !Trace ) X if( lib == NIL(char) ) X printf("touch(%s)", name ); X else if( cp->ce_attr & A_SYMBOL ) X printf("touch(%s((%s)))", lib, name ); X else X printf("touch(%s(%s))", lib, name ); X X if( !Trace ) X if( Do_touch( name, lib, X (cp->ce_attr & A_SYMBOL) ? &name : NIL(char *) ) != 0 ) X printf( " not touched - non-existant" ); X X printf( "\n" ); X Update_time_stamp( cp ); X } X else if( cp->ce_recipe != NIL(STRING) ) { X if( !(cp->ce_flag & F_SINGLE) ) X rval = Exec_commands( cp ); X else { X TKSTR tk; X X _drop_mac( m_q ); X SET_TOKEN( &tk, outall ); X X Doing_bang = TRUE; X name = Get_token( &tk, "", FALSE ); X do { X m_q->ht_value = name; X X Wait_for_completion = TRUE; /* Reset in Exec_commands */ X rval = Exec_commands( cp ); X Unlink_temp_files(cp); X } X while( *(name = Get_token( &tk, "", FALSE )) != '\0' ); X Doing_bang = FALSE; X Update_time_stamp( cp ); X X m_q->ht_value = NIL(char); X } X } X else if( !(cp->ce_flag & F_RULES) && !(cp->ce_flag & F_STAT) && X (!(cp->ce_attr & A_ROOT) || !(cp->ce_flag & F_EXPLICIT)) ) X Fatal( "Don't know how to make `%s'",cp->CE_NAME ); X else { X /* Empty recipe, set the flag as MADE and update the time stamp */ X Update_time_stamp( cp ); X } X } X else X mark_made = TRUE; X X /* Make sure everyone gets remade if Force is set */ X tcp = cp; X do { X if( !(tcp->ce_flag & F_TARGET) && Force ) tcp->ce_time = Do_time(); X if( mark_made ) tcp->ce_flag |= F_MADE; X X tcp->ce_flag |= F_VISITED; X X /* Note: If the prerequisite was made using a .SETDIR= attribute X * directory then we will include the directory in the fname X * of the target. */ X if( push ) { X char *nname = Build_path(_prefix(Makedir,tcp->ce_dir), tcp->ce_fname); X X if( (tcp->ce_attr & A_FFNAME) && (tcp->ce_fname != NIL(char)) ) X FREE( tcp->ce_fname ); X X tcp->ce_fname = _strdup(nname); X tcp->ce_attr |= A_FFNAME; X } X X tcp = tcp->ce_all; X } X while( tcp != NIL(CELL) && tcp != cp ); X stop_making_it: X _drop_mac( m_g ); X _drop_mac( m_q ); X _drop_mac( m_b ); X _drop_mac( m_l ); X _drop_mac( m_bb ); X _drop_mac( m_up ); X _drop_mac( m_at ); X X while( push-- ) Pop_dir(FALSE); X X if( inf != NIL(char) ) FREE( inf ); X if( all != NIL(char) ) FREE( all ); X if( imm != NIL(char) ) FREE( imm ); X if( outall != NIL(char) ) FREE( outall ); X X DB_PRINT( "mem", ("%s:-< mem %ld", cp->CE_NAME, (long) coreleft()) ); X DB_RETURN( rval ); } X X static char * _prefix( pfx, pat ) char *pfx; char *pat; { X char *opat = pat; X while( *pfx && *pat && *pfx++ == *pat++ ); X X return( !*pfx ? _strspn(pat,DirBrkStr) : opat ); } X X static LINKPTR _dup_prq( lp ) LINKPTR lp; { X LINKPTR tlp; X X if( lp == NIL(LINK) ) return(lp); X X TALLOC(tlp, 1, LINK); X *tlp = *lp; X tlp->cl_next = _dup_prq( lp->cl_next ); X X return(tlp); } X X static void _drop_mac( hp )/* ================ set a macro value to zero. */ HASHPTR hp; { X if( hp && hp->ht_value != NIL(char) ) { X FREE( hp->ht_value ); X hp->ht_value = NIL(char); X } } X X X PUBLIC int Exec_commands( cp )/* ===================== X Execute the commands one at a time that are pointed to by the rules pointer X of the target cp. If a group is indicated, then the ce_attr determines X .IGNORE and .SILENT treatment for the group. X X The function returns 0, if the command is executed and has successfully X returned, and returns 1 if the command is executing but has not yet X returned (for parallel makes). X X The F_MADE bit in the cell is guaranteed set when the command has X successfully completed. */ CELLPTR cp; { X static HASHPTR useshell = NIL(HASH); X static HASHPTR command = NIL(HASH); X static int read_cmnd = 0; X register STRINGPTR rp; X STRINGPTR orp; X char *cmnd; X char *groupfile; X FILE *tmpfile; X int do_it; X t_attr attr; X int group; X int trace; X int rval = 0; X X DB_ENTER( "Exec_commands" ); X X Current_target = cp; X attr = Glob_attr | cp->ce_attr; X trace = Trace || !(attr & A_SILENT); X group = cp->ce_flag & F_GROUP; X X /* Do it again here for those that call us from places other than Make() X * above. */ X orp = _recipes[ RP_RECIPE ]; X _recipes[ RP_RECIPE ] = cp->ce_recipe; X X if( group ) { X trace = Trace || !(attr & A_SILENT); X X if( !Trace ) tmpfile = Start_temp( Grp_suff, cp, &groupfile ); X if( trace ) fputs( "[\n", stdout ); X X /* Emit group prolog */ X if( attr & A_PROLOG ) X _append_file( _recipes[RP_GPPROLOG], tmpfile, cp->CE_NAME, trace ); X } X X if( !useshell ) useshell=Def_macro("USESHELL",NIL(char),M_MULTI|M_EXPANDED); X if( !read_cmnd ) {command = GET_MACRO("COMMAND"); read_cmnd = 1;} X X /* Process commands in recipe. If in group, merely append to file. X * Otherwise, run them. */ X for( rp = _recipes[RP_RECIPE]; rp != NIL(STRING); rp=rp->st_next,FREE(cmnd)){ X t_attr a_attr = A_DEFAULT; X char *p; X int new_attr = FALSE; X int shell; X X /* Only check for +,-,%,@ if the recipe line begins with a '$' macro X * expansion. Otherwise there is no way it is going to find these X * now. */ X if( *rp->st_string == '$' && !group ) { X t_attr s_attr = Glob_attr; X Glob_attr |= A_SILENT; X Suppress_temp_file = TRUE; X cmnd = Expand(rp->st_string); X Suppress_temp_file = FALSE; X a_attr |= Rcp_attribute(cmnd); X FREE(cmnd); X ++new_attr; X Glob_attr = s_attr; X } X X attr |= a_attr|rp->st_attr; X shell = ((attr & A_SHELL) != 0); X useshell->ht_value = (group||shell)?"yes":"no"; X X cmnd = Expand( rp->st_string ); X X if( new_attr ) { X char *ecmnd = cmnd; X cmnd = _strdup(_strspn(cmnd, " \t\n+-@%")); X FREE(ecmnd); X } X X /* COMMAND macro is set to "$(CMNDNAME) $(CMNDARGS)" by default, it is X * possible for the user to reset it to, for example X * COMMAND = $(CMNDNAME) @$(mktmp $(CMNDARGS)) X * in order to get a different interface for his command execution. */ X if( command != NIL(HASH) && !group && *(p = _strpbrk(cmnd, " \t\n")) ) { X char *cname = cmnd; X X *p = '\0'; X (void) Def_macro("CMNDNAME",cname,M_MULTI|M_EXPANDED); X (void) Def_macro("CMNDARGS",p+1,M_MULTI|M_EXPANDED); X X cmnd = Expand("$(COMMAND)"); X FREE(cname); /* cname == cmnd at this point. */ X } X X Swap_on_exec = ((attr & A_SWAP) != 0); /* Swapping for DOS only */ X do_it = !Trace; X X if( !group && Trace && _strstr(rp->st_string,"$(MAKE)") ) { X Wait_for_completion |= Trace; X do_it = TRUE; X } X X if( group ) X Append_line( cmnd, TRUE, tmpfile, cp->CE_NAME, trace, 0 ); X else { X if( *_strspn(cmnd, " \t") != '\0' ) X _print_cmnd(cmnd, !(do_it && (attr & A_SILENT)), 0); X else X do_it = FALSE; X X rval=Do_cmnd(cmnd,FALSE,do_it,cp,(attr&A_IGNORE)!=0, shell, X rp->st_next == NIL(STRING) ); X } X } X X /* If it is a group then output the EPILOG if required and possibly X * execute the command */ X if( group ) { X if( attr & A_EPILOG ) /* emit epilog */ X _append_file( _recipes[RP_GPEPILOG], tmpfile, cp->CE_NAME, trace ); X X if( trace ) fputs("]\n", stdout); X X if( do_it = !Trace ) Close_temp( cp, tmpfile ); X rval = Do_cmnd(groupfile, TRUE, do_it, cp, (attr & A_IGNORE)!=0, X TRUE, TRUE); X } X X Wait_for_completion = FALSE; X _recipes[ RP_RECIPE ] = orp; X DB_RETURN( rval ); } X X static void _print_cmnd( cmnd, echo, map )/* ================================ X This routine is called to print out the command to stdout. If echo is X false the printing to stdout is supressed, but the new lines in the command X are still deleted. */ char *cmnd; int echo; int map; { X register char *p; X register char *n; X X DB_ENTER( "_print_cmnd" ); X X if( echo ) { X printf( "%s\n", cmnd ); X fflush(stdout); X } X X for( p=cmnd; (n = strchr(p, CONTINUATION_CHAR)) != NIL(char); ) X if(n[1] == '\n') { X DB_PRINT( "make", ("fixing [%s]", p) ); X strcpy( n, n+2 ); X p = n; X } X else { X if( map ) Map_esc( n ); X p = n+1; X } X X DB_VOID_RETURN; } X X X /* These routines are used to maintain a stack of directories when making X * the targets. If a target cd's to the directory then it is assumed that X * it will undo it when it is finished making itself. */ X static STRINGPTR dir_stack = NIL(STRING); X int Push_dir( dir, name, ignore )/* =============================== X Change the current working directory to dir and save the current X working directory on the stack so that we can come back. X X If ignore is TRUE then do not complain about _ch_dir if not possible.*/ char *dir; char *name; int ignore; { X STRINGPTR new_dir; X X DB_ENTER( "Push_dir" ); X X if( dir == NIL(char) ) dir = Pwd; X if( *dir == '\'' && dir[strlen(dir)-1] == '\'' ) { X dir = _strdup(dir+1); X dir[strlen(dir)-1]='\0'; X } X else X dir = Expand(dir); X X if( Set_dir(dir) ) { X if( !ignore ) X Fatal( "Unable to change to directory `%s', target is [%s]", X dir, name ); X FREE(dir); X DB_RETURN( 0 ); X } X X DB_PRINT( "dir", ("Push: [%s]", dir) ); X if( Verbose & V_PRINT_DIR ) X printf( "%s: Changed to directory [%s]\n", Pname, dir ); X X FREE( dir ); X TALLOC( new_dir, 1, STRING ); X new_dir->st_next = dir_stack; X dir_stack = new_dir; X new_dir->st_string = _strdup( Pwd ); X X Def_macro( "PWD", Get_current_dir(), M_MULTI | M_EXPANDED ); X _set_tmd(); X X DB_RETURN( 1 ); } X X X PUBLIC void Pop_dir(ignore)/* ================= X Change the current working directory to the previous saved dir. */ int ignore; { X STRINGPTR old_dir; X char *dir; X X DB_ENTER( "Pop_dir" ); X X if( dir_stack == NIL(STRING) ) X if( ignore ) { X DB_VOID_RETURN; X } X else X Error( "Directory stack empty for return from .SETDIR" ); X X if( Set_dir(dir = dir_stack->st_string) ) X Fatal( "Could not change to directory `%s'", dir ); X X Def_macro( "PWD", dir, M_MULTI | M_EXPANDED ); X DB_PRINT( "dir", ("Pop: [%s]", dir) ); X if( Verbose & V_PRINT_DIR ) X printf( "%s: Changed back to directory [%s]\n", Pname, dir); X X old_dir = dir_stack; X dir_stack = dir_stack->st_next; X X FREE( old_dir->st_string ); X FREE( old_dir ); X _set_tmd(); X X DB_VOID_RETURN; } X X X static void _set_tmd()/* ============ X Set the TWD Macro */ { X TKSTR md, pd; X char *m, *p; X char *tmd; X int is_sep; X int first = 1; X X SET_TOKEN( &md, Makedir ); X SET_TOKEN( &pd, Pwd ); X X m = Get_token( &md, DirBrkStr, FALSE ); X (void) Get_token( &pd, DirBrkStr, FALSE ); X is_sep = (strchr(DirBrkStr, *m) != NIL(char)); X tmd = _strdup( "" ); X X do { X m = Get_token( &md, DirBrkStr, FALSE ); X p = Get_token( &pd, DirBrkStr, FALSE ); X X if( !is_sep && strcmp(m, p) ) { /* they differ */ X char *tmp; X if( first ) { /* They differ in the first component */ X tmd = Makedir; /* In this case use the full path */ X break; X } X X if( *p ) tmp = Build_path( "..", tmd ); X if( *m ) tmp = Build_path( tmd, m ); X FREE( tmd ); X tmd = _strdup( tmp ); X } X X is_sep = 1-is_sep; X first = 0; X } while (*m || *p); X X CLEAR_TOKEN( &md ); X CLEAR_TOKEN( &pd ); X X Def_macro( "TMD", tmd, M_MULTI | M_EXPANDED ); X if( tmd != Makedir ) FREE( tmd ); } X X static void _set_recipe( target, ind )/* ============================ X Set up the _recipes static variable so that the slot passed in points X at the rules corresponding to the target supplied. */ char *target; int ind; { X CELLPTR cp; X HASHPTR hp; X X if( (hp = Get_name(target, Defs, FALSE)) != NIL(HASH) ) { X cp = hp->CP_OWNR; X _recipes[ ind ] = cp->ce_recipe; X } X else X _recipes[ ind ] = NIL(STRING); } X X X PUBLIC void Append_line( cmnd, newline, tmpfile, name, printit, map ) char *cmnd; int newline; FILE *tmpfile; char *name; int printit; int map; { X _print_cmnd( cmnd, printit, map ); X X if( Trace ) return; X X fputs(cmnd, tmpfile); X if( newline ) fputc('\n', tmpfile); X fflush(tmpfile); X X if( ferror(tmpfile) ) X Fatal("Write error on temporary file, while processing `%s'", name); } X X X static void _append_file( rp, tmpfile, name, printit ) register STRINGPTR rp; FILE *tmpfile; char *name; int printit; { X char *cmnd; X X while( rp != NIL(STRING) ) { X Append_line(cmnd = Expand(rp->st_string), TRUE, tmpfile, name, printit,0); X FREE(cmnd); X rp = rp->st_next; X } } X X #define NUM_BUCKETS 20 X typedef struct strpool { X char *string; /* a pointer to the string value */ X uint32 keyval; /* the strings hash value */ X struct strpool *next; /* hash table link pointer */ } POOL, *POOLPTR; X static POOLPTR strings[ NUM_BUCKETS ]; X static char * _pool_lookup( str )/* ===================== X Scan down the list of chained strings and see if one of them matches X the string we are looking for. */ char *str; { X register POOLPTR key; X uint32 keyval; X uint16 hv; X uint16 keyindex; X char *string; X X DB_ENTER( "_pool_lookup" ); X X if( str == NIL(char) ) DB_RETURN(""); X X hv = Hash(str, &keyval); X key = strings[ keyindex = (hv % NUM_BUCKETS) ]; X X while( key != NIL(POOL) ) X if( (key->keyval != keyval) || strcmp(str, key->string) ) X key = key->next; X else X break; X X if( key == NIL(POOL) ) { X DB_PRINT( "pool", ("Adding string [%s]", str) ); X TALLOC( key, 1, POOL ); /* not found so add string */ X X key->string = string = _strdup(str); X key->keyval = keyval; X X key->next = strings[ keyindex ]; X strings[ keyindex ] = key; X } X else { X DB_PRINT( "pool", ("Found string [%s], key->string") ); X string = key->string; X } X X DB_RETURN( string ); } SHAR_EOF chmod 0640 dmake/make.c || echo 'restore of dmake/make.c failed' Wc_c="`wc -c < 'dmake/make.c'`" test 27141 -eq "$Wc_c" || echo 'dmake/make.c: original size 27141, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= dmake/make.cmd ============== if test -f 'dmake/make.cmd' -a X"$1" != X"-c"; then echo 'x - skipping dmake/make.cmd (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp sed 's/^X//' << 'SHAR_EOF' > 'dmake/make.cmd' && echo off rem *** This is the make command file that is used under OS/2 to make the rem *** first version of dmake. It isn't pretty but it does work, assuming rem *** the compilers have been correctly setup. rem echo Running make.cmd script to make a %1 copy of dmake. X if %0%1 == %0 goto error if %1 == msc40 goto mkmsc40 if %1 == msc50 goto mkmsc50 if %1 == msc51 goto mkmsc51 if %1 == msc60 goto mkmsc60 X rem label the possible DOS variations for dmake here. :error echo OS/2 INDEX: You must specify one of: echo msc40 - Microsoft C 4.0 compile. echo msc50 - Microsoft C 5.0 compile. echo msc51 - Microsoft C 5.1 compile. echo msc60 - Microsoft C 6.0 compile. goto end X rem This is the script that makes dmake using Microsoft C 4.0 :mkmsc40 os2\mscdos\mk40.cmd goto end X rem This is the script that makes dmake using Microsoft C 5.0 :mkmsc50 os2\mscdos\mk50.cmd goto end X rem This is the script that makes dmake using Microsoft C 5.1 :mkmsc51 os2\mscdos\mk51.cmd goto end X rem This is the script that makes dmake using Microsoft C 6.0 :mkmsc60 os2\mscdos\mk60.cmd goto end X rem All done! :end SHAR_EOF chmod 0640 dmake/make.cmd || echo 'restore of dmake/make.cmd failed' Wc_c="`wc -c < 'dmake/make.cmd'`" test 1124 -eq "$Wc_c" || echo 'dmake/make.cmd: original size 1124, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= dmake/makefile.mk ============== if test -f 'dmake/makefile.mk' -a X"$1" != X"-c"; then echo 'x - skipping dmake/makefile.mk (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp sed 's/^X//' << 'SHAR_EOF' > 'dmake/makefile.mk' && # //// Makefile for DMAKE. \\\\ # The target system is characterized by the following macros imported from # the environment. # # OS - gives the class of operating system SHAR_EOF true || echo 'restore of dmake/makefile.mk failed' fi echo 'End of part 11, continue with part 12' echo 12 > _shar_seq_.tmp exit 0 exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.