Changeset 903 for trunk/src/gmakenew/main.c
- Timestamp:
- May 23, 2007, 7:31:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/main.c
r877 r903 1 1 /* Argument parsing and main program of GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software 4 4 Foundation, Inc. 5 5 This file is part of GNU Make. … … 57 57 #endif 58 58 59 extern void init_dir PARAMS ((void)); 60 extern void remote_setup PARAMS ((void)); 61 extern void remote_cleanup PARAMS ((void)); 62 extern RETSIGTYPE fatal_error_signal PARAMS ((int sig)); 63 64 extern void print_variable_data_base PARAMS ((void)); 65 extern void print_dir_data_base PARAMS ((void)); 66 extern void print_rule_data_base PARAMS ((void)); 67 extern void print_file_data_base PARAMS ((void)); 68 extern void print_vpath_data_base PARAMS ((void)); 59 void init_dir (void); 60 void remote_setup (void); 61 void remote_cleanup (void); 62 RETSIGTYPE fatal_error_signal (int sig); 63 64 void print_variable_data_base (void); 65 void print_dir_data_base (void); 66 void print_rule_data_base (void); 67 void print_file_data_base (void); 68 void print_vpath_data_base (void); 69 70 void verify_file_data_base (void); 69 71 70 72 #if defined HAVE_WAITPID || defined HAVE_WAIT3 … … 72 74 #endif 73 75 74 #if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER) 75 externint chdir ();76 #if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER) /* bird */ 77 int chdir (); 76 78 #endif 77 79 #ifndef STDC_HEADERS 78 80 # ifndef sun /* Sun has an incorrect decl in a header. */ 79 extern void exit PARAMS ((int)) __attribute__ ((noreturn));81 void exit (int) __attribute__ ((noreturn)); 80 82 # endif 81 externdouble atof ();82 #endif 83 84 static void clean_jobserver PARAMS ((int status));85 static void print_data_base PARAMS ((void));86 static void print_version PARAMS ((void));87 static void decode_switches PARAMS ((int argc, char **argv, int env));88 static void decode_env_switches PARAMS ((char *envar, unsigned int len));89 static void define_makeflags PARAMS ((int all, int makefile));90 static char *quote_for_env PARAMS ((char *out, char *in));91 static void initialize_global_hash_tables PARAMS ((void));83 double atof (); 84 #endif 85 86 static void clean_jobserver (int status); 87 static void print_data_base (void); 88 static void print_version (void); 89 static void decode_switches (int argc, char **argv, int env); 90 static void decode_env_switches (char *envar, unsigned int len); 91 static void define_makeflags (int all, int makefile); 92 static char *quote_for_env (char *out, const char *in); 93 static void initialize_global_hash_tables (void); 92 94 93 95 … … 104 106 flag_off, /* Turn int flag off. */ 105 107 string, /* One string per switch. */ 108 filename, /* A string containing a file name. */ 106 109 positive_int, /* A positive integer. */ 107 110 floating, /* A floating-point number (double). */ … … 109 112 } type; 110 113 111 char*value_ptr; /* Pointer to the value-holding variable. */114 void *value_ptr; /* Pointer to the value-holding variable. */ 112 115 113 116 unsigned int env:1; /* Can come from MAKEFLAGS. */ … … 115 118 unsigned int no_makefile:1; /* Don't propagate when remaking makefiles. */ 116 119 117 c har *noarg_value; /* Pointer to value used if no argument isgiven. */118 c har *default_value;/* Pointer to default value. */120 const void *noarg_value; /* Pointer to value used if no arg given. */ 121 const void *default_value; /* Pointer to default value. */ 119 122 120 123 char *long_name; /* Long option name. */ … … 130 133 struct stringlist 131 134 { 132 c har **list; /* Nil-terminated list of strings. */135 const char **list; /* Nil-terminated list of strings. */ 133 136 unsigned int idx; /* Index into above. */ 134 137 unsigned int max; /* Number of pointers allocated. */ … … 164 167 165 168 int db_level = 0; 169 170 /* Output level (--verbosity). */ 171 172 static struct stringlist *verbosity_flags; 166 173 167 174 #ifdef WINDOWS32 … … 288 295 289 296 struct variable shell_var; 297 298 /* This character introduces a command: it's the first char on the line. */ 299 300 char cmd_prefix = '\t'; 290 301 291 302 #ifdef KMK … … 382 393 { 383 394 { 'b', ignore, 0, 0, 0, 0, 0, 0, 0 }, 384 { 'B', flag, (char *)&always_make_set, 1, 1, 0, 0, 0, "always-make" },385 { 'C', string, (char *)&directories, 0, 0, 0, 0, 0, "directory" },386 { 'd', flag, (char *)&debug_flag, 1, 1, 0, 0, 0, 0 },387 { CHAR_MAX+1, string, (char *)&db_flags, 1, 1, 0, "basic", 0, "debug" },395 { 'B', flag, &always_make_set, 1, 1, 0, 0, 0, "always-make" }, 396 { 'C', filename, &directories, 0, 0, 0, 0, 0, "directory" }, 397 { 'd', flag, &debug_flag, 1, 1, 0, 0, 0, 0 }, 398 { CHAR_MAX+1, string, &db_flags, 1, 1, 0, "basic", 0, "debug" }, 388 399 #ifdef WINDOWS32 389 { 'D', flag, (char *) &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" }, 390 #endif 391 { 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0, 392 "environment-overrides", }, 393 { 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0, "file" }, 394 { 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0, "help" }, 395 { 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0, 396 "ignore-errors" }, 397 { 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0, 400 { 'D', flag, &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" }, 401 #endif 402 { 'e', flag, &env_overrides, 1, 1, 0, 0, 0, "environment-overrides", }, 403 { 'f', filename, &makefiles, 0, 0, 0, 0, 0, "file" }, 404 { 'h', flag, &print_usage_flag, 0, 0, 0, 0, 0, "help" }, 405 { 'i', flag, &ignore_errors_flag, 1, 1, 0, 0, 0, "ignore-errors" }, 406 { 'I', filename, &include_directories, 1, 1, 0, 0, 0, 398 407 "include-dir" }, 399 { 'j', positive_int, (char *) &job_slots, 1, 1, 0, (char *) &inf_jobs, 400 (char *) &default_job_slots, "jobs" }, 401 { CHAR_MAX+2, string, (char *) &jobserver_fds, 1, 1, 0, 0, 0, 402 "jobserver-fds" }, 403 { 'k', flag, (char *) &keep_going_flag, 1, 1, 0, 0, 404 (char *) &default_keep_going_flag, "keep-going" }, 408 { 'j', positive_int, &job_slots, 1, 1, 0, &inf_jobs, &default_job_slots, 409 "jobs" }, 410 { CHAR_MAX+2, string, &jobserver_fds, 1, 1, 0, 0, 0, "jobserver-fds" }, 411 { 'k', flag, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag, 412 "keep-going" }, 405 413 #ifndef NO_FLOAT 406 { 'l', floating, (char *) &max_load_average, 1, 1, 0, 407 (char *) &default_load_average, (char *) &default_load_average, 408 "load-average" }, 414 { 'l', floating, &max_load_average, 1, 1, 0, &default_load_average, 415 &default_load_average, "load-average" }, 409 416 #else 410 { 'l', positive_int, (char *) &max_load_average, 1, 1, 0, 411 (char *) &default_load_average, (char *) &default_load_average, 412 "load-average" }, 413 #endif 414 { 'L', flag, (char *) &check_symlink_flag, 1, 1, 0, 0, 0, 415 "check-symlink-times" }, 417 { 'l', positive_int, &max_load_average, 1, 1, 0, &default_load_average, 418 &default_load_average, "load-average" }, 419 #endif 420 { 'L', flag, &check_symlink_flag, 1, 1, 0, 0, 0, "check-symlink-times" }, 416 421 { 'm', ignore, 0, 0, 0, 0, 0, 0, 0 }, 417 { 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0, "just-print" }, 418 { 'o', string, (char *) &old_files, 0, 0, 0, 0, 0, "old-file" }, 419 { 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0, 420 "print-data-base" }, 422 { 'n', flag, &just_print_flag, 1, 1, 1, 0, 0, "just-print" }, 423 { 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" }, 424 { 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, "print-data-base" }, 421 425 #ifdef CONFIG_PRETTY_COMMAND_PRINTING 422 426 { CHAR_MAX+6, flag, (char *) &pretty_command_printing, 1, 1, 1, 0, 0, … … 427 431 (char *) &process_priority, (char *) &process_priority, "priority" }, 428 432 #endif 429 { 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0, "question" }, 430 { 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0, 431 "no-builtin-rules" }, 432 { 'R', flag, (char *) &no_builtin_variables_flag, 1, 1, 0, 0, 0, 433 { 'q', flag, &question_flag, 1, 1, 1, 0, 0, "question" }, 434 { 'r', flag, &no_builtin_rules_flag, 1, 1, 0, 0, 0, "no-builtin-rules" }, 435 { 'R', flag, &no_builtin_variables_flag, 1, 1, 0, 0, 0, 433 436 "no-builtin-variables" }, 434 { 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0, "silent" }, 435 { 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0, 0, 436 (char *) &default_keep_going_flag, "no-keep-going" }, 437 { 't', flag, (char *) &touch_flag, 1, 1, 1, 0, 0, "touch" }, 438 { 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0, "version" }, 439 { 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0, 440 "print-directory" }, 441 { CHAR_MAX+3, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0, 437 { 's', flag, &silent_flag, 1, 1, 0, 0, 0, "silent" }, 438 { 'S', flag_off, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag, 439 "no-keep-going" }, 440 { 't', flag, &touch_flag, 1, 1, 1, 0, 0, "touch" }, 441 { 'v', flag, &print_version_flag, 1, 1, 0, 0, 0, "version" }, 442 { CHAR_MAX+3, string, &verbosity_flags, 1, 1, 0, 0, 0, 443 "verbosity" }, 444 { 'w', flag, &print_directory_flag, 1, 1, 0, 0, 0, "print-directory" }, 445 { CHAR_MAX+4, flag, &inhibit_print_directory_flag, 1, 1, 0, 0, 0, 442 446 "no-print-directory" }, 443 { 'W', string, (char *)&new_files, 0, 0, 0, 0, 0, "what-if" },444 { CHAR_MAX+ 4, flag, (char *)&warn_undefined_variables_flag, 1, 1, 0, 0, 0,447 { 'W', filename, &new_files, 0, 0, 0, 0, 0, "what-if" }, 448 { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0, 445 449 "warn-undefined-variables" }, 446 450 { 0, 0, 0, 0, 0, 0, 0, 0, 0 } … … 588 592 } 589 593 590 static struct file*591 e nter_command_line_file (char *name)594 static const char * 595 expand_command_line_file (char *name) 592 596 { 597 const char *cp; 598 char *expanded = 0; 599 593 600 if (name[0] == '\0') 594 601 fatal (NILF, _("empty string invalid as file name")); … … 596 603 if (name[0] == '~') 597 604 { 598 char *expanded = tilde_expand (name);605 expanded = tilde_expand (name); 599 606 if (expanded != 0) 600 name = expanded; /* Memory leak; I don't care. */607 name = expanded; 601 608 } 602 609 … … 622 629 } 623 630 624 return enter_file (xstrdup (name)); 631 cp = strcache_add (name); 632 633 if (expanded) 634 free (expanded); 635 636 return cp; 625 637 } 626 638 … … 638 650 decode_debug_flags (void) 639 651 { 640 c har **pp;652 const char **pp; 641 653 642 654 if (debug_flag) … … 814 826 815 827 int 816 find_and_set_default_shell (c har *token)828 find_and_set_default_shell (const char *token) 817 829 { 818 830 int sh_found = 0; 831 char *atoken = 0; 819 832 char *search_token; 820 833 char *tokend; … … 825 838 search_token = default_shell; 826 839 else 827 search_token = token; 828 840 atoken = search_token = xstrdup (token); 829 841 830 842 /* If the user explicitly requests the DOS cmd shell, obey that request. … … 836 848 || (tokend > search_token 837 849 && (tokend[-1] == '/' || tokend[-1] == '\\'))) 838 && !strc mpi(tokend, "cmd"))850 && !strcasecmp (tokend, "cmd")) 839 851 || ((tokend - 4 == search_token 840 852 || (tokend - 4 > search_token 841 853 && (tokend[-5] == '/' || tokend[-5] == '\\'))) 842 && !strc mpi(tokend - 4, "cmd.exe"))) {854 && !strcasecmp (tokend - 4, "cmd.exe"))) { 843 855 batch_mode_shell = 1; 844 856 unixy_shell = 0; … … 852 864 /* no new information, path already set or known */ 853 865 sh_found = 1; 854 } else if (file_exists_p (search_token)) {866 } else if (file_exists_p (search_token)) { 855 867 /* search token path was found */ 856 sprintf (sh_path, "%s", search_token);857 default_shell = xstrdup (w32ify(sh_path,0));868 sprintf (sh_path, "%s", search_token); 869 default_shell = xstrdup (w32ify (sh_path, 0)); 858 870 DB (DB_VERBOSE, 859 871 (_("find_and_set_shell setting default_shell = %s\n"), default_shell)); … … 868 880 869 881 p = v->value; 870 ep = strchr (p, PATH_SEPARATOR_CHAR);882 ep = strchr (p, PATH_SEPARATOR_CHAR); 871 883 872 884 while (ep && *ep) { 873 885 *ep = '\0'; 874 886 875 if (dir_file_exists_p (p, search_token)) {876 sprintf (sh_path, "%s/%s", p, search_token);877 default_shell = xstrdup (w32ify(sh_path,0));887 if (dir_file_exists_p (p, search_token)) { 888 sprintf (sh_path, "%s/%s", p, search_token); 889 default_shell = xstrdup (w32ify (sh_path, 0)); 878 890 sh_found = 1; 879 891 *ep = PATH_SEPARATOR_CHAR; 880 892 881 893 /* terminate loop */ 882 p += strlen (p);894 p += strlen (p); 883 895 } else { 884 896 *ep = PATH_SEPARATOR_CHAR; … … 886 898 } 887 899 888 ep = strchr (p, PATH_SEPARATOR_CHAR);900 ep = strchr (p, PATH_SEPARATOR_CHAR); 889 901 } 890 902 891 903 /* be sure to check last element of Path */ 892 if (p && *p && dir_file_exists_p (p, search_token)) {893 sprintf (sh_path, "%s/%s", p, search_token);894 default_shell = xstrdup (w32ify(sh_path,0));904 if (p && *p && dir_file_exists_p (p, search_token)) { 905 sprintf (sh_path, "%s/%s", p, search_token); 906 default_shell = xstrdup (w32ify (sh_path, 0)); 895 907 sh_found = 1; 896 908 } … … 916 928 /* naive test */ 917 929 if (!unixy_shell && sh_found && 918 (strstr (default_shell, "sh") || strstr(default_shell, "SH"))) {930 (strstr (default_shell, "sh") || strstr (default_shell, "SH"))) { 919 931 unixy_shell = 1; 920 932 batch_mode_shell = 0; … … 924 936 batch_mode_shell = 1; 925 937 #endif 938 939 if (atoken) 940 free (atoken); 926 941 927 942 return (sh_found); … … 995 1010 #endif /* WINDOWS32 */ 996 1011 997 #ifdef __MSDOS__ 998 1012 #ifdef __MSDOS__ 999 1013 static void 1000 1014 msdos_return_to_initial_directory (void) … … 1003 1017 chdir (directory_before_chdir); 1004 1018 } 1005 #endif 1006 1007 #ifndef _MSC_VER 1008 extern char *mktemp PARAMS ((char *template));1009 #endif 1010 extern int mkstemp PARAMS ((char *template));1019 #endif /* __MSDOS__ */ 1020 1021 #ifndef _MSC_VER /* bird */ 1022 char *mktemp (char *template); 1023 #endif 1024 int mkstemp (char *template); 1011 1025 1012 1026 FILE * … … 1061 1075 { 1062 1076 static char *stdin_nm = 0; 1063 struct file *f;1064 int i;1065 1077 int makefile_status = MAKE_SUCCESS; 1066 char **p;1067 1078 struct dep *read_makefiles; 1068 1079 PATH_VAR (current_directory); … … 1193 1204 # else /* setvbuf not reversed. */ 1194 1205 /* Some buggy systems lose if we pass 0 instead of allocating ourselves. */ 1195 setvbuf (stdout, (char *)0, _IOLBF, BUFSIZ);1206 setvbuf (stdout, 0, _IOLBF, BUFSIZ); 1196 1207 # endif /* setvbuf reversed. */ 1197 1208 #elif HAVE_SETLINEBUF … … 1301 1312 1302 1313 #ifndef _AMIGA 1303 for (i = 0; envp[i] != 0; ++i) 1304 { 1305 int do_not_define = 0; 1306 char *ep = envp[i]; 1307 1308 while (*ep != '\0' && *ep != '=') 1309 ++ep; 1314 { 1315 unsigned int i; 1316 1317 for (i = 0; envp[i] != 0; ++i) 1318 { 1319 int do_not_define = 0; 1320 char *ep = envp[i]; 1321 1322 while (*ep != '\0' && *ep != '=') 1323 ++ep; 1310 1324 #ifdef WINDOWS32 1311 if (!unix_path && strneq(envp[i], "PATH=", 5)) 1312 unix_path = ep+1; 1313 else if (!strnicmp(envp[i], "Path=", 5)) { 1314 do_not_define = 1; /* it gets defined after loop exits */ 1315 if (!windows32_path) 1316 windows32_path = ep+1; 1325 if (!unix_path && strneq(envp[i], "PATH=", 5)) 1326 unix_path = ep+1; 1327 else if (!strnicmp(envp[i], "Path=", 5)) { 1328 do_not_define = 1; /* it gets defined after loop exits */ 1329 if (!windows32_path) 1330 windows32_path = ep+1; 1331 } 1332 #endif 1333 /* The result of pointer arithmetic is cast to unsigned int for 1334 machines where ptrdiff_t is a different size that doesn't widen 1335 the same. */ 1336 if (!do_not_define) 1337 { 1338 struct variable *v; 1339 1340 v = define_variable (envp[i], (unsigned int) (ep - envp[i]), 1341 ep + 1, o_env, 1); 1342 /* Force exportation of every variable culled from the 1343 environment. We used to rely on target_environment's 1344 v_default code to do this. But that does not work for the 1345 case where an environment variable is redefined in a makefile 1346 with `override'; it should then still be exported, because it 1347 was originally in the environment. */ 1348 v->export = v_export; 1349 1350 /* Another wrinkle is that POSIX says the value of SHELL set in 1351 the makefile won't change the value of SHELL given to 1352 subprocesses. */ 1353 if (streq (v->name, "SHELL")) 1354 { 1355 #ifndef __MSDOS__ 1356 v->export = v_noexport; 1357 #endif 1358 shell_var.name = "SHELL"; 1359 shell_var.value = xstrdup (ep + 1); 1360 } 1361 1362 /* If MAKE_RESTARTS is set, remember it but don't export it. */ 1363 if (streq (v->name, "MAKE_RESTARTS")) 1364 { 1365 v->export = v_noexport; 1366 restarts = (unsigned int) atoi (ep + 1); 1367 } 1368 } 1317 1369 } 1318 #endif 1319 /* The result of pointer arithmetic is cast to unsigned int for 1320 machines where ptrdiff_t is a different size that doesn't widen 1321 the same. */ 1322 if (!do_not_define) 1323 { 1324 struct variable *v; 1325 1326 v = define_variable (envp[i], (unsigned int) (ep - envp[i]), 1327 ep + 1, o_env, 1); 1328 /* Force exportation of every variable culled from the environment. 1329 We used to rely on target_environment's v_default code to do this. 1330 But that does not work for the case where an environment variable 1331 is redefined in a makefile with `override'; it should then still 1332 be exported, because it was originally in the environment. */ 1333 v->export = v_export; 1334 1335 /* Another wrinkle is that POSIX says the value of SHELL set in the 1336 makefile won't change the value of SHELL given to subprocesses */ 1337 if (streq (v->name, "SHELL")) 1338 { 1339 #ifndef __MSDOS__ 1340 v->export = v_noexport; 1341 #endif 1342 shell_var.name = "SHELL"; 1343 shell_var.value = xstrdup (ep + 1); 1344 } 1345 1346 /* If MAKE_RESTARTS is set, remember it but don't export it. */ 1347 if (streq (v->name, "MAKE_RESTARTS")) 1348 { 1349 v->export = v_noexport; 1350 restarts = (unsigned int) atoi (ep + 1); 1351 } 1352 } 1353 } 1370 } 1354 1371 #ifdef WINDOWS32 1355 1372 /* If we didn't find a correctly spelled PATH we define PATH as … … 1397 1414 #if 0 1398 1415 /* People write things like: 1399 1416 MFLAGS="CC=gcc -pipe" "CFLAGS=-g" 1400 1417 and we set the -p, -i and -e switches. Doesn't seem quite right. */ 1401 1418 decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS")); … … 1464 1481 && argv[0] != 0 1465 1482 && (argv[0][0] != '/' && (argv[0][0] == '\0' || argv[0][1] != ':')) 1466 # ifdef __EMX__1483 # ifdef __EMX__ 1467 1484 /* do not prepend cwd if argv[0] contains no '/', e.g. "make" */ 1468 1485 && (strchr (argv[0], '/') != 0 || strchr (argv[0], '\\') != 0) 1469 1486 # endif 1470 1487 ) 1471 argv[0] = concat (current_directory, "/", argv[0]);1488 argv[0] = xstrdup (concat (current_directory, "/", argv[0])); 1472 1489 #else /* !__MSDOS__ */ 1473 1490 if (current_directory[0] != '\0' 1474 && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0) 1475 argv[0] = concat (current_directory, "/", argv[0]); 1491 && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0 1492 #ifdef HAVE_DOS_PATHS 1493 && (argv[0][0] != '\\' && (!argv[0][0] || argv[0][1] != ':')) 1494 && strchr (argv[0], '\\') != 0 1495 #endif 1496 ) 1497 argv[0] = xstrdup (concat (current_directory, "/", argv[0])); 1476 1498 #endif /* !__MSDOS__ */ 1477 1499 #endif /* WINDOWS32 */ … … 1507 1529 1508 1530 /* Now allocate a buffer big enough and fill it. */ 1509 p = value = (char *)alloca (len);1531 p = value = alloca (len); 1510 1532 for (cv = command_variables; cv != 0; cv = cv->next) 1511 1533 { … … 1590 1612 } 1591 1613 } 1592 #endif 1614 #endif /* KMK */ 1593 1615 1594 1616 /* If there were -C flags, move ourselves about. */ 1595 1617 if (directories != 0) 1596 for (i = 0; directories->list[i] != 0; ++i) 1597 { 1598 char *dir = directories->list[i]; 1599 char *expanded = 0; 1600 if (dir[0] == '~') 1601 { 1602 expanded = tilde_expand (dir); 1603 if (expanded != 0) 1604 dir = expanded; 1605 } 1618 { 1619 unsigned int i; 1620 for (i = 0; directories->list[i] != 0; ++i) 1621 { 1622 const char *dir = directories->list[i]; 1606 1623 #ifdef WINDOWS32 1607 /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/' 1608 But allow -C/ just in case someone wants that. */ 1609 { 1610 char *p = dir + strlen (dir) - 1; 1611 while (p > dir && (p[0] == '/' || p[0] == '\\')) 1612 --p; 1613 p[1] = '\0'; 1624 /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/' 1625 But allow -C/ just in case someone wants that. */ 1626 { 1627 char *p = (char *)dir + strlen (dir) - 1; 1628 while (p > dir && (p[0] == '/' || p[0] == '\\')) 1629 --p; 1630 p[1] = '\0'; 1631 } 1632 #endif 1633 if (chdir (dir) < 0) 1634 pfatal_with_name (dir); 1614 1635 } 1615 #endif 1616 if (chdir (dir) < 0) 1617 pfatal_with_name (dir); 1618 if (expanded) 1619 free (expanded); 1620 } 1636 } 1621 1637 1622 1638 #ifdef WINDOWS32 … … 1656 1672 /* Construct the list of include directories to search. */ 1657 1673 1658 construct_include_path (include_directories == 0 ? (char **) 01659 1674 construct_include_path (include_directories == 0 1675 ? 0 : include_directories->list); 1660 1676 1661 1677 /* Figure out where we are now, after chdir'ing. */ … … 1688 1704 if (makefiles != 0) 1689 1705 { 1690 registerunsigned int i;1706 unsigned int i; 1691 1707 for (i = 0; i < makefiles->idx; ++i) 1692 1708 if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0') … … 1721 1737 tmpdir = DEFAULT_TMPDIR; 1722 1738 1723 template = (char *) alloca (strlen (tmpdir) 1724 + sizeof (DEFAULT_TMPFILE) + 1); 1739 template = alloca (strlen (tmpdir) + sizeof (DEFAULT_TMPFILE) + 1); 1725 1740 strcpy (template, tmpdir); 1726 1741 … … 1746 1761 pfatal_with_name (_("fwrite (temporary file)")); 1747 1762 } 1748 (void)fclose (outfile);1763 fclose (outfile); 1749 1764 1750 1765 /* Replace the name that read_all_makefiles will 1751 1766 see with the name of the temporary file. */ 1752 makefiles->list[i] = xstrdup(stdin_nm);1767 makefiles->list[i] = strcache_add (stdin_nm); 1753 1768 1754 1769 /* Make sure the temporary file will not be remade. */ 1755 f = enter_file (stdin_nm); 1756 f->updated = 1; 1757 f->update_status = 0; 1758 f->command_state = cs_finished; 1759 /* Can't be intermediate, or it'll be removed too early for 1760 make re-exec. */ 1761 f->intermediate = 0; 1762 f->dontcare = 0; 1770 { 1771 struct file *f = enter_file (strcache_add (stdin_nm)); 1772 f->updated = 1; 1773 f->update_status = 0; 1774 f->command_state = cs_finished; 1775 /* Can't be intermediate, or it'll be removed too early for 1776 make re-exec. */ 1777 f->intermediate = 0; 1778 f->dontcare = 0; 1779 } 1763 1780 } 1764 1781 } 1765 1782 1766 #if !defined(__EMX__) || defined(__KLIBC__) /* Don't use a SIGCHLD handler for good old EMX */1783 #if !defined(__EMX__) || defined(__KLIBC__) /* Don't use a SIGCHLD handler for good old EMX (bird) */ 1767 1784 #if defined(MAKE_JOBSERVER) || !defined(HAVE_WAIT_NOHANG) 1768 1785 /* Set up to handle children dying. This must be done before … … 1779 1796 If none of these are true, we don't need a signal handler at all. */ 1780 1797 { 1781 extern RETSIGTYPE child_handler PARAMS ((int sig));1798 RETSIGTYPE child_handler (int sig); 1782 1799 # if defined SIGCHLD 1783 1800 bsd_signal (SIGCHLD, child_handler); … … 1819 1836 define_default_variables (); 1820 1837 1821 default_file = enter_file ( ".DEFAULT");1838 default_file = enter_file (strcache_add (".DEFAULT")); 1822 1839 1823 1840 { … … 1829 1846 1830 1847 read_makefiles 1831 = read_all_makefiles (makefiles == 0 ? (char **)0 : makefiles->list);1848 = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list); 1832 1849 1833 1850 #ifdef WINDOWS32 … … 1884 1901 if (jobserver_fds) 1885 1902 { 1886 c har *cp;1903 const char *cp; 1887 1904 unsigned int ui; 1888 1905 … … 1898 1915 fatal (NILF, 1899 1916 _("internal error: invalid --jobserver-fds string `%s'"), cp); 1917 1918 DB (DB_JOBS, 1919 (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1])); 1900 1920 1901 1921 /* The combination of a pipe + !job_slots means we're using the … … 1940 1960 if (job_slots > 1) 1941 1961 { 1962 char *cp; 1942 1963 char c = '+'; 1943 1964 … … 1963 1984 /* Fill in the jobserver_fds struct for our children. */ 1964 1985 1986 cp = xmalloc ((sizeof ("1024")*2)+1); 1987 sprintf (cp, "%d,%d", job_fds[0], job_fds[1]); 1988 1965 1989 jobserver_fds = (struct stringlist *) 1966 1990 xmalloc (sizeof (struct stringlist)); 1967 jobserver_fds->list = (char **) xmalloc (sizeof (char *)); 1968 jobserver_fds->list[0] = xmalloc ((sizeof ("1024")*2)+1); 1969 1970 sprintf (jobserver_fds->list[0], "%d,%d", job_fds[0], job_fds[1]); 1991 jobserver_fds->list = xmalloc (sizeof (char *)); 1992 jobserver_fds->list[0] = cp; 1971 1993 jobserver_fds->idx = 1; 1972 1994 jobserver_fds->max = 1; … … 2018 2040 2019 2041 if (old_files != 0) 2020 for (p = old_files->list; *p != 0; ++p) 2021 { 2022 f = enter_command_line_file (*p); 2023 f->last_mtime = f->mtime_before_update = OLD_MTIME; 2024 f->updated = 1; 2025 f->update_status = 0; 2026 f->command_state = cs_finished; 2027 } 2042 { 2043 const char **p; 2044 for (p = old_files->list; *p != 0; ++p) 2045 { 2046 struct file *f = enter_file (*p); 2047 f->last_mtime = f->mtime_before_update = OLD_MTIME; 2048 f->updated = 1; 2049 f->update_status = 0; 2050 f->command_state = cs_finished; 2051 } 2052 } 2028 2053 2029 2054 if (!restarts && new_files != 0) 2030 2055 { 2056 const char **p; 2031 2057 for (p = new_files->list; *p != 0; ++p) 2032 2058 { 2033 f = enter_command_line_file (*p);2059 struct file *f = enter_file (*p); 2034 2060 f->last_mtime = f->mtime_before_update = NEW_MTIME; 2035 2061 } … … 2063 2089 while (d != 0) 2064 2090 { 2065 registerstruct file *f = d->file;2091 struct file *f = d->file; 2066 2092 if (f->double_colon) 2067 2093 for (f = f->double_colon; f != NULL; f = f->prev) … … 2096 2122 if (f == NULL || !f->double_colon) 2097 2123 { 2098 makefile_mtimes = (FILE_TIMESTAMP *)2099 xrealloc ((char *) makefile_mtimes,2100 (mm_idx + 1)* sizeof (FILE_TIMESTAMP));2124 makefile_mtimes = xrealloc (makefile_mtimes, 2125 (mm_idx+1) 2126 * sizeof (FILE_TIMESTAMP)); 2101 2127 makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file); 2102 2128 last = d; … … 2217 2243 char *p = &argv[i][2]; 2218 2244 if (*p == '\0') 2219 argv[++i] = makefiles->list[j]; 2245 /* This cast is OK since we never modify argv. */ 2246 argv[++i] = (char *) makefiles->list[j]; 2220 2247 else 2221 argv[i] = concat ("-f", makefiles->list[j], "");2248 argv[i] = xstrdup (concat ("-f", makefiles->list[j], "")); 2222 2249 ++j; 2223 2250 } … … 2227 2254 if (stdin_nm) 2228 2255 { 2229 nargv = (char **)xmalloc ((nargc + 2) * sizeof (char *));2230 bcopy ((char *) argv, (char *) nargv, argc * sizeof (char *));2231 nargv[nargc++] = concat ("-o", stdin_nm, "");2256 nargv = xmalloc ((nargc + 2) * sizeof (char *)); 2257 memcpy (nargv, argv, argc * sizeof (char *)); 2258 nargv[nargc++] = xstrdup (concat ("-o", stdin_nm, "")); 2232 2259 nargv[nargc] = 0; 2233 2260 } … … 2235 2262 if (directories != 0 && directories->idx > 0) 2236 2263 { 2237 char bad;2264 int bad = 1; 2238 2265 if (directory_before_chdir != 0) 2239 2266 { 2240 2267 if (chdir (directory_before_chdir) < 0) 2241 {2242 2268 perror_with_name ("chdir", ""); 2243 bad = 1;2244 }2245 2269 else 2246 2270 bad = 0; 2247 2271 } 2248 else2249 bad = 1;2250 2272 if (bad) 2251 2273 fatal (NILF, _("Couldn't change back to original directory.")); … … 2264 2286 2265 2287 #ifndef _AMIGA 2266 for (p = environ; *p != 0; ++p) 2267 { 2268 if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH) 2269 && (*p)[MAKELEVEL_LENGTH] == '=') 2270 { 2271 /* The SGI compiler apparently can't understand 2272 the concept of storing the result of a function 2273 in something other than a local variable. */ 2274 char *sgi_loses; 2275 sgi_loses = (char *) alloca (40); 2276 *p = sgi_loses; 2277 sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel); 2278 } 2279 if (strneq (*p, "MAKE_RESTARTS=", 14)) 2280 { 2281 char *sgi_loses; 2282 sgi_loses = (char *) alloca (40); 2283 *p = sgi_loses; 2284 sprintf (*p, "MAKE_RESTARTS=%u", restarts); 2285 restarts = 0; 2286 } 2287 } 2288 { 2289 char **p; 2290 for (p = environ; *p != 0; ++p) 2291 { 2292 if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH) 2293 && (*p)[MAKELEVEL_LENGTH] == '=') 2294 { 2295 *p = alloca (40); 2296 sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel); 2297 } 2298 if (strneq (*p, "MAKE_RESTARTS=", 14)) 2299 { 2300 *p = alloca (40); 2301 sprintf (*p, "MAKE_RESTARTS=%u", restarts); 2302 restarts = 0; 2303 } 2304 } 2305 } 2288 2306 #else /* AMIGA */ 2289 2307 { … … 2351 2369 /* Free the makefile mtimes (if we allocated any). */ 2352 2370 if (makefile_mtimes) 2353 free ( (char *)makefile_mtimes);2371 free (makefile_mtimes); 2354 2372 } 2355 2373 … … 2363 2381 if (restarts && new_files != 0) 2364 2382 { 2383 const char **p; 2365 2384 for (p = new_files->list; *p != 0; ++p) 2366 2385 { 2367 f = enter_command_line_file (*p);2386 struct file *f = enter_file (*p); 2368 2387 f->last_mtime = f->mtime_before_update = NEW_MTIME; 2369 2388 } … … 2404 2423 fatal (NILF, _(".DEFAULT_GOAL contains more than one target")); 2405 2424 2406 default_goal_file = enter_file ( ns->name);2425 default_goal_file = enter_file (strcache_add (ns->name)); 2407 2426 2408 2427 ns->name = 0; /* It was reused by enter_file(). */ … … 2508 2527 2509 2528 case string: 2529 case filename: 2510 2530 case positive_int: 2511 2531 case floating: … … 2552 2572 2553 2573 if (! cv) { 2554 cv = (struct command_variable *)xmalloc (sizeof (*cv));2574 cv = xmalloc (sizeof (*cv)); 2555 2575 cv->variable = v; 2556 2576 cv->next = command_variables; … … 2563 2583 target! Enter it as a file and add it to the dep chain of 2564 2584 goals. */ 2565 struct file *f = enter_ command_line_file (arg);2585 struct file *f = enter_file (strcache_add (expand_command_line_file (arg))); 2566 2586 f->cmd_target = 1; 2567 2587 … … 2581 2601 { 2582 2602 /* Add this target name to the MAKECMDGOALS variable. */ 2583 struct variable * v;2584 c har *value;2585 2586 v = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));2587 if ( v == 0)2603 struct variable *gv; 2604 const char *value; 2605 2606 gv = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS")); 2607 if (gv == 0) 2588 2608 value = f->name; 2589 2609 else … … 2591 2611 /* Paste the old and new values together */ 2592 2612 unsigned int oldlen, newlen; 2593 2594 oldlen = strlen (v->value); 2613 char *vp; 2614 2615 oldlen = strlen (gv->value); 2595 2616 newlen = strlen (f->name); 2596 value = (char *) alloca (oldlen + 1 + newlen + 1); 2597 bcopy (v->value, value, oldlen); 2598 value[oldlen] = ' '; 2599 bcopy (f->name, &value[oldlen + 1], newlen + 1); 2617 vp = alloca (oldlen + 1 + newlen + 1); 2618 memcpy (vp, gv->value, oldlen); 2619 vp[oldlen] = ' '; 2620 memcpy (&vp[oldlen + 1], f->name, newlen + 1); 2621 value = vp; 2600 2622 } 2601 2623 define_variable ("MAKECMDGOALS", 12, value, o_default, 0); … … 2629 2651 printf (_("\nThis program is built for %s/%s/%s (%s) [" __DATE__ " " __TIME__ "]\n"), 2630 2652 BUILD_PLATFORM, BUILD_PLATFORM_ARCH, BUILD_PLATFORM_CPU, remote_description); 2631 #else 2653 #else /* !KMK */ 2632 2654 if (!remote_description || *remote_description == '\0') 2633 2655 fprintf (usageto, _("\nThis program built for %s\n"), make_host); … … 2635 2657 fprintf (usageto, _("\nThis program built for %s (%s)\n"), 2636 2658 make_host, remote_description); 2637 #endif 2659 #endif /* !KMK */ 2638 2660 2639 2661 fprintf (usageto, _("Report bugs to <bug-make@gnu.org>\n")); … … 2702 2724 2703 2725 case string: 2726 case filename: 2704 2727 if (!doit) 2705 2728 break; 2706 2729 2707 2730 if (optarg == 0) 2708 optarg = cs->noarg_value;2731 optarg = xstrdup (cs->noarg_value); 2709 2732 else if (*optarg == '\0') 2710 2733 { … … 2721 2744 sl->max = 5; 2722 2745 sl->idx = 0; 2723 sl->list = (char **)xmalloc (5 * sizeof (char *));2746 sl->list = xmalloc (5 * sizeof (char *)); 2724 2747 *(struct stringlist **) cs->value_ptr = sl; 2725 2748 } … … 2727 2750 { 2728 2751 sl->max += 5; 2729 sl->list = (char **) 2730 xrealloc ((char *) sl->list, 2731 sl->max * sizeof (char *)); 2752 sl->list = xrealloc (sl->list, 2753 sl->max * sizeof (char *)); 2732 2754 } 2733 sl->list[sl->idx++] = optarg; 2755 if (cs->type == filename) 2756 sl->list[sl->idx++] = expand_command_line_file (optarg); 2757 else 2758 sl->list[sl->idx++] = optarg; 2734 2759 sl->list[sl->idx] = 0; 2735 2760 break; … … 2816 2841 decode_env_switches (char *envar, unsigned int len) 2817 2842 { 2818 char *varref = (char *)alloca (2 + len + 2);2843 char *varref = alloca (2 + len + 2); 2819 2844 char *value, *p; 2820 2845 int argc; … … 2824 2849 varref[0] = '$'; 2825 2850 varref[1] = '('; 2826 bcopy (envar, &varref[2], len);2851 memcpy (&varref[2], envar, len); 2827 2852 varref[2 + len] = ')'; 2828 2853 varref[2 + len + 1] = '\0'; … … 2836 2861 2837 2862 /* Allocate a vector that is definitely big enough. */ 2838 argv = (char **)alloca ((1 + len + 1) * sizeof (char *));2863 argv = alloca ((1 + len + 1) * sizeof (char *)); 2839 2864 2840 2865 /* Allocate a buffer to copy the value into while we split it into words 2841 2866 and unquote it. We must use permanent storage for this because 2842 2867 decode_switches may store pointers into the passed argument words. */ 2843 p = (char *)xmalloc (2 * len);2868 p = xmalloc (2 * len); 2844 2869 2845 2870 /* getopt will look at the arguments starting at ARGV[1]. … … 2872 2897 need permanent storage for this in case decode_switches saves 2873 2898 pointers into the value. */ 2874 argv[1] = concat ("-", argv[1], "");2899 argv[1] = xstrdup (concat ("-", argv[1], "")); 2875 2900 2876 2901 /* Parse those words. */ … … 2886 2911 2887 2912 static char * 2888 quote_for_env (char *out, c har *in)2913 quote_for_env (char *out, const char *in) 2889 2914 { 2890 2915 while (*in != '\0') … … 2924 2949 struct flag *next; 2925 2950 const struct command_switch *cs; 2926 c har *arg;2951 const char *arg; 2927 2952 }; 2928 2953 struct flag *flags = 0; … … 2930 2955 #define ADD_FLAG(ARG, LEN) \ 2931 2956 do { \ 2932 struct flag *new = (struct flag *) alloca (sizeof (struct flag));\2957 struct flag *new = alloca (sizeof (struct flag)); \ 2933 2958 new->cs = cs; \ 2934 2959 new->arg = (ARG); \ … … 2948 2973 switch (cs->type) 2949 2974 { 2950 default:2951 abort ();2952 2953 2975 case ignore: 2954 2976 break; … … 2980 3002 else 2981 3003 { 2982 char *buf = (char *)alloca (30);3004 char *buf = alloca (30); 2983 3005 sprintf (buf, "%u", *(unsigned int *) cs->value_ptr); 2984 3006 ADD_FLAG (buf, strlen (buf)); … … 3001 3023 else 3002 3024 { 3003 char *buf = (char *)alloca (100);3025 char *buf = alloca (100); 3004 3026 sprintf (buf, "%g", *(double *) cs->value_ptr); 3005 3027 ADD_FLAG (buf, strlen (buf)); … … 3009 3031 #endif 3010 3032 3033 case filename: 3011 3034 case string: 3012 3035 if (all) … … 3015 3038 if (sl != 0) 3016 3039 { 3017 /* Add the elements in reverse order, because 3018 all the flags get reversed below; and the order3019 matters for someswitches (like -I). */3020 registerunsigned int i = sl->idx;3040 /* Add the elements in reverse order, because all the flags 3041 get reversed below; and the order matters for some 3042 switches (like -I). */ 3043 unsigned int i = sl->idx; 3021 3044 while (i-- > 0) 3022 3045 ADD_FLAG (sl->list[i], strlen (sl->list[i])); … … 3024 3047 } 3025 3048 break; 3049 3050 default: 3051 abort (); 3026 3052 } 3027 3053 … … 3032 3058 /* Construct the value in FLAGSTRING. 3033 3059 We allocate enough space for a preceding dash and trailing null. */ 3034 flagstring = (char *)alloca (1 + flagslen + 1);3035 bzero (flagstring, 1 + flagslen + 1);3060 flagstring = alloca (1 + flagslen + 1); 3061 memset (flagstring, '\0', 1 + flagslen + 1); 3036 3062 p = flagstring; 3037 3063 words = 1; … … 3125 3151 if (posix_pedantic) 3126 3152 { 3127 bcopy (posixref, p, sizeof posixref - 1);3153 memcpy (p, posixref, sizeof posixref - 1); 3128 3154 p += sizeof posixref - 1; 3129 3155 } 3130 3156 else 3131 3157 { 3132 bcopy (ref, p, sizeof ref - 1);3158 memcpy (p, ref, sizeof ref - 1); 3133 3159 p += sizeof ref - 1; 3134 3160 } … … 3342 3368 if (print_data_base_flag) 3343 3369 print_data_base (); 3370 3371 verify_file_data_base (); 3344 3372 3345 3373 clean_jobserver (status);
Note:
See TracChangeset
for help on using the changeset viewer.