compat.c revision 1.1 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3 1.1 cgd * Copyright (c) 1988, 1989 by Adam de Boor
4 1.1 cgd * Copyright (c) 1989 by Berkeley Softworks
5 1.1 cgd * All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This code is derived from software contributed to Berkeley by
8 1.1 cgd * Adam de Boor.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.1 cgd * This product includes software developed by the University of
21 1.1 cgd * California, Berkeley and its contributors.
22 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
23 1.1 cgd * may be used to endorse or promote products derived from this software
24 1.1 cgd * without specific prior written permission.
25 1.1 cgd *
26 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 cgd * SUCH DAMAGE.
37 1.1 cgd */
38 1.1 cgd
39 1.1 cgd #ifndef lint
40 1.1 cgd static char sccsid[] = "@(#)compat.c 5.7 (Berkeley) 3/1/91";
41 1.1 cgd #endif /* not lint */
42 1.1 cgd
43 1.1 cgd /*-
44 1.1 cgd * compat.c --
45 1.1 cgd * The routines in this file implement the full-compatibility
46 1.1 cgd * mode of PMake. Most of the special functionality of PMake
47 1.1 cgd * is available in this mode. Things not supported:
48 1.1 cgd * - different shells.
49 1.1 cgd * - friendly variable substitution.
50 1.1 cgd *
51 1.1 cgd * Interface:
52 1.1 cgd * Compat_Run Initialize things for this module and recreate
53 1.1 cgd * thems as need creatin'
54 1.1 cgd */
55 1.1 cgd
56 1.1 cgd #include <stdio.h>
57 1.1 cgd #include <sys/types.h>
58 1.1 cgd #include <sys/signal.h>
59 1.1 cgd #include <sys/wait.h>
60 1.1 cgd #include <sys/errno.h>
61 1.1 cgd #include <ctype.h>
62 1.1 cgd #include "make.h"
63 1.1 cgd extern int errno;
64 1.1 cgd
65 1.1 cgd /*
66 1.1 cgd * The following array is used to make a fast determination of which
67 1.1 cgd * characters are interpreted specially by the shell. If a command
68 1.1 cgd * contains any of these characters, it is executed by the shell, not
69 1.1 cgd * directly by us.
70 1.1 cgd */
71 1.1 cgd
72 1.1 cgd static char meta[256];
73 1.1 cgd
74 1.1 cgd static GNode *curTarg = NILGNODE;
75 1.1 cgd static GNode *ENDNode;
76 1.1 cgd static int CompatRunCommand();
77 1.1 cgd
78 1.1 cgd /*-
79 1.1 cgd *-----------------------------------------------------------------------
80 1.1 cgd * CompatInterrupt --
81 1.1 cgd * Interrupt the creation of the current target and remove it if
82 1.1 cgd * it ain't precious.
83 1.1 cgd *
84 1.1 cgd * Results:
85 1.1 cgd * None.
86 1.1 cgd *
87 1.1 cgd * Side Effects:
88 1.1 cgd * The target is removed and the process exits. If .INTERRUPT exists,
89 1.1 cgd * its commands are run first WITH INTERRUPTS IGNORED..
90 1.1 cgd *
91 1.1 cgd *-----------------------------------------------------------------------
92 1.1 cgd */
93 1.1 cgd static void
94 1.1 cgd CompatInterrupt (signo)
95 1.1 cgd int signo;
96 1.1 cgd {
97 1.1 cgd GNode *gn;
98 1.1 cgd
99 1.1 cgd if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
100 1.1 cgd char *file = Var_Value (TARGET, curTarg);
101 1.1 cgd
102 1.1 cgd if (unlink (file) == SUCCESS) {
103 1.1 cgd printf ("*** %s removed\n", file);
104 1.1 cgd }
105 1.1 cgd
106 1.1 cgd /*
107 1.1 cgd * Run .INTERRUPT only if hit with interrupt signal
108 1.1 cgd */
109 1.1 cgd if (signo == SIGINT) {
110 1.1 cgd gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
111 1.1 cgd if (gn != NILGNODE) {
112 1.1 cgd Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
113 1.1 cgd }
114 1.1 cgd }
115 1.1 cgd }
116 1.1 cgd exit (0);
117 1.1 cgd }
118 1.1 cgd
119 1.1 cgd /*-
121 1.1 cgd *-----------------------------------------------------------------------
122 1.1 cgd * CompatRunCommand --
123 1.1 cgd * Execute the next command for a target. If the command returns an
124 1.1 cgd * error, the node's made field is set to ERROR and creation stops.
125 1.1 cgd *
126 1.1 cgd * Results:
127 1.1 cgd * 0 if the command succeeded, 1 if an error occurred.
128 1.1 cgd *
129 1.1 cgd * Side Effects:
130 1.1 cgd * The node's 'made' field may be set to ERROR.
131 1.1 cgd *
132 1.1 cgd *-----------------------------------------------------------------------
133 1.1 cgd */
134 1.1 cgd static int
135 1.1 cgd CompatRunCommand (cmd, gn)
136 1.1 cgd char *cmd; /* Command to execute */
137 1.1 cgd GNode *gn; /* Node from which the command came */
138 1.1 cgd {
139 1.1 cgd char *cmdStart; /* Start of expanded command */
140 1.1 cgd register char *cp;
141 1.1 cgd Boolean silent, /* Don't print command */
142 1.1 cgd errCheck; /* Check errors */
143 1.1 cgd union wait reason; /* Reason for child's death */
144 1.1 cgd int status; /* Description of child's death */
145 1.1 cgd int cpid; /* Child actually found */
146 1.1 cgd int numWritten; /* Number of bytes written for error message */
147 1.1 cgd ReturnStatus stat; /* Status of fork */
148 1.1 cgd LstNode cmdNode; /* Node where current command is located */
149 1.1 cgd char **av; /* Argument vector for thing to exec */
150 1.1 cgd int argc; /* Number of arguments in av or 0 if not
151 1.1 cgd * dynamically allocated */
152 1.1 cgd Boolean local; /* TRUE if command should be executed
153 1.1 cgd * locally */
154 1.1 cgd
155 1.1 cgd silent = gn->type & OP_SILENT;
156 1.1 cgd errCheck = !(gn->type & OP_IGNORE);
157 1.1 cgd
158 1.1 cgd cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
159 1.1 cgd cmdStart = Var_Subst (cmd, gn, FALSE);
160 1.1 cgd
161 1.1 cgd /*
162 1.1 cgd * brk_string will return an argv with a NULL in av[1], thus causing
163 1.1 cgd * execvp to choke and die horribly. Besides, how can we execute a null
164 1.1 cgd * command? In any case, we warn the user that the command expanded to
165 1.1 cgd * nothing (is this the right thing to do?).
166 1.1 cgd */
167 1.1 cgd
168 1.1 cgd if (*cmdStart == '\0') {
169 1.1 cgd Error("%s expands to empty string", cmd);
170 1.1 cgd return(0);
171 1.1 cgd } else {
172 1.1 cgd cmd = cmdStart;
173 1.1 cgd }
174 1.1 cgd Lst_Replace (cmdNode, (ClientData)cmdStart);
175 1.1 cgd
176 1.1 cgd if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
177 1.1 cgd (void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
178 1.1 cgd return(0);
179 1.1 cgd } else if (strcmp(cmdStart, "...") == 0) {
180 1.1 cgd gn->type |= OP_SAVE_CMDS;
181 1.1 cgd return(0);
182 1.1 cgd }
183 1.1 cgd
184 1.1 cgd while ((*cmd == '@') || (*cmd == '-')) {
185 1.1 cgd if (*cmd == '@') {
186 1.1 cgd silent = TRUE;
187 1.1 cgd } else {
188 1.1 cgd errCheck = FALSE;
189 1.1 cgd }
190 1.1 cgd cmd++;
191 1.1 cgd }
192 1.1 cgd
193 1.1 cgd while (isspace(*cmd)) cmd++;
194 1.1 cgd
195 1.1 cgd /*
196 1.1 cgd * Search for meta characters in the command. If there are no meta
197 1.1 cgd * characters, there's no need to execute a shell to execute the
198 1.1 cgd * command.
199 1.1 cgd */
200 1.1 cgd for (cp = cmd; !meta[*cp]; cp++) {
201 1.1 cgd continue;
202 1.1 cgd }
203 1.1 cgd
204 1.1 cgd /*
205 1.1 cgd * Print the command before echoing if we're not supposed to be quiet for
206 1.1 cgd * this one. We also print the command if -n given.
207 1.1 cgd */
208 1.1 cgd if (!silent || noExecute) {
209 1.1 cgd printf ("%s\n", cmd);
210 1.1 cgd fflush(stdout);
211 1.1 cgd }
212 1.1 cgd
213 1.1 cgd /*
214 1.1 cgd * If we're not supposed to execute any commands, this is as far as
215 1.1 cgd * we go...
216 1.1 cgd */
217 1.1 cgd if (noExecute) {
218 1.1 cgd return (0);
219 1.1 cgd }
220 1.1 cgd
221 1.1 cgd if (*cp != '\0') {
222 1.1 cgd /*
223 1.1 cgd * If *cp isn't the null character, we hit a "meta" character and
224 1.1 cgd * need to pass the command off to the shell. We give the shell the
225 1.1 cgd * -e flag as well as -c if it's supposed to exit when it hits an
226 1.1 cgd * error.
227 1.1 cgd */
228 1.1 cgd static char *shargv[4] = { "/bin/sh" };
229 1.1 cgd
230 1.1 cgd shargv[1] = (errCheck ? "-ec" : "-c");
231 1.1 cgd shargv[2] = cmd;
232 1.1 cgd shargv[3] = (char *)NULL;
233 1.1 cgd av = shargv;
234 1.1 cgd argc = 0;
235 1.1 cgd } else {
236 1.1 cgd /*
237 1.1 cgd * No meta-characters, so no need to exec a shell. Break the command
238 1.1 cgd * into words to form an argument vector we can execute.
239 1.1 cgd * brk_string sticks our name in av[0], so we have to
240 1.1 cgd * skip over it...
241 1.1 cgd */
242 1.1 cgd av = brk_string(cmd, &argc);
243 1.1 cgd av += 1;
244 1.1 cgd }
245 1.1 cgd
246 1.1 cgd local = TRUE;
247 1.1 cgd
248 1.1 cgd /*
249 1.1 cgd * Fork and execute the single command. If the fork fails, we abort.
250 1.1 cgd */
251 1.1 cgd cpid = vfork();
252 1.1 cgd if (cpid < 0) {
253 1.1 cgd Fatal("Could not fork");
254 1.1 cgd }
255 1.1 cgd if (cpid == 0) {
256 1.1 cgd if (local) {
257 1.1 cgd execvp(av[0], av);
258 1.1 cgd numWritten = write (2, av[0], strlen (av[0]));
259 1.1 cgd numWritten = write (2, ": not found\n", sizeof(": not found"));
260 1.1 cgd } else {
261 1.1 cgd (void)execv(av[0], av);
262 1.1 cgd }
263 1.1 cgd exit(1);
264 1.1 cgd }
265 1.1 cgd
266 1.1 cgd /*
267 1.1 cgd * The child is off and running. Now all we can do is wait...
268 1.1 cgd */
269 1.1 cgd while (1) {
270 1.1 cgd int id;
271 1.1 cgd
272 1.1 cgd if (!local) {
273 1.1 cgd id = 0;
274 1.1 cgd }
275 1.1 cgd
276 1.1 cgd while ((stat = wait((int *)&reason)) != cpid) {
277 1.1 cgd if (stat == -1 && errno != EINTR) {
278 1.1 cgd break;
279 1.1 cgd }
280 1.1 cgd }
281 1.1 cgd
282 1.1 cgd if (stat > -1) {
283 1.1 cgd if (WIFSTOPPED(reason)) {
284 1.1 cgd status = reason.w_stopval; /* stopped */
285 1.1 cgd } else if (WIFEXITED(reason)) {
286 1.1 cgd status = reason.w_retcode; /* exited */
287 1.1 cgd if (status != 0) {
288 1.1 cgd printf ("*** Error code %d", status);
289 1.1 cgd }
290 1.1 cgd } else {
291 1.1 cgd status = reason.w_termsig; /* signaled */
292 1.1 cgd printf ("*** Signal %d", status);
293 1.1 cgd }
294 1.1 cgd
295 1.1 cgd
296 1.1 cgd if (!WIFEXITED(reason) || (status != 0)) {
297 1.1 cgd if (errCheck) {
298 1.1 cgd gn->made = ERROR;
299 1.1 cgd if (keepgoing) {
300 1.1 cgd /*
301 1.1 cgd * Abort the current target, but let others
302 1.1 cgd * continue.
303 1.1 cgd */
304 1.1 cgd printf (" (continuing)\n");
305 1.1 cgd }
306 1.1 cgd } else {
307 1.1 cgd /*
308 1.1 cgd * Continue executing commands for this target.
309 1.1 cgd * If we return 0, this will happen...
310 1.1 cgd */
311 1.1 cgd printf (" (ignored)\n");
312 1.1 cgd status = 0;
313 1.1 cgd }
314 1.1 cgd }
315 1.1 cgd break;
316 1.1 cgd } else {
317 1.1 cgd Fatal ("error in wait: %d", stat);
318 1.1 cgd /*NOTREACHED*/
319 1.1 cgd }
320 1.1 cgd }
321 1.1 cgd
322 1.1 cgd return (status);
323 1.1 cgd }
324 1.1 cgd
325 1.1 cgd /*-
327 1.1 cgd *-----------------------------------------------------------------------
328 1.1 cgd * CompatMake --
329 1.1 cgd * Make a target.
330 1.1 cgd *
331 1.1 cgd * Results:
332 1.1 cgd * 0
333 1.1 cgd *
334 1.1 cgd * Side Effects:
335 1.1 cgd * If an error is detected and not being ignored, the process exits.
336 1.1 cgd *
337 1.1 cgd *-----------------------------------------------------------------------
338 1.1 cgd */
339 1.1 cgd static int
340 1.1 cgd CompatMake (gn, pgn)
341 1.1 cgd GNode *gn; /* The node to make */
342 1.1 cgd GNode *pgn; /* Parent to abort if necessary */
343 1.1 cgd {
344 1.1 cgd if (gn->type & OP_USE) {
345 1.1 cgd Make_HandleUse(gn, pgn);
346 1.1 cgd } else if (gn->made == UNMADE) {
347 1.1 cgd /*
348 1.1 cgd * First mark ourselves to be made, then apply whatever transformations
349 1.1 cgd * the suffix module thinks are necessary. Once that's done, we can
350 1.1 cgd * descend and make all our children. If any of them has an error
351 1.1 cgd * but the -k flag was given, our 'make' field will be set FALSE again.
352 1.1 cgd * This is our signal to not attempt to do anything but abort our
353 1.1 cgd * parent as well.
354 1.1 cgd */
355 1.1 cgd gn->make = TRUE;
356 1.1 cgd gn->made = BEINGMADE;
357 1.1 cgd Suff_FindDeps (gn);
358 1.1 cgd Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
359 1.1 cgd if (!gn->make) {
360 1.1 cgd gn->made = ABORTED;
361 1.1 cgd pgn->make = FALSE;
362 1.1 cgd return (0);
363 1.1 cgd }
364 1.1 cgd
365 1.1 cgd if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
366 1.1 cgd Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
367 1.1 cgd }
368 1.1 cgd
369 1.1 cgd /*
370 1.1 cgd * All the children were made ok. Now cmtime contains the modification
371 1.1 cgd * time of the newest child, we need to find out if we exist and when
372 1.1 cgd * we were modified last. The criteria for datedness are defined by the
373 1.1 cgd * Make_OODate function.
374 1.1 cgd */
375 1.1 cgd if (DEBUG(MAKE)) {
376 1.1 cgd printf("Examining %s...", gn->name);
377 1.1 cgd }
378 1.1 cgd if (! Make_OODate(gn)) {
379 1.1 cgd gn->made = UPTODATE;
380 1.1 cgd if (DEBUG(MAKE)) {
381 1.1 cgd printf("up-to-date.\n");
382 1.1 cgd }
383 1.1 cgd return (0);
384 1.1 cgd } else if (DEBUG(MAKE)) {
385 1.1 cgd printf("out-of-date.\n");
386 1.1 cgd }
387 1.1 cgd
388 1.1 cgd /*
389 1.1 cgd * If the user is just seeing if something is out-of-date, exit now
390 1.1 cgd * to tell him/her "yes".
391 1.1 cgd */
392 1.1 cgd if (queryFlag) {
393 1.1 cgd exit (-1);
394 1.1 cgd }
395 1.1 cgd
396 1.1 cgd /*
397 1.1 cgd * We need to be re-made. We also have to make sure we've got a $?
398 1.1 cgd * variable. To be nice, we also define the $> variable using
399 1.1 cgd * Make_DoAllVar().
400 1.1 cgd */
401 1.1 cgd Make_DoAllVar(gn);
402 1.1 cgd
403 1.1 cgd /*
404 1.1 cgd * Alter our type to tell if errors should be ignored or things
405 1.1 cgd * should not be printed so CompatRunCommand knows what to do.
406 1.1 cgd */
407 1.1 cgd if (Targ_Ignore (gn)) {
408 1.1 cgd gn->type |= OP_IGNORE;
409 1.1 cgd }
410 1.1 cgd if (Targ_Silent (gn)) {
411 1.1 cgd gn->type |= OP_SILENT;
412 1.1 cgd }
413 1.1 cgd
414 1.1 cgd if (Job_CheckCommands (gn, Fatal)) {
415 1.1 cgd /*
416 1.1 cgd * Our commands are ok, but we still have to worry about the -t
417 1.1 cgd * flag...
418 1.1 cgd */
419 1.1 cgd if (!touchFlag) {
420 1.1 cgd curTarg = gn;
421 1.1 cgd Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
422 1.1 cgd curTarg = NILGNODE;
423 1.1 cgd } else {
424 1.1 cgd Job_Touch (gn, gn->type & OP_SILENT);
425 1.1 cgd }
426 1.1 cgd } else {
427 1.1 cgd gn->made = ERROR;
428 1.1 cgd }
429 1.1 cgd
430 1.1 cgd if (gn->made != ERROR) {
431 1.1 cgd /*
432 1.1 cgd * If the node was made successfully, mark it so, update
433 1.1 cgd * its modification time and timestamp all its parents. Note
434 1.1 cgd * that for .ZEROTIME targets, the timestamping isn't done.
435 1.1 cgd * This is to keep its state from affecting that of its parent.
436 1.1 cgd */
437 1.1 cgd gn->made = MADE;
438 1.1 cgd #ifndef RECHECK
439 1.1 cgd /*
440 1.1 cgd * We can't re-stat the thing, but we can at least take care of
441 1.1 cgd * rules where a target depends on a source that actually creates
442 1.1 cgd * the target, but only if it has changed, e.g.
443 1.1 cgd *
444 1.1 cgd * parse.h : parse.o
445 1.1 cgd *
446 1.1 cgd * parse.o : parse.y
447 1.1 cgd * yacc -d parse.y
448 1.1 cgd * cc -c y.tab.c
449 1.1 cgd * mv y.tab.o parse.o
450 1.1 cgd * cmp -s y.tab.h parse.h || mv y.tab.h parse.h
451 1.1 cgd *
452 1.1 cgd * In this case, if the definitions produced by yacc haven't
453 1.1 cgd * changed from before, parse.h won't have been updated and
454 1.1 cgd * gn->mtime will reflect the current modification time for
455 1.1 cgd * parse.h. This is something of a kludge, I admit, but it's a
456 1.1 cgd * useful one..
457 1.1 cgd *
458 1.1 cgd * XXX: People like to use a rule like
459 1.1 cgd *
460 1.1 cgd * FRC:
461 1.1 cgd *
462 1.1 cgd * To force things that depend on FRC to be made, so we have to
463 1.1 cgd * check for gn->children being empty as well...
464 1.1 cgd */
465 1.1 cgd if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
466 1.1 cgd gn->mtime = now;
467 1.1 cgd }
468 1.1 cgd #else
469 1.1 cgd /*
470 1.1 cgd * This is what Make does and it's actually a good thing, as it
471 1.1 cgd * allows rules like
472 1.1 cgd *
473 1.1 cgd * cmp -s y.tab.h parse.h || cp y.tab.h parse.h
474 1.1 cgd *
475 1.1 cgd * to function as intended. Unfortunately, thanks to the stateless
476 1.1 cgd * nature of NFS (and the speed of this program), there are times
477 1.1 cgd * when the modification time of a file created on a remote
478 1.1 cgd * machine will not be modified before the stat() implied by
479 1.1 cgd * the Dir_MTime occurs, thus leading us to believe that the file
480 1.1 cgd * is unchanged, wreaking havoc with files that depend on this one.
481 1.1 cgd *
482 1.1 cgd * I have decided it is better to make too much than to make too
483 1.1 cgd * little, so this stuff is commented out unless you're sure it's
484 1.1 cgd * ok.
485 1.1 cgd * -- ardeb 1/12/88
486 1.1 cgd */
487 1.1 cgd if (noExecute || Dir_MTime(gn) == 0) {
488 1.1 cgd gn->mtime = now;
489 1.1 cgd }
490 1.1 cgd if (DEBUG(MAKE)) {
491 1.1 cgd printf("update time: %s\n", Targ_FmtTime(gn->mtime));
492 1.1 cgd }
493 1.1 cgd #endif
494 1.1 cgd if (!(gn->type & OP_EXEC)) {
495 1.1 cgd pgn->childMade = TRUE;
496 1.1 cgd Make_TimeStamp(pgn, gn);
497 1.1 cgd }
498 1.1 cgd } else if (keepgoing) {
499 1.1 cgd pgn->make = FALSE;
500 1.1 cgd } else {
501 1.1 cgd printf ("\n\nStop.\n");
502 1.1 cgd exit (1);
503 1.1 cgd }
504 1.1 cgd } else if (gn->made == ERROR) {
505 1.1 cgd /*
506 1.1 cgd * Already had an error when making this beastie. Tell the parent
507 1.1 cgd * to abort.
508 1.1 cgd */
509 1.1 cgd pgn->make = FALSE;
510 1.1 cgd } else {
511 1.1 cgd if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
512 1.1 cgd Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
513 1.1 cgd }
514 1.1 cgd switch(gn->made) {
515 1.1 cgd case BEINGMADE:
516 1.1 cgd Error("Graph cycles through %s\n", gn->name);
517 1.1 cgd gn->made = ERROR;
518 1.1 cgd pgn->make = FALSE;
519 1.1 cgd break;
520 1.1 cgd case MADE:
521 1.1 cgd if ((gn->type & OP_EXEC) == 0) {
522 1.1 cgd pgn->childMade = TRUE;
523 1.1 cgd Make_TimeStamp(pgn, gn);
524 1.1 cgd }
525 1.1 cgd break;
526 1.1 cgd case UPTODATE:
527 1.1 cgd if ((gn->type & OP_EXEC) == 0) {
528 1.1 cgd Make_TimeStamp(pgn, gn);
529 1.1 cgd }
530 1.1 cgd break;
531 1.1 cgd }
532 1.1 cgd }
533 1.1 cgd
534 1.1 cgd return (0);
535 1.1 cgd }
536 1.1 cgd
537 1.1 cgd /*-
539 1.1 cgd *-----------------------------------------------------------------------
540 1.1 cgd * Compat_Run --
541 1.1 cgd * Initialize this mode and start making.
542 1.1 cgd *
543 1.1 cgd * Results:
544 1.1 cgd * None.
545 1.1 cgd *
546 1.1 cgd * Side Effects:
547 1.1 cgd * Guess what?
548 1.1 cgd *
549 1.1 cgd *-----------------------------------------------------------------------
550 1.1 cgd */
551 1.1 cgd void
552 1.1 cgd Compat_Run(targs)
553 1.1 cgd Lst targs; /* List of target nodes to re-create */
554 1.1 cgd {
555 1.1 cgd char *cp; /* Pointer to string of shell meta-characters */
556 1.1 cgd GNode *gn; /* Current root target */
557 1.1 cgd int errors; /* Number of targets not remade due to errors */
558 1.1 cgd
559 1.1 cgd if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
560 1.1 cgd signal(SIGINT, CompatInterrupt);
561 1.1 cgd }
562 1.1 cgd if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
563 1.1 cgd signal(SIGTERM, CompatInterrupt);
564 1.1 cgd }
565 1.1 cgd if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
566 1.1 cgd signal(SIGHUP, CompatInterrupt);
567 1.1 cgd }
568 1.1 cgd if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
569 1.1 cgd signal(SIGQUIT, CompatInterrupt);
570 1.1 cgd }
571 1.1 cgd
572 1.1 cgd for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
573 1.1 cgd meta[*cp] = 1;
574 1.1 cgd }
575 1.1 cgd /*
576 1.1 cgd * The null character serves as a sentinel in the string.
577 1.1 cgd */
578 1.1 cgd meta[0] = 1;
579 1.1 cgd
580 1.1 cgd ENDNode = Targ_FindNode(".END", TARG_CREATE);
581 1.1 cgd /*
582 1.1 cgd * If the user has defined a .BEGIN target, execute the commands attached
583 1.1 cgd * to it.
584 1.1 cgd */
585 1.1 cgd if (!queryFlag) {
586 1.1 cgd gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
587 1.1 cgd if (gn != NILGNODE) {
588 1.1 cgd Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
589 1.1 cgd }
590 1.1 cgd }
591 1.1 cgd
592 1.1 cgd /*
593 1.1 cgd * For each entry in the list of targets to create, call CompatMake on
594 1.1 cgd * it to create the thing. CompatMake will leave the 'made' field of gn
595 1.1 cgd * in one of several states:
596 1.1 cgd * UPTODATE gn was already up-to-date
597 1.1 cgd * MADE gn was recreated successfully
598 1.1 cgd * ERROR An error occurred while gn was being created
599 1.1 cgd * ABORTED gn was not remade because one of its inferiors
600 1.1 cgd * could not be made due to errors.
601 1.1 cgd */
602 1.1 cgd errors = 0;
603 1.1 cgd while (!Lst_IsEmpty (targs)) {
604 1.1 cgd gn = (GNode *) Lst_DeQueue (targs);
605 1.1 cgd CompatMake (gn, gn);
606 1.1 cgd
607 1.1 cgd if (gn->made == UPTODATE) {
608 1.1 cgd printf ("`%s' is up to date.\n", gn->name);
609 1.1 cgd } else if (gn->made == ABORTED) {
610 1.1 cgd printf ("`%s' not remade because of errors.\n", gn->name);
611 1.1 cgd errors += 1;
612 1.1 cgd }
613 1.1 cgd }
614 1.1 cgd
615 1.1 cgd /*
616 1.1 cgd * If the user has defined a .END target, run its commands.
617 1.1 cgd */
618 1.1 cgd if (errors == 0) {
619 Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
620 }
621 }
622