/* ;=======================================================================; ; ; ; ... ... ... ..... ... ... ... ; ; ............. ....... ... ... ... _______________________ ; ; .... ... ... ... ... ... ... ... ; ; ... ... ... ... ... ... ... MORRIS CODE WORKS ; ; ... ... ... ... ... ... ... ; ; ... ... ... ... ... ... ... SYSTEM SOFTWARE FILE ; ; ... ... ... ... ... ... ... ... _______________________ ; ; ... ... ... ....... ........... ; ; ... ... ... ..... .. .. ; ; ; ; ; ;=======================================================================; ; Copyright (c) 1985 by Morris Code Works ; ;=======================================================================; ; ; ; File: MAKE.C ; ; ; ; Description: UNIX like 'make' command ; ; ; ; Create Date: 06 Aug 85 ; ; ; ;=======================================================================; ; ; ; Revision History ; ; ; ; When Who Description ; ; --------- --- ---------------------------------------------- ; ; 06 Aug 85 TGM Module created ; ; 27 Aug 85 TGM Released for use ; ; ; ;=======================================================================; */ #include "make.h" #include /********************************************************/ /* */ /* g l o b a l d a t a d e f i n i t i o n s */ /* */ /********************************************************/ struct defnrec *defnlist = NULL; /* no definitions */ struct dorec *dolist = NULL; /* nothing to do */ struct macdef *maclist = NULL; /* no macros yet */ boolean execute = TRUE; /* build submit file */ boolean debug = FALSE; /* not in debug mode */ boolean silent = FALSE; /* show commands */ boolean touch = FALSE; /* do not 'touch' files */ boolean knowhow; /* know how to make file */ boolean madesomething; /* actually made a file */ FILE *mfp; /* 'make' submit file pointer */ /********************************************************/ /* */ /* make - a U n i x - l i k e u t i l i t y */ /* */ /********************************************************/ main( argc, argv ) int argc; char *argv[]; { long make(); /* 'make' files */ void init(); /* initialization code */ void debugmode(); /* show data structures */ FILE *fopen(); /* standard file-open */ char *getmem(); /* alloc block of mem */ Š /* go initialize data structures */ init( argc, argv ); /* display structures if desired */ if( debug ) debugmode(); /* create submit file */ if( (mfp = fopen( EXECFILE, "w")) == 0 ) { fprintf( stderr, "make: can't create %s.\n", EXECFILE ); exit( 1 ); } if( silent ) fprintf( mfp, "put console output to file null [system]\n" ); /* if no name was given use the first definition */ if( dolist == NULL ) { dolist = (struct dorec *) getmem( sizeof( struct dorec ) ); dolist->name = defnlist->name; } /* now fall down the dolist and do them all */ while( dolist != NULL ) { /* haven't made anything yet */ madesomething = FALSE; /* try to make something */ (void) make( dolist->name ); if( !madesomething ) { if( knowhow ) fprintf( stderr, "make: %s is up to date.\n", dolist->name ); else fprintf( stderr, "make: don't know how to make %s.\n", dolist->name ); } dolist = dolist->next; } /* finish up the command file */ if( silent ) fprintf( mfp, "put console output to console\n" ); fprintf( mfp, "erase %s\n", EXECFILE ); fclose( mfp ); /* see if we made anything */ if( execute && madesomething ) { /* chain to command file */ sprintf( 0x0080, "SUBMIT %s\r", EXECFILE ); bdos( 47, 0 ); } } long make( s ) /* returns the modified date/time */ char *s; { struct defnrec *defnp; /* working ptrs */ struct deprec *depp; /* to various */ struct howrec *howp; /* structures */ unsigned long latest; /* current 'latest' file time */ unsigned long FileTime(); /* return file 'modified' time */ unsigned long CurrTime(); /* return 'current' time */ unsigned long max(); /* compute unsigned maximum */ char *expand(); /* expand macros */ char *mod; /* list of files needing 'making' */ /* look for the definition */ defnp = defnlist; while( defnp ) { if( !strcmp( defnp->name, s ) ) break; defnp = defnp->next; } if( defnp == NULL ) { /* don't know how to make it */ knowhow = FALSE; latest = FileTime( s ); if( latest == 0 ) { /* doesn't exist but don't know how to make it */ fprintf( stderr, "make: can't make %s.\n", s ); exit( 1 ); } else return( latest ); Š } /* if file is up to date */ if( defnp->uptodate ) /* return actual modification time */ return( defnp->modified ); /* make sure everything it depends on is up to date */ latest = 0; /* no files need 'making' yet */ *(mod = getmem( 1 )) = NULL; depp = defnp->dependson; while( depp ) { latest = max( make( depp->name ), latest ); if( FileTime( depp->name ) > defnp->modified ) { if( (mod = realloc( mod, strlen(mod)+strlen(depp->name)+2 )) == NULL ) OutOfMem(); /* add this name to the list */ if( strlen( mod ) > 0 ) strcat( mod, " "); strcat( mod, depp->name ); } depp = depp->next; } /* has dependencies therefore we know how */ knowhow = TRUE; /* if necessary, execute all of the commands to make it */ /* if ( out of date ) || ( depends on nothing ) */ if( (latest > defnp->modified) || (defnp->dependson == NULL) ) { /* make these guys */ howp = defnp->howto; /* see if only 'touching' files */ if( touch ) { fprintf( stderr, "touch(%s)\n", s ); fprintf( mfp, "touch %s\n", s ); } else while( howp ) { if( (!silent && *howp->howcom != '@') || !execute ) printf( "%s\n", expand( howp->howcom, s, mod ) ); /* add line to create file to the submit file */ if( *howp->howcom == '@' ) ++howp->howcom; fprintf( mfp, "%s\n", expand( howp->howcom, s, mod ) ); /* skip to next command */ howp = howp->next; } /* file has now been modified */ defnp->modified = CurrTime(); defnp->uptodate = TRUE; if( defnp->howto ) /* we had instructions */ madesomething = TRUE; } /* return the update file time */ free( mod ); return( defnp->modified ); }