| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: main.c,v 1.320 2020/08/28 04:48:57 rillig Exp $ */ | | 1 | /* $NetBSD: main.c,v 1.321 2020/08/29 07:05:12 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,39 +59,39 @@ | | | @@ -59,39 +59,39 @@ |
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 |
72 | static char rcsid[] = "$NetBSD: main.c,v 1.320 2020/08/28 04:48:57 rillig Exp $"; | | 72 | static char rcsid[] = "$NetBSD: main.c,v 1.321 2020/08/29 07:05:12 rillig Exp $"; |
73 | #else | | 73 | #else |
74 | #include <sys/cdefs.h> | | 74 | #include <sys/cdefs.h> |
75 | #ifndef lint | | 75 | #ifndef lint |
76 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ | | 76 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ |
77 | The Regents of the University of California. All rights reserved."); | | 77 | The Regents of the University of California. All rights reserved."); |
78 | #endif /* not lint */ | | 78 | #endif /* not lint */ |
79 | | | 79 | |
80 | #ifndef lint | | 80 | #ifndef lint |
81 | #if 0 | | 81 | #if 0 |
82 | static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; | | 82 | static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; |
83 | #else | | 83 | #else |
84 | __RCSID("$NetBSD: main.c,v 1.320 2020/08/28 04:48:57 rillig Exp $"); | | 84 | __RCSID("$NetBSD: main.c,v 1.321 2020/08/29 07:05:12 rillig Exp $"); |
85 | #endif | | 85 | #endif |
86 | #endif /* not lint */ | | 86 | #endif /* not lint */ |
87 | #endif | | 87 | #endif |
88 | | | 88 | |
89 | /*- | | 89 | /*- |
90 | * main.c -- | | 90 | * main.c -- |
91 | * The main file for this entire program. Exit routines etc | | 91 | * The main file for this entire program. Exit routines etc |
92 | * reside here. | | 92 | * reside here. |
93 | * | | 93 | * |
94 | * Utility functions defined in this file: | | 94 | * Utility functions defined in this file: |
95 | * Main_ParseArgLine Takes a line of arguments, breaks them and | | 95 | * Main_ParseArgLine Takes a line of arguments, breaks them and |
96 | * treats them as if they were given when first | | 96 | * treats them as if they were given when first |
97 | * invoked. Used by the parse module to implement | | 97 | * invoked. Used by the parse module to implement |
| @@ -775,35 +775,29 @@ Main_SetVarObjdir(const char *var, const | | | @@ -775,35 +775,29 @@ Main_SetVarObjdir(const char *var, const |
775 | xpath = path; | | 775 | xpath = path; |
776 | xpath_freeIt = NULL; | | 776 | xpath_freeIt = NULL; |
777 | if (strchr(path, '$') != 0) | | 777 | if (strchr(path, '$') != 0) |
778 | xpath = xpath_freeIt = Var_Subst(path, VAR_GLOBAL, | | 778 | xpath = xpath_freeIt = Var_Subst(path, VAR_GLOBAL, |
779 | VARE_WANTRES); | | 779 | VARE_WANTRES); |
780 | | | 780 | |
781 | (void)Main_SetObjdir("%s%s", xpath, suffix); | | 781 | (void)Main_SetObjdir("%s%s", xpath, suffix); |
782 | | | 782 | |
783 | bmake_free(xpath_freeIt); | | 783 | bmake_free(xpath_freeIt); |
784 | bmake_free(path_freeIt); | | 784 | bmake_free(path_freeIt); |
785 | return TRUE; | | 785 | return TRUE; |
786 | } | | 786 | } |
787 | | | 787 | |
788 | /*- | | 788 | /* Return 0 if reading the makefile failed, for Lst_Find. */ |
789 | * ReadAllMakefiles -- | | | |
790 | * wrapper around ReadMakefile() to read all. | | | |
791 | * | | | |
792 | * Results: | | | |
793 | * TRUE if ok, FALSE on error | | | |
794 | */ | | | |
795 | static int | | 789 | static int |
796 | ReadAllMakefiles(const void *p, const void *q) | | 790 | ReadMakefileFailed(const void *p, const void *q) |
797 | { | | 791 | { |
798 | return ReadMakefile(p, q) == 0; | | 792 | return ReadMakefile(p, q) == 0; |
799 | } | | 793 | } |
800 | | | 794 | |
801 | int | | 795 | int |
802 | str2Lst_Append(Lst lp, char *str, const char *sep) | | 796 | str2Lst_Append(Lst lp, char *str, const char *sep) |
803 | { | | 797 | { |
804 | char *cp; | | 798 | char *cp; |
805 | int n; | | 799 | int n; |
806 | | | 800 | |
807 | if (!sep) | | 801 | if (!sep) |
808 | sep = " \t"; | | 802 | sep = " \t"; |
809 | | | 803 | |
| @@ -1329,27 +1323,27 @@ main(int argc, char **argv) | | | @@ -1329,27 +1323,27 @@ main(int argc, char **argv) |
1329 | sysMkPath); | | 1323 | sysMkPath); |
1330 | if (Lst_IsEmpty(sysMkPath)) | | 1324 | if (Lst_IsEmpty(sysMkPath)) |
1331 | Fatal("%s: no system rules (%s).", progname, | | 1325 | Fatal("%s: no system rules (%s).", progname, |
1332 | _PATH_DEFSYSMK); | | 1326 | _PATH_DEFSYSMK); |
1333 | ln = Lst_Find(sysMkPath, ReadMakefile, NULL); | | 1327 | ln = Lst_Find(sysMkPath, ReadMakefile, NULL); |
1334 | if (ln == NULL) | | 1328 | if (ln == NULL) |
1335 | Fatal("%s: cannot open %s.", progname, | | 1329 | Fatal("%s: cannot open %s.", progname, |
1336 | (char *)Lst_Datum(ln)); | | 1330 | (char *)Lst_Datum(ln)); |
1337 | } | | 1331 | } |
1338 | | | 1332 | |
1339 | if (!Lst_IsEmpty(makefiles)) { | | 1333 | if (!Lst_IsEmpty(makefiles)) { |
1340 | LstNode ln; | | 1334 | LstNode ln; |
1341 | | | 1335 | |
1342 | ln = Lst_Find(makefiles, ReadAllMakefiles, NULL); | | 1336 | ln = Lst_Find(makefiles, ReadMakefileFailed, NULL); |
1343 | if (ln != NULL) | | 1337 | if (ln != NULL) |
1344 | Fatal("%s: cannot open %s.", progname, | | 1338 | Fatal("%s: cannot open %s.", progname, |
1345 | (char *)Lst_Datum(ln)); | | 1339 | (char *)Lst_Datum(ln)); |
1346 | } else { | | 1340 | } else { |
1347 | p1 = Var_Subst("${" MAKEFILE_PREFERENCE "}", | | 1341 | p1 = Var_Subst("${" MAKEFILE_PREFERENCE "}", |
1348 | VAR_CMD, VARE_WANTRES); | | 1342 | VAR_CMD, VARE_WANTRES); |
1349 | if (p1) { | | 1343 | if (p1) { |
1350 | (void)str2Lst_Append(makefiles, p1, NULL); | | 1344 | (void)str2Lst_Append(makefiles, p1, NULL); |
1351 | (void)Lst_Find(makefiles, ReadMakefile, NULL); | | 1345 | (void)Lst_Find(makefiles, ReadMakefile, NULL); |
1352 | free(p1); | | 1346 | free(p1); |
1353 | } | | 1347 | } |
1354 | } | | 1348 | } |
1355 | | | 1349 | |
| @@ -1487,35 +1481,30 @@ main(int argc, char **argv) | | | @@ -1487,35 +1481,30 @@ main(int argc, char **argv) |
1487 | #endif | | 1481 | #endif |
1488 | Suff_End(); | | 1482 | Suff_End(); |
1489 | Targ_End(); | | 1483 | Targ_End(); |
1490 | Arch_End(); | | 1484 | Arch_End(); |
1491 | Var_End(); | | 1485 | Var_End(); |
1492 | Parse_End(); | | 1486 | Parse_End(); |
1493 | Dir_End(); | | 1487 | Dir_End(); |
1494 | Job_End(); | | 1488 | Job_End(); |
1495 | Trace_End(); | | 1489 | Trace_End(); |
1496 | | | 1490 | |
1497 | return outOfDate ? 1 : 0; | | 1491 | return outOfDate ? 1 : 0; |
1498 | } | | 1492 | } |
1499 | | | 1493 | |
1500 | /*- | | 1494 | /* Open and parse the given makefile, with all its side effects. |
1501 | * ReadMakefile -- | | | |
1502 | * Open and parse the given makefile. | | | |
1503 | * | | 1495 | * |
1504 | * Results: | | 1496 | * Results: |
1505 | * 0 if ok. -1 if couldn't open file. | | 1497 | * 0 if ok. -1 if couldn't open file. |
1506 | * | | | |
1507 | * Side Effects: | | | |
1508 | * lots | | | |
1509 | */ | | 1498 | */ |
1510 | static int | | 1499 | static int |
1511 | ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED) | | 1500 | ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED) |
1512 | { | | 1501 | { |
1513 | const char *fname = p; /* makefile to read */ | | 1502 | const char *fname = p; /* makefile to read */ |
1514 | int fd; | | 1503 | int fd; |
1515 | char *name, *path = NULL; | | 1504 | char *name, *path = NULL; |
1516 | | | 1505 | |
1517 | if (!strcmp(fname, "-")) { | | 1506 | if (!strcmp(fname, "-")) { |
1518 | Parse_File(NULL /*stdin*/, -1); | | 1507 | Parse_File(NULL /*stdin*/, -1); |
1519 | Var_Set("MAKEFILE", "", VAR_INTERNAL); | | 1508 | Var_Set("MAKEFILE", "", VAR_INTERNAL); |
1520 | } else { | | 1509 | } else { |
1521 | /* if we've chdir'd, rebuild the path name */ | | 1510 | /* if we've chdir'd, rebuild the path name */ |