📄 make.c
字号:
/*
* Copyright 1993, 1995 Christopher Seiwald.
*
* This file is part of Jam - see jam.c for Copyright information.
*/
/* This file is ALSO:
* Copyright 2001-2004 David Abrahams.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
*/
/*
* make.c - bring a target up to date, once rules are in place
*
* This modules controls the execution of rules to bring a target and
* its dependencies up to date. It is invoked after the targets, rules,
* et. al. described in rules.h are created by the interpreting of the
* jam files.
*
* This file contains the main make() entry point and the first pass
* make0(). The second pass, make1(), which actually does the command
* execution, is in make1.c.
*
* External routines:
* make() - make a target, given its name
*
* Internal routines:
* make0() - bind and scan everything to make a TARGET
* make0sort() - reorder TARGETS chain by their time (newest to oldest)
*
* 12/26/93 (seiwald) - allow NOTIME targets to be expanded via $(<), $(>)
* 01/04/94 (seiwald) - print all targets, bounded, when tracing commands
* 04/08/94 (seiwald) - progress report now reflects only targets with actions
* 04/11/94 (seiwald) - Combined deps & headers into deps[2] in TARGET.
* 12/20/94 (seiwald) - NOTIME renamed NOTFILE.
* 12/20/94 (seiwald) - make0() headers after determining fate of target, so
* that headers aren't seen as dependents on themselves.
* 01/19/95 (seiwald) - distinguish between CANTFIND/CANTMAKE targets.
* 02/02/95 (seiwald) - propagate leaf source time for new LEAVES rule.
* 02/14/95 (seiwald) - NOUPDATE rule means don't update existing target.
* 08/22/95 (seiwald) - NOUPDATE targets immune to anyhow (-a) flag.
* 09/06/00 (seiwald) - NOCARE affects targets with sources/actions.
* 03/02/01 (seiwald) - reverse NOCARE change.
* 03/14/02 (seiwald) - TEMPORARY targets no longer take on parents age
* 03/16/02 (seiwald) - support for -g (reorder builds by source time)
*/
# include "jam.h"
# include "lists.h"
# include "parse.h"
# include "variable.h"
# include "rules.h"
#ifdef OPT_HEADER_CACHE_EXT
# include "hcache.h"
#endif
# include "search.h"
# include "newstr.h"
# include "make.h"
# include "headers.h"
# include "command.h"
# include <assert.h>
# ifndef max
# define max( a,b ) ((a)>(b)?(a):(b))
# endif
static TARGETS *make0sort( TARGETS *c );
#ifdef OPT_GRAPH_DEBUG_EXT
static void dependGraphOutput( TARGET *t, int depth );
#endif
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 */
"rebuild", /* T_FATE_REBUILD */
"missing", /* T_FATE_MISSING */
"needtmp", /* T_FATE_NEEDTMP */
"old", /* T_FATE_OUTDATED */
"update", /* T_FATE_UPDATE */
"nofind", /* T_FATE_CANTFIND */
"nomake" /* T_FATE_CANTMAKE */
} ;
static const char *target_bind[] =
{
"unbound",
"missing",
"parents",
"exists",
} ;
# define spaces(x) ( " " + ( x > 20 ? 0 : 20-x ) )
/*
* make() - make a target, given its name
*/
int
make(
int n_targets,
const char **targets,
int anyhow )
{
int i;
COUNTS counts[1];
int status = 0; /* 1 if anything fails */
#ifdef OPT_HEADER_CACHE_EXT
hcache_init();
#endif
memset( (char *)counts, 0, sizeof( *counts ) );
/* First bind all targets with LOCATE_TARGET setting. This is
needed to correctly handle dependencies to generated headers.
*/
bind_explicitly_located_targets();
for( i = 0; i < n_targets; i++ )
{
TARGET *t = bindtarget( targets[i] );
make0( t, 0, 0, counts, anyhow );
}
#ifdef OPT_GRAPH_DEBUG_EXT
if( DEBUG_GRAPH )
{
for( i = 0; i < n_targets; i++ )
{
TARGET *t = bindtarget( targets[i] );
dependGraphOutput( t, 0 );
}
}
#endif
if( DEBUG_MAKE )
{
if( counts->targets )
printf( "...found %d target%s...\n", counts->targets,
counts->targets > 1 ? "s" : "" );
if( counts->temp )
printf( "...using %d temp target%s...\n", counts->temp,
counts->temp > 1 ? "s" : "" );
if( counts->updating )
printf( "...updating %d target%s...\n", counts->updating,
counts->updating > 1 ? "s" : "" );
if( counts->cantfind )
printf( "...can't find %d target%s...\n", counts->cantfind,
counts->cantfind > 1 ? "s" : "" );
if( counts->cantmake )
printf( "...can't make %d target%s...\n", counts->cantmake,
counts->cantmake > 1 ? "s" : "" );
}
#ifdef OPT_HEADER_CACHE_EXT
hcache_done();
#endif
status = counts->cantfind || counts->cantmake;
for( i = 0; i < n_targets; i++ )
status |= make1( bindtarget( targets[i] ) );
return status;
}
/* Force any dependents of t that have already at least begun being
* visited by make0 to be updated.
*/
static void update_dependents(TARGET* t)
{
TARGETS *q;
for (q = t->dependents; q; q = q->next)
{
TARGET* p = q->target;
char fate0 = p->fate;
/* If we've already at least begun visiting it and
* we're not already rebuilding it for other reasons
*/
if (fate0 != T_FATE_INIT && fate0 < T_FATE_BUILD)
{
p->fate = T_FATE_UPDATE;
if (DEBUG_FATE)
{
printf( "fate change %s from %s to %s (as dependent of %s)\n",
p->name, target_fate[fate0], target_fate[p->fate], t->name);
}
/* If we're done visiting it, go back and make sure its
* dependents get rebuilt.
*/
if (fate0 > T_FATE_MAKING)
update_dependents(p);
}
}
}
/* Make sure that all of t's rebuilds get rebuilt */
static void force_rebuilds(TARGET* t)
{
TARGETS* d;
for (d = t->rebuilds; d; d = d->next)
{
TARGET* r = d->target;
/* If it's not already being rebuilt for other reasons */
if (r->fate < T_FATE_BUILD)
{
if (DEBUG_FATE)
printf( "fate change %s from %s to %s (by rebuild)\n",
r->name, target_fate[r->fate], target_fate[T_FATE_REBUILD]);
/* Force rebuild it */
r->fate = T_FATE_REBUILD;
/* And make sure its dependents are updated too */
update_dependents(r);
}
}
}
/*
* make0() - bind and scan everything to make a TARGET
*
* Make0() recursively binds a target, searches for #included headers,
* calls itself on those headers, and calls itself on any dependents.
*/
void
make0(
TARGET *t,
TARGET *p, /* parent */
int depth, /* for display purposes */
COUNTS *counts, /* for reporting */
int anyhow ) /* forcibly touch all (real) targets */
{
TARGETS *c, *d, *incs;
TARGET *ptime = t;
time_t last, leaf, hlast;
int fate;
const char *flag = "";
SETTINGS *s;
#ifdef OPT_GRAPH_DEBUG_EXT
int savedFate, oldTimeStamp;
#endif
if( DEBUG_MAKEPROG )
printf( "make\t--\t%s%s\n", spaces( depth ), t->name );
/*
* 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. */
s = copysettings( t->settings );
pushsettings( s );
/* Step 2b: find and timestamp the target file (if it's a file). */
if( t->binding == T_BIND_UNBOUND && !( t->flags & T_FLAG_NOTFILE ) )
{
char* another_target;
t->boundname = search( t->name, &t->time, &another_target );
/* If it was detected that this target refers to an already
existing and bound one, we add include dependency, so that
every target which depends on us will depend on that other
target. */
if( another_target )
{
TARGET* includes;
if (!t->includes) {
t->includes = copytarget(t);
t->includes->original_target = t;
}
includes = t->includes;
includes->depends = targetlist( includes->depends,
list_new( L0, another_target ) );
}
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( p && t->flags & T_FLAG_TEMP &&
t->binding == T_BIND_MISSING &&
p->binding != T_BIND_MISSING )
{
t->binding = T_BIND_PARENTS;
ptime = p;
}
#ifdef OPT_SEMAPHORE
{
LIST *var = var_get( "JAM_SEMAPHORE" );
if( var )
{
TARGET *semaphore = bindtarget( var->string );
semaphore->progress = T_MAKE_SEMAPHORE;
t->semaphore = semaphore;
}
}
#endif
/* Step 2c: If its a file, search for headers. */
if( t->binding == T_BIND_EXISTS )
headers( t );
/* Step 2d: reset "on target" variables */
popsettings( s );
freesettings( s );
/*
* Pause for a little progress reporting
*/
if( DEBUG_BIND )
{
if( strcmp( t->name, t->boundname ) )
{
printf( "bind\t--\t%s%s: %s\n",
spaces( depth ), t->name, t->boundname );
}
switch( t->binding )
{
case T_BIND_UNBOUND:
case T_BIND_MISSING:
case T_BIND_PARENTS:
printf( "time\t--\t%s%s: %s\n",
spaces( depth ), t->name, target_bind[ t->binding ] );
break;
case T_BIND_EXISTS:
printf( "time\t--\t%s%s: %s",
spaces( depth ), t->name, ctime( &t->time ) );
break;
}
}
/*
* 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;
/* Seems like it's not relevant for us....
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 */
if( t->includes )
make0( t->includes, p, depth + 1, counts, anyhow );
/* 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 );
t->depends = targetchain( t->depends, incs );
/*
* 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 )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -