- Timestamp:
- May 16, 2005 11:34:55 PM (20 years ago)
- Location:
- trunk/src/gmake
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/Makefile.kmk
r278 r287 13 13 kmk_DEFS = \ 14 14 HAVE_CONFIG_H \ 15 NO_ARCHIVES \ 15 16 CONFIG_NO_DEFAULT_SUFFIXES \ 16 17 CONFIG_NO_DEFAULT_PATTERN_RULES \ … … 111 112 # 112 113 $(PATH_TARGET)/config.h: config.h.$(BUILD_TARGET) 114 $(MKDIR) -p $(dir $@) 113 115 $(CP) $^ $@ 114 116 -
trunk/src/gmake/commands.c
r225 r287 40 40 /* Set FILE's automatic variables up. */ 41 41 42 staticvoid42 void 43 43 set_file_variables (struct file *file) 44 44 { 45 struct dep *d; 45 46 char *at, *percent, *star, *less; 46 47 … … 107 108 star = file->stem; 108 109 109 /* $< is the first dependency. */ 110 less = file->deps != 0 ? dep_name (file->deps) : ""; 110 /* $< is the first not order-only dependency. */ 111 less = ""; 112 for (d = file->deps; d != 0; d = d->next) 113 if (!d->ignore_mtime) 114 { 115 less = dep_name (d); 116 break; 117 } 111 118 112 119 if (file->cmds == default_file->cmds) … … 136 143 char *qp; 137 144 char *bp; 138 struct dep *d;139 145 unsigned int len; 140 146 … … 343 349 break; 344 350 } 345 if (!(flags & COMMANDS_RECURSE)) 346 { 347 unsigned int len = strlen (p); 348 if (sindex (p, len, "$(MAKE)", 7) != 0 349 || sindex (p, len, "${MAKE}", 7) != 0) 350 flags |= COMMANDS_RECURSE; 351 } 351 352 /* If no explicit '+' was given, look for MAKE variable references. */ 353 if (!(flags & COMMANDS_RECURSE) 354 && (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0)) 355 flags |= COMMANDS_RECURSE; 356 352 357 #ifdef CONFIG_WITH_KMK_BUILTIN 358 /* check if kmk builtin command */ 353 359 if (!strncmp(p, "kmk_builtin_", sizeof("kmk_builtin_") - 1)) 354 360 flags |= COMMANDS_BUILTIN; 355 361 #endif 356 362 … … 486 492 #endif 487 493 494 #ifdef WINDOWS32 495 /* Cannot call W32_kill with a pid (it needs a handle) */ 496 exit (EXIT_FAILURE); 497 #else 488 498 /* Signal the same code; this time it will really be fatal. The signal 489 499 will be unblocked when we return and arrive then to kill us. */ 490 500 if (kill (getpid (), sig) < 0) 491 501 pfatal_with_name ("kill"); 502 #endif /* not WINDOWS32 */ 492 503 #endif /* not Amiga */ 493 504 #endif /* not __MSDOS__ */ -
trunk/src/gmake/commands.h
r225 r287 43 43 extern void delete_child_targets PARAMS ((struct child *child)); 44 44 extern void chop_commands PARAMS ((struct commands *cmds)); 45 extern void set_file_variables PARAMS ((struct file *file)); -
trunk/src/gmake/default.c
r192 r287 318 318 #ifdef __ALPHA 319 319 "ARCH", "ALPHA", 320 #else 320 #endif 321 #ifdef __ia64 322 "ARCH", "IA64", 323 #endif 324 #ifdef __VAX 321 325 "ARCH", "VAX", 322 326 #endif -
trunk/src/gmake/dir.c
r57 r287 124 124 downcase (char *filename) 125 125 { 126 #ifdef _AMIGA 127 static char new_filename[136]; 128 #else 129 static char new_filename[PATH_MAX]; 130 #endif 126 static PATH_VAR (new_filename); 131 127 char *df; 132 128 int i; … … 1142 1138 d = (struct dirent *) buf; 1143 1139 #ifdef __MINGW32__ 1144 # if __MINGW32_ VERSION_MAJOR < 3 || (__MINGW32_VERSION_MAJOR== 3 && \1145 __MINGW32_ VERSION_MINOR== 0)1140 # if __MINGW32_MAJOR_VERSION < 3 || (__MINGW32_MAJOR_VERSION == 3 && \ 1141 __MINGW32_MINOR_VERSION == 0) 1146 1142 d->d_name = xmalloc(len); 1147 1143 # endif … … 1163 1159 1164 1160 static void 1165 ansi_free (void *p)1166 { 1167 1168 1161 ansi_free (void *p) 1162 { 1163 if (p) 1164 free(p); 1169 1165 } 1170 1166 -
trunk/src/gmake/file.c
r218 r287 31 31 #include "hash.h" 32 32 33 34 /* Remember whether snap_deps has been invoked: we need this to be sure we 35 don't add new rules (via $(eval ...)) afterwards. In the future it would 36 be nice to support this, but it means we'd need to re-run snap_deps() or 37 at least its functionality... it might mean changing snap_deps() to be run 38 per-file, so we can invoke it after the eval... or remembering which files 39 in the hash have been snapped (a new boolean flag?) and having snap_deps() 40 only work on files which have not yet been snapped. */ 41 int snapped_deps = 0; 33 42 34 43 /* Hash table of files the makefile knows how to make. */ … … 345 354 { 346 355 register struct file *f = *file_slot; 356 /* Is this file eligible for automatic deletion? 357 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't 358 given on the command-line, and it's either a -include makefile or 359 it's not precious. */ 347 360 if (f->intermediate && (f->dontcare || !f->precious) 348 361 && !f->secondary && !f->cmd_target) … … 405 418 } 406 419 420 /* Expand and parse each dependency line. */ 421 static void 422 expand_deps (struct file *f) 423 { 424 struct dep *d, *d1; 425 struct dep *new = 0; 426 struct dep *old = f->deps; 427 unsigned int last_dep_has_cmds = f->updating; 428 int initialized = 0; 429 430 f->updating = 0; 431 f->deps = 0; 432 433 for (d = old; d != 0; d = d->next) 434 { 435 if (d->name != 0) 436 { 437 char *p; 438 439 /* If we need a second expansion on these, set up the file 440 variables, etc. It takes a lot of extra memory and processing 441 to do this, so only do it if it's needed. */ 442 if (! d->need_2nd_expansion) 443 p = d->name; 444 else 445 { 446 /* We are going to do second expansion so initialize file 447 variables for the file. */ 448 if (!initialized) 449 { 450 initialize_file_variables (f, 0); 451 initialized = 1; 452 } 453 454 set_file_variables (f); 455 456 p = variable_expand_for_file (d->name, f); 457 } 458 459 /* Parse the dependencies. */ 460 new = (struct dep *) 461 multi_glob ( 462 parse_file_seq (&p, '|', sizeof (struct dep), 1), 463 sizeof (struct dep)); 464 465 if (*p) 466 { 467 /* Files that follow '|' are special prerequisites that 468 need only exist in order to satisfy the dependency. 469 Their modification times are irrelevant. */ 470 struct dep **d_ptr; 471 472 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next) 473 ; 474 ++p; 475 476 *d_ptr = (struct dep *) 477 multi_glob ( 478 parse_file_seq (&p, '\0', sizeof (struct dep), 1), 479 sizeof (struct dep)); 480 481 for (d1 = *d_ptr; d1 != 0; d1 = d1->next) 482 d1->ignore_mtime = 1; 483 } 484 485 /* Enter them as files. */ 486 for (d1 = new; d1 != 0; d1 = d1->next) 487 { 488 d1->file = lookup_file (d1->name); 489 if (d1->file == 0) 490 d1->file = enter_file (d1->name); 491 else 492 free (d1->name); 493 d1->name = 0; 494 d1->need_2nd_expansion = 0; 495 } 496 497 /* Add newly parsed deps to f->deps. If this is the last 498 dependency line and this target has commands then put 499 it in front so the last dependency line (the one with 500 commands) ends up being the first. This is important 501 because people expect $< to hold first prerequisite 502 from the rule with commands. If it is not the last 503 dependency line or the rule does not have commands 504 then link it at the end so it appears in makefile 505 order. */ 506 507 if (new != 0) 508 { 509 if (d->next == 0 && last_dep_has_cmds) 510 { 511 struct dep **d_ptr; 512 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next) 513 ; 514 515 *d_ptr = f->deps; 516 f->deps = new; 517 } 518 else 519 { 520 struct dep **d_ptr; 521 for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next) 522 ; 523 524 *d_ptr = new; 525 } 526 } 527 } 528 } 529 530 free_ns_chain ((struct nameseq *) old); 531 } 532 407 533 /* For each dependency of each file, make the `struct dep' point 408 534 at the appropriate `struct file' (which may have to be created). … … 414 540 snap_deps (void) 415 541 { 416 register struct file *f; 417 register struct file *f2; 418 register struct dep *d; 419 register struct file **file_slot_0; 420 register struct file **file_slot; 421 register struct file **file_end; 422 423 /* Enter each dependency name as a file. */ 542 struct file *f; 543 struct file *f2; 544 struct dep *d; 545 struct file **file_slot_0; 546 struct file **file_slot; 547 struct file **file_end; 548 549 /* Perform second expansion and enter each dependency 550 name as a file. */ 551 552 /* Expand .SUFFIXES first; it's dependencies are used for 553 $$* calculation. */ 554 for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev) 555 expand_deps (f); 556 424 557 /* We must use hash_dump (), because within this loop 425 558 we might add new files to the table, possibly causing … … 428 561 file_end = file_slot_0 + files.ht_fill; 429 562 for (file_slot = file_slot_0; file_slot < file_end; file_slot++) 430 for (f2 = *file_slot; f2 != 0; f2 = f2->prev) 431 for (d = f2->deps; d != 0; d = d->next) 432 if (d->name != 0) 433 { 434 d->file = lookup_file (d->name); 435 if (d->file == 0) 436 d->file = enter_file (d->name); 437 else 438 free (d->name); 439 d->name = 0; 440 } 563 for (f = *file_slot; f != 0; f = f->prev) 564 { 565 if (strcmp (f->name, ".SUFFIXES") != 0) 566 expand_deps (f); 567 } 441 568 free (file_slot_0); 442 569 … … 455 582 for (f2 = d->file; f2 != 0; f2 = f2->prev) 456 583 { 457 /* Mark this file as phony and nonexistent. */584 /* Mark this file as phony nonexistent target. */ 458 585 f2->phony = 1; 586 f2->is_target = 1; 459 587 f2->last_mtime = NONEXISTENT_MTIME; 460 588 f2->mtime_before_update = NONEXISTENT_MTIME; … … 537 665 } 538 666 667 /* Remember that we've done this. */ 668 snapped_deps = 1; 539 669 } 540 670 … … 699 829 puts (_("# Command-line target.")); 700 830 if (f->dontcare) 701 puts (_("# A default or MAKEFILESmakefile."));831 puts (_("# A default, MAKEFILES, or -include/sinclude makefile.")); 702 832 puts (f->tried_implicit 703 833 ? _("# Implicit rule search has been done.") -
trunk/src/gmake/function.c
r160 r287 74 74 the length of SUBST and RLEN is the length of REPLACE. If BY_WORD is 75 75 nonzero, substitutions are done only on matches which are complete 76 whitespace-delimited words. If SUFFIX_ONLY is nonzero, substitutions are 77 done only at the ends of whitespace-delimited words. */ 76 whitespace-delimited words. */ 78 77 79 78 char * 80 79 subst_expand (char *o, char *text, char *subst, char *replace, 81 unsigned int slen, unsigned int rlen, 82 int by_word, int suffix_only) 80 unsigned int slen, unsigned int rlen, int by_word) 83 81 { 84 82 char *t = text; 85 unsigned int tlen = strlen (text);86 83 char *p; 87 84 88 if (slen == 0 && !by_word && !suffix_only)85 if (slen == 0 && !by_word) 89 86 { 90 87 /* The first occurrence of "" in any string is its end. */ 91 o = variable_buffer_output (o, t, tlen);88 o = variable_buffer_output (o, t, strlen (t)); 92 89 if (rlen > 0) 93 90 o = variable_buffer_output (o, replace, rlen); … … 97 94 do 98 95 { 99 if ( (by_word | suffix_only)&& slen == 0)96 if (by_word && slen == 0) 100 97 /* When matching by words, the empty string should match 101 98 the end of each word, rather than the end of the whole text. */ … … 103 100 else 104 101 { 105 p = s index (t, tlen, subst, slen);102 p = strstr (t, subst); 106 103 if (p == 0) 107 104 { 108 105 /* No more matches. Output everything left on the end. */ 109 o = variable_buffer_output (o, t, tlen);106 o = variable_buffer_output (o, t, strlen (t)); 110 107 return o; 111 108 } … … 118 115 /* If we're substituting only by fully matched words, 119 116 or only at the ends of words, check that this case qualifies. */ 120 if ((by_word 121 && ((p > t && !isblank ((unsigned char)p[-1])) 122 || (p[slen] != '\0' && !isblank ((unsigned char)p[slen])))) 123 || (suffix_only 124 && (p[slen] != '\0' && !isblank ((unsigned char)p[slen])))) 117 if (by_word 118 && ((p > text && !isblank ((unsigned char)p[-1])) 119 || (p[slen] != '\0' && !isblank ((unsigned char)p[slen])))) 125 120 /* Struck out. Output the rest of the string that is 126 121 no longer to be replaced. */ … … 130 125 o = variable_buffer_output (o, replace, rlen); 131 126 132 /* Advance T past the string to be replaced ; adjust tlen. */127 /* Advance T past the string to be replaced. */ 133 128 { 134 129 char *nt = p + slen; 135 tlen -= nt - t;136 130 t = nt; 137 131 } … … 140 134 return o; 141 135 } 136 142 137 143 138 … … 147 142 run through find_percent, and PATTERN_PERCENT is the result. 148 143 If REPLACE_PERCENT is not nil, REPLACE has already been 149 run through find_percent, and REPLACE_PERCENT is the result. */ 144 run through find_percent, and REPLACE_PERCENT is the result. 145 Note that we expect PATTERN_PERCENT and REPLACE_PERCENT to point to the 146 character _AFTER_ the %, not to the % itself. 147 */ 150 148 151 149 char * … … 154 152 { 155 153 unsigned int pattern_prepercent_len, pattern_postpercent_len; 156 unsigned int replace_prepercent_len, replace_postpercent_len = 0;154 unsigned int replace_prepercent_len, replace_postpercent_len; 157 155 char *t; 158 156 unsigned int len; … … 161 159 /* We call find_percent on REPLACE before checking PATTERN so that REPLACE 162 160 will be collapsed before we call subst_expand if PATTERN has no %. */ 163 if (replace_percent == 0) 164 replace_percent = find_percent (replace); 165 if (replace_percent != 0) 166 { 167 /* Record the length of REPLACE before and after the % so 168 we don't have to compute these lengths more than once. */ 169 replace_prepercent_len = replace_percent - replace; 170 replace_postpercent_len = strlen (replace_percent + 1); 161 if (!replace_percent) 162 { 163 replace_percent = find_percent (replace); 164 if (replace_percent) 165 ++replace_percent; 166 } 167 168 /* Record the length of REPLACE before and after the % so we don't have to 169 compute these lengths more than once. */ 170 if (replace_percent) 171 { 172 replace_prepercent_len = replace_percent - replace - 1; 173 replace_postpercent_len = strlen (replace_percent); 171 174 } 172 175 else 173 /* We store the length of the replacement 174 so we only need to compute it once. */ 175 replace_prepercent_len = strlen (replace); 176 177 if (pattern_percent == 0) 178 pattern_percent = find_percent (pattern); 179 if (pattern_percent == 0) 176 { 177 replace_prepercent_len = strlen (replace); 178 replace_postpercent_len = 0; 179 } 180 181 if (!pattern_percent) 182 { 183 pattern_percent = find_percent (pattern); 184 if (pattern_percent) 185 ++pattern_percent; 186 } 187 if (!pattern_percent) 180 188 /* With no % in the pattern, this is just a simple substitution. */ 181 189 return subst_expand (o, text, pattern, replace, 182 strlen (pattern), strlen (replace), 1 , 0);190 strlen (pattern), strlen (replace), 1); 183 191 184 192 /* Record the length of PATTERN before and after the % 185 193 so we don't have to compute it more than once. */ 186 pattern_prepercent_len = pattern_percent - pattern ;187 pattern_postpercent_len = strlen (pattern_percent + 1);194 pattern_prepercent_len = pattern_percent - pattern - 1; 195 pattern_postpercent_len = strlen (pattern_percent); 188 196 189 197 while ((t = find_next_token (&text, &len)) != 0) … … 198 206 if (!fail && pattern_prepercent_len > 0 199 207 && (*t != *pattern 200 || t[pattern_prepercent_len - 1] != pattern_percent[- 1]208 || t[pattern_prepercent_len - 1] != pattern_percent[-2] 201 209 || !strneq (t + 1, pattern + 1, pattern_prepercent_len - 1))) 202 210 fail = 1; … … 204 212 /* Does the suffix match? */ 205 213 if (!fail && pattern_postpercent_len > 0 206 && (t[len - 1] != pattern_percent[pattern_postpercent_len ]207 || t[len - pattern_postpercent_len] != pattern_percent[1]214 && (t[len - 1] != pattern_percent[pattern_postpercent_len - 1] 215 || t[len - pattern_postpercent_len] != *pattern_percent 208 216 || !strneq (&t[len - pattern_postpercent_len], 209 &pattern_percent[1], pattern_postpercent_len - 1)))217 pattern_percent, pattern_postpercent_len - 1))) 210 218 fail = 1; 211 219 … … 228 236 + pattern_postpercent_len)); 229 237 /* Output the part of the replacement after the %. */ 230 o = variable_buffer_output (o, replace_percent + 1,238 o = variable_buffer_output (o, replace_percent, 231 239 replace_postpercent_len); 232 240 } … … 648 656 { 649 657 o = subst_expand (o, argv[2], argv[0], argv[1], strlen (argv[0]), 650 strlen (argv[1]), 0 , 0);658 strlen (argv[1]), 0); 651 659 652 660 return o; … … 667 675 } 668 676 677 static char * 678 func_lastword (char *o, char **argv, const char *funcname UNUSED) 679 { 680 unsigned int i; 681 char *words = argv[0]; /* Use a temp variable for find_next_token */ 682 char *p = 0; 683 char *t; 684 685 while ((t = find_next_token (&words, &i))) 686 p = t; 687 688 if (p != 0) 689 o = variable_buffer_output (o, p, i); 690 691 return o; 692 } 669 693 670 694 static char * … … 690 714 * begpp-1. 691 715 */ 692 staticchar *716 char * 693 717 strip_whitespace (const char **begpp, const char **endpp) 694 718 { … … 755 779 756 780 start = atoi (argv[0]); 781 if (start < 1) 782 fatal (reading_file, 783 "invalid first argument to `wordlist' function: `%d'", start); 784 757 785 count = atoi (argv[1]) - start + 1; 758 786 … … 784 812 { 785 813 /* Find the first occurrence of the first string in the second. */ 786 int i = strlen (argv[0]); 787 if (sindex (argv[1], 0, argv[0], i) != 0) 788 o = variable_buffer_output (o, argv[0], i); 814 if (strstr (argv[1], argv[0]) != 0) 815 o = variable_buffer_output (o, argv[0], strlen (argv[0])); 789 816 790 817 return o; … … 1067 1094 strcpy (p, *argvp); 1068 1095 1069 if (*funcname == 'e') 1070 fatal (reading_file, "%s", msg); 1096 switch (*funcname) { 1097 case 'e': 1098 fatal (reading_file, "%s", msg); 1099 1100 case 'w': 1101 error (reading_file, "%s", msg); 1102 break; 1103 1104 case 'i': 1105 printf ("%s\n", msg); 1106 break; 1107 1108 default: 1109 fatal (reading_file, "Internal error: func_error: '%s'", funcname); 1110 } 1071 1111 1072 1112 /* The warning function expands to the empty string. */ 1073 error (reading_file, "%s", msg);1074 1075 1113 return o; 1076 1114 } … … 1457 1495 1458 1496 /* For error messages. */ 1459 if (reading_file != 0)1497 if (reading_file && reading_file->filenm) 1460 1498 { 1461 1499 error_prefix = (char *) alloca (strlen (reading_file->filenm)+11+4); … … 1700 1738 */ 1701 1739 static char * 1702 func_eq (char *o, char **argv, char *funcname)1740 func_eq (char *o, char **argv, char *funcname) 1703 1741 { 1704 1742 int result = ! strcmp (argv[0], argv[1]); … … 1712 1750 */ 1713 1751 static char * 1714 func_not (char *o, char **argv, char *funcname)1715 { 1716 char * 1752 func_not (char *o, char **argv, char *funcname) 1753 { 1754 char *s = argv[0]; 1717 1755 int result = 0; 1718 1756 while (isspace ((unsigned char)*s)) … … 1726 1764 1727 1765 1766 /* Return the absolute name of file NAME which does not contain any `.', 1767 `..' components nor any repeated path separators ('/'). */ 1768 1769 static char * 1770 abspath (const char *name, char *apath) 1771 { 1772 char *dest; 1773 const char *start, *end, *apath_limit; 1774 1775 if (name[0] == '\0' || apath == NULL) 1776 return NULL; 1777 1778 apath_limit = apath + GET_PATH_MAX; 1779 1780 if (name[0] != '/') 1781 { 1782 /* It is unlikely we would make it until here but just to make sure. */ 1783 if (!starting_directory) 1784 return NULL; 1785 1786 strcpy (apath, starting_directory); 1787 1788 dest = strchr (apath, '\0'); 1789 } 1790 else 1791 { 1792 apath[0] = '/'; 1793 dest = apath + 1; 1794 } 1795 1796 for (start = end = name; *start != '\0'; start = end) 1797 { 1798 unsigned long len; 1799 1800 /* Skip sequence of multiple path-separators. */ 1801 while (*start == '/') 1802 ++start; 1803 1804 /* Find end of path component. */ 1805 for (end = start; *end != '\0' && *end != '/'; ++end) 1806 ; 1807 1808 len = end - start; 1809 1810 if (len == 0) 1811 break; 1812 else if (len == 1 && start[0] == '.') 1813 /* nothing */; 1814 else if (len == 2 && start[0] == '.' && start[1] == '.') 1815 { 1816 /* Back up to previous component, ignore if at root already. */ 1817 if (dest > apath + 1) 1818 while ((--dest)[-1] != '/'); 1819 } 1820 else 1821 { 1822 if (dest[-1] != '/') 1823 *dest++ = '/'; 1824 1825 if (dest + len >= apath_limit) 1826 return NULL; 1827 1828 dest = memcpy (dest, start, len); 1829 dest += len; 1830 *dest = '\0'; 1831 } 1832 } 1833 1834 /* Unless it is root strip trailing separator. */ 1835 if (dest > apath + 1 && dest[-1] == '/') 1836 --dest; 1837 1838 *dest = '\0'; 1839 1840 return apath; 1841 } 1842 1843 1844 static char * 1845 func_realpath (char *o, char **argv, const char *funcname UNUSED) 1846 { 1847 /* Expand the argument. */ 1848 char *p = argv[0]; 1849 char *path = 0; 1850 int doneany = 0; 1851 unsigned int len = 0; 1852 PATH_VAR (in); 1853 PATH_VAR (out); 1854 1855 while ((path = find_next_token (&p, &len)) != 0) 1856 { 1857 if (len < GET_PATH_MAX) 1858 { 1859 strncpy (in, path, len); 1860 in[len] = '\0'; 1861 1862 if 1863 ( 1864 #ifdef HAVE_REALPATH 1865 realpath (in, out) 1866 #else 1867 abspath (in, out) 1868 #endif 1869 ) 1870 { 1871 o = variable_buffer_output (o, out, strlen (out)); 1872 o = variable_buffer_output (o, " ", 1); 1873 doneany = 1; 1874 } 1875 } 1876 } 1877 1878 /* Kill last space. */ 1879 if (doneany) 1880 --o; 1881 1882 return o; 1883 } 1884 1885 static char * 1886 func_abspath (char *o, char **argv, const char *funcname UNUSED) 1887 { 1888 /* Expand the argument. */ 1889 char *p = argv[0]; 1890 char *path = 0; 1891 int doneany = 0; 1892 unsigned int len = 0; 1893 PATH_VAR (in); 1894 PATH_VAR (out); 1895 1896 while ((path = find_next_token (&p, &len)) != 0) 1897 { 1898 if (len < GET_PATH_MAX) 1899 { 1900 strncpy (in, path, len); 1901 in[len] = '\0'; 1902 1903 if (abspath (in, out)) 1904 { 1905 o = variable_buffer_output (o, out, strlen (out)); 1906 o = variable_buffer_output (o, " ", 1); 1907 doneany = 1; 1908 } 1909 } 1910 } 1911 1912 /* Kill last space. */ 1913 if (doneany) 1914 --o; 1915 1916 return o; 1917 } 1918 1728 1919 /* Lookup table for builtin functions. 1729 1920 … … 1744 1935 { 1745 1936 /* Name/size */ /* MIN MAX EXP? Function */ 1937 { STRING_SIZE_TUPLE("abspath"), 0, 1, 1, func_abspath}, 1746 1938 { STRING_SIZE_TUPLE("addprefix"), 2, 2, 1, func_addsuffix_addprefix}, 1747 1939 { STRING_SIZE_TUPLE("addsuffix"), 2, 2, 1, func_addsuffix_addprefix}, … … 1756 1948 { STRING_SIZE_TUPLE("firstword"), 0, 1, 1, func_firstword}, 1757 1949 { STRING_SIZE_TUPLE("join"), 2, 2, 1, func_join}, 1950 { STRING_SIZE_TUPLE("lastword"), 0, 1, 1, func_lastword}, 1758 1951 { STRING_SIZE_TUPLE("patsubst"), 3, 3, 1, func_patsubst}, 1952 { STRING_SIZE_TUPLE("realpath"), 0, 1, 1, func_realpath}, 1759 1953 { STRING_SIZE_TUPLE("shell"), 0, 1, 1, func_shell}, 1760 1954 { STRING_SIZE_TUPLE("sort"), 0, 1, 1, func_sort}, … … 1767 1961 { STRING_SIZE_TUPLE("foreach"), 3, 3, 0, func_foreach}, 1768 1962 { STRING_SIZE_TUPLE("call"), 1, 0, 1, func_call}, 1963 { STRING_SIZE_TUPLE("info"), 0, 1, 1, func_error}, 1769 1964 { STRING_SIZE_TUPLE("error"), 0, 1, 1, func_error}, 1770 1965 { STRING_SIZE_TUPLE("warning"), 0, 1, 1, func_error}, -
trunk/src/gmake/hash.h
r53 r287 83 83 /* hash and comparison macros for case-sensitive string keys. */ 84 84 85 #if 0 85 86 #define STRING_HASH_1(KEY, RESULT) do { \ 86 87 unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ … … 88 89 (RESULT) += (*_key_ << (_key_[1] & 0xf)); \ 89 90 } while (0) 91 #else 92 #define STRING_HASH_1(KEY, RESULT) do { \ 93 unsigned char const *_key_ = (unsigned char const *) (KEY); \ 94 unsigned int _ch_ = *_key_; \ 95 while (_ch_) \ 96 { \ 97 unsigned char _ch2_ = *++_key_; \ 98 (RESULT) += (_ch_ << (_ch2_ & 0xf)); \ 99 _ch_ = _ch2_; \ 100 } \ 101 } while (0) 102 #endif 90 103 #define return_STRING_HASH_1(KEY) do { \ 91 104 unsigned long _result_ = 0; \ … … 94 107 } while (0) 95 108 109 #if 0 96 110 #define STRING_HASH_2(KEY, RESULT) do { \ 97 111 unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ … … 99 113 (RESULT) += (*_key_ << (_key_[1] & 0x7)); \ 100 114 } while (0) 115 #else 116 #define STRING_HASH_2(KEY, RESULT) do { \ 117 unsigned char const *_key_ = (unsigned char const *) (KEY); \ 118 unsigned int _ch_ = *_key_; \ 119 while (_ch_) \ 120 { \ 121 unsigned char _ch2_ = *++_key_; \ 122 (RESULT) += (_ch_ << (_ch2_ & 0x7)); \ 123 _ch_ = _ch2_; \ 124 } \ 125 } while (0) 126 #endif 101 127 #define return_STRING_HASH_2(KEY) do { \ 102 128 unsigned long _result_ = 0; \ … … 112 138 } while (0) 113 139 114 115 #define STRING_N_HASH_1(KEY, N, RESULT) do { \140 #if 0 141 #define _STRING_N_HASH_1(KEY, N, RESULT) do { \ 116 142 unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ 117 143 int _n_ = (N); \ … … 121 147 (RESULT) += *++_key_; \ 122 148 } while (0) 149 #else 150 #define STRING_N_HASH_1(KEY, N, RESULT) do { \ 151 unsigned char const *_key_ = (unsigned char const *) (KEY); \ 152 unsigned int _ch_ = *_key_; \ 153 int _n_ = (N); \ 154 if (_n_) \ 155 { \ 156 for (;;) \ 157 { \ 158 unsigned char _ch2_; \ 159 if (!--_n_) \ 160 { \ 161 (RESULT) += _ch_; \ 162 break; \ 163 } \ 164 _ch2_ = *++_key_; \ 165 (RESULT) += (_ch_ << (_ch2_ & 0xf)); \ 166 _ch_ = _ch2_; \ 167 if (!_ch_) break; \ 168 } \ 169 } \ 170 else \ 171 (RESULT) += _ch_; \ 172 } while (0) 173 #endif 123 174 #define return_STRING_N_HASH_1(KEY, N) do { \ 124 175 unsigned long _result_ = 0; \ … … 127 178 } while (0) 128 179 180 #if 0 129 181 #define STRING_N_HASH_2(KEY, N, RESULT) do { \ 130 182 unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ … … 135 187 (RESULT) += *++_key_; \ 136 188 } while (0) 189 #else 190 #define STRING_N_HASH_2(KEY, N, RESULT) do { \ 191 unsigned char const *_key_ = (unsigned char const *) (KEY); \ 192 unsigned int _ch_ = *_key_; \ 193 int _n_ = (N); \ 194 if (_n_) \ 195 { \ 196 for (;;) \ 197 { \ 198 unsigned char _ch2_; \ 199 if (!--_n_) \ 200 { \ 201 (RESULT) += _ch_; \ 202 break; \ 203 } \ 204 _ch2_ = *++_key_; \ 205 (RESULT) += (_ch_ << (_ch2_ & 0x7)); \ 206 _ch_ = _ch2_; \ 207 if (!_ch_) break; \ 208 } \ 209 } \ 210 else \ 211 (RESULT) += _ch_; \ 212 } while (0) 213 #endif 137 214 #define return_STRING_N_HASH_2(KEY, N) do { \ 138 215 unsigned long _result_ = 0; \ … … 152 229 /* hash and comparison macros for case-insensitive string _key_s. */ 153 230 231 #if 1 /* testme */ 154 232 #define ISTRING_HASH_1(KEY, RESULT) do { \ 155 233 unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ … … 157 235 (RESULT) += ((isupper (*_key_) ? tolower (*_key_) : *_key_) << (_key_[1] & 0xf)); \ 158 236 } while (0) 237 #else 238 #define ISTRING_HASH_1(KEY, RESULT) do { \ 239 unsigned char const *_key_ = (unsigned char const *) (KEY); \ 240 unsigned int _ch_ = *_key_; 241 while (_ch_) \ 242 { \ 243 unsigned _ch2_ = *++_key_; \ 244 (RESULT) += ((isupper (_ch_) ? tolower (_ch_) : _ch_) << (_ch2_ & 0xf)); \ 245 _ch_ = _ch2_; \ 246 } \ 247 } while (0) 248 #endif 159 249 #define return_ISTRING_HASH_1(KEY) do { \ 160 250 unsigned long _result_ = 0; \ … … 163 253 } while (0) 164 254 255 #if 1 /* testme */ 165 256 #define ISTRING_HASH_2(KEY, RESULT) do { \ 166 257 unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \ … … 168 259 (RESULT) += ((isupper (*_key_) ? tolower (*_key_) : *_key_) << (_key_[1] & 0x7)); \ 169 260 } while (0) 261 #else 262 #define ISTRING_HASH_2(KEY, RESULT) do { \ 263 unsigned char const *_key_ = (unsigned char const *) (KEY); \ 264 unsigned int _ch_ = *_key_; 265 while (_ch_) \ 266 { \ 267 unsigned _ch2_ = *++_key_; \ 268 (RESULT) += ((isupper (_ch_) ? tolower (_ch_) : _ch_) << (_ch2_ & 0x7)); \ 269 _ch_ = _ch2_; \ 270 } \ 271 } while (0) 272 #endif 170 273 #define return_ISTRING_HASH_2(KEY) do { \ 171 274 unsigned long _result_ = 0; \ -
trunk/src/gmake/job.c
r232 r287 1 1 /* Job execution and handling for GNU Make. 2 Copyright (C) 1988,89,90,91,92,93,94,95,96,97,99 Free Software Foundation, Inc. 2 Copyright (C) 1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1999, 3 2000,2001,2002,2003,2004,2005 Free Software Foundation, Inc. 3 4 This file is part of GNU Make. 4 5 … … 69 70 70 71 # include <descrip.h> 72 char default_shell[] = ""; 73 int batch_mode_shell = 0; 74 75 #elif defined (__riscos__) 76 71 77 char default_shell[] = ""; 72 78 int batch_mode_shell = 0; … … 176 182 #endif /* Don't have `union wait'. */ 177 183 178 #ifdef VMS179 static int vms_jobsefnmask = 0;180 #endif /* !VMS */181 182 184 #ifndef HAVE_UNISTD_H 183 185 extern int dup2 (); … … 207 209 static int job_next_command PARAMS ((struct child *)); 208 210 static int start_waiting_job PARAMS ((struct child *)); 209 #ifdef VMS210 static void vmsWaitForChildren PARAMS ((int *));211 #endif212 211 #ifdef MAKE_DLLSHELL 213 212 static int spawn_command PARAMS ((char **argv, char **envp, struct child *child)); … … 239 238 unsigned long job_counter = 0; 240 239 240 /* Number of jobserver tokens this instance is currently using. */ 241 242 unsigned int jobserver_tokens = 0; 241 243 242 244 … … 248 250 w32_kill(int pid, int sig) 249 251 { 250 return ((process_kill(pid, sig) == TRUE) ? 0 : -1); 252 return ((process_kill((HANDLE)pid, sig) == TRUE) ? 0 : -1); 253 } 254 255 /* This function creates a temporary file name with the given extension 256 * the unixy param controls both the extension and the path separator 257 * return an xmalloc'ed string of a newly created temp file or die. */ 258 static char * 259 create_batch_filename(char const *base, int unixy) 260 { 261 const char *const ext = unixy ? "sh" : "bat"; 262 const char *error = NULL; 263 char temp_path[MAXPATHLEN]; /* need to know its length */ 264 unsigned path_size = GetTempPath(sizeof temp_path, temp_path); 265 int path_is_dot = 0; 266 unsigned uniq = 1; 267 const unsigned sizemax = strlen (base) + strlen (ext) + 10; 268 269 if (path_size == 0) 270 { 271 path_size = GetCurrentDirectory (sizeof temp_path, temp_path); 272 path_is_dot = 1; 273 } 274 275 while (path_size > 0 && 276 path_size + sizemax < sizeof temp_path && 277 uniq < 0x10000) 278 { 279 unsigned size = sprintf (temp_path + path_size, 280 "%s%s-%x.%s", 281 temp_path[path_size - 1] == '\\' ? "" : "\\", 282 base, uniq, ext); 283 HANDLE h = CreateFile (temp_path, /* file name */ 284 GENERIC_READ | GENERIC_WRITE, /* desired access */ 285 0, /* no share mode */ 286 NULL, /* default security attributes */ 287 CREATE_NEW, /* creation disposition */ 288 FILE_ATTRIBUTE_NORMAL | /* flags and attributes */ 289 FILE_ATTRIBUTE_TEMPORARY, /* we'll delete it */ 290 NULL); /* no template file */ 291 292 if (h == INVALID_HANDLE_VALUE) 293 { 294 const DWORD er = GetLastError(); 295 296 if (er == ERROR_FILE_EXISTS || er == ERROR_ALREADY_EXISTS) 297 ++uniq; 298 299 /* the temporary path is not guaranteed to exist */ 300 else if (path_is_dot == 0) 301 { 302 path_size = GetCurrentDirectory (sizeof temp_path, temp_path); 303 path_is_dot = 1; 304 } 305 306 else 307 { 308 error = map_windows32_error_to_string (er); 309 break; 310 } 311 } 312 else 313 { 314 const unsigned final_size = path_size + size + 1; 315 char *const path = (char *) xmalloc (final_size); 316 memcpy (path, temp_path, final_size); 317 CloseHandle (h); 318 if (unixy) 319 { 320 char *p; 321 int ch; 322 for (p = path; (ch = *p) != 0; ++p) 323 if (ch == '\\') 324 *p = '/'; 325 } 326 return path; /* good return */ 327 } 328 } 329 330 if (error == NULL) 331 error = _("Cannot create a temporary file\n"); 332 fatal (NILF, error); 333 334 /* not reached */ 335 return NULL; 251 336 } 252 337 #endif /* WINDOWS32 */ … … 328 413 329 414 330 #ifdef VMS331 /* Wait for nchildren children to terminate */332 static void333 vmsWaitForChildren(int *status)334 {335 while (1)336 {337 if (!vms_jobsefnmask)338 {339 *status = 0;340 return;341 }342 343 *status = sys$wflor (32, vms_jobsefnmask);344 }345 return;346 }347 348 /* Set up IO redirection. */349 350 char *351 vms_redirect (struct dsc$descriptor_s *desc, char *fname, char *ibuf)352 {353 char *fptr;354 extern char *vmsify ();355 356 ibuf++;357 while (isspace ((unsigned char)*ibuf))358 ibuf++;359 fptr = ibuf;360 while (*ibuf && !isspace ((unsigned char)*ibuf))361 ibuf++;362 *ibuf = 0;363 if (strcmp (fptr, "/dev/null") != 0)364 {365 strcpy (fname, vmsify (fptr, 0));366 if (strchr (fname, '.') == 0)367 strcat (fname, ".");368 }369 desc->dsc$w_length = strlen(fname);370 desc->dsc$a_pointer = fname;371 desc->dsc$b_dtype = DSC$K_DTYPE_T;372 desc->dsc$b_class = DSC$K_CLASS_S;373 374 if (*fname == 0)375 printf (_("Warning: Empty redirection\n"));376 return ibuf;377 }378 379 380 /* found apostrophe at (p-1)381 inc p until after closing apostrophe.382 */383 384 static char *385 vms_handle_apos (char *p)386 {387 int alast;388 389 #define SEPCHARS ",/()= "390 391 alast = 0;392 393 while (*p != 0)394 {395 if (*p == '"')396 {397 if (alast)398 {399 alast = 0;400 p++;401 }402 else403 {404 p++;405 if (strchr (SEPCHARS, *p))406 break;407 alast = 1;408 }409 }410 else411 p++;412 }413 414 return p;415 }416 417 #endif418 419 415 420 416 /* Handle a dead child. This handler may or may not ever be installed. … … 485 481 { 486 482 int remote = 0; 487 register int pid;483 pid_t pid; 488 484 int exit_code, exit_sig, coredump; 489 485 register struct child *lastc, *c; … … 569 565 { 570 566 #ifdef VMS 567 static void vmsWaitForChildren PARAMS ((int *)); 571 568 vmsWaitForChildren (&status); 572 569 pid = c->pid; … … 644 641 HANDLE hPID; 645 642 int err; 643 exit_code = 0; 644 exit_sig = 0; 645 coredump = 0; 646 646 647 647 /* wait for anything to finish */ 648 if (hPID = process_wait_for_any()) { 649 650 /* was an error found on this process? */ 651 err = process_last_err(hPID); 652 653 /* get exit data */ 654 exit_code = process_exit_code(hPID); 655 656 if (err) 657 fprintf(stderr, "make (e=%d): %s", 658 exit_code, map_windows32_error_to_string(exit_code)); 659 660 /* signal */ 661 exit_sig = process_signal(hPID); 662 663 /* cleanup process */ 664 process_cleanup(hPID); 665 666 coredump = 0; 667 } 668 pid = (int) hPID; 648 hPID = process_wait_for_any(); 649 if (hPID) 650 { 651 652 /* was an error found on this process? */ 653 err = process_last_err(hPID); 654 655 /* get exit data */ 656 exit_code = process_exit_code(hPID); 657 658 if (err) 659 fprintf(stderr, "make (e=%d): %s", 660 exit_code, map_windows32_error_to_string(exit_code)); 661 662 /* signal */ 663 exit_sig = process_signal(hPID); 664 665 /* cleanup process */ 666 process_cleanup(hPID); 667 668 coredump = 0; 669 } 670 pid = (pid_t) hPID; 669 671 } 670 672 #endif /* WINDOWS32 */ … … 840 842 free_child (struct child *child) 841 843 { 842 /* If this child is the only one it was our "free" job, so don't put a 843 token back for it. This child has already been removed from the list, 844 so if there any left this wasn't the last one. */ 845 846 if (job_fds[1] >= 0 && children) 844 if (!jobserver_tokens) 845 fatal (NILF, "INTERNAL: Freeing child 0x%08lx (%s) but no tokens left!\n", 846 (unsigned long int) child, child->file->name); 847 848 /* If we're using the jobserver and this child is not the only outstanding 849 job, put a token back into the pipe for it. */ 850 851 if (job_fds[1] >= 0 && jobserver_tokens > 1) 847 852 { 848 853 char token = '+'; … … 858 863 (unsigned long int) child, child->file->name)); 859 864 } 865 866 --jobserver_tokens; 860 867 861 868 if (handling_fatal_signal) /* Don't bother free'ing if about to die. */ … … 898 905 } 899 906 900 #ifdef 907 #ifdef POSIX 901 908 void 902 909 unblock_sigs (void) … … 909 916 910 917 #ifdef MAKE_JOBSERVER 918 RETSIGTYPE 919 job_noop (int sig UNUSED) 920 { 921 } 911 922 /* Set the child handler action flags to FLAGS. */ 912 923 static void 913 set_child_handler_action_flags (int flags)924 set_child_handler_action_flags (int set_handler, int set_alarm) 914 925 { 915 926 struct sigaction sa; 927 928 #ifdef __EMX__ 929 /* The child handler must be turned off here. */ 930 signal (SIGCHLD, SIG_DFL); 931 #endif 932 916 933 bzero ((char *) &sa, sizeof sa); 917 934 sa.sa_handler = child_handler; 918 sa.sa_flags = flags;935 sa.sa_flags = set_handler ? 0 : SA_RESTART; 919 936 #if defined SIGCHLD 920 937 sigaction (SIGCHLD, &sa, NULL); … … 922 939 #if defined SIGCLD && SIGCLD != SIGCHLD 923 940 sigaction (SIGCLD, &sa, NULL); 941 #endif 942 #if defined SIGALRM 943 if (set_alarm) 944 { 945 /* If we're about to enter the read(), set an alarm to wake up in a 946 second so we can check if the load has dropped and we can start more 947 work. On the way out, turn off the alarm and set SIG_DFL. */ 948 alarm (set_handler ? 1 : 0); 949 sa.sa_handler = set_handler ? job_noop : SIG_DFL; 950 sa.sa_flags = 0; 951 sigaction (SIGALRM, &sa, NULL); 952 } 924 953 #endif 925 954 } … … 1226 1255 1227 1256 #ifdef VMS 1228 1229 1257 if (!child_execute_job (argv, child)) { 1230 1258 /* Fork failed! */ … … 1670 1698 1671 1699 /* If we don't already have a job started, use our "free" token. */ 1672 if (! children)1700 if (!jobserver_tokens) 1673 1701 break; 1674 1702 … … 1705 1733 reap_children (0, 0); 1706 1734 1707 /* If our "free" token has become available, use it. */ 1735 /* Kick off any jobs we have waiting for an opportunity that 1736 can run now (ie waiting for load). */ 1737 start_waiting_jobs (); 1738 1739 /* If our "free" slot has become available, use it; we don't need an 1740 actual token. */ 1741 if (!jobserver_tokens) 1742 break; 1743 1744 /* There must be at least one child already, or we have no business 1745 waiting for a token. */ 1708 1746 if (!children) 1709 break;1747 fatal (NILF, "INTERNAL: no children as we go to sleep on read\n"); 1710 1748 1711 1749 /* Set interruptible system calls, and read() for a job token. */ 1712 set_child_handler_action_flags ( 0);1750 set_child_handler_action_flags (1, waiting_jobs != NULL); 1713 1751 got_token = read (job_rfd, &token, 1); 1714 1752 saved_errno = errno; 1715 #if defined(__EMX__) && !defined(__INNOTEK_LIBC__) 1716 /* The child handler must be turned off here. */ 1717 signal (SIGCHLD, SIG_DFL); 1718 #endif 1719 set_child_handler_action_flags (SA_RESTART); 1753 set_child_handler_action_flags (0, waiting_jobs != NULL); 1720 1754 1721 1755 /* If we got one, we're done here. */ … … 1736 1770 } 1737 1771 #endif 1772 1773 ++jobserver_tokens; 1738 1774 1739 1775 /* The job is now primed. Start it running. … … 1816 1852 load_too_high (void) 1817 1853 { 1818 #if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) 1854 #if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) || defined(__riscos__) 1819 1855 return 1; 1820 1856 #else … … 1900 1936 1901 1937 #ifndef WINDOWS32 1902 #ifdef VMS1903 #include <descrip.h>1904 #include <clidef.h>1905 1906 /* This is called as an AST when a child process dies (it won't get1907 interrupted by anything except a higher level AST).1908 */1909 int vmsHandleChildTerm(struct child *child)1910 {1911 int status;1912 register struct child *lastc, *c;1913 int child_failed;1914 1915 vms_jobsefnmask &= ~(1 << (child->efn - 32));1916 1917 lib$free_ef(&child->efn);1918 1919 (void) sigblock (fatal_signal_mask);1920 1921 child_failed = !(child->cstatus & 1 || ((child->cstatus & 7) == 0));1922 1923 /* Search for a child matching the deceased one. */1924 lastc = 0;1925 #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */1926 for (c = children; c != 0 && c != child; lastc = c, c = c->next);1927 #else1928 c = child;1929 #endif1930 1931 if (child_failed && !c->noerror && !ignore_errors_flag)1932 {1933 /* The commands failed. Write an error message,1934 delete non-precious targets, and abort. */1935 child_error (c->file->name, c->cstatus, 0, 0, 0);1936 c->file->update_status = 1;1937 delete_child_targets (c);1938 }1939 else1940 {1941 if (child_failed)1942 {1943 /* The commands failed, but we don't care. */1944 child_error (c->file->name, c->cstatus, 0, 0, 1);1945 child_failed = 0;1946 }1947 1948 #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */1949 /* If there are more commands to run, try to start them. */1950 start_job (c);1951 1952 switch (c->file->command_state)1953 {1954 case cs_running:1955 /* Successfully started. */1956 break;1957 1958 case cs_finished:1959 if (c->file->update_status != 0) {1960 /* We failed to start the commands. */1961 delete_child_targets (c);1962 }1963 break;1964 1965 default:1966 error (NILF, _("internal error: `%s' command_state"),1967 c->file->name);1968 abort ();1969 break;1970 }1971 #endif /* RECURSIVEJOBS */1972 }1973 1974 /* Set the state flag to say the commands have finished. */1975 c->file->command_state = cs_finished;1976 notice_finished_file (c->file);1977 1978 #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */1979 /* Remove the child from the chain and free it. */1980 if (lastc == 0)1981 children = c->next;1982 else1983 lastc->next = c->next;1984 free_child (c);1985 #endif /* RECURSIVEJOBS */1986 1987 /* There is now another slot open. */1988 if (job_slots_used > 0)1989 --job_slots_used;1990 1991 /* If the job failed, and the -k flag was not given, die. */1992 if (child_failed && !keep_going_flag)1993 die (EXIT_FAILURE);1994 1995 (void) sigsetmask (sigblock (0) & ~(fatal_signal_mask));1996 1997 return 1;1998 }1999 2000 /* VMS:2001 Spawn a process executing the command in ARGV and return its pid. */2002 2003 #define MAXCMDLEN 2002004 2005 /* local helpers to make ctrl+c and ctrl+y working, see below */2006 #include <iodef.h>2007 #include <libclidef.h>2008 #include <ssdef.h>2009 2010 static int ctrlMask= LIB$M_CLI_CTRLY;2011 static int oldCtrlMask;2012 static int setupYAstTried= 0;2013 static int pidToAbort= 0;2014 static int chan= 0;2015 2016 static void reEnableAst(void) {2017 lib$enable_ctrl (&oldCtrlMask,0);2018 }2019 2020 static astHandler (void) {2021 if (pidToAbort) {2022 sys$forcex (&pidToAbort, 0, SS$_ABORT);2023 pidToAbort= 0;2024 }2025 kill (getpid(),SIGQUIT);2026 }2027 2028 static void tryToSetupYAst(void) {2029 $DESCRIPTOR(inputDsc,"SYS$COMMAND");2030 int status;2031 struct {2032 short int status, count;2033 int dvi;2034 } iosb;2035 2036 setupYAstTried++;2037 2038 if (!chan) {2039 status= sys$assign(&inputDsc,&chan,0,0);2040 if (!(status&SS$_NORMAL)) {2041 lib$signal(status);2042 return;2043 }2044 }2045 status= sys$qiow (0, chan, IO$_SETMODE|IO$M_CTRLYAST,&iosb,0,0,2046 astHandler,0,0,0,0,0);2047 if (status==SS$_ILLIOFUNC) {2048 sys$dassgn(chan);2049 #ifdef CTRLY_ENABLED_ANYWAY2050 fprintf (stderr,2051 _("-warning, CTRL-Y will leave sub-process(es) around.\n"));2052 #else2053 return;2054 #endif2055 }2056 if (status==SS$_NORMAL)2057 status= iosb.status;2058 if (!(status&SS$_NORMAL)) {2059 lib$signal(status);2060 return;2061 }2062 2063 /* called from AST handler ? */2064 if (setupYAstTried>1)2065 return;2066 if (atexit(reEnableAst))2067 fprintf (stderr,2068 _("-warning, you may have to re-enable CTRL-Y handling from DCL.\n"));2069 status= lib$disable_ctrl (&ctrlMask, &oldCtrlMask);2070 if (!(status&SS$_NORMAL)) {2071 lib$signal(status);2072 return;2073 }2074 }2075 int2076 child_execute_job (char *argv, struct child *child)2077 {2078 int i;2079 static struct dsc$descriptor_s cmddsc;2080 static struct dsc$descriptor_s pnamedsc;2081 static struct dsc$descriptor_s ifiledsc;2082 static struct dsc$descriptor_s ofiledsc;2083 static struct dsc$descriptor_s efiledsc;2084 int have_redirection = 0;2085 int have_newline = 0;2086 2087 int spflags = CLI$M_NOWAIT;2088 int status;2089 char *cmd = alloca (strlen (argv) + 512), *p, *q;2090 char ifile[256], ofile[256], efile[256];2091 char *comname = 0;2092 char procname[100];2093 2094 /* Parse IO redirection. */2095 2096 ifile[0] = 0;2097 ofile[0] = 0;2098 efile[0] = 0;2099 2100 DB (DB_JOBS, ("child_execute_job (%s)\n", argv));2101 2102 while (isspace ((unsigned char)*argv))2103 argv++;2104 2105 if (*argv == 0)2106 return 0;2107 2108 sprintf (procname, "GMAKE_%05x", getpid () & 0xfffff);2109 pnamedsc.dsc$w_length = strlen(procname);2110 pnamedsc.dsc$a_pointer = procname;2111 pnamedsc.dsc$b_dtype = DSC$K_DTYPE_T;2112 pnamedsc.dsc$b_class = DSC$K_CLASS_S;2113 2114 /* Handle comments and redirection. */2115 for (p = argv, q = cmd; *p; p++, q++)2116 {2117 switch (*p)2118 {2119 case '#':2120 *p-- = 0;2121 *q-- = 0;2122 break;2123 case '\\':2124 p++;2125 if (*p == '\n')2126 p++;2127 if (isspace ((unsigned char)*p))2128 {2129 do { p++; } while (isspace ((unsigned char)*p));2130 p--;2131 }2132 *q = *p;2133 break;2134 case '<':2135 p = vms_redirect (&ifiledsc, ifile, p);2136 *q = ' ';2137 have_redirection = 1;2138 break;2139 case '>':2140 have_redirection = 1;2141 if (*(p-1) == '2')2142 {2143 q--;2144 if (strncmp (p, ">&1", 3) == 0)2145 {2146 p += 3;2147 strcpy (efile, "sys$output");2148 efiledsc.dsc$w_length = strlen(efile);2149 efiledsc.dsc$a_pointer = efile;2150 efiledsc.dsc$b_dtype = DSC$K_DTYPE_T;2151 efiledsc.dsc$b_class = DSC$K_CLASS_S;2152 }2153 else2154 {2155 p = vms_redirect (&efiledsc, efile, p);2156 }2157 }2158 else2159 {2160 p = vms_redirect (&ofiledsc, ofile, p);2161 }2162 *q = ' ';2163 break;2164 case '\n':2165 have_newline = 1;2166 default:2167 *q = *p;2168 break;2169 }2170 }2171 *q = *p;2172 2173 if (strncmp (cmd, "builtin_", 8) == 0)2174 {2175 child->pid = 270163;2176 child->efn = 0;2177 child->cstatus = 1;2178 2179 DB (DB_JOBS, (_("BUILTIN [%s][%s]\n"), cmd, cmd+8));2180 2181 p = cmd + 8;2182 2183 if ((*(p) == 'c')2184 && (*(p+1) == 'd')2185 && ((*(p+2) == ' ') || (*(p+2) == '\t')))2186 {2187 p += 3;2188 while ((*p == ' ') || (*p == '\t'))2189 p++;2190 DB (DB_JOBS, (_("BUILTIN CD %s\n"), p));2191 if (chdir (p))2192 return 0;2193 else2194 return 1;2195 }2196 else if ((*(p) == 'r')2197 && (*(p+1) == 'm')2198 && ((*(p+2) == ' ') || (*(p+2) == '\t')))2199 {2200 int in_arg;2201 2202 /* rm */2203 p += 3;2204 while ((*p == ' ') || (*p == '\t'))2205 p++;2206 in_arg = 1;2207 2208 DB (DB_JOBS, (_("BUILTIN RM %s\n"), p));2209 while (*p)2210 {2211 switch (*p)2212 {2213 case ' ':2214 case '\t':2215 if (in_arg)2216 {2217 *p++ = ';';2218 in_arg = 0;2219 }2220 break;2221 default:2222 break;2223 }2224 p++;2225 }2226 }2227 else2228 {2229 printf(_("Unknown builtin command '%s'\n"), cmd);2230 fflush(stdout);2231 return 0;2232 }2233 }2234 2235 /* Create a *.com file if either the command is too long for2236 lib$spawn, or the command contains a newline, or if redirection2237 is desired. Forcing commands with newlines into DCLs allows to2238 store search lists on user mode logicals. */2239 2240 if (strlen (cmd) > MAXCMDLEN2241 || (have_redirection != 0)2242 || (have_newline != 0))2243 {2244 FILE *outfile;2245 char c;2246 char *sep;2247 int alevel = 0; /* apostrophe level */2248 2249 if (strlen (cmd) == 0)2250 {2251 printf (_("Error, empty command\n"));2252 fflush (stdout);2253 return 0;2254 }2255 2256 outfile = open_tmpfile (&comname, "sys$scratch:CMDXXXXXX.COM");2257 if (outfile == 0)2258 pfatal_with_name (_("fopen (temporary file)"));2259 2260 if (ifile[0])2261 {2262 fprintf (outfile, "$ assign/user %s sys$input\n", ifile);2263 DB (DB_JOBS, (_("Redirected input from %s\n"), ifile));2264 ifiledsc.dsc$w_length = 0;2265 }2266 2267 if (efile[0])2268 {2269 fprintf (outfile, "$ define sys$error %s\n", efile);2270 DB (DB_JOBS, (_("Redirected error to %s\n"), efile));2271 efiledsc.dsc$w_length = 0;2272 }2273 2274 if (ofile[0])2275 {2276 fprintf (outfile, "$ define sys$output %s\n", ofile);2277 DB (DB_JOBS, (_("Redirected output to %s\n"), ofile));2278 ofiledsc.dsc$w_length = 0;2279 }2280 2281 p = sep = q = cmd;2282 for (c = '\n'; c; c = *q++)2283 {2284 switch (c)2285 {2286 case '\n':2287 /* At a newline, skip any whitespace around a leading $2288 from the command and issue exactly one $ into the DCL. */2289 while (isspace ((unsigned char)*p))2290 p++;2291 if (*p == '$')2292 p++;2293 while (isspace ((unsigned char)*p))2294 p++;2295 fwrite (p, 1, q - p, outfile);2296 fputc ('$', outfile);2297 fputc (' ', outfile);2298 /* Reset variables. */2299 p = sep = q;2300 break;2301 2302 /* Nice places for line breaks are after strings, after2303 comma or space and before slash. */2304 case '"':2305 q = vms_handle_apos (q);2306 sep = q;2307 break;2308 case ',':2309 case ' ':2310 sep = q;2311 break;2312 case '/':2313 case '\0':2314 sep = q - 1;2315 break;2316 default:2317 break;2318 }2319 if (sep - p > 78)2320 {2321 /* Enough stuff for a line. */2322 fwrite (p, 1, sep - p, outfile);2323 p = sep;2324 if (*sep)2325 {2326 /* The command continues. */2327 fputc ('-', outfile);2328 }2329 fputc ('\n', outfile);2330 }2331 }2332 2333 fwrite (p, 1, q - p, outfile);2334 fputc ('\n', outfile);2335 2336 fclose (outfile);2337 2338 sprintf (cmd, "$ @%s", comname);2339 2340 DB (DB_JOBS, (_("Executing %s instead\n"), cmd));2341 }2342 2343 cmddsc.dsc$w_length = strlen(cmd);2344 cmddsc.dsc$a_pointer = cmd;2345 cmddsc.dsc$b_dtype = DSC$K_DTYPE_T;2346 cmddsc.dsc$b_class = DSC$K_CLASS_S;2347 2348 child->efn = 0;2349 while (child->efn < 32 || child->efn > 63)2350 {2351 status = lib$get_ef ((unsigned long *)&child->efn);2352 if (!(status & 1))2353 return 0;2354 }2355 2356 sys$clref (child->efn);2357 2358 vms_jobsefnmask |= (1 << (child->efn - 32));2359 2360 /*2361 LIB$SPAWN [command-string]2362 [,input-file]2363 [,output-file]2364 [,flags]2365 [,process-name]2366 [,process-id] [,completion-status-address] [,byte-integer-event-flag-num]2367 [,AST-address] [,varying-AST-argument]2368 [,prompt-string] [,cli] [,table]2369 */2370 2371 #ifndef DONTWAITFORCHILD2372 /*2373 * Code to make ctrl+c and ctrl+y working.2374 * The problem starts with the synchronous case where after lib$spawn is2375 * called any input will go to the child. But with input re-directed,2376 * both control characters won't make it to any of the programs, neither2377 * the spawning nor to the spawned one. Hence the caller needs to spawn2378 * with CLI$M_NOWAIT to NOT give up the input focus. A sys$waitfr2379 * has to follow to simulate the wanted synchronous behaviour.2380 * The next problem is ctrl+y which isn't caught by the crtl and2381 * therefore isn't converted to SIGQUIT (for a signal handler which is2382 * already established). The only way to catch ctrl+y, is an AST2383 * assigned to the input channel. But ctrl+y handling of DCL needs to be2384 * disabled, otherwise it will handle it. Not to mention the previous2385 * ctrl+y handling of DCL needs to be re-established before make exits.2386 * One more: At the time of LIB$SPAWN signals are blocked. SIGQUIT will2387 * make it to the signal handler after the child "normally" terminates.2388 * This isn't enough. It seems reasonable for simple command lines like2389 * a 'cc foobar.c' spawned in a subprocess but it is unacceptable for2390 * spawning make. Therefore we need to abort the process in the AST.2391 *2392 * Prior to the spawn it is checked if an AST is already set up for2393 * ctrl+y, if not one is set up for a channel to SYS$COMMAND. In general2394 * this will work except if make is run in a batch environment, but there2395 * nobody can press ctrl+y. During the setup the DCL handling of ctrl+y2396 * is disabled and an exit handler is established to re-enable it.2397 * If the user interrupts with ctrl+y, the assigned AST will fire, force2398 * an abort to the subprocess and signal SIGQUIT, which will be caught by2399 * the already established handler and will bring us back to common code.2400 * After the spawn (now /nowait) a sys$waitfr simulates the /wait and2401 * enables the ctrl+y be delivered to this code. And the ctrl+c too,2402 * which the crtl converts to SIGINT and which is caught by the common2403 * signal handler. Because signals were blocked before entering this code2404 * sys$waitfr will always complete and the SIGQUIT will be processed after2405 * it (after termination of the current block, somewhere in common code).2406 * And SIGINT too will be delayed. That is ctrl+c can only abort when the2407 * current command completes. Anyway it's better than nothing :-)2408 */2409 2410 if (!setupYAstTried)2411 tryToSetupYAst();2412 status = lib$spawn (&cmddsc, /* cmd-string */2413 (ifiledsc.dsc$w_length == 0)?0:&ifiledsc, /* input-file */2414 (ofiledsc.dsc$w_length == 0)?0:&ofiledsc, /* output-file */2415 &spflags, /* flags */2416 &pnamedsc, /* proc name */2417 &child->pid, &child->cstatus, &child->efn,2418 0, 0,2419 0, 0, 0);2420 if (status & 1)2421 {2422 pidToAbort= child->pid;2423 status= sys$waitfr (child->efn);2424 pidToAbort= 0;2425 vmsHandleChildTerm(child);2426 }2427 #else2428 status = lib$spawn (&cmddsc,2429 (ifiledsc.dsc$w_length == 0)?0:&ifiledsc,2430 (ofiledsc.dsc$w_length == 0)?0:&ofiledsc,2431 &spflags,2432 &pnamedsc,2433 &child->pid, &child->cstatus, &child->efn,2434 vmsHandleChildTerm, child,2435 0, 0, 0);2436 #endif2437 2438 if (!(status & 1))2439 {2440 printf (_("Error spawning, %d\n") ,status);2441 fflush (stdout);2442 switch (status)2443 {2444 case 0x1c:2445 errno = EPROCLIM;2446 break;2447 default:2448 errno = EFAIL;2449 }2450 }2451 2452 if (comname && !ISDB (DB_JOBS))2453 unlink (comname);2454 2455 return (status & 1);2456 }2457 2458 #else /* !VMS */2459 1938 2460 1939 /* EMX: Start a child process. This function returns the new pid. */ 2461 # if defined __MSDOS__ || defined __EMX__2462 1940 /* The child argument can be NULL (that's why we return the pid), if it is 2463 1941 and the shell is a dllshell:// a child structure is created and inserted … … 2466 1944 BTW. the name of this function in this port is very misleading, spawn_job 2467 1945 would perhaps be more appropriate. */ 2468 1946 # if defined __MSDOS__ || defined __EMX__ 2469 1947 int 2470 1948 child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp, … … 2509 1987 #endif 2510 1988 2511 /* Restore stdout/stdin of the parent process. */ 2512 if (stdin_fd != 0 && dup2 (save_stdin, 0) != 0) 2513 fatal (NILF, _("restoring of stdin failed\n")); 2514 if (stdout_fd != 1 && dup2 (save_stdout, 1) != 1) 2515 fatal (NILF, _("restoring of stdout failed\n")); 2516 2517 /* Cleanup handles */ 1989 /* Restore stdout/stdin of the parent and close temporary FDs. */ 2518 1990 if (stdin_fd != 0) 2519 close (save_stdin); 1991 { 1992 if (dup2 (save_stdin, 0) != 0) 1993 fatal (NILF, _("Could not restore stdin\n")); 1994 else 1995 close (save_stdin); 1996 } 1997 2520 1998 if (stdout_fd != 1) 2521 close (save_stdout); 1999 { 2000 if (dup2 (save_stdout, 1) != 1) 2001 fatal (NILF, _("Could not restore stdout\n")); 2002 else 2003 close (save_stdout); 2004 } 2522 2005 2523 2006 return pid; … … 2546 2029 } 2547 2030 #endif /* !AMIGA && !__MSDOS__ */ 2548 #endif /* !VMS */2549 2031 #endif /* !WINDOWS32 */ 2550 2032 … … 2678 2160 int 2679 2161 # else 2680 2162 void 2681 2163 # endif 2682 2164 exec_command (char **argv, char **envp) … … 2718 2200 2719 2201 /* wait and reap last child */ 2720 while (hWaitPID = process_wait_for_any()) 2202 hWaitPID = process_wait_for_any(); 2203 while (hWaitPID) 2721 2204 { 2722 2205 /* was an error found on this process? */ … … 2786 2269 char **new_argv; 2787 2270 int argc; 2271 int i=1; 2788 2272 2789 2273 # ifdef __EMX__ … … 2804 2288 ++argc; 2805 2289 2290 # ifdef __EMX__ 2291 if (!unixy_shell) 2292 ++argc; 2293 # endif 2294 2806 2295 new_argv = (char **) alloca ((1 + argc + 1) * sizeof (char *)); 2807 2296 new_argv[0] = shell; 2808 new_argv[1] = argv[0]; 2297 2298 # ifdef __EMX__ 2299 if (!unixy_shell) 2300 { 2301 new_argv[1] = "/c"; 2302 ++i; 2303 --argc; 2304 } 2305 # endif 2306 2307 new_argv[i] = argv[0]; 2809 2308 while (argc > 0) 2810 2309 { 2811 new_argv[ 1+ argc] = argv[argc];2310 new_argv[i + argc] = argv[argc]; 2812 2311 --argc; 2813 2312 } … … 2977 2476 char* sh_chars; 2978 2477 char** sh_cmds; 2478 #elif defined(__riscos__) 2479 static char sh_chars[] = ""; 2480 static char *sh_cmds[] = { 0 }; 2979 2481 #else /* must be UNIX-ish */ 2980 2482 static char sh_chars[] = "#;\"*?[]&|<>(){}$`^~!"; … … 3254 2756 register int j; 3255 2757 for (j = 0; sh_cmds[j] != 0; ++j) 3256 if (streq (sh_cmds[j], new_argv[0])) 3257 goto slow; 2758 { 2759 if (streq (sh_cmds[j], new_argv[0])) 2760 goto slow; 2761 # ifdef __EMX__ 2762 /* Non-Unix shells are case insensitive. */ 2763 if (!unixy_shell 2764 && strcasecmp (sh_cmds[j], new_argv[0]) == 0) 2765 goto slow; 2766 # endif 2767 } 3258 2768 } 3259 2769 … … 3293 2803 /* Line was empty. */ 3294 2804 return 0; 3295 else 3296 2805 2806 return new_argv; 3297 2807 3298 2808 slow:; … … 3443 2953 int id = GetCurrentProcessId(); 3444 2954 PATH_VAR(fbuf); 3445 char* fname = NULL;3446 2955 3447 2956 /* create a file name */ 3448 2957 sprintf(fbuf, "make%d", id); 3449 fname = tempnam(".", fbuf); 3450 3451 /* create batch file name */ 3452 *batch_filename_ptr = xmalloc(strlen(fname) + 5); 3453 strcpy(*batch_filename_ptr, fname); 3454 3455 /* make sure path name is in DOS backslash format */ 3456 if (!unixy_shell) { 3457 fname = *batch_filename_ptr; 3458 for (i = 0; fname[i] != '\0'; ++i) 3459 if (fname[i] == '/') 3460 fname[i] = '\\'; 3461 strcat(*batch_filename_ptr, ".bat"); 3462 } else { 3463 strcat(*batch_filename_ptr, ".sh"); 3464 } 2958 *batch_filename_ptr = create_batch_filename (fbuf, unixy_shell); 3465 2959 3466 2960 DB (DB_JOBS, (_("Creating temporary batch file %s\n"), … … 3491 2985 (char *) 0, (char *) 0, 3492 2986 (char **) 0); 3493 # 2987 #ifdef __EMX__ 3494 2988 else if (!unixy_shell) 3495 2989 { 3496 /* new_line is local, must not be freed therefore */ 3497 char *p, *q; 3498 int quote; 3499 size_t index; 3500 size_t len; 3501 3502 /* handle quotes 3503 We have to remove all double quotes and to split the line 3504 into distinct arguments because of the strange handling 3505 of builtin commands by cmd: 'echo "bla"' prints "bla" 3506 (with quotes) while 'c:\bin\echo.exe "bla"' prints bla 3507 (without quotes). Some programs like autoconf rely 3508 on the second behaviour. */ 3509 3510 len = strlen (new_line) + 1; 3511 3512 /* More than 1 arg per character is impossible. */ 3513 new_argv = (char **) xmalloc (len * sizeof (char *)); 3514 3515 /* All the args can fit in a buffer as big as new_line is. */ 3516 new_argv[0] = (char *) xmalloc (len); 3517 3518 index = 0; 3519 quote = 0; 3520 q = new_line; 3521 p = new_argv[index]; 3522 while(*q != '\0') 3523 { 3524 /* searching for closing quote */ 3525 if (quote) 3526 { 3527 if (*q == quote) 3528 { 3529 /* remove the quote */ 3530 q++; 3531 quote = 0; 3532 } 3533 else /* normal character: copy it */ 3534 *p++ = *q++; 3535 } 3536 3537 /* searching for opening quote */ 3538 else if (*q == '\"' 3539 # ifndef NO_CMD_DEFAULT 3540 || *q == '\'' 3541 # endif 3542 ) 3543 { 3544 /* remove opening quote */ 3545 quote = *q; 3546 q++; 3547 } 3548 3549 /* spaces outside of a quoted string: remove them 3550 and start a new argument */ 3551 else if (*q == ' ' || *q == '\t') 3552 { 3553 *p++ = '\0'; /* trailing '\0' for last argument */ 3554 3555 /* remove all successive spaces */ 3556 do 3557 { 3558 q++; 3559 } 3560 while(*q == ' ' || *q == '\t'); 3561 3562 /* start new argument */ 3563 index++; 3564 new_argv[index] = p; 3565 } 3566 3567 /* normal character (no space) outside a quoted string*/ 3568 else 3569 *p++ = *q++; 3570 } /* end while() */ 3571 3572 *p = '\0'; /* trailing '\0' for the last argument */ 3573 new_argv[index + 1] = NULL; 3574 3575 # ifndef NO_CMD_DEFAULT 3576 /* special case: echo x="y" 3577 (e.g. autoconf uses this to determine whether make works) 3578 this is pure idioty but cmd works this way: 3579 if 'echo' and 'x="y"' are two different arguments cmd 3580 will print '"x="y""' but if they are only one argument 3581 cmd will print 'bla="blurb"' as it should be 3582 note: if we do not allow cmd to be the default shell 3583 we do not need this kind of voodoo */ 3584 if (index == 3 && strcasecmp(new_argv[2], "echo") == 0) 3585 { 3586 new_argv[2][4] = ' '; 3587 new_argv[3] = NULL; 3588 } 3589 # endif 2990 /* new_line is local, must not be freed therefore 2991 We use line here instead of new_line because we run the shell 2992 manually. */ 2993 size_t line_len = strlen (line); 2994 char *p = new_line; 2995 char *q = new_line; 2996 memcpy (new_line, line, line_len + 1); 2997 /* replace all backslash-newline combination and also following tabs */ 2998 while (*q != '\0') 2999 { 3000 if (q[0] == '\\' && q[1] == '\n') 3001 { 3002 q += 2; /* remove '\\' and '\n' */ 3003 if (q[0] == '\t') 3004 q++; /* remove 1st tab in the next line */ 3005 } 3006 else 3007 *p++ = *q++; 3008 } 3009 *p = '\0'; 3010 3011 # ifndef NO_CMD_DEFAULT 3012 if (strnicmp (new_line, "echo", 4) == 0 3013 && (new_line[4] == ' ' || new_line[4] == '\t')) 3014 { 3015 /* the builtin echo command: handle it separately */ 3016 size_t echo_len = line_len - 5; 3017 char *echo_line = new_line + 5; 3018 3019 /* special case: echo 'x="y"' 3020 cmd works this way: a string is printed as is, i.e., no quotes 3021 are removed. But autoconf uses a command like echo 'x="y"' to 3022 determine whether make works. autoconf expects the output x="y" 3023 so we will do exactly that. 3024 Note: if we do not allow cmd to be the default shell 3025 we do not need this kind of voodoo */ 3026 if (echo_line[0] == '\'' 3027 && echo_line[echo_len - 1] == '\'' 3028 && strncmp (echo_line + 1, "ac_maketemp=", 3029 strlen ("ac_maketemp=")) == 0) 3030 { 3031 /* remove the enclosing quotes */ 3032 memmove (echo_line, echo_line + 1, echo_len - 2); 3033 echo_line[echo_len - 2] = '\0'; 3034 } 3035 } 3036 # endif 3037 3038 { 3039 /* Let the shell decide what to do. Put the command line into the 3040 2nd command line argument and hope for the best ;-) */ 3041 size_t sh_len = strlen (shell); 3042 3043 /* exactly 3 arguments + NULL */ 3044 new_argv = (char **) xmalloc (4 * sizeof (char *)); 3045 /* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times 3046 the trailing '\0' */ 3047 new_argv[0] = (char *) malloc (sh_len + line_len + 5); 3048 memcpy (new_argv[0], shell, sh_len + 1); 3049 new_argv[1] = new_argv[0] + sh_len + 1; 3050 memcpy (new_argv[1], "/c", 3); 3051 new_argv[2] = new_argv[1] + 3; 3052 memcpy (new_argv[2], new_line, line_len + 1); 3053 new_argv[3] = NULL; 3054 } 3590 3055 } 3591 3056 #elif defined(__MSDOS__) … … 3768 3233 } 3769 3234 #endif /* !HAPE_DUP2 && !_AMIGA */ 3235 3236 /* On VMS systems, include special VMS functions. */ 3237 3238 #ifdef VMS 3239 #include "vmsjobs.c" 3240 #endif -
trunk/src/gmake/job.h
r227 r287 109 109 #endif 110 110 111 extern unsigned int jobserver_tokens; 112 111 113 #ifdef MAKE_DLLSHELL 112 114 extern pid_t wait_jobs PARAMS ((int *status, int block)); -
trunk/src/gmake/main.c
r218 r287 1 1 /* Argument parsing and main program of GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 3 2002, 2003 Free Software Foundation, Inc.3 2002, 2003, 2005 Free Software Foundation, Inc. 4 4 This file is part of GNU Make. 5 5 … … 36 36 #ifdef WINDOWS32 37 37 #include <windows.h> 38 #include <io.h> 38 39 #include "pathstuff.h" 39 40 #endif … … 44 45 #ifdef HAVE_FCNTL_H 45 46 # include <fcntl.h> 47 #endif 48 49 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) 50 # define SET_STACK_SIZE 51 #endif 52 53 #ifdef SET_STACK_SIZE 54 # include <sys/resource.h> 46 55 #endif 47 56 … … 186 195 int default_keep_going_flag = 0; 187 196 197 /* Nonzero means check symlink mtimes. */ 198 199 int check_symlink_flag = 0; 200 188 201 /* Nonzero means print directory before starting and when done (-w). */ 189 202 … … 207 220 unsigned int job_slots = 1; 208 221 unsigned int default_job_slots = 1; 222 static unsigned int master_job_slots = 0; 209 223 210 224 /* Value of job_slots that means no limit. */ … … 260 274 261 275 int always_make_flag = 0; 276 277 /* If nonzero, we're in the "try to rebuild makefiles" phase. */ 278 279 int rebuilding_makefiles = 0; 280 281 /* Remember the original value of the SHELL variable, from the environment. */ 282 283 struct variable shell_var; 284 262 285 263 286 … … 301 324 Don't start multiple jobs unless load is below N.\n"), 302 325 N_("\ 326 -L, --check-symlink-times Use the latest mtime between symlinks and target.\n"), 327 N_("\ 303 328 -n, --just-print, --dry-run, --recon\n\ 304 329 Don't actually run any commands; just print them.\n"), … … 348 373 #endif 349 374 { 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0, 350 375 "environment-overrides", }, 351 376 { 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0, "file" }, 352 377 { 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0, "help" }, 353 378 { 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0, 354 379 "ignore-errors" }, 355 380 { 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0, 356 381 "include-dir" }, 357 382 { 'j', positive_int, (char *) &job_slots, 1, 1, 0, (char *) &inf_jobs, 358 383 (char *) &default_job_slots, "jobs" }, 359 384 { CHAR_MAX+2, string, (char *) &jobserver_fds, 1, 1, 0, 0, 0, 360 385 "jobserver-fds" }, 361 386 { 'k', flag, (char *) &keep_going_flag, 1, 1, 0, 0, 362 387 (char *) &default_keep_going_flag, "keep-going" }, 363 388 #ifndef NO_FLOAT 364 389 { 'l', floating, (char *) &max_load_average, 1, 1, 0, 365 366 390 (char *) &default_load_average, (char *) &default_load_average, 391 "load-average" }, 367 392 #else 368 393 { 'l', positive_int, (char *) &max_load_average, 1, 1, 0, 369 (char *) &default_load_average, (char *) &default_load_average, 370 "load-average" }, 371 #endif 394 (char *) &default_load_average, (char *) &default_load_average, 395 "load-average" }, 396 #endif 397 { 'L', flag, (char *) &check_symlink_flag, 1, 1, 0, 0, 0, 398 "check-symlink-times" }, 372 399 { 'm', ignore, 0, 0, 0, 0, 0, 0, 0 }, 373 400 { 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0, "just-print" }, 374 401 { 'o', string, (char *) &old_files, 0, 0, 0, 0, 0, "old-file" }, 375 402 { 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0, 376 403 "print-data-base" }, 377 404 { 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0, "question" }, 378 405 { 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0, 379 406 "no-builtin-rules" }, 380 407 { 'R', flag, (char *) &no_builtin_variables_flag, 1, 1, 0, 0, 0, 381 408 "no-builtin-variables" }, 382 409 { 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0, "silent" }, 383 410 { 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0, 0, … … 386 413 { 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0, "version" }, 387 414 { 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0, 388 415 "print-directory" }, 389 416 { CHAR_MAX+3, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0, 390 417 "no-print-directory" }, 391 418 { 'W', string, (char *) &new_files, 0, 0, 0, 0, 0, "what-if" }, 392 419 { CHAR_MAX+4, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0, 393 420 "warn-undefined-variables" }, 394 421 { 0 } 395 422 }; … … 446 473 447 474 struct file *default_goal_file; 475 476 /* Pointer to the value of the .DEFAULT_GOAL special 477 variable. */ 478 char ** default_goal_name; 448 479 449 480 /* Pointer to structure for the file .DEFAULT … … 551 582 /* Toggle -d on receipt of SIGUSR1. */ 552 583 584 #ifdef SIGUSR1 553 585 static RETSIGTYPE 554 586 debug_signal_handler (int sig UNUSED) … … 556 588 db_level = db_level ? DB_NONE : DB_BASIC; 557 589 } 590 #endif 558 591 559 592 static void … … 701 734 { 702 735 int sh_found = 0; 703 char* search_token; 736 char *search_token; 737 char *tokend; 704 738 PATH_VAR(sh_path); 705 739 extern char *default_shell; … … 710 744 search_token = token; 711 745 712 if (!no_default_sh_exe && 713 (token == NULL || !strcmp(search_token, default_shell))) { 746 747 /* If the user explicitly requests the DOS cmd shell, obey that request. 748 However, make sure that's what they really want by requiring the value 749 of SHELL either equal, or have a final path element of, "cmd" or 750 "cmd.exe" case-insensitive. */ 751 tokend = search_token + strlen (search_token) - 3; 752 if (((tokend == search_token 753 || (tokend > search_token 754 && (tokend[-1] == '/' || tokend[-1] == '\\'))) 755 && !strcmpi (tokend, "cmd")) 756 || ((tokend - 4 == search_token 757 || (tokend - 4 > search_token 758 && (tokend[-5] == '/' || tokend[-5] == '\\'))) 759 && !strcmpi (tokend - 4, "cmd.exe"))) { 760 batch_mode_shell = 1; 761 unixy_shell = 0; 762 sh_found = 0; 763 } else if (!no_default_sh_exe && 764 (token == NULL || !strcmp (search_token, default_shell))) { 714 765 /* no new information, path already set or known */ 715 766 sh_found = 1; … … 723 774 } else { 724 775 char *p; 725 struct variable *v = lookup_variable ("Path", 4); 726 727 /* 728 * Search Path for shell 729 */ 776 struct variable *v = lookup_variable ("PATH", 4); 777 778 /* Search Path for shell */ 730 779 if (v && v->value) { 731 780 char *ep; … … 846 895 struct file *f; 847 896 int i; 897 int makefile_status = MAKE_SUCCESS; 848 898 char **p; 849 899 struct dep *read_makefiles; … … 858 908 unixy_shell = 0; 859 909 no_default_sh_exe = 1; 910 #endif 911 912 #ifdef SET_STACK_SIZE 913 /* Get rid of any avoidable limit on stack size. */ 914 { 915 struct rlimit rlim; 916 917 /* Set the stack limit huge so that alloca does not fail. */ 918 if (getrlimit (RLIMIT_STACK, &rlim) == 0) 919 { 920 rlim.rlim_cur = rlim.rlim_max; 921 setrlimit (RLIMIT_STACK, &rlim); 922 } 923 } 860 924 #endif 861 925 … … 983 1047 program = argv[0] + 1; 984 1048 #endif 1049 #ifdef WINDOWS32 1050 if (program == 0) 1051 { 1052 /* Extract program from full path */ 1053 int argv0_len; 1054 char *p = strrchr (argv[0], '\\'); 1055 if (!p) 1056 p = argv[0]; 1057 argv0_len = strlen(p); 1058 if (argv0_len > 4 1059 && streq (&p[argv0_len - 4], ".exe")) 1060 { 1061 /* Remove .exe extension */ 1062 p[argv0_len - 4] = '\0'; 1063 /* Increment past the initial '\' */ 1064 program = p + 1; 1065 } 1066 } 1067 #endif 985 1068 if (program == 0) 986 1069 program = argv[0]; … … 1003 1086 { 1004 1087 #ifdef HAVE_GETCWD 1005 perror_with_name ("getcwd :", "");1088 perror_with_name ("getcwd", ""); 1006 1089 #else 1007 1090 error (NILF, "getwd: %s", current_directory); … … 1019 1102 /* Initialize the special variables. */ 1020 1103 define_variable (".VARIABLES", 10, "", o_default, 0)->special = 1; 1021 /* define_variable (".TARGETS", 8, "", o_default, 0); */ 1104 /* define_variable (".TARGETS", 8, "", o_default, 0)->special = 1; */ 1105 1106 /* Set up .FEATURES */ 1107 define_variable (".FEATURES", 9, 1108 "target-specific order-only second-expansion", 1109 o_default, 0); 1110 #ifdef MAKE_JOBSERVER 1111 do_variable_definition (NILF, ".FEATURES", "jobserver", 1112 o_default, f_append, 0); 1113 #endif 1114 #ifdef MAKE_SYMLINKS 1115 do_variable_definition (NILF, ".FEATURES", "check-symlink", 1116 o_default, f_append, 0); 1117 #endif 1022 1118 1023 1119 /* Read in variables from the environment. It is important that this be … … 1028 1124 for (i = 0; envp[i] != 0; ++i) 1029 1125 { 1030 int do_not_define; 1031 register char *ep = envp[i]; 1032 1033 /* by default, everything gets defined and exported */ 1034 do_not_define = 0; 1035 1036 while (*ep != '=') 1126 int do_not_define = 0; 1127 char *ep = envp[i]; 1128 1129 while (*ep != '\0' && *ep != '=') 1037 1130 ++ep; 1038 1131 #ifdef WINDOWS32 1039 1132 if (!unix_path && strneq(envp[i], "PATH=", 5)) 1040 1133 unix_path = ep+1; 1041 else if (! windows32_path && !strnicmp(envp[i], "Path=", 5)) {1134 else if (!strnicmp(envp[i], "Path=", 5)) { 1042 1135 do_not_define = 1; /* it gets defined after loop exits */ 1043 windows32_path = ep+1; 1136 if (!windows32_path) 1137 windows32_path = ep+1; 1044 1138 } 1045 1139 #endif … … 1048 1142 the same. */ 1049 1143 if (!do_not_define) 1050 define_variable (envp[i], (unsigned int) (ep - envp[i]), 1051 ep + 1, o_env, 1) 1052 /* Force exportation of every variable culled from the environment. 1053 We used to rely on target_environment's v_default code to do this. 1054 But that does not work for the case where an environment variable 1055 is redefined in a makefile with `override'; it should then still 1056 be exported, because it was originally in the environment. */ 1057 ->export = v_export; 1144 { 1145 struct variable *v; 1146 1147 v = define_variable (envp[i], (unsigned int) (ep - envp[i]), 1148 ep + 1, o_env, 1); 1149 /* Force exportation of every variable culled from the environment. 1150 We used to rely on target_environment's v_default code to do this. 1151 But that does not work for the case where an environment variable 1152 is redefined in a makefile with `override'; it should then still 1153 be exported, because it was originally in the environment. */ 1154 v->export = v_export; 1155 1156 /* Another wrinkle is that POSIX says the value of SHELL set in the 1157 makefile should not change the value of SHELL given to 1158 subprocesses, which seems silly to me but... */ 1159 if (strncmp (envp[i], "SHELL=", 6) == 0) 1160 { 1161 #ifndef __MSDOS__ 1162 v->export = v_noexport; 1163 #endif 1164 shell_var.name = "SHELL"; 1165 shell_var.value = xstrdup (ep + 1); 1166 } 1167 } 1058 1168 } 1059 1169 #ifdef WINDOWS32 1060 /* 1061 * Make sure that this particular spelling of 'Path' is available1170 /* If we didn't find a correctly spelled PATH we define PATH as 1171 * either the first mispelled value or an empty string 1062 1172 */ 1063 if (windows32_path) 1064 define_variable("Path", 4, windows32_path, o_env, 1)->export = v_export; 1065 else if (unix_path) 1066 define_variable("Path", 4, unix_path, o_env, 1)->export = v_export; 1067 else 1068 define_variable("Path", 4, "", o_env, 1)->export = v_export; 1069 1070 /* 1071 * PATH defaults to Path iff PATH not found and Path is found. 1072 */ 1073 if (!unix_path && windows32_path) 1074 define_variable("PATH", 4, windows32_path, o_env, 1)->export = v_export; 1173 if (!unix_path) 1174 define_variable("PATH", 4, 1175 windows32_path ? windows32_path : "", 1176 o_env, 1)->export = v_export; 1075 1177 #endif 1076 1178 #else /* For Amiga, read the ENV: device, ignoring all dirs */ … … 1242 1344 { 1243 1345 char *dir = directories->list[i]; 1346 char *expanded = 0; 1244 1347 if (dir[0] == '~') 1245 1348 { 1246 char *expanded = tilde_expand (dir);1349 expanded = tilde_expand (dir); 1247 1350 if (expanded != 0) 1248 1351 dir = expanded; 1249 1352 } 1353 #ifdef WINDOWS32 1354 /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/' 1355 But allow -C/ just in case someone wants that. */ 1356 { 1357 char *p = dir + strlen (dir) - 1; 1358 while (p > dir && (p[0] == '/' || p[0] == '\\')) 1359 --p; 1360 p[1] = '\0'; 1361 } 1362 #endif 1250 1363 if (chdir (dir) < 0) 1251 1364 pfatal_with_name (dir); 1252 if ( dir != directories->list[i])1253 free ( dir);1365 if (expanded) 1366 free (expanded); 1254 1367 } 1255 1368 … … 1306 1419 { 1307 1420 #ifdef HAVE_GETCWD 1308 perror_with_name ("getcwd :", "");1421 perror_with_name ("getcwd", ""); 1309 1422 #else 1310 1423 error (NILF, "getwd: %s", current_directory); … … 1373 1486 if (outfile == 0) 1374 1487 pfatal_with_name (_("fopen (temporary file)")); 1375 while (!feof (stdin) )1488 while (!feof (stdin) && ! ferror (stdin)) 1376 1489 { 1377 1490 char buf[2048]; … … 1453 1566 define_default_variables (); 1454 1567 1568 default_file = enter_file (".DEFAULT"); 1569 1570 { 1571 struct variable *v = define_variable (".DEFAULT_GOAL", 13, "", o_file, 0); 1572 default_goal_name = &v->value; 1573 } 1574 1455 1575 /* Read all the makefiles. */ 1456 1457 default_file = enter_file (".DEFAULT");1458 1576 1459 1577 read_makefiles … … 1585 1703 want job_slots to be 0 to indicate we're using the jobserver. */ 1586 1704 1705 master_job_slots = job_slots; 1706 1587 1707 while (--job_slots) 1588 1708 { … … 1604 1724 jobserver_fds->idx = 1; 1605 1725 jobserver_fds->max = 1; 1726 } 1727 #endif 1728 1729 #ifndef MAKE_SYMLINKS 1730 if (check_symlink_flag) 1731 { 1732 error (NILF, _("Symbolic links not supported: disabling -L.")); 1733 check_symlink_flag = 0; 1606 1734 } 1607 1735 #endif … … 1673 1801 int nargc = argc; 1674 1802 int orig_db_level = db_level; 1803 int status; 1675 1804 1676 1805 if (! ISDB (DB_MAKEFILES)) … … 1733 1862 define_makeflags (1, 1); 1734 1863 1735 switch (update_goal_chain (read_makefiles, 1)) 1864 rebuilding_makefiles = 1; 1865 status = update_goal_chain (read_makefiles); 1866 rebuilding_makefiles = 0; 1867 1868 switch (status) 1736 1869 { 1737 1870 case 1: … … 1782 1915 any_remade |= (mtime != NONEXISTENT_MTIME 1783 1916 && mtime != makefile_mtimes[i]); 1917 makefile_status = MAKE_FAILURE; 1784 1918 } 1785 1919 } … … 1871 2005 #ifndef _AMIGA 1872 2006 for (p = environ; *p != 0; ++p) 1873 if ( (*p)[MAKELEVEL_LENGTH] == '='1874 && strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH))2007 if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH) 2008 && (*p)[MAKELEVEL_LENGTH] == '=') 1875 2009 { 1876 2010 /* The SGI compiler apparently can't understand … … 1927 2061 int pid; 1928 2062 int status; 1929 pid = child_execute_job (0, 1, nargv, environ, NULL);2063 pid = child_execute_job (0, 1, nargv, environ, NULL); 1930 2064 1931 2065 /* is this loop really necessary? */ 1932 2066 do { 1933 pid = wait (&status);1934 } while (pid <= 0);2067 pid = wait (&status); 2068 } while (pid <= 0); 1935 2069 /* use the exit code of the child process */ 1936 exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);2070 exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE); 1937 2071 } 1938 2072 #else … … 1948 2082 1949 2083 db_level = orig_db_level; 2084 2085 /* Free the makefile mtimes (if we allocated any). */ 2086 if (makefile_mtimes) 2087 free ((char *) makefile_mtimes); 1950 2088 } 1951 2089 … … 1964 2102 if (goals == 0) 1965 2103 { 1966 if (default_goal_file != 0) 1967 { 1968 goals = (struct dep *) xmalloc (sizeof (struct dep)); 1969 goals->next = 0; 1970 goals->name = 0; 2104 if (**default_goal_name != '\0') 2105 { 2106 if (default_goal_file == 0 || 2107 strcmp (*default_goal_name, default_goal_file->name) != 0) 2108 { 2109 default_goal_file = lookup_file (*default_goal_name); 2110 2111 /* In case user set .DEFAULT_GOAL to a non-existent target 2112 name let's just enter this name into the table and let 2113 the standard logic sort it out. */ 2114 if (default_goal_file == 0) 2115 { 2116 struct nameseq *ns; 2117 char *p = *default_goal_name; 2118 2119 ns = multi_glob ( 2120 parse_file_seq (&p, '\0', sizeof (struct nameseq), 1), 2121 sizeof (struct nameseq)); 2122 2123 /* .DEFAULT_GOAL should contain one target. */ 2124 if (ns->next != 0) 2125 fatal (NILF, _(".DEFAULT_GOAL contains more than one target")); 2126 2127 default_goal_file = enter_file (ns->name); 2128 2129 ns->name = 0; /* It was reused by enter_file(). */ 2130 free_ns_chain (ns); 2131 } 2132 } 2133 2134 goals = (struct dep *) xmalloc (sizeof (struct dep)); 2135 goals->next = 0; 2136 goals->name = 0; 1971 2137 goals->ignore_mtime = 0; 1972 goals->file = default_goal_file; 1973 } 2138 goals->need_2nd_expansion = 0; 2139 goals->file = default_goal_file; 2140 } 1974 2141 } 1975 2142 else 1976 2143 lastgoal->next = 0; 2144 1977 2145 1978 2146 if (!goals) … … 1988 2156 DB (DB_BASIC, (_("Updating goal targets....\n"))); 1989 2157 1990 switch (update_goal_chain (goals , 0))2158 switch (update_goal_chain (goals)) 1991 2159 { 1992 2160 case -1: … … 1994 2162 case 0: 1995 2163 /* Updated successfully. */ 1996 status = MAKE_SUCCESS;2164 status = makefile_status; 1997 2165 break; 1998 2166 case 1: … … 2098 2266 if (v != 0) 2099 2267 { 2100 /* It is indeed a variable definition. Record a pointer to 2101 the variable for later use in define_makeflags. */ 2102 struct command_variable *cv 2103 = (struct command_variable *) xmalloc (sizeof (*cv)); 2104 cv->variable = v; 2105 cv->next = command_variables; 2106 command_variables = cv; 2268 /* It is indeed a variable definition. If we don't already have this 2269 one, record a pointer to the variable for later use in 2270 define_makeflags. */ 2271 struct command_variable *cv; 2272 2273 for (cv = command_variables; cv != 0; cv = cv->next) 2274 if (cv->variable == v) 2275 break; 2276 2277 if (! cv) { 2278 cv = (struct command_variable *) xmalloc (sizeof (*cv)); 2279 cv->variable = v; 2280 cv->next = command_variables; 2281 command_variables = cv; 2282 } 2107 2283 } 2108 2284 else if (! env) … … 2127 2303 lastgoal->file = f; 2128 2304 lastgoal->ignore_mtime = 0; 2305 lastgoal->need_2nd_expansion = 0; 2129 2306 2130 2307 { … … 2775 2952 if (!dying) 2776 2953 { 2954 char token = '+'; 2777 2955 int err; 2778 2956 … … 2794 2972 if (print_data_base_flag) 2795 2973 print_data_base (); 2974 2975 /* Sanity: have we written all our jobserver tokens back? If our 2976 exit status is 2 that means some kind of syntax error; we might not 2977 have written all our tokens so do that now. If tokens are left 2978 after any other error code, that's bad. */ 2979 2980 if (job_fds[0] != -1 && jobserver_tokens) 2981 { 2982 if (status != 2) 2983 error (NILF, 2984 "INTERNAL: Exiting with %u jobserver tokens (should be 0)!", 2985 jobserver_tokens); 2986 else 2987 while (jobserver_tokens--) 2988 { 2989 int r; 2990 2991 EINTRLOOP (r, write (job_fds[1], &token, 1)); 2992 if (r != 1) 2993 perror_with_name ("write", ""); 2994 } 2995 } 2996 2997 2998 /* Sanity: If we're the master, were all the tokens written back? */ 2999 3000 if (master_job_slots) 3001 { 3002 /* We didn't write one for ourself, so start at 1. */ 3003 unsigned int tcnt = 1; 3004 3005 /* Close the write side, so the read() won't hang. */ 3006 close (job_fds[1]); 3007 3008 while ((err = read (job_fds[0], &token, 1)) == 1) 3009 ++tcnt; 3010 3011 if (tcnt != master_job_slots) 3012 error (NILF, 3013 "INTERNAL: Exiting with %u jobserver tokens available; should be %u!", 3014 tcnt, master_job_slots); 3015 } 2796 3016 2797 3017 /* Try to move back to the original directory. This is essential on … … 2859 3079 printf (_("%s[%u]: Leaving directory `%s'\n"), 2860 3080 program, makelevel, starting_directory); 3081 3082 /* Flush stdout to be sure this comes before any stderr output. */ 3083 fflush (stdout); 2861 3084 } -
trunk/src/gmake/read.c
r191 r287 79 79 unsigned int if_cmds; /* Depth of conditional nesting. */ 80 80 unsigned int allocated; /* Elts allocated in following arrays. */ 81 char *ignoring; /* Are we ignoring or interepreting? */ 81 char *ignoring; /* Are we ignoring or interpreting? 82 0=interpreting, 1=not yet interpreted, 83 2=already interpreted */ 82 84 char *seen_else; /* Have we already seen an `else'? */ 83 85 }; … … 131 133 enum variable_origin origin, 132 134 struct ebuffer *ebuf)); 133 static int conditional_line PARAMS ((char *line, const struct floc *flocp));135 static int conditional_line PARAMS ((char *line, int len, const struct floc *flocp)); 134 136 static void record_files PARAMS ((struct nameseq *filenames, char *pattern, char *pattern_percent, 135 137 struct dep *deps, unsigned int cmds_started, char *commands, 136 138 unsigned int commands_idx, int two_colon, 137 int have_sysv_atvar, 138 const struct floc *flocp, int set_default)); 139 const struct floc *flocp)); 139 140 static void record_target_var PARAMS ((struct nameseq *filenames, char *defn, 140 141 enum variable_origin origin, … … 257 258 d->file->dontcare = 1; 258 259 d->ignore_mtime = 0; 260 d->need_2nd_expansion = 0; 259 261 /* Tell update_goal_chain to bail out as soon as this file is 260 262 made, and main not to die if we can't make this file. */ … … 372 374 deps->file = lookup_file (filename); 373 375 if (deps->file == 0) 374 { 375 deps->file = enter_file (xstrdup (filename)); 376 if (flags & RM_DONTCARE) 377 deps->file->dontcare = 1; 378 } 376 deps->file = enter_file (xstrdup (filename)); 379 377 if (filename != ebuf.floc.filenm) 380 378 free (filename); … … 382 380 deps->changed = flags; 383 381 deps->ignore_mtime = 0; 382 deps->need_2nd_expansion = 0; 383 if (flags & RM_DONTCARE) 384 deps->file->dontcare = 1; 384 385 385 386 /* If the makefile can't be found at all, give up entirely. */ … … 413 414 414 415 free (ebuf.bufstart); 416 alloca (0); 415 417 return r; 416 418 } … … 444 446 reading_file = curfile; 445 447 448 alloca (0); 446 449 return r; 447 450 } … … 465 468 int ignoring = 0, in_ignored_define = 0; 466 469 int no_targets = 0; /* Set when reading a rule without targets. */ 467 int have_sysv_atvar = 0;468 470 struct nameseq *filenames = 0; 469 471 struct dep *deps = 0; … … 482 484 record_files (filenames, pattern, pattern_percent, deps, \ 483 485 cmds_started, commands, commands_idx, two_colon, \ 484 have_sysv_atvar, &fi, set_default);\486 &fi); \ 485 487 } \ 486 488 filenames = 0; \ … … 619 621 following lines. */ 620 622 621 if (!in_ignored_define 622 && (word1eq ("ifdef") || word1eq ("ifndef")623 || word1eq ("ifeq") || word1eq ("ifneq") 624 || word1eq ("else") || word1eq ("endif")))625 626 int i = conditional_line (p, fstart);627 if (i < 0) 628 fatal (fstart, _("invalid syntax in conditional")); 629 630 ignoring = i;631 continue; 623 if (!in_ignored_define) 624 { 625 int i = conditional_line (p, len, fstart); 626 if (i != -2) 627 { 628 if (i == -1) 629 fatal (fstart, _("invalid syntax in conditional")); 630 631 ignoring = i; 632 continue; 633 } 632 634 } 633 635 … … 854 856 goto rule_complete; 855 857 858 /* This line starts with a tab but was not caught above because there 859 was no preceding target, and the line might have been usable as a 860 variable definition. But now we know it is definitely lossage. */ 856 861 if (line[0] == '\t') 857 { 858 p = collapsed; /* Ignore comments, etc. */ 859 while (isblank ((unsigned char)*p)) 860 ++p; 861 if (*p == '\0') 862 /* The line is completely blank; that is harmless. */ 863 continue; 864 865 /* This line starts with a tab but was not caught above 866 because there was no preceding target, and the line 867 might have been usable as a variable definition. 868 But now we know it is definitely lossage. */ 869 fatal(fstart, _("commands commence before first target")); 870 } 862 fatal(fstart, _("commands commence before first target")); 871 863 872 864 /* This line describes some target files. This is complicated by … … 887 879 unsigned int len, plen = 0; 888 880 char *colonp; 881 const char *end, *beg; /* Helpers for whitespace stripping. */ 889 882 890 883 /* Record the previous rule. */ … … 935 928 936 929 p2 = variable_expand_string(NULL, lb_next, len); 930 937 931 while (1) 938 932 { … … 1041 1035 if (*lb_next != '\0') 1042 1036 { 1043 unsigned int l = p - variable_buffer; 1044 unsigned int l2 = p2 - variable_buffer; 1037 unsigned int l = p2 - variable_buffer; 1045 1038 plen = strlen (p2); 1046 1039 (void) variable_buffer_output (p2+plen, 1047 1040 lb_next, strlen (lb_next)+1); 1048 p = variable_buffer + l; 1049 p2 = variable_buffer + l2; 1041 p2 = variable_buffer + l; 1050 1042 } 1051 1043 … … 1113 1105 } 1114 1106 } 1115 1116 /* Do any of the prerequisites appear to have $@ etc.? */1117 have_sysv_atvar = 0;1118 if (!posix_pedantic)1119 for (p = strchr (p2, '$'); p != 0; p = strchr (p+1, '$'))1120 if (p[1] == '@' || ((p[1] == '(' || p[1] == '{') && p[2] == '@'))1121 {1122 have_sysv_atvar = 1;1123 break;1124 }1125 1107 1126 1108 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */ … … 1188 1170 pattern = 0; 1189 1171 1190 /* Parse the dependencies. */ 1191 deps = (struct dep *) 1192 multi_glob (parse_file_seq (&p2, '|', sizeof (struct dep), 1), 1193 sizeof (struct dep)); 1194 if (*p2) 1172 /* Strip leading and trailing whitespaces. */ 1173 beg = p2; 1174 end = beg + strlen (beg) - 1; 1175 strip_whitespace (&beg, &end); 1176 1177 if (beg <= end && *beg != '\0') 1195 1178 { 1196 /* Files that follow '|' are special prerequisites that 1197 need only exist in order to satisfy the dependency. 1198 Their modification times are irrelevant. */ 1199 struct dep **deps_ptr = &deps; 1200 struct dep *d; 1201 for (deps_ptr = &deps; *deps_ptr; deps_ptr = &(*deps_ptr)->next) 1202 ; 1203 ++p2; 1204 *deps_ptr = (struct dep *) 1205 multi_glob (parse_file_seq (&p2, '\0', sizeof (struct dep), 1), 1206 sizeof (struct dep)); 1207 for (d = *deps_ptr; d != 0; d = d->next) 1208 d->ignore_mtime = 1; 1179 char *top; 1180 const char *fromp = beg; 1181 1182 /* Make a copy of the dependency string. Note if we find '$'. */ 1183 deps = (struct dep*) xmalloc (sizeof (struct dep)); 1184 deps->next = 0; 1185 deps->name = top = (char *) xmalloc (end - beg + 2); 1186 deps->need_2nd_expansion = 0; 1187 while (fromp <= end) 1188 { 1189 if (*fromp == '$') 1190 deps->need_2nd_expansion = 1; 1191 *(top++) = *(fromp++); 1192 } 1193 *top = '\0'; 1194 deps->file = 0; 1209 1195 } 1196 else 1197 deps = 0; 1210 1198 1211 1199 commands_idx = 0; … … 1226 1214 commands_idx += len; 1227 1215 commands[commands_idx++] = '\n'; 1216 } 1217 1218 /* Determine if this target should be made default. We used to do 1219 this in record_files() but because of the delayed target recording 1220 and because preprocessor directives are legal in target's commands 1221 it is too late. Consider this fragment for example: 1222 1223 foo: 1224 1225 ifeq ($(.DEFAULT_GOAL),foo) 1226 ... 1227 endif 1228 1229 Because the target is not recorded until after ifeq directive is 1230 evaluated the .DEFAULT_GOAL does not contain foo yet as one 1231 would expect. Because of this we have to move some of the logic 1232 here. */ 1233 1234 if (**default_goal_name == '\0' && set_default) 1235 { 1236 char* name; 1237 struct dep *d; 1238 struct nameseq *t = filenames; 1239 1240 for (; t != 0; t = t->next) 1241 { 1242 int reject = 0; 1243 name = t->name; 1244 1245 /* We have nothing to do if this is an implicit rule. */ 1246 if (strchr (name, '%') != 0) 1247 break; 1248 1249 /* See if this target's name does not start with a `.', 1250 unless it contains a slash. */ 1251 if (*name == '.' && strchr (name, '/') == 0 1252 #ifdef HAVE_DOS_PATHS 1253 && strchr (name, '\\') == 0 1254 #endif 1255 ) 1256 continue; 1257 1258 1259 /* If this file is a suffix, don't let it be 1260 the default goal file. */ 1261 for (d = suffix_file->deps; d != 0; d = d->next) 1262 { 1263 register struct dep *d2; 1264 if (*dep_name (d) != '.' && streq (name, dep_name (d))) 1265 { 1266 reject = 1; 1267 break; 1268 } 1269 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) 1270 { 1271 register unsigned int len = strlen (dep_name (d2)); 1272 if (!strneq (name, dep_name (d2), len)) 1273 continue; 1274 if (streq (name + len, dep_name (d))) 1275 { 1276 reject = 1; 1277 break; 1278 } 1279 } 1280 1281 if (reject) 1282 break; 1283 } 1284 1285 if (!reject) 1286 { 1287 define_variable_global (".DEFAULT_GOAL", 13, t->name, 1288 o_file, 0, NILF); 1289 break; 1290 } 1291 } 1228 1292 } 1229 1293 … … 1284 1348 char *line; 1285 1349 1350 nlines = readline (ebuf); 1286 1351 ebuf->floc.lineno += nlines; 1287 nlines = readline (ebuf);1288 1352 1289 1353 /* If there is nothing left to eval, we're done. */ … … 1366 1430 current makefile. They are used for error messages. 1367 1431 1368 Value is -1 if the line is invalid, 1432 Value is -2 if the line is not a conditional at all, 1433 -1 if the line is an invalid conditional, 1369 1434 0 if following text should be interpreted, 1370 1435 1 if following text should be ignored. */ 1371 1436 1372 1437 static int 1373 conditional_line (char *line, const struct floc *flocp)1438 conditional_line (char *line, int len, const struct floc *flocp) 1374 1439 { 1375 int notdef;1376 1440 char *cmdname; 1377 register unsigned int i; 1378 1379 if (*line == 'i') 1380 { 1381 /* It's an "if..." command. */ 1382 notdef = line[2] == 'n'; 1383 if (notdef) 1384 { 1385 cmdname = line[3] == 'd' ? "ifndef" : "ifneq"; 1386 line += cmdname[3] == 'd' ? 7 : 6; 1387 } 1388 else 1389 { 1390 cmdname = line[2] == 'd' ? "ifdef" : "ifeq"; 1391 line += cmdname[2] == 'd' ? 6 : 5; 1392 } 1393 } 1441 enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype; 1442 unsigned int i; 1443 unsigned int o; 1444 1445 /* Compare a word, both length and contents. */ 1446 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1)) 1447 #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); } 1448 1449 /* Make sure this line is a conditional. */ 1450 chkword ("ifdef", c_ifdef) 1451 else chkword ("ifndef", c_ifndef) 1452 else chkword ("ifeq", c_ifeq) 1453 else chkword ("ifneq", c_ifneq) 1454 else chkword ("else", c_else) 1455 else chkword ("endif", c_endif) 1394 1456 else 1395 { 1396 /* It's an "else" or "endif" command. */ 1397 notdef = line[1] == 'n'; 1398 cmdname = notdef ? "endif" : "else"; 1399 line += notdef ? 5 : 4; 1400 } 1401 1402 line = next_token (line); 1403 1404 if (*cmdname == 'e') 1457 return -2; 1458 1459 /* Found one: skip past it and any whitespace after it. */ 1460 line = next_token (line + len); 1461 1462 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname) 1463 1464 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */ 1465 if (cmdtype == c_endif) 1405 1466 { 1406 1467 if (*line != '\0') 1407 error (flocp, _("Extraneous text after `%s' directive"), cmdname);1408 /* "Else" or "endif". */ 1409 if ( conditionals->if_cmds == 0)1468 EXTRANEOUS (); 1469 1470 if (!conditionals->if_cmds) 1410 1471 fatal (flocp, _("extraneous `%s'"), cmdname); 1411 /* NOTDEF indicates an `endif' command. */ 1412 if (notdef) 1413 --conditionals->if_cmds; 1414 else if (conditionals->seen_else[conditionals->if_cmds - 1]) 1415 fatal (flocp, _("only one `else' per conditional")); 1472 1473 --conditionals->if_cmds; 1474 1475 goto DONE; 1476 } 1477 1478 /* An 'else' statement can either be simple, or it can have another 1479 conditional after it. */ 1480 if (cmdtype == c_else) 1481 { 1482 const char *p; 1483 1484 if (!conditionals->if_cmds) 1485 fatal (flocp, _("extraneous `%s'"), cmdname); 1486 1487 o = conditionals->if_cmds - 1; 1488 1489 if (conditionals->seen_else[o]) 1490 fatal (flocp, _("only one `else' per conditional")); 1491 1492 /* Change the state of ignorance. */ 1493 switch (conditionals->ignoring[o]) 1494 { 1495 case 0: 1496 /* We've just been interpreting. Never do it again. */ 1497 conditionals->ignoring[o] = 2; 1498 break; 1499 case 1: 1500 /* We've never interpreted yet. Maybe this time! */ 1501 conditionals->ignoring[o] = 0; 1502 break; 1503 } 1504 1505 /* It's a simple 'else'. */ 1506 if (*line == '\0') 1507 { 1508 conditionals->seen_else[o] = 1; 1509 goto DONE; 1510 } 1511 1512 /* The 'else' has extra text. That text must be another conditional 1513 and cannot be an 'else' or 'endif'. */ 1514 1515 /* Find the length of the next word. */ 1516 for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p) 1517 ; 1518 len = p - line; 1519 1520 /* If it's 'else' or 'endif' or an illegal conditional, fail. */ 1521 if (word1eq("else") || word1eq("endif") 1522 || conditional_line (line, len, flocp) < 0) 1523 EXTRANEOUS (); 1416 1524 else 1417 { 1418 /* Toggle the state of ignorance. */ 1419 conditionals->ignoring[conditionals->if_cmds - 1] 1420 = !conditionals->ignoring[conditionals->if_cmds - 1]; 1421 /* Record that we have seen an `else' in this conditional. 1422 A second `else' will be erroneous. */ 1423 conditionals->seen_else[conditionals->if_cmds - 1] = 1; 1424 } 1425 for (i = 0; i < conditionals->if_cmds; ++i) 1426 if (conditionals->ignoring[i]) 1427 return 1; 1428 return 0; 1525 { 1526 /* conditional_line() created a new level of conditional. 1527 Raise it back to this level. */ 1528 if (conditionals->ignoring[o] < 2) 1529 conditionals->ignoring[o] = conditionals->ignoring[o+1]; 1530 --conditionals->if_cmds; 1531 } 1532 1533 goto DONE; 1429 1534 } 1430 1535 … … 1436 1541 } 1437 1542 1438 ++conditionals->if_cmds;1543 o = conditionals->if_cmds++; 1439 1544 if (conditionals->if_cmds > conditionals->allocated) 1440 1545 { … … 1447 1552 1448 1553 /* Record that we have seen an `if...' but no `else' so far. */ 1449 conditionals->seen_else[ conditionals->if_cmds - 1] = 0;1554 conditionals->seen_else[o] = 0; 1450 1555 1451 1556 /* Search through the stack to see if we're already ignoring. */ 1452 for (i = 0; i < conditionals->if_cmds - 1; ++i)1557 for (i = 0; i < o; ++i) 1453 1558 if (conditionals->ignoring[i]) 1454 1559 { 1455 /* We are already ignoring, so just push a level 1456 to match the next "else" or "endif", and keep ignoring.1457 We don't want to expandvariables in the condition. */1458 conditionals->ignoring[ conditionals->if_cmds - 1] = 1;1560 /* We are already ignoring, so just push a level to match the next 1561 "else" or "endif", and keep ignoring. We don't want to expand 1562 variables in the condition. */ 1563 conditionals->ignoring[o] = 1; 1459 1564 return 1; 1460 1565 } 1461 1566 1462 if (cmd name[notdef ? 3 : 2] == 'd')1567 if (cmdtype == c_ifdef || cmdtype == c_ifndef) 1463 1568 { 1464 /* "Ifdef" or "ifndef". */1465 1569 char *var; 1466 1570 struct variable *v; 1467 registerchar *p;1571 char *p; 1468 1572 1469 1573 /* Expand the thing we're looking up, so we can use indirect and … … 1479 1583 1480 1584 var[i] = '\0'; 1481 v = lookup_variable (var, strlen (var)); 1482 conditionals->ignoring[conditionals->if_cmds - 1] 1483 = (v != 0 && *v->value != '\0') == notdef; 1585 v = lookup_variable (var, i); 1586 1587 conditionals->ignoring[o] = 1588 ((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef)); 1484 1589 1485 1590 free (var); … … 1499 1604 if (termin == ',') 1500 1605 { 1501 registerint count = 0;1606 int count = 0; 1502 1607 for (; *line != '\0'; ++line) 1503 1608 if (*line == '(') … … 1573 1678 line = next_token (++line); 1574 1679 if (*line != '\0') 1575 error (flocp, _("Extraneous text after `%s' directive"), cmdname);1680 EXTRANEOUS (); 1576 1681 1577 1682 s2 = variable_expand (s2); 1578 conditionals->ignoring[conditionals->if_cmds - 1] 1579 = streq (s1, s2) == notdef; 1683 conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq)); 1580 1684 } 1581 1685 1686 DONE: 1582 1687 /* Search through the stack to see if we're ignoring. */ 1583 1688 for (i = 0; i < conditionals->if_cmds; ++i) … … 1695 1800 p = create_pattern_var (name, percent); 1696 1801 p->variable.fileinfo = *flocp; 1802 /* I don't think this can fail since we already determined it was a 1803 variable definition. */ 1697 1804 v = parse_variable_definition (&p->variable, defn); 1698 v->value = xstrdup (v->value); 1699 if (!v) 1700 error (flocp, _("Malformed pattern-specific variable definition")); 1805 assert (v != 0); 1806 1807 if (v->flavor == f_simple) 1808 v->value = allocated_variable_expand (v->value); 1809 else 1810 v->value = xstrdup (v->value); 1811 1701 1812 fname = p->target; 1702 1813 } … … 1772 1883 struct dep *deps, unsigned int cmds_started, char *commands, 1773 1884 unsigned int commands_idx, int two_colon, 1774 int have_sysv_atvar, const struct floc *flocp, int set_default)1885 const struct floc *flocp) 1775 1886 { 1776 1887 struct nameseq *nextf; … … 1779 1890 char **targets = 0, **target_percents = 0; 1780 1891 struct commands *cmds; 1892 1893 /* If we've already snapped deps, that means we're in an eval being 1894 resolved after the makefiles have been read in. We can't add more rules 1895 at this time, since they won't get snapped and we'll get core dumps. 1896 See Savannah bug # 12124. */ 1897 if (snapped_deps) 1898 fatal (flocp, _("prerequisites cannot be defined in command scripts")); 1781 1899 1782 1900 if (commands_idx > 0) … … 1844 1962 /* If there are multiple filenames, copy the chain DEPS 1845 1963 for all but the last one. It is not safe for the same deps 1846 to go in more than one place in the data 1964 to go in more than one place in the database. */ 1847 1965 this = nextf != 0 ? copy_dep_chain (deps) : deps; 1848 1966 … … 1861 1979 } 1862 1980 else 1863 { 1864 /* We use patsubst_expand to do the work of translating 1865 the target pattern, the target's name and the dependencies' 1866 patterns into plain dependency names. */ 1867 char *buffer = variable_expand (""); 1868 1869 for (d = this; d != 0; d = d->next) 1870 { 1871 char *o; 1872 char *percent = find_percent (d->name); 1873 if (percent == 0) 1874 continue; 1875 o = patsubst_expand (buffer, name, pattern, d->name, 1876 pattern_percent, percent); 1877 /* If the name expanded to the empty string, that's 1878 illegal. */ 1879 if (o == buffer) 1880 fatal (flocp, 1881 _("target `%s' leaves prerequisite pattern empty"), 1882 name); 1883 free (d->name); 1884 d->name = savestring (buffer, o - buffer); 1885 } 1886 } 1887 } 1888 1889 /* If at least one of the dependencies uses $$@ etc. deal with that. 1890 It would be very nice and very simple to just expand everything, but 1891 it would break a lot of backward compatibility. Maybe that's OK 1892 since we're just emulating a SysV function, and if we do that then 1893 why not emulate it completely (that's what SysV make does: it 1894 re-expands the entire prerequisite list, all the time, with $@ 1895 etc. in scope). But, it would be a pain indeed to document this 1896 ("iff you use $$@, your prerequisite lists is expanded twice...") 1897 Ouch. Maybe better to make the code more complex. */ 1898 1899 if (have_sysv_atvar) 1900 { 1901 char *p; 1902 int tlen = strlen (name); 1903 char *fnp = strrchr (name, '/'); 1904 int dlen; 1905 int flen; 1906 1907 if (fnp) 1908 { 1909 dlen = fnp - name; 1910 ++fnp; 1911 flen = strlen (fnp); 1912 } 1913 else 1914 { 1915 dlen = 0; 1916 fnp = name; 1917 flen = tlen; 1918 } 1919 1920 1921 for (d = this; d != 0; d = d->next) 1922 for (p = strchr (d->name, '$'); p != 0; p = strchr (p+1, '$')) 1981 /* We use subst_expand to do the work of translating % to $* in 1982 the dependency line. */ 1983 1984 if (this != 0 && find_percent (this->name) != 0) 1923 1985 { 1924 char *s = p; 1925 char *at; 1926 int atlen; 1927 1928 /* If it's '$@', '$(@', or '${@', it's escaped */ 1929 if ((++p)[0] == '$' 1930 && (p[1] == '@' 1931 || ((p[1] == '(' || p[1] == '{') && p[2] == '@'))) 1932 { 1933 bcopy (p, s, strlen (p)+1); 1934 continue; 1935 } 1936 1937 /* Maybe found one. We like anything of any form matching @, 1938 [({]@[}):], or [({]@[DF][}):]. */ 1939 1940 if (! (p[0] == '@' 1941 || ((p[0] == '(' || p[0] == '{') && (++p)[0] == '@' 1942 && (((++p)[0] == ')' || p[0] == '}' || p[0] == ':') 1943 || ((p[1] == ')' || p[1] == '}' || p[1] == ':') 1944 && (p[0] == 'D' || p[0] == 'F')))))) 1945 continue; 1946 1947 /* Found one. Compute the length and string ptr. Move p 1948 past the variable reference. */ 1949 switch (p[0]) 1950 { 1951 case 'D': 1952 atlen = dlen; 1953 at = name; 1954 p += 2; 1955 break; 1956 1957 case 'F': 1958 atlen = flen; 1959 at = fnp; 1960 p += 2; 1961 break; 1962 1963 default: 1964 atlen = tlen; 1965 at = name; 1966 ++p; 1967 break; 1968 } 1969 1970 /* Get more space. */ 1971 { 1972 int soff = s - d->name; 1973 int poff = p - d->name; 1974 d->name = (char *) xrealloc (d->name, 1975 strlen (d->name) + atlen + 1); 1976 s = d->name + soff; 1977 p = d->name + poff; 1978 } 1979 1980 /* Copy the string over. */ 1981 bcopy(p, s+atlen, strlen (p)+1); 1982 bcopy(at, s, atlen); 1983 p = s + atlen - 1; 1986 char *o; 1987 char *buffer = variable_expand (""); 1988 1989 o = subst_expand (buffer, this->name, "%", "$*", 1, 2, 0); 1990 1991 free (this->name); 1992 this->name = savestring (buffer, o - buffer); 1993 this->need_2nd_expansion = 1; 1984 1994 } 1985 1995 } 1986 1996 1987 1997 if (!two_colon) … … 2022 2032 if (cmds != 0) 2023 2033 f->cmds = cmds; 2034 2024 2035 /* Defining .SUFFIXES with no dependencies 2025 2036 clears out the list of suffixes. */ … … 2036 2047 f->deps = 0; 2037 2048 } 2038 else if (f->deps != 0)2049 else if (this != 0) 2039 2050 { 2040 2051 /* Add the file's old deps and the new ones in THIS together. */ 2041 2052 2042 struct dep *firstdeps, *moredeps; 2043 if (cmds != 0) 2044 { 2045 /* This is the rule with commands, so put its deps first. 2046 The rationale behind this is that $< expands to the 2047 first dep in the chain, and commands use $< expecting 2048 to get the dep that rule specifies. */ 2049 firstdeps = this; 2050 moredeps = f->deps; 2051 } 2052 else 2053 { 2054 /* Append the new deps to the old ones. */ 2055 firstdeps = f->deps; 2056 moredeps = this; 2057 } 2058 2059 if (firstdeps == 0) 2060 firstdeps = moredeps; 2061 else 2062 { 2063 d = firstdeps; 2064 while (d->next != 0) 2065 d = d->next; 2066 d->next = moredeps; 2067 } 2068 2069 f->deps = firstdeps; 2053 if (f->deps != 0) 2054 { 2055 struct dep **d_ptr = &f->deps; 2056 2057 while ((*d_ptr)->next != 0) 2058 d_ptr = &(*d_ptr)->next; 2059 2060 if (cmds != 0) 2061 { 2062 /* This is the rule with commands, so put its deps 2063 last. The rationale behind this is that $< expands 2064 to the first dep in the chain, and commands use $< 2065 expecting to get the dep that rule specifies. 2066 However the second expansion algorithm reverses 2067 the order thus we need to make it last here. */ 2068 2069 (*d_ptr)->next = this; 2070 } 2071 else 2072 { 2073 /* This is the rule without commands. Put its 2074 dependencies at the end but before dependencies 2075 from the rule with commands (if any). This way 2076 everything appears in makefile order. */ 2077 2078 if (f->cmds != 0) 2079 { 2080 this->next = *d_ptr; 2081 *d_ptr = this; 2082 } 2083 else 2084 (*d_ptr)->next = this; 2085 } 2086 } 2087 else 2088 f->deps = this; 2089 2090 /* This is a hack. I need a way to communicate to snap_deps() 2091 that the last dependency line in this file came with commands 2092 (so that logic in snap_deps() can put it in front and all 2093 this $< -logic works). I cannot simply rely on file->cmds 2094 being not 0 because of the cases like the following: 2095 2096 foo: bar 2097 foo: 2098 ... 2099 2100 I am going to temporarily "borrow" UPDATING member in 2101 `struct file' for this. */ 2102 2103 if (cmds != 0) 2104 f->updating = 1; 2070 2105 } 2071 else2072 f->deps = this;2073 2106 2074 2107 /* If this is a static pattern rule, set the file's stem to … … 2080 2113 char *buffer = variable_expand (""); 2081 2114 char *o = patsubst_expand (buffer, name, pattern, percent, 2082 pattern_percent , percent);2115 pattern_percent+1, percent+1); 2083 2116 f->stem = savestring (buffer, o - buffer); 2084 2117 } … … 2116 2149 } 2117 2150 2118 /* See if this is first target seen whose name does 2119 not start with a `.', unless it contains a slash. */ 2120 if (default_goal_file == 0 && set_default 2121 && (*name != '.' || strchr (name, '/') != 0 2122 #ifdef HAVE_DOS_PATHS 2123 || strchr (name, '\\') != 0 2124 #endif 2125 )) 2126 { 2127 int reject = 0; 2128 2129 /* If this file is a suffix, don't 2130 let it be the default goal file. */ 2131 2132 for (d = suffix_file->deps; d != 0; d = d->next) 2133 { 2134 register struct dep *d2; 2135 if (*dep_name (d) != '.' && streq (name, dep_name (d))) 2136 { 2137 reject = 1; 2138 break; 2139 } 2140 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) 2141 { 2142 register unsigned int len = strlen (dep_name (d2)); 2143 if (!strneq (name, dep_name (d2), len)) 2144 continue; 2145 if (streq (name + len, dep_name (d))) 2146 { 2147 reject = 1; 2148 break; 2149 } 2150 } 2151 if (reject) 2152 break; 2153 } 2154 2155 if (!reject) 2156 default_goal_file = f; 2157 } 2151 /* If this target is a default target, update DEFAULT_GOAL_FILE. */ 2152 if (strcmp (*default_goal_name, name) == 0 2153 && (default_goal_file == 0 2154 || strcmp (default_goal_file->name, name) != 0)) 2155 default_goal_file = f; 2158 2156 } 2159 2157 … … 2179 2177 unsigned int string_len = 0; 2180 2178 register char *p = string; 2179 register int ch; 2181 2180 2182 2181 while (1) 2183 2182 { 2184 2183 if (stop2 && blank) 2185 while ( *p != '\0' && *p != stop1 && *p!= stop22186 && ! isblank ((unsigned char) *p))2184 while ((ch = *p) != '\0' && ch != stop1 && ch != stop2 2185 && ! isblank ((unsigned char) ch)) 2187 2186 ++p; 2188 2187 else if (stop2) 2189 while ( *p != '\0' && *p != stop1 && *p!= stop2)2188 while ((ch = *p) != '\0' && ch != stop1 && ch != stop2) 2190 2189 ++p; 2191 2190 else if (blank) 2192 while ( *p != '\0' && *p!= stop12193 && ! isblank ((unsigned char) *p))2191 while ((ch = *p) != '\0' && ch != stop1 2192 && ! isblank ((unsigned char) ch)) 2194 2193 ++p; 2195 2194 else 2196 while ( *p != '\0' && *p!= stop1)2195 while ((ch = *p) != '\0' && ch != stop1) 2197 2196 ++p; 2198 2197 2199 if ( *p== '\0')2198 if (ch == '\0') 2200 2199 break; 2201 2200 … … 2499 2498 readstring (struct ebuffer *ebuf) 2500 2499 { 2501 char * p;2500 char *eol; 2502 2501 2503 2502 /* If there is nothing left in this buffer, return 0. */ 2504 if (ebuf->bufnext > ebuf->bufstart + ebuf->size)2503 if (ebuf->bufnext >= ebuf->bufstart + ebuf->size) 2505 2504 return -1; 2506 2505 … … 2508 2507 next logical line (taking into account backslash/newline pairs). */ 2509 2508 2510 p= ebuf->buffer = ebuf->bufnext;2509 eol = ebuf->buffer = ebuf->bufnext; 2511 2510 2512 2511 while (1) 2513 2512 { 2514 2513 int backslash = 0; 2515 2516 /* Find the next newline. Keep track of backslashes as we look. */ 2517 for (; *p != '\n' && *p != '\0'; ++p) 2518 if (*p == '\\') 2519 backslash = !backslash; 2520 2521 /* If we got to the end of the string or a newline with no backslash, 2522 we're done. */ 2523 if (*p == '\0' || !backslash) 2514 char *bol = eol; 2515 char *p; 2516 2517 /* Find the next newline. At EOS, stop. */ 2518 eol = p = strchr (eol , '\n'); 2519 if (!eol) 2520 { 2521 ebuf->bufnext = ebuf->bufstart + ebuf->size + 1; 2522 return 0; 2523 } 2524 2525 /* Found a newline; if it's escaped continue; else we're done. */ 2526 while (p > bol && *(--p) == '\\') 2527 backslash = !backslash; 2528 if (!backslash) 2524 2529 break; 2530 ++eol; 2525 2531 } 2526 2532 2527 2533 /* Overwrite the newline char. */ 2528 * p= '\0';2529 ebuf->bufnext = p+1;2534 *eol = '\0'; 2535 ebuf->bufnext = eol+1; 2530 2536 2531 2537 return 0; -
trunk/src/gmake/remake.c
r218 r287 75 75 /* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing 76 76 was done, 0 if all goals were updated successfully, or 1 if a goal failed. 77 If MAKEFILES is nonzero, these goals are makefiles, so -t, -q, and -n should 78 be disabled for them unless they were also command-line targets, and we 79 should only make one goal at a time and return as soon as one goal whose 80 `changed' member is nonzero is successfully made. */ 77 78 If rebuilding_makefiles is nonzero, these goals are makefiles, so -t, -q, 79 and -n should be disabled for them unless they were also command-line 80 targets, and we should only make one goal at a time and return as soon as 81 one goal whose `changed' member is nonzero is successfully made. */ 81 82 82 83 int 83 update_goal_chain (struct dep *goals , int makefiles)84 update_goal_chain (struct dep *goals) 84 85 { 85 86 int t = touch_flag, q = question_flag, n = just_print_flag; … … 87 88 int status = -1; 88 89 89 #define MTIME(file) ( makefiles ? file_mtime_no_search (file) \90 #define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \ 90 91 : file_mtime (file)) 91 92 … … 137 138 int x; 138 139 check_renamed (file); 139 if ( makefiles)140 if (rebuilding_makefiles) 140 141 { 141 142 if (file->cmd_target) … … 154 155 ocommands_started = commands_started; 155 156 156 x = update_file (file, makefiles ? 1 : 0);157 x = update_file (file, rebuilding_makefiles ? 1 : 0); 157 158 check_renamed (file); 158 159 … … 177 178 matter how much more we run, since we already know 178 179 the answer to return. */ 179 stop = ( !keep_going_flag && !question_flag180 && ! makefiles);180 stop = (question_flag && !keep_going_flag 181 && !rebuilding_makefiles); 181 182 } 182 183 else … … 194 195 If STATUS is changed, we will get re-exec'd, and 195 196 enter an infinite loop. */ 196 if (! makefiles197 if (!rebuilding_makefiles 197 198 || (!just_print_flag && !question_flag)) 198 199 status = 0; 199 if ( makefiles && file->dontcare)200 if (rebuilding_makefiles && file->dontcare) 200 201 /* This is a default makefile; stop remaking. */ 201 202 stop = 1; … … 220 221 print a message saying nothing needs doing. */ 221 222 222 if (! makefiles223 if (!rebuilding_makefiles 223 224 /* If the update_status is zero, we updated successfully 224 225 or not at all. G->changed will have been set above if … … 259 260 } 260 261 261 if ( makefiles)262 if (rebuilding_makefiles) 262 263 { 263 264 touch_flag = t; … … 309 310 check_renamed (f); 310 311 312 /* If we got an error, don't bother with double_colon etc. */ 311 313 if (status != 0 && !keep_going_flag) 312 break;314 return status; 313 315 314 316 if (f->command_state == cs_running … … 324 326 /* Process the remaining rules in the double colon chain so they're marked 325 327 considered. Start their prerequisites, too. */ 326 for (; f != 0 ; f = f->prev) 327 { 328 struct dep *d; 329 330 f->considered = considered; 331 332 for (d = f->deps; d != 0; d = d->next) 333 status |= update_file (d->file, depth + 1); 334 } 328 if (file->double_colon) 329 for (; f != 0 ; f = f->prev) 330 { 331 struct dep *d; 332 333 f->considered = considered; 334 335 for (d = f->deps; d != 0; d = d->next) 336 status |= update_file (d->file, depth + 1); 337 } 335 338 336 339 return status; 337 340 } 338 341 342 343 /* Show a message stating the target failed to build. */ 344 345 static void 346 complain (const struct file *file) 347 { 348 const char *msg_noparent 349 = _("%sNo rule to make target `%s'%s"); 350 const char *msg_parent 351 = _("%sNo rule to make target `%s', needed by `%s'%s"); 352 353 if (!keep_going_flag) 354 { 355 if (file->parent == 0) 356 fatal (NILF, msg_noparent, "", file->name, ""); 357 358 fatal (NILF, msg_parent, "", file->name, file->parent->name, ""); 359 } 360 361 if (file->parent == 0) 362 error (NILF, msg_noparent, "*** ", file->name, "."); 363 else 364 error (NILF, msg_parent, "*** ", file->name, file->parent->name, "."); 365 } 339 366 340 367 /* Consider a single `struct file' and update it as appropriate. */ … … 357 384 DBF (DB_VERBOSE, 358 385 _("Recently tried and failed to update file `%s'.\n")); 386 387 /* If the file we tried to make is marked dontcare then no message 388 was printed about it when it failed during the makefile rebuild. 389 If we're trying to build it again in the normal rebuild, print a 390 message now. */ 391 if (file->dontcare && !rebuilding_makefiles) 392 { 393 file->dontcare = 0; 394 complain (file); 395 } 396 359 397 return file->update_status; 360 398 } … … 435 473 FILE_TIMESTAMP mtime; 436 474 int maybe_make; 475 int dontcare = 0; 437 476 438 477 check_renamed (d->file); … … 458 497 d->file->parent = file; 459 498 maybe_make = must_make; 499 500 /* Inherit dontcare flag from our parent. */ 501 if (rebuilding_makefiles) 502 { 503 dontcare = d->file->dontcare; 504 d->file->dontcare = file->dontcare; 505 } 506 507 460 508 dep_status |= check_dep (d->file, depth, this_mtime, &maybe_make); 509 510 /* Restore original dontcare flag. */ 511 if (rebuilding_makefiles) 512 d->file->dontcare = dontcare; 513 461 514 if (! d->ignore_mtime) 462 515 must_make = maybe_make; … … 495 548 if (d->file->intermediate) 496 549 { 550 int dontcare = 0; 551 497 552 FILE_TIMESTAMP mtime = file_mtime (d->file); 498 553 check_renamed (d->file); 499 554 d->file->parent = file; 555 556 /* Inherit dontcare flag from our parent. */ 557 if (rebuilding_makefiles) 558 { 559 dontcare = d->file->dontcare; 560 d->file->dontcare = file->dontcare; 561 } 562 563 500 564 dep_status |= update_file (d->file, depth); 565 566 /* Restore original dontcare flag. */ 567 if (rebuilding_makefiles) 568 d->file->dontcare = dontcare; 569 501 570 check_renamed (d->file); 502 571 … … 856 925 start_updating (file); 857 926 858 if ( !file->intermediate)859 /* If this is a non-intermediate file, update it and record860 whether it is newer than THIS_MTIME. */861 {927 if (file->phony || !file->intermediate) 928 { 929 /* If this is a non-intermediate file, update it and record 930 whether it is newer than THIS_MTIME. */ 862 931 FILE_TIMESTAMP mtime; 863 932 dep_status = update_file (file, depth); … … 1026 1095 else 1027 1096 { 1028 const char *msg_noparent1029 = _("%sNo rule to make target `%s'%s");1030 const char *msg_parent1031 = _("%sNo rule to make target `%s', needed by `%s'%s");1032 1033 1097 /* This is a dependency file we cannot remake. Fail. */ 1034 if (!keep_going_flag && !file->dontcare) 1035 { 1036 if (file->parent == 0) 1037 fatal (NILF, msg_noparent, "", file->name, ""); 1038 1039 fatal (NILF, msg_parent, "", file->name, file->parent->name, ""); 1040 } 1041 1042 if (!file->dontcare) 1043 { 1044 if (file->parent == 0) 1045 error (NILF, msg_noparent, "*** ", file->name, "."); 1046 else 1047 error (NILF, msg_parent, "*** ", 1048 file->name, file->parent->name, "."); 1049 } 1098 if (!rebuilding_makefiles || !file->dontcare) 1099 complain (file); 1050 1100 file->update_status = 2; 1051 1101 } … … 1283 1333 /* Return the mtime of the file or archive-member reference NAME. */ 1284 1334 1335 /* First, we check with stat(). If the file does not exist, then we return 1336 NONEXISTENT_MTIME. If it does, and the symlink check flag is set, then 1337 examine each indirection of the symlink and find the newest mtime. 1338 This causes one duplicate stat() when -L is being used, but the code is 1339 much cleaner. */ 1340 1285 1341 static FILE_TIMESTAMP 1286 1342 name_mtime (char *name) 1287 1343 { 1344 FILE_TIMESTAMP mtime; 1288 1345 struct stat st; 1289 1346 int e; … … 1293 1350 { 1294 1351 if (errno != ENOENT && errno != ENOTDIR) 1295 perror_with_name ("stat: ", name);1352 perror_with_name ("stat: ", name); 1296 1353 return NONEXISTENT_MTIME; 1297 1354 } 1298 1299 return FILE_TIMESTAMP_STAT_MODTIME (name, st); 1355 mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st); 1356 1357 #ifdef MAKE_SYMLINKS 1358 #ifndef S_ISLNK 1359 # define S_ISLNK(_m) (((_m)&S_IFMT)==S_IFLNK) 1360 #endif 1361 if (check_symlink_flag) 1362 { 1363 PATH_VAR (lpath); 1364 1365 /* Check each symbolic link segment (if any). Find the latest mtime 1366 amongst all of them (and the target file of course). 1367 Note that we have already successfully dereferenced all the links 1368 above. So, if we run into any error trying to lstat(), or 1369 readlink(), or whatever, something bizarre-o happened. Just give up 1370 and use whatever mtime we've already computed at that point. */ 1371 strcpy (lpath, name); 1372 while (1) 1373 { 1374 FILE_TIMESTAMP ltime; 1375 PATH_VAR (lbuf); 1376 long llen; 1377 char *p; 1378 1379 EINTRLOOP (e, lstat (lpath, &st)); 1380 if (e) 1381 { 1382 /* Eh? Just take what we have. */ 1383 perror_with_name ("lstat: ", lpath); 1384 break; 1385 } 1386 1387 /* If this is not a symlink, we're done (we started with the real 1388 file's mtime so we don't need to test it again). */ 1389 if (!S_ISLNK (st.st_mode)) 1390 break; 1391 1392 /* If this mtime is newer than what we had, keep the new one. */ 1393 ltime = FILE_TIMESTAMP_STAT_MODTIME (lpath, st); 1394 if (ltime > mtime) 1395 mtime = ltime; 1396 1397 /* Set up to check the file pointed to by this link. */ 1398 EINTRLOOP (llen, readlink (lpath, lbuf, GET_PATH_MAX)); 1399 if (llen < 0) 1400 { 1401 /* Eh? Just take what we have. */ 1402 perror_with_name ("readlink: ", lpath); 1403 break; 1404 } 1405 lbuf[llen] = '\0'; 1406 1407 /* If the target is fully-qualified or the source is just a 1408 filename, then the new path is the target. Otherwise it's the 1409 source directory plus the target. */ 1410 if (lbuf[0] == '/' || (p = strrchr (lpath, '/')) == NULL) 1411 strcpy (lpath, lbuf); 1412 else if ((p - lpath) + llen + 2 > GET_PATH_MAX) 1413 /* Eh? Path too long! Again, just go with what we have. */ 1414 break; 1415 else 1416 /* Create the next step in the symlink chain. */ 1417 strcpy (p+1, lbuf); 1418 } 1419 } 1420 #endif 1421 1422 return mtime; 1300 1423 } 1301 1424 -
trunk/src/gmake/variable.c
r225 r287 500 500 501 501 do 502 /* We found one, so insert it into the set. */ 503 do_variable_definition (&p->variable.fileinfo, p->variable.name, 504 p->variable.value, p->variable.origin, 505 p->variable.flavor, 1); 502 { 503 /* We found one, so insert it into the set. */ 504 505 struct variable *v; 506 507 if (p->variable.flavor == f_simple) 508 { 509 v = define_variable_loc ( 510 p->variable.name, strlen (p->variable.name), 511 p->variable.value, p->variable.origin, 512 0, &p->variable.fileinfo); 513 514 v->flavor = f_simple; 515 } 516 else 517 { 518 v = do_variable_definition ( 519 &p->variable.fileinfo, p->variable.name, 520 p->variable.value, p->variable.origin, 521 p->variable.flavor, 1); 522 } 523 524 /* Also mark it as a per-target and copy export status. */ 525 v->per_target = p->variable.per_target; 526 v->export = p->variable.export; 527 } 506 528 while ((p = lookup_pattern_var (p, file->name)) != 0); 507 529 … … 735 757 #endif 736 758 737 /* This won't override any definition, but it 738 will provide one if thereisn't one there. */759 /* This won't override any definition, but it will provide one if there 760 isn't one there. */ 739 761 v = define_variable ("SHELL", 5, default_shell, o_default, 0); 740 v->export = v_export; /* Always export SHELL. */ 741 742 /* On MSDOS we do use SHELL from environment, since 743 it isn't a standard environment variable on MSDOS, 744 so whoever sets it, does that on purpose. 745 On OS/2 we do not use SHELL from environment but 746 we have already handled that problem above. */ 762 763 /* On MSDOS we do use SHELL from environment, since it isn't a standard 764 environment variable on MSDOS, so whoever sets it, does that on purpose. 765 On OS/2 we do not use SHELL from environment but we have already handled 766 that problem above. */ 747 767 #if !defined(__MSDOS__) && !defined(__EMX__) 748 768 /* Don't let SHELL come from the environment. */ … … 862 882 863 883 case v_noexport: 864 continue; 884 /* If this is the SHELL variable and it's not exported, then 885 add the value from our original environment. */ 886 if (streq (v->name, "SHELL")) 887 { 888 extern struct variable shell_var; 889 v = &shell_var; 890 break; 891 } 892 continue; 865 893 866 894 case v_ifset: … … 977 1005 v = lookup_variable_in_set (varname, strlen (varname), 978 1006 current_variable_set_list->set); 1007 1008 /* Don't append from the global set if a previous non-appending 1009 target-specific variable definition exists. */ 1010 if (v && !v->append) 1011 append = 0; 979 1012 } 980 1013 else … … 1035 1068 && strcmp (varname, "SHELL") == 0) 1036 1069 { 1037 char shellpath[PATH_MAX];1070 PATH_VAR (shellpath); 1038 1071 extern char * __dosexec_find_on_path (const char *, char *[], char *); 1039 1072 … … 1420 1453 sync_Path_environment (void) 1421 1454 { 1422 char *path = allocated_variable_expand ("$(P ath)");1455 char *path = allocated_variable_expand ("$(PATH)"); 1423 1456 static char *environ_path = NULL; 1424 1457 … … 1437 1470 */ 1438 1471 convert_Path_to_windows32 (path, ';'); 1439 environ_path = concat ("P ath", "=", path);1472 environ_path = concat ("PATH", "=", path); 1440 1473 putenv (environ_path); 1441 1474 free (path);
Note:
See TracChangeset
for help on using the changeset viewer.