VirtualBox

source: kBuild/trunk/src/kmk/implicit.c@ 2001

Last change on this file since 2001 was 2001, checked in by bird, 16 years ago

kmk: pedantic warnings.

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