Changeset 501 for vendor/gnumake/current/main.c
- Timestamp:
- Sep 15, 2006, 4:30:32 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/main.c
r280 r501 1 1 /* Argument parsing and main program of GNU Make. 2 Copyright (C) 1988, 1989, 1990, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 3 2002, 2003, 2005 Free Software Foundation, Inc. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 4 Foundation, Inc. 4 5 This file is part of GNU Make. 5 6 6 GNU Make is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Make is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Make; see the file COPYING. If not, write to 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 19 MA 02111-1307, USA. */ 7 GNU Make is free software; you can redistribute it and/or modify it under the 8 terms of the GNU General Public License as published by the Free Software 9 Foundation; either version 2, or (at your option) any later version. 10 11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 13 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along with 16 GNU Make; see the file COPYING. If not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 20 18 21 19 #include "make.h" … … 84 82 #endif 85 83 84 static void clean_jobserver PARAMS ((int status)); 86 85 static void print_data_base PARAMS ((void)); 87 86 static void print_version PARAMS ((void)); … … 273 272 they appear out of date or not. */ 274 273 274 static int always_make_set = 0; 275 275 int always_make_flag = 0; 276 276 … … 365 365 { 366 366 { 'b', ignore, 0, 0, 0, 0, 0, 0, 0 }, 367 { 'B', flag, (char *) &always_make_ flag, 1, 1, 0, 0, 0, "always-make" },367 { 'B', flag, (char *) &always_make_set, 1, 1, 0, 0, 0, "always-make" }, 368 368 { 'C', string, (char *) &directories, 0, 0, 0, 0, 0, "directory" }, 369 369 { 'd', flag, (char *) &debug_flag, 1, 1, 0, 0, 0, 0 }, … … 419 419 { CHAR_MAX+4, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0, 420 420 "warn-undefined-variables" }, 421 { 0 }421 { 0, 0, 0, 0, 0, 0, 0, 0, 0 } 422 422 }; 423 423 … … 488 488 489 489 int posix_pedantic; 490 491 /* Nonzero if we have seen the '.SECONDEXPANSION' target. 492 This turns on secondary expansion of prerequisites. */ 493 494 int second_expansion; 490 495 491 496 /* Nonzero if we have seen the `.NOTPARALLEL' target. … … 536 541 { 537 542 init_hash_global_variable_set (); 543 strcache_init (); 538 544 init_hash_files (); 539 545 hash_init_directories (); … … 666 672 { 667 673 sprintf(errmsg, 668 _("%s: Interrupt/Exception caught (code = 0x% x, addr = 0x%x)\n"),669 prg, exrec->ExceptionCode, exrec->ExceptionAddress);674 _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%lx)\n"), 675 prg, exrec->ExceptionCode, (DWORD)exrec->ExceptionAddress); 670 676 fprintf(stderr, errmsg); 671 677 exit(255); … … 673 679 674 680 sprintf(errmsg, 675 _("\nUnhandled exception filter called from program %s\nExceptionCode = % x\nExceptionFlags = %x\nExceptionAddress = %x\n"),681 _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = %lx\n"), 676 682 prg, exrec->ExceptionCode, exrec->ExceptionFlags, 677 exrec->ExceptionAddress);683 (DWORD)exrec->ExceptionAddress); 678 684 679 685 if (exrec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION … … 681 687 sprintf(&errmsg[strlen(errmsg)], 682 688 (exrec->ExceptionInformation[0] 683 ? _("Access violation: write operation at address % x\n")684 : _("Access violation: read operation at address % x\n")),689 ? _("Access violation: write operation at address %lx\n") 690 : _("Access violation: read operation at address %lx\n")), 685 691 exrec->ExceptionInformation[1]); 686 692 … … 755 761 batch_mode_shell = 1; 756 762 unixy_shell = 0; 757 sh_found = 0; 763 sprintf (sh_path, "%s", search_token); 764 default_shell = xstrdup (w32ify (sh_path, 0)); 765 DB (DB_VERBOSE, 766 (_("find_and_set_shell setting default_shell = %s\n"), default_shell)); 767 sh_found = 1; 758 768 } else if (!no_default_sh_exe && 759 769 (token == NULL || !strcmp (search_token, default_shell))) { … … 769 779 } else { 770 780 char *p; 771 struct variable *v = lookup_variable ( "PATH", 4);781 struct variable *v = lookup_variable (STRING_SIZE_TUPLE ("PATH")); 772 782 773 783 /* Search Path for shell */ … … 842 852 open_tmpfile(char **name, const char *template) 843 853 { 854 #ifdef HAVE_FDOPEN 844 855 int fd; 856 #endif 845 857 846 858 #if defined HAVE_MKSTEMP || defined HAVE_MKTEMP … … 894 906 struct dep *read_makefiles; 895 907 PATH_VAR (current_directory); 908 unsigned int restarts = 0; 896 909 #ifdef WINDOWS32 897 910 char *unix_path = NULL; … … 917 930 } 918 931 } 932 #endif 933 934 #ifdef HAVE_ATEXIT 935 atexit (close_stdout); 919 936 #endif 920 937 … … 1047 1064 /* Extract program from full path */ 1048 1065 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")) 1066 program = strrchr (argv[0], '\\'); 1067 if (program) 1055 1068 { 1056 /* Remove .exe extension */1057 p[argv0_len - 4] = '\0';1058 /* Increment past the initial '\'*/1059 program = p + 1;1069 argv0_len = strlen(program); 1070 if (argv0_len > 4 && streq (&program[argv0_len - 4], ".exe")) 1071 /* Remove .exe extension */ 1072 program[argv0_len - 4] = '\0'; 1060 1073 } 1061 1074 } … … 1101 1114 /* Set up .FEATURES */ 1102 1115 define_variable (".FEATURES", 9, 1103 "target-specific order-only second-expansion ",1116 "target-specific order-only second-expansion else-if", 1104 1117 o_default, 0); 1118 #ifndef NO_ARCHIVES 1119 do_variable_definition (NILF, ".FEATURES", "archives", 1120 o_default, f_append, 0); 1121 #endif 1105 1122 #ifdef MAKE_JOBSERVER 1106 1123 do_variable_definition (NILF, ".FEATURES", "jobserver", … … 1150 1167 1151 1168 /* 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) 1169 makefile won't change the value of SHELL given to subprocesses */ 1170 if (streq (v->name, "SHELL")) 1155 1171 { 1156 1172 #ifndef __MSDOS__ … … 1159 1175 shell_var.name = "SHELL"; 1160 1176 shell_var.value = xstrdup (ep + 1); 1177 } 1178 1179 /* If MAKE_RESTARTS is set, remember it but don't export it. */ 1180 if (streq (v->name, "MAKE_RESTARTS")) 1181 { 1182 v->export = v_noexport; 1183 restarts = (unsigned int) atoi (ep + 1); 1161 1184 } 1162 1185 } … … 1204 1227 /* Decode the switches. */ 1205 1228 1206 decode_env_switches ( "MAKEFLAGS", 9);1229 decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS")); 1207 1230 #if 0 1208 1231 /* People write things like: 1209 1232 MFLAGS="CC=gcc -pipe" "CFLAGS=-g" 1210 1233 and we set the -p, -i and -e switches. Doesn't seem quite right. */ 1211 decode_env_switches ( "MFLAGS", 6);1234 decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS")); 1212 1235 #endif 1213 1236 decode_switches (argc, argv, 0); 1214 1237 #ifdef WINDOWS32 1215 1238 if (suspend_flag) { 1216 fprintf(stderr, "%s (pid = % d)\n", argv[0], GetCurrentProcessId());1239 fprintf(stderr, "%s (pid = %ld)\n", argv[0], GetCurrentProcessId()); 1217 1240 fprintf(stderr, _("%s is suspending for 30 seconds..."), argv[0]); 1218 1241 Sleep(30 * 1000); … … 1223 1246 decode_debug_flags (); 1224 1247 1248 /* Set always_make_flag if -B was given and we've not restarted already. */ 1249 always_make_flag = always_make_set && (restarts == 0); 1250 1225 1251 /* Print version information. */ 1226 1227 1252 if (print_version_flag || print_data_base_flag || db_level) 1228 print_version (); 1229 1230 /* `make --version' is supposed to just print the version and exit. */ 1231 if (print_version_flag) 1232 die (0); 1253 { 1254 print_version (); 1255 1256 /* `make --version' is supposed to just print the version and exit. */ 1257 if (print_version_flag) 1258 die (0); 1259 } 1233 1260 1234 1261 #ifndef VMS … … 1377 1404 /* Figure out the level of recursion. */ 1378 1405 { 1379 struct variable *v = lookup_variable ( MAKELEVEL_NAME, MAKELEVEL_LENGTH);1406 struct variable *v = lookup_variable (STRING_SIZE_TUPLE (MAKELEVEL_NAME)); 1380 1407 if (v != 0 && v->value[0] != '\0' && v->value[0] != '-') 1381 1408 makelevel = (unsigned int) atoi (v->value); … … 1424 1451 } 1425 1452 1426 (void) define_variable ("CURDIR", 6, current_directory, o_ default, 0);1453 (void) define_variable ("CURDIR", 6, current_directory, o_file, 0); 1427 1454 1428 1455 /* Read any stdin makefiles into temporary files. */ … … 1577 1604 if (no_default_sh_exe) 1578 1605 no_default_sh_exe = !find_and_set_default_shell(NULL); 1579 1580 if (no_default_sh_exe && job_slots != 1) {1581 error (NILF, _("Do not specify -j or --jobs if sh.exe is not available."));1582 error (NILF, _("Resetting make for single job mode."));1583 job_slots = 1;1584 }1585 1606 #endif /* WINDOWS32 */ 1586 1607 … … 1589 1610 { 1590 1611 extern int _is_unixy_shell (const char *_path); 1591 struct variable *shv = lookup_variable ( "SHELL", 5);1612 struct variable *shv = lookup_variable (STRING_SIZE_TUPLE ("SHELL")); 1592 1613 extern int unixy_shell; 1593 1614 extern char *default_shell; … … 1608 1629 1609 1630 /* Decode switches again, in case the variables were set by the makefile. */ 1610 decode_env_switches ( "MAKEFLAGS", 9);1631 decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS")); 1611 1632 #if 0 1612 decode_env_switches ( "MFLAGS", 6);1633 decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS")); 1613 1634 #endif 1614 1635 … … 1761 1782 build_vpath_lists (); 1762 1783 1763 /* Mark files given with -o flags as very old 1764 a nd as having been updated already, and files given with -W flags as1765 brand new (time-stamp as far as possible into the future). */1784 /* Mark files given with -o flags as very old and as having been updated 1785 already, and files given with -W flags as brand new (time-stamp as far 1786 as possible into the future). If restarts is set we'll do -W later. */ 1766 1787 1767 1788 if (old_files != 0) … … 1775 1796 } 1776 1797 1777 if ( new_files != 0)1798 if (!restarts && new_files != 0) 1778 1799 { 1779 1800 for (p = new_files->list; *p != 0; ++p) … … 1835 1856 1836 1857 /* Free the storage. */ 1837 free ((char *)d);1858 free_dep (d); 1838 1859 1839 1860 d = last == 0 ? read_makefiles : last->next; … … 1954 1975 log_working_directory (0); 1955 1976 1977 clean_jobserver (0); 1978 1956 1979 if (makefiles != 0) 1957 1980 { … … 1998 2021 } 1999 2022 2000 #ifndef _AMIGA 2001 for (p = environ; *p != 0; ++p) 2002 if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH) 2003 && (*p)[MAKELEVEL_LENGTH] == '=') 2004 { 2005 /* The SGI compiler apparently can't understand 2006 the concept of storing the result of a function 2007 in something other than a local variable. */ 2008 char *sgi_loses; 2009 sgi_loses = (char *) alloca (40); 2010 *p = sgi_loses; 2011 sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel); 2012 break; 2013 } 2014 #else /* AMIGA */ 2015 { 2016 char buffer[256]; 2017 int len; 2018 2019 len = GetVar (MAKELEVEL_NAME, buffer, sizeof (buffer), GVF_GLOBAL_ONLY); 2020 2021 if (len != -1) 2022 { 2023 sprintf (buffer, "%u", makelevel); 2024 SetVar (MAKELEVEL_NAME, buffer, -1, GVF_GLOBAL_ONLY); 2025 } 2026 } 2027 #endif 2023 ++restarts; 2028 2024 2029 2025 if (ISDB (DB_BASIC)) 2030 2026 { 2031 2027 char **p; 2032 fputs (_("Re-executing:"), stdout);2028 printf (_("Re-executing[%u]:"), restarts); 2033 2029 for (p = nargv; *p != 0; ++p) 2034 2030 printf (" %s", *p); 2035 2031 putchar ('\n'); 2036 2032 } 2033 2034 #ifndef _AMIGA 2035 for (p = environ; *p != 0; ++p) 2036 { 2037 if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH) 2038 && (*p)[MAKELEVEL_LENGTH] == '=') 2039 { 2040 /* The SGI compiler apparently can't understand 2041 the concept of storing the result of a function 2042 in something other than a local variable. */ 2043 char *sgi_loses; 2044 sgi_loses = (char *) alloca (40); 2045 *p = sgi_loses; 2046 sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel); 2047 } 2048 if (strneq (*p, "MAKE_RESTARTS=", 14)) 2049 { 2050 char *sgi_loses; 2051 sgi_loses = (char *) alloca (40); 2052 *p = sgi_loses; 2053 sprintf (*p, "MAKE_RESTARTS=%u", restarts); 2054 restarts = 0; 2055 } 2056 } 2057 #else /* AMIGA */ 2058 { 2059 char buffer[256]; 2060 2061 sprintf (buffer, "%u", makelevel); 2062 SetVar (MAKELEVEL_NAME, buffer, -1, GVF_GLOBAL_ONLY); 2063 2064 sprintf (buffer, "%u", restarts); 2065 SetVar ("MAKE_RESTARTS", buffer, -1, GVF_GLOBAL_ONLY); 2066 restarts = 0; 2067 } 2068 #endif 2069 2070 /* If we didn't set the restarts variable yet, add it. */ 2071 if (restarts) 2072 { 2073 char *b = alloca (40); 2074 sprintf (b, "MAKE_RESTARTS=%u", restarts); 2075 putenv (b); 2076 } 2037 2077 2038 2078 fflush (stdout); … … 2086 2126 define_makeflags (1, 0); 2087 2127 2128 /* Set always_make_flag if -B was given. */ 2129 always_make_flag = always_make_set; 2130 2131 /* If restarts is set we haven't set up -W files yet, so do that now. */ 2132 if (restarts && new_files != 0) 2133 { 2134 for (p = new_files->list; *p != 0; ++p) 2135 { 2136 f = enter_command_line_file (*p); 2137 f->last_mtime = f->mtime_before_update = NEW_MTIME; 2138 } 2139 } 2140 2088 2141 /* If there is a temp file from reading a makefile from stdin, get rid of 2089 2142 it now. */ … … 2127 2180 } 2128 2181 2129 goals = (struct dep *) xmalloc (sizeof (struct dep)); 2130 goals->next = 0; 2131 goals->name = 0; 2132 goals->ignore_mtime = 0; 2133 goals->need_2nd_expansion = 0; 2182 goals = alloc_dep (); 2134 2183 goals->file = default_goal_file; 2135 2184 } … … 2181 2230 } 2182 2231 2232 /* NOTREACHED */ 2183 2233 return 0; 2184 2234 } … … 2287 2337 if (goals == 0) 2288 2338 { 2289 goals = (struct dep *) xmalloc (sizeof (struct dep));2339 goals = alloc_dep (); 2290 2340 lastgoal = goals; 2291 2341 } 2292 2342 else 2293 2343 { 2294 lastgoal->next = (struct dep *) xmalloc (sizeof (struct dep));2344 lastgoal->next = alloc_dep (); 2295 2345 lastgoal = lastgoal->next; 2296 2346 } 2297 lastgoal->name = 0; 2347 2298 2348 lastgoal->file = f; 2299 lastgoal->ignore_mtime = 0;2300 lastgoal->need_2nd_expansion = 0;2301 2349 2302 2350 { … … 2305 2353 char *value; 2306 2354 2307 v = lookup_variable ( "MAKECMDGOALS", 12);2355 v = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS")); 2308 2356 if (v == 0) 2309 2357 value = f->name; … … 2896 2944 2897 2945 printf ("%sGNU Make %s\n\ 2898 %sCopyright (C) 200 3Free Software Foundation, Inc.\n",2946 %sCopyright (C) 2006 Free Software Foundation, Inc.\n", 2899 2947 precede, version_string, precede); 2900 2948 … … 2920 2968 2921 2969 static void 2922 print_data_base ( void)2970 print_data_base () 2923 2971 { 2924 2972 time_t when; … … 2932 2980 print_file_data_base (); 2933 2981 print_vpath_data_base (); 2982 strcache_print_stats ("#"); 2934 2983 2935 2984 when = time ((time_t *) 0); 2936 2985 printf (_("\n# Finished Make data base on %s\n"), ctime (&when)); 2986 } 2987 2988 static void 2989 clean_jobserver (int status) 2990 { 2991 char token = '+'; 2992 2993 /* Sanity: have we written all our jobserver tokens back? If our 2994 exit status is 2 that means some kind of syntax error; we might not 2995 have written all our tokens so do that now. If tokens are left 2996 after any other error code, that's bad. */ 2997 2998 if (job_fds[0] != -1 && jobserver_tokens) 2999 { 3000 if (status != 2) 3001 error (NILF, 3002 "INTERNAL: Exiting with %u jobserver tokens (should be 0)!", 3003 jobserver_tokens); 3004 else 3005 while (jobserver_tokens--) 3006 { 3007 int r; 3008 3009 EINTRLOOP (r, write (job_fds[1], &token, 1)); 3010 if (r != 1) 3011 perror_with_name ("write", ""); 3012 } 3013 } 3014 3015 3016 /* Sanity: If we're the master, were all the tokens written back? */ 3017 3018 if (master_job_slots) 3019 { 3020 /* We didn't write one for ourself, so start at 1. */ 3021 unsigned int tcnt = 1; 3022 3023 /* Close the write side, so the read() won't hang. */ 3024 close (job_fds[1]); 3025 3026 while (read (job_fds[0], &token, 1) == 1) 3027 ++tcnt; 3028 3029 if (tcnt != master_job_slots) 3030 error (NILF, 3031 "INTERNAL: Exiting with %u jobserver tokens available; should be %u!", 3032 tcnt, master_job_slots); 3033 3034 close (job_fds[0]); 3035 } 2937 3036 } 2938 3037 … … 2947 3046 if (!dying) 2948 3047 { 2949 char token = '+';2950 3048 int err; 2951 3049 … … 2956 3054 2957 3055 /* Wait for children to die. */ 2958 for (err = (status != 0); job_slots_used > 0; err = 0) 3056 err = (status != 0); 3057 while (job_slots_used > 0) 2959 3058 reap_children (1, err); 2960 3059 … … 2968 3067 print_data_base (); 2969 3068 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 } 3069 clean_jobserver (status); 3011 3070 3012 3071 /* Try to move back to the original directory. This is essential on
Note:
See TracChangeset
for help on using the changeset viewer.