main.c (198199) | main.c (201526) |
---|---|
1/*- 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. --- 32 unchanged lines hidden (view full) --- 41#ifndef lint 42#if 0 43static char copyright[] = 44"@(#) Copyright (c) 1988, 1989, 1990, 1993\n\ 45 The Regents of the University of California. All rights reserved.\n"; 46#endif 47#endif /* not lint */ 48#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. --- 32 unchanged lines hidden (view full) --- 41#ifndef lint 42#if 0 43static char copyright[] = 44"@(#) Copyright (c) 1988, 1989, 1990, 1993\n\ 45 The Regents of the University of California. All rights reserved.\n"; 46#endif 47#endif /* not lint */ 48#include <sys/cdefs.h> |
49__FBSDID("$FreeBSD: head/usr.bin/make/main.c 198199 2009-10-18 11:28:31Z fjoe $"); | 49__FBSDID("$FreeBSD: head/usr.bin/make/main.c 201526 2010-01-04 18:57:22Z obrien $"); |
50 51/* 52 * main.c 53 * The main file for this entire program. Exit routines etc 54 * reside here. 55 * 56 * Utility functions defined in this file: 57 * Main_ParseArgLine --- 305 unchanged lines hidden (view full) --- 363 * Various global and local flags will be set depending on the flags 364 * given 365 */ 366static void 367MainParseArgs(int argc, char **argv) 368{ 369 int c; 370 Boolean found_dd = FALSE; | 50 51/* 52 * main.c 53 * The main file for this entire program. Exit routines etc 54 * reside here. 55 * 56 * Utility functions defined in this file: 57 * Main_ParseArgLine --- 305 unchanged lines hidden (view full) --- 363 * Various global and local flags will be set depending on the flags 364 * given 365 */ 366static void 367MainParseArgs(int argc, char **argv) 368{ 369 int c; 370 Boolean found_dd = FALSE; |
371 char found_dir[MAXPATHLEN + 1]; /* for searching for sys.mk */ |
|
371 372rearg: 373 optind = 1; /* since we're called more than once */ 374 optreset = 1; 375#define OPTFLAGS "ABC:D:d:E:ef:I:ij:km:nPpQqrSstV:vXx:" 376 for (;;) { 377 if ((optind < argc) && strcmp(argv[optind], "--") == 0) { 378 found_dd = TRUE; --- 10 unchanged lines hidden (view full) --- 389 case 'B': 390 compatMake = TRUE; 391 MFLAGS_append("-B", NULL); 392 unsetenv("MAKE_JOBS_FIFO"); 393 break; 394 case 'C': 395 if (chdir(optarg) == -1) 396 err(1, "chdir %s", optarg); | 372 373rearg: 374 optind = 1; /* since we're called more than once */ 375 optreset = 1; 376#define OPTFLAGS "ABC:D:d:E:ef:I:ij:km:nPpQqrSstV:vXx:" 377 for (;;) { 378 if ((optind < argc) && strcmp(argv[optind], "--") == 0) { 379 found_dd = TRUE; --- 10 unchanged lines hidden (view full) --- 390 case 'B': 391 compatMake = TRUE; 392 MFLAGS_append("-B", NULL); 393 unsetenv("MAKE_JOBS_FIFO"); 394 break; 395 case 'C': 396 if (chdir(optarg) == -1) 397 err(1, "chdir %s", optarg); |
398 if (getcwd(curdir, MAXPATHLEN) == NULL) 399 err(2, NULL); |
|
397 break; 398 case 'D': 399 Var_SetGlobal(optarg, "1"); 400 MFLAGS_append("-D", optarg); 401 break; 402 case 'd': { 403 char *modules = optarg; 404 --- 82 unchanged lines hidden (view full) --- 487 MFLAGS_append("-j", optarg); 488 break; 489 } 490 case 'k': 491 keepgoing = TRUE; 492 MFLAGS_append("-k", NULL); 493 break; 494 case 'm': | 400 break; 401 case 'D': 402 Var_SetGlobal(optarg, "1"); 403 MFLAGS_append("-D", optarg); 404 break; 405 case 'd': { 406 char *modules = optarg; 407 --- 82 unchanged lines hidden (view full) --- 490 MFLAGS_append("-j", optarg); 491 break; 492 } 493 case 'k': 494 keepgoing = TRUE; 495 MFLAGS_append("-k", NULL); 496 break; 497 case 'm': |
495 Path_AddDir(&sysIncPath, optarg); | 498 /* look for magic parent directory search string */ 499 if (strncmp(".../", optarg, 4) == 0) { 500 if (!Dir_FindHereOrAbove(curdir, optarg + 4, 501 found_dir, sizeof(found_dir))) 502 break; /* nothing doing */ 503 Path_AddDir(&sysIncPath, found_dir); 504 } else { 505 Path_AddDir(&sysIncPath, optarg); 506 } |
496 MFLAGS_append("-m", optarg); 497 break; 498 case 'n': 499 noExecute = TRUE; 500 MFLAGS_append("-n", NULL); 501 break; 502 case 'P': 503 usePipes = FALSE; --- 360 unchanged lines hidden (view full) --- 864 const char *machine_cpu; 865 Boolean outOfDate = TRUE; /* FALSE if all targets up to date */ 866 const char *p; 867 const char *pathp; 868 const char *path; 869 char mdpath[MAXPATHLEN]; 870 char obpath[MAXPATHLEN]; 871 char cdpath[MAXPATHLEN]; | 507 MFLAGS_append("-m", optarg); 508 break; 509 case 'n': 510 noExecute = TRUE; 511 MFLAGS_append("-n", NULL); 512 break; 513 case 'P': 514 usePipes = FALSE; --- 360 unchanged lines hidden (view full) --- 875 const char *machine_cpu; 876 Boolean outOfDate = TRUE; /* FALSE if all targets up to date */ 877 const char *p; 878 const char *pathp; 879 const char *path; 880 char mdpath[MAXPATHLEN]; 881 char obpath[MAXPATHLEN]; 882 char cdpath[MAXPATHLEN]; |
883 char found_dir[MAXPATHLEN + 1]; /* for searching for sys.mk */ |
|
872 char *cp = NULL, *start; 873 874 save_argv = argv; 875 save_makeflags = getenv("MAKEFLAGS"); 876 if (save_makeflags != NULL) 877 save_makeflags = estrdup(save_makeflags); 878 879 /* --- 137 unchanged lines hidden (view full) --- 1017 snprintf(tmp, sizeof(tmp), "%u", getpid()); 1018 Var_SetGlobal(".MAKE.PID", tmp); 1019 snprintf(tmp, sizeof(tmp), "%u", getppid()); 1020 Var_SetGlobal(".MAKE.PPID", tmp); 1021 } 1022 Job_SetPrefix(); 1023 1024 /* | 884 char *cp = NULL, *start; 885 886 save_argv = argv; 887 save_makeflags = getenv("MAKEFLAGS"); 888 if (save_makeflags != NULL) 889 save_makeflags = estrdup(save_makeflags); 890 891 /* --- 137 unchanged lines hidden (view full) --- 1029 snprintf(tmp, sizeof(tmp), "%u", getpid()); 1030 Var_SetGlobal(".MAKE.PID", tmp); 1031 snprintf(tmp, sizeof(tmp), "%u", getppid()); 1032 Var_SetGlobal(".MAKE.PPID", tmp); 1033 } 1034 Job_SetPrefix(); 1035 1036 /* |
1037 * Find where we are... 1038 */ 1039 if (getcwd(curdir, MAXPATHLEN) == NULL) 1040 err(2, NULL); 1041 1042 /* |
|
1025 * First snag things out of the MAKEFLAGS environment 1026 * variable. Then parse the command line arguments. 1027 */ 1028 Main_ParseArgLine(getenv("MAKEFLAGS"), 1); 1029 1030 MainParseArgs(argc, argv); 1031 1032 /* | 1043 * First snag things out of the MAKEFLAGS environment 1044 * variable. Then parse the command line arguments. 1045 */ 1046 Main_ParseArgLine(getenv("MAKEFLAGS"), 1); 1047 1048 MainParseArgs(argc, argv); 1049 1050 /* |
1033 * Find where we are... | 1051 * Verify that cwd is sane (after -C may have changed it). |
1034 */ | 1052 */ |
1035 if (getcwd(curdir, MAXPATHLEN) == NULL) 1036 err(2, NULL); 1037 | |
1038 { 1039 struct stat sa; 1040 1041 if (stat(curdir, &sa) == -1) 1042 err(2, "%s", curdir); 1043 } 1044 1045 /* --- 81 unchanged lines hidden (view full) --- 1127 1128 1129 /* 1130 * If no user-supplied system path was given (through the -m option) 1131 * add the directories from the DEFSYSPATH (more than one may be given 1132 * as dir1:...:dirn) to the system include path. 1133 */ 1134 if (TAILQ_EMPTY(&sysIncPath)) { | 1053 { 1054 struct stat sa; 1055 1056 if (stat(curdir, &sa) == -1) 1057 err(2, "%s", curdir); 1058 } 1059 1060 /* --- 81 unchanged lines hidden (view full) --- 1142 1143 1144 /* 1145 * If no user-supplied system path was given (through the -m option) 1146 * add the directories from the DEFSYSPATH (more than one may be given 1147 * as dir1:...:dirn) to the system include path. 1148 */ 1149 if (TAILQ_EMPTY(&sysIncPath)) { |
1135 char syspath[] = PATH_DEFSYSPATH; | 1150 char defsyspath[] = PATH_DEFSYSPATH; 1151 char *syspath = getenv("MAKESYSPATH"); |
1136 | 1152 |
1153 /* 1154 * If no user-supplied system path was given (thru -m option) 1155 * add the directories from the DEFSYSPATH (more than one may 1156 * be given as dir1:...:dirn) to the system include path. 1157 */ 1158 if (syspath == NULL || *syspath == '\0') 1159 syspath = defsyspath; 1160 else 1161 syspath = estrdup(syspath); 1162 |
|
1137 for (start = syspath; *start != '\0'; start = cp) { 1138 for (cp = start; *cp != '\0' && *cp != ':'; cp++) 1139 continue; | 1163 for (start = syspath; *start != '\0'; start = cp) { 1164 for (cp = start; *cp != '\0' && *cp != ':'; cp++) 1165 continue; |
1140 if (*cp == '\0') { 1141 Path_AddDir(&sysIncPath, start); 1142 } else { | 1166 if (*cp == ':') { |
1143 *cp++ = '\0'; | 1167 *cp++ = '\0'; |
1168 } 1169 /* look for magic parent directory search string */ 1170 if (strncmp(".../", start, 4) == 0) { 1171 if (Dir_FindHereOrAbove(curdir, start + 4, 1172 found_dir, sizeof(found_dir))) { 1173 Path_AddDir(&sysIncPath, found_dir); 1174 } 1175 } else { |
|
1144 Path_AddDir(&sysIncPath, start); 1145 } 1146 } | 1176 Path_AddDir(&sysIncPath, start); 1177 } 1178 } |
1179 if (syspath != defsyspath) 1180 free(syspath); |
|
1147 } 1148 1149 /* 1150 * Read in the built-in rules first, followed by the specified 1151 * makefile, if it was (makefile != (char *) NULL), or the default 1152 * Makefile and makefile, in that order, if it wasn't. 1153 */ 1154 if (!noBuiltins) { --- 159 unchanged lines hidden --- | 1181 } 1182 1183 /* 1184 * Read in the built-in rules first, followed by the specified 1185 * makefile, if it was (makefile != (char *) NULL), or the default 1186 * Makefile and makefile, in that order, if it wasn't. 1187 */ 1188 if (!noBuiltins) { --- 159 unchanged lines hidden --- |