1 /* Reading and parsing of makefiles for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 2002 Free Software Foundation, Inc.
4 This file is part of GNU Make.
6 GNU Make is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Make is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Make; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
42 struct passwd
*getpwnam
PARAMS ((char *name
));
45 #endif /* !WINDOWS32 */
47 /* A 'struct ebuffer' controls the origin of the makefile we are currently
53 char *buffer
; /* Start of the current line in the buffer. */
54 char *bufnext
; /* Start of the next line in the buffer. */
55 char *bufstart
; /* Start of the entire buffer. */
56 unsigned int size
; /* Malloc'd size of buffer. */
57 FILE *fp
; /* File, or NULL if this is an internal buffer. */
58 struct floc floc
; /* Info on the file in fp (if any). */
61 /* Types of "words" that can be read in a makefile. */
64 w_bogus
, w_eol
, w_static
, w_variable
, w_colon
, w_dcolon
, w_semicolon
,
69 /* A `struct conditionals' contains the information describing
70 all the active conditionals in a makefile.
72 The global variable `conditionals' contains the conditionals
73 information for the current makefile. It is initialized from
74 the static structure `toplevel_conditionals' and is later changed
75 to new structures for included makefiles. */
79 unsigned int if_cmds
; /* Depth of conditional nesting. */
80 unsigned int allocated
; /* Elts allocated in following arrays. */
81 char *ignoring
; /* Are we ignoring or interpreting?
82 0=interpreting, 1=not yet interpreted,
83 2=already interpreted */
84 char *seen_else
; /* Have we already seen an `else'? */
87 static struct conditionals toplevel_conditionals
;
88 static struct conditionals
*conditionals
= &toplevel_conditionals
;
91 /* Default directories to search for include files in */
93 static char *default_include_directories
[] =
95 #if defined(WINDOWS32) && !defined(INCLUDEDIR)
97 * This completely up to the user when they install MSVC or other packages.
98 * This is defined as a placeholder.
100 #define INCLUDEDIR "."
105 "/usr/local/include",
111 /* List of directories to search for include files in */
113 static char **include_directories
;
115 /* Maximum length of an element of the above. */
117 static unsigned int max_incl_len
;
119 /* The filename and pointer to line number of the
120 makefile currently being read in. */
122 const struct floc
*reading_file
= 0;
124 /* The chain of makefiles read by read_makefile. */
126 static struct dep
*read_makefiles
= 0;
128 static int eval_makefile
PARAMS ((char *filename
, int flags
));
129 static int eval
PARAMS ((struct ebuffer
*buffer
, int flags
));
131 static long readline
PARAMS ((struct ebuffer
*ebuf
));
132 static void do_define
PARAMS ((char *name
, unsigned int namelen
,
133 enum variable_origin origin
,
134 struct ebuffer
*ebuf
));
135 static int conditional_line
PARAMS ((char *line
, int len
, const struct floc
*flocp
));
136 static void record_files
PARAMS ((struct nameseq
*filenames
, char *pattern
, char *pattern_percent
,
137 struct dep
*deps
, unsigned int cmds_started
, char *commands
,
138 unsigned int commands_idx
, int two_colon
,
139 const struct floc
*flocp
));
140 static void record_target_var
PARAMS ((struct nameseq
*filenames
, char *defn
,
141 enum variable_origin origin
,
143 const struct floc
*flocp
));
144 static enum make_word_type get_next_mword
PARAMS ((char *buffer
, char *delim
,
145 char **startp
, unsigned int *length
));
147 /* Read in all the makefiles and return the chain of their names. */
150 read_all_makefiles (char **makefiles
)
152 unsigned int num_makefiles
= 0;
154 /* Create *_LIST variables, to hold the makefiles, targets, and variables
155 we will be reading. */
157 define_variable ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", o_file
, 0);
159 DB (DB_BASIC
, (_("Reading makefiles...\n")));
161 /* If there's a non-null variable MAKEFILES, its value is a list of
162 files to read first thing. But don't let it prevent reading the
163 default makefiles and don't let the default goal come from there. */
171 /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
172 int save
= warn_undefined_variables_flag
;
173 warn_undefined_variables_flag
= 0;
175 value
= allocated_variable_expand ("$(MAKEFILES)");
177 warn_undefined_variables_flag
= save
;
180 /* Set NAME to the start of next token and LENGTH to its length.
181 MAKEFILES is updated for finding remaining tokens. */
184 while ((name
= find_next_token (&p
, &length
)) != 0)
188 name
= xstrdup (name
);
189 if (eval_makefile (name
,
190 RM_NO_DEFAULT_GOAL
|RM_INCLUDED
|RM_DONTCARE
) < 2)
197 /* Read makefiles specified with -f switches. */
200 while (*makefiles
!= 0)
202 struct dep
*tail
= read_makefiles
;
203 register struct dep
*d
;
205 if (! eval_makefile (*makefiles
, 0))
206 perror_with_name ("", *makefiles
);
208 /* Find the right element of read_makefiles. */
210 while (d
->next
!= tail
)
213 /* Use the storage read_makefile allocates. */
214 *makefiles
= dep_name (d
);
219 /* If there were no -f switches, try the default names. */
221 if (num_makefiles
== 0)
223 static char *default_makefiles
[] =
225 /* all lower case since readdir() (the vms version) 'lowercasifies' */
226 { "makefile.vms", "gnumakefile.", "makefile.", 0 };
229 { "GNUmakefile", "Makefile", "SMakefile", 0 };
230 #else /* !Amiga && !VMS */
231 { "GNUmakefile", "makefile", "Makefile", 0 };
234 register char **p
= default_makefiles
;
235 while (*p
!= 0 && !file_exists_p (*p
))
240 if (! eval_makefile (*p
, 0))
241 perror_with_name ("", *p
);
245 /* No default makefile was found. Add the default makefiles to the
246 `read_makefiles' chain so they will be updated if possible. */
247 struct dep
*tail
= read_makefiles
;
248 /* Add them to the tail, after any MAKEFILES variable makefiles. */
249 while (tail
!= 0 && tail
->next
!= 0)
251 for (p
= default_makefiles
; *p
!= 0; ++p
)
253 struct dep
*d
= (struct dep
*) xmalloc (sizeof (struct dep
));
255 d
->file
= enter_file (*p
);
256 d
->file
->dontcare
= 1;
258 d
->need_2nd_expansion
= 0;
259 /* Tell update_goal_chain to bail out as soon as this file is
260 made, and main not to die if we can't make this file. */
261 d
->changed
= RM_DONTCARE
;
273 return read_makefiles
;
276 /* Install a new conditional and return the previous one. */
278 static struct conditionals
*
279 install_conditionals (struct conditionals
*new)
281 struct conditionals
*save
= conditionals
;
283 bzero ((char *) new, sizeof (*new));
289 /* Free the current conditionals and reinstate a saved one. */
292 restore_conditionals (struct conditionals
*saved
)
294 /* Free any space allocated by conditional_line. */
295 if (conditionals
->ignoring
)
296 free (conditionals
->ignoring
);
297 if (conditionals
->seen_else
)
298 free (conditionals
->seen_else
);
301 conditionals
= saved
;
305 eval_makefile (char *filename
, int flags
)
309 const struct floc
*curfile
;
313 ebuf
.floc
.filenm
= filename
;
314 ebuf
.floc
.lineno
= 1;
316 if (ISDB (DB_VERBOSE
))
318 printf (_("Reading makefile `%s'"), filename
);
319 if (flags
& RM_NO_DEFAULT_GOAL
)
320 printf (_(" (no default goal)"));
321 if (flags
& RM_INCLUDED
)
322 printf (_(" (search path)"));
323 if (flags
& RM_DONTCARE
)
324 printf (_(" (don't care)"));
325 if (flags
& RM_NO_TILDE
)
326 printf (_(" (no ~ expansion)"));
330 /* First, get a stream to read. */
332 /* Expand ~ in FILENAME unless it came from `include',
333 in which case it was already done. */
334 if (!(flags
& RM_NO_TILDE
) && filename
[0] == '~')
336 char *expanded
= tilde_expand (filename
);
341 ebuf
.fp
= fopen (filename
, "r");
342 /* Save the error code so we print the right message later. */
343 makefile_errno
= errno
;
345 /* If the makefile wasn't found and it's either a makefile from
346 the `MAKEFILES' variable or an included makefile,
347 search the included makefile search path for this makefile. */
348 if (ebuf
.fp
== 0 && (flags
& RM_INCLUDED
) && *filename
!= '/')
350 register unsigned int i
;
351 for (i
= 0; include_directories
[i
] != 0; ++i
)
353 char *name
= concat (include_directories
[i
], "/", filename
);
354 ebuf
.fp
= fopen (name
, "r");
365 /* Add FILENAME to the chain of read makefiles. */
366 deps
= (struct dep
*) xmalloc (sizeof (struct dep
));
367 deps
->next
= read_makefiles
;
368 read_makefiles
= deps
;
370 deps
->file
= lookup_file (filename
);
372 deps
->file
= enter_file (xstrdup (filename
));
373 if (filename
!= ebuf
.floc
.filenm
)
375 filename
= deps
->file
->name
;
376 deps
->changed
= flags
;
377 deps
->ignore_mtime
= 0;
378 deps
->need_2nd_expansion
= 0;
379 if (flags
& RM_DONTCARE
)
380 deps
->file
->dontcare
= 1;
382 /* If the makefile can't be found at all, give up entirely. */
386 /* If we did some searching, errno has the error from the last
387 attempt, rather from FILENAME itself. Restore it in case the
388 caller wants to use it in a message. */
389 errno
= makefile_errno
;
393 /* Add this makefile to the list. */
394 do_variable_definition (&ebuf
.floc
, "MAKEFILE_LIST", filename
, o_file
,
397 /* Evaluate the makefile */
400 ebuf
.buffer
= ebuf
.bufnext
= ebuf
.bufstart
= xmalloc (ebuf
.size
);
402 curfile
= reading_file
;
403 reading_file
= &ebuf
.floc
;
405 r
= eval (&ebuf
, !(flags
& RM_NO_DEFAULT_GOAL
));
407 reading_file
= curfile
;
411 free (ebuf
.bufstart
);
417 eval_buffer (char *buffer
)
420 struct conditionals
*saved
;
421 struct conditionals
new;
422 const struct floc
*curfile
;
425 /* Evaluate the buffer */
427 ebuf
.size
= strlen (buffer
);
428 ebuf
.buffer
= ebuf
.bufnext
= ebuf
.bufstart
= buffer
;
431 ebuf
.floc
= *reading_file
;
433 curfile
= reading_file
;
434 reading_file
= &ebuf
.floc
;
436 saved
= install_conditionals (&new);
440 restore_conditionals (saved
);
442 reading_file
= curfile
;
449 /* Read file FILENAME as a makefile and add its contents to the data base.
451 SET_DEFAULT is true if we are allowed to set the default goal. */
455 eval (struct ebuffer
*ebuf
, int set_default
)
458 unsigned int collapsed_length
= 0;
459 unsigned int commands_len
= 200;
461 unsigned int commands_idx
= 0;
462 unsigned int cmds_started
, tgts_started
;
463 int ignoring
= 0, in_ignored_define
= 0;
464 int no_targets
= 0; /* Set when reading a rule without targets. */
465 struct nameseq
*filenames
= 0;
466 struct dep
*deps
= 0;
469 char *pattern
= 0, *pattern_percent
;
473 #define record_waiting_files() \
476 if (filenames != 0) \
478 fi.lineno = tgts_started; \
479 record_files (filenames, pattern, pattern_percent, deps, \
480 cmds_started, commands, commands_idx, two_colon, \
486 if (pattern) { free(pattern); pattern = 0; } \
490 cmds_started
= tgts_started
= 1;
492 fstart
= &ebuf
->floc
;
493 fi
.filenm
= ebuf
->floc
.filenm
;
495 /* Loop over lines in the file.
496 The strategy is to accumulate target names in FILENAMES, dependencies
497 in DEPS and commands in COMMANDS. These are used to define a rule
498 when the start of the next rule (or eof) is encountered.
500 When you see a "continue" in the loop below, that means we are moving on
501 to the next line _without_ ending any rule that we happen to be working
502 with at the moment. If you see a "goto rule_complete", then the
503 statement we just parsed also finishes the previous rule. */
505 commands
= xmalloc (200);
509 unsigned int linelen
;
515 /* Grab the next line to be evaluated */
516 ebuf
->floc
.lineno
+= nlines
;
517 nlines
= readline (ebuf
);
519 /* If there is nothing left to eval, we're done. */
523 /* If this line is empty, skip it. */
528 linelen
= strlen (line
);
530 /* Check for a shell command line first.
531 If it is not one, we can stop treating tab specially. */
535 /* Ignore the commands in a rule with no targets. */
538 /* If there is no preceding rule line, don't treat this line
539 as a command, even though it begins with a tab character.
540 SunOS 4 make appears to behave this way. */
545 /* Yep, this is a shell command, and we don't care. */
548 /* Append this command line to the line being accumulated. */
549 if (commands_idx
== 0)
550 cmds_started
= ebuf
->floc
.lineno
;
552 if (linelen
+ 1 + commands_idx
> commands_len
)
554 commands_len
= (linelen
+ 1 + commands_idx
) * 2;
555 commands
= xrealloc (commands
, commands_len
);
557 bcopy (line
, &commands
[commands_idx
], linelen
);
558 commands_idx
+= linelen
;
559 commands
[commands_idx
++] = '\n';
565 /* This line is not a shell command line. Don't worry about tabs.
566 Get more space if we need it; we don't need to preserve the current
567 contents of the buffer. */
569 if (collapsed_length
< linelen
+1)
571 collapsed_length
= linelen
+1;
573 free ((char *)collapsed
);
574 collapsed
= (char *) xmalloc (collapsed_length
);
576 strcpy (collapsed
, line
);
577 /* Collapse continuation lines. */
578 collapse_continuations (collapsed
);
579 remove_comments (collapsed
);
581 /* Compare a word, both length and contents. */
582 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
584 while (isspace ((unsigned char)*p
))
588 /* This line is completely empty--ignore it. */
591 /* Find the end of the first token. Note we don't need to worry about
592 * ":" here since we compare tokens by length (so "export" will never
593 * be equal to "export:").
595 for (p2
= p
+1; *p2
!= '\0' && !isspace ((unsigned char)*p2
); ++p2
)
599 /* Find the start of the second token. If it looks like a target or
600 variable definition it can't be a preprocessor token so skip
601 them--this allows variables/targets named `ifdef', `export', etc. */
602 while (isspace ((unsigned char)*p2
))
605 if ((p2
[0] == ':' || p2
[0] == '+' || p2
[0] == '=') && p2
[1] == '\0')
607 /* It can't be a preprocessor token so skip it if we're ignoring */
611 goto skip_conditionals
;
614 /* We must first check for conditional and `define' directives before
615 ignoring anything, since they control what we will do with
618 if (!in_ignored_define
)
620 int i
= conditional_line (p
, len
, fstart
);
624 fatal (fstart
, _("invalid syntax in conditional"));
631 if (word1eq ("endef"))
633 if (!in_ignored_define
)
634 fatal (fstart
, _("extraneous `endef'"));
635 in_ignored_define
= 0;
639 if (word1eq ("define"))
642 in_ignored_define
= 1;
646 fatal (fstart
, _("empty variable name"));
648 /* Let the variable name be the whole rest of the line,
649 with trailing blanks stripped (comments have already been
650 removed), so it could be a complex variable/function
651 reference that might contain blanks. */
652 p
= strchr (p2
, '\0');
653 while (isblank ((unsigned char)p
[-1]))
655 do_define (p2
, p
- p2
, o_file
, ebuf
);
660 if (word1eq ("override"))
663 error (fstart
, _("empty `override' directive"));
665 if (strneq (p2
, "define", 6)
666 && (isblank ((unsigned char)p2
[6]) || p2
[6] == '\0'))
669 in_ignored_define
= 1;
672 p2
= next_token (p2
+ 6);
674 fatal (fstart
, _("empty variable name"));
676 /* Let the variable name be the whole rest of the line,
677 with trailing blanks stripped (comments have already been
678 removed), so it could be a complex variable/function
679 reference that might contain blanks. */
680 p
= strchr (p2
, '\0');
681 while (isblank ((unsigned char)p
[-1]))
683 do_define (p2
, p
- p2
, o_override
, ebuf
);
687 && !try_variable_definition (fstart
, p2
, o_override
, 0))
688 error (fstart
, _("invalid `override' directive"));
694 /* Ignore the line. We continue here so conditionals
695 can appear in the middle of a rule. */
698 if (word1eq ("export"))
700 /* 'export' by itself causes everything to be exported. */
702 export_all_variables
= 1;
707 v
= try_variable_definition (fstart
, p2
, o_file
, 0);
709 v
->export
= v_export
;
715 /* Expand the line so we can use indirect and constructed
716 variable names in an export command. */
717 p2
= ap
= allocated_variable_expand (p2
);
719 for (p
= find_next_token (&p2
, &len
); p
!= 0;
720 p
= find_next_token (&p2
, &len
))
722 v
= lookup_variable (p
, len
);
724 v
= define_variable_loc (p
, len
, "", o_file
, 0,
726 v
->export
= v_export
;
735 if (word1eq ("unexport"))
738 export_all_variables
= 0;
745 /* Expand the line so we can use indirect and constructed
746 variable names in an unexport command. */
747 p2
= ap
= allocated_variable_expand (p2
);
749 for (p
= find_next_token (&p2
, &len
); p
!= 0;
750 p
= find_next_token (&p2
, &len
))
752 v
= lookup_variable (p
, len
);
754 v
= define_variable_loc (p
, len
, "", o_file
, 0, fstart
);
756 v
->export
= v_noexport
;
765 if (word1eq ("vpath"))
769 p2
= variable_expand (p2
);
770 p
= find_next_token (&p2
, &len
);
773 pattern
= savestring (p
, len
);
774 p
= find_next_token (&p2
, &len
);
775 /* No searchpath means remove all previous
776 selective VPATH's with the same pattern. */
779 /* No pattern means remove all previous selective VPATH's. */
781 construct_vpath_list (pattern
, p
);
788 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
790 /* We have found an `include' line specifying a nested
791 makefile to be read at this point. */
792 struct conditionals
*save
;
793 struct conditionals new_conditionals
;
794 struct nameseq
*files
;
795 /* "-include" (vs "include") says no error if the file does not
796 exist. "sinclude" is an alias for this from SGI. */
797 int noerror
= (p
[0] != 'i');
799 p
= allocated_variable_expand (p2
);
803 _("no file name for `%sinclude'"), noerror
? "-" : "");
807 /* Parse the list of file names. */
809 files
= multi_glob (parse_file_seq (&p2
, '\0',
810 sizeof (struct nameseq
),
812 sizeof (struct nameseq
));
815 /* Save the state of conditionals and start
816 the included makefile with a clean slate. */
817 save
= install_conditionals (&new_conditionals
);
819 /* Record the rules that are waiting so they will determine
820 the default goal before those in the included makefile. */
821 record_waiting_files ();
823 /* Read each included makefile. */
826 struct nameseq
*next
= files
->next
;
827 char *name
= files
->name
;
830 free ((char *)files
);
833 r
= eval_makefile (name
, (RM_INCLUDED
| RM_NO_TILDE
834 | (noerror
? RM_DONTCARE
: 0)));
838 error (fstart
, "%s: %s", name
, strerror (errno
));
843 /* Restore conditional state. */
844 restore_conditionals (save
);
849 if (try_variable_definition (fstart
, p
, o_file
, 0))
850 /* This line has been dealt with. */
853 /* This line starts with a tab but was not caught above because there
854 was no preceding target, and the line might have been usable as a
855 variable definition. But now we know it is definitely lossage. */
857 fatal(fstart
, _("commands commence before first target"));
859 /* This line describes some target files. This is complicated by
860 the existence of target-specific variables, because we can't
861 expand the entire line until we know if we have one or not. So
862 we expand the line word by word until we find the first `:',
863 then check to see if it's a target-specific variable.
865 In this algorithm, `lb_next' will point to the beginning of the
866 unexpanded parts of the input buffer, while `p2' points to the
867 parts of the expanded buffer we haven't searched yet. */
870 enum make_word_type wtype
;
871 enum variable_origin v_origin
;
873 char *cmdleft
, *semip
, *lb_next
;
874 unsigned int len
, plen
= 0;
876 const char *end
, *beg
; /* Helpers for whitespace stripping. */
878 /* Record the previous rule. */
880 record_waiting_files ();
881 tgts_started
= fstart
->lineno
;
883 /* Search the line for an unquoted ; that is not after an
885 cmdleft
= find_char_unquote (line
, ';', '#', 0);
886 if (cmdleft
!= 0 && *cmdleft
== '#')
888 /* We found a comment before a semicolon. */
892 else if (cmdleft
!= 0)
893 /* Found one. Cut the line short there before expanding it. */
897 collapse_continuations (line
);
899 /* We can't expand the entire line, since if it's a per-target
900 variable we don't want to expand it. So, walk from the
901 beginning, expanding as we go, and looking for "interesting"
902 chars. The first word is always expandable. */
903 wtype
= get_next_mword(line
, NULL
, &lb_next
, &len
);
908 fatal(fstart
, _("missing rule before commands"));
909 /* This line contained something but turned out to be nothing
910 but whitespace (a comment?). */
915 /* We accept and ignore rules without targets for
916 compatibility with SunOS 4 make. */
924 p2
= variable_expand_string(NULL
, lb_next
, len
);
931 /* Look for a semicolon in the expanded line. */
932 cmdleft
= find_char_unquote (p2
, ';', 0, 0);
936 unsigned long p2_off
= p2
- variable_buffer
;
937 unsigned long cmd_off
= cmdleft
- variable_buffer
;
938 char *pend
= p2
+ strlen(p2
);
940 /* Append any remnants of lb, then cut the line short
944 /* One school of thought says that you shouldn't expand
945 here, but merely copy, since now you're beyond a ";"
946 and into a command script. However, the old parser
947 expanded the whole line, so we continue that for
948 backwards-compatiblity. Also, it wouldn't be
949 entirely consistent, since we do an unconditional
950 expand below once we know we don't have a
951 target-specific variable. */
952 (void)variable_expand_string(pend
, lb_next
, (long)-1);
953 lb_next
+= strlen(lb_next
);
954 p2
= variable_buffer
+ p2_off
;
955 cmdleft
= variable_buffer
+ cmd_off
+ 1;
959 colonp
= find_char_unquote(p2
, ':', 0, 0);
960 #ifdef HAVE_DOS_PATHS
961 /* The drive spec brain-damage strikes again... */
962 /* Note that the only separators of targets in this context
963 are whitespace and a left paren. If others are possible,
964 they should be added to the string in the call to index. */
965 while (colonp
&& (colonp
[1] == '/' || colonp
[1] == '\\') &&
966 colonp
> p2
&& isalpha ((unsigned char)colonp
[-1]) &&
967 (colonp
== p2
+ 1 || strchr (" \t(", colonp
[-2]) != 0))
968 colonp
= find_char_unquote(colonp
+ 1, ':', 0, 0);
973 wtype
= get_next_mword(lb_next
, NULL
, &lb_next
, &len
);
979 p2
= variable_expand_string(p2
, lb_next
, len
);
980 /* We don't need to worry about cmdleft here, because if it was
981 found in the variable_buffer the entire buffer has already
982 been expanded... we'll never get here. */
985 p2
= next_token (variable_buffer
);
987 /* If the word we're looking at is EOL, see if there's _anything_
988 on the line. If not, a variable expanded to nothing, so ignore
989 it. If so, we can't parse this line so punt. */
993 /* There's no need to be ivory-tower about this: check for
994 one of the most common bugs found in makefiles... */
995 fatal (fstart
, _("missing separator%s"),
996 !strneq(line
, " ", 8) ? ""
997 : _(" (did you mean TAB instead of 8 spaces?)"));
1001 /* Make the colon the end-of-string so we know where to stop
1002 looking for targets. */
1004 filenames
= multi_glob (parse_file_seq (&p2
, '\0',
1005 sizeof (struct nameseq
),
1007 sizeof (struct nameseq
));
1012 /* We accept and ignore rules without targets for
1013 compatibility with SunOS 4 make. */
1017 /* This should never be possible; we handled it above. */
1018 assert (*p2
!= '\0');
1021 /* Is this a one-colon or two-colon entry? */
1022 two_colon
= *p2
== ':';
1026 /* Test to see if it's a target-specific variable. Copy the rest
1027 of the buffer over, possibly temporarily (we'll expand it later
1028 if it's not a target-specific variable). PLEN saves the length
1029 of the unparsed section of p2, for later. */
1030 if (*lb_next
!= '\0')
1032 unsigned int l
= p2
- variable_buffer
;
1034 (void) variable_buffer_output (p2
+plen
,
1035 lb_next
, strlen (lb_next
)+1);
1036 p2
= variable_buffer
+ l
;
1039 /* See if it's an "override" or "export" keyword; if so see if what
1040 comes after it looks like a variable definition. */
1042 wtype
= get_next_mword (p2
, NULL
, &p
, &len
);
1046 if (wtype
== w_static
)
1048 if (word1eq ("override"))
1050 v_origin
= o_override
;
1051 wtype
= get_next_mword (p
+len
, NULL
, &p
, &len
);
1053 else if (word1eq ("export"))
1056 wtype
= get_next_mword (p
+len
, NULL
, &p
, &len
);
1061 wtype
= get_next_mword (p
+len
, NULL
, NULL
, NULL
);
1063 if (wtype
== w_varassign
)
1065 /* If there was a semicolon found, add it back, plus anything
1069 unsigned int l
= p
- variable_buffer
;
1071 variable_buffer_output (p2
+ strlen (p2
),
1072 semip
, strlen (semip
)+1);
1073 p
= variable_buffer
+ l
;
1075 record_target_var (filenames
, p
, v_origin
, exported
, fstart
);
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);
1084 /* We have some targets, so don't ignore the following commands. */
1087 /* Expand the dependencies, etc. */
1088 if (*lb_next
!= '\0')
1090 unsigned int l
= p2
- variable_buffer
;
1091 (void) variable_expand_string (p2
+ plen
, lb_next
, (long)-1);
1092 p2
= variable_buffer
+ l
;
1094 /* Look for a semicolon in the expanded line. */
1097 cmdleft
= find_char_unquote (p2
, ';', 0, 0);
1099 *(cmdleft
++) = '\0';
1103 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
1104 p
= strchr (p2
, ':');
1105 while (p
!= 0 && p
[-1] == '\\')
1107 register char *q
= &p
[-1];
1108 register int backslash
= 0;
1109 while (*q
-- == '\\')
1110 backslash
= !backslash
;
1112 p
= strchr (p
+ 1, ':');
1117 /* Here, the situation is quite complicated. Let's have a look
1118 at a couple of targets:
1126 The rule is that it's only a target, if there are TWO :'s
1127 OR a space around the :.
1129 if (p
&& !(isspace ((unsigned char)p
[1]) || !p
[1]
1130 || isspace ((unsigned char)p
[-1])))
1133 #ifdef HAVE_DOS_PATHS
1139 /* For DOS-style paths, skip a "C:\..." or a "C:/..." */
1140 if (p
!= 0 && (p
[1] == '\\' || p
[1] == '/') &&
1141 isalpha ((unsigned char)p
[-1]) &&
1142 (p
== p2
+ 1 || strchr (" \t:(", p
[-2]) != 0)) {
1143 p
= strchr (p
+ 1, ':');
1146 } while (check_again
);
1151 struct nameseq
*target
;
1152 target
= parse_file_seq (&p2
, ':', sizeof (struct nameseq
), 1);
1155 fatal (fstart
, _("missing target pattern"));
1156 else if (target
->next
!= 0)
1157 fatal (fstart
, _("multiple target patterns"));
1158 pattern
= target
->name
;
1159 pattern_percent
= find_percent (pattern
);
1160 if (pattern_percent
== 0)
1161 fatal (fstart
, _("target pattern contains no `%%'"));
1162 free((char *)target
);
1167 /* Strip leading and trailing whitespaces. */
1169 end
= beg
+ strlen (beg
) - 1;
1170 strip_whitespace (&beg
, &end
);
1172 if (beg
<= end
&& *beg
!= '\0')
1175 const char *fromp
= beg
;
1177 /* Make a copy of the dependency string. Note if we find '$'. */
1178 deps
= (struct dep
*) xmalloc (sizeof (struct dep
));
1180 deps
->name
= top
= (char *) xmalloc (end
- beg
+ 2);
1181 deps
->need_2nd_expansion
= 0;
1182 while (fromp
<= end
)
1185 deps
->need_2nd_expansion
= 1;
1186 *(top
++) = *(fromp
++);
1197 /* Semicolon means rest of line is a command. */
1198 unsigned int len
= strlen (cmdleft
);
1200 cmds_started
= fstart
->lineno
;
1202 /* Add this command line to the buffer. */
1203 if (len
+ 2 > commands_len
)
1205 commands_len
= (len
+ 2) * 2;
1206 commands
= (char *) xrealloc (commands
, commands_len
);
1208 bcopy (cmdleft
, commands
, len
);
1209 commands_idx
+= len
;
1210 commands
[commands_idx
++] = '\n';
1213 /* Determine if this target should be made default. We used to do
1214 this in record_files() but because of the delayed target recording
1215 and because preprocessor directives are legal in target's commands
1216 it is too late. Consider this fragment for example:
1220 ifeq ($(.DEFAULT_GOAL),foo)
1224 Because the target is not recorded until after ifeq directive is
1225 evaluated the .DEFAULT_GOAL does not contain foo yet as one
1226 would expect. Because of this we have to move some of the logic
1229 if (**default_goal_name
== '\0' && set_default
)
1233 struct nameseq
*t
= filenames
;
1235 for (; t
!= 0; t
= t
->next
)
1240 /* We have nothing to do if this is an implicit rule. */
1241 if (strchr (name
, '%') != 0)
1244 /* See if this target's name does not start with a `.',
1245 unless it contains a slash. */
1246 if (*name
== '.' && strchr (name
, '/') == 0
1247 #ifdef HAVE_DOS_PATHS
1248 && strchr (name
, '\\') == 0
1254 /* If this file is a suffix, don't let it be
1255 the default goal file. */
1256 for (d
= suffix_file
->deps
; d
!= 0; d
= d
->next
)
1258 register struct dep
*d2
;
1259 if (*dep_name (d
) != '.' && streq (name
, dep_name (d
)))
1264 for (d2
= suffix_file
->deps
; d2
!= 0; d2
= d2
->next
)
1266 register unsigned int len
= strlen (dep_name (d2
));
1267 if (!strneq (name
, dep_name (d2
), len
))
1269 if (streq (name
+ len
, dep_name (d
)))
1282 define_variable_global (".DEFAULT_GOAL", 13, t
->name
,
1292 /* We get here except in the case that we just read a rule line.
1293 Record now the last rule we read, so following spurious
1294 commands are properly diagnosed. */
1296 record_waiting_files ();
1301 if (conditionals
->if_cmds
)
1302 fatal (fstart
, _("missing `endif'"));
1304 /* At eof, record the last rule. */
1305 record_waiting_files ();
1308 free ((char *) collapsed
);
1309 free ((char *) commands
);
1315 /* Execute a `define' directive.
1316 The first line has already been read, and NAME is the name of
1317 the variable to be defined. The following lines remain to be read. */
1320 do_define (char *name
, unsigned int namelen
,
1321 enum variable_origin origin
, struct ebuffer
*ebuf
)
1323 struct floc defstart
;
1326 unsigned int length
= 100;
1327 char *definition
= (char *) xmalloc (length
);
1328 unsigned int idx
= 0;
1331 /* Expand the variable name. */
1332 char *var
= (char *) alloca (namelen
+ 1);
1333 bcopy (name
, var
, namelen
);
1334 var
[namelen
] = '\0';
1335 var
= variable_expand (var
);
1337 defstart
= ebuf
->floc
;
1344 nlines
= readline (ebuf
);
1345 ebuf
->floc
.lineno
+= nlines
;
1347 /* If there is nothing left to eval, we're done. */
1351 line
= ebuf
->buffer
;
1353 collapse_continuations (line
);
1355 /* If the line doesn't begin with a tab, test to see if it introduces
1356 another define, or ends one. */
1358 /* Stop if we find an 'endef' */
1359 if (line
[0] != '\t')
1361 p
= next_token (line
);
1364 /* If this is another 'define', increment the level count. */
1365 if ((len
== 6 || (len
> 6 && isblank ((unsigned char)p
[6])))
1366 && strneq (p
, "define", 6))
1369 /* If this is an 'endef', decrement the count. If it's now 0,
1370 we've found the last one. */
1371 else if ((len
== 5 || (len
> 5 && isblank ((unsigned char)p
[5])))
1372 && strneq (p
, "endef", 5))
1375 remove_comments (p
);
1376 if (*next_token (p
) != '\0')
1378 _("Extraneous text after `endef' directive"));
1382 /* Define the variable. */
1384 definition
[0] = '\0';
1386 definition
[idx
- 1] = '\0';
1388 /* Always define these variables in the global set. */
1389 define_variable_global (var
, strlen (var
), definition
,
1390 origin
, 1, &defstart
);
1397 /* Otherwise add this line to the variable definition. */
1398 len
= strlen (line
);
1399 if (idx
+ len
+ 1 > length
)
1401 length
= (idx
+ len
) * 2;
1402 definition
= (char *) xrealloc (definition
, length
+ 1);
1405 bcopy (line
, &definition
[idx
], len
);
1407 /* Separate lines with a newline. */
1408 definition
[idx
++] = '\n';
1412 fatal (&defstart
, _("missing `endef', unterminated `define'"));
1418 /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
1419 "ifneq", "else" and "endif".
1420 LINE is the input line, with the command as its first word.
1422 FILENAME and LINENO are the filename and line number in the
1423 current makefile. They are used for error messages.
1425 Value is -2 if the line is not a conditional at all,
1426 -1 if the line is an invalid conditional,
1427 0 if following text should be interpreted,
1428 1 if following text should be ignored. */
1431 conditional_line (char *line
, int len
, const struct floc
*flocp
)
1434 enum { c_ifdef
, c_ifndef
, c_ifeq
, c_ifneq
, c_else
, c_endif
} cmdtype
;
1438 /* Compare a word, both length and contents. */
1439 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
1440 #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
1442 /* Make sure this line is a conditional. */
1443 chkword ("ifdef", c_ifdef
)
1444 else chkword ("ifndef", c_ifndef
)
1445 else chkword ("ifeq", c_ifeq
)
1446 else chkword ("ifneq", c_ifneq
)
1447 else chkword ("else", c_else
)
1448 else chkword ("endif", c_endif
)
1452 /* Found one: skip past it and any whitespace after it. */
1453 line
= next_token (line
+ len
);
1455 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
1457 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
1458 if (cmdtype
== c_endif
)
1463 if (!conditionals
->if_cmds
)
1464 fatal (flocp
, _("extraneous `%s'"), cmdname
);
1466 --conditionals
->if_cmds
;
1471 /* An 'else' statement can either be simple, or it can have another
1472 conditional after it. */
1473 if (cmdtype
== c_else
)
1477 if (!conditionals
->if_cmds
)
1478 fatal (flocp
, _("extraneous `%s'"), cmdname
);
1480 o
= conditionals
->if_cmds
- 1;
1482 if (conditionals
->seen_else
[o
])
1483 fatal (flocp
, _("only one `else' per conditional"));
1485 /* Change the state of ignorance. */
1486 switch (conditionals
->ignoring
[o
])
1489 /* We've just been interpreting. Never do it again. */
1490 conditionals
->ignoring
[o
] = 2;
1493 /* We've never interpreted yet. Maybe this time! */
1494 conditionals
->ignoring
[o
] = 0;
1498 /* It's a simple 'else'. */
1501 conditionals
->seen_else
[o
] = 1;
1505 /* The 'else' has extra text. That text must be another conditional
1506 and cannot be an 'else' or 'endif'. */
1508 /* Find the length of the next word. */
1509 for (p
= line
+1; *p
!= '\0' && !isspace ((unsigned char)*p
); ++p
)
1513 /* If it's 'else' or 'endif' or an illegal conditional, fail. */
1514 if (word1eq("else") || word1eq("endif")
1515 || conditional_line (line
, len
, flocp
) < 0)
1519 /* conditional_line() created a new level of conditional.
1520 Raise it back to this level. */
1521 if (conditionals
->ignoring
[o
] < 2)
1522 conditionals
->ignoring
[o
] = conditionals
->ignoring
[o
+1];
1523 --conditionals
->if_cmds
;
1529 if (conditionals
->allocated
== 0)
1531 conditionals
->allocated
= 5;
1532 conditionals
->ignoring
= (char *) xmalloc (conditionals
->allocated
);
1533 conditionals
->seen_else
= (char *) xmalloc (conditionals
->allocated
);
1536 o
= conditionals
->if_cmds
++;
1537 if (conditionals
->if_cmds
> conditionals
->allocated
)
1539 conditionals
->allocated
+= 5;
1540 conditionals
->ignoring
= (char *)
1541 xrealloc (conditionals
->ignoring
, conditionals
->allocated
);
1542 conditionals
->seen_else
= (char *)
1543 xrealloc (conditionals
->seen_else
, conditionals
->allocated
);
1546 /* Record that we have seen an `if...' but no `else' so far. */
1547 conditionals
->seen_else
[o
] = 0;
1549 /* Search through the stack to see if we're already ignoring. */
1550 for (i
= 0; i
< o
; ++i
)
1551 if (conditionals
->ignoring
[i
])
1553 /* We are already ignoring, so just push a level to match the next
1554 "else" or "endif", and keep ignoring. We don't want to expand
1555 variables in the condition. */
1556 conditionals
->ignoring
[o
] = 1;
1560 if (cmdtype
== c_ifdef
|| cmdtype
== c_ifndef
)
1566 /* Expand the thing we're looking up, so we can use indirect and
1567 constructed variable names. */
1568 var
= allocated_variable_expand (line
);
1570 /* Make sure there's only one variable name to test. */
1571 p
= end_of_token (var
);
1578 v
= lookup_variable (var
, i
);
1580 conditionals
->ignoring
[o
] =
1581 ((v
!= 0 && *v
->value
!= '\0') == (cmdtype
== c_ifndef
));
1587 /* "Ifeq" or "ifneq". */
1590 char termin
= *line
== '(' ? ',' : *line
;
1592 if (termin
!= ',' && termin
!= '"' && termin
!= '\'')
1596 /* Find the end of the first string. */
1600 for (; *line
!= '\0'; ++line
)
1603 else if (*line
== ')')
1605 else if (*line
== ',' && count
<= 0)
1609 while (*line
!= '\0' && *line
!= termin
)
1617 /* Strip blanks after the first string. */
1619 while (isblank ((unsigned char)p
[-1]))
1626 s2
= variable_expand (s1
);
1627 /* We must allocate a new copy of the expanded string because
1628 variable_expand re-uses the same buffer. */
1630 s1
= (char *) alloca (len
+ 1);
1631 bcopy (s2
, s1
, len
+ 1);
1634 /* Find the start of the second string. */
1635 line
= next_token (line
);
1637 termin
= termin
== ',' ? ')' : *line
;
1638 if (termin
!= ')' && termin
!= '"' && termin
!= '\'')
1641 /* Find the end of the second string. */
1644 register int count
= 0;
1645 s2
= next_token (line
);
1646 for (line
= s2
; *line
!= '\0'; ++line
)
1650 else if (*line
== ')')
1663 while (*line
!= '\0' && *line
!= termin
)
1671 line
= next_token (++line
);
1675 s2
= variable_expand (s2
);
1676 conditionals
->ignoring
[o
] = (streq (s1
, s2
) == (cmdtype
== c_ifneq
));
1680 /* Search through the stack to see if we're ignoring. */
1681 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
1682 if (conditionals
->ignoring
[i
])
1687 /* Remove duplicate dependencies in CHAIN. */
1689 static unsigned long
1690 dep_hash_1 (const void *key
)
1692 return_STRING_HASH_1 (dep_name ((struct dep
const *) key
));
1695 static unsigned long
1696 dep_hash_2 (const void *key
)
1698 return_STRING_HASH_2 (dep_name ((struct dep
const *) key
));
1702 dep_hash_cmp (const void *x
, const void *y
)
1704 struct dep
*dx
= (struct dep
*) x
;
1705 struct dep
*dy
= (struct dep
*) y
;
1706 int cmp
= strcmp (dep_name (dx
), dep_name (dy
));
1708 /* If the names are the same but ignore_mtimes are not equal, one of these
1709 is an order-only prerequisite and one isn't. That means that we should
1710 remove the one that isn't and keep the one that is. */
1712 if (!cmp
&& dx
->ignore_mtime
!= dy
->ignore_mtime
)
1713 dx
->ignore_mtime
= dy
->ignore_mtime
= 0;
1720 uniquize_deps (struct dep
*chain
)
1722 struct hash_table deps
;
1723 register struct dep
**depp
;
1725 hash_init (&deps
, 500, dep_hash_1
, dep_hash_2
, dep_hash_cmp
);
1727 /* Make sure that no dependencies are repeated. This does not
1728 really matter for the purpose of updating targets, but it
1729 might make some names be listed twice for $^ and $?. */
1734 struct dep
*dep
= *depp
;
1735 struct dep
**dep_slot
= (struct dep
**) hash_find_slot (&deps
, dep
);
1736 if (HASH_VACANT (*dep_slot
))
1738 hash_insert_at (&deps
, dep
, dep_slot
);
1743 /* Don't bother freeing duplicates.
1744 It's dangerous and little benefit accrues. */
1749 hash_free (&deps
, 0);
1752 /* Record target-specific variable values for files FILENAMES.
1753 TWO_COLON is nonzero if a double colon was used.
1755 The links of FILENAMES are freed, and so are any names in it
1756 that are not incorporated into other data structures.
1758 If the target is a pattern, add the variable to the pattern-specific
1759 variable value list. */
1762 record_target_var (struct nameseq
*filenames
, char *defn
,
1763 enum variable_origin origin
, int exported
,
1764 const struct floc
*flocp
)
1766 struct nameseq
*nextf
;
1767 struct variable_set_list
*global
;
1769 global
= current_variable_set_list
;
1771 /* If the variable is an append version, store that but treat it as a
1772 normal recursive variable. */
1774 for (; filenames
!= 0; filenames
= nextf
)
1777 register char *name
= filenames
->name
;
1780 struct pattern_var
*p
;
1782 nextf
= filenames
->next
;
1783 free ((char *) filenames
);
1785 /* If it's a pattern target, then add it to the pattern-specific
1787 percent
= find_percent (name
);
1790 /* Get a reference for this pattern-specific variable struct. */
1791 p
= create_pattern_var (name
, percent
);
1792 p
->variable
.fileinfo
= *flocp
;
1793 /* I don't think this can fail since we already determined it was a
1794 variable definition. */
1795 v
= parse_variable_definition (&p
->variable
, defn
);
1798 if (v
->flavor
== f_simple
)
1799 v
->value
= allocated_variable_expand (v
->value
);
1801 v
->value
= xstrdup (v
->value
);
1809 /* Get a file reference for this file, and initialize it.
1810 We don't want to just call enter_file() because that allocates a
1811 new entry if the file is a double-colon, which we don't want in
1813 f
= lookup_file (name
);
1815 f
= enter_file (name
);
1816 else if (f
->double_colon
)
1817 f
= f
->double_colon
;
1819 initialize_file_variables (f
, 1);
1822 current_variable_set_list
= f
->variables
;
1823 v
= try_variable_definition (flocp
, defn
, origin
, 1);
1825 error (flocp
, _("Malformed target-specific variable definition"));
1826 current_variable_set_list
= global
;
1829 /* Set up the variable to be *-specific. */
1833 v
->export
= v_export
;
1835 /* If it's not an override, check to see if there was a command-line
1836 setting. If so, reset the value. */
1837 if (origin
!= o_override
)
1839 struct variable
*gv
;
1840 int len
= strlen(v
->name
);
1842 gv
= lookup_variable (v
->name
, len
);
1843 if (gv
&& (gv
->origin
== o_env_override
|| gv
->origin
== o_command
))
1847 v
->value
= xstrdup (gv
->value
);
1848 v
->origin
= gv
->origin
;
1849 v
->recursive
= gv
->recursive
;
1854 /* Free name if not needed further. */
1855 if (name
!= fname
&& (name
< fname
|| name
> fname
+ strlen (fname
)))
1860 /* Record a description line for files FILENAMES,
1861 with dependencies DEPS, commands to execute described
1862 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
1863 TWO_COLON is nonzero if a double colon was used.
1864 If not nil, PATTERN is the `%' pattern to make this
1865 a static pattern rule, and PATTERN_PERCENT is a pointer
1866 to the `%' within it.
1868 The links of FILENAMES are freed, and so are any names in it
1869 that are not incorporated into other data structures. */
1872 record_files (struct nameseq
*filenames
, char *pattern
, char *pattern_percent
,
1873 struct dep
*deps
, unsigned int cmds_started
, char *commands
,
1874 unsigned int commands_idx
, int two_colon
,
1875 const struct floc
*flocp
)
1877 struct nameseq
*nextf
;
1879 unsigned int max_targets
= 0, target_idx
= 0;
1880 char **targets
= 0, **target_percents
= 0;
1881 struct commands
*cmds
;
1883 /* If we've already snapped deps, that means we're in an eval being
1884 resolved after the makefiles have been read in. We can't add more rules
1885 at this time, since they won't get snapped and we'll get core dumps.
1886 See Savannah bug # 12124. */
1888 fatal (flocp
, _("prerequisites cannot be defined in command scripts"));
1890 if (commands_idx
> 0)
1892 cmds
= (struct commands
*) xmalloc (sizeof (struct commands
));
1893 cmds
->fileinfo
.filenm
= flocp
->filenm
;
1894 cmds
->fileinfo
.lineno
= cmds_started
;
1895 cmds
->commands
= savestring (commands
, commands_idx
);
1896 cmds
->command_lines
= 0;
1901 for (; filenames
!= 0; filenames
= nextf
)
1903 char *name
= filenames
->name
;
1907 char *implicit_percent
;
1909 nextf
= filenames
->next
;
1912 /* Check for .POSIX. We used to do this in snap_deps() but that's not
1913 good enough: it doesn't happen until after the makefile is read,
1914 which means we cannot use its value during parsing. */
1916 if (streq (name
, ".POSIX"))
1919 implicit_percent
= find_percent (name
);
1920 implicit
|= implicit_percent
!= 0;
1922 if (implicit
&& pattern
!= 0)
1923 fatal (flocp
, _("mixed implicit and static pattern rules"));
1925 if (implicit
&& implicit_percent
== 0)
1926 fatal (flocp
, _("mixed implicit and normal rules"));
1933 targets
= (char **) xmalloc (5 * sizeof (char *));
1934 target_percents
= (char **) xmalloc (5 * sizeof (char *));
1937 else if (target_idx
== max_targets
- 1)
1940 targets
= (char **) xrealloc ((char *) targets
,
1941 max_targets
* sizeof (char *));
1943 = (char **) xrealloc ((char *) target_percents
,
1944 max_targets
* sizeof (char *));
1946 targets
[target_idx
] = name
;
1947 target_percents
[target_idx
] = implicit_percent
;
1952 /* If there are multiple filenames, copy the chain DEPS
1953 for all but the last one. It is not safe for the same deps
1954 to go in more than one place in the database. */
1955 this = nextf
!= 0 ? copy_dep_chain (deps
) : deps
;
1959 /* If this is an extended static rule:
1960 `targets: target%pattern: dep%pattern; cmds',
1961 translate each dependency pattern into a plain filename
1962 using the target pattern and this target's name. */
1963 if (!pattern_matches (pattern
, pattern_percent
, name
))
1965 /* Give a warning if the rule is meaningless. */
1967 _("target `%s' doesn't match the target pattern"), name
);
1971 /* We use subst_expand to do the work of translating % to $* in
1972 the dependency line. */
1974 if (this != 0 && find_percent (this->name
) != 0)
1977 char *buffer
= variable_expand ("");
1979 o
= subst_expand (buffer
, this->name
, "%", "$*", 1, 2, 0);
1982 this->name
= savestring (buffer
, o
- buffer
);
1983 this->need_2nd_expansion
= 1;
1989 /* Single-colon. Combine these dependencies
1990 with others in file's existing record, if any. */
1991 f
= enter_file (name
);
1993 if (f
->double_colon
)
1995 _("target file `%s' has both : and :: entries"), f
->name
);
1997 /* If CMDS == F->CMDS, this target was listed in this rule
1998 more than once. Just give a warning since this is harmless. */
1999 if (cmds
!= 0 && cmds
== f
->cmds
)
2001 _("target `%s' given more than once in the same rule."),
2004 /* Check for two single-colon entries both with commands.
2005 Check is_target so that we don't lose on files such as .c.o
2006 whose commands were preinitialized. */
2007 else if (cmds
!= 0 && f
->cmds
!= 0 && f
->is_target
)
2009 error (&cmds
->fileinfo
,
2010 _("warning: overriding commands for target `%s'"),
2012 error (&f
->cmds
->fileinfo
,
2013 _("warning: ignoring old commands for target `%s'"),
2019 /* Defining .DEFAULT with no deps or cmds clears it. */
2020 if (f
== default_file
&& this == 0 && cmds
== 0)
2025 /* Defining .SUFFIXES with no dependencies
2026 clears out the list of suffixes. */
2027 if (f
== suffix_file
&& this == 0)
2032 struct dep
*nextd
= d
->next
;
2041 /* Add the file's old deps and the new ones in THIS together. */
2045 struct dep
**d_ptr
= &f
->deps
;
2047 while ((*d_ptr
)->next
!= 0)
2048 d_ptr
= &(*d_ptr
)->next
;
2052 /* This is the rule with commands, so put its deps
2053 last. The rationale behind this is that $< expands
2054 to the first dep in the chain, and commands use $<
2055 expecting to get the dep that rule specifies.
2056 However the second expansion algorithm reverses
2057 the order thus we need to make it last here. */
2059 (*d_ptr
)->next
= this;
2063 /* This is the rule without commands. Put its
2064 dependencies at the end but before dependencies
2065 from the rule with commands (if any). This way
2066 everything appears in makefile order. */
2070 this->next
= *d_ptr
;
2074 (*d_ptr
)->next
= this;
2080 /* This is a hack. I need a way to communicate to snap_deps()
2081 that the last dependency line in this file came with commands
2082 (so that logic in snap_deps() can put it in front and all
2083 this $< -logic works). I cannot simply rely on file->cmds
2084 being not 0 because of the cases like the following:
2090 I am going to temporarily "borrow" UPDATING member in
2091 `struct file' for this. */
2097 /* If this is a static pattern rule, set the file's stem to
2098 the part of its name that matched the `%' in the pattern,
2099 so you can use $* in the commands. */
2102 static char *percent
= "%";
2103 char *buffer
= variable_expand ("");
2104 char *o
= patsubst_expand (buffer
, name
, pattern
, percent
,
2105 pattern_percent
+1, percent
+1);
2106 f
->stem
= savestring (buffer
, o
- buffer
);
2111 /* Double-colon. Make a new record
2112 even if the file already has one. */
2113 f
= lookup_file (name
);
2114 /* Check for both : and :: rules. Check is_target so
2115 we don't lose on default suffix rules or makefiles. */
2116 if (f
!= 0 && f
->is_target
&& !f
->double_colon
)
2118 _("target file `%s' has both : and :: entries"), f
->name
);
2119 f
= enter_file (name
);
2120 /* If there was an existing entry and it was a double-colon
2121 entry, enter_file will have returned a new one, making it the
2122 prev pointer of the old one, and setting its double_colon
2123 pointer to the first one. */
2124 if (f
->double_colon
== 0)
2125 /* This is the first entry for this name, so we must
2126 set its double_colon pointer to itself. */
2127 f
->double_colon
= f
;
2133 /* Free name if not needed further. */
2134 if (f
!= 0 && name
!= f
->name
2135 && (name
< f
->name
|| name
> f
->name
+ strlen (f
->name
)))
2141 /* If this target is a default target, update DEFAULT_GOAL_FILE. */
2142 if (strcmp (*default_goal_name
, name
) == 0
2143 && (default_goal_file
== 0
2144 || strcmp (default_goal_file
->name
, name
) != 0))
2145 default_goal_file
= f
;
2150 targets
[target_idx
] = 0;
2151 target_percents
[target_idx
] = 0;
2152 create_pattern_rule (targets
, target_percents
, two_colon
, deps
, cmds
, 1);
2153 free ((char *) target_percents
);
2157 /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
2158 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
2159 Quoting backslashes are removed from STRING by compacting it into
2160 itself. Returns a pointer to the first unquoted STOPCHAR if there is
2161 one, or nil if there are none. */
2164 find_char_unquote (char *string
, int stop1
, int stop2
, int blank
)
2166 unsigned int string_len
= 0;
2167 register char *p
= string
;
2172 while (*p
!= '\0' && *p
!= stop1
&& *p
!= stop2
2173 && ! isblank ((unsigned char) *p
))
2176 while (*p
!= '\0' && *p
!= stop1
&& *p
!= stop2
)
2179 while (*p
!= '\0' && *p
!= stop1
2180 && ! isblank ((unsigned char) *p
))
2183 while (*p
!= '\0' && *p
!= stop1
)
2189 if (p
> string
&& p
[-1] == '\\')
2191 /* Search for more backslashes. */
2192 register int i
= -2;
2193 while (&p
[i
] >= string
&& p
[i
] == '\\')
2196 /* Only compute the length if really needed. */
2197 if (string_len
== 0)
2198 string_len
= strlen (string
);
2199 /* The number of backslashes is now -I.
2200 Copy P over itself to swallow half of them. */
2201 bcopy (&p
[i
/ 2], &p
[i
], (string_len
- (p
- string
)) - (i
/ 2) + 1);
2204 /* All the backslashes quoted each other; the STOPCHAR was
2208 /* The STOPCHAR was quoted by a backslash. Look for another. */
2211 /* No backslash in sight. */
2215 /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
2219 /* Search PATTERN for an unquoted %. */
2222 find_percent (char *pattern
)
2224 return find_char_unquote (pattern
, '%', 0, 0);
2227 /* Parse a string into a sequence of filenames represented as a
2228 chain of struct nameseq's in reverse order and return that chain.
2230 The string is passed as STRINGP, the address of a string pointer.
2231 The string pointer is updated to point at the first character
2232 not parsed, which either is a null char or equals STOPCHAR.
2234 SIZE is how big to construct chain elements.
2235 This is useful if we want them actually to be other structures
2236 that have room for additional info.
2238 If STRIP is nonzero, strip `./'s off the beginning. */
2241 parse_file_seq (char **stringp
, int stopchar
, unsigned int size
, int strip
)
2243 register struct nameseq
*new = 0;
2244 register struct nameseq
*new1
, *lastnew1
;
2245 register char *p
= *stringp
;
2250 # define VMS_COMMA ','
2252 # define VMS_COMMA 0
2257 /* Skip whitespace; see if any more names are left. */
2264 /* Yes, find end of next name. */
2266 p
= find_char_unquote (q
, stopchar
, VMS_COMMA
, 1);
2268 /* convert comma separated list to space separated */
2273 if (stopchar
== ':' && p
&& *p
== ':'
2274 && !(isspace ((unsigned char)p
[1]) || !p
[1]
2275 || isspace ((unsigned char)p
[-1])))
2277 p
= find_char_unquote (p
+1, stopchar
, VMS_COMMA
, 1);
2280 #ifdef HAVE_DOS_PATHS
2281 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
2282 first colon which isn't followed by a slash or a backslash.
2283 Note that tokens separated by spaces should be treated as separate
2284 tokens since make doesn't allow path names with spaces */
2285 if (stopchar
== ':')
2286 while (p
!= 0 && !isspace ((unsigned char)*p
) &&
2287 (p
[1] == '\\' || p
[1] == '/') && isalpha ((unsigned char)p
[-1]))
2288 p
= find_char_unquote (p
+ 1, stopchar
, VMS_COMMA
, 1);
2295 /* Skip leading `[]'s. */
2296 while (p
- q
> 2 && q
[0] == '[' && q
[1] == ']')
2298 /* Skip leading `./'s. */
2299 while (p
- q
> 2 && q
[0] == '.' && q
[1] == '/')
2302 q
+= 2; /* Skip "./". */
2303 while (q
< p
&& *q
== '/')
2304 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
2308 /* Extract the filename just found, and skip it. */
2311 /* ".///" was stripped to "". */
2316 name
= savestring ("", 0);
2318 name
= savestring ("./", 2);
2323 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need
2324 * to remove this '\' before we can use the filename.
2325 * Savestring called because q may be read-only string constant.
2328 char *qbase
= xstrdup (q
);
2329 char *pbase
= qbase
+ (p
-q
);
2336 if (*q1
== '\\' && *(q1
+1) == ':')
2343 name
= savestring (qbase
, p1
- qbase
);
2347 name
= savestring (q
, p
- q
);
2350 /* Add it to the front of the chain. */
2351 new1
= (struct nameseq
*) xmalloc (size
);
2359 /* Look for multi-word archive references.
2360 They are indicated by a elt ending with an unmatched `)' and
2361 an elt further down the chain (i.e., previous in the file list)
2362 with an unmatched `(' (e.g., "lib(mem"). */
2367 if (new1
->name
[0] != '(' /* Don't catch "(%)" and suchlike. */
2368 && new1
->name
[strlen (new1
->name
) - 1] == ')'
2369 && strchr (new1
->name
, '(') == 0)
2371 /* NEW1 ends with a `)' but does not contain a `('.
2372 Look back for an elt with an opening `(' but no closing `)'. */
2374 struct nameseq
*n
= new1
->next
, *lastn
= new1
;
2376 while (n
!= 0 && (paren
= strchr (n
->name
, '(')) == 0)
2382 /* Ignore something starting with `(', as that cannot actually
2383 be an archive-member reference (and treating it as such
2384 results in an empty file name, which causes much lossage). */
2385 && n
->name
[0] != '(')
2387 /* N is the first element in the archive group.
2388 Its name looks like "lib(mem" (with no closing `)'). */
2392 /* Copy "lib(" into LIBNAME. */
2394 libname
= (char *) alloca (paren
- n
->name
+ 1);
2395 bcopy (n
->name
, libname
, paren
- n
->name
);
2396 libname
[paren
- n
->name
] = '\0';
2400 /* N was just "lib(", part of something like "lib( a b)".
2401 Edit it out of the chain and free its storage. */
2402 lastn
->next
= n
->next
;
2405 /* LASTN->next is the new stopping elt for the loop below. */
2410 /* Replace N's name with the full archive reference. */
2411 name
= concat (libname
, paren
, ")");
2416 if (new1
->name
[1] == '\0')
2418 /* NEW1 is just ")", part of something like "lib(a b )".
2419 Omit it from the chain and free its storage. */
2423 lastnew1
->next
= new1
->next
;
2427 free ((char *) lastn
);
2431 /* Replace also NEW1->name, which already has closing `)'. */
2432 name
= concat (libname
, new1
->name
, "");
2438 /* Trace back from NEW1 (the end of the list) until N
2439 (the beginning of the list), rewriting each name
2440 with the full archive reference. */
2444 name
= concat (libname
, new1
->name
, ")");
2453 /* No frobnication happening. Just step down the list. */
2470 /* Find the next line of text in an eval buffer, combining continuation lines
2472 Return the number of actual lines read (> 1 if continuation lines).
2473 Returns -1 if there's nothing left in the buffer.
2475 After this function, ebuf->buffer points to the first character of the
2479 /* Read a line of text from a STRING.
2480 Since we aren't really reading from a file, don't bother with linenumbers.
2483 static unsigned long
2484 readstring (struct ebuffer
*ebuf
)
2488 /* If there is nothing left in this buffer, return 0. */
2489 if (ebuf
->bufnext
>= ebuf
->bufstart
+ ebuf
->size
)
2492 /* Set up a new starting point for the buffer, and find the end of the
2493 next logical line (taking into account backslash/newline pairs). */
2495 eol
= ebuf
->buffer
= ebuf
->bufnext
;
2503 /* Find the next newline. At EOS, stop. */
2504 eol
= p
= strchr (eol
, '\n');
2507 ebuf
->bufnext
= ebuf
->bufstart
+ ebuf
->size
+ 1;
2511 /* Found a newline; if it's escaped continue; else we're done. */
2512 while (p
> bol
&& *(--p
) == '\\')
2513 backslash
= !backslash
;
2519 /* Overwrite the newline char. */
2521 ebuf
->bufnext
= eol
+1;
2527 readline (struct ebuffer
*ebuf
)
2534 /* The behaviors between string and stream buffers are different enough to
2535 warrant different functions. Do the Right Thing. */
2538 return readstring (ebuf
);
2540 /* When reading from a file, we always start over at the beginning of the
2541 buffer for each new line. */
2543 p
= start
= ebuf
->bufstart
;
2544 end
= p
+ ebuf
->size
;
2547 while (fgets (p
, end
- p
, ebuf
->fp
) != 0)
2556 /* This only happens when the first thing on the line is a '\0'.
2557 It is a pretty hopeless case, but (wonder of wonders) Athena
2558 lossage strikes again! (xmkmf puts NULs in its makefiles.)
2559 There is nothing really to be done; we synthesize a newline so
2560 the following line doesn't appear to be part of this line. */
2562 _("warning: NUL character seen; rest of line ignored"));
2567 /* Jump past the text we just read. */
2570 /* If the last char isn't a newline, the whole line didn't fit into the
2571 buffer. Get some more buffer and try again. */
2575 /* We got a newline, so add one to the count of lines. */
2578 #if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
2579 /* Check to see if the line was really ended with CRLF; if so ignore
2581 if ((p
- start
) > 1 && p
[-2] == '\r')
2589 for (p2
= p
- 2; p2
>= start
; --p2
)
2593 backslash
= !backslash
;
2602 /* It was a backslash/newline combo. If we have more space, read
2607 /* We need more space at the end of our buffer, so realloc it.
2608 Make sure to preserve the current offset of p. */
2611 unsigned long off
= p
- start
;
2613 start
= ebuf
->buffer
= ebuf
->bufstart
= (char *) xrealloc (start
,
2616 end
= start
+ ebuf
->size
;
2621 if (ferror (ebuf
->fp
))
2622 pfatal_with_name (ebuf
->floc
.filenm
);
2624 /* If we found some lines, return how many.
2625 If we didn't, but we did find _something_, that indicates we read the last
2626 line of a file with no final newline; return 1.
2627 If we read nothing, we're at EOF; return -1. */
2629 return nlines
? nlines
: p
== ebuf
->bufstart
? -1 : 1;
2632 /* Parse the next "makefile word" from the input buffer, and return info
2635 A "makefile word" is one of:
2637 w_bogus Should never happen
2639 w_static A static word; cannot be expanded
2640 w_variable A word containing one or more variables/functions
2642 w_dcolon A double-colon
2643 w_semicolon A semicolon
2644 w_varassign A variable assignment operator (=, :=, +=, or ?=)
2646 Note that this function is only used when reading certain parts of the
2647 makefile. Don't use it where special rules hold sway (RHS of a variable,
2648 in a command list, etc.) */
2650 static enum make_word_type
2651 get_next_mword (char *buffer
, char *delim
, char **startp
, unsigned int *length
)
2653 enum make_word_type wtype
= w_bogus
;
2654 char *p
= buffer
, *beg
;
2657 /* Skip any leading whitespace. */
2658 while (isblank ((unsigned char)*p
))
2670 wtype
= w_semicolon
;
2674 wtype
= w_varassign
;
2688 wtype
= w_varassign
;
2698 wtype
= w_varassign
;
2703 if (delim
&& strchr (delim
, c
))
2708 /* Did we find something? If so, return now. */
2709 if (wtype
!= w_bogus
)
2712 /* This is some non-operator word. A word consists of the longest
2713 string of characters that doesn't contain whitespace, one of [:=#],
2714 or [?+]=, or one of the chars in the DELIM string. */
2716 /* We start out assuming a static word; if we see a variable we'll
2717 adjust our assumptions then. */
2720 /* We already found the first value of "c", above. */
2735 #ifdef HAVE_DOS_PATHS
2736 /* A word CAN include a colon in its drive spec. The drive
2737 spec is allowed either at the beginning of a word, or as part
2738 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
2740 && (*p
== '/' || *p
== '\\') && isalpha ((unsigned char)p
[-2])
2741 && (p
- beg
== 2 || p
[-3] == '(')))
2750 /* This is a variable reference, so note that it's expandable.
2751 Then read it to the matching close paren. */
2759 /* This is a single-letter variable reference. */
2762 for (count
=0; *p
!= '\0'; ++p
)
2766 else if (*p
== closeparen
&& --count
< 0)
2793 if (delim
&& strchr (delim
, c
))
2811 /* Construct the list of include directories
2812 from the arguments and the default list. */
2815 construct_include_path (char **arg_dirs
)
2817 register unsigned int i
;
2818 #ifdef VAXC /* just don't ask ... */
2823 /* Table to hold the dirs. */
2825 register unsigned int defsize
= (sizeof (default_include_directories
)
2826 / sizeof (default_include_directories
[0]));
2827 register unsigned int max
= 5;
2828 register char **dirs
= (char **) xmalloc ((5 + defsize
) * sizeof (char *));
2829 register unsigned int idx
= 0;
2835 /* First consider any dirs specified with -I switches.
2836 Ignore dirs that don't exist. */
2839 while (*arg_dirs
!= 0)
2841 char *dir
= *arg_dirs
++;
2846 char *expanded
= tilde_expand (dir
);
2851 EINTRLOOP (e
, stat (dir
, &stbuf
));
2852 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2858 xrealloc ((char *) dirs
, (max
+ defsize
) * sizeof (char *));
2862 else if (dir
!= arg_dirs
[-1])
2866 /* Now add at the end the standard default dirs. */
2870 /* The environment variable $DJDIR holds the root of the
2871 DJGPP directory tree; add ${DJDIR}/include. */
2872 struct variable
*djdir
= lookup_variable ("DJDIR", 5);
2876 char *defdir
= (char *) xmalloc (strlen (djdir
->value
) + 8 + 1);
2878 strcat (strcpy (defdir
, djdir
->value
), "/include");
2879 dirs
[idx
++] = defdir
;
2884 for (i
= 0; default_include_directories
[i
] != 0; ++i
)
2888 EINTRLOOP (e
, stat (default_include_directories
[i
], &stbuf
));
2889 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2890 dirs
[idx
++] = default_include_directories
[i
];
2895 /* Now compute the maximum length of any name in it. */
2898 for (i
= 0; i
< idx
; ++i
)
2900 unsigned int len
= strlen (dirs
[i
]);
2901 /* If dir name is written with a trailing slash, discard it. */
2902 if (dirs
[i
][len
- 1] == '/')
2903 /* We can't just clobber a null in because it may have come from
2904 a literal string and literal strings may not be writable. */
2905 dirs
[i
] = savestring (dirs
[i
], len
- 1);
2906 if (len
> max_incl_len
)
2910 include_directories
= dirs
;
2913 /* Expand ~ or ~USER at the beginning of NAME.
2914 Return a newly malloc'd string or 0. */
2917 tilde_expand (char *name
)
2920 if (name
[1] == '/' || name
[1] == '\0')
2922 extern char *getenv ();
2927 /* Turn off --warn-undefined-variables while we expand HOME. */
2928 int save
= warn_undefined_variables_flag
;
2929 warn_undefined_variables_flag
= 0;
2931 home_dir
= allocated_variable_expand ("$(HOME)");
2933 warn_undefined_variables_flag
= save
;
2936 is_variable
= home_dir
[0] != '\0';
2940 home_dir
= getenv ("HOME");
2942 #if !defined(_AMIGA) && !defined(WINDOWS32)
2943 if (home_dir
== 0 || home_dir
[0] == '\0')
2945 extern char *getlogin ();
2946 char *logname
= getlogin ();
2950 struct passwd
*p
= getpwnam (logname
);
2952 home_dir
= p
->pw_dir
;
2955 #endif /* !AMIGA && !WINDOWS32 */
2958 char *new = concat (home_dir
, "", name
+ 1);
2964 #if !defined(_AMIGA) && !defined(WINDOWS32)
2967 struct passwd
*pwent
;
2968 char *userend
= strchr (name
+ 1, '/');
2971 pwent
= getpwnam (name
+ 1);
2975 return xstrdup (pwent
->pw_dir
);
2977 return concat (pwent
->pw_dir
, "/", userend
+ 1);
2979 else if (userend
!= 0)
2982 #endif /* !AMIGA && !WINDOWS32 */
2987 /* Given a chain of struct nameseq's describing a sequence of filenames,
2988 in reverse of the intended order, return a new chain describing the
2989 result of globbing the filenames. The new chain is in forward order.
2990 The links of the old chain are freed or used in the new chain.
2991 Likewise for the names in the old chain.
2993 SIZE is how big to construct chain elements.
2994 This is useful if we want them actually to be other structures
2995 that have room for additional info. */
2998 multi_glob (struct nameseq
*chain
, unsigned int size
)
3000 extern void dir_setup_glob ();
3001 register struct nameseq
*new = 0;
3002 register struct nameseq
*old
;
3003 struct nameseq
*nexto
;
3006 dir_setup_glob (&gl
);
3008 for (old
= chain
; old
!= 0; old
= nexto
)
3016 if (old
->name
[0] == '~')
3018 char *newname
= tilde_expand (old
->name
);
3022 old
->name
= newname
;
3027 if (ar_name (old
->name
))
3029 /* OLD->name is an archive member reference.
3030 Replace it with the archive file name,
3031 and save the member name in MEMNAME.
3032 We will glob on the archive name and then
3033 reattach MEMNAME later. */
3035 ar_parse_name (old
->name
, &arname
, &memname
);
3041 #endif /* !NO_ARCHIVES */
3043 switch (glob (old
->name
, GLOB_NOCHECK
|GLOB_ALTDIRFUNC
, NULL
, &gl
))
3045 case 0: /* Success. */
3047 register int i
= gl
.gl_pathc
;
3053 /* Try to glob on MEMNAME within the archive. */
3054 struct nameseq
*found
3055 = ar_glob (gl
.gl_pathv
[i
], memname
, size
);
3058 /* No matches. Use MEMNAME as-is. */
3059 unsigned int alen
= strlen (gl
.gl_pathv
[i
]);
3060 unsigned int mlen
= strlen (memname
);
3062 = (struct nameseq
*) xmalloc (size
);
3063 if (size
> sizeof (struct nameseq
))
3064 bzero (((char *) elt
) + sizeof (struct nameseq
),
3065 size
- sizeof (struct nameseq
));
3066 elt
->name
= (char *) xmalloc (alen
+ 1 + mlen
+ 2);
3067 bcopy (gl
.gl_pathv
[i
], elt
->name
, alen
);
3068 elt
->name
[alen
] = '(';
3069 bcopy (memname
, &elt
->name
[alen
+ 1], mlen
);
3070 elt
->name
[alen
+ 1 + mlen
] = ')';
3071 elt
->name
[alen
+ 1 + mlen
+ 1] = '\0';
3077 /* Find the end of the FOUND chain. */
3078 struct nameseq
*f
= found
;
3079 while (f
->next
!= 0)
3082 /* Attach the chain being built to the end of the FOUND
3083 chain, and make FOUND the new NEW chain. */
3091 #endif /* !NO_ARCHIVES */
3093 struct nameseq
*elt
= (struct nameseq
*) xmalloc (size
);
3094 if (size
> sizeof (struct nameseq
))
3095 bzero (((char *) elt
) + sizeof (struct nameseq
),
3096 size
- sizeof (struct nameseq
));
3097 elt
->name
= xstrdup (gl
.gl_pathv
[i
]);
3109 fatal (NILF
, _("virtual memory exhausted"));