home *** CD-ROM | disk | FTP | other *** search
- /* > c.Main
- * make [-f makefile] [-ins] [target(s) ...]
- *
- * (Better than EON mk but not quite as good as UNIX make)
- *
- * -f makefile name
- * -i ignore exit status
- * -n Pretend to make
- * -p Print all macros & targets
- * -q Question up-to-dateness of target. Return exit status 1 if not
- * -r Don't not use inbuilt rules
- * -s Make silently
- * -t Touch files instead of making them
- * -o Change Output file from !Make
- * -@ RISC OS application invocation
- */
-
- #include <stdio.h>
- #include "os.h"
- #include "h.h"
-
-
- char * myname;
- char * makefile; /* The make file */
-
- FILE * outfile; /* output file descriptor */
- FILE * ifd; /* Input file desciptor */
- bool domake = TRUE; /* Go through the motions option */
- bool ignore = FALSE; /* Ignore exit status option */
- bool silent = FALSE; /* Silent option */
- bool print = FALSE; /* Print debuging information */
- bool rules = TRUE; /* Use inbuilt rules */
- bool dotouch = FALSE;/* Touch files instead of making */
- bool quest = FALSE; /* Question up-to-dateness of file */
-
- os_regset regs; /* registers for OS_CLI */
- char cmd[LZ];
- char filepath[LZ]; /* where to find all of the files */
- char outfile_name[LZ];/* the full file of stuff to do later */
- char * outfile_tail; /* the last part of the name */
-
- /* I have omitted reference to ctype.h as its wrong , mentioning */
- /* things that dont appear in the stubs part of the library */
- /* this has to be missing Acorn ??? !!!! */
- /*unsigned char _ctype[256]; blowout its not in the library stubs !!! */
-
- /* moved to top to happify ANSI c */
- void
- usage(void)
- {
- fprintf(stderr, "Usage: %s [-f makefile] [-inpqrsto@] [macro=val ...] [target(s) ...]\n", myname);
- exit(1);
- }
-
-
-
- int
- main(int argc, char **argv)
- {
- register char * p; /* For argument processing */
- int estat = 0; /* For question */
- register struct name * np;
- makefile = NULL;
- outfile_tail =NULL;
-
- *filepath = 0; /* no path */
-
- myname = (argc-- < 1) ? "make" : *argv++;
-
- printf("Make from comp.sources.unix: v2.01 %s\nModified by M.James\n\n",__DATE__);
-
-
- while ((argc > 0) && (**argv == '-'))
- {
- argc--; /* One less to process */
- p = *argv++; /* Now processing this one */
-
- while (*++p != '\0')
- {
- switch(*p)
- {
- case 'f': /* Alternate file name */
- if (*++p == '\0')
- {
- if (argc-- <= 0)
- usage();
- p = *argv++;
- }
- makefile = p;
- goto end_of_args;
- case '@': /* RISC OS invocation */
- if (*++p == '\0')
- {
- if (argc-- <= 0)
- usage();
- p = *argv++;
- }
- makefile = p;
- strcpy (filepath,makefile); /* set up the filepath as same as */
- *strrchr(filepath,'.')=0; /* makefile */
- goto end_of_args;
- case 'o': /* Alternate output file name */
- if (*++p == '\0')
- {
- if (argc-- <= 0)
- usage();
- p = *argv++;
- }
- outfile_tail=p;
- goto end_of_args;
- case 'n': /* Pretend mode */
- domake = FALSE;
- break;
- case 'i': /* Ignore fault mode */
- ignore = TRUE;
- break;
- case 's': /* Silent about commands */
- silent = TRUE;
- break;
- case 'p':
- print = TRUE;
- break;
- case 'r':
- rules = FALSE;
- break;
- case 't':
- dotouch = TRUE;
- break;
- case 'q':
- quest = TRUE;
- break;
- default: /* Wrong option */
- usage();
- }
- }
- end_of_args:;
- }
-
- if (strcmp(makefile, "-") == 0) /* Can use stdin as makefile */
- ifd = stdin;
- else
- if (!makefile) /* If no file, then use default */
- {
- if ((ifd = fopen(DEFN1, "r")) == (FILE *)0)
- fatal("Can't open %s", DEFN1);
- }
- else
- if ((ifd = fopen(makefile, "r")) == (FILE *)0)
- fatal("Can't open %s", makefile);
-
- if (domake)
- {
- if (!outfile_tail) /* If no output file, then use default */
- outfile_tail = OUTDEF;
-
- if (*filepath)
- sprintf(outfile_name,"%s.%s",filepath,outfile_tail);
- else
- strcpy(outfile_name,outfile_tail); /* dont put in the . */
-
- if ((outfile = fopen(outfile_name, "w")) == (FILE *)0)
- fatal("Can't open %s", outfile_name);
-
- if (*filepath)
- fprintf(outfile,"dir %s\n",filepath);
- }
-
- makerules();
-
- setmacro("$", "$");
-
- while (argc && (p = index(*argv, '=')))
- {
- char c;
-
- c = *p;
- *p = '\0';
- setmacro(*argv, p+1);
- *p = c;
-
- argv++;
- argc--;
- }
-
- input(ifd); /* Input all the gunga */
- fclose(ifd); /* Finished with makefile */
- lineno = 0; /* Any calls to error now print no line number */
-
- if (print)
- prt(); /* Print out structures */
-
- np = newname(".SILENT");
- if (np->n_flag & N_TARG)
- silent = TRUE;
-
- np = newname(".IGNORE");
- if (np->n_flag & N_TARG)
- ignore = TRUE;
-
- precious();
-
- if (!firstname)
- fatal("No targets have been defined");
-
- circh(); /* Check circles in target definitions */
-
- if (!argc)
- {
- estat = make(firstname, 0);
- }
- else while (argc--)
- {
- if (!print && !silent && strcmp(*argv, "love") == 0)
- printf("Not war!\n");
- estat |= make(newname(*argv++), 0);
- };
-
- if (domake) /* reset cwd in exec file */
- {
- if (*filepath)
- fprintf(outfile,"back\n");
- fclose(outfile);
- };
-
- if (quest)
- {
- exit(estat);
- }
- else
- {
- if (domake)
- {
- printf("\nNow to Exec %s\n\n",outfile_name);
- sprintf(cmd,"exec %s",outfile_name);
- system(cmd);
- }
- exit(0);
- }
- return(0);
- }
-