From 179a2a89bbdf4f946c0346915e4a2eb8fe5e2800 Mon Sep 17 00:00:00 2001 From: ketmar Date: Thu, 18 Aug 2011 14:31:14 +0300 Subject: [PATCH] cosmetix --- src/make.c | 263 ++++++++++++++++++++++++++----------------------------------- 1 file changed, 113 insertions(+), 150 deletions(-) diff --git a/src/make.c b/src/make.c index 36141f7..7de7db0 100644 --- a/src/make.c +++ b/src/make.c @@ -3,7 +3,6 @@ * * This file is part of Jam - see jam.c for Copyright information. */ - /* * make.c - bring a target up to date, once rules are in place * @@ -51,23 +50,23 @@ * 04/14/06 (kaib) - fix targets to show in 'updated' when their includes * are newer */ +#include "jam.h" -# include "jam.h" - -# include "lists.h" -# include "parse.h" -# include "variable.h" -# include "rules.h" +#include "lists.h" +#include "parse.h" +#include "variable.h" +#include "rules.h" -# include "search.h" -# include "newstr.h" -# include "make.h" -# include "headers.h" -# include "command.h" +#include "search.h" +#include "newstr.h" +#include "make.h" +#include "headers.h" +#include "command.h" -# ifndef max +#ifndef max # define max(a,b) ((a)>(b)?(a):(b)) -# endif +#endif + typedef struct { int temp; @@ -86,18 +85,18 @@ static TARGETS *make0sort (TARGETS *c); static const char *target_fate[] = { - "init", /* T_FATE_INIT */ - "making", /* T_FATE_MAKING */ - "stable", /* T_FATE_STABLE */ - "newer", /* T_FATE_NEWER */ - "temp", /* T_FATE_ISTMP */ - "touched", /* T_FATE_TOUCHED */ - "missing", /* T_FATE_MISSING */ - "needtmp", /* T_FATE_NEEDTMP */ - "old", /* T_FATE_OUTDATED */ - "update", /* T_FATE_UPDATE */ - "nofind", /* T_FATE_CANTFIND */ - "nomake" /* T_FATE_CANTMAKE */ + "init", /* T_FATE_INIT */ + "making", /* T_FATE_MAKING */ + "stable", /* T_FATE_STABLE */ + "newer", /* T_FATE_NEWER */ + "temp", /* T_FATE_ISTMP */ + "touched", /* T_FATE_TOUCHED */ + "missing", /* T_FATE_MISSING */ + "needtmp", /* T_FATE_NEEDTMP */ + "old", /* T_FATE_OUTDATED */ + "update", /* T_FATE_UPDATE */ + "nofind", /* T_FATE_CANTFIND */ + "nomake" /* T_FATE_CANTMAKE */ }; @@ -108,7 +107,7 @@ static const char *target_bind[] = { "exists", }; -# define spaces(x) (" " + 16 - (x > 16 ? 16 : x)) +#define spaces(x) (" "+16-(x>16?16:x)) /* @@ -118,9 +117,9 @@ int make (int n_targets, const char **targets, int anyhow) { int i; COUNTS counts[1]; int status = 0; /* 1 if anything fails */ - + // memset((char *)counts, 0, sizeof(*counts)); - for (i = 0; i < n_targets; i++) { + for (i = 0; i < n_targets; ++i) { TARGET *t = bindtarget(targets[i]); make0(t, 0, 0, counts, anyhow); } @@ -132,7 +131,7 @@ int make (int n_targets, const char **targets, int anyhow) { if (counts->cantmake) printf("...can't make %d target%s...\n", counts->cantmake, multiFormSfx(counts->cantmake)); } status = counts->cantfind || counts->cantmake; - for (i = 0; i < n_targets; i++) status |= make1(bindtarget(targets[i])); + for (i = 0; i < n_targets; ++i) status |= make1(bindtarget(targets[i])); return status; } @@ -156,24 +155,22 @@ static void make0 ( int fate; const char *flag = ""; SETTINGS *s; + // /* step 1: initialize */ if (DEBUG_MAKEPROG) printf("make\t--\t%s%s\n", spaces(depth), t->name); t->fate = T_FATE_MAKING; - /* - * Step 2: under the influence of "on target" variables, - * bind the target and search for headers. - */ - /* Step 2a: set "on target" variables. */ + /* step 2: under the influence of "on target" variables, bind the target and search for headers */ + /* step 2a: set "on target" variables */ s = copysettings(t->settings); pushsettings(s); - /* Step 2b: find and timestamp the target file (if it's a file). */ + /* step 2b: find and timestamp the target file (if it's a file) */ if (t->binding == T_BIND_UNBOUND && !(t->flags & T_FLAG_NOTFILE)) { t->boundname = search(t->name, &t->time); t->binding = t->time ? T_BIND_EXISTS : T_BIND_MISSING; } /* INTERNAL, NOTFILE header nodes have the time of their parents */ if (p && t->flags & T_FLAG_INTERNAL) ptime = p; - /* If temp file doesn't exist but parent does, use parent */ + /* if temp file doesn't exist but parent does, use parent */ if (p && t->flags & T_FLAG_TEMP && t->binding == T_BIND_MISSING && p->binding != T_BIND_MISSING) { t->binding = T_BIND_PARENTS; ptime = p; @@ -188,12 +185,12 @@ static void make0 ( } } #endif - /* Step 2c: If its a file, search for headers. */ + /* step 2c: If its a file, search for headers */ if (t->binding == T_BIND_EXISTS) headers(t); - /* Step 2d: reset "on target" variables */ + /* step 2d: reset "on target" variables */ popsettings(s); freesettings(s); - /* Pause for a little progress reporting */ + /* pause for a little progress reporting */ if (DEBUG_MAKEPROG) { if (strcmp(t->name, t->boundname)) { printf("bind\t--\t%s%s: %s\n", spaces(depth), t->name, t->boundname); @@ -207,94 +204,71 @@ static void make0 ( break; } } - - /* - * Step 3: recursively make0() dependents & headers - */ - /* Step 3a: recursively make0() dependents */ + /* step 3: recursively make0() dependents & headers */ + /* step 3a: recursively make0() dependents */ for (c = t->depends; c; c = c->next) { int internal = t->flags & T_FLAG_INTERNAL; - - if (DEBUG_DEPENDS) - printf("%s \"%s\" : \"%s\" ;\n", - internal ? "Includes" : "Depends", - t->name, c->target->name); - - /* Warn about circular deps, except for includes, */ - /* which include each other alot. */ + // + if (DEBUG_DEPENDS) printf("%s \"%s\" : \"%s\" ;\n", internal?"Includes":"Depends", t->name, c->target->name); + /* warn about circular deps, except for includes, which include each other alot */ if (c->target->fate == T_FATE_INIT) make0(c->target, ptime, depth+1, counts, anyhow); else if (c->target->fate == T_FATE_MAKING && !internal) printf("warning: %s depends on itself\n", c->target->name); } - /* Step 3b: recursively make0() internal includes node */ + /* step 3b: recursively make0() internal includes node */ if (t->includes) make0(t->includes, p, depth+1, counts, anyhow); - /* Step 3c: add dependents' includes to our direct dependencies */ + /* step 3c: add dependents' includes to our direct dependencies */ incs = 0; for (c = t->depends; c; c = c->next) { if (c->target->includes) { incs = targetentry(incs, c->target->includes); - /* If the includes are newer than we are their original target - also needs to be marked newer. This is needed so that 'updated' - correctly will include the original target in the $(<) variable. */ + /* if the includes are newer than we are their original target also needs to be marked newer */ + /* this is needed so that 'updated' correctly will include the original target in the $(<) variable */ if (c->target->includes->time > t->time) c->target->fate = max(T_FATE_NEWER, c->target->fate); } } - t->depends = targetchain(t->depends, incs); - - /* - * Step 4: compute time & fate - */ - /* Step 4a: pick up dependents' time and fate */ + /* step 4: compute time & fate */ + /* step 4a: pick up dependents' time and fate */ last = 0; leaf = 0; fate = T_FATE_STABLE; for (c = t->depends; c; c = c->next) { - /* If LEAVES has been applied, we only heed the timestamps of */ - /* the leaf source nodes. */ + /* if LEAVES has been applied, we only heed the timestamps of the leaf source nodes */ leaf = max(leaf, c->target->leaf); - if (t->flags & T_FLAG_LEAVES) { - last = leaf; - continue; - } + if (t->flags & T_FLAG_LEAVES) { last = leaf; continue; } last = max(last, c->target->time); fate = max(fate, c->target->fate); } - - /* Step 4b: pick up included headers time */ - /* - * If a header is newer than a temp source that includes it, - * the temp source will need building. - */ + /* step 4b: pick up included headers time */ + /* if a header is newer than a temp source that includes it, the temp source will need building */ hlast = t->includes ? t->includes->time : 0; - /* Step 4c: handle NOUPDATE oddity */ - /* - * If a NOUPDATE file exists, make dependents eternally old. - * Don't inherit our fate from our dependents. Decide fate - * based only upon other flags and our binding (done later). - */ + /* step 4c: handle NOUPDATE oddity */ + /* If a NOUPDATE file exists, make dependents eternally old */ + /* don't inherit our fate from our dependents */ + /* decide fate based only upon other flags and our binding (done later) */ if (t->flags & T_FLAG_NOUPDATE) { last = 0; t->time = 0; fate = T_FATE_STABLE; } - /* Step 4d: determine fate: rebuild target or what? */ + /* step 4d: determine fate: rebuild target or what? */ /* - In English: - If can't find or make child, can't make target. - If children changed, make target. - If target missing, make it. - If children newer, make target. - If temp's children newer than parent, make temp. - If temp's headers newer than parent, make temp. - If deliberately touched, make it. - If up-to-date temp file present, use it. - If target newer than non-notfile parent, mark target newer. - Otherwise, stable! - - Note this block runs from least to most stable: - as we make it further down the list, the target's - fate is getting stabler. - */ + * In English: + * If can't find or make child, can't make target. + * If children changed, make target. + * If target missing, make it. + * If children newer, make target. + * If temp's children newer than parent, make temp. + * If temp's headers newer than parent, make temp. + * If deliberately touched, make it. + * If up-to-date temp file present, use it. + * If target newer than non-notfile parent, mark target newer. + * Otherwise, stable! + * + * Note this block runs from least to most stable: + * as we make it further down the list, the target's + * fate is getting stabler. + */ if (fate >= T_FATE_BROKEN) { fate = T_FATE_CANTMAKE; } else if (fate >= T_FATE_SPOIL) { @@ -318,11 +292,11 @@ static void make0 ( } else { fate = T_FATE_STABLE; } - /* Step 4e: handle missing files */ - /* If it's missing and there are no actions to create it, boom. */ - /* If we can't make a target we don't care about, 'sokay */ - /* We could insist that there are updating actions for all missing */ - /* files, but if they have dependents we just pretend it's NOTFILE. */ + /* step 4e: handle missing files */ + /* if it's missing and there are no actions to create it, boom */ + /* if we can't make a target we don't care about, 'sokay */ + /* we could insist that there are updating actions for all missing + * files, but if they have dependents we just pretend it's NOTFILE */ if (fate == T_FATE_MISSING && !t->actions && !t->depends) { if (t->flags & T_FLAG_NOCARE) { fate = T_FATE_STABLE; @@ -331,39 +305,31 @@ static void make0 ( fate = T_FATE_CANTFIND; } } - /* Step 4f: propagate dependents' time & fate. */ - /* Set leaf time to be our time only if this is a leaf. */ + /* step 4f: propagate dependents' time & fate */ + /* set leaf time to be our time only if this is a leaf */ t->time = max(t->time, last); - t->leaf = leaf ? leaf : t->time ; + t->leaf = leaf?leaf:t->time; t->fate = fate; - - /* - * Step 5: sort dependents by their update time. - */ + /* step 5: sort dependents by their update time */ if (globs.newestfirst) t->depends = make0sort(t->depends); - - /* - * Step 6: a little harmless tabulating for tracing purposes - */ - /* Don't count or report interal includes nodes. */ + /* step 6: a little harmless tabulating for tracing purposes */ + /* don't count or report interal includes nodes */ if (t->flags & T_FLAG_INTERNAL) return; - if (!(++counts->targets % 1000) && DEBUG_MAKE) printf("...patience...\n"); - - if (fate == T_FATE_ISTMP) counts->temp++; - else if (fate == T_FATE_CANTFIND) counts->cantfind++; - else if (fate == T_FATE_CANTMAKE && t->actions) counts->cantmake++; - else if (fate >= T_FATE_BUILD && fate < T_FATE_BROKEN && t->actions) counts->updating++; - + ++counts->targets; + if ((counts->targets%1000 == 0 || counts->targets == 100) && DEBUG_MAKE) printf("...patience...\n"); + // + if (fate == T_FATE_ISTMP) ++counts->temp; + else if (fate == T_FATE_CANTFIND) ++counts->cantfind; + else if (fate == T_FATE_CANTMAKE && t->actions) ++counts->cantmake; + else if (fate >= T_FATE_BUILD && fate < T_FATE_BROKEN && t->actions) ++counts->updating; + // if (!(t->flags & T_FLAG_NOTFILE) && fate >= T_FATE_SPOIL) flag = "+"; else if (t->binding == T_BIND_EXISTS && p && t->time > p->time) flag = "*"; - - if (DEBUG_MAKEPROG) - printf("made%s\t%s\t%s%s\n", - flag, target_fate[(int)t->fate], - spaces(depth), t->name); - - if (DEBUG_CAUSES && t->fate >= T_FATE_NEWER && t->fate <= T_FATE_MISSING) - printf("%s %s\n", target_fate[ (int)t->fate ], t->name); + // + if (DEBUG_MAKEPROG) printf("made%s\t%s\t%s%s\n", flag, target_fate[(int)t->fate], spaces(depth), t->name); + if (DEBUG_CAUSES && t->fate >= T_FATE_NEWER && t->fate <= T_FATE_MISSING) { + printf("%s %s\n", target_fate[(int)t->fate], t->name); + } } @@ -372,30 +338,27 @@ static void make0 ( */ static TARGETS *make0sort (TARGETS *chain) { TARGETS *result = 0; - /* We walk chain, taking each item and inserting it on the */ - /* sorted result, with newest items at the front. This involves */ - /* updating each TARGETS' c->next and c->tail. Note that we */ - /* make c->tail a valid prev pointer for every entry. Normally, */ - /* it is only valid at the head, where prev == tail. Note also */ - /* that while tail is a loop, next ends at the end of the chain. */ - - /* Walk current target list */ + /* we walk chain, taking each item and inserting it on the + * sorted result, with newest items at the front */ + /* this involves updating each TARGETS' c->next and c->tail */ + /* note that we make c->tail a valid prev pointer for every entry */ + /* normally, it is only valid at the head, where prev == tail */ + /* note also that while tail is a loop, next ends at the end of the chain */ + /* walk current target list */ while (chain) { - TARGETS *c = chain; - TARGETS *s = result; - + TARGETS *c = chain, *s = result; + // chain = chain->next; - /* Find point s in result for c */ + /* find point s in result for c */ while (s && s->target->time > c->target->time) s = s->next; - /* Insert c in front of s (might be 0). */ - /* Don't even think of deciphering this. */ - c->next = s; /* good even if s = 0 */ + /* insert c in front of s (might be 0) */ + /* don't even think of deciphering this */ + c->next = s; /* good even if s = 0 */ if (result == s) result = c; /* new head of chain? */ - if (!s) s = result; /* wrap to ensure a next */ + if (!s) s = result; /* wrap to ensure a next */ if (result != c) s->tail->next = c; /* not head? be prev's next */ - c->tail = s->tail; /* take on next's prev */ - s->tail = c; /* make next's prev us */ + c->tail = s->tail; /* take on next's prev */ + s->tail = c; /* make next's prev us */ } - return result; } -- 2.11.4.GIT