home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / sozobon / scsrc20 / make / main.c < prev    next >
C/C++ Source or Header  |  1988-10-13  |  5KB  |  243 lines

  1. /***************************************************************
  2. *                                *
  3. *  PDMAKE, Atari ST version                    *
  4. *                                *
  5. *  Adapted from mod.sources Vol 7 Issue 71, 1986-12-03.        *
  6. *                                *
  7. *  This port makes extensive use of the original net.sources    *
  8. *  port by Jwahar Bammi.                    *
  9. *                                *
  10. *      Ton van Overbeek                        *
  11. *      Email: TPC862@ESTEC.BITNET                *
  12. *             TPC862%ESTEC.BITNET@WISCVM.WISC.EDU    (ARPA)    *
  13. *             ...!mcvax!tpc862%estec.bitnet   (UUCP Europe)    *
  14. *             ...!ucbvax!tpc862%estec.bitnet  (UUCP U.S.A.)    *
  15. *             71450,3537  (CompuServe)                *
  16. *                                *
  17. \***************************************************************/
  18.  
  19. /*
  20.  *    make [-f makefile] [-ins] [target(s) ...]
  21.  *
  22.  *    (Better than EON mk but not quite as good as UNIX make)
  23.  *
  24.  *    -f makefile name
  25.  *    -i ignore exit status
  26.  *    -n Pretend to make
  27.  *    -p Print all macros & targets
  28.  *    -q Question up-to-dateness of target.  Return exit status 1 if not
  29.  *    -r Don't not use inbuilt rules
  30.  *    -s Make silently
  31.  *    -t Touch files instead of making them
  32.  *    -m Change memory requirements (EON only)
  33.  *
  34.  *    -e Don't read the environment to set marcros (tony)
  35.  *    -c dir  chdir to 'dir' before running...
  36.  */
  37.  
  38. long    _BLKSIZ = 4096;        /* don't grab too much memory */
  39.  
  40. #include <stdio.h>
  41. #include "h.h"
  42.  
  43. #include "astat.h"
  44.  
  45. long    _STKSIZ = 16 * 1024L;
  46.  
  47. char    *myname;
  48. char    *makefile = "";        /*  The make file  */
  49.  
  50. FILE *ifd;            /*  Input file desciptor  */
  51. bool    domake = TRUE;        /*  Go through the motions option  */
  52. bool    ignore = FALSE;        /*  Ignore exit status option  */
  53. bool    silent = FALSE;        /*  Silent option  */
  54. bool    print = FALSE;        /*  Print debuging information  */
  55. bool    rules = TRUE;        /*  Use inbuilt rules  */
  56. bool    dotouch = FALSE;    /*  Touch files instead of making  */
  57. bool    quest = FALSE;        /*  Question up-to-dateness of file  */
  58. bool    doenv = FALSE;        /*  macros in the env. take precendence */
  59. char    *dir = NULL;        /*  'cd' here before starting */
  60.  
  61.  
  62. main(argc, argv)
  63. int    argc;
  64. char    *argv[];
  65. {
  66.     register char    *p;    /*  For argument processing  */
  67.     int    estat = 0;    /*  For question  */
  68.     register struct name *np;
  69.  
  70.     myname = "make";            /*  TOS doesn't pass argv[0]  */
  71.     argc--;  
  72.     argv++;
  73.  
  74.     while ((argc > 0) && (**argv == '-')) {
  75.         argc--;                /*  One less to process  */
  76.         p = *argv++;            /*  Now processing this one  */
  77.  
  78.         while (*++p != '\0') {
  79.             switch (*p) {
  80.             case 'f':        /*  Alternate file name  */
  81.             case 'F':
  82.                 if (*++p == '\0') {
  83.                     if (argc-- <= 0)
  84.                         usage();
  85.                     p = *argv++;
  86.                 }
  87.                 makefile = p;
  88.                 goto end_of_args;
  89.             case 'c':
  90.             case 'C':
  91.                 if (*++p == '\0') {
  92.                     if (argc-- <= 0)
  93.                         usage();
  94.                     p = *argv++;
  95.                 }
  96.                 dir = p;
  97.                 goto end_of_args;
  98.                 break;
  99.             case 'n':        /*  Pretend mode  */
  100.             case 'N':
  101.                 domake = FALSE;
  102.                 break;
  103.             case 'i':        /*  Ignore fault mode  */
  104.             case 'I':
  105.                 ignore = TRUE;
  106.                 break;
  107.             case 's':        /*  Silent about commands  */
  108.             case 'S':
  109.                 silent = TRUE;
  110.                 break;
  111.             case 'p':
  112.             case 'P':
  113.                 print = TRUE;
  114.                 break;
  115.             case 'r':
  116.             case 'R':
  117.                 rules = FALSE;
  118.                 break;
  119.             case 't':
  120.             case 'T':
  121.                 dotouch = TRUE;
  122.                 break;
  123.             case 'q':
  124.             case 'Q':
  125.                 quest = TRUE;
  126.                 break;
  127.             case 'e':
  128.             case 'E':
  129.                 doenv = TRUE;
  130.                 break;
  131.             default:    /*  Wrong option  */
  132.                 usage();
  133.             }
  134.         }
  135. end_of_args:
  136.         ;
  137.     }
  138.  
  139.     if (dir != NULL) {
  140.         if (chdir(dir) != 0)
  141.             fatal("Can't chdir to %s", dir);
  142.     }
  143.  
  144.     if (strcmp(makefile, "-") == 0)    /*  Can use stdin as makefile  */
  145.         ifd = stdin;
  146.     else if (*makefile == '\0')    /*  If no file, then use default */
  147.         ifd = fopen(DEFN1, "r");
  148.     else if ((ifd = fopen(makefile, "r")) == (FILE * )0)
  149.         fatal("Can't open %s", makefile);
  150.  
  151.     makerules();
  152.  
  153.     setmacro("$", "$");
  154.  
  155.     while (argc && (p = strchr(*argv, '='))) {
  156.         char    c;
  157.  
  158.         c = *p;
  159.         *p = '\0';
  160.         setmacro(*argv, p + 1);
  161.         *p = c;
  162.  
  163.         argv++;
  164.         argc--;
  165.     }
  166.  
  167.     /*
  168.      * By default macro values are read from the environment before
  169.      * the makefile is scanned. That way, the makefile overrides any
  170.      * values set in the environment.
  171.      */
  172.     if (!doenv)
  173.         readenv();
  174.  
  175.     if (ifd != NULL) {
  176.         input(ifd);    /*  Input all the gunga  */
  177.         fclose(ifd);    /*  Finished with makefile  */
  178.     }
  179.  
  180.     /*
  181.      * If the environment takes precedence, read it last.
  182.      */
  183.     if (doenv)
  184.         readenv();
  185.  
  186.     lineno = 0;    /*  Any calls to error now print no line number */
  187.  
  188.     if (print)
  189.         prt();        /*  Print out structures  */
  190.  
  191.     np = newname(".SILENT");
  192.     if (np->n_flag & N_TARG)
  193.         silent = TRUE;
  194.  
  195.     np = newname(".IGNORE");
  196.     if (np->n_flag & N_TARG)
  197.         ignore = TRUE;
  198.  
  199.     precious();
  200.  
  201.     if (!firstname && ifd != NULL)
  202.         fatal("No targets defined");
  203.  
  204.     circh();        /*  Check circles in target definitions  */
  205.  
  206.     if (!argc) {
  207.         if (firstname)
  208.             estat = make(firstname, 0);
  209.         else
  210.             fatal("No target or makefile");
  211.     } else 
  212.         while (argc--) {
  213.             if (!print && !silent && strcmp(*argv, "love") == 0)
  214.                 printf("Not war!\n");
  215.             estat |= make(newname(*argv++), 0);
  216.         }
  217.  
  218.     if (quest)
  219.         exit(estat);
  220.     else
  221.         exit(0);
  222. }
  223.  
  224.  
  225. usage()
  226. {
  227.     fprintf(stderr,
  228.         "Usage: %s [-f makefile] [-inpqrst] [macro=val ...] [target(s) ...]\n",
  229.         myname);
  230.     exit(1);
  231. }
  232.  
  233.  
  234. void
  235. fatal(msg, a1, a2, a3, a4, a5, a6)
  236. char    *msg;
  237. {
  238.     fprintf(stderr, "%s: ", myname);
  239.     fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
  240.     fputc('\n', stderr);
  241.     exit(1);
  242. }
  243.