VirtualBox

source: kBuild/vendor/gnumake/2007-05-23/implicit.c@ 1989

Last change on this file since 1989 was 900, checked in by bird, 18 years ago

Load /home/bird/src/Gnu/make/2007-05-23 into vendor/gnumake/current.

  • Property svn:eol-style set to native
File size: 30.1 KB
Line 
1/* Implicit rule searching for GNU Make.
2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
4Foundation, Inc.
5This file is part of GNU Make.
6
7GNU Make is free software; you can redistribute it and/or modify it under the
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 2, or (at your option) any later version.
10
11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License along with
16GNU Make; see the file COPYING. If not, write to the Free Software
17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
18
19#include "make.h"
20#include "filedef.h"
21#include "rule.h"
22#include "dep.h"
23#include "debug.h"
24#include "variable.h"
25#include "job.h" /* struct child, used inside commands.h */
26#include "commands.h" /* set_file_variables */
27
28static int pattern_search (struct file *file, int archive,
29 unsigned int depth, unsigned int recursions);
30
31
32/* For a FILE which has no commands specified, try to figure out some
33 from the implicit pattern rules.
34 Returns 1 if a suitable implicit rule was found,
35 after modifying FILE to contain the appropriate commands and deps,
36 or returns 0 if no implicit rule was found. */
37
38int
39try_implicit_rule (struct file *file, unsigned int depth)
40{
41 DBF (DB_IMPLICIT, _("Looking for an implicit rule for `%s'.\n"));
42
43 /* The order of these searches was previously reversed. My logic now is
44 that since the non-archive search uses more information in the target
45 (the archive search omits the archive name), it is more specific and
46 should come first. */
47
48 if (pattern_search (file, 0, depth, 0))
49 return 1;
50
51#ifndef NO_ARCHIVES
52 /* If this is an archive member reference, use just the
53 archive member name to search for implicit rules. */
54 if (ar_name (file->name))
55 {
56 DBF (DB_IMPLICIT,
57 _("Looking for archive-member implicit rule for `%s'.\n"));
58 if (pattern_search (file, 1, depth, 0))
59 return 1;
60 }
61#endif
62
63 return 0;
64}
65
66
67
68/* Struct idep captures information about implicit prerequisites
69 that come from implicit rules. */
70struct idep
71{
72 struct idep *next; /* struct dep -compatible interface */
73 const char *name; /* name of the prerequisite */
74 struct file *intermediate_file; /* intermediate file, 0 otherwise */
75 const char *intermediate_pattern; /* pattern for intermediate file */
76 unsigned char had_stem; /* had % substituted with stem */
77 unsigned char ignore_mtime; /* ignore_mtime flag */
78};
79
80static void
81free_idep_chain (struct idep *p)
82{
83 struct idep *n;
84
85 for (; p != 0; p = n)
86 {
87 n = p->next;
88 free (p);
89 }
90}
91
92
93/* Scans the BUFFER for the next word with whitespace as a separator.
94 Returns the pointer to the beginning of the word. LENGTH hold the
95 length of the word. */
96
97static char *
98get_next_word (const char *buffer, unsigned int *length)
99{
100 const char *p = buffer, *beg;
101 char c;
102
103 /* Skip any leading whitespace. */
104 while (isblank ((unsigned char)*p))
105 ++p;
106
107 beg = p;
108 c = *(p++);
109
110 if (c == '\0')
111 return 0;
112
113
114 /* We already found the first value of "c", above. */
115 while (1)
116 {
117 char closeparen;
118 int count;
119
120 switch (c)
121 {
122 case '\0':
123 case ' ':
124 case '\t':
125 goto done_word;
126
127 case '$':
128 c = *(p++);
129 if (c == '$')
130 break;
131
132 /* This is a variable reference, so read it to the matching
133 close paren. */
134
135 if (c == '(')
136 closeparen = ')';
137 else if (c == '{')
138 closeparen = '}';
139 else
140 /* This is a single-letter variable reference. */
141 break;
142
143 for (count = 0; *p != '\0'; ++p)
144 {
145 if (*p == c)
146 ++count;
147 else if (*p == closeparen && --count < 0)
148 {
149 ++p;
150 break;
151 }
152 }
153 break;
154
155 case '|':
156 goto done;
157
158 default:
159 break;
160 }
161
162 c = *(p++);
163 }
164 done_word:
165 --p;
166
167 done:
168 if (length)
169 *length = p - beg;
170
171 return (char *)beg;
172}
173
174/* Search the pattern rules for a rule with an existing dependency to make
175 FILE. If a rule is found, the appropriate commands and deps are put in FILE
176 and 1 is returned. If not, 0 is returned.
177
178 If ARCHIVE is nonzero, FILE->name is of the form "LIB(MEMBER)". A rule for
179 "(MEMBER)" will be searched for, and "(MEMBER)" will not be chopped up into
180 directory and filename parts.
181
182 If an intermediate file is found by pattern search, the intermediate file
183 is set up as a target by the recursive call and is also made a dependency
184 of FILE.
185
186 DEPTH is used for debugging messages. */
187
188static int
189pattern_search (struct file *file, int archive,
190 unsigned int depth, unsigned int recursions)
191{
192 /* Filename we are searching for a rule for. */
193 const char *filename = archive ? strchr (file->name, '(') : file->name;
194
195 /* Length of FILENAME. */
196 unsigned int namelen = strlen (filename);
197
198 /* The last slash in FILENAME (or nil if there is none). */
199 char *lastslash;
200
201 /* This is a file-object used as an argument in
202 recursive calls. It never contains any data
203 except during a recursive call. */
204 struct file *intermediate_file = 0;
205
206 /* This linked list records all the prerequisites actually
207 found for a rule along with some other useful information
208 (see struct idep for details). */
209 struct idep* deps = 0;
210
211 /* 1 if we need to remove explicit prerequisites, 0 otherwise. */
212 unsigned int remove_explicit_deps = 0;
213
214 /* Names of possible dependencies are constructed in this buffer. */
215 char *depname = alloca (namelen + max_pattern_dep_length);
216
217 /* The start and length of the stem of FILENAME for the current rule. */
218 const char *stem = 0;
219 unsigned int stemlen = 0;
220 unsigned int fullstemlen = 0;
221
222 /* Buffer in which we store all the rules that are possibly applicable. */
223 struct rule **tryrules = xmalloc (num_pattern_rules * max_pattern_targets
224 * sizeof (struct rule *));
225
226 /* Number of valid elements in TRYRULES. */
227 unsigned int nrules;
228
229 /* The numbers of the rule targets of each rule
230 in TRYRULES that matched the target file. */
231 unsigned int *matches = alloca (num_pattern_rules * sizeof (unsigned int));
232
233 /* Each element is nonzero if LASTSLASH was used in
234 matching the corresponding element of TRYRULES. */
235 char *checked_lastslash = alloca (num_pattern_rules * sizeof (char));
236
237 /* The index in TRYRULES of the rule we found. */
238 unsigned int foundrule;
239
240 /* Nonzero if should consider intermediate files as dependencies. */
241 int intermed_ok;
242
243 /* Nonzero if we have matched a pattern-rule target
244 that is not just `%'. */
245 int specific_rule_matched = 0;
246
247 unsigned int ri; /* uninit checks OK */
248 struct rule *rule;
249 struct dep *dep, *expl_d;
250
251 struct idep *d;
252 struct idep **id_ptr;
253 struct dep **d_ptr;
254
255 PATH_VAR (stem_str); /* @@ Need to get rid of stem, stemlen, etc. */
256
257#ifndef NO_ARCHIVES
258 if (archive || ar_name (filename))
259 lastslash = 0;
260 else
261#endif
262 {
263 /* Set LASTSLASH to point at the last slash in FILENAME
264 but not counting any slash at the end. (foo/bar/ counts as
265 bar/ in directory foo/, not empty in directory foo/bar/.) */
266#ifdef VMS
267 lastslash = strrchr (filename, ']');
268 if (lastslash == 0)
269 lastslash = strrchr (filename, ':');
270#else
271 lastslash = strrchr (filename, '/');
272#ifdef HAVE_DOS_PATHS
273 /* Handle backslashes (possibly mixed with forward slashes)
274 and the case of "d:file". */
275 {
276 char *bslash = strrchr (filename, '\\');
277 if (lastslash == 0 || bslash > lastslash)
278 lastslash = bslash;
279 if (lastslash == 0 && filename[0] && filename[1] == ':')
280 lastslash = filename + 1;
281 }
282#endif
283#endif
284 if (lastslash != 0 && lastslash[1] == '\0')
285 lastslash = 0;
286 }
287
288 /* First see which pattern rules match this target
289 and may be considered. Put them in TRYRULES. */
290
291 nrules = 0;
292 for (rule = pattern_rules; rule != 0; rule = rule->next)
293 {
294 unsigned int ti;
295
296 /* If the pattern rule has deps but no commands, ignore it.
297 Users cancel built-in rules by redefining them without commands. */
298 if (rule->deps != 0 && rule->cmds == 0)
299 continue;
300
301 /* If this rule is in use by a parent pattern_search,
302 don't use it here. */
303 if (rule->in_use)
304 {
305 DBS (DB_IMPLICIT, (_("Avoiding implicit rule recursion.\n")));
306 continue;
307 }
308
309 for (ti = 0; ti < rule->num; ++ti)
310 {
311 const char *target = rule->targets[ti];
312 const char *suffix = rule->suffixes[ti];
313 int check_lastslash;
314
315 /* Rules that can match any filename and are not terminal
316 are ignored if we're recursing, so that they cannot be
317 intermediate files. */
318 if (recursions > 0 && target[1] == '\0' && !rule->terminal)
319 continue;
320
321 if (rule->lens[ti] > namelen)
322 /* It can't possibly match. */
323 continue;
324
325 /* From the lengths of the filename and the pattern parts,
326 find the stem: the part of the filename that matches the %. */
327 stem = filename + (suffix - target - 1);
328 stemlen = namelen - rule->lens[ti] + 1;
329
330 /* Set CHECK_LASTSLASH if FILENAME contains a directory
331 prefix and the target pattern does not contain a slash. */
332
333 check_lastslash = 0;
334 if (lastslash)
335 {
336#ifdef VMS
337 check_lastslash = (strchr (target, ']') == 0
338 && strchr (target, ':') == 0);
339#else
340 check_lastslash = strchr (target, '/') == 0;
341#ifdef HAVE_DOS_PATHS
342 /* Didn't find it yet: check for DOS-type directories. */
343 if (check_lastslash)
344 {
345 char *b = strchr (target, '\\');
346 check_lastslash = !(b || (target[0] && target[1] == ':'));
347 }
348#endif
349#endif
350 }
351 if (check_lastslash)
352 {
353 /* If so, don't include the directory prefix in STEM here. */
354 unsigned int difference = lastslash - filename + 1;
355 if (difference > stemlen)
356 continue;
357 stemlen -= difference;
358 stem += difference;
359 }
360
361 /* Check that the rule pattern matches the text before the stem. */
362 if (check_lastslash)
363 {
364 if (stem > (lastslash + 1)
365 && !strneq (target, lastslash + 1, stem - lastslash - 1))
366 continue;
367 }
368 else if (stem > filename
369 && !strneq (target, filename, stem - filename))
370 continue;
371
372 /* Check that the rule pattern matches the text after the stem.
373 We could test simply use streq, but this way we compare the
374 first two characters immediately. This saves time in the very
375 common case where the first character matches because it is a
376 period. */
377 if (*suffix != stem[stemlen]
378 || (*suffix != '\0' && !streq (&suffix[1], &stem[stemlen + 1])))
379 continue;
380
381 /* Record if we match a rule that not all filenames will match. */
382 if (target[1] != '\0')
383 specific_rule_matched = 1;
384
385 /* A rule with no dependencies and no commands exists solely to set
386 specific_rule_matched when it matches. Don't try to use it. */
387 if (rule->deps == 0 && rule->cmds == 0)
388 continue;
389
390 /* Record this rule in TRYRULES and the index of the matching
391 target in MATCHES. If several targets of the same rule match,
392 that rule will be in TRYRULES more than once. */
393 tryrules[nrules] = rule;
394 matches[nrules] = ti;
395 checked_lastslash[nrules] = check_lastslash;
396 ++nrules;
397 }
398 }
399
400 /* If we have found a matching rule that won't match all filenames,
401 retroactively reject any non-"terminal" rules that do always match. */
402 if (specific_rule_matched)
403 for (ri = 0; ri < nrules; ++ri)
404 if (!tryrules[ri]->terminal)
405 {
406 unsigned int j;
407 for (j = 0; j < tryrules[ri]->num; ++j)
408 if (tryrules[ri]->targets[j][1] == '\0')
409 {
410 tryrules[ri] = 0;
411 break;
412 }
413 }
414
415 /* We are going to do second expansion so initialize file variables
416 for the rule. */
417 initialize_file_variables (file, 0);
418
419 /* Try each rule once without intermediate files, then once with them. */
420 for (intermed_ok = 0; intermed_ok == !!intermed_ok; ++intermed_ok)
421 {
422 /* Try each pattern rule till we find one that applies.
423 If it does, expand its dependencies (as substituted)
424 and chain them in DEPS. */
425
426 for (ri = 0; ri < nrules; ri++)
427 {
428 struct file *f;
429 unsigned int failed = 0;
430 int check_lastslash;
431 int file_variables_set = 0;
432
433 rule = tryrules[ri];
434
435 remove_explicit_deps = 0;
436
437 /* RULE is nil when we discover that a rule,
438 already placed in TRYRULES, should not be applied. */
439 if (rule == 0)
440 continue;
441
442 /* Reject any terminal rules if we're
443 looking to make intermediate files. */
444 if (intermed_ok && rule->terminal)
445 continue;
446
447 /* Mark this rule as in use so a recursive
448 pattern_search won't try to use it. */
449 rule->in_use = 1;
450
451 /* From the lengths of the filename and the matching pattern parts,
452 find the stem: the part of the filename that matches the %. */
453 stem = filename
454 + (rule->suffixes[matches[ri]] - rule->targets[matches[ri]]) - 1;
455 stemlen = namelen - rule->lens[matches[ri]] + 1;
456 check_lastslash = checked_lastslash[ri];
457 if (check_lastslash)
458 {
459 stem += lastslash - filename + 1;
460 stemlen -= (lastslash - filename) + 1;
461 }
462
463 DBS (DB_IMPLICIT, (_("Trying pattern rule with stem `%.*s'.\n"),
464 (int) stemlen, stem));
465
466 strncpy (stem_str, stem, stemlen);
467 stem_str[stemlen] = '\0';
468
469 /* Temporary assign STEM to file->stem (needed to set file
470 variables below). */
471 file->stem = stem_str;
472
473 /* Try each dependency; see if it "exists". */
474
475 for (dep = rule->deps; dep != 0; dep = dep->next)
476 {
477 unsigned int len;
478 char *p;
479 char *p2;
480 unsigned int order_only = 0; /* Set if '|' was seen. */
481
482 /* In an ideal world we would take the dependency line,
483 substitute the stem, re-expand the whole line and chop it
484 into individual prerequisites. Unfortunately this won't work
485 because of the "check_lastslash" twist. Instead, we will
486 have to go word by word, taking $()'s into account, for each
487 word we will substitute the stem, re-expand, chop it up, and,
488 if check_lastslash != 0, add the directory part to each
489 resulting prerequisite. */
490
491 p = get_next_word (dep->name, &len);
492
493 while (1)
494 {
495 int add_dir = 0;
496 int had_stem = 0;
497
498 if (p == 0)
499 break; /* No more words */
500
501 /* Is there a pattern in this prerequisite? */
502
503 for (p2 = p; p2 < p + len && *p2 != '%'; ++p2)
504 ;
505
506 if (dep->need_2nd_expansion)
507 {
508 /* If the dependency name has %, substitute the stem.
509
510 Watch out, we are going to do something tricky
511 here. If we just replace % with the stem value,
512 later, when we do the second expansion, we will
513 re-expand this stem value once again. This is not
514 good especially if you have certain characters in
515 your stem (like $).
516
517 Instead, we will replace % with $* and allow the
518 second expansion to take care of it for us. This way
519 (since $* is a simple variable) there won't be
520 additional re-expansion of the stem. */
521
522 if (p2 < p + len)
523 {
524 unsigned int i = p2 - p;
525 memcpy (depname, p, i);
526 memcpy (depname + i, "$*", 2);
527 memcpy (depname + i + 2, p2 + 1, len - i - 1);
528 depname[len + 2 - 1] = '\0';
529
530 if (check_lastslash)
531 add_dir = 1;
532
533 had_stem = 1;
534 }
535 else
536 {
537 memcpy (depname, p, len);
538 depname[len] = '\0';
539 }
540
541 /* Set file variables. Note that we cannot do it once
542 at the beginning of the function because of the stem
543 value. */
544 if (!file_variables_set)
545 {
546 set_file_variables (file);
547 file_variables_set = 1;
548 }
549
550 p2 = variable_expand_for_file (depname, file);
551 }
552 else
553 {
554 if (p2 < p + len)
555 {
556 unsigned int i = p2 - p;
557 memcpy (depname, p, i);
558 memcpy (depname + i, stem_str, stemlen);
559 memcpy (depname + i + stemlen, p2 + 1, len - i - 1);
560 depname[len + stemlen - 1] = '\0';
561
562 if (check_lastslash)
563 add_dir = 1;
564
565 had_stem = 1;
566 }
567 else
568 {
569 memcpy (depname, p, len);
570 depname[len] = '\0';
571 }
572
573 p2 = depname;
574 }
575
576 /* Parse the dependencies. */
577
578 while (1)
579 {
580 id_ptr = &deps;
581
582 for (; *id_ptr; id_ptr = &(*id_ptr)->next)
583 ;
584
585 *id_ptr = (struct idep *)
586 multi_glob (
587 parse_file_seq (&p2,
588 order_only ? '\0' : '|',
589 sizeof (struct idep),
590 1), sizeof (struct idep));
591
592 /* @@ It would be nice to teach parse_file_seq or
593 multi_glob to add prefix. This would save us some
594 reallocations. */
595
596 if (order_only || add_dir || had_stem)
597 {
598 unsigned long l = lastslash - filename + 1;
599
600 for (d = *id_ptr; d != 0; d = d->next)
601 {
602 if (order_only)
603 d->ignore_mtime = 1;
604
605 if (add_dir)
606 {
607 char *n = alloca (strlen (d->name) + l + 1);
608 memcpy (n, filename, l);
609 memcpy (n+l, d->name, strlen (d->name) + 1);
610 d->name = strcache_add (n);
611 }
612
613 if (had_stem)
614 d->had_stem = 1;
615 }
616 }
617
618 if (!order_only && *p2)
619 {
620 ++p2;
621 order_only = 1;
622 continue;
623 }
624
625 break;
626 }
627
628 p += len;
629 p = get_next_word (p, &len);
630 }
631 }
632
633 /* Reset the stem in FILE. */
634
635 file->stem = 0;
636
637 /* @@ This loop can be combined with the previous one. I do
638 it separately for now for transparency.*/
639
640 for (d = deps; d != 0; d = d->next)
641 {
642 const char *name = d->name;
643
644 if (file_impossible_p (name))
645 {
646 /* If this dependency has already been ruled "impossible",
647 then the rule fails and don't bother trying it on the
648 second pass either since we know that will fail too. */
649 DBS (DB_IMPLICIT,
650 (d->had_stem
651 ? _("Rejecting impossible implicit prerequisite `%s'.\n")
652 : _("Rejecting impossible rule prerequisite `%s'.\n"),
653 name));
654 tryrules[ri] = 0;
655
656 failed = 1;
657 break;
658 }
659
660 DBS (DB_IMPLICIT,
661 (d->had_stem
662 ? _("Trying implicit prerequisite `%s'.\n")
663 : _("Trying rule prerequisite `%s'.\n"), name));
664
665 /* If this prerequisite also happened to be explicitly mentioned
666 for FILE skip all the test below since it it has to be built
667 anyway, no matter which implicit rule we choose. */
668
669 for (expl_d = file->deps; expl_d != 0; expl_d = expl_d->next)
670 if (streq (dep_name (expl_d), name))
671 break;
672 if (expl_d != 0)
673 continue;
674
675 /* The DEP->changed flag says that this dependency resides in a
676 nonexistent directory. So we normally can skip looking for
677 the file. However, if CHECK_LASTSLASH is set, then the
678 dependency file we are actually looking for is in a different
679 directory (the one gotten by prepending FILENAME's directory),
680 so it might actually exist. */
681
682 /* @@ dep->changed check is disabled. */
683 if (((f = lookup_file (name)) != 0 && f->is_target)
684 /*|| ((!dep->changed || check_lastslash) && */
685 || file_exists_p (name))
686 continue;
687
688 /* This code, given FILENAME = "lib/foo.o", dependency name
689 "lib/foo.c", and VPATH=src, searches for "src/lib/foo.c". */
690 {
691 const char *vname = vpath_search (name, 0);
692 if (vname)
693 {
694 DBS (DB_IMPLICIT,
695 (_("Found prerequisite `%s' as VPATH `%s'\n"),
696 name, vname));
697 continue;
698 }
699 }
700
701
702 /* We could not find the file in any place we should look. Try
703 to make this dependency as an intermediate file, but only on
704 the second pass. */
705
706 if (intermed_ok)
707 {
708 if (intermediate_file == 0)
709 intermediate_file = alloca (sizeof (struct file));
710
711 DBS (DB_IMPLICIT,
712 (_("Looking for a rule with intermediate file `%s'.\n"),
713 name));
714
715 memset (intermediate_file, '\0', sizeof (struct file));
716 intermediate_file->name = name;
717 if (pattern_search (intermediate_file,
718 0,
719 depth + 1,
720 recursions + 1))
721 {
722 d->intermediate_pattern = intermediate_file->name;
723 intermediate_file->name = strcache_add (name);
724 d->intermediate_file = intermediate_file;
725 intermediate_file = 0;
726
727 continue;
728 }
729
730 /* If we have tried to find P as an intermediate
731 file and failed, mark that name as impossible
732 so we won't go through the search again later. */
733 if (intermediate_file->variables)
734 free_variable_set (intermediate_file->variables);
735 file_impossible (name);
736 }
737
738 /* A dependency of this rule does not exist. Therefore,
739 this rule fails. */
740 failed = 1;
741 break;
742 }
743
744 /* This rule is no longer `in use' for recursive searches. */
745 rule->in_use = 0;
746
747 if (failed)
748 {
749 /* This pattern rule does not apply. If some of its
750 dependencies succeeded, free the data structure
751 describing them. */
752 free_idep_chain (deps);
753 deps = 0;
754 }
755 else
756 /* This pattern rule does apply. Stop looking for one. */
757 break;
758 }
759
760 /* If we found an applicable rule without
761 intermediate files, don't try with them. */
762 if (ri < nrules)
763 break;
764
765 rule = 0;
766 }
767
768 /* RULE is nil if the loop went all the way
769 through the list and everything failed. */
770 if (rule == 0)
771 goto done;
772
773 foundrule = ri;
774
775 /* If we are recursing, store the pattern that matched
776 FILENAME in FILE->name for use in upper levels. */
777
778 if (recursions > 0)
779 /* Kludge-o-matic */
780 file->name = rule->targets[matches[foundrule]];
781
782 /* FOUND_FILES lists the dependencies for the rule we found.
783 This includes the intermediate files, if any.
784 Convert them into entries on the deps-chain of FILE. */
785
786 if (remove_explicit_deps)
787 {
788 /* Remove all the dependencies that didn't come from
789 this implicit rule. */
790
791 dep = file->deps;
792 while (dep != 0)
793 {
794 struct dep *next = dep->next;
795 free_dep (dep);
796 dep = next;
797 }
798 file->deps = 0;
799 }
800
801 expl_d = file->deps; /* We will add them at the end. */
802 d_ptr = &file->deps;
803
804 for (d = deps; d != 0; d = d->next)
805 {
806 const char *s;
807
808 if (d->intermediate_file != 0)
809 {
810 /* If we need to use an intermediate file,
811 make sure it is entered as a target, with the info that was
812 found for it in the recursive pattern_search call.
813 We know that the intermediate file did not already exist as
814 a target; therefore we can assume that the deps and cmds
815 of F below are null before we change them. */
816
817 struct file *imf = d->intermediate_file;
818 register struct file *f = lookup_file (imf->name);
819
820 /* We don't want to delete an intermediate file that happened
821 to be a prerequisite of some (other) target. Mark it as
822 precious. */
823 if (f != 0)
824 f->precious = 1;
825 else
826 f = enter_file (strcache_add (imf->name));
827
828 f->deps = imf->deps;
829 f->cmds = imf->cmds;
830 f->stem = imf->stem;
831 f->also_make = imf->also_make;
832 f->is_target = 1;
833
834 if (!f->precious)
835 {
836 imf = lookup_file (d->intermediate_pattern);
837 if (imf != 0 && imf->precious)
838 f->precious = 1;
839 }
840
841 f->intermediate = 1;
842 f->tried_implicit = 1;
843 for (dep = f->deps; dep != 0; dep = dep->next)
844 {
845 dep->file = enter_file (dep->name);
846 dep->name = 0;
847 dep->file->tried_implicit |= dep->changed;
848 }
849 }
850
851 dep = alloc_dep ();
852 dep->ignore_mtime = d->ignore_mtime;
853 s = d->name; /* Hijacking the name. */
854 d->name = 0;
855 if (recursions == 0)
856 {
857 dep->file = lookup_file (s);
858 if (dep->file == 0)
859 dep->file = enter_file (s);
860 }
861 else
862 dep->name = s;
863
864 if (d->intermediate_file == 0 && tryrules[foundrule]->terminal)
865 {
866 /* If the file actually existed (was not an intermediate file),
867 and the rule that found it was a terminal one, then we want
868 to mark the found file so that it will not have implicit rule
869 search done for it. If we are not entering a `struct file' for
870 it now, we indicate this with the `changed' flag. */
871 if (dep->file == 0)
872 dep->changed = 1;
873 else
874 dep->file->tried_implicit = 1;
875 }
876
877 *d_ptr = dep;
878 d_ptr = &dep->next;
879 }
880
881 *d_ptr = expl_d;
882
883 if (!checked_lastslash[foundrule])
884 {
885 /* Always allocate new storage, since STEM might be
886 on the stack for an intermediate file. */
887 file->stem = strcache_add_len (stem, stemlen);
888 fullstemlen = stemlen;
889 }
890 else
891 {
892 int dirlen = (lastslash + 1) - filename;
893 char *sp;
894
895 /* We want to prepend the directory from
896 the original FILENAME onto the stem. */
897 fullstemlen = dirlen + stemlen;
898 sp = alloca (fullstemlen + 1);
899 memcpy (sp, filename, dirlen);
900 memcpy (sp + dirlen, stem, stemlen);
901 sp[fullstemlen] = '\0';
902 file->stem = strcache_add (sp);
903 }
904
905 file->cmds = rule->cmds;
906 file->is_target = 1;
907
908 /* Set precious flag. */
909 {
910 struct file *f = lookup_file (rule->targets[matches[foundrule]]);
911 if (f && f->precious)
912 file->precious = 1;
913 }
914
915 /* If this rule builds other targets, too, put the others into FILE's
916 `also_make' member. */
917
918 if (rule->num > 1)
919 for (ri = 0; ri < rule->num; ++ri)
920 if (ri != matches[foundrule])
921 {
922 char *p = alloca (rule->lens[ri] + fullstemlen + 1);
923 struct file *f;
924 struct dep *new = alloc_dep ();
925
926 /* GKM FIMXE: handle '|' here too */
927 memcpy (p, rule->targets[ri],
928 rule->suffixes[ri] - rule->targets[ri] - 1);
929 p += rule->suffixes[ri] - rule->targets[ri] - 1;
930 memcpy (p, file->stem, fullstemlen);
931 p += fullstemlen;
932 memcpy (p, rule->suffixes[ri],
933 rule->lens[ri] - (rule->suffixes[ri] - rule->targets[ri])+1);
934 new->name = strcache_add (p);
935 new->file = enter_file (new->name);
936 new->next = file->also_make;
937
938 /* Set precious flag. */
939 f = lookup_file (rule->targets[ri]);
940 if (f && f->precious)
941 new->file->precious = 1;
942
943 /* Set the is_target flag so that this file is not treated
944 as intermediate by the pattern rule search algorithm and
945 file_exists_p cannot pick it up yet. */
946 new->file->is_target = 1;
947
948 file->also_make = new;
949 }
950
951 done:
952 free_idep_chain (deps);
953 free (tryrules);
954
955 return rule != 0;
956}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette