1/* 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. --- 25 unchanged lines hidden (view full) --- 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)targ.c 8.2 (Berkeley) 3/19/94 39 */ 40 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: head/usr.bin/make/targ.c 138264 2004-12-01 10:29:20Z harti $"); |
43 44/*- 45 * targ.c -- 46 * Functions for maintaining the Lst allTargets. Target nodes are 47 * kept in two structures: a Lst, maintained by the list library, and a 48 * hash table, maintained by the hash library. 49 * 50 * Interface: --- 103 unchanged lines hidden (view full) --- 154 * The gnode is added to the list of all gnodes. 155 *----------------------------------------------------------------------- 156 */ 157GNode * 158Targ_NewGN(char *name) 159{ 160 GNode *gn; 161 |
162 gn = emalloc(sizeof(GNode)); |
163 gn->name = estrdup(name); |
164 gn->path = NULL; |
165 if (name[0] == '-' && name[1] == 'l') { 166 gn->type = OP_LIB; 167 } else { 168 gn->type = 0; 169 } 170 gn->unmade = 0; 171 gn->make = FALSE; 172 gn->made = UNMADE; --- 27 unchanged lines hidden (view full) --- 200 * 201 * Side Effects: 202 * None. 203 *----------------------------------------------------------------------- 204 */ 205static void 206TargFreeGN(void *gnp) 207{ |
208 GNode *gn = gnp; |
209 210 free(gn->name); 211 free(gn->path); 212 213 Lst_Destroy(gn->iParents, NOFREE); 214 Lst_Destroy(gn->cohorts, NOFREE); 215 Lst_Destroy(gn->parents, NOFREE); 216 Lst_Destroy(gn->children, NOFREE); 217 Lst_Destroy(gn->successors, NOFREE); 218 Lst_Destroy(gn->preds, NOFREE); 219 Lst_Destroy(gn->context, NOFREE); 220 Lst_Destroy(gn->commands, NOFREE); 221 free(gn); 222} 223 |
224/*- 225 *----------------------------------------------------------------------- 226 * Targ_FindNode -- 227 * Find a node in the list using the given name for matching 228 * 229 * Results: 230 * The node in the list if it was. If it wasn't, return NULL of 231 * flags was TARG_NOCREATE or the newly created and initialized node --- 11 unchanged lines hidden (view full) --- 243 Boolean isNew; /* Set TRUE if Hash_CreateEntry had to create */ 244 /* an entry for the node */ 245 246 if (flags & TARG_CREATE) { 247 he = Hash_CreateEntry(&targets, name, &isNew); 248 if (isNew) { 249 gn = Targ_NewGN(name); 250 Hash_SetValue (he, gn); |
251 Lst_AtEnd(allTargets, gn); |
252 } 253 } else { 254 he = Hash_FindEntry(&targets, name); 255 } 256 |
257 if (he == NULL) { |
258 return (NULL); 259 } else { |
260 return (Hash_GetValue(he)); |
261 } 262} 263 264/*- 265 *----------------------------------------------------------------------- 266 * Targ_FindList -- 267 * Make a complete list of GNodes from the given list of names 268 * --- 16 unchanged lines hidden (view full) --- 285 char *name; 286 287 nodes = Lst_Init(FALSE); 288 289 if (Lst_Open(names) == FAILURE) { 290 return (nodes); 291 } 292 while ((ln = Lst_Next(names)) != NULL) { |
293 name = Lst_Datum(ln); |
294 gn = Targ_FindNode(name, flags); 295 if (gn != NULL) { 296 /* 297 * Note: Lst_AtEnd must come before the Lst_Concat so the nodes 298 * are added to the list in the order in which they were 299 * encountered in the makefile. 300 */ |
301 Lst_AtEnd(nodes, gn); |
302 if (gn->type & OP_DOUBLEDEP) { 303 Lst_Concat(nodes, gn->cohorts, LST_CONCNEW); 304 } 305 } else if (flags == TARG_NOCREATE) { 306 Error("\"%s\" -- target unknown.", name); 307 } 308 } 309 Lst_Close(names); --- 197 unchanged lines hidden (view full) --- 507 *----------------------------------------------------------------------- 508 * TargPrintNode -- 509 * print the contents of a node 510 *----------------------------------------------------------------------- 511 */ 512static int 513TargPrintNode(void *gnp, void *passp) 514{ |
515 GNode *gn = gnp; |
516 int pass = *(int *)passp; 517 518 if (!OP_NOP(gn->type)) { 519 printf("#\n"); 520 if (gn == mainTarg) { 521 printf("# *** MAIN TARGET ***\n"); 522 } 523 if (pass == 2) { 524 if (gn->unmade) { 525 printf("# %d unmade children\n", gn->unmade); 526 } else { 527 printf("# No unmade children\n"); 528 } |
529 if (!(gn->type & (OP_JOIN | OP_USE | OP_EXEC))) { |
530 if (gn->mtime != 0) { 531 printf("# last modified %s: %s\n", 532 Targ_FmtTime(gn->mtime), 533 (gn->made == UNMADE ? "unmade" : 534 (gn->made == MADE ? "made" : 535 (gn->made == UPTODATE ? "up-to-date" : 536 "error when made")))); 537 } else if (gn->made != UNMADE) { 538 printf("# non-existent (maybe): %s\n", 539 (gn->made == MADE ? "made" : 540 (gn->made == UPTODATE ? "up-to-date" : 541 (gn->made == ERROR ? "error when made" : 542 "aborted")))); 543 } else { 544 printf("# unmade\n"); 545 } 546 } 547 if (!Lst_IsEmpty (gn->iParents)) { 548 printf("# implicit parents: "); |
549 Lst_ForEach(gn->iParents, TargPrintName, (void *)NULL); |
550 fputc('\n', stdout); 551 } 552 } 553 if (!Lst_IsEmpty (gn->parents)) { 554 printf("# parents: "); |
555 Lst_ForEach(gn->parents, TargPrintName, (void *)NULL); |
556 fputc('\n', stdout); 557 } 558 559 printf("%-16s", gn->name); 560 switch (gn->type & OP_OPMASK) { 561 case OP_DEPENDS: 562 printf(": "); break; 563 case OP_FORCE: 564 printf("! "); break; 565 case OP_DOUBLEDEP: 566 printf(":: "); break; 567 default: 568 break; 569 } 570 Targ_PrintType(gn->type); |
571 Lst_ForEach(gn->children, TargPrintName, (void *)NULL); |
572 fputc('\n', stdout); |
573 Lst_ForEach(gn->commands, Targ_PrintCmd, (void *)NULL); |
574 printf("\n\n"); 575 if (gn->type & OP_DOUBLEDEP) { |
576 Lst_ForEach(gn->cohorts, TargPrintNode, &pass); |
577 } 578 } 579 return (0); 580} 581 582/*- 583 *----------------------------------------------------------------------- 584 * TargPrintOnlySrc -- --- 5 unchanged lines hidden (view full) --- 590 * Side Effects: 591 * The name of each file is printed preceded by #\t 592 * 593 *----------------------------------------------------------------------- 594 */ 595static int 596TargPrintOnlySrc(void *gnp, void *dummy __unused) 597{ |
598 GNode *gn = gnp; |
599 600 if (OP_NOP(gn->type)) 601 printf("#\t%s [%s]\n", gn->name, gn->path ? gn->path : gn->name); 602 603 return (0); 604} 605 606/*- --- 6 unchanged lines hidden (view full) --- 613 * 614 * Side Effects: 615 * lots o' output 616 *----------------------------------------------------------------------- 617 */ 618void 619Targ_PrintGraph(int pass) 620{ |
621 |
622 printf("#*** Input graph:\n"); |
623 Lst_ForEach(allTargets, TargPrintNode, &pass); |
624 printf("\n\n"); 625 printf("#\n# Files that are only sources:\n"); |
626 Lst_ForEach(allTargets, TargPrintOnlySrc, (void *)NULL); |
627 printf("#*** Global Variables:\n"); 628 Var_Dump(VAR_GLOBAL); 629 printf("#*** Command-line Variables:\n"); 630 Var_Dump(VAR_CMD); 631 printf("\n"); 632 Dir_PrintDirectories(); 633 printf("\n"); 634 Suff_PrintAll(); 635} |