Changeset 280 in kBuild for branches/GNU/src/gmake/main.c
- Timestamp:
- May 16, 2005 4:54:02 PM (20 years ago)
- Location:
- branches/GNU/src/gmake
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gmake
- Property svn:ignore
-
old new 34 34 README.DOS 35 35 README.W32 36 README.OS2 36 37 aclocal.m4 37 38 autom4te.cache
-
- Property svn:ignore
-
branches/GNU/src/gmake/main.c
r153 r280 1 1 /* Argument parsing and main program of GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 3 2002, 2003 Free Software Foundation, Inc.3 2002, 2003, 2005 Free Software Foundation, Inc. 4 4 This file is part of GNU Make. 5 5 … … 36 36 #ifdef WINDOWS32 37 37 #include <windows.h> 38 #include <io.h> 38 39 #include "pathstuff.h" 39 40 #endif … … 44 45 #ifdef HAVE_FCNTL_H 45 46 # include <fcntl.h> 47 #endif 48 49 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) 50 # define SET_STACK_SIZE 51 #endif 52 53 #ifdef SET_STACK_SIZE 54 # include <sys/resource.h> 46 55 #endif 47 56 … … 186 195 int default_keep_going_flag = 0; 187 196 197 /* Nonzero means check symlink mtimes. */ 198 199 int check_symlink_flag = 0; 200 188 201 /* Nonzero means print directory before starting and when done (-w). */ 189 202 … … 207 220 unsigned int job_slots = 1; 208 221 unsigned int default_job_slots = 1; 222 static unsigned int master_job_slots = 0; 209 223 210 224 /* Value of job_slots that means no limit. */ … … 260 274 261 275 int always_make_flag = 0; 276 277 /* If nonzero, we're in the "try to rebuild makefiles" phase. */ 278 279 int rebuilding_makefiles = 0; 280 281 /* Remember the original value of the SHELL variable, from the environment. */ 282 283 struct variable shell_var; 284 262 285 263 286 … … 301 324 Don't start multiple jobs unless load is below N.\n"), 302 325 N_("\ 326 -L, --check-symlink-times Use the latest mtime between symlinks and target.\n"), 327 N_("\ 303 328 -n, --just-print, --dry-run, --recon\n\ 304 329 Don't actually run any commands; just print them.\n"), … … 348 373 #endif 349 374 { 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0, 350 375 "environment-overrides", }, 351 376 { 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0, "file" }, 352 377 { 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0, "help" }, 353 378 { 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0, 354 379 "ignore-errors" }, 355 380 { 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0, 356 381 "include-dir" }, 357 382 { 'j', positive_int, (char *) &job_slots, 1, 1, 0, (char *) &inf_jobs, 358 383 (char *) &default_job_slots, "jobs" }, 359 384 { CHAR_MAX+2, string, (char *) &jobserver_fds, 1, 1, 0, 0, 0, 360 385 "jobserver-fds" }, 361 386 { 'k', flag, (char *) &keep_going_flag, 1, 1, 0, 0, 362 387 (char *) &default_keep_going_flag, "keep-going" }, 363 388 #ifndef NO_FLOAT 364 389 { 'l', floating, (char *) &max_load_average, 1, 1, 0, 365 366 390 (char *) &default_load_average, (char *) &default_load_average, 391 "load-average" }, 367 392 #else 368 393 { 'l', positive_int, (char *) &max_load_average, 1, 1, 0, 369 (char *) &default_load_average, (char *) &default_load_average, 370 "load-average" }, 371 #endif 394 (char *) &default_load_average, (char *) &default_load_average, 395 "load-average" }, 396 #endif 397 { 'L', flag, (char *) &check_symlink_flag, 1, 1, 0, 0, 0, 398 "check-symlink-times" }, 372 399 { 'm', ignore, 0, 0, 0, 0, 0, 0, 0 }, 373 400 { 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0, "just-print" }, 374 401 { 'o', string, (char *) &old_files, 0, 0, 0, 0, 0, "old-file" }, 375 402 { 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0, 376 403 "print-data-base" }, 377 404 { 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0, "question" }, 378 405 { 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0, 379 406 "no-builtin-rules" }, 380 407 { 'R', flag, (char *) &no_builtin_variables_flag, 1, 1, 0, 0, 0, 381 408 "no-builtin-variables" }, 382 409 { 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0, "silent" }, 383 410 { 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0, 0, … … 386 413 { 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0, "version" }, 387 414 { 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0, 388 415 "print-directory" }, 389 416 { CHAR_MAX+3, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0, 390 417 "no-print-directory" }, 391 418 { 'W', string, (char *) &new_files, 0, 0, 0, 0, 0, "what-if" }, 392 419 { CHAR_MAX+4, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0, 393 420 "warn-undefined-variables" }, 394 421 { 0 } 395 422 }; … … 446 473 447 474 struct file *default_goal_file; 475 476 /* Pointer to the value of the .DEFAULT_GOAL special 477 variable. */ 478 char ** default_goal_name; 448 479 449 480 /* Pointer to structure for the file .DEFAULT … … 549 580 /* Toggle -d on receipt of SIGUSR1. */ 550 581 582 #ifdef SIGUSR1 551 583 static RETSIGTYPE 552 584 debug_signal_handler (int sig UNUSED) … … 554 586 db_level = db_level ? DB_NONE : DB_BASIC; 555 587 } 588 #endif 556 589 557 590 static void … … 696 729 { 697 730 int sh_found = 0; 698 char* search_token; 731 char *search_token; 732 char *tokend; 699 733 PATH_VAR(sh_path); 700 734 extern char *default_shell; … … 705 739 search_token = token; 706 740 707 if (!no_default_sh_exe && 708 (token == NULL || !strcmp(search_token, default_shell))) { 741 742 /* If the user explicitly requests the DOS cmd shell, obey that request. 743 However, make sure that's what they really want by requiring the value 744 of SHELL either equal, or have a final path element of, "cmd" or 745 "cmd.exe" case-insensitive. */ 746 tokend = search_token + strlen (search_token) - 3; 747 if (((tokend == search_token 748 || (tokend > search_token 749 && (tokend[-1] == '/' || tokend[-1] == '\\'))) 750 && !strcmpi (tokend, "cmd")) 751 || ((tokend - 4 == search_token 752 || (tokend - 4 > search_token 753 && (tokend[-5] == '/' || tokend[-5] == '\\'))) 754 && !strcmpi (tokend - 4, "cmd.exe"))) { 755 batch_mode_shell = 1; 756 unixy_shell = 0; 757 sh_found = 0; 758 } else if (!no_default_sh_exe && 759 (token == NULL || !strcmp (search_token, default_shell))) { 709 760 /* no new information, path already set or known */ 710 761 sh_found = 1; … … 718 769 } else { 719 770 char *p; 720 struct variable *v = lookup_variable ("Path", 4); 721 722 /* 723 * Search Path for shell 724 */ 771 struct variable *v = lookup_variable ("PATH", 4); 772 773 /* Search Path for shell */ 725 774 if (v && v->value) { 726 775 char *ep; … … 841 890 struct file *f; 842 891 int i; 892 int makefile_status = MAKE_SUCCESS; 843 893 char **p; 844 894 struct dep *read_makefiles; … … 853 903 unixy_shell = 0; 854 904 no_default_sh_exe = 1; 905 #endif 906 907 #ifdef SET_STACK_SIZE 908 /* Get rid of any avoidable limit on stack size. */ 909 { 910 struct rlimit rlim; 911 912 /* Set the stack limit huge so that alloca does not fail. */ 913 if (getrlimit (RLIMIT_STACK, &rlim) == 0) 914 { 915 rlim.rlim_cur = rlim.rlim_max; 916 setrlimit (RLIMIT_STACK, &rlim); 917 } 918 } 855 919 #endif 856 920 … … 978 1042 program = argv[0] + 1; 979 1043 #endif 1044 #ifdef WINDOWS32 1045 if (program == 0) 1046 { 1047 /* Extract program from full path */ 1048 int argv0_len; 1049 char *p = strrchr (argv[0], '\\'); 1050 if (!p) 1051 p = argv[0]; 1052 argv0_len = strlen(p); 1053 if (argv0_len > 4 1054 && streq (&p[argv0_len - 4], ".exe")) 1055 { 1056 /* Remove .exe extension */ 1057 p[argv0_len - 4] = '\0'; 1058 /* Increment past the initial '\' */ 1059 program = p + 1; 1060 } 1061 } 1062 #endif 980 1063 if (program == 0) 981 1064 program = argv[0]; … … 998 1081 { 999 1082 #ifdef HAVE_GETCWD 1000 perror_with_name ("getcwd :", "");1083 perror_with_name ("getcwd", ""); 1001 1084 #else 1002 1085 error (NILF, "getwd: %s", current_directory); … … 1014 1097 /* Initialize the special variables. */ 1015 1098 define_variable (".VARIABLES", 10, "", o_default, 0)->special = 1; 1016 /* define_variable (".TARGETS", 8, "", o_default, 0); */ 1099 /* define_variable (".TARGETS", 8, "", o_default, 0)->special = 1; */ 1100 1101 /* Set up .FEATURES */ 1102 define_variable (".FEATURES", 9, 1103 "target-specific order-only second-expansion", 1104 o_default, 0); 1105 #ifdef MAKE_JOBSERVER 1106 do_variable_definition (NILF, ".FEATURES", "jobserver", 1107 o_default, f_append, 0); 1108 #endif 1109 #ifdef MAKE_SYMLINKS 1110 do_variable_definition (NILF, ".FEATURES", "check-symlink", 1111 o_default, f_append, 0); 1112 #endif 1017 1113 1018 1114 /* Read in variables from the environment. It is important that this be … … 1023 1119 for (i = 0; envp[i] != 0; ++i) 1024 1120 { 1025 int do_not_define; 1026 register char *ep = envp[i]; 1027 1028 /* by default, everything gets defined and exported */ 1029 do_not_define = 0; 1030 1031 while (*ep != '=') 1121 int do_not_define = 0; 1122 char *ep = envp[i]; 1123 1124 while (*ep != '\0' && *ep != '=') 1032 1125 ++ep; 1033 1126 #ifdef WINDOWS32 1034 1127 if (!unix_path && strneq(envp[i], "PATH=", 5)) 1035 1128 unix_path = ep+1; 1036 else if (! windows32_path && !strnicmp(envp[i], "Path=", 5)) {1129 else if (!strnicmp(envp[i], "Path=", 5)) { 1037 1130 do_not_define = 1; /* it gets defined after loop exits */ 1038 windows32_path = ep+1; 1131 if (!windows32_path) 1132 windows32_path = ep+1; 1039 1133 } 1040 1134 #endif … … 1043 1137 the same. */ 1044 1138 if (!do_not_define) 1045 define_variable (envp[i], (unsigned int) (ep - envp[i]), 1046 ep + 1, o_env, 1) 1047 /* Force exportation of every variable culled from the environment. 1048 We used to rely on target_environment's v_default code to do this. 1049 But that does not work for the case where an environment variable 1050 is redefined in a makefile with `override'; it should then still 1051 be exported, because it was originally in the environment. */ 1052 ->export = v_export; 1139 { 1140 struct variable *v; 1141 1142 v = define_variable (envp[i], (unsigned int) (ep - envp[i]), 1143 ep + 1, o_env, 1); 1144 /* Force exportation of every variable culled from the environment. 1145 We used to rely on target_environment's v_default code to do this. 1146 But that does not work for the case where an environment variable 1147 is redefined in a makefile with `override'; it should then still 1148 be exported, because it was originally in the environment. */ 1149 v->export = v_export; 1150 1151 /* Another wrinkle is that POSIX says the value of SHELL set in the 1152 makefile should not change the value of SHELL given to 1153 subprocesses, which seems silly to me but... */ 1154 if (strncmp (envp[i], "SHELL=", 6) == 0) 1155 { 1156 #ifndef __MSDOS__ 1157 v->export = v_noexport; 1158 #endif 1159 shell_var.name = "SHELL"; 1160 shell_var.value = xstrdup (ep + 1); 1161 } 1162 } 1053 1163 } 1054 1164 #ifdef WINDOWS32 1055 /* 1056 * Make sure that this particular spelling of 'Path' is available1165 /* If we didn't find a correctly spelled PATH we define PATH as 1166 * either the first mispelled value or an empty string 1057 1167 */ 1058 if (windows32_path) 1059 define_variable("Path", 4, windows32_path, o_env, 1)->export = v_export; 1060 else if (unix_path) 1061 define_variable("Path", 4, unix_path, o_env, 1)->export = v_export; 1062 else 1063 define_variable("Path", 4, "", o_env, 1)->export = v_export; 1064 1065 /* 1066 * PATH defaults to Path iff PATH not found and Path is found. 1067 */ 1068 if (!unix_path && windows32_path) 1069 define_variable("PATH", 4, windows32_path, o_env, 1)->export = v_export; 1168 if (!unix_path) 1169 define_variable("PATH", 4, 1170 windows32_path ? windows32_path : "", 1171 o_env, 1)->export = v_export; 1070 1172 #endif 1071 1173 #else /* For Amiga, read the ENV: device, ignoring all dirs */ … … 1237 1339 { 1238 1340 char *dir = directories->list[i]; 1341 char *expanded = 0; 1239 1342 if (dir[0] == '~') 1240 1343 { 1241 char *expanded = tilde_expand (dir);1344 expanded = tilde_expand (dir); 1242 1345 if (expanded != 0) 1243 1346 dir = expanded; 1244 1347 } 1348 #ifdef WINDOWS32 1349 /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/' 1350 But allow -C/ just in case someone wants that. */ 1351 { 1352 char *p = dir + strlen (dir) - 1; 1353 while (p > dir && (p[0] == '/' || p[0] == '\\')) 1354 --p; 1355 p[1] = '\0'; 1356 } 1357 #endif 1245 1358 if (chdir (dir) < 0) 1246 1359 pfatal_with_name (dir); 1247 if ( dir != directories->list[i])1248 free ( dir);1360 if (expanded) 1361 free (expanded); 1249 1362 } 1250 1363 … … 1301 1414 { 1302 1415 #ifdef HAVE_GETCWD 1303 perror_with_name ("getcwd :", "");1416 perror_with_name ("getcwd", ""); 1304 1417 #else 1305 1418 error (NILF, "getwd: %s", current_directory); … … 1368 1481 if (outfile == 0) 1369 1482 pfatal_with_name (_("fopen (temporary file)")); 1370 while (!feof (stdin) )1483 while (!feof (stdin) && ! ferror (stdin)) 1371 1484 { 1372 1485 char buf[2048]; … … 1448 1561 define_default_variables (); 1449 1562 1563 default_file = enter_file (".DEFAULT"); 1564 1565 { 1566 struct variable *v = define_variable (".DEFAULT_GOAL", 13, "", o_file, 0); 1567 default_goal_name = &v->value; 1568 } 1569 1450 1570 /* Read all the makefiles. */ 1451 1452 default_file = enter_file (".DEFAULT");1453 1571 1454 1572 read_makefiles … … 1580 1698 want job_slots to be 0 to indicate we're using the jobserver. */ 1581 1699 1700 master_job_slots = job_slots; 1701 1582 1702 while (--job_slots) 1583 1703 { … … 1599 1719 jobserver_fds->idx = 1; 1600 1720 jobserver_fds->max = 1; 1721 } 1722 #endif 1723 1724 #ifndef MAKE_SYMLINKS 1725 if (check_symlink_flag) 1726 { 1727 error (NILF, _("Symbolic links not supported: disabling -L.")); 1728 check_symlink_flag = 0; 1601 1729 } 1602 1730 #endif … … 1668 1796 int nargc = argc; 1669 1797 int orig_db_level = db_level; 1798 int status; 1670 1799 1671 1800 if (! ISDB (DB_MAKEFILES)) … … 1728 1857 define_makeflags (1, 1); 1729 1858 1730 switch (update_goal_chain (read_makefiles, 1)) 1859 rebuilding_makefiles = 1; 1860 status = update_goal_chain (read_makefiles); 1861 rebuilding_makefiles = 0; 1862 1863 switch (status) 1731 1864 { 1732 1865 case 1: … … 1777 1910 any_remade |= (mtime != NONEXISTENT_MTIME 1778 1911 && mtime != makefile_mtimes[i]); 1912 makefile_status = MAKE_FAILURE; 1779 1913 } 1780 1914 } … … 1866 2000 #ifndef _AMIGA 1867 2001 for (p = environ; *p != 0; ++p) 1868 if ( (*p)[MAKELEVEL_LENGTH] == '='1869 && strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH))2002 if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH) 2003 && (*p)[MAKELEVEL_LENGTH] == '=') 1870 2004 { 1871 2005 /* The SGI compiler apparently can't understand … … 1922 2056 int pid; 1923 2057 int status; 1924 pid = child_execute_job (0, 1, nargv, environ);2058 pid = child_execute_job (0, 1, nargv, environ); 1925 2059 1926 2060 /* is this loop really necessary? */ 1927 2061 do { 1928 pid = wait (&status);1929 } while (pid <= 0);2062 pid = wait (&status); 2063 } while (pid <= 0); 1930 2064 /* use the exit code of the child process */ 1931 exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);2065 exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE); 1932 2066 } 1933 2067 #else … … 1943 2077 1944 2078 db_level = orig_db_level; 2079 2080 /* Free the makefile mtimes (if we allocated any). */ 2081 if (makefile_mtimes) 2082 free ((char *) makefile_mtimes); 1945 2083 } 1946 2084 … … 1959 2097 if (goals == 0) 1960 2098 { 1961 if (default_goal_file != 0) 1962 { 1963 goals = (struct dep *) xmalloc (sizeof (struct dep)); 1964 goals->next = 0; 1965 goals->name = 0; 2099 if (**default_goal_name != '\0') 2100 { 2101 if (default_goal_file == 0 || 2102 strcmp (*default_goal_name, default_goal_file->name) != 0) 2103 { 2104 default_goal_file = lookup_file (*default_goal_name); 2105 2106 /* In case user set .DEFAULT_GOAL to a non-existent target 2107 name let's just enter this name into the table and let 2108 the standard logic sort it out. */ 2109 if (default_goal_file == 0) 2110 { 2111 struct nameseq *ns; 2112 char *p = *default_goal_name; 2113 2114 ns = multi_glob ( 2115 parse_file_seq (&p, '\0', sizeof (struct nameseq), 1), 2116 sizeof (struct nameseq)); 2117 2118 /* .DEFAULT_GOAL should contain one target. */ 2119 if (ns->next != 0) 2120 fatal (NILF, _(".DEFAULT_GOAL contains more than one target")); 2121 2122 default_goal_file = enter_file (ns->name); 2123 2124 ns->name = 0; /* It was reused by enter_file(). */ 2125 free_ns_chain (ns); 2126 } 2127 } 2128 2129 goals = (struct dep *) xmalloc (sizeof (struct dep)); 2130 goals->next = 0; 2131 goals->name = 0; 1966 2132 goals->ignore_mtime = 0; 1967 goals->file = default_goal_file; 1968 } 2133 goals->need_2nd_expansion = 0; 2134 goals->file = default_goal_file; 2135 } 1969 2136 } 1970 2137 else 1971 2138 lastgoal->next = 0; 2139 1972 2140 1973 2141 if (!goals) … … 1983 2151 DB (DB_BASIC, (_("Updating goal targets....\n"))); 1984 2152 1985 switch (update_goal_chain (goals , 0))2153 switch (update_goal_chain (goals)) 1986 2154 { 1987 2155 case -1: … … 1989 2157 case 0: 1990 2158 /* Updated successfully. */ 1991 status = MAKE_SUCCESS;2159 status = makefile_status; 1992 2160 break; 1993 2161 case 1: … … 2093 2261 if (v != 0) 2094 2262 { 2095 /* It is indeed a variable definition. Record a pointer to 2096 the variable for later use in define_makeflags. */ 2097 struct command_variable *cv 2098 = (struct command_variable *) xmalloc (sizeof (*cv)); 2099 cv->variable = v; 2100 cv->next = command_variables; 2101 command_variables = cv; 2263 /* It is indeed a variable definition. If we don't already have this 2264 one, record a pointer to the variable for later use in 2265 define_makeflags. */ 2266 struct command_variable *cv; 2267 2268 for (cv = command_variables; cv != 0; cv = cv->next) 2269 if (cv->variable == v) 2270 break; 2271 2272 if (! cv) { 2273 cv = (struct command_variable *) xmalloc (sizeof (*cv)); 2274 cv->variable = v; 2275 cv->next = command_variables; 2276 command_variables = cv; 2277 } 2102 2278 } 2103 2279 else if (! env) … … 2122 2298 lastgoal->file = f; 2123 2299 lastgoal->ignore_mtime = 0; 2300 lastgoal->need_2nd_expansion = 0; 2124 2301 2125 2302 { … … 2770 2947 if (!dying) 2771 2948 { 2949 char token = '+'; 2772 2950 int err; 2773 2951 … … 2789 2967 if (print_data_base_flag) 2790 2968 print_data_base (); 2969 2970 /* Sanity: have we written all our jobserver tokens back? If our 2971 exit status is 2 that means some kind of syntax error; we might not 2972 have written all our tokens so do that now. If tokens are left 2973 after any other error code, that's bad. */ 2974 2975 if (job_fds[0] != -1 && jobserver_tokens) 2976 { 2977 if (status != 2) 2978 error (NILF, 2979 "INTERNAL: Exiting with %u jobserver tokens (should be 0)!", 2980 jobserver_tokens); 2981 else 2982 while (jobserver_tokens--) 2983 { 2984 int r; 2985 2986 EINTRLOOP (r, write (job_fds[1], &token, 1)); 2987 if (r != 1) 2988 perror_with_name ("write", ""); 2989 } 2990 } 2991 2992 2993 /* Sanity: If we're the master, were all the tokens written back? */ 2994 2995 if (master_job_slots) 2996 { 2997 /* We didn't write one for ourself, so start at 1. */ 2998 unsigned int tcnt = 1; 2999 3000 /* Close the write side, so the read() won't hang. */ 3001 close (job_fds[1]); 3002 3003 while ((err = read (job_fds[0], &token, 1)) == 1) 3004 ++tcnt; 3005 3006 if (tcnt != master_job_slots) 3007 error (NILF, 3008 "INTERNAL: Exiting with %u jobserver tokens available; should be %u!", 3009 tcnt, master_job_slots); 3010 } 2791 3011 2792 3012 /* Try to move back to the original directory. This is essential on … … 2854 3074 printf (_("%s[%u]: Leaving directory `%s'\n"), 2855 3075 program, makelevel, starting_directory); 3076 3077 /* Flush stdout to be sure this comes before any stderr output. */ 3078 fflush (stdout); 2856 3079 }
Note:
See TracChangeset
for help on using the changeset viewer.