summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/targ.c
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-04-01 11:12:29 +0000
committerharti <harti@FreeBSD.org>2005-04-01 11:12:29 +0000
commit0f7b53389dfbc46114297551b8373c6c0c5d3fee (patch)
tree1d34a680c8eaa9dfd41ce379578ebea9360e3381 /usr.bin/make/targ.c
parented2180b0e1a5f2dc571aa2ff68ddab932c842012 (diff)
downloadFreeBSD-src-0f7b53389dfbc46114297551b8373c6c0c5d3fee.zip
FreeBSD-src-0f7b53389dfbc46114297551b8373c6c0c5d3fee.tar.gz
Style: fix indentation.
Diffstat (limited to 'usr.bin/make/targ.c')
-rw-r--r--usr.bin/make/targ.c575
1 files changed, 268 insertions, 307 deletions
diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c
index 55c1dc1..bbe666f 100644
--- a/usr.bin/make/targ.c
+++ b/usr.bin/make/targ.c
@@ -41,43 +41,40 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-/*-
- * targ.c --
- * Functions for maintaining the Lst allTargets. Target nodes are
+/*
+ * Functions for maintaining the Lst allTargets. Target nodes are
* kept in two structures: a Lst, maintained by the list library, and a
* hash table, maintained by the hash library.
*
* Interface:
- * Targ_Init Initialization procedure.
+ * Targ_Init Initialization procedure.
*
- * Targ_NewGN Create a new GNode for the passed target
- * (string). The node is *not* placed in the
- * hash table, though all its fields are
- * initialized.
+ * Targ_NewGN Create a new GNode for the passed target (string).
+ * The node is *not* placed in the hash table, though all
+ * its fields are initialized.
*
- * Targ_FindNode Find the node for a given target, creating
- * and storing it if it doesn't exist and the
- * flags are right (TARG_CREATE)
+ * Targ_FindNode Find the node for a given target, creating and storing
+ * it if it doesn't exist and the flags are right
+ * (TARG_CREATE)
*
- * Targ_FindList Given a list of names, find nodes for all
- * of them. If a name doesn't exist and the
- * TARG_NOCREATE flag was given, an error message
- * is printed. Else, if a name doesn't exist,
- * its node is created.
+ * Targ_FindList Given a list of names, find nodes for all of them. If a
+ * name doesn't exist and the TARG_NOCREATE flag was given,
+ * an error message is printed. Else, if a name doesn't
+ * exist, its node is created.
*
- * Targ_Ignore Return TRUE if errors should be ignored when
- * creating the given target.
+ * Targ_Ignore Return TRUE if errors should be ignored when creating
+ * the given target.
*
- * Targ_Silent Return TRUE if we should be silent when
- * creating the given target.
+ * Targ_Silent Return TRUE if we should be silent when creating the
+ * given target.
*
- * Targ_Precious Return TRUE if the target is precious and
- * should not be removed if we are interrupted.
+ * Targ_Precious Return TRUE if the target is precious and should not
+ * be removed if we are interrupted.
*
* Debugging:
- * Targ_PrintGraph Print out the entire graphm all variables
- * and statistics for the directory cache. Should
- * print something for suffixes, too, but...
+ * Targ_PrintGraph Print out the entire graphm all variables and statistics
+ * for the directory cache. Should print something for
+ * suffixes, too, but...
*/
#include <stdio.h>
@@ -100,28 +97,22 @@ static Hash_Table targets; /* a hash table of same */
#define HTSIZE 191 /* initial size of hash table */
-/*-
- *-----------------------------------------------------------------------
- * Targ_Init --
+/**
+ * Targ_Init
* Initialize this module
*
- * Results:
- * None
- *
* Side Effects:
* The allTargets list and the targets hash table are initialized
- *-----------------------------------------------------------------------
*/
void
Targ_Init(void)
{
- Hash_InitTable(&targets, HTSIZE);
+ Hash_InitTable(&targets, HTSIZE);
}
-/*-
- *-----------------------------------------------------------------------
- * Targ_NewGN --
+/**
+ * Targ_NewGN
* Create and initialize a new graph node
*
* Results:
@@ -130,43 +121,41 @@ Targ_Init(void)
*
* Side Effects:
* The gnode is added to the list of all gnodes.
- *-----------------------------------------------------------------------
*/
GNode *
Targ_NewGN(const char *name)
{
- GNode *gn;
-
- gn = emalloc(sizeof(GNode));
- gn->name = estrdup(name);
- gn->path = NULL;
- if (name[0] == '-' && name[1] == 'l') {
- gn->type = OP_LIB;
- } else {
- gn->type = 0;
- }
- gn->unmade = 0;
- gn->make = FALSE;
- gn->made = UNMADE;
- gn->childMade = FALSE;
- gn->order = 0;
- gn->mtime = gn->cmtime = 0;
- Lst_Init(&gn->iParents);
- Lst_Init(&gn->cohorts);
- Lst_Init(&gn->parents);
- Lst_Init(&gn->children);
- Lst_Init(&gn->successors);
- Lst_Init(&gn->preds);
- Lst_Init(&gn->context);
- Lst_Init(&gn->commands);
- gn->suffix = NULL;
-
- return (gn);
+ GNode *gn;
+
+ gn = emalloc(sizeof(GNode));
+ gn->name = estrdup(name);
+ gn->path = NULL;
+ if (name[0] == '-' && name[1] == 'l') {
+ gn->type = OP_LIB;
+ } else {
+ gn->type = 0;
+ }
+ gn->unmade = 0;
+ gn->make = FALSE;
+ gn->made = UNMADE;
+ gn->childMade = FALSE;
+ gn->order = 0;
+ gn->mtime = gn->cmtime = 0;
+ Lst_Init(&gn->iParents);
+ Lst_Init(&gn->cohorts);
+ Lst_Init(&gn->parents);
+ Lst_Init(&gn->children);
+ Lst_Init(&gn->successors);
+ Lst_Init(&gn->preds);
+ Lst_Init(&gn->context);
+ Lst_Init(&gn->commands);
+ gn->suffix = NULL;
+
+ return (gn);
}
-/*-
- *-----------------------------------------------------------------------
- * Targ_FindNode --
+/**
+ * Targ_FindNode
* Find a node in the list using the given name for matching
*
* Results:
@@ -176,37 +165,35 @@ Targ_NewGN(const char *name)
*
* Side Effects:
* Sometimes a node is created and added to the list
- *-----------------------------------------------------------------------
*/
GNode *
Targ_FindNode(const char *name, int flags)
{
- GNode *gn; /* node in that element */
- Hash_Entry *he; /* New or used hash entry for node */
- Boolean isNew; /* Set TRUE if Hash_CreateEntry had to create */
- /* an entry for the node */
-
- if (flags & TARG_CREATE) {
- he = Hash_CreateEntry(&targets, name, &isNew);
- if (isNew) {
- gn = Targ_NewGN(name);
- Hash_SetValue(he, gn);
- Lst_AtEnd(&allTargets, gn);
+ GNode *gn; /* node in that element */
+ Hash_Entry *he; /* New or used hash entry for node */
+ Boolean isNew; /* Set TRUE if Hash_CreateEntry had to create */
+ /* an entry for the node */
+
+ if (flags & TARG_CREATE) {
+ he = Hash_CreateEntry(&targets, name, &isNew);
+ if (isNew) {
+ gn = Targ_NewGN(name);
+ Hash_SetValue(he, gn);
+ Lst_AtEnd(&allTargets, gn);
+ }
+ } else {
+ he = Hash_FindEntry(&targets, name);
+ }
+
+ if (he == NULL) {
+ return (NULL);
+ } else {
+ return (Hash_GetValue(he));
}
- } else {
- he = Hash_FindEntry(&targets, name);
- }
-
- if (he == NULL) {
- return (NULL);
- } else {
- return (Hash_GetValue(he));
- }
}
-/*-
- *-----------------------------------------------------------------------
- * Targ_FindList --
+/**
+ * Targ_FindList
* Make a complete list of GNodes from the given list of names
*
* Results:
@@ -217,130 +204,107 @@ Targ_FindNode(const char *name, int flags)
* If flags is TARG_CREATE, nodes will be created for all names in
* names which do not yet have graph nodes. If flags is TARG_NOCREATE,
* an error message will be printed for each name which can't be found.
- * -----------------------------------------------------------------------
*/
void
Targ_FindList(Lst *nodes, Lst *names, int flags)
{
- LstNode *ln; /* name list element */
- GNode *gn; /* node in tLn */
- char *name;
-
- for (ln = Lst_First(names); ln != NULL; ln = Lst_Succ(ln)) {
- name = Lst_Datum(ln);
- gn = Targ_FindNode(name, flags);
- if (gn != NULL) {
- /*
- * Note: Lst_AtEnd must come before the Lst_Concat so the nodes
- * are added to the list in the order in which they were
- * encountered in the makefile.
- */
- Lst_AtEnd(nodes, gn);
- if (gn->type & OP_DOUBLEDEP) {
- Lst_Concat(nodes, &gn->cohorts, LST_CONCNEW);
- }
- } else if (flags == TARG_NOCREATE) {
- Error("\"%s\" -- target unknown.", name);
+ LstNode *ln; /* name list element */
+ GNode *gn; /* node in tLn */
+ char *name;
+
+ for (ln = Lst_First(names); ln != NULL; ln = Lst_Succ(ln)) {
+ name = Lst_Datum(ln);
+ gn = Targ_FindNode(name, flags);
+ if (gn != NULL) {
+ /*
+ * Note: Lst_AtEnd must come before the Lst_Concat so
+ * the nodes are added to the list in the order in which
+ * they were encountered in the makefile.
+ */
+ Lst_AtEnd(nodes, gn);
+ if (gn->type & OP_DOUBLEDEP) {
+ Lst_Concat(nodes, &gn->cohorts, LST_CONCNEW);
+ }
+
+ } else if (flags == TARG_NOCREATE) {
+ Error("\"%s\" -- target unknown.", name);
+ }
}
- }
}
-/*-
- *-----------------------------------------------------------------------
- * Targ_Ignore --
+/**
+ * Targ_Ignore
* Return true if should ignore errors when creating gn
*
* Results:
* TRUE if should ignore errors
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
*/
Boolean
Targ_Ignore(GNode *gn)
{
- if (ignoreErrors || (gn->type & OP_IGNORE)) {
- return (TRUE);
- } else {
- return (FALSE);
- }
+ if (ignoreErrors || (gn->type & OP_IGNORE)) {
+ return (TRUE);
+ } else {
+ return (FALSE);
+ }
}
-/*-
- *-----------------------------------------------------------------------
- * Targ_Silent --
+/**
+ * Targ_Silent
* Return true if be silent when creating gn
*
* Results:
* TRUE if should be silent
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
*/
Boolean
Targ_Silent(GNode *gn)
{
- if (beSilent || (gn->type & OP_SILENT)) {
- return (TRUE);
- } else {
- return (FALSE);
- }
+ if (beSilent || (gn->type & OP_SILENT)) {
+ return (TRUE);
+ } else {
+ return (FALSE);
+ }
}
-/*-
- *-----------------------------------------------------------------------
- * Targ_Precious --
+/**
+ * Targ_Precious
* See if the given target is precious
*
* Results:
* TRUE if it is precious. FALSE otherwise
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
*/
Boolean
Targ_Precious(GNode *gn)
{
- if (allPrecious || (gn->type & (OP_PRECIOUS | OP_DOUBLEDEP))) {
- return (TRUE);
- } else {
- return (FALSE);
- }
+ if (allPrecious || (gn->type & (OP_PRECIOUS | OP_DOUBLEDEP))) {
+ return (TRUE);
+ } else {
+ return (FALSE);
+ }
}
-/******************* DEBUG INFO PRINTING ****************/
+static GNode *mainTarg; /* the main target, as set by Targ_SetMain */
-static GNode *mainTarg; /* the main target, as set by Targ_SetMain */
-
-/*-
- *-----------------------------------------------------------------------
- * Targ_SetMain --
+/**
+ * Targ_SetMain
* Set our idea of the main target we'll be creating. Used for
* debugging output.
*
- * Results:
- * None.
- *
* Side Effects:
* "mainTarg" is set to the main target's node.
- *-----------------------------------------------------------------------
*/
void
Targ_SetMain(GNode *gn)
{
- mainTarg = gn;
+ mainTarg = gn;
}
-/*-
- *-----------------------------------------------------------------------
- * Targ_FmtTime --
+/**
+ * Targ_FmtTime
* Format a modification time in some reasonable way and return it.
*
* Results:
@@ -349,183 +313,180 @@ Targ_SetMain(GNode *gn)
* Side Effects:
* The time is placed in a static area, so it is overwritten
* with each call.
- *
- *-----------------------------------------------------------------------
*/
char *
Targ_FmtTime(time_t modtime)
{
- struct tm *parts;
- static char buf[128];
+ struct tm *parts;
+ static char buf[128];
- parts = localtime(&modtime);
+ parts = localtime(&modtime);
- strftime(buf, sizeof(buf), "%H:%M:%S %b %d, %Y", parts);
- buf[sizeof(buf) - 1] = '\0';
- return (buf);
+ strftime(buf, sizeof(buf), "%H:%M:%S %b %d, %Y", parts);
+ buf[sizeof(buf) - 1] = '\0';
+ return (buf);
}
-/*-
- *-----------------------------------------------------------------------
- * Targ_PrintType --
+/**
+ * Targ_PrintType
* Print out a type field giving only those attributes the user can
* set.
- *
- * Results:
- *
- * Side Effects:
- *
- *-----------------------------------------------------------------------
*/
void
Targ_PrintType(int type)
{
- int tbit;
-
-#define PRINTBIT(attr) case CONCAT(OP_,attr): printf("." #attr " "); break
-#define PRINTDBIT(attr) case CONCAT(OP_,attr): DEBUGF(TARG, ("." #attr " ")); break
-
- type &= ~OP_OPMASK;
-
- while (type) {
- tbit = 1 << (ffs(type) - 1);
- type &= ~tbit;
-
- switch(tbit) {
- PRINTBIT(OPTIONAL);
- PRINTBIT(USE);
- PRINTBIT(EXEC);
- PRINTBIT(IGNORE);
- PRINTBIT(PRECIOUS);
- PRINTBIT(SILENT);
- PRINTBIT(MAKE);
- PRINTBIT(JOIN);
- PRINTBIT(INVISIBLE);
- PRINTBIT(NOTMAIN);
- PRINTDBIT(LIB);
- /*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
- case OP_MEMBER: DEBUGF(TARG, (".MEMBER ")); break;
- PRINTDBIT(ARCHV);
+ int tbit;
+
+#define PRINTBIT(attr) \
+ case CONCAT(OP_,attr): \
+ printf("." #attr " "); \
+ break
+
+#define PRINTDBIT(attr) \
+ case CONCAT(OP_,attr): \
+ DEBUGF(TARG, ("." #attr " ")); \
+ break
+
+ type &= ~OP_OPMASK;
+
+ while (type) {
+ tbit = 1 << (ffs(type) - 1);
+ type &= ~tbit;
+
+ switch(tbit) {
+ PRINTBIT(OPTIONAL);
+ PRINTBIT(USE);
+ PRINTBIT(EXEC);
+ PRINTBIT(IGNORE);
+ PRINTBIT(PRECIOUS);
+ PRINTBIT(SILENT);
+ PRINTBIT(MAKE);
+ PRINTBIT(JOIN);
+ PRINTBIT(INVISIBLE);
+ PRINTBIT(NOTMAIN);
+ PRINTDBIT(LIB);
+ /*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
+ case OP_MEMBER:
+ DEBUGF(TARG, (".MEMBER "));
+ break;
+ PRINTDBIT(ARCHV);
+ }
}
- }
}
-/*-
- *-----------------------------------------------------------------------
- * TargPrintNode --
+/**
+ * TargPrintNode
* print the contents of a node
- *-----------------------------------------------------------------------
*/
static int
TargPrintNode(const GNode *gn, int pass)
{
- const LstNode *tln;
+ const LstNode *tln;
- if (!OP_NOP(gn->type)) {
- printf("#\n");
- if (gn == mainTarg) {
- printf("# *** MAIN TARGET ***\n");
- }
- if (pass == 2) {
- if (gn->unmade) {
- printf("# %d unmade children\n", gn->unmade);
- } else {
- printf("# No unmade children\n");
- }
- if (!(gn->type & (OP_JOIN | OP_USE | OP_EXEC))) {
- if (gn->mtime != 0) {
- printf("# last modified %s: %s\n",
- Targ_FmtTime(gn->mtime),
- (gn->made == UNMADE ? "unmade" :
- (gn->made == MADE ? "made" :
- (gn->made == UPTODATE ? "up-to-date" :
- "error when made"))));
- } else if (gn->made != UNMADE) {
- printf("# non-existent (maybe): %s\n",
- (gn->made == MADE ? "made" :
- (gn->made == UPTODATE ? "up-to-date" :
- (gn->made == ERROR ? "error when made" :
- "aborted"))));
- } else {
- printf("# unmade\n");
+ if (!OP_NOP(gn->type)) {
+ printf("#\n");
+ if (gn == mainTarg) {
+ printf("# *** MAIN TARGET ***\n");
+ }
+ if (pass == 2) {
+ if (gn->unmade) {
+ printf("# %d unmade children\n", gn->unmade);
+ } else {
+ printf("# No unmade children\n");
+ }
+ if (!(gn->type & (OP_JOIN | OP_USE | OP_EXEC))) {
+ if (gn->mtime != 0) {
+ printf("# last modified %s: %s\n",
+ Targ_FmtTime(gn->mtime),
+ gn->made == UNMADE ? "unmade" :
+ gn->made == MADE ? "made" :
+ gn->made == UPTODATE ? "up-to-date":
+ "error when made");
+ } else if (gn->made != UNMADE) {
+ printf("# non-existent (maybe): %s\n",
+ gn->made == MADE ? "made" :
+ gn->made == UPTODATE ? "up-to-date":
+ gn->made == ERROR?"error when made":
+ "aborted");
+ } else {
+ printf("# unmade\n");
+ }
+ }
+ if (!Lst_IsEmpty(&gn->iParents)) {
+ printf("# implicit parents: ");
+ LST_FOREACH(tln, &gn->iParents)
+ printf("%s ", ((const GNode *)
+ Lst_Datum(tln))->name);
+ printf("\n");
+ }
}
- }
- if (!Lst_IsEmpty(&gn->iParents)) {
- printf("# implicit parents: ");
- LST_FOREACH(tln, &gn->iParents)
+ if (!Lst_IsEmpty(&gn->parents)) {
+ printf("# parents: ");
+ LST_FOREACH(tln, &gn->parents)
+ printf("%s ", ((const GNode *)
+ Lst_Datum(tln))->name);
+ printf("\n");
+ }
+
+ printf("%-16s", gn->name);
+ switch (gn->type & OP_OPMASK) {
+ case OP_DEPENDS:
+ printf(": ");
+ break;
+ case OP_FORCE:
+ printf("! ");
+ break;
+ case OP_DOUBLEDEP:
+ printf(":: ");
+ break;
+ default:
+ break;
+ }
+ Targ_PrintType(gn->type);
+ LST_FOREACH(tln, &gn->children)
printf("%s ", ((const GNode *)Lst_Datum(tln))->name);
printf("\n");
- }
- }
- if (!Lst_IsEmpty(&gn->parents)) {
- printf("# parents: ");
- LST_FOREACH(tln, &gn->parents)
- printf("%s ", ((const GNode *)Lst_Datum(tln))->name);
- printf("\n");
- }
-
- printf("%-16s", gn->name);
- switch (gn->type & OP_OPMASK) {
- case OP_DEPENDS:
- printf(": "); break;
- case OP_FORCE:
- printf("! "); break;
- case OP_DOUBLEDEP:
- printf(":: "); break;
- default:
- break;
- }
- Targ_PrintType(gn->type);
- LST_FOREACH(tln, &gn->children)
- printf("%s ", ((const GNode *)Lst_Datum(tln))->name);
- printf("\n");
- LST_FOREACH(tln, &gn->commands)
- printf("\t%s\n", (const char *)Lst_Datum(tln));
- printf("\n\n");
- if (gn->type & OP_DOUBLEDEP) {
- LST_FOREACH(tln, &gn->cohorts)
- TargPrintNode((const GNode *)Lst_Datum(tln), pass);
+ LST_FOREACH(tln, &gn->commands)
+ printf("\t%s\n", (const char *)Lst_Datum(tln));
+ printf("\n\n");
+ if (gn->type & OP_DOUBLEDEP) {
+ LST_FOREACH(tln, &gn->cohorts)
+ TargPrintNode((const GNode *)Lst_Datum(tln),
+ pass);
+ }
}
- }
- return (0);
+ return (0);
}
-/*-
- *-----------------------------------------------------------------------
- * Targ_PrintGraph --
+/**
+ * Targ_PrintGraph
* Print the entire graph.
- *
- * Results:
- * none
- *
- * Side Effects:
- * lots o' output
- *-----------------------------------------------------------------------
*/
void
Targ_PrintGraph(int pass)
{
- const GNode *gn;
- const LstNode *tln;
-
- printf("#*** Input graph:\n");
- LST_FOREACH(tln, &allTargets)
- TargPrintNode((const GNode *)Lst_Datum(tln), pass);
- printf("\n\n");
-
- printf("#\n# Files that are only sources:\n");
- LST_FOREACH(tln, &allTargets) {
- gn = Lst_Datum(tln);
- if (OP_NOP(gn->type))
- printf("#\t%s [%s]\n", gn->name, gn->path ? gn->path : gn->name);
- }
-
- printf("#*** Global Variables:\n");
- Var_Dump(VAR_GLOBAL);
- printf("#*** Command-line Variables:\n");
- Var_Dump(VAR_CMD);
- printf("\n");
- Dir_PrintDirectories();
- printf("\n");
- Suff_PrintAll();
+ const GNode *gn;
+ const LstNode *tln;
+
+ printf("#*** Input graph:\n");
+ LST_FOREACH(tln, &allTargets)
+ TargPrintNode((const GNode *)Lst_Datum(tln), pass);
+ printf("\n\n");
+
+ printf("#\n# Files that are only sources:\n");
+ LST_FOREACH(tln, &allTargets) {
+ gn = Lst_Datum(tln);
+ if (OP_NOP(gn->type))
+ printf("#\t%s [%s]\n", gn->name,
+ gn->path ? gn->path : gn->name);
+ }
+
+ printf("#*** Global Variables:\n");
+ Var_Dump(VAR_GLOBAL);
+ printf("#*** Command-line Variables:\n");
+ Var_Dump(VAR_CMD);
+ printf("\n");
+ Dir_PrintDirectories();
+ printf("\n");
+ Suff_PrintAll();
}
OpenPOWER on IntegriCloud