/* ;=======================================================================; ; ; ; ... ... ... ..... ... ... ... ; ; ............. ....... ... ... ... _______________________ ; ; .... ... ... ... ... ... ... ... ; ; ... ... ... ... ... ... ... MORRIS CODE WORKS ; ; ... ... ... ... ... ... ... ; ; ... ... ... ... ... ... ... SYSTEM SOFTWARE FILE ; ; ... ... ... ... ... ... ... ... _______________________ ; ; ... ... ... ....... ........... ; ; ... ... ... ..... .. .. ; ; ; ; ; ;=======================================================================; ; Copyright (c) 1985 by Morris Code Works ; ;=======================================================================; ; ; ; File: MAKEINIT.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 #include "make.h" extern boolean debug; extern boolean silent; extern boolean execute; extern boolean touch; extern struct defnrec *defnlist; extern struct macdef *maclist; /********************************************************/ /* */ /* i n i t i a l i z e s t r u c t u r e s */ /* */ /********************************************************/ init( argc, argv ) int argc; char *argv[]; { int i; /* parameter index */ boolean usedefault = TRUE; /* assume dflt file */ boolean readmakefile(); /* process a 'make' file */ char toupper(); /* convert char to upper */ void add_to(); /* add name to 'do' list */ void usage(); /* explain how to use */ /* scan thru all supplied parameters */ for( i = 1; i < argc; ++i ) { if( argv[i][0] == '-' ) { /* decode this option */ switch( toupper( argv[i][1] ) ) { case 'D': /* show everything on the next 'make' file */ debug = TRUE; break; case 'F': /* use a special 'make' file */ if( ++i < argc ) { if( readmakefile( argv[i] ) == FALSE ) exit( 1 ); usedefault = FALSE; } else usage(); break; case 'N': /* this is only a dry run */ execute = FALSE; break; case 'S': /* don't say a word while building file */ silent = TRUE; break; case 'T': /* only 'touch' the files */ touch = TRUE; break; default: /* give a hint at how to use */ usage(); break; } } else /* add this file to do list */ add_to( argv[i] ); } /* check if any files were read */ if( usedefault ) /* read the default file if not */ if( readmakefile( DEFAULT ) == FALSE ) /* that's all she wrote on errors */ exit( 1 ); } /********************************************************/ /* */ /* d i s p l a y a l l d e f i n i t i o n s */ /* */ /********************************************************/ void debugmode() { struct macdef *macp; /* ptr to macro definitions */ struct defnrec *defnp; /* ptr to 'make' definitions */ struct deprec *depp; /* ptr to 'make' dependencies */ struct howrec *howp; /* ptr to how-to commands */ char *ListTime(); /* convert long to ASCII */ char time[20]; /* buffer for time */ /* first do the macro definitions */ fprintf( stderr, "\nMacros:\n" ); for( macp = maclist; macp; macp = macp->next ) fprintf( stderr, "\t%s = %.60s\n", macp->name, macp->mactext ); /* now do the 'make' definitions */ for( defnp = defnlist; defnp; defnp = defnp->next ) { register int cc; /* temp counter */ /* tell which file we're talking about */ fprintf( stderr, "\nFile(%s): Modified(%s)\n depends on:", defnp->name, ListTime( defnp->modified, time ) ); /* display the dependencies */ for( cc = 0, depp = defnp->dependson; depp; depp = depp->next ) { fprintf( stderr, "%c%s", (cc == 0 ? '\t' : ' '), depp->name ); if( (cc += strlen( depp->name ) + 1) > 44 ) { /* reposition for next file if not last */ if( depp->next ) fprintf( stderr, "\n\t" ); /* reset the column counter */ cc = 0; } } /* display the associated commands */ fprintf( stderr, "\n commands:\n" ); for( howp = defnp->howto; howp; howp = howp->next ) fprintf( stderr, "\t%.70s\n", howp->howcom ); } } /********************************************************/ /* */ /* e x p l a i n h o w t o u s e m a k e */ /* */ /********************************************************/ void usage() { fprintf( stderr, "usage: make [-d] [-n] [-s] [-t] [-f makefile] [filename ...]\n" ); exit( 1 ); } /********************************************************/ /* */ /* a d d _ t o : add name to do_list */ /* */ /********************************************************/ void add_to( s ) char *s; { struct dorec *ptr1; /* ptr to this 'do' record */ extern dolist; /* list of names to 'make' */ char *getmem(); /* alloc block of memory */ char *lc(); /* convert to lowercase */ void chain(); /* chain structure to next */ /* get a pointer to newly allocated structure */ ptr1 = (struct dorec *) getmem( sizeof( struct dorec ) ); /* okay since only called with an argv */ ptr1->name = lc( s ); /* place this entry at end of a list */ chain( &dolist, ptr1 ); } char *lc( s ) /* convert string to lower case */ char *s; { char *str; for( str = s; *str = tolower( *str ); ++str ); return( s ); }