home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 216.lha / PdMake / main.c < prev    next >
C/C++ Source or Header  |  1996-02-15  |  4KB  |  165 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.  *     -a Make everything, timestamps ignored.
  10.  *     -p Print all macros & targets
  11.  *     -q Question up-to-dateness of target.  Return exit status 1 if not
  12.  *     -r Don't not use inbuilt rules
  13.  *     -s Make silently
  14.  *     -t Touch files instead of making them
  15.  *     -e enviroment variables take priority over macros.
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include "h.h"
  20.  
  21. #ifdef unix
  22. #if !msoft
  23. #include <sys/errno.h>
  24. #else
  25. #include <errno.h>
  26. #endif
  27. #endif
  28.  
  29. char *            myname;
  30. char *            makefile;    /*  The make file  */
  31.  
  32. bool            domake = TRUE;  /*  Go through the motions option  */
  33. bool            ignore = FALSE; /*  Ignore exit status option  */
  34. bool            silent = FALSE; /*  Silent option  */
  35. bool            print = FALSE;  /*  Print debuging information  */
  36. bool            rules = TRUE;   /*  Use inbuilt rules  */
  37. bool            dotouch = FALSE;/*  Touch files instead of making  */
  38. bool            quest = FALSE;  /*  Question up-to-dateness of file  */
  39. bool            makeall = FALSE;/*  make all */ 
  40. bool            efirst = FALSE;    /*  enviroment variables take priority over macros */
  41.  
  42. /* from PAMAKE */
  43.  
  44. FILE            *ifile[4] = {0};
  45. int                fln[4] = {0,0,0,0}; 
  46. char            fname[4][80] = {"stdin"};
  47. int                nestlvl = 0;
  48. char            ifmessage = '#';
  49.  
  50. void main(argc, argv) int argc; char *argv[];
  51. {
  52.     register char            *p;        /*  For argument processing  */
  53.     int            estat = 0;      /*  For question  */
  54.     register struct name *  np;
  55.  
  56.     myname = (argc-- < 1) ? "make" : *argv++;
  57.  
  58.     while ((argc > 0) && (**argv == '-'))        /* dash options */
  59.     {
  60.         argc--;                                    /* One less to process    */
  61.         p = *argv++;                            /*  Now processing this one  */
  62.  
  63.         while (*++p != '\0')                    /* while options */
  64.         {    switch(*p) {
  65.             case 'f':                            /*  Alternate file name  */
  66.                 if (*++p == '\0')                /* if not this arg */
  67.                 {    if (argc-- <= 0) usage();    /* try next arg, else usage */
  68.                     p = *argv++;
  69.                 }
  70.                 makefile = p;                    /* set makefile name */
  71.                 goto end_of_args;
  72.             case 'n': domake  = FALSE; break;    /* Pretend mode  */
  73.             case 'i': ignore  = TRUE;  break;    /* Ignore fault mode  */
  74.             case 's': silent  = TRUE;  break;    /* Silent about commands  */
  75.             case 'a': makeall = TRUE;  break;    /* Make all  */
  76.             case 'p': print   = TRUE;  break;    /* print structures */
  77.             case 'r': rules   = FALSE; break;    /* use built-in rules */
  78.             case 't': dotouch = TRUE;  break;    /* touch files */
  79.             case 'q': quest   = TRUE;  break;    /* question up-to-date */
  80.             case 'e': efirst  = TRUE;  break;    /* environment vars first */
  81.             default:     /*  Wrong option  */
  82.                 usage();
  83.             }
  84.         }
  85.     end_of_args:;
  86.     }
  87.  
  88.     if (strcmp(makefile,"-") == 0)                /*  Can use stdin as makefile  */
  89.     {    ifile[0] = stdin;
  90.     }
  91.     else if (!makefile)                            /*  If no file, then use default */
  92.     {    if ((ifile[0] = fopen(DEFN1, "r")) == NULL)
  93.             fatal("Can't open %s", DEFN1);
  94.         strncpy(fname[0],DEFN1,80);
  95.     }
  96.     else
  97.     {    if ((ifile[0] = fopen(makefile, "r")) == NULL)
  98.             fatal("Can't open %s", makefile);
  99.         strncpy(fname[0],makefile,80);
  100.     }
  101.  
  102.     makerules();
  103.  
  104.     setmacro("$", "$");
  105.  
  106.     while (argc && (p = index(*argv, '=')))
  107.     {
  108.         char        c;
  109.         c = *p;
  110.         *p = '\0';
  111.         setmacro(*argv, p+1);
  112.         *p = c;
  113.  
  114.         argv++;
  115.         argc--;
  116.     }
  117.  
  118.     input();             /*  Input all the gunga    */
  119. /*    fclose(ifile[0]); *//*  Finished with makefile  */
  120.     lineno = 0;          /*  Any calls to error now print no line number */
  121.  
  122.     if (print) prt();  /*  Print out structures  */
  123.  
  124.     np = newname(".SILENT");
  125.     if (np->n_flag & N_TARG) silent = TRUE;
  126.  
  127.     np = newname(".IGNORE");
  128.     if (np->n_flag & N_TARG) ignore = TRUE;
  129.  
  130.     precious();
  131.  
  132.     if (!firstname) fatal("No targets defined");
  133.  
  134.     circh();     /*  Check circles in target definitions    */
  135.  
  136.     if (!argc)
  137.         estat = make(firstname, 0);
  138.     else while (argc--)
  139.     {
  140. #if !MSDOS  /* Cute -- */
  141.         if (!print && !silent && strcmp(*argv, "love") == 0)
  142.             printf("Not war!\n");
  143. #endif
  144.         estat |= make(newname(*argv++), 0);
  145.     }
  146.  
  147.     if (quest) exit(estat);
  148.     else exit(0);
  149. }
  150.  
  151. usage()
  152. {    fprintf(stderr, "Usage: %s [-f makefile] [-inpqrst] [macro=val ...] [target(s) ...]\n", myname);
  153.     exit(1);
  154. }
  155.  
  156. void
  157. fatal(msg, a1, a2, a3, a4, a5, a6)
  158. char   *msg;
  159. {
  160.     fprintf(stderr, "%s: ", myname);
  161.     fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
  162.     fputc('\n', stderr);
  163.     exit(1);
  164. }
  165.