| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: main.c,v 1.403 2020/10/27 08:05:20 rillig Exp $ */ | | 1 | /* $NetBSD: main.c,v 1.404 2020/10/27 17:09:09 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.403 2020/10/27 08:05:20 rillig Exp $"); | | 121 | MAKE_RCSID("$NetBSD: main.c,v 1.404 2020/10/27 17:09:09 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 */ |
| @@ -938,26 +938,35 @@ InitVarTargets(void) | | | @@ -938,26 +938,35 @@ InitVarTargets(void) |
938 | StringListNode *ln; | | 938 | StringListNode *ln; |
939 | | | 939 | |
940 | if (Lst_IsEmpty(opts.create)) { | | 940 | if (Lst_IsEmpty(opts.create)) { |
941 | Var_Set(".TARGETS", "", VAR_GLOBAL); | | 941 | Var_Set(".TARGETS", "", VAR_GLOBAL); |
942 | return; | | 942 | return; |
943 | } | | 943 | } |
944 | | | 944 | |
945 | for (ln = opts.create->first; ln != NULL; ln = ln->next) { | | 945 | for (ln = opts.create->first; ln != NULL; ln = ln->next) { |
946 | char *name = ln->datum; | | 946 | char *name = ln->datum; |
947 | Var_Append(".TARGETS", name, VAR_GLOBAL); | | 947 | Var_Append(".TARGETS", name, VAR_GLOBAL); |
948 | } | | 948 | } |
949 | } | | 949 | } |
950 | | | 950 | |
| | | 951 | static void |
| | | 952 | InitRandom(void) |
| | | 953 | { |
| | | 954 | struct timeval tv; |
| | | 955 | |
| | | 956 | gettimeofday(&tv, NULL); |
| | | 957 | srandom((unsigned int)(tv.tv_sec + tv.tv_usec)); |
| | | 958 | } |
| | | 959 | |
951 | static const char * | | 960 | static const char * |
952 | init_machine(const struct utsname *utsname) | | 961 | init_machine(const struct utsname *utsname) |
953 | { | | 962 | { |
954 | const char *machine = getenv("MACHINE"); | | 963 | const char *machine = getenv("MACHINE"); |
955 | if (machine != NULL) | | 964 | if (machine != NULL) |
956 | return machine; | | 965 | return machine; |
957 | | | 966 | |
958 | #ifdef MAKE_NATIVE | | 967 | #ifdef MAKE_NATIVE |
959 | return utsname->machine; | | 968 | return utsname->machine; |
960 | #else | | 969 | #else |
961 | #ifdef MAKE_MACHINE | | 970 | #ifdef MAKE_MACHINE |
962 | return MAKE_MACHINE; | | 971 | return MAKE_MACHINE; |
963 | #else | | 972 | #else |
| @@ -1245,41 +1254,36 @@ CleanUp(void) | | | @@ -1245,41 +1254,36 @@ CleanUp(void) |
1245 | * Side Effects: | | 1254 | * Side Effects: |
1246 | * The program exits when done. Targets are created. etc. etc. etc. | | 1255 | * The program exits when done. Targets are created. etc. etc. etc. |
1247 | */ | | 1256 | */ |
1248 | int | | 1257 | int |
1249 | main(int argc, char **argv) | | 1258 | main(int argc, char **argv) |
1250 | { | | 1259 | { |
1251 | Boolean outOfDate; /* FALSE if all targets up to date */ | | 1260 | Boolean outOfDate; /* FALSE if all targets up to date */ |
1252 | struct stat sa; | | 1261 | struct stat sa; |
1253 | char *p1; | | 1262 | char *p1; |
1254 | char mdpath[MAXPATHLEN]; | | 1263 | char mdpath[MAXPATHLEN]; |
1255 | const char *machine; | | 1264 | const char *machine; |
1256 | const char *machine_arch; | | 1265 | const char *machine_arch; |
1257 | char *syspath = getenv("MAKESYSPATH"); | | 1266 | char *syspath = getenv("MAKESYSPATH"); |
1258 | struct timeval rightnow; /* to initialize random seed */ | | | |
1259 | struct utsname utsname; | | 1267 | struct utsname utsname; |
1260 | | | 1268 | |
1261 | /* default to writing debug to stderr */ | | 1269 | /* default to writing debug to stderr */ |
1262 | opts.debug_file = stderr; | | 1270 | opts.debug_file = stderr; |
1263 | | | 1271 | |
1264 | #ifdef SIGINFO | | 1272 | #ifdef SIGINFO |
1265 | (void)bmake_signal(SIGINFO, siginfo); | | 1273 | (void)bmake_signal(SIGINFO, siginfo); |
1266 | #endif | | 1274 | #endif |
1267 | /* | | 1275 | |
1268 | * Set the seed to produce a different random sequence | | 1276 | InitRandom(); |
1269 | * on each program execution. | | | |
1270 | */ | | | |
1271 | gettimeofday(&rightnow, NULL); | | | |
1272 | srandom((unsigned int)(rightnow.tv_sec + rightnow.tv_usec)); | | | |
1273 | | | 1277 | |
1274 | if ((progname = strrchr(argv[0], '/')) != NULL) | | 1278 | if ((progname = strrchr(argv[0], '/')) != NULL) |
1275 | progname++; | | 1279 | progname++; |
1276 | else | | 1280 | else |
1277 | progname = argv[0]; | | 1281 | progname = argv[0]; |
1278 | | | 1282 | |
1279 | UnlimitFiles(); | | 1283 | UnlimitFiles(); |
1280 | | | 1284 | |
1281 | if (uname(&utsname) == -1) { | | 1285 | if (uname(&utsname) == -1) { |
1282 | (void)fprintf(stderr, "%s: uname failed (%s).\n", progname, | | 1286 | (void)fprintf(stderr, "%s: uname failed (%s).\n", progname, |
1283 | strerror(errno)); | | 1287 | strerror(errno)); |
1284 | exit(2); | | 1288 | exit(2); |
1285 | } | | 1289 | } |