-
Notifications
You must be signed in to change notification settings - Fork 6
/
make.c
1781 lines (1481 loc) · 51.9 KB
/
make.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
/*
--
-- SYNOPSIS
-- Perform the update of all outdated targets.
--
-- DESCRIPTION
-- This is where we traverse the make graph looking for targets that
-- are out of date, and we try to infer how to make them if we can.
-- The usual make macros are understood, as well as some new ones:
--
-- $$ - expands to $
-- $@ - full target name
-- $* - target name with no suffix, same as $(@:db)
-- or, the value of % in % meta rule recipes
-- $? - list of out of date prerequisites
-- $< - all prerequisites associated with rules line
-- $& - all prerequisites associated with target
-- $> - library name for target (if any)
-- $^ - out of date prerequisites taken from value of $<
--
-- AUTHOR
-- Dennis Vadura, [email protected]
--
-- WWW
-- http://dmake.wticorp.com/
--
-- COPYRIGHT
-- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
--
-- This program is NOT free software; you can redistribute it and/or
-- modify it under the terms of the Software License Agreement Provided
-- in the file <distribution-root>/readme/license.txt.
--
-- LOG
-- Use cvs log to obtain detailed change logs.
*/
#include "extern.h"
#include "sysintf.h"
typedef struct cell {
char *datum;
struct cell *next;
size_t len;
} LISTCELL, *LISTCELLPTR;
typedef struct {
LISTCELLPTR first;
LISTCELLPTR last;
size_t len;
} LISTSTRING, *LISTSTRINGPTR;
static void _drop_mac ANSI((HASHPTR));
static void _set_recipe ANSI((char*, int));
static void _set_tmd ANSI(());
static void _append_file ANSI((STRINGPTR, FILE*, char*, int));
static LINKPTR _dup_prq ANSI((LINKPTR));
static LINKPTR _expand_dynamic_prq ANSI(( LINKPTR, LINKPTR, char * ));
static char* _prefix ANSI((char *, char *));
static char* _pool_lookup ANSI((char *));
static int _explode_graph ANSI((CELLPTR, LINKPTR, CELLPTR));
#define RP_GPPROLOG 0
#define RP_RECIPE 1
#define RP_GPEPILOG 2
#define NUM_RECIPES 3
static STRINGPTR _recipes[NUM_RECIPES];
static LISTCELLPTR _freelist=NULL;
static LISTCELLPTR
get_cell()
{
LISTCELLPTR cell;
if (!_freelist) {
if ((cell=MALLOC(1,LISTCELL)) == NULL)
No_ram();
}
else {
cell = _freelist;
_freelist = cell->next;
}
return(cell);
}
static void
free_cell(LISTCELLPTR cell)
{
cell->next = _freelist;
_freelist = cell;
}
static void
free_list(LISTCELLPTR c)
{
if(c) {
free_list(c->next);
free_cell(c);
}
}
static void
list_init(LISTSTRINGPTR s)
{
s->first = NULL;
s->last = NULL;
s->len = 0;
}
static void
list_add(LISTSTRINGPTR s, char *str)
{
LISTCELLPTR p;
int l;
if ((l = strlen(str)) == 0)
return;
p = get_cell();
p->datum = str;
p->next = NULL;
p->len = l;
if(s->first == NULL)
s->first = p;
else
s->last->next = p;
s->last = p;
s->len += l+1;
}
static char *
gen_path_list_string(LISTSTRINGPTR s)/*
=======================================
Take a list of filepaths and create a string from it separating
the filenames by a space.
This function honors the cygwin specific .WINPATH attribute. */
{
LISTCELLPTR next, cell;
int len;
int slen, slen_rest;
char *result;
char *p, *tpath;
if( (slen_rest = slen = s->len) == 0)
return(NIL(char));
/* reserve enough space to hold the concated original filenames. */
if((p = result = MALLOC(slen, char)) == NULL) No_ram();
for (cell=s->first; cell; cell=next) {
#if !defined(__CYGWIN__)
tpath = cell->datum;
len=cell->len;
#else
/* For cygwin with .WINPATH set the lenght of the converted
* filepaths might be longer. Extra checking is needed ... */
tpath = DO_WINPATH(cell->datum);
if( tpath == cell->datum ) {
len=cell->len;
}
else {
/* ... but only if DO_WINPATH() did something. */
len = strlen(tpath);
}
if( len >= slen_rest ) {
/* We need more memory. As DOS paths are usually shorter than the
* original cygwin POSIX paths (exception mounted paths) this should
* rarely happen. */
int p_offset = p - result;
/* Get more than needed. */
slen = slen + len - slen_rest + 128;
if((result = realloc( result, slen ) ) == NULL)
No_ram();
p = result + p_offset;
}
#endif
memcpy((void *)p, (void *)tpath, len);
p += len;
*p++ = ' ';
#if defined(__CYGWIN__)
/* slen_rest is only used in the cygwin / .WINPATH case. */
slen_rest = slen - (p - result);
#endif
next = cell->next;
free_cell(cell);
}
*--p = '\0';
list_init(s);
return(result);
}
PUBLIC int
Make_targets()/*
================
Actually go and make the targets on the target list */
{
LINKPTR lp;
int done = 0;
DB_ENTER( "Make_targets" );
Read_state();
_set_recipe( ".GROUPPROLOG", RP_GPPROLOG );
_set_recipe( ".GROUPEPILOG", RP_GPEPILOG );
/* Prevent recipe inference for .ROOT */
if ( Root->ce_recipe == NIL(STRING) ) {
TALLOC( Root->ce_recipe, 1, STRING );
Root->ce_recipe->st_string = "";
}
/* Prevent recipe inference for .TARGETS */
if ( Targets->ce_recipe == NIL(STRING) ) {
TALLOC( Targets->ce_recipe, 1, STRING );
Targets->ce_recipe->st_string = "";
}
/* Make sure that user defined targets are marked as root targets */
for( lp = Targets->ce_prq; lp != NIL(LINK); lp = lp->cl_next )
lp->cl_prq->ce_attr |= A_ROOT;
while( !done ) {
int rval;
if( (rval = Make(Root, NIL(CELL))) == -1 )
DB_RETURN(1);
else
done = Root->ce_flag & F_MADE;
if( !rval && !done ) Wait_for_child( FALSE, -1 );
}
for( lp = Targets->ce_prq; lp != NIL(LINK); lp = lp->cl_next ) {
CELLPTR tgt = lp->cl_prq;
if( !(tgt->ce_attr & A_UPDATED)
&& (Verbose & V_MAKE) )
printf( "`%s' is up to date\n", tgt->CE_NAME );
}
DB_RETURN( 0 );
}
PUBLIC int
Make( cp, setdirroot )/*
========================
Make target cp. Make() is also called on prerequisites that have no rule
associated (F_TARGET is not set) to verify that they exist. */
CELLPTR cp;
CELLPTR setdirroot;
{
register LINKPTR dp, prev,next;
register CELLPTR tcp;
CELLPTR nsetdirroot;
char *name, *lib;
HASHPTR m_at, m_q, m_b, m_g, m_l, m_bb, m_up;
LISTSTRING all_list, imm_list, outall_list, inf_list;
char *all = NIL(char);
char *inf = NIL(char);
char *outall = NIL(char);
char *imm = NIL(char);
int rval = 0; /* 0==ready, 1==target still running, -1==error */
int push = 0;
int made = F_MADE;
int ignore;
time_t otime = (time_t) 1L; /* Hold time of newest prerequisite. */
int mark_made = FALSE;
#if defined(__CYGWIN__)
/* static variable to hold .WINPATH status of previously made target.
* 0, 1 are .WINPATH states, -1 indicates the first target. */
static int prev_winpath_attr = -1;
#endif
DB_ENTER( "Make" );
DB_PRINT( "mem", ("%s:-> mem %ld", cp->CE_NAME, (long) coreleft()) );
/* Initialize the various temporary storage */
m_q = m_b = m_g = m_l = m_bb = m_up = NIL(HASH);
list_init(&all_list);
list_init(&imm_list);
list_init(&outall_list);
list_init(&inf_list);
if (cp->ce_set && cp->ce_set != cp) {
if( Verbose & V_MAKE )
printf( "%s: Building .UPDATEALL representative [%s]\n", Pname,
cp->ce_set->CE_NAME );
cp = cp->ce_set;
}
/* If we are supposed to change directories for this target then do so.
* If we do change dir, then modify the setdirroot variable to reflect
* that fact for all of the prerequisites that we will be making. */
nsetdirroot = setdirroot;
ignore = (((cp->ce_attr|Glob_attr)&A_IGNORE) != 0);
/* Set the UseWinpath variable to reflect the (global/local) .WINPATH
* attribute. The variable is used by DO_WINPATH() and in some other
* places. */
#if defined(__CYGWIN__)
UseWinpath = (((cp->ce_attr|Glob_attr)&A_WINPATH) != 0);
#endif
/* m_at needs to be defined before going to a "stop_making_it" where
* a _drop_mac( m_at ) would try to free it. */
/* FIXME: m_at can most probably not be changed before the next
* Def_macro("@", ...) command. Check if both this and the next
* call are needed. */
m_at = Def_macro("@", DO_WINPATH(cp->ce_fname), M_MULTI);
if( cp->ce_attr & A_SETDIR ) {
/* Change directory only if the previous .SETDIR is a different
* directory from the current one. ie. all cells with the same .SETDIR
* attribute are assumed to come from the same directory. */
if( (setdirroot == NIL(CELL) || setdirroot->ce_dir != cp->ce_dir) &&
(push = Push_dir(cp->ce_dir,cp->CE_NAME,ignore)) != 0 )
setdirroot = cp;
}
DB_PRINT( "mem", ("%s:-A mem %ld", cp->CE_NAME, (long) coreleft()) );
/* FIXME: F_MULTI targets don't have cp->ce_recipe set but the recipes
* are known nevertheless. It is not necessary to infer them.
* If (cp->ce_flag & F_MULTI) is true the recipes of the corresponding
* subtargets can be used. */
if( cp->ce_recipe == NIL(STRING) ) {
char *dir = cp->ce_dir;
if( Verbose & V_MAKE )
printf( "%s: Infering prerequisite(s) and recipe for [%s]\n", Pname,
cp->CE_NAME );
Infer_recipe( cp, setdirroot );
/* See if the directory has changed, if it has then make sure we
* push it. */
if( dir != cp->ce_dir ) {
if( push ) Pop_dir(FALSE);
push = Push_dir( cp->ce_dir, cp->CE_NAME, ignore );
setdirroot = cp;
}
}
for(dp=CeMeToo(cp); dp; dp=dp->cl_next) {
tcp = dp->cl_prq;
if( push ) {
/* If we changed the directory because of .SETDIR write Pwd into
* tcp->ce_dir so that it holds an absolute path. */
if( !(tcp->ce_attr & A_POOL) && tcp->ce_dir ) FREE( tcp->ce_dir );
tcp->ce_dir = _pool_lookup(Pwd);
tcp->ce_attr |= A_SETDIR|A_POOL;
}
tcp->ce_setdir = nsetdirroot;
}
DB_PRINT( "mem", ("%s:-A mem %ld", cp->CE_NAME, (long) coreleft()) );
/* If we have not yet statted the target then do so. */
if( !(cp->ce_flag & F_STAT) && !(cp->ce_attr&A_PHONY) ) {
if (cp->ce_parent && (cp->ce_parent->ce_flag & F_MULTI)) {
/* Inherit the stat info from the F_MULTI parent. */
cp->ce_time = cp->ce_parent->ce_time;
cp->ce_flag |= F_STAT;
/* Propagate the A_PRECIOUS attribute from the parent. */
cp->ce_attr |= cp->ce_parent->ce_attr & A_PRECIOUS;
}
else {
for(dp=CeMeToo(cp); dp; dp=dp->cl_next) {
tcp = dp->cl_prq;
/* Check if target already exists. */
Stat_target( tcp, 1, FALSE );
if( tcp->ce_time != (time_t)0L ) {
/* File exists so don't remove it later. */
tcp->ce_attr |= A_PRECIOUS;
}
if( Verbose & V_MAKE )
printf("%s: Time stamp of [%s] is %ld\n",Pname,tcp->CE_NAME,
tcp->ce_time);
}
}
}
DB_PRINT( "make", ("(%s, %ld, 0x%08x, 0x%04x)", cp->CE_NAME,
cp->ce_time, cp->ce_attr, cp->ce_flag) );
/* Handle targets without rule and without existing file. */
if( !(cp->ce_flag & F_TARGET) && (cp->ce_time == (time_t) 0L) ) {
if( Makemkf ) {
rval = -1;
goto stop_making_it;
}
else if( cp->ce_prq != NIL(LINK)
|| (BTOBOOL(Augmake) && (cp->ce_flag&F_EXPLICIT)))
/* Assume an empty recipe for a target that we have run inference on
* but do not have a set of rules for but for which we have inferred
* a list of prerequisites. */
cp->ce_flag |= F_RULES;
else
Fatal( "`%s' not found, and can't be made", cp->CE_NAME );
}
DB_PRINT( "mem", ("%s:-A mem %ld", cp->CE_NAME, (long) coreleft()) );
/* set value of $* if we have not infered a recipe, in this case $* is
* the same as $(@:db), this allows us to be compatible with BSD make */
if( cp->ce_per == NIL(char) ) cp->ce_per = "$(@:db)";
/* Search the prerequisite list for dynamic prerequisites and if we find
* them copy the list of prerequisites for potential later re-use. */
if ( cp->ce_prqorg == NIL(LINK) ) {
for( dp = cp->ce_prq; dp != NIL(LINK); dp = dp->cl_next ) {
char * ce_name = dp->cl_prq->CE_NAME;
if ( strchr(ce_name, '$') != NULL )
break;
}
if (dp != NIL(LINK)) {
cp->ce_prqorg = _dup_prq(cp->ce_prq);
}
}
/* Define $@ macro. The only reason for defining it here (that I see ATM)
* is that $@ is already defined in conditional macros. */
/* FIXME: check if both this and the previous Def_macro("@", ...) call
* are needed. */
m_at = Def_macro("@", DO_WINPATH(cp->ce_fname), M_MULTI);
/* Define conditional macros if any, note this is done BEFORE we process
* prerequisites for the current target. Thus the making of a prerequisite
* is done using the current value of the conditional macro. */
for(dp=CeMeToo(cp); dp; dp=dp->cl_next) {
tcp=dp->cl_prq;
if (tcp->ce_cond != NIL(STRING)) {
STRINGPTR sp;
tcp->ce_pushed = NIL(HASH);
for(sp=tcp->ce_cond; sp; sp=sp->st_next) {
if(Parse_macro(sp->st_string,M_MULTI|M_PUSH)) {
HASHPTR hp;
hp = GET_MACRO(LastMacName);
hp->ht_link = tcp->ce_pushed;
tcp->ce_pushed = hp;
}
else {
Error("Invalid conditional macro expression [%s]",sp->st_string);
}
}
}
}
/* First round, will be repeated a second time below. */
for( prev=NULL,dp=cp->ce_prq; dp != NIL(LINK); prev=dp, dp=next ) {
int seq;
/* This loop executes Make() to build prerequisites if needed.
* The only macro that needs to be reset after a Make() was executed
* is $@ as it might be used when expanding potential dynamic
* prerequisites. As UseWinpath is a global variable we also
* need to restore it. */
if (m_at->ht_value == NIL(char)) {
/* This check effectively tests if Make() was run before because
* Make() frees all dynamic macro values at the end. */
#if defined(__CYGWIN__)
UseWinpath = (((cp->ce_attr|Glob_attr)&A_WINPATH) != 0);
#endif
m_at = Def_macro("@", DO_WINPATH(cp->ce_fname), M_MULTI);
}
/* Make the prerequisite, note that if the current target has the
* .LIBRARY attribute set we pass on to the prerequisite the .LIBRARYM
* attribute and pass on the name of the current target as the library
* name, and we take it away when we are done. */
next = dp->cl_next;
tcp = dp->cl_prq;
if( Verbose & V_MAKE )
printf("Checking prerequisite [%s]\n", tcp->CE_NAME);
seq = (((cp->ce_attr | Glob_attr) & A_SEQ) != 0);
/* This checks if this prerequisite is still in the making, if yes
* come back later. */
if( tcp->ce_flag & F_VISITED ) {
/* Check if this currently or fully made target has the same
* .SETDIR setting. If yes, continue if it was made or come
* back later otherwise. */
if( _explode_graph(tcp, dp, setdirroot) == 0 ) {
/* didn't blow it up so see if we need to wait for it. */
if( tcp->ce_flag & F_MADE ) {
/* Target was made. */
continue;
}
else
/* Target is still in the making ... */
goto stop_making_it;
}
else
/* Use the new prerequisite with the new .SETDIR value. */
tcp = dp->cl_prq;
}
/* If the previous target (prereq) is not yet ready return if
* seq is TRUE. */
if( seq && !made ) goto stop_making_it;
/* Expand dynamic prerequisites. The F_MARK flag is guarging against
* possible double expandion of dynamic prerequisites containing more
* than one prerequisite. */
/* A new A_DYNAMIC attribute could save a lot of strchr( ,'$') calls. */
if ( tcp && !(tcp->ce_flag & F_MARK) && strchr(tcp->CE_NAME, '$') ) {
/* Replace this dynamic prerequisite with the real prerequisite,
* and add the additional prerequisites if there are more than one.*/
name = Expand( tcp->CE_NAME );
if( strcmp(name,cp->CE_NAME) == 0 )
Fatal("Detected circular dynamic dependency; generated '%s'",name);
/* Call helper for dynamic prerequisite expansion to replace the
* prerequisite with the expanded version and add the new
* prerequisites, if the macro expanded to more than one, after
* the current list element. */
dp = _expand_dynamic_prq( cp->ce_prq, dp, name );
FREE( name );
/* _expand_dynamic_prq() probably changed dp->cl_prq. */
tcp = dp->cl_prq;
if ( tcp ) {
next = dp->cl_next;
}
}
/* Dynamic expansion results in a NULL cell only when the new
* prerequisite is already in the prerequisite list or empty. In this
* case delete the cell and continue. */
if ( tcp == NIL(CELL) ) {
FREE(dp);
if ( prev == NIL(LINK) ) {
cp->ce_prq = next;
dp = NULL; /* dp will be the new value of prev. */
}
else {
prev->cl_next = next;
dp = prev;
}
continue;
}
/* Clear F_MARK flag that could have been set by _expand_dynamic_prq(). */
tcp->ce_flag &= ~(F_MARK);
if( cp->ce_attr & A_LIBRARY ) {
tcp->ce_attr |= A_LIBRARYM;
tcp->ce_lib = cp->ce_fname;
}
/* Propagate the parent's F_REMOVE and F_INFER flags to the
* prerequisites. */
tcp->ce_flag |= cp->ce_flag & (F_REMOVE|F_INFER);
/* Propagate parents A_ROOT attribute to a child if the parent is a
* F_MULTI target. */
if( (cp->ce_flag & F_MULTI) && (cp->ce_attr & A_ROOT) )
tcp->ce_attr |= A_ROOT;
tcp->ce_parent = cp;
rval |= Make(tcp, setdirroot);
if( cp->ce_attr & A_LIBRARY )
tcp->ce_attr ^= A_LIBRARYM;
/* Return on error or if Make() is still running and A_SEQ is set.
* (All F_MULTI targets have the A_SEQ attribute.) */
if( rval == -1 || (seq && (rval==1)) )
goto stop_making_it;
/* If tcp is ready, set made = F_MADE. */
made &= tcp->ce_flag & F_MADE;
}
/* Do the loop again. We are most definitely going to make the current
* cell now. NOTE: doing this loop here also results in a reduction
* in peak memory usage by the algorithm. */
for( dp = cp->ce_prq; dp != NIL(LINK); dp = dp->cl_next ) {
int tgflg;
tcp = dp->cl_prq;
if( tcp == NIL(CELL) )
Fatal("Internal Error: Found prerequisite list cell without prerequisite!");
name = tcp->ce_fname;
/* make certain that all prerequisites are made prior to advancing. */
if( !(tcp->ce_flag & F_MADE) ) goto stop_making_it;
/* If the target is a library, then check to make certain that a member
* is newer than an object file sitting on disk. If the disk version
* is newer then set the time stamps so that the archived member is
* replaced. */
if( cp->ce_attr & A_LIBRARY )
if( tcp->ce_time <= cp->ce_time ) {
time_t mtime = Do_stat( name, tcp->ce_lib, FALSE );
if( mtime < tcp->ce_time ) tcp->ce_time = cp->ce_time+1L;
}
/* Set otime to the newest time stamp of all prereqs or 1 if there
* are no prerequisites. */
if( tcp->ce_time > otime ) otime = tcp->ce_time;
list_add(&all_list, name);
if( (tgflg = (dp->cl_flag & F_TARGET)) != 0 )
list_add(&inf_list, name);
if((cp->ce_time<tcp->ce_time) || ((tcp->ce_flag & F_TARGET) && Force)) {
list_add(&outall_list, name);
if( tgflg )
list_add(&imm_list, name);
}
}
/* If we are building a F_MULTI target inherit the time from
* its children. */
if( (cp->ce_flag & F_MULTI) )
cp->ce_time = otime;
/* All prerequisites are made, now make the current target. */
/* Restore UseWinpath and $@ if needed, see above for an explanation. */
if (m_at->ht_value == NIL(char)) {
/* This check effectively tests if Make() was run before because
* Make() frees all dynamic macro values at the end. */
#if defined(__CYGWIN__)
UseWinpath = (((cp->ce_attr|Glob_attr)&A_WINPATH) != 0);
#endif
m_at = Def_macro("@", DO_WINPATH(cp->ce_fname), M_MULTI);
}
/* Create a string with all concatenate filenames. The function
* respects .WINPATH. Note that gen_path_list_string empties its
* parameter :( */
all = gen_path_list_string(&all_list);
imm = gen_path_list_string(&imm_list);
outall = gen_path_list_string(&outall_list);
inf = gen_path_list_string(&inf_list);
DB_PRINT( "mem", ("%s:-C mem %ld", cp->CE_NAME, (long) coreleft()) );
DB_PRINT( "make", ("I make '%s' if %ld > %ld", cp->CE_NAME, otime,
cp->ce_time) );
if( Verbose & V_MAKE ) {
printf( "%s: >>>> Making ", Pname );
/* Also print the F_MULTI master target. */
if( cp->ce_flag & F_MULTI )
printf( "(::-\"master\" target) " );
if( cp->ce_count != 0 )
printf( "[%s::{%d}]\n", cp->CE_NAME, cp->ce_count );
else
printf( "[%s]\n", cp->CE_NAME );
}
/* Only PWD, TMD, MAKEDIR and the dynamic macros are affected by
* .WINPATH. $@ is handled earlier, do the rest now. */
#if defined(__CYGWIN__)
/* This is only relevant for cygwin. */
if( UseWinpath != prev_winpath_attr ) {
Def_macro( "MAKEDIR", Makedir, M_FORCE | M_EXPANDED );
/* If push is TRUE (Push_dir() was used) PWD and TMD are already
* set. */
if( !push ) {
Def_macro( "PWD", Pwd, M_FORCE | M_EXPANDED );
_set_tmd();
}
}
prev_winpath_attr = UseWinpath;
#endif
/* Set the remaining dynamic macros $*, $>, $?, $<, $& and $^. */
/* $* is either expanded as the result of a % inference or defined to
* $(@:db) and hence unexpanded otherwise. The latter doesn't start
* with / and will therefore not be touched by DO_WINPATH(). */
m_bb = Def_macro( "*", DO_WINPATH(cp->ce_per), M_MULTI );
/* This is expanded. */
m_g = Def_macro( ">", DO_WINPATH(cp->ce_lib), M_MULTI|M_EXPANDED );
/* These strings are generated with gen_path_list_string() and honor
* .WINPATH */
m_q = Def_macro( "?", outall, M_MULTI|M_EXPANDED );
m_b = Def_macro( "<", inf, M_MULTI|M_EXPANDED );
m_l = Def_macro( "&", all, M_MULTI|M_EXPANDED );
m_up = Def_macro( "^", imm, M_MULTI|M_EXPANDED );
_recipes[ RP_RECIPE ] = cp->ce_recipe;
/* We attempt to make the target if
* 1. it has a newer prerequisite
* 2. It is a target and Force is set
* 3. It's set of recipe lines has changed.
*/
if( Check_state(cp, _recipes, NUM_RECIPES )
|| (cp->ce_time < otime)
|| ((cp->ce_flag & F_TARGET) && Force)
) {
if( Measure & M_TARGET )
Do_profile_output( "s", M_TARGET, cp );
/* Only checking so stop as soon as we determine we will make
* something */
if( Check ) {
rval = -1;
goto stop_making_it;
}
if( Verbose & V_MAKE )
printf( "%s: Updating [%s], (%ld > %ld)\n", Pname,
cp->CE_NAME, otime, cp->ce_time );
/* In order to check if a targets time stamp was properly updated
* after the target was made and to keep the dependency chain valid
* for targets without recipes we store the minimum required file
* time. If the target time stamp is older than the newest
* prerequisite use that time, otherwise the current time. (This
* avoids the call to Do_time() for every target, still checks
* if the target time is new enough for the given prerequisite and
* mintime is also the newest time of the given prerequisites and
* can be used for targets without recipes.)
* We reuse the ce_time member to store this minimum time until
* the target is finished by Update_time_stamp(). This function
* checks if the file time was updated properly and warns if it was
* not. (While making a target this value does not change.) */
cp->ce_time = ( cp->ce_time < otime ? otime : Do_time() );
DB_PRINT( "make", ("Set ce_time (mintime) to: %ld", cp->ce_time) );
if( Touch ) {
if( !(cp->ce_attr & A_PHONY) && (!(Glob_attr & A_SILENT) || !Trace) ) {
name = cp->ce_fname;
lib = cp->ce_lib;
if( lib == NIL(char) )
printf("touch(%s)", name );
else if( cp->ce_attr & A_SYMBOL )
printf("touch(%s((%s)))", lib, name );
else
printf("touch(%s(%s))", lib, name );
if( !Trace )
/* .SYMBOL feature is not implement for touch */
if(cp->ce_attr & A_SYMBOL)
Fatal("Library symbol names not supported");
if( Do_touch( name, lib ) )
printf( " not touched - non-existant" );
printf( "\n" );
}
Update_time_stamp( cp );
}
else if( cp->ce_recipe != NIL(STRING) ) {
/* If a recipe is found use it. Note this misses F_MULTI targets. */
if( !(cp->ce_flag & F_SINGLE) ) /* Execute the recipes once ... */
rval = Exec_commands( cp );
/* Update_time_stamp() is called inside Exec_commands() after the
* last recipe line is finished. (In _finished_child()) */
else { /* or for every out of date dependency
* if the ruleop ! was used. */
TKSTR tk;
/* We will redefine $? to be the prerequisite that the recipes
* are currently evaluated for. */
_drop_mac( m_q );
/* Execute recipes for each out out of date prerequisites.
* WARNING! If no prerequisite is given the recipes are not
* executed at all! */
if( outall && *outall ) {
/* Wait for each prerequisite to finish, save the status
* of Wait_for_completion. */
int wait_for_completion_status = Wait_for_completion;
Wait_for_completion = TRUE;
SET_TOKEN( &tk, outall );
/* No need to update the target timestamp/removing temporary
* prerequisites (Update_time_stamp() in _finished_child())
* until all prerequisites are done. */
Doing_bang = TRUE;
name = Get_token( &tk, "", FALSE );
/* This loop might fail if outall contains filenames with
* spaces. */
do {
/* Set $? to current prerequisite. */
m_q->ht_value = name;
rval = Exec_commands( cp );
/* Thanks to Wait_for_completion = TRUE we are allowed
* to remove the temp files here. */
Unlink_temp_files(cp);
}
while( *(name = Get_token( &tk, "", FALSE )) != '\0' );
Wait_for_completion = wait_for_completion_status;
Doing_bang = FALSE;
}
Update_time_stamp( cp );
/* Erase $? again. Don't free the pointer, it was part of outall. */
m_q->ht_value = NIL(char);
}
}
else if( !(cp->ce_flag & F_RULES) && !(cp->ce_flag & F_STAT) &&
(!(cp->ce_attr & A_ROOT) || !(cp->ce_flag & F_EXPLICIT)) &&
!(cp->ce_count) )
/* F_MULTI subtargets should evaluate its parents F_RULES value
* but _make_multi always sets the F_RULES value of the master
* target. Assume F_RULES is set for subtargets. This might not
* be true if there are no prerequisites and no recipes in any
* of the subtargets. (FIXME) */
Fatal( "Don't know how to make `%s'",cp->CE_NAME );
else {
/* Empty recipe, set the flag as MADE and update the time stamp */
/* This might be a the master cell of a F_MULTI target. */
Update_time_stamp( cp );
}
}
else {
if( Verbose & V_MAKE )
printf( "%s: Up to date [%s], prq time = %ld , target time = %ld)\n", Pname,
cp->CE_NAME, otime, cp->ce_time );
mark_made = TRUE;
}
/* If mark_made == TRUE the target is up-to-date otherwise it is
* currently in the making. */
/* Update all targets in .UPDATEALL rule / only target cp. */
for(dp=CeMeToo(cp); dp; dp=dp->cl_next) {
tcp=dp->cl_prq;
/* Set the time stamp of those prerequisites without rule to the current
* time if Force is TRUE to make sure that targets depending on those
* prerequisites get remade. */
if( !(tcp->ce_flag & F_TARGET) && Force ) tcp->ce_time = Do_time();
if( mark_made ) {
tcp->ce_flag |= F_MADE;
if( tcp->ce_flag & F_MULTI ) {
LINKPTR tdp;
for( tdp = tcp->ce_prq; tdp != NIL(LINK); tdp = tdp->cl_next )
tcp->ce_attr |= tdp->cl_prq->ce_attr & A_UPDATED;
}
}
/* Note that the target is in the making. */
tcp->ce_flag |= F_VISITED;
/* Note: If the prerequisite was made using a .SETDIR= attribute
* directory then we will include the directory in the fname
* of the target. */
if( push ) {
char *dir = nsetdirroot ? nsetdirroot->ce_dir : Makedir;
/* get relative path from current SETDIR to new SETDIR. */
/* Attention, even with .WINPATH set this has to be a POSIX
* path as ce_fname neeed to be POSIX. */
char *pref = _prefix( dir, tcp->ce_dir );
char *nname = Build_path(pref, tcp->ce_fname);
FREE(pref);
if( (tcp->ce_attr & A_FFNAME) && (tcp->ce_fname != NIL(char)) )
FREE( tcp->ce_fname );
tcp->ce_fname = DmStrDup(nname);
tcp->ce_attr |= A_FFNAME;
}
}
stop_making_it:
_drop_mac( m_g );
_drop_mac( m_q );
_drop_mac( m_b );
_drop_mac( m_l );
_drop_mac( m_bb );
_drop_mac( m_up );
_drop_mac( m_at );
/* undefine conditional macros if any */
for(dp=CeMeToo(cp); dp; dp=dp->cl_next) {
tcp=dp->cl_prq;
while (tcp->ce_pushed != NIL(HASH)) {
HASHPTR cur = tcp->ce_pushed;
tcp->ce_pushed = cur->ht_link;
Pop_macro(cur);
FREE(cur->ht_name);
if(cur->ht_value)
FREE(cur->ht_value);
FREE(cur);
}
}
if( push )
Pop_dir(FALSE);
/* Undefine the strings that we used for constructing inferred
* prerequisites. */
if( inf != NIL(char) ) FREE( inf );
if( all != NIL(char) ) FREE( all );
if( imm != NIL(char) ) FREE( imm );
if( outall != NIL(char) ) FREE( outall );
free_list(all_list.first);
free_list(imm_list.first);
free_list(outall_list.first);
free_list(inf_list.first);
DB_PRINT( "mem", ("%s:-< mem %ld", cp->CE_NAME, (long) coreleft()) );
DB_RETURN(rval);
}
static char *
_prefix( pfx, pat )/*
=====================
Return the relative path from pfx to pat. Both paths have to be absolute
paths. If the paths are on different resources or drives (if applicable)
or only share a relative path going up to the root dir and down again
return pat. */
char *pfx;
char *pat;
{
char *cmp1=pfx;
char *cmp2=pat;
char *tpat=pat; /* Keep pointer to original pat. */
char *result;
char *up;
int first = 1;
int samerootdir = 1; /* Marks special treatment for the root dir. */
#ifdef HAVE_DRIVE_LETTERS
int pfxdl = 0;
int patdl = 0;
#endif
/* Micro optimization return immediately if pfx and pat are equal. */
if( strcmp(pfx, pat) == 0 )
return(DmStrDup(""));
#ifdef HAVE_DRIVE_LETTERS
/* remove the drive letters to avoid getting them into the relative
* path later. */
if( *pfx && pfx[1] == ':' && isalpha(*pfx) ) {
pfxdl = 1;
cmp1 = DmStrSpn(pfx+2, DirBrkStr);
}
if( *pat && pat[1] == ':' && isalpha(*pat) ) {
patdl = 1;
cmp2 = DmStrSpn(pat+2, DirBrkStr);
}
/* If the drive letters are different use the abs. path. */
if( pfxdl && patdl && (tolower(*pfx) != tolower(*pat)) )
return(DmStrDup(pat));
/* If only one has a drive letter also use the abs. path. */
if( pfxdl != patdl )
return(DmStrDup(pat));
else if( pfxdl )
/* If both are the same drive letter, disable the special top
* dir treatment. */
samerootdir = 0;
/* Continue without the drive letters. (Either none was present,
* or both were the same. This also solves the problem that the
* case of the drive letters sometimes depends on the shell.
* (cmd.exe vs. cygwin bash) */
pfx = cmp1;
pat = cmp2;
#endif
/* Cut off equal leading parts of pfx, pat. Both have to be abs. paths. */