| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: main.c,v 1.399 2020/10/27 07:38:08 rillig Exp $ */ | | 1 | /* $NetBSD: main.c,v 1.400 2020/10/27 07:44:43 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.399 2020/10/27 07:38:08 rillig Exp $"); | | 121 | MAKE_RCSID("$NetBSD: main.c,v 1.400 2020/10/27 07:44:43 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 */ |
| @@ -1130,49 +1130,81 @@ ReadBuiltinRules(void) | | | @@ -1130,49 +1130,81 @@ ReadBuiltinRules(void) |
1130 | { | | 1130 | { |
1131 | StringList *sysMkPath = Lst_New(); | | 1131 | StringList *sysMkPath = Lst_New(); |
1132 | Dir_Expand(_PATH_DEFSYSMK, | | 1132 | Dir_Expand(_PATH_DEFSYSMK, |
1133 | Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath, | | 1133 | Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath, |
1134 | sysMkPath); | | 1134 | sysMkPath); |
1135 | if (Lst_IsEmpty(sysMkPath)) | | 1135 | if (Lst_IsEmpty(sysMkPath)) |
1136 | Fatal("%s: no system rules (%s).", progname, _PATH_DEFSYSMK); | | 1136 | Fatal("%s: no system rules (%s).", progname, _PATH_DEFSYSMK); |
1137 | if (!Lst_ForEachUntil(sysMkPath, ReadMakefileSucceeded, NULL)) | | 1137 | if (!Lst_ForEachUntil(sysMkPath, ReadMakefileSucceeded, NULL)) |
1138 | Fatal("%s: cannot open %s.", progname, | | 1138 | Fatal("%s: cannot open %s.", progname, |
1139 | (char *)sysMkPath->first->datum); | | 1139 | (char *)sysMkPath->first->datum); |
1140 | /* XXX: sysMkPath is not freed */ | | 1140 | /* XXX: sysMkPath is not freed */ |
1141 | } | | 1141 | } |
1142 | | | 1142 | |
| | | 1143 | /* |
| | | 1144 | * For compatibility, look at the directories in the VPATH variable |
| | | 1145 | * and add them to the search path, if the variable is defined. The |
| | | 1146 | * variable's value is in the same format as the PATH environment |
| | | 1147 | * variable, i.e. <directory>:<directory>:<directory>... |
| | | 1148 | */ |
| | | 1149 | static void |
| | | 1150 | InitVpath(void) |
| | | 1151 | { |
| | | 1152 | char *vpath, savec, *path; |
| | | 1153 | if (!Var_Exists("VPATH", VAR_CMD)) |
| | | 1154 | return; |
| | | 1155 | |
| | | 1156 | (void)Var_Subst("${VPATH}", VAR_CMD, VARE_WANTRES, &vpath); |
| | | 1157 | /* TODO: handle errors */ |
| | | 1158 | path = vpath; |
| | | 1159 | do { |
| | | 1160 | char *cp; |
| | | 1161 | /* skip to end of directory */ |
| | | 1162 | for (cp = path; *cp != ':' && *cp != '\0'; cp++) |
| | | 1163 | continue; |
| | | 1164 | /* Save terminator character so know when to stop */ |
| | | 1165 | savec = *cp; |
| | | 1166 | *cp = '\0'; |
| | | 1167 | /* Add directory to search path */ |
| | | 1168 | (void)Dir_AddDir(dirSearchPath, path); |
| | | 1169 | *cp = savec; |
| | | 1170 | path = cp + 1; |
| | | 1171 | } while (savec == ':'); |
| | | 1172 | free(vpath); |
| | | 1173 | } |
| | | 1174 | |
1143 | /*- | | 1175 | /*- |
1144 | * main -- | | 1176 | * main -- |
1145 | * The main function, for obvious reasons. Initializes variables | | 1177 | * The main function, for obvious reasons. Initializes variables |
1146 | * and a few modules, then parses the arguments give it in the | | 1178 | * and a few modules, then parses the arguments give it in the |
1147 | * environment and on the command line. Reads the system makefile | | 1179 | * environment and on the command line. Reads the system makefile |
1148 | * followed by either Makefile, makefile or the file given by the | | 1180 | * followed by either Makefile, makefile or the file given by the |
1149 | * -f argument. Sets the .MAKEFLAGS PMake variable based on all the | | 1181 | * -f argument. Sets the .MAKEFLAGS PMake variable based on all the |
1150 | * flags it has received by then uses either the Make or the Compat | | 1182 | * flags it has received by then uses either the Make or the Compat |
1151 | * module to create the initial list of targets. | | 1183 | * module to create the initial list of targets. |
1152 | * | | 1184 | * |
1153 | * Results: | | 1185 | * Results: |
1154 | * If -q was given, exits -1 if anything was out-of-date. Else it exits | | 1186 | * If -q was given, exits -1 if anything was out-of-date. Else it exits |
1155 | * 0. | | 1187 | * 0. |
1156 | * | | 1188 | * |
1157 | * Side Effects: | | 1189 | * Side Effects: |
1158 | * The program exits when done. Targets are created. etc. etc. etc. | | 1190 | * The program exits when done. Targets are created. etc. etc. etc. |
1159 | */ | | 1191 | */ |
1160 | int | | 1192 | int |
1161 | main(int argc, char **argv) | | 1193 | main(int argc, char **argv) |
1162 | { | | 1194 | { |
1163 | Boolean outOfDate; /* FALSE if all targets up to date */ | | 1195 | Boolean outOfDate; /* FALSE if all targets up to date */ |
1164 | struct stat sa; | | 1196 | struct stat sa; |
1165 | char *p1, *path; | | 1197 | char *p1; |
1166 | char mdpath[MAXPATHLEN]; | | 1198 | char mdpath[MAXPATHLEN]; |
1167 | const char *machine; | | 1199 | const char *machine; |
1168 | const char *machine_arch; | | 1200 | const char *machine_arch; |
1169 | char *syspath = getenv("MAKESYSPATH"); | | 1201 | char *syspath = getenv("MAKESYSPATH"); |
1170 | struct timeval rightnow; /* to initialize random seed */ | | 1202 | struct timeval rightnow; /* to initialize random seed */ |
1171 | struct utsname utsname; | | 1203 | struct utsname utsname; |
1172 | | | 1204 | |
1173 | /* default to writing debug to stderr */ | | 1205 | /* default to writing debug to stderr */ |
1174 | opts.debug_file = stderr; | | 1206 | opts.debug_file = stderr; |
1175 | | | 1207 | |
1176 | #ifdef SIGINFO | | 1208 | #ifdef SIGINFO |
1177 | (void)bmake_signal(SIGINFO, siginfo); | | 1209 | (void)bmake_signal(SIGINFO, siginfo); |
1178 | #endif | | 1210 | #endif |
| @@ -1460,54 +1492,27 @@ main(int argc, char **argv) | | | @@ -1460,54 +1492,27 @@ main(int argc, char **argv) |
1460 | */ | | 1492 | */ |
1461 | if (!opts.compatMake && !forceJobs) { | | 1493 | if (!opts.compatMake && !forceJobs) { |
1462 | opts.compatMake = TRUE; | | 1494 | opts.compatMake = TRUE; |
1463 | } | | 1495 | } |
1464 | | | 1496 | |
1465 | if (!opts.compatMake) | | 1497 | if (!opts.compatMake) |
1466 | Job_ServerStart(maxJobTokens, jp_0, jp_1); | | 1498 | Job_ServerStart(maxJobTokens, jp_0, jp_1); |
1467 | DEBUG5(JOB, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n", | | 1499 | DEBUG5(JOB, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n", |
1468 | jp_0, jp_1, opts.maxJobs, maxJobTokens, opts.compatMake ? 1 : 0); | | 1500 | jp_0, jp_1, opts.maxJobs, maxJobTokens, opts.compatMake ? 1 : 0); |
1469 | | | 1501 | |
1470 | if (!opts.printVars) | | 1502 | if (!opts.printVars) |
1471 | Main_ExportMAKEFLAGS(TRUE); /* initial export */ | | 1503 | Main_ExportMAKEFLAGS(TRUE); /* initial export */ |
1472 | | | 1504 | |
1473 | | | 1505 | InitVpath(); |
1474 | /* | | | |
1475 | * For compatibility, look at the directories in the VPATH variable | | | |
1476 | * and add them to the search path, if the variable is defined. The | | | |
1477 | * variable's value is in the same format as the PATH envariable, i.e. | | | |
1478 | * <directory>:<directory>:<directory>... | | | |
1479 | */ | | | |
1480 | if (Var_Exists("VPATH", VAR_CMD)) { | | | |
1481 | char *vpath, savec; | | | |
1482 | | | | |
1483 | (void)Var_Subst("${VPATH}", VAR_CMD, VARE_WANTRES, &vpath); | | | |
1484 | /* TODO: handle errors */ | | | |
1485 | path = vpath; | | | |
1486 | do { | | | |
1487 | char *cp; | | | |
1488 | /* skip to end of directory */ | | | |
1489 | for (cp = path; *cp != ':' && *cp != '\0'; cp++) | | | |
1490 | continue; | | | |
1491 | /* Save terminator character so know when to stop */ | | | |
1492 | savec = *cp; | | | |
1493 | *cp = '\0'; | | | |
1494 | /* Add directory to search path */ | | | |
1495 | (void)Dir_AddDir(dirSearchPath, path); | | | |
1496 | *cp = savec; | | | |
1497 | path = cp + 1; | | | |
1498 | } while (savec == ':'); | | | |
1499 | free(vpath); | | | |
1500 | } | | | |
1501 | | | 1506 | |
1502 | /* | | 1507 | /* |
1503 | * Now that all search paths have been read for suffixes et al, it's | | 1508 | * Now that all search paths have been read for suffixes et al, it's |
1504 | * time to add the default search path to their lists... | | 1509 | * time to add the default search path to their lists... |
1505 | */ | | 1510 | */ |
1506 | Suff_DoPaths(); | | 1511 | Suff_DoPaths(); |
1507 | | | 1512 | |
1508 | /* | | 1513 | /* |
1509 | * Propagate attributes through :: dependency lists. | | 1514 | * Propagate attributes through :: dependency lists. |
1510 | */ | | 1515 | */ |
1511 | Targ_Propagate(); | | 1516 | Targ_Propagate(); |
1512 | | | 1517 | |
1513 | /* print the initial graph, if the user requested it */ | | 1518 | /* print the initial graph, if the user requested it */ |