home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / make_1 / !make_c_Main < prev    next >
Encoding:
Text File  |  1994-10-12  |  5.2 KB  |  241 lines

  1. /* > c.Main
  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.  * -o Change Output file from !Make
  15.  * -@ RISC OS application invocation
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include "os.h"
  20. #include "h.h"
  21.  
  22.  
  23. char *   myname;
  24. char *   makefile; /*  The make file  */
  25.  
  26. FILE *   outfile; /* output file descriptor */
  27. FILE *   ifd;  /*  Input file desciptor  */
  28. bool   domake = TRUE; /*  Go through the motions option  */
  29. bool   ignore = FALSE; /*  Ignore exit status option  */
  30. bool   silent = FALSE; /*  Silent option  */
  31. bool   print = FALSE; /*  Print debuging information  */
  32. bool   rules = TRUE; /*  Use inbuilt rules  */
  33. bool   dotouch = FALSE;/*  Touch files instead of making  */
  34. bool   quest = FALSE; /*  Question up-to-dateness of file  */
  35.  
  36. os_regset regs; /* registers for OS_CLI */
  37. char cmd[LZ];
  38. char filepath[LZ]; /* where to find all of the files */
  39. char outfile_name[LZ];/* the full file of stuff to do later */
  40. char * outfile_tail; /* the last part of the name */
  41.  
  42. /* I have omitted reference to ctype.h as its wrong , mentioning */
  43. /* things that dont appear in the stubs part of the library */
  44. /* this has to be missing Acorn ??? !!!! */
  45. /*unsigned char _ctype[256]; blowout its not in the library stubs !!! */
  46.  
  47. /* moved to top to happify ANSI c */
  48. void
  49. usage(void)
  50. {
  51.  fprintf(stderr, "Usage: %s [-f makefile] [-inpqrsto@] [macro=val ...] [target(s) ...]\n", myname);
  52.  exit(1);
  53. }
  54.  
  55.  
  56.  
  57. int
  58. main(int argc, char **argv)
  59. {
  60.  register char *  p;  /*  For argument processing  */
  61.  int   estat = 0; /*  For question  */
  62.  register struct name * np;
  63.  makefile = NULL;
  64.  outfile_tail =NULL;          
  65.  
  66.  *filepath = 0;  /* no path */
  67.  
  68.  myname = (argc-- < 1) ? "make" : *argv++;
  69.  
  70.  printf("Make from comp.sources.unix: v2.01 %s\nModified by M.James\n\n",__DATE__);
  71.  
  72.  
  73.  while ((argc > 0) && (**argv == '-'))
  74.  {
  75.   argc--;  /*  One less to process  */
  76.   p = *argv++; /*  Now processing this one  */
  77.  
  78.   while (*++p != '\0')
  79.   {
  80.    switch(*p)
  81.    {
  82.    case 'f': /*  Alternate file name  */
  83.     if (*++p == '\0')
  84.     {
  85.      if (argc-- <= 0)
  86.       usage();
  87.      p = *argv++;
  88.     }
  89.     makefile = p;
  90.     goto end_of_args;
  91.    case '@': /* RISC OS invocation */
  92.     if (*++p == '\0')
  93.     {
  94.      if (argc-- <= 0)
  95.       usage();
  96.      p = *argv++;
  97.     }
  98.     makefile = p;
  99.     strcpy (filepath,makefile);   /* set up the filepath as same as */
  100.     *strrchr(filepath,'.')=0;      /* makefile */
  101.     goto end_of_args;
  102.    case 'o': /*  Alternate output file name  */
  103.     if (*++p == '\0')
  104.     {
  105.      if (argc-- <= 0)
  106.       usage();
  107.      p = *argv++;
  108.     }
  109.     outfile_tail=p;
  110.     goto end_of_args;
  111.    case 'n': /*  Pretend mode  */
  112.     domake = FALSE;
  113.     break;
  114.    case 'i': /*  Ignore fault mode  */
  115.     ignore = TRUE;
  116.     break;
  117.    case 's': /*  Silent about commands  */
  118.     silent = TRUE;
  119.     break;
  120.    case 'p':
  121.     print = TRUE;
  122.     break;
  123.    case 'r':
  124.     rules = FALSE;
  125.     break;
  126.    case 't':
  127.     dotouch = TRUE;
  128.     break;
  129.    case 'q':
  130.     quest = TRUE;
  131.     break;
  132.    default: /*  Wrong option  */
  133.     usage();
  134.    }
  135.   }
  136.  end_of_args:;
  137.  }
  138.  
  139.  if (strcmp(makefile, "-") == 0) /*  Can use stdin as makefile  */
  140.   ifd = stdin;
  141.  else
  142.   if (!makefile)  /*  If no file, then use default */
  143.   {
  144.    if ((ifd = fopen(DEFN1, "r")) == (FILE *)0)
  145.     fatal("Can't open %s", DEFN1);
  146.   }
  147.   else
  148.    if ((ifd = fopen(makefile, "r")) == (FILE *)0)
  149.     fatal("Can't open %s", makefile);
  150.  
  151.  if (domake)
  152.   {
  153.   if (!outfile_tail)  /*  If no output file, then use default */
  154.     outfile_tail = OUTDEF;
  155.                              
  156.   if (*filepath) 
  157.     sprintf(outfile_name,"%s.%s",filepath,outfile_tail);
  158.   else
  159.     strcpy(outfile_name,outfile_tail); /* dont put in the . */               
  160.  
  161.   if ((outfile = fopen(outfile_name, "w")) == (FILE *)0)
  162.     fatal("Can't open %s", outfile_name);
  163.  
  164.   if (*filepath)
  165.     fprintf(outfile,"dir %s\n",filepath); 
  166.   }
  167.  
  168.   makerules();
  169.  
  170.  setmacro("$", "$");
  171.  
  172.  while (argc && (p = index(*argv, '=')))
  173.  {
  174.   char  c;
  175.  
  176.   c = *p;
  177.   *p = '\0';
  178.   setmacro(*argv, p+1);
  179.   *p = c;
  180.  
  181.   argv++;
  182.   argc--;
  183.  }
  184.  
  185.  input(ifd); /*  Input all the gunga  */
  186.  fclose(ifd); /*  Finished with makefile  */
  187.  lineno = 0; /*  Any calls to error now print no line number */
  188.  
  189.  if (print)
  190.   prt(); /*  Print out structures  */
  191.  
  192.  np = newname(".SILENT");
  193.  if (np->n_flag & N_TARG)
  194.   silent = TRUE;
  195.  
  196.  np = newname(".IGNORE");
  197.  if (np->n_flag & N_TARG)
  198.   ignore = TRUE;
  199.  
  200.  precious();
  201.  
  202.  if (!firstname)
  203.   fatal("No targets have been defined");
  204.  
  205.  circh(); /*  Check circles in target definitions  */
  206.  
  207.  if (!argc)
  208.   {
  209.   estat = make(firstname, 0); 
  210.   }
  211.  else while (argc--)
  212.   {
  213.    if (!print && !silent && strcmp(*argv, "love") == 0)
  214.     printf("Not war!\n");
  215.    estat |= make(newname(*argv++), 0);
  216.   };
  217.  
  218.  if (domake)  /* reset cwd in exec file */
  219.    {
  220.    if (*filepath)
  221.      fprintf(outfile,"back\n"); 
  222.    fclose(outfile);
  223.    };
  224.  
  225.  if (quest)
  226.   { 
  227.   exit(estat);
  228.   }
  229.  else
  230.    {
  231.   if (domake)
  232.     {
  233.     printf("\nNow to Exec %s\n\n",outfile_name); 
  234.     sprintf(cmd,"exec %s",outfile_name);
  235.     system(cmd);
  236.     }
  237.   exit(0);
  238.   }
  239. return(0);
  240. }
  241.