| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "makeint.h" |
| 18 |
#include "filedef.h" |
| 19 |
#include "dep.h" |
| 20 |
#include "variable.h" |
| 21 |
#include "job.h" |
| 22 |
#include "commands.h" |
| 23 |
#include "expand.h" |
| 24 |
|
| 25 |
#define FILE_LIST_SEPARATOR ' ' |
| 26 |
|
| 27 |
#ifndef HAVE_UNISTD_H |
| 28 |
pid_t getpid (); |
| 29 |
#endif |
| 30 |
|
| 31 |
|
| 32 |
static unsigned long |
| 33 |
dep_hash_1 (const void *key) |
| 34 |
{ |
| 35 |
const struct dep *d = key; |
| 36 |
return_STRING_HASH_1 (dep_name (d)); |
| 37 |
} |
| 38 |
|
| 39 |
static unsigned long |
| 40 |
dep_hash_2 (const void *key) |
| 41 |
{ |
| 42 |
const struct dep *d = key; |
| 43 |
return_STRING_HASH_2 (dep_name (d)); |
| 44 |
} |
| 45 |
|
| 46 |
static int |
| 47 |
dep_hash_cmp (const void *x, const void *y) |
| 48 |
{ |
| 49 |
const struct dep *dx = x; |
| 50 |
const struct dep *dy = y; |
| 51 |
return strcmp (dep_name (dx), dep_name (dy)); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
void |
| 57 |
set_file_variables (struct file *file) |
| 58 |
{ |
| 59 |
struct dep *d; |
| 60 |
const char *at, *percent, *star, *less; |
| 61 |
|
| 62 |
#ifndef NO_ARCHIVES |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
if (ar_name (file->name)) |
| 67 |
{ |
| 68 |
size_t len; |
| 69 |
const char *cp; |
| 70 |
char *p; |
| 71 |
|
| 72 |
cp = strchr (file->name, '('); |
| 73 |
p = alloca (cp - file->name + 1); |
| 74 |
memcpy (p, file->name, cp - file->name); |
| 75 |
p[cp - file->name] = '\0'; |
| 76 |
at = p; |
| 77 |
len = strlen (cp + 1); |
| 78 |
p = alloca (len); |
| 79 |
memcpy (p, cp + 1, len - 1); |
| 80 |
p[len - 1] = '\0'; |
| 81 |
percent = p; |
| 82 |
} |
| 83 |
else |
| 84 |
#endif |
| 85 |
{ |
| 86 |
at = file->name; |
| 87 |
percent = ""; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
if (file->stem == 0) |
| 92 |
{ |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
const char *name; |
| 97 |
size_t len; |
| 98 |
|
| 99 |
#ifndef NO_ARCHIVES |
| 100 |
if (ar_name (file->name)) |
| 101 |
{ |
| 102 |
name = strchr (file->name, '(') + 1; |
| 103 |
len = strlen (name) - 1; |
| 104 |
} |
| 105 |
else |
| 106 |
#endif |
| 107 |
{ |
| 108 |
name = file->name; |
| 109 |
len = strlen (name); |
| 110 |
} |
| 111 |
|
| 112 |
for (d = enter_file (strcache_add (".SUFFIXES"))->deps; d ; d = d->next) |
| 113 |
{ |
| 114 |
size_t slen = strlen (dep_name (d)); |
| 115 |
if (len > slen && strneq (dep_name (d), name + (len - slen), slen)) |
| 116 |
{ |
| 117 |
file->stem = strcache_add_len (name, len - slen); |
| 118 |
break; |
| 119 |
} |
| 120 |
} |
| 121 |
if (d == 0) |
| 122 |
file->stem = ""; |
| 123 |
} |
| 124 |
star = file->stem; |
| 125 |
|
| 126 |
|
| 127 |
less = ""; |
| 128 |
for (d = file->deps; d != 0; d = d->next) |
| 129 |
if (!d->ignore_mtime && !d->ignore_automatic_vars) |
| 130 |
{ |
| 131 |
if (!d->need_2nd_expansion) |
| 132 |
less = dep_name (d); |
| 133 |
break; |
| 134 |
} |
| 135 |
|
| 136 |
if (file->cmds != 0 && file->cmds == default_file->cmds) |
| 137 |
|
| 138 |
|
| 139 |
less = at; |
| 140 |
|
| 141 |
#define DEFINE_VARIABLE(name, len, value) \ |
| 142 |
(void) define_variable_for_file (name,len,value,o_automatic,0,file) |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
DEFINE_VARIABLE ("<", 1, less); |
| 147 |
DEFINE_VARIABLE ("*", 1, star); |
| 148 |
DEFINE_VARIABLE ("@", 1, at); |
| 149 |
DEFINE_VARIABLE ("%", 1, percent); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
{ |
| 154 |
static char *plus_value=0, *bar_value=0, *qmark_value=0; |
| 155 |
static size_t plus_max=0, bar_max=0, qmark_max=0; |
| 156 |
|
| 157 |
size_t qmark_len, plus_len, bar_len; |
| 158 |
char *cp; |
| 159 |
char *caret_value; |
| 160 |
char *qp; |
| 161 |
char *bp; |
| 162 |
size_t len; |
| 163 |
|
| 164 |
struct hash_table dep_hash; |
| 165 |
void **slot; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
plus_len = 0; |
| 171 |
bar_len = 0; |
| 172 |
for (d = file->deps; d != 0; d = d->next) |
| 173 |
{ |
| 174 |
if (!d->need_2nd_expansion && !d->ignore_automatic_vars) |
| 175 |
{ |
| 176 |
if (d->ignore_mtime) |
| 177 |
bar_len += strlen (dep_name (d)) + 1; |
| 178 |
else |
| 179 |
plus_len += strlen (dep_name (d)) + 1; |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
if (bar_len == 0) |
| 184 |
bar_len++; |
| 185 |
|
| 186 |
if (plus_len == 0) |
| 187 |
plus_len++; |
| 188 |
|
| 189 |
if (plus_len > plus_max) |
| 190 |
plus_value = xrealloc (plus_value, plus_max = plus_len); |
| 191 |
|
| 192 |
cp = plus_value; |
| 193 |
|
| 194 |
qmark_len = plus_len + 1; |
| 195 |
for (d = file->deps; d != 0; d = d->next) |
| 196 |
if (! d->ignore_mtime && ! d->need_2nd_expansion && ! d->ignore_automatic_vars) |
| 197 |
{ |
| 198 |
const char *c = dep_name (d); |
| 199 |
|
| 200 |
#ifndef NO_ARCHIVES |
| 201 |
if (ar_name (c)) |
| 202 |
{ |
| 203 |
c = strchr (c, '(') + 1; |
| 204 |
len = strlen (c) - 1; |
| 205 |
} |
| 206 |
else |
| 207 |
#endif |
| 208 |
len = strlen (c); |
| 209 |
|
| 210 |
memcpy (cp, c, len); |
| 211 |
cp += len; |
| 212 |
*cp++ = FILE_LIST_SEPARATOR; |
| 213 |
if (! (d->changed || always_make_flag)) |
| 214 |
qmark_len -= len + 1; |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
cp[cp > plus_value ? -1 : 0] = '\0'; |
| 220 |
DEFINE_VARIABLE ("+", 1, plus_value); |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
cp = caret_value = plus_value; |
| 225 |
|
| 226 |
if (qmark_len > qmark_max) |
| 227 |
qmark_value = xrealloc (qmark_value, qmark_max = qmark_len); |
| 228 |
qp = qmark_value; |
| 229 |
|
| 230 |
if (bar_len > bar_max) |
| 231 |
bar_value = xrealloc (bar_value, bar_max = bar_len); |
| 232 |
bp = bar_value; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
hash_init (&dep_hash, 500, dep_hash_1, dep_hash_2, dep_hash_cmp); |
| 240 |
|
| 241 |
for (d = file->deps; d != 0; d = d->next) |
| 242 |
{ |
| 243 |
if (d->need_2nd_expansion || d->ignore_automatic_vars) |
| 244 |
continue; |
| 245 |
|
| 246 |
slot = hash_find_slot (&dep_hash, d); |
| 247 |
if (HASH_VACANT (*slot)) |
| 248 |
hash_insert_at (&dep_hash, d, slot); |
| 249 |
else |
| 250 |
{ |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
struct dep* hd = (struct dep*) *slot; |
| 255 |
|
| 256 |
if (d->ignore_mtime != hd->ignore_mtime) |
| 257 |
d->ignore_mtime = hd->ignore_mtime = 0; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
for (d = file->deps; d != 0; d = d->next) |
| 262 |
{ |
| 263 |
const char *c; |
| 264 |
|
| 265 |
if (d->need_2nd_expansion || d->ignore_automatic_vars || hash_find_item (&dep_hash, d) != d) |
| 266 |
continue; |
| 267 |
|
| 268 |
c = dep_name (d); |
| 269 |
#ifndef NO_ARCHIVES |
| 270 |
if (ar_name (c)) |
| 271 |
{ |
| 272 |
c = strchr (c, '(') + 1; |
| 273 |
len = strlen (c) - 1; |
| 274 |
} |
| 275 |
else |
| 276 |
#endif |
| 277 |
len = strlen (c); |
| 278 |
|
| 279 |
if (d->ignore_mtime) |
| 280 |
{ |
| 281 |
memcpy (bp, c, len); |
| 282 |
bp += len; |
| 283 |
*bp++ = FILE_LIST_SEPARATOR; |
| 284 |
} |
| 285 |
else |
| 286 |
{ |
| 287 |
memcpy (cp, c, len); |
| 288 |
cp += len; |
| 289 |
*cp++ = FILE_LIST_SEPARATOR; |
| 290 |
if (d->changed || always_make_flag) |
| 291 |
{ |
| 292 |
memcpy (qp, c, len); |
| 293 |
qp += len; |
| 294 |
*qp++ = FILE_LIST_SEPARATOR; |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
hash_free (&dep_hash, 0); |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
cp[cp > caret_value ? -1 : 0] = '\0'; |
| 304 |
DEFINE_VARIABLE ("^", 1, caret_value); |
| 305 |
|
| 306 |
qp[qp > qmark_value ? -1 : 0] = '\0'; |
| 307 |
DEFINE_VARIABLE ("?", 1, qmark_value); |
| 308 |
|
| 309 |
bp[bp > bar_value ? -1 : 0] = '\0'; |
| 310 |
DEFINE_VARIABLE ("|", 1, bar_value); |
| 311 |
} |
| 312 |
|
| 313 |
#undef DEFINE_VARIABLE |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
void |
| 320 |
chop_commands (struct commands *cmds) |
| 321 |
{ |
| 322 |
unsigned int nlines; |
| 323 |
unsigned short idx; |
| 324 |
char **lines; |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
if (!cmds || cmds->command_lines != 0) |
| 330 |
return; |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
if (one_shell) |
| 335 |
{ |
| 336 |
size_t l = strlen (cmds->commands); |
| 337 |
|
| 338 |
nlines = 1; |
| 339 |
lines = xmalloc (nlines * sizeof (char *)); |
| 340 |
lines[0] = xstrdup (cmds->commands); |
| 341 |
|
| 342 |
|
| 343 |
if (l > 0 && lines[0][l-1] == '\n') |
| 344 |
lines[0][l-1] = '\0'; |
| 345 |
} |
| 346 |
else |
| 347 |
{ |
| 348 |
const char *p; |
| 349 |
|
| 350 |
nlines = 5; |
| 351 |
lines = xmalloc (nlines * sizeof (char *)); |
| 352 |
idx = 0; |
| 353 |
p = cmds->commands; |
| 354 |
while (*p != '\0') |
| 355 |
{ |
| 356 |
const char *end = p; |
| 357 |
find_end:; |
| 358 |
end = strchr (end, '\n'); |
| 359 |
if (end == 0) |
| 360 |
end = p + strlen (p); |
| 361 |
else if (end > p && end[-1] == '\\') |
| 362 |
{ |
| 363 |
int backslash = 1; |
| 364 |
const char *b; |
| 365 |
for (b = end - 2; b >= p && *b == '\\'; --b) |
| 366 |
backslash = !backslash; |
| 367 |
if (backslash) |
| 368 |
{ |
| 369 |
++end; |
| 370 |
goto find_end; |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
if (idx == nlines) |
| 375 |
{ |
| 376 |
nlines += 2; |
| 377 |
lines = xrealloc (lines, nlines * sizeof (char *)); |
| 378 |
} |
| 379 |
lines[idx++] = xstrndup (p, (size_t) (end - p)); |
| 380 |
p = end; |
| 381 |
if (*p != '\0') |
| 382 |
++p; |
| 383 |
} |
| 384 |
|
| 385 |
if (idx != nlines) |
| 386 |
{ |
| 387 |
nlines = idx; |
| 388 |
lines = xrealloc (lines, nlines * sizeof (char *)); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
if (nlines > USHRT_MAX) |
| 396 |
ON (fatal, &cmds->fileinfo, _("Recipe has too many lines (%ud)"), nlines); |
| 397 |
|
| 398 |
cmds->ncommand_lines = (unsigned short)nlines; |
| 399 |
cmds->command_lines = lines; |
| 400 |
|
| 401 |
cmds->any_recurse = 0; |
| 402 |
cmds->lines_flags = xmalloc (nlines); |
| 403 |
|
| 404 |
for (idx = 0; idx < nlines; ++idx) |
| 405 |
{ |
| 406 |
unsigned char flags = 0; |
| 407 |
const char *p = lines[idx]; |
| 408 |
|
| 409 |
while (ISBLANK (*p) || *p == '-' || *p == '@' || *p == '+') |
| 410 |
switch (*(p++)) |
| 411 |
{ |
| 412 |
case '+': |
| 413 |
flags |= COMMANDS_RECURSE; |
| 414 |
break; |
| 415 |
case '@': |
| 416 |
flags |= COMMANDS_SILENT; |
| 417 |
break; |
| 418 |
case '-': |
| 419 |
flags |= COMMANDS_NOERROR; |
| 420 |
break; |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
if (!(flags & COMMANDS_RECURSE) |
| 425 |
&& (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0)) |
| 426 |
flags |= COMMANDS_RECURSE; |
| 427 |
|
| 428 |
cmds->lines_flags[idx] = flags; |
| 429 |
cmds->any_recurse |= flags & COMMANDS_RECURSE ? 1 : 0; |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
void expand_command_lines(struct commands *cmds, char **lines, |
| 435 |
struct file *file) |
| 436 |
{ |
| 437 |
unsigned int i; |
| 438 |
|
| 439 |
for (i = 0; i < cmds->ncommand_lines; ++i) |
| 440 |
{ |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
char *in, *out, *ref; |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
in = out = cmds->command_lines[i]; |
| 456 |
while ((ref = strchr (in, '$')) != 0) |
| 457 |
{ |
| 458 |
++ref; |
| 459 |
|
| 460 |
if (out != in) |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
memmove (out, in, ref - in); |
| 465 |
|
| 466 |
|
| 467 |
out += ref - in; |
| 468 |
in = ref; |
| 469 |
|
| 470 |
if (*ref == '(' || *ref == '{') |
| 471 |
{ |
| 472 |
char openparen = *ref; |
| 473 |
char closeparen = openparen == '(' ? ')' : '}'; |
| 474 |
int count; |
| 475 |
char *p; |
| 476 |
|
| 477 |
*out++ = *in++; |
| 478 |
|
| 479 |
|
| 480 |
count = 0; |
| 481 |
while (*in != '\0') |
| 482 |
{ |
| 483 |
if (*in == closeparen && --count < 0) |
| 484 |
break; |
| 485 |
else if (*in == '\\' && in[1] == '\n') |
| 486 |
{ |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
int quoted = 0; |
| 492 |
for (p = in - 1; p > ref && *p == '\\'; --p) |
| 493 |
quoted = !quoted; |
| 494 |
|
| 495 |
if (quoted) |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
*out++ = *in++; |
| 502 |
else |
| 503 |
{ |
| 504 |
|
| 505 |
|
| 506 |
in = next_token (in + 2); |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
while (out > ref |
| 511 |
&& isblank ((unsigned char)out[-1])) |
| 512 |
--out; |
| 513 |
|
| 514 |
|
| 515 |
*out++ = ' '; |
| 516 |
} |
| 517 |
} |
| 518 |
else |
| 519 |
{ |
| 520 |
if (*in == openparen) |
| 521 |
++count; |
| 522 |
|
| 523 |
*out++ = *in++; |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
if (out != in) |
| 532 |
memmove (out, in, strlen (in) + 1); |
| 533 |
|
| 534 |
|
| 535 |
lines[i] = allocated_variable_expand_for_file (cmds->command_lines[i], |
| 536 |
file); |
| 537 |
} |
| 538 |
|
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
void |
| 546 |
execute_file_commands (file_t *file, target_stack_node_t *p_call_stack) |
| 547 |
{ |
| 548 |
const char *p; |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
for (p = file->cmds->commands; *p != '\0'; ++p) |
| 554 |
if (!ISSPACE (*p) && *p != '-' && *p != '@' && *p != '+') |
| 555 |
break; |
| 556 |
if (*p == '\0') |
| 557 |
{ |
| 558 |
|
| 559 |
set_command_state (file, cs_running); |
| 560 |
file->update_status = us_success; |
| 561 |
notice_finished_file (file); |
| 562 |
return; |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
initialize_file_variables (file, 0); |
| 568 |
|
| 569 |
set_file_variables (file); |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
if (file->loaded) |
| 574 |
unload_file (file->name); |
| 575 |
|
| 576 |
|
| 577 |
new_job (file, p_call_stack); |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
int handling_fatal_signal = 0; |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
RETSIGTYPE |
| 588 |
fatal_error_signal (int sig) |
| 589 |
{ |
| 590 |
#ifdef __MSDOS__ |
| 591 |
extern int dos_status, dos_command_running; |
| 592 |
|
| 593 |
if (dos_command_running) |
| 594 |
{ |
| 595 |
|
| 596 |
dos_status |= (sig << 8); |
| 597 |
return; |
| 598 |
} |
| 599 |
remove_intermediates (1); |
| 600 |
exit (EXIT_FAILURE); |
| 601 |
#else |
| 602 |
#ifdef WINDOWS32 |
| 603 |
extern HANDLE main_thread; |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
if (main_thread) |
| 609 |
{ |
| 610 |
DWORD susp_count = SuspendThread (main_thread); |
| 611 |
|
| 612 |
if (susp_count != 0) |
| 613 |
fprintf (stderr, "SuspendThread: suspend count = %ld\n", susp_count); |
| 614 |
else if (susp_count == (DWORD)-1) |
| 615 |
{ |
| 616 |
DWORD ierr = GetLastError (); |
| 617 |
|
| 618 |
fprintf (stderr, "SuspendThread: error %ld: %s\n", |
| 619 |
ierr, map_windows32_error_to_string (ierr)); |
| 620 |
} |
| 621 |
} |
| 622 |
#endif |
| 623 |
handling_fatal_signal = 1; |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
signal (sig, SIG_DFL); |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
if (sig == SIGTERM) |
| 633 |
{ |
| 634 |
struct child *c; |
| 635 |
for (c = children; c != 0; c = c->next) |
| 636 |
if (!c->remote && c->pid > 0) |
| 637 |
(void) kill (c->pid, SIGTERM); |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
if (sig == SIGTERM || sig == SIGINT |
| 644 |
#ifdef SIGHUP |
| 645 |
|| sig == SIGHUP |
| 646 |
#endif |
| 647 |
#ifdef SIGQUIT |
| 648 |
|| sig == SIGQUIT |
| 649 |
#endif |
| 650 |
) |
| 651 |
{ |
| 652 |
struct child *c; |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
for (c = children; c != 0; c = c->next) |
| 657 |
if (c->remote && c->pid > 0) |
| 658 |
(void) remote_kill (c->pid, sig); |
| 659 |
|
| 660 |
for (c = children; c != 0; c = c->next) |
| 661 |
delete_child_targets (c); |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
while (job_slots_used > 0) |
| 666 |
reap_children (1, 0, NULL); |
| 667 |
} |
| 668 |
else |
| 669 |
|
| 670 |
while (job_slots_used > 0) |
| 671 |
reap_children (1, 1, NULL); |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
remove_intermediates (1); |
| 676 |
|
| 677 |
#ifdef SIGQUIT |
| 678 |
if (sig == SIGQUIT) |
| 679 |
|
| 680 |
|
| 681 |
exit (MAKE_TROUBLE); |
| 682 |
#endif |
| 683 |
|
| 684 |
#ifdef WINDOWS32 |
| 685 |
if (main_thread) |
| 686 |
CloseHandle (main_thread); |
| 687 |
|
| 688 |
|
| 689 |
exit (130); |
| 690 |
#else |
| 691 |
|
| 692 |
|
| 693 |
if (kill (getpid (), sig) < 0) |
| 694 |
pfatal_with_name ("kill"); |
| 695 |
#endif |
| 696 |
#endif |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
static void |
| 703 |
delete_target (struct file *file, const char *on_behalf_of) |
| 704 |
{ |
| 705 |
struct stat st; |
| 706 |
int e; |
| 707 |
|
| 708 |
if (file->precious || file->phony) |
| 709 |
return; |
| 710 |
|
| 711 |
#ifndef NO_ARCHIVES |
| 712 |
if (ar_name (file->name)) |
| 713 |
{ |
| 714 |
time_t file_date = (file->last_mtime == NONEXISTENT_MTIME |
| 715 |
? (time_t) -1 |
| 716 |
: (time_t) FILE_TIMESTAMP_S (file->last_mtime)); |
| 717 |
time_t member_date = NONEXISTENT_MTIME; |
| 718 |
int found; |
| 719 |
found = ar_member_date (file->name, &member_date); |
| 720 |
if (found && member_date != file_date) |
| 721 |
{ |
| 722 |
if (on_behalf_of) |
| 723 |
OSS (error, NILF, |
| 724 |
_("*** [%s] Archive member '%s' may be bogus; not deleted"), |
| 725 |
on_behalf_of, file->name); |
| 726 |
else |
| 727 |
OS (error, NILF, |
| 728 |
_("*** Archive member '%s' may be bogus; not deleted"), |
| 729 |
file->name); |
| 730 |
} |
| 731 |
return; |
| 732 |
} |
| 733 |
#endif |
| 734 |
|
| 735 |
EINTRLOOP (e, stat (file->name, &st)); |
| 736 |
if (e == 0 |
| 737 |
&& S_ISREG (st.st_mode) |
| 738 |
&& FILE_TIMESTAMP_STAT_MODTIME (file->name, st) != file->last_mtime) |
| 739 |
{ |
| 740 |
if (on_behalf_of) |
| 741 |
OSS (error, NILF, |
| 742 |
_("*** [%s] Deleting file '%s'"), on_behalf_of, file->name); |
| 743 |
else |
| 744 |
OS (error, NILF, _("*** Deleting file '%s'"), file->name); |
| 745 |
if (unlink (file->name) < 0 |
| 746 |
&& errno != ENOENT) |
| 747 |
perror_with_name ("unlink: ", file->name); |
| 748 |
} |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
void |
| 756 |
delete_child_targets (struct child *child) |
| 757 |
{ |
| 758 |
struct dep *d; |
| 759 |
|
| 760 |
if (child->deleted || child->pid < 0) |
| 761 |
return; |
| 762 |
|
| 763 |
|
| 764 |
delete_target (child->file, NULL); |
| 765 |
|
| 766 |
|
| 767 |
for (d = child->file->also_make; d != 0; d = d->next) |
| 768 |
delete_target (d->file, child->file->name); |
| 769 |
|
| 770 |
child->deleted = 1; |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
void |
| 781 |
print_commands (file_t *p_target, commands_t *p_cmds, bool b_expand) |
| 782 |
{ |
| 783 |
const char *s; |
| 784 |
|
| 785 |
fputs (_("# recipe to execute"), stdout); |
| 786 |
|
| 787 |
if (p_cmds->fileinfo.filenm == 0) |
| 788 |
puts (_(" (built-in):")); |
| 789 |
else |
| 790 |
printf (_(" (from '%s', line %lu):\n"), |
| 791 |
p_cmds->fileinfo.filenm, p_cmds->fileinfo.lineno); |
| 792 |
|
| 793 |
if (b_expand && p_target) { |
| 794 |
variable_set_list_t *p_file_vars = NULL; |
| 795 |
initialize_file_variables (p_target, 0); |
| 796 |
set_file_variables (p_target); |
| 797 |
p_file_vars = p_target->variables; |
| 798 |
s = variable_expand_set(p_cmds->commands, p_file_vars); |
| 799 |
} else { |
| 800 |
s = p_cmds->commands; |
| 801 |
} |
| 802 |
|
| 803 |
while (*s != '\0') |
| 804 |
{ |
| 805 |
const char *end; |
| 806 |
int bs; |
| 807 |
|
| 808 |
|
| 809 |
for (end = s, bs = 0; *end != '\0'; ++end) |
| 810 |
{ |
| 811 |
if (*end == '\n' && !bs) |
| 812 |
break; |
| 813 |
|
| 814 |
bs = *end == '\\' ? !bs : 0; |
| 815 |
} |
| 816 |
|
| 817 |
printf ("%c%.*s\n", cmd_prefix, (int) (end - s), s); |
| 818 |
|
| 819 |
s = end + (end[0] == '\n'); |
| 820 |
} |
| 821 |
} |