/
read.c
3194 lines (2690 loc) · 89.6 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, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 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 "make.h"
#include <assert.h>
#include <glob.h>
#include "dep.h"
#include "filedef.h"
#include "job.h"
#include "commands.h"
#include "variable.h"
#include "rule.h"
#include "debug.h"
#include "hash.h"
#ifndef 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. */
struct floc floc; /* Info on the file in fp (if any). */
};
/* 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 struct floc *reading_file = 0;
/* The chain of makefiles read by read_makefile. */
static struct dep *read_makefiles = 0;
static int eval_makefile (const char *filename, int flags);
static int eval (struct ebuffer *buffer, int flags);
static long readline (struct ebuffer *ebuf);
static void do_define (char *name, unsigned int namelen,
enum variable_origin origin, struct ebuffer *ebuf);
static int conditional_line (char *line, int len, const struct floc *flocp);
static void record_files (struct nameseq *filenames, const char *pattern,
const char *pattern_percent, struct dep *deps,
unsigned int cmds_started, char *commands,
unsigned int commands_idx, int two_colon,
const struct floc *flocp);
static void record_target_var (struct nameseq *filenames, char *defn,
enum variable_origin origin, int enabled,
const struct 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 stop1, int stop2,
int blank, int ignorevars);
/* Read in all the makefiles and return the chain of their names. */
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 ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", 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_makefiles;
register struct dep *d;
if (! eval_makefile (*makefiles, 0))
perror_with_name ("", *makefiles);
/* Find the right element of read_makefiles. */
d = read_makefiles;
while (d->next != tail)
d = d->next;
/* Use the storage read_makefile allocates. */
*makefiles = dep_name (d);
++num_makefiles;
++makefiles;
}
/* If there were no -f switches, try the default names. */
if (num_makefiles == 0)
{
static char *default_makefiles[] =
#ifdef VMS
/* all lower case since readdir() (the vms version) 'lowercasifies' */
{ "makefile.vms", "gnumakefile.", "makefile.", 0 };
#else
#ifdef _AMIGA
{ "GNUmakefile", "Makefile", "SMakefile", 0 };
#else /* !Amiga && !VMS */
{ "GNUmakefile", "makefile", "Makefile", 0 };
#endif /* AMIGA */
#endif /* VMS */
register 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_makefiles' chain so they will be updated if possible. */
struct dep *tail = read_makefiles;
/* 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->file->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_makefiles = d;
else
tail->next = d;
tail = d;
}
if (tail != 0)
tail->next = 0;
}
}
return read_makefiles;
}
/* 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. */
if (conditionals->ignoring)
free (conditionals->ignoring);
if (conditionals->seen_else)
free (conditionals->seen_else);
/* Restore state. */
conditionals = saved;
}
static int
eval_makefile (const char *filename, int flags)
{
struct dep *deps;
struct ebuffer ebuf;
const struct floc *curfile;
char *expanded = 0;
int makefile_errno;
int r;
filename = strcache_add (filename);
ebuf.floc.filenm = filename;
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;
}
ebuf.fp = fopen (filename, "r");
/* Save the error code so we print the right message later. */
makefile_errno = errno;
/* 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 (include_directories[i], "/", filename);
ebuf.fp = fopen (included, "r");
if (ebuf.fp)
{
filename = strcache_add (included);
break;
}
}
}
/* Add FILENAME to the chain of read makefiles. */
deps = alloc_dep ();
deps->next = read_makefiles;
read_makefiles = 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->file->dontcare = 1;
if (expanded)
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;
}
/* 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;
r = eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));
reading_file = curfile;
fclose (ebuf.fp);
free (ebuf.bufstart);
alloca (0);
return r;
}
int
eval_buffer (char *buffer)
{
struct ebuffer ebuf;
struct conditionals *saved;
struct conditionals new;
const struct floc *curfile;
int r;
/* Evaluate the buffer */
ebuf.size = strlen (buffer);
ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer;
ebuf.fp = NULL;
ebuf.floc = *reading_file;
curfile = reading_file;
reading_file = &ebuf.floc;
saved = install_conditionals (&new);
r = eval (&ebuf, 1);
restore_conditionals (saved);
reading_file = curfile;
alloca (0);
return r;
}
/* 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 int
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;
struct dep *deps = 0;
long nlines = 0;
int two_colon = 0;
const char *pattern = 0;
const char *pattern_percent;
struct floc *fstart;
struct floc fi;
#define record_waiting_files() \
do \
{ \
if (filenames != 0) \
{ \
fi.lineno = tgts_started; \
record_files (filenames, pattern, pattern_percent, deps, \
cmds_started, commands, commands_idx, two_colon, \
&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 _without_ ending any rule that we happen to be working
with at the moment. If you see a "goto rule_complete", then the
statement we just parsed also finishes the previous rule. */
commands = xmalloc (200);
while (1)
{
unsigned int linelen;
char *line;
unsigned int wlen;
char *p;
char *p2;
/* 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;
/* If this line is empty, skip it. */
line = ebuf->buffer;
if (line[0] == '\0')
continue;
linelen = strlen (line);
/* Check for a shell command line first.
If it is not one, we can stop treating tab 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 tab character.
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;
/* Append this command line to the line being accumulated.
Strip command prefix chars that appear after newlines. */
if (commands_idx == 0)
cmds_started = ebuf->floc.lineno;
if (linelen + commands_idx > commands_len)
{
commands_len = (linelen + commands_idx) * 2;
commands = xrealloc (commands, commands_len);
}
p = &commands[commands_idx];
p2 = line + 1;
while (--linelen)
{
++commands_idx;
*(p++) = *p2;
if (p2[0] == '\n' && p2[1] == cmd_prefix)
{
++p2;
--linelen;
}
++p2;
}
*p = '\n';
++commands_idx;
continue;
}
}
/* This line is not a shell command line. Don't worry about tabs.
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;
if (collapsed)
free (collapsed);
collapsed = xmalloc (collapsed_length);
}
strcpy (collapsed, line);
/* Collapse continuation lines. */
collapse_continuations (collapsed);
remove_comments (collapsed);
/* Compare a word, both length and contents. */
#define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
p = collapsed;
while (isspace ((unsigned char)*p))
++p;
if (*p == '\0')
/* This line is completely empty--ignore it. */
continue;
/* Find the end of the first token. Note we don't need to worry about
* ":" here since we compare tokens by length (so "export" will never
* be equal to "export:").
*/
for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2)
;
wlen = p2 - p;
/* Find the start of the second token. If it looks like a target or
variable definition it can't be a preprocessor token so skip
them--this allows variables/targets named `ifdef', `export', etc. */
while (isspace ((unsigned char)*p2))
++p2;
if ((p2[0] == ':' || p2[0] == '+' || p2[0] == '=') && p2[1] == '\0')
{
/* It can't be a preprocessor token so skip it if we're ignoring */
if (ignoring)
continue;
goto skip_conditionals;
}
/* We must first check for conditional and `define' directives before
ignoring anything, since they control what we will do with
following lines. */
if (!in_ignored_define)
{
int i = conditional_line (p, wlen, fstart);
if (i != -2)
{
if (i == -1)
fatal (fstart, _("invalid syntax in conditional"));
ignoring = i;
continue;
}
}
if (word1eq ("endef"))
{
if (!in_ignored_define)
fatal (fstart, _("extraneous `endef'"));
in_ignored_define = 0;
continue;
}
if (word1eq ("define"))
{
if (ignoring)
in_ignored_define = 1;
else
{
if (*p2 == '\0')
fatal (fstart, _("empty variable name"));
/* Let the variable name be the whole rest of the line,
with trailing blanks stripped (comments have already been
removed), so it could be a complex variable/function
reference that might contain blanks. */
p = strchr (p2, '\0');
while (isblank ((unsigned char)p[-1]))
--p;
do_define (p2, p - p2, o_file, ebuf);
}
continue;
}
if (word1eq ("override"))
{
if (*p2 == '\0')
error (fstart, _("empty `override' directive"));
if (strneq (p2, "define", 6)
&& (isblank ((unsigned char)p2[6]) || p2[6] == '\0'))
{
if (ignoring)
in_ignored_define = 1;
else
{
p2 = next_token (p2 + 6);
if (*p2 == '\0')
fatal (fstart, _("empty variable name"));
/* Let the variable name be the whole rest of the line,
with trailing blanks stripped (comments have already been
removed), so it could be a complex variable/function
reference that might contain blanks. */
p = strchr (p2, '\0');
while (isblank ((unsigned char)p[-1]))
--p;
do_define (p2, p - p2, o_override, ebuf);
}
}
else if (!ignoring
&& !try_variable_definition (fstart, p2, o_override, 0))
error (fstart, _("invalid `override' directive"));
continue;
}
if (ignoring)
/* Ignore the line. We continue here so conditionals
can appear in the middle of a rule. */
continue;
if (word1eq ("export"))
{
/* 'export' by itself causes everything to be exported. */
if (*p2 == '\0')
export_all_variables = 1;
else
{
struct variable *v;
v = try_variable_definition (fstart, p2, o_file, 0);
if (v != 0)
v->export = v_export;
else
{
unsigned int l;
const char *cp;
char *ap;
/* Expand the line so we can use indirect and constructed
variable names in an export command. */
cp = ap = allocated_variable_expand (p2);
for (p = find_next_token (&cp, &l); p != 0;
p = find_next_token (&cp, &l))
{
v = lookup_variable (p, l);
if (v == 0)
v = define_variable_loc (p, l, "", o_file, 0, fstart);
v->export = v_export;
}
free (ap);
}
}
goto rule_complete;
}
if (word1eq ("unexport"))
{
if (*p2 == '\0')
export_all_variables = 0;
else
{
unsigned int l;
struct variable *v;
const char *cp;
char *ap;
/* Expand the line so we can use indirect and constructed
variable names in an unexport command. */
cp = ap = allocated_variable_expand (p2);
for (p = find_next_token (&cp, &l); p != 0;
p = find_next_token (&cp, &l))
{
v = lookup_variable (p, l);
if (v == 0)
v = define_variable_loc (p, l, "", o_file, 0, fstart);
v->export = v_noexport;
}
free (ap);
}
goto rule_complete;
}
skip_conditionals:
if (word1eq ("vpath"))
{
const char *cp;
char *vpat;
unsigned int l;
cp = variable_expand (p2);
p = find_next_token (&cp, &l);
if (p != 0)
{
vpat = savestring (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);
if (vpat != 0)
free (vpat);
goto rule_complete;
}
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');
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. */
p2 = p;
files = multi_glob (parse_file_seq (&p2, '\0',
sizeof (struct nameseq),
1),
sizeof (struct nameseq));
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 (files);
files = next;
r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE
| (noerror ? RM_DONTCARE : 0)));
if (!r && !noerror)
error (fstart, "%s: %s", name, strerror (errno));
}
/* Restore conditional state. */
restore_conditionals (save);
goto rule_complete;
}
if (try_variable_definition (fstart, p, o_file, 0))
/* This line has been dealt with. */
goto rule_complete;
/* 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)
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.
In this algorithm, `lb_next' will point to the beginning of the
unexpanded parts of the input buffer, while `p2' points to the
parts of the expanded buffer we haven't searched yet. */
{
enum make_word_type wtype;
enum variable_origin v_origin;
int exported;
char *cmdleft, *semip, *lb_next;
unsigned int plen = 0;
char *colonp;
const char *end, *beg; /* Helpers for whitespace stripping. */
/* Record the previous rule. */
record_waiting_files ();
tgts_started = fstart->lineno;
/* Search the line for an unquoted ; that is not after an
unquoted #. */
cmdleft = find_char_unquote (line, ';', '#', 0, 1);
if (cmdleft != 0 && *cmdleft == '#')
{
/* We found a comment before a semicolon. */
*cmdleft = '\0';
cmdleft = 0;
}
else if (cmdleft != 0)
/* Found one. Cut the line short there before expanding it. */
*(cmdleft++) = '\0';
semip = cmdleft;
collapse_continuations (line);
/* We can't expand the entire line, since if it's a per-target
variable we don't want to expand it. So, walk from the
beginning, expanding as we go, and looking for "interesting"
chars. The first word is always expandable. */
wtype = get_next_mword(line, NULL, &lb_next, &wlen);
switch (wtype)
{
case w_eol:
if (cmdleft != 0)
fatal(fstart, _("missing rule before recipe"));
/* This line contained something but turned out to be nothing
but whitespace (a comment?). */
continue;
case w_colon:
case w_dcolon:
/* We accept and ignore rules without targets for
compatibility with SunOS 4 make. */
no_targets = 1;
continue;
default:
break;
}
p2 = variable_expand_string(NULL, lb_next, wlen);
while (1)
{
lb_next += wlen;
if (cmdleft == 0)
{
/* Look for a semicolon in the expanded line. */
cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
if (cmdleft != 0)
{
unsigned long p2_off = p2 - variable_buffer;
unsigned long cmd_off = cmdleft - variable_buffer;
char *pend = p2 + strlen(p2);
/* Append any remnants of lb, then cut the line short
at the semicolon. */
*cmdleft = '\0';
/* One school of thought says that you shouldn't expand
here, but merely copy, since now you're beyond a ";"
and into a command script. However, the old parser
expanded the whole line, so we continue that for
backwards-compatiblity. Also, it wouldn't be
entirely consistent, since we do an unconditional
expand below once we know we don't have a
target-specific variable. */
(void)variable_expand_string(pend, lb_next, (long)-1);
lb_next += strlen(lb_next);
p2 = variable_buffer + p2_off;
cmdleft = variable_buffer + cmd_off + 1;
}
}
colonp = find_char_unquote(p2, ':', 0, 0, 0);
#ifdef HAVE_DOS_PATHS
/* The drive spec brain-damage strikes again... */
/* Note that the only separators of targets in this context
are whitespace and a left paren. If others are possible,
they should be added to the string in the call to index. */
while (colonp && (colonp[1] == '/' || colonp[1] == '\\') &&
colonp > p2 && isalpha ((unsigned char)colonp[-1]) &&
(colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0);
#endif
if (colonp != 0)
break;
wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen);
if (wtype == w_eol)
break;
p2 += strlen(p2);
*(p2++) = ' ';
p2 = variable_expand_string(p2, lb_next, wlen);
/* We don't need to worry about cmdleft here, because if it was
found in the variable_buffer the entire buffer has already
been expanded... we'll never get here. */
}
p2 = next_token (variable_buffer);
/* If the word we're looking at is EOL, see if there's _anything_
on the line. If not, a variable expanded to nothing, so ignore
it. If so, we can't parse this line so punt. */
if (wtype == w_eol)
{
if (*p2 != '\0')
/* There's no need to be ivory-tower about this: check for
one of the most common bugs found in makefiles... */
fatal (fstart, _("missing separator%s"),
(cmd_prefix == '\t' && !strneq(line, " ", 8))
? "" : _(" (did you mean TAB instead of 8 spaces?)"));