Changeset 3138 for vendor/gnumake/current/main.c
- Timestamp:
- Mar 12, 2018, 8:32:29 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/main.c
r2596 r3138 1 1 /* Argument parsing and main program of GNU Make. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4 2010 Free Software Foundation, Inc. 2 Copyright (C) 1988-2016 Free Software Foundation, Inc. 5 3 This file is part of GNU Make. 6 4 … … 17 15 this program. If not, see <http://www.gnu.org/licenses/>. */ 18 16 19 #include "make.h" 17 #include "makeint.h" 18 #include "os.h" 19 #include "filedef.h" 20 20 #include "dep.h" 21 #include "filedef.h"22 21 #include "variable.h" 23 22 #include "job.h" … … 33 32 #endif 34 33 #ifdef WINDOWS32 35 #include <windows.h> 36 #include <io.h> 37 #include "pathstuff.h" 34 # include <windows.h> 35 # include <io.h> 36 # include "pathstuff.h" 37 # include "sub_proc.h" 38 # include "w32err.h" 38 39 #endif 39 40 #ifdef __EMX__ … … 48 49 int __stack = 20000; /* Make sure we have 20K of stack space */ 49 50 #endif 50 51 void init_dir (void); 52 void remote_setup (void); 53 void remote_cleanup (void); 54 RETSIGTYPE fatal_error_signal (int sig); 55 56 void print_variable_data_base (void); 57 void print_dir_data_base (void); 58 void print_rule_data_base (void); 59 void print_vpath_data_base (void); 60 61 void verify_file_data_base (void); 51 #ifdef VMS 52 int vms_use_mcr_command = 0; 53 int vms_always_use_cmd_file = 0; 54 int vms_gnv_shell = 0; 55 int vms_legacy_behavior = 0; 56 int vms_comma_separator = 0; 57 int vms_unix_simulation = 0; 58 int vms_report_unix_paths = 0; 59 60 /* Evaluates if a VMS environment option is set, only look at first character */ 61 static int 62 get_vms_env_flag (const char *name, int default_value) 63 { 64 char * value; 65 char x; 66 67 value = getenv (name); 68 if (value == NULL) 69 return default_value; 70 71 x = toupper (value[0]); 72 switch (x) 73 { 74 case '1': 75 case 'T': 76 case 'E': 77 return 1; 78 break; 79 case '0': 80 case 'F': 81 case 'D': 82 return 0; 83 } 84 } 85 #endif 62 86 63 87 #if defined HAVE_WAITPID || defined HAVE_WAIT3 … … 65 89 #endif 66 90 67 #ifndef 91 #ifndef HAVE_UNISTD_H 68 92 int chdir (); 69 93 #endif 70 #ifndef 71 # ifndef sun 94 #ifndef STDC_HEADERS 95 # ifndef sun /* Sun has an incorrect decl in a header. */ 72 96 void exit (int) __attribute__ ((noreturn)); 73 97 # endif … … 78 102 static void print_data_base (void); 79 103 static void print_version (void); 80 static void decode_switches (int argc, c har **argv, int env);81 static void decode_env_switches (c har *envar, unsigned int len);82 static const char*define_makeflags (int all, int makefile);104 static void decode_switches (int argc, const char **argv, int env); 105 static void decode_env_switches (const char *envar, unsigned int len); 106 static struct variable *define_makeflags (int all, int makefile); 83 107 static char *quote_for_env (char *out, const char *in); 84 108 static void initialize_global_hash_tables (void); … … 90 114 struct command_switch 91 115 { 92 int c; 93 94 enum 116 int c; /* The switch character. */ 117 118 enum /* Type of the value. */ 95 119 { 96 flag, /* Turn int flag on. */ 97 flag_off, /* Turn int flag off. */ 98 string, /* One string per switch. */ 99 filename, /* A string containing a file name. */ 100 positive_int, /* A positive integer. */ 101 floating, /* A floating-point number (double). */ 102 ignore /* Ignored. */ 120 flag, /* Turn int flag on. */ 121 flag_off, /* Turn int flag off. */ 122 string, /* One string per invocation. */ 123 strlist, /* One string per switch. */ 124 filename, /* A string containing a file name. */ 125 positive_int, /* A positive integer. */ 126 floating, /* A floating-point number (double). */ 127 ignore /* Ignored. */ 103 128 } type; 104 129 105 void *value_ptr; 106 107 unsigned int env:1; 108 unsigned int toenv:1; 109 unsigned int no_makefile:1; 110 111 const void *noarg_value; 112 const void *default_value; 113 114 c har *long_name;/* Long option name. */130 void *value_ptr; /* Pointer to the value-holding variable. */ 131 132 unsigned int env:1; /* Can come from MAKEFLAGS. */ 133 unsigned int toenv:1; /* Should be put in MAKEFLAGS. */ 134 unsigned int no_makefile:1; /* Don't propagate when remaking makefiles. */ 135 136 const void *noarg_value; /* Pointer to value used if no arg given. */ 137 const void *default_value; /* Pointer to default value. */ 138 139 const char *long_name; /* Long option name. */ 115 140 }; 116 141 … … 120 145 121 146 /* The structure used to hold the list of strings given 122 in command switches of a type that takes str ingarguments. */147 in command switches of a type that takes strlist arguments. */ 123 148 124 149 struct stringlist 125 150 { 126 const char **list; 127 unsigned int idx; 128 unsigned int max; 151 const char **list; /* Nil-terminated list of strings. */ 152 unsigned int idx; /* Index into above. */ 153 unsigned int max; /* Number of pointers allocated. */ 129 154 }; 130 155 131 156 132 157 /* The recognized command switches. */ 158 159 /* Nonzero means do extra verification (that may slow things down). */ 160 161 int verify_flag; 133 162 134 163 /* Nonzero means do not print commands to be executed (-s). */ … … 148 177 /* Print debugging info (--debug). */ 149 178 150 static struct stringlist *db_flags ;179 static struct stringlist *db_flags = 0; 151 180 static int debug_flag = 0; 152 181 153 182 int db_level = 0; 154 183 155 /* Output level (--verbosity). */156 157 static struct stringlist *verbosity_flags;184 /* Synchronize output (--output-sync). */ 185 186 char *output_sync_option = 0; 158 187 159 188 #ifdef WINDOWS32 … … 220 249 221 250 222 /* Number of job slots (commands that can be run at once). */ 223 224 unsigned int job_slots = 1; 225 unsigned int default_job_slots = 1; 251 /* Number of job slots for parallelism. */ 252 253 unsigned int job_slots; 254 255 #define INVALID_JOB_SLOTS (-1) 226 256 static unsigned int master_job_slots = 0; 257 static int arg_job_slots = INVALID_JOB_SLOTS; 258 259 static const int default_job_slots = INVALID_JOB_SLOTS; 227 260 228 261 /* Value of job_slots that means no limit. */ 229 262 230 static unsigned int inf_jobs = 0; 231 232 /* File descriptors for the jobs pipe. */ 233 234 static struct stringlist *jobserver_fds = 0; 235 236 int job_fds[2] = { -1, -1 }; 237 int job_rfd = -1; 263 static const int inf_jobs = 0; 264 265 /* Authorization for the jobserver. */ 266 267 static char *jobserver_auth = NULL; 268 269 /* Handle for the mutex used on Windows to synchronize output of our 270 children under -O. */ 271 272 char *sync_mutex = NULL; 238 273 239 274 /* Maximum load average at which multiple jobs will be run. … … 346 381 Consider FILE to be very old and don't remake it.\n"), 347 382 N_("\ 383 -O[TYPE], --output-sync[=TYPE]\n\ 384 Synchronize output of parallel jobs by TYPE.\n"), 385 N_("\ 348 386 -p, --print-data-base Print make's internal database.\n"), 349 387 N_("\ … … 361 399 -t, --touch Touch targets instead of remaking them.\n"), 362 400 N_("\ 401 --trace Print tracing information.\n"), 402 N_("\ 363 403 -v, --version Print the version number of make and exit.\n"), 364 404 N_("\ … … 374 414 }; 375 415 376 /* The table of command switches. */ 416 /* The table of command switches. 417 Order matters here: this is the order MAKEFLAGS will be constructed. 418 So be sure all simple flags (single char, no argument) come first. */ 377 419 378 420 static const struct command_switch switches[] = … … 380 422 { 'b', ignore, 0, 0, 0, 0, 0, 0, 0 }, 381 423 { 'B', flag, &always_make_set, 1, 1, 0, 0, 0, "always-make" }, 382 { 'C', filename, &directories, 0, 0, 0, 0, 0, "directory" },383 424 { 'd', flag, &debug_flag, 1, 1, 0, 0, 0, 0 }, 384 { CHAR_MAX+1, string, &db_flags, 1, 1, 0, "basic", 0, "debug" },385 425 #ifdef WINDOWS32 386 426 { 'D', flag, &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" }, 387 427 #endif 388 428 { 'e', flag, &env_overrides, 1, 1, 0, 0, 0, "environment-overrides", }, 389 { 'f', filename, &makefiles, 0, 0, 0, 0, 0, "file" },390 429 { 'h', flag, &print_usage_flag, 0, 0, 0, 0, 0, "help" }, 391 430 { 'i', flag, &ignore_errors_flag, 1, 1, 0, 0, 0, "ignore-errors" }, 392 { 'I', filename, &include_directories, 1, 1, 0, 0, 0,393 "include-dir" },394 { 'j', positive_int, &job_slots, 1, 1, 0, &inf_jobs, &default_job_slots,395 "jobs" },396 { CHAR_MAX+2, string, &jobserver_fds, 1, 1, 0, 0, 0, "jobserver-fds" },397 431 { 'k', flag, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag, 398 432 "keep-going" }, 399 #ifndef NO_FLOAT400 { 'l', floating, &max_load_average, 1, 1, 0, &default_load_average,401 &default_load_average, "load-average" },402 #else403 { 'l', positive_int, &max_load_average, 1, 1, 0, &default_load_average,404 &default_load_average, "load-average" },405 #endif406 433 { 'L', flag, &check_symlink_flag, 1, 1, 0, 0, 0, "check-symlink-times" }, 407 434 { 'm', ignore, 0, 0, 0, 0, 0, 0, 0 }, 408 435 { 'n', flag, &just_print_flag, 1, 1, 1, 0, 0, "just-print" }, 409 { 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" },410 436 { 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, "print-data-base" }, 411 437 { 'q', flag, &question_flag, 1, 1, 1, 0, 0, "question" }, … … 418 444 { 't', flag, &touch_flag, 1, 1, 1, 0, 0, "touch" }, 419 445 { 'v', flag, &print_version_flag, 1, 1, 0, 0, 0, "version" }, 420 { CHAR_MAX+3, string, &verbosity_flags, 1, 1, 0, 0, 0,421 "verbosity" },422 446 { 'w', flag, &print_directory_flag, 1, 1, 0, 0, 0, "print-directory" }, 447 448 /* These options take arguments. */ 449 { 'C', filename, &directories, 0, 0, 0, 0, 0, "directory" }, 450 { 'f', filename, &makefiles, 0, 0, 0, 0, 0, "file" }, 451 { 'I', filename, &include_directories, 1, 1, 0, 0, 0, 452 "include-dir" }, 453 { 'j', positive_int, &arg_job_slots, 1, 1, 0, &inf_jobs, &default_job_slots, 454 "jobs" }, 455 #ifndef NO_FLOAT 456 { 'l', floating, &max_load_average, 1, 1, 0, &default_load_average, 457 &default_load_average, "load-average" }, 458 #else 459 { 'l', positive_int, &max_load_average, 1, 1, 0, &default_load_average, 460 &default_load_average, "load-average" }, 461 #endif 462 { 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" }, 463 { 'O', string, &output_sync_option, 1, 1, 0, "target", 0, "output-sync" }, 464 { 'W', filename, &new_files, 0, 0, 0, 0, 0, "what-if" }, 465 466 /* These are long-style options. */ 467 { CHAR_MAX+1, strlist, &db_flags, 1, 1, 0, "basic", 0, "debug" }, 468 { CHAR_MAX+2, string, &jobserver_auth, 1, 1, 0, 0, 0, "jobserver-auth" }, 469 { CHAR_MAX+3, flag, &trace_flag, 1, 1, 0, 0, 0, "trace" }, 423 470 { CHAR_MAX+4, flag, &inhibit_print_directory_flag, 1, 1, 0, 0, 0, 424 471 "no-print-directory" }, 425 { 'W', filename, &new_files, 0, 0, 0, 0, 0, "what-if" },426 472 { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0, 427 473 "warn-undefined-variables" }, 428 { CHAR_MAX+6, string, &eval_strings, 1, 0, 0, 0, 0, "eval" }, 474 { CHAR_MAX+6, strlist, &eval_strings, 1, 0, 0, 0, 0, "eval" }, 475 { CHAR_MAX+7, string, &sync_mutex, 1, 1, 0, 0, 0, "sync-mutex" }, 429 476 { 0, 0, 0, 0, 0, 0, 0, 0, 0 } 430 477 }; … … 434 481 static struct option long_option_aliases[] = 435 482 { 436 { "quiet", no_argument,0, 's' },437 { "stop", no_argument,0, 'S' },438 { "new-file", required_argument,0, 'W' },439 { "assume-new", required_argument,0, 'W' },440 { "assume-old", required_argument,0, 'o' },441 { "max-load", optional_argument,0, 'l' },442 { "dry-run", no_argument,0, 'n' },443 { "recon", no_argument,0, 'n' },444 { "makefile", required_argument,0, 'f' },483 { "quiet", no_argument, 0, 's' }, 484 { "stop", no_argument, 0, 'S' }, 485 { "new-file", required_argument, 0, 'W' }, 486 { "assume-new", required_argument, 0, 'W' }, 487 { "assume-old", required_argument, 0, 'o' }, 488 { "max-load", optional_argument, 0, 'l' }, 489 { "dry-run", no_argument, 0, 'n' }, 490 { "recon", no_argument, 0, 'n' }, 491 { "makefile", required_argument, 0, 'f' }, 445 492 }; 446 493 447 494 /* List of goal targets. */ 448 495 449 static struct dep *goals, *lastgoal;496 static struct goaldep *goals, *lastgoal; 450 497 451 498 /* List of variables which were defined on the command line … … 462 509 /* The name we were invoked with. */ 463 510 511 #ifdef WINDOWS32 512 /* On MS-Windows, we chop off the .exe suffix in 'main', so this 513 cannot be 'const'. */ 464 514 char *program; 515 #else 516 const char *program; 517 #endif 465 518 466 519 /* Our current directory before processing any -C options. */ … … 490 543 struct file *default_file; 491 544 492 /* Nonzero if we have seen the magic `.POSIX' target.545 /* Nonzero if we have seen the magic '.POSIX' target. 493 546 This turns on pedantic compliance with POSIX.2. */ 494 547 … … 506 559 int one_shell; 507 560 508 /* Nonzero if we have seen the `.NOTPARALLEL' target. 561 /* One of OUTPUT_SYNC_* if the "--output-sync" option was given. This 562 attempts to synchronize the output of parallel jobs such that the results 563 of each job stay together. */ 564 565 int output_sync = OUTPUT_SYNC_NONE; 566 567 /* Nonzero if the "--trace" option was given. */ 568 569 int trace_flag = 0; 570 571 /* Nonzero if we have seen the '.NOTPARALLEL' target. 509 572 This turns off parallel builds for this invocation of make. */ 510 573 … … 517 580 int clock_skew_detected; 518 581 582 /* Map of possible stop characters for searching strings. */ 583 #ifndef UCHAR_MAX 584 # define UCHAR_MAX 255 585 #endif 586 unsigned short stopchar_map[UCHAR_MAX + 1] = {0}; 587 588 /* If output-sync is enabled we'll collect all the output generated due to 589 options, while reading makefiles, etc. */ 590 591 struct output make_sync; 592 593 519 594 520 595 /* Mask of signals that are being caught with fatal_error_signal. */ 521 596 522 #ifdef 597 #ifdef POSIX 523 598 sigset_t fatal_signal_set; 524 599 #else 525 # ifdef 600 # ifdef HAVE_SIGSETMASK 526 601 int fatal_signal_mask; 527 602 # endif … … 559 634 } 560 635 636 /* This character map locate stop chars when parsing GNU makefiles. 637 Each element is true if we should stop parsing on that character. */ 638 639 static void 640 initialize_stopchar_map (void) 641 { 642 int i; 643 644 stopchar_map[(int)'\0'] = MAP_NUL; 645 stopchar_map[(int)'#'] = MAP_COMMENT; 646 stopchar_map[(int)';'] = MAP_SEMI; 647 stopchar_map[(int)'='] = MAP_EQUALS; 648 stopchar_map[(int)':'] = MAP_COLON; 649 stopchar_map[(int)'%'] = MAP_PERCENT; 650 stopchar_map[(int)'|'] = MAP_PIPE; 651 stopchar_map[(int)'.'] = MAP_DOT | MAP_USERFUNC; 652 stopchar_map[(int)','] = MAP_COMMA; 653 stopchar_map[(int)'$'] = MAP_VARIABLE; 654 655 stopchar_map[(int)'-'] = MAP_USERFUNC; 656 stopchar_map[(int)'_'] = MAP_USERFUNC; 657 658 stopchar_map[(int)' '] = MAP_BLANK; 659 stopchar_map[(int)'\t'] = MAP_BLANK; 660 661 stopchar_map[(int)'/'] = MAP_DIRSEP; 662 #if defined(VMS) 663 stopchar_map[(int)':'] |= MAP_DIRSEP; 664 stopchar_map[(int)']'] |= MAP_DIRSEP; 665 stopchar_map[(int)'>'] |= MAP_DIRSEP; 666 #elif defined(HAVE_DOS_PATHS) 667 stopchar_map[(int)'\\'] |= MAP_DIRSEP; 668 #endif 669 670 for (i = 1; i <= UCHAR_MAX; ++i) 671 { 672 if (isspace (i) && NONE_SET (stopchar_map[i], MAP_BLANK)) 673 /* Don't mark blank characters as newline characters. */ 674 stopchar_map[i] |= MAP_NEWLINE; 675 else if (isalnum (i)) 676 stopchar_map[i] |= MAP_USERFUNC; 677 } 678 } 679 561 680 static const char * 562 expand_command_line_file (c har *name)681 expand_command_line_file (const char *name) 563 682 { 564 683 const char *cp; … … 566 685 567 686 if (name[0] == '\0') 568 fatal (NILF, _("empty string invalid as file name"));687 O (fatal, NILF, _("empty string invalid as file name")); 569 688 570 689 if (name[0] == '~') 571 690 { 572 691 expanded = tilde_expand (name); 573 if (expanded != 0)574 692 if (expanded && expanded[0] != '\0') 693 name = expanded; 575 694 } 576 695 … … 578 697 for names read from makefiles. It is here for names passed 579 698 on the command line. */ 580 while (name[0] == '.' && name[1] == '/' && name[2] != '\0')699 while (name[0] == '.' && name[1] == '/') 581 700 { 582 701 name += 2; 583 while (*name == '/') 584 /* Skip following slashes: ".//foo" is "foo", not "/foo". */ 585 ++name; 586 } 587 588 if (*name == '\0') 589 { 590 /* It was all slashes! Move back to the dot and truncate 591 it after the first slash, so it becomes just "./". */ 592 do 593 --name; 594 while (name[0] != '.'); 595 name[2] = '\0'; 702 while (name[0] == '/') 703 /* Skip following slashes: ".//foo" is "foo", not "/foo". */ 704 ++name; 705 } 706 707 if (name[0] == '\0') 708 { 709 /* Nothing else but one or more "./", maybe plus slashes! */ 710 name = "./"; 596 711 } 597 712 598 713 cp = strcache_add (name); 599 714 600 if (expanded) 601 free (expanded); 715 free (expanded); 602 716 603 717 return cp; … … 622 736 db_level = DB_ALL; 623 737 624 if (!db_flags) 625 return; 626 627 for (pp=db_flags->list; *pp; ++pp) 628 { 629 const char *p = *pp; 630 631 while (1) 632 { 633 switch (tolower (p[0])) 634 { 635 case 'a': 636 db_level |= DB_ALL; 738 if (db_flags) 739 for (pp=db_flags->list; *pp; ++pp) 740 { 741 const char *p = *pp; 742 743 while (1) 744 { 745 switch (tolower (p[0])) 746 { 747 case 'a': 748 db_level |= DB_ALL; 749 break; 750 case 'b': 751 db_level |= DB_BASIC; 752 break; 753 case 'i': 754 db_level |= DB_BASIC | DB_IMPLICIT; 755 break; 756 case 'j': 757 db_level |= DB_JOBS; 758 break; 759 case 'm': 760 db_level |= DB_BASIC | DB_MAKEFILES; 761 break; 762 case 'n': 763 db_level = 0; 764 break; 765 case 'v': 766 db_level |= DB_BASIC | DB_VERBOSE; 767 break; 768 default: 769 OS (fatal, NILF, 770 _("unknown debug level specification '%s'"), p); 771 } 772 773 while (*(++p) != '\0') 774 if (*p == ',' || *p == ' ') 775 { 776 ++p; 777 break; 778 } 779 780 if (*p == '\0') 637 781 break; 638 case 'b': 639 db_level |= DB_BASIC; 640 break; 641 case 'i': 642 db_level |= DB_BASIC | DB_IMPLICIT; 643 break; 644 case 'j': 645 db_level |= DB_JOBS; 646 break; 647 case 'm': 648 db_level |= DB_BASIC | DB_MAKEFILES; 649 break; 650 case 'v': 651 db_level |= DB_BASIC | DB_VERBOSE; 652 break; 653 default: 654 fatal (NILF, _("unknown debug level specification `%s'"), p); 655 } 656 657 while (*(++p) != '\0') 658 if (*p == ',' || *p == ' ') 659 break; 660 661 if (*p == '\0') 662 break; 663 664 ++p; 665 } 666 } 782 } 783 } 784 785 if (db_level) 786 verify_flag = 1; 787 788 if (! db_level) 789 debug_flag = 0; 667 790 } 668 791 792 static void 793 decode_output_sync_flags (void) 794 { 795 #ifdef NO_OUTPUT_SYNC 796 output_sync = OUTPUT_SYNC_NONE; 797 #else 798 if (output_sync_option) 799 { 800 if (streq (output_sync_option, "none")) 801 output_sync = OUTPUT_SYNC_NONE; 802 else if (streq (output_sync_option, "line")) 803 output_sync = OUTPUT_SYNC_LINE; 804 else if (streq (output_sync_option, "target")) 805 output_sync = OUTPUT_SYNC_TARGET; 806 else if (streq (output_sync_option, "recurse")) 807 output_sync = OUTPUT_SYNC_RECURSE; 808 else 809 OS (fatal, NILF, 810 _("unknown output-sync type '%s'"), output_sync_option); 811 } 812 813 if (sync_mutex) 814 RECORD_SYNC_MUTEX (sync_mutex); 815 #endif 816 } 817 669 818 #ifdef WINDOWS32 819 820 #ifndef NO_OUTPUT_SYNC 821 822 /* This is called from start_job_command when it detects that 823 output_sync option is in effect. The handle to the synchronization 824 mutex is passed, as a string, to sub-makes via the --sync-mutex 825 command-line argument. */ 826 void 827 prepare_mutex_handle_string (sync_handle_t handle) 828 { 829 if (!sync_mutex) 830 { 831 /* Prepare the mutex handle string for our children. */ 832 /* 2 hex digits per byte + 2 characters for "0x" + null. */ 833 sync_mutex = xmalloc ((2 * sizeof (sync_handle_t)) + 2 + 1); 834 sprintf (sync_mutex, "0x%Ix", handle); 835 define_makeflags (1, 0); 836 } 837 } 838 839 #endif /* NO_OUTPUT_SYNC */ 840 670 841 /* 671 842 * HANDLE runtime exceptions by avoiding a requestor on the GUI. Capture … … 678 849 */ 679 850 LONG WINAPI 680 handle_runtime_exceptions ( struct _EXCEPTION_POINTERS *exinfo)851 handle_runtime_exceptions (struct _EXCEPTION_POINTERS *exinfo) 681 852 { 682 853 PEXCEPTION_RECORD exrec = exinfo->ExceptionRecord; 683 LPSTR cmdline = GetCommandLine ();684 LPSTR prg = strtok (cmdline, " ");854 LPSTR cmdline = GetCommandLine (); 855 LPSTR prg = strtok (cmdline, " "); 685 856 CHAR errmsg[1024]; 686 857 #ifdef USE_EVENT_LOG … … 691 862 if (! ISDB (DB_VERBOSE)) 692 863 { 693 sprintf (errmsg,694 _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%p)\n"),695 prg, exrec->ExceptionCode, exrec->ExceptionAddress);696 fprintf (stderr, errmsg);697 exit (255);698 } 699 700 sprintf (errmsg,701 _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = 0x%p\n"),702 prg, exrec->ExceptionCode, exrec->ExceptionFlags,703 exrec->ExceptionAddress);864 sprintf (errmsg, 865 _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%p)\n"), 866 prg, exrec->ExceptionCode, exrec->ExceptionAddress); 867 fprintf (stderr, errmsg); 868 exit (255); 869 } 870 871 sprintf (errmsg, 872 _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = 0x%p\n"), 873 prg, exrec->ExceptionCode, exrec->ExceptionFlags, 874 exrec->ExceptionAddress); 704 875 705 876 if (exrec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION 706 877 && exrec->NumberParameters >= 2) 707 sprintf (&errmsg[strlen(errmsg)],708 (exrec->ExceptionInformation[0]709 ? _("Access violation: write operation at address 0x%p\n")710 : _("Access violation: read operation at address 0x%p\n")),711 (PVOID)exrec->ExceptionInformation[1]);878 sprintf (&errmsg[strlen(errmsg)], 879 (exrec->ExceptionInformation[0] 880 ? _("Access violation: write operation at address 0x%p\n") 881 : _("Access violation: read operation at address 0x%p\n")), 882 (PVOID)exrec->ExceptionInformation[1]); 712 883 713 884 /* turn this on if we want to put stuff in the event log too */ 714 885 #ifdef USE_EVENT_LOG 715 hEventSource = RegisterEventSource (NULL, "GNU Make");886 hEventSource = RegisterEventSource (NULL, "GNU Make"); 716 887 lpszStrings[0] = errmsg; 717 888 718 889 if (hEventSource != NULL) 719 890 { 720 ReportEvent (hEventSource, /* handle of event source */721 EVENTLOG_ERROR_TYPE, /* event type */722 0, /* event category */723 0, /* event ID */724 NULL, /* current user's SID */725 1, /* strings in lpszStrings */726 0, /* no bytes of raw data */727 lpszStrings, /* array of error strings */728 NULL); /* no raw data */729 730 (VOID) DeregisterEventSource (hEventSource);891 ReportEvent (hEventSource, /* handle of event source */ 892 EVENTLOG_ERROR_TYPE, /* event type */ 893 0, /* event category */ 894 0, /* event ID */ 895 NULL, /* current user's SID */ 896 1, /* strings in lpszStrings */ 897 0, /* no bytes of raw data */ 898 lpszStrings, /* array of error strings */ 899 NULL); /* no raw data */ 900 901 (VOID) DeregisterEventSource (hEventSource); 731 902 } 732 903 #endif 733 904 734 905 /* Write the error to stderr too */ 735 fprintf (stderr, errmsg);906 fprintf (stderr, errmsg); 736 907 737 908 #ifdef DEBUG 738 909 return EXCEPTION_CONTINUE_SEARCH; 739 910 #else 740 exit (255);911 exit (255); 741 912 return (255); /* not reached */ 742 913 #endif … … 746 917 * On WIN32 systems we don't have the luxury of a /bin directory that 747 918 * is mapped globally to every drive mounted to the system. Since make could 748 * be invoked from any drive, and we don't want to prop ogate /bin/sh919 * be invoked from any drive, and we don't want to propagate /bin/sh 749 920 * to every single drive. Allow ourselves a chance to search for 750 921 * a value for default shell here (if the default path does not exist). … … 756 927 int sh_found = 0; 757 928 char *atoken = 0; 758 c har *search_token;759 c har *tokend;929 const char *search_token; 930 const char *tokend; 760 931 PATH_VAR(sh_path); 761 extern c har *default_shell;932 extern const char *default_shell; 762 933 763 934 if (!token) 764 935 search_token = default_shell; 765 936 else 766 atoken = search_token = xstrdup (token);937 search_token = atoken = xstrdup (token); 767 938 768 939 /* If the user explicitly requests the DOS cmd shell, obey that request. … … 778 949 || (tokend - 4 > search_token 779 950 && (tokend[-5] == '/' || tokend[-5] == '\\'))) 780 && !strcasecmp (tokend - 4, "cmd.exe"))) { 781 batch_mode_shell = 1; 782 unixy_shell = 0; 783 sprintf (sh_path, "%s", search_token); 784 default_shell = xstrdup (w32ify (sh_path, 0)); 785 DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"), 786 default_shell)); 787 sh_found = 1; 788 } else if (!no_default_sh_exe && 789 (token == NULL || !strcmp (search_token, default_shell))) { 790 /* no new information, path already set or known */ 791 sh_found = 1; 792 } else if (file_exists_p (search_token)) { 793 /* search token path was found */ 794 sprintf (sh_path, "%s", search_token); 795 default_shell = xstrdup (w32ify (sh_path, 0)); 796 DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"), 797 default_shell)); 798 sh_found = 1; 799 } else { 800 char *p; 801 struct variable *v = lookup_variable (STRING_SIZE_TUPLE ("PATH")); 802 803 /* Search Path for shell */ 804 if (v && v->value) { 805 char *ep; 806 807 p = v->value; 808 ep = strchr (p, PATH_SEPARATOR_CHAR); 809 810 while (ep && *ep) { 811 *ep = '\0'; 812 813 if (dir_file_exists_p (p, search_token)) { 814 sprintf (sh_path, "%s/%s", p, search_token); 815 default_shell = xstrdup (w32ify (sh_path, 0)); 816 sh_found = 1; 817 *ep = PATH_SEPARATOR_CHAR; 818 819 /* terminate loop */ 820 p += strlen (p); 821 } else { 822 *ep = PATH_SEPARATOR_CHAR; 823 p = ++ep; 951 && !strcasecmp (tokend - 4, "cmd.exe"))) 952 { 953 batch_mode_shell = 1; 954 unixy_shell = 0; 955 sprintf (sh_path, "%s", search_token); 956 default_shell = xstrdup (w32ify (sh_path, 0)); 957 DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"), 958 default_shell)); 959 sh_found = 1; 960 } 961 else if (!no_default_sh_exe 962 && (token == NULL || !strcmp (search_token, default_shell))) 963 { 964 /* no new information, path already set or known */ 965 sh_found = 1; 966 } 967 else if (_access (search_token, 0) == 0) 968 { 969 /* search token path was found */ 970 sprintf (sh_path, "%s", search_token); 971 default_shell = xstrdup (w32ify (sh_path, 0)); 972 DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"), 973 default_shell)); 974 sh_found = 1; 975 } 976 else 977 { 978 char *p; 979 struct variable *v = lookup_variable (STRING_SIZE_TUPLE ("PATH")); 980 981 /* Search Path for shell */ 982 if (v && v->value) 983 { 984 char *ep; 985 986 p = v->value; 987 ep = strchr (p, PATH_SEPARATOR_CHAR); 988 989 while (ep && *ep) 990 { 991 *ep = '\0'; 992 993 sprintf (sh_path, "%s/%s", p, search_token); 994 if (_access (sh_path, 0) == 0) 995 { 996 default_shell = xstrdup (w32ify (sh_path, 0)); 997 sh_found = 1; 998 *ep = PATH_SEPARATOR_CHAR; 999 1000 /* terminate loop */ 1001 p += strlen (p); 1002 } 1003 else 1004 { 1005 *ep = PATH_SEPARATOR_CHAR; 1006 p = ++ep; 1007 } 1008 1009 ep = strchr (p, PATH_SEPARATOR_CHAR); 1010 } 1011 1012 /* be sure to check last element of Path */ 1013 if (p && *p) 1014 { 1015 sprintf (sh_path, "%s/%s", p, search_token); 1016 if (_access (sh_path, 0) == 0) 1017 { 1018 default_shell = xstrdup (w32ify (sh_path, 0)); 1019 sh_found = 1; 1020 } 1021 } 1022 1023 if (sh_found) 1024 DB (DB_VERBOSE, 1025 (_("find_and_set_shell() path search set default_shell = %s\n"), 1026 default_shell)); 824 1027 } 825 826 ep = strchr (p, PATH_SEPARATOR_CHAR); 827 } 828 829 /* be sure to check last element of Path */ 830 if (p && *p && dir_file_exists_p (p, search_token)) { 831 sprintf (sh_path, "%s/%s", p, search_token); 832 default_shell = xstrdup (w32ify (sh_path, 0)); 833 sh_found = 1; 834 } 835 836 if (sh_found) 837 DB (DB_VERBOSE, 838 (_("find_and_set_shell() path search set default_shell = %s\n"), 839 default_shell)); 840 } 841 } 1028 } 842 1029 843 1030 /* naive test */ 844 if (!unixy_shell && sh_found && 845 (strstr (default_shell, "sh") || strstr (default_shell, "SH"))) { 846 unixy_shell = 1; 847 batch_mode_shell = 0; 848 } 1031 if (!unixy_shell && sh_found 1032 && (strstr (default_shell, "sh") || strstr (default_shell, "SH"))) 1033 { 1034 unixy_shell = 1; 1035 batch_mode_shell = 0; 1036 } 849 1037 850 1038 #ifdef BATCH_MODE_ONLY_SHELL … … 852 1040 #endif 853 1041 854 if (atoken) 855 free (atoken); 1042 free (atoken); 856 1043 857 1044 return (sh_found); … … 868 1055 #endif /* __MSDOS__ */ 869 1056 870 char *mktemp (char *template); 871 int mkstemp (char *template); 872 873 FILE * 874 open_tmpfile(char **name, const char *template) 1057 static void 1058 reset_jobserver (void) 875 1059 { 876 #ifdef HAVE_FDOPEN 877 int fd; 878 #endif 879 880 #if defined HAVE_MKSTEMP || defined HAVE_MKTEMP 881 # define TEMPLATE_LEN strlen (template) 882 #else 883 # define TEMPLATE_LEN L_tmpnam 884 #endif 885 *name = xmalloc (TEMPLATE_LEN + 1); 886 strcpy (*name, template); 887 888 #if defined HAVE_MKSTEMP && defined HAVE_FDOPEN 889 /* It's safest to use mkstemp(), if we can. */ 890 fd = mkstemp (*name); 891 if (fd == -1) 892 return 0; 893 return fdopen (fd, "w"); 894 #else 895 # ifdef HAVE_MKTEMP 896 (void) mktemp (*name); 897 # else 898 (void) tmpnam (*name); 899 # endif 900 901 # ifdef HAVE_FDOPEN 902 /* Can't use mkstemp(), but guard against a race condition. */ 903 fd = open (*name, O_CREAT|O_EXCL|O_WRONLY, 0600); 904 if (fd == -1) 905 return 0; 906 return fdopen (fd, "w"); 907 # else 908 /* Not secure, but what can we do? */ 909 return fopen (*name, "w"); 910 # endif 911 #endif 1060 jobserver_clear (); 1061 free (jobserver_auth); 1062 jobserver_auth = NULL; 912 1063 } 913 914 1064 915 1065 #ifdef _AMIGA … … 923 1073 static char *stdin_nm = 0; 924 1074 int makefile_status = MAKE_SUCCESS; 925 struct dep *read_makefiles;1075 struct goaldep *read_files; 926 1076 PATH_VAR (current_directory); 927 1077 unsigned int restarts = 0; 1078 unsigned int syncing = 0; 1079 int argv_slots; 928 1080 #ifdef WINDOWS32 929 c har *unix_path = NULL;930 c har *windows32_path = NULL;931 932 SetUnhandledExceptionFilter (handle_runtime_exceptions);1081 const char *unix_path = NULL; 1082 const char *windows32_path = NULL; 1083 1084 SetUnhandledExceptionFilter (handle_runtime_exceptions); 933 1085 934 1086 /* start off assuming we have no shell */ … … 936 1088 no_default_sh_exe = 1; 937 1089 #endif 1090 1091 output_init (&make_sync); 1092 1093 initialize_stopchar_map(); 938 1094 939 1095 #ifdef SET_STACK_SIZE … … 955 1111 #endif 956 1112 957 #ifdef HAVE_ATEXIT958 atexit (close_stdout);959 #endif960 961 1113 /* Needed for OS/2 */ 962 initialize_main(&argc, &argv); 963 964 reading_file = 0; 1114 initialize_main (&argc, &argv); 1115 1116 #ifdef MAKE_MAINTAINER_MODE 1117 /* In maintainer mode we always enable verification. */ 1118 verify_flag = 1; 1119 #endif 965 1120 966 1121 #if defined (__MSDOS__) && !defined (_POSIX_SOURCE) 967 /* Request the most powerful version of `system', to1122 /* Request the most powerful version of 'system', to 968 1123 make up for the dumb default shell. */ 969 1124 __system_flags = (__system_redirect 970 971 972 973 974 1125 | __system_use_shell 1126 | __system_allow_multiple_cmds 1127 | __system_allow_long_cmds 1128 | __system_handle_null_commands 1129 | __system_emulate_chdir); 975 1130 976 1131 #endif … … 983 1138 (void)textdomain (PACKAGE); 984 1139 985 #ifdef 1140 #ifdef POSIX 986 1141 sigemptyset (&fatal_signal_set); 987 #define ADD_SIG(sig)sigaddset (&fatal_signal_set, sig)1142 #define ADD_SIG(sig) sigaddset (&fatal_signal_set, sig) 988 1143 #else 989 #ifdef 1144 #ifdef HAVE_SIGSETMASK 990 1145 fatal_signal_mask = 0; 991 #define ADD_SIG(sig)fatal_signal_mask |= sigmask (sig)1146 #define ADD_SIG(sig) fatal_signal_mask |= sigmask (sig) 992 1147 #else 993 #define ADD_SIG(sig) (void)sig /* Needed to avoid warnings in MSVC. */994 #endif 995 #endif 996 997 #define FATAL_SIG(sig)\998 if (bsd_signal (sig, fatal_error_signal) == SIG_IGN) 999 bsd_signal (sig, SIG_IGN); 1000 else 1148 #define ADD_SIG(sig) (void)sig 1149 #endif 1150 #endif 1151 1152 #define FATAL_SIG(sig) \ 1153 if (bsd_signal (sig, fatal_error_signal) == SIG_IGN) \ 1154 bsd_signal (sig, SIG_IGN); \ 1155 else \ 1001 1156 ADD_SIG (sig); 1002 1157 … … 1017 1172 #endif 1018 1173 1019 #ifdef 1174 #ifdef SIGDANGER 1020 1175 FATAL_SIG (SIGDANGER); 1021 1176 #endif … … 1027 1182 #endif 1028 1183 1029 #undef 1184 #undef FATAL_SIG 1030 1185 1031 1186 /* Do not ignore the child-death signal. This must be done before … … 1043 1198 #endif 1044 1199 1045 /* Make sure stdout is line-buffered. */ 1046 1047 #ifdef HAVE_SETVBUF 1048 # ifdef SETVBUF_REVERSED 1049 setvbuf (stdout, _IOLBF, xmalloc (BUFSIZ), BUFSIZ); 1050 # else /* setvbuf not reversed. */ 1051 /* Some buggy systems lose if we pass 0 instead of allocating ourselves. */ 1052 setvbuf (stdout, 0, _IOLBF, BUFSIZ); 1053 # endif /* setvbuf reversed. */ 1054 #elif HAVE_SETLINEBUF 1055 setlinebuf (stdout); 1056 #endif /* setlinebuf missing. */ 1200 output_init (NULL); 1057 1201 1058 1202 /* Figure out where this program lives. */ 1059 1203 1060 1204 if (argv[0] == 0) 1061 argv[0] = "";1205 argv[0] = (char *)""; 1062 1206 if (argv[0][0] == '\0') 1063 1207 program = "make"; 1064 1208 else 1065 1209 { 1066 #ifdef VMS1067 program = strrchr (argv[0], ']');1068 #else1069 1210 program = strrchr (argv[0], '/'); 1070 #endif1071 1211 #if defined(__MSDOS__) || defined(__EMX__) 1072 1212 if (program == 0) 1073 1213 program = strrchr (argv[0], '\\'); 1074 1214 else 1075 1076 1077 1078 1079 1080 1081 1215 { 1216 /* Some weird environments might pass us argv[0] with 1217 both kinds of slashes; we must find the rightmost. */ 1218 char *p = strrchr (argv[0], '\\'); 1219 if (p && p > program) 1220 program = p; 1221 } 1082 1222 if (program == 0 && argv[0][1] == ':') 1083 1223 program = argv[0] + 1; 1084 1224 #endif 1085 1225 #ifdef WINDOWS32 … … 1087 1227 { 1088 1228 /* Extract program from full path */ 1089 int argv0_len;1090 1229 program = strrchr (argv[0], '\\'); 1091 1230 if (program) 1092 1231 { 1093 argv0_len = strlen(program);1232 int argv0_len = strlen (program); 1094 1233 if (argv0_len > 4 && streq (&program[argv0_len - 4], ".exe")) 1095 1234 /* Remove .exe extension */ … … 1098 1237 } 1099 1238 #endif 1239 #ifdef VMS 1240 set_program_name (argv[0]); 1241 program = program_name; 1242 { 1243 const char *shell; 1244 char pwdbuf[256]; 1245 char *pwd; 1246 shell = getenv ("SHELL"); 1247 if (shell != NULL) 1248 vms_gnv_shell = 1; 1249 1250 /* Need to know if CRTL set to report UNIX paths. Use getcwd as 1251 it works on all versions of VMS. */ 1252 pwd = getcwd(pwdbuf, 256); 1253 if (pwd[0] == '/') 1254 vms_report_unix_paths = 1; 1255 1256 vms_use_mcr_command = get_vms_env_flag ("GNV$MAKE_USE_MCR", 0); 1257 1258 vms_always_use_cmd_file = get_vms_env_flag ("GNV$MAKE_USE_CMD_FILE", 0); 1259 1260 /* Legacy behavior is on VMS is older behavior that needed to be 1261 changed to be compatible with standard make behavior. 1262 For now only completely disable when running under a Bash shell. 1263 TODO: Update VMS built in recipes and macros to not need this 1264 behavior, at which time the default may change. */ 1265 vms_legacy_behavior = get_vms_env_flag ("GNV$MAKE_OLD_VMS", 1266 !vms_gnv_shell); 1267 1268 /* VMS was changed to use a comma separator in the past, but that is 1269 incompatible with built in functions that expect space separated 1270 lists. Allow this to be selectively turned off. */ 1271 vms_comma_separator = get_vms_env_flag ("GNV$MAKE_COMMA", 1272 vms_legacy_behavior); 1273 1274 /* Some Posix shell syntax options are incompatible with VMS syntax. 1275 VMS requires double quotes for strings and escapes quotes 1276 differently. When this option is active, VMS will try 1277 to simulate Posix shell simulations instead of using 1278 VMS DCL behavior. */ 1279 vms_unix_simulation = get_vms_env_flag ("GNV$MAKE_SHELL_SIM", 1280 !vms_legacy_behavior); 1281 1282 } 1283 if (need_vms_symbol () && !vms_use_mcr_command) 1284 create_foreign_command (program_name, argv[0]); 1285 #else 1100 1286 if (program == 0) 1101 1287 program = argv[0]; 1102 1288 else 1103 ++program; 1289 ++program; 1290 #endif 1104 1291 } 1105 1292 … … 1117 1304 #endif 1118 1305 { 1119 #ifdef 1306 #ifdef HAVE_GETCWD 1120 1307 perror_with_name ("getcwd", ""); 1121 1308 #else 1122 error (NILF, "getwd: %s", current_directory);1309 OS (error, NILF, "getwd: %s", current_directory); 1123 1310 #endif 1124 1311 current_directory[0] = '\0'; … … 1127 1314 else 1128 1315 directory_before_chdir = xstrdup (current_directory); 1316 1129 1317 #ifdef __MSDOS__ 1130 1318 /* Make sure we will return to the initial directory, come what may. */ … … 1137 1325 define_variable_cname (".RECIPEPREFIX", "", o_default, 0)->special = 1; 1138 1326 define_variable_cname (".SHELLFLAGS", "-c", o_default, 0); 1327 define_variable_cname (".LOADED", "", o_default, 0); 1139 1328 1140 1329 /* Set up .FEATURES 1141 We must do this in multiple calls because define_variable_cname() is1142 a macro andsome compilers (MSVC) don't like conditionals in macros. */1330 Use a separate variable because define_variable_cname() is a macro and 1331 some compilers (MSVC) don't like conditionals in macros. */ 1143 1332 { 1144 1333 const char *features = "target-specific order-only second-expansion" 1145 " else-if shortest-stem undefine "1334 " else-if shortest-stem undefine oneshell" 1146 1335 #ifndef NO_ARCHIVES 1147 1336 " archives" … … 1150 1339 " jobserver" 1151 1340 #endif 1341 #ifndef NO_OUTPUT_SYNC 1342 " output-sync" 1343 #endif 1152 1344 #ifdef MAKE_SYMLINKS 1153 1345 " check-symlink" 1154 1346 #endif 1347 #ifdef HAVE_GUILE 1348 " guile" 1349 #endif 1350 #ifdef MAKE_LOAD 1351 " load" 1352 #endif 1155 1353 ; 1156 1354 1157 1355 define_variable_cname (".FEATURES", features, o_default, 0); 1158 1356 } 1357 1358 /* Configure GNU Guile support */ 1359 guile_gmake_setup (NILF); 1159 1360 1160 1361 /* Read in variables from the environment. It is important that this be … … 1168 1369 for (i = 0; envp[i] != 0; ++i) 1169 1370 { 1170 int do_not_define = 0; 1171 char *ep = envp[i]; 1172 1173 while (*ep != '\0' && *ep != '=') 1371 struct variable *v; 1372 const char *ep = envp[i]; 1373 /* By default, export all variables culled from the environment. */ 1374 enum variable_export export = v_export; 1375 unsigned int len; 1376 1377 while (! STOP_SET (*ep, MAP_EQUALS)) 1174 1378 ++ep; 1379 1380 /* If there's no equals sign it's a malformed environment. Ignore. */ 1381 if (*ep == '\0') 1382 continue; 1383 1175 1384 #ifdef WINDOWS32 1176 if (!unix_path && strneq (envp[i], "PATH=", 5))1385 if (!unix_path && strneq (envp[i], "PATH=", 5)) 1177 1386 unix_path = ep+1; 1178 else if (!strnicmp(envp[i], "Path=", 5)) { 1179 do_not_define = 1; /* it gets defined after loop exits */ 1180 if (!windows32_path) 1181 windows32_path = ep+1; 1182 } 1183 #endif 1184 /* The result of pointer arithmetic is cast to unsigned int for 1185 machines where ptrdiff_t is a different size that doesn't widen 1186 the same. */ 1187 if (!do_not_define) 1387 else if (!strnicmp (envp[i], "Path=", 5)) 1188 1388 { 1189 struct variable *v; 1190 1191 v = define_variable (envp[i], (unsigned int) (ep - envp[i]), 1192 ep + 1, o_env, 1); 1193 /* Force exportation of every variable culled from the 1194 environment. We used to rely on target_environment's 1195 v_default code to do this. But that does not work for the 1196 case where an environment variable is redefined in a makefile 1197 with `override'; it should then still be exported, because it 1198 was originally in the environment. */ 1199 v->export = v_export; 1200 1201 /* Another wrinkle is that POSIX says the value of SHELL set in 1202 the makefile won't change the value of SHELL given to 1203 subprocesses. */ 1204 if (streq (v->name, "SHELL")) 1389 if (!windows32_path) 1390 windows32_path = ep+1; 1391 /* PATH gets defined after the loop exits. */ 1392 continue; 1393 } 1394 #endif 1395 1396 /* Length of the variable name, and skip the '='. */ 1397 len = ep++ - envp[i]; 1398 1399 /* If this is MAKE_RESTARTS, check to see if the "already printed 1400 the enter statement" flag is set. */ 1401 if (len == 13 && strneq (envp[i], "MAKE_RESTARTS", 13)) 1402 { 1403 if (*ep == '-') 1205 1404 { 1405 OUTPUT_TRACED (); 1406 ++ep; 1407 } 1408 restarts = (unsigned int) atoi (ep); 1409 export = v_noexport; 1410 } 1411 1412 v = define_variable (envp[i], len, ep, o_env, 1); 1413 1414 /* POSIX says the value of SHELL set in the makefile won't change the 1415 value of SHELL given to subprocesses. */ 1416 if (streq (v->name, "SHELL")) 1417 { 1206 1418 #ifndef __MSDOS__ 1207 v->export = v_noexport; 1208 #endif 1209 shell_var.name = "SHELL"; 1210 shell_var.length = 5; 1211 shell_var.value = xstrdup (ep + 1); 1212 } 1213 1214 /* If MAKE_RESTARTS is set, remember it but don't export it. */ 1215 if (streq (v->name, "MAKE_RESTARTS")) 1216 { 1217 v->export = v_noexport; 1218 restarts = (unsigned int) atoi (ep + 1); 1219 } 1419 export = v_noexport; 1420 #endif 1421 shell_var.name = xstrdup ("SHELL"); 1422 shell_var.length = 5; 1423 shell_var.value = xstrdup (ep); 1220 1424 } 1425 1426 v->export = export; 1221 1427 } 1222 1428 } 1223 1429 #ifdef WINDOWS32 1224 1430 /* If we didn't find a correctly spelled PATH we define PATH as 1225 * either the first mis pelled value or an empty string1431 * either the first misspelled value or an empty string 1226 1432 */ 1227 1433 if (!unix_path) … … 1231 1437 #else /* For Amiga, read the ENV: device, ignoring all dirs */ 1232 1438 { 1233 BPTR env, file, old; 1234 char buffer[1024]; 1235 int len; 1236 __aligned struct FileInfoBlock fib; 1237 1238 env = Lock ("ENV:", ACCESS_READ); 1239 if (env) 1240 { 1241 old = CurrentDir (DupLock(env)); 1242 Examine (env, &fib); 1243 1244 while (ExNext (env, &fib)) 1245 { 1246 if (fib.fib_DirEntryType < 0) /* File */ 1247 { 1248 /* Define an empty variable. It will be filled in 1249 variable_lookup(). Makes startup quite a bit 1250 faster. */ 1251 define_variable (fib.fib_FileName, 1252 strlen (fib.fib_FileName), 1253 "", o_env, 1)->export = v_export; 1254 } 1255 } 1256 UnLock (env); 1257 UnLock(CurrentDir(old)); 1258 } 1439 BPTR env, file, old; 1440 char buffer[1024]; 1441 int len; 1442 __aligned struct FileInfoBlock fib; 1443 1444 env = Lock ("ENV:", ACCESS_READ); 1445 if (env) 1446 { 1447 old = CurrentDir (DupLock (env)); 1448 Examine (env, &fib); 1449 1450 while (ExNext (env, &fib)) 1451 { 1452 if (fib.fib_DirEntryType < 0) /* File */ 1453 { 1454 /* Define an empty variable. It will be filled in 1455 variable_lookup(). Makes startup quite a bit faster. */ 1456 define_variable (fib.fib_FileName, 1457 strlen (fib.fib_FileName), 1458 "", o_env, 1)->export = v_export; 1459 } 1460 } 1461 UnLock (env); 1462 UnLock (CurrentDir (old)); 1463 } 1259 1464 } 1260 1465 #endif 1261 1466 1262 1467 /* Decode the switches. */ 1468 decode_env_switches (STRING_SIZE_TUPLE ("GNUMAKEFLAGS")); 1469 1470 /* Clear GNUMAKEFLAGS to avoid duplication. */ 1471 define_variable_cname ("GNUMAKEFLAGS", "", o_env, 0); 1263 1472 1264 1473 decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS")); 1474 1265 1475 #if 0 1266 1476 /* People write things like: … … 1270 1480 #endif 1271 1481 1272 decode_switches (argc, argv, 0); 1482 /* In output sync mode we need to sync any output generated by reading the 1483 makefiles, such as in $(info ...) or stderr from $(shell ...) etc. */ 1484 1485 syncing = make_sync.syncout = (output_sync == OUTPUT_SYNC_LINE 1486 || output_sync == OUTPUT_SYNC_TARGET); 1487 OUTPUT_SET (&make_sync); 1488 1489 /* Remember the job slots set through the environment vs. command line. */ 1490 { 1491 int env_slots = arg_job_slots; 1492 arg_job_slots = INVALID_JOB_SLOTS; 1493 1494 decode_switches (argc, (const char **)argv, 0); 1495 argv_slots = arg_job_slots; 1496 1497 if (arg_job_slots == INVALID_JOB_SLOTS) 1498 arg_job_slots = env_slots; 1499 } 1500 1501 /* Set a variable specifying whether stdout/stdin is hooked to a TTY. */ 1502 #ifdef HAVE_ISATTY 1503 if (isatty (fileno (stdout))) 1504 if (! lookup_variable (STRING_SIZE_TUPLE ("MAKE_TERMOUT"))) 1505 { 1506 const char *tty = TTYNAME (fileno (stdout)); 1507 define_variable_cname ("MAKE_TERMOUT", tty ? tty : DEFAULT_TTYNAME, 1508 o_default, 0)->export = v_export; 1509 } 1510 if (isatty (fileno (stderr))) 1511 if (! lookup_variable (STRING_SIZE_TUPLE ("MAKE_TERMERR"))) 1512 { 1513 const char *tty = TTYNAME (fileno (stderr)); 1514 define_variable_cname ("MAKE_TERMERR", tty ? tty : DEFAULT_TTYNAME, 1515 o_default, 0)->export = v_export; 1516 } 1517 #endif 1518 1519 /* Reset in case the switches changed our minds. */ 1520 syncing = (output_sync == OUTPUT_SYNC_LINE 1521 || output_sync == OUTPUT_SYNC_TARGET); 1522 1523 if (make_sync.syncout && ! syncing) 1524 output_close (&make_sync); 1525 1526 make_sync.syncout = syncing; 1527 OUTPUT_SET (&make_sync); 1528 1529 /* Figure out the level of recursion. */ 1530 { 1531 struct variable *v = lookup_variable (STRING_SIZE_TUPLE (MAKELEVEL_NAME)); 1532 if (v && v->value[0] != '\0' && v->value[0] != '-') 1533 makelevel = (unsigned int) atoi (v->value); 1534 else 1535 makelevel = 0; 1536 } 1273 1537 1274 1538 #ifdef WINDOWS32 1275 if (suspend_flag) { 1276 fprintf(stderr, "%s (pid = %ld)\n", argv[0], GetCurrentProcessId()); 1277 fprintf(stderr, _("%s is suspending for 30 seconds..."), argv[0]); 1278 Sleep(30 * 1000); 1279 fprintf(stderr, _("done sleep(30). Continuing.\n")); 1280 } 1281 #endif 1282 1283 decode_debug_flags (); 1539 if (suspend_flag) 1540 { 1541 fprintf (stderr, "%s (pid = %ld)\n", argv[0], GetCurrentProcessId ()); 1542 fprintf (stderr, _("%s is suspending for 30 seconds..."), argv[0]); 1543 Sleep (30 * 1000); 1544 fprintf (stderr, _("done sleep(30). Continuing.\n")); 1545 } 1546 #endif 1284 1547 1285 1548 /* Set always_make_flag if -B was given and we've not restarted already. */ 1286 1549 always_make_flag = always_make_set && (restarts == 0); 1287 1550 1288 /* Print version information . */1289 if (print_version_flag || print_data_base_flag || db_level)1551 /* Print version information, and exit. */ 1552 if (print_version_flag) 1290 1553 { 1291 1554 print_version (); 1292 1293 /* `make --version' is supposed to just print the version and exit. */1294 if (print_version_flag) 1295 die (0);1296 }1555 die (MAKE_SUCCESS); 1556 } 1557 1558 if (ISDB (DB_BASIC)) 1559 print_version (); 1297 1560 1298 1561 #ifndef VMS … … 1309 1572 * CreateProcess(). 1310 1573 */ 1311 if (strpbrk(argv[0], "/:\\") || 1312 strstr(argv[0], "..") || 1313 strneq(argv[0], "//", 2)) 1314 argv[0] = xstrdup(w32ify(argv[0],1)); 1574 if (strpbrk (argv[0], "/:\\") || strstr (argv[0], "..") 1575 || strneq (argv[0], "//", 2)) 1576 argv[0] = xstrdup (w32ify (argv[0], 1)); 1315 1577 #else /* WINDOWS32 */ 1316 1578 #if defined (__MSDOS__) || defined (__EMX__) … … 1321 1583 argv[0] = xstrdup (argv[0]); 1322 1584 for (p = argv[0]; *p; p++) 1323 1324 1585 if (*p == '\\') 1586 *p = '/'; 1325 1587 } 1326 1588 /* If argv[0] is not in absolute form, prepend the current … … 1349 1611 #endif 1350 1612 1613 /* We may move, but until we do, here we are. */ 1614 starting_directory = current_directory; 1615 1616 /* Set up the job_slots value and the jobserver. This can't be usefully set 1617 in the makefile, and we want to verify the authorization is valid before 1618 make has a chance to start using it for something else. */ 1619 1620 if (jobserver_auth) 1621 { 1622 if (argv_slots == INVALID_JOB_SLOTS) 1623 { 1624 if (jobserver_parse_auth (jobserver_auth)) 1625 { 1626 /* Success! Use the jobserver. */ 1627 job_slots = 0; 1628 goto job_setup_complete; 1629 } 1630 1631 O (error, NILF, _("warning: jobserver unavailable: using -j1. Add '+' to parent make rule.")); 1632 arg_job_slots = 1; 1633 } 1634 1635 /* The user provided a -j setting on the command line: use it. */ 1636 else if (!restarts) 1637 /* If restarts is >0 we already printed this message. */ 1638 O (error, NILF, 1639 _("warning: -jN forced in submake: disabling jobserver mode.")); 1640 1641 /* We failed to use our parent's jobserver. */ 1642 reset_jobserver (); 1643 job_slots = (unsigned int)arg_job_slots; 1644 } 1645 else if (arg_job_slots == INVALID_JOB_SLOTS) 1646 /* The default is one job at a time. */ 1647 job_slots = 1; 1648 else 1649 /* Use whatever was provided. */ 1650 job_slots = (unsigned int)arg_job_slots; 1651 1652 job_setup_complete: 1653 1351 1654 /* The extra indirection through $(MAKE_COMMAND) is done 1352 1655 for hysterical raisins. */ 1656 1657 #ifdef VMS 1658 if (vms_use_mcr_command) 1659 define_variable_cname ("MAKE_COMMAND", vms_command (argv[0]), o_default, 0); 1660 else 1661 define_variable_cname ("MAKE_COMMAND", program, o_default, 0); 1662 #else 1353 1663 define_variable_cname ("MAKE_COMMAND", argv[0], o_default, 0); 1664 #endif 1354 1665 define_variable_cname ("MAKE", "$(MAKE_COMMAND)", o_default, 1); 1355 1666 … … 1362 1673 1363 1674 /* Figure out how much space will be taken up by the command-line 1364 1675 variable definitions. */ 1365 1676 for (cv = command_variables; cv != 0; cv = cv->next) 1366 1367 1368 1369 1370 1371 1372 1373 1374 1677 { 1678 v = cv->variable; 1679 len += 2 * strlen (v->name); 1680 if (! v->recursive) 1681 ++len; 1682 ++len; 1683 len += 2 * strlen (v->value); 1684 ++len; 1685 } 1375 1686 1376 1687 /* Now allocate a buffer big enough and fill it. */ 1377 1688 p = value = alloca (len); 1378 1689 for (cv = command_variables; cv != 0; cv = cv->next) 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 p[-1] = '\0'; 1690 { 1691 v = cv->variable; 1692 p = quote_for_env (p, v->name); 1693 if (! v->recursive) 1694 *p++ = ':'; 1695 *p++ = '='; 1696 p = quote_for_env (p, v->value); 1697 *p++ = ' '; 1698 } 1699 p[-1] = '\0'; /* Kill the final space and terminate. */ 1389 1700 1390 1701 /* Define an unchangeable variable with a name that no POSIX.2 1391 1702 makefile could validly use for its own variable. */ 1392 1703 define_variable_cname ("-*-command-variables-*-", value, o_automatic, 0); 1393 1704 … … 1400 1711 define_variable_cname ("MAKEOVERRIDES", "${-*-command-variables-*-}", 1401 1712 o_env, 1); 1713 #ifdef VMS 1714 vms_export_dcl_symbol ("MAKEOVERRIDES", "${-*-command-variables-*-}"); 1715 #endif 1402 1716 } 1403 1717 … … 1434 1748 * at the wrong place when it was first evaluated. 1435 1749 */ 1436 no_default_sh_exe = !find_and_set_default_shell(NULL); 1437 1750 no_default_sh_exe = !find_and_set_default_shell (NULL); 1438 1751 #endif /* WINDOWS32 */ 1439 /* Figure out the level of recursion. */1440 {1441 struct variable *v = lookup_variable (STRING_SIZE_TUPLE (MAKELEVEL_NAME));1442 if (v != 0 && v->value[0] != '\0' && v->value[0] != '-')1443 makelevel = (unsigned int) atoi (v->value);1444 else1445 makelevel = 0;1446 }1447 1752 1448 1753 /* Except under -s, always do -w in sub-makes and under -C. */ … … 1463 1768 ? 0 : include_directories->list); 1464 1769 1465 /* Figure out where we are now, after chdir'ing. */ 1466 if (directories == 0) 1467 /* We didn't move, so we're still in the same place. */ 1468 starting_directory = current_directory; 1469 else 1770 /* If we chdir'ed, figure out where we are now. */ 1771 if (directories) 1470 1772 { 1471 1773 #ifdef WINDOWS32 … … 1474 1776 if (getcwd (current_directory, GET_PATH_MAX) == 0) 1475 1777 #endif 1476 1477 #ifdef 1478 1778 { 1779 #ifdef HAVE_GETCWD 1780 perror_with_name ("getcwd", ""); 1479 1781 #else 1480 error (NILF, "getwd: %s", current_directory);1481 #endif 1482 1483 1782 OS (error, NILF, "getwd: %s", current_directory); 1783 #endif 1784 starting_directory = 0; 1785 } 1484 1786 else 1485 1787 starting_directory = current_directory; 1486 1788 } 1487 1789 … … 1494 1796 unsigned int i; 1495 1797 for (i = 0; i < makefiles->idx; ++i) 1496 if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0') 1497 { 1498 /* This makefile is standard input. Since we may re-exec 1499 and thus re-read the makefiles, we read standard input 1500 into a temporary file and read from that. */ 1501 FILE *outfile; 1502 char *template, *tmpdir; 1798 if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0') 1799 { 1800 /* This makefile is standard input. Since we may re-exec 1801 and thus re-read the makefiles, we read standard input 1802 into a temporary file and read from that. */ 1803 FILE *outfile; 1804 char *template; 1805 const char *tmpdir; 1503 1806 1504 1807 if (stdin_nm) 1505 fatal (NILF, _("Makefile from standard input specified twice.")); 1808 O (fatal, NILF, 1809 _("Makefile from standard input specified twice.")); 1506 1810 1507 1811 #ifdef VMS 1508 # define DEFAULT_TMPDIR " sys$scratch:"1812 # define DEFAULT_TMPDIR "/sys$scratch/" 1509 1813 #else 1510 1814 # ifdef P_tmpdir … … 1516 1820 #define DEFAULT_TMPFILE "GmXXXXXX" 1517 1821 1518 1822 if (((tmpdir = getenv ("TMPDIR")) == NULL || *tmpdir == '\0') 1519 1823 #if defined (__MSDOS__) || defined (WINDOWS32) || defined (__EMX__) 1520 1824 /* These are also used commonly on these platforms. */ … … 1523 1827 #endif 1524 1828 ) 1525 1526 1527 template = alloca (strlen (tmpdir) + sizeof (DEFAULT_TMPFILE) + 1);1528 1829 tmpdir = DEFAULT_TMPDIR; 1830 1831 template = alloca (strlen (tmpdir) + CSTRLEN (DEFAULT_TMPFILE) + 2); 1832 strcpy (template, tmpdir); 1529 1833 1530 1834 #ifdef HAVE_DOS_PATHS 1531 1532 1835 if (strchr ("/\\", template[strlen (template) - 1]) == NULL) 1836 strcat (template, "/"); 1533 1837 #else 1534 1838 # ifndef VMS 1535 1536 1839 if (template[strlen (template) - 1] != '/') 1840 strcat (template, "/"); 1537 1841 # endif /* !VMS */ 1538 1842 #endif /* !HAVE_DOS_PATHS */ 1539 1843 1540 1541 outfile = open_tmpfile (&stdin_nm, template);1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1844 strcat (template, DEFAULT_TMPFILE); 1845 outfile = output_tmpfile (&stdin_nm, template); 1846 if (outfile == 0) 1847 pfatal_with_name (_("fopen (temporary file)")); 1848 while (!feof (stdin) && ! ferror (stdin)) 1849 { 1850 char buf[2048]; 1851 unsigned int n = fread (buf, 1, sizeof (buf), stdin); 1852 if (n > 0 && fwrite (buf, 1, n, outfile) != n) 1853 pfatal_with_name (_("fwrite (temporary file)")); 1854 } 1855 fclose (outfile); 1856 1857 /* Replace the name that read_all_makefiles will 1858 see with the name of the temporary file. */ 1555 1859 makefiles->list[i] = strcache_add (stdin_nm); 1556 1860 1557 1861 /* Make sure the temporary file will not be remade. */ 1558 1862 { 1559 1863 struct file *f = enter_file (strcache_add (stdin_nm)); 1560 1864 f->updated = 1; 1561 f->update_status = 0;1865 f->update_status = us_success; 1562 1866 f->command_state = cs_finished; 1563 1867 /* Can't be intermediate, or it'll be removed too early for … … 1566 1870 f->dontcare = 0; 1567 1871 } 1568 1872 } 1569 1873 } 1570 1874 1571 1875 #ifndef __EMX__ /* Don't use a SIGCHLD handler for OS/2 */ 1572 #if defined(MAKE_JOBSERVER) || !defined(HAVE_WAIT_NOHANG)1876 #if !defined(HAVE_WAIT_NOHANG) || defined(MAKE_JOBSERVER) 1573 1877 /* Set up to handle children dying. This must be done before 1574 reading in the makefiles so that `shell' function calls will work.1878 reading in the makefiles so that 'shell' function calls will work. 1575 1879 1576 1880 If we don't have a hanging wait we have to fall back to old, broken … … 1578 1882 children. 1579 1883 1580 If we're using the jobs pipe we need a signal handler so that 1581 SIGCHLD is not ignored; we need it to interrupt the read(2) of the1582 jobserver pipe in job.c ifwe're waiting for a token.1884 If we're using the jobs pipe we need a signal handler so that SIGCHLD is 1885 not ignored; we need it to interrupt the read(2) of the jobserver pipe if 1886 we're waiting for a token. 1583 1887 1584 1888 If none of these are true, we don't need a signal handler at all. */ 1585 1889 { 1586 RETSIGTYPE child_handler (int sig);1587 1890 # if defined SIGCHLD 1588 1891 bsd_signal (SIGCHLD, child_handler); … … 1592 1895 # endif 1593 1896 } 1897 1898 #ifdef HAVE_PSELECT 1899 /* If we have pselect() then we need to block SIGCHLD so it's deferred. */ 1900 { 1901 sigset_t block; 1902 sigemptyset (&block); 1903 sigaddset (&block, SIGCHLD); 1904 if (sigprocmask (SIG_SETMASK, &block, NULL) < 0) 1905 pfatal_with_name ("sigprocmask(SIG_SETMASK, SIGCHLD)"); 1906 } 1907 #endif 1908 1594 1909 #endif 1595 1910 #endif … … 1601 1916 1602 1917 /* Define the initial list of suffixes for old-style rules. */ 1603 1604 1918 set_default_suffixes (); 1605 1919 … … 1609 1923 makefiles, it results in the built-in pattern rules taking precedence 1610 1924 over makefile-specified suffix rules, which is wrong. */ 1611 1612 1925 install_default_suffix_rules (); 1613 1926 1614 1927 /* Define some internal and special variables. */ 1615 1616 1928 define_automatic_variables (); 1617 1929 1618 /* Set up the MAKEFLAGS and MFLAGS variables 1619 so makefiles can look at them. */ 1620 1621 define_makeflags (0, 0); 1930 /* Set up the MAKEFLAGS and MFLAGS variables for makefiles to see. 1931 Initialize it to be exported but allow the makefile to reset it. */ 1932 define_makeflags (0, 0)->export = v_export; 1622 1933 1623 1934 /* Define the default variables. */ … … 1635 1946 char *p, *value; 1636 1947 unsigned int i; 1637 unsigned int len = sizeof ("--eval=") * eval_strings->idx;1948 unsigned int len = (CSTRLEN ("--eval=") + 1) * eval_strings->idx; 1638 1949 1639 1950 for (i = 0; i < eval_strings->idx; ++i) … … 1641 1952 p = xstrdup (eval_strings->list[i]); 1642 1953 len += 2 * strlen (p); 1643 eval_buffer (p );1954 eval_buffer (p, NULL); 1644 1955 free (p); 1645 1956 } … … 1649 1960 { 1650 1961 strcpy (p, "--eval="); 1651 p += strlen (p);1962 p += CSTRLEN ("--eval="); 1652 1963 p = quote_for_env (p, eval_strings->list[i]); 1653 1964 *(p++) = ' '; … … 1660 1971 /* Read all the makefiles. */ 1661 1972 1662 read_makefiles 1663 = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list); 1973 read_files = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list); 1664 1974 1665 1975 #ifdef WINDOWS32 1666 1976 /* look one last time after reading all Makefiles */ 1667 1977 if (no_default_sh_exe) 1668 no_default_sh_exe = !find_and_set_default_shell (NULL);1978 no_default_sh_exe = !find_and_set_default_shell (NULL); 1669 1979 #endif /* WINDOWS32 */ 1670 1980 1671 #if defined (__MSDOS__) || defined (__EMX__) 1981 #if defined (__MSDOS__) || defined (__EMX__) || defined (VMS) 1672 1982 /* We need to know what kind of shell we will be using. */ 1673 1983 { … … 1675 1985 struct variable *shv = lookup_variable (STRING_SIZE_TUPLE ("SHELL")); 1676 1986 extern int unixy_shell; 1677 extern c har *default_shell;1987 extern const char *default_shell; 1678 1988 1679 1989 if (shv && *shv->value) 1680 1990 { 1681 char *shell_path = recursively_expand(shv);1682 1683 1684 1685 1686 1687 1688 1991 char *shell_path = recursively_expand (shv); 1992 1993 if (shell_path && _is_unixy_shell (shell_path)) 1994 unixy_shell = 1; 1995 else 1996 unixy_shell = 0; 1997 if (shell_path) 1998 default_shell = shell_path; 1689 1999 } 1690 2000 } 1691 2001 #endif /* __MSDOS__ || __EMX__ */ 1692 2002 1693 /* Decode switches again, in case the variables were set by the makefile. */ 1694 decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS")); 2003 { 2004 int old_builtin_rules_flag = no_builtin_rules_flag; 2005 int old_builtin_variables_flag = no_builtin_variables_flag; 2006 2007 /* Decode switches again, for variables set by the makefile. */ 2008 decode_env_switches (STRING_SIZE_TUPLE ("GNUMAKEFLAGS")); 2009 2010 /* Clear GNUMAKEFLAGS to avoid duplication. */ 2011 define_variable_cname ("GNUMAKEFLAGS", "", o_override, 0); 2012 2013 decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS")); 1695 2014 #if 0 1696 decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS")); 1697 #endif 1698 1699 #if defined (__MSDOS__) || defined (__EMX__) 1700 if (job_slots != 1 2015 decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS")); 2016 #endif 2017 2018 /* Reset in case the switches changed our mind. */ 2019 syncing = (output_sync == OUTPUT_SYNC_LINE 2020 || output_sync == OUTPUT_SYNC_TARGET); 2021 2022 if (make_sync.syncout && ! syncing) 2023 output_close (&make_sync); 2024 2025 make_sync.syncout = syncing; 2026 OUTPUT_SET (&make_sync); 2027 2028 /* If we've disabled builtin rules, get rid of them. */ 2029 if (no_builtin_rules_flag && ! old_builtin_rules_flag) 2030 { 2031 if (suffix_file->builtin) 2032 { 2033 free_dep_chain (suffix_file->deps); 2034 suffix_file->deps = 0; 2035 } 2036 define_variable_cname ("SUFFIXES", "", o_default, 0); 2037 } 2038 2039 /* If we've disabled builtin variables, get rid of them. */ 2040 if (no_builtin_variables_flag && ! old_builtin_variables_flag) 2041 undefine_default_variables (); 2042 } 2043 2044 #if defined (__MSDOS__) || defined (__EMX__) || defined (VMS) 2045 if (arg_job_slots != 1 1701 2046 # ifdef __EMX__ 1702 2047 && _osmode != OS2_MODE /* turn off -j if we are in DOS mode */ … … 1704 2049 ) 1705 2050 { 1706 error (NILF, 1707 _("Parallel jobs (-j) are not supported on this platform.")); 1708 error (NILF, _("Resetting to single job (-j1) mode.")); 1709 job_slots = 1; 1710 } 1711 #endif 1712 1713 #ifdef MAKE_JOBSERVER 1714 /* If the jobserver-fds option is seen, make sure that -j is reasonable. */ 1715 1716 if (jobserver_fds) 1717 { 1718 const char *cp; 1719 unsigned int ui; 1720 1721 for (ui=1; ui < jobserver_fds->idx; ++ui) 1722 if (!streq (jobserver_fds->list[0], jobserver_fds->list[ui])) 1723 fatal (NILF, _("internal error: multiple --jobserver-fds options")); 1724 1725 /* Now parse the fds string and make sure it has the proper format. */ 1726 1727 cp = jobserver_fds->list[0]; 1728 1729 if (sscanf (cp, "%d,%d", &job_fds[0], &job_fds[1]) != 2) 1730 fatal (NILF, 1731 _("internal error: invalid --jobserver-fds string `%s'"), cp); 1732 1733 DB (DB_JOBS, 1734 (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1])); 1735 1736 /* The combination of a pipe + !job_slots means we're using the 1737 jobserver. If !job_slots and we don't have a pipe, we can start 1738 infinite jobs. If we see both a pipe and job_slots >0 that means the 1739 user set -j explicitly. This is broken; in this case obey the user 1740 (ignore the jobserver pipe for this make) but print a message. */ 1741 1742 if (job_slots > 0) 1743 error (NILF, 1744 _("warning: -jN forced in submake: disabling jobserver mode.")); 1745 1746 /* Create a duplicate pipe, that will be closed in the SIGCHLD 1747 handler. If this fails with EBADF, the parent has closed the pipe 1748 on us because it didn't think we were a submake. If so, print a 1749 warning then default to -j1. */ 1750 1751 else if ((job_rfd = dup (job_fds[0])) < 0) 2051 O (error, NILF, 2052 _("Parallel jobs (-j) are not supported on this platform.")); 2053 O (error, NILF, _("Resetting to single job (-j1) mode.")); 2054 arg_job_slots = job_slots = 1; 2055 } 2056 #endif 2057 2058 /* If we have >1 slot at this point, then we're a top-level make. 2059 Set up the jobserver. 2060 2061 Every make assumes that it always has one job it can run. For the 2062 submakes it's the token they were given by their parent. For the top 2063 make, we just subtract one from the number the user wants. */ 2064 2065 if (job_slots > 1 && jobserver_setup (job_slots - 1)) 2066 { 2067 /* Fill in the jobserver_auth for our children. */ 2068 jobserver_auth = jobserver_get_auth (); 2069 2070 if (jobserver_auth) 1752 2071 { 1753 if (errno != EBADF) 1754 pfatal_with_name (_("dup jobserver")); 1755 1756 error (NILF, 1757 _("warning: jobserver unavailable: using -j1. Add `+' to parent make rule.")); 1758 job_slots = 1; 2072 /* We're using the jobserver so set job_slots to 0. */ 2073 master_job_slots = job_slots; 2074 job_slots = 0; 1759 2075 } 1760 1761 if (job_slots > 0) 1762 { 1763 close (job_fds[0]); 1764 close (job_fds[1]); 1765 job_fds[0] = job_fds[1] = -1; 1766 free (jobserver_fds->list); 1767 free (jobserver_fds); 1768 jobserver_fds = 0; 1769 } 1770 } 1771 1772 /* If we have >1 slot but no jobserver-fds, then we're a top-level make. 1773 Set up the pipe and install the fds option for our children. */ 1774 1775 if (job_slots > 1) 1776 { 1777 char *cp; 1778 char c = '+'; 1779 1780 if (pipe (job_fds) < 0 || (job_rfd = dup (job_fds[0])) < 0) 1781 pfatal_with_name (_("creating jobs pipe")); 1782 1783 /* Every make assumes that it always has one job it can run. For the 1784 submakes it's the token they were given by their parent. For the 1785 top make, we just subtract one from the number the user wants. We 1786 want job_slots to be 0 to indicate we're using the jobserver. */ 1787 1788 master_job_slots = job_slots; 1789 1790 while (--job_slots) 1791 { 1792 int r; 1793 1794 EINTRLOOP (r, write (job_fds[1], &c, 1)); 1795 if (r != 1) 1796 pfatal_with_name (_("init jobserver pipe")); 1797 } 1798 1799 /* Fill in the jobserver_fds struct for our children. */ 1800 1801 cp = xmalloc ((sizeof ("1024")*2)+1); 1802 sprintf (cp, "%d,%d", job_fds[0], job_fds[1]); 1803 1804 jobserver_fds = (struct stringlist *) 1805 xmalloc (sizeof (struct stringlist)); 1806 jobserver_fds->list = xmalloc (sizeof (char *)); 1807 jobserver_fds->list[0] = cp; 1808 jobserver_fds->idx = 1; 1809 jobserver_fds->max = 1; 1810 } 1811 #endif 2076 } 2077 2078 /* If we're not using parallel jobs, then we don't need output sync. 2079 This is so people can enable output sync in GNUMAKEFLAGS or similar, but 2080 not have it take effect unless parallel builds are enabled. */ 2081 if (syncing && job_slots == 1) 2082 { 2083 OUTPUT_UNSET (); 2084 output_close (&make_sync); 2085 syncing = 0; 2086 output_sync = OUTPUT_SYNC_NONE; 2087 } 1812 2088 1813 2089 #ifndef MAKE_SYMLINKS 1814 2090 if (check_symlink_flag) 1815 2091 { 1816 error (NILF, _("Symbolic links not supported: disabling -L."));2092 O (error, NILF, _("Symbolic links not supported: disabling -L.")); 1817 2093 check_symlink_flag = 0; 1818 2094 } … … 1823 2099 define_makeflags (1, 0); 1824 2100 1825 /* Make each `struct dep' point at the `struct file' for the file2101 /* Make each 'struct goaldep' point at the 'struct file' for the file 1826 2102 depended on. Also do magic for special targets. */ 1827 2103 … … 1862 2138 f->last_mtime = f->mtime_before_update = OLD_MTIME; 1863 2139 f->updated = 1; 1864 f->update_status = 0;2140 f->update_status = us_success; 1865 2141 f->command_state = cs_finished; 1866 2142 } … … 1871 2147 const char **p; 1872 2148 for (p = new_files->list; *p != 0; ++p) 1873 1874 1875 1876 2149 { 2150 struct file *f = enter_file (*p); 2151 f->last_mtime = f->mtime_before_update = NEW_MTIME; 2152 } 1877 2153 } 1878 2154 … … 1880 2156 remote_setup (); 1881 2157 1882 if (read_makefiles != 0) 2158 /* Dump any output we've collected. */ 2159 2160 OUTPUT_UNSET (); 2161 output_close (&make_sync); 2162 2163 if (read_files != 0) 1883 2164 { 1884 2165 /* Update any makefiles if necessary. */ … … 1886 2167 FILE_TIMESTAMP *makefile_mtimes = 0; 1887 2168 unsigned int mm_idx = 0; 1888 char **nargv; 2169 char **aargv = NULL; 2170 const char **nargv; 1889 2171 int nargc; 1890 int orig_db_level = db_level; 1891 int status; 1892 1893 if (! ISDB (DB_MAKEFILES)) 1894 db_level = DB_NONE; 2172 enum update_status status; 1895 2173 1896 2174 DB (DB_BASIC, (_("Updating makefiles....\n"))); 1897 2175 1898 2176 /* Remove any makefiles we don't want to try to update. 1899 2177 Also record the current modtimes so we can compare them later. */ 1900 2178 { 1901 register structdep *d, *last;1902 1903 d = read_makefiles;1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 (_("Makefile `%s' might loop; not remaking it.\n"),2179 register struct goaldep *d, *last; 2180 last = 0; 2181 d = read_files; 2182 while (d != 0) 2183 { 2184 struct file *f = d->file; 2185 if (f->double_colon) 2186 for (f = f->double_colon; f != NULL; f = f->prev) 2187 { 2188 if (f->deps == 0 && f->cmds != 0) 2189 { 2190 /* This makefile is a :: target with commands, but 2191 no dependencies. So, it will always be remade. 2192 This might well cause an infinite loop, so don't 2193 try to remake it. (This will only happen if 2194 your makefiles are written exceptionally 2195 stupidly; but if you work for Athena, that's how 2196 you write your makefiles.) */ 2197 2198 DB (DB_VERBOSE, 2199 (_("Makefile '%s' might loop; not remaking it.\n"), 1922 2200 f->name)); 1923 2201 1924 if (last == 0) 1925 read_makefiles = d->next; 1926 else 1927 last->next = d->next; 1928 1929 /* Free the storage. */ 1930 free_dep (d); 1931 1932 d = last == 0 ? read_makefiles : last->next; 1933 1934 break; 1935 } 1936 } 1937 if (f == NULL || !f->double_colon) 1938 { 2202 if (last == 0) 2203 read_files = d->next; 2204 else 2205 last->next = d->next; 2206 2207 /* Free the storage. */ 2208 free_goaldep (d); 2209 2210 d = last == 0 ? read_files : last->next; 2211 2212 break; 2213 } 2214 } 2215 2216 if (f == NULL || !f->double_colon) 2217 { 1939 2218 makefile_mtimes = xrealloc (makefile_mtimes, 1940 2219 (mm_idx+1) 1941 2220 * sizeof (FILE_TIMESTAMP)); 1942 1943 1944 1945 1946 2221 makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file); 2222 last = d; 2223 d = d->next; 2224 } 2225 } 1947 2226 } 1948 2227 1949 /* Set up `MAKEFLAGS' specially while remaking makefiles. */2228 /* Set up 'MAKEFLAGS' specially while remaking makefiles. */ 1950 2229 define_makeflags (1, 1); 1951 2230 1952 rebuilding_makefiles = 1; 1953 status = update_goal_chain (read_makefiles); 1954 rebuilding_makefiles = 0; 2231 { 2232 int orig_db_level = db_level; 2233 2234 if (! ISDB (DB_MAKEFILES)) 2235 db_level = DB_NONE; 2236 2237 rebuilding_makefiles = 1; 2238 status = update_goal_chain (read_files); 2239 rebuilding_makefiles = 0; 2240 2241 db_level = orig_db_level; 2242 } 1955 2243 1956 2244 switch (status) 1957 1958 case 1:2245 { 2246 case us_question: 1959 2247 /* The only way this can happen is if the user specified -q and asked 1960 * for one of the makefiles to be remade as a target on the command 1961 * line. Since we're not actually updating anything with -q we can 1962 * treat this as "did nothing". 1963 */ 1964 1965 case -1: 1966 /* Did nothing. */ 1967 break; 1968 1969 case 2: 1970 /* Failed to update. Figure out if we care. */ 1971 { 1972 /* Nonzero if any makefile was successfully remade. */ 1973 int any_remade = 0; 1974 /* Nonzero if any makefile we care about failed 1975 in updating or could not be found at all. */ 1976 int any_failed = 0; 1977 unsigned int i; 1978 struct dep *d; 1979 1980 for (i = 0, d = read_makefiles; d != 0; ++i, d = d->next) 2248 for one of the makefiles to be remade as a target on the command 2249 line. Since we're not actually updating anything with -q we can 2250 treat this as "did nothing". */ 2251 2252 case us_none: 2253 /* Did nothing. */ 2254 break; 2255 2256 case us_failed: 2257 /* Failed to update. Figure out if we care. */ 2258 { 2259 /* Nonzero if any makefile was successfully remade. */ 2260 int any_remade = 0; 2261 /* Nonzero if any makefile we care about failed 2262 in updating or could not be found at all. */ 2263 int any_failed = 0; 2264 unsigned int i; 2265 struct goaldep *d; 2266 2267 for (i = 0, d = read_files; d != 0; ++i, d = d->next) 1981 2268 { 1982 /* Reset the considered flag; we may need to look at the file1983 again to print an error. */1984 d->file->considered = 0;1985 1986 2269 if (d->file->updated) 1987 2270 { 1988 2271 /* This makefile was updated. */ 1989 if (d->file->update_status == 0)2272 if (d->file->update_status == us_success) 1990 2273 { 1991 2274 /* It was successfully updated. */ … … 1993 2276 != makefile_mtimes[i]); 1994 2277 } 1995 else if (! (d-> changed& RM_DONTCARE))2278 else if (! (d->flags & RM_DONTCARE)) 1996 2279 { 1997 2280 FILE_TIMESTAMP mtime; 1998 2281 /* The update failed and this makefile was not 1999 2282 from the MAKEFILES variable, so we care. */ 2000 error (NILF, _("Failed to remake makefile `%s'."),2001 2283 OS (error, NILF, _("Failed to remake makefile '%s'."), 2284 d->file->name); 2002 2285 mtime = file_mtime_no_search (d->file); 2003 2286 any_remade |= (mtime != NONEXISTENT_MTIME … … 2008 2291 else 2009 2292 /* This makefile was not found at all. */ 2010 if (! (d-> changed& RM_DONTCARE))2293 if (! (d->flags & RM_DONTCARE)) 2011 2294 { 2295 const char *dnm = dep_name (d); 2296 size_t l = strlen (dnm); 2297 2012 2298 /* This is a makefile we care about. See how much. */ 2013 if (d->changed & RM_INCLUDED) 2014 /* An included makefile. We don't need 2015 to die, but we do want to complain. */ 2016 error (NILF, 2017 _("Included makefile `%s' was not found."), 2018 dep_name (d)); 2299 if (d->flags & RM_INCLUDED) 2300 /* An included makefile. We don't need to die, but we 2301 do want to complain. */ 2302 error (NILF, l, 2303 _("Included makefile '%s' was not found."), dnm); 2019 2304 else 2020 2305 { 2021 2306 /* A normal makefile. We must die later. */ 2022 error (NILF, _("Makefile `%s' was not found"),2023 dep_name (d));2307 error (NILF, l, 2308 _("Makefile '%s' was not found"), dnm); 2024 2309 any_failed = 1; 2025 2310 } … … 2027 2312 } 2028 2313 /* Reset this to empty so we get the right error message below. */ 2029 read_ makefiles = 0;2030 2031 2032 2033 2034 die (2);2314 read_files = 0; 2315 2316 if (any_remade) 2317 goto re_exec; 2318 if (any_failed) 2319 die (MAKE_FAILURE); 2035 2320 break; 2036 } 2037 2038 case 0: 2039 re_exec: 2040 /* Updated successfully. Re-exec ourselves. */ 2041 2042 remove_intermediates (0); 2043 2044 if (print_data_base_flag) 2045 print_data_base (); 2046 2047 log_working_directory (0); 2321 } 2322 2323 case us_success: 2324 re_exec: 2325 /* Updated successfully. Re-exec ourselves. */ 2326 2327 remove_intermediates (0); 2328 2329 if (print_data_base_flag) 2330 print_data_base (); 2048 2331 2049 2332 clean_jobserver (0); 2050 2333 2051 2052 2053 2054 2055 2056 2057 2058 2334 if (makefiles != 0) 2335 { 2336 /* These names might have changed. */ 2337 int i, j = 0; 2338 for (i = 1; i < argc; ++i) 2339 if (strneq (argv[i], "-f", 2)) /* XXX */ 2340 { 2341 if (argv[i][2] == '\0') 2059 2342 /* This cast is OK since we never modify argv. */ 2060 2061 2062 2063 2064 2065 2343 argv[++i] = (char *) makefiles->list[j]; 2344 else 2345 argv[i] = xstrdup (concat (2, "-f", makefiles->list[j])); 2346 ++j; 2347 } 2348 } 2066 2349 2067 2350 /* Add -o option for the stdin temporary file, if necessary. */ … … 2069 2352 if (stdin_nm) 2070 2353 { 2071 nargv = xmalloc ((nargc + 2) * sizeof (char *)); 2072 memcpy (nargv, argv, argc * sizeof (char *)); 2073 nargv[nargc++] = xstrdup (concat (2, "-o", stdin_nm)); 2074 nargv[nargc] = 0; 2354 void *m = xmalloc ((nargc + 2) * sizeof (char *)); 2355 aargv = m; 2356 memcpy (aargv, argv, argc * sizeof (char *)); 2357 aargv[nargc++] = xstrdup (concat (2, "-o", stdin_nm)); 2358 aargv[nargc] = 0; 2359 nargv = m; 2075 2360 } 2076 2361 else 2077 nargv = argv; 2078 2079 if (directories != 0 && directories->idx > 0) 2080 { 2081 int bad = 1; 2082 if (directory_before_chdir != 0) 2083 { 2084 if (chdir (directory_before_chdir) < 0) 2085 perror_with_name ("chdir", ""); 2086 else 2087 bad = 0; 2088 } 2089 if (bad) 2090 fatal (NILF, _("Couldn't change back to original directory.")); 2091 } 2362 nargv = (const char**)argv; 2363 2364 if (directories != 0 && directories->idx > 0) 2365 { 2366 int bad = 1; 2367 if (directory_before_chdir != 0) 2368 { 2369 if (chdir (directory_before_chdir) < 0) 2370 perror_with_name ("chdir", ""); 2371 else 2372 bad = 0; 2373 } 2374 if (bad) 2375 O (fatal, NILF, 2376 _("Couldn't change back to original directory.")); 2377 } 2092 2378 2093 2379 ++restarts; 2094 2380 2095 /* Reset makeflags in case they were changed. */ 2096 { 2097 const char *pv = define_makeflags (1, 1); 2098 char *p = alloca (sizeof ("MAKEFLAGS=") + strlen (pv) + 1); 2099 sprintf (p, "MAKEFLAGS=%s", pv); 2100 putenv (p); 2101 } 2102 2103 if (ISDB (DB_BASIC)) 2104 { 2105 char **p; 2106 printf (_("Re-executing[%u]:"), restarts); 2107 for (p = nargv; *p != 0; ++p) 2108 printf (" %s", *p); 2109 putchar ('\n'); 2110 } 2381 if (ISDB (DB_BASIC)) 2382 { 2383 const char **p; 2384 printf (_("Re-executing[%u]:"), restarts); 2385 for (p = nargv; *p != 0; ++p) 2386 printf (" %s", *p); 2387 putchar ('\n'); 2388 fflush (stdout); 2389 } 2111 2390 2112 2391 #ifndef _AMIGA … … 2115 2394 for (p = environ; *p != 0; ++p) 2116 2395 { 2117 if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH) 2118 && (*p)[MAKELEVEL_LENGTH] == '=') 2396 if (strneq (*p, MAKELEVEL_NAME "=", MAKELEVEL_LENGTH+1)) 2119 2397 { 2120 2398 *p = alloca (40); 2121 2399 sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel); 2400 #ifdef VMS 2401 vms_putenv_symbol (*p); 2402 #endif 2122 2403 } 2123 if (strneq (*p, "MAKE_RESTARTS=", 14))2404 else if (strneq (*p, "MAKE_RESTARTS=", CSTRLEN ("MAKE_RESTARTS="))) 2124 2405 { 2125 2406 *p = alloca (40); 2126 sprintf (*p, "MAKE_RESTARTS=%u", restarts); 2407 sprintf (*p, "MAKE_RESTARTS=%s%u", 2408 OUTPUT_IS_TRACED () ? "-" : "", restarts); 2127 2409 restarts = 0; 2128 2410 } … … 2130 2412 } 2131 2413 #else /* AMIGA */ 2132 2133 2414 { 2415 char buffer[256]; 2134 2416 2135 2417 sprintf (buffer, "%u", makelevel); 2136 2418 SetVar (MAKELEVEL_NAME, buffer, -1, GVF_GLOBAL_ONLY); 2137 2419 2138 sprintf (buffer, "% u", restarts);2420 sprintf (buffer, "%s%u", OUTPUT_IS_TRACED () ? "-" : "", restarts); 2139 2421 SetVar ("MAKE_RESTARTS", buffer, -1, GVF_GLOBAL_ONLY); 2140 2422 restarts = 0; 2141 2423 } 2142 2424 #endif 2143 2425 … … 2146 2428 { 2147 2429 char *b = alloca (40); 2148 sprintf (b, "MAKE_RESTARTS=%u", restarts); 2430 sprintf (b, "MAKE_RESTARTS=%s%u", 2431 OUTPUT_IS_TRACED () ? "-" : "", restarts); 2149 2432 putenv (b); 2150 2433 } 2151 2434 2152 fflush (stdout); 2153 fflush (stderr); 2154 2155 /* Close the dup'd jobserver pipe if we opened one. */ 2156 if (job_rfd >= 0) 2157 close (job_rfd); 2435 fflush (stdout); 2436 fflush (stderr); 2158 2437 2159 2438 #ifdef _AMIGA 2160 2161 2439 exec_command (nargv); 2440 exit (0); 2162 2441 #elif defined (__EMX__) 2163 2164 2165 2166 2167 2168 2169 2170 2171 int status;2172 pid = child_execute_job (0, 1, nargv, environ);2173 2174 2175 2176 pid = wait (&status);2177 2178 2179 exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);2180 2442 { 2443 /* It is not possible to use execve() here because this 2444 would cause the parent process to be terminated with 2445 exit code 0 before the child process has been terminated. 2446 Therefore it may be the best solution simply to spawn the 2447 child process including all file handles and to wait for its 2448 termination. */ 2449 int pid; 2450 int r; 2451 pid = child_execute_job (NULL, 1, nargv, environ); 2452 2453 /* is this loop really necessary? */ 2454 do { 2455 pid = wait (&r); 2456 } while (pid <= 0); 2457 /* use the exit code of the child process */ 2458 exit (WIFEXITED(r) ? WEXITSTATUS(r) : EXIT_FAILURE); 2459 } 2181 2460 #else 2182 exec_command (nargv, environ); 2183 #endif 2184 /* NOTREACHED */ 2185 2186 default: 2187 #define BOGUS_UPDATE_STATUS 0 2188 assert (BOGUS_UPDATE_STATUS); 2189 break; 2190 } 2191 2192 db_level = orig_db_level; 2193 2194 /* Free the makefile mtimes (if we allocated any). */ 2195 if (makefile_mtimes) 2196 free (makefile_mtimes); 2197 } 2198 2199 /* Set up `MAKEFLAGS' again for the normal targets. */ 2461 #ifdef SET_STACK_SIZE 2462 /* Reset limits, if necessary. */ 2463 if (stack_limit.rlim_cur) 2464 setrlimit (RLIMIT_STACK, &stack_limit); 2465 #endif 2466 exec_command ((char **)nargv, environ); 2467 #endif 2468 free (aargv); 2469 break; 2470 } 2471 2472 /* Free the makefile mtimes. */ 2473 free (makefile_mtimes); 2474 } 2475 2476 /* Set up 'MAKEFLAGS' again for the normal targets. */ 2200 2477 define_makeflags (1, 0); 2201 2478 … … 2208 2485 const char **p; 2209 2486 for (p = new_files->list; *p != 0; ++p) 2210 2211 2212 2213 2487 { 2488 struct file *f = enter_file (*p); 2489 f->last_mtime = f->mtime_before_update = NEW_MTIME; 2490 } 2214 2491 } 2215 2492 … … 2244 2521 struct nameseq *ns; 2245 2522 2246 ns = PARSE_ FILE_SEQ (&p, struct nameseq, '\0', NULL, 0);2523 ns = PARSE_SIMPLE_SEQ (&p, struct nameseq); 2247 2524 if (ns) 2248 2525 { 2249 2526 /* .DEFAULT_GOAL should contain one target. */ 2250 2527 if (ns->next != 0) 2251 fatal (NILF, _(".DEFAULT_GOAL contains more than one target")); 2528 O (fatal, NILF, 2529 _(".DEFAULT_GOAL contains more than one target")); 2252 2530 2253 2531 f = enter_file (strcache_add (ns->name)); … … 2260 2538 if (f) 2261 2539 { 2262 goals = alloc_ dep ();2540 goals = alloc_goaldep (); 2263 2541 goals->file = f; 2264 2542 } … … 2271 2549 if (!goals) 2272 2550 { 2273 if (read_ makefiles == 0)2274 fatal (NILF, _("No targets specified and no makefile found"));2275 2276 fatal (NILF, _("No targets"));2551 if (read_files == 0) 2552 O (fatal, NILF, _("No targets specified and no makefile found")); 2553 2554 O (fatal, NILF, _("No targets")); 2277 2555 } 2278 2556 … … 2282 2560 2283 2561 { 2284 int status;2285 2286 2562 switch (update_goal_chain (goals)) 2287 2563 { 2288 case -1:2564 case us_none: 2289 2565 /* Nothing happened. */ 2290 case 0:2291 /* Updated successfully. */2292 status = makefile_status;2566 /* FALLTHROUGH */ 2567 case us_success: 2568 /* Keep the previous result. */ 2293 2569 break; 2294 case 1:2570 case us_question: 2295 2571 /* We are under -q and would run some commands. */ 2296 status = MAKE_TROUBLE;2572 makefile_status = MAKE_TROUBLE; 2297 2573 break; 2298 case 2: 2299 /* Updating failed. POSIX.2 specifies exit status >1 for this; 2300 but in VMS, there is only success and failure. */ 2301 status = MAKE_FAILURE; 2574 case us_failed: 2575 /* Updating failed. POSIX.2 specifies exit status >1 for this; */ 2576 makefile_status = MAKE_FAILURE; 2302 2577 break; 2303 default:2304 abort ();2305 2578 } 2306 2579 2307 2580 /* If we detected some clock skew, generate one last warning */ 2308 2581 if (clock_skew_detected) 2309 error (NILF,2310 2582 O (error, NILF, 2583 _("warning: Clock skew detected. Your build may be incomplete.")); 2311 2584 2312 2585 /* Exit. */ 2313 die ( status);2586 die (makefile_status); 2314 2587 } 2315 2588 2316 2589 /* NOTREACHED */ 2317 return 0;2590 exit (MAKE_SUCCESS); 2318 2591 } 2319 2592 … … 2323 2596 static char options[1 + sizeof (switches) / sizeof (switches[0]) * 3]; 2324 2597 static struct option long_options[(sizeof (switches) / sizeof (switches[0])) + 2325 2326 2598 (sizeof (long_option_aliases) / 2599 sizeof (long_option_aliases[0]))]; 2327 2600 2328 2601 /* Fill in the string and vector for getopt. */ … … 2347 2620 { 2348 2621 long_options[i].name = (switches[i].long_name == 0 ? "" : 2349 2622 switches[i].long_name); 2350 2623 long_options[i].flag = 0; 2351 2624 long_options[i].val = switches[i].c; 2352 2625 if (short_option (switches[i].c)) 2353 2626 *p++ = switches[i].c; 2354 2627 switch (switches[i].type) 2355 { 2356 case flag: 2357 case flag_off: 2358 case ignore: 2359 long_options[i].has_arg = no_argument; 2360 break; 2361 2362 case string: 2628 { 2629 case flag: 2630 case flag_off: 2631 case ignore: 2632 long_options[i].has_arg = no_argument; 2633 break; 2634 2635 case string: 2636 case strlist: 2363 2637 case filename: 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2638 case positive_int: 2639 case floating: 2640 if (short_option (switches[i].c)) 2641 *p++ = ':'; 2642 if (switches[i].noarg_value != 0) 2643 { 2644 if (short_option (switches[i].c)) 2645 *p++ = ':'; 2646 long_options[i].has_arg = optional_argument; 2647 } 2648 else 2649 long_options[i].has_arg = required_argument; 2650 break; 2651 } 2378 2652 } 2379 2653 *p = '\0'; 2380 2654 for (c = 0; c < (sizeof (long_option_aliases) / 2381 2655 sizeof (long_option_aliases[0])); 2382 2656 ++c) 2383 2657 long_options[i++] = long_option_aliases[c]; … … 2385 2659 } 2386 2660 2661 2662 /* Non-option argument. It might be a variable definition. */ 2387 2663 static void 2388 handle_non_switch_argument (c har *arg, int env)2664 handle_non_switch_argument (const char *arg, int env) 2389 2665 { 2390 /* Non-option argument. It might be a variable definition. */2391 2666 struct variable *v; 2667 2392 2668 if (arg[0] == '-' && arg[1] == '\0') 2393 /* Ignore plain `-' for compatibility. */2669 /* Ignore plain '-' for compatibility. */ 2394 2670 return; 2671 2672 #ifdef VMS 2673 { 2674 /* VMS DCL quoting can result in foo="bar baz" showing up here. 2675 Need to remove the double quotes from the value. */ 2676 char * eq_ptr; 2677 char * new_arg; 2678 eq_ptr = strchr (arg, '='); 2679 if ((eq_ptr != NULL) && (eq_ptr[1] == '"')) 2680 { 2681 int len; 2682 int seg1; 2683 int seg2; 2684 len = strlen(arg); 2685 new_arg = alloca(len); 2686 seg1 = eq_ptr - arg + 1; 2687 strncpy(new_arg, arg, (seg1)); 2688 seg2 = len - seg1 - 1; 2689 strncpy(&new_arg[seg1], &eq_ptr[2], seg2); 2690 new_arg[seg1 + seg2] = 0; 2691 if (new_arg[seg1 + seg2 - 1] == '"') 2692 new_arg[seg1 + seg2 - 1] = 0; 2693 arg = new_arg; 2694 } 2695 } 2696 #endif 2395 2697 v = try_variable_definition (0, arg, o_command, 0); 2396 2698 if (v != 0) 2397 2699 { 2398 2700 /* It is indeed a variable definition. If we don't already have this 2399 2400 2701 one, record a pointer to the variable for later use in 2702 define_makeflags. */ 2401 2703 struct command_variable *cv; 2402 2704 … … 2405 2707 break; 2406 2708 2407 if (! cv) { 2408 cv = xmalloc (sizeof (*cv)); 2409 cv->variable = v; 2410 cv->next = command_variables; 2411 command_variables = cv; 2412 } 2709 if (! cv) 2710 { 2711 cv = xmalloc (sizeof (*cv)); 2712 cv->variable = v; 2713 cv->next = command_variables; 2714 command_variables = cv; 2715 } 2413 2716 } 2414 2717 else if (! env) 2415 2718 { 2416 2719 /* Not an option or variable definition; it must be a goal 2417 2418 2720 target! Enter it as a file and add it to the dep chain of 2721 goals. */ 2419 2722 struct file *f = enter_file (strcache_add (expand_command_line_file (arg))); 2420 2723 f->cmd_target = 1; 2421 2724 2422 2725 if (goals == 0) 2423 2424 goals = alloc_dep ();2425 2426 2726 { 2727 goals = alloc_goaldep (); 2728 lastgoal = goals; 2729 } 2427 2730 else 2428 2429 lastgoal->next = alloc_dep ();2430 2431 2731 { 2732 lastgoal->next = alloc_goaldep (); 2733 lastgoal = lastgoal->next; 2734 } 2432 2735 2433 2736 lastgoal->file = f; … … 2491 2794 2492 2795 static void 2493 decode_switches (int argc, c har **argv, int env)2796 decode_switches (int argc, const char **argv, int env) 2494 2797 { 2495 2798 int bad = 0; … … 2511 2814 while (optind < argc) 2512 2815 { 2816 const char *coptarg; 2817 2513 2818 /* Parse the next argument. */ 2514 c = getopt_long (argc, argv, options, long_options, (int *) 0); 2819 c = getopt_long (argc, (char*const*)argv, options, long_options, NULL); 2820 coptarg = optarg; 2515 2821 if (c == EOF) 2516 2517 2822 /* End of arguments, or "--" marker seen. */ 2823 break; 2518 2824 else if (c == 1) 2519 2520 handle_non_switch_argument (optarg, env);2825 /* An argument not starting with a dash. */ 2826 handle_non_switch_argument (coptarg, env); 2521 2827 else if (c == '?') 2522 2523 2524 2525 2828 /* Bad option. We will print a usage message and die later. 2829 But continue to parse the other options so the user can 2830 see all he did wrong. */ 2831 bad = 1; 2526 2832 else 2527 for (cs = switches; cs->c != '\0'; ++cs) 2528 if (cs->c == c) 2529 { 2530 /* Whether or not we will actually do anything with 2531 this switch. We test this individually inside the 2532 switch below rather than just once outside it, so that 2533 options which are to be ignored still consume args. */ 2534 int doit = !env || cs->env; 2535 2536 switch (cs->type) 2537 { 2538 default: 2539 abort (); 2540 2541 case ignore: 2542 break; 2543 2544 case flag: 2545 case flag_off: 2546 if (doit) 2547 *(int *) cs->value_ptr = cs->type == flag; 2548 break; 2549 2550 case string: 2551 case filename: 2552 if (!doit) 2553 break; 2554 2555 if (optarg == 0) 2556 optarg = xstrdup (cs->noarg_value); 2557 else if (*optarg == '\0') 2833 for (cs = switches; cs->c != '\0'; ++cs) 2834 if (cs->c == c) 2835 { 2836 /* Whether or not we will actually do anything with 2837 this switch. We test this individually inside the 2838 switch below rather than just once outside it, so that 2839 options which are to be ignored still consume args. */ 2840 int doit = !env || cs->env; 2841 2842 switch (cs->type) 2843 { 2844 default: 2845 abort (); 2846 2847 case ignore: 2848 break; 2849 2850 case flag: 2851 case flag_off: 2852 if (doit) 2853 *(int *) cs->value_ptr = cs->type == flag; 2854 break; 2855 2856 case string: 2857 case strlist: 2858 case filename: 2859 if (!doit) 2860 break; 2861 2862 if (! coptarg) 2863 coptarg = xstrdup (cs->noarg_value); 2864 else if (*coptarg == '\0') 2558 2865 { 2559 2866 char opt[2] = "c"; … … 2565 2872 op = cs->long_name; 2566 2873 2567 error (NILF, _("the `%s%s' option requires a non-empty string argument"), 2874 error (NILF, strlen (op), 2875 _("the '%s%s' option requires a non-empty string argument"), 2568 2876 short_option (cs->c) ? "-" : "--", op); 2569 2877 bad = 1; 2878 break; 2570 2879 } 2571 2880 2572 sl = *(struct stringlist **) cs->value_ptr; 2573 if (sl == 0) 2574 { 2575 sl = (struct stringlist *) 2576 xmalloc (sizeof (struct stringlist)); 2577 sl->max = 5; 2578 sl->idx = 0; 2579 sl->list = xmalloc (5 * sizeof (char *)); 2580 *(struct stringlist **) cs->value_ptr = sl; 2581 } 2582 else if (sl->idx == sl->max - 1) 2583 { 2584 sl->max += 5; 2881 if (cs->type == string) 2882 { 2883 char **val = (char **)cs->value_ptr; 2884 free (*val); 2885 *val = xstrdup (coptarg); 2886 break; 2887 } 2888 2889 sl = *(struct stringlist **) cs->value_ptr; 2890 if (sl == 0) 2891 { 2892 sl = xmalloc (sizeof (struct stringlist)); 2893 sl->max = 5; 2894 sl->idx = 0; 2895 sl->list = xmalloc (5 * sizeof (char *)); 2896 *(struct stringlist **) cs->value_ptr = sl; 2897 } 2898 else if (sl->idx == sl->max - 1) 2899 { 2900 sl->max += 5; 2585 2901 /* MSVC erroneously warns without a cast here. */ 2586 2902 sl->list = xrealloc ((void *)sl->list, 2587 2903 sl->max * sizeof (char *)); 2588 2904 } 2589 2905 if (cs->type == filename) 2590 sl->list[sl->idx++] = expand_command_line_file ( optarg);2906 sl->list[sl->idx++] = expand_command_line_file (coptarg); 2591 2907 else 2592 sl->list[sl->idx++] = optarg;2593 2594 2595 2596 2908 sl->list[sl->idx++] = xstrdup (coptarg); 2909 sl->list[sl->idx] = 0; 2910 break; 2911 2912 case positive_int: 2597 2913 /* See if we have an option argument; if we do require that 2598 2914 it's all digits, not something like "10foo". */ 2599 if (optarg == 0 && argc > optind)2915 if (coptarg == 0 && argc > optind) 2600 2916 { 2601 2917 const char *cp; … … 2603 2919 ; 2604 2920 if (cp[0] == '\0') 2605 optarg = argv[optind++];2921 coptarg = argv[optind++]; 2606 2922 } 2607 2923 2608 2609 2610 2611 if (optarg != 0)2612 2613 int i = atoi (optarg);2924 if (!doit) 2925 break; 2926 2927 if (coptarg) 2928 { 2929 int i = atoi (coptarg); 2614 2930 const char *cp; 2615 2931 2616 2932 /* Yes, I realize we're repeating this in some cases. */ 2617 for (cp = optarg; ISDIGIT (cp[0]); ++cp)2933 for (cp = coptarg; ISDIGIT (cp[0]); ++cp) 2618 2934 ; 2619 2935 2620 if (i < 1 || cp[0] != '\0') 2621 { 2622 error (NILF, _("the `-%c' option requires a positive integral argument"), 2936 if (i < 1 || cp[0] != '\0') 2937 { 2938 error (NILF, 0, 2939 _("the '-%c' option requires a positive integer argument"), 2623 2940 cs->c); 2624 2625 2626 2627 2628 2629 2630 2631 2632 2941 bad = 1; 2942 } 2943 else 2944 *(unsigned int *) cs->value_ptr = i; 2945 } 2946 else 2947 *(unsigned int *) cs->value_ptr 2948 = *(unsigned int *) cs->noarg_value; 2949 break; 2633 2950 2634 2951 #ifndef NO_FLOAT 2635 2636 if (optarg == 0 && optind < argc2637 2638 2639 2640 2641 2642 = (optarg != 0 ? atof (optarg)2643 2644 2645 2646 #endif 2647 2648 2649 2650 2651 2952 case floating: 2953 if (coptarg == 0 && optind < argc 2954 && (ISDIGIT (argv[optind][0]) || argv[optind][0] == '.')) 2955 coptarg = argv[optind++]; 2956 2957 if (doit) 2958 *(double *) cs->value_ptr 2959 = (coptarg != 0 ? atof (coptarg) 2960 : *(double *) cs->noarg_value); 2961 2962 break; 2963 #endif 2964 } 2965 2966 /* We've found the switch. Stop looking. */ 2967 break; 2968 } 2652 2969 } 2653 2970 … … 2659 2976 handle_non_switch_argument (argv[optind++], env); 2660 2977 2661 2662 2978 if (!env && (bad || print_usage_flag)) 2663 2979 { 2664 2980 print_usage (bad); 2665 die (bad ? 2 : 0); 2666 } 2981 die (bad ? MAKE_FAILURE : MAKE_SUCCESS); 2982 } 2983 2984 /* If there are any options that need to be decoded do it now. */ 2985 decode_debug_flags (); 2986 decode_output_sync_flags (); 2667 2987 } 2668 2988 … … 2673 2993 2674 2994 static void 2675 decode_env_switches (c har *envar, unsigned int len)2995 decode_env_switches (const char *envar, unsigned int len) 2676 2996 { 2677 2997 char *varref = alloca (2 + len + 2); 2678 char *value, *p ;2998 char *value, *p, *buf; 2679 2999 int argc; 2680 c har **argv;3000 const char **argv; 2681 3001 2682 3002 /* Get the variable's value. */ … … 2689 3009 2690 3010 /* Skip whitespace, and check for an empty value. */ 2691 value = next_token(value);3011 NEXT_TOKEN (value); 2692 3012 len = strlen (value); 2693 3013 if (len == 0) … … 2696 3016 /* Allocate a vector that is definitely big enough. */ 2697 3017 argv = alloca ((1 + len + 1) * sizeof (char *)); 2698 2699 /* Allocate a buffer to copy the value into while we split it into words2700 and unquote it. We must use permanent storage for this because2701 decode_switches may store pointers into the passed argument words. */2702 p = xmalloc (2 * len);2703 3018 2704 3019 /* getopt will look at the arguments starting at ARGV[1]. … … 2706 3021 argv[0] = 0; 2707 3022 argc = 1; 3023 3024 /* We need a buffer to copy the value into while we split it into words 3025 and unquote it. Set up in case we need to prepend a dash later. */ 3026 buf = alloca (1 + len + 1); 3027 buf[0] = '-'; 3028 p = buf+1; 2708 3029 argv[argc] = p; 2709 3030 while (*value != '\0') 2710 3031 { 2711 3032 if (*value == '\\' && value[1] != '\0') 2712 ++value;/* Skip the backslash. */2713 else if ( isblank ((unsigned char)*value))2714 2715 2716 2717 2718 2719 2720 while (isblank ((unsigned char)*value));2721 2722 3033 ++value; /* Skip the backslash. */ 3034 else if (ISBLANK (*value)) 3035 { 3036 /* End of the word. */ 3037 *p++ = '\0'; 3038 argv[++argc] = p; 3039 do 3040 ++value; 3041 while (ISBLANK (*value)); 3042 continue; 3043 } 2723 3044 *p++ = *value++; 2724 3045 } 2725 3046 *p = '\0'; 2726 3047 argv[++argc] = 0; 3048 assert (p < buf + len + 2); 2727 3049 2728 3050 if (argv[1][0] != '-' && strchr (argv[1], '=') == 0) 2729 3051 /* The first word doesn't start with a dash and isn't a variable 2730 definition. Add a dash and pass it along to decode_switches. We 2731 need permanent storage for this in case decode_switches saves 2732 pointers into the value. */ 2733 argv[1] = xstrdup (concat (2, "-", argv[1])); 3052 definition, so add a dash. */ 3053 argv[1] = buf; 2734 3054 2735 3055 /* Parse those words. */ … … 2750 3070 { 2751 3071 if (*in == '$') 2752 2753 else if ( isblank ((unsigned char)*in) || *in == '\\')3072 *out++ = '$'; 3073 else if (ISBLANK (*in) || *in == '\\') 2754 3074 *out++ = '\\'; 2755 3075 *out++ = *in++; … … 2761 3081 /* Define the MAKEFLAGS and MFLAGS variables to reflect the settings of the 2762 3082 command switches. Include options with args if ALL is nonzero. 2763 Don't include options with the `no_makefile' flag set if MAKEFILE. */2764 2765 static const char*3083 Don't include options with the 'no_makefile' flag set if MAKEFILE. */ 3084 3085 static struct variable * 2766 3086 define_makeflags (int all, int makefile) 2767 3087 { … … 2771 3091 const struct command_switch *cs; 2772 3092 char *flagstring; 2773 register char *p; 2774 unsigned int words; 2775 struct variable *v; 2776 2777 /* We will construct a linked list of `struct flag's describing 3093 char *p; 3094 3095 /* We will construct a linked list of 'struct flag's describing 2778 3096 all the flags which need to go in MAKEFLAGS. Then, once we 2779 3097 know how many there are and their lengths, we can put them all … … 2787 3105 }; 2788 3106 struct flag *flags = 0; 3107 struct flag *last = 0; 2789 3108 unsigned int flagslen = 0; 2790 #define ADD_FLAG(ARG, LEN) \ 2791 do { \ 2792 struct flag *new = alloca (sizeof (struct flag)); \ 2793 new->cs = cs; \ 2794 new->arg = (ARG); \ 2795 new->next = flags; \ 2796 flags = new; \ 2797 if (new->arg == 0) \ 2798 ++flagslen; /* Just a single flag letter. */ \ 2799 else \ 2800 /* " -x foo", plus space to expand "foo". */ \ 2801 flagslen += 1 + 1 + 1 + 1 + (3 * (LEN)); \ 2802 if (!short_option (cs->c)) \ 3109 #define ADD_FLAG(ARG, LEN) \ 3110 do { \ 3111 struct flag *new = alloca (sizeof (struct flag)); \ 3112 new->cs = cs; \ 3113 new->arg = (ARG); \ 3114 new->next = 0; \ 3115 if (! flags) \ 3116 flags = new; \ 3117 else \ 3118 last->next = new; \ 3119 last = new; \ 3120 if (new->arg == 0) \ 3121 /* Just a single flag letter: " -x" */ \ 3122 flagslen += 3; \ 3123 else \ 3124 /* " -xfoo", plus space to escape "foo". */ \ 3125 flagslen += 1 + 1 + 1 + (3 * (LEN)); \ 3126 if (!short_option (cs->c)) \ 2803 3127 /* This switch has no single-letter version, so we use the long. */ \ 2804 flagslen += 2 + strlen (cs->long_name); 3128 flagslen += 2 + strlen (cs->long_name); \ 2805 3129 } while (0) 2806 3130 … … 2808 3132 if (cs->toenv && (!makefile || !cs->no_makefile)) 2809 3133 switch (cs->type) 2810 { 2811 case ignore: 2812 break; 2813 2814 case flag: 2815 case flag_off: 2816 if (!*(int *) cs->value_ptr == (cs->type == flag_off) 2817 && (cs->default_value == 0 2818 || *(int *) cs->value_ptr != *(int *) cs->default_value)) 2819 ADD_FLAG (0, 0); 2820 break; 2821 2822 case positive_int: 2823 if (all) 2824 { 2825 if ((cs->default_value != 0 2826 && (*(unsigned int *) cs->value_ptr 2827 == *(unsigned int *) cs->default_value))) 2828 break; 2829 else if (cs->noarg_value != 0 2830 && (*(unsigned int *) cs->value_ptr == 2831 *(unsigned int *) cs->noarg_value)) 2832 ADD_FLAG ("", 0); /* Optional value omitted; see below. */ 2833 else if (cs->c == 'j') 2834 /* Special case for `-j'. */ 2835 ADD_FLAG ("1", 1); 2836 else 2837 { 2838 char *buf = alloca (30); 2839 sprintf (buf, "%u", *(unsigned int *) cs->value_ptr); 2840 ADD_FLAG (buf, strlen (buf)); 2841 } 2842 } 2843 break; 3134 { 3135 case ignore: 3136 break; 3137 3138 case flag: 3139 case flag_off: 3140 if ((!*(int *) cs->value_ptr) == (cs->type == flag_off) 3141 && (cs->default_value == 0 3142 || *(int *) cs->value_ptr != *(int *) cs->default_value)) 3143 ADD_FLAG (0, 0); 3144 break; 3145 3146 case positive_int: 3147 if (all) 3148 { 3149 if ((cs->default_value != 0 3150 && (*(unsigned int *) cs->value_ptr 3151 == *(unsigned int *) cs->default_value))) 3152 break; 3153 else if (cs->noarg_value != 0 3154 && (*(unsigned int *) cs->value_ptr == 3155 *(unsigned int *) cs->noarg_value)) 3156 ADD_FLAG ("", 0); /* Optional value omitted; see below. */ 3157 else 3158 { 3159 char *buf = alloca (30); 3160 sprintf (buf, "%u", *(unsigned int *) cs->value_ptr); 3161 ADD_FLAG (buf, strlen (buf)); 3162 } 3163 } 3164 break; 2844 3165 2845 3166 #ifndef NO_FLOAT 2846 case floating: 2847 if (all) 2848 { 2849 if (cs->default_value != 0 2850 && (*(double *) cs->value_ptr 2851 == *(double *) cs->default_value)) 2852 break; 2853 else if (cs->noarg_value != 0 2854 && (*(double *) cs->value_ptr 2855 == *(double *) cs->noarg_value)) 2856 ADD_FLAG ("", 0); /* Optional value omitted; see below. */ 2857 else 2858 { 2859 char *buf = alloca (100); 2860 sprintf (buf, "%g", *(double *) cs->value_ptr); 2861 ADD_FLAG (buf, strlen (buf)); 2862 } 2863 } 2864 break; 2865 #endif 2866 2867 case filename: 2868 case string: 2869 if (all) 2870 { 2871 struct stringlist *sl = *(struct stringlist **) cs->value_ptr; 2872 if (sl != 0) 2873 { 2874 /* Add the elements in reverse order, because all the flags 2875 get reversed below; and the order matters for some 2876 switches (like -I). */ 2877 unsigned int i = sl->idx; 2878 while (i-- > 0) 2879 ADD_FLAG (sl->list[i], strlen (sl->list[i])); 2880 } 2881 } 2882 break; 2883 2884 default: 2885 abort (); 2886 } 2887 2888 /* Four more for the possible " -- ". */ 2889 flagslen += 4 + sizeof (posixref) + sizeof (evalref); 2890 2891 #undef ADD_FLAG 3167 case floating: 3168 if (all) 3169 { 3170 if (cs->default_value != 0 3171 && (*(double *) cs->value_ptr 3172 == *(double *) cs->default_value)) 3173 break; 3174 else if (cs->noarg_value != 0 3175 && (*(double *) cs->value_ptr 3176 == *(double *) cs->noarg_value)) 3177 ADD_FLAG ("", 0); /* Optional value omitted; see below. */ 3178 else 3179 { 3180 char *buf = alloca (100); 3181 sprintf (buf, "%g", *(double *) cs->value_ptr); 3182 ADD_FLAG (buf, strlen (buf)); 3183 } 3184 } 3185 break; 3186 #endif 3187 3188 case string: 3189 if (all) 3190 { 3191 p = *((char **)cs->value_ptr); 3192 if (p) 3193 ADD_FLAG (p, strlen (p)); 3194 } 3195 break; 3196 3197 case filename: 3198 case strlist: 3199 if (all) 3200 { 3201 struct stringlist *sl = *(struct stringlist **) cs->value_ptr; 3202 if (sl != 0) 3203 { 3204 unsigned int i; 3205 for (i = 0; i < sl->idx; ++i) 3206 ADD_FLAG (sl->list[i], strlen (sl->list[i])); 3207 } 3208 } 3209 break; 3210 3211 default: 3212 abort (); 3213 } 3214 3215 #undef ADD_FLAG 3216 3217 /* Four more for the possible " -- ", plus variable references. */ 3218 flagslen += 4 + CSTRLEN (posixref) + 1 + CSTRLEN (evalref) + 1; 2892 3219 2893 3220 /* Construct the value in FLAGSTRING. … … 2896 3223 memset (flagstring, '\0', 1 + flagslen + 1); 2897 3224 p = flagstring; 2898 words = 1; 3225 3226 /* Start with a dash, for MFLAGS. */ 2899 3227 *p++ = '-'; 2900 while (flags != 0) 2901 { 3228 3229 /* Add simple options as a group. */ 3230 while (flags != 0 && !flags->arg && short_option (flags->cs->c)) 3231 { 3232 *p++ = flags->cs->c; 3233 flags = flags->next; 3234 } 3235 3236 /* Now add more complex flags: ones with options and/or long names. */ 3237 while (flags) 3238 { 3239 *p++ = ' '; 3240 *p++ = '-'; 3241 2902 3242 /* Add the flag letter or name to the string. */ 2903 3243 if (short_option (flags->cs->c)) 2904 3244 *p++ = flags->cs->c; 2905 3245 else 2906 { 2907 if (*p != '-') 2908 { 2909 *p++ = ' '; 2910 *p++ = '-'; 2911 } 2912 *p++ = '-'; 2913 strcpy (p, flags->cs->long_name); 2914 p += strlen (p); 2915 } 2916 if (flags->arg != 0) 2917 { 2918 /* A flag that takes an optional argument which in this case is 2919 omitted is specified by ARG being "". We must distinguish 2920 because a following flag appended without an intervening " -" 2921 is considered the arg for the first. */ 2922 if (flags->arg[0] != '\0') 2923 { 2924 /* Add its argument too. */ 2925 *p++ = !short_option (flags->cs->c) ? '=' : ' '; 2926 p = quote_for_env (p, flags->arg); 2927 } 2928 ++words; 2929 /* Write a following space and dash, for the next flag. */ 2930 *p++ = ' '; 2931 *p++ = '-'; 2932 } 2933 else if (!short_option (flags->cs->c)) 2934 { 2935 ++words; 2936 /* Long options must each go in their own word, 2937 so we write the following space and dash. */ 2938 *p++ = ' '; 2939 *p++ = '-'; 2940 } 3246 { 3247 /* Long options require a double-dash. */ 3248 *p++ = '-'; 3249 strcpy (p, flags->cs->long_name); 3250 p += strlen (p); 3251 } 3252 /* An omitted optional argument has an ARG of "". */ 3253 if (flags->arg && flags->arg[0] != '\0') 3254 { 3255 if (!short_option (flags->cs->c)) 3256 /* Long options require '='. */ 3257 *p++ = '='; 3258 p = quote_for_env (p, flags->arg); 3259 } 2941 3260 flags = flags->next; 2942 3261 } 2943 3262 2944 /* Define MFLAGS before appending variable definitions. */ 2945 3263 /* If no flags at all, get rid of the initial dash. */ 2946 3264 if (p == &flagstring[1]) 2947 /* No flags. */ 2948 flagstring[0] = '\0'; 2949 else if (p[-1] == '-') 2950 { 2951 /* Kill the final space and dash. */ 2952 p -= 2; 2953 *p = '\0'; 2954 } 2955 else 2956 /* Terminate the string. */ 2957 *p = '\0'; 2958 2959 /* Since MFLAGS is not parsed for flags, there is no reason to 3265 { 3266 flagstring[0] = '\0'; 3267 p = flagstring; 3268 } 3269 3270 /* Define MFLAGS before appending variable definitions. Omit an initial 3271 empty dash. Since MFLAGS is not parsed for flags, there is no reason to 2960 3272 override any makefile redefinition. */ 2961 define_variable_cname ("MFLAGS", flagstring, o_env, 1); 3273 define_variable_cname ("MFLAGS", 3274 flagstring + (flagstring[0] == '-' && flagstring[1] == ' ' ? 2 : 0), 3275 o_env, 1); 2962 3276 2963 3277 /* Write a reference to -*-eval-flags-*-, which contains all the --eval … … 2965 3279 if (eval_strings) 2966 3280 { 2967 if (p == &flagstring[1]) 2968 /* No flags written, so elide the leading dash already written. */ 2969 p = flagstring; 2970 else 2971 *p++ = ' '; 2972 memcpy (p, evalref, sizeof (evalref) - 1); 2973 p += sizeof (evalref) - 1; 2974 } 2975 2976 if (all && command_variables != 0) 2977 { 2978 /* Now write a reference to $(MAKEOVERRIDES), which contains all the 2979 command-line variable definitions. */ 2980 2981 if (p == &flagstring[1]) 2982 /* No flags written, so elide the leading dash already written. */ 2983 p = flagstring; 2984 else 2985 { 2986 /* Separate the variables from the switches with a "--" arg. */ 2987 if (p[-1] != '-') 2988 { 2989 /* We did not already write a trailing " -". */ 2990 *p++ = ' '; 2991 *p++ = '-'; 2992 } 2993 /* There is a trailing " -"; fill it out to " -- ". */ 2994 *p++ = '-'; 2995 *p++ = ' '; 2996 } 3281 *p++ = ' '; 3282 memcpy (p, evalref, CSTRLEN (evalref)); 3283 p += CSTRLEN (evalref); 3284 } 3285 3286 if (all && command_variables) 3287 { 3288 /* Write a reference to $(MAKEOVERRIDES), which contains all the 3289 command-line variable definitions. Separate the variables from the 3290 switches with a "--" arg. */ 3291 3292 strcpy (p, " -- "); 3293 p += 4; 2997 3294 2998 3295 /* Copy in the string. */ 2999 3296 if (posix_pedantic) 3000 3001 memcpy (p, posixref, sizeof (posixref) - 1);3002 p += sizeof (posixref) - 1;3003 3297 { 3298 memcpy (p, posixref, CSTRLEN (posixref)); 3299 p += CSTRLEN (posixref); 3300 } 3004 3301 else 3005 { 3006 memcpy (p, ref, sizeof (ref) - 1); 3007 p += sizeof (ref) - 1; 3008 } 3009 } 3010 else if (p == &flagstring[1]) 3011 { 3012 words = 0; 3013 --p; 3014 } 3015 else if (p[-1] == '-') 3016 /* Kill the final space and dash. */ 3017 p -= 2; 3018 /* Terminate the string. */ 3019 *p = '\0'; 3020 3021 /* If there are switches, omit the leading dash unless it is a single long 3022 option with two leading dashes. */ 3023 if (flagstring[0] == '-' && flagstring[1] != '-') 3302 { 3303 memcpy (p, ref, CSTRLEN (ref)); 3304 p += CSTRLEN (ref); 3305 } 3306 } 3307 3308 /* If there is a leading dash, omit it. */ 3309 if (flagstring[0] == '-') 3024 3310 ++flagstring; 3025 3311 3026 v = define_variable_cname ("MAKEFLAGS", flagstring, 3027 /* This used to use o_env, but that lost when a 3028 makefile defined MAKEFLAGS. Makefiles set 3029 MAKEFLAGS to add switches, but we still want 3030 to redefine its value with the full set of 3031 switches. Of course, an override or command 3032 definition will still take precedence. */ 3033 o_file, 1); 3034 3035 if (! all) 3036 /* The first time we are called, set MAKEFLAGS to always be exported. 3037 We should not do this again on the second call, because that is 3038 after reading makefiles which might have done `unexport MAKEFLAGS'. */ 3039 v->export = v_export; 3040 3041 return v->value; 3312 /* This used to use o_env, but that lost when a makefile defined MAKEFLAGS. 3313 Makefiles set MAKEFLAGS to add switches, but we still want to redefine 3314 its value with the full set of switches. Then we used o_file, but that 3315 lost when users added -e, causing a previous MAKEFLAGS env. var. to take 3316 precedence over the new one. Of course, an override or command 3317 definition will still take precedence. */ 3318 return define_variable_cname ("MAKEFLAGS", flagstring, 3319 env_overrides ? o_env_override : o_file, 1); 3042 3320 } 3043 3321 … … 3050 3328 static int printed_version = 0; 3051 3329 3052 c har *precede = print_data_base_flag ? "# " : "";3330 const char *precede = print_data_base_flag ? "# " : ""; 3053 3331 3054 3332 if (printed_version) … … 3067 3345 (C) to the copyright symbol, but this string is going to change every 3068 3346 year, and none of the rest of it should be translated (including the 3069 word "Copyright", so it hardly seems worth it. */ 3070 3071 printf ("%sCopyright (C) 2010 Free Software Foundation, Inc.\n", precede); 3347 word "Copyright"), so it hardly seems worth it. */ 3348 3349 printf ("%sCopyright (C) 1988-2016 Free Software Foundation, Inc.\n", 3350 precede); 3072 3351 3073 3352 printf (_("%sLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\ … … 3079 3358 3080 3359 /* Flush stdout so the user doesn't have to wait to see the 3081 version information while things are thought about. */3360 version information while make thinks about things. */ 3082 3361 fflush (stdout); 3083 3362 } … … 3086 3365 3087 3366 static void 3088 print_data_base ( )3367 print_data_base (void) 3089 3368 { 3090 time_t when; 3091 3092 when = time ((time_t *) 0); 3369 time_t when = time ((time_t *) 0); 3370 3371 print_version (); 3372 3093 3373 printf (_("\n# Make data base, printed on %s"), ctime (&when)); 3094 3374 … … 3107 3387 clean_jobserver (int status) 3108 3388 { 3109 char token = '+';3110 3111 3389 /* Sanity: have we written all our jobserver tokens back? If our 3112 3390 exit status is 2 that means some kind of syntax error; we might not … … 3114 3392 after any other error code, that's bad. */ 3115 3393 3116 if (job _fds[0] != -1&& jobserver_tokens)3394 if (jobserver_enabled() && jobserver_tokens) 3117 3395 { 3118 3396 if (status != 2) 3119 error (NILF,3120 3121 3397 ON (error, NILF, 3398 "INTERNAL: Exiting with %u jobserver tokens (should be 0)!", 3399 jobserver_tokens); 3122 3400 else 3123 while (jobserver_tokens--) 3124 { 3125 int r; 3126 3127 EINTRLOOP (r, write (job_fds[1], &token, 1)); 3128 if (r != 1) 3129 perror_with_name ("write", ""); 3130 } 3401 /* Don't write back the "free" token */ 3402 while (--jobserver_tokens) 3403 jobserver_release (0); 3131 3404 } 3132 3405 … … 3137 3410 { 3138 3411 /* We didn't write one for ourself, so start at 1. */ 3139 unsigned int tcnt = 1; 3140 3141 /* Close the write side, so the read() won't hang. */ 3142 close (job_fds[1]); 3143 3144 while (read (job_fds[0], &token, 1) == 1) 3145 ++tcnt; 3146 3147 if (tcnt != master_job_slots) 3148 error (NILF, 3149 "INTERNAL: Exiting with %u jobserver tokens available; should be %u!", 3150 tcnt, master_job_slots); 3151 3152 close (job_fds[0]); 3153 3154 /* Clean out jobserver_fds so we don't pass this information to any 3155 sub-makes. Also reset job_slots since it will be put on the command 3156 line, not in MAKEFLAGS. */ 3157 job_slots = default_job_slots; 3158 if (jobserver_fds) 3159 { 3160 /* MSVC erroneously warns without a cast here. */ 3161 free ((void *)jobserver_fds->list); 3162 free (jobserver_fds); 3163 jobserver_fds = 0; 3164 } 3412 unsigned int tokens = 1 + jobserver_acquire_all (); 3413 3414 if (tokens != master_job_slots) 3415 ONN (error, NILF, 3416 "INTERNAL: Exiting with %u jobserver tokens available; should be %u!", 3417 tokens, master_job_slots); 3418 3419 reset_jobserver (); 3165 3420 } 3166 3421 } … … 3181 3436 3182 3437 if (print_version_flag) 3183 3438 print_version (); 3184 3439 3185 3440 /* Wait for children to die. */ 3186 3441 err = (status != 0); 3187 3442 while (job_slots_used > 0) 3188 3443 reap_children (1, err); 3189 3444 3190 3445 /* Let the remote job module clean up its state. */ … … 3195 3450 3196 3451 if (print_data_base_flag) 3197 print_data_base (); 3198 3199 verify_file_data_base (); 3452 print_data_base (); 3453 3454 if (verify_flag) 3455 verify_file_data_base (); 3200 3456 3201 3457 clean_jobserver (status); 3202 3458 3459 if (output_context) 3460 { 3461 /* die() might be called in a recipe output context due to an 3462 $(error ...) function. */ 3463 output_close (output_context); 3464 3465 if (output_context != &make_sync) 3466 output_close (&make_sync); 3467 3468 OUTPUT_UNSET (); 3469 } 3470 3471 output_close (NULL); 3472 3203 3473 /* Try to move back to the original directory. This is essential on 3204 3205 3206 3474 MS-DOS (where there is really only one process), and on Unix it 3475 puts core files in the original directory instead of the -C 3476 directory. Must wait until after remove_intermediates(), or unlinks 3207 3477 of relative pathnames fail. */ 3208 3478 if (directory_before_chdir != 0) 3209 3479 { 3210 3480 /* If it fails we don't care: shut up GCC. */ 3211 int _x ;3481 int _x UNUSED; 3212 3482 _x = chdir (directory_before_chdir); 3213 3483 } 3214 3215 log_working_directory (0);3216 3484 } 3217 3485 3218 3486 exit (status); 3219 3487 } 3220 3221 3222 /* Write a message indicating that we've just entered or3223 left (according to ENTERING) the current directory. */3224 3225 void3226 log_working_directory (int entering)3227 {3228 static int entered = 0;3229 3230 /* Print nothing without the flag. Don't print the entering message3231 again if we already have. Don't print the leaving message if we3232 haven't printed the entering message. */3233 if (! print_directory_flag || entering == entered)3234 return;3235 3236 entered = entering;3237 3238 if (print_data_base_flag)3239 fputs ("# ", stdout);3240 3241 /* Use entire sentences to give the translators a fighting chance. */3242 3243 if (makelevel == 0)3244 if (starting_directory == 0)3245 if (entering)3246 printf (_("%s: Entering an unknown directory\n"), program);3247 else3248 printf (_("%s: Leaving an unknown directory\n"), program);3249 else3250 if (entering)3251 printf (_("%s: Entering directory `%s'\n"),3252 program, starting_directory);3253 else3254 printf (_("%s: Leaving directory `%s'\n"),3255 program, starting_directory);3256 else3257 if (starting_directory == 0)3258 if (entering)3259 printf (_("%s[%u]: Entering an unknown directory\n"),3260 program, makelevel);3261 else3262 printf (_("%s[%u]: Leaving an unknown directory\n"),3263 program, makelevel);3264 else3265 if (entering)3266 printf (_("%s[%u]: Entering directory `%s'\n"),3267 program, makelevel, starting_directory);3268 else3269 printf (_("%s[%u]: Leaving directory `%s'\n"),3270 program, makelevel, starting_directory);3271 3272 /* Flush stdout to be sure this comes before any stderr output. */3273 fflush (stdout);3274 }
Note:
See TracChangeset
for help on using the changeset viewer.