1 /* Reading and parsing of makefiles for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
4 2012 Free Software Foundation, Inc.
5 This file is part of GNU Make.
7 GNU Make is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 3 of the License, or (at your option) any later
12 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with
17 this program. If not, see <http://www.gnu.org/licenses/>. */
40 struct passwd
*getpwnam (char *name
);
43 #endif /* !WINDOWS32 */
45 /* A 'struct ebuffer' controls the origin of the makefile we are currently
51 char *buffer
; /* Start of the current line in the buffer. */
52 char *bufnext
; /* Start of the next line in the buffer. */
53 char *bufstart
; /* Start of the entire buffer. */
54 unsigned int size
; /* Malloc'd size of buffer. */
55 FILE *fp
; /* File, or NULL if this is an internal buffer. */
56 struct floc floc
; /* Info on the file in fp (if any). */
59 /* Track the modifiers we can have on variable assignments */
63 unsigned int assign_v
:1;
64 unsigned int define_v
:1;
65 unsigned int undefine_v
:1;
66 unsigned int export_v
:1;
67 unsigned int override_v
:1;
68 unsigned int private_v
:1;
71 /* Types of "words" that can be read in a makefile. */
74 w_bogus
, w_eol
, w_static
, w_variable
, w_colon
, w_dcolon
, w_semicolon
,
79 /* A `struct conditionals' contains the information describing
80 all the active conditionals in a makefile.
82 The global variable `conditionals' contains the conditionals
83 information for the current makefile. It is initialized from
84 the static structure `toplevel_conditionals' and is later changed
85 to new structures for included makefiles. */
89 unsigned int if_cmds
; /* Depth of conditional nesting. */
90 unsigned int allocated
; /* Elts allocated in following arrays. */
91 char *ignoring
; /* Are we ignoring or interpreting?
92 0=interpreting, 1=not yet interpreted,
93 2=already interpreted */
94 char *seen_else
; /* Have we already seen an `else'? */
97 static struct conditionals toplevel_conditionals
;
98 static struct conditionals
*conditionals
= &toplevel_conditionals
;
101 /* Default directories to search for include files in */
103 static const char *default_include_directories
[] =
105 #if defined(WINDOWS32) && !defined(INCLUDEDIR)
106 /* This completely up to the user when they install MSVC or other packages.
107 This is defined as a placeholder. */
108 # define INCLUDEDIR "."
113 "/usr/local/include",
119 /* List of directories to search for include files in */
121 static const char **include_directories
;
123 /* Maximum length of an element of the above. */
125 static unsigned int max_incl_len
;
127 /* The filename and pointer to line number of the
128 makefile currently being read in. */
130 const struct floc
*reading_file
= 0;
132 /* The chain of makefiles read by read_makefile. */
134 static struct dep
*read_makefiles
= 0;
136 static int eval_makefile (const char *filename
, int flags
);
137 static void eval (struct ebuffer
*buffer
, int flags
);
139 static long readline (struct ebuffer
*ebuf
);
140 static void do_undefine (char *name
, enum variable_origin origin
,
141 struct ebuffer
*ebuf
);
142 static struct variable
*do_define (char *name
, enum variable_origin origin
,
143 struct ebuffer
*ebuf
);
144 static int conditional_line (char *line
, int len
, const struct floc
*flocp
);
145 static void record_files (struct nameseq
*filenames
, const char *pattern
,
146 const char *pattern_percent
, char *depstr
,
147 unsigned int cmds_started
, char *commands
,
148 unsigned int commands_idx
, int two_colon
,
149 char prefix
, const struct floc
*flocp
);
150 static void record_target_var (struct nameseq
*filenames
, char *defn
,
151 enum variable_origin origin
,
152 struct vmodifiers
*vmod
,
153 const struct floc
*flocp
);
154 static enum make_word_type
get_next_mword (char *buffer
, char *delim
,
155 char **startp
, unsigned int *length
);
156 static void remove_comments (char *line
);
157 static char *find_char_unquote (char *string
, int stop1
, int stop2
,
158 int blank
, int ignorevars
);
161 /* Compare a word, both length and contents.
162 P must point to the word to be tested, and WLEN must be the length.
164 #define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
167 /* Read in all the makefiles and return the chain of their names. */
170 read_all_makefiles (const char **makefiles
)
172 unsigned int num_makefiles
= 0;
174 /* Create *_LIST variables, to hold the makefiles, targets, and variables
175 we will be reading. */
177 define_variable_cname ("MAKEFILE_LIST", "", o_file
, 0);
179 DB (DB_BASIC
, (_("Reading makefiles...\n")));
181 /* If there's a non-null variable MAKEFILES, its value is a list of
182 files to read first thing. But don't let it prevent reading the
183 default makefiles and don't let the default goal come from there. */
191 /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
192 int save
= warn_undefined_variables_flag
;
193 warn_undefined_variables_flag
= 0;
195 value
= allocated_variable_expand ("$(MAKEFILES)");
197 warn_undefined_variables_flag
= save
;
200 /* Set NAME to the start of next token and LENGTH to its length.
201 MAKEFILES is updated for finding remaining tokens. */
204 while ((name
= find_next_token ((const char **)&p
, &length
)) != 0)
208 eval_makefile (name
, RM_NO_DEFAULT_GOAL
|RM_INCLUDED
|RM_DONTCARE
);
214 /* Read makefiles specified with -f switches. */
217 while (*makefiles
!= 0)
219 struct dep
*tail
= read_makefiles
;
220 register struct dep
*d
;
222 if (! eval_makefile (*makefiles
, 0))
223 perror_with_name ("", *makefiles
);
225 /* Find the right element of read_makefiles. */
227 while (d
->next
!= tail
)
230 /* Use the storage read_makefile allocates. */
231 *makefiles
= dep_name (d
);
236 /* If there were no -f switches, try the default names. */
238 if (num_makefiles
== 0)
240 static char *default_makefiles
[] =
242 /* all lower case since readdir() (the vms version) 'lowercasifies' */
243 { "makefile.vms", "gnumakefile.", "makefile.", 0 };
246 { "GNUmakefile", "Makefile", "SMakefile", 0 };
247 #else /* !Amiga && !VMS */
248 { "GNUmakefile", "makefile", "Makefile", 0 };
251 register char **p
= default_makefiles
;
252 while (*p
!= 0 && !file_exists_p (*p
))
257 if (! eval_makefile (*p
, 0))
258 perror_with_name ("", *p
);
262 /* No default makefile was found. Add the default makefiles to the
263 `read_makefiles' chain so they will be updated if possible. */
264 struct dep
*tail
= read_makefiles
;
265 /* Add them to the tail, after any MAKEFILES variable makefiles. */
266 while (tail
!= 0 && tail
->next
!= 0)
268 for (p
= default_makefiles
; *p
!= 0; ++p
)
270 struct dep
*d
= alloc_dep ();
271 d
->file
= enter_file (strcache_add (*p
));
273 /* Tell update_goal_chain to bail out as soon as this file is
274 made, and main not to die if we can't make this file. */
275 d
->changed
= RM_DONTCARE
;
287 return read_makefiles
;
290 /* Install a new conditional and return the previous one. */
292 static struct conditionals
*
293 install_conditionals (struct conditionals
*new)
295 struct conditionals
*save
= conditionals
;
297 memset (new, '\0', sizeof (*new));
303 /* Free the current conditionals and reinstate a saved one. */
306 restore_conditionals (struct conditionals
*saved
)
308 /* Free any space allocated by conditional_line. */
309 if (conditionals
->ignoring
)
310 free (conditionals
->ignoring
);
311 if (conditionals
->seen_else
)
312 free (conditionals
->seen_else
);
315 conditionals
= saved
;
319 eval_makefile (const char *filename
, int flags
)
323 const struct floc
*curfile
;
327 ebuf
.floc
.filenm
= filename
; /* Use the original file name. */
328 ebuf
.floc
.lineno
= 1;
330 if (ISDB (DB_VERBOSE
))
332 printf (_("Reading makefile `%s'"), filename
);
333 if (flags
& RM_NO_DEFAULT_GOAL
)
334 printf (_(" (no default goal)"));
335 if (flags
& RM_INCLUDED
)
336 printf (_(" (search path)"));
337 if (flags
& RM_DONTCARE
)
338 printf (_(" (don't care)"));
339 if (flags
& RM_NO_TILDE
)
340 printf (_(" (no ~ expansion)"));
344 /* First, get a stream to read. */
346 /* Expand ~ in FILENAME unless it came from `include',
347 in which case it was already done. */
348 if (!(flags
& RM_NO_TILDE
) && filename
[0] == '~')
350 expanded
= tilde_expand (filename
);
355 ebuf
.fp
= fopen (filename
, "r");
356 /* Save the error code so we print the right message later. */
357 makefile_errno
= errno
;
359 /* If the makefile wasn't found and it's either a makefile from
360 the `MAKEFILES' variable or an included makefile,
361 search the included makefile search path for this makefile. */
362 if (ebuf
.fp
== 0 && (flags
& RM_INCLUDED
) && *filename
!= '/')
365 for (i
= 0; include_directories
[i
] != 0; ++i
)
367 const char *included
= concat (3, include_directories
[i
],
369 ebuf
.fp
= fopen (included
, "r");
378 /* Now we have the final name for this makefile. Enter it into
380 filename
= strcache_add (filename
);
382 /* Add FILENAME to the chain of read makefiles. */
384 deps
->next
= read_makefiles
;
385 read_makefiles
= deps
;
386 deps
->file
= lookup_file (filename
);
388 deps
->file
= enter_file (filename
);
389 filename
= deps
->file
->name
;
390 deps
->changed
= flags
;
391 if (flags
& RM_DONTCARE
)
397 /* If the makefile can't be found at all, give up entirely. */
401 /* If we did some searching, errno has the error from the last
402 attempt, rather from FILENAME itself. Restore it in case the
403 caller wants to use it in a message. */
404 errno
= makefile_errno
;
408 /* Set close-on-exec to avoid leaking the makefile to children, such as
411 CLOSE_ON_EXEC (fileno (ebuf
.fp
));
414 /* Add this makefile to the list. */
415 do_variable_definition (&ebuf
.floc
, "MAKEFILE_LIST", filename
, o_file
,
418 /* Evaluate the makefile */
421 ebuf
.buffer
= ebuf
.bufnext
= ebuf
.bufstart
= xmalloc (ebuf
.size
);
423 curfile
= reading_file
;
424 reading_file
= &ebuf
.floc
;
426 eval (&ebuf
, !(flags
& RM_NO_DEFAULT_GOAL
));
428 reading_file
= curfile
;
432 free (ebuf
.bufstart
);
439 eval_buffer (char *buffer
)
442 struct conditionals
*saved
;
443 struct conditionals
new;
444 const struct floc
*curfile
;
446 /* Evaluate the buffer */
448 ebuf
.size
= strlen (buffer
);
449 ebuf
.buffer
= ebuf
.bufnext
= ebuf
.bufstart
= buffer
;
453 ebuf
.floc
= *reading_file
;
455 ebuf
.floc
.filenm
= NULL
;
457 curfile
= reading_file
;
458 reading_file
= &ebuf
.floc
;
460 saved
= install_conditionals (&new);
464 restore_conditionals (saved
);
466 reading_file
= curfile
;
471 /* Check LINE to see if it's a variable assignment or undefine.
473 It might use one of the modifiers "export", "override", "private", or it
474 might be one of the conditional tokens like "ifdef", "include", etc.
476 If it's not a variable assignment or undefine, VMOD.V_ASSIGN is 0.
479 Returns a pointer to the first non-modifier character, and sets VMOD
480 based on the modifiers found if any, plus V_ASSIGN is 1.
483 parse_var_assignment (const char *line
, struct vmodifiers
*vmod
)
486 memset (vmod
, '\0', sizeof (*vmod
));
488 /* Find the start of the next token. If there isn't one we're done. */
489 line
= next_token (line
);
498 enum variable_flavor flavor
;
500 p2
= parse_variable_definition (p
, &flavor
);
502 /* If this is a variable assignment, we're done. */
506 /* It's not a variable; see if it's a modifier. */
507 p2
= end_of_token (p
);
510 if (word1eq ("export"))
512 else if (word1eq ("override"))
513 vmod
->override_v
= 1;
514 else if (word1eq ("private"))
516 else if (word1eq ("define"))
518 /* We can't have modifiers after 'define' */
523 else if (word1eq ("undefine"))
525 /* We can't have modifiers after 'undefine' */
526 vmod
->undefine_v
= 1;
531 /* Not a variable or modifier: this is not a variable assignment. */
534 /* It was a modifier. Try the next word. */
540 /* Found a variable assignment or undefine. */
546 /* Read file FILENAME as a makefile and add its contents to the data base.
548 SET_DEFAULT is true if we are allowed to set the default goal. */
551 eval (struct ebuffer
*ebuf
, int set_default
)
554 unsigned int collapsed_length
= 0;
555 unsigned int commands_len
= 200;
557 unsigned int commands_idx
= 0;
558 unsigned int cmds_started
, tgts_started
;
559 int ignoring
= 0, in_ignored_define
= 0;
560 int no_targets
= 0; /* Set when reading a rule without targets. */
561 struct nameseq
*filenames
= 0;
565 char prefix
= cmd_prefix
;
566 const char *pattern
= 0;
567 const char *pattern_percent
;
571 #define record_waiting_files() \
574 if (filenames != 0) \
576 fi.lineno = tgts_started; \
577 record_files (filenames, pattern, pattern_percent, depstr, \
578 cmds_started, commands, commands_idx, two_colon, \
588 cmds_started
= tgts_started
= 1;
590 fstart
= &ebuf
->floc
;
591 fi
.filenm
= ebuf
->floc
.filenm
;
593 /* Loop over lines in the file.
594 The strategy is to accumulate target names in FILENAMES, dependencies
595 in DEPS and commands in COMMANDS. These are used to define a rule
596 when the start of the next rule (or eof) is encountered.
598 When you see a "continue" in the loop below, that means we are moving on
599 to the next line _without_ ending any rule that we happen to be working
600 with at the moment. If you see a "goto rule_complete", then the
601 statement we just parsed also finishes the previous rule. */
603 commands
= xmalloc (200);
607 unsigned int linelen
;
612 struct vmodifiers vmod
;
614 /* At the top of this loop, we are starting a brand new line. */
615 /* Grab the next line to be evaluated */
616 ebuf
->floc
.lineno
+= nlines
;
617 nlines
= readline (ebuf
);
619 /* If there is nothing left to eval, we're done. */
623 /* If this line is empty, skip it. */
628 linelen
= strlen (line
);
630 /* Check for a shell command line first.
631 If it is not one, we can stop treating cmd_prefix specially. */
632 if (line
[0] == cmd_prefix
)
635 /* Ignore the commands in a rule with no targets. */
638 /* If there is no preceding rule line, don't treat this line
639 as a command, even though it begins with a recipe prefix.
640 SunOS 4 make appears to behave this way. */
645 /* Yep, this is a shell command, and we don't care. */
648 if (commands_idx
== 0)
649 cmds_started
= ebuf
->floc
.lineno
;
651 /* Append this command line to the line being accumulated.
652 Skip the initial command prefix character. */
653 if (linelen
+ commands_idx
> commands_len
)
655 commands_len
= (linelen
+ commands_idx
) * 2;
656 commands
= xrealloc (commands
, commands_len
);
658 memcpy (&commands
[commands_idx
], line
+ 1, linelen
- 1);
659 commands_idx
+= linelen
- 1;
660 commands
[commands_idx
++] = '\n';
665 /* This line is not a shell command line. Don't worry about whitespace.
666 Get more space if we need it; we don't need to preserve the current
667 contents of the buffer. */
669 if (collapsed_length
< linelen
+1)
671 collapsed_length
= linelen
+1;
674 /* Don't need xrealloc: we don't need to preserve the content. */
675 collapsed
= xmalloc (collapsed_length
);
677 strcpy (collapsed
, line
);
678 /* Collapse continuation lines. */
679 collapse_continuations (collapsed
);
680 remove_comments (collapsed
);
682 /* Get rid if starting space (including formfeed, vtab, etc.) */
684 while (isspace ((unsigned char)*p
))
687 /* See if this is a variable assignment. We need to do this early, to
688 allow variables with names like 'ifdef', 'export', 'private', etc. */
689 p
= parse_var_assignment(p
, &vmod
);
693 enum variable_origin origin
= vmod
.override_v
? o_override
: o_file
;
695 /* If we're ignoring then we're done now. */
699 in_ignored_define
= 1;
705 do_undefine (p
, origin
, ebuf
);
707 /* This line has been dealt with. */
710 else if (vmod
.define_v
)
711 v
= do_define (p
, origin
, ebuf
);
713 v
= try_variable_definition (fstart
, p
, origin
, 0);
718 v
->export
= v_export
;
722 /* This line has been dealt with. */
726 /* If this line is completely empty, ignore it. */
730 p2
= end_of_token (p
);
732 p2
= next_token (p2
);
734 /* If we're in an ignored define, skip this line (but maybe get out). */
735 if (in_ignored_define
)
737 /* See if this is an endef line (plus optional comment). */
738 if (word1eq ("endef") && (*p2
== '\0' || *p2
== '#'))
739 in_ignored_define
= 0;
744 /* Check for conditional state changes. */
746 int i
= conditional_line (p
, wlen
, fstart
);
750 fatal (fstart
, _("invalid syntax in conditional"));
757 /* Nothing to see here... move along. */
761 /* Manage the "export" keyword used outside of variable assignment
762 as well as "unexport". */
763 if (word1eq ("export") || word1eq ("unexport"))
765 int exporting
= *p
== 'u' ? 0 : 1;
767 /* (un)export by itself causes everything to be (un)exported. */
769 export_all_variables
= exporting
;
776 /* Expand the line so we can use indirect and constructed
777 variable names in an (un)export command. */
778 cp
= ap
= allocated_variable_expand (p2
);
780 for (p
= find_next_token (&cp
, &l
); p
!= 0;
781 p
= find_next_token (&cp
, &l
))
783 struct variable
*v
= lookup_variable (p
, l
);
785 v
= define_variable_global (p
, l
, "", o_file
, 0, fstart
);
786 v
->export
= exporting
? v_export
: v_noexport
;
794 /* Handle the special syntax for vpath. */
795 if (word1eq ("vpath"))
800 cp
= variable_expand (p2
);
801 p
= find_next_token (&cp
, &l
);
804 vpat
= xstrndup (p
, l
);
805 p
= find_next_token (&cp
, &l
);
806 /* No searchpath means remove all previous
807 selective VPATH's with the same pattern. */
810 /* No pattern means remove all previous selective VPATH's. */
812 construct_vpath_list (vpat
, p
);
819 /* Handle include and variants. */
820 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
822 /* We have found an `include' line specifying a nested
823 makefile to be read at this point. */
824 struct conditionals
*save
;
825 struct conditionals new_conditionals
;
826 struct nameseq
*files
;
827 /* "-include" (vs "include") says no error if the file does not
828 exist. "sinclude" is an alias for this from SGI. */
829 int noerror
= (p
[0] != 'i');
831 p
= allocated_variable_expand (p2
);
833 /* If no filenames, it's a no-op. */
840 /* Parse the list of file names. Don't expand archive references! */
842 files
= PARSE_FILE_SEQ (&p2
, struct nameseq
, '\0', NULL
,
846 /* Save the state of conditionals and start
847 the included makefile with a clean slate. */
848 save
= install_conditionals (&new_conditionals
);
850 /* Record the rules that are waiting so they will determine
851 the default goal before those in the included makefile. */
852 record_waiting_files ();
854 /* Read each included makefile. */
857 struct nameseq
*next
= files
->next
;
858 const char *name
= files
->name
;
864 r
= eval_makefile (name
,
865 (RM_INCLUDED
| RM_NO_TILDE
866 | (noerror
? RM_DONTCARE
: 0)
867 | (set_default
? 0 : RM_NO_DEFAULT_GOAL
)));
869 error (fstart
, "%s: %s", name
, strerror (errno
));
872 /* Restore conditional state. */
873 restore_conditionals (save
);
878 /* This line starts with a tab but was not caught above because there
879 was no preceding target, and the line might have been usable as a
880 variable definition. But now we know it is definitely lossage. */
881 if (line
[0] == cmd_prefix
)
882 fatal(fstart
, _("recipe commences before first target"));
884 /* This line describes some target files. This is complicated by
885 the existence of target-specific variables, because we can't
886 expand the entire line until we know if we have one or not. So
887 we expand the line word by word until we find the first `:',
888 then check to see if it's a target-specific variable.
890 In this algorithm, `lb_next' will point to the beginning of the
891 unexpanded parts of the input buffer, while `p2' points to the
892 parts of the expanded buffer we haven't searched yet. */
895 enum make_word_type wtype
;
896 char *cmdleft
, *semip
, *lb_next
;
897 unsigned int plen
= 0;
899 const char *end
, *beg
; /* Helpers for whitespace stripping. */
901 /* Record the previous rule. */
903 record_waiting_files ();
904 tgts_started
= fstart
->lineno
;
906 /* Search the line for an unquoted ; that is not after an
908 cmdleft
= find_char_unquote (line
, ';', '#', 0, 1);
909 if (cmdleft
!= 0 && *cmdleft
== '#')
911 /* We found a comment before a semicolon. */
915 else if (cmdleft
!= 0)
916 /* Found one. Cut the line short there before expanding it. */
920 collapse_continuations (line
);
922 /* We can't expand the entire line, since if it's a per-target
923 variable we don't want to expand it. So, walk from the
924 beginning, expanding as we go, and looking for "interesting"
925 chars. The first word is always expandable. */
926 wtype
= get_next_mword(line
, NULL
, &lb_next
, &wlen
);
931 fatal(fstart
, _("missing rule before recipe"));
932 /* This line contained something but turned out to be nothing
933 but whitespace (a comment?). */
938 /* We accept and ignore rules without targets for
939 compatibility with SunOS 4 make. */
947 p2
= variable_expand_string(NULL
, lb_next
, wlen
);
954 /* Look for a semicolon in the expanded line. */
955 cmdleft
= find_char_unquote (p2
, ';', 0, 0, 0);
959 unsigned long p2_off
= p2
- variable_buffer
;
960 unsigned long cmd_off
= cmdleft
- variable_buffer
;
961 char *pend
= p2
+ strlen(p2
);
963 /* Append any remnants of lb, then cut the line short
967 /* One school of thought says that you shouldn't expand
968 here, but merely copy, since now you're beyond a ";"
969 and into a command script. However, the old parser
970 expanded the whole line, so we continue that for
971 backwards-compatiblity. Also, it wouldn't be
972 entirely consistent, since we do an unconditional
973 expand below once we know we don't have a
974 target-specific variable. */
975 (void)variable_expand_string(pend
, lb_next
, (long)-1);
976 lb_next
+= strlen(lb_next
);
977 p2
= variable_buffer
+ p2_off
;
978 cmdleft
= variable_buffer
+ cmd_off
+ 1;
982 colonp
= find_char_unquote(p2
, ':', 0, 0, 0);
983 #ifdef HAVE_DOS_PATHS
984 /* The drive spec brain-damage strikes again... */
985 /* Note that the only separators of targets in this context
986 are whitespace and a left paren. If others are possible,
987 they should be added to the string in the call to index. */
988 while (colonp
&& (colonp
[1] == '/' || colonp
[1] == '\\') &&
989 colonp
> p2
&& isalpha ((unsigned char)colonp
[-1]) &&
990 (colonp
== p2
+ 1 || strchr (" \t(", colonp
[-2]) != 0))
991 colonp
= find_char_unquote(colonp
+ 1, ':', 0, 0, 0);
996 wtype
= get_next_mword(lb_next
, NULL
, &lb_next
, &wlen
);
1002 p2
= variable_expand_string(p2
, lb_next
, wlen
);
1003 /* We don't need to worry about cmdleft here, because if it was
1004 found in the variable_buffer the entire buffer has already
1005 been expanded... we'll never get here. */
1008 p2
= next_token (variable_buffer
);
1010 /* If the word we're looking at is EOL, see if there's _anything_
1011 on the line. If not, a variable expanded to nothing, so ignore
1012 it. If so, we can't parse this line so punt. */
1016 /* There's no need to be ivory-tower about this: check for
1017 one of the most common bugs found in makefiles... */
1018 fatal (fstart
, _("missing separator%s"),
1019 (cmd_prefix
== '\t' && !strneq (line
, " ", 8))
1020 ? "" : _(" (did you mean TAB instead of 8 spaces?)"));
1024 /* Make the colon the end-of-string so we know where to stop
1025 looking for targets. Start there again once we're done. */
1027 filenames
= PARSE_FILE_SEQ (&p2
, struct nameseq
, '\0', NULL
, 0);
1033 /* We accept and ignore rules without targets for
1034 compatibility with SunOS 4 make. */
1038 /* This should never be possible; we handled it above. */
1039 assert (*p2
!= '\0');
1042 /* Is this a one-colon or two-colon entry? */
1043 two_colon
= *p2
== ':';
1047 /* Test to see if it's a target-specific variable. Copy the rest
1048 of the buffer over, possibly temporarily (we'll expand it later
1049 if it's not a target-specific variable). PLEN saves the length
1050 of the unparsed section of p2, for later. */
1051 if (*lb_next
!= '\0')
1053 unsigned int l
= p2
- variable_buffer
;
1055 variable_buffer_output (p2
+plen
, lb_next
, strlen (lb_next
)+1);
1056 p2
= variable_buffer
+ l
;
1059 p2
= parse_var_assignment (p2
, &vmod
);
1062 /* If there was a semicolon found, add it back, plus anything
1066 unsigned int l
= p
- variable_buffer
;
1068 collapse_continuations (semip
);
1069 variable_buffer_output (p2
+ strlen (p2
),
1070 semip
, strlen (semip
)+1);
1071 p
= variable_buffer
+ l
;
1073 record_target_var (filenames
, p2
,
1074 vmod
.override_v
? o_override
: o_file
,
1080 /* This is a normal target, _not_ a target-specific variable.
1081 Unquote any = in the dependency list. */
1082 find_char_unquote (lb_next
, '=', 0, 0, 0);
1084 /* Remember the command prefix for this target. */
1085 prefix
= cmd_prefix
;
1087 /* We have some targets, so don't ignore the following commands. */
1090 /* Expand the dependencies, etc. */
1091 if (*lb_next
!= '\0')
1093 unsigned int l
= p2
- variable_buffer
;
1094 (void) variable_expand_string (p2
+ plen
, lb_next
, (long)-1);
1095 p2
= variable_buffer
+ l
;
1097 /* Look for a semicolon in the expanded line. */
1100 cmdleft
= find_char_unquote (p2
, ';', 0, 0, 0);
1102 *(cmdleft
++) = '\0';
1106 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
1107 p
= strchr (p2
, ':');
1108 while (p
!= 0 && p
[-1] == '\\')
1112 while (*q
-- == '\\')
1113 backslash
= !backslash
;
1115 p
= strchr (p
+ 1, ':');
1120 /* Here, the situation is quite complicated. Let's have a look
1121 at a couple of targets:
1129 The rule is that it's only a target, if there are TWO :'s
1130 OR a space around the :.
1132 if (p
&& !(isspace ((unsigned char)p
[1]) || !p
[1]
1133 || isspace ((unsigned char)p
[-1])))
1136 #ifdef HAVE_DOS_PATHS
1141 /* For DOS-style paths, skip a "C:\..." or a "C:/..." */
1142 if (p
!= 0 && (p
[1] == '\\' || p
[1] == '/') &&
1143 isalpha ((unsigned char)p
[-1]) &&
1144 (p
== p2
+ 1 || strchr (" \t:(", p
[-2]) != 0)) {
1145 p
= strchr (p
+ 1, ':');
1148 } while (check_again
);
1153 struct nameseq
*target
;
1154 target
= PARSE_FILE_SEQ (&p2
, struct nameseq
, ':', NULL
,
1158 fatal (fstart
, _("missing target pattern"));
1159 else if (target
->next
!= 0)
1160 fatal (fstart
, _("multiple target patterns"));
1161 pattern_percent
= find_percent_cached (&target
->name
);
1162 pattern
= target
->name
;
1163 if (pattern_percent
== 0)
1164 fatal (fstart
, _("target pattern contains no `%%'"));
1170 /* Strip leading and trailing whitespaces. */
1172 end
= beg
+ strlen (beg
) - 1;
1173 strip_whitespace (&beg
, &end
);
1175 /* Put all the prerequisites here; they'll be parsed later. */
1176 if (beg
<= end
&& *beg
!= '\0')
1177 depstr
= xstrndup (beg
, end
- beg
+ 1);
1184 /* Semicolon means rest of line is a command. */
1185 unsigned int l
= strlen (cmdleft
);
1187 cmds_started
= fstart
->lineno
;
1189 /* Add this command line to the buffer. */
1190 if (l
+ 2 > commands_len
)
1192 commands_len
= (l
+ 2) * 2;
1193 commands
= xrealloc (commands
, commands_len
);
1195 memcpy (commands
, cmdleft
, l
);
1197 commands
[commands_idx
++] = '\n';
1200 /* Determine if this target should be made default. We used to do
1201 this in record_files() but because of the delayed target recording
1202 and because preprocessor directives are legal in target's commands
1203 it is too late. Consider this fragment for example:
1207 ifeq ($(.DEFAULT_GOAL),foo)
1211 Because the target is not recorded until after ifeq directive is
1212 evaluated the .DEFAULT_GOAL does not contain foo yet as one
1213 would expect. Because of this we have to move the logic here. */
1215 if (set_default
&& default_goal_var
->value
[0] == '\0')
1219 struct nameseq
*t
= filenames
;
1221 for (; t
!= 0; t
= t
->next
)
1226 /* We have nothing to do if this is an implicit rule. */
1227 if (strchr (name
, '%') != 0)
1230 /* See if this target's name does not start with a `.',
1231 unless it contains a slash. */
1232 if (*name
== '.' && strchr (name
, '/') == 0
1233 #ifdef HAVE_DOS_PATHS
1234 && strchr (name
, '\\') == 0
1240 /* If this file is a suffix, don't let it be
1241 the default goal file. */
1242 for (d
= suffix_file
->deps
; d
!= 0; d
= d
->next
)
1244 register struct dep
*d2
;
1245 if (*dep_name (d
) != '.' && streq (name
, dep_name (d
)))
1250 for (d2
= suffix_file
->deps
; d2
!= 0; d2
= d2
->next
)
1252 unsigned int l
= strlen (dep_name (d2
));
1253 if (!strneq (name
, dep_name (d2
), l
))
1255 if (streq (name
+ l
, dep_name (d
)))
1268 define_variable_global (".DEFAULT_GOAL", 13, t
->name
,
1278 /* We get here except in the case that we just read a rule line.
1279 Record now the last rule we read, so following spurious
1280 commands are properly diagnosed. */
1282 record_waiting_files ();
1287 if (conditionals
->if_cmds
)
1288 fatal (fstart
, _("missing `endif'"));
1290 /* At eof, record the last rule. */
1291 record_waiting_files ();
1299 /* Remove comments from LINE.
1300 This is done by copying the text at LINE onto itself. */
1303 remove_comments (char *line
)
1307 comment
= find_char_unquote (line
, '#', 0, 0, 0);
1310 /* Cut off the line at the #. */
1314 /* Execute a `undefine' directive.
1315 The undefine line has already been read, and NAME is the name of
1316 the variable to be undefined. */
1319 do_undefine (char *name
, enum variable_origin origin
, struct ebuffer
*ebuf
)
1323 /* Expand the variable name and find the beginning (NAME) and end. */
1324 var
= allocated_variable_expand (name
);
1325 name
= next_token (var
);
1327 fatal (&ebuf
->floc
, _("empty variable name"));
1328 p
= name
+ strlen (name
) - 1;
1329 while (p
> name
&& isblank ((unsigned char)*p
))
1333 undefine_variable_global (name
, p
- name
+ 1, origin
);
1337 /* Execute a `define' directive.
1338 The first line has already been read, and NAME is the name of
1339 the variable to be defined. The following lines remain to be read. */
1341 static struct variable
*
1342 do_define (char *name
, enum variable_origin origin
, struct ebuffer
*ebuf
)
1345 enum variable_flavor flavor
;
1346 struct floc defstart
;
1348 unsigned int length
= 100;
1349 char *definition
= xmalloc (length
);
1350 unsigned int idx
= 0;
1353 defstart
= ebuf
->floc
;
1355 p
= parse_variable_definition (name
, &flavor
);
1357 /* No assignment token, so assume recursive. */
1358 flavor
= f_recursive
;
1361 if (*(next_token (p
)) != '\0')
1362 error (&defstart
, _("extraneous text after `define' directive"));
1364 /* Chop the string before the assignment token to get the name. */
1365 p
[flavor
== f_recursive
? -1 : -2] = '\0';
1368 /* Expand the variable name and find the beginning (NAME) and end. */
1369 var
= allocated_variable_expand (name
);
1370 name
= next_token (var
);
1372 fatal (&defstart
, _("empty variable name"));
1373 p
= name
+ strlen (name
) - 1;
1374 while (p
> name
&& isblank ((unsigned char)*p
))
1378 /* Now read the value of the variable. */
1383 long nlines
= readline (ebuf
);
1385 /* If there is nothing left to be eval'd, there's no 'endef'!! */
1387 fatal (&defstart
, _("missing `endef', unterminated `define'"));
1389 ebuf
->floc
.lineno
+= nlines
;
1390 line
= ebuf
->buffer
;
1392 collapse_continuations (line
);
1394 /* If the line doesn't begin with a tab, test to see if it introduces
1395 another define, or ends one. Stop if we find an 'endef' */
1396 if (line
[0] != cmd_prefix
)
1398 p
= next_token (line
);
1401 /* If this is another 'define', increment the level count. */
1402 if ((len
== 6 || (len
> 6 && isblank ((unsigned char)p
[6])))
1403 && strneq (p
, "define", 6))
1406 /* If this is an 'endef', decrement the count. If it's now 0,
1407 we've found the last one. */
1408 else if ((len
== 5 || (len
> 5 && isblank ((unsigned char)p
[5])))
1409 && strneq (p
, "endef", 5))
1412 remove_comments (p
);
1413 if (*(next_token (p
)) != '\0')
1415 _("extraneous text after `endef' directive"));
1422 /* Add this line to the variable definition. */
1423 len
= strlen (line
);
1424 if (idx
+ len
+ 1 > length
)
1426 length
= (idx
+ len
) * 2;
1427 definition
= xrealloc (definition
, length
+ 1);
1430 memcpy (&definition
[idx
], line
, len
);
1432 /* Separate lines with a newline. */
1433 definition
[idx
++] = '\n';
1436 /* We've got what we need; define the variable. */
1438 definition
[0] = '\0';
1440 definition
[idx
- 1] = '\0';
1442 v
= do_variable_definition (&defstart
, name
, definition
, origin
, flavor
, 0);
1448 /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
1449 "ifneq", "else" and "endif".
1450 LINE is the input line, with the command as its first word.
1452 FILENAME and LINENO are the filename and line number in the
1453 current makefile. They are used for error messages.
1455 Value is -2 if the line is not a conditional at all,
1456 -1 if the line is an invalid conditional,
1457 0 if following text should be interpreted,
1458 1 if following text should be ignored. */
1461 conditional_line (char *line
, int len
, const struct floc
*flocp
)
1464 enum { c_ifdef
, c_ifndef
, c_ifeq
, c_ifneq
, c_else
, c_endif
} cmdtype
;
1468 /* Compare a word, both length and contents. */
1469 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
1470 #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
1472 /* Make sure this line is a conditional. */
1473 chkword ("ifdef", c_ifdef
)
1474 else chkword ("ifndef", c_ifndef
)
1475 else chkword ("ifeq", c_ifeq
)
1476 else chkword ("ifneq", c_ifneq
)
1477 else chkword ("else", c_else
)
1478 else chkword ("endif", c_endif
)
1482 /* Found one: skip past it and any whitespace after it. */
1483 line
= next_token (line
+ len
);
1485 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
1487 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
1488 if (cmdtype
== c_endif
)
1493 if (!conditionals
->if_cmds
)
1494 fatal (flocp
, _("extraneous `%s'"), cmdname
);
1496 --conditionals
->if_cmds
;
1501 /* An 'else' statement can either be simple, or it can have another
1502 conditional after it. */
1503 if (cmdtype
== c_else
)
1507 if (!conditionals
->if_cmds
)
1508 fatal (flocp
, _("extraneous `%s'"), cmdname
);
1510 o
= conditionals
->if_cmds
- 1;
1512 if (conditionals
->seen_else
[o
])
1513 fatal (flocp
, _("only one `else' per conditional"));
1515 /* Change the state of ignorance. */
1516 switch (conditionals
->ignoring
[o
])
1519 /* We've just been interpreting. Never do it again. */
1520 conditionals
->ignoring
[o
] = 2;
1523 /* We've never interpreted yet. Maybe this time! */
1524 conditionals
->ignoring
[o
] = 0;
1528 /* It's a simple 'else'. */
1531 conditionals
->seen_else
[o
] = 1;
1535 /* The 'else' has extra text. That text must be another conditional
1536 and cannot be an 'else' or 'endif'. */
1538 /* Find the length of the next word. */
1539 for (p
= line
+1; *p
!= '\0' && !isspace ((unsigned char)*p
); ++p
)
1543 /* If it's 'else' or 'endif' or an illegal conditional, fail. */
1544 if (word1eq("else") || word1eq("endif")
1545 || conditional_line (line
, len
, flocp
) < 0)
1549 /* conditional_line() created a new level of conditional.
1550 Raise it back to this level. */
1551 if (conditionals
->ignoring
[o
] < 2)
1552 conditionals
->ignoring
[o
] = conditionals
->ignoring
[o
+1];
1553 --conditionals
->if_cmds
;
1559 if (conditionals
->allocated
== 0)
1561 conditionals
->allocated
= 5;
1562 conditionals
->ignoring
= xmalloc (conditionals
->allocated
);
1563 conditionals
->seen_else
= xmalloc (conditionals
->allocated
);
1566 o
= conditionals
->if_cmds
++;
1567 if (conditionals
->if_cmds
> conditionals
->allocated
)
1569 conditionals
->allocated
+= 5;
1570 conditionals
->ignoring
= xrealloc (conditionals
->ignoring
,
1571 conditionals
->allocated
);
1572 conditionals
->seen_else
= xrealloc (conditionals
->seen_else
,
1573 conditionals
->allocated
);
1576 /* Record that we have seen an `if...' but no `else' so far. */
1577 conditionals
->seen_else
[o
] = 0;
1579 /* Search through the stack to see if we're already ignoring. */
1580 for (i
= 0; i
< o
; ++i
)
1581 if (conditionals
->ignoring
[i
])
1583 /* We are already ignoring, so just push a level to match the next
1584 "else" or "endif", and keep ignoring. We don't want to expand
1585 variables in the condition. */
1586 conditionals
->ignoring
[o
] = 1;
1590 if (cmdtype
== c_ifdef
|| cmdtype
== c_ifndef
)
1596 /* Expand the thing we're looking up, so we can use indirect and
1597 constructed variable names. */
1598 var
= allocated_variable_expand (line
);
1600 /* Make sure there's only one variable name to test. */
1601 p
= end_of_token (var
);
1608 v
= lookup_variable (var
, i
);
1610 conditionals
->ignoring
[o
] =
1611 ((v
!= 0 && *v
->value
!= '\0') == (cmdtype
== c_ifndef
));
1617 /* "ifeq" or "ifneq". */
1620 char termin
= *line
== '(' ? ',' : *line
;
1622 if (termin
!= ',' && termin
!= '"' && termin
!= '\'')
1626 /* Find the end of the first string. */
1630 for (; *line
!= '\0'; ++line
)
1633 else if (*line
== ')')
1635 else if (*line
== ',' && count
<= 0)
1639 while (*line
!= '\0' && *line
!= termin
)
1647 /* Strip blanks after the first string. */
1649 while (isblank ((unsigned char)p
[-1]))
1656 s2
= variable_expand (s1
);
1657 /* We must allocate a new copy of the expanded string because
1658 variable_expand re-uses the same buffer. */
1660 s1
= alloca (l
+ 1);
1661 memcpy (s1
, s2
, l
+ 1);
1664 /* Find the start of the second string. */
1665 line
= next_token (line
);
1667 termin
= termin
== ',' ? ')' : *line
;
1668 if (termin
!= ')' && termin
!= '"' && termin
!= '\'')
1671 /* Find the end of the second string. */
1675 s2
= next_token (line
);
1676 for (line
= s2
; *line
!= '\0'; ++line
)
1680 else if (*line
== ')')
1693 while (*line
!= '\0' && *line
!= termin
)
1701 line
= next_token (++line
);
1705 s2
= variable_expand (s2
);
1706 conditionals
->ignoring
[o
] = (streq (s1
, s2
) == (cmdtype
== c_ifneq
));
1710 /* Search through the stack to see if we're ignoring. */
1711 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
1712 if (conditionals
->ignoring
[i
])
1718 /* Record target-specific variable values for files FILENAMES.
1719 TWO_COLON is nonzero if a double colon was used.
1721 The links of FILENAMES are freed, and so are any names in it
1722 that are not incorporated into other data structures.
1724 If the target is a pattern, add the variable to the pattern-specific
1725 variable value list. */
1728 record_target_var (struct nameseq
*filenames
, char *defn
,
1729 enum variable_origin origin
, struct vmodifiers
*vmod
,
1730 const struct floc
*flocp
)
1732 struct nameseq
*nextf
;
1733 struct variable_set_list
*global
;
1735 global
= current_variable_set_list
;
1737 /* If the variable is an append version, store that but treat it as a
1738 normal recursive variable. */
1740 for (; filenames
!= 0; filenames
= nextf
)
1743 const char *name
= filenames
->name
;
1745 const char *percent
;
1746 struct pattern_var
*p
;
1748 nextf
= filenames
->next
;
1749 free_ns (filenames
);
1751 /* If it's a pattern target, then add it to the pattern-specific
1753 percent
= find_percent_cached (&name
);
1756 /* Get a reference for this pattern-specific variable struct. */
1757 p
= create_pattern_var (name
, percent
);
1758 p
->variable
.fileinfo
= *flocp
;
1759 /* I don't think this can fail since we already determined it was a
1760 variable definition. */
1761 v
= assign_variable_definition (&p
->variable
, defn
);
1765 if (v
->flavor
== f_simple
)
1766 v
->value
= allocated_variable_expand (v
->value
);
1768 v
->value
= xstrdup (v
->value
);
1776 /* Get a file reference for this file, and initialize it.
1777 We don't want to just call enter_file() because that allocates a
1778 new entry if the file is a double-colon, which we don't want in
1780 f
= lookup_file (name
);
1782 f
= enter_file (strcache_add (name
));
1783 else if (f
->double_colon
)
1784 f
= f
->double_colon
;
1786 initialize_file_variables (f
, 1);
1789 current_variable_set_list
= f
->variables
;
1790 v
= try_variable_definition (flocp
, defn
, origin
, 1);
1792 fatal (flocp
, _("Malformed target-specific variable definition"));
1793 current_variable_set_list
= global
;
1796 /* Set up the variable to be *-specific. */
1798 v
->private_var
= vmod
->private_v
;
1799 v
->export
= vmod
->export_v
? v_export
: v_default
;
1801 /* If it's not an override, check to see if there was a command-line
1802 setting. If so, reset the value. */
1803 if (v
->origin
!= o_override
)
1805 struct variable
*gv
;
1806 int len
= strlen(v
->name
);
1808 gv
= lookup_variable (v
->name
, len
);
1810 && (gv
->origin
== o_env_override
|| gv
->origin
== o_command
))
1814 v
->value
= xstrdup (gv
->value
);
1815 v
->origin
= gv
->origin
;
1816 v
->recursive
= gv
->recursive
;
1823 /* Record a description line for files FILENAMES,
1824 with dependencies DEPS, commands to execute described
1825 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
1826 TWO_COLON is nonzero if a double colon was used.
1827 If not nil, PATTERN is the `%' pattern to make this
1828 a static pattern rule, and PATTERN_PERCENT is a pointer
1829 to the `%' within it.
1831 The links of FILENAMES are freed, and so are any names in it
1832 that are not incorporated into other data structures. */
1835 record_files (struct nameseq
*filenames
, const char *pattern
,
1836 const char *pattern_percent
, char *depstr
,
1837 unsigned int cmds_started
, char *commands
,
1838 unsigned int commands_idx
, int two_colon
,
1839 char prefix
, const struct floc
*flocp
)
1841 struct commands
*cmds
;
1843 const char *implicit_percent
;
1846 /* If we've already snapped deps, that means we're in an eval being
1847 resolved after the makefiles have been read in. We can't add more rules
1848 at this time, since they won't get snapped and we'll get core dumps.
1849 See Savannah bug # 12124. */
1851 fatal (flocp
, _("prerequisites cannot be defined in recipes"));
1853 /* Determine if this is a pattern rule or not. */
1854 name
= filenames
->name
;
1855 implicit_percent
= find_percent_cached (&name
);
1857 /* If there's a recipe, set up a struct for it. */
1858 if (commands_idx
> 0)
1860 cmds
= xmalloc (sizeof (struct commands
));
1861 cmds
->fileinfo
.filenm
= flocp
->filenm
;
1862 cmds
->fileinfo
.lineno
= cmds_started
;
1863 cmds
->commands
= xstrndup (commands
, commands_idx
);
1864 cmds
->command_lines
= 0;
1865 cmds
->recipe_prefix
= prefix
;
1870 /* If there's a prereq string then parse it--unless it's eligible for 2nd
1871 expansion: if so, snap_deps() will do it. */
1874 else if (second_expansion
&& strchr (depstr
, '$'))
1876 deps
= alloc_dep ();
1877 deps
->name
= depstr
;
1878 deps
->need_2nd_expansion
= 1;
1879 deps
->staticpattern
= pattern
!= 0;
1883 deps
= split_prereqs (depstr
);
1886 /* We'll enter static pattern prereqs later when we have the stem. We
1887 don't want to enter pattern rules at all so that we don't think that
1888 they ought to exist (make manual "Implicit Rule Search Algorithm",
1890 if (! pattern
&& ! implicit_percent
)
1891 deps
= enter_prereqs (deps
, NULL
);
1894 /* For implicit rules, _all_ the targets must have a pattern. That means we
1895 can test the first one to see if we're working with an implicit rule; if
1896 so we handle it specially. */
1898 if (implicit_percent
)
1900 struct nameseq
*nextf
;
1901 const char **targets
, **target_pats
;
1905 fatal (flocp
, _("mixed implicit and static pattern rules"));
1907 /* Count the targets to create an array of target names.
1908 We already have the first one. */
1909 nextf
= filenames
->next
;
1910 free_ns (filenames
);
1913 for (c
= 1; nextf
; ++c
, nextf
= nextf
->next
)
1915 targets
= xmalloc (c
* sizeof (const char *));
1916 target_pats
= xmalloc (c
* sizeof (const char *));
1919 target_pats
[0] = implicit_percent
;
1924 name
= filenames
->name
;
1925 implicit_percent
= find_percent_cached (&name
);
1927 if (implicit_percent
== 0)
1928 fatal (flocp
, _("mixed implicit and normal rules"));
1931 target_pats
[c
] = implicit_percent
;
1934 nextf
= filenames
->next
;
1935 free_ns (filenames
);
1939 create_pattern_rule (targets
, target_pats
, c
, two_colon
, deps
, cmds
, 1);
1945 /* Walk through each target and create it in the database.
1946 We already set up the first target, above. */
1949 struct nameseq
*nextf
= filenames
->next
;
1951 struct dep
*this = 0;
1953 free_ns (filenames
);
1955 /* Check for special targets. Do it here instead of, say, snap_deps()
1956 so that we can immediately use the value. */
1957 if (streq (name
, ".POSIX"))
1960 define_variable_cname (".SHELLFLAGS", "-ec", o_default
, 0);
1962 else if (streq (name
, ".SECONDEXPANSION"))
1963 second_expansion
= 1;
1964 #if !defined(WINDOWS32) && !defined (__MSDOS__) && !defined (__EMX__)
1965 else if (streq (name
, ".ONESHELL"))
1969 /* If this is a static pattern rule:
1970 `targets: target%pattern: prereq%pattern; recipe',
1971 make sure the pattern matches this target name. */
1972 if (pattern
&& !pattern_matches (pattern
, pattern_percent
, name
))
1973 error (flocp
, _("target `%s' doesn't match the target pattern"), name
);
1975 /* If there are multiple targets, copy the chain DEPS for all but the
1976 last one. It is not safe for the same deps to go in more than one
1977 place in the database. */
1978 this = nextf
!= 0 ? copy_dep_chain (deps
) : deps
;
1980 /* Find or create an entry in the file database for this target. */
1983 /* Single-colon. Combine this rule with the file's existing record,
1985 f
= enter_file (strcache_add (name
));
1986 if (f
->double_colon
)
1988 _("target file `%s' has both : and :: entries"), f
->name
);
1990 /* If CMDS == F->CMDS, this target was listed in this rule
1991 more than once. Just give a warning since this is harmless. */
1992 if (cmds
!= 0 && cmds
== f
->cmds
)
1994 _("target `%s' given more than once in the same rule."),
1997 /* Check for two single-colon entries both with commands.
1998 Check is_target so that we don't lose on files such as .c.o
1999 whose commands were preinitialized. */
2000 else if (cmds
!= 0 && f
->cmds
!= 0 && f
->is_target
)
2002 error (&cmds
->fileinfo
,
2003 _("warning: overriding recipe for target `%s'"),
2005 error (&f
->cmds
->fileinfo
,
2006 _("warning: ignoring old recipe for target `%s'"),
2010 /* Defining .DEFAULT with no deps or cmds clears it. */
2011 if (f
== default_file
&& this == 0 && cmds
== 0)
2016 /* Defining .SUFFIXES with no dependencies clears out the list of
2018 if (f
== suffix_file
&& this == 0)
2020 free_dep_chain (f
->deps
);
2026 /* Double-colon. Make a new record even if there already is one. */
2027 f
= lookup_file (name
);
2029 /* Check for both : and :: rules. Check is_target so we don't lose
2030 on default suffix rules or makefiles. */
2031 if (f
!= 0 && f
->is_target
&& !f
->double_colon
)
2033 _("target file `%s' has both : and :: entries"), f
->name
);
2035 f
= enter_file (strcache_add (name
));
2036 /* If there was an existing entry and it was a double-colon entry,
2037 enter_file will have returned a new one, making it the prev
2038 pointer of the old one, and setting its double_colon pointer to
2040 if (f
->double_colon
== 0)
2041 /* This is the first entry for this name, so we must set its
2042 double_colon pointer to itself. */
2043 f
->double_colon
= f
;
2050 /* If this is a static pattern rule, set the stem to the part of its
2051 name that matched the `%' in the pattern, so you can use $* in the
2052 commands. If we didn't do it before, enter the prereqs now. */
2055 static const char *percent
= "%";
2056 char *buffer
= variable_expand ("");
2057 char *o
= patsubst_expand_pat (buffer
, name
, pattern
, percent
,
2058 pattern_percent
+1, percent
+1);
2059 f
->stem
= strcache_add_len (buffer
, o
- buffer
);
2062 if (! this->need_2nd_expansion
)
2063 this = enter_prereqs (this, f
->stem
);
2065 this->stem
= f
->stem
;
2069 /* Add the dependencies to this file entry. */
2072 /* Add the file's old deps and the new ones in THIS together. */
2077 struct dep
*d
= this;
2079 /* If this rule has commands, put these deps first. */
2080 while (d
->next
!= 0)
2088 struct dep
*d
= f
->deps
;
2090 /* A rule without commands: put its prereqs at the end. */
2091 while (d
->next
!= 0)
2100 /* All done! Set up for the next one. */
2106 /* Reduce escaped percents. If there are any unescaped it's an error */
2107 name
= filenames
->name
;
2108 if (find_percent_cached (&name
))
2109 fatal (flocp
, _("mixed implicit and normal rules"));
2113 /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
2114 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
2115 Quoting backslashes are removed from STRING by compacting it into
2116 itself. Returns a pointer to the first unquoted STOPCHAR if there is
2117 one, or nil if there are none. STOPCHARs inside variable references are
2118 ignored if IGNOREVARS is true.
2120 STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */
2123 find_char_unquote (char *string
, int stop1
, int stop2
, int blank
,
2126 unsigned int string_len
= 0;
2135 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
&& *p
!= stop2
2136 && ! isblank ((unsigned char) *p
))
2139 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
&& *p
!= stop2
)
2142 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
2143 && ! isblank ((unsigned char) *p
))
2146 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
)
2152 /* If we stopped due to a variable reference, skip over its contents. */
2153 if (*p
== ignorevars
)
2155 char openparen
= p
[1];
2159 /* Skip the contents of a non-quoted, multi-char variable ref. */
2160 if (openparen
== '(' || openparen
== '{')
2162 unsigned int pcount
= 1;
2163 char closeparen
= (openparen
== '(' ? ')' : '}');
2167 if (*p
== openparen
)
2169 else if (*p
== closeparen
)
2179 /* Skipped the variable reference: look for STOPCHARS again. */
2183 if (p
> string
&& p
[-1] == '\\')
2185 /* Search for more backslashes. */
2187 while (&p
[i
] >= string
&& p
[i
] == '\\')
2190 /* Only compute the length if really needed. */
2191 if (string_len
== 0)
2192 string_len
= strlen (string
);
2193 /* The number of backslashes is now -I.
2194 Copy P over itself to swallow half of them. */
2195 memmove (&p
[i
], &p
[i
/2], (string_len
- (p
- string
)) - (i
/2) + 1);
2198 /* All the backslashes quoted each other; the STOPCHAR was
2202 /* The STOPCHAR was quoted by a backslash. Look for another. */
2205 /* No backslash in sight. */
2209 /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
2213 /* Search PATTERN for an unquoted % and handle quoting. */
2216 find_percent (char *pattern
)
2218 return find_char_unquote (pattern
, '%', 0, 0, 0);
2221 /* Search STRING for an unquoted % and handle quoting. Returns a pointer to
2222 the % or NULL if no % was found.
2223 This version is used with strings in the string cache: if there's a need to
2224 modify the string a new version will be added to the string cache and
2225 *STRING will be set to that. */
2228 find_percent_cached (const char **string
)
2230 const char *p
= *string
;
2234 /* If the first char is a % return now. This lets us avoid extra tests
2241 while (*p
!= '\0' && *p
!= '%')
2247 /* See if this % is escaped with a backslash; if not we're done. */
2252 /* Search for more backslashes. */
2256 while (&p
[i
] >= *string
&& p
[i
] == '\\')
2260 /* At this point we know we'll need to allocate a new string.
2261 Make a copy if we haven't yet done so. */
2264 slen
= strlen (*string
);
2265 new = alloca (slen
+ 1);
2266 memcpy (new, *string
, slen
+ 1);
2267 p
= new + (p
- *string
);
2271 /* At this point *string, p, and new all point into the same string.
2272 Get a non-const version of p so we can modify new. */
2273 pv
= new + (p
- *string
);
2275 /* The number of backslashes is now -I.
2276 Copy P over itself to swallow half of them. */
2277 memmove (&pv
[i
], &pv
[i
/2], (slen
- (pv
- new)) - (i
/2) + 1);
2280 /* If the backslashes quoted each other; the % was unquoted. */
2286 /* If we had to change STRING, add it to the strcache. */
2289 *string
= strcache_add (*string
);
2290 p
= *string
+ (p
- new);
2293 /* If we didn't find a %, return NULL. Otherwise return a ptr to it. */
2294 return (*p
== '\0') ? NULL
: p
;
2297 /* Find the next line of text in an eval buffer, combining continuation lines
2299 Return the number of actual lines read (> 1 if continuation lines).
2300 Returns -1 if there's nothing left in the buffer.
2302 After this function, ebuf->buffer points to the first character of the
2306 /* Read a line of text from a STRING.
2307 Since we aren't really reading from a file, don't bother with linenumbers.
2310 static unsigned long
2311 readstring (struct ebuffer
*ebuf
)
2315 /* If there is nothing left in this buffer, return 0. */
2316 if (ebuf
->bufnext
>= ebuf
->bufstart
+ ebuf
->size
)
2319 /* Set up a new starting point for the buffer, and find the end of the
2320 next logical line (taking into account backslash/newline pairs). */
2322 eol
= ebuf
->buffer
= ebuf
->bufnext
;
2327 const char *bol
= eol
;
2330 /* Find the next newline. At EOS, stop. */
2331 p
= eol
= strchr (eol
, '\n');
2334 ebuf
->bufnext
= ebuf
->bufstart
+ ebuf
->size
+ 1;
2338 /* Found a newline; if it's escaped continue; else we're done. */
2339 while (p
> bol
&& *(--p
) == '\\')
2340 backslash
= !backslash
;
2346 /* Overwrite the newline char. */
2348 ebuf
->bufnext
= eol
+1;
2354 readline (struct ebuffer
*ebuf
)
2361 /* The behaviors between string and stream buffers are different enough to
2362 warrant different functions. Do the Right Thing. */
2365 return readstring (ebuf
);
2367 /* When reading from a file, we always start over at the beginning of the
2368 buffer for each new line. */
2370 p
= start
= ebuf
->bufstart
;
2371 end
= p
+ ebuf
->size
;
2374 while (fgets (p
, end
- p
, ebuf
->fp
) != 0)
2383 /* This only happens when the first thing on the line is a '\0'.
2384 It is a pretty hopeless case, but (wonder of wonders) Athena
2385 lossage strikes again! (xmkmf puts NULs in its makefiles.)
2386 There is nothing really to be done; we synthesize a newline so
2387 the following line doesn't appear to be part of this line. */
2389 _("warning: NUL character seen; rest of line ignored"));
2394 /* Jump past the text we just read. */
2397 /* If the last char isn't a newline, the whole line didn't fit into the
2398 buffer. Get some more buffer and try again. */
2402 /* We got a newline, so add one to the count of lines. */
2405 #if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
2406 /* Check to see if the line was really ended with CRLF; if so ignore
2408 if ((p
- start
) > 1 && p
[-2] == '\r')
2416 for (p2
= p
- 2; p2
>= start
; --p2
)
2420 backslash
= !backslash
;
2429 /* It was a backslash/newline combo. If we have more space, read
2434 /* We need more space at the end of our buffer, so realloc it.
2435 Make sure to preserve the current offset of p. */
2438 unsigned long off
= p
- start
;
2440 start
= ebuf
->buffer
= ebuf
->bufstart
= xrealloc (start
, ebuf
->size
);
2442 end
= start
+ ebuf
->size
;
2447 if (ferror (ebuf
->fp
))
2448 pfatal_with_name (ebuf
->floc
.filenm
);
2450 /* If we found some lines, return how many.
2451 If we didn't, but we did find _something_, that indicates we read the last
2452 line of a file with no final newline; return 1.
2453 If we read nothing, we're at EOF; return -1. */
2455 return nlines
? nlines
: p
== ebuf
->bufstart
? -1 : 1;
2458 /* Parse the next "makefile word" from the input buffer, and return info
2461 A "makefile word" is one of:
2463 w_bogus Should never happen
2465 w_static A static word; cannot be expanded
2466 w_variable A word containing one or more variables/functions
2468 w_dcolon A double-colon
2469 w_semicolon A semicolon
2470 w_varassign A variable assignment operator (=, :=, +=, ?=, or !=)
2472 Note that this function is only used when reading certain parts of the
2473 makefile. Don't use it where special rules hold sway (RHS of a variable,
2474 in a command list, etc.) */
2476 static enum make_word_type
2477 get_next_mword (char *buffer
, char *delim
, char **startp
, unsigned int *length
)
2479 enum make_word_type wtype
= w_bogus
;
2480 char *p
= buffer
, *beg
;
2483 /* Skip any leading whitespace. */
2484 while (isblank ((unsigned char)*p
))
2496 wtype
= w_semicolon
;
2500 wtype
= w_varassign
;
2514 wtype
= w_varassign
;
2525 wtype
= w_varassign
;
2530 if (delim
&& strchr (delim
, c
))
2535 /* Did we find something? If so, return now. */
2536 if (wtype
!= w_bogus
)
2539 /* This is some non-operator word. A word consists of the longest
2540 string of characters that doesn't contain whitespace, one of [:=#],
2541 or [?+!]=, or one of the chars in the DELIM string. */
2543 /* We start out assuming a static word; if we see a variable we'll
2544 adjust our assumptions then. */
2547 /* We already found the first value of "c", above. */
2562 #ifdef HAVE_DOS_PATHS
2563 /* A word CAN include a colon in its drive spec. The drive
2564 spec is allowed either at the beginning of a word, or as part
2565 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
2567 && (*p
== '/' || *p
== '\\') && isalpha ((unsigned char)p
[-2])
2568 && (p
- beg
== 2 || p
[-3] == '(')))
2577 /* This is a variable reference, so note that it's expandable.
2578 Then read it to the matching close paren. */
2586 /* This is a single-letter variable reference. */
2589 for (count
=0; *p
!= '\0'; ++p
)
2593 else if (*p
== closeparen
&& --count
< 0)
2620 if (delim
&& strchr (delim
, c
))
2638 /* Construct the list of include directories
2639 from the arguments and the default list. */
2642 construct_include_path (const char **arg_dirs
)
2644 #ifdef VAXC /* just don't ask ... */
2653 /* Compute the number of pointers we need in the table. */
2654 idx
= sizeof (default_include_directories
) / sizeof (const char *);
2656 for (cpp
= arg_dirs
; *cpp
!= 0; ++cpp
)
2660 /* Add one for $DJDIR. */
2664 dirs
= xmalloc (idx
* sizeof (const char *));
2669 /* First consider any dirs specified with -I switches.
2670 Ignore any that don't exist. Remember the maximum string length. */
2673 while (*arg_dirs
!= 0)
2675 const char *dir
= *(arg_dirs
++);
2681 expanded
= tilde_expand (dir
);
2686 EINTRLOOP (e
, stat (dir
, &stbuf
));
2687 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2689 unsigned int len
= strlen (dir
);
2690 /* If dir name is written with trailing slashes, discard them. */
2691 while (len
> 1 && dir
[len
- 1] == '/')
2693 if (len
> max_incl_len
)
2695 dirs
[idx
++] = strcache_add_len (dir
, len
);
2702 /* Now add the standard default dirs at the end. */
2706 /* The environment variable $DJDIR holds the root of the DJGPP directory
2707 tree; add ${DJDIR}/include. */
2708 struct variable
*djdir
= lookup_variable ("DJDIR", 5);
2712 unsigned int len
= strlen (djdir
->value
) + 8;
2713 char *defdir
= alloca (len
+ 1);
2715 strcat (strcpy (defdir
, djdir
->value
), "/include");
2716 dirs
[idx
++] = strcache_add (defdir
);
2718 if (len
> max_incl_len
)
2724 for (cpp
= default_include_directories
; *cpp
!= 0; ++cpp
)
2728 EINTRLOOP (e
, stat (*cpp
, &stbuf
));
2729 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2731 unsigned int len
= strlen (*cpp
);
2732 /* If dir name is written with trailing slashes, discard them. */
2733 while (len
> 1 && (*cpp
)[len
- 1] == '/')
2735 if (len
> max_incl_len
)
2737 dirs
[idx
++] = strcache_add_len (*cpp
, len
);
2743 /* Now add each dir to the .INCLUDE_DIRS variable. */
2745 for (cpp
= dirs
; *cpp
!= 0; ++cpp
)
2746 do_variable_definition (NILF
, ".INCLUDE_DIRS", *cpp
,
2747 o_default
, f_append
, 0);
2749 include_directories
= dirs
;
2752 /* Expand ~ or ~USER at the beginning of NAME.
2753 Return a newly malloc'd string or 0. */
2756 tilde_expand (const char *name
)
2759 if (name
[1] == '/' || name
[1] == '\0')
2761 extern char *getenv ();
2766 /* Turn off --warn-undefined-variables while we expand HOME. */
2767 int save
= warn_undefined_variables_flag
;
2768 warn_undefined_variables_flag
= 0;
2770 home_dir
= allocated_variable_expand ("$(HOME)");
2772 warn_undefined_variables_flag
= save
;
2775 is_variable
= home_dir
[0] != '\0';
2779 home_dir
= getenv ("HOME");
2781 # if !defined(_AMIGA) && !defined(WINDOWS32)
2782 if (home_dir
== 0 || home_dir
[0] == '\0')
2784 extern char *getlogin ();
2785 char *logname
= getlogin ();
2789 struct passwd
*p
= getpwnam (logname
);
2791 home_dir
= p
->pw_dir
;
2794 # endif /* !AMIGA && !WINDOWS32 */
2797 char *new = xstrdup (concat (2, home_dir
, name
+ 1));
2803 # if !defined(_AMIGA) && !defined(WINDOWS32)
2806 struct passwd
*pwent
;
2807 char *userend
= strchr (name
+ 1, '/');
2810 pwent
= getpwnam (name
+ 1);
2814 return xstrdup (pwent
->pw_dir
);
2816 return xstrdup (concat (3, pwent
->pw_dir
, "/", userend
+ 1));
2818 else if (userend
!= 0)
2821 # endif /* !AMIGA && !WINDOWS32 */
2826 /* Parse a string into a sequence of filenames represented as a chain of
2827 struct nameseq's and return that chain. Optionally expand the strings via
2830 The string is passed as STRINGP, the address of a string pointer.
2831 The string pointer is updated to point at the first character
2832 not parsed, which either is a null char or equals STOPCHAR.
2834 SIZE is how big to construct chain elements.
2835 This is useful if we want them actually to be other structures
2836 that have room for additional info.
2838 PREFIX, if non-null, is added to the beginning of each filename.
2840 FLAGS allows one or more of the following bitflags to be set:
2841 PARSEFS_NOSTRIP - Do no strip './'s off the beginning
2842 PARSEFS_NOAR - Do not check filenames for archive references
2843 PARSEFS_NOGLOB - Do not expand globbing characters
2844 PARSEFS_EXISTS - Only return globbed files that actually exist
2845 (cannot also set NOGLOB)
2846 PARSEFS_NOCACHE - Do not add filenames to the strcache (caller frees)
2850 parse_file_seq (char **stringp
, unsigned int size
, int stopchar
,
2851 const char *prefix
, int flags
)
2853 extern void dir_setup_glob (glob_t
*glob
);
2855 /* tmp points to tmpbuf after the prefix, if any.
2856 tp is the end of the buffer. */
2857 static char *tmpbuf
= NULL
;
2858 static int tmpbuf_len
= 0;
2860 int cachep
= (! (flags
& PARSEFS_NOCACHE
));
2862 struct nameseq
*new = 0;
2863 struct nameseq
**newp
= &new;
2864 #define NEWELT(_n) do { \
2865 const char *__n = (_n); \
2866 *newp = xcalloc (size); \
2867 (*newp)->name = (cachep ? strcache_add (__n) : xstrdup (__n)); \
2868 newp = &(*newp)->next; \
2876 # define VMS_COMMA ','
2878 # define VMS_COMMA 0
2881 if (size
< sizeof (struct nameseq
))
2882 size
= sizeof (struct nameseq
);
2884 if (! (flags
& PARSEFS_NOGLOB
))
2885 dir_setup_glob (&gl
);
2887 /* Get enough temporary space to construct the largest possible target. */
2889 int l
= strlen (*stringp
) + 1;
2892 tmpbuf
= xrealloc (tmpbuf
, l
);
2898 /* Parse STRING. P will always point to the end of the parsed content. */
2903 const char **nlist
= 0;
2914 /* Skip whitespace; at the end of the string or STOPCHAR we're done. */
2916 if (*p
== '\0' || *p
== stopchar
)
2919 /* There are names left, so find the end of the next name.
2920 Throughout this iteration S points to the start. */
2922 p
= find_char_unquote (p
, stopchar
, VMS_COMMA
, 1, 0);
2924 /* convert comma separated list to space separated */
2929 if (stopchar
== ':' && p
&& *p
== ':'
2930 && !(isspace ((unsigned char)p
[1]) || !p
[1]
2931 || isspace ((unsigned char)p
[-1])))
2932 p
= find_char_unquote (p
+1, stopchar
, VMS_COMMA
, 1, 0);
2934 #ifdef HAVE_DOS_PATHS
2935 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
2936 first colon which isn't followed by a slash or a backslash.
2937 Note that tokens separated by spaces should be treated as separate
2938 tokens since make doesn't allow path names with spaces */
2939 if (stopchar
== ':')
2940 while (p
!= 0 && !isspace ((unsigned char)*p
) &&
2941 (p
[1] == '\\' || p
[1] == '/') && isalpha ((unsigned char)p
[-1]))
2942 p
= find_char_unquote (p
+ 1, stopchar
, VMS_COMMA
, 1, 0);
2947 /* Strip leading "this directory" references. */
2948 if (! (flags
& PARSEFS_NOSTRIP
))
2950 /* Skip leading `[]'s. */
2951 while (p
- s
> 2 && s
[0] == '[' && s
[1] == ']')
2953 /* Skip leading `./'s. */
2954 while (p
- s
> 2 && s
[0] == '.' && s
[1] == '/')
2957 /* Skip "./" and all following slashes. */
2963 /* Extract the filename just found, and skip it.
2964 Set NAME to the string, and NLEN to its length. */
2968 /* The name was stripped to empty ("./"). */
2971 #elif defined(_AMIGA)
2972 /* PDS-- This cannot be right!! */
2985 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need
2986 * to remove this '\' before we can use the filename.
2987 * xstrdup called because S may be read-only string constant.
2992 if (s
[0] == '\\' && s
[1] == ':')
3000 memcpy (tp
, s
, nlen
);
3005 /* At this point, TP points to the element and NLEN is its length. */
3008 /* If this is the start of an archive group that isn't complete, set up
3009 to add the archive prefix for future files. A file list like:
3010 "libf.a(x.o y.o z.o)" needs to be expanded as:
3011 "libf.a(x.o) libf.a(y.o) libf.a(z.o)"
3013 TP == TMP means we're not already in an archive group. Ignore
3014 something starting with `(', as that cannot actually be an
3015 archive-member reference (and treating it as such results in an empty
3016 file name, which causes much lossage). Also if it ends in ")" then
3017 it's a complete reference so we don't need to treat it specially.
3019 Finally, note that archive groups must end with ')' as the last
3020 character, so ensure there's some word ending like that before
3021 considering this an archive group. */
3022 if (! (flags
& PARSEFS_NOAR
)
3023 && tp
== tmpbuf
&& tp
[0] != '(' && tp
[nlen
-1] != ')')
3025 char *n
= strchr (tp
, '(');
3028 /* This looks like the first element in an open archive group.
3029 A valid group MUST have ')' as the last character. */
3034 /* Find the end of this word. We don't want to unquote and
3035 we don't care about quoting since we're looking for the
3036 last char in the word. */
3037 while (*e
!= '\0' && *e
!= stopchar
&& *e
!= VMS_COMMA
3038 && ! isblank ((unsigned char) *e
))
3042 /* Found the end, so this is the first element in an
3043 open archive group. It looks like "lib(mem".
3044 Reset TP past the open paren. */
3045 nlen
-= (n
+ 1) - tp
;
3048 /* We can stop looking now. */
3054 /* If we have just "lib(", part of something like "lib( a b)",
3055 go to the next item. */
3061 /* If we are inside an archive group, make sure it has an end. */
3064 if (tp
[nlen
-1] == ')')
3066 /* This is the natural end; reset TP. */
3069 /* This is just ")", something like "lib(a b )": skip it. */
3075 /* Not the end, so add a "fake" end. */
3082 /* If we're not globbing we're done: add it to the end of the chain.
3083 Go to the next item in the string. */
3084 if (flags
& PARSEFS_NOGLOB
)
3086 NEWELT (concat (2, prefix
, tmpbuf
));
3090 /* If we get here we know we're doing glob expansion.
3091 TP is a string in tmpbuf. NLEN is no longer used.
3092 We may need to do more work: after this NAME will be set. */
3095 /* Expand tilde if applicable. */
3096 if (tmpbuf
[0] == '~')
3098 tildep
= tilde_expand (tmpbuf
);
3104 /* If NAME is an archive member reference replace it with the archive
3105 file name, and save the member name in MEMNAME. We will glob on the
3106 archive name and then reattach MEMNAME later. */
3107 if (! (flags
& PARSEFS_NOAR
) && ar_name (name
))
3109 ar_parse_name (name
, &arname
, &memname
);
3112 #endif /* !NO_ARCHIVES */
3114 /* glob() is expensive: don't call it unless we need to. */
3115 if (!(flags
& PARSEFS_EXISTS
) && strpbrk (name
, "?*[") == NULL
)
3122 switch (glob (name
, GLOB_NOSORT
|GLOB_ALTDIRFUNC
, NULL
, &gl
))
3125 fatal (NILF
, _("virtual memory exhausted"));
3130 nlist
= (const char **)gl
.gl_pathv
;
3134 /* If we want only existing items, skip this one. */
3135 if (flags
& PARSEFS_EXISTS
)
3143 /* By default keep this name. */
3149 /* For each matched element, add it to the list. */
3154 /* Try to glob on MEMNAME within the archive. */
3155 struct nameseq
*found
= ar_glob (nlist
[i
], memname
, size
);
3157 /* No matches. Use MEMNAME as-is. */
3158 NEWELT (concat (5, prefix
, nlist
[i
], "(", memname
, ")"));
3161 /* We got a chain of items. Attach them. */
3163 (*newp
)->next
= found
;
3167 /* Find and set the new end. Massage names if necessary. */
3171 found
->name
= xstrdup (concat (2, prefix
, name
));
3173 found
->name
= strcache_add (concat (2, prefix
, name
));
3175 if (found
->next
== 0)
3178 found
= found
->next
;
3180 newp
= &found
->next
;
3184 #endif /* !NO_ARCHIVES */
3185 NEWELT (concat (2, prefix
, nlist
[i
]));