targ.c (138232) | targ.c (138264) |
---|---|
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> | 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 138232 2004-11-30 17:46:29Z harti $"); | 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 | 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 = (GNode *)emalloc(sizeof(GNode)); | 162 gn = emalloc(sizeof(GNode)); |
163 gn->name = estrdup(name); | 163 gn->name = estrdup(name); |
164 gn->path = (char *)0; | 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{ | 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 = (GNode *) gnp; | 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 | 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 *----------------------------------------------------------------------- 227 * Targ_FindNode -- 228 * Find a node in the list using the given name for matching 229 * 230 * Results: 231 * The node in the list if it was. If it wasn't, return NULL of 232 * flags was TARG_NOCREATE or the newly created and initialized node --- 11 unchanged lines hidden (view full) --- 244 Boolean isNew; /* Set TRUE if Hash_CreateEntry had to create */ 245 /* an entry for the node */ 246 247 if (flags & TARG_CREATE) { 248 he = Hash_CreateEntry(&targets, name, &isNew); 249 if (isNew) { 250 gn = Targ_NewGN(name); 251 Hash_SetValue (he, gn); | 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); |
252 Lst_AtEnd(allTargets, (void *)gn); | 251 Lst_AtEnd(allTargets, gn); |
253 } 254 } else { 255 he = Hash_FindEntry(&targets, name); 256 } 257 | 252 } 253 } else { 254 he = Hash_FindEntry(&targets, name); 255 } 256 |
258 if (he == (Hash_Entry *) NULL) { | 257 if (he == NULL) { |
259 return (NULL); 260 } else { | 258 return (NULL); 259 } else { |
261 return ((GNode *)Hash_GetValue(he)); | 260 return (Hash_GetValue(he)); |
262 } 263} 264 265/*- 266 *----------------------------------------------------------------------- 267 * Targ_FindList -- 268 * Make a complete list of GNodes from the given list of names 269 * --- 16 unchanged lines hidden (view full) --- 286 char *name; 287 288 nodes = Lst_Init(FALSE); 289 290 if (Lst_Open(names) == FAILURE) { 291 return (nodes); 292 } 293 while ((ln = Lst_Next(names)) != NULL) { | 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) { |
294 name = (char *)Lst_Datum(ln); | 293 name = Lst_Datum(ln); |
295 gn = Targ_FindNode(name, flags); 296 if (gn != NULL) { 297 /* 298 * Note: Lst_AtEnd must come before the Lst_Concat so the nodes 299 * are added to the list in the order in which they were 300 * encountered in the makefile. 301 */ | 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 */ |
302 Lst_AtEnd(nodes, (void *)gn); | 301 Lst_AtEnd(nodes, gn); |
303 if (gn->type & OP_DOUBLEDEP) { 304 Lst_Concat(nodes, gn->cohorts, LST_CONCNEW); 305 } 306 } else if (flags == TARG_NOCREATE) { 307 Error("\"%s\" -- target unknown.", name); 308 } 309 } 310 Lst_Close(names); --- 197 unchanged lines hidden (view full) --- 508 *----------------------------------------------------------------------- 509 * TargPrintNode -- 510 * print the contents of a node 511 *----------------------------------------------------------------------- 512 */ 513static int 514TargPrintNode(void *gnp, void *passp) 515{ | 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{ |
516 GNode *gn = (GNode *)gnp; | 515 GNode *gn = gnp; |
517 int pass = *(int *)passp; 518 519 if (!OP_NOP(gn->type)) { 520 printf("#\n"); 521 if (gn == mainTarg) { 522 printf("# *** MAIN TARGET ***\n"); 523 } 524 if (pass == 2) { 525 if (gn->unmade) { 526 printf("# %d unmade children\n", gn->unmade); 527 } else { 528 printf("# No unmade children\n"); 529 } | 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 } |
530 if (! (gn->type & (OP_JOIN|OP_USE|OP_EXEC))) { | 529 if (!(gn->type & (OP_JOIN | OP_USE | OP_EXEC))) { |
531 if (gn->mtime != 0) { 532 printf("# last modified %s: %s\n", 533 Targ_FmtTime(gn->mtime), 534 (gn->made == UNMADE ? "unmade" : 535 (gn->made == MADE ? "made" : 536 (gn->made == UPTODATE ? "up-to-date" : 537 "error when made")))); 538 } else if (gn->made != UNMADE) { 539 printf("# non-existent (maybe): %s\n", 540 (gn->made == MADE ? "made" : 541 (gn->made == UPTODATE ? "up-to-date" : 542 (gn->made == ERROR ? "error when made" : 543 "aborted")))); 544 } else { 545 printf("# unmade\n"); 546 } 547 } 548 if (!Lst_IsEmpty (gn->iParents)) { 549 printf("# implicit parents: "); | 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: "); |
550 Lst_ForEach(gn->iParents, TargPrintName, (void *)0); | 549 Lst_ForEach(gn->iParents, TargPrintName, (void *)NULL); |
551 fputc('\n', stdout); 552 } 553 } 554 if (!Lst_IsEmpty (gn->parents)) { 555 printf("# parents: "); | 550 fputc('\n', stdout); 551 } 552 } 553 if (!Lst_IsEmpty (gn->parents)) { 554 printf("# parents: "); |
556 Lst_ForEach(gn->parents, TargPrintName, (void *)0); | 555 Lst_ForEach(gn->parents, TargPrintName, (void *)NULL); |
557 fputc('\n', stdout); 558 } 559 560 printf("%-16s", gn->name); 561 switch (gn->type & OP_OPMASK) { 562 case OP_DEPENDS: 563 printf(": "); break; 564 case OP_FORCE: 565 printf("! "); break; 566 case OP_DOUBLEDEP: 567 printf(":: "); break; 568 default: 569 break; 570 } 571 Targ_PrintType(gn->type); | 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); |
572 Lst_ForEach(gn->children, TargPrintName, (void *)0); | 571 Lst_ForEach(gn->children, TargPrintName, (void *)NULL); |
573 fputc('\n', stdout); | 572 fputc('\n', stdout); |
574 Lst_ForEach(gn->commands, Targ_PrintCmd, (void *)0); | 573 Lst_ForEach(gn->commands, Targ_PrintCmd, (void *)NULL); |
575 printf("\n\n"); 576 if (gn->type & OP_DOUBLEDEP) { | 574 printf("\n\n"); 575 if (gn->type & OP_DOUBLEDEP) { |
577 Lst_ForEach(gn->cohorts, TargPrintNode, (void *)&pass); | 576 Lst_ForEach(gn->cohorts, TargPrintNode, &pass); |
578 } 579 } 580 return (0); 581} 582 583/*- 584 *----------------------------------------------------------------------- 585 * TargPrintOnlySrc -- --- 5 unchanged lines hidden (view full) --- 591 * Side Effects: 592 * The name of each file is printed preceded by #\t 593 * 594 *----------------------------------------------------------------------- 595 */ 596static int 597TargPrintOnlySrc(void *gnp, void *dummy __unused) 598{ | 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{ |
599 GNode *gn = (GNode *)gnp; | 598 GNode *gn = gnp; |
600 601 if (OP_NOP(gn->type)) 602 printf("#\t%s [%s]\n", gn->name, gn->path ? gn->path : gn->name); 603 604 return (0); 605} 606 607/*- --- 6 unchanged lines hidden (view full) --- 614 * 615 * Side Effects: 616 * lots o' output 617 *----------------------------------------------------------------------- 618 */ 619void 620Targ_PrintGraph(int pass) 621{ | 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"); | 622 printf("#*** Input graph:\n"); |
623 Lst_ForEach(allTargets, TargPrintNode, (void *)&pass); | 623 Lst_ForEach(allTargets, TargPrintNode, &pass); |
624 printf("\n\n"); 625 printf("#\n# Files that are only sources:\n"); | 624 printf("\n\n"); 625 printf("#\n# Files that are only sources:\n"); |
626 Lst_ForEach(allTargets, TargPrintOnlySrc, (void *)0); | 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} | 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} |