| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 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" |
|---|
| 26 |
#include "commands.h" |
|---|
| 27 |
|
|---|
| 28 |
static int |
|---|
| 29 |
pattern_search PARAMS ((struct file *file, int archive, |
|---|
| 30 |
unsigned int depth, unsigned int recursions)); |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
int |
|---|
| 39 |
try_implicit_rule (struct file *file, unsigned int depth) |
|---|
| 40 |
{ |
|---|
| 41 |
DBF (DB_IMPLICIT, _("Looking for an implicit rule for `%s'.\n")); |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
if (pattern_search (file, 0, depth, 0)) |
|---|
| 49 |
return 1; |
|---|
| 50 |
|
|---|
| 51 |
#ifndef NO_ARCHIVES |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 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 |
|
|---|
| 69 |
struct idep |
|---|
| 70 |
{ |
|---|
| 71 |
struct idep *next; |
|---|
| 72 |
char *name; |
|---|
| 73 |
struct file *intermediate_file; |
|---|
| 74 |
char *intermediate_pattern; |
|---|
| 75 |
unsigned char had_stem; |
|---|
| 76 |
unsigned char ignore_mtime; |
|---|
| 77 |
}; |
|---|
| 78 |
|
|---|
| 79 |
static void |
|---|
| 80 |
free_idep_chain (struct idep *p) |
|---|
| 81 |
{ |
|---|
| 82 |
struct idep *n; |
|---|
| 83 |
|
|---|
| 84 |
for (; p != 0; p = n) |
|---|
| 85 |
{ |
|---|
| 86 |
n = p->next; |
|---|
| 87 |
|
|---|
| 88 |
if (p->name) |
|---|
| 89 |
{ |
|---|
| 90 |
struct file *f = p->intermediate_file; |
|---|
| 91 |
|
|---|
| 92 |
if (f != 0 |
|---|
| 93 |
&& (f->stem < f->name || f->stem > f->name + strlen (f->name))) |
|---|
| 94 |
free (f->stem); |
|---|
| 95 |
|
|---|
| 96 |
free (p->name); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
free (p); |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
static char * |
|---|
| 109 |
get_next_word (char *buffer, unsigned int *length) |
|---|
| 110 |
{ |
|---|
| 111 |
char *p = buffer, *beg; |
|---|
| 112 |
char c; |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
while (isblank ((unsigned char)*p)) |
|---|
| 116 |
++p; |
|---|
| 117 |
|
|---|
| 118 |
beg = p; |
|---|
| 119 |
c = *(p++); |
|---|
| 120 |
|
|---|
| 121 |
if (c == '\0') |
|---|
| 122 |
return 0; |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
while (1) |
|---|
| 127 |
{ |
|---|
| 128 |
char closeparen; |
|---|
| 129 |
int count; |
|---|
| 130 |
|
|---|
| 131 |
switch (c) |
|---|
| 132 |
{ |
|---|
| 133 |
case '\0': |
|---|
| 134 |
case ' ': |
|---|
| 135 |
case '\t': |
|---|
| 136 |
goto done_word; |
|---|
| 137 |
|
|---|
| 138 |
case '$': |
|---|
| 139 |
c = *(p++); |
|---|
| 140 |
if (c == '$') |
|---|
| 141 |
break; |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
if (c == '(') |
|---|
| 147 |
closeparen = ')'; |
|---|
| 148 |
else if (c == '{') |
|---|
| 149 |
closeparen = '}'; |
|---|
| 150 |
else |
|---|
| 151 |
|
|---|
| 152 |
break; |
|---|
| 153 |
|
|---|
| 154 |
for (count = 0; *p != '\0'; ++p) |
|---|
| 155 |
{ |
|---|
| 156 |
if (*p == c) |
|---|
| 157 |
++count; |
|---|
| 158 |
else if (*p == closeparen && --count < 0) |
|---|
| 159 |
{ |
|---|
| 160 |
++p; |
|---|
| 161 |
break; |
|---|
| 162 |
} |
|---|
| 163 |
} |
|---|
| 164 |
break; |
|---|
| 165 |
|
|---|
| 166 |
case '|': |
|---|
| 167 |
goto done; |
|---|
| 168 |
|
|---|
| 169 |
default: |
|---|
| 170 |
break; |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
c = *(p++); |
|---|
| 174 |
} |
|---|
| 175 |
done_word: |
|---|
| 176 |
--p; |
|---|
| 177 |
|
|---|
| 178 |
done: |
|---|
| 179 |
if (length) |
|---|
| 180 |
*length = p - beg; |
|---|
| 181 |
|
|---|
| 182 |
return beg; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
static int |
|---|
| 200 |
pattern_search (struct file *file, int archive, |
|---|
| 201 |
unsigned int depth, unsigned int recursions) |
|---|
| 202 |
{ |
|---|
| 203 |
|
|---|
| 204 |
char *filename = archive ? strchr (file->name, '(') : file->name; |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
unsigned int namelen = strlen (filename); |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
char *lastslash; |
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
struct file *intermediate_file = 0; |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
struct idep* deps = 0; |
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
unsigned int remove_explicit_deps = 0; |
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
register char *depname = (char *) alloca (namelen + max_pattern_dep_length); |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
register char *stem = 0; |
|---|
| 230 |
register unsigned int stemlen = 0; |
|---|
| 231 |
register unsigned int fullstemlen = 0; |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
struct rule **tryrules |
|---|
| 235 |
= (struct rule **) xmalloc (num_pattern_rules * max_pattern_targets |
|---|
| 236 |
* sizeof (struct rule *)); |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
unsigned int nrules; |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
unsigned int *matches |
|---|
| 244 |
= (unsigned int *) alloca (num_pattern_rules * sizeof (unsigned int)); |
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
char *checked_lastslash |
|---|
| 249 |
= (char *) alloca (num_pattern_rules * sizeof (char)); |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
unsigned int foundrule; |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
int intermed_ok; |
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
int specific_rule_matched = 0; |
|---|
| 260 |
|
|---|
| 261 |
unsigned int i = 0; |
|---|
| 262 |
struct rule *rule; |
|---|
| 263 |
struct dep *dep, *expl_d; |
|---|
| 264 |
|
|---|
| 265 |
char *p, *vname; |
|---|
| 266 |
|
|---|
| 267 |
struct idep *d; |
|---|
| 268 |
struct idep **id_ptr; |
|---|
| 269 |
struct dep **d_ptr; |
|---|
| 270 |
|
|---|
| 271 |
PATH_VAR (stem_str); |
|---|
| 272 |
|
|---|
| 273 |
#ifndef NO_ARCHIVES |
|---|
| 274 |
if (archive || ar_name (filename)) |
|---|
| 275 |
lastslash = 0; |
|---|
| 276 |
else |
|---|
| 277 |
#endif |
|---|
| 278 |
{ |
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
#ifdef VMS |
|---|
| 283 |
lastslash = strrchr (filename, ']'); |
|---|
| 284 |
if (lastslash == 0) |
|---|
| 285 |
lastslash = strrchr (filename, ':'); |
|---|
| 286 |
#else |
|---|
| 287 |
lastslash = strrchr (filename, '/'); |
|---|
| 288 |
#ifdef HAVE_DOS_PATHS |
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
{ |
|---|
| 292 |
char *bslash = strrchr (filename, '\\'); |
|---|
| 293 |
if (lastslash == 0 || bslash > lastslash) |
|---|
| 294 |
lastslash = bslash; |
|---|
| 295 |
if (lastslash == 0 && filename[0] && filename[1] == ':') |
|---|
| 296 |
lastslash = filename + 1; |
|---|
| 297 |
} |
|---|
| 298 |
#endif |
|---|
| 299 |
#endif |
|---|
| 300 |
if (lastslash != 0 && lastslash[1] == '\0') |
|---|
| 301 |
lastslash = 0; |
|---|
| 302 |
} |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
nrules = 0; |
|---|
| 308 |
for (rule = pattern_rules; rule != 0; rule = rule->next) |
|---|
| 309 |
{ |
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
if (rule->deps != 0 && rule->cmds == 0) |
|---|
| 313 |
continue; |
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
if (rule->in_use) |
|---|
| 318 |
{ |
|---|
| 319 |
DBS (DB_IMPLICIT, (_("Avoiding implicit rule recursion.\n"))); |
|---|
| 320 |
continue; |
|---|
| 321 |
} |
|---|
| 322 |
|
|---|
| 323 |
for (i = 0; rule->targets[i] != 0; ++i) |
|---|
| 324 |
{ |
|---|
| 325 |
char *target = rule->targets[i]; |
|---|
| 326 |
char *suffix = rule->suffixes[i]; |
|---|
| 327 |
int check_lastslash; |
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
if (recursions > 0 && target[1] == '\0' && !rule->terminal) |
|---|
| 333 |
continue; |
|---|
| 334 |
|
|---|
| 335 |
if (rule->lens[i] > namelen) |
|---|
| 336 |
|
|---|
| 337 |
continue; |
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
stem = filename + (suffix - target - 1); |
|---|
| 342 |
stemlen = namelen - rule->lens[i] + 1; |
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
check_lastslash = 0; |
|---|
| 348 |
if (lastslash) |
|---|
| 349 |
{ |
|---|
| 350 |
#ifdef VMS |
|---|
| 351 |
check_lastslash = (strchr (target, ']') == 0 |
|---|
| 352 |
&& strchr (target, ':') == 0); |
|---|
| 353 |
#else |
|---|
| 354 |
check_lastslash = strchr (target, '/') == 0; |
|---|
| 355 |
#ifdef HAVE_DOS_PATHS |
|---|
| 356 |
|
|---|
| 357 |
if (check_lastslash) |
|---|
| 358 |
{ |
|---|
| 359 |
char *b = strchr (target, '\\'); |
|---|
| 360 |
check_lastslash = !(b || (target[0] && target[1] == ':')); |
|---|
| 361 |
} |
|---|
| 362 |
#endif |
|---|
| 363 |
#endif |
|---|
| 364 |
} |
|---|
| 365 |
if (check_lastslash) |
|---|
| 366 |
{ |
|---|
| 367 |
|
|---|
| 368 |
unsigned int difference = lastslash - filename + 1; |
|---|
| 369 |
if (difference > stemlen) |
|---|
| 370 |
continue; |
|---|
| 371 |
stemlen -= difference; |
|---|
| 372 |
stem += difference; |
|---|
| 373 |
} |
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
if (check_lastslash) |
|---|
| 377 |
{ |
|---|
| 378 |
if (stem > (lastslash + 1) |
|---|
| 379 |
&& !strneq (target, lastslash + 1, stem - lastslash - 1)) |
|---|
| 380 |
continue; |
|---|
| 381 |
} |
|---|
| 382 |
else if (stem > filename |
|---|
| 383 |
&& !strneq (target, filename, stem - filename)) |
|---|
| 384 |
continue; |
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
if (*suffix != stem[stemlen] |
|---|
| 392 |
|| (*suffix != '\0' && !streq (&suffix[1], &stem[stemlen + 1]))) |
|---|
| 393 |
continue; |
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
if (target[1] != '\0') |
|---|
| 397 |
specific_rule_matched = 1; |
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
if (rule->deps == 0 && rule->cmds == 0) |
|---|
| 402 |
continue; |
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
tryrules[nrules] = rule; |
|---|
| 408 |
matches[nrules] = i; |
|---|
| 409 |
checked_lastslash[nrules] = check_lastslash; |
|---|
| 410 |
++nrules; |
|---|
| 411 |
} |
|---|
| 412 |
} |
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
if (specific_rule_matched) |
|---|
| 417 |
for (i = 0; i < nrules; ++i) |
|---|
| 418 |
if (!tryrules[i]->terminal) |
|---|
| 419 |
{ |
|---|
| 420 |
register unsigned int j; |
|---|
| 421 |
for (j = 0; tryrules[i]->targets[j] != 0; ++j) |
|---|
| 422 |
if (tryrules[i]->targets[j][1] == '\0') |
|---|
| 423 |
break; |
|---|
| 424 |
if (tryrules[i]->targets[j] != 0) |
|---|
| 425 |
tryrules[i] = 0; |
|---|
| 426 |
} |
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
initialize_file_variables (file, 0); |
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
for (intermed_ok = 0; intermed_ok == !!intermed_ok; ++intermed_ok) |
|---|
| 434 |
{ |
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
for (i = 0; i < nrules; i++) |
|---|
| 440 |
{ |
|---|
| 441 |
struct file *f; |
|---|
| 442 |
unsigned int failed = 0; |
|---|
| 443 |
int check_lastslash; |
|---|
| 444 |
int file_variables_set = 0; |
|---|
| 445 |
|
|---|
| 446 |
rule = tryrules[i]; |
|---|
| 447 |
|
|---|
| 448 |
remove_explicit_deps = 0; |
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
if (rule == 0) |
|---|
| 453 |
continue; |
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
if (intermed_ok && rule->terminal) |
|---|
| 458 |
continue; |
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
rule->in_use = 1; |
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
stem = filename |
|---|
| 467 |
+ (rule->suffixes[matches[i]] - rule->targets[matches[i]]) - 1; |
|---|
| 468 |
stemlen = namelen - rule->lens[matches[i]] + 1; |
|---|
| 469 |
check_lastslash = checked_lastslash[i]; |
|---|
| 470 |
if (check_lastslash) |
|---|
| 471 |
{ |
|---|
| 472 |
stem += lastslash - filename + 1; |
|---|
| 473 |
stemlen -= (lastslash - filename) + 1; |
|---|
| 474 |
} |
|---|
| 475 |
|
|---|
| 476 |
DBS (DB_IMPLICIT, (_("Trying pattern rule with stem `%.*s'.\n"), |
|---|
| 477 |
(int) stemlen, stem)); |
|---|
| 478 |
|
|---|
| 479 |
strncpy (stem_str, stem, stemlen); |
|---|
| 480 |
stem_str[stemlen] = '\0'; |
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
file->stem = stem_str; |
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
for (dep = rule->deps; dep != 0; dep = dep->next) |
|---|
| 489 |
{ |
|---|
| 490 |
unsigned int len; |
|---|
| 491 |
char *p2; |
|---|
| 492 |
unsigned int order_only = 0; |
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
p = get_next_word (dep->name, &len); |
|---|
| 504 |
|
|---|
| 505 |
while (1) |
|---|
| 506 |
{ |
|---|
| 507 |
int add_dir = 0; |
|---|
| 508 |
int had_stem = 0; |
|---|
| 509 |
|
|---|
| 510 |
if (p == 0) |
|---|
| 511 |
break; |
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
for (p2 = p; p2 < p + len && *p2 != '%'; ++p2) |
|---|
| 516 |
; |
|---|
| 517 |
|
|---|
| 518 |
if (dep->need_2nd_expansion) |
|---|
| 519 |
{ |
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
|
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
if (p2 < p + len) |
|---|
| 535 |
{ |
|---|
| 536 |
register unsigned int i = p2 - p; |
|---|
| 537 |
bcopy (p, depname, i); |
|---|
| 538 |
bcopy ("$*", depname + i, 2); |
|---|
| 539 |
bcopy (p2 + 1, depname + i + 2, len - i - 1); |
|---|
| 540 |
depname[len + 2 - 1] = '\0'; |
|---|
| 541 |
|
|---|
| 542 |
if (check_lastslash) |
|---|
| 543 |
add_dir = 1; |
|---|
| 544 |
|
|---|
| 545 |
had_stem = 1; |
|---|
| 546 |
} |
|---|
| 547 |
else |
|---|
| 548 |
{ |
|---|
| 549 |
bcopy (p, depname, len); |
|---|
| 550 |
depname[len] = '\0'; |
|---|
| 551 |
} |
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
if (!file_variables_set) |
|---|
| 557 |
{ |
|---|
| 558 |
set_file_variables (file); |
|---|
| 559 |
file_variables_set = 1; |
|---|
| 560 |
} |
|---|
| 561 |
|
|---|
| 562 |
p2 = variable_expand_for_file (depname, file); |
|---|
| 563 |
} |
|---|
| 564 |
else |
|---|
| 565 |
{ |
|---|
| 566 |
if (p2 < p + len) |
|---|
| 567 |
{ |
|---|
| 568 |
register unsigned int i = p2 - p; |
|---|
| 569 |
bcopy (p, depname, i); |
|---|
| 570 |
bcopy (stem_str, depname + i, stemlen); |
|---|
| 571 |
bcopy (p2 + 1, depname + i + stemlen, len - i - 1); |
|---|
| 572 |
depname[len + stemlen - 1] = '\0'; |
|---|
| 573 |
|
|---|
| 574 |
if (check_lastslash) |
|---|
| 575 |
add_dir = 1; |
|---|
| 576 |
|
|---|
| 577 |
had_stem = 1; |
|---|
| 578 |
} |
|---|
| 579 |
else |
|---|
| 580 |
{ |
|---|
| 581 |
bcopy (p, depname, len); |
|---|
| 582 |
depname[len] = '\0'; |
|---|
| 583 |
} |
|---|
| 584 |
|
|---|
| 585 |
p2 = depname; |
|---|
| 586 |
} |
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
while (1) |
|---|
| 591 |
{ |
|---|
| 592 |
id_ptr = &deps; |
|---|
| 593 |
|
|---|
| 594 |
for (; *id_ptr; id_ptr = &(*id_ptr)->next) |
|---|
| 595 |
; |
|---|
| 596 |
|
|---|
| 597 |
*id_ptr = (struct idep *) |
|---|
| 598 |
multi_glob ( |
|---|
| 599 |
parse_file_seq (&p2, |
|---|
| 600 |
order_only ? '\0' : '|', |
|---|
| 601 |
sizeof (struct idep), |
|---|
| 602 |
1), sizeof (struct idep)); |
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 |
|
|---|
| 608 |
if (order_only || add_dir || had_stem) |
|---|
| 609 |
{ |
|---|
| 610 |
unsigned long l = lastslash - filename + 1; |
|---|
| 611 |
|
|---|
| 612 |
for (d = *id_ptr; d != 0; d = d->next) |
|---|
| 613 |
{ |
|---|
| 614 |
if (order_only) |
|---|
| 615 |
d->ignore_mtime = 1; |
|---|
| 616 |
|
|---|
| 617 |
if (add_dir) |
|---|
| 618 |
{ |
|---|
| 619 |
char *p = d->name; |
|---|
| 620 |
|
|---|
| 621 |
d->name = xmalloc (strlen (p) + l + 1); |
|---|
| 622 |
|
|---|
| 623 |
bcopy (filename, d->name, l); |
|---|
| 624 |
bcopy (p, d->name + l, strlen (p) + 1); |
|---|
| 625 |
|
|---|
| 626 |
free (p); |
|---|
| 627 |
} |
|---|
| 628 |
|
|---|
| 629 |
if (had_stem) |
|---|
| 630 |
d->had_stem = 1; |
|---|
| 631 |
} |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
if (!order_only && *p2) |
|---|
| 635 |
{ |
|---|
| 636 |
++p2; |
|---|
| 637 |
order_only = 1; |
|---|
| 638 |
continue; |
|---|
| 639 |
} |
|---|
| 640 |
|
|---|
| 641 |
break; |
|---|
| 642 |
} |
|---|
| 643 |
|
|---|
| 644 |
p += len; |
|---|
| 645 |
p = get_next_word (p, &len); |
|---|
| 646 |
} |
|---|
| 647 |
} |
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 |
|
|---|
| 651 |
file->stem = 0; |
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
for (d = deps; d != 0; d = d->next) |
|---|
| 657 |
{ |
|---|
| 658 |
char *name = d->name; |
|---|
| 659 |
|
|---|
| 660 |
if (file_impossible_p (name)) |
|---|
| 661 |
{ |
|---|
| 662 |
|
|---|
| 663 |
|
|---|
| 664 |
|
|---|
| 665 |
DBS (DB_IMPLICIT, |
|---|
| 666 |
(d->had_stem |
|---|
| 667 |
? _("Rejecting impossible implicit prerequisite `%s'.\n") |
|---|
| 668 |
: _("Rejecting impossible rule prerequisite `%s'.\n"), |
|---|
| 669 |
name)); |
|---|
| 670 |
tryrules[i] = 0; |
|---|
| 671 |
|
|---|
| 672 |
failed = 1; |
|---|
| 673 |
break; |
|---|
| 674 |
} |
|---|
| 675 |
|
|---|
| 676 |
DBS (DB_IMPLICIT, |
|---|
| 677 |
(d->had_stem |
|---|
| 678 |
? _("Trying implicit prerequisite `%s'.\n") |
|---|
| 679 |
: _("Trying rule prerequisite `%s'.\n"), name)); |
|---|
| 680 |
|
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 |
|
|---|
| 684 |
|
|---|
| 685 |
for (expl_d = file->deps; expl_d != 0; expl_d = expl_d->next) |
|---|
| 686 |
if (streq (dep_name (expl_d), name)) |
|---|
| 687 |
break; |
|---|
| 688 |
if (expl_d != 0) |
|---|
| 689 |
continue; |
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
|
|---|
| 697 |
|
|---|
| 698 |
|
|---|
| 699 |
if (((f = lookup_file (name)) != 0 && f->is_target) |
|---|
| 700 |
|
|---|
| 701 |
|| file_exists_p (name)) |
|---|
| 702 |
continue; |
|---|
| 703 |
|
|---|
| 704 |
|
|---|
| 705 |
|
|---|
| 706 |
vname = name; |
|---|
| 707 |
if (vpath_search (&vname, (FILE_TIMESTAMP *) 0)) |
|---|
| 708 |
{ |
|---|
| 709 |
DBS (DB_IMPLICIT, |
|---|
| 710 |
(_("Found prerequisite `%s' as VPATH `%s'\n"), |
|---|
| 711 |
name, |
|---|
| 712 |
vname)); |
|---|
| 713 |
|
|---|
| 714 |
free (vname); |
|---|
| 715 |
continue; |
|---|
| 716 |
} |
|---|
| 717 |
|
|---|
| 718 |
|
|---|
| 719 |
|
|---|
| 720 |
|
|---|
| 721 |
|
|---|
| 722 |
|
|---|
| 723 |
if (intermed_ok) |
|---|
| 724 |
{ |
|---|
| 725 |
if (intermediate_file == 0) |
|---|
| 726 |
intermediate_file |
|---|
| 727 |
= (struct file *) alloca (sizeof (struct file)); |
|---|
| 728 |
|
|---|
| 729 |
DBS (DB_IMPLICIT, |
|---|
| 730 |
(_("Looking for a rule with intermediate file `%s'.\n"), |
|---|
| 731 |
name)); |
|---|
| 732 |
|
|---|
| 733 |
bzero ((char *) intermediate_file, sizeof (struct file)); |
|---|
| 734 |
intermediate_file->name = name; |
|---|
| 735 |
if (pattern_search (intermediate_file, |
|---|
| 736 |
0, |
|---|
| 737 |
depth + 1, |
|---|
| 738 |
recursions + 1)) |
|---|
| 739 |
{ |
|---|
| 740 |
d->intermediate_file = intermediate_file; |
|---|
| 741 |
d->intermediate_pattern = intermediate_file->name; |
|---|
| 742 |
|
|---|
| 743 |
intermediate_file->name = xstrdup (name); |
|---|
| 744 |
intermediate_file = 0; |
|---|
| 745 |
|
|---|
| 746 |
continue; |
|---|
| 747 |
} |
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 |
if (intermediate_file->variables) |
|---|
| 753 |
free_variable_set (intermediate_file->variables); |
|---|
| 754 |
file_impossible (name); |
|---|
| 755 |
} |
|---|
| 756 |
|
|---|
| 757 |
|
|---|
| 758 |
|
|---|
| 759 |
failed = 1; |
|---|
| 760 |
break; |
|---|
| 761 |
} |
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 |
rule->in_use = 0; |
|---|
| 765 |
|
|---|
| 766 |
if (failed) |
|---|
| 767 |
{ |
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 |
|
|---|
| 771 |
free_idep_chain (deps); |
|---|
| 772 |
deps = 0; |
|---|
| 773 |
} |
|---|
| 774 |
else |
|---|
| 775 |
|
|---|
| 776 |
break; |
|---|
| 777 |
} |
|---|
| 778 |
|
|---|
| 779 |
|
|---|
| 780 |
|
|---|
| 781 |
if (i < nrules) |
|---|
| 782 |
break; |
|---|
| 783 |
|
|---|
| 784 |
rule = 0; |
|---|
| 785 |
} |
|---|
| 786 |
|
|---|
| 787 |
|
|---|
| 788 |
|
|---|
| 789 |
if (rule == 0) |
|---|
| 790 |
goto done; |
|---|
| 791 |
|
|---|
| 792 |
foundrule = i; |
|---|
| 793 |
|
|---|
| 794 |
|
|---|
| 795 |
|
|---|
| 796 |
|
|---|
| 797 |
if (recursions > 0) |
|---|
| 798 |
|
|---|
| 799 |
file->name = rule->targets[matches[foundrule]]; |
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 |
|
|---|
| 803 |
|
|---|
| 804 |
|
|---|
| 805 |
if (remove_explicit_deps) |
|---|
| 806 |
{ |
|---|
| 807 |
|
|---|
| 808 |
|
|---|
| 809 |
|
|---|
| 810 |
dep = file->deps; |
|---|
| 811 |
while (dep != 0) |
|---|
| 812 |
{ |
|---|
| 813 |
struct dep *next = dep->next; |
|---|
| 814 |
free_dep (dep); |
|---|
| 815 |
dep = next; |
|---|
| 816 |
} |
|---|
| 817 |
file->deps = 0; |
|---|
| 818 |
} |
|---|
| 819 |
|
|---|
| 820 |
expl_d = file->deps; |
|---|
| 821 |
d_ptr = &file->deps; |
|---|
| 822 |
|
|---|
| 823 |
for (d = deps; d != 0; d = d->next) |
|---|
| 824 |
{ |
|---|
| 825 |
register char *s; |
|---|
| 826 |
|
|---|
| 827 |
if (d->intermediate_file != 0) |
|---|
| 828 |
{ |
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 |
|
|---|
| 832 |
|
|---|
| 833 |
|
|---|
| 834 |
|
|---|
| 835 |
|
|---|
| 836 |
struct file *imf = d->intermediate_file; |
|---|
| 837 |
register struct file *f = lookup_file (imf->name); |
|---|
| 838 |
|
|---|
| 839 |
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 |
if (f != 0) |
|---|
| 843 |
f->precious = 1; |
|---|
| 844 |
else |
|---|
| 845 |
f = enter_file (imf->name); |
|---|
| 846 |
|
|---|
| 847 |
f->deps = imf->deps; |
|---|
| 848 |
f->cmds = imf->cmds; |
|---|
| 849 |
f->stem = imf->stem; |
|---|
| 850 |
f->also_make = imf->also_make; |
|---|
| 851 |
f->is_target = 1; |
|---|
| 852 |
|
|---|
| 853 |
if (!f->precious) |
|---|
| 854 |
{ |
|---|
| 855 |
imf = lookup_file (d->intermediate_pattern); |
|---|
| 856 |
if (imf != 0 && imf->precious) |
|---|
| 857 |
f->precious = 1; |
|---|
| 858 |
} |
|---|
| 859 |
|
|---|
| 860 |
f->intermediate = 1; |
|---|
| 861 |
f->tried_implicit = 1; |
|---|
| 862 |
for (dep = f->deps; dep != 0; dep = dep->next) |
|---|
| 863 |
{ |
|---|
| 864 |
dep->file = enter_file (dep->name); |
|---|
| 865 |
|
|---|
| 866 |
if (dep->name != dep->file->name) |
|---|
| 867 |
free (dep->name); |
|---|
| 868 |
dep->name = 0; |
|---|
| 869 |
dep->file->tried_implicit |= dep->changed; |
|---|
| 870 |
} |
|---|
| 871 |
} |
|---|
| 872 |
|
|---|
| 873 |
dep = alloc_dep (); |
|---|
| 874 |
dep->ignore_mtime = d->ignore_mtime; |
|---|
| 875 |
s = d->name; |
|---|
| 876 |
d->name = 0; |
|---|
| 877 |
if (recursions == 0) |
|---|
| 878 |
{ |
|---|
| 879 |
dep->file = lookup_file (s); |
|---|
| 880 |
if (dep->file == 0) |
|---|
| 881 |
|
|---|
| 882 |
dep->file = enter_file (s); |
|---|
| 883 |
else |
|---|
| 884 |
|
|---|
| 885 |
|
|---|
| 886 |
free (s); |
|---|
| 887 |
} |
|---|
| 888 |
else |
|---|
| 889 |
{ |
|---|
| 890 |
dep->name = s; |
|---|
| 891 |
} |
|---|
| 892 |
|
|---|
| 893 |
if (d->intermediate_file == 0 && tryrules[foundrule]->terminal) |
|---|
| 894 |
{ |
|---|
| 895 |
|
|---|
| 896 |
|
|---|
| 897 |
|
|---|
| 898 |
|
|---|
| 899 |
|
|---|
| 900 |
if (dep->file == 0) |
|---|
| 901 |
dep->changed = 1; |
|---|
| 902 |
else |
|---|
| 903 |
dep->file->tried_implicit = 1; |
|---|
| 904 |
} |
|---|
| 905 |
|
|---|
| 906 |
*d_ptr = dep; |
|---|
| 907 |
d_ptr = &dep->next; |
|---|
| 908 |
} |
|---|
| 909 |
|
|---|
| 910 |
*d_ptr = expl_d; |
|---|
| 911 |
|
|---|
| 912 |
if (!checked_lastslash[foundrule]) |
|---|
| 913 |
{ |
|---|
| 914 |
|
|---|
| 915 |
|
|---|
| 916 |
file->stem = savestring (stem, stemlen); |
|---|
| 917 |
fullstemlen = stemlen; |
|---|
| 918 |
} |
|---|
| 919 |
else |
|---|
| 920 |
{ |
|---|
| 921 |
int dirlen = (lastslash + 1) - filename; |
|---|
| 922 |
|
|---|
| 923 |
|
|---|
| 924 |
|
|---|
| 925 |
fullstemlen = dirlen + stemlen; |
|---|
| 926 |
file->stem = (char *) xmalloc (fullstemlen + 1); |
|---|
| 927 |
bcopy (filename, file->stem, dirlen); |
|---|
| 928 |
bcopy (stem, file->stem + dirlen, stemlen); |
|---|
| 929 |
file->stem[fullstemlen] = '\0'; |
|---|
| 930 |
} |
|---|
| 931 |
|
|---|
| 932 |
file->cmds = rule->cmds; |
|---|
| 933 |
file->is_target = 1; |
|---|
| 934 |
|
|---|
| 935 |
|
|---|
| 936 |
{ |
|---|
| 937 |
struct file *f = lookup_file (rule->targets[matches[foundrule]]); |
|---|
| 938 |
if (f && f->precious) |
|---|
| 939 |
file->precious = 1; |
|---|
| 940 |
} |
|---|
| 941 |
|
|---|
| 942 |
|
|---|
| 943 |
|
|---|
| 944 |
|
|---|
| 945 |
if (rule->targets[1] != 0) |
|---|
| 946 |
for (i = 0; rule->targets[i] != 0; ++i) |
|---|
| 947 |
if (i != matches[foundrule]) |
|---|
| 948 |
{ |
|---|
| 949 |
struct file *f; |
|---|
| 950 |
struct dep *new = alloc_dep (); |
|---|
| 951 |
|
|---|
| 952 |
|
|---|
| 953 |
new->name = p = (char *) xmalloc (rule->lens[i] + fullstemlen + 1); |
|---|
| 954 |
bcopy (rule->targets[i], p, |
|---|
| 955 |
rule->suffixes[i] - rule->targets[i] - 1); |
|---|
| 956 |
p += rule->suffixes[i] - rule->targets[i] - 1; |
|---|
| 957 |
bcopy (file->stem, p, fullstemlen); |
|---|
| 958 |
p += fullstemlen; |
|---|
| 959 |
bcopy (rule->suffixes[i], p, |
|---|
| 960 |
rule->lens[i] - (rule->suffixes[i] - rule->targets[i]) + 1); |
|---|
| 961 |
new->file = enter_file (new->name); |
|---|
| 962 |
new->next = file->also_make; |
|---|
| 963 |
|
|---|
| 964 |
|
|---|
| 965 |
f = lookup_file (rule->targets[i]); |
|---|
| 966 |
if (f && f->precious) |
|---|
| 967 |
new->file->precious = 1; |
|---|
| 968 |
|
|---|
| 969 |
|
|---|
| 970 |
|
|---|
| 971 |
|
|---|
| 972 |
new->file->is_target = 1; |
|---|
| 973 |
|
|---|
| 974 |
file->also_make = new; |
|---|
| 975 |
} |
|---|
| 976 |
|
|---|
| 977 |
done: |
|---|
| 978 |
free_idep_chain (deps); |
|---|
| 979 |
free (tryrules); |
|---|
| 980 |
|
|---|
| 981 |
return rule != 0; |
|---|
| 982 |
} |
|---|