Changeset 503 for trunk/src/gmake/file.c
- Timestamp:
- Sep 15, 2006, 7:09:38 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/file.c
r429 r503 1 /* Target file hash tablemanagement for GNU Make.1 /* Target file management for GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 2002 Free Software Foundation, Inc. 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 4 Foundation, Inc. 4 5 This file is part of GNU Make. 5 6 6 GNU Make is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Make is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Make; see the file COPYING. If not, write to 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 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. */ 20 18 21 19 #include "make.h" … … 91 89 #ifdef VMS 92 90 # ifndef WANT_CASE_SENSITIVE_TARGETS 93 { 94 register char *n; 95 lname = (char *) malloc (strlen (name) + 1); 96 for (n = name, ln = lname; *n != '\0'; ++n, ++ln) 97 *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n; 98 *ln = '\0'; 99 name = lname; 100 } 91 if (*name != '.') 92 { 93 register char *n; 94 lname = (char *) malloc (strlen (name) + 1); 95 for (n = name, ln = lname; *n != '\0'; ++n, ++ln) 96 *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n; 97 *ln = '\0'; 98 name = lname; 99 } 101 100 # endif 102 101 … … 127 126 f = (struct file *) hash_find_item (&files, &file_key); 128 127 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 129 free (lname); 128 if (*name != '.') 129 free (lname); 130 130 #endif 131 131 return f; … … 146 146 147 147 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 148 { 149 register char *n; 150 lname = (char *) malloc (strlen (name) + 1); 151 for (n = name, ln = lname; *n != '\0'; ++n, ++ln) 152 { 153 if (isupper ((unsigned char)*n)) 154 *ln = tolower ((unsigned char)*n); 155 else 156 *ln = *n; 157 } 158 159 *ln = 0; 160 /* Creates a possible leak, old value of name is unreachable, but I 161 currently don't know how to fix it. */ 162 name = lname; 163 } 148 if (*name != '.') 149 { 150 register char *n; 151 lname = (char *) malloc (strlen (name) + 1); 152 for (n = name, ln = lname; *n != '\0'; ++n, ++ln) 153 { 154 if (isupper ((unsigned char)*n)) 155 *ln = tolower ((unsigned char)*n); 156 else 157 *ln = *n; 158 } 159 160 *ln = 0; 161 /* Creates a possible leak, old value of name is unreachable, but I 162 currently don't know how to fix it. */ 163 name = lname; 164 } 164 165 #endif 165 166 … … 170 171 { 171 172 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 172 free(lname); 173 if (*name != '.') 174 free (lname); 173 175 #endif 174 176 return f; … … 181 183 182 184 if (HASH_VACANT (f)) 183 hash_insert_at (&files, new, file_slot); 185 { 186 new->last = new; 187 hash_insert_at (&files, new, file_slot); 188 } 184 189 else 185 190 { 186 191 /* There is already a double-colon entry for this file. */ 187 192 new->double_colon = f; 188 while (f->prev != 0) 189 f = f->prev; 190 f->prev = new; 193 f->last->prev = new; 194 f->last = new; 191 195 } 192 196 … … 409 413 410 414 415 struct dep * 416 parse_prereqs (char *p) 417 { 418 struct dep *new = (struct dep *) 419 multi_glob (parse_file_seq (&p, '|', sizeof (struct dep), 1), 420 sizeof (struct dep)); 421 422 if (*p) 423 { 424 /* Files that follow '|' are "order-only" prerequisites that satisfy the 425 dependency by existing: their modification times are irrelevant. */ 426 struct dep *ood; 427 428 ++p; 429 ood = (struct dep *) 430 multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1), 431 sizeof (struct dep)); 432 433 if (! new) 434 new = ood; 435 else 436 { 437 struct dep *dp; 438 for (dp = new; dp->next != NULL; dp = dp->next) 439 ; 440 dp->next = ood; 441 } 442 443 for (; ood != NULL; ood = ood->next) 444 ood->ignore_mtime = 1; 445 } 446 447 return new; 448 } 449 450 411 451 /* Set the intermediate flag. */ 412 452 … … 422 462 expand_deps (struct file *f) 423 463 { 424 struct dep *d, *d1; 425 struct dep *new = 0; 464 struct dep *d; 426 465 struct dep *old = f->deps; 466 char *file_stem = f->stem; 427 467 unsigned int last_dep_has_cmds = f->updating; 428 468 int initialized = 0; … … 433 473 for (d = old; d != 0; d = d->next) 434 474 { 435 if (d->name != 0) 475 struct dep *new, *d1; 476 char *p; 477 478 if (! d->name) 479 continue; 480 481 /* Create the dependency list. 482 If we're not doing 2nd expansion, then it's just the name. */ 483 if (! d->need_2nd_expansion) 484 p = d->name; 485 else 436 486 { 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; 487 /* If it's from a static pattern rule, convert the patterns into 488 "$*" so they'll expand properly. */ 489 if (d->staticpattern) 490 { 491 char *o; 492 char *buffer = variable_expand (""); 493 494 o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0); 495 496 free (d->name); 497 d->name = savestring (buffer, o - buffer); 498 d->staticpattern = 0; /* Clear staticpattern so that we don't 499 re-expand %s below. */ 500 } 501 502 /* We are going to do second expansion so initialize file variables 503 for the file. Since the stem for static pattern rules comes from 504 individual dep lines, we will temporarily set f->stem to d->stem. 505 */ 506 if (!initialized) 507 { 508 initialize_file_variables (f, 0); 509 initialized = 1; 510 } 511 512 if (d->stem != 0) 513 f->stem = d->stem; 514 515 set_file_variables (f); 516 517 p = variable_expand_for_file (d->name, f); 518 519 if (d->stem != 0) 520 f->stem = file_stem; 521 } 522 523 /* Parse the prerequisites. */ 524 new = parse_prereqs (p); 525 526 /* If this dep list was from a static pattern rule, expand the %s. We 527 use patsubst_expand to translate the prerequisites' patterns into 528 plain prerequisite names. */ 529 if (new && d->staticpattern) 530 { 531 char *pattern = "%"; 532 char *buffer = variable_expand (""); 533 struct dep *dp = new, *dl = 0; 534 535 while (dp != 0) 536 { 537 char *percent = find_percent (dp->name); 538 if (percent) 539 { 540 /* We have to handle empty stems specially, because that 541 would be equivalent to $(patsubst %,dp->name,) which 542 will always be empty. */ 543 if (d->stem[0] == '\0') 544 /* This needs memmove() in ISO C. */ 545 bcopy (percent+1, percent, strlen (percent)); 546 else 547 { 548 char *o = patsubst_expand (buffer, d->stem, pattern, 549 dp->name, pattern+1, 550 percent+1); 551 if (o == buffer) 552 dp->name[0] = '\0'; 553 else 554 { 555 free (dp->name); 556 dp->name = savestring (buffer, o - buffer); 557 } 558 } 559 560 /* If the name expanded to the empty string, ignore it. */ 561 if (dp->name[0] == '\0') 562 { 563 struct dep *df = dp; 564 if (dp == new) 565 dp = new = new->next; 566 else 567 dp = dl->next = dp->next; 568 /* @@ Are we leaking df->name here? */ 569 df->name = 0; 570 free_dep (df); 571 continue; 572 } 573 } 574 dl = dp; 575 dp = dp->next; 576 } 577 } 578 579 /* Enter them as files. */ 580 for (d1 = new; d1 != 0; d1 = d1->next) 581 { 582 d1->file = lookup_file (d1->name); 583 if (d1->file == 0) 584 d1->file = enter_file (d1->name); 585 else 586 free (d1->name); 587 d1->name = 0; 588 d1->staticpattern = 0; 589 d1->need_2nd_expansion = 0; 590 } 591 592 /* Add newly parsed deps to f->deps. If this is the last dependency 593 line and this target has commands then put it in front so the 594 last dependency line (the one with commands) ends up being the 595 first. This is important because people expect $< to hold first 596 prerequisite from the rule with commands. If it is not the last 597 dependency line or the rule does not have commands then link it 598 at the end so it appears in makefile order. */ 599 600 if (new != 0) 601 { 602 if (d->next == 0 && last_dep_has_cmds) 603 { 604 struct dep **d_ptr; 605 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next) 606 ; 607 608 *d_ptr = f->deps; 609 f->deps = new; 610 } 444 611 else 445 612 { 446 /* We are going to do second expansion so initialize file447 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 that468 need only exist in order to satisfy the dependency.469 Their modification times are irrelevant. */470 613 struct dep **d_ptr; 471 472 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next) 614 for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next) 473 615 ; 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 } 616 617 *d_ptr = new; 526 618 } 527 619 } 528 620 } 529 621 530 free_ ns_chain ((struct nameseq *)old);622 free_dep_chain (old); 531 623 } 532 624 … … 646 738 } 647 739 648 f = lookup_file (".POSIX");649 if (f != 0 && f->is_target)650 posix_pedantic = 1;651 652 740 /* kmk changed */ 653 741 f = lookup_file (".NOTPARALLEL"); … … 664 752 f2->command_flags |= COMMANDS_NOTPARALLEL; 665 753 } 754 755 #ifndef NO_MINUS_C_MINUS_O 756 /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */ 757 /* This needs more work: what if the user sets this in the makefile? 758 if (posix_pedantic) 759 define_variable (STRING_SIZE_TUPLE("OUTPUT_OPTION"), "", o_default, 1); 760 */ 761 #endif 666 762 667 763 /* Remember that we've done this. */
Note:
See TracChangeset
for help on using the changeset viewer.