Annotation of src/usr.bin/make/compat.c, Revision 1.68
1.36 espie 1: /* $OpenPackages$ */
1.61 espie 2: /* $OpenBSD$ */
1.8 millert 3: /* $NetBSD: compat.c,v 1.14 1996/11/06 17:59:01 christos Exp $ */
1.1 deraadt 4:
5: /*
6: * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
7: * Copyright (c) 1988, 1989 by Adam de Boor
8: * Copyright (c) 1989 by Berkeley Softworks
9: * All rights reserved.
10: *
11: * This code is derived from software contributed to Berkeley by
12: * Adam de Boor.
13: *
14: * Redistribution and use in source and binary forms, with or without
15: * modification, are permitted provided that the following conditions
16: * are met:
17: * 1. Redistributions of source code must retain the above copyright
18: * notice, this list of conditions and the following disclaimer.
19: * 2. Redistributions in binary form must reproduce the above copyright
20: * notice, this list of conditions and the following disclaimer in the
21: * documentation and/or other materials provided with the distribution.
1.49 millert 22: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: */
38:
1.39 espie 39: #include <limits.h>
1.37 espie 40: #include <signal.h>
41: #include <stdio.h>
1.39 espie 42: #include <stdlib.h>
1.37 espie 43: #include "config.h"
44: #include "defines.h"
45: #include "dir.h"
1.55 espie 46: #include "engine.h"
1.37 espie 47: #include "compat.h"
48: #include "suff.h"
49: #include "var.h"
50: #include "targ.h"
51: #include "error.h"
52: #include "extern.h"
53: #include "gnode.h"
54: #include "timestamp.h"
55: #include "lst.h"
1.1 deraadt 56:
1.36 espie 57: static void CompatMake(void *, void *);
1.60 espie 58:
1.1 deraadt 59: /*-
60: *-----------------------------------------------------------------------
61: * CompatMake --
62: * Make a target.
63: *
64: * Side Effects:
65: * If an error is detected and not being ignored, the process exits.
66: *-----------------------------------------------------------------------
67: */
1.26 espie 68: static void
1.50 espie 69: CompatMake(void *gnp, /* The node to make */
70: void *pgnp) /* Parent to abort if necessary */
1.1 deraadt 71: {
1.57 espie 72: GNode *gn = (GNode *)gnp;
73: GNode *pgn = (GNode *)pgnp;
74:
1.63 espie 75: look_harder_for_target(gn);
76:
1.57 espie 77: if (pgn->type & OP_MADE) {
78: (void)Dir_MTime(gn);
1.67 espie 79: gn->built_status = UPTODATE;
1.57 espie 80: }
81:
82: if (gn->type & OP_USE) {
83: Make_HandleUse(gn, pgn);
1.68 ! espie 84: } else if (gn->built_status == UNKNOWN) {
1.57 espie 85: /* First mark ourselves to be made, then apply whatever
1.60 espie 86: * transformations the suffix module thinks are necessary.
87: * Once that's done, we can descend and make all our children.
88: * If any of them has an error but the -k flag was given,
1.67 espie 89: * our 'must_make' field will be set false again. This is our
1.60 espie 90: * signal to not attempt to do anything but abort our
91: * parent as well. */
1.67 espie 92: gn->must_make = true;
93: gn->built_status = BEINGMADE;
1.57 espie 94: Suff_FindDeps(gn);
95: Lst_ForEach(&gn->children, CompatMake, gn);
1.67 espie 96: if (!gn->must_make) {
97: gn->built_status = ABORTED;
98: pgn->must_make = false;
1.57 espie 99: return;
100: }
1.5 millert 101:
1.57 espie 102: /* All the children were made ok. Now cmtime contains the
103: * modification time of the newest child, we need to find out
1.60 espie 104: * if we exist and when we were modified last. The criteria
105: * for datedness are defined by the Make_OODate function. */
1.57 espie 106: if (DEBUG(MAKE))
107: printf("Examining %s...", gn->name);
1.60 espie 108: if (!Make_OODate(gn)) {
1.67 espie 109: gn->built_status = UPTODATE;
1.57 espie 110: if (DEBUG(MAKE))
111: printf("up-to-date.\n");
112: return;
113: } else if (DEBUG(MAKE))
114: printf("out-of-date.\n");
115:
1.60 espie 116: /* If the user is just seeing if something is out-of-date,
117: * exit now to tell him/her "yes". */
1.57 espie 118: if (queryFlag)
119: exit(-1);
120:
1.60 espie 121: /* We need to be re-made. We also have to make sure we've
122: * got a $? variable. To be nice, we also define the $>
123: * variable using Make_DoAllVar(). */
1.57 espie 124: Make_DoAllVar(gn);
125:
126: if (Job_CheckCommands(gn, Fatal)) {
1.62 espie 127: /* Our commands are ok, but we still have to worry
128: * about the -t flag... */
129: if (!touchFlag)
1.63 espie 130: run_gnode(gn, 0);
1.62 espie 131: else
1.65 espie 132: Job_Touch(gn);
1.57 espie 133: } else
1.67 espie 134: gn->built_status = ERROR;
1.57 espie 135:
1.67 espie 136: if (gn->built_status != ERROR) {
1.57 espie 137: /* If the node was made successfully, mark it so,
1.60 espie 138: * update its modification time and timestamp all
139: * its parents.
140: * This is to keep its state from affecting that of
141: * its parent. */
1.67 espie 142: gn->built_status = MADE;
1.57 espie 143: /* This is what Make does and it's actually a good
144: * thing, as it allows rules like
145: *
146: * cmp -s y.tab.h parse.h || cp y.tab.h parse.h
147: *
148: * to function as intended. Unfortunately, thanks to
1.60 espie 149: * the stateless nature of NFS (and the speed of
150: * this program), there are times when the
151: * modification time of a file created on a remote
152: * machine will not be modified before the stat()
153: * implied by the Dir_MTime occurs, thus leading us
154: * to believe that the file is unchanged, wreaking
155: * havoc with files that depend on this one.
1.57 espie 156: */
157: if (noExecute || is_out_of_date(Dir_MTime(gn)))
158: gn->mtime = now;
159: if (is_strictly_before(gn->mtime, gn->cmtime))
160: gn->mtime = gn->cmtime;
161: if (DEBUG(MAKE))
1.59 espie 162: printf("update time: %s\n",
1.57 espie 163: time_to_string(gn->mtime));
164: if (!(gn->type & OP_EXEC)) {
165: pgn->childMade = true;
166: Make_TimeStamp(pgn, gn);
167: }
168: } else if (keepgoing)
1.67 espie 169: pgn->must_make = false;
1.57 espie 170: else {
1.36 espie 171:
1.57 espie 172: if (gn->lineno)
173: printf("\n\nStop in %s (line %lu of %s).\n",
174: Var_Value(".CURDIR"),
175: (unsigned long)gn->lineno,
176: gn->fname);
177: else
1.59 espie 178: printf("\n\nStop in %s.\n",
1.57 espie 179: Var_Value(".CURDIR"));
180: exit(1);
181: }
1.67 espie 182: } else if (gn->built_status == ERROR)
183: /* Already had an error when making this beastie. Tell the
184: * parent to abort. */
185: pgn->must_make = false;
1.57 espie 186: else {
1.67 espie 187: switch (gn->built_status) {
1.57 espie 188: case BEINGMADE:
189: Error("Graph cycles through %s\n", gn->name);
1.67 espie 190: gn->built_status = ERROR;
191: pgn->must_make = false;
1.57 espie 192: break;
193: case MADE:
194: if ((gn->type & OP_EXEC) == 0) {
195: pgn->childMade = true;
196: Make_TimeStamp(pgn, gn);
197: }
198: break;
199: case UPTODATE:
200: if ((gn->type & OP_EXEC) == 0)
201: Make_TimeStamp(pgn, gn);
202: break;
203: default:
204: break;
205: }
1.1 deraadt 206: }
207: }
1.36 espie 208:
1.1 deraadt 209: void
1.50 espie 210: Compat_Run(Lst targs) /* List of target nodes to re-create */
1.1 deraadt 211: {
1.60 espie 212: GNode *gn = NULL; /* Current root target */
213: int errors; /* Number of targets not remade due to errors */
1.57 espie 214:
1.63 espie 215: setup_engine();
1.57 espie 216: /* If the user has defined a .BEGIN target, execute the commands
217: * attached to it. */
218: if (!queryFlag) {
1.63 espie 219: if (run_gnode(begin_node, 0) == ERROR) {
1.60 espie 220: printf("\n\nStop.\n");
221: exit(1);
1.57 espie 222: }
223: }
224:
225: /* For each entry in the list of targets to create, call CompatMake on
1.67 espie 226: * it to create the thing. CompatMake will leave the 'built_status'
227: * field of gn in one of several states:
1.57 espie 228: * UPTODATE gn was already up-to-date
229: * MADE gn was recreated successfully
1.60 espie 230: * ERROR An error occurred while gn was being
231: * created
1.59 espie 232: * ABORTED gn was not remade because one of its
1.60 espie 233: * inferiors could not be made due to errors.
1.57 espie 234: */
235: errors = 0;
236: while ((gn = (GNode *)Lst_DeQueue(targs)) != NULL) {
237: CompatMake(gn, gn);
238:
1.67 espie 239: if (gn->built_status == UPTODATE)
1.57 espie 240: printf("`%s' is up to date.\n", gn->name);
1.67 espie 241: else if (gn->built_status == ABORTED) {
1.59 espie 242: printf("`%s' not remade because of errors.\n",
1.57 espie 243: gn->name);
1.58 espie 244: errors++;
1.57 espie 245: }
246: }
247:
248: /* If the user has defined a .END target, run its commands. */
249: if (errors == 0)
1.63 espie 250: run_gnode(end_node, 0);
1.1 deraadt 251: }