-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.c
3356 lines (2815 loc) · 99.1 KB
/
read.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
/* Reading and parsing of makefiles for GNU Make.
Copyright (C) 1988-2014 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 <assert.h>
#include <glob.h>
#include "filedef.h"
#include "dep.h"
#include "job.h"
#include "commands.h"
#include "variable.h"
#include "rule.h"
#include "debug.h"
#include "hash.h"
#ifdef WINDOWS32
#include <windows.h>
#include "sub_proc.h"
#else /* !WINDOWS32 */
#ifndef _AMIGA
#ifndef VMS
#include <pwd.h>
#else
struct passwd *getpwnam (char *name);
#endif
#endif
#endif /* !WINDOWS32 */
/* A 'struct ebuffer' controls the origin of the makefile we are currently
eval'ing.
*/
struct ebuffer
{
char *buffer; /* Start of the current line in the buffer. */
char *bufnext; /* Start of the next line in the buffer. */
char *bufstart; /* Start of the entire buffer. */
unsigned int size; /* Malloc'd size of buffer. */
FILE *fp; /* File, or NULL if this is an internal buffer. */
gmk_floc floc; /* Info on the file in fp (if any). */
};
/* Track the modifiers we can have on variable assignments */
struct vmodifiers
{
unsigned int assign_v:1;
unsigned int define_v:1;
unsigned int undefine_v:1;
unsigned int export_v:1;
unsigned int override_v:1;
unsigned int private_v:1;
};
/* Types of "words" that can be read in a makefile. */
enum make_word_type
{
w_bogus, w_eol, w_static, w_variable, w_colon, w_dcolon, w_semicolon,
w_varassign
};
/* A 'struct conditionals' contains the information describing
all the active conditionals in a makefile.
The global variable 'conditionals' contains the conditionals
information for the current makefile. It is initialized from
the static structure 'toplevel_conditionals' and is later changed
to new structures for included makefiles. */
struct conditionals
{
unsigned int if_cmds; /* Depth of conditional nesting. */
unsigned int allocated; /* Elts allocated in following arrays. */
char *ignoring; /* Are we ignoring or interpreting?
0=interpreting, 1=not yet interpreted,
2=already interpreted */
char *seen_else; /* Have we already seen an 'else'? */
};
static struct conditionals toplevel_conditionals;
static struct conditionals *conditionals = &toplevel_conditionals;
/* Default directories to search for include files in */
static const char *default_include_directories[] =
{
#if defined(WINDOWS32) && !defined(INCLUDEDIR)
/* This completely up to the user when they install MSVC or other packages.
This is defined as a placeholder. */
# define INCLUDEDIR "."
#endif
INCLUDEDIR,
#ifndef _AMIGA
"/usr/gnu/include",
"/usr/local/include",
"/usr/include",
#endif
0
};
/* List of directories to search for include files in */
static const char **include_directories;
/* Maximum length of an element of the above. */
static unsigned int max_incl_len;
/* The filename and pointer to line number of the
makefile currently being read in. */
const gmk_floc *reading_file = 0;
/* The chain of files read by read_all_makefiles. */
static struct dep *read_files = 0;
static int eval_makefile (const char *filename, int flags);
static void eval (struct ebuffer *buffer, int flags);
static long readline (struct ebuffer *ebuf);
static void do_undefine (char *name, enum variable_origin origin,
struct ebuffer *ebuf);
static struct variable *do_define (char *name, enum variable_origin origin,
struct ebuffer *ebuf);
static int conditional_line (char *line, int len, const gmk_floc *flocp);
static void record_files (struct nameseq *filenames, const char *pattern,
const char *pattern_percent, char *depstr,
unsigned int cmds_started, char *commands,
unsigned int commands_idx, int two_colon,
char prefix, const gmk_floc *flocp);
static void record_target_var (struct nameseq *filenames, char *defn,
enum variable_origin origin,
struct vmodifiers *vmod,
const gmk_floc *flocp);
static enum make_word_type get_next_mword (char *buffer, char *delim,
char **startp, unsigned int *length);
static void remove_comments (char *line);
static char *find_char_unquote (char *string, int map);
static char *unescape_char (char *string, int c);
/* Compare a word, both length and contents.
P must point to the word to be tested, and WLEN must be the length.
*/
#define word1eq(s) (wlen == CSTRLEN (s) && strneq (s, p, CSTRLEN (s)))
/* Read in all the makefiles and return a chain of targets to rebuild. */
struct dep *
read_all_makefiles (const char **makefiles)
{
unsigned int num_makefiles = 0;
/* Create *_LIST variables, to hold the makefiles, targets, and variables
we will be reading. */
define_variable_cname ("MAKEFILE_LIST", "", o_file, 0);
DB (DB_BASIC, (_("Reading makefiles...\n")));
/* If there's a non-null variable MAKEFILES, its value is a list of
files to read first thing. But don't let it prevent reading the
default makefiles and don't let the default goal come from there. */
{
char *value;
char *name, *p;
unsigned int length;
{
/* Turn off --warn-undefined-variables while we expand MAKEFILES. */
int save = warn_undefined_variables_flag;
warn_undefined_variables_flag = 0;
value = allocated_variable_expand ("$(MAKEFILES)");
warn_undefined_variables_flag = save;
}
/* Set NAME to the start of next token and LENGTH to its length.
MAKEFILES is updated for finding remaining tokens. */
p = value;
while ((name = find_next_token ((const char **)&p, &length)) != 0)
{
if (*p != '\0')
*p++ = '\0';
eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
}
free (value);
}
/* Read makefiles specified with -f switches. */
if (makefiles != 0)
while (*makefiles != 0)
{
struct dep *tail = read_files;
struct dep *d;
if (! eval_makefile (*makefiles, 0))
perror_with_name ("", *makefiles);
/* Find the first element eval_makefile() added to read_files. */
d = read_files;
while (d->next != tail)
d = d->next;
/* Reuse the storage allocated for the read_file. */
*makefiles = dep_name (d);
++num_makefiles;
++makefiles;
}
/* If there were no -f switches, try the default names. */
if (num_makefiles == 0)
{
static const char *default_makefiles[] =
#ifdef VMS
/* all lower case since readdir() (the vms version) 'lowercasifies' */
/* TODO: Above is not always true, this needs more work */
{ "makefile.vms", "gnumakefile", "makefile", 0 };
#else
#ifdef _AMIGA
{ "GNUmakefile", "Makefile", "SMakefile", 0 };
#else /* !Amiga && !VMS */
#ifdef WINDOWS32
{ "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 };
#else /* !Amiga && !VMS && !WINDOWS32 */
{ "GNUmakefile", "makefile", "Makefile", 0 };
#endif /* !Amiga && !VMS && !WINDOWS32 */
#endif /* AMIGA */
#endif /* VMS */
const char **p = default_makefiles;
while (*p != 0 && !file_exists_p (*p))
++p;
if (*p != 0)
{
if (! eval_makefile (*p, 0))
perror_with_name ("", *p);
}
else
{
/* No default makefile was found. Add the default makefiles to the
'read_files' chain so they will be updated if possible. */
struct dep *tail = read_files;
/* Add them to the tail, after any MAKEFILES variable makefiles. */
while (tail != 0 && tail->next != 0)
tail = tail->next;
for (p = default_makefiles; *p != 0; ++p)
{
struct dep *d = alloc_dep ();
d->file = enter_file (strcache_add (*p));
d->dontcare = 1;
/* Tell update_goal_chain to bail out as soon as this file is
made, and main not to die if we can't make this file. */
d->changed = RM_DONTCARE;
if (tail == 0)
read_files = d;
else
tail->next = d;
tail = d;
}
if (tail != 0)
tail->next = 0;
}
}
return read_files;
}
/* Install a new conditional and return the previous one. */
static struct conditionals *
install_conditionals (struct conditionals *new)
{
struct conditionals *save = conditionals;
memset (new, '\0', sizeof (*new));
conditionals = new;
return save;
}
/* Free the current conditionals and reinstate a saved one. */
static void
restore_conditionals (struct conditionals *saved)
{
/* Free any space allocated by conditional_line. */
free (conditionals->ignoring);
free (conditionals->seen_else);
/* Restore state. */
conditionals = saved;
}
static int
eval_makefile (const char *filename, int flags)
{
struct dep *deps;
struct ebuffer ebuf;
const gmk_floc *curfile;
char *expanded = 0;
int makefile_errno;
ebuf.floc.filenm = filename; /* Use the original file name. */
ebuf.floc.lineno = 1;
if (ISDB (DB_VERBOSE))
{
printf (_("Reading makefile '%s'"), filename);
if (flags & RM_NO_DEFAULT_GOAL)
printf (_(" (no default goal)"));
if (flags & RM_INCLUDED)
printf (_(" (search path)"));
if (flags & RM_DONTCARE)
printf (_(" (don't care)"));
if (flags & RM_NO_TILDE)
printf (_(" (no ~ expansion)"));
puts ("...");
}
/* First, get a stream to read. */
/* Expand ~ in FILENAME unless it came from 'include',
in which case it was already done. */
if (!(flags & RM_NO_TILDE) && filename[0] == '~')
{
expanded = tilde_expand (filename);
if (expanded != 0)
filename = expanded;
}
ENULLLOOP (ebuf.fp, fopen (filename, "r"));
/* Save the error code so we print the right message later. */
makefile_errno = errno;
/* Check for unrecoverable errors: out of mem or FILE slots. */
switch (makefile_errno)
{
#ifdef EMFILE
case EMFILE:
#endif
#ifdef ENFILE
case ENFILE:
#endif
case ENOMEM:
{
const char *err = strerror (makefile_errno);
OS (fatal, reading_file, "%s", err);
}
}
/* If the makefile wasn't found and it's either a makefile from
the 'MAKEFILES' variable or an included makefile,
search the included makefile search path for this makefile. */
if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
{
unsigned int i;
for (i = 0; include_directories[i] != 0; ++i)
{
const char *included = concat (3, include_directories[i],
"/", filename);
ebuf.fp = fopen (included, "r");
if (ebuf.fp)
{
filename = included;
break;
}
}
}
/* Now we have the final name for this makefile. Enter it into
the cache. */
filename = strcache_add (filename);
/* Add FILENAME to the chain of read makefiles. */
deps = alloc_dep ();
deps->next = read_files;
read_files = deps;
deps->file = lookup_file (filename);
if (deps->file == 0)
deps->file = enter_file (filename);
filename = deps->file->name;
deps->changed = flags;
if (flags & RM_DONTCARE)
deps->dontcare = 1;
free (expanded);
/* If the makefile can't be found at all, give up entirely. */
if (ebuf.fp == 0)
{
/* If we did some searching, errno has the error from the last
attempt, rather from FILENAME itself. Restore it in case the
caller wants to use it in a message. */
errno = makefile_errno;
return 0;
}
/* Set close-on-exec to avoid leaking the makefile to children, such as
$(shell ...). */
#ifdef HAVE_FILENO
CLOSE_ON_EXEC (fileno (ebuf.fp));
#endif
/* Add this makefile to the list. */
do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file,
f_append, 0);
/* Evaluate the makefile */
ebuf.size = 200;
ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size);
curfile = reading_file;
reading_file = &ebuf.floc;
eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));
reading_file = curfile;
fclose (ebuf.fp);
free (ebuf.bufstart);
alloca (0);
return 1;
}
void
eval_buffer (char *buffer, const gmk_floc *floc)
{
struct ebuffer ebuf;
struct conditionals *saved;
struct conditionals new;
const gmk_floc *curfile;
/* Evaluate the buffer */
ebuf.size = strlen (buffer);
ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer;
ebuf.fp = NULL;
if (floc)
ebuf.floc = *floc;
else if (reading_file)
ebuf.floc = *reading_file;
else
{
ebuf.floc.filenm = NULL;
ebuf.floc.lineno = 1;
}
curfile = reading_file;
reading_file = &ebuf.floc;
saved = install_conditionals (&new);
eval (&ebuf, 1);
restore_conditionals (saved);
reading_file = curfile;
alloca (0);
}
/* Check LINE to see if it's a variable assignment or undefine.
It might use one of the modifiers "export", "override", "private", or it
might be one of the conditional tokens like "ifdef", "include", etc.
If it's not a variable assignment or undefine, VMOD.V_ASSIGN is 0.
Returns LINE.
Returns a pointer to the first non-modifier character, and sets VMOD
based on the modifiers found if any, plus V_ASSIGN is 1.
*/
static char *
parse_var_assignment (const char *line, struct vmodifiers *vmod)
{
const char *p;
memset (vmod, '\0', sizeof (*vmod));
/* Find the start of the next token. If there isn't one we're done. */
line = next_token (line);
if (*line == '\0')
return (char *)line;
p = line;
while (1)
{
int wlen;
const char *p2;
struct variable v;
p2 = parse_variable_definition (p, &v);
/* If this is a variable assignment, we're done. */
if (p2)
break;
/* It's not a variable; see if it's a modifier. */
p2 = end_of_token (p);
wlen = p2 - p;
if (word1eq ("export"))
vmod->export_v = 1;
else if (word1eq ("override"))
vmod->override_v = 1;
else if (word1eq ("private"))
vmod->private_v = 1;
else if (word1eq ("define"))
{
/* We can't have modifiers after 'define' */
vmod->define_v = 1;
p = next_token (p2);
break;
}
else if (word1eq ("undefine"))
{
/* We can't have modifiers after 'undefine' */
vmod->undefine_v = 1;
p = next_token (p2);
break;
}
else
/* Not a variable or modifier: this is not a variable assignment. */
return (char *)line;
/* It was a modifier. Try the next word. */
p = next_token (p2);
if (*p == '\0')
return (char *)line;
}
/* Found a variable assignment or undefine. */
vmod->assign_v = 1;
return (char *)p;
}
/* Read file FILENAME as a makefile and add its contents to the data base.
SET_DEFAULT is true if we are allowed to set the default goal. */
static void
eval (struct ebuffer *ebuf, int set_default)
{
char *collapsed = 0;
unsigned int collapsed_length = 0;
unsigned int commands_len = 200;
char *commands;
unsigned int commands_idx = 0;
unsigned int cmds_started, tgts_started;
int ignoring = 0, in_ignored_define = 0;
int no_targets = 0; /* Set when reading a rule without targets. */
struct nameseq *filenames = 0;
char *depstr = 0;
long nlines = 0;
int two_colon = 0;
char prefix = cmd_prefix;
const char *pattern = 0;
const char *pattern_percent;
gmk_floc *fstart;
gmk_floc fi;
#define record_waiting_files() \
do \
{ \
if (filenames != 0) \
{ \
fi.lineno = tgts_started; \
record_files (filenames, pattern, pattern_percent, depstr, \
cmds_started, commands, commands_idx, two_colon, \
prefix, &fi); \
filenames = 0; \
} \
commands_idx = 0; \
no_targets = 0; \
pattern = 0; \
} while (0)
pattern_percent = 0;
cmds_started = tgts_started = 1;
fstart = &ebuf->floc;
fi.filenm = ebuf->floc.filenm;
/* Loop over lines in the file.
The strategy is to accumulate target names in FILENAMES, dependencies
in DEPS and commands in COMMANDS. These are used to define a rule
when the start of the next rule (or eof) is encountered.
When you see a "continue" in the loop below, that means we are moving on
to the next line. If you see record_waiting_files(), then the statement
we are parsing also finishes the previous rule. */
commands = xmalloc (200);
while (1)
{
unsigned int linelen;
char *line;
unsigned int wlen;
char *p;
char *p2;
struct vmodifiers vmod;
/* At the top of this loop, we are starting a brand new line. */
/* Grab the next line to be evaluated */
ebuf->floc.lineno += nlines;
nlines = readline (ebuf);
/* If there is nothing left to eval, we're done. */
if (nlines < 0)
break;
line = ebuf->buffer;
/* If this is the first line, check for a UTF-8 BOM and skip it. */
if (ebuf->floc.lineno == 1 && line[0] == (char)0xEF
&& line[1] == (char)0xBB && line[2] == (char)0xBF)
{
line += 3;
if (ISDB(DB_BASIC))
{
if (ebuf->floc.filenm)
printf (_("Skipping UTF-8 BOM in makefile '%s'\n"),
ebuf->floc.filenm);
else
printf (_("Skipping UTF-8 BOM in makefile buffer\n"));
}
}
/* If this line is empty, skip it. */
if (line[0] == '\0')
continue;
linelen = strlen (line);
/* Check for a shell command line first.
If it is not one, we can stop treating cmd_prefix specially. */
if (line[0] == cmd_prefix)
{
if (no_targets)
/* Ignore the commands in a rule with no targets. */
continue;
/* If there is no preceding rule line, don't treat this line
as a command, even though it begins with a recipe prefix.
SunOS 4 make appears to behave this way. */
if (filenames != 0)
{
if (ignoring)
/* Yep, this is a shell command, and we don't care. */
continue;
if (commands_idx == 0)
cmds_started = ebuf->floc.lineno;
/* Append this command line to the line being accumulated.
Skip the initial command prefix character. */
if (linelen + commands_idx > commands_len)
{
commands_len = (linelen + commands_idx) * 2;
commands = xrealloc (commands, commands_len);
}
memcpy (&commands[commands_idx], line + 1, linelen - 1);
commands_idx += linelen - 1;
commands[commands_idx++] = '\n';
continue;
}
}
/* This line is not a shell command line. Don't worry about whitespace.
Get more space if we need it; we don't need to preserve the current
contents of the buffer. */
if (collapsed_length < linelen+1)
{
collapsed_length = linelen+1;
free (collapsed);
/* Don't need xrealloc: we don't need to preserve the content. */
collapsed = xmalloc (collapsed_length);
}
strcpy (collapsed, line);
/* Collapse continuation lines. */
collapse_continuations (collapsed);
remove_comments (collapsed);
/* Get rid if starting space (including formfeed, vtab, etc.) */
p = collapsed;
while (isspace ((unsigned char)*p))
++p;
/* See if this is a variable assignment. We need to do this early, to
allow variables with names like 'ifdef', 'export', 'private', etc. */
p = parse_var_assignment (p, &vmod);
if (vmod.assign_v)
{
struct variable *v;
enum variable_origin origin = vmod.override_v ? o_override : o_file;
/* Variable assignment ends the previous rule. */
record_waiting_files ();
/* If we're ignoring then we're done now. */
if (ignoring)
{
if (vmod.define_v)
in_ignored_define = 1;
continue;
}
if (vmod.undefine_v)
{
do_undefine (p, origin, ebuf);
continue;
}
else if (vmod.define_v)
v = do_define (p, origin, ebuf);
else
v = try_variable_definition (fstart, p, origin, 0);
assert (v != NULL);
if (vmod.export_v)
v->export = v_export;
if (vmod.private_v)
v->private_var = 1;
/* This line has been dealt with. */
continue;
}
/* If this line is completely empty, ignore it. */
if (*p == '\0')
continue;
p2 = end_of_token (p);
wlen = p2 - p;
p2 = next_token (p2);
/* If we're in an ignored define, skip this line (but maybe get out). */
if (in_ignored_define)
{
/* See if this is an endef line (plus optional comment). */
if (word1eq ("endef") && STOP_SET (*p2, MAP_COMMENT|MAP_NUL))
in_ignored_define = 0;
continue;
}
/* Check for conditional state changes. */
{
int i = conditional_line (p, wlen, fstart);
if (i != -2)
{
if (i == -1)
O (fatal, fstart, _("invalid syntax in conditional"));
ignoring = i;
continue;
}
}
/* Nothing to see here... move along. */
if (ignoring)
continue;
/* Manage the "export" keyword used outside of variable assignment
as well as "unexport". */
if (word1eq ("export") || word1eq ("unexport"))
{
int exporting = *p == 'u' ? 0 : 1;
/* Export/unexport ends the previous rule. */
record_waiting_files ();
/* (un)export by itself causes everything to be (un)exported. */
if (*p2 == '\0')
export_all_variables = exporting;
else
{
unsigned int l;
const char *cp;
char *ap;
/* Expand the line so we can use indirect and constructed
variable names in an (un)export command. */
cp = ap = allocated_variable_expand (p2);
for (p = find_next_token (&cp, &l); p != 0;
p = find_next_token (&cp, &l))
{
struct variable *v = lookup_variable (p, l);
if (v == 0)
v = define_variable_global (p, l, "", o_file, 0, fstart);
v->export = exporting ? v_export : v_noexport;
}
free (ap);
}
continue;
}
/* Handle the special syntax for vpath. */
if (word1eq ("vpath"))
{
const char *cp;
char *vpat;
unsigned int l;
/* vpath ends the previous rule. */
record_waiting_files ();
cp = variable_expand (p2);
p = find_next_token (&cp, &l);
if (p != 0)
{
vpat = xstrndup (p, l);
p = find_next_token (&cp, &l);
/* No searchpath means remove all previous
selective VPATH's with the same pattern. */
}
else
/* No pattern means remove all previous selective VPATH's. */
vpat = 0;
construct_vpath_list (vpat, p);
free (vpat);
continue;
}
/* Handle include and variants. */
if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
{
/* We have found an 'include' line specifying a nested
makefile to be read at this point. */
struct conditionals *save;
struct conditionals new_conditionals;
struct nameseq *files;
/* "-include" (vs "include") says no error if the file does not
exist. "sinclude" is an alias for this from SGI. */
int noerror = (p[0] != 'i');
/* Include ends the previous rule. */
record_waiting_files ();
p = allocated_variable_expand (p2);
/* If no filenames, it's a no-op. */
if (*p == '\0')
{
free (p);
continue;
}
/* Parse the list of file names. Don't expand archive references! */
p2 = p;
files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
PARSEFS_NOAR);
free (p);
/* Save the state of conditionals and start
the included makefile with a clean slate. */
save = install_conditionals (&new_conditionals);
/* Record the rules that are waiting so they will determine
the default goal before those in the included makefile. */
record_waiting_files ();
/* Read each included makefile. */
while (files != 0)
{
struct nameseq *next = files->next;
const char *name = files->name;
int r;
free_ns (files);
files = next;
r = eval_makefile (name,
(RM_INCLUDED | RM_NO_TILDE
| (noerror ? RM_DONTCARE : 0)
| (set_default ? 0 : RM_NO_DEFAULT_GOAL)));
if (!r && !noerror)
{
const char *err = strerror (errno);
OSS (error, fstart, "%s: %s", name, err);
}
}
/* Restore conditional state. */
restore_conditionals (save);
continue;
}
/* Handle the load operations. */
if (word1eq ("load") || word1eq ("-load"))
{
/* A 'load' line specifies a dynamic object to load. */
struct nameseq *files;
int noerror = (p[0] == '-');
/* Load ends the previous rule. */
record_waiting_files ();
p = allocated_variable_expand (p2);
/* If no filenames, it's a no-op. */
if (*p == '\0')
{
free (p);
continue;
}
/* Parse the list of file names.
Don't expand archive references or strip "./" */
p2 = p;
files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
PARSEFS_NOAR);
free (p);
/* Load each file. */
while (files != 0)
{
struct nameseq *next = files->next;
const char *name = files->name;
struct dep *deps;
int r;
/* Load the file. 0 means failure. */
r = load_file (&ebuf->floc, &name, noerror);
if (! r && ! noerror)
OS (fatal, &ebuf->floc, _("%s: failed to load"), name);
free_ns (files);
files = next;
/* Return of -1 means a special load: don't rebuild it. */
if (r == -1)
continue;
/* It succeeded, so add it to the list "to be rebuilt". */
deps = alloc_dep ();
deps->next = read_files;
read_files = deps;
deps->file = lookup_file (name);
if (deps->file == 0)
deps->file = enter_file (name);
deps->file->loaded = 1;
}
continue;
}
/* This line starts with a tab but was not caught above because there
was no preceding target, and the line might have been usable as a
variable definition. But now we know it is definitely lossage. */
if (line[0] == cmd_prefix)
O (fatal, fstart, _("recipe commences before first target"));
/* This line describes some target files. This is complicated by
the existence of target-specific variables, because we can't
expand the entire line until we know if we have one or not. So
we expand the line word by word until we find the first ':',
then check to see if it's a target-specific variable.