| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: main.c,v 1.406 2020/10/27 18:12:15 rillig Exp $ */ | | 1 | /* $NetBSD: main.c,v 1.407 2020/10/27 18:16:19 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.406 2020/10/27 18:12:15 rillig Exp $"); | | 121 | MAKE_RCSID("$NetBSD: main.c,v 1.407 2020/10/27 18:16:19 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 */ |
| @@ -1045,26 +1045,49 @@ HandlePWD(const struct stat *curdir_st) | | | @@ -1045,26 +1045,49 @@ HandlePWD(const struct stat *curdir_st) |
1045 | if (makeobjdir != NULL && strchr(makeobjdir, '$') != NULL) | | 1045 | if (makeobjdir != NULL && strchr(makeobjdir, '$') != NULL) |
1046 | goto ignore_pwd; | | 1046 | goto ignore_pwd; |
1047 | | | 1047 | |
1048 | if (stat(pwd, &pwd_st) == 0 && | | 1048 | if (stat(pwd, &pwd_st) == 0 && |
1049 | curdir_st->st_ino == pwd_st.st_ino && | | 1049 | curdir_st->st_ino == pwd_st.st_ino && |
1050 | curdir_st->st_dev == pwd_st.st_dev) | | 1050 | curdir_st->st_dev == pwd_st.st_dev) |
1051 | (void)strncpy(curdir, pwd, MAXPATHLEN); | | 1051 | (void)strncpy(curdir, pwd, MAXPATHLEN); |
1052 | | | 1052 | |
1053 | ignore_pwd: | | 1053 | ignore_pwd: |
1054 | bmake_free(makeobjdir_freeIt); | | 1054 | bmake_free(makeobjdir_freeIt); |
1055 | } | | 1055 | } |
1056 | #endif | | 1056 | #endif |
1057 | | | 1057 | |
| | | 1058 | /* |
| | | 1059 | * Find the .OBJDIR. If MAKEOBJDIRPREFIX, or failing that, |
| | | 1060 | * MAKEOBJDIR is set in the environment, try only that value |
| | | 1061 | * and fall back to .CURDIR if it does not exist. |
| | | 1062 | * |
| | | 1063 | * Otherwise, try _PATH_OBJDIR.MACHINE-MACHINE_ARCH, _PATH_OBJDIR.MACHINE, |
| | | 1064 | * and * finally _PATH_OBJDIRPREFIX`pwd`, in that order. If none |
| | | 1065 | * of these paths exist, just use .CURDIR. |
| | | 1066 | */ |
| | | 1067 | static void |
| | | 1068 | InitObjdir(const char *machine, const char *machine_arch) |
| | | 1069 | { |
| | | 1070 | Dir_InitDir(curdir); |
| | | 1071 | (void)Main_SetObjdir("%s", curdir); |
| | | 1072 | |
| | | 1073 | if (!Main_SetVarObjdir("MAKEOBJDIRPREFIX", curdir) && |
| | | 1074 | !Main_SetVarObjdir("MAKEOBJDIR", "") && |
| | | 1075 | !Main_SetObjdir("%s.%s-%s", _PATH_OBJDIR, machine, machine_arch) && |
| | | 1076 | !Main_SetObjdir("%s.%s", _PATH_OBJDIR, machine) && |
| | | 1077 | !Main_SetObjdir("%s", _PATH_OBJDIR)) |
| | | 1078 | (void)Main_SetObjdir("%s%s", _PATH_OBJDIRPREFIX, curdir); |
| | | 1079 | } |
| | | 1080 | |
1058 | /* get rid of resource limit on file descriptors */ | | 1081 | /* get rid of resource limit on file descriptors */ |
1059 | static void | | 1082 | static void |
1060 | UnlimitFiles(void) | | 1083 | UnlimitFiles(void) |
1061 | { | | 1084 | { |
1062 | #if defined(MAKE_NATIVE) || (defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)) | | 1085 | #if defined(MAKE_NATIVE) || (defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)) |
1063 | struct rlimit rl; | | 1086 | struct rlimit rl; |
1064 | if (getrlimit(RLIMIT_NOFILE, &rl) != -1 && | | 1087 | if (getrlimit(RLIMIT_NOFILE, &rl) != -1 && |
1065 | rl.rlim_cur != rl.rlim_max) { | | 1088 | rl.rlim_cur != rl.rlim_max) { |
1066 | rl.rlim_cur = rl.rlim_max; | | 1089 | rl.rlim_cur = rl.rlim_max; |
1067 | (void)setrlimit(RLIMIT_NOFILE, &rl); | | 1090 | (void)setrlimit(RLIMIT_NOFILE, &rl); |
1068 | } | | 1091 | } |
1069 | #endif | | 1092 | #endif |
1070 | } | | 1093 | } |
| @@ -1432,44 +1455,27 @@ main(int argc, char **argv) | | | @@ -1432,44 +1455,27 @@ main(int argc, char **argv) |
1432 | * Verify that cwd is sane. | | 1455 | * Verify that cwd is sane. |
1433 | */ | | 1456 | */ |
1434 | if (stat(curdir, &sa) == -1) { | | 1457 | if (stat(curdir, &sa) == -1) { |
1435 | (void)fprintf(stderr, "%s: %s: %s.\n", | | 1458 | (void)fprintf(stderr, "%s: %s: %s.\n", |
1436 | progname, curdir, strerror(errno)); | | 1459 | progname, curdir, strerror(errno)); |
1437 | exit(2); | | 1460 | exit(2); |
1438 | } | | 1461 | } |
1439 | | | 1462 | |
1440 | #ifndef NO_PWD_OVERRIDE | | 1463 | #ifndef NO_PWD_OVERRIDE |
1441 | HandlePWD(&sa); | | 1464 | HandlePWD(&sa); |
1442 | #endif | | 1465 | #endif |
1443 | Var_Set(".CURDIR", curdir, VAR_GLOBAL); | | 1466 | Var_Set(".CURDIR", curdir, VAR_GLOBAL); |
1444 | | | 1467 | |
1445 | /* | | 1468 | InitObjdir(machine, machine_arch); |
1446 | * Find the .OBJDIR. If MAKEOBJDIRPREFIX, or failing that, | | | |
1447 | * MAKEOBJDIR is set in the environment, try only that value | | | |
1448 | * and fall back to .CURDIR if it does not exist. | | | |
1449 | * | | | |
1450 | * Otherwise, try _PATH_OBJDIR.MACHINE-MACHINE_ARCH, _PATH_OBJDIR.MACHINE, | | | |
1451 | * and * finally _PATH_OBJDIRPREFIX`pwd`, in that order. If none | | | |
1452 | * of these paths exist, just use .CURDIR. | | | |
1453 | */ | | | |
1454 | Dir_InitDir(curdir); | | | |
1455 | (void)Main_SetObjdir("%s", curdir); | | | |
1456 | | | | |
1457 | if (!Main_SetVarObjdir("MAKEOBJDIRPREFIX", curdir) && | | | |
1458 | !Main_SetVarObjdir("MAKEOBJDIR", "") && | | | |
1459 | !Main_SetObjdir("%s.%s-%s", _PATH_OBJDIR, machine, machine_arch) && | | | |
1460 | !Main_SetObjdir("%s.%s", _PATH_OBJDIR, machine) && | | | |
1461 | !Main_SetObjdir("%s", _PATH_OBJDIR)) | | | |
1462 | (void)Main_SetObjdir("%s%s", _PATH_OBJDIRPREFIX, curdir); | | | |
1463 | | | 1469 | |
1464 | /* | | 1470 | /* |
1465 | * Initialize archive, target and suffix modules in preparation for | | 1471 | * Initialize archive, target and suffix modules in preparation for |
1466 | * parsing the makefile(s) | | 1472 | * parsing the makefile(s) |
1467 | */ | | 1473 | */ |
1468 | Arch_Init(); | | 1474 | Arch_Init(); |
1469 | Targ_Init(); | | 1475 | Targ_Init(); |
1470 | Suff_Init(); | | 1476 | Suff_Init(); |
1471 | Trace_Init(tracefile); | | 1477 | Trace_Init(tracefile); |
1472 | | | 1478 | |
1473 | DEFAULT = NULL; | | 1479 | DEFAULT = NULL; |
1474 | (void)time(&now); | | 1480 | (void)time(&now); |
1475 | | | 1481 | |