Fri Aug 28 17:27:21 2020 UTC ()
make(1): clean up suffix handling


(rillig)
diff -r1.126 -r1.127 src/usr.bin/make/suff.c

cvs diff -r1.126 -r1.127 src/usr.bin/make/suff.c (expand / switch to unified diff)

--- src/usr.bin/make/suff.c 2020/08/28 06:37:21 1.126
+++ src/usr.bin/make/suff.c 2020/08/28 17:27:21 1.127
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: suff.c,v 1.126 2020/08/28 06:37:21 rillig Exp $ */ 1/* $NetBSD: suff.c,v 1.127 2020/08/28 17:27:21 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: suff.c,v 1.126 2020/08/28 06:37:21 rillig Exp $"; 72static char rcsid[] = "$NetBSD: suff.c,v 1.127 2020/08/28 17:27:21 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; 77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
78#else 78#else
79__RCSID("$NetBSD: suff.c,v 1.126 2020/08/28 06:37:21 rillig Exp $"); 79__RCSID("$NetBSD: suff.c,v 1.127 2020/08/28 17:27:21 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * suff.c -- 85 * suff.c --
86 * Functions to maintain suffix lists and find implicit dependents 86 * Functions to maintain suffix lists and find implicit dependents
87 * using suffix transformation rules 87 * using suffix transformation rules
88 * 88 *
89 * Interface: 89 * Interface:
90 * Suff_Init Initialize all things to do with suffixes. 90 * Suff_Init Initialize all things to do with suffixes.
91 * 91 *
92 * Suff_End Cleanup the module 92 * Suff_End Cleanup the module
@@ -2422,42 +2422,33 @@ sfnd_return: @@ -2422,42 +2422,33 @@ sfnd_return:
2422 *----------------------------------------------------------------------- 2422 *-----------------------------------------------------------------------
2423 */ 2423 */
2424 2424
2425void 2425void
2426Suff_FindDeps(GNode *gn) 2426Suff_FindDeps(GNode *gn)
2427{ 2427{
2428 2428
2429 SuffFindDeps(gn, srclist); 2429 SuffFindDeps(gn, srclist);
2430 while (SuffRemoveSrc(srclist)) 2430 while (SuffRemoveSrc(srclist))
2431 continue; 2431 continue;
2432} 2432}
2433 2433
2434 2434
2435/* 
2436 * Input: 
2437 * gn node we're dealing with 
2438 * 
2439 */ 
2440static void 2435static void
2441SuffFindDeps(GNode *gn, Lst slst) 2436SuffFindDeps(GNode *gn, Lst slst)
2442{ 2437{
2443 if (gn->type & OP_DEPS_FOUND) { 2438 if (gn->type & OP_DEPS_FOUND)
2444 /* 
2445 * If dependencies already found, no need to do it again... 
2446 */ 
2447 return; 2439 return;
2448 } else { 2440 gn->type |= OP_DEPS_FOUND;
2449 gn->type |= OP_DEPS_FOUND; 2441
2450 } 
2451 /* 2442 /*
2452 * Make sure we have these set, may get revised below. 2443 * Make sure we have these set, may get revised below.
2453 */ 2444 */
2454 Var_Set(TARGET, gn->path ? gn->path : gn->name, gn); 2445 Var_Set(TARGET, gn->path ? gn->path : gn->name, gn);
2455 Var_Set(PREFIX, gn->name, gn); 2446 Var_Set(PREFIX, gn->name, gn);
2456 2447
2457 if (DEBUG(SUFF)) { 2448 if (DEBUG(SUFF)) {
2458 fprintf(debug_file, "SuffFindDeps (%s)\n", gn->name); 2449 fprintf(debug_file, "SuffFindDeps (%s)\n", gn->name);
2459 } 2450 }
2460 2451
2461 if (gn->type & OP_ARCHV) { 2452 if (gn->type & OP_ARCHV) {
2462 SuffFindArchiveDeps(gn, slst); 2453 SuffFindArchiveDeps(gn, slst);
2463 } else if (gn->type & OP_LIB) { 2454 } else if (gn->type & OP_LIB) {
@@ -2492,105 +2483,78 @@ SuffFindDeps(GNode *gn, Lst slst) @@ -2492,105 +2483,78 @@ SuffFindDeps(GNode *gn, Lst slst)
2492 } else { 2483 } else {
2493 SuffFindNormalDeps(gn, slst); 2484 SuffFindNormalDeps(gn, slst);
2494 } 2485 }
2495} 2486}
2496 2487
2497/*- 2488/*-
2498 *----------------------------------------------------------------------- 2489 *-----------------------------------------------------------------------
2499 * Suff_SetNull -- 2490 * Suff_SetNull --
2500 * Define which suffix is the null suffix. 2491 * Define which suffix is the null suffix.
2501 * 2492 *
2502 * Input: 2493 * Input:
2503 * name Name of null suffix 2494 * name Name of null suffix
2504 * 2495 *
2505 * Results: 
2506 * None. 
2507 * 
2508 * Side Effects: 2496 * Side Effects:
2509 * 'suffNull' is altered. 2497 * 'suffNull' is altered.
2510 * 2498 *
2511 * Notes: 2499 * Notes:
2512 * Need to handle the changing of the null suffix gracefully so the 2500 * Need to handle the changing of the null suffix gracefully so the
2513 * old transformation rules don't just go away. 2501 * old transformation rules don't just go away.
2514 * 
2515 *----------------------------------------------------------------------- 2502 *-----------------------------------------------------------------------
2516 */ 2503 */
2517void 2504void
2518Suff_SetNull(char *name) 2505Suff_SetNull(char *name)
2519{ 2506{
2520 Suff *s; 2507 Suff *s;
2521 LstNode ln; 2508 LstNode ln;
2522 2509
2523 ln = Lst_Find(sufflist, SuffSuffHasNameP, name); 2510 ln = Lst_Find(sufflist, SuffSuffHasNameP, name);
2524 if (ln != NULL) { 2511 if (ln != NULL) {
2525 s = Lst_Datum(ln); 2512 s = Lst_Datum(ln);
2526 if (suffNull != NULL) { 2513 if (suffNull != NULL) {
2527 suffNull->flags &= ~SUFF_NULL; 2514 suffNull->flags &= ~SUFF_NULL;
2528 } 2515 }
2529 s->flags |= SUFF_NULL; 2516 s->flags |= SUFF_NULL;
2530 /* 2517 /*
2531 * XXX: Here's where the transformation mangling would take place 2518 * XXX: Here's where the transformation mangling would take place
2532 */ 2519 */
2533 suffNull = s; 2520 suffNull = s;
2534 } else { 2521 } else {
2535 Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.", 2522 Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.",
2536 name); 2523 name);
2537 } 2524 }
2538} 2525}
2539 2526
2540/*- 2527/* Initialize the suffixes module. */
2541 *----------------------------------------------------------------------- 
2542 * Suff_Init -- 
2543 * Initialize suffixes module 
2544 * 
2545 * Results: 
2546 * None 
2547 * 
2548 * Side Effects: 
2549 * Many 
2550 *----------------------------------------------------------------------- 
2551 */ 
2552void 2528void
2553Suff_Init(void) 2529Suff_Init(void)
2554{ 2530{
2555#ifdef CLEANUP 2531#ifdef CLEANUP
2556 suffClean = Lst_Init(); 2532 suffClean = Lst_Init();
2557 sufflist = Lst_Init(); 2533 sufflist = Lst_Init();
2558#endif 2534#endif
2559 srclist = Lst_Init(); 2535 srclist = Lst_Init();
2560 transforms = Lst_Init(); 2536 transforms = Lst_Init();
2561 2537
2562 /* 2538 /*
2563 * Create null suffix for single-suffix rules (POSIX). The thing doesn't 2539 * Create null suffix for single-suffix rules (POSIX). The thing doesn't
2564 * actually go on the suffix list or everyone will think that's its 2540 * actually go on the suffix list or everyone will think that's its
2565 * suffix. 2541 * suffix.
2566 */ 2542 */
2567 Suff_ClearSuffixes(); 2543 Suff_ClearSuffixes();
2568} 2544}
2569 2545
2570 2546
2571/*- 2547/* Clean up the suffixes module. */
2572 *---------------------------------------------------------------------- 
2573 * Suff_End -- 
2574 * Cleanup the this module 
2575 * 
2576 * Results: 
2577 * None 
2578 * 
2579 * Side Effects: 
2580 * The memory is free'd. 
2581 *---------------------------------------------------------------------- 
2582 */ 
2583 
2584void 2548void
2585Suff_End(void) 2549Suff_End(void)
2586{ 2550{
2587#ifdef CLEANUP 2551#ifdef CLEANUP
2588 Lst_Destroy(sufflist, SuffFree); 2552 Lst_Destroy(sufflist, SuffFree);
2589 Lst_Destroy(suffClean, SuffFree); 2553 Lst_Destroy(suffClean, SuffFree);
2590 if (suffNull) 2554 if (suffNull)
2591 SuffFree(suffNull); 2555 SuffFree(suffNull);
2592 Lst_Free(srclist); 2556 Lst_Free(srclist);
2593 Lst_Free(transforms); 2557 Lst_Free(transforms);
2594#endif 2558#endif
2595} 2559}
2596 2560