Changeset 503 in kBuild for trunk/src/gmake/implicit.c
- Timestamp:
- Sep 15, 2006 5:09:38 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/implicit.c
r281 r503 1 1 /* Implicit rule searching for GNU Make. 2 Copyright (C) 1988,1989,1990,1991,1992,1993,1994,1997,2000,2004,2005 Free Software Foundation, Inc. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 4 Foundation, Inc. 3 5 This file is part of GNU Make. 4 6 5 GNU Make is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2, or (at your option) 8 any later version. 9 10 GNU Make is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with GNU Make; see the file COPYING. If not, write to 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 Boston, MA 02111-1307, USA. */ 7 GNU Make is free software; you can redistribute it and/or modify it under the 8 terms of the GNU General Public License as published by the Free Software 9 Foundation; either version 2, or (at your option) any later version. 10 11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 13 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along with 16 GNU Make; see the file COPYING. If not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 19 18 20 19 #include "make.h" … … 81 80 82 81 static void 83 free_idep_chain (struct idep *p)82 free_idep_chain (struct idep *p) 84 83 { 85 register struct idep* n; 86 register struct file *f; 84 struct idep *n; 87 85 88 86 for (; p != 0; p = n) … … 92 90 if (p->name) 93 91 { 92 struct file *f = p->intermediate_file; 93 94 if (f != 0 95 && (f->stem < f->name || f->stem > f->name + strlen (f->name))) 96 free (f->stem); 97 94 98 free (p->name); 95 96 f = p->intermediate_file;97 98 if (f != 099 && (f->stem < f->name100 || f->stem > f->name + strlen (f->name)))101 free (f->stem);102 99 } 103 100 … … 264 261 int specific_rule_matched = 0; 265 262 266 registerunsigned int i = 0; /* uninit checks OK */267 registerstruct rule *rule;268 registerstruct dep *dep, *expl_d;263 unsigned int i = 0; /* uninit checks OK */ 264 struct rule *rule; 265 struct dep *dep, *expl_d; 269 266 270 267 char *p, *vname; … … 350 347 prefix and the target pattern does not contain a slash. */ 351 348 349 check_lastslash = 0; 350 if (lastslash) 351 { 352 352 #ifdef VMS 353 check_lastslash = lastslash != 0 354 && ((strchr (target, ']') == 0) 355 && (strchr (target, ':') == 0)); 353 check_lastslash = (strchr (target, ']') == 0 354 && strchr (target, ':') == 0); 356 355 #else 357 check_lastslash = lastslash != 0 && strchr (target, '/') == 0; 356 check_lastslash = strchr (target, '/') == 0; 357 #ifdef HAVE_DOS_PATHS 358 /* Didn't find it yet: check for DOS-type directories. */ 359 if (check_lastslash) 360 { 361 char *b = strchr (target, '\\'); 362 check_lastslash = !(b || (target[0] && target[1] == ':')); 363 } 358 364 #endif 365 #endif 366 } 359 367 if (check_lastslash) 360 368 { 361 /* In that case, don't include the 362 directory prefix in STEM here. */ 369 /* If so, don't include the directory prefix in STEM here. */ 363 370 unsigned int difference = lastslash - filename + 1; 364 371 if (difference > stemlen) … … 437 444 unsigned int failed = 0; 438 445 int check_lastslash; 446 int file_variables_set = 0; 439 447 440 448 rule = tryrules[i]; … … 474 482 stem_str[stemlen] = '\0'; 475 483 476 /* Temporary assign STEM to file->stem and set file variables. */ 484 /* Temporary assign STEM to file->stem (needed to set file 485 variables below). */ 477 486 file->stem = stem_str; 478 set_file_variables (file);479 487 480 488 /* Try each dependency; see if it "exists". */ 481 482 /* @@ There is always only one dep line for any given implicit483 rule. So the loop is not necessary. Can rule->deps be 0?484 485 Watch out for conversion of suffix rules to implicit rules.486 */487 489 488 490 for (dep = rule->deps; dep != 0; dep = dep->next) … … 493 495 494 496 /* In an ideal world we would take the dependency line, 495 substitute the stem, re-expand the whole line and 496 chop it into individual prerequisites. Unfortunately497 this won't work because of the "check_lastslash" twist.498 Instead, we will have to go word by word, taking $()'s499 into account, for each word we will substitute the stem,500 re-expand, chop it up, and, if check_lastslash != 0,501 add the directory part to eachresulting prerequisite. */497 substitute the stem, re-expand the whole line and chop it 498 into individual prerequisites. Unfortunately this won't work 499 because of the "check_lastslash" twist. Instead, we will 500 have to go word by word, taking $()'s into account, for each 501 word we will substitute the stem, re-expand, chop it up, and, 502 if check_lastslash != 0, add the directory part to each 503 resulting prerequisite. */ 502 504 503 505 p = get_next_word (dep->name, &len); … … 511 513 break; /* No more words */ 512 514 513 /* If the dependency name has %, substitute the stem. 514 Watch out, we are going to do something tricky here. If 515 we just replace % with the stem value, later, when we do 516 the second expansion, we will re-expand this stem value 517 once again. This is not good especially if you have 518 certain characters in your setm (like $). 519 520 Instead, we will replace % with $* and allow the second 521 expansion to take care of it for us. This way (since $* 522 is a simple variable) there won't be additional 523 re-expansion of the stem. */ 515 /* Is there a pattern in this prerequisite? */ 524 516 525 517 for (p2 = p; p2 < p + len && *p2 != '%'; ++p2) 526 518 ; 527 519 528 if ( p2 < p + len)520 if (dep->need_2nd_expansion) 529 521 { 530 register unsigned int i = p2 - p; 531 bcopy (p, depname, i); 532 bcopy ("$*", depname + i, 2); 533 bcopy (p2 + 1, depname + i + 2, len - i - 1); 534 depname[len + 2 - 1] = '\0'; 535 536 if (check_lastslash) 537 add_dir = 1; 538 539 had_stem = 1; 522 /* If the dependency name has %, substitute the stem. 523 524 Watch out, we are going to do something tricky 525 here. If we just replace % with the stem value, 526 later, when we do the second expansion, we will 527 re-expand this stem value once again. This is not 528 good especially if you have certain characters in 529 your stem (like $). 530 531 Instead, we will replace % with $* and allow the 532 second expansion to take care of it for us. This way 533 (since $* is a simple variable) there won't be 534 additional re-expansion of the stem. */ 535 536 if (p2 < p + len) 537 { 538 register unsigned int i = p2 - p; 539 bcopy (p, depname, i); 540 bcopy ("$*", depname + i, 2); 541 bcopy (p2 + 1, depname + i + 2, len - i - 1); 542 depname[len + 2 - 1] = '\0'; 543 544 if (check_lastslash) 545 add_dir = 1; 546 547 had_stem = 1; 548 } 549 else 550 { 551 bcopy (p, depname, len); 552 depname[len] = '\0'; 553 } 554 555 /* Set file variables. Note that we cannot do it once 556 at the beginning of the function because of the stem 557 value. */ 558 if (!file_variables_set) 559 { 560 set_file_variables (file); 561 file_variables_set = 1; 562 } 563 564 p2 = variable_expand_for_file (depname, file); 540 565 } 541 566 else 542 567 { 543 bcopy (p, depname, len); 544 depname[len] = '\0'; 568 if (p2 < p + len) 569 { 570 register unsigned int i = p2 - p; 571 bcopy (p, depname, i); 572 bcopy (stem_str, depname + i, stemlen); 573 bcopy (p2 + 1, depname + i + stemlen, len - i - 1); 574 depname[len + stemlen - 1] = '\0'; 575 576 if (check_lastslash) 577 add_dir = 1; 578 579 had_stem = 1; 580 } 581 else 582 { 583 bcopy (p, depname, len); 584 depname[len] = '\0'; 585 } 586 587 p2 = depname; 545 588 } 546 547 p2 = variable_expand_for_file (depname, file);548 589 549 590 /* Parse the dependencies. */ … … 564 605 565 606 /* @@ It would be nice to teach parse_file_seq or 566 multi_glob to add prefix. This would save us 567 somereallocations. */607 multi_glob to add prefix. This would save us some 608 reallocations. */ 568 609 569 610 if (order_only || add_dir || had_stem) … … 621 662 if (file_impossible_p (name)) 622 663 { 623 /* If this dependency has already been ruled 624 "impossible", then the rule fails and don't 625 bother trying it on the second pass either 626 since we know that will fail too. */ 664 /* If this dependency has already been ruled "impossible", 665 then the rule fails and don't bother trying it on the 666 second pass either since we know that will fail too. */ 627 667 DBS (DB_IMPLICIT, 628 668 (d->had_stem … … 641 681 : _("Trying rule prerequisite `%s'.\n"), name)); 642 682 643 /* If this prerequisite also happened to be explicitly 644 mentioned for FILE skip all the test below since it 645 it has to be built anyway, no matter which implicit 646 rule we choose. */ 683 /* If this prerequisite also happened to be explicitly mentioned 684 for FILE skip all the test below since it it has to be built 685 anyway, no matter which implicit rule we choose. */ 647 686 648 687 for (expl_d = file->deps; expl_d != 0; expl_d = expl_d->next) 649 if (str cmp (dep_name (expl_d), name) == 0) break;650 688 if (streq (dep_name (expl_d), name)) 689 break; 651 690 if (expl_d != 0) 652 691 continue; 653 654 655 692 656 693 /* The DEP->changed flag says that this dependency resides in a … … 665 702 /*|| ((!dep->changed || check_lastslash) && */ 666 703 || file_exists_p (name)) 667 { 668 continue; 669 } 704 continue; 670 705 671 706 /* This code, given FILENAME = "lib/foo.o", dependency name … … 684 719 685 720 686 /* We could not find the file in any place we should look. 687 Try to make this dependency as an intermediate file,688 but only onthe second pass. */721 /* We could not find the file in any place we should look. Try 722 to make this dependency as an intermediate file, but only on 723 the second pass. */ 689 724 690 725 if (intermed_ok) … … 717 752 file and failed, mark that name as impossible 718 753 so we won't go through the search again later. */ 754 if (intermediate_file->variables) 755 free_variable_set (intermediate_file->variables); 719 756 file_impossible (name); 720 757 } … … 777 814 { 778 815 struct dep *next = dep->next; 779 free (dep->name); 780 free ((char *)dep); 816 free_dep (dep); 781 817 dep = next; 782 818 } … … 837 873 } 838 874 839 dep = (struct dep *) xmalloc (sizeof (struct dep));875 dep = alloc_dep (); 840 876 dep->ignore_mtime = d->ignore_mtime; 841 dep->need_2nd_expansion = 0;842 877 s = d->name; /* Hijacking the name. */ 843 878 d->name = 0; 844 879 if (recursions == 0) 845 880 { 846 dep->name = 0;847 881 dep->file = lookup_file (s); 848 882 if (dep->file == 0) … … 857 891 { 858 892 dep->name = s; 859 dep->file = 0;860 dep->changed = 0;861 893 } 894 862 895 if (d->intermediate_file == 0 && tryrules[foundrule]->terminal) 863 896 { … … 902 935 file->is_target = 1; 903 936 937 /* Set precious flag. */ 938 { 939 struct file *f = lookup_file (rule->targets[matches[foundrule]]); 940 if (f && f->precious) 941 file->precious = 1; 942 } 943 904 944 /* If this rule builds other targets, too, put the others into FILE's 905 945 `also_make' member. */ … … 909 949 if (i != matches[foundrule]) 910 950 { 911 struct dep *new = (struct dep *) xmalloc (sizeof (struct dep)); 951 struct file *f; 952 struct dep *new = alloc_dep (); 953 912 954 /* GKM FIMXE: handle '|' here too */ 913 new->ignore_mtime = 0;914 new->need_2nd_expansion = 0;915 955 new->name = p = (char *) xmalloc (rule->lens[i] + fullstemlen + 1); 916 956 bcopy (rule->targets[i], p, … … 923 963 new->file = enter_file (new->name); 924 964 new->next = file->also_make; 965 966 /* Set precious flag. */ 967 f = lookup_file (rule->targets[i]); 968 if (f && f->precious) 969 new->file->precious = 1; 970 971 /* Set the is_target flag so that this file is not treated 972 as intermediate by the pattern rule search algorithm and 973 file_exists_p cannot pick it up yet. */ 974 new->file->is_target = 1; 975 925 976 file->also_make = new; 926 977 }
Note:
See TracChangeset
for help on using the changeset viewer.