Changeset 900 for vendor/gnumake/current/main.c
- Timestamp:
- May 23, 2007, 5:13:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/main.c
r501 r900 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 … … 73 75 74 76 #ifndef HAVE_UNISTD_H 75 externint chdir ();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. */ … … 158 161 159 162 int db_level = 0; 163 164 /* Output level (--verbosity). */ 165 166 static struct stringlist *verbosity_flags; 160 167 161 168 #ifdef WINDOWS32 … … 282 289 283 290 struct variable shell_var; 291 292 /* This character introduces a command: it's the first char on the line. */ 293 294 char cmd_prefix = '\t'; 284 295 285 296 … … 365 376 { 366 377 { 'b', ignore, 0, 0, 0, 0, 0, 0, 0 }, 367 { 'B', flag, (char *)&always_make_set, 1, 1, 0, 0, 0, "always-make" },368 { 'C', string, (char *)&directories, 0, 0, 0, 0, 0, "directory" },369 { 'd', flag, (char *)&debug_flag, 1, 1, 0, 0, 0, 0 },370 { CHAR_MAX+1, string, (char *)&db_flags, 1, 1, 0, "basic", 0, "debug" },378 { 'B', flag, &always_make_set, 1, 1, 0, 0, 0, "always-make" }, 379 { 'C', filename, &directories, 0, 0, 0, 0, 0, "directory" }, 380 { 'd', flag, &debug_flag, 1, 1, 0, 0, 0, 0 }, 381 { CHAR_MAX+1, string, &db_flags, 1, 1, 0, "basic", 0, "debug" }, 371 382 #ifdef WINDOWS32 372 { 'D', flag, (char *) &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" }, 373 #endif 374 { 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0, 375 "environment-overrides", }, 376 { 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0, "file" }, 377 { 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0, "help" }, 378 { 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0, 379 "ignore-errors" }, 380 { 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0, 383 { 'D', flag, &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" }, 384 #endif 385 { 'e', flag, &env_overrides, 1, 1, 0, 0, 0, "environment-overrides", }, 386 { 'f', filename, &makefiles, 0, 0, 0, 0, 0, "file" }, 387 { 'h', flag, &print_usage_flag, 0, 0, 0, 0, 0, "help" }, 388 { 'i', flag, &ignore_errors_flag, 1, 1, 0, 0, 0, "ignore-errors" }, 389 { 'I', filename, &include_directories, 1, 1, 0, 0, 0, 381 390 "include-dir" }, 382 { 'j', positive_int, (char *) &job_slots, 1, 1, 0, (char *) &inf_jobs, 383 (char *) &default_job_slots, "jobs" }, 384 { CHAR_MAX+2, string, (char *) &jobserver_fds, 1, 1, 0, 0, 0, 385 "jobserver-fds" }, 386 { 'k', flag, (char *) &keep_going_flag, 1, 1, 0, 0, 387 (char *) &default_keep_going_flag, "keep-going" }, 391 { 'j', positive_int, &job_slots, 1, 1, 0, &inf_jobs, &default_job_slots, 392 "jobs" }, 393 { CHAR_MAX+2, string, &jobserver_fds, 1, 1, 0, 0, 0, "jobserver-fds" }, 394 { 'k', flag, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag, 395 "keep-going" }, 388 396 #ifndef NO_FLOAT 389 { 'l', floating, (char *) &max_load_average, 1, 1, 0, 390 (char *) &default_load_average, (char *) &default_load_average, 391 "load-average" }, 397 { 'l', floating, &max_load_average, 1, 1, 0, &default_load_average, 398 &default_load_average, "load-average" }, 392 399 #else 393 { 'l', positive_int, (char *) &max_load_average, 1, 1, 0, 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" }, 400 { 'l', positive_int, &max_load_average, 1, 1, 0, &default_load_average, 401 &default_load_average, "load-average" }, 402 #endif 403 { 'L', flag, &check_symlink_flag, 1, 1, 0, 0, 0, "check-symlink-times" }, 399 404 { 'm', ignore, 0, 0, 0, 0, 0, 0, 0 }, 400 { 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0, "just-print" }, 401 { 'o', string, (char *) &old_files, 0, 0, 0, 0, 0, "old-file" }, 402 { 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0, 403 "print-data-base" }, 404 { 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0, "question" }, 405 { 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0, 406 "no-builtin-rules" }, 407 { 'R', flag, (char *) &no_builtin_variables_flag, 1, 1, 0, 0, 0, 405 { 'n', flag, &just_print_flag, 1, 1, 1, 0, 0, "just-print" }, 406 { 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" }, 407 { 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, "print-data-base" }, 408 { 'q', flag, &question_flag, 1, 1, 1, 0, 0, "question" }, 409 { 'r', flag, &no_builtin_rules_flag, 1, 1, 0, 0, 0, "no-builtin-rules" }, 410 { 'R', flag, &no_builtin_variables_flag, 1, 1, 0, 0, 0, 408 411 "no-builtin-variables" }, 409 { 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0, "silent" }, 410 { 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0, 0, 411 (char *) &default_keep_going_flag, "no-keep-going" }, 412 { 't', flag, (char *) &touch_flag, 1, 1, 1, 0, 0, "touch" }, 413 { 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0, "version" }, 414 { 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0, 415 "print-directory" }, 416 { CHAR_MAX+3, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0, 412 { 's', flag, &silent_flag, 1, 1, 0, 0, 0, "silent" }, 413 { 'S', flag_off, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag, 414 "no-keep-going" }, 415 { 't', flag, &touch_flag, 1, 1, 1, 0, 0, "touch" }, 416 { 'v', flag, &print_version_flag, 1, 1, 0, 0, 0, "version" }, 417 { CHAR_MAX+3, string, &verbosity_flags, 1, 1, 0, 0, 0, 418 "verbosity" }, 419 { 'w', flag, &print_directory_flag, 1, 1, 0, 0, 0, "print-directory" }, 420 { CHAR_MAX+4, flag, &inhibit_print_directory_flag, 1, 1, 0, 0, 0, 417 421 "no-print-directory" }, 418 { 'W', string, (char *)&new_files, 0, 0, 0, 0, 0, "what-if" },419 { CHAR_MAX+ 4, flag, (char *)&warn_undefined_variables_flag, 1, 1, 0, 0, 0,422 { 'W', filename, &new_files, 0, 0, 0, 0, 0, "what-if" }, 423 { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0, 420 424 "warn-undefined-variables" }, 421 425 { 0, 0, 0, 0, 0, 0, 0, 0, 0 } … … 547 551 } 548 552 549 static struct file*550 e nter_command_line_file (char *name)553 static const char * 554 expand_command_line_file (char *name) 551 555 { 556 const char *cp; 557 char *expanded = 0; 558 552 559 if (name[0] == '\0') 553 560 fatal (NILF, _("empty string invalid as file name")); … … 555 562 if (name[0] == '~') 556 563 { 557 char *expanded = tilde_expand (name);564 expanded = tilde_expand (name); 558 565 if (expanded != 0) 559 name = expanded; /* Memory leak; I don't care. */566 name = expanded; 560 567 } 561 568 … … 581 588 } 582 589 583 return enter_file (xstrdup (name)); 590 cp = strcache_add (name); 591 592 if (expanded) 593 free (expanded); 594 595 return cp; 584 596 } 585 597 … … 597 609 decode_debug_flags (void) 598 610 { 599 c har **pp;611 const char **pp; 600 612 601 613 if (debug_flag) … … 732 744 733 745 int 734 find_and_set_default_shell (c har *token)746 find_and_set_default_shell (const char *token) 735 747 { 736 748 int sh_found = 0; 749 char *atoken = 0; 737 750 char *search_token; 738 751 char *tokend; … … 743 756 search_token = default_shell; 744 757 else 745 search_token = token; 746 758 atoken = search_token = xstrdup (token); 747 759 748 760 /* If the user explicitly requests the DOS cmd shell, obey that request. … … 754 766 || (tokend > search_token 755 767 && (tokend[-1] == '/' || tokend[-1] == '\\'))) 756 && !strc mpi(tokend, "cmd"))768 && !strcasecmp (tokend, "cmd")) 757 769 || ((tokend - 4 == search_token 758 770 || (tokend - 4 > search_token 759 771 && (tokend[-5] == '/' || tokend[-5] == '\\'))) 760 && !strc mpi(tokend - 4, "cmd.exe"))) {772 && !strcasecmp (tokend - 4, "cmd.exe"))) { 761 773 batch_mode_shell = 1; 762 774 unixy_shell = 0; … … 770 782 /* no new information, path already set or known */ 771 783 sh_found = 1; 772 } else if (file_exists_p (search_token)) {784 } else if (file_exists_p (search_token)) { 773 785 /* search token path was found */ 774 sprintf (sh_path, "%s", search_token);775 default_shell = xstrdup (w32ify(sh_path,0));786 sprintf (sh_path, "%s", search_token); 787 default_shell = xstrdup (w32ify (sh_path, 0)); 776 788 DB (DB_VERBOSE, 777 789 (_("find_and_set_shell setting default_shell = %s\n"), default_shell)); … … 786 798 787 799 p = v->value; 788 ep = strchr (p, PATH_SEPARATOR_CHAR);800 ep = strchr (p, PATH_SEPARATOR_CHAR); 789 801 790 802 while (ep && *ep) { 791 803 *ep = '\0'; 792 804 793 if (dir_file_exists_p (p, search_token)) {794 sprintf (sh_path, "%s/%s", p, search_token);795 default_shell = xstrdup (w32ify(sh_path,0));805 if (dir_file_exists_p (p, search_token)) { 806 sprintf (sh_path, "%s/%s", p, search_token); 807 default_shell = xstrdup (w32ify (sh_path, 0)); 796 808 sh_found = 1; 797 809 *ep = PATH_SEPARATOR_CHAR; 798 810 799 811 /* terminate loop */ 800 p += strlen (p);812 p += strlen (p); 801 813 } else { 802 814 *ep = PATH_SEPARATOR_CHAR; … … 804 816 } 805 817 806 ep = strchr (p, PATH_SEPARATOR_CHAR);818 ep = strchr (p, PATH_SEPARATOR_CHAR); 807 819 } 808 820 809 821 /* be sure to check last element of Path */ 810 if (p && *p && dir_file_exists_p (p, search_token)) {811 sprintf (sh_path, "%s/%s", p, search_token);812 default_shell = xstrdup (w32ify(sh_path,0));822 if (p && *p && dir_file_exists_p (p, search_token)) { 823 sprintf (sh_path, "%s/%s", p, search_token); 824 default_shell = xstrdup (w32ify (sh_path, 0)); 813 825 sh_found = 1; 814 826 } … … 823 835 /* naive test */ 824 836 if (!unixy_shell && sh_found && 825 (strstr (default_shell, "sh") || strstr(default_shell, "SH"))) {837 (strstr (default_shell, "sh") || strstr (default_shell, "SH"))) { 826 838 unixy_shell = 1; 827 839 batch_mode_shell = 0; … … 832 844 #endif 833 845 846 if (atoken) 847 free (atoken); 848 834 849 return (sh_found); 835 850 } 836 851 #endif /* WINDOWS32 */ 837 852 838 #ifdef __MSDOS__ 839 853 #ifdef __MSDOS__ 840 854 static void 841 855 msdos_return_to_initial_directory (void) … … 844 858 chdir (directory_before_chdir); 845 859 } 846 #endif 847 848 extern char *mktemp PARAMS ((char *template));849 extern int mkstemp PARAMS ((char *template));860 #endif /* __MSDOS__ */ 861 862 char *mktemp (char *template); 863 int mkstemp (char *template); 850 864 851 865 FILE * … … 900 914 { 901 915 static char *stdin_nm = 0; 902 struct file *f;903 int i;904 916 int makefile_status = MAKE_SUCCESS; 905 char **p;906 917 struct dep *read_makefiles; 907 918 PATH_VAR (current_directory); … … 1026 1037 # else /* setvbuf not reversed. */ 1027 1038 /* Some buggy systems lose if we pass 0 instead of allocating ourselves. */ 1028 setvbuf (stdout, (char *)0, _IOLBF, BUFSIZ);1039 setvbuf (stdout, 0, _IOLBF, BUFSIZ); 1029 1040 # endif /* setvbuf reversed. */ 1030 1041 #elif HAVE_SETLINEBUF … … 1134 1145 1135 1146 #ifndef _AMIGA 1136 for (i = 0; envp[i] != 0; ++i) 1137 { 1138 int do_not_define = 0; 1139 char *ep = envp[i]; 1140 1141 while (*ep != '\0' && *ep != '=') 1142 ++ep; 1147 { 1148 unsigned int i; 1149 1150 for (i = 0; envp[i] != 0; ++i) 1151 { 1152 int do_not_define = 0; 1153 char *ep = envp[i]; 1154 1155 while (*ep != '\0' && *ep != '=') 1156 ++ep; 1143 1157 #ifdef WINDOWS32 1144 if (!unix_path && strneq(envp[i], "PATH=", 5)) 1145 unix_path = ep+1; 1146 else if (!strnicmp(envp[i], "Path=", 5)) { 1147 do_not_define = 1; /* it gets defined after loop exits */ 1148 if (!windows32_path) 1149 windows32_path = ep+1; 1158 if (!unix_path && strneq(envp[i], "PATH=", 5)) 1159 unix_path = ep+1; 1160 else if (!strnicmp(envp[i], "Path=", 5)) { 1161 do_not_define = 1; /* it gets defined after loop exits */ 1162 if (!windows32_path) 1163 windows32_path = ep+1; 1164 } 1165 #endif 1166 /* The result of pointer arithmetic is cast to unsigned int for 1167 machines where ptrdiff_t is a different size that doesn't widen 1168 the same. */ 1169 if (!do_not_define) 1170 { 1171 struct variable *v; 1172 1173 v = define_variable (envp[i], (unsigned int) (ep - envp[i]), 1174 ep + 1, o_env, 1); 1175 /* Force exportation of every variable culled from the 1176 environment. We used to rely on target_environment's 1177 v_default code to do this. But that does not work for the 1178 case where an environment variable is redefined in a makefile 1179 with `override'; it should then still be exported, because it 1180 was originally in the environment. */ 1181 v->export = v_export; 1182 1183 /* Another wrinkle is that POSIX says the value of SHELL set in 1184 the makefile won't change the value of SHELL given to 1185 subprocesses. */ 1186 if (streq (v->name, "SHELL")) 1187 { 1188 #ifndef __MSDOS__ 1189 v->export = v_noexport; 1190 #endif 1191 shell_var.name = "SHELL"; 1192 shell_var.value = xstrdup (ep + 1); 1193 } 1194 1195 /* If MAKE_RESTARTS is set, remember it but don't export it. */ 1196 if (streq (v->name, "MAKE_RESTARTS")) 1197 { 1198 v->export = v_noexport; 1199 restarts = (unsigned int) atoi (ep + 1); 1200 } 1201 } 1150 1202 } 1151 #endif 1152 /* The result of pointer arithmetic is cast to unsigned int for 1153 machines where ptrdiff_t is a different size that doesn't widen 1154 the same. */ 1155 if (!do_not_define) 1156 { 1157 struct variable *v; 1158 1159 v = define_variable (envp[i], (unsigned int) (ep - envp[i]), 1160 ep + 1, o_env, 1); 1161 /* Force exportation of every variable culled from the environment. 1162 We used to rely on target_environment's v_default code to do this. 1163 But that does not work for the case where an environment variable 1164 is redefined in a makefile with `override'; it should then still 1165 be exported, because it was originally in the environment. */ 1166 v->export = v_export; 1167 1168 /* Another wrinkle is that POSIX says the value of SHELL set in the 1169 makefile won't change the value of SHELL given to subprocesses */ 1170 if (streq (v->name, "SHELL")) 1171 { 1172 #ifndef __MSDOS__ 1173 v->export = v_noexport; 1174 #endif 1175 shell_var.name = "SHELL"; 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); 1184 } 1185 } 1186 } 1203 } 1187 1204 #ifdef WINDOWS32 1188 1205 /* If we didn't find a correctly spelled PATH we define PATH as … … 1230 1247 #if 0 1231 1248 /* People write things like: 1232 1249 MFLAGS="CC=gcc -pipe" "CFLAGS=-g" 1233 1250 and we set the -p, -i and -e switches. Doesn't seem quite right. */ 1234 1251 decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS")); … … 1293 1310 && argv[0] != 0 1294 1311 && (argv[0][0] != '/' && (argv[0][0] == '\0' || argv[0][1] != ':')) 1295 # ifdef __EMX__1312 # ifdef __EMX__ 1296 1313 /* do not prepend cwd if argv[0] contains no '/', e.g. "make" */ 1297 1314 && (strchr (argv[0], '/') != 0 || strchr (argv[0], '\\') != 0) 1298 1315 # endif 1299 1316 ) 1300 argv[0] = concat (current_directory, "/", argv[0]);1317 argv[0] = xstrdup (concat (current_directory, "/", argv[0])); 1301 1318 #else /* !__MSDOS__ */ 1302 1319 if (current_directory[0] != '\0' 1303 && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0) 1304 argv[0] = concat (current_directory, "/", argv[0]); 1320 && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0 1321 #ifdef HAVE_DOS_PATHS 1322 && (argv[0][0] != '\\' && (!argv[0][0] || argv[0][1] != ':')) 1323 && strchr (argv[0], '\\') != 0 1324 #endif 1325 ) 1326 argv[0] = xstrdup (concat (current_directory, "/", argv[0])); 1305 1327 #endif /* !__MSDOS__ */ 1306 1328 #endif /* WINDOWS32 */ … … 1333 1355 1334 1356 /* Now allocate a buffer big enough and fill it. */ 1335 p = value = (char *)alloca (len);1357 p = value = alloca (len); 1336 1358 for (cv = command_variables; cv != 0; cv = cv->next) 1337 1359 { … … 1363 1385 /* If there were -C flags, move ourselves about. */ 1364 1386 if (directories != 0) 1365 for (i = 0; directories->list[i] != 0; ++i) 1366 { 1367 char *dir = directories->list[i]; 1368 char *expanded = 0; 1369 if (dir[0] == '~') 1370 { 1371 expanded = tilde_expand (dir); 1372 if (expanded != 0) 1373 dir = expanded; 1374 } 1387 { 1388 unsigned int i; 1389 for (i = 0; directories->list[i] != 0; ++i) 1390 { 1391 const char *dir = directories->list[i]; 1375 1392 #ifdef WINDOWS32 1376 /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/' 1377 But allow -C/ just in case someone wants that. */ 1378 { 1379 char *p = dir + strlen (dir) - 1; 1380 while (p > dir && (p[0] == '/' || p[0] == '\\')) 1381 --p; 1382 p[1] = '\0'; 1393 /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/' 1394 But allow -C/ just in case someone wants that. */ 1395 { 1396 char *p = dir + strlen (dir) - 1; 1397 while (p > dir && (p[0] == '/' || p[0] == '\\')) 1398 --p; 1399 p[1] = '\0'; 1400 } 1401 #endif 1402 if (chdir (dir) < 0) 1403 pfatal_with_name (dir); 1383 1404 } 1384 #endif 1385 if (chdir (dir) < 0) 1386 pfatal_with_name (dir); 1387 if (expanded) 1388 free (expanded); 1389 } 1405 } 1390 1406 1391 1407 #ifdef WINDOWS32 … … 1425 1441 /* Construct the list of include directories to search. */ 1426 1442 1427 construct_include_path (include_directories == 0 ? (char **) 01428 1443 construct_include_path (include_directories == 0 1444 ? 0 : include_directories->list); 1429 1445 1430 1446 /* Figure out where we are now, after chdir'ing. */ … … 1457 1473 if (makefiles != 0) 1458 1474 { 1459 registerunsigned int i;1475 unsigned int i; 1460 1476 for (i = 0; i < makefiles->idx; ++i) 1461 1477 if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0') … … 1490 1506 tmpdir = DEFAULT_TMPDIR; 1491 1507 1492 template = (char *) alloca (strlen (tmpdir) 1493 + sizeof (DEFAULT_TMPFILE) + 1); 1508 template = alloca (strlen (tmpdir) + sizeof (DEFAULT_TMPFILE) + 1); 1494 1509 strcpy (template, tmpdir); 1495 1510 … … 1515 1530 pfatal_with_name (_("fwrite (temporary file)")); 1516 1531 } 1517 (void)fclose (outfile);1532 fclose (outfile); 1518 1533 1519 1534 /* Replace the name that read_all_makefiles will 1520 1535 see with the name of the temporary file. */ 1521 makefiles->list[i] = xstrdup(stdin_nm);1536 makefiles->list[i] = strcache_add (stdin_nm); 1522 1537 1523 1538 /* Make sure the temporary file will not be remade. */ 1524 f = enter_file (stdin_nm); 1525 f->updated = 1; 1526 f->update_status = 0; 1527 f->command_state = cs_finished; 1528 /* Can't be intermediate, or it'll be removed too early for 1529 make re-exec. */ 1530 f->intermediate = 0; 1531 f->dontcare = 0; 1539 { 1540 struct file *f = enter_file (strcache_add (stdin_nm)); 1541 f->updated = 1; 1542 f->update_status = 0; 1543 f->command_state = cs_finished; 1544 /* Can't be intermediate, or it'll be removed too early for 1545 make re-exec. */ 1546 f->intermediate = 0; 1547 f->dontcare = 0; 1548 } 1532 1549 } 1533 1550 } … … 1548 1565 If none of these are true, we don't need a signal handler at all. */ 1549 1566 { 1550 extern RETSIGTYPE child_handler PARAMS ((int sig));1567 RETSIGTYPE child_handler (int sig); 1551 1568 # if defined SIGCHLD 1552 1569 bsd_signal (SIGCHLD, child_handler); … … 1588 1605 define_default_variables (); 1589 1606 1590 default_file = enter_file ( ".DEFAULT");1607 default_file = enter_file (strcache_add (".DEFAULT")); 1591 1608 1592 1609 { … … 1598 1615 1599 1616 read_makefiles 1600 = read_all_makefiles (makefiles == 0 ? (char **)0 : makefiles->list);1617 = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list); 1601 1618 1602 1619 #ifdef WINDOWS32 … … 1653 1670 if (jobserver_fds) 1654 1671 { 1655 c har *cp;1672 const char *cp; 1656 1673 unsigned int ui; 1657 1674 … … 1667 1684 fatal (NILF, 1668 1685 _("internal error: invalid --jobserver-fds string `%s'"), cp); 1686 1687 DB (DB_JOBS, 1688 (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1])); 1669 1689 1670 1690 /* The combination of a pipe + !job_slots means we're using the … … 1709 1729 if (job_slots > 1) 1710 1730 { 1731 char *cp; 1711 1732 char c = '+'; 1712 1733 … … 1732 1753 /* Fill in the jobserver_fds struct for our children. */ 1733 1754 1755 cp = xmalloc ((sizeof ("1024")*2)+1); 1756 sprintf (cp, "%d,%d", job_fds[0], job_fds[1]); 1757 1734 1758 jobserver_fds = (struct stringlist *) 1735 1759 xmalloc (sizeof (struct stringlist)); 1736 jobserver_fds->list = (char **) xmalloc (sizeof (char *)); 1737 jobserver_fds->list[0] = xmalloc ((sizeof ("1024")*2)+1); 1738 1739 sprintf (jobserver_fds->list[0], "%d,%d", job_fds[0], job_fds[1]); 1760 jobserver_fds->list = xmalloc (sizeof (char *)); 1761 jobserver_fds->list[0] = cp; 1740 1762 jobserver_fds->idx = 1; 1741 1763 jobserver_fds->max = 1; … … 1787 1809 1788 1810 if (old_files != 0) 1789 for (p = old_files->list; *p != 0; ++p) 1790 { 1791 f = enter_command_line_file (*p); 1792 f->last_mtime = f->mtime_before_update = OLD_MTIME; 1793 f->updated = 1; 1794 f->update_status = 0; 1795 f->command_state = cs_finished; 1796 } 1811 { 1812 const char **p; 1813 for (p = old_files->list; *p != 0; ++p) 1814 { 1815 struct file *f = enter_file (*p); 1816 f->last_mtime = f->mtime_before_update = OLD_MTIME; 1817 f->updated = 1; 1818 f->update_status = 0; 1819 f->command_state = cs_finished; 1820 } 1821 } 1797 1822 1798 1823 if (!restarts && new_files != 0) 1799 1824 { 1825 const char **p; 1800 1826 for (p = new_files->list; *p != 0; ++p) 1801 1827 { 1802 f = enter_command_line_file (*p);1828 struct file *f = enter_file (*p); 1803 1829 f->last_mtime = f->mtime_before_update = NEW_MTIME; 1804 1830 } … … 1832 1858 while (d != 0) 1833 1859 { 1834 registerstruct file *f = d->file;1860 struct file *f = d->file; 1835 1861 if (f->double_colon) 1836 1862 for (f = f->double_colon; f != NULL; f = f->prev) … … 1865 1891 if (f == NULL || !f->double_colon) 1866 1892 { 1867 makefile_mtimes = (FILE_TIMESTAMP *)1868 xrealloc ((char *) makefile_mtimes,1869 (mm_idx + 1)* sizeof (FILE_TIMESTAMP));1893 makefile_mtimes = xrealloc (makefile_mtimes, 1894 (mm_idx+1) 1895 * sizeof (FILE_TIMESTAMP)); 1870 1896 makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file); 1871 1897 last = d; … … 1986 2012 char *p = &argv[i][2]; 1987 2013 if (*p == '\0') 1988 argv[++i] = makefiles->list[j]; 2014 /* This cast is OK since we never modify argv. */ 2015 argv[++i] = (char *) makefiles->list[j]; 1989 2016 else 1990 argv[i] = concat ("-f", makefiles->list[j], "");2017 argv[i] = xstrdup (concat ("-f", makefiles->list[j], "")); 1991 2018 ++j; 1992 2019 } … … 1996 2023 if (stdin_nm) 1997 2024 { 1998 nargv = (char **)xmalloc ((nargc + 2) * sizeof (char *));1999 bcopy ((char *) argv, (char *) nargv, argc * sizeof (char *));2000 nargv[nargc++] = concat ("-o", stdin_nm, "");2025 nargv = xmalloc ((nargc + 2) * sizeof (char *)); 2026 memcpy (nargv, argv, argc * sizeof (char *)); 2027 nargv[nargc++] = xstrdup (concat ("-o", stdin_nm, "")); 2001 2028 nargv[nargc] = 0; 2002 2029 } … … 2004 2031 if (directories != 0 && directories->idx > 0) 2005 2032 { 2006 char bad;2033 int bad = 1; 2007 2034 if (directory_before_chdir != 0) 2008 2035 { 2009 2036 if (chdir (directory_before_chdir) < 0) 2010 {2011 2037 perror_with_name ("chdir", ""); 2012 bad = 1;2013 }2014 2038 else 2015 2039 bad = 0; 2016 2040 } 2017 else2018 bad = 1;2019 2041 if (bad) 2020 2042 fatal (NILF, _("Couldn't change back to original directory.")); … … 2033 2055 2034 2056 #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 { 2058 char **p; 2059 for (p = environ; *p != 0; ++p) 2060 { 2061 if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH) 2062 && (*p)[MAKELEVEL_LENGTH] == '=') 2063 { 2064 *p = alloca (40); 2065 sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel); 2066 } 2067 if (strneq (*p, "MAKE_RESTARTS=", 14)) 2068 { 2069 *p = alloca (40); 2070 sprintf (*p, "MAKE_RESTARTS=%u", restarts); 2071 restarts = 0; 2072 } 2073 } 2074 } 2057 2075 #else /* AMIGA */ 2058 2076 { … … 2120 2138 /* Free the makefile mtimes (if we allocated any). */ 2121 2139 if (makefile_mtimes) 2122 free ( (char *)makefile_mtimes);2140 free (makefile_mtimes); 2123 2141 } 2124 2142 … … 2132 2150 if (restarts && new_files != 0) 2133 2151 { 2152 const char **p; 2134 2153 for (p = new_files->list; *p != 0; ++p) 2135 2154 { 2136 f = enter_command_line_file (*p);2155 struct file *f = enter_file (*p); 2137 2156 f->last_mtime = f->mtime_before_update = NEW_MTIME; 2138 2157 } … … 2173 2192 fatal (NILF, _(".DEFAULT_GOAL contains more than one target")); 2174 2193 2175 default_goal_file = enter_file ( ns->name);2194 default_goal_file = enter_file (strcache_add (ns->name)); 2176 2195 2177 2196 ns->name = 0; /* It was reused by enter_file(). */ … … 2277 2296 2278 2297 case string: 2298 case filename: 2279 2299 case positive_int: 2280 2300 case floating: … … 2321 2341 2322 2342 if (! cv) { 2323 cv = (struct command_variable *)xmalloc (sizeof (*cv));2343 cv = xmalloc (sizeof (*cv)); 2324 2344 cv->variable = v; 2325 2345 cv->next = command_variables; … … 2332 2352 target! Enter it as a file and add it to the dep chain of 2333 2353 goals. */ 2334 struct file *f = enter_ command_line_file (arg);2354 struct file *f = enter_file (strcache_add (expand_command_line_file (arg))); 2335 2355 f->cmd_target = 1; 2336 2356 … … 2350 2370 { 2351 2371 /* Add this target name to the MAKECMDGOALS variable. */ 2352 struct variable * v;2353 c har *value;2354 2355 v = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));2356 if ( v == 0)2372 struct variable *gv; 2373 const char *value; 2374 2375 gv = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS")); 2376 if (gv == 0) 2357 2377 value = f->name; 2358 2378 else … … 2360 2380 /* Paste the old and new values together */ 2361 2381 unsigned int oldlen, newlen; 2362 2363 oldlen = strlen (v->value); 2382 char *vp; 2383 2384 oldlen = strlen (gv->value); 2364 2385 newlen = strlen (f->name); 2365 value = (char *) alloca (oldlen + 1 + newlen + 1); 2366 bcopy (v->value, value, oldlen); 2367 value[oldlen] = ' '; 2368 bcopy (f->name, &value[oldlen + 1], newlen + 1); 2386 vp = alloca (oldlen + 1 + newlen + 1); 2387 memcpy (vp, gv->value, oldlen); 2388 vp[oldlen] = ' '; 2389 memcpy (&vp[oldlen + 1], f->name, newlen + 1); 2390 value = vp; 2369 2391 } 2370 2392 define_variable ("MAKECMDGOALS", 12, value, o_default, 0); … … 2462 2484 2463 2485 case string: 2486 case filename: 2464 2487 if (!doit) 2465 2488 break; 2466 2489 2467 2490 if (optarg == 0) 2468 optarg = cs->noarg_value;2491 optarg = xstrdup (cs->noarg_value); 2469 2492 else if (*optarg == '\0') 2470 2493 { … … 2481 2504 sl->max = 5; 2482 2505 sl->idx = 0; 2483 sl->list = (char **)xmalloc (5 * sizeof (char *));2506 sl->list = xmalloc (5 * sizeof (char *)); 2484 2507 *(struct stringlist **) cs->value_ptr = sl; 2485 2508 } … … 2487 2510 { 2488 2511 sl->max += 5; 2489 sl->list = (char **) 2490 xrealloc ((char *) sl->list, 2491 sl->max * sizeof (char *)); 2512 sl->list = xrealloc (sl->list, 2513 sl->max * sizeof (char *)); 2492 2514 } 2493 sl->list[sl->idx++] = optarg; 2515 if (cs->type == filename) 2516 sl->list[sl->idx++] = expand_command_line_file (optarg); 2517 else 2518 sl->list[sl->idx++] = optarg; 2494 2519 sl->list[sl->idx] = 0; 2495 2520 break; … … 2576 2601 decode_env_switches (char *envar, unsigned int len) 2577 2602 { 2578 char *varref = (char *)alloca (2 + len + 2);2603 char *varref = alloca (2 + len + 2); 2579 2604 char *value, *p; 2580 2605 int argc; … … 2584 2609 varref[0] = '$'; 2585 2610 varref[1] = '('; 2586 bcopy (envar, &varref[2], len);2611 memcpy (&varref[2], envar, len); 2587 2612 varref[2 + len] = ')'; 2588 2613 varref[2 + len + 1] = '\0'; … … 2596 2621 2597 2622 /* Allocate a vector that is definitely big enough. */ 2598 argv = (char **)alloca ((1 + len + 1) * sizeof (char *));2623 argv = alloca ((1 + len + 1) * sizeof (char *)); 2599 2624 2600 2625 /* Allocate a buffer to copy the value into while we split it into words 2601 2626 and unquote it. We must use permanent storage for this because 2602 2627 decode_switches may store pointers into the passed argument words. */ 2603 p = (char *)xmalloc (2 * len);2628 p = xmalloc (2 * len); 2604 2629 2605 2630 /* getopt will look at the arguments starting at ARGV[1]. … … 2632 2657 need permanent storage for this in case decode_switches saves 2633 2658 pointers into the value. */ 2634 argv[1] = concat ("-", argv[1], "");2659 argv[1] = xstrdup (concat ("-", argv[1], "")); 2635 2660 2636 2661 /* Parse those words. */ … … 2646 2671 2647 2672 static char * 2648 quote_for_env (char *out, c har *in)2673 quote_for_env (char *out, const char *in) 2649 2674 { 2650 2675 while (*in != '\0') … … 2684 2709 struct flag *next; 2685 2710 const struct command_switch *cs; 2686 c har *arg;2711 const char *arg; 2687 2712 }; 2688 2713 struct flag *flags = 0; … … 2690 2715 #define ADD_FLAG(ARG, LEN) \ 2691 2716 do { \ 2692 struct flag *new = (struct flag *) alloca (sizeof (struct flag));\2717 struct flag *new = alloca (sizeof (struct flag)); \ 2693 2718 new->cs = cs; \ 2694 2719 new->arg = (ARG); \ … … 2708 2733 switch (cs->type) 2709 2734 { 2710 default:2711 abort ();2712 2713 2735 case ignore: 2714 2736 break; … … 2738 2760 else 2739 2761 { 2740 char *buf = (char *)alloca (30);2762 char *buf = alloca (30); 2741 2763 sprintf (buf, "%u", *(unsigned int *) cs->value_ptr); 2742 2764 ADD_FLAG (buf, strlen (buf)); … … 2759 2781 else 2760 2782 { 2761 char *buf = (char *)alloca (100);2783 char *buf = alloca (100); 2762 2784 sprintf (buf, "%g", *(double *) cs->value_ptr); 2763 2785 ADD_FLAG (buf, strlen (buf)); … … 2767 2789 #endif 2768 2790 2791 case filename: 2769 2792 case string: 2770 2793 if (all) … … 2773 2796 if (sl != 0) 2774 2797 { 2775 /* Add the elements in reverse order, because 2776 all the flags get reversed below; and the order2777 matters for someswitches (like -I). */2778 registerunsigned int i = sl->idx;2798 /* Add the elements in reverse order, because all the flags 2799 get reversed below; and the order matters for some 2800 switches (like -I). */ 2801 unsigned int i = sl->idx; 2779 2802 while (i-- > 0) 2780 2803 ADD_FLAG (sl->list[i], strlen (sl->list[i])); … … 2782 2805 } 2783 2806 break; 2807 2808 default: 2809 abort (); 2784 2810 } 2785 2811 … … 2790 2816 /* Construct the value in FLAGSTRING. 2791 2817 We allocate enough space for a preceding dash and trailing null. */ 2792 flagstring = (char *)alloca (1 + flagslen + 1);2793 bzero (flagstring, 1 + flagslen + 1);2818 flagstring = alloca (1 + flagslen + 1); 2819 memset (flagstring, '\0', 1 + flagslen + 1); 2794 2820 p = flagstring; 2795 2821 words = 1; … … 2883 2909 if (posix_pedantic) 2884 2910 { 2885 bcopy (posixref, p, sizeof posixref - 1);2911 memcpy (p, posixref, sizeof posixref - 1); 2886 2912 p += sizeof posixref - 1; 2887 2913 } 2888 2914 else 2889 2915 { 2890 bcopy (ref, p, sizeof ref - 1);2916 memcpy (p, ref, sizeof ref - 1); 2891 2917 p += sizeof ref - 1; 2892 2918 } … … 3066 3092 if (print_data_base_flag) 3067 3093 print_data_base (); 3094 3095 verify_file_data_base (); 3068 3096 3069 3097 clean_jobserver (status);
Note:
See TracChangeset
for help on using the changeset viewer.