home *** CD-ROM | disk | FTP | other *** search
/ Total Destruction / Total_Destruction.iso / addons / Lccwin32.exe / Lccwin32 / lccpub / make / MAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-09  |  4.5 KB  |  208 lines

  1. /*
  2.  *    make [-f makefile] [-ins] [target(s) ...]
  3.  *
  4.  *    (Better than EON mk but not quite as good as UNIX make)
  5.  *
  6.  *    -f makefile name
  7.  *    -i ignore exit status
  8.  *    -n Pretend to make
  9.  *    -p Print all macros & targets
  10.  *    -q Question up-to-dateness of target.  Return exit status 1 if not
  11.  *    -r Don't not use inbuilt rules
  12.  *    -s Make silently
  13.  *    -t Touch files instead of making them
  14.  */
  15.  
  16. #include "h.h"
  17.  
  18. char *myname;
  19. char *prgversion = "1.04";
  20.  
  21. FILE *ifd;        /*  Input file desciptor  */
  22. bool domake = TRUE;    /*  Go through the motions option  */
  23. bool ignore = FALSE;    /*  Ignore exit status option  */
  24. bool silent = FALSE;    /*  Silent option  */
  25. bool print = FALSE;    /*  Print debuging information  */
  26. bool rules = TRUE;    /*  Use inbuilt rules  */
  27. bool dotouch = FALSE;   /*  Touch files instead of making  */
  28. bool quest = FALSE;    /*  Question up-to-dateness of file  */
  29.  
  30. char *makefile = NULL;    /*  The make file  */
  31. int _stdcall CtrlHandler(unsigned long event)
  32. {
  33.         printf("make: Killed\n");
  34.         exit(1);
  35. }
  36. int main(int argc,char **argv)
  37. {
  38.   register char        *p;        /*  For argument processing  */
  39.   int               estat = 0;    /*  For question  */
  40.   int                  arg;
  41.   register struct name *np;
  42.   long clockStart = clock();
  43.  
  44.   myname = argv[0];
  45.   for (arg = 1;arg < argc;arg++)
  46.     {
  47.       p = argv[arg];
  48.       if (*p++ != '-')
  49.     break;
  50.       while (*p != '\0')
  51.     {
  52.       if (*p == 'n') {    /*  Pretend mode  */
  53.         domake = FALSE;
  54.         p++;
  55.         continue;
  56.       }
  57.  
  58.       if (*p == 'i') {    /*  Ignore fault mode  */
  59.         ignore = TRUE;
  60.         p++;
  61.         continue;
  62.       }
  63.  
  64.       if (*p == 's') {    /*  Silent about commands  */
  65.         silent = TRUE;
  66.         p++;
  67.         continue;
  68.       }
  69.  
  70.       if (*p == 'p') {
  71.         print = TRUE;
  72.         p++;
  73.         continue;
  74.       }
  75.  
  76.       if (*p == 'r') {
  77.         rules = FALSE;
  78.         p++;
  79.         continue;
  80.       }  
  81.  
  82.       if (*p == 't') {
  83.         dotouch = TRUE;
  84.         p++;
  85.         continue;
  86.       }
  87.  
  88.       if (*p == 'q') {
  89.         quest = TRUE;
  90.         p++;
  91.         continue;
  92.       }
  93.  
  94.       if (*p == 'f') {    /*  Alternate file name  */
  95.         if (p[1] != '\0') {
  96.           makefile = &p[1];
  97.           arg ++;
  98.           break;        /* while (*p != 0) */
  99.         }
  100.         if (arg == argc) {
  101.           usage(1);
  102.           return -1;
  103.         }
  104.         makefile = argv[++arg];
  105.         break;        /* while (*p != 0) */
  106.       }
  107.  
  108.       usage( (*p == 'h') ? 1 : 0);        /* help or default : ???   */
  109.  
  110.     } /* while (*p != 0) */
  111.  
  112.     } /* for (arg = 1;arg < argc;arg++) */
  113.  
  114.  
  115.   if (makefile == NULL)
  116.     makefile = DEFN1;
  117.   SetConsoleCtrlHandler((void *)CtrlHandler,1);
  118.   ifd = fopen(makefile,"r");
  119.   if (ifd == NULL)
  120.     fatal("Can't open %s",makefile);
  121.  
  122.   makerules();
  123.   setmacro("$", "$");
  124.   setmacro("MAKEFILE",makefile);
  125.  
  126.   while (arg < argc)
  127.     {
  128.       char buffer[128];
  129.  
  130.       strcpy(buffer,argv[arg]);
  131.       if ((p = strchr(buffer,'=')) == NULL)
  132.     break;
  133.       *p++ = '\0';
  134.       setmacro(buffer, p);
  135.       arg++;
  136.     }
  137.  
  138.   input(ifd);    /*  Input all the gunga  */
  139.   fclose(ifd);    /*  Finished with makefile  */
  140.   lineno = 0;    /*  Any calls to error now print no line number */
  141.   
  142.   if (print)
  143.     prt();    /*  Print out structures  */
  144.   
  145.   np = newname(".SILENT");
  146.   if (np->n_flag & N_TARG)
  147.     silent = TRUE;
  148.   
  149.   np = newname(".IGNORE");
  150.   if (np->n_flag & N_TARG)
  151.     ignore = TRUE;
  152.   
  153.   precious();
  154.   
  155.   if (!firstname)
  156.     fatal("No targets defined");
  157.  
  158.   circh();    /*  Check circles in target definitions  */
  159.   
  160.   if (arg >= argc) {
  161.     estat = make(firstname, 0);
  162.   } else {
  163.     while (arg < argc) 
  164.       estat |= make(newname(argv[arg++]), 0);
  165.   }
  166.   SetConsoleCtrlHandler((void *)CtrlHandler,0);
  167.   printf("Time: %g seconds\n",(double)(clock() - clockStart)/1000.0);
  168.   if (quest)
  169.     exit(estat);
  170.   else
  171.     exit(0);
  172. }
  173.  
  174.  
  175. usage(exitvalue)
  176. int exitvalue;
  177. {
  178.   fprintf(stderr, 
  179.       "make version %s ("__DATE__")\n"
  180.       "Usage:\n"
  181.       " %s [-f makefile] [-inpqrst] [macro=val ...] [target...]\n"
  182.       " Options :\n"
  183.       "   -f makefile name\n"
  184.       "   -i ignore exit status\n"
  185.       "   -n Pretend to make\n"
  186.       "   -p Print all macros & targets\n"
  187.       "   -q Question up-to-dateness of target.  (1 = not up to date)\n"
  188.       "   -r Don't not use inbuilt rules\n"
  189.       "   -s Make silently\n"
  190.       "   -t Touch files instead of making them\n"
  191.       "   -h This help menu\n\n", 
  192.       prgversion,myname); 
  193.   exit(exitvalue);
  194. }
  195.  
  196. void fatal(const char *msg,...)
  197. {
  198.   va_list msgargs;
  199.  
  200.   fprintf(stderr, "%s: ", myname);
  201.   va_start (msgargs,msg);
  202.   vfprintf(stderr, msg, msgargs);
  203.   va_end (msgargs);
  204.   fputc('\n', stderr);
  205.   exit(1);
  206. }
  207.  
  208.