home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tools / make / make_pd / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-10  |  4.6 KB  |  230 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.  *    -m Change memory requirements (EON only)
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include "h.h"
  19.  
  20. #ifdef MSC
  21. #include <errno.h>
  22. #endif
  23. #ifdef unix
  24. #include <sys/errno.h>
  25. #endif
  26. #ifdef eon
  27. #include <sys/err.h>
  28. #endif
  29. #ifdef os9
  30. #include <errno.h>
  31. #endif
  32.  
  33.  
  34. #ifdef eon
  35. #define MEMSPACE    (16384)
  36. #endif
  37.  
  38.  
  39. char *            myname;
  40. char *            makefile;    /*  The make file  */
  41. #ifdef eon
  42. unsigned        memspace = MEMSPACE;
  43. #endif
  44.  
  45. FILE *            ifd;        /*  Input file desciptor  */
  46. bool            domake = TRUE;    /*  Go through the motions option  */
  47. bool            ignore = FALSE;    /*  Ignore exit status option  */
  48. bool            silent = FALSE;    /*  Silent option  */
  49. bool            print = FALSE;    /*  Print debuging information  */
  50. bool            rules = TRUE;    /*  Use inbuilt rules  */
  51. bool            dotouch = FALSE;/*  Touch files instead of making  */
  52. bool            quest = FALSE;    /*  Question up-to-dateness of file  */
  53.  
  54.  
  55. void
  56. main(argc, argv)
  57. int            argc;
  58. char **            argv;
  59. {
  60.     register char *        p;        /*  For argument processing  */
  61.     int            estat = 0;    /*  For question  */
  62.     register struct name *    np;
  63.  
  64.  
  65.     myname = (argc-- < 1) ? "make" : *argv++;
  66.  
  67.     while ((argc > 0) && (**argv == '-'))
  68.     {
  69.         argc--;        /*  One less to process  */
  70.         p = *argv++;    /*  Now processing this one  */
  71.  
  72.         while (*++p != '\0')
  73.         {
  74.             switch(*p)
  75.             {
  76.             case 'f':    /*  Alternate file name  */
  77.                 if (*++p == '\0')
  78.                 {
  79.                     if (argc-- <= 0)
  80.                         usage();
  81.                     p = *argv++;
  82.                 }
  83.                 makefile = p;
  84.                 goto end_of_args;
  85. #ifdef eon
  86.             case 'm':    /*  Change space requirements  */
  87.                 if (*++p == '\0')
  88.                 {
  89.                     if (argc-- <= 0)
  90.                         usage();
  91.                     p = *argv++;
  92.                 }
  93.                 memspace = atoi(p);
  94.                 goto end_of_args;
  95. #endif
  96.             case 'n':    /*  Pretend mode  */
  97.                 domake = FALSE;
  98.                 break;
  99.             case 'i':    /*  Ignore fault mode  */
  100.                 ignore = TRUE;
  101.                 break;
  102.             case 's':    /*  Silent about commands  */
  103.                 silent = TRUE;
  104.                 break;
  105.             case 'p':
  106.                 print = TRUE;
  107.                 break;
  108.             case 'r':
  109.                 rules = FALSE;
  110.                 break;
  111.             case 't':
  112.                 dotouch = TRUE;
  113.                 break;
  114.             case 'q':
  115.                 quest = TRUE;
  116.                 break;
  117.             default:    /*  Wrong option  */
  118.                 usage();
  119.             }
  120.         }
  121.     end_of_args:;
  122.     }
  123.  
  124. #ifdef eon
  125.     if (initalloc(memspace) == 0xffff)  /*  Must get memory for alloc  */
  126.         fatal("Cannot initalloc memory");
  127. #endif
  128.  
  129.     if (strcmp(makefile, "-") == 0)    /*  Can use stdin as makefile  */
  130.         ifd = stdin;
  131.     else
  132.         if (!makefile)        /*  If no file, then use default */
  133.         {
  134.             if ((ifd = fopen(DEFN1, "r")) == (FILE *)0)
  135. #ifdef eon
  136.                 if (errno != ER_NOTF)
  137.                     fatal("Can't open %s; error %02x", DEFN1, errno);
  138. #endif
  139. #ifdef MSC
  140.                 if (errno != ENOENT)
  141.                     fatal("Can't open %s; error %02x", DEFN1, errno);
  142. #endif
  143. #ifdef unix
  144.                 if (errno != ENOENT)
  145.                     fatal("Can't open %s; error %02x", DEFN1, errno);
  146. #endif
  147. #ifndef os9
  148.             if ((ifd == (FILE *)0)
  149.                   && ((ifd = fopen(DEFN2, "r")) == (FILE *)0))
  150.                 fatal("Can't open %s", DEFN2);
  151. #else
  152.                 fatal("Can't open %s", DEFN1);
  153. #endif
  154.         }
  155.         else
  156.             if ((ifd = fopen(makefile, "r")) == (FILE *)0)
  157.                 fatal("Can't open %s", makefile);
  158.  
  159.     makerules();
  160.  
  161.     setmacro("$", "$");
  162.  
  163.     while (argc && (p = index(*argv, '=')))
  164.     {
  165.         char        c;
  166.  
  167.         c = *p;
  168.         *p = '\0';
  169.         setmacro(*argv, p+1);
  170.         *p = c;
  171.  
  172.         argv++;
  173.         argc--;
  174.     }
  175.  
  176.     input(ifd);    /*  Input all the gunga  */
  177.     fclose(ifd);    /*  Finished with makefile  */
  178.     lineno = 0;    /*  Any calls to error now print no line number */
  179.  
  180.     if (print)
  181.         prt();    /*  Print out structures  */
  182.  
  183.     np = newname(".SILENT");
  184.     if (np->n_flag & N_TARG)
  185.         silent = TRUE;
  186.  
  187.     np = newname(".IGNORE");
  188.     if (np->n_flag & N_TARG)
  189.         ignore = TRUE;
  190.  
  191.     precious();
  192.  
  193.     if (!firstname)
  194.         fatal("No targets defined");
  195.  
  196.     circh();    /*  Check circles in target definitions  */
  197.  
  198.     if (!argc)
  199.         estat = make(firstname, 0);
  200.     else while (argc--)
  201.     {
  202.         if (!print && !silent && strcmp(*argv, "love") == 0)
  203.             printf("Not war!\n");
  204.         estat |= make(newname(*argv++), 0);
  205.     }
  206.  
  207.     if (quest)
  208.         exit(estat);
  209.     else
  210.         exit(0);
  211. }
  212.  
  213.  
  214. usage()
  215. {
  216.     fprintf(stderr, "Usage: %s [-f makefile] [-inpqrst] [macro=val ...] [target(s) ...]\n", myname);
  217.     exit(1);
  218. }
  219.  
  220.  
  221. void
  222. fatal(msg, a1, a2, a3, a4, a5, a6)
  223. char    *msg;
  224. {
  225.     fprintf(stderr, "%s: ", myname);
  226.     fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
  227.     fputc('\n', stderr);
  228.     exit(1);
  229. }
  230.