| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: main.c,v 1.397 2020/10/27 07:28:33 rillig Exp $ */ | | 1 | /* $NetBSD: main.c,v 1.398 2020/10/27 07:34:36 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. |
| @@ -108,27 +108,27 @@ | | | @@ -108,27 +108,27 @@ |
108 | | | 108 | |
109 | #include <errno.h> | | 109 | #include <errno.h> |
110 | #include <signal.h> | | 110 | #include <signal.h> |
111 | #include <stdarg.h> | | 111 | #include <stdarg.h> |
112 | #include <time.h> | | 112 | #include <time.h> |
113 | | | 113 | |
114 | #include "make.h" | | 114 | #include "make.h" |
115 | #include "dir.h" | | 115 | #include "dir.h" |
116 | #include "job.h" | | 116 | #include "job.h" |
117 | #include "pathnames.h" | | 117 | #include "pathnames.h" |
118 | #include "trace.h" | | 118 | #include "trace.h" |
119 | | | 119 | |
120 | /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ | | 120 | /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ |
121 | MAKE_RCSID("$NetBSD: main.c,v 1.397 2020/10/27 07:28:33 rillig Exp $"); | | 121 | MAKE_RCSID("$NetBSD: main.c,v 1.398 2020/10/27 07:34:36 rillig Exp $"); |
122 | #if defined(MAKE_NATIVE) && !defined(lint) | | 122 | #if defined(MAKE_NATIVE) && !defined(lint) |
123 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " | | 123 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " |
124 | "The Regents of the University of California. " | | 124 | "The Regents of the University of California. " |
125 | "All rights reserved."); | | 125 | "All rights reserved."); |
126 | #endif | | 126 | #endif |
127 | | | 127 | |
128 | #ifndef DEFMAXLOCAL | | 128 | #ifndef DEFMAXLOCAL |
129 | #define DEFMAXLOCAL DEFMAXJOBS | | 129 | #define DEFMAXLOCAL DEFMAXJOBS |
130 | #endif | | 130 | #endif |
131 | | | 131 | |
132 | CmdOpts opts; | | 132 | CmdOpts opts; |
133 | time_t now; /* Time at start of make */ | | 133 | time_t now; /* Time at start of make */ |
134 | GNode *DEFAULT; /* .DEFAULT node */ | | 134 | GNode *DEFAULT; /* .DEFAULT node */ |
| @@ -1115,26 +1115,41 @@ InitDefIncPath(char *syspath) | | | @@ -1115,26 +1115,41 @@ InitDefIncPath(char *syspath) |
1115 | } else { | | 1115 | } else { |
1116 | char *dir = Dir_FindHereOrAbove(curdir, start + 4); | | 1116 | char *dir = Dir_FindHereOrAbove(curdir, start + 4); |
1117 | if (dir != NULL) { | | 1117 | if (dir != NULL) { |
1118 | (void)Dir_AddDir(defIncPath, dir); | | 1118 | (void)Dir_AddDir(defIncPath, dir); |
1119 | free(dir); | | 1119 | free(dir); |
1120 | } | | 1120 | } |
1121 | } | | 1121 | } |
1122 | } | | 1122 | } |
1123 | | | 1123 | |
1124 | if (syspath != defsyspath) | | 1124 | if (syspath != defsyspath) |
1125 | free(syspath); | | 1125 | free(syspath); |
1126 | } | | 1126 | } |
1127 | | | 1127 | |
| | | 1128 | static void |
| | | 1129 | ReadBuiltinRules(void) |
| | | 1130 | { |
| | | 1131 | StringList *sysMkPath = Lst_New(); |
| | | 1132 | Dir_Expand(_PATH_DEFSYSMK, |
| | | 1133 | Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath, |
| | | 1134 | sysMkPath); |
| | | 1135 | if (Lst_IsEmpty(sysMkPath)) |
| | | 1136 | Fatal("%s: no system rules (%s).", progname, _PATH_DEFSYSMK); |
| | | 1137 | if (!Lst_ForEachUntil(sysMkPath, ReadMakefileSucceeded, NULL)) |
| | | 1138 | Fatal("%s: cannot open %s.", progname, |
| | | 1139 | (char *)sysMkPath->first->datum); |
| | | 1140 | /* XXX: sysMkPath is not freed */ |
| | | 1141 | } |
| | | 1142 | |
1128 | /*- | | 1143 | /*- |
1129 | * main -- | | 1144 | * main -- |
1130 | * The main function, for obvious reasons. Initializes variables | | 1145 | * The main function, for obvious reasons. Initializes variables |
1131 | * and a few modules, then parses the arguments give it in the | | 1146 | * and a few modules, then parses the arguments give it in the |
1132 | * environment and on the command line. Reads the system makefile | | 1147 | * environment and on the command line. Reads the system makefile |
1133 | * followed by either Makefile, makefile or the file given by the | | 1148 | * followed by either Makefile, makefile or the file given by the |
1134 | * -f argument. Sets the .MAKEFLAGS PMake variable based on all the | | 1149 | * -f argument. Sets the .MAKEFLAGS PMake variable based on all the |
1135 | * flags it has received by then uses either the Make or the Compat | | 1150 | * flags it has received by then uses either the Make or the Compat |
1136 | * module to create the initial list of targets. | | 1151 | * module to create the initial list of targets. |
1137 | * | | 1152 | * |
1138 | * Results: | | 1153 | * Results: |
1139 | * If -q was given, exits -1 if anything was out-of-date. Else it exits | | 1154 | * If -q was given, exits -1 if anything was out-of-date. Else it exits |
1140 | * 0. | | 1155 | * 0. |
| @@ -1142,27 +1157,26 @@ InitDefIncPath(char *syspath) | | | @@ -1142,27 +1157,26 @@ InitDefIncPath(char *syspath) |
1142 | * Side Effects: | | 1157 | * Side Effects: |
1143 | * The program exits when done. Targets are created. etc. etc. etc. | | 1158 | * The program exits when done. Targets are created. etc. etc. etc. |
1144 | */ | | 1159 | */ |
1145 | int | | 1160 | int |
1146 | main(int argc, char **argv) | | 1161 | main(int argc, char **argv) |
1147 | { | | 1162 | { |
1148 | Boolean outOfDate; /* FALSE if all targets up to date */ | | 1163 | Boolean outOfDate; /* FALSE if all targets up to date */ |
1149 | struct stat sa; | | 1164 | struct stat sa; |
1150 | char *p1, *path; | | 1165 | char *p1, *path; |
1151 | char mdpath[MAXPATHLEN]; | | 1166 | char mdpath[MAXPATHLEN]; |
1152 | const char *machine; | | 1167 | const char *machine; |
1153 | const char *machine_arch; | | 1168 | const char *machine_arch; |
1154 | char *syspath = getenv("MAKESYSPATH"); | | 1169 | char *syspath = getenv("MAKESYSPATH"); |
1155 | StringList *sysMkPath; /* Path of sys.mk */ | | | |
1156 | struct timeval rightnow; /* to initialize random seed */ | | 1170 | struct timeval rightnow; /* to initialize random seed */ |
1157 | struct utsname utsname; | | 1171 | struct utsname utsname; |
1158 | | | 1172 | |
1159 | /* default to writing debug to stderr */ | | 1173 | /* default to writing debug to stderr */ |
1160 | opts.debug_file = stderr; | | 1174 | opts.debug_file = stderr; |
1161 | | | 1175 | |
1162 | #ifdef SIGINFO | | 1176 | #ifdef SIGINFO |
1163 | (void)bmake_signal(SIGINFO, siginfo); | | 1177 | (void)bmake_signal(SIGINFO, siginfo); |
1164 | #endif | | 1178 | #endif |
1165 | /* | | 1179 | /* |
1166 | * Set the seed to produce a different random sequence | | 1180 | * Set the seed to produce a different random sequence |
1167 | * on each program execution. | | 1181 | * on each program execution. |
1168 | */ | | 1182 | */ |
| @@ -1365,38 +1379,28 @@ main(int argc, char **argv) | | | @@ -1365,38 +1379,28 @@ main(int argc, char **argv) |
1365 | (void)time(&now); | | 1379 | (void)time(&now); |
1366 | | | 1380 | |
1367 | Trace_Log(MAKESTART, NULL); | | 1381 | Trace_Log(MAKESTART, NULL); |
1368 | | | 1382 | |
1369 | InitVarTargets(); | | 1383 | InitVarTargets(); |
1370 | | | 1384 | |
1371 | InitDefIncPath(syspath); | | 1385 | InitDefIncPath(syspath); |
1372 | | | 1386 | |
1373 | /* | | 1387 | /* |
1374 | * Read in the built-in rules first, followed by the specified | | 1388 | * Read in the built-in rules first, followed by the specified |
1375 | * makefiles, or the default makefile and Makefile, in that order, | | 1389 | * makefiles, or the default makefile and Makefile, in that order, |
1376 | * if no makefiles were given on the command line. | | 1390 | * if no makefiles were given on the command line. |
1377 | */ | | 1391 | */ |
1378 | if (!opts.noBuiltins) { | | 1392 | if (!opts.noBuiltins) |
1379 | sysMkPath = Lst_New(); | | 1393 | ReadBuiltinRules(); |
1380 | Dir_Expand(_PATH_DEFSYSMK, | | | |
1381 | Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath, | | | |
1382 | sysMkPath); | | | |
1383 | if (Lst_IsEmpty(sysMkPath)) | | | |
1384 | Fatal("%s: no system rules (%s).", progname, | | | |
1385 | _PATH_DEFSYSMK); | | | |
1386 | if (!Lst_ForEachUntil(sysMkPath, ReadMakefileSucceeded, NULL)) | | | |
1387 | Fatal("%s: cannot open %s.", progname, | | | |
1388 | (char *)sysMkPath->first->datum); | | | |
1389 | } | | | |
1390 | | | 1394 | |
1391 | if (opts.makefiles->first != NULL) { | | 1395 | if (opts.makefiles->first != NULL) { |
1392 | StringListNode *ln; | | 1396 | StringListNode *ln; |
1393 | | | 1397 | |
1394 | for (ln = opts.makefiles->first; ln != NULL; ln = ln->next) { | | 1398 | for (ln = opts.makefiles->first; ln != NULL; ln = ln->next) { |
1395 | if (ReadMakefile(ln->datum) != 0) | | 1399 | if (ReadMakefile(ln->datum) != 0) |
1396 | Fatal("%s: cannot open %s.", | | 1400 | Fatal("%s: cannot open %s.", |
1397 | progname, (char *)ln->datum); | | 1401 | progname, (char *)ln->datum); |
1398 | } | | 1402 | } |
1399 | } else { | | 1403 | } else { |
1400 | (void)Var_Subst("${" MAKEFILE_PREFERENCE "}", | | 1404 | (void)Var_Subst("${" MAKEFILE_PREFERENCE "}", |
1401 | VAR_CMD, VARE_WANTRES, &p1); | | 1405 | VAR_CMD, VARE_WANTRES, &p1); |
1402 | /* TODO: handle errors */ | | 1406 | /* TODO: handle errors */ |