home *** CD-ROM | disk | FTP | other *** search
- /*
- * Do the actual making for make
- */
-
- #include "c:stdio.h" /* "c:" is my ramdisk */
- #include "c:fcntl.h"
- #include "h.h"
-
- FILE *execfile; /* Submit file to execute the "shell-exec's" */
-
- extern long ftime();
-
- /*
- * Exec a shell that returns exit status correctly (/bin/esh).
- * The standard EON shell returns the process number of the last
- * async command, used by the debugger (ugg).
- * [exec on eon is like a fork+exec on unix]
- */
- int
- dosh(command, args)
- char *command;
- char *args;
- {
- if (!execfile) {
- execfile = fopen(MAKERUN, "w");
- if (!execfile) {
- errout("Make: can't create ");
- errout(MAKERUN);
- errout("\r\n");
- exit(-1);
- }
- }
-
- fprintf(execfile, "%s %s", command, args);
- return 0;
- }
-
-
- /*
- * Do commands to make a target
- */
- void
- docmds(np)
- struct name * np;
- {
- bool ssilent;
- bool signore;
- int estat;
- register char * q;
- register char * p;
- char * shell;
- register struct line * lp;
- register struct cmd * cp;
- ssilent = silent;
-
- /*
- * Under cp/m the "ignore or not to ignore" is sorta done in dosh()
- * where colons are inserted or not into the cp/m submit file.
- * The actual ignoring (or not) is done when cpm 3.0's submit
- * program executes the submit file.
- *
- * -mdk
- */
-
- signore = ignore;
-
- if (*(shell = getmacro("SHELL")) == '\0')
- shell = ":bin/esh";
-
- for (lp = np->n_line; lp; lp = lp->l_next)
- for (cp = lp->l_cmd; cp; cp = cp->c_next)
- {
- strcpy(str1, cp->c_cmd);
- expand(str1);
- q = str1;
- while ((*q == '@') || (*q == '-'))
- {
- if (*q == '@') /* Specific silent */
- ssilent = TRUE;
- else /* Specific ignore */
- signore = TRUE;
- q++; /* Not part of the command */
- }
-
- if (!ssilent)
- fputs(" ", stdout);
-
- if ((!ssilent) && (!signore)) { /* cp/m stuff */
- putchar(':');
- putchar(' ');
- }
- for (p=q; *p; p++)
- {
- if (*p == '\n' && p[1] != '\0')
- {
- *p = ' ';
- if (!ssilent)
- fputs("\\\n", stdout);
- }
- else if (!ssilent)
- putchar(*p);
- }
- if (!ssilent)
- putchar('\n');
-
- if (domake)
- { /* Get the shell to execute it */
- /*
- * Colon in front of line makes execution
- * conditional on error code in cp/m 3.0 .
- * (Sortof, with one "minor" problem)
- */
-
- if (!signore)
- dosh(":","");
-
- if ((estat = dosh(q,"\n")) != 0)
- {
- if (estat == -1)
- fatal("Couldn't execute %s", shell);
- else
- {
- printf("%s: Error code %d", myname, estat);
- if (signore)
- fputs(" (Ignored)\n", stdout);
- else
- {
- putchar('\n');
- if (!(np->n_flag & N_PREC))
- if (unlink(np->n_name) == 0)
- printf("%s: '%s' removed.\n", myname, np->n_name);
- exit(estat);
- }
- }
- }
- }
- }
- }
-
-
-
- /*
- * Update the mod time of a file to now.
- */
- void
- touch(np)
- struct name * np;
- {
- char c;
- int fd;
- char fcb[36]; /* set area for CP/M fcb */
- char tempbuffer[128]; /* CPM record size */
-
-
- if (!domake || !silent)
- printf(" touch %s\n", np->n_name);
-
- if (domake) {
- if ((fd=open(np->n_name,O_RDONLY)) < 0 ) {
- printf("%s: '%s' not touched - non-existant\n",
- myname, np->n_name);
- }
- else {
- close(fd);
- OpenRandomFile(np->n_name,fcb); /* open file */
- ReadRandomFile(tempbuffer,0,fcb); /* read record */
- WriteRandomFile(tempbuffer,0,fcb); /* write it back */
- }
- CloseRandomFile(fcb);
- }
- }
-
-
- /*
- * Recursive routine to make a target.
- */
- int
- make(np, level)
- struct name * np;
- int level;
- {
- register struct depend * dp;
- register struct line * lp;
- time_t dtime = 1l;
-
-
- if (np->n_flag & N_DONE)
- return 0;
-
- if (!np->n_time) {
- np->n_time = ftime(np->n_name);/* Gets modtime of this file*/
- }
-
- if (rules) {
- for (lp = np->n_line; lp; lp = lp->l_next)
- if (lp->l_cmd)
- break;
- if (!lp)
- dyndep(np);
- }
-
- if (!(np->n_flag & N_TARG) && np->n_time == 0L)
- fatal("Don't know how to make %s", np->n_name);
-
- for (lp = np->n_line; lp; lp = lp->l_next)
- for (dp = lp->l_dep; dp; dp = dp->d_next)
- {
- make(dp->d_name, level+1);
- dtime = max(dtime, dp->d_name->n_time);
- }
-
- np->n_flag |= N_DONE;
-
- if (quest)
- {
- time(&np->n_time); /* used to be rtime() zzz */
- return np->n_time < dtime;
- }
- else if (np->n_time < dtime)
- {
- if (dotouch)
- touch(np);
- else
- {
- setmacro("@", np->n_name);
- docmds(np);
- }
- time(&np->n_time); /* used to be rtime() zzz */
- }
- else if (level == 0)
- printf("%s: '%s' is up to date\n", myname, np->n_name);
- return 0;
- }
-