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