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