| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "makeint.h" |
| 18 |
#include "globals.h" |
| 19 |
#include "profile.h" |
| 20 |
|
| 21 |
#include "cmd.h" |
| 22 |
#include "filedef.h" |
| 23 |
#include "job.h" |
| 24 |
#include "commands.h" |
| 25 |
#include "dep.h" |
| 26 |
#include "variable.h" |
| 27 |
#include "debug.h" |
| 28 |
|
| 29 |
#include <assert.h> |
| 30 |
|
| 31 |
#ifdef HAVE_FCNTL_H |
| 32 |
#include <fcntl.h> |
| 33 |
#else |
| 34 |
#include <sys/file.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#define start_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\ |
| 42 |
->updating = 1) |
| 43 |
#define finish_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\ |
| 44 |
->updating = 0) |
| 45 |
#define is_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\ |
| 46 |
->updating) |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
unsigned int commands_started = 0; |
| 51 |
|
| 52 |
|
| 53 |
static struct goaldep *goal_list; |
| 54 |
static struct dep *goal_dep; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
static unsigned int considered = 0; |
| 59 |
|
| 60 |
static enum update_status update_file (struct file *file, unsigned int depth, |
| 61 |
target_stack_node_t *p_call_stack); |
| 62 |
static enum update_status update_file_1 (struct file *file, unsigned int depth, |
| 63 |
target_stack_node_t *p_call_stack); |
| 64 |
|
| 65 |
static enum update_status check_dep (struct file *file, unsigned int depth, |
| 66 |
FILE_TIMESTAMP this_mtime, int *must_make_ptr, |
| 67 |
target_stack_node_t *p_call_stack); |
| 68 |
static enum update_status touch_file (struct file *file); |
| 69 |
static void remake_file (struct file *file, |
| 70 |
target_stack_node_t *p_call_stack); |
| 71 |
static FILE_TIMESTAMP name_mtime (const char *name); |
| 72 |
static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
enum update_status |
| 84 |
update_goal_chain (struct goaldep *goaldeps) |
| 85 |
{ |
| 86 |
int t = touch_flag, q = question_flag, n = just_print_flag; |
| 87 |
enum update_status status = us_none; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
struct dep *goals = copy_dep_chain ((struct dep *)goaldeps); |
| 92 |
|
| 93 |
goal_list = rebuilding_makefiles ? goaldeps : NULL; |
| 94 |
|
| 95 |
#define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \ |
| 96 |
: file_mtime (file)) |
| 97 |
|
| 98 |
|
| 99 |
++considered; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
while (goals != 0) |
| 104 |
{ |
| 105 |
struct dep *g, *lastgoal; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
start_waiting_jobs (NULL); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
reap_children (1, 0, NULL); |
| 114 |
|
| 115 |
lastgoal = 0; |
| 116 |
g = goals; |
| 117 |
while (g != 0) |
| 118 |
{ |
| 119 |
|
| 120 |
struct file *file; |
| 121 |
int stop = 0, any_not_updated = 0; |
| 122 |
|
| 123 |
goal_dep = g; |
| 124 |
|
| 125 |
for (file = g->file->double_colon ? g->file->double_colon : g->file; |
| 126 |
file != NULL; |
| 127 |
file = file->prev) |
| 128 |
{ |
| 129 |
unsigned int ocommands_started; |
| 130 |
enum update_status fail; |
| 131 |
|
| 132 |
file->dontcare = ANY_SET (g->flags, RM_DONTCARE); |
| 133 |
|
| 134 |
check_renamed (file); |
| 135 |
if (rebuilding_makefiles) |
| 136 |
{ |
| 137 |
if (file->cmd_target) |
| 138 |
{ |
| 139 |
touch_flag = t; |
| 140 |
question_flag = q; |
| 141 |
just_print_flag = n; |
| 142 |
} |
| 143 |
else |
| 144 |
touch_flag = question_flag = just_print_flag = 0; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
ocommands_started = commands_started; |
| 151 |
|
| 152 |
fail = update_file (file, rebuilding_makefiles ? 1 : 0, NULL); |
| 153 |
check_renamed (file); |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
if (commands_started > ocommands_started) |
| 159 |
g->changed = 1; |
| 160 |
|
| 161 |
stop = 0; |
| 162 |
if ((fail || file->updated) && status < us_question) |
| 163 |
{ |
| 164 |
|
| 165 |
|
| 166 |
if (file->update_status) |
| 167 |
{ |
| 168 |
|
| 169 |
|
| 170 |
status = file->update_status; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
stop = (question_flag && !keep_going_flag |
| 175 |
&& !rebuilding_makefiles); |
| 176 |
} |
| 177 |
else |
| 178 |
{ |
| 179 |
FILE_TIMESTAMP mtime = MTIME (file); |
| 180 |
check_renamed (file); |
| 181 |
|
| 182 |
if (file->updated && g->changed && |
| 183 |
mtime != file->mtime_before_update) |
| 184 |
{ |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
if (!rebuilding_makefiles |
| 192 |
|| (!just_print_flag && !question_flag)) |
| 193 |
status = us_success; |
| 194 |
if (rebuilding_makefiles && file->dontcare) |
| 195 |
|
| 196 |
stop = 1; |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
any_not_updated |= !file->updated; |
| 204 |
|
| 205 |
file->dontcare = 0; |
| 206 |
|
| 207 |
if (stop) |
| 208 |
break; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
file = g->file; |
| 213 |
|
| 214 |
if (stop || !any_not_updated) |
| 215 |
{ |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
if (!rebuilding_makefiles |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
&& file->update_status == us_success && !g->changed |
| 224 |
|
| 225 |
&& !run_silent && !question_flag) { |
| 226 |
OS (message, 1, ((file->phony || file->cmds == 0) |
| 227 |
? _("Nothing to be done for '%s'.") |
| 228 |
: _("'%s' is up to date.")), |
| 229 |
file->name); |
| 230 |
if ( debugger_enabled && b_debugger_goal ) |
| 231 |
enter_debugger(NULL, file, -2, DEBUG_GOAL_UPDATED_HIT); |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
if (lastgoal == 0) |
| 236 |
goals = g->next; |
| 237 |
else |
| 238 |
lastgoal->next = g->next; |
| 239 |
|
| 240 |
|
| 241 |
free (g); |
| 242 |
|
| 243 |
g = lastgoal == 0 ? goals : lastgoal->next; |
| 244 |
|
| 245 |
if (stop) |
| 246 |
break; |
| 247 |
} |
| 248 |
else |
| 249 |
{ |
| 250 |
lastgoal = g; |
| 251 |
g = g->next; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
if (g == 0) |
| 258 |
++considered; |
| 259 |
} |
| 260 |
|
| 261 |
if (rebuilding_makefiles) |
| 262 |
{ |
| 263 |
touch_flag = t; |
| 264 |
question_flag = q; |
| 265 |
just_print_flag = n; |
| 266 |
} |
| 267 |
|
| 268 |
return status; |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
void |
| 275 |
show_goal_error (void) |
| 276 |
{ |
| 277 |
struct goaldep *goal; |
| 278 |
|
| 279 |
if ((goal_dep->flags & (RM_INCLUDED|RM_DONTCARE)) != RM_INCLUDED) |
| 280 |
return; |
| 281 |
|
| 282 |
for (goal = goal_list; goal; goal = goal->next) |
| 283 |
if (goal_dep->file == goal->file) |
| 284 |
{ |
| 285 |
if (goal->error) |
| 286 |
{ |
| 287 |
OSS (error, &goal->floc, "%s: %s", |
| 288 |
goal->file->name, strerror ((int)goal->error)); |
| 289 |
goal->error = 0; |
| 290 |
} |
| 291 |
return; |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
static enum update_status |
| 308 |
update_file (struct file *file, unsigned int depth, |
| 309 |
target_stack_node_t *p_call_stack) |
| 310 |
{ |
| 311 |
enum update_status status = us_success; |
| 312 |
struct file *f; |
| 313 |
|
| 314 |
f = file->double_colon ? file->double_colon : file; |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
if (f->considered == considered) |
| 321 |
{ |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
if (!(f->updated && f->update_status > us_none |
| 326 |
&& !f->dontcare && f->no_diag)) |
| 327 |
{ |
| 328 |
DBF (DB_VERBOSE, _("Pruning file '%s'.\n")); |
| 329 |
return f->command_state == cs_finished ? f->update_status : us_success; |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
for (; f != 0; f = f->prev) |
| 336 |
{ |
| 337 |
enum update_status new; |
| 338 |
|
| 339 |
f->considered = considered; |
| 340 |
|
| 341 |
new = update_file_1 (f, depth, p_call_stack); |
| 342 |
check_renamed (f); |
| 343 |
|
| 344 |
|
| 345 |
alloca (0); |
| 346 |
|
| 347 |
|
| 348 |
if (new && !keep_going_flag) |
| 349 |
return new; |
| 350 |
|
| 351 |
if (f->command_state == cs_running |
| 352 |
|| f->command_state == cs_deps_running) |
| 353 |
|
| 354 |
|
| 355 |
return us_success; |
| 356 |
|
| 357 |
if (new > status) |
| 358 |
status = new; |
| 359 |
} |
| 360 |
|
| 361 |
return status; |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
static void |
| 367 |
complain (struct file *file) |
| 368 |
{ |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
struct dep *d; |
| 376 |
|
| 377 |
for (d = file->deps; d != 0; d = d->next) |
| 378 |
{ |
| 379 |
if (d->file->updated && d->file->update_status > us_none && file->no_diag) |
| 380 |
{ |
| 381 |
complain (d->file); |
| 382 |
break; |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
if (d == 0) |
| 387 |
{ |
| 388 |
show_goal_error (); |
| 389 |
|
| 390 |
|
| 391 |
if (file->parent) |
| 392 |
{ |
| 393 |
size_t l = strlen (file->name) + strlen (file->parent->name) + 4; |
| 394 |
const char *m = _("%sNo rule to make target '%s', needed by '%s'%s"); |
| 395 |
|
| 396 |
if (!keep_going_flag) |
| 397 |
fatal (NILF, l, m, "", file->name, file->parent->name, ""); |
| 398 |
|
| 399 |
error (NILF, l, m, "*** ", file->name, file->parent->name, "."); |
| 400 |
} |
| 401 |
else |
| 402 |
{ |
| 403 |
size_t l = strlen (file->name) + 4; |
| 404 |
const char *m = _("%sNo rule to make target '%s'%s"); |
| 405 |
|
| 406 |
if (!keep_going_flag) |
| 407 |
fatal (NILF, l, m, "", file->name, ""); |
| 408 |
|
| 409 |
error (NILF, l, m, "*** ", file->name, "."); |
| 410 |
} |
| 411 |
|
| 412 |
file->no_diag = 0; |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
static enum update_status |
| 420 |
update_file_1 (struct file *file, unsigned int depth, |
| 421 |
target_stack_node_t *p_call_stack) |
| 422 |
{ |
| 423 |
enum update_status dep_status = us_success; |
| 424 |
FILE_TIMESTAMP this_mtime; |
| 425 |
int noexist, must_make, deps_changed; |
| 426 |
struct file *ofile; |
| 427 |
struct dep *d, *ad; |
| 428 |
struct dep amake; |
| 429 |
int running = 0; |
| 430 |
|
| 431 |
DBF (DB_VERBOSE, _("Considering target file '%s'.\n")); |
| 432 |
p_stack_top = p_call_stack = trace_push_target(p_call_stack, file); |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
if ( (i_debugger_stepping && file->cmds) || |
| 438 |
(file->tracing & BRK_BEFORE_PREREQ) ) |
| 439 |
enter_debugger(p_call_stack, file, 0, DEBUG_BRKPT_BEFORE_PREREQ); |
| 440 |
|
| 441 |
if (file->updated) |
| 442 |
{ |
| 443 |
if (file->update_status > us_none) |
| 444 |
{ |
| 445 |
DBF (DB_VERBOSE, |
| 446 |
_("Recently tried and failed to update file '%s'.\n")); |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
if (file->no_diag && !file->dontcare) |
| 453 |
complain (file); |
| 454 |
|
| 455 |
return file->update_status; |
| 456 |
} |
| 457 |
|
| 458 |
DBF (DB_VERBOSE, _("File '%s' was considered already.\n")); |
| 459 |
trace_pop_target(p_call_stack); |
| 460 |
return 0; |
| 461 |
} |
| 462 |
|
| 463 |
switch (file->command_state) |
| 464 |
{ |
| 465 |
case cs_not_started: |
| 466 |
case cs_deps_running: |
| 467 |
break; |
| 468 |
case cs_running: |
| 469 |
DBF (DB_VERBOSE, _("Still updating file '%s'.\n")); |
| 470 |
trace_pop_target(p_call_stack); |
| 471 |
return 0; |
| 472 |
case cs_finished: |
| 473 |
DBF (DB_VERBOSE, _("Finished updating file '%s'.\n")); |
| 474 |
trace_pop_target(p_call_stack); |
| 475 |
return file->update_status; |
| 476 |
default: |
| 477 |
abort (); |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
file->no_diag = file->dontcare; |
| 483 |
|
| 484 |
++depth; |
| 485 |
|
| 486 |
|
| 487 |
start_updating (file); |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
ofile = file; |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
this_mtime = file_mtime (file); |
| 500 |
check_renamed (file); |
| 501 |
noexist = this_mtime == NONEXISTENT_MTIME; |
| 502 |
if (noexist) { |
| 503 |
DBF (DB_BASIC, _("File '%s' does not exist.\n")); |
| 504 |
if (i_debugger_nexting && file->cmds) { |
| 505 |
enter_debugger(p_call_stack, file, 0, DEBUG_STEP_HIT); |
| 506 |
} |
| 507 |
} else if (ORDINARY_MTIME_MIN <= this_mtime && this_mtime <= ORDINARY_MTIME_MAX |
| 508 |
&& file->low_resolution_time) |
| 509 |
{ |
| 510 |
|
| 511 |
int ns = FILE_TIMESTAMP_NS (this_mtime); |
| 512 |
if (ns != 0) |
| 513 |
OS (error, NILF, |
| 514 |
_("*** Warning: .LOW_RESOLUTION_TIME file '%s' has a high resolution time stamp"), |
| 515 |
file->name); |
| 516 |
this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns; |
| 517 |
} |
| 518 |
|
| 519 |
must_make = noexist; |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
if (!file->phony && file->cmds == 0 && !file->tried_implicit) |
| 525 |
{ |
| 526 |
if (try_implicit_rule (file, depth)) |
| 527 |
DBF (DB_IMPLICIT, _("Found an implicit rule for '%s'.\n")); |
| 528 |
else |
| 529 |
DBF (DB_IMPLICIT, _("No implicit rule found for '%s'.\n")); |
| 530 |
file->tried_implicit = 1; |
| 531 |
} |
| 532 |
if (file->cmds == 0 && !file->is_target |
| 533 |
&& default_file != 0 && default_file->cmds != 0) |
| 534 |
{ |
| 535 |
DBF (DB_IMPLICIT, _("Using default recipe for '%s'.\n")); |
| 536 |
file->cmds = default_file->cmds; |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
amake.file = file; |
| 545 |
amake.next = file->also_make; |
| 546 |
ad = &amake; |
| 547 |
while (ad) |
| 548 |
{ |
| 549 |
struct dep *lastd = 0; |
| 550 |
|
| 551 |
|
| 552 |
d = ad->file->deps; |
| 553 |
ad = ad->next; |
| 554 |
|
| 555 |
while (d) |
| 556 |
{ |
| 557 |
enum update_status new; |
| 558 |
FILE_TIMESTAMP mtime; |
| 559 |
int maybe_make; |
| 560 |
int dontcare = 0; |
| 561 |
|
| 562 |
check_renamed (d->file); |
| 563 |
|
| 564 |
mtime = file_mtime (d->file); |
| 565 |
check_renamed (d->file); |
| 566 |
|
| 567 |
if (is_updating (d->file)) |
| 568 |
{ |
| 569 |
OSS (error, NILF, _("Circular %s <- %s dependency dropped."), |
| 570 |
file->name, d->file->name); |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
if (lastd == 0) |
| 575 |
file->deps = d->next; |
| 576 |
else |
| 577 |
lastd->next = d->next; |
| 578 |
d = d->next; |
| 579 |
continue; |
| 580 |
} |
| 581 |
|
| 582 |
d->file->parent = file; |
| 583 |
maybe_make = must_make; |
| 584 |
|
| 585 |
|
| 586 |
if (rebuilding_makefiles) |
| 587 |
{ |
| 588 |
dontcare = d->file->dontcare; |
| 589 |
d->file->dontcare = file->dontcare; |
| 590 |
} |
| 591 |
|
| 592 |
new = check_dep (d->file, depth, this_mtime, &maybe_make, |
| 593 |
p_call_stack); |
| 594 |
if (new > dep_status) |
| 595 |
dep_status = new; |
| 596 |
|
| 597 |
|
| 598 |
if (rebuilding_makefiles) |
| 599 |
d->file->dontcare = dontcare; |
| 600 |
|
| 601 |
if (! d->ignore_mtime) |
| 602 |
must_make = maybe_make; |
| 603 |
|
| 604 |
check_renamed (d->file); |
| 605 |
|
| 606 |
{ |
| 607 |
struct file *f = d->file; |
| 608 |
if (f->double_colon) |
| 609 |
f = f->double_colon; |
| 610 |
do |
| 611 |
{ |
| 612 |
running |= (f->command_state == cs_running |
| 613 |
|| f->command_state == cs_deps_running); |
| 614 |
f = f->prev; |
| 615 |
} |
| 616 |
while (f != 0); |
| 617 |
} |
| 618 |
|
| 619 |
if (dep_status && !keep_going_flag) |
| 620 |
break; |
| 621 |
|
| 622 |
if (!running) |
| 623 |
|
| 624 |
|
| 625 |
d->changed = ((file_mtime (d->file) != mtime) |
| 626 |
|| (mtime == NONEXISTENT_MTIME)); |
| 627 |
|
| 628 |
lastd = d; |
| 629 |
d = d->next; |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
if (must_make || always_make_flag) |
| 637 |
{ |
| 638 |
for (d = file->deps; d != 0; d = d->next) |
| 639 |
if (d->file->intermediate) |
| 640 |
{ |
| 641 |
enum update_status new; |
| 642 |
int dontcare = 0; |
| 643 |
|
| 644 |
FILE_TIMESTAMP mtime = file_mtime (d->file); |
| 645 |
check_renamed (d->file); |
| 646 |
d->file->parent = file; |
| 647 |
|
| 648 |
|
| 649 |
if (rebuilding_makefiles) |
| 650 |
{ |
| 651 |
dontcare = d->file->dontcare; |
| 652 |
d->file->dontcare = file->dontcare; |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
d->file->considered = 0; |
| 659 |
|
| 660 |
new = update_file (d->file, depth, p_call_stack); |
| 661 |
if (new > dep_status) |
| 662 |
dep_status = new; |
| 663 |
|
| 664 |
|
| 665 |
if (rebuilding_makefiles) |
| 666 |
d->file->dontcare = dontcare; |
| 667 |
|
| 668 |
check_renamed (d->file); |
| 669 |
|
| 670 |
{ |
| 671 |
struct file *f = d->file; |
| 672 |
if (f->double_colon) |
| 673 |
f = f->double_colon; |
| 674 |
do |
| 675 |
{ |
| 676 |
running |= (f->command_state == cs_running |
| 677 |
|| f->command_state == cs_deps_running); |
| 678 |
f = f->prev; |
| 679 |
} |
| 680 |
while (f != 0); |
| 681 |
} |
| 682 |
|
| 683 |
if (dep_status && !keep_going_flag) |
| 684 |
break; |
| 685 |
|
| 686 |
if (!running) |
| 687 |
d->changed = ((file->phony && file->cmds != 0) |
| 688 |
|| file_mtime (d->file) != mtime); |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
finish_updating (file); |
| 693 |
finish_updating (ofile); |
| 694 |
|
| 695 |
DBF (DB_VERBOSE, _("Finished prerequisites of target file '%s'.\n")); |
| 696 |
|
| 697 |
if ( file->tracing & BRK_AFTER_PREREQ ) |
| 698 |
enter_debugger(p_call_stack, file, 0, DEBUG_BRKPT_AFTER_PREREQ); |
| 699 |
|
| 700 |
if (running) |
| 701 |
{ |
| 702 |
set_command_state (file, cs_deps_running); |
| 703 |
--depth; |
| 704 |
DBF (DB_VERBOSE, _("The prerequisites of '%s' are being made.\n")); |
| 705 |
trace_pop_target(p_call_stack); |
| 706 |
return 0; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
if (dep_status) |
| 712 |
{ |
| 713 |
|
| 714 |
file->update_status = dep_status == us_none ? us_failed : dep_status; |
| 715 |
notice_finished_file (file); |
| 716 |
|
| 717 |
--depth; |
| 718 |
|
| 719 |
DBF (DB_VERBOSE, _("Giving up on target file '%s'.\n")); |
| 720 |
|
| 721 |
if (depth == 0 && keep_going_flag |
| 722 |
&& !just_print_flag && !question_flag) |
| 723 |
OS (error, NILF, |
| 724 |
_("Target '%s' not remade because of errors."), file->name); |
| 725 |
|
| 726 |
trace_pop_target(p_call_stack); |
| 727 |
return dep_status; |
| 728 |
} |
| 729 |
|
| 730 |
if (file->command_state == cs_deps_running) |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
set_command_state (file, cs_not_started); |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
deps_changed = 0; |
| 745 |
for (d = file->deps; d != 0; d = d->next) |
| 746 |
{ |
| 747 |
FILE_TIMESTAMP d_mtime = file_mtime (d->file); |
| 748 |
check_renamed (d->file); |
| 749 |
|
| 750 |
if (! d->ignore_mtime) |
| 751 |
{ |
| 752 |
#if 1 |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate) |
| 757 |
|
| 758 |
|
| 759 |
must_make = 1; |
| 760 |
#endif |
| 761 |
|
| 762 |
|
| 763 |
deps_changed |= d->changed; |
| 764 |
} |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
d->changed |= noexist || d_mtime > this_mtime; |
| 769 |
|
| 770 |
if (!noexist && ISDB (DB_BASIC|DB_VERBOSE)) |
| 771 |
{ |
| 772 |
const char *fmt = 0; |
| 773 |
|
| 774 |
if (d->ignore_mtime) |
| 775 |
{ |
| 776 |
if (ISDB (DB_VERBOSE)) |
| 777 |
fmt = _("Prerequisite '%s' is order-only for target '%s'.\n"); |
| 778 |
} |
| 779 |
else if (d_mtime == NONEXISTENT_MTIME) |
| 780 |
{ |
| 781 |
if (ISDB (DB_BASIC)) |
| 782 |
fmt = _("Prerequisite '%s' of target '%s' does not exist.\n"); |
| 783 |
} |
| 784 |
else if (d->changed) |
| 785 |
{ |
| 786 |
if (ISDB (DB_BASIC)) |
| 787 |
fmt = _("Prerequisite '%s' is newer than target '%s'.\n"); |
| 788 |
} |
| 789 |
else if (ISDB (DB_VERBOSE)) |
| 790 |
fmt = _("Prerequisite '%s' is older than target '%s'.\n"); |
| 791 |
|
| 792 |
if (fmt) |
| 793 |
{ |
| 794 |
print_spaces (depth); |
| 795 |
printf (fmt, dep_name (d), file->name); |
| 796 |
fflush (stdout); |
| 797 |
} |
| 798 |
} |
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
depth--; |
| 803 |
|
| 804 |
if (file->double_colon && file->deps == 0) |
| 805 |
{ |
| 806 |
must_make = 1; |
| 807 |
DBF (DB_BASIC, |
| 808 |
_("Target '%s' is double-colon and has no prerequisites.\n")); |
| 809 |
} |
| 810 |
else if (!noexist && file->is_target && !deps_changed && file->cmds == 0 |
| 811 |
&& !always_make_flag) |
| 812 |
{ |
| 813 |
must_make = 0; |
| 814 |
DBF (DB_VERBOSE, |
| 815 |
_("No recipe for '%s' and no prerequisites actually changed.\n")); |
| 816 |
} |
| 817 |
else if (!must_make && file->cmds != 0 && always_make_flag) |
| 818 |
{ |
| 819 |
must_make = 1; |
| 820 |
DBF (DB_VERBOSE, _("Making '%s' due to always-make flag.\n")); |
| 821 |
} |
| 822 |
|
| 823 |
if (!must_make) |
| 824 |
{ |
| 825 |
if (ISDB (DB_VERBOSE)) |
| 826 |
{ |
| 827 |
print_spaces (depth); |
| 828 |
printf (_("No need to remake target '%s'"), file->name); |
| 829 |
if (!streq (file->name, file->hname)) |
| 830 |
printf (_("; using VPATH name '%s'"), file->hname); |
| 831 |
puts ("."); |
| 832 |
fflush (stdout); |
| 833 |
} |
| 834 |
|
| 835 |
notice_finished_file (file); |
| 836 |
trace_pop_target(p_call_stack); |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
while (file) |
| 843 |
{ |
| 844 |
file->name = file->hname; |
| 845 |
file = file->prev; |
| 846 |
} |
| 847 |
|
| 848 |
return 0; |
| 849 |
} |
| 850 |
|
| 851 |
DBF (DB_BASIC, _("Must remake target '%s'.\n")); |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
if (!streq (file->name, file->hname)) |
| 856 |
{ |
| 857 |
DB (DB_BASIC, (_(" Ignoring VPATH name '%s'.\n"), file->hname)); |
| 858 |
file->ignore_vpath = 1; |
| 859 |
} |
| 860 |
|
| 861 |
|
| 862 |
remake_file (file, p_call_stack); |
| 863 |
|
| 864 |
if (file->command_state != cs_finished) |
| 865 |
{ |
| 866 |
DBF (DB_VERBOSE, _("Recipe of '%s' is being run.\n")); |
| 867 |
if ( file->tracing & BRK_AFTER_CMD || i_debugger_stepping ) |
| 868 |
enter_debugger(p_call_stack, file, 0, DEBUG_BRKPT_AFTER_CMD); |
| 869 |
trace_pop_target(p_call_stack); |
| 870 |
return 0; |
| 871 |
} |
| 872 |
|
| 873 |
switch (file->update_status) |
| 874 |
{ |
| 875 |
case us_failed: |
| 876 |
DBF (DB_BASIC, _("Failed to remake target file '%s'.\n")); |
| 877 |
break; |
| 878 |
case us_success: |
| 879 |
DBF (DB_BASIC, _("Successfully remade target file '%s'.\n")); |
| 880 |
break; |
| 881 |
case us_question: |
| 882 |
DBF (DB_BASIC, _("Target file '%s' needs to be remade under -q.\n")); |
| 883 |
break; |
| 884 |
case us_none: |
| 885 |
break; |
| 886 |
} |
| 887 |
|
| 888 |
file->updated = 1; |
| 889 |
if ( file->tracing & BRK_AFTER_CMD || i_debugger_stepping ) |
| 890 |
enter_debugger(p_call_stack, file, 0, DEBUG_BRKPT_AFTER_CMD); |
| 891 |
|
| 892 |
trace_pop_target(p_call_stack); |
| 893 |
return file->update_status; |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
void |
| 903 |
notice_finished_file (struct file *file) |
| 904 |
{ |
| 905 |
struct dep *d; |
| 906 |
int ran = file->command_state == cs_running; |
| 907 |
int touched = 0; |
| 908 |
|
| 909 |
file->command_state = cs_finished; |
| 910 |
file->updated = 1; |
| 911 |
|
| 912 |
if (touch_flag |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
&& file->update_status == us_success) |
| 920 |
{ |
| 921 |
if (file->cmds != 0 && file->cmds->any_recurse) |
| 922 |
{ |
| 923 |
|
| 924 |
|
| 925 |
unsigned int i; |
| 926 |
for (i = 0; i < file->cmds->ncommand_lines; ++i) |
| 927 |
if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE)) |
| 928 |
goto have_nonrecursing; |
| 929 |
} |
| 930 |
else |
| 931 |
{ |
| 932 |
have_nonrecursing: |
| 933 |
if (file->phony) |
| 934 |
file->update_status = us_success; |
| 935 |
|
| 936 |
else if (file->cmds != 0) |
| 937 |
{ |
| 938 |
|
| 939 |
file->update_status = touch_file (file); |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
commands_started++; |
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
touched = 1; |
| 950 |
} |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
if (file->mtime_before_update == UNKNOWN_MTIME) |
| 955 |
file->mtime_before_update = file->last_mtime; |
| 956 |
|
| 957 |
if ((ran && !file->phony) || touched) |
| 958 |
{ |
| 959 |
int i = 0; |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
if ((question_flag || just_print_flag || touch_flag) && file->cmds) |
| 966 |
{ |
| 967 |
for (i = file->cmds->ncommand_lines; i > 0; --i) |
| 968 |
if (! (file->cmds->lines_flags[i-1] & COMMANDS_RECURSE)) |
| 969 |
break; |
| 970 |
} |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
else if (file->is_target && file->cmds == 0) |
| 975 |
i = 1; |
| 976 |
|
| 977 |
file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME; |
| 978 |
} |
| 979 |
|
| 980 |
if (file->double_colon) |
| 981 |
{ |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
struct file *f; |
| 993 |
FILE_TIMESTAMP max_mtime = file->last_mtime; |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
for (f = file->double_colon; f != 0 && f->updated; f = f->prev) |
| 999 |
if (max_mtime != UNKNOWN_MTIME |
| 1000 |
&& (f->last_mtime == UNKNOWN_MTIME || f->last_mtime > max_mtime)) |
| 1001 |
max_mtime = f->last_mtime; |
| 1002 |
|
| 1003 |
if (f == 0) |
| 1004 |
for (f = file->double_colon; f != 0; f = f->prev) |
| 1005 |
f->last_mtime = max_mtime; |
| 1006 |
} |
| 1007 |
|
| 1008 |
if (ran && file->update_status != us_none) |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
for (d = file->also_make; d != 0; d = d->next) |
| 1014 |
{ |
| 1015 |
d->file->command_state = cs_finished; |
| 1016 |
d->file->updated = 1; |
| 1017 |
d->file->update_status = file->update_status; |
| 1018 |
|
| 1019 |
if (ran && !d->file->phony) |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
f_mtime (d->file, 0); |
| 1025 |
} |
| 1026 |
else if (file->update_status == us_none) |
| 1027 |
|
| 1028 |
|
| 1029 |
file->update_status = us_success; |
| 1030 |
|
| 1031 |
if (profile_flag) { |
| 1032 |
profile_add_timestamp(file); |
| 1033 |
} |
| 1034 |
} |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
static enum update_status |
| 1043 |
check_dep (struct file *file, unsigned int depth, |
| 1044 |
FILE_TIMESTAMP this_mtime, int *must_make_ptr, |
| 1045 |
target_stack_node_t *p_call_stack) |
| 1046 |
{ |
| 1047 |
struct file *ofile; |
| 1048 |
struct dep *d; |
| 1049 |
enum update_status dep_status = us_success; |
| 1050 |
|
| 1051 |
++depth; |
| 1052 |
start_updating (file); |
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
ofile = file; |
| 1057 |
|
| 1058 |
if (file->phony || !file->intermediate) |
| 1059 |
{ |
| 1060 |
|
| 1061 |
|
| 1062 |
FILE_TIMESTAMP mtime; |
| 1063 |
dep_status = update_file (file, depth, p_call_stack); |
| 1064 |
check_renamed (file); |
| 1065 |
mtime = file_mtime (file); |
| 1066 |
check_renamed (file); |
| 1067 |
if (mtime == NONEXISTENT_MTIME || mtime > this_mtime) |
| 1068 |
*must_make_ptr = 1; |
| 1069 |
} |
| 1070 |
else |
| 1071 |
{ |
| 1072 |
|
| 1073 |
FILE_TIMESTAMP mtime; |
| 1074 |
|
| 1075 |
if (!file->phony && file->cmds == 0 && !file->tried_implicit) |
| 1076 |
{ |
| 1077 |
if (try_implicit_rule (file, depth)) |
| 1078 |
DBF (DB_IMPLICIT, _("Found an implicit rule for '%s'.\n")); |
| 1079 |
else |
| 1080 |
DBF (DB_IMPLICIT, _("No implicit rule found for '%s'.\n")); |
| 1081 |
file->tried_implicit = 1; |
| 1082 |
} |
| 1083 |
if (file->cmds == 0 && !file->is_target |
| 1084 |
&& default_file != 0 && default_file->cmds != 0) |
| 1085 |
{ |
| 1086 |
DBF (DB_IMPLICIT, _("Using default commands for '%s'.\n")); |
| 1087 |
file->cmds = default_file->cmds; |
| 1088 |
} |
| 1089 |
|
| 1090 |
check_renamed (file); |
| 1091 |
mtime = file_mtime (file); |
| 1092 |
check_renamed (file); |
| 1093 |
if (mtime != NONEXISTENT_MTIME && mtime > this_mtime) |
| 1094 |
|
| 1095 |
|
| 1096 |
*must_make_ptr = 1; |
| 1097 |
else |
| 1098 |
{ |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
struct dep *ld; |
| 1103 |
int deps_running = 0; |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
if (file->command_state != cs_running) |
| 1109 |
{ |
| 1110 |
|
| 1111 |
|
| 1112 |
if (file->command_state == cs_deps_running) |
| 1113 |
file->considered = 0; |
| 1114 |
|
| 1115 |
set_command_state (file, cs_not_started); |
| 1116 |
} |
| 1117 |
|
| 1118 |
ld = 0; |
| 1119 |
d = file->deps; |
| 1120 |
while (d != 0) |
| 1121 |
{ |
| 1122 |
enum update_status new; |
| 1123 |
int maybe_make; |
| 1124 |
|
| 1125 |
if (is_updating (d->file)) |
| 1126 |
{ |
| 1127 |
OSS (error, NILF, _("Circular %s <- %s dependency dropped."), |
| 1128 |
file->name, d->file->name); |
| 1129 |
if (ld == 0) |
| 1130 |
{ |
| 1131 |
file->deps = d->next; |
| 1132 |
free_dep (d); |
| 1133 |
d = file->deps; |
| 1134 |
} |
| 1135 |
else |
| 1136 |
{ |
| 1137 |
ld->next = d->next; |
| 1138 |
free_dep (d); |
| 1139 |
d = ld->next; |
| 1140 |
} |
| 1141 |
continue; |
| 1142 |
} |
| 1143 |
|
| 1144 |
d->file->parent = file; |
| 1145 |
maybe_make = *must_make_ptr; |
| 1146 |
new = check_dep (d->file, depth, this_mtime, &maybe_make, p_call_stack); |
| 1147 |
if (new > dep_status) |
| 1148 |
dep_status = new; |
| 1149 |
|
| 1150 |
if (! d->ignore_mtime) |
| 1151 |
*must_make_ptr = maybe_make; |
| 1152 |
check_renamed (d->file); |
| 1153 |
if (dep_status && !keep_going_flag) |
| 1154 |
break; |
| 1155 |
|
| 1156 |
if (d->file->command_state == cs_running |
| 1157 |
|| d->file->command_state == cs_deps_running) |
| 1158 |
deps_running = 1; |
| 1159 |
|
| 1160 |
ld = d; |
| 1161 |
d = d->next; |
| 1162 |
} |
| 1163 |
|
| 1164 |
if (deps_running) |
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
set_command_state (file, cs_deps_running); |
| 1169 |
} |
| 1170 |
} |
| 1171 |
|
| 1172 |
finish_updating (file); |
| 1173 |
finish_updating (ofile); |
| 1174 |
|
| 1175 |
return dep_status; |
| 1176 |
} |
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
#define TOUCH_ERROR(call) do{ perror_with_name ((call), file->name); \ |
| 1181 |
return us_failed; }while(0) |
| 1182 |
|
| 1183 |
static enum update_status |
| 1184 |
touch_file (struct file *file) |
| 1185 |
{ |
| 1186 |
if (!run_silent) |
| 1187 |
OS (message, 0, "touch %s", file->name); |
| 1188 |
|
| 1189 |
|
| 1190 |
if (just_print_flag) |
| 1191 |
return us_success; |
| 1192 |
|
| 1193 |
#ifndef NO_ARCHIVES |
| 1194 |
if (ar_name (file->name)) |
| 1195 |
return ar_touch (file->name) ? us_failed : us_success; |
| 1196 |
else |
| 1197 |
#endif |
| 1198 |
{ |
| 1199 |
int fd; |
| 1200 |
|
| 1201 |
EINTRLOOP (fd, open (file->name, O_RDWR | O_CREAT, 0666)); |
| 1202 |
if (fd < 0) |
| 1203 |
TOUCH_ERROR ("touch: open: "); |
| 1204 |
else |
| 1205 |
{ |
| 1206 |
struct stat statbuf; |
| 1207 |
char buf = 'x'; |
| 1208 |
int e; |
| 1209 |
|
| 1210 |
EINTRLOOP (e, fstat (fd, &statbuf)); |
| 1211 |
if (e < 0) |
| 1212 |
TOUCH_ERROR ("touch: fstat: "); |
| 1213 |
|
| 1214 |
EINTRLOOP (e, read (fd, &buf, 1)); |
| 1215 |
if (e < 0) |
| 1216 |
TOUCH_ERROR ("touch: read: "); |
| 1217 |
{ |
| 1218 |
off_t o; |
| 1219 |
EINTRLOOP (o, lseek (fd, 0L, 0)); |
| 1220 |
if (o < 0L) |
| 1221 |
TOUCH_ERROR ("touch: lseek: "); |
| 1222 |
} |
| 1223 |
EINTRLOOP (e, write (fd, &buf, 1)); |
| 1224 |
if (e < 0) |
| 1225 |
TOUCH_ERROR ("touch: write: "); |
| 1226 |
|
| 1227 |
|
| 1228 |
if (statbuf.st_size == 0) |
| 1229 |
{ |
| 1230 |
(void) close (fd); |
| 1231 |
EINTRLOOP (fd, open (file->name, O_RDWR | O_TRUNC, 0666)); |
| 1232 |
if (fd < 0) |
| 1233 |
TOUCH_ERROR ("touch: open: "); |
| 1234 |
} |
| 1235 |
(void) close (fd); |
| 1236 |
} |
| 1237 |
} |
| 1238 |
|
| 1239 |
return us_success; |
| 1240 |
} |
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
static void |
| 1247 |
remake_file (file_t *file, target_stack_node_t *p_call_stack) |
| 1248 |
{ |
| 1249 |
if (file->cmds == 0) |
| 1250 |
{ |
| 1251 |
if (file->phony) |
| 1252 |
|
| 1253 |
file->update_status = us_success; |
| 1254 |
else if (file->is_target) |
| 1255 |
|
| 1256 |
|
| 1257 |
file->update_status = us_success; |
| 1258 |
else |
| 1259 |
{ |
| 1260 |
|
| 1261 |
if (!rebuilding_makefiles || !file->dontcare) |
| 1262 |
complain (file); |
| 1263 |
file->update_status = us_failed; |
| 1264 |
} |
| 1265 |
} |
| 1266 |
else |
| 1267 |
{ |
| 1268 |
chop_commands (file->cmds); |
| 1269 |
|
| 1270 |
|
| 1271 |
if (!touch_flag || file->cmds->any_recurse) |
| 1272 |
{ |
| 1273 |
execute_file_commands (file, p_call_stack); |
| 1274 |
return; |
| 1275 |
} |
| 1276 |
|
| 1277 |
|
| 1278 |
file->update_status = us_success; |
| 1279 |
} |
| 1280 |
|
| 1281 |
|
| 1282 |
notice_finished_file (file); |
| 1283 |
} |
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
FILE_TIMESTAMP |
| 1294 |
f_mtime (struct file *file, int search) |
| 1295 |
{ |
| 1296 |
FILE_TIMESTAMP mtime; |
| 1297 |
unsigned int propagate_timestamp; |
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
#ifndef NO_ARCHIVES |
| 1302 |
if (ar_name (file->name)) |
| 1303 |
{ |
| 1304 |
|
| 1305 |
|
| 1306 |
char *arname, *memname; |
| 1307 |
struct file *arfile; |
| 1308 |
int found; |
| 1309 |
time_t member_date; |
| 1310 |
|
| 1311 |
|
| 1312 |
ar_parse_name (file->name, &arname, &memname); |
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
arfile = lookup_file (arname); |
| 1317 |
if (arfile == 0) |
| 1318 |
arfile = enter_file (strcache_add (arname)); |
| 1319 |
mtime = f_mtime (arfile, search); |
| 1320 |
check_renamed (arfile); |
| 1321 |
if (search && strcmp (arfile->hname, arname)) |
| 1322 |
{ |
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
char *name; |
| 1327 |
size_t arlen, memlen; |
| 1328 |
|
| 1329 |
arlen = strlen (arfile->hname); |
| 1330 |
memlen = strlen (memname); |
| 1331 |
|
| 1332 |
name = alloca (arlen + 1 + memlen + 2); |
| 1333 |
memcpy (name, arfile->hname, arlen); |
| 1334 |
name[arlen] = '('; |
| 1335 |
memcpy (name + arlen + 1, memname, memlen); |
| 1336 |
name[arlen + 1 + memlen] = ')'; |
| 1337 |
name[arlen + 1 + memlen + 1] = '\0'; |
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
if (arfile->name == arfile->hname) |
| 1342 |
rename_file (file, strcache_add (name)); |
| 1343 |
else |
| 1344 |
rehash_file (file, strcache_add (name)); |
| 1345 |
check_renamed (file); |
| 1346 |
} |
| 1347 |
|
| 1348 |
free (arname); |
| 1349 |
|
| 1350 |
file->low_resolution_time = 1; |
| 1351 |
|
| 1352 |
if (mtime == NONEXISTENT_MTIME) |
| 1353 |
|
| 1354 |
return NONEXISTENT_MTIME; |
| 1355 |
|
| 1356 |
found = ar_member_date (file->hname, &member_date); |
| 1357 |
if (found && member_date == (time_t) 0) |
| 1358 |
{ |
| 1359 |
OSS (error, NILF, |
| 1360 |
_("Warning: Archive '%s' seems to have been created in deterministic mode. '%s' will always be updated. Please consider passing the U flag to ar to avoid the problem."), |
| 1361 |
arfile->name, memname); |
| 1362 |
|
| 1363 |
} |
| 1364 |
mtime = found ? file_timestamp_cons (file->hname, member_date, 0) : NONEXISTENT_MTIME; |
| 1365 |
} |
| 1366 |
else |
| 1367 |
#endif |
| 1368 |
{ |
| 1369 |
mtime = name_mtime (file->name); |
| 1370 |
|
| 1371 |
if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath) |
| 1372 |
{ |
| 1373 |
|
| 1374 |
const char *name = vpath_search (file->name, &mtime, NULL, NULL); |
| 1375 |
if (name |
| 1376 |
|
| 1377 |
|| (file->name[0] == '-' && file->name[1] == 'l' |
| 1378 |
&& (name = library_search (file->name, &mtime)) != 0)) |
| 1379 |
{ |
| 1380 |
size_t name_len; |
| 1381 |
|
| 1382 |
if (mtime != UNKNOWN_MTIME) |
| 1383 |
|
| 1384 |
|
| 1385 |
file->last_mtime = mtime; |
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
name_len = strlen (name) - strlen (file->name); |
| 1391 |
if (name[name_len - 1] == '/') |
| 1392 |
name_len--; |
| 1393 |
if (gpath_search (name, name_len)) |
| 1394 |
{ |
| 1395 |
rename_file (file, name); |
| 1396 |
check_renamed (file); |
| 1397 |
return file_mtime (file); |
| 1398 |
} |
| 1399 |
|
| 1400 |
rehash_file (file, name); |
| 1401 |
check_renamed (file); |
| 1402 |
|
| 1403 |
|
| 1404 |
if (mtime != OLD_MTIME && mtime != NEW_MTIME) |
| 1405 |
mtime = name_mtime (name); |
| 1406 |
} |
| 1407 |
} |
| 1408 |
} |
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
if (!clock_skew_detected |
| 1417 |
&& mtime != NONEXISTENT_MTIME && mtime != NEW_MTIME |
| 1418 |
&& !file->updated) |
| 1419 |
{ |
| 1420 |
static FILE_TIMESTAMP adjusted_now; |
| 1421 |
|
| 1422 |
FILE_TIMESTAMP adjusted_mtime = mtime; |
| 1423 |
|
| 1424 |
#if defined(WINDOWS32) || defined(__MSDOS__) |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
#define FAT_ADJ_OFFSET (FILE_TIMESTAMP) 3 |
| 1429 |
|
| 1430 |
FILE_TIMESTAMP adjustment = FAT_ADJ_OFFSET << FILE_TIMESTAMP_LO_BITS; |
| 1431 |
if (ORDINARY_MTIME_MIN + adjustment <= adjusted_mtime) |
| 1432 |
adjusted_mtime -= adjustment; |
| 1433 |
#elif defined(__EMX__) |
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
FILE_TIMESTAMP adjustment = (((FILE_TIMESTAMP_S (adjusted_mtime) & 1) == 0 |
| 1438 |
&& FILE_TIMESTAMP_NS (adjusted_mtime) == 0) |
| 1439 |
? (FILE_TIMESTAMP) 1 << FILE_TIMESTAMP_LO_BITS |
| 1440 |
: 0); |
| 1441 |
#endif |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
if (adjusted_now < adjusted_mtime) |
| 1446 |
{ |
| 1447 |
int resolution; |
| 1448 |
FILE_TIMESTAMP now = file_timestamp_now (&resolution); |
| 1449 |
adjusted_now = now + (resolution - 1); |
| 1450 |
if (adjusted_now < adjusted_mtime) |
| 1451 |
{ |
| 1452 |
double from_now = |
| 1453 |
(FILE_TIMESTAMP_S (mtime) - FILE_TIMESTAMP_S (now) |
| 1454 |
+ ((FILE_TIMESTAMP_NS (mtime) - FILE_TIMESTAMP_NS (now)) |
| 1455 |
/ 1e9)); |
| 1456 |
char from_now_string[100]; |
| 1457 |
|
| 1458 |
if (from_now >= 99 && from_now <= ULONG_MAX) |
| 1459 |
sprintf (from_now_string, "%lu", (unsigned long) from_now); |
| 1460 |
else |
| 1461 |
sprintf (from_now_string, "%.2g", from_now); |
| 1462 |
OSS (error, NILF, |
| 1463 |
_("Warning: File '%s' has modification time %s s in the future"), |
| 1464 |
file->name, from_now_string); |
| 1465 |
clock_skew_detected = 1; |
| 1466 |
} |
| 1467 |
} |
| 1468 |
} |
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
if (file->double_colon) |
| 1474 |
file = file->double_colon; |
| 1475 |
|
| 1476 |
propagate_timestamp = file->updated; |
| 1477 |
do |
| 1478 |
{ |
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
if (mtime != NONEXISTENT_MTIME && file->command_state == cs_not_started |
| 1485 |
&& !file->tried_implicit && file->intermediate) |
| 1486 |
file->intermediate = 0; |
| 1487 |
|
| 1488 |
if (file->updated == propagate_timestamp) |
| 1489 |
file->last_mtime = mtime; |
| 1490 |
file = file->prev; |
| 1491 |
} |
| 1492 |
while (file != 0); |
| 1493 |
|
| 1494 |
return mtime; |
| 1495 |
} |
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
static FILE_TIMESTAMP |
| 1507 |
name_mtime (const char *name) |
| 1508 |
{ |
| 1509 |
FILE_TIMESTAMP mtime; |
| 1510 |
struct stat st; |
| 1511 |
int e; |
| 1512 |
|
| 1513 |
#if defined(WINDOWS32) |
| 1514 |
{ |
| 1515 |
char tem[MAXPATHLEN], *tstart, *tend; |
| 1516 |
const char *p = name + strlen (name); |
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
if (p > name) |
| 1523 |
{ |
| 1524 |
memcpy (tem, name, p - name + 1); |
| 1525 |
tstart = tem; |
| 1526 |
if (tstart[1] == ':') |
| 1527 |
tstart += 2; |
| 1528 |
tend = tem + (p - name - 1); |
| 1529 |
if (*tend == '.' && tend > tstart) |
| 1530 |
tend--; |
| 1531 |
if (*tend == '.' && tend > tstart) |
| 1532 |
tend--; |
| 1533 |
for ( ; tend > tstart && (*tend == '/' || *tend == '\\'); tend--) |
| 1534 |
*tend = '\0'; |
| 1535 |
} |
| 1536 |
else |
| 1537 |
{ |
| 1538 |
tem[0] = '\0'; |
| 1539 |
tend = &tem[0]; |
| 1540 |
} |
| 1541 |
|
| 1542 |
e = stat (tem, &st); |
| 1543 |
if (e == 0 && !_S_ISDIR (st.st_mode) && tend < tem + (p - name - 1)) |
| 1544 |
{ |
| 1545 |
errno = ENOTDIR; |
| 1546 |
e = -1; |
| 1547 |
} |
| 1548 |
} |
| 1549 |
#else |
| 1550 |
EINTRLOOP (e, stat (name, &st)); |
| 1551 |
#endif |
| 1552 |
if (e == 0) |
| 1553 |
mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st); |
| 1554 |
else if (errno == ENOENT || errno == ENOTDIR) |
| 1555 |
mtime = NONEXISTENT_MTIME; |
| 1556 |
else |
| 1557 |
{ |
| 1558 |
perror_with_name ("stat: ", name); |
| 1559 |
return NONEXISTENT_MTIME; |
| 1560 |
} |
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
#ifdef MAKE_SYMLINKS |
| 1566 |
#ifndef S_ISLNK |
| 1567 |
# define S_ISLNK(_m) (((_m)&S_IFMT)==S_IFLNK) |
| 1568 |
#endif |
| 1569 |
if (check_symlink_flag && strlen (name) <= GET_PATH_MAX) |
| 1570 |
{ |
| 1571 |
PATH_VAR (lpath); |
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
strcpy (lpath, name); |
| 1580 |
while (1) |
| 1581 |
{ |
| 1582 |
FILE_TIMESTAMP ltime; |
| 1583 |
PATH_VAR (lbuf); |
| 1584 |
long llen; |
| 1585 |
char *p; |
| 1586 |
|
| 1587 |
EINTRLOOP (e, lstat (lpath, &st)); |
| 1588 |
if (e) |
| 1589 |
{ |
| 1590 |
|
| 1591 |
if (errno != ENOENT && errno != ENOTDIR) |
| 1592 |
perror_with_name ("lstat: ", lpath); |
| 1593 |
break; |
| 1594 |
} |
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
if (!S_ISLNK (st.st_mode)) |
| 1599 |
break; |
| 1600 |
|
| 1601 |
|
| 1602 |
ltime = FILE_TIMESTAMP_STAT_MODTIME (lpath, st); |
| 1603 |
if (ltime > mtime) |
| 1604 |
mtime = ltime; |
| 1605 |
|
| 1606 |
|
| 1607 |
EINTRLOOP (llen, readlink (lpath, lbuf, GET_PATH_MAX)); |
| 1608 |
if (llen < 0) |
| 1609 |
{ |
| 1610 |
|
| 1611 |
perror_with_name ("readlink: ", lpath); |
| 1612 |
break; |
| 1613 |
} |
| 1614 |
lbuf[llen] = '\0'; |
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
if (lbuf[0] == '/' || (p = strrchr (lpath, '/')) == NULL) |
| 1620 |
strcpy (lpath, lbuf); |
| 1621 |
else if ((p - lpath) + llen + 2 > GET_PATH_MAX) |
| 1622 |
|
| 1623 |
break; |
| 1624 |
else |
| 1625 |
|
| 1626 |
strcpy (p+1, lbuf); |
| 1627 |
} |
| 1628 |
} |
| 1629 |
#endif |
| 1630 |
|
| 1631 |
return mtime; |
| 1632 |
} |
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
static const char * |
| 1640 |
library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr) |
| 1641 |
{ |
| 1642 |
static const char *dirs[] = |
| 1643 |
{ |
| 1644 |
"/lib", |
| 1645 |
"/usr/lib", |
| 1646 |
#if defined(WINDOWS32) && !defined(LIBDIR) |
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
#define LIBDIR "." |
| 1652 |
#endif |
| 1653 |
LIBDIR, |
| 1654 |
0 |
| 1655 |
}; |
| 1656 |
|
| 1657 |
const char *file = 0; |
| 1658 |
char *libpatterns; |
| 1659 |
FILE_TIMESTAMP mtime; |
| 1660 |
|
| 1661 |
|
| 1662 |
char *p; |
| 1663 |
const char *p2; |
| 1664 |
size_t len; |
| 1665 |
size_t liblen; |
| 1666 |
|
| 1667 |
|
| 1668 |
unsigned int best_vpath = 0, best_path = 0; |
| 1669 |
|
| 1670 |
const char **dp; |
| 1671 |
|
| 1672 |
libpatterns = xstrdup (variable_expand ("$(.LIBPATTERNS)")); |
| 1673 |
|
| 1674 |
|
| 1675 |
lib += 2; |
| 1676 |
liblen = strlen (lib); |
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
p2 = libpatterns; |
| 1682 |
while ((p = find_next_token (&p2, &len)) != 0) |
| 1683 |
{ |
| 1684 |
static char *buf = NULL; |
| 1685 |
static size_t buflen = 0; |
| 1686 |
static size_t libdir_maxlen = 0; |
| 1687 |
static unsigned int std_dirs = 0; |
| 1688 |
char *libbuf = variable_expand (""); |
| 1689 |
|
| 1690 |
|
| 1691 |
{ |
| 1692 |
char c = p[len]; |
| 1693 |
char *p3, *p4; |
| 1694 |
|
| 1695 |
p[len] = '\0'; |
| 1696 |
p3 = find_percent (p); |
| 1697 |
if (!p3) |
| 1698 |
{ |
| 1699 |
|
| 1700 |
OS (error, NILF, |
| 1701 |
_(".LIBPATTERNS element '%s' is not a pattern"), p); |
| 1702 |
p[len] = c; |
| 1703 |
continue; |
| 1704 |
} |
| 1705 |
p4 = variable_buffer_output (libbuf, p, p3-p); |
| 1706 |
p4 = variable_buffer_output (p4, lib, liblen); |
| 1707 |
p4 = variable_buffer_output (p4, p3+1, len - (p3-p)); |
| 1708 |
p[len] = c; |
| 1709 |
} |
| 1710 |
|
| 1711 |
|
| 1712 |
mtime = name_mtime (libbuf); |
| 1713 |
if (mtime != NONEXISTENT_MTIME) |
| 1714 |
{ |
| 1715 |
if (mtime_ptr != 0) |
| 1716 |
*mtime_ptr = mtime; |
| 1717 |
file = strcache_add (libbuf); |
| 1718 |
|
| 1719 |
break; |
| 1720 |
} |
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
{ |
| 1725 |
unsigned int vpath_index, path_index; |
| 1726 |
const char* f = vpath_search (libbuf, mtime_ptr ? &mtime : NULL, |
| 1727 |
&vpath_index, &path_index); |
| 1728 |
if (f) |
| 1729 |
{ |
| 1730 |
|
| 1731 |
if (file == 0 || |
| 1732 |
vpath_index < best_vpath || |
| 1733 |
(vpath_index == best_vpath && path_index < best_path)) |
| 1734 |
{ |
| 1735 |
file = f; |
| 1736 |
best_vpath = vpath_index; |
| 1737 |
best_path = path_index; |
| 1738 |
|
| 1739 |
if (mtime_ptr != 0) |
| 1740 |
*mtime_ptr = mtime; |
| 1741 |
} |
| 1742 |
} |
| 1743 |
} |
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
if (!buflen) |
| 1748 |
{ |
| 1749 |
for (dp = dirs; *dp != 0; ++dp) |
| 1750 |
{ |
| 1751 |
size_t l = strlen (*dp); |
| 1752 |
if (l > libdir_maxlen) |
| 1753 |
libdir_maxlen = l; |
| 1754 |
std_dirs++; |
| 1755 |
} |
| 1756 |
buflen = strlen (libbuf); |
| 1757 |
buf = xmalloc (libdir_maxlen + buflen + 2); |
| 1758 |
} |
| 1759 |
else if (buflen < strlen (libbuf)) |
| 1760 |
{ |
| 1761 |
buflen = strlen (libbuf); |
| 1762 |
buf = xrealloc (buf, libdir_maxlen + buflen + 2); |
| 1763 |
} |
| 1764 |
|
| 1765 |
{ |
| 1766 |
|
| 1767 |
|
| 1768 |
unsigned int vpath_index = ~((unsigned int)0) - std_dirs; |
| 1769 |
|
| 1770 |
for (dp = dirs; *dp != 0; ++dp) |
| 1771 |
{ |
| 1772 |
sprintf (buf, "%s/%s", *dp, libbuf); |
| 1773 |
mtime = name_mtime (buf); |
| 1774 |
if (mtime != NONEXISTENT_MTIME) |
| 1775 |
{ |
| 1776 |
if (file == 0 || vpath_index < best_vpath) |
| 1777 |
{ |
| 1778 |
file = strcache_add (buf); |
| 1779 |
best_vpath = vpath_index; |
| 1780 |
|
| 1781 |
if (mtime_ptr != 0) |
| 1782 |
*mtime_ptr = mtime; |
| 1783 |
} |
| 1784 |
} |
| 1785 |
|
| 1786 |
vpath_index++; |
| 1787 |
} |
| 1788 |
} |
| 1789 |
|
| 1790 |
} |
| 1791 |
|
| 1792 |
free (libpatterns); |
| 1793 |
return file; |
| 1794 |
} |