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 interepreting? */
82 char *seen_else
; /* Have we already seen an `else'? */
85 static struct conditionals toplevel_conditionals
;
86 static struct conditionals
*conditionals
= &toplevel_conditionals
;
89 /* Default directories to search for include files in */
91 static char *default_include_directories
[] =
93 #if defined(WINDOWS32) && !defined(INCLUDEDIR)
95 * This completely up to the user when they install MSVC or other packages.
96 * This is defined as a placeholder.
98 #define INCLUDEDIR "."
103 "/usr/local/include",
109 /* List of directories to search for include files in */
111 static char **include_directories
;
113 /* Maximum length of an element of the above. */
115 static unsigned int max_incl_len
;
117 /* The filename and pointer to line number of the
118 makefile currently being read in. */
120 const struct floc
*reading_file
= 0;
122 /* The chain of makefiles read by read_makefile. */
124 static struct dep
*read_makefiles
= 0;
126 static int eval_makefile
PARAMS ((char *filename
, int flags
));
127 static int eval
PARAMS ((struct ebuffer
*buffer
, int flags
));
129 static long readline
PARAMS ((struct ebuffer
*ebuf
));
130 static void do_define
PARAMS ((char *name
, unsigned int namelen
,
131 enum variable_origin origin
,
132 struct ebuffer
*ebuf
));
133 static int conditional_line
PARAMS ((char *line
, const struct floc
*flocp
));
134 static void record_files
PARAMS ((struct nameseq
*filenames
, char *pattern
, char *pattern_percent
,
135 struct dep
*deps
, unsigned int cmds_started
, char *commands
,
136 unsigned int commands_idx
, int two_colon
,
138 const struct floc
*flocp
, int set_default
));
139 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 /* Tell update_goal_chain to bail out as soon as this file is
259 made, and main not to die if we can't make this file. */
260 d
->changed
= RM_DONTCARE
;
272 return read_makefiles
;
275 /* Install a new conditional and return the previous one. */
277 static struct conditionals
*
278 install_conditionals (struct conditionals
*new)
280 struct conditionals
*save
= conditionals
;
282 bzero ((char *) new, sizeof (*new));
288 /* Free the current conditionals and reinstate a saved one. */
291 restore_conditionals (struct conditionals
*saved
)
293 /* Free any space allocated by conditional_line. */
294 if (conditionals
->ignoring
)
295 free (conditionals
->ignoring
);
296 if (conditionals
->seen_else
)
297 free (conditionals
->seen_else
);
300 conditionals
= saved
;
304 eval_makefile (char *filename
, int flags
)
308 const struct floc
*curfile
;
312 ebuf
.floc
.filenm
= filename
;
313 ebuf
.floc
.lineno
= 1;
315 if (ISDB (DB_VERBOSE
))
317 printf (_("Reading makefile `%s'"), filename
);
318 if (flags
& RM_NO_DEFAULT_GOAL
)
319 printf (_(" (no default goal)"));
320 if (flags
& RM_INCLUDED
)
321 printf (_(" (search path)"));
322 if (flags
& RM_DONTCARE
)
323 printf (_(" (don't care)"));
324 if (flags
& RM_NO_TILDE
)
325 printf (_(" (no ~ expansion)"));
329 /* First, get a stream to read. */
331 /* Expand ~ in FILENAME unless it came from `include',
332 in which case it was already done. */
333 if (!(flags
& RM_NO_TILDE
) && filename
[0] == '~')
335 char *expanded
= tilde_expand (filename
);
340 ebuf
.fp
= fopen (filename
, "r");
341 /* Save the error code so we print the right message later. */
342 makefile_errno
= errno
;
344 /* If the makefile wasn't found and it's either a makefile from
345 the `MAKEFILES' variable or an included makefile,
346 search the included makefile search path for this makefile. */
347 if (ebuf
.fp
== 0 && (flags
& RM_INCLUDED
) && *filename
!= '/')
349 register unsigned int i
;
350 for (i
= 0; include_directories
[i
] != 0; ++i
)
352 char *name
= concat (include_directories
[i
], "/", filename
);
353 ebuf
.fp
= fopen (name
, "r");
364 /* Add FILENAME to the chain of read makefiles. */
365 deps
= (struct dep
*) xmalloc (sizeof (struct dep
));
366 deps
->next
= read_makefiles
;
367 read_makefiles
= deps
;
369 deps
->file
= lookup_file (filename
);
372 deps
->file
= enter_file (xstrdup (filename
));
373 if (flags
& RM_DONTCARE
)
374 deps
->file
->dontcare
= 1;
376 if (filename
!= ebuf
.floc
.filenm
)
378 filename
= deps
->file
->name
;
379 deps
->changed
= flags
;
380 deps
->ignore_mtime
= 0;
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
);
416 eval_buffer (char *buffer
)
419 struct conditionals
*saved
;
420 struct conditionals
new;
421 const struct floc
*curfile
;
424 /* Evaluate the buffer */
426 ebuf
.size
= strlen (buffer
);
427 ebuf
.buffer
= ebuf
.bufnext
= ebuf
.bufstart
= buffer
;
430 ebuf
.floc
= *reading_file
;
432 curfile
= reading_file
;
433 reading_file
= &ebuf
.floc
;
435 saved
= install_conditionals (&new);
439 restore_conditionals (saved
);
441 reading_file
= curfile
;
447 /* Read file FILENAME as a makefile and add its contents to the data base.
449 SET_DEFAULT is true if we are allowed to set the default goal. */
453 eval (struct ebuffer
*ebuf
, int set_default
)
456 unsigned int collapsed_length
= 0;
457 unsigned int commands_len
= 200;
459 unsigned int commands_idx
= 0;
460 unsigned int cmds_started
, tgts_started
;
461 int ignoring
= 0, in_ignored_define
= 0;
462 int no_targets
= 0; /* Set when reading a rule without targets. */
463 int have_sysv_atvar
= 0;
464 struct nameseq
*filenames
= 0;
465 struct dep
*deps
= 0;
468 char *pattern
= 0, *pattern_percent
;
472 #define record_waiting_files() \
475 if (filenames != 0) \
477 fi.lineno = tgts_started; \
478 record_files (filenames, pattern, pattern_percent, deps, \
479 cmds_started, commands, commands_idx, two_colon, \
480 have_sysv_atvar, &fi, set_default); \
485 if (pattern) { free(pattern); pattern = 0; } \
489 cmds_started
= tgts_started
= 1;
491 fstart
= &ebuf
->floc
;
492 fi
.filenm
= ebuf
->floc
.filenm
;
494 /* Loop over lines in the file.
495 The strategy is to accumulate target names in FILENAMES, dependencies
496 in DEPS and commands in COMMANDS. These are used to define a rule
497 when the start of the next rule (or eof) is encountered.
499 When you see a "continue" in the loop below, that means we are moving on
500 to the next line _without_ ending any rule that we happen to be working
501 with at the moment. If you see a "goto rule_complete", then the
502 statement we just parsed also finishes the previous rule. */
504 commands
= xmalloc (200);
514 /* Grab the next line to be evaluated */
515 ebuf
->floc
.lineno
+= nlines
;
516 nlines
= readline (ebuf
);
518 /* If there is nothing left to eval, we're done. */
522 /* If this line is empty, skip it. */
527 linelen
= strlen (line
);
529 /* Check for a shell command line first.
530 If it is not one, we can stop treating tab specially. */
534 /* Ignore the commands in a rule with no targets. */
537 /* If there is no preceding rule line, don't treat this line
538 as a command, even though it begins with a tab character.
539 SunOS 4 make appears to behave this way. */
544 /* Yep, this is a shell command, and we don't care. */
547 /* Append this command line to the line being accumulated. */
548 if (commands_idx
== 0)
549 cmds_started
= ebuf
->floc
.lineno
;
551 if (linelen
+ 1 + commands_idx
> commands_len
)
553 commands_len
= (linelen
+ 1 + commands_idx
) * 2;
554 commands
= xrealloc (commands
, commands_len
);
556 bcopy (line
, &commands
[commands_idx
], linelen
);
557 commands_idx
+= linelen
;
558 commands
[commands_idx
++] = '\n';
564 /* This line is not a shell command line. Don't worry about tabs.
565 Get more space if we need it; we don't need to preserve the current
566 contents of the buffer. */
568 if (collapsed_length
< linelen
+1)
570 collapsed_length
= linelen
+1;
572 free ((char *)collapsed
);
573 collapsed
= (char *) xmalloc (collapsed_length
);
575 strcpy (collapsed
, line
);
576 /* Collapse continuation lines. */
577 collapse_continuations (collapsed
);
578 remove_comments (collapsed
);
580 /* Compare a word, both length and contents. */
581 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
583 while (isspace ((unsigned char)*p
))
587 /* This line is completely empty--ignore it. */
590 /* Find the end of the first token. Note we don't need to worry about
591 * ":" here since we compare tokens by length (so "export" will never
592 * be equal to "export:").
594 for (p2
= p
+1; *p2
!= '\0' && !isspace ((unsigned char)*p2
); ++p2
)
598 /* Find the start of the second token. If it looks like a target or
599 variable definition it can't be a preprocessor token so skip
600 them--this allows variables/targets named `ifdef', `export', etc. */
601 while (isspace ((unsigned char)*p2
))
604 if ((p2
[0] == ':' || p2
[0] == '+' || p2
[0] == '=') && p2
[1] == '\0')
606 /* It can't be a preprocessor token so skip it if we're ignoring */
610 goto skip_conditionals
;
613 /* We must first check for conditional and `define' directives before
614 ignoring anything, since they control what we will do with
617 if (!in_ignored_define
618 && (word1eq ("ifdef") || word1eq ("ifndef")
619 || word1eq ("ifeq") || word1eq ("ifneq")
620 || word1eq ("else") || word1eq ("endif")))
622 int i
= conditional_line (p
, fstart
);
624 fatal (fstart
, _("invalid syntax in conditional"));
630 if (word1eq ("endef"))
632 if (!in_ignored_define
)
633 fatal (fstart
, _("extraneous `endef'"));
634 in_ignored_define
= 0;
638 if (word1eq ("define"))
641 in_ignored_define
= 1;
645 fatal (fstart
, _("empty variable name"));
647 /* Let the variable name be the whole rest of the line,
648 with trailing blanks stripped (comments have already been
649 removed), so it could be a complex variable/function
650 reference that might contain blanks. */
651 p
= strchr (p2
, '\0');
652 while (isblank ((unsigned char)p
[-1]))
654 do_define (p2
, p
- p2
, o_file
, ebuf
);
659 if (word1eq ("override"))
662 error (fstart
, _("empty `override' directive"));
664 if (strneq (p2
, "define", 6)
665 && (isblank ((unsigned char)p2
[6]) || p2
[6] == '\0'))
668 in_ignored_define
= 1;
671 p2
= next_token (p2
+ 6);
673 fatal (fstart
, _("empty variable name"));
675 /* Let the variable name be the whole rest of the line,
676 with trailing blanks stripped (comments have already been
677 removed), so it could be a complex variable/function
678 reference that might contain blanks. */
679 p
= strchr (p2
, '\0');
680 while (isblank ((unsigned char)p
[-1]))
682 do_define (p2
, p
- p2
, o_override
, ebuf
);
686 && !try_variable_definition (fstart
, p2
, o_override
, 0))
687 error (fstart
, _("invalid `override' directive"));
693 /* Ignore the line. We continue here so conditionals
694 can appear in the middle of a rule. */
697 if (word1eq ("export"))
699 /* 'export' by itself causes everything to be exported. */
701 export_all_variables
= 1;
706 v
= try_variable_definition (fstart
, p2
, o_file
, 0);
708 v
->export
= v_export
;
714 /* Expand the line so we can use indirect and constructed
715 variable names in an export command. */
716 p2
= ap
= allocated_variable_expand (p2
);
718 for (p
= find_next_token (&p2
, &len
); p
!= 0;
719 p
= find_next_token (&p2
, &len
))
721 v
= lookup_variable (p
, len
);
723 v
= define_variable_loc (p
, len
, "", o_file
, 0,
725 v
->export
= v_export
;
734 if (word1eq ("unexport"))
737 export_all_variables
= 0;
744 /* Expand the line so we can use indirect and constructed
745 variable names in an unexport command. */
746 p2
= ap
= allocated_variable_expand (p2
);
748 for (p
= find_next_token (&p2
, &len
); p
!= 0;
749 p
= find_next_token (&p2
, &len
))
751 v
= lookup_variable (p
, len
);
753 v
= define_variable_loc (p
, len
, "", o_file
, 0, fstart
);
755 v
->export
= v_noexport
;
764 if (word1eq ("vpath"))
768 p2
= variable_expand (p2
);
769 p
= find_next_token (&p2
, &len
);
772 pattern
= savestring (p
, len
);
773 p
= find_next_token (&p2
, &len
);
774 /* No searchpath means remove all previous
775 selective VPATH's with the same pattern. */
778 /* No pattern means remove all previous selective VPATH's. */
780 construct_vpath_list (pattern
, p
);
787 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
789 /* We have found an `include' line specifying a nested
790 makefile to be read at this point. */
791 struct conditionals
*save
;
792 struct conditionals new_conditionals
;
793 struct nameseq
*files
;
794 /* "-include" (vs "include") says no error if the file does not
795 exist. "sinclude" is an alias for this from SGI. */
796 int noerror
= (p
[0] != 'i');
798 p
= allocated_variable_expand (p2
);
802 _("no file name for `%sinclude'"), noerror
? "-" : "");
806 /* Parse the list of file names. */
808 files
= multi_glob (parse_file_seq (&p2
, '\0',
809 sizeof (struct nameseq
),
811 sizeof (struct nameseq
));
814 /* Save the state of conditionals and start
815 the included makefile with a clean slate. */
816 save
= install_conditionals (&new_conditionals
);
818 /* Record the rules that are waiting so they will determine
819 the default goal before those in the included makefile. */
820 record_waiting_files ();
822 /* Read each included makefile. */
825 struct nameseq
*next
= files
->next
;
826 char *name
= files
->name
;
829 free ((char *)files
);
832 r
= eval_makefile (name
, (RM_INCLUDED
| RM_NO_TILDE
833 | (noerror
? RM_DONTCARE
: 0)));
837 error (fstart
, "%s: %s", name
, strerror (errno
));
842 /* Restore conditional state. */
843 restore_conditionals (save
);
848 if (try_variable_definition (fstart
, p
, o_file
, 0))
849 /* This line has been dealt with. */
854 p
= collapsed
; /* Ignore comments, etc. */
855 while (isblank ((unsigned char)*p
))
858 /* The line is completely blank; that is harmless. */
861 /* This line starts with a tab but was not caught above
862 because there was no preceding target, and the line
863 might have been usable as a variable definition.
864 But now we know it is definitely lossage. */
865 fatal(fstart
, _("commands commence before first target"));
868 /* This line describes some target files. This is complicated by
869 the existence of target-specific variables, because we can't
870 expand the entire line until we know if we have one or not. So
871 we expand the line word by word until we find the first `:',
872 then check to see if it's a target-specific variable.
874 In this algorithm, `lb_next' will point to the beginning of the
875 unexpanded parts of the input buffer, while `p2' points to the
876 parts of the expanded buffer we haven't searched yet. */
879 enum make_word_type wtype
;
880 enum variable_origin v_origin
;
882 char *cmdleft
, *semip
, *lb_next
;
883 unsigned int len
, plen
= 0;
886 /* Record the previous rule. */
888 record_waiting_files ();
889 tgts_started
= fstart
->lineno
;
891 /* Search the line for an unquoted ; that is not after an
893 cmdleft
= find_char_unquote (line
, ';', '#', 0);
894 if (cmdleft
!= 0 && *cmdleft
== '#')
896 /* We found a comment before a semicolon. */
900 else if (cmdleft
!= 0)
901 /* Found one. Cut the line short there before expanding it. */
905 collapse_continuations (line
);
907 /* We can't expand the entire line, since if it's a per-target
908 variable we don't want to expand it. So, walk from the
909 beginning, expanding as we go, and looking for "interesting"
910 chars. The first word is always expandable. */
911 wtype
= get_next_mword(line
, NULL
, &lb_next
, &len
);
916 fatal(fstart
, _("missing rule before commands"));
917 /* This line contained something but turned out to be nothing
918 but whitespace (a comment?). */
923 /* We accept and ignore rules without targets for
924 compatibility with SunOS 4 make. */
932 p2
= variable_expand_string(NULL
, lb_next
, len
);
938 /* Look for a semicolon in the expanded line. */
939 cmdleft
= find_char_unquote (p2
, ';', 0, 0);
943 unsigned long p2_off
= p2
- variable_buffer
;
944 unsigned long cmd_off
= cmdleft
- variable_buffer
;
945 char *pend
= p2
+ strlen(p2
);
947 /* Append any remnants of lb, then cut the line short
951 /* One school of thought says that you shouldn't expand
952 here, but merely copy, since now you're beyond a ";"
953 and into a command script. However, the old parser
954 expanded the whole line, so we continue that for
955 backwards-compatiblity. Also, it wouldn't be
956 entirely consistent, since we do an unconditional
957 expand below once we know we don't have a
958 target-specific variable. */
959 (void)variable_expand_string(pend
, lb_next
, (long)-1);
960 lb_next
+= strlen(lb_next
);
961 p2
= variable_buffer
+ p2_off
;
962 cmdleft
= variable_buffer
+ cmd_off
+ 1;
966 colonp
= find_char_unquote(p2
, ':', 0, 0);
967 #ifdef HAVE_DOS_PATHS
968 /* The drive spec brain-damage strikes again... */
969 /* Note that the only separators of targets in this context
970 are whitespace and a left paren. If others are possible,
971 they should be added to the string in the call to index. */
972 while (colonp
&& (colonp
[1] == '/' || colonp
[1] == '\\') &&
973 colonp
> p2
&& isalpha ((unsigned char)colonp
[-1]) &&
974 (colonp
== p2
+ 1 || strchr (" \t(", colonp
[-2]) != 0))
975 colonp
= find_char_unquote(colonp
+ 1, ':', 0, 0);
980 wtype
= get_next_mword(lb_next
, NULL
, &lb_next
, &len
);
986 p2
= variable_expand_string(p2
, lb_next
, len
);
987 /* We don't need to worry about cmdleft here, because if it was
988 found in the variable_buffer the entire buffer has already
989 been expanded... we'll never get here. */
992 p2
= next_token (variable_buffer
);
994 /* If the word we're looking at is EOL, see if there's _anything_
995 on the line. If not, a variable expanded to nothing, so ignore
996 it. If so, we can't parse this line so punt. */
1000 /* There's no need to be ivory-tower about this: check for
1001 one of the most common bugs found in makefiles... */
1002 fatal (fstart
, _("missing separator%s"),
1003 !strneq(line
, " ", 8) ? ""
1004 : _(" (did you mean TAB instead of 8 spaces?)"));
1008 /* Make the colon the end-of-string so we know where to stop
1009 looking for targets. */
1011 filenames
= multi_glob (parse_file_seq (&p2
, '\0',
1012 sizeof (struct nameseq
),
1014 sizeof (struct nameseq
));
1019 /* We accept and ignore rules without targets for
1020 compatibility with SunOS 4 make. */
1024 /* This should never be possible; we handled it above. */
1025 assert (*p2
!= '\0');
1028 /* Is this a one-colon or two-colon entry? */
1029 two_colon
= *p2
== ':';
1033 /* Test to see if it's a target-specific variable. Copy the rest
1034 of the buffer over, possibly temporarily (we'll expand it later
1035 if it's not a target-specific variable). PLEN saves the length
1036 of the unparsed section of p2, for later. */
1037 if (*lb_next
!= '\0')
1039 unsigned int l
= p
- variable_buffer
;
1040 unsigned int l2
= p2
- variable_buffer
;
1042 (void) variable_buffer_output (p2
+plen
,
1043 lb_next
, strlen (lb_next
)+1);
1044 p
= variable_buffer
+ l
;
1045 p2
= variable_buffer
+ l2
;
1048 /* See if it's an "override" or "export" keyword; if so see if what
1049 comes after it looks like a variable definition. */
1051 wtype
= get_next_mword (p2
, NULL
, &p
, &len
);
1055 if (wtype
== w_static
)
1056 if (word1eq ("override"))
1058 v_origin
= o_override
;
1059 wtype
= get_next_mword (p
+len
, NULL
, &p
, &len
);
1061 else if (word1eq ("export"))
1064 wtype
= get_next_mword (p
+len
, NULL
, &p
, &len
);
1068 wtype
= get_next_mword (p
+len
, NULL
, NULL
, NULL
);
1070 if (wtype
== w_varassign
)
1072 /* If there was a semicolon found, add it back, plus anything
1076 unsigned int l
= p
- variable_buffer
;
1078 variable_buffer_output (p2
+ strlen (p2
),
1079 semip
, strlen (semip
)+1);
1080 p
= variable_buffer
+ l
;
1082 record_target_var (filenames
, p
, two_colon
, v_origin
, exported
,
1088 /* This is a normal target, _not_ a target-specific variable.
1089 Unquote any = in the dependency list. */
1090 find_char_unquote (lb_next
, '=', 0, 0);
1092 /* We have some targets, so don't ignore the following commands. */
1095 /* Expand the dependencies, etc. */
1096 if (*lb_next
!= '\0')
1098 unsigned int l
= p2
- variable_buffer
;
1099 (void) variable_expand_string (p2
+ plen
, lb_next
, (long)-1);
1100 p2
= variable_buffer
+ l
;
1102 /* Look for a semicolon in the expanded line. */
1105 cmdleft
= find_char_unquote (p2
, ';', 0, 0);
1107 *(cmdleft
++) = '\0';
1111 /* Do any of the prerequisites appear to have $@ etc.? */
1112 have_sysv_atvar
= 0;
1113 if (!posix_pedantic
)
1114 for (p
= strchr (p2
, '$'); p
!= 0; p
= strchr (p
+1, '$'))
1115 if (p
[1] == '@' || ((p
[1] == '(' || p
[1] == '{') && p
[2] == '@'))
1117 have_sysv_atvar
= 1;
1121 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
1122 p
= strchr (p2
, ':');
1123 while (p
!= 0 && p
[-1] == '\\')
1125 register char *q
= &p
[-1];
1126 register int backslash
= 0;
1127 while (*q
-- == '\\')
1128 backslash
= !backslash
;
1130 p
= strchr (p
+ 1, ':');
1135 /* Here, the situation is quite complicated. Let's have a look
1136 at a couple of targets:
1144 The rule is that it's only a target, if there are TWO :'s
1145 OR a space around the :.
1147 if (p
&& !(isspace ((unsigned char)p
[1]) || !p
[1]
1148 || isspace ((unsigned char)p
[-1])))
1151 #ifdef HAVE_DOS_PATHS
1157 /* For DOS-style paths, skip a "C:\..." or a "C:/..." */
1158 if (p
!= 0 && (p
[1] == '\\' || p
[1] == '/') &&
1159 isalpha ((unsigned char)p
[-1]) &&
1160 (p
== p2
+ 1 || strchr (" \t:(", p
[-2]) != 0)) {
1161 p
= strchr (p
+ 1, ':');
1164 } while (check_again
);
1169 struct nameseq
*target
;
1170 target
= parse_file_seq (&p2
, ':', sizeof (struct nameseq
), 1);
1173 fatal (fstart
, _("missing target pattern"));
1174 else if (target
->next
!= 0)
1175 fatal (fstart
, _("multiple target patterns"));
1176 pattern
= target
->name
;
1177 pattern_percent
= find_percent (pattern
);
1178 if (pattern_percent
== 0)
1179 fatal (fstart
, _("target pattern contains no `%%'"));
1180 free((char *)target
);
1185 /* Parse the dependencies. */
1186 deps
= (struct dep
*)
1187 multi_glob (parse_file_seq (&p2
, '|', sizeof (struct dep
), 1),
1188 sizeof (struct dep
));
1191 /* Files that follow '|' are special prerequisites that
1192 need only exist in order to satisfy the dependency.
1193 Their modification times are irrelevant. */
1194 struct dep
**deps_ptr
= &deps
;
1196 for (deps_ptr
= &deps
; *deps_ptr
; deps_ptr
= &(*deps_ptr
)->next
)
1199 *deps_ptr
= (struct dep
*)
1200 multi_glob (parse_file_seq (&p2
, '\0', sizeof (struct dep
), 1),
1201 sizeof (struct dep
));
1202 for (d
= *deps_ptr
; d
!= 0; d
= d
->next
)
1203 d
->ignore_mtime
= 1;
1209 /* Semicolon means rest of line is a command. */
1210 unsigned int len
= strlen (cmdleft
);
1212 cmds_started
= fstart
->lineno
;
1214 /* Add this command line to the buffer. */
1215 if (len
+ 2 > commands_len
)
1217 commands_len
= (len
+ 2) * 2;
1218 commands
= (char *) xrealloc (commands
, commands_len
);
1220 bcopy (cmdleft
, commands
, len
);
1221 commands_idx
+= len
;
1222 commands
[commands_idx
++] = '\n';
1228 /* We get here except in the case that we just read a rule line.
1229 Record now the last rule we read, so following spurious
1230 commands are properly diagnosed. */
1232 record_waiting_files ();
1237 if (conditionals
->if_cmds
)
1238 fatal (fstart
, _("missing `endif'"));
1240 /* At eof, record the last rule. */
1241 record_waiting_files ();
1244 free ((char *) collapsed
);
1245 free ((char *) commands
);
1251 /* Execute a `define' directive.
1252 The first line has already been read, and NAME is the name of
1253 the variable to be defined. The following lines remain to be read. */
1256 do_define (char *name
, unsigned int namelen
,
1257 enum variable_origin origin
, struct ebuffer
*ebuf
)
1259 struct floc defstart
;
1262 unsigned int length
= 100;
1263 char *definition
= (char *) xmalloc (length
);
1264 unsigned int idx
= 0;
1267 /* Expand the variable name. */
1268 char *var
= (char *) alloca (namelen
+ 1);
1269 bcopy (name
, var
, namelen
);
1270 var
[namelen
] = '\0';
1271 var
= variable_expand (var
);
1273 defstart
= ebuf
->floc
;
1280 ebuf
->floc
.lineno
+= nlines
;
1281 nlines
= readline (ebuf
);
1283 /* If there is nothing left to eval, we're done. */
1287 line
= ebuf
->buffer
;
1289 collapse_continuations (line
);
1291 /* If the line doesn't begin with a tab, test to see if it introduces
1292 another define, or ends one. */
1294 /* Stop if we find an 'endef' */
1295 if (line
[0] != '\t')
1297 p
= next_token (line
);
1300 /* If this is another 'define', increment the level count. */
1301 if ((len
== 6 || (len
> 6 && isblank ((unsigned char)p
[6])))
1302 && strneq (p
, "define", 6))
1305 /* If this is an 'endef', decrement the count. If it's now 0,
1306 we've found the last one. */
1307 else if ((len
== 5 || (len
> 5 && isblank ((unsigned char)p
[5])))
1308 && strneq (p
, "endef", 5))
1311 remove_comments (p
);
1312 if (*next_token (p
) != '\0')
1314 _("Extraneous text after `endef' directive"));
1318 /* Define the variable. */
1320 definition
[0] = '\0';
1322 definition
[idx
- 1] = '\0';
1324 /* Always define these variables in the global set. */
1325 define_variable_global (var
, strlen (var
), definition
,
1326 origin
, 1, &defstart
);
1333 /* Otherwise add this line to the variable definition. */
1334 len
= strlen (line
);
1335 if (idx
+ len
+ 1 > length
)
1337 length
= (idx
+ len
) * 2;
1338 definition
= (char *) xrealloc (definition
, length
+ 1);
1341 bcopy (line
, &definition
[idx
], len
);
1343 /* Separate lines with a newline. */
1344 definition
[idx
++] = '\n';
1348 fatal (&defstart
, _("missing `endef', unterminated `define'"));
1354 /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
1355 "ifneq", "else" and "endif".
1356 LINE is the input line, with the command as its first word.
1358 FILENAME and LINENO are the filename and line number in the
1359 current makefile. They are used for error messages.
1361 Value is -1 if the line is invalid,
1362 0 if following text should be interpreted,
1363 1 if following text should be ignored. */
1366 conditional_line (char *line
, const struct floc
*flocp
)
1370 register unsigned int i
;
1374 /* It's an "if..." command. */
1375 notdef
= line
[2] == 'n';
1378 cmdname
= line
[3] == 'd' ? "ifndef" : "ifneq";
1379 line
+= cmdname
[3] == 'd' ? 7 : 6;
1383 cmdname
= line
[2] == 'd' ? "ifdef" : "ifeq";
1384 line
+= cmdname
[2] == 'd' ? 6 : 5;
1389 /* It's an "else" or "endif" command. */
1390 notdef
= line
[1] == 'n';
1391 cmdname
= notdef
? "endif" : "else";
1392 line
+= notdef
? 5 : 4;
1395 line
= next_token (line
);
1397 if (*cmdname
== 'e')
1400 error (flocp
, _("Extraneous text after `%s' directive"), cmdname
);
1401 /* "Else" or "endif". */
1402 if (conditionals
->if_cmds
== 0)
1403 fatal (flocp
, _("extraneous `%s'"), cmdname
);
1404 /* NOTDEF indicates an `endif' command. */
1406 --conditionals
->if_cmds
;
1407 else if (conditionals
->seen_else
[conditionals
->if_cmds
- 1])
1408 fatal (flocp
, _("only one `else' per conditional"));
1411 /* Toggle the state of ignorance. */
1412 conditionals
->ignoring
[conditionals
->if_cmds
- 1]
1413 = !conditionals
->ignoring
[conditionals
->if_cmds
- 1];
1414 /* Record that we have seen an `else' in this conditional.
1415 A second `else' will be erroneous. */
1416 conditionals
->seen_else
[conditionals
->if_cmds
- 1] = 1;
1418 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
1419 if (conditionals
->ignoring
[i
])
1424 if (conditionals
->allocated
== 0)
1426 conditionals
->allocated
= 5;
1427 conditionals
->ignoring
= (char *) xmalloc (conditionals
->allocated
);
1428 conditionals
->seen_else
= (char *) xmalloc (conditionals
->allocated
);
1431 ++conditionals
->if_cmds
;
1432 if (conditionals
->if_cmds
> conditionals
->allocated
)
1434 conditionals
->allocated
+= 5;
1435 conditionals
->ignoring
= (char *)
1436 xrealloc (conditionals
->ignoring
, conditionals
->allocated
);
1437 conditionals
->seen_else
= (char *)
1438 xrealloc (conditionals
->seen_else
, conditionals
->allocated
);
1441 /* Record that we have seen an `if...' but no `else' so far. */
1442 conditionals
->seen_else
[conditionals
->if_cmds
- 1] = 0;
1444 /* Search through the stack to see if we're already ignoring. */
1445 for (i
= 0; i
< conditionals
->if_cmds
- 1; ++i
)
1446 if (conditionals
->ignoring
[i
])
1448 /* We are already ignoring, so just push a level
1449 to match the next "else" or "endif", and keep ignoring.
1450 We don't want to expand variables in the condition. */
1451 conditionals
->ignoring
[conditionals
->if_cmds
- 1] = 1;
1455 if (cmdname
[notdef
? 3 : 2] == 'd')
1457 /* "Ifdef" or "ifndef". */
1460 register char *p
= end_of_token (line
);
1466 /* Expand the thing we're looking up, so we can use indirect and
1467 constructed variable names. */
1469 var
= allocated_variable_expand (line
);
1471 v
= lookup_variable (var
, strlen (var
));
1472 conditionals
->ignoring
[conditionals
->if_cmds
- 1]
1473 = (v
!= 0 && *v
->value
!= '\0') == notdef
;
1479 /* "Ifeq" or "ifneq". */
1482 char termin
= *line
== '(' ? ',' : *line
;
1484 if (termin
!= ',' && termin
!= '"' && termin
!= '\'')
1488 /* Find the end of the first string. */
1491 register int count
= 0;
1492 for (; *line
!= '\0'; ++line
)
1495 else if (*line
== ')')
1497 else if (*line
== ',' && count
<= 0)
1501 while (*line
!= '\0' && *line
!= termin
)
1509 /* Strip blanks after the first string. */
1511 while (isblank ((unsigned char)p
[-1]))
1518 s2
= variable_expand (s1
);
1519 /* We must allocate a new copy of the expanded string because
1520 variable_expand re-uses the same buffer. */
1522 s1
= (char *) alloca (len
+ 1);
1523 bcopy (s2
, s1
, len
+ 1);
1526 /* Find the start of the second string. */
1527 line
= next_token (line
);
1529 termin
= termin
== ',' ? ')' : *line
;
1530 if (termin
!= ')' && termin
!= '"' && termin
!= '\'')
1533 /* Find the end of the second string. */
1536 register int count
= 0;
1537 s2
= next_token (line
);
1538 for (line
= s2
; *line
!= '\0'; ++line
)
1542 else if (*line
== ')')
1555 while (*line
!= '\0' && *line
!= termin
)
1563 line
= next_token (++line
);
1565 error (flocp
, _("Extraneous text after `%s' directive"), cmdname
);
1567 s2
= variable_expand (s2
);
1568 conditionals
->ignoring
[conditionals
->if_cmds
- 1]
1569 = streq (s1
, s2
) == notdef
;
1572 /* Search through the stack to see if we're ignoring. */
1573 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
1574 if (conditionals
->ignoring
[i
])
1579 /* Remove duplicate dependencies in CHAIN. */
1581 static unsigned long
1582 dep_hash_1 (const void *key
)
1584 return_STRING_HASH_1 (dep_name ((struct dep
const *) key
));
1587 static unsigned long
1588 dep_hash_2 (const void *key
)
1590 return_STRING_HASH_2 (dep_name ((struct dep
const *) key
));
1594 dep_hash_cmp (const void *x
, const void *y
)
1596 struct dep
*dx
= (struct dep
*) x
;
1597 struct dep
*dy
= (struct dep
*) y
;
1598 int cmp
= strcmp (dep_name (dx
), dep_name (dy
));
1600 /* If the names are the same but ignore_mtimes are not equal, one of these
1601 is an order-only prerequisite and one isn't. That means that we should
1602 remove the one that isn't and keep the one that is. */
1604 if (!cmp
&& dx
->ignore_mtime
!= dy
->ignore_mtime
)
1605 dx
->ignore_mtime
= dy
->ignore_mtime
= 0;
1612 uniquize_deps (struct dep
*chain
)
1614 struct hash_table deps
;
1615 register struct dep
**depp
;
1617 hash_init (&deps
, 500, dep_hash_1
, dep_hash_2
, dep_hash_cmp
);
1619 /* Make sure that no dependencies are repeated. This does not
1620 really matter for the purpose of updating targets, but it
1621 might make some names be listed twice for $^ and $?. */
1626 struct dep
*dep
= *depp
;
1627 struct dep
**dep_slot
= (struct dep
**) hash_find_slot (&deps
, dep
);
1628 if (HASH_VACANT (*dep_slot
))
1630 hash_insert_at (&deps
, dep
, dep_slot
);
1635 /* Don't bother freeing duplicates.
1636 It's dangerous and little benefit accrues. */
1641 hash_free (&deps
, 0);
1644 /* Record target-specific variable values for files FILENAMES.
1645 TWO_COLON is nonzero if a double colon was used.
1647 The links of FILENAMES are freed, and so are any names in it
1648 that are not incorporated into other data structures.
1650 If the target is a pattern, add the variable to the pattern-specific
1651 variable value list. */
1654 record_target_var (struct nameseq
*filenames
, char *defn
, int two_colon
,
1655 enum variable_origin origin
, int exported
,
1656 const struct floc
*flocp
)
1658 struct nameseq
*nextf
;
1659 struct variable_set_list
*global
;
1661 global
= current_variable_set_list
;
1663 /* If the variable is an append version, store that but treat it as a
1664 normal recursive variable. */
1666 for (; filenames
!= 0; filenames
= nextf
)
1669 register char *name
= filenames
->name
;
1672 struct pattern_var
*p
;
1674 nextf
= filenames
->next
;
1675 free ((char *) filenames
);
1677 /* If it's a pattern target, then add it to the pattern-specific
1679 percent
= find_percent (name
);
1682 /* Get a reference for this pattern-specific variable struct. */
1683 p
= create_pattern_var (name
, percent
);
1684 p
->variable
.fileinfo
= *flocp
;
1685 v
= parse_variable_definition (&p
->variable
, defn
);
1686 v
->value
= xstrdup (v
->value
);
1688 error (flocp
, _("Malformed pattern-specific variable definition"));
1695 /* Get a file reference for this file, and initialize it.
1696 We don't want to just call enter_file() because that allocates a
1697 new entry if the file is a double-colon, which we don't want in
1699 f
= lookup_file (name
);
1701 f
= enter_file (name
);
1702 else if (f
->double_colon
)
1703 f
= f
->double_colon
;
1705 initialize_file_variables (f
, 1);
1708 current_variable_set_list
= f
->variables
;
1709 v
= try_variable_definition (flocp
, defn
, origin
, 1);
1711 error (flocp
, _("Malformed target-specific variable definition"));
1712 current_variable_set_list
= global
;
1715 /* Set up the variable to be *-specific. */
1719 v
->export
= v_export
;
1721 /* If it's not an override, check to see if there was a command-line
1722 setting. If so, reset the value. */
1723 if (origin
!= o_override
)
1725 struct variable
*gv
;
1726 int len
= strlen(v
->name
);
1728 gv
= lookup_variable (v
->name
, len
);
1729 if (gv
&& (gv
->origin
== o_env_override
|| gv
->origin
== o_command
))
1733 v
->value
= xstrdup (gv
->value
);
1734 v
->origin
= gv
->origin
;
1735 v
->recursive
= gv
->recursive
;
1740 /* Free name if not needed further. */
1741 if (name
!= fname
&& (name
< fname
|| name
> fname
+ strlen (fname
)))
1746 /* Record a description line for files FILENAMES,
1747 with dependencies DEPS, commands to execute described
1748 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
1749 TWO_COLON is nonzero if a double colon was used.
1750 If not nil, PATTERN is the `%' pattern to make this
1751 a static pattern rule, and PATTERN_PERCENT is a pointer
1752 to the `%' within it.
1754 The links of FILENAMES are freed, and so are any names in it
1755 that are not incorporated into other data structures. */
1758 record_files (struct nameseq
*filenames
, char *pattern
, char *pattern_percent
,
1759 struct dep
*deps
, unsigned int cmds_started
, char *commands
,
1760 unsigned int commands_idx
, int two_colon
,
1761 int have_sysv_atvar
, const struct floc
*flocp
, int set_default
)
1763 struct nameseq
*nextf
;
1765 unsigned int max_targets
= 0, target_idx
= 0;
1766 char **targets
= 0, **target_percents
= 0;
1767 struct commands
*cmds
;
1769 if (commands_idx
> 0)
1771 cmds
= (struct commands
*) xmalloc (sizeof (struct commands
));
1772 cmds
->fileinfo
.filenm
= flocp
->filenm
;
1773 cmds
->fileinfo
.lineno
= cmds_started
;
1774 cmds
->commands
= savestring (commands
, commands_idx
);
1775 cmds
->command_lines
= 0;
1780 for (; filenames
!= 0; filenames
= nextf
)
1782 char *name
= filenames
->name
;
1786 char *implicit_percent
;
1788 nextf
= filenames
->next
;
1791 /* Check for .POSIX. We used to do this in snap_deps() but that's not
1792 good enough: it doesn't happen until after the makefile is read,
1793 which means we cannot use its value during parsing. */
1795 if (streq (name
, ".POSIX"))
1798 implicit_percent
= find_percent (name
);
1799 implicit
|= implicit_percent
!= 0;
1801 if (implicit
&& pattern
!= 0)
1802 fatal (flocp
, _("mixed implicit and static pattern rules"));
1804 if (implicit
&& implicit_percent
== 0)
1805 fatal (flocp
, _("mixed implicit and normal rules"));
1812 targets
= (char **) xmalloc (5 * sizeof (char *));
1813 target_percents
= (char **) xmalloc (5 * sizeof (char *));
1816 else if (target_idx
== max_targets
- 1)
1819 targets
= (char **) xrealloc ((char *) targets
,
1820 max_targets
* sizeof (char *));
1822 = (char **) xrealloc ((char *) target_percents
,
1823 max_targets
* sizeof (char *));
1825 targets
[target_idx
] = name
;
1826 target_percents
[target_idx
] = implicit_percent
;
1831 /* If there are multiple filenames, copy the chain DEPS
1832 for all but the last one. It is not safe for the same deps
1833 to go in more than one place in the data base. */
1834 this = nextf
!= 0 ? copy_dep_chain (deps
) : deps
;
1838 /* If this is an extended static rule:
1839 `targets: target%pattern: dep%pattern; cmds',
1840 translate each dependency pattern into a plain filename
1841 using the target pattern and this target's name. */
1842 if (!pattern_matches (pattern
, pattern_percent
, name
))
1844 /* Give a warning if the rule is meaningless. */
1846 _("target `%s' doesn't match the target pattern"), name
);
1851 /* We use patsubst_expand to do the work of translating
1852 the target pattern, the target's name and the dependencies'
1853 patterns into plain dependency names. */
1854 char *buffer
= variable_expand ("");
1856 for (d
= this; d
!= 0; d
= d
->next
)
1859 char *percent
= find_percent (d
->name
);
1862 o
= patsubst_expand (buffer
, name
, pattern
, d
->name
,
1863 pattern_percent
, percent
);
1864 /* If the name expanded to the empty string, that's
1868 _("target `%s' leaves prerequisite pattern empty"),
1871 d
->name
= savestring (buffer
, o
- buffer
);
1876 /* If at least one of the dependencies uses $$@ etc. deal with that.
1877 It would be very nice and very simple to just expand everything, but
1878 it would break a lot of backward compatibility. Maybe that's OK
1879 since we're just emulating a SysV function, and if we do that then
1880 why not emulate it completely (that's what SysV make does: it
1881 re-expands the entire prerequisite list, all the time, with $@
1882 etc. in scope). But, it would be a pain indeed to document this
1883 ("iff you use $$@, your prerequisite lists is expanded twice...")
1884 Ouch. Maybe better to make the code more complex. */
1886 if (have_sysv_atvar
)
1889 int tlen
= strlen (name
);
1890 char *fnp
= strrchr (name
, '/');
1898 flen
= strlen (fnp
);
1908 for (d
= this; d
!= 0; d
= d
->next
)
1909 for (p
= strchr (d
->name
, '$'); p
!= 0; p
= strchr (p
+1, '$'))
1915 /* If it's '$@', '$(@', or '${@', it's escaped */
1918 || ((p
[1] == '(' || p
[1] == '{') && p
[2] == '@')))
1920 bcopy (p
, s
, strlen (p
)+1);
1924 /* Maybe found one. We like anything of any form matching @,
1925 [({]@[}):], or [({]@[DF][}):]. */
1928 || ((p
[0] == '(' || p
[0] == '{') && (++p
)[0] == '@'
1929 && (((++p
)[0] == ')' || p
[0] == '}' || p
[0] == ':')
1930 || ((p
[1] == ')' || p
[1] == '}' || p
[1] == ':')
1931 && (p
[0] == 'D' || p
[0] == 'F'))))))
1934 /* Found one. Compute the length and string ptr. Move p
1935 past the variable reference. */
1957 /* Get more space. */
1959 int soff
= s
- d
->name
;
1960 int poff
= p
- d
->name
;
1961 d
->name
= (char *) xrealloc (d
->name
,
1962 strlen (d
->name
) + atlen
+ 1);
1967 /* Copy the string over. */
1968 bcopy(p
, s
+atlen
, strlen (p
)+1);
1969 bcopy(at
, s
, atlen
);
1976 /* Single-colon. Combine these dependencies
1977 with others in file's existing record, if any. */
1978 f
= enter_file (name
);
1980 if (f
->double_colon
)
1982 _("target file `%s' has both : and :: entries"), f
->name
);
1984 /* If CMDS == F->CMDS, this target was listed in this rule
1985 more than once. Just give a warning since this is harmless. */
1986 if (cmds
!= 0 && cmds
== f
->cmds
)
1988 _("target `%s' given more than once in the same rule."),
1991 /* Check for two single-colon entries both with commands.
1992 Check is_target so that we don't lose on files such as .c.o
1993 whose commands were preinitialized. */
1994 else if (cmds
!= 0 && f
->cmds
!= 0 && f
->is_target
)
1996 error (&cmds
->fileinfo
,
1997 _("warning: overriding commands for target `%s'"),
1999 error (&f
->cmds
->fileinfo
,
2000 _("warning: ignoring old commands for target `%s'"),
2006 /* Defining .DEFAULT with no deps or cmds clears it. */
2007 if (f
== default_file
&& this == 0 && cmds
== 0)
2011 /* Defining .SUFFIXES with no dependencies
2012 clears out the list of suffixes. */
2013 if (f
== suffix_file
&& this == 0)
2018 struct dep
*nextd
= d
->next
;
2025 else if (f
->deps
!= 0)
2027 /* Add the file's old deps and the new ones in THIS together. */
2029 struct dep
*firstdeps
, *moredeps
;
2032 /* This is the rule with commands, so put its deps first.
2033 The rationale behind this is that $< expands to the
2034 first dep in the chain, and commands use $< expecting
2035 to get the dep that rule specifies. */
2041 /* Append the new deps to the old ones. */
2042 firstdeps
= f
->deps
;
2047 firstdeps
= moredeps
;
2051 while (d
->next
!= 0)
2056 f
->deps
= firstdeps
;
2061 /* If this is a static pattern rule, set the file's stem to
2062 the part of its name that matched the `%' in the pattern,
2063 so you can use $* in the commands. */
2066 static char *percent
= "%";
2067 char *buffer
= variable_expand ("");
2068 char *o
= patsubst_expand (buffer
, name
, pattern
, percent
,
2069 pattern_percent
, percent
);
2070 f
->stem
= savestring (buffer
, o
- buffer
);
2075 /* Double-colon. Make a new record
2076 even if the file already has one. */
2077 f
= lookup_file (name
);
2078 /* Check for both : and :: rules. Check is_target so
2079 we don't lose on default suffix rules or makefiles. */
2080 if (f
!= 0 && f
->is_target
&& !f
->double_colon
)
2082 _("target file `%s' has both : and :: entries"), f
->name
);
2083 f
= enter_file (name
);
2084 /* If there was an existing entry and it was a double-colon
2085 entry, enter_file will have returned a new one, making it the
2086 prev pointer of the old one, and setting its double_colon
2087 pointer to the first one. */
2088 if (f
->double_colon
== 0)
2089 /* This is the first entry for this name, so we must
2090 set its double_colon pointer to itself. */
2091 f
->double_colon
= f
;
2097 /* Free name if not needed further. */
2098 if (f
!= 0 && name
!= f
->name
2099 && (name
< f
->name
|| name
> f
->name
+ strlen (f
->name
)))
2105 /* See if this is first target seen whose name does
2106 not start with a `.', unless it contains a slash. */
2107 if (default_goal_file
== 0 && set_default
2108 && (*name
!= '.' || strchr (name
, '/') != 0
2109 #ifdef HAVE_DOS_PATHS
2110 || strchr (name
, '\\') != 0
2116 /* If this file is a suffix, don't
2117 let it be the default goal file. */
2119 for (d
= suffix_file
->deps
; d
!= 0; d
= d
->next
)
2121 register struct dep
*d2
;
2122 if (*dep_name (d
) != '.' && streq (name
, dep_name (d
)))
2127 for (d2
= suffix_file
->deps
; d2
!= 0; d2
= d2
->next
)
2129 register unsigned int len
= strlen (dep_name (d2
));
2130 if (!strneq (name
, dep_name (d2
), len
))
2132 if (streq (name
+ len
, dep_name (d
)))
2143 default_goal_file
= f
;
2149 targets
[target_idx
] = 0;
2150 target_percents
[target_idx
] = 0;
2151 create_pattern_rule (targets
, target_percents
, two_colon
, deps
, cmds
, 1);
2152 free ((char *) target_percents
);
2156 /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
2157 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
2158 Quoting backslashes are removed from STRING by compacting it into
2159 itself. Returns a pointer to the first unquoted STOPCHAR if there is
2160 one, or nil if there are none. */
2163 find_char_unquote (char *string
, int stop1
, int stop2
, int blank
)
2165 unsigned int string_len
= 0;
2166 register char *p
= string
;
2171 while (*p
!= '\0' && *p
!= stop1
&& *p
!= stop2
2172 && ! isblank ((unsigned char) *p
))
2175 while (*p
!= '\0' && *p
!= stop1
&& *p
!= stop2
)
2178 while (*p
!= '\0' && *p
!= stop1
2179 && ! isblank ((unsigned char) *p
))
2182 while (*p
!= '\0' && *p
!= stop1
)
2188 if (p
> string
&& p
[-1] == '\\')
2190 /* Search for more backslashes. */
2191 register int i
= -2;
2192 while (&p
[i
] >= string
&& p
[i
] == '\\')
2195 /* Only compute the length if really needed. */
2196 if (string_len
== 0)
2197 string_len
= strlen (string
);
2198 /* The number of backslashes is now -I.
2199 Copy P over itself to swallow half of them. */
2200 bcopy (&p
[i
/ 2], &p
[i
], (string_len
- (p
- string
)) - (i
/ 2) + 1);
2203 /* All the backslashes quoted each other; the STOPCHAR was
2207 /* The STOPCHAR was quoted by a backslash. Look for another. */
2210 /* No backslash in sight. */
2214 /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
2218 /* Search PATTERN for an unquoted %. */
2221 find_percent (char *pattern
)
2223 return find_char_unquote (pattern
, '%', 0, 0);
2226 /* Parse a string into a sequence of filenames represented as a
2227 chain of struct nameseq's in reverse order and return that chain.
2229 The string is passed as STRINGP, the address of a string pointer.
2230 The string pointer is updated to point at the first character
2231 not parsed, which either is a null char or equals STOPCHAR.
2233 SIZE is how big to construct chain elements.
2234 This is useful if we want them actually to be other structures
2235 that have room for additional info.
2237 If STRIP is nonzero, strip `./'s off the beginning. */
2240 parse_file_seq (char **stringp
, int stopchar
, unsigned int size
, int strip
)
2242 register struct nameseq
*new = 0;
2243 register struct nameseq
*new1
, *lastnew1
;
2244 register char *p
= *stringp
;
2249 # define VMS_COMMA ','
2251 # define VMS_COMMA 0
2256 /* Skip whitespace; see if any more names are left. */
2263 /* Yes, find end of next name. */
2265 p
= find_char_unquote (q
, stopchar
, VMS_COMMA
, 1);
2267 /* convert comma separated list to space separated */
2272 if (stopchar
== ':' && p
&& *p
== ':'
2273 && !(isspace ((unsigned char)p
[1]) || !p
[1]
2274 || isspace ((unsigned char)p
[-1])))
2276 p
= find_char_unquote (p
+1, stopchar
, VMS_COMMA
, 1);
2279 #ifdef HAVE_DOS_PATHS
2280 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
2281 first colon which isn't followed by a slash or a backslash.
2282 Note that tokens separated by spaces should be treated as separate
2283 tokens since make doesn't allow path names with spaces */
2284 if (stopchar
== ':')
2285 while (p
!= 0 && !isspace ((unsigned char)*p
) &&
2286 (p
[1] == '\\' || p
[1] == '/') && isalpha ((unsigned char)p
[-1]))
2287 p
= find_char_unquote (p
+ 1, stopchar
, VMS_COMMA
, 1);
2294 /* Skip leading `[]'s. */
2295 while (p
- q
> 2 && q
[0] == '[' && q
[1] == ']')
2297 /* Skip leading `./'s. */
2298 while (p
- q
> 2 && q
[0] == '.' && q
[1] == '/')
2301 q
+= 2; /* Skip "./". */
2302 while (q
< p
&& *q
== '/')
2303 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
2307 /* Extract the filename just found, and skip it. */
2310 /* ".///" was stripped to "". */
2315 name
= savestring ("", 0);
2317 name
= savestring ("./", 2);
2322 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need
2323 * to remove this '\' before we can use the filename.
2324 * Savestring called because q may be read-only string constant.
2327 char *qbase
= xstrdup (q
);
2328 char *pbase
= qbase
+ (p
-q
);
2335 if (*q1
== '\\' && *(q1
+1) == ':')
2342 name
= savestring (qbase
, p1
- qbase
);
2346 name
= savestring (q
, p
- q
);
2349 /* Add it to the front of the chain. */
2350 new1
= (struct nameseq
*) xmalloc (size
);
2358 /* Look for multi-word archive references.
2359 They are indicated by a elt ending with an unmatched `)' and
2360 an elt further down the chain (i.e., previous in the file list)
2361 with an unmatched `(' (e.g., "lib(mem"). */
2366 if (new1
->name
[0] != '(' /* Don't catch "(%)" and suchlike. */
2367 && new1
->name
[strlen (new1
->name
) - 1] == ')'
2368 && strchr (new1
->name
, '(') == 0)
2370 /* NEW1 ends with a `)' but does not contain a `('.
2371 Look back for an elt with an opening `(' but no closing `)'. */
2373 struct nameseq
*n
= new1
->next
, *lastn
= new1
;
2375 while (n
!= 0 && (paren
= strchr (n
->name
, '(')) == 0)
2381 /* Ignore something starting with `(', as that cannot actually
2382 be an archive-member reference (and treating it as such
2383 results in an empty file name, which causes much lossage). */
2384 && n
->name
[0] != '(')
2386 /* N is the first element in the archive group.
2387 Its name looks like "lib(mem" (with no closing `)'). */
2391 /* Copy "lib(" into LIBNAME. */
2393 libname
= (char *) alloca (paren
- n
->name
+ 1);
2394 bcopy (n
->name
, libname
, paren
- n
->name
);
2395 libname
[paren
- n
->name
] = '\0';
2399 /* N was just "lib(", part of something like "lib( a b)".
2400 Edit it out of the chain and free its storage. */
2401 lastn
->next
= n
->next
;
2404 /* LASTN->next is the new stopping elt for the loop below. */
2409 /* Replace N's name with the full archive reference. */
2410 name
= concat (libname
, paren
, ")");
2415 if (new1
->name
[1] == '\0')
2417 /* NEW1 is just ")", part of something like "lib(a b )".
2418 Omit it from the chain and free its storage. */
2422 lastnew1
->next
= new1
->next
;
2426 free ((char *) lastn
);
2430 /* Replace also NEW1->name, which already has closing `)'. */
2431 name
= concat (libname
, new1
->name
, "");
2437 /* Trace back from NEW1 (the end of the list) until N
2438 (the beginning of the list), rewriting each name
2439 with the full archive reference. */
2443 name
= concat (libname
, new1
->name
, ")");
2452 /* No frobnication happening. Just step down the list. */
2469 /* Find the next line of text in an eval buffer, combining continuation lines
2471 Return the number of actual lines read (> 1 if continuation lines).
2472 Returns -1 if there's nothing left in the buffer.
2474 After this function, ebuf->buffer points to the first character of the
2478 /* Read a line of text from a STRING.
2479 Since we aren't really reading from a file, don't bother with linenumbers.
2482 static unsigned long
2483 readstring (struct ebuffer
*ebuf
)
2487 /* If there is nothing left in this buffer, return 0. */
2488 if (ebuf
->bufnext
> ebuf
->bufstart
+ ebuf
->size
)
2491 /* Set up a new starting point for the buffer, and find the end of the
2492 next logical line (taking into account backslash/newline pairs). */
2494 p
= ebuf
->buffer
= ebuf
->bufnext
;
2500 /* Find the next newline. Keep track of backslashes as we look. */
2501 for (; *p
!= '\n' && *p
!= '\0'; ++p
)
2503 backslash
= !backslash
;
2505 /* If we got to the end of the string or a newline with no backslash,
2507 if (*p
== '\0' || !backslash
)
2511 /* Overwrite the newline char. */
2513 ebuf
->bufnext
= p
+1;
2519 readline (struct ebuffer
*ebuf
)
2526 /* The behaviors between string and stream buffers are different enough to
2527 warrant different functions. Do the Right Thing. */
2530 return readstring (ebuf
);
2532 /* When reading from a file, we always start over at the beginning of the
2533 buffer for each new line. */
2535 p
= start
= ebuf
->bufstart
;
2536 end
= p
+ ebuf
->size
;
2539 while (fgets (p
, end
- p
, ebuf
->fp
) != 0)
2548 /* This only happens when the first thing on the line is a '\0'.
2549 It is a pretty hopeless case, but (wonder of wonders) Athena
2550 lossage strikes again! (xmkmf puts NULs in its makefiles.)
2551 There is nothing really to be done; we synthesize a newline so
2552 the following line doesn't appear to be part of this line. */
2554 _("warning: NUL character seen; rest of line ignored"));
2559 /* Jump past the text we just read. */
2562 /* If the last char isn't a newline, the whole line didn't fit into the
2563 buffer. Get some more buffer and try again. */
2567 /* We got a newline, so add one to the count of lines. */
2570 #if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
2571 /* Check to see if the line was really ended with CRLF; if so ignore
2573 if ((p
- start
) > 1 && p
[-2] == '\r')
2581 for (p2
= p
- 2; p2
>= start
; --p2
)
2585 backslash
= !backslash
;
2594 /* It was a backslash/newline combo. If we have more space, read
2599 /* We need more space at the end of our buffer, so realloc it.
2600 Make sure to preserve the current offset of p. */
2603 unsigned long off
= p
- start
;
2605 start
= ebuf
->buffer
= ebuf
->bufstart
= (char *) xrealloc (start
,
2608 end
= start
+ ebuf
->size
;
2613 if (ferror (ebuf
->fp
))
2614 pfatal_with_name (ebuf
->floc
.filenm
);
2616 /* If we found some lines, return how many.
2617 If we didn't, but we did find _something_, that indicates we read the last
2618 line of a file with no final newline; return 1.
2619 If we read nothing, we're at EOF; return -1. */
2621 return nlines
? nlines
: p
== ebuf
->bufstart
? -1 : 1;
2624 /* Parse the next "makefile word" from the input buffer, and return info
2627 A "makefile word" is one of:
2629 w_bogus Should never happen
2631 w_static A static word; cannot be expanded
2632 w_variable A word containing one or more variables/functions
2634 w_dcolon A double-colon
2635 w_semicolon A semicolon
2636 w_varassign A variable assignment operator (=, :=, +=, or ?=)
2638 Note that this function is only used when reading certain parts of the
2639 makefile. Don't use it where special rules hold sway (RHS of a variable,
2640 in a command list, etc.) */
2642 static enum make_word_type
2643 get_next_mword (char *buffer
, char *delim
, char **startp
, unsigned int *length
)
2645 enum make_word_type wtype
= w_bogus
;
2646 char *p
= buffer
, *beg
;
2649 /* Skip any leading whitespace. */
2650 while (isblank ((unsigned char)*p
))
2662 wtype
= w_semicolon
;
2666 wtype
= w_varassign
;
2680 wtype
= w_varassign
;
2690 wtype
= w_varassign
;
2695 if (delim
&& strchr (delim
, c
))
2700 /* Did we find something? If so, return now. */
2701 if (wtype
!= w_bogus
)
2704 /* This is some non-operator word. A word consists of the longest
2705 string of characters that doesn't contain whitespace, one of [:=#],
2706 or [?+]=, or one of the chars in the DELIM string. */
2708 /* We start out assuming a static word; if we see a variable we'll
2709 adjust our assumptions then. */
2712 /* We already found the first value of "c", above. */
2727 #ifdef HAVE_DOS_PATHS
2728 /* A word CAN include a colon in its drive spec. The drive
2729 spec is allowed either at the beginning of a word, or as part
2730 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
2732 && (*p
== '/' || *p
== '\\') && isalpha ((unsigned char)p
[-2])
2733 && (p
- beg
== 2 || p
[-3] == '(')))
2742 /* This is a variable reference, so note that it's expandable.
2743 Then read it to the matching close paren. */
2751 /* This is a single-letter variable reference. */
2754 for (count
=0; *p
!= '\0'; ++p
)
2758 else if (*p
== closeparen
&& --count
< 0)
2785 if (delim
&& strchr (delim
, c
))
2803 /* Construct the list of include directories
2804 from the arguments and the default list. */
2807 construct_include_path (char **arg_dirs
)
2809 register unsigned int i
;
2810 #ifdef VAXC /* just don't ask ... */
2815 /* Table to hold the dirs. */
2817 register unsigned int defsize
= (sizeof (default_include_directories
)
2818 / sizeof (default_include_directories
[0]));
2819 register unsigned int max
= 5;
2820 register char **dirs
= (char **) xmalloc ((5 + defsize
) * sizeof (char *));
2821 register unsigned int idx
= 0;
2827 /* First consider any dirs specified with -I switches.
2828 Ignore dirs that don't exist. */
2831 while (*arg_dirs
!= 0)
2833 char *dir
= *arg_dirs
++;
2838 char *expanded
= tilde_expand (dir
);
2843 EINTRLOOP (e
, stat (dir
, &stbuf
));
2844 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2850 xrealloc ((char *) dirs
, (max
+ defsize
) * sizeof (char *));
2854 else if (dir
!= arg_dirs
[-1])
2858 /* Now add at the end the standard default dirs. */
2862 /* The environment variable $DJDIR holds the root of the
2863 DJGPP directory tree; add ${DJDIR}/include. */
2864 struct variable
*djdir
= lookup_variable ("DJDIR", 5);
2868 char *defdir
= (char *) xmalloc (strlen (djdir
->value
) + 8 + 1);
2870 strcat (strcpy (defdir
, djdir
->value
), "/include");
2871 dirs
[idx
++] = defdir
;
2876 for (i
= 0; default_include_directories
[i
] != 0; ++i
)
2880 EINTRLOOP (e
, stat (default_include_directories
[i
], &stbuf
));
2881 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2882 dirs
[idx
++] = default_include_directories
[i
];
2887 /* Now compute the maximum length of any name in it. */
2890 for (i
= 0; i
< idx
; ++i
)
2892 unsigned int len
= strlen (dirs
[i
]);
2893 /* If dir name is written with a trailing slash, discard it. */
2894 if (dirs
[i
][len
- 1] == '/')
2895 /* We can't just clobber a null in because it may have come from
2896 a literal string and literal strings may not be writable. */
2897 dirs
[i
] = savestring (dirs
[i
], len
- 1);
2898 if (len
> max_incl_len
)
2902 include_directories
= dirs
;
2905 /* Expand ~ or ~USER at the beginning of NAME.
2906 Return a newly malloc'd string or 0. */
2909 tilde_expand (char *name
)
2912 if (name
[1] == '/' || name
[1] == '\0')
2914 extern char *getenv ();
2919 /* Turn off --warn-undefined-variables while we expand HOME. */
2920 int save
= warn_undefined_variables_flag
;
2921 warn_undefined_variables_flag
= 0;
2923 home_dir
= allocated_variable_expand ("$(HOME)");
2925 warn_undefined_variables_flag
= save
;
2928 is_variable
= home_dir
[0] != '\0';
2932 home_dir
= getenv ("HOME");
2934 #if !defined(_AMIGA) && !defined(WINDOWS32)
2935 if (home_dir
== 0 || home_dir
[0] == '\0')
2937 extern char *getlogin ();
2938 char *logname
= getlogin ();
2942 struct passwd
*p
= getpwnam (logname
);
2944 home_dir
= p
->pw_dir
;
2947 #endif /* !AMIGA && !WINDOWS32 */
2950 char *new = concat (home_dir
, "", name
+ 1);
2956 #if !defined(_AMIGA) && !defined(WINDOWS32)
2959 struct passwd
*pwent
;
2960 char *userend
= strchr (name
+ 1, '/');
2963 pwent
= getpwnam (name
+ 1);
2967 return xstrdup (pwent
->pw_dir
);
2969 return concat (pwent
->pw_dir
, "/", userend
+ 1);
2971 else if (userend
!= 0)
2974 #endif /* !AMIGA && !WINDOWS32 */
2979 /* Given a chain of struct nameseq's describing a sequence of filenames,
2980 in reverse of the intended order, return a new chain describing the
2981 result of globbing the filenames. The new chain is in forward order.
2982 The links of the old chain are freed or used in the new chain.
2983 Likewise for the names in the old chain.
2985 SIZE is how big to construct chain elements.
2986 This is useful if we want them actually to be other structures
2987 that have room for additional info. */
2990 multi_glob (struct nameseq
*chain
, unsigned int size
)
2992 extern void dir_setup_glob ();
2993 register struct nameseq
*new = 0;
2994 register struct nameseq
*old
;
2995 struct nameseq
*nexto
;
2998 dir_setup_glob (&gl
);
3000 for (old
= chain
; old
!= 0; old
= nexto
)
3008 if (old
->name
[0] == '~')
3010 char *newname
= tilde_expand (old
->name
);
3014 old
->name
= newname
;
3019 if (ar_name (old
->name
))
3021 /* OLD->name is an archive member reference.
3022 Replace it with the archive file name,
3023 and save the member name in MEMNAME.
3024 We will glob on the archive name and then
3025 reattach MEMNAME later. */
3027 ar_parse_name (old
->name
, &arname
, &memname
);
3033 #endif /* !NO_ARCHIVES */
3035 switch (glob (old
->name
, GLOB_NOCHECK
|GLOB_ALTDIRFUNC
, NULL
, &gl
))
3037 case 0: /* Success. */
3039 register int i
= gl
.gl_pathc
;
3045 /* Try to glob on MEMNAME within the archive. */
3046 struct nameseq
*found
3047 = ar_glob (gl
.gl_pathv
[i
], memname
, size
);
3050 /* No matches. Use MEMNAME as-is. */
3051 unsigned int alen
= strlen (gl
.gl_pathv
[i
]);
3052 unsigned int mlen
= strlen (memname
);
3054 = (struct nameseq
*) xmalloc (size
);
3055 if (size
> sizeof (struct nameseq
))
3056 bzero (((char *) elt
) + sizeof (struct nameseq
),
3057 size
- sizeof (struct nameseq
));
3058 elt
->name
= (char *) xmalloc (alen
+ 1 + mlen
+ 2);
3059 bcopy (gl
.gl_pathv
[i
], elt
->name
, alen
);
3060 elt
->name
[alen
] = '(';
3061 bcopy (memname
, &elt
->name
[alen
+ 1], mlen
);
3062 elt
->name
[alen
+ 1 + mlen
] = ')';
3063 elt
->name
[alen
+ 1 + mlen
+ 1] = '\0';
3069 /* Find the end of the FOUND chain. */
3070 struct nameseq
*f
= found
;
3071 while (f
->next
!= 0)
3074 /* Attach the chain being built to the end of the FOUND
3075 chain, and make FOUND the new NEW chain. */
3083 #endif /* !NO_ARCHIVES */
3085 struct nameseq
*elt
= (struct nameseq
*) xmalloc (size
);
3086 if (size
> sizeof (struct nameseq
))
3087 bzero (((char *) elt
) + sizeof (struct nameseq
),
3088 size
- sizeof (struct nameseq
));
3089 elt
->name
= xstrdup (gl
.gl_pathv
[i
]);
3101 fatal (NILF
, _("virtual memory exhausted"));