-
Notifications
You must be signed in to change notification settings - Fork 0
/
remake.c
1676 lines (1401 loc) · 53 KB
/
remake.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Basic dependency engine for GNU Make.
Copyright (C) 1988-2013 Free Software Foundation, Inc.
This file is part of GNU Make.
GNU Make is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.
GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>. */
#include "makeint.h"
#include "filedef.h"
#include "job.h"
#include "commands.h"
#include "dep.h"
#include "variable.h"
#include "debug.h"
#include <assert.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#include <sys/file.h>
#endif
#ifdef VMS
#include <starlet.h>
#endif
#ifdef WINDOWS32
#include <io.h>
#endif
extern int try_implicit_rule (struct file *file, unsigned int depth);
/* The test for circular dependencies is based on the 'updating' bit in
'struct file'. However, double colon targets have separate 'struct
file's; make sure we always use the base of the double colon chain. */
#define start_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
->updating = 1)
#define finish_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
->updating = 0)
#define is_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
->updating)
/* Incremented when a command is started (under -n, when one would be). */
unsigned int commands_started = 0;
/* Current value for pruning the scan of the goal chain (toggle 0/1). */
static unsigned int considered;
static int update_file (struct file *file, unsigned int depth);
static int update_file_1 (struct file *file, unsigned int depth);
static int check_dep (struct file *file, unsigned int depth,
FILE_TIMESTAMP this_mtime, int *must_make_ptr);
static enum update_status touch_file (struct file *file);
static void remake_file (struct file *file);
static FILE_TIMESTAMP name_mtime (const char *name);
static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr);
/* Remake all the goals in the 'struct dep' chain GOALS. Return -1 if nothing
was done, 0 if all goals were updated successfully, or 1 if a goal failed.
If rebuilding_makefiles is nonzero, these goals are makefiles, so -t, -q,
and -n should be disabled for them unless they were also command-line
targets, and we should only make one goal at a time and return as soon as
one goal whose 'changed' member is nonzero is successfully made. */
enum update_status
update_goal_chain (struct dep *goals)
{
int t = touch_flag, q = question_flag, n = just_print_flag;
enum update_status status = us_none;
#define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \
: file_mtime (file))
/* Duplicate the chain so we can remove things from it. */
goals = copy_dep_chain (goals);
{
/* Clear the 'changed' flag of each goal in the chain.
We will use the flag below to notice when any commands
have actually been run for a target. When no commands
have been run, we give an "up to date" diagnostic. */
struct dep *g;
for (g = goals; g != 0; g = g->next)
g->changed = 0;
}
/* All files start with the considered bit 0, so the global value is 1. */
considered = 1;
/* Update all the goals until they are all finished. */
while (goals != 0)
{
register struct dep *g, *lastgoal;
/* Start jobs that are waiting for the load to go down. */
start_waiting_jobs ();
/* Wait for a child to die. */
reap_children (1, 0);
lastgoal = 0;
g = goals;
while (g != 0)
{
/* Iterate over all double-colon entries for this file. */
struct file *file;
int stop = 0, any_not_updated = 0;
for (file = g->file->double_colon ? g->file->double_colon : g->file;
file != NULL;
file = file->prev)
{
unsigned int ocommands_started;
int fail;
file->dontcare = g->dontcare;
check_renamed (file);
if (rebuilding_makefiles)
{
if (file->cmd_target)
{
touch_flag = t;
question_flag = q;
just_print_flag = n;
}
else
touch_flag = question_flag = just_print_flag = 0;
}
/* Save the old value of 'commands_started' so we can compare
later. It will be incremented when any commands are
actually run. */
ocommands_started = commands_started;
fail = update_file (file, rebuilding_makefiles ? 1 : 0);
check_renamed (file);
/* Set the goal's 'changed' flag if any commands were started
by calling update_file above. We check this flag below to
decide when to give an "up to date" diagnostic. */
if (commands_started > ocommands_started)
g->changed = 1;
/* If we updated a file and STATUS was not already 1, set it to
1 if updating failed, or to 0 if updating succeeded. Leave
STATUS as it is if no updating was done. */
stop = 0;
if ((fail || file->updated) && status < us_question)
{
if (file->update_status != us_success)
{
/* Updating failed, or -q triggered. The STATUS value
tells our caller which. */
status = file->update_status;
/* If -q just triggered, stop immediately. It doesn't
matter how much more we run, since we already know
the answer to return. */
stop = (question_flag && !keep_going_flag
&& !rebuilding_makefiles);
}
else
{
FILE_TIMESTAMP mtime = MTIME (file);
check_renamed (file);
if (file->updated && g->changed &&
mtime != file->mtime_before_update)
{
/* Updating was done. If this is a makefile and
just_print_flag or question_flag is set (meaning
-n or -q was given and this file was specified
as a command-line target), don't change STATUS.
If STATUS is changed, we will get re-exec'd, and
enter an infinite loop. */
if (!rebuilding_makefiles
|| (!just_print_flag && !question_flag))
status = us_success;
if (rebuilding_makefiles && file->dontcare)
/* This is a default makefile; stop remaking. */
stop = 1;
}
}
}
/* Keep track if any double-colon entry is not finished.
When they are all finished, the goal is finished. */
any_not_updated |= !file->updated;
file->dontcare = 0;
if (stop)
break;
}
/* Reset FILE since it is null at the end of the loop. */
file = g->file;
if (stop || !any_not_updated)
{
/* If we have found nothing whatever to do for the goal,
print a message saying nothing needs doing. */
if (!rebuilding_makefiles
/* If the update_status is success, we updated successfully
or not at all. G->changed will have been set above if
any commands were actually started for this goal. */
&& file->update_status == us_success && !g->changed
/* Never give a message under -s or -q. */
&& !silent_flag && !question_flag)
message (1, ((file->phony || file->cmds == 0)
? _("Nothing to be done for '%s'.")
: _("'%s' is up to date.")),
file->name);
/* This goal is finished. Remove it from the chain. */
if (lastgoal == 0)
goals = g->next;
else
lastgoal->next = g->next;
/* Free the storage. */
free (g);
g = lastgoal == 0 ? goals : lastgoal->next;
if (stop)
break;
}
else
{
lastgoal = g;
g = g->next;
}
}
/* If we reached the end of the dependency graph toggle the considered
flag for the next pass. */
if (g == 0)
considered = !considered;
}
if (rebuilding_makefiles)
{
touch_flag = t;
question_flag = q;
just_print_flag = n;
}
return status;
}
/* If FILE is not up to date, execute the commands for it.
Return 0 if successful, non-0 if unsuccessful;
but with some flag settings, just call 'exit' if unsuccessful.
DEPTH is the depth in recursions of this function.
We increment it during the consideration of our dependencies,
then decrement it again after finding out whether this file
is out of date.
If there are multiple double-colon entries for FILE,
each is considered in turn. */
static int
update_file (struct file *file, unsigned int depth)
{
int status = 0;
register struct file *f;
f = file->double_colon ? file->double_colon : file;
/* Prune the dependency graph: if we've already been here on _this_
pass through the dependency graph, we don't have to go any further.
We won't reap_children until we start the next pass, so no state
change is possible below here until then. */
if (f->considered == considered)
{
/* Check for the case where a target has been tried and failed but
the diagnostics haven't been issued. If we need the diagnostics
then we will have to continue. */
if (!(f->updated && f->update_status > us_none
&& !f->dontcare && f->no_diag))
{
DBF (DB_VERBOSE, _("Pruning file '%s'.\n"));
return f->command_state == cs_finished ? f->update_status : 0;
}
}
/* This loop runs until we start commands for a double colon rule, or until
the chain is exhausted. */
for (; f != 0; f = f->prev)
{
f->considered = considered;
status |= update_file_1 (f, depth);
check_renamed (f);
/* Clean up any alloca() used during the update. */
alloca (0);
/* If we got an error, don't bother with double_colon etc. */
if (status != 0 && !keep_going_flag)
return status;
if (f->command_state == cs_running
|| f->command_state == cs_deps_running)
{
/* Don't run the other :: rules for this
file until this rule is finished. */
status = 0;
break;
}
}
/* Process the remaining rules in the double colon chain so they're marked
considered. Start their prerequisites, too. */
if (file->double_colon)
for (; f != 0 ; f = f->prev)
{
struct dep *d;
f->considered = considered;
for (d = f->deps; d != 0; d = d->next)
status |= update_file (d->file, depth + 1);
}
return status;
}
/* Show a message stating the target failed to build. */
static void
complain (struct file *file)
{
/* If this file has no_diag set then it means we tried to update it
before in the dontcare mode and failed. The target that actually
failed is not necessarily this file but could be one of its direct
or indirect dependencies. So traverse this file's dependencies and
find the one that actually caused the failure. */
struct dep *d;
for (d = file->deps; d != 0; d = d->next)
{
if (d->file->updated && d->file->update_status > us_none && file->no_diag)
{
complain (d->file);
break;
}
}
if (d == 0)
{
const char *msg_noparent
= _("%sNo rule to make target '%s'%s");
const char *msg_parent
= _("%sNo rule to make target '%s', needed by '%s'%s");
/* Didn't find any dependencies to complain about. */
if (!keep_going_flag)
{
if (file->parent == 0)
fatal (NILF, msg_noparent, "", file->name, "");
fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
}
if (file->parent == 0)
error (NILF, msg_noparent, "*** ", file->name, ".");
else
error (NILF, msg_parent, "*** ", file->name, file->parent->name, ".");
file->no_diag = 0;
}
}
/* Consider a single 'struct file' and update it as appropriate.
Return 0 on success, or non-0 on failure. */
static int
update_file_1 (struct file *file, unsigned int depth)
{
FILE_TIMESTAMP this_mtime;
int noexist, must_make, deps_changed;
int dep_status = 0;
struct file *ofile;
struct dep *d, *ad;
struct dep amake;
int running = 0;
DBF (DB_VERBOSE, _("Considering target file '%s'.\n"));
if (file->updated)
{
if (file->update_status > us_none)
{
DBF (DB_VERBOSE,
_("Recently tried and failed to update file '%s'.\n"));
/* If the file we tried to make is marked no_diag then no message
was printed about it when it failed during the makefile rebuild.
If we're trying to build it again in the normal rebuild, print a
message now. */
if (file->no_diag && !file->dontcare)
complain (file);
return file->update_status;
}
DBF (DB_VERBOSE, _("File '%s' was considered already.\n"));
return 0;
}
switch (file->command_state)
{
case cs_not_started:
case cs_deps_running:
break;
case cs_running:
DBF (DB_VERBOSE, _("Still updating file '%s'.\n"));
return 0;
case cs_finished:
DBF (DB_VERBOSE, _("Finished updating file '%s'.\n"));
return file->update_status;
default:
abort ();
}
/* Determine whether the diagnostics will be issued should this update
fail. */
file->no_diag = file->dontcare;
++depth;
/* Notice recursive update of the same file. */
start_updating (file);
/* We might change file if we find a different one via vpath;
remember this one to turn off updating. */
ofile = file;
/* Looking at the file's modtime beforehand allows the possibility
that its name may be changed by a VPATH search, and thus it may
not need an implicit rule. If this were not done, the file
might get implicit commands that apply to its initial name, only
to have that name replaced with another found by VPATH search. */
this_mtime = file_mtime (file);
check_renamed (file);
noexist = this_mtime == NONEXISTENT_MTIME;
if (noexist)
DBF (DB_BASIC, _("File '%s' does not exist.\n"));
else if (ORDINARY_MTIME_MIN <= this_mtime && this_mtime <= ORDINARY_MTIME_MAX
&& file->low_resolution_time)
{
/* Avoid spurious rebuilds due to low resolution time stamps. */
int ns = FILE_TIMESTAMP_NS (this_mtime);
if (ns != 0)
error (NILF, _("*** Warning: .LOW_RESOLUTION_TIME file '%s' has a high resolution time stamp"),
file->name);
this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns;
}
must_make = noexist;
/* If file was specified as a target with no commands,
come up with some default commands. */
if (!file->phony && file->cmds == 0 && !file->tried_implicit)
{
if (try_implicit_rule (file, depth))
DBF (DB_IMPLICIT, _("Found an implicit rule for '%s'.\n"));
else
DBF (DB_IMPLICIT, _("No implicit rule found for '%s'.\n"));
file->tried_implicit = 1;
}
if (file->cmds == 0 && !file->is_target
&& default_file != 0 && default_file->cmds != 0)
{
DBF (DB_IMPLICIT, _("Using default recipe for '%s'.\n"));
file->cmds = default_file->cmds;
}
/* Update all non-intermediate files we depend on, if necessary, and see
whether any of them is more recent than this file. We need to walk our
deps, AND the deps of any also_make targets to ensure everything happens
in the correct order. */
amake.file = file;
amake.next = file->also_make;
ad = &amake;
while (ad)
{
struct dep *lastd = 0;
/* Find the deps we're scanning */
d = ad->file->deps;
ad = ad->next;
while (d)
{
FILE_TIMESTAMP mtime;
int maybe_make;
int dontcare = 0;
check_renamed (d->file);
mtime = file_mtime (d->file);
check_renamed (d->file);
if (is_updating (d->file))
{
error (NILF, _("Circular %s <- %s dependency dropped."),
file->name, d->file->name);
/* We cannot free D here because our the caller will still have
a reference to it when we were called recursively via
check_dep below. */
if (lastd == 0)
file->deps = d->next;
else
lastd->next = d->next;
d = d->next;
continue;
}
d->file->parent = file;
maybe_make = must_make;
/* Inherit dontcare flag from our parent. */
if (rebuilding_makefiles)
{
dontcare = d->file->dontcare;
d->file->dontcare = file->dontcare;
}
dep_status |= check_dep (d->file, depth, this_mtime, &maybe_make);
/* Restore original dontcare flag. */
if (rebuilding_makefiles)
d->file->dontcare = dontcare;
if (! d->ignore_mtime)
must_make = maybe_make;
check_renamed (d->file);
{
register struct file *f = d->file;
if (f->double_colon)
f = f->double_colon;
do
{
running |= (f->command_state == cs_running
|| f->command_state == cs_deps_running);
f = f->prev;
}
while (f != 0);
}
if (dep_status && !keep_going_flag)
break;
if (!running)
/* The prereq is considered changed if the timestamp has changed while
it was built, OR it doesn't exist. */
d->changed = ((file_mtime (d->file) != mtime)
|| (mtime == NONEXISTENT_MTIME));
lastd = d;
d = d->next;
}
}
/* Now we know whether this target needs updating.
If it does, update all the intermediate files we depend on. */
if (must_make || always_make_flag)
{
for (d = file->deps; d != 0; d = d->next)
if (d->file->intermediate)
{
int dontcare = 0;
FILE_TIMESTAMP mtime = file_mtime (d->file);
check_renamed (d->file);
d->file->parent = file;
/* Inherit dontcare flag from our parent. */
if (rebuilding_makefiles)
{
dontcare = d->file->dontcare;
d->file->dontcare = file->dontcare;
}
/* We may have already considered this file, when we didn't know
we'd need to update it. Force update_file() to consider it and
not prune it. */
d->file->considered = !considered;
dep_status |= update_file (d->file, depth);
/* Restore original dontcare flag. */
if (rebuilding_makefiles)
d->file->dontcare = dontcare;
check_renamed (d->file);
{
register struct file *f = d->file;
if (f->double_colon)
f = f->double_colon;
do
{
running |= (f->command_state == cs_running
|| f->command_state == cs_deps_running);
f = f->prev;
}
while (f != 0);
}
if (dep_status && !keep_going_flag)
break;
if (!running)
d->changed = ((file->phony && file->cmds != 0)
|| file_mtime (d->file) != mtime);
}
}
finish_updating (file);
finish_updating (ofile);
DBF (DB_VERBOSE, _("Finished prerequisites of target file '%s'.\n"));
if (running)
{
set_command_state (file, cs_deps_running);
--depth;
DBF (DB_VERBOSE, _("The prerequisites of '%s' are being made.\n"));
return 0;
}
/* If any dependency failed, give up now. */
if (dep_status != 0)
{
file->update_status = us_failed;
notice_finished_file (file);
--depth;
DBF (DB_VERBOSE, _("Giving up on target file '%s'.\n"));
if (depth == 0 && keep_going_flag
&& !just_print_flag && !question_flag)
error (NILF,
_("Target '%s' not remade because of errors."), file->name);
return dep_status;
}
if (file->command_state == cs_deps_running)
/* The commands for some deps were running on the last iteration, but
they have finished now. Reset the command_state to not_started to
simplify later bookkeeping. It is important that we do this only
when the prior state was cs_deps_running, because that prior state
was definitely propagated to FILE's also_make's by set_command_state
(called above), but in another state an also_make may have
independently changed to finished state, and we would confuse that
file's bookkeeping (updated, but not_started is bogus state). */
set_command_state (file, cs_not_started);
/* Now record which prerequisites are more
recent than this file, so we can define $?. */
deps_changed = 0;
for (d = file->deps; d != 0; d = d->next)
{
FILE_TIMESTAMP d_mtime = file_mtime (d->file);
check_renamed (d->file);
if (! d->ignore_mtime)
{
#if 1
/* %%% In version 4, remove this code completely to
implement not remaking deps if their deps are newer
than their parents. */
if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate)
/* We must remake if this dep does not
exist and is not intermediate. */
must_make = 1;
#endif
/* Set DEPS_CHANGED if this dep actually changed. */
deps_changed |= d->changed;
}
/* Set D->changed if either this dep actually changed,
or its dependent, FILE, is older or does not exist. */
d->changed |= noexist || d_mtime > this_mtime;
if (!noexist && ISDB (DB_BASIC|DB_VERBOSE))
{
const char *fmt = 0;
if (d->ignore_mtime)
{
if (ISDB (DB_VERBOSE))
fmt = _("Prerequisite '%s' is order-only for target '%s'.\n");
}
else if (d_mtime == NONEXISTENT_MTIME)
{
if (ISDB (DB_BASIC))
fmt = _("Prerequisite '%s' of target '%s' does not exist.\n");
}
else if (d->changed)
{
if (ISDB (DB_BASIC))
fmt = _("Prerequisite '%s' is newer than target '%s'.\n");
}
else if (ISDB (DB_VERBOSE))
fmt = _("Prerequisite '%s' is older than target '%s'.\n");
if (fmt)
{
print_spaces (depth);
printf (fmt, dep_name (d), file->name);
fflush (stdout);
}
}
}
/* Here depth returns to the value it had when we were called. */
depth--;
if (file->double_colon && file->deps == 0)
{
must_make = 1;
DBF (DB_BASIC,
_("Target '%s' is double-colon and has no prerequisites.\n"));
}
else if (!noexist && file->is_target && !deps_changed && file->cmds == 0
&& !always_make_flag)
{
must_make = 0;
DBF (DB_VERBOSE,
_("No recipe for '%s' and no prerequisites actually changed.\n"));
}
else if (!must_make && file->cmds != 0 && always_make_flag)
{
must_make = 1;
DBF (DB_VERBOSE, _("Making '%s' due to always-make flag.\n"));
}
if (!must_make)
{
if (ISDB (DB_VERBOSE))
{
print_spaces (depth);
printf (_("No need to remake target '%s'"), file->name);
if (!streq (file->name, file->hname))
printf (_("; using VPATH name '%s'"), file->hname);
puts (".");
fflush (stdout);
}
notice_finished_file (file);
/* Since we don't need to remake the file, convert it to use the
VPATH filename if we found one. hfile will be either the
local name if no VPATH or the VPATH name if one was found. */
while (file)
{
file->name = file->hname;
file = file->prev;
}
return 0;
}
DBF (DB_BASIC, _("Must remake target '%s'.\n"));
/* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
VPATH. */
if (!streq (file->name, file->hname))
{
DB (DB_BASIC, (_(" Ignoring VPATH name '%s'.\n"), file->hname));
file->ignore_vpath = 1;
}
/* Now, take appropriate actions to remake the file. */
remake_file (file);
if (file->command_state != cs_finished)
{
DBF (DB_VERBOSE, _("Recipe of '%s' is being run.\n"));
return 0;
}
switch (file->update_status)
{
case us_failed:
DBF (DB_BASIC, _("Failed to remake target file '%s'.\n"));
break;
case us_success:
DBF (DB_BASIC, _("Successfully remade target file '%s'.\n"));
break;
case us_question:
DBF (DB_BASIC, _("Target file '%s' needs to be remade under -q.\n"));
break;
case us_none:
break;
}
file->updated = 1;
return file->update_status;
}
/* Set FILE's 'updated' flag and re-check its mtime and the mtime's of all
files listed in its 'also_make' member. Under -t, this function also
touches FILE.
On return, FILE->update_status will no longer be us_none if it was. */
void
notice_finished_file (struct file *file)
{
struct dep *d;
int ran = file->command_state == cs_running;
int touched = 0;
file->command_state = cs_finished;
file->updated = 1;
if (touch_flag
/* The update status will be:
us_success if 0 or more commands (+ or ${MAKE}) were run and won;
us_none if this target was not remade;
>us_none if some commands were run and lost.
We touch the target if it has commands which either were not run
or won when they ran (i.e. status is 0). */
&& file->update_status == us_success)
{
if (file->cmds != 0 && file->cmds->any_recurse)
{
/* If all the command lines were recursive,
we don't want to do the touching. */
unsigned int i;
for (i = 0; i < file->cmds->ncommand_lines; ++i)
if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
goto have_nonrecursing;
}
else
{
have_nonrecursing:
if (file->phony)
file->update_status = us_success;
/* According to POSIX, -t doesn't affect targets with no cmds. */
else if (file->cmds != 0)
{
/* Should set file's modification date and do nothing else. */
file->update_status = touch_file (file);
/* Pretend we ran a real touch command, to suppress the
"'foo' is up to date" message. */
commands_started++;
/* Request for the timestamp to be updated (and distributed
to the double-colon entries). Simply setting ran=1 would
almost have done the trick, but messes up with the also_make
updating logic below. */
touched = 1;
}
}
}
if (file->mtime_before_update == UNKNOWN_MTIME)
file->mtime_before_update = file->last_mtime;
if ((ran && !file->phony) || touched)
{
int i = 0;
/* If -n, -t, or -q and all the commands are recursive, we ran them so
really check the target's mtime again. Otherwise, assume the target
would have been updated. */
if ((question_flag || just_print_flag || touch_flag) && file->cmds)
{
for (i = file->cmds->ncommand_lines; i > 0; --i)
if (! (file->cmds->lines_flags[i-1] & COMMANDS_RECURSE))
break;
}
/* If there were no commands at all, it's always new. */
else if (file->is_target && file->cmds == 0)
i = 1;
file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME;
}
if (file->double_colon)
{
/* If this is a double colon rule and it is the last one to be
updated, propagate the change of modification time to all the
double-colon entries for this file.
We do it on the last update because it is important to handle
individual entries as separate rules with separate timestamps
while they are treated as targets and then as one rule with the
unified timestamp when they are considered as a prerequisite
of some target. */
struct file *f;
FILE_TIMESTAMP max_mtime = file->last_mtime;
/* Check that all rules were updated and at the same time find
the max timestamp. We assume UNKNOWN_MTIME is newer then
any other value. */
for (f = file->double_colon; f != 0 && f->updated; f = f->prev)
if (max_mtime != UNKNOWN_MTIME
&& (f->last_mtime == UNKNOWN_MTIME || f->last_mtime > max_mtime))
max_mtime = f->last_mtime;
if (f == 0)
for (f = file->double_colon; f != 0; f = f->prev)
f->last_mtime = max_mtime;
}
if (ran && file->update_status != us_none)
/* We actually tried to update FILE, which has
updated its also_make's as well (if it worked).
If it didn't work, it wouldn't work again for them.
So mark them as updated with the same status. */
for (d = file->also_make; d != 0; d = d->next)
{
d->file->command_state = cs_finished;
d->file->updated = 1;
d->file->update_status = file->update_status;
if (ran && !d->file->phony)
/* Fetch the new modification time.
We do this instead of just invalidating the cached time
so that a vpath_search can happen. Otherwise, it would
never be done because the target is already updated. */
f_mtime (d->file, 0);
}
else if (file->update_status == us_none)
/* Nothing was done for FILE, but it needed nothing done.
So mark it now as "succeeded". */
file->update_status = us_success;
}
/* Check whether another file (whose mtime is THIS_MTIME) needs updating on
account of a dependency which is file FILE. If it does, store 1 in
*MUST_MAKE_PTR. In the process, update any non-intermediate files that
FILE depends on (including FILE itself). Return nonzero if any updating
failed. */
static int
check_dep (struct file *file, unsigned int depth,
FILE_TIMESTAMP this_mtime, int *must_make_ptr)
{
struct file *ofile;
struct dep *d;
int dep_status = 0;
++depth;
start_updating (file);
/* We might change file if we find a different one via vpath;
remember this one to turn off updating. */
ofile = file;
if (file->phony || !file->intermediate)
{