1*b0c40a00SSimon J. Gerraty /* $NetBSD: make.c,v 1.244 2021/04/04 10:05:08 rillig Exp $ */ 23955d011SMarcel Moolenaar 33955d011SMarcel Moolenaar /* 43955d011SMarcel Moolenaar * Copyright (c) 1988, 1989, 1990, 1993 53955d011SMarcel Moolenaar * The Regents of the University of California. All rights reserved. 63955d011SMarcel Moolenaar * 73955d011SMarcel Moolenaar * This code is derived from software contributed to Berkeley by 83955d011SMarcel Moolenaar * Adam de Boor. 93955d011SMarcel Moolenaar * 103955d011SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 113955d011SMarcel Moolenaar * modification, are permitted provided that the following conditions 123955d011SMarcel Moolenaar * are met: 133955d011SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 143955d011SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 153955d011SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 163955d011SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 173955d011SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 183955d011SMarcel Moolenaar * 3. Neither the name of the University nor the names of its contributors 193955d011SMarcel Moolenaar * may be used to endorse or promote products derived from this software 203955d011SMarcel Moolenaar * without specific prior written permission. 213955d011SMarcel Moolenaar * 223955d011SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 233955d011SMarcel Moolenaar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 243955d011SMarcel Moolenaar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 253955d011SMarcel Moolenaar * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 263955d011SMarcel Moolenaar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 273955d011SMarcel Moolenaar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 283955d011SMarcel Moolenaar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 293955d011SMarcel Moolenaar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 303955d011SMarcel Moolenaar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 313955d011SMarcel Moolenaar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 323955d011SMarcel Moolenaar * SUCH DAMAGE. 333955d011SMarcel Moolenaar */ 343955d011SMarcel Moolenaar 353955d011SMarcel Moolenaar /* 363955d011SMarcel Moolenaar * Copyright (c) 1989 by Berkeley Softworks 373955d011SMarcel Moolenaar * All rights reserved. 383955d011SMarcel Moolenaar * 393955d011SMarcel Moolenaar * This code is derived from software contributed to Berkeley by 403955d011SMarcel Moolenaar * Adam de Boor. 413955d011SMarcel Moolenaar * 423955d011SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 433955d011SMarcel Moolenaar * modification, are permitted provided that the following conditions 443955d011SMarcel Moolenaar * are met: 453955d011SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 463955d011SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 473955d011SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 483955d011SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 493955d011SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 503955d011SMarcel Moolenaar * 3. All advertising materials mentioning features or use of this software 513955d011SMarcel Moolenaar * must display the following acknowledgement: 523955d011SMarcel Moolenaar * This product includes software developed by the University of 533955d011SMarcel Moolenaar * California, Berkeley and its contributors. 543955d011SMarcel Moolenaar * 4. Neither the name of the University nor the names of its contributors 553955d011SMarcel Moolenaar * may be used to endorse or promote products derived from this software 563955d011SMarcel Moolenaar * without specific prior written permission. 573955d011SMarcel Moolenaar * 583955d011SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 593955d011SMarcel Moolenaar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 603955d011SMarcel Moolenaar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 613955d011SMarcel Moolenaar * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 623955d011SMarcel Moolenaar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 633955d011SMarcel Moolenaar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 643955d011SMarcel Moolenaar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 653955d011SMarcel Moolenaar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 663955d011SMarcel Moolenaar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 673955d011SMarcel Moolenaar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 683955d011SMarcel Moolenaar * SUCH DAMAGE. 693955d011SMarcel Moolenaar */ 703955d011SMarcel Moolenaar 7106b9b3e0SSimon J. Gerraty /* 7206b9b3e0SSimon J. Gerraty * Examination of targets and their suitability for creation. 733955d011SMarcel Moolenaar * 743955d011SMarcel Moolenaar * Interface: 75*b0c40a00SSimon J. Gerraty * Make_Run Initialize things for the module. Returns true if 76e2eeea75SSimon J. Gerraty * work was (or would have been) done. 773955d011SMarcel Moolenaar * 78e2eeea75SSimon J. Gerraty * Make_Update After a target is made, update all its parents. 79e2eeea75SSimon J. Gerraty * Perform various bookkeeping chores like the updating 80956e45f6SSimon J. Gerraty * of the youngestChild field of the parent, filling 81dba7b0efSSimon J. Gerraty * of the IMPSRC variable, etc. Place the parent on the 82dba7b0efSSimon J. Gerraty * toBeMade queue if it should be. 833955d011SMarcel Moolenaar * 84e2eeea75SSimon J. Gerraty * GNode_UpdateYoungestChild 85e2eeea75SSimon J. Gerraty * Update the node's youngestChild field based on the 86e2eeea75SSimon J. Gerraty * child's modification time. 873955d011SMarcel Moolenaar * 88*b0c40a00SSimon J. Gerraty * GNode_SetLocalVars 89*b0c40a00SSimon J. Gerraty * Set up the various local variables for a 903955d011SMarcel Moolenaar * target, including the .ALLSRC variable, making 913955d011SMarcel Moolenaar * sure that any variable that needs to exist 923955d011SMarcel Moolenaar * at the very least has the empty value. 933955d011SMarcel Moolenaar * 94e2eeea75SSimon J. Gerraty * GNode_IsOODate Determine if a target is out-of-date. 953955d011SMarcel Moolenaar * 963955d011SMarcel Moolenaar * Make_HandleUse See if a child is a .USE node for a parent 973955d011SMarcel Moolenaar * and perform the .USE actions if so. 983955d011SMarcel Moolenaar * 993955d011SMarcel Moolenaar * Make_ExpandUse Expand .USE nodes 1003955d011SMarcel Moolenaar */ 1013955d011SMarcel Moolenaar 1023955d011SMarcel Moolenaar #include "make.h" 1033955d011SMarcel Moolenaar #include "dir.h" 1043955d011SMarcel Moolenaar #include "job.h" 1053955d011SMarcel Moolenaar 106956e45f6SSimon J. Gerraty /* "@(#)make.c 8.1 (Berkeley) 6/6/93" */ 107*b0c40a00SSimon J. Gerraty MAKE_RCSID("$NetBSD: make.c,v 1.244 2021/04/04 10:05:08 rillig Exp $"); 1083955d011SMarcel Moolenaar 109956e45f6SSimon J. Gerraty /* Sequence # to detect recursion. */ 110e2eeea75SSimon J. Gerraty static unsigned int checked_seqno = 1; 111956e45f6SSimon J. Gerraty 11206b9b3e0SSimon J. Gerraty /* 11306b9b3e0SSimon J. Gerraty * The current fringe of the graph. 114956e45f6SSimon J. Gerraty * These are nodes which await examination by MakeOODate. 11506b9b3e0SSimon J. Gerraty * It is added to by Make_Update and subtracted from by MakeStartJobs 11606b9b3e0SSimon J. Gerraty */ 11706b9b3e0SSimon J. Gerraty static GNodeList toBeMade = LST_INIT; 118956e45f6SSimon J. Gerraty 1193955d011SMarcel Moolenaar 120956e45f6SSimon J. Gerraty void 121956e45f6SSimon J. Gerraty debug_printf(const char *fmt, ...) 122956e45f6SSimon J. Gerraty { 123956e45f6SSimon J. Gerraty va_list args; 124956e45f6SSimon J. Gerraty 125956e45f6SSimon J. Gerraty va_start(args, fmt); 126956e45f6SSimon J. Gerraty vfprintf(opts.debug_file, fmt, args); 127956e45f6SSimon J. Gerraty va_end(args); 128956e45f6SSimon J. Gerraty } 129956e45f6SSimon J. Gerraty 1303955d011SMarcel Moolenaar MAKE_ATTR_DEAD static void 13106b9b3e0SSimon J. Gerraty make_abort(GNode *gn, int lineno) 1323955d011SMarcel Moolenaar { 13306b9b3e0SSimon J. Gerraty 13406b9b3e0SSimon J. Gerraty debug_printf("make_abort from line %d\n", lineno); 135956e45f6SSimon J. Gerraty Targ_PrintNode(gn, 2); 13606b9b3e0SSimon J. Gerraty Targ_PrintNodes(&toBeMade, 2); 1373955d011SMarcel Moolenaar Targ_PrintGraph(3); 1383955d011SMarcel Moolenaar abort(); 1393955d011SMarcel Moolenaar } 1403955d011SMarcel Moolenaar 1412c3632d1SSimon J. Gerraty ENUM_FLAGS_RTTI_31(GNodeType, 1422c3632d1SSimon J. Gerraty OP_DEPENDS, OP_FORCE, OP_DOUBLEDEP, 1432c3632d1SSimon J. Gerraty /* OP_OPMASK is omitted since it combines other flags */ 1442c3632d1SSimon J. Gerraty OP_OPTIONAL, OP_USE, OP_EXEC, OP_IGNORE, 1452c3632d1SSimon J. Gerraty OP_PRECIOUS, OP_SILENT, OP_MAKE, OP_JOIN, 1462c3632d1SSimon J. Gerraty OP_MADE, OP_SPECIAL, OP_USEBEFORE, OP_INVISIBLE, 1472c3632d1SSimon J. Gerraty OP_NOTMAIN, OP_PHONY, OP_NOPATH, OP_WAIT, 1482c3632d1SSimon J. Gerraty OP_NOMETA, OP_META, OP_NOMETA_CMP, OP_SUBMAKE, 1492c3632d1SSimon J. Gerraty OP_TRANSFORM, OP_MEMBER, OP_LIB, OP_ARCHV, 1502c3632d1SSimon J. Gerraty OP_HAS_COMMANDS, OP_SAVE_CMDS, OP_DEPS_FOUND, OP_MARK); 1512c3632d1SSimon J. Gerraty 152dba7b0efSSimon J. Gerraty ENUM_FLAGS_RTTI_9(GNodeFlags, 1532c3632d1SSimon J. Gerraty REMAKE, CHILDMADE, FORCE, DONE_WAIT, 1542c3632d1SSimon J. Gerraty DONE_ORDER, FROM_DEPEND, DONE_ALLSRC, CYCLE, 155dba7b0efSSimon J. Gerraty DONECYCLE); 1562c3632d1SSimon J. Gerraty 1572c3632d1SSimon J. Gerraty void 1582c3632d1SSimon J. Gerraty GNode_FprintDetails(FILE *f, const char *prefix, const GNode *gn, 1592c3632d1SSimon J. Gerraty const char *suffix) 1602c3632d1SSimon J. Gerraty { 1612c3632d1SSimon J. Gerraty char type_buf[GNodeType_ToStringSize]; 1622c3632d1SSimon J. Gerraty char flags_buf[GNodeFlags_ToStringSize]; 1632c3632d1SSimon J. Gerraty 164dba7b0efSSimon J. Gerraty fprintf(f, "%s%s, type %s, flags %s%s", 1652c3632d1SSimon J. Gerraty prefix, 166dba7b0efSSimon J. Gerraty GNodeMade_Name(gn->made), 167dba7b0efSSimon J. Gerraty GNodeType_ToString(type_buf, gn->type), 168dba7b0efSSimon J. Gerraty GNodeFlags_ToString(flags_buf, gn->flags), 1692c3632d1SSimon J. Gerraty suffix); 1702c3632d1SSimon J. Gerraty } 1712c3632d1SSimon J. Gerraty 172*b0c40a00SSimon J. Gerraty bool 173956e45f6SSimon J. Gerraty GNode_ShouldExecute(GNode *gn) 174956e45f6SSimon J. Gerraty { 17506b9b3e0SSimon J. Gerraty return !((gn->type & OP_MAKE) 17606b9b3e0SSimon J. Gerraty ? opts.noRecursiveExecute 17706b9b3e0SSimon J. Gerraty : opts.noExecute); 178956e45f6SSimon J. Gerraty } 179956e45f6SSimon J. Gerraty 180956e45f6SSimon J. Gerraty /* Update the youngest child of the node, according to the given child. */ 181956e45f6SSimon J. Gerraty void 182e2eeea75SSimon J. Gerraty GNode_UpdateYoungestChild(GNode *gn, GNode *cgn) 1833955d011SMarcel Moolenaar { 184e2eeea75SSimon J. Gerraty if (gn->youngestChild == NULL || cgn->mtime > gn->youngestChild->mtime) 185e2eeea75SSimon J. Gerraty gn->youngestChild = cgn; 1863955d011SMarcel Moolenaar } 187e2eeea75SSimon J. Gerraty 188*b0c40a00SSimon J. Gerraty static bool 189e2eeea75SSimon J. Gerraty IsOODateRegular(GNode *gn) 190e2eeea75SSimon J. Gerraty { 191e2eeea75SSimon J. Gerraty /* These rules are inherited from the original Make. */ 192e2eeea75SSimon J. Gerraty 193e2eeea75SSimon J. Gerraty if (gn->youngestChild != NULL) { 194e2eeea75SSimon J. Gerraty if (gn->mtime < gn->youngestChild->mtime) { 195e2eeea75SSimon J. Gerraty DEBUG1(MAKE, "modified before source \"%s\"...", 196e2eeea75SSimon J. Gerraty GNode_Path(gn->youngestChild)); 197*b0c40a00SSimon J. Gerraty return true; 198e2eeea75SSimon J. Gerraty } 199*b0c40a00SSimon J. Gerraty return false; 200e2eeea75SSimon J. Gerraty } 201e2eeea75SSimon J. Gerraty 202e2eeea75SSimon J. Gerraty if (gn->mtime == 0 && !(gn->type & OP_OPTIONAL)) { 20306b9b3e0SSimon J. Gerraty DEBUG0(MAKE, "nonexistent and no sources..."); 204*b0c40a00SSimon J. Gerraty return true; 205e2eeea75SSimon J. Gerraty } 206e2eeea75SSimon J. Gerraty 207e2eeea75SSimon J. Gerraty if (gn->type & OP_DOUBLEDEP) { 208e2eeea75SSimon J. Gerraty DEBUG0(MAKE, ":: operator and no sources..."); 209*b0c40a00SSimon J. Gerraty return true; 210e2eeea75SSimon J. Gerraty } 211e2eeea75SSimon J. Gerraty 212*b0c40a00SSimon J. Gerraty return false; 2133955d011SMarcel Moolenaar } 2143955d011SMarcel Moolenaar 21506b9b3e0SSimon J. Gerraty /* 21606b9b3e0SSimon J. Gerraty * See if the node is out of date with respect to its sources. 2173955d011SMarcel Moolenaar * 2183955d011SMarcel Moolenaar * Used by Make_Run when deciding which nodes to place on the 219956e45f6SSimon J. Gerraty * toBeMade queue initially and by Make_Update to screen out .USE and 220956e45f6SSimon J. Gerraty * .EXEC nodes. In the latter case, however, any other sort of node 2213955d011SMarcel Moolenaar * must be considered out-of-date since at least one of its children 2223955d011SMarcel Moolenaar * will have been recreated. 2233955d011SMarcel Moolenaar * 224956e45f6SSimon J. Gerraty * The mtime field of the node and the youngestChild field of its parents 225956e45f6SSimon J. Gerraty * may be changed. 2263955d011SMarcel Moolenaar */ 227*b0c40a00SSimon J. Gerraty bool 228e2eeea75SSimon J. Gerraty GNode_IsOODate(GNode *gn) 2293955d011SMarcel Moolenaar { 230*b0c40a00SSimon J. Gerraty bool oodate; 2313955d011SMarcel Moolenaar 2323955d011SMarcel Moolenaar /* 2333955d011SMarcel Moolenaar * Certain types of targets needn't even be sought as their datedness 2343955d011SMarcel Moolenaar * doesn't depend on their modification time... 2353955d011SMarcel Moolenaar */ 236e2eeea75SSimon J. Gerraty if (!(gn->type & (OP_JOIN | OP_USE | OP_USEBEFORE | OP_EXEC))) { 237*b0c40a00SSimon J. Gerraty Dir_UpdateMTime(gn, true); 2383955d011SMarcel Moolenaar if (DEBUG(MAKE)) { 239e2eeea75SSimon J. Gerraty if (gn->mtime != 0) 24006b9b3e0SSimon J. Gerraty debug_printf("modified %s...", 24106b9b3e0SSimon J. Gerraty Targ_FmtTime(gn->mtime)); 242e2eeea75SSimon J. Gerraty else 24306b9b3e0SSimon J. Gerraty debug_printf("nonexistent..."); 2443955d011SMarcel Moolenaar } 2453955d011SMarcel Moolenaar } 2463955d011SMarcel Moolenaar 2473955d011SMarcel Moolenaar /* 2483955d011SMarcel Moolenaar * A target is remade in one of the following circumstances: 24906b9b3e0SSimon J. Gerraty * 25006b9b3e0SSimon J. Gerraty * its modification time is smaller than that of its youngest 25106b9b3e0SSimon J. Gerraty * child and it would actually be run (has commands or is not 25206b9b3e0SSimon J. Gerraty * GNode_IsTarget) 25306b9b3e0SSimon J. Gerraty * 2543955d011SMarcel Moolenaar * it's the object of a force operator 2553955d011SMarcel Moolenaar * 25606b9b3e0SSimon J. Gerraty * it has no children, was on the lhs of an operator and doesn't 25706b9b3e0SSimon J. Gerraty * exist already. 2583955d011SMarcel Moolenaar * 25906b9b3e0SSimon J. Gerraty * Libraries are only considered out-of-date if the archive module 26006b9b3e0SSimon J. Gerraty * says they are. 26106b9b3e0SSimon J. Gerraty * 26206b9b3e0SSimon J. Gerraty * These weird rules are brought to you by Backward-Compatibility 26306b9b3e0SSimon J. Gerraty * and the strange people who wrote 'Make'. 2643955d011SMarcel Moolenaar */ 2653955d011SMarcel Moolenaar if (gn->type & (OP_USE | OP_USEBEFORE)) { 2663955d011SMarcel Moolenaar /* 2673955d011SMarcel Moolenaar * If the node is a USE node it is *never* out of date 2683955d011SMarcel Moolenaar * no matter *what*. 2693955d011SMarcel Moolenaar */ 270956e45f6SSimon J. Gerraty DEBUG0(MAKE, ".USE node..."); 271*b0c40a00SSimon J. Gerraty oodate = false; 272e2eeea75SSimon J. Gerraty } else if ((gn->type & OP_LIB) && (gn->mtime == 0 || Arch_IsLib(gn))) { 273956e45f6SSimon J. Gerraty DEBUG0(MAKE, "library..."); 2743955d011SMarcel Moolenaar 2753955d011SMarcel Moolenaar /* 2763955d011SMarcel Moolenaar * always out of date if no children and :: target 27706b9b3e0SSimon J. Gerraty * or nonexistent. 2783955d011SMarcel Moolenaar */ 2793955d011SMarcel Moolenaar oodate = (gn->mtime == 0 || Arch_LibOODate(gn) || 28006b9b3e0SSimon J. Gerraty (gn->youngestChild == NULL && 28106b9b3e0SSimon J. Gerraty (gn->type & OP_DOUBLEDEP))); 2823955d011SMarcel Moolenaar } else if (gn->type & OP_JOIN) { 2833955d011SMarcel Moolenaar /* 2843955d011SMarcel Moolenaar * A target with the .JOIN attribute is only considered 2853955d011SMarcel Moolenaar * out-of-date if any of its children was out-of-date. 2863955d011SMarcel Moolenaar */ 287956e45f6SSimon J. Gerraty DEBUG0(MAKE, ".JOIN node..."); 28806b9b3e0SSimon J. Gerraty DEBUG1(MAKE, "source %smade...", 28906b9b3e0SSimon J. Gerraty gn->flags & CHILDMADE ? "" : "not "); 290e2eeea75SSimon J. Gerraty oodate = (gn->flags & CHILDMADE) != 0; 2913955d011SMarcel Moolenaar } else if (gn->type & (OP_FORCE | OP_EXEC | OP_PHONY)) { 2923955d011SMarcel Moolenaar /* 29306b9b3e0SSimon J. Gerraty * A node which is the object of the force (!) operator or 29406b9b3e0SSimon J. Gerraty * which has the .EXEC attribute is always considered 29506b9b3e0SSimon J. Gerraty * out-of-date. 2963955d011SMarcel Moolenaar */ 2973955d011SMarcel Moolenaar if (DEBUG(MAKE)) { 2983955d011SMarcel Moolenaar if (gn->type & OP_FORCE) { 299956e45f6SSimon J. Gerraty debug_printf("! operator..."); 3003955d011SMarcel Moolenaar } else if (gn->type & OP_PHONY) { 301956e45f6SSimon J. Gerraty debug_printf(".PHONY node..."); 3023955d011SMarcel Moolenaar } else { 303956e45f6SSimon J. Gerraty debug_printf(".EXEC node..."); 3043955d011SMarcel Moolenaar } 3053955d011SMarcel Moolenaar } 306*b0c40a00SSimon J. Gerraty oodate = true; 307e2eeea75SSimon J. Gerraty } else if (IsOODateRegular(gn)) { 308*b0c40a00SSimon J. Gerraty oodate = true; 3093955d011SMarcel Moolenaar } else { 3103955d011SMarcel Moolenaar /* 31106b9b3e0SSimon J. Gerraty * When a nonexistent child with no sources 3123955d011SMarcel Moolenaar * (such as a typically used FORCE source) has been made and 3133955d011SMarcel Moolenaar * the target of the child (usually a directory) has the same 31406b9b3e0SSimon J. Gerraty * timestamp as the timestamp just given to the nonexistent 31506b9b3e0SSimon J. Gerraty * child after it was considered made. 3163955d011SMarcel Moolenaar */ 3173955d011SMarcel Moolenaar if (DEBUG(MAKE)) { 3183955d011SMarcel Moolenaar if (gn->flags & FORCE) 319956e45f6SSimon J. Gerraty debug_printf("non existing child..."); 3203955d011SMarcel Moolenaar } 321e2eeea75SSimon J. Gerraty oodate = (gn->flags & FORCE) != 0; 3223955d011SMarcel Moolenaar } 3233955d011SMarcel Moolenaar 3243955d011SMarcel Moolenaar #ifdef USE_META 3253955d011SMarcel Moolenaar if (useMeta) { 3263955d011SMarcel Moolenaar oodate = meta_oodate(gn, oodate); 3273955d011SMarcel Moolenaar } 3283955d011SMarcel Moolenaar #endif 3293955d011SMarcel Moolenaar 3303955d011SMarcel Moolenaar /* 3313955d011SMarcel Moolenaar * If the target isn't out-of-date, the parents need to know its 3323955d011SMarcel Moolenaar * modification time. Note that targets that appear to be out-of-date 333956e45f6SSimon J. Gerraty * but aren't, because they have no commands and are GNode_IsTarget, 33406b9b3e0SSimon J. Gerraty * have their mtime stay below their children's mtime to keep parents 33506b9b3e0SSimon J. Gerraty * from thinking they're out-of-date. 3363955d011SMarcel Moolenaar */ 3373955d011SMarcel Moolenaar if (!oodate) { 338956e45f6SSimon J. Gerraty GNodeListNode *ln; 33906b9b3e0SSimon J. Gerraty for (ln = gn->parents.first; ln != NULL; ln = ln->next) 340e2eeea75SSimon J. Gerraty GNode_UpdateYoungestChild(ln->datum, gn); 3413955d011SMarcel Moolenaar } 3423955d011SMarcel Moolenaar 3433841c287SSimon J. Gerraty return oodate; 3443955d011SMarcel Moolenaar } 3452c3632d1SSimon J. Gerraty 346e2eeea75SSimon J. Gerraty static void 347e2eeea75SSimon J. Gerraty PretendAllChildrenAreMade(GNode *pgn) 3483955d011SMarcel Moolenaar { 349e2eeea75SSimon J. Gerraty GNodeListNode *ln; 3503955d011SMarcel Moolenaar 35106b9b3e0SSimon J. Gerraty for (ln = pgn->children.first; ln != NULL; ln = ln->next) { 352e2eeea75SSimon J. Gerraty GNode *cgn = ln->datum; 3532c3632d1SSimon J. Gerraty 35406b9b3e0SSimon J. Gerraty /* This may also update cgn->path. */ 355*b0c40a00SSimon J. Gerraty Dir_UpdateMTime(cgn, false); 356e2eeea75SSimon J. Gerraty GNode_UpdateYoungestChild(pgn, cgn); 3573955d011SMarcel Moolenaar pgn->unmade--; 358e2eeea75SSimon J. Gerraty } 3593955d011SMarcel Moolenaar } 3602c3632d1SSimon J. Gerraty 36106b9b3e0SSimon J. Gerraty /* 36206b9b3e0SSimon J. Gerraty * Called by Make_Run and SuffApplyTransform on the downward pass to handle 3632c3632d1SSimon J. Gerraty * .USE and transformation nodes, by copying the child node's commands, type 3642c3632d1SSimon J. Gerraty * flags and children to the parent node. 3653955d011SMarcel Moolenaar * 3662c3632d1SSimon J. Gerraty * A .USE node is much like an explicit transformation rule, except its 3672c3632d1SSimon J. Gerraty * commands are always added to the target node, even if the target already 3682c3632d1SSimon J. Gerraty * has commands. 3693955d011SMarcel Moolenaar * 3703955d011SMarcel Moolenaar * Input: 371956e45f6SSimon J. Gerraty * cgn The source node, which is either a .USE/.USEBEFORE 372956e45f6SSimon J. Gerraty * node or a transformation node (OP_TRANSFORM). 373956e45f6SSimon J. Gerraty * pgn The target node 3743955d011SMarcel Moolenaar */ 3753955d011SMarcel Moolenaar void 3763955d011SMarcel Moolenaar Make_HandleUse(GNode *cgn, GNode *pgn) 3773955d011SMarcel Moolenaar { 378956e45f6SSimon J. Gerraty GNodeListNode *ln; /* An element in the children list */ 3793955d011SMarcel Moolenaar 3803955d011SMarcel Moolenaar #ifdef DEBUG_SRC 381e2eeea75SSimon J. Gerraty if (!(cgn->type & (OP_USE | OP_USEBEFORE | OP_TRANSFORM))) { 38206b9b3e0SSimon J. Gerraty debug_printf("Make_HandleUse: called for plain node %s\n", 38306b9b3e0SSimon J. Gerraty cgn->name); 38406b9b3e0SSimon J. Gerraty /* XXX: debug mode should not affect control flow */ 38506b9b3e0SSimon J. Gerraty return; 3863955d011SMarcel Moolenaar } 3873955d011SMarcel Moolenaar #endif 3883955d011SMarcel Moolenaar 38906b9b3e0SSimon J. Gerraty if ((cgn->type & (OP_USE | OP_USEBEFORE)) || 39006b9b3e0SSimon J. Gerraty Lst_IsEmpty(&pgn->commands)) { 3913955d011SMarcel Moolenaar if (cgn->type & OP_USEBEFORE) { 3922c3632d1SSimon J. Gerraty /* .USEBEFORE */ 39306b9b3e0SSimon J. Gerraty Lst_PrependAll(&pgn->commands, &cgn->commands); 3943955d011SMarcel Moolenaar } else { 3952c3632d1SSimon J. Gerraty /* .USE, or target has no commands */ 39606b9b3e0SSimon J. Gerraty Lst_AppendAll(&pgn->commands, &cgn->commands); 3973955d011SMarcel Moolenaar } 3983955d011SMarcel Moolenaar } 3993955d011SMarcel Moolenaar 40006b9b3e0SSimon J. Gerraty for (ln = cgn->children.first; ln != NULL; ln = ln->next) { 401956e45f6SSimon J. Gerraty GNode *gn = ln->datum; 4023955d011SMarcel Moolenaar 4033955d011SMarcel Moolenaar /* 4043955d011SMarcel Moolenaar * Expand variables in the .USE node's name 4053955d011SMarcel Moolenaar * and save the unexpanded form. 4063955d011SMarcel Moolenaar * We don't need to do this for commands. 4073955d011SMarcel Moolenaar * They get expanded properly when we execute. 4083955d011SMarcel Moolenaar */ 4093955d011SMarcel Moolenaar if (gn->uname == NULL) { 4103955d011SMarcel Moolenaar gn->uname = gn->name; 4113955d011SMarcel Moolenaar } else { 4123955d011SMarcel Moolenaar free(gn->name); 4133955d011SMarcel Moolenaar } 414956e45f6SSimon J. Gerraty (void)Var_Subst(gn->uname, pgn, VARE_WANTRES, &gn->name); 415956e45f6SSimon J. Gerraty /* TODO: handle errors */ 41606b9b3e0SSimon J. Gerraty if (gn->uname != NULL && strcmp(gn->name, gn->uname) != 0) { 4173955d011SMarcel Moolenaar /* See if we have a target for this node. */ 418956e45f6SSimon J. Gerraty GNode *tgn = Targ_FindNode(gn->name); 4193955d011SMarcel Moolenaar if (tgn != NULL) 4203955d011SMarcel Moolenaar gn = tgn; 4213955d011SMarcel Moolenaar } 4223955d011SMarcel Moolenaar 42306b9b3e0SSimon J. Gerraty Lst_Append(&pgn->children, gn); 42406b9b3e0SSimon J. Gerraty Lst_Append(&gn->parents, pgn); 425956e45f6SSimon J. Gerraty pgn->unmade++; 4263955d011SMarcel Moolenaar } 4273955d011SMarcel Moolenaar 42806b9b3e0SSimon J. Gerraty pgn->type |= 42906b9b3e0SSimon J. Gerraty cgn->type & ~(OP_OPMASK | OP_USE | OP_USEBEFORE | OP_TRANSFORM); 4303955d011SMarcel Moolenaar } 4313955d011SMarcel Moolenaar 43206b9b3e0SSimon J. Gerraty /* 43306b9b3e0SSimon J. Gerraty * Used by Make_Run on the downward pass to handle .USE nodes. Should be 434956e45f6SSimon J. Gerraty * called before the children are enqueued to be looked at by MakeAddChild. 435956e45f6SSimon J. Gerraty * 436956e45f6SSimon J. Gerraty * For a .USE child, the commands, type flags and children are copied to the 437956e45f6SSimon J. Gerraty * parent node, and since the relation to the .USE node is then no longer 438956e45f6SSimon J. Gerraty * needed, that relation is removed. 4393955d011SMarcel Moolenaar * 4403955d011SMarcel Moolenaar * Input: 441956e45f6SSimon J. Gerraty * cgn the child, which may be a .USE node 442956e45f6SSimon J. Gerraty * pgn the current parent 4433955d011SMarcel Moolenaar */ 444956e45f6SSimon J. Gerraty static void 445956e45f6SSimon J. Gerraty MakeHandleUse(GNode *cgn, GNode *pgn, GNodeListNode *ln) 4463955d011SMarcel Moolenaar { 447*b0c40a00SSimon J. Gerraty bool unmarked; 4483955d011SMarcel Moolenaar 449e2eeea75SSimon J. Gerraty unmarked = !(cgn->type & OP_MARK); 4503955d011SMarcel Moolenaar cgn->type |= OP_MARK; 4513955d011SMarcel Moolenaar 452e2eeea75SSimon J. Gerraty if (!(cgn->type & (OP_USE | OP_USEBEFORE))) 453956e45f6SSimon J. Gerraty return; 4543955d011SMarcel Moolenaar 4553955d011SMarcel Moolenaar if (unmarked) 4563955d011SMarcel Moolenaar Make_HandleUse(cgn, pgn); 4573955d011SMarcel Moolenaar 4583955d011SMarcel Moolenaar /* 4593955d011SMarcel Moolenaar * This child node is now "made", so we decrement the count of 4603955d011SMarcel Moolenaar * unmade children in the parent... We also remove the child 4613955d011SMarcel Moolenaar * from the parent's list to accurately reflect the number of decent 4623955d011SMarcel Moolenaar * children the parent has. This is used by Make_Run to decide 4633955d011SMarcel Moolenaar * whether to queue the parent or examine its children... 4643955d011SMarcel Moolenaar */ 46506b9b3e0SSimon J. Gerraty Lst_Remove(&pgn->children, ln); 4663955d011SMarcel Moolenaar pgn->unmade--; 4673955d011SMarcel Moolenaar } 468956e45f6SSimon J. Gerraty 469956e45f6SSimon J. Gerraty static void 470956e45f6SSimon J. Gerraty HandleUseNodes(GNode *gn) 471956e45f6SSimon J. Gerraty { 472956e45f6SSimon J. Gerraty GNodeListNode *ln, *nln; 47306b9b3e0SSimon J. Gerraty for (ln = gn->children.first; ln != NULL; ln = nln) { 474956e45f6SSimon J. Gerraty nln = ln->next; 475956e45f6SSimon J. Gerraty MakeHandleUse(ln->datum, gn, ln); 476956e45f6SSimon J. Gerraty } 4773955d011SMarcel Moolenaar } 4783955d011SMarcel Moolenaar 4793955d011SMarcel Moolenaar 48006b9b3e0SSimon J. Gerraty /* 48106b9b3e0SSimon J. Gerraty * Check the modification time of a gnode, and update it if necessary. 48206b9b3e0SSimon J. Gerraty * Return 0 if the gnode does not exist, or its filesystem time if it does. 48306b9b3e0SSimon J. Gerraty */ 4843955d011SMarcel Moolenaar time_t 4853955d011SMarcel Moolenaar Make_Recheck(GNode *gn) 4863955d011SMarcel Moolenaar { 487e2eeea75SSimon J. Gerraty time_t mtime; 488e2eeea75SSimon J. Gerraty 489*b0c40a00SSimon J. Gerraty Dir_UpdateMTime(gn, true); 490e2eeea75SSimon J. Gerraty mtime = gn->mtime; 4913955d011SMarcel Moolenaar 4923955d011SMarcel Moolenaar #ifndef RECHECK 4933955d011SMarcel Moolenaar /* 4943955d011SMarcel Moolenaar * We can't re-stat the thing, but we can at least take care of rules 4953955d011SMarcel Moolenaar * where a target depends on a source that actually creates the 4963955d011SMarcel Moolenaar * target, but only if it has changed, e.g. 4973955d011SMarcel Moolenaar * 4983955d011SMarcel Moolenaar * parse.h : parse.o 4993955d011SMarcel Moolenaar * 5003955d011SMarcel Moolenaar * parse.o : parse.y 5013955d011SMarcel Moolenaar * yacc -d parse.y 5023955d011SMarcel Moolenaar * cc -c y.tab.c 5033955d011SMarcel Moolenaar * mv y.tab.o parse.o 5043955d011SMarcel Moolenaar * cmp -s y.tab.h parse.h || mv y.tab.h parse.h 5053955d011SMarcel Moolenaar * 5063955d011SMarcel Moolenaar * In this case, if the definitions produced by yacc haven't changed 5073955d011SMarcel Moolenaar * from before, parse.h won't have been updated and gn->mtime will 5083955d011SMarcel Moolenaar * reflect the current modification time for parse.h. This is 509e2eeea75SSimon J. Gerraty * something of a kludge, I admit, but it's a useful one. 5103955d011SMarcel Moolenaar * 511e2eeea75SSimon J. Gerraty * XXX: People like to use a rule like "FRC:" to force things that 512e2eeea75SSimon J. Gerraty * depend on FRC to be made, so we have to check for gn->children 513e2eeea75SSimon J. Gerraty * being empty as well. 5143955d011SMarcel Moolenaar */ 5153955d011SMarcel Moolenaar if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) { 5163955d011SMarcel Moolenaar gn->mtime = now; 5173955d011SMarcel Moolenaar } 5183955d011SMarcel Moolenaar #else 5193955d011SMarcel Moolenaar /* 5203955d011SMarcel Moolenaar * This is what Make does and it's actually a good thing, as it 5213955d011SMarcel Moolenaar * allows rules like 5223955d011SMarcel Moolenaar * 5233955d011SMarcel Moolenaar * cmp -s y.tab.h parse.h || cp y.tab.h parse.h 5243955d011SMarcel Moolenaar * 5253955d011SMarcel Moolenaar * to function as intended. Unfortunately, thanks to the stateless 5263955d011SMarcel Moolenaar * nature of NFS (by which I mean the loose coupling of two clients 52706b9b3e0SSimon J. Gerraty * using the same file from a common server), there are times when 52806b9b3e0SSimon J. Gerraty * the modification time of a file created on a remote machine 52906b9b3e0SSimon J. Gerraty * will not be modified before the local stat() implied by the 53006b9b3e0SSimon J. Gerraty * Dir_UpdateMTime occurs, thus leading us to believe that the file 5313955d011SMarcel Moolenaar * is unchanged, wreaking havoc with files that depend on this one. 5323955d011SMarcel Moolenaar * 5333955d011SMarcel Moolenaar * I have decided it is better to make too much than to make too 5343955d011SMarcel Moolenaar * little, so this stuff is commented out unless you're sure it's ok. 5353955d011SMarcel Moolenaar * -- ardeb 1/12/88 5363955d011SMarcel Moolenaar */ 5373955d011SMarcel Moolenaar /* 538e2eeea75SSimon J. Gerraty * Christos, 4/9/92: If we are saving commands, pretend that 539e2eeea75SSimon J. Gerraty * the target is made now. Otherwise archives with '...' rules 5403955d011SMarcel Moolenaar * don't work! 5413955d011SMarcel Moolenaar */ 542956e45f6SSimon J. Gerraty if (!GNode_ShouldExecute(gn) || (gn->type & OP_SAVE_CMDS) || 5433955d011SMarcel Moolenaar (mtime == 0 && !(gn->type & OP_WAIT))) { 544956e45f6SSimon J. Gerraty DEBUG2(MAKE, " recheck(%s): update time from %s to now\n", 54506b9b3e0SSimon J. Gerraty gn->name, 54606b9b3e0SSimon J. Gerraty gn->mtime == 0 ? "nonexistent" : Targ_FmtTime(gn->mtime)); 5473955d011SMarcel Moolenaar gn->mtime = now; 548e2eeea75SSimon J. Gerraty } else { 549956e45f6SSimon J. Gerraty DEBUG2(MAKE, " recheck(%s): current update time: %s\n", 5503955d011SMarcel Moolenaar gn->name, Targ_FmtTime(gn->mtime)); 5513955d011SMarcel Moolenaar } 5523955d011SMarcel Moolenaar #endif 553e2eeea75SSimon J. Gerraty 554e2eeea75SSimon J. Gerraty /* XXX: The returned mtime may differ from gn->mtime. 555e2eeea75SSimon J. Gerraty * Intentionally? */ 5563955d011SMarcel Moolenaar return mtime; 5573955d011SMarcel Moolenaar } 5583955d011SMarcel Moolenaar 559956e45f6SSimon J. Gerraty /* 560956e45f6SSimon J. Gerraty * Set the .PREFIX and .IMPSRC variables for all the implied parents 561956e45f6SSimon J. Gerraty * of this node. 562956e45f6SSimon J. Gerraty */ 563956e45f6SSimon J. Gerraty static void 564956e45f6SSimon J. Gerraty UpdateImplicitParentsVars(GNode *cgn, const char *cname) 565956e45f6SSimon J. Gerraty { 566956e45f6SSimon J. Gerraty GNodeListNode *ln; 567956e45f6SSimon J. Gerraty const char *cpref = GNode_VarPrefix(cgn); 568956e45f6SSimon J. Gerraty 56906b9b3e0SSimon J. Gerraty for (ln = cgn->implicitParents.first; ln != NULL; ln = ln->next) { 570956e45f6SSimon J. Gerraty GNode *pgn = ln->datum; 571956e45f6SSimon J. Gerraty if (pgn->flags & REMAKE) { 572dba7b0efSSimon J. Gerraty Var_Set(pgn, IMPSRC, cname); 573956e45f6SSimon J. Gerraty if (cpref != NULL) 574dba7b0efSSimon J. Gerraty Var_Set(pgn, PREFIX, cpref); 575956e45f6SSimon J. Gerraty } 576956e45f6SSimon J. Gerraty } 577956e45f6SSimon J. Gerraty } 578956e45f6SSimon J. Gerraty 579e2eeea75SSimon J. Gerraty /* See if a .ORDER rule stops us from building this node. */ 580*b0c40a00SSimon J. Gerraty static bool 581e2eeea75SSimon J. Gerraty IsWaitingForOrder(GNode *gn) 582e2eeea75SSimon J. Gerraty { 583e2eeea75SSimon J. Gerraty GNodeListNode *ln; 584e2eeea75SSimon J. Gerraty 58506b9b3e0SSimon J. Gerraty for (ln = gn->order_pred.first; ln != NULL; ln = ln->next) { 586e2eeea75SSimon J. Gerraty GNode *ogn = ln->datum; 587e2eeea75SSimon J. Gerraty 58806b9b3e0SSimon J. Gerraty if (GNode_IsDone(ogn) || !(ogn->flags & REMAKE)) 589e2eeea75SSimon J. Gerraty continue; 590e2eeea75SSimon J. Gerraty 59106b9b3e0SSimon J. Gerraty DEBUG2(MAKE, 59206b9b3e0SSimon J. Gerraty "IsWaitingForOrder: Waiting for .ORDER node \"%s%s\"\n", 593e2eeea75SSimon J. Gerraty ogn->name, ogn->cohort_num); 594*b0c40a00SSimon J. Gerraty return true; 595e2eeea75SSimon J. Gerraty } 596*b0c40a00SSimon J. Gerraty return false; 597e2eeea75SSimon J. Gerraty } 598e2eeea75SSimon J. Gerraty 599dba7b0efSSimon J. Gerraty static void MakeBuildParent(GNode *, GNodeListNode *); 60006b9b3e0SSimon J. Gerraty 60106b9b3e0SSimon J. Gerraty static void 60206b9b3e0SSimon J. Gerraty ScheduleOrderSuccessors(GNode *gn) 60306b9b3e0SSimon J. Gerraty { 60406b9b3e0SSimon J. Gerraty GNodeListNode *toBeMadeNext = toBeMade.first; 60506b9b3e0SSimon J. Gerraty GNodeListNode *ln; 60606b9b3e0SSimon J. Gerraty 60706b9b3e0SSimon J. Gerraty for (ln = gn->order_succ.first; ln != NULL; ln = ln->next) 608dba7b0efSSimon J. Gerraty MakeBuildParent(ln->datum, toBeMadeNext); 60906b9b3e0SSimon J. Gerraty } 61006b9b3e0SSimon J. Gerraty 61106b9b3e0SSimon J. Gerraty /* 61206b9b3e0SSimon J. Gerraty * Perform update on the parents of a node. Used by JobFinish once 6133955d011SMarcel Moolenaar * a node has been dealt with and by MakeStartJobs if it finds an 6143955d011SMarcel Moolenaar * up-to-date node. 6153955d011SMarcel Moolenaar * 6163955d011SMarcel Moolenaar * The unmade field of pgn is decremented and pgn may be placed on 6173955d011SMarcel Moolenaar * the toBeMade queue if this field becomes 0. 6183955d011SMarcel Moolenaar * 6193955d011SMarcel Moolenaar * If the child was made, the parent's flag CHILDMADE field will be 6203955d011SMarcel Moolenaar * set true. 6213955d011SMarcel Moolenaar * 6223955d011SMarcel Moolenaar * If the child is not up-to-date and still does not exist, 6233955d011SMarcel Moolenaar * set the FORCE flag on the parents. 6243955d011SMarcel Moolenaar * 625956e45f6SSimon J. Gerraty * If the child wasn't made, the youngestChild field of the parent will be 6263955d011SMarcel Moolenaar * altered if the child's mtime is big enough. 6273955d011SMarcel Moolenaar * 6283955d011SMarcel Moolenaar * Finally, if the child is the implied source for the parent, the 6293955d011SMarcel Moolenaar * parent's IMPSRC variable is set appropriately. 6303955d011SMarcel Moolenaar */ 6313955d011SMarcel Moolenaar void 6323955d011SMarcel Moolenaar Make_Update(GNode *cgn) 6333955d011SMarcel Moolenaar { 6342c3632d1SSimon J. Gerraty const char *cname; /* the child's name */ 6353955d011SMarcel Moolenaar time_t mtime = -1; 636956e45f6SSimon J. Gerraty GNodeList *parents; 637956e45f6SSimon J. Gerraty GNodeListNode *ln; 6383955d011SMarcel Moolenaar GNode *centurion; 6393955d011SMarcel Moolenaar 6403955d011SMarcel Moolenaar /* It is save to re-examine any nodes again */ 641e2eeea75SSimon J. Gerraty checked_seqno++; 6423955d011SMarcel Moolenaar 643956e45f6SSimon J. Gerraty cname = GNode_VarTarget(cgn); 6443955d011SMarcel Moolenaar 645956e45f6SSimon J. Gerraty DEBUG2(MAKE, "Make_Update: %s%s\n", cgn->name, cgn->cohort_num); 6463955d011SMarcel Moolenaar 6473955d011SMarcel Moolenaar /* 6483955d011SMarcel Moolenaar * If the child was actually made, see what its modification time is 64906b9b3e0SSimon J. Gerraty * now -- some rules won't actually update the file. If the file 65006b9b3e0SSimon J. Gerraty * still doesn't exist, make its mtime now. 6513955d011SMarcel Moolenaar */ 6523955d011SMarcel Moolenaar if (cgn->made != UPTODATE) { 6533955d011SMarcel Moolenaar mtime = Make_Recheck(cgn); 6543955d011SMarcel Moolenaar } 6553955d011SMarcel Moolenaar 6563955d011SMarcel Moolenaar /* 6573955d011SMarcel Moolenaar * If this is a `::' node, we must consult its first instance 6583955d011SMarcel Moolenaar * which is where all parents are linked. 6593955d011SMarcel Moolenaar */ 6603955d011SMarcel Moolenaar if ((centurion = cgn->centurion) != NULL) { 66106b9b3e0SSimon J. Gerraty if (!Lst_IsEmpty(&cgn->parents)) 66206b9b3e0SSimon J. Gerraty Punt("%s%s: cohort has parents", cgn->name, 66306b9b3e0SSimon J. Gerraty cgn->cohort_num); 664956e45f6SSimon J. Gerraty centurion->unmade_cohorts--; 6653955d011SMarcel Moolenaar if (centurion->unmade_cohorts < 0) 66606b9b3e0SSimon J. Gerraty Error("Graph cycles through centurion %s", 66706b9b3e0SSimon J. Gerraty centurion->name); 6683955d011SMarcel Moolenaar } else { 6693955d011SMarcel Moolenaar centurion = cgn; 6703955d011SMarcel Moolenaar } 67106b9b3e0SSimon J. Gerraty parents = ¢urion->parents; 6723955d011SMarcel Moolenaar 6733955d011SMarcel Moolenaar /* If this was a .ORDER node, schedule the RHS */ 67406b9b3e0SSimon J. Gerraty ScheduleOrderSuccessors(centurion); 6753955d011SMarcel Moolenaar 6763955d011SMarcel Moolenaar /* Now mark all the parents as having one less unmade child */ 677956e45f6SSimon J. Gerraty for (ln = parents->first; ln != NULL; ln = ln->next) { 678956e45f6SSimon J. Gerraty GNode *pgn = ln->datum; 679956e45f6SSimon J. Gerraty 680e2eeea75SSimon J. Gerraty if (DEBUG(MAKE)) { 68106b9b3e0SSimon J. Gerraty debug_printf("inspect parent %s%s: ", pgn->name, 68206b9b3e0SSimon J. Gerraty pgn->cohort_num); 683e2eeea75SSimon J. Gerraty GNode_FprintDetails(opts.debug_file, "", pgn, ""); 684e2eeea75SSimon J. Gerraty debug_printf(", unmade %d ", pgn->unmade - 1); 685e2eeea75SSimon J. Gerraty } 6863955d011SMarcel Moolenaar 6873955d011SMarcel Moolenaar if (!(pgn->flags & REMAKE)) { 6883955d011SMarcel Moolenaar /* This parent isn't needed */ 689956e45f6SSimon J. Gerraty DEBUG0(MAKE, "- not needed\n"); 6903955d011SMarcel Moolenaar continue; 6913955d011SMarcel Moolenaar } 6923955d011SMarcel Moolenaar if (mtime == 0 && !(cgn->type & OP_WAIT)) 6933955d011SMarcel Moolenaar pgn->flags |= FORCE; 6943955d011SMarcel Moolenaar 6953955d011SMarcel Moolenaar /* 6963955d011SMarcel Moolenaar * If the parent has the .MADE attribute, its timestamp got 697956e45f6SSimon J. Gerraty * updated to that of its newest child, and its unmade 6983955d011SMarcel Moolenaar * child count got set to zero in Make_ExpandUse(). 6993955d011SMarcel Moolenaar * However other things might cause us to build one of its 7003955d011SMarcel Moolenaar * children - and so we mustn't do any processing here when 7013955d011SMarcel Moolenaar * the child build finishes. 7023955d011SMarcel Moolenaar */ 7033955d011SMarcel Moolenaar if (pgn->type & OP_MADE) { 704956e45f6SSimon J. Gerraty DEBUG0(MAKE, "- .MADE\n"); 7053955d011SMarcel Moolenaar continue; 7063955d011SMarcel Moolenaar } 7073955d011SMarcel Moolenaar 7083955d011SMarcel Moolenaar if (!(cgn->type & (OP_EXEC | OP_USE | OP_USEBEFORE))) { 7093955d011SMarcel Moolenaar if (cgn->made == MADE) 7103955d011SMarcel Moolenaar pgn->flags |= CHILDMADE; 711e2eeea75SSimon J. Gerraty GNode_UpdateYoungestChild(pgn, cgn); 7123955d011SMarcel Moolenaar } 7133955d011SMarcel Moolenaar 7143955d011SMarcel Moolenaar /* 7153955d011SMarcel Moolenaar * A parent must wait for the completion of all instances 7163955d011SMarcel Moolenaar * of a `::' dependency. 7173955d011SMarcel Moolenaar */ 71806b9b3e0SSimon J. Gerraty if (centurion->unmade_cohorts != 0 || 71906b9b3e0SSimon J. Gerraty !GNode_IsDone(centurion)) { 72006b9b3e0SSimon J. Gerraty DEBUG2(MAKE, 72106b9b3e0SSimon J. Gerraty "- centurion made %d, %d unmade cohorts\n", 7223955d011SMarcel Moolenaar centurion->made, centurion->unmade_cohorts); 7233955d011SMarcel Moolenaar continue; 7243955d011SMarcel Moolenaar } 7253955d011SMarcel Moolenaar 7263955d011SMarcel Moolenaar /* One more child of this parent is now made */ 727956e45f6SSimon J. Gerraty pgn->unmade--; 7283955d011SMarcel Moolenaar if (pgn->unmade < 0) { 7293955d011SMarcel Moolenaar if (DEBUG(MAKE)) { 730956e45f6SSimon J. Gerraty debug_printf("Graph cycles through %s%s\n", 7313955d011SMarcel Moolenaar pgn->name, pgn->cohort_num); 7323955d011SMarcel Moolenaar Targ_PrintGraph(2); 7333955d011SMarcel Moolenaar } 73406b9b3e0SSimon J. Gerraty Error("Graph cycles through %s%s", pgn->name, 73506b9b3e0SSimon J. Gerraty pgn->cohort_num); 7363955d011SMarcel Moolenaar } 7373955d011SMarcel Moolenaar 73806b9b3e0SSimon J. Gerraty /* 73906b9b3e0SSimon J. Gerraty * We must always rescan the parents of .WAIT and .ORDER 74006b9b3e0SSimon J. Gerraty * nodes. 74106b9b3e0SSimon J. Gerraty */ 7423955d011SMarcel Moolenaar if (pgn->unmade != 0 && !(centurion->type & OP_WAIT) 7433955d011SMarcel Moolenaar && !(centurion->flags & DONE_ORDER)) { 744956e45f6SSimon J. Gerraty DEBUG0(MAKE, "- unmade children\n"); 7453955d011SMarcel Moolenaar continue; 7463955d011SMarcel Moolenaar } 7473955d011SMarcel Moolenaar if (pgn->made != DEFERRED) { 7483955d011SMarcel Moolenaar /* 74906b9b3e0SSimon J. Gerraty * Either this parent is on a different branch of 75006b9b3e0SSimon J. Gerraty * the tree, or it on the RHS of a .WAIT directive 7513955d011SMarcel Moolenaar * or it is already on the toBeMade list. 7523955d011SMarcel Moolenaar */ 753956e45f6SSimon J. Gerraty DEBUG0(MAKE, "- not deferred\n"); 7543955d011SMarcel Moolenaar continue; 7553955d011SMarcel Moolenaar } 756e2eeea75SSimon J. Gerraty 757e2eeea75SSimon J. Gerraty if (IsWaitingForOrder(pgn)) 7583955d011SMarcel Moolenaar continue; 759e2eeea75SSimon J. Gerraty 7603955d011SMarcel Moolenaar if (DEBUG(MAKE)) { 761956e45f6SSimon J. Gerraty debug_printf("- %s%s made, schedule %s%s (made %d)\n", 7623955d011SMarcel Moolenaar cgn->name, cgn->cohort_num, 7633955d011SMarcel Moolenaar pgn->name, pgn->cohort_num, pgn->made); 764956e45f6SSimon J. Gerraty Targ_PrintNode(pgn, 2); 7653955d011SMarcel Moolenaar } 7663955d011SMarcel Moolenaar /* Ok, we can schedule the parent again */ 7673955d011SMarcel Moolenaar pgn->made = REQUESTED; 76806b9b3e0SSimon J. Gerraty Lst_Enqueue(&toBeMade, pgn); 7693955d011SMarcel Moolenaar } 7703955d011SMarcel Moolenaar 771956e45f6SSimon J. Gerraty UpdateImplicitParentsVars(cgn, cname); 772956e45f6SSimon J. Gerraty } 773956e45f6SSimon J. Gerraty 774956e45f6SSimon J. Gerraty static void 775956e45f6SSimon J. Gerraty UnmarkChildren(GNode *gn) 7762c3632d1SSimon J. Gerraty { 777956e45f6SSimon J. Gerraty GNodeListNode *ln; 7783955d011SMarcel Moolenaar 77906b9b3e0SSimon J. Gerraty for (ln = gn->children.first; ln != NULL; ln = ln->next) { 780956e45f6SSimon J. Gerraty GNode *child = ln->datum; 781956e45f6SSimon J. Gerraty child->type &= ~OP_MARK; 7823955d011SMarcel Moolenaar } 7833955d011SMarcel Moolenaar } 7842c3632d1SSimon J. Gerraty 78506b9b3e0SSimon J. Gerraty /* 78606b9b3e0SSimon J. Gerraty * Add a child's name to the ALLSRC and OODATE variables of the given 787956e45f6SSimon J. Gerraty * node, but only if it has not been given the .EXEC, .USE or .INVISIBLE 788956e45f6SSimon J. Gerraty * attributes. .EXEC and .USE children are very rarely going to be files, 789956e45f6SSimon J. Gerraty * so... 790956e45f6SSimon J. Gerraty * 7913955d011SMarcel Moolenaar * If the child is a .JOIN node, its ALLSRC is propagated to the parent. 7923955d011SMarcel Moolenaar * 7933955d011SMarcel Moolenaar * A child is added to the OODATE variable if its modification time is 7943955d011SMarcel Moolenaar * later than that of its parent, as defined by Make, except if the 7953955d011SMarcel Moolenaar * parent is a .JOIN node. In that case, it is only added to the OODATE 7963955d011SMarcel Moolenaar * variable if it was actually made (since .JOIN nodes don't have 7973955d011SMarcel Moolenaar * modification times, the comparison is rather unfair...).. 7983955d011SMarcel Moolenaar * 7993955d011SMarcel Moolenaar * Input: 800956e45f6SSimon J. Gerraty * cgn The child to add 801956e45f6SSimon J. Gerraty * pgn The parent to whose ALLSRC variable it should 8023955d011SMarcel Moolenaar * be added 8033955d011SMarcel Moolenaar */ 804956e45f6SSimon J. Gerraty static void 805956e45f6SSimon J. Gerraty MakeAddAllSrc(GNode *cgn, GNode *pgn) 8063955d011SMarcel Moolenaar { 807dba7b0efSSimon J. Gerraty const char *child, *allsrc; 808dba7b0efSSimon J. Gerraty 8093955d011SMarcel Moolenaar if (cgn->type & OP_MARK) 810956e45f6SSimon J. Gerraty return; 8113955d011SMarcel Moolenaar cgn->type |= OP_MARK; 8123955d011SMarcel Moolenaar 813dba7b0efSSimon J. Gerraty if (cgn->type & (OP_EXEC | OP_USE | OP_USEBEFORE | OP_INVISIBLE)) 814dba7b0efSSimon J. Gerraty return; 8153955d011SMarcel Moolenaar 8163955d011SMarcel Moolenaar if (cgn->type & OP_ARCHV) 817956e45f6SSimon J. Gerraty child = GNode_VarMember(cgn); 8183955d011SMarcel Moolenaar else 819956e45f6SSimon J. Gerraty child = GNode_Path(cgn); 820dba7b0efSSimon J. Gerraty 821dba7b0efSSimon J. Gerraty if (cgn->type & OP_JOIN) 822956e45f6SSimon J. Gerraty allsrc = GNode_VarAllsrc(cgn); 823dba7b0efSSimon J. Gerraty else 8243955d011SMarcel Moolenaar allsrc = child; 825dba7b0efSSimon J. Gerraty 8263955d011SMarcel Moolenaar if (allsrc != NULL) 827dba7b0efSSimon J. Gerraty Var_Append(pgn, ALLSRC, allsrc); 828dba7b0efSSimon J. Gerraty 8293955d011SMarcel Moolenaar if (pgn->type & OP_JOIN) { 830dba7b0efSSimon J. Gerraty if (cgn->made == MADE) 831dba7b0efSSimon J. Gerraty Var_Append(pgn, OODATE, child); 832dba7b0efSSimon J. Gerraty 8333955d011SMarcel Moolenaar } else if ((pgn->mtime < cgn->mtime) || 83406b9b3e0SSimon J. Gerraty (cgn->mtime >= now && cgn->made == MADE)) { 8353955d011SMarcel Moolenaar /* 83606b9b3e0SSimon J. Gerraty * It goes in the OODATE variable if the parent is 83706b9b3e0SSimon J. Gerraty * younger than the child or if the child has been 83806b9b3e0SSimon J. Gerraty * modified more recently than the start of the make. 83906b9b3e0SSimon J. Gerraty * This is to keep pmake from getting confused if 84006b9b3e0SSimon J. Gerraty * something else updates the parent after the make 84106b9b3e0SSimon J. Gerraty * starts (shouldn't happen, I know, but sometimes it 84206b9b3e0SSimon J. Gerraty * does). In such a case, if we've updated the child, 84306b9b3e0SSimon J. Gerraty * the parent is likely to have a modification time 84406b9b3e0SSimon J. Gerraty * later than that of the child and anything that 84506b9b3e0SSimon J. Gerraty * relies on the OODATE variable will be hosed. 8463955d011SMarcel Moolenaar * 84706b9b3e0SSimon J. Gerraty * XXX: This will cause all made children to go in 84806b9b3e0SSimon J. Gerraty * the OODATE variable, even if they're not touched, 84906b9b3e0SSimon J. Gerraty * if RECHECK isn't defined, since cgn->mtime is set 85006b9b3e0SSimon J. Gerraty * to now in Make_Update. According to some people, 85106b9b3e0SSimon J. Gerraty * this is good... 8523955d011SMarcel Moolenaar */ 853dba7b0efSSimon J. Gerraty Var_Append(pgn, OODATE, child); 8543955d011SMarcel Moolenaar } 8553955d011SMarcel Moolenaar } 8562c3632d1SSimon J. Gerraty 85706b9b3e0SSimon J. Gerraty /* 85806b9b3e0SSimon J. Gerraty * Set up the ALLSRC and OODATE variables. Sad to say, it must be 8593955d011SMarcel Moolenaar * done separately, rather than while traversing the graph. This is 8603955d011SMarcel Moolenaar * because Make defined OODATE to contain all sources whose modification 8613955d011SMarcel Moolenaar * times were later than that of the target, *not* those sources that 8623955d011SMarcel Moolenaar * were out-of-date. Since in both compatibility and native modes, 8633955d011SMarcel Moolenaar * the modification time of the parent isn't found until the child 8643955d011SMarcel Moolenaar * has been dealt with, we have to wait until now to fill in the 8653955d011SMarcel Moolenaar * variable. As for ALLSRC, the ordering is important and not 8663955d011SMarcel Moolenaar * guaranteed when in native mode, so it must be set here, too. 8673955d011SMarcel Moolenaar * 8683955d011SMarcel Moolenaar * If the node is a .JOIN node, its TARGET variable will be set to 8693955d011SMarcel Moolenaar * match its ALLSRC variable. 8703955d011SMarcel Moolenaar */ 8713955d011SMarcel Moolenaar void 872*b0c40a00SSimon J. Gerraty GNode_SetLocalVars(GNode *gn) 8733955d011SMarcel Moolenaar { 874956e45f6SSimon J. Gerraty GNodeListNode *ln; 875956e45f6SSimon J. Gerraty 8763955d011SMarcel Moolenaar if (gn->flags & DONE_ALLSRC) 8773955d011SMarcel Moolenaar return; 8783955d011SMarcel Moolenaar 879956e45f6SSimon J. Gerraty UnmarkChildren(gn); 88006b9b3e0SSimon J. Gerraty for (ln = gn->children.first; ln != NULL; ln = ln->next) 881956e45f6SSimon J. Gerraty MakeAddAllSrc(ln->datum, gn); 8823955d011SMarcel Moolenaar 883dba7b0efSSimon J. Gerraty if (!Var_Exists(gn, OODATE)) 884dba7b0efSSimon J. Gerraty Var_Set(gn, OODATE, ""); 885dba7b0efSSimon J. Gerraty if (!Var_Exists(gn, ALLSRC)) 886dba7b0efSSimon J. Gerraty Var_Set(gn, ALLSRC, ""); 8873955d011SMarcel Moolenaar 888956e45f6SSimon J. Gerraty if (gn->type & OP_JOIN) 889dba7b0efSSimon J. Gerraty Var_Set(gn, TARGET, GNode_VarAllsrc(gn)); 8903955d011SMarcel Moolenaar gn->flags |= DONE_ALLSRC; 8913955d011SMarcel Moolenaar } 8922c3632d1SSimon J. Gerraty 893*b0c40a00SSimon J. Gerraty static bool 89406b9b3e0SSimon J. Gerraty MakeBuildChild(GNode *cn, GNodeListNode *toBeMadeNext) 8953955d011SMarcel Moolenaar { 8963955d011SMarcel Moolenaar 897e2eeea75SSimon J. Gerraty if (DEBUG(MAKE)) { 898e2eeea75SSimon J. Gerraty debug_printf("MakeBuildChild: inspect %s%s, ", 899e2eeea75SSimon J. Gerraty cn->name, cn->cohort_num); 900e2eeea75SSimon J. Gerraty GNode_FprintDetails(opts.debug_file, "", cn, "\n"); 901e2eeea75SSimon J. Gerraty } 90206b9b3e0SSimon J. Gerraty if (GNode_IsReady(cn)) 903*b0c40a00SSimon J. Gerraty return false; 9043955d011SMarcel Moolenaar 9053955d011SMarcel Moolenaar /* If this node is on the RHS of a .ORDER, check LHSs. */ 906e2eeea75SSimon J. Gerraty if (IsWaitingForOrder(cn)) { 9073955d011SMarcel Moolenaar /* Can't build this (or anything else in this child list) yet */ 9083955d011SMarcel Moolenaar cn->made = DEFERRED; 909*b0c40a00SSimon J. Gerraty return false; /* but keep looking */ 9103955d011SMarcel Moolenaar } 9113955d011SMarcel Moolenaar 91206b9b3e0SSimon J. Gerraty DEBUG2(MAKE, "MakeBuildChild: schedule %s%s\n", 91306b9b3e0SSimon J. Gerraty cn->name, cn->cohort_num); 9143955d011SMarcel Moolenaar 9153955d011SMarcel Moolenaar cn->made = REQUESTED; 91606b9b3e0SSimon J. Gerraty if (toBeMadeNext == NULL) 91706b9b3e0SSimon J. Gerraty Lst_Append(&toBeMade, cn); 9183955d011SMarcel Moolenaar else 91906b9b3e0SSimon J. Gerraty Lst_InsertBefore(&toBeMade, toBeMadeNext, cn); 9203955d011SMarcel Moolenaar 92106b9b3e0SSimon J. Gerraty if (cn->unmade_cohorts != 0) { 92206b9b3e0SSimon J. Gerraty ListNode *ln; 92306b9b3e0SSimon J. Gerraty 92406b9b3e0SSimon J. Gerraty for (ln = cn->cohorts.first; ln != NULL; ln = ln->next) 925dba7b0efSSimon J. Gerraty if (MakeBuildChild(ln->datum, toBeMadeNext)) 92606b9b3e0SSimon J. Gerraty break; 92706b9b3e0SSimon J. Gerraty } 9283955d011SMarcel Moolenaar 9293955d011SMarcel Moolenaar /* 930956e45f6SSimon J. Gerraty * If this node is a .WAIT node with unmade children 9313955d011SMarcel Moolenaar * then don't add the next sibling. 9323955d011SMarcel Moolenaar */ 9333955d011SMarcel Moolenaar return cn->type & OP_WAIT && cn->unmade > 0; 9343955d011SMarcel Moolenaar } 9353955d011SMarcel Moolenaar 936e2eeea75SSimon J. Gerraty /* When a .ORDER LHS node completes, we do this on each RHS. */ 937dba7b0efSSimon J. Gerraty static void 93806b9b3e0SSimon J. Gerraty MakeBuildParent(GNode *pn, GNodeListNode *toBeMadeNext) 9393955d011SMarcel Moolenaar { 9403955d011SMarcel Moolenaar if (pn->made != DEFERRED) 941dba7b0efSSimon J. Gerraty return; 9423955d011SMarcel Moolenaar 943dba7b0efSSimon J. Gerraty if (!MakeBuildChild(pn, toBeMadeNext)) { 94406b9b3e0SSimon J. Gerraty /* When this node is built, reschedule its parents. */ 9453955d011SMarcel Moolenaar pn->flags |= DONE_ORDER; 9463955d011SMarcel Moolenaar } 9473955d011SMarcel Moolenaar } 9483955d011SMarcel Moolenaar 94906b9b3e0SSimon J. Gerraty static void 95006b9b3e0SSimon J. Gerraty MakeChildren(GNode *gn) 95106b9b3e0SSimon J. Gerraty { 95206b9b3e0SSimon J. Gerraty GNodeListNode *toBeMadeNext = toBeMade.first; 95306b9b3e0SSimon J. Gerraty GNodeListNode *ln; 95406b9b3e0SSimon J. Gerraty 95506b9b3e0SSimon J. Gerraty for (ln = gn->children.first; ln != NULL; ln = ln->next) 956dba7b0efSSimon J. Gerraty if (MakeBuildChild(ln->datum, toBeMadeNext)) 95706b9b3e0SSimon J. Gerraty break; 95806b9b3e0SSimon J. Gerraty } 95906b9b3e0SSimon J. Gerraty 96006b9b3e0SSimon J. Gerraty /* 96106b9b3e0SSimon J. Gerraty * Start as many jobs as possible, taking them from the toBeMade queue. 962956e45f6SSimon J. Gerraty * 963e2eeea75SSimon J. Gerraty * If the -q option was given, no job will be started, 964956e45f6SSimon J. Gerraty * but as soon as an out-of-date target is found, this function 965*b0c40a00SSimon J. Gerraty * returns true. In all other cases, this function returns false. 966956e45f6SSimon J. Gerraty */ 967*b0c40a00SSimon J. Gerraty static bool 9683955d011SMarcel Moolenaar MakeStartJobs(void) 9693955d011SMarcel Moolenaar { 9703955d011SMarcel Moolenaar GNode *gn; 971*b0c40a00SSimon J. Gerraty bool have_token = false; 9723955d011SMarcel Moolenaar 97306b9b3e0SSimon J. Gerraty while (!Lst_IsEmpty(&toBeMade)) { 97406b9b3e0SSimon J. Gerraty /* 97506b9b3e0SSimon J. Gerraty * Get token now to avoid cycling job-list when we only 97606b9b3e0SSimon J. Gerraty * have 1 token 97706b9b3e0SSimon J. Gerraty */ 9783955d011SMarcel Moolenaar if (!have_token && !Job_TokenWithdraw()) 9793955d011SMarcel Moolenaar break; 980*b0c40a00SSimon J. Gerraty have_token = true; 9813955d011SMarcel Moolenaar 98206b9b3e0SSimon J. Gerraty gn = Lst_Dequeue(&toBeMade); 983956e45f6SSimon J. Gerraty DEBUG2(MAKE, "Examining %s%s...\n", gn->name, gn->cohort_num); 9843955d011SMarcel Moolenaar 9853955d011SMarcel Moolenaar if (gn->made != REQUESTED) { 98606b9b3e0SSimon J. Gerraty /* 98706b9b3e0SSimon J. Gerraty * XXX: Replace %d with string representation; 98806b9b3e0SSimon J. Gerraty * see made_name. 98906b9b3e0SSimon J. Gerraty */ 990956e45f6SSimon J. Gerraty DEBUG1(MAKE, "state %d\n", gn->made); 9913955d011SMarcel Moolenaar 9923955d011SMarcel Moolenaar make_abort(gn, __LINE__); 9933955d011SMarcel Moolenaar } 9943955d011SMarcel Moolenaar 995e2eeea75SSimon J. Gerraty if (gn->checked_seqno == checked_seqno) { 99606b9b3e0SSimon J. Gerraty /* 99706b9b3e0SSimon J. Gerraty * We've already looked at this node since a job 99806b9b3e0SSimon J. Gerraty * finished... 99906b9b3e0SSimon J. Gerraty */ 100006b9b3e0SSimon J. Gerraty DEBUG2(MAKE, "already checked %s%s\n", gn->name, 100106b9b3e0SSimon J. Gerraty gn->cohort_num); 10023955d011SMarcel Moolenaar gn->made = DEFERRED; 10033955d011SMarcel Moolenaar continue; 10043955d011SMarcel Moolenaar } 1005e2eeea75SSimon J. Gerraty gn->checked_seqno = checked_seqno; 10063955d011SMarcel Moolenaar 10073955d011SMarcel Moolenaar if (gn->unmade != 0) { 10083955d011SMarcel Moolenaar /* 100906b9b3e0SSimon J. Gerraty * We can't build this yet, add all unmade children 101006b9b3e0SSimon J. Gerraty * to toBeMade, just before the current first element. 10113955d011SMarcel Moolenaar */ 10123955d011SMarcel Moolenaar gn->made = DEFERRED; 101306b9b3e0SSimon J. Gerraty 101406b9b3e0SSimon J. Gerraty MakeChildren(gn); 101506b9b3e0SSimon J. Gerraty 10163955d011SMarcel Moolenaar /* and drop this node on the floor */ 101706b9b3e0SSimon J. Gerraty DEBUG2(MAKE, "dropped %s%s\n", gn->name, 101806b9b3e0SSimon J. Gerraty gn->cohort_num); 10193955d011SMarcel Moolenaar continue; 10203955d011SMarcel Moolenaar } 10213955d011SMarcel Moolenaar 10223955d011SMarcel Moolenaar gn->made = BEINGMADE; 1023e2eeea75SSimon J. Gerraty if (GNode_IsOODate(gn)) { 1024956e45f6SSimon J. Gerraty DEBUG0(MAKE, "out-of-date\n"); 1025e2eeea75SSimon J. Gerraty if (opts.queryFlag) 1026*b0c40a00SSimon J. Gerraty return true; 1027*b0c40a00SSimon J. Gerraty GNode_SetLocalVars(gn); 10283955d011SMarcel Moolenaar Job_Make(gn); 1029*b0c40a00SSimon J. Gerraty have_token = false; 10303955d011SMarcel Moolenaar } else { 1031956e45f6SSimon J. Gerraty DEBUG0(MAKE, "up-to-date\n"); 10323955d011SMarcel Moolenaar gn->made = UPTODATE; 10333955d011SMarcel Moolenaar if (gn->type & OP_JOIN) { 10343955d011SMarcel Moolenaar /* 103506b9b3e0SSimon J. Gerraty * Even for an up-to-date .JOIN node, we 1036dba7b0efSSimon J. Gerraty * need it to have its local variables so 103706b9b3e0SSimon J. Gerraty * references to it get the correct value 1038dba7b0efSSimon J. Gerraty * for .TARGET when building up the local 103906b9b3e0SSimon J. Gerraty * variables of its parent(s)... 10403955d011SMarcel Moolenaar */ 1041*b0c40a00SSimon J. Gerraty GNode_SetLocalVars(gn); 10423955d011SMarcel Moolenaar } 10433955d011SMarcel Moolenaar Make_Update(gn); 10443955d011SMarcel Moolenaar } 10453955d011SMarcel Moolenaar } 10463955d011SMarcel Moolenaar 10473955d011SMarcel Moolenaar if (have_token) 10483955d011SMarcel Moolenaar Job_TokenReturn(); 10493955d011SMarcel Moolenaar 1050*b0c40a00SSimon J. Gerraty return false; 10513955d011SMarcel Moolenaar } 10522c3632d1SSimon J. Gerraty 1053e2eeea75SSimon J. Gerraty /* Print the status of a .ORDER node. */ 1054956e45f6SSimon J. Gerraty static void 1055956e45f6SSimon J. Gerraty MakePrintStatusOrderNode(GNode *ogn, GNode *gn) 10563955d011SMarcel Moolenaar { 105706b9b3e0SSimon J. Gerraty if (!GNode_IsWaitingFor(ogn)) 1058956e45f6SSimon J. Gerraty return; 10593955d011SMarcel Moolenaar 10602c3632d1SSimon J. Gerraty printf(" `%s%s' has .ORDER dependency against %s%s ", 10612c3632d1SSimon J. Gerraty gn->name, gn->cohort_num, ogn->name, ogn->cohort_num); 10622c3632d1SSimon J. Gerraty GNode_FprintDetails(stdout, "(", ogn, ")\n"); 10632c3632d1SSimon J. Gerraty 1064956e45f6SSimon J. Gerraty if (DEBUG(MAKE) && opts.debug_file != stdout) { 1065956e45f6SSimon J. Gerraty debug_printf(" `%s%s' has .ORDER dependency against %s%s ", 10662c3632d1SSimon J. Gerraty gn->name, gn->cohort_num, ogn->name, ogn->cohort_num); 1067956e45f6SSimon J. Gerraty GNode_FprintDetails(opts.debug_file, "(", ogn, ")\n"); 10682c3632d1SSimon J. Gerraty } 10693955d011SMarcel Moolenaar } 10703955d011SMarcel Moolenaar 1071956e45f6SSimon J. Gerraty static void 1072956e45f6SSimon J. Gerraty MakePrintStatusOrder(GNode *gn) 10733955d011SMarcel Moolenaar { 1074956e45f6SSimon J. Gerraty GNodeListNode *ln; 107506b9b3e0SSimon J. Gerraty for (ln = gn->order_pred.first; ln != NULL; ln = ln->next) 1076956e45f6SSimon J. Gerraty MakePrintStatusOrderNode(ln->datum, gn); 1077956e45f6SSimon J. Gerraty } 10783955d011SMarcel Moolenaar 1079956e45f6SSimon J. Gerraty static void MakePrintStatusList(GNodeList *, int *); 1080956e45f6SSimon J. Gerraty 108106b9b3e0SSimon J. Gerraty /* 108206b9b3e0SSimon J. Gerraty * Print the status of a top-level node, viz. it being up-to-date already 1083956e45f6SSimon J. Gerraty * or not created due to an error in a lower level. 1084956e45f6SSimon J. Gerraty */ 1085*b0c40a00SSimon J. Gerraty static bool 1086956e45f6SSimon J. Gerraty MakePrintStatus(GNode *gn, int *errors) 1087956e45f6SSimon J. Gerraty { 108806b9b3e0SSimon J. Gerraty if (gn->flags & DONECYCLE) { 108906b9b3e0SSimon J. Gerraty /* 109006b9b3e0SSimon J. Gerraty * We've completely processed this node before, don't do 109106b9b3e0SSimon J. Gerraty * it again. 109206b9b3e0SSimon J. Gerraty */ 1093*b0c40a00SSimon J. Gerraty return false; 109406b9b3e0SSimon J. Gerraty } 10953955d011SMarcel Moolenaar 10963955d011SMarcel Moolenaar if (gn->unmade == 0) { 10973955d011SMarcel Moolenaar gn->flags |= DONECYCLE; 10983955d011SMarcel Moolenaar switch (gn->made) { 10993955d011SMarcel Moolenaar case UPTODATE: 110006b9b3e0SSimon J. Gerraty printf("`%s%s' is up to date.\n", gn->name, 110106b9b3e0SSimon J. Gerraty gn->cohort_num); 11023955d011SMarcel Moolenaar break; 11033955d011SMarcel Moolenaar case MADE: 11043955d011SMarcel Moolenaar break; 11053955d011SMarcel Moolenaar case UNMADE: 11063955d011SMarcel Moolenaar case DEFERRED: 11073955d011SMarcel Moolenaar case REQUESTED: 11083955d011SMarcel Moolenaar case BEINGMADE: 11093955d011SMarcel Moolenaar (*errors)++; 111006b9b3e0SSimon J. Gerraty printf("`%s%s' was not built", gn->name, 111106b9b3e0SSimon J. Gerraty gn->cohort_num); 11122c3632d1SSimon J. Gerraty GNode_FprintDetails(stdout, " (", gn, ")!\n"); 1113956e45f6SSimon J. Gerraty if (DEBUG(MAKE) && opts.debug_file != stdout) { 111406b9b3e0SSimon J. Gerraty debug_printf("`%s%s' was not built", gn->name, 111506b9b3e0SSimon J. Gerraty gn->cohort_num); 111606b9b3e0SSimon J. Gerraty GNode_FprintDetails(opts.debug_file, " (", gn, 111706b9b3e0SSimon J. Gerraty ")!\n"); 11182c3632d1SSimon J. Gerraty } 11193955d011SMarcel Moolenaar /* Most likely problem is actually caused by .ORDER */ 1120956e45f6SSimon J. Gerraty MakePrintStatusOrder(gn); 11213955d011SMarcel Moolenaar break; 11223955d011SMarcel Moolenaar default: 11233955d011SMarcel Moolenaar /* Errors - already counted */ 11243955d011SMarcel Moolenaar printf("`%s%s' not remade because of errors.\n", 11253955d011SMarcel Moolenaar gn->name, gn->cohort_num); 1126956e45f6SSimon J. Gerraty if (DEBUG(MAKE) && opts.debug_file != stdout) 112706b9b3e0SSimon J. Gerraty debug_printf( 112806b9b3e0SSimon J. Gerraty "`%s%s' not remade because of errors.\n", 11293955d011SMarcel Moolenaar gn->name, gn->cohort_num); 11303955d011SMarcel Moolenaar break; 11313955d011SMarcel Moolenaar } 1132*b0c40a00SSimon J. Gerraty return false; 11333955d011SMarcel Moolenaar } 11343955d011SMarcel Moolenaar 1135956e45f6SSimon J. Gerraty DEBUG3(MAKE, "MakePrintStatus: %s%s has %d unmade children\n", 11363955d011SMarcel Moolenaar gn->name, gn->cohort_num, gn->unmade); 11373955d011SMarcel Moolenaar /* 11383955d011SMarcel Moolenaar * If printing cycles and came to one that has unmade children, 11393955d011SMarcel Moolenaar * print out the cycle by recursing on its children. 11403955d011SMarcel Moolenaar */ 11413955d011SMarcel Moolenaar if (!(gn->flags & CYCLE)) { 1142e2eeea75SSimon J. Gerraty /* First time we've seen this node, check all children */ 11433955d011SMarcel Moolenaar gn->flags |= CYCLE; 114406b9b3e0SSimon J. Gerraty MakePrintStatusList(&gn->children, errors); 11453955d011SMarcel Moolenaar /* Mark that this node needn't be processed again */ 11463955d011SMarcel Moolenaar gn->flags |= DONECYCLE; 1147*b0c40a00SSimon J. Gerraty return false; 11483955d011SMarcel Moolenaar } 11493955d011SMarcel Moolenaar 11503955d011SMarcel Moolenaar /* Only output the error once per node */ 11513955d011SMarcel Moolenaar gn->flags |= DONECYCLE; 11523955d011SMarcel Moolenaar Error("Graph cycles through `%s%s'", gn->name, gn->cohort_num); 11533955d011SMarcel Moolenaar if ((*errors)++ > 100) 11543955d011SMarcel Moolenaar /* Abandon the whole error report */ 1155*b0c40a00SSimon J. Gerraty return true; 11563955d011SMarcel Moolenaar 11573955d011SMarcel Moolenaar /* Reporting for our children will give the rest of the loop */ 115806b9b3e0SSimon J. Gerraty MakePrintStatusList(&gn->children, errors); 1159*b0c40a00SSimon J. Gerraty return false; 11603955d011SMarcel Moolenaar } 11612c3632d1SSimon J. Gerraty 1162956e45f6SSimon J. Gerraty static void 1163956e45f6SSimon J. Gerraty MakePrintStatusList(GNodeList *gnodes, int *errors) 1164956e45f6SSimon J. Gerraty { 1165956e45f6SSimon J. Gerraty GNodeListNode *ln; 116606b9b3e0SSimon J. Gerraty 1167956e45f6SSimon J. Gerraty for (ln = gnodes->first; ln != NULL; ln = ln->next) 1168956e45f6SSimon J. Gerraty if (MakePrintStatus(ln->datum, errors)) 1169956e45f6SSimon J. Gerraty break; 1170956e45f6SSimon J. Gerraty } 11713955d011SMarcel Moolenaar 1172e2eeea75SSimon J. Gerraty static void 1173e2eeea75SSimon J. Gerraty ExamineLater(GNodeList *examine, GNodeList *toBeExamined) 1174e2eeea75SSimon J. Gerraty { 1175e2eeea75SSimon J. Gerraty ListNode *ln; 1176e2eeea75SSimon J. Gerraty 1177e2eeea75SSimon J. Gerraty for (ln = toBeExamined->first; ln != NULL; ln = ln->next) { 1178e2eeea75SSimon J. Gerraty GNode *gn = ln->datum; 1179e2eeea75SSimon J. Gerraty 1180e2eeea75SSimon J. Gerraty if (gn->flags & REMAKE) 1181e2eeea75SSimon J. Gerraty continue; 1182e2eeea75SSimon J. Gerraty if (gn->type & (OP_USE | OP_USEBEFORE)) 1183e2eeea75SSimon J. Gerraty continue; 1184e2eeea75SSimon J. Gerraty 1185e2eeea75SSimon J. Gerraty DEBUG2(MAKE, "ExamineLater: need to examine \"%s%s\"\n", 1186e2eeea75SSimon J. Gerraty gn->name, gn->cohort_num); 1187e2eeea75SSimon J. Gerraty Lst_Enqueue(examine, gn); 1188e2eeea75SSimon J. Gerraty } 1189e2eeea75SSimon J. Gerraty } 1190e2eeea75SSimon J. Gerraty 119106b9b3e0SSimon J. Gerraty /* 119206b9b3e0SSimon J. Gerraty * Expand .USE nodes and create a new targets list. 11933955d011SMarcel Moolenaar * 11943955d011SMarcel Moolenaar * Input: 11953955d011SMarcel Moolenaar * targs the initial list of targets 11963955d011SMarcel Moolenaar */ 11973955d011SMarcel Moolenaar void 1198956e45f6SSimon J. Gerraty Make_ExpandUse(GNodeList *targs) 11993955d011SMarcel Moolenaar { 120006b9b3e0SSimon J. Gerraty GNodeList examine = LST_INIT; /* Queue of targets to examine */ 120106b9b3e0SSimon J. Gerraty Lst_AppendAll(&examine, targs); 12023955d011SMarcel Moolenaar 12033955d011SMarcel Moolenaar /* 120406b9b3e0SSimon J. Gerraty * Make an initial downward pass over the graph, marking nodes to 120506b9b3e0SSimon J. Gerraty * be made as we go down. 120606b9b3e0SSimon J. Gerraty * 120706b9b3e0SSimon J. Gerraty * We call Suff_FindDeps to find where a node is and to get some 120806b9b3e0SSimon J. Gerraty * children for it if it has none and also has no commands. If the 120906b9b3e0SSimon J. Gerraty * node is a leaf, we stick it on the toBeMade queue to be looked 121006b9b3e0SSimon J. Gerraty * at in a minute, otherwise we add its children to our queue and 121106b9b3e0SSimon J. Gerraty * go on about our business. 12123955d011SMarcel Moolenaar */ 121306b9b3e0SSimon J. Gerraty while (!Lst_IsEmpty(&examine)) { 121406b9b3e0SSimon J. Gerraty GNode *gn = Lst_Dequeue(&examine); 12153955d011SMarcel Moolenaar 12163955d011SMarcel Moolenaar if (gn->flags & REMAKE) 12173955d011SMarcel Moolenaar /* We've looked at this one already */ 12183955d011SMarcel Moolenaar continue; 12193955d011SMarcel Moolenaar gn->flags |= REMAKE; 1220956e45f6SSimon J. Gerraty DEBUG2(MAKE, "Make_ExpandUse: examine %s%s\n", 12213955d011SMarcel Moolenaar gn->name, gn->cohort_num); 12223955d011SMarcel Moolenaar 12232c3632d1SSimon J. Gerraty if (gn->type & OP_DOUBLEDEP) 122406b9b3e0SSimon J. Gerraty Lst_PrependAll(&examine, &gn->cohorts); 12253955d011SMarcel Moolenaar 12263955d011SMarcel Moolenaar /* 122706b9b3e0SSimon J. Gerraty * Apply any .USE rules before looking for implicit 122806b9b3e0SSimon J. Gerraty * dependencies to make sure everything has commands that 122906b9b3e0SSimon J. Gerraty * should. 123006b9b3e0SSimon J. Gerraty * 12313955d011SMarcel Moolenaar * Make sure that the TARGET is set, so that we can make 12323955d011SMarcel Moolenaar * expansions. 12333955d011SMarcel Moolenaar */ 12343955d011SMarcel Moolenaar if (gn->type & OP_ARCHV) { 1235e2eeea75SSimon J. Gerraty char *eoa = strchr(gn->name, '('); 1236e2eeea75SSimon J. Gerraty char *eon = strchr(gn->name, ')'); 12373955d011SMarcel Moolenaar if (eoa == NULL || eon == NULL) 12383955d011SMarcel Moolenaar continue; 12393955d011SMarcel Moolenaar *eoa = '\0'; 12403955d011SMarcel Moolenaar *eon = '\0'; 1241dba7b0efSSimon J. Gerraty Var_Set(gn, MEMBER, eoa + 1); 1242dba7b0efSSimon J. Gerraty Var_Set(gn, ARCHIVE, gn->name); 12433955d011SMarcel Moolenaar *eoa = '('; 12443955d011SMarcel Moolenaar *eon = ')'; 12453955d011SMarcel Moolenaar } 12463955d011SMarcel Moolenaar 1247*b0c40a00SSimon J. Gerraty Dir_UpdateMTime(gn, false); 1248dba7b0efSSimon J. Gerraty Var_Set(gn, TARGET, GNode_Path(gn)); 1249956e45f6SSimon J. Gerraty UnmarkChildren(gn); 1250956e45f6SSimon J. Gerraty HandleUseNodes(gn); 12513955d011SMarcel Moolenaar 1252e2eeea75SSimon J. Gerraty if (!(gn->type & OP_MADE)) 12533955d011SMarcel Moolenaar Suff_FindDeps(gn); 12543955d011SMarcel Moolenaar else { 1255e2eeea75SSimon J. Gerraty PretendAllChildrenAreMade(gn); 125606b9b3e0SSimon J. Gerraty if (gn->unmade != 0) { 125706b9b3e0SSimon J. Gerraty printf( 125806b9b3e0SSimon J. Gerraty "Warning: " 125906b9b3e0SSimon J. Gerraty "%s%s still has %d unmade children\n", 12603955d011SMarcel Moolenaar gn->name, gn->cohort_num, gn->unmade); 12613955d011SMarcel Moolenaar } 12623955d011SMarcel Moolenaar } 12633955d011SMarcel Moolenaar 126406b9b3e0SSimon J. Gerraty if (gn->unmade != 0) 126506b9b3e0SSimon J. Gerraty ExamineLater(&examine, &gn->children); 126606b9b3e0SSimon J. Gerraty } 126706b9b3e0SSimon J. Gerraty 126806b9b3e0SSimon J. Gerraty Lst_Done(&examine); 12693955d011SMarcel Moolenaar } 12703955d011SMarcel Moolenaar 1271956e45f6SSimon J. Gerraty /* Make the .WAIT node depend on the previous children */ 1272956e45f6SSimon J. Gerraty static void 1273956e45f6SSimon J. Gerraty add_wait_dependency(GNodeListNode *owln, GNode *wn) 12743955d011SMarcel Moolenaar { 1275956e45f6SSimon J. Gerraty GNodeListNode *cln; 1276956e45f6SSimon J. Gerraty GNode *cn; 12773955d011SMarcel Moolenaar 1278956e45f6SSimon J. Gerraty for (cln = owln; (cn = cln->datum) != wn; cln = cln->next) { 1279956e45f6SSimon J. Gerraty DEBUG3(MAKE, ".WAIT: add dependency %s%s -> %s\n", 12803955d011SMarcel Moolenaar cn->name, cn->cohort_num, wn->name); 12813955d011SMarcel Moolenaar 1282956e45f6SSimon J. Gerraty /* XXX: This pattern should be factored out, it repeats often */ 128306b9b3e0SSimon J. Gerraty Lst_Append(&wn->children, cn); 12843955d011SMarcel Moolenaar wn->unmade++; 128506b9b3e0SSimon J. Gerraty Lst_Append(&cn->parents, wn); 1286956e45f6SSimon J. Gerraty } 12873955d011SMarcel Moolenaar } 12883955d011SMarcel Moolenaar 1289956e45f6SSimon J. Gerraty /* Convert .WAIT nodes into dependencies. */ 12903955d011SMarcel Moolenaar static void 1291956e45f6SSimon J. Gerraty Make_ProcessWait(GNodeList *targs) 12923955d011SMarcel Moolenaar { 12933955d011SMarcel Moolenaar GNode *pgn; /* 'parent' node we are examining */ 1294956e45f6SSimon J. Gerraty GNodeListNode *owln; /* Previous .WAIT node */ 129506b9b3e0SSimon J. Gerraty GNodeList examine; /* List of targets to examine */ 12963955d011SMarcel Moolenaar 12973955d011SMarcel Moolenaar /* 12983955d011SMarcel Moolenaar * We need all the nodes to have a common parent in order for the 12993955d011SMarcel Moolenaar * .WAIT and .ORDER scheduling to work. 13003955d011SMarcel Moolenaar * Perhaps this should be done earlier... 13013955d011SMarcel Moolenaar */ 13023955d011SMarcel Moolenaar 1303e2eeea75SSimon J. Gerraty pgn = GNode_New(".MAIN"); 13043955d011SMarcel Moolenaar pgn->flags = REMAKE; 13053955d011SMarcel Moolenaar pgn->type = OP_PHONY | OP_DEPENDS; 13063955d011SMarcel Moolenaar /* Get it displayed in the diag dumps */ 13072c3632d1SSimon J. Gerraty Lst_Prepend(Targ_List(), pgn); 13083955d011SMarcel Moolenaar 1309956e45f6SSimon J. Gerraty { 1310956e45f6SSimon J. Gerraty GNodeListNode *ln; 1311956e45f6SSimon J. Gerraty for (ln = targs->first; ln != NULL; ln = ln->next) { 1312956e45f6SSimon J. Gerraty GNode *cgn = ln->datum; 1313956e45f6SSimon J. Gerraty 131406b9b3e0SSimon J. Gerraty Lst_Append(&pgn->children, cgn); 131506b9b3e0SSimon J. Gerraty Lst_Append(&cgn->parents, pgn); 1316956e45f6SSimon J. Gerraty pgn->unmade++; 1317956e45f6SSimon J. Gerraty } 1318956e45f6SSimon J. Gerraty } 13193955d011SMarcel Moolenaar 13203955d011SMarcel Moolenaar /* Start building with the 'dummy' .MAIN' node */ 13213955d011SMarcel Moolenaar MakeBuildChild(pgn, NULL); 13223955d011SMarcel Moolenaar 132306b9b3e0SSimon J. Gerraty Lst_Init(&examine); 132406b9b3e0SSimon J. Gerraty Lst_Append(&examine, pgn); 13253955d011SMarcel Moolenaar 132606b9b3e0SSimon J. Gerraty while (!Lst_IsEmpty(&examine)) { 1327956e45f6SSimon J. Gerraty GNodeListNode *ln; 1328956e45f6SSimon J. Gerraty 132906b9b3e0SSimon J. Gerraty pgn = Lst_Dequeue(&examine); 13303955d011SMarcel Moolenaar 13313955d011SMarcel Moolenaar /* We only want to process each child-list once */ 13323955d011SMarcel Moolenaar if (pgn->flags & DONE_WAIT) 13333955d011SMarcel Moolenaar continue; 13343955d011SMarcel Moolenaar pgn->flags |= DONE_WAIT; 1335956e45f6SSimon J. Gerraty DEBUG1(MAKE, "Make_ProcessWait: examine %s\n", pgn->name); 13363955d011SMarcel Moolenaar 13372c3632d1SSimon J. Gerraty if (pgn->type & OP_DOUBLEDEP) 133806b9b3e0SSimon J. Gerraty Lst_PrependAll(&examine, &pgn->cohorts); 13393955d011SMarcel Moolenaar 134006b9b3e0SSimon J. Gerraty owln = pgn->children.first; 134106b9b3e0SSimon J. Gerraty for (ln = pgn->children.first; ln != NULL; ln = ln->next) { 1342956e45f6SSimon J. Gerraty GNode *cgn = ln->datum; 13433955d011SMarcel Moolenaar if (cgn->type & OP_WAIT) { 1344956e45f6SSimon J. Gerraty add_wait_dependency(owln, cgn); 13453955d011SMarcel Moolenaar owln = ln; 13463955d011SMarcel Moolenaar } else { 134706b9b3e0SSimon J. Gerraty Lst_Append(&examine, cgn); 13483955d011SMarcel Moolenaar } 13493955d011SMarcel Moolenaar } 13503955d011SMarcel Moolenaar } 13513955d011SMarcel Moolenaar 135206b9b3e0SSimon J. Gerraty Lst_Done(&examine); 13533955d011SMarcel Moolenaar } 13543955d011SMarcel Moolenaar 135506b9b3e0SSimon J. Gerraty /* 135606b9b3e0SSimon J. Gerraty * Initialize the nodes to remake and the list of nodes which are ready to 135706b9b3e0SSimon J. Gerraty * be made by doing a breadth-first traversal of the graph starting from the 135806b9b3e0SSimon J. Gerraty * nodes in the given list. Once this traversal is finished, all the 'leaves' 135906b9b3e0SSimon J. Gerraty * of the graph are in the toBeMade queue. 136006b9b3e0SSimon J. Gerraty * 136106b9b3e0SSimon J. Gerraty * Using this queue and the Job module, work back up the graph, calling on 136206b9b3e0SSimon J. Gerraty * MakeStartJobs to keep the job table as full as possible. 13633955d011SMarcel Moolenaar * 13643955d011SMarcel Moolenaar * Input: 13653955d011SMarcel Moolenaar * targs the initial list of targets 13663955d011SMarcel Moolenaar * 13673955d011SMarcel Moolenaar * Results: 1368*b0c40a00SSimon J. Gerraty * True if work was done, false otherwise. 13693955d011SMarcel Moolenaar * 13703955d011SMarcel Moolenaar * Side Effects: 13713955d011SMarcel Moolenaar * The make field of all nodes involved in the creation of the given 13723955d011SMarcel Moolenaar * targets is set to 1. The toBeMade list is set to contain all the 13733955d011SMarcel Moolenaar * 'leaves' of these subgraphs. 13743955d011SMarcel Moolenaar */ 1375*b0c40a00SSimon J. Gerraty bool 1376956e45f6SSimon J. Gerraty Make_Run(GNodeList *targs) 13773955d011SMarcel Moolenaar { 13783955d011SMarcel Moolenaar int errors; /* Number of errors the Job module reports */ 13793955d011SMarcel Moolenaar 13803955d011SMarcel Moolenaar /* Start trying to make the current targets... */ 138106b9b3e0SSimon J. Gerraty Lst_Init(&toBeMade); 13823955d011SMarcel Moolenaar 13833955d011SMarcel Moolenaar Make_ExpandUse(targs); 13843955d011SMarcel Moolenaar Make_ProcessWait(targs); 13853955d011SMarcel Moolenaar 13863955d011SMarcel Moolenaar if (DEBUG(MAKE)) { 1387956e45f6SSimon J. Gerraty debug_printf("#***# full graph\n"); 13883955d011SMarcel Moolenaar Targ_PrintGraph(1); 13893955d011SMarcel Moolenaar } 13903955d011SMarcel Moolenaar 1391956e45f6SSimon J. Gerraty if (opts.queryFlag) { 13923955d011SMarcel Moolenaar /* 139306b9b3e0SSimon J. Gerraty * We wouldn't do any work unless we could start some jobs 139406b9b3e0SSimon J. Gerraty * in the next loop... (we won't actually start any, of 139506b9b3e0SSimon J. Gerraty * course, this is just to see if any of the targets was out 139606b9b3e0SSimon J. Gerraty * of date) 13973955d011SMarcel Moolenaar */ 13983841c287SSimon J. Gerraty return MakeStartJobs(); 13993955d011SMarcel Moolenaar } 14003955d011SMarcel Moolenaar /* 14013955d011SMarcel Moolenaar * Initialization. At the moment, no jobs are running and until some 14023955d011SMarcel Moolenaar * get started, nothing will happen since the remaining upward 14033955d011SMarcel Moolenaar * traversal of the graph is performed by the routines in job.c upon 14043955d011SMarcel Moolenaar * the finishing of a job. So we fill the Job table as much as we can 14053955d011SMarcel Moolenaar * before going into our loop. 14063955d011SMarcel Moolenaar */ 14073955d011SMarcel Moolenaar (void)MakeStartJobs(); 14083955d011SMarcel Moolenaar 14093955d011SMarcel Moolenaar /* 14103955d011SMarcel Moolenaar * Main Loop: The idea here is that the ending of jobs will take 141106b9b3e0SSimon J. Gerraty * care of the maintenance of data structures and the waiting for 141206b9b3e0SSimon J. Gerraty * output will cause us to be idle most of the time while our 141306b9b3e0SSimon J. Gerraty * children run as much as possible. Because the job table is kept 141406b9b3e0SSimon J. Gerraty * as full as possible, the only time when it will be empty is when 141506b9b3e0SSimon J. Gerraty * all the jobs which need running have been run, so that is the end 141606b9b3e0SSimon J. Gerraty * condition of this loop. Note that the Job module will exit if 141706b9b3e0SSimon J. Gerraty * there were any errors unless the keepgoing flag was given. 14183955d011SMarcel Moolenaar */ 141906b9b3e0SSimon J. Gerraty while (!Lst_IsEmpty(&toBeMade) || jobTokensRunning > 0) { 14203955d011SMarcel Moolenaar Job_CatchOutput(); 14213955d011SMarcel Moolenaar (void)MakeStartJobs(); 14223955d011SMarcel Moolenaar } 14233955d011SMarcel Moolenaar 14243955d011SMarcel Moolenaar errors = Job_Finish(); 14253955d011SMarcel Moolenaar 14263955d011SMarcel Moolenaar /* 14273955d011SMarcel Moolenaar * Print the final status of each target. E.g. if it wasn't made 14283955d011SMarcel Moolenaar * because some inferior reported an error. 14293955d011SMarcel Moolenaar */ 1430956e45f6SSimon J. Gerraty DEBUG1(MAKE, "done: errors %d\n", errors); 14313955d011SMarcel Moolenaar if (errors == 0) { 1432956e45f6SSimon J. Gerraty MakePrintStatusList(targs, &errors); 14333955d011SMarcel Moolenaar if (DEBUG(MAKE)) { 1434956e45f6SSimon J. Gerraty debug_printf("done: errors %d\n", errors); 1435e2eeea75SSimon J. Gerraty if (errors > 0) 14363955d011SMarcel Moolenaar Targ_PrintGraph(4); 14373955d011SMarcel Moolenaar } 14383955d011SMarcel Moolenaar } 1439e2eeea75SSimon J. Gerraty return errors > 0; 14403955d011SMarcel Moolenaar } 1441