1 /* Reading and parsing of makefiles for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
5 This file is part of GNU Make.
7 GNU Make is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 2, or (at your option) any later version.
11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with
16 GNU Make; see the file COPYING. If not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
40 struct passwd
*getpwnam
PARAMS ((char *name
));
43 #endif /* !WINDOWS32 */
45 /* A 'struct ebuffer' controls the origin of the makefile we are currently
51 char *buffer
; /* Start of the current line in the buffer. */
52 char *bufnext
; /* Start of the next line in the buffer. */
53 char *bufstart
; /* Start of the entire buffer. */
54 unsigned int size
; /* Malloc'd size of buffer. */
55 FILE *fp
; /* File, or NULL if this is an internal buffer. */
56 struct floc floc
; /* Info on the file in fp (if any). */
59 /* Types of "words" that can be read in a makefile. */
62 w_bogus
, w_eol
, w_static
, w_variable
, w_colon
, w_dcolon
, w_semicolon
,
67 /* A `struct conditionals' contains the information describing
68 all the active conditionals in a makefile.
70 The global variable `conditionals' contains the conditionals
71 information for the current makefile. It is initialized from
72 the static structure `toplevel_conditionals' and is later changed
73 to new structures for included makefiles. */
77 unsigned int if_cmds
; /* Depth of conditional nesting. */
78 unsigned int allocated
; /* Elts allocated in following arrays. */
79 char *ignoring
; /* Are we ignoring or interpreting?
80 0=interpreting, 1=not yet interpreted,
81 2=already interpreted */
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
, int len
, 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
,
137 const struct floc
*flocp
));
138 static void record_target_var
PARAMS ((struct nameseq
*filenames
, char *defn
,
139 enum variable_origin origin
,
141 const struct floc
*flocp
));
142 static enum make_word_type get_next_mword
PARAMS ((char *buffer
, char *delim
,
143 char **startp
, unsigned int *length
));
144 static void remove_comments
PARAMS ((char *line
));
145 static char *find_char_unquote
PARAMS ((char *string
, int stop1
,
146 int stop2
, int blank
, int ignorevars
));
148 /* Read in all the makefiles and return the chain of their names. */
151 read_all_makefiles (char **makefiles
)
153 unsigned int num_makefiles
= 0;
155 /* Create *_LIST variables, to hold the makefiles, targets, and variables
156 we will be reading. */
158 define_variable ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", o_file
, 0);
160 DB (DB_BASIC
, (_("Reading makefiles...\n")));
162 /* If there's a non-null variable MAKEFILES, its value is a list of
163 files to read first thing. But don't let it prevent reading the
164 default makefiles and don't let the default goal come from there. */
172 /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
173 int save
= warn_undefined_variables_flag
;
174 warn_undefined_variables_flag
= 0;
176 value
= allocated_variable_expand ("$(MAKEFILES)");
178 warn_undefined_variables_flag
= save
;
181 /* Set NAME to the start of next token and LENGTH to its length.
182 MAKEFILES is updated for finding remaining tokens. */
185 while ((name
= find_next_token (&p
, &length
)) != 0)
189 eval_makefile (name
, RM_NO_DEFAULT_GOAL
|RM_INCLUDED
|RM_DONTCARE
);
195 /* Read makefiles specified with -f switches. */
198 while (*makefiles
!= 0)
200 struct dep
*tail
= read_makefiles
;
201 register struct dep
*d
;
203 if (! eval_makefile (*makefiles
, 0))
204 perror_with_name ("", *makefiles
);
206 /* Find the right element of read_makefiles. */
208 while (d
->next
!= tail
)
211 /* Use the storage read_makefile allocates. */
212 *makefiles
= dep_name (d
);
217 /* If there were no -f switches, try the default names. */
219 if (num_makefiles
== 0)
221 static char *default_makefiles
[] =
223 /* all lower case since readdir() (the vms version) 'lowercasifies' */
224 { "makefile.vms", "gnumakefile.", "makefile.", 0 };
227 { "GNUmakefile", "Makefile", "SMakefile", 0 };
228 #else /* !Amiga && !VMS */
229 { "GNUmakefile", "makefile", "Makefile", 0 };
232 register char **p
= default_makefiles
;
233 while (*p
!= 0 && !file_exists_p (*p
))
238 if (! eval_makefile (*p
, 0))
239 perror_with_name ("", *p
);
243 /* No default makefile was found. Add the default makefiles to the
244 `read_makefiles' chain so they will be updated if possible. */
245 struct dep
*tail
= read_makefiles
;
246 /* Add them to the tail, after any MAKEFILES variable makefiles. */
247 while (tail
!= 0 && tail
->next
!= 0)
249 for (p
= default_makefiles
; *p
!= 0; ++p
)
251 struct dep
*d
= alloc_dep ();
252 d
->file
= enter_file (*p
);
253 d
->file
->dontcare
= 1;
254 /* Tell update_goal_chain to bail out as soon as this file is
255 made, and main not to die if we can't make this file. */
256 d
->changed
= RM_DONTCARE
;
268 return read_makefiles
;
271 /* Install a new conditional and return the previous one. */
273 static struct conditionals
*
274 install_conditionals (struct conditionals
*new)
276 struct conditionals
*save
= conditionals
;
278 bzero ((char *) new, sizeof (*new));
284 /* Free the current conditionals and reinstate a saved one. */
287 restore_conditionals (struct conditionals
*saved
)
289 /* Free any space allocated by conditional_line. */
290 if (conditionals
->ignoring
)
291 free (conditionals
->ignoring
);
292 if (conditionals
->seen_else
)
293 free (conditionals
->seen_else
);
296 conditionals
= saved
;
300 eval_makefile (char *filename
, int flags
)
304 const struct floc
*curfile
;
310 ebuf
.floc
.filenm
= strcache_add (filename
);
311 ebuf
.floc
.lineno
= 1;
313 if (ISDB (DB_VERBOSE
))
315 printf (_("Reading makefile `%s'"), filename
);
316 if (flags
& RM_NO_DEFAULT_GOAL
)
317 printf (_(" (no default goal)"));
318 if (flags
& RM_INCLUDED
)
319 printf (_(" (search path)"));
320 if (flags
& RM_DONTCARE
)
321 printf (_(" (don't care)"));
322 if (flags
& RM_NO_TILDE
)
323 printf (_(" (no ~ expansion)"));
327 /* First, get a stream to read. */
329 /* Expand ~ in FILENAME unless it came from `include',
330 in which case it was already done. */
331 if (!(flags
& RM_NO_TILDE
) && filename
[0] == '~')
333 expanded
= tilde_expand (filename
);
338 ebuf
.fp
= fopen (filename
, "r");
339 /* Save the error code so we print the right message later. */
340 makefile_errno
= errno
;
342 /* If the makefile wasn't found and it's either a makefile from
343 the `MAKEFILES' variable or an included makefile,
344 search the included makefile search path for this makefile. */
345 if (ebuf
.fp
== 0 && (flags
& RM_INCLUDED
) && *filename
!= '/')
347 register unsigned int i
;
348 for (i
= 0; include_directories
[i
] != 0; ++i
)
350 included
= concat (include_directories
[i
], "/", filename
);
351 ebuf
.fp
= fopen (included
, "r");
359 /* If we're not using it, we already freed it above. */
360 if (filename
!= included
)
364 /* Add FILENAME to the chain of read makefiles. */
366 deps
->next
= read_makefiles
;
367 read_makefiles
= deps
;
368 deps
->file
= lookup_file (filename
);
370 deps
->file
= enter_file (xstrdup (filename
));
371 filename
= deps
->file
->name
;
372 deps
->changed
= flags
;
373 if (flags
& RM_DONTCARE
)
374 deps
->file
->dontcare
= 1;
381 /* If the makefile can't be found at all, give up entirely. */
385 /* If we did some searching, errno has the error from the last
386 attempt, rather from FILENAME itself. Restore it in case the
387 caller wants to use it in a message. */
388 errno
= makefile_errno
;
392 /* Add this makefile to the list. */
393 do_variable_definition (&ebuf
.floc
, "MAKEFILE_LIST", filename
, o_file
,
396 /* Evaluate the makefile */
399 ebuf
.buffer
= ebuf
.bufnext
= ebuf
.bufstart
= xmalloc (ebuf
.size
);
401 curfile
= reading_file
;
402 reading_file
= &ebuf
.floc
;
404 r
= eval (&ebuf
, !(flags
& RM_NO_DEFAULT_GOAL
));
406 reading_file
= curfile
;
410 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
;
448 /* Read file FILENAME as a makefile and add its contents to the data base.
450 SET_DEFAULT is true if we are allowed to set the default goal. */
454 eval (struct ebuffer
*ebuf
, int set_default
)
457 unsigned int collapsed_length
= 0;
458 unsigned int commands_len
= 200;
460 unsigned int commands_idx
= 0;
461 unsigned int cmds_started
, tgts_started
;
462 int ignoring
= 0, in_ignored_define
= 0;
463 int no_targets
= 0; /* Set when reading a rule without targets. */
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, \
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);
508 unsigned int linelen
;
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
)
619 int i
= conditional_line (p
, len
, fstart
);
623 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
);
800 /* If no filenames, it's a no-op. */
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)));
836 error (fstart
, "%s: %s", name
, strerror (errno
));
840 /* Restore conditional state. */
841 restore_conditionals (save
);
846 if (try_variable_definition (fstart
, p
, o_file
, 0))
847 /* This line has been dealt with. */
850 /* This line starts with a tab but was not caught above because there
851 was no preceding target, and the line might have been usable as a
852 variable definition. But now we know it is definitely lossage. */
854 fatal(fstart
, _("commands commence before first target"));
856 /* This line describes some target files. This is complicated by
857 the existence of target-specific variables, because we can't
858 expand the entire line until we know if we have one or not. So
859 we expand the line word by word until we find the first `:',
860 then check to see if it's a target-specific variable.
862 In this algorithm, `lb_next' will point to the beginning of the
863 unexpanded parts of the input buffer, while `p2' points to the
864 parts of the expanded buffer we haven't searched yet. */
867 enum make_word_type wtype
;
868 enum variable_origin v_origin
;
870 char *cmdleft
, *semip
, *lb_next
;
871 unsigned int len
, plen
= 0;
873 const char *end
, *beg
; /* Helpers for whitespace stripping. */
875 /* Record the previous rule. */
877 record_waiting_files ();
878 tgts_started
= fstart
->lineno
;
880 /* Search the line for an unquoted ; that is not after an
882 cmdleft
= find_char_unquote (line
, ';', '#', 0, 1);
883 if (cmdleft
!= 0 && *cmdleft
== '#')
885 /* We found a comment before a semicolon. */
889 else if (cmdleft
!= 0)
890 /* Found one. Cut the line short there before expanding it. */
894 collapse_continuations (line
);
896 /* We can't expand the entire line, since if it's a per-target
897 variable we don't want to expand it. So, walk from the
898 beginning, expanding as we go, and looking for "interesting"
899 chars. The first word is always expandable. */
900 wtype
= get_next_mword(line
, NULL
, &lb_next
, &len
);
905 fatal(fstart
, _("missing rule before commands"));
906 /* This line contained something but turned out to be nothing
907 but whitespace (a comment?). */
912 /* We accept and ignore rules without targets for
913 compatibility with SunOS 4 make. */
921 p2
= variable_expand_string(NULL
, lb_next
, len
);
928 /* Look for a semicolon in the expanded line. */
929 cmdleft
= find_char_unquote (p2
, ';', 0, 0, 0);
933 unsigned long p2_off
= p2
- variable_buffer
;
934 unsigned long cmd_off
= cmdleft
- variable_buffer
;
935 char *pend
= p2
+ strlen(p2
);
937 /* Append any remnants of lb, then cut the line short
941 /* One school of thought says that you shouldn't expand
942 here, but merely copy, since now you're beyond a ";"
943 and into a command script. However, the old parser
944 expanded the whole line, so we continue that for
945 backwards-compatiblity. Also, it wouldn't be
946 entirely consistent, since we do an unconditional
947 expand below once we know we don't have a
948 target-specific variable. */
949 (void)variable_expand_string(pend
, lb_next
, (long)-1);
950 lb_next
+= strlen(lb_next
);
951 p2
= variable_buffer
+ p2_off
;
952 cmdleft
= variable_buffer
+ cmd_off
+ 1;
956 colonp
= find_char_unquote(p2
, ':', 0, 0, 0);
957 #ifdef HAVE_DOS_PATHS
958 /* The drive spec brain-damage strikes again... */
959 /* Note that the only separators of targets in this context
960 are whitespace and a left paren. If others are possible,
961 they should be added to the string in the call to index. */
962 while (colonp
&& (colonp
[1] == '/' || colonp
[1] == '\\') &&
963 colonp
> p2
&& isalpha ((unsigned char)colonp
[-1]) &&
964 (colonp
== p2
+ 1 || strchr (" \t(", colonp
[-2]) != 0))
965 colonp
= find_char_unquote(colonp
+ 1, ':', 0, 0, 0);
970 wtype
= get_next_mword(lb_next
, NULL
, &lb_next
, &len
);
976 p2
= variable_expand_string(p2
, lb_next
, len
);
977 /* We don't need to worry about cmdleft here, because if it was
978 found in the variable_buffer the entire buffer has already
979 been expanded... we'll never get here. */
982 p2
= next_token (variable_buffer
);
984 /* If the word we're looking at is EOL, see if there's _anything_
985 on the line. If not, a variable expanded to nothing, so ignore
986 it. If so, we can't parse this line so punt. */
990 /* There's no need to be ivory-tower about this: check for
991 one of the most common bugs found in makefiles... */
992 fatal (fstart
, _("missing separator%s"),
993 !strneq(line
, " ", 8) ? ""
994 : _(" (did you mean TAB instead of 8 spaces?)"));
998 /* Make the colon the end-of-string so we know where to stop
999 looking for targets. */
1001 filenames
= multi_glob (parse_file_seq (&p2
, '\0',
1002 sizeof (struct nameseq
),
1004 sizeof (struct nameseq
));
1009 /* We accept and ignore rules without targets for
1010 compatibility with SunOS 4 make. */
1014 /* This should never be possible; we handled it above. */
1015 assert (*p2
!= '\0');
1018 /* Is this a one-colon or two-colon entry? */
1019 two_colon
= *p2
== ':';
1023 /* Test to see if it's a target-specific variable. Copy the rest
1024 of the buffer over, possibly temporarily (we'll expand it later
1025 if it's not a target-specific variable). PLEN saves the length
1026 of the unparsed section of p2, for later. */
1027 if (*lb_next
!= '\0')
1029 unsigned int l
= p2
- variable_buffer
;
1031 (void) variable_buffer_output (p2
+plen
,
1032 lb_next
, strlen (lb_next
)+1);
1033 p2
= variable_buffer
+ l
;
1036 /* See if it's an "override" or "export" keyword; if so see if what
1037 comes after it looks like a variable definition. */
1039 wtype
= get_next_mword (p2
, NULL
, &p
, &len
);
1043 if (wtype
== w_static
)
1045 if (word1eq ("override"))
1047 v_origin
= o_override
;
1048 wtype
= get_next_mword (p
+len
, NULL
, &p
, &len
);
1050 else if (word1eq ("export"))
1053 wtype
= get_next_mword (p
+len
, NULL
, &p
, &len
);
1058 wtype
= get_next_mword (p
+len
, NULL
, NULL
, NULL
);
1060 if (wtype
== w_varassign
)
1062 /* If there was a semicolon found, add it back, plus anything
1066 unsigned int l
= p
- variable_buffer
;
1068 variable_buffer_output (p2
+ strlen (p2
),
1069 semip
, strlen (semip
)+1);
1070 p
= variable_buffer
+ l
;
1072 record_target_var (filenames
, p
, v_origin
, exported
, fstart
);
1077 /* This is a normal target, _not_ a target-specific variable.
1078 Unquote any = in the dependency list. */
1079 find_char_unquote (lb_next
, '=', 0, 0, 0);
1081 /* We have some targets, so don't ignore the following commands. */
1084 /* Expand the dependencies, etc. */
1085 if (*lb_next
!= '\0')
1087 unsigned int l
= p2
- variable_buffer
;
1088 (void) variable_expand_string (p2
+ plen
, lb_next
, (long)-1);
1089 p2
= variable_buffer
+ l
;
1091 /* Look for a semicolon in the expanded line. */
1094 cmdleft
= find_char_unquote (p2
, ';', 0, 0, 0);
1096 *(cmdleft
++) = '\0';
1100 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
1101 p
= strchr (p2
, ':');
1102 while (p
!= 0 && p
[-1] == '\\')
1104 register char *q
= &p
[-1];
1105 register int backslash
= 0;
1106 while (*q
-- == '\\')
1107 backslash
= !backslash
;
1109 p
= strchr (p
+ 1, ':');
1114 /* Here, the situation is quite complicated. Let's have a look
1115 at a couple of targets:
1123 The rule is that it's only a target, if there are TWO :'s
1124 OR a space around the :.
1126 if (p
&& !(isspace ((unsigned char)p
[1]) || !p
[1]
1127 || isspace ((unsigned char)p
[-1])))
1130 #ifdef HAVE_DOS_PATHS
1136 /* For DOS-style paths, skip a "C:\..." or a "C:/..." */
1137 if (p
!= 0 && (p
[1] == '\\' || p
[1] == '/') &&
1138 isalpha ((unsigned char)p
[-1]) &&
1139 (p
== p2
+ 1 || strchr (" \t:(", p
[-2]) != 0)) {
1140 p
= strchr (p
+ 1, ':');
1143 } while (check_again
);
1148 struct nameseq
*target
;
1149 target
= parse_file_seq (&p2
, ':', sizeof (struct nameseq
), 1);
1152 fatal (fstart
, _("missing target pattern"));
1153 else if (target
->next
!= 0)
1154 fatal (fstart
, _("multiple target patterns"));
1155 pattern
= target
->name
;
1156 pattern_percent
= find_percent (pattern
);
1157 if (pattern_percent
== 0)
1158 fatal (fstart
, _("target pattern contains no `%%'"));
1159 free ((char *)target
);
1164 /* Strip leading and trailing whitespaces. */
1166 end
= beg
+ strlen (beg
) - 1;
1167 strip_whitespace (&beg
, &end
);
1169 if (beg
<= end
&& *beg
!= '\0')
1171 /* Put all the prerequisites here; they'll be parsed later. */
1172 deps
= alloc_dep ();
1173 deps
->name
= savestring (beg
, end
- beg
+ 1);
1181 /* Semicolon means rest of line is a command. */
1182 unsigned int len
= strlen (cmdleft
);
1184 cmds_started
= fstart
->lineno
;
1186 /* Add this command line to the buffer. */
1187 if (len
+ 2 > commands_len
)
1189 commands_len
= (len
+ 2) * 2;
1190 commands
= (char *) xrealloc (commands
, commands_len
);
1192 bcopy (cmdleft
, commands
, len
);
1193 commands_idx
+= len
;
1194 commands
[commands_idx
++] = '\n';
1197 /* Determine if this target should be made default. We used to do
1198 this in record_files() but because of the delayed target recording
1199 and because preprocessor directives are legal in target's commands
1200 it is too late. Consider this fragment for example:
1204 ifeq ($(.DEFAULT_GOAL),foo)
1208 Because the target is not recorded until after ifeq directive is
1209 evaluated the .DEFAULT_GOAL does not contain foo yet as one
1210 would expect. Because of this we have to move some of the logic
1213 if (**default_goal_name
== '\0' && set_default
)
1217 struct nameseq
*t
= filenames
;
1219 for (; t
!= 0; t
= t
->next
)
1224 /* We have nothing to do if this is an implicit rule. */
1225 if (strchr (name
, '%') != 0)
1228 /* See if this target's name does not start with a `.',
1229 unless it contains a slash. */
1230 if (*name
== '.' && strchr (name
, '/') == 0
1231 #ifdef HAVE_DOS_PATHS
1232 && strchr (name
, '\\') == 0
1238 /* If this file is a suffix, don't let it be
1239 the default goal file. */
1240 for (d
= suffix_file
->deps
; d
!= 0; d
= d
->next
)
1242 register struct dep
*d2
;
1243 if (*dep_name (d
) != '.' && streq (name
, dep_name (d
)))
1248 for (d2
= suffix_file
->deps
; d2
!= 0; d2
= d2
->next
)
1250 register unsigned int len
= strlen (dep_name (d2
));
1251 if (!strneq (name
, dep_name (d2
), len
))
1253 if (streq (name
+ len
, dep_name (d
)))
1266 define_variable_global (".DEFAULT_GOAL", 13, t
->name
,
1276 /* We get here except in the case that we just read a rule line.
1277 Record now the last rule we read, so following spurious
1278 commands are properly diagnosed. */
1280 record_waiting_files ();
1285 if (conditionals
->if_cmds
)
1286 fatal (fstart
, _("missing `endif'"));
1288 /* At eof, record the last rule. */
1289 record_waiting_files ();
1292 free ((char *) collapsed
);
1293 free ((char *) commands
);
1299 /* Remove comments from LINE.
1300 This is done by copying the text at LINE onto itself. */
1303 remove_comments (char *line
)
1307 comment
= find_char_unquote (line
, '#', 0, 0, 0);
1310 /* Cut off the line at the #. */
1314 /* Execute a `define' directive.
1315 The first line has already been read, and NAME is the name of
1316 the variable to be defined. The following lines remain to be read. */
1319 do_define (char *name
, unsigned int namelen
,
1320 enum variable_origin origin
, struct ebuffer
*ebuf
)
1322 struct floc defstart
;
1325 unsigned int length
= 100;
1326 char *definition
= (char *) xmalloc (length
);
1327 unsigned int idx
= 0;
1330 /* Expand the variable name. */
1331 char *var
= (char *) alloca (namelen
+ 1);
1332 bcopy (name
, var
, namelen
);
1333 var
[namelen
] = '\0';
1334 var
= variable_expand (var
);
1336 defstart
= ebuf
->floc
;
1343 nlines
= readline (ebuf
);
1344 ebuf
->floc
.lineno
+= nlines
;
1346 /* If there is nothing left to eval, we're done. */
1350 line
= ebuf
->buffer
;
1352 collapse_continuations (line
);
1354 /* If the line doesn't begin with a tab, test to see if it introduces
1355 another define, or ends one. */
1357 /* Stop if we find an 'endef' */
1358 if (line
[0] != '\t')
1360 p
= next_token (line
);
1363 /* If this is another 'define', increment the level count. */
1364 if ((len
== 6 || (len
> 6 && isblank ((unsigned char)p
[6])))
1365 && strneq (p
, "define", 6))
1368 /* If this is an 'endef', decrement the count. If it's now 0,
1369 we've found the last one. */
1370 else if ((len
== 5 || (len
> 5 && isblank ((unsigned char)p
[5])))
1371 && strneq (p
, "endef", 5))
1374 remove_comments (p
);
1375 if (*next_token (p
) != '\0')
1377 _("Extraneous text after `endef' directive"));
1381 /* Define the variable. */
1383 definition
[0] = '\0';
1385 definition
[idx
- 1] = '\0';
1387 /* Always define these variables in the global set. */
1388 define_variable_global (var
, strlen (var
), definition
,
1389 origin
, 1, &defstart
);
1396 /* Otherwise add this line to the variable definition. */
1397 len
= strlen (line
);
1398 if (idx
+ len
+ 1 > length
)
1400 length
= (idx
+ len
) * 2;
1401 definition
= (char *) xrealloc (definition
, length
+ 1);
1404 bcopy (line
, &definition
[idx
], len
);
1406 /* Separate lines with a newline. */
1407 definition
[idx
++] = '\n';
1411 fatal (&defstart
, _("missing `endef', unterminated `define'"));
1417 /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
1418 "ifneq", "else" and "endif".
1419 LINE is the input line, with the command as its first word.
1421 FILENAME and LINENO are the filename and line number in the
1422 current makefile. They are used for error messages.
1424 Value is -2 if the line is not a conditional at all,
1425 -1 if the line is an invalid conditional,
1426 0 if following text should be interpreted,
1427 1 if following text should be ignored. */
1430 conditional_line (char *line
, int len
, const struct floc
*flocp
)
1433 enum { c_ifdef
, c_ifndef
, c_ifeq
, c_ifneq
, c_else
, c_endif
} cmdtype
;
1437 /* Compare a word, both length and contents. */
1438 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
1439 #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
1441 /* Make sure this line is a conditional. */
1442 chkword ("ifdef", c_ifdef
)
1443 else chkword ("ifndef", c_ifndef
)
1444 else chkword ("ifeq", c_ifeq
)
1445 else chkword ("ifneq", c_ifneq
)
1446 else chkword ("else", c_else
)
1447 else chkword ("endif", c_endif
)
1451 /* Found one: skip past it and any whitespace after it. */
1452 line
= next_token (line
+ len
);
1454 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
1456 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
1457 if (cmdtype
== c_endif
)
1462 if (!conditionals
->if_cmds
)
1463 fatal (flocp
, _("extraneous `%s'"), cmdname
);
1465 --conditionals
->if_cmds
;
1470 /* An 'else' statement can either be simple, or it can have another
1471 conditional after it. */
1472 if (cmdtype
== c_else
)
1476 if (!conditionals
->if_cmds
)
1477 fatal (flocp
, _("extraneous `%s'"), cmdname
);
1479 o
= conditionals
->if_cmds
- 1;
1481 if (conditionals
->seen_else
[o
])
1482 fatal (flocp
, _("only one `else' per conditional"));
1484 /* Change the state of ignorance. */
1485 switch (conditionals
->ignoring
[o
])
1488 /* We've just been interpreting. Never do it again. */
1489 conditionals
->ignoring
[o
] = 2;
1492 /* We've never interpreted yet. Maybe this time! */
1493 conditionals
->ignoring
[o
] = 0;
1497 /* It's a simple 'else'. */
1500 conditionals
->seen_else
[o
] = 1;
1504 /* The 'else' has extra text. That text must be another conditional
1505 and cannot be an 'else' or 'endif'. */
1507 /* Find the length of the next word. */
1508 for (p
= line
+1; *p
!= '\0' && !isspace ((unsigned char)*p
); ++p
)
1512 /* If it's 'else' or 'endif' or an illegal conditional, fail. */
1513 if (word1eq("else") || word1eq("endif")
1514 || conditional_line (line
, len
, flocp
) < 0)
1518 /* conditional_line() created a new level of conditional.
1519 Raise it back to this level. */
1520 if (conditionals
->ignoring
[o
] < 2)
1521 conditionals
->ignoring
[o
] = conditionals
->ignoring
[o
+1];
1522 --conditionals
->if_cmds
;
1528 if (conditionals
->allocated
== 0)
1530 conditionals
->allocated
= 5;
1531 conditionals
->ignoring
= (char *) xmalloc (conditionals
->allocated
);
1532 conditionals
->seen_else
= (char *) xmalloc (conditionals
->allocated
);
1535 o
= conditionals
->if_cmds
++;
1536 if (conditionals
->if_cmds
> conditionals
->allocated
)
1538 conditionals
->allocated
+= 5;
1539 conditionals
->ignoring
= (char *)
1540 xrealloc (conditionals
->ignoring
, conditionals
->allocated
);
1541 conditionals
->seen_else
= (char *)
1542 xrealloc (conditionals
->seen_else
, conditionals
->allocated
);
1545 /* Record that we have seen an `if...' but no `else' so far. */
1546 conditionals
->seen_else
[o
] = 0;
1548 /* Search through the stack to see if we're already ignoring. */
1549 for (i
= 0; i
< o
; ++i
)
1550 if (conditionals
->ignoring
[i
])
1552 /* We are already ignoring, so just push a level to match the next
1553 "else" or "endif", and keep ignoring. We don't want to expand
1554 variables in the condition. */
1555 conditionals
->ignoring
[o
] = 1;
1559 if (cmdtype
== c_ifdef
|| cmdtype
== c_ifndef
)
1565 /* Expand the thing we're looking up, so we can use indirect and
1566 constructed variable names. */
1567 var
= allocated_variable_expand (line
);
1569 /* Make sure there's only one variable name to test. */
1570 p
= end_of_token (var
);
1577 v
= lookup_variable (var
, i
);
1579 conditionals
->ignoring
[o
] =
1580 ((v
!= 0 && *v
->value
!= '\0') == (cmdtype
== c_ifndef
));
1586 /* "Ifeq" or "ifneq". */
1589 char termin
= *line
== '(' ? ',' : *line
;
1591 if (termin
!= ',' && termin
!= '"' && termin
!= '\'')
1595 /* Find the end of the first string. */
1599 for (; *line
!= '\0'; ++line
)
1602 else if (*line
== ')')
1604 else if (*line
== ',' && count
<= 0)
1608 while (*line
!= '\0' && *line
!= termin
)
1616 /* Strip blanks after the first string. */
1618 while (isblank ((unsigned char)p
[-1]))
1625 s2
= variable_expand (s1
);
1626 /* We must allocate a new copy of the expanded string because
1627 variable_expand re-uses the same buffer. */
1629 s1
= (char *) alloca (len
+ 1);
1630 bcopy (s2
, s1
, len
+ 1);
1633 /* Find the start of the second string. */
1634 line
= next_token (line
);
1636 termin
= termin
== ',' ? ')' : *line
;
1637 if (termin
!= ')' && termin
!= '"' && termin
!= '\'')
1640 /* Find the end of the second string. */
1643 register int count
= 0;
1644 s2
= next_token (line
);
1645 for (line
= s2
; *line
!= '\0'; ++line
)
1649 else if (*line
== ')')
1662 while (*line
!= '\0' && *line
!= termin
)
1670 line
= next_token (++line
);
1674 s2
= variable_expand (s2
);
1675 conditionals
->ignoring
[o
] = (streq (s1
, s2
) == (cmdtype
== c_ifneq
));
1679 /* Search through the stack to see if we're ignoring. */
1680 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
1681 if (conditionals
->ignoring
[i
])
1686 /* Remove duplicate dependencies in CHAIN. */
1688 static unsigned long
1689 dep_hash_1 (const void *key
)
1691 return_STRING_HASH_1 (dep_name ((struct dep
const *) key
));
1694 static unsigned long
1695 dep_hash_2 (const void *key
)
1697 return_STRING_HASH_2 (dep_name ((struct dep
const *) key
));
1701 dep_hash_cmp (const void *x
, const void *y
)
1703 struct dep
*dx
= (struct dep
*) x
;
1704 struct dep
*dy
= (struct dep
*) y
;
1705 int cmp
= strcmp (dep_name (dx
), dep_name (dy
));
1707 /* If the names are the same but ignore_mtimes are not equal, one of these
1708 is an order-only prerequisite and one isn't. That means that we should
1709 remove the one that isn't and keep the one that is. */
1711 if (!cmp
&& dx
->ignore_mtime
!= dy
->ignore_mtime
)
1712 dx
->ignore_mtime
= dy
->ignore_mtime
= 0;
1719 uniquize_deps (struct dep
*chain
)
1721 struct hash_table deps
;
1722 register struct dep
**depp
;
1724 hash_init (&deps
, 500, dep_hash_1
, dep_hash_2
, dep_hash_cmp
);
1726 /* Make sure that no dependencies are repeated. This does not
1727 really matter for the purpose of updating targets, but it
1728 might make some names be listed twice for $^ and $?. */
1733 struct dep
*dep
= *depp
;
1734 struct dep
**dep_slot
= (struct dep
**) hash_find_slot (&deps
, dep
);
1735 if (HASH_VACANT (*dep_slot
))
1737 hash_insert_at (&deps
, dep
, dep_slot
);
1742 /* Don't bother freeing duplicates.
1743 It's dangerous and little benefit accrues. */
1748 hash_free (&deps
, 0);
1751 /* Record target-specific variable values for files FILENAMES.
1752 TWO_COLON is nonzero if a double colon was used.
1754 The links of FILENAMES are freed, and so are any names in it
1755 that are not incorporated into other data structures.
1757 If the target is a pattern, add the variable to the pattern-specific
1758 variable value list. */
1761 record_target_var (struct nameseq
*filenames
, char *defn
,
1762 enum variable_origin origin
, int exported
,
1763 const struct floc
*flocp
)
1765 struct nameseq
*nextf
;
1766 struct variable_set_list
*global
;
1768 global
= current_variable_set_list
;
1770 /* If the variable is an append version, store that but treat it as a
1771 normal recursive variable. */
1773 for (; filenames
!= 0; filenames
= nextf
)
1776 register char *name
= filenames
->name
;
1779 struct pattern_var
*p
;
1781 nextf
= filenames
->next
;
1782 free ((char *) filenames
);
1784 /* If it's a pattern target, then add it to the pattern-specific
1786 percent
= find_percent (name
);
1789 /* Get a reference for this pattern-specific variable struct. */
1790 p
= create_pattern_var (name
, percent
);
1791 p
->variable
.fileinfo
= *flocp
;
1792 /* I don't think this can fail since we already determined it was a
1793 variable definition. */
1794 v
= parse_variable_definition (&p
->variable
, defn
);
1797 if (v
->flavor
== f_simple
)
1798 v
->value
= allocated_variable_expand (v
->value
);
1800 v
->value
= xstrdup (v
->value
);
1808 /* Get a file reference for this file, and initialize it.
1809 We don't want to just call enter_file() because that allocates a
1810 new entry if the file is a double-colon, which we don't want in
1812 f
= lookup_file (name
);
1814 f
= enter_file (name
);
1815 else if (f
->double_colon
)
1816 f
= f
->double_colon
;
1818 initialize_file_variables (f
, 1);
1821 current_variable_set_list
= f
->variables
;
1822 v
= try_variable_definition (flocp
, defn
, origin
, 1);
1824 error (flocp
, _("Malformed target-specific variable definition"));
1825 current_variable_set_list
= global
;
1828 /* Set up the variable to be *-specific. */
1831 v
->export
= exported
? v_export
: v_default
;
1833 /* If it's not an override, check to see if there was a command-line
1834 setting. If so, reset the value. */
1835 if (origin
!= o_override
)
1837 struct variable
*gv
;
1838 int len
= strlen(v
->name
);
1840 gv
= lookup_variable (v
->name
, len
);
1841 if (gv
&& (gv
->origin
== o_env_override
|| gv
->origin
== o_command
))
1845 v
->value
= xstrdup (gv
->value
);
1846 v
->origin
= gv
->origin
;
1847 v
->recursive
= gv
->recursive
;
1852 /* Free name if not needed further. */
1853 if (name
!= fname
&& (name
< fname
|| name
> fname
+ strlen (fname
)))
1858 /* Record a description line for files FILENAMES,
1859 with dependencies DEPS, commands to execute described
1860 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
1861 TWO_COLON is nonzero if a double colon was used.
1862 If not nil, PATTERN is the `%' pattern to make this
1863 a static pattern rule, and PATTERN_PERCENT is a pointer
1864 to the `%' within it.
1866 The links of FILENAMES are freed, and so are any names in it
1867 that are not incorporated into other data structures. */
1870 record_files (struct nameseq
*filenames
, char *pattern
, char *pattern_percent
,
1871 struct dep
*deps
, unsigned int cmds_started
, char *commands
,
1872 unsigned int commands_idx
, int two_colon
,
1873 const struct floc
*flocp
)
1875 struct nameseq
*nextf
;
1877 unsigned int max_targets
= 0, target_idx
= 0;
1878 char **targets
= 0, **target_percents
= 0;
1879 struct commands
*cmds
;
1881 /* If we've already snapped deps, that means we're in an eval being
1882 resolved after the makefiles have been read in. We can't add more rules
1883 at this time, since they won't get snapped and we'll get core dumps.
1884 See Savannah bug # 12124. */
1886 fatal (flocp
, _("prerequisites cannot be defined in command scripts"));
1888 if (commands_idx
> 0)
1890 cmds
= (struct commands
*) xmalloc (sizeof (struct commands
));
1891 cmds
->fileinfo
.filenm
= flocp
->filenm
;
1892 cmds
->fileinfo
.lineno
= cmds_started
;
1893 cmds
->commands
= savestring (commands
, commands_idx
);
1894 cmds
->command_lines
= 0;
1899 for (; filenames
!= 0; filenames
= nextf
)
1901 char *name
= filenames
->name
;
1903 struct dep
*this = 0;
1904 char *implicit_percent
;
1906 nextf
= filenames
->next
;
1909 /* Check for special targets. Do it here instead of, say, snap_deps()
1910 so that we can immediately use the value. */
1912 if (streq (name
, ".POSIX"))
1914 else if (streq (name
, ".SECONDEXPANSION"))
1915 second_expansion
= 1;
1917 implicit_percent
= find_percent (name
);
1918 implicit
|= implicit_percent
!= 0;
1920 if (implicit
&& pattern
!= 0)
1921 fatal (flocp
, _("mixed implicit and static pattern rules"));
1923 if (implicit
&& implicit_percent
== 0)
1924 fatal (flocp
, _("mixed implicit and normal rules"));
1931 targets
= (char **) xmalloc (5 * sizeof (char *));
1932 target_percents
= (char **) xmalloc (5 * sizeof (char *));
1935 else if (target_idx
== max_targets
- 1)
1938 targets
= (char **) xrealloc ((char *) targets
,
1939 max_targets
* sizeof (char *));
1941 = (char **) xrealloc ((char *) target_percents
,
1942 max_targets
* sizeof (char *));
1944 targets
[target_idx
] = name
;
1945 target_percents
[target_idx
] = implicit_percent
;
1950 /* If this is a static pattern rule:
1951 `targets: target%pattern: dep%pattern; cmds',
1952 make sure the pattern matches this target name. */
1953 if (pattern
&& !pattern_matches (pattern
, pattern_percent
, name
))
1954 error (flocp
, _("target `%s' doesn't match the target pattern"), name
);
1957 /* If there are multiple filenames, copy the chain DEPS for all but
1958 the last one. It is not safe for the same deps to go in more
1959 than one place in the database. */
1960 this = nextf
!= 0 ? copy_dep_chain (deps
) : deps
;
1961 this->need_2nd_expansion
= (second_expansion
1962 && strchr (this->name
, '$'));
1967 /* Single-colon. Combine these dependencies
1968 with others in file's existing record, if any. */
1969 f
= enter_file (name
);
1971 if (f
->double_colon
)
1973 _("target file `%s' has both : and :: entries"), f
->name
);
1975 /* If CMDS == F->CMDS, this target was listed in this rule
1976 more than once. Just give a warning since this is harmless. */
1977 if (cmds
!= 0 && cmds
== f
->cmds
)
1979 _("target `%s' given more than once in the same rule."),
1982 /* Check for two single-colon entries both with commands.
1983 Check is_target so that we don't lose on files such as .c.o
1984 whose commands were preinitialized. */
1985 else if (cmds
!= 0 && f
->cmds
!= 0 && f
->is_target
)
1987 error (&cmds
->fileinfo
,
1988 _("warning: overriding commands for target `%s'"),
1990 error (&f
->cmds
->fileinfo
,
1991 _("warning: ignoring old commands for target `%s'"),
1997 /* Defining .DEFAULT with no deps or cmds clears it. */
1998 if (f
== default_file
&& this == 0 && cmds
== 0)
2003 /* Defining .SUFFIXES with no dependencies clears out the list of
2005 if (f
== suffix_file
&& this == 0)
2007 free_dep_chain (f
->deps
);
2012 /* Add the file's old deps and the new ones in THIS together. */
2016 struct dep
**d_ptr
= &f
->deps
;
2018 while ((*d_ptr
)->next
!= 0)
2019 d_ptr
= &(*d_ptr
)->next
;
2022 /* This is the rule with commands, so put its deps
2023 last. The rationale behind this is that $< expands to
2024 the first dep in the chain, and commands use $<
2025 expecting to get the dep that rule specifies. However
2026 the second expansion algorithm reverses the order thus
2027 we need to make it last here. */
2028 (*d_ptr
)->next
= this;
2031 /* This is the rule without commands. Put its
2032 dependencies at the end but before dependencies from
2033 the rule with commands (if any). This way everything
2034 appears in makefile order. */
2038 this->next
= *d_ptr
;
2042 (*d_ptr
)->next
= this;
2048 /* This is a hack. I need a way to communicate to snap_deps()
2049 that the last dependency line in this file came with commands
2050 (so that logic in snap_deps() can put it in front and all
2051 this $< -logic works). I cannot simply rely on file->cmds
2052 being not 0 because of the cases like the following:
2058 I am going to temporarily "borrow" UPDATING member in
2059 `struct file' for this. */
2067 /* Double-colon. Make a new record even if there already is one. */
2068 f
= lookup_file (name
);
2070 /* Check for both : and :: rules. Check is_target so
2071 we don't lose on default suffix rules or makefiles. */
2072 if (f
!= 0 && f
->is_target
&& !f
->double_colon
)
2074 _("target file `%s' has both : and :: entries"), f
->name
);
2075 f
= enter_file (name
);
2076 /* If there was an existing entry and it was a double-colon entry,
2077 enter_file will have returned a new one, making it the prev
2078 pointer of the old one, and setting its double_colon pointer to
2080 if (f
->double_colon
== 0)
2081 /* This is the first entry for this name, so we must set its
2082 double_colon pointer to itself. */
2083 f
->double_colon
= f
;
2089 /* If this is a static pattern rule, set the stem to the part of its
2090 name that matched the `%' in the pattern, so you can use $* in the
2094 static char *percent
= "%";
2095 char *buffer
= variable_expand ("");
2096 char *o
= patsubst_expand (buffer
, name
, pattern
, percent
,
2097 pattern_percent
+1, percent
+1);
2098 f
->stem
= savestring (buffer
, o
- buffer
);
2101 this->staticpattern
= 1;
2102 this->stem
= xstrdup (f
->stem
);
2106 /* Free name if not needed further. */
2107 if (f
!= 0 && name
!= f
->name
2108 && (name
< f
->name
|| name
> f
->name
+ strlen (f
->name
)))
2114 /* If this target is a default target, update DEFAULT_GOAL_FILE. */
2115 if (streq (*default_goal_name
, name
)
2116 && (default_goal_file
== 0
2117 || ! streq (default_goal_file
->name
, name
)))
2118 default_goal_file
= f
;
2123 targets
[target_idx
] = 0;
2124 target_percents
[target_idx
] = 0;
2126 deps
->need_2nd_expansion
= second_expansion
;
2127 create_pattern_rule (targets
, target_percents
, two_colon
, deps
, cmds
, 1);
2128 free ((char *) target_percents
);
2132 /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
2133 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
2134 Quoting backslashes are removed from STRING by compacting it into
2135 itself. Returns a pointer to the first unquoted STOPCHAR if there is
2136 one, or nil if there are none. STOPCHARs inside variable references are
2137 ignored if IGNOREVARS is true.
2139 STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */
2142 find_char_unquote (char *string
, int stop1
, int stop2
, int blank
,
2145 unsigned int string_len
= 0;
2146 register char *p
= string
;
2154 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
&& *p
!= stop2
2155 && ! isblank ((unsigned char) *p
))
2158 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
&& *p
!= stop2
)
2161 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
2162 && ! isblank ((unsigned char) *p
))
2165 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
)
2171 /* If we stopped due to a variable reference, skip over its contents. */
2172 if (*p
== ignorevars
)
2174 char openparen
= p
[1];
2178 /* Skip the contents of a non-quoted, multi-char variable ref. */
2179 if (openparen
== '(' || openparen
== '{')
2181 unsigned int pcount
= 1;
2182 char closeparen
= (openparen
== '(' ? ')' : '}');
2186 if (*p
== openparen
)
2188 else if (*p
== closeparen
)
2198 /* Skipped the variable reference: look for STOPCHARS again. */
2202 if (p
> string
&& p
[-1] == '\\')
2204 /* Search for more backslashes. */
2205 register int i
= -2;
2206 while (&p
[i
] >= string
&& p
[i
] == '\\')
2209 /* Only compute the length if really needed. */
2210 if (string_len
== 0)
2211 string_len
= strlen (string
);
2212 /* The number of backslashes is now -I.
2213 Copy P over itself to swallow half of them. */
2214 bcopy (&p
[i
/ 2], &p
[i
], (string_len
- (p
- string
)) - (i
/ 2) + 1);
2217 /* All the backslashes quoted each other; the STOPCHAR was
2221 /* The STOPCHAR was quoted by a backslash. Look for another. */
2224 /* No backslash in sight. */
2228 /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
2232 /* Search PATTERN for an unquoted %. */
2235 find_percent (char *pattern
)
2237 return find_char_unquote (pattern
, '%', 0, 0, 0);
2240 /* Parse a string into a sequence of filenames represented as a
2241 chain of struct nameseq's in reverse order and return that chain.
2243 The string is passed as STRINGP, the address of a string pointer.
2244 The string pointer is updated to point at the first character
2245 not parsed, which either is a null char or equals STOPCHAR.
2247 SIZE is how big to construct chain elements.
2248 This is useful if we want them actually to be other structures
2249 that have room for additional info.
2251 If STRIP is nonzero, strip `./'s off the beginning. */
2254 parse_file_seq (char **stringp
, int stopchar
, unsigned int size
, int strip
)
2256 struct nameseq
*new = 0;
2257 struct nameseq
*new1
, *lastnew1
;
2263 # define VMS_COMMA ','
2265 # define VMS_COMMA 0
2270 /* Skip whitespace; see if any more names are left. */
2277 /* Yes, find end of next name. */
2279 p
= find_char_unquote (q
, stopchar
, VMS_COMMA
, 1, 0);
2281 /* convert comma separated list to space separated */
2286 if (stopchar
== ':' && p
&& *p
== ':'
2287 && !(isspace ((unsigned char)p
[1]) || !p
[1]
2288 || isspace ((unsigned char)p
[-1])))
2290 p
= find_char_unquote (p
+1, stopchar
, VMS_COMMA
, 1, 0);
2293 #ifdef HAVE_DOS_PATHS
2294 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
2295 first colon which isn't followed by a slash or a backslash.
2296 Note that tokens separated by spaces should be treated as separate
2297 tokens since make doesn't allow path names with spaces */
2298 if (stopchar
== ':')
2299 while (p
!= 0 && !isspace ((unsigned char)*p
) &&
2300 (p
[1] == '\\' || p
[1] == '/') && isalpha ((unsigned char)p
[-1]))
2301 p
= find_char_unquote (p
+ 1, stopchar
, VMS_COMMA
, 1, 0);
2308 /* Skip leading `[]'s. */
2309 while (p
- q
> 2 && q
[0] == '[' && q
[1] == ']')
2311 /* Skip leading `./'s. */
2312 while (p
- q
> 2 && q
[0] == '.' && q
[1] == '/')
2315 q
+= 2; /* Skip "./". */
2316 while (q
< p
&& *q
== '/')
2317 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
2321 /* Extract the filename just found, and skip it. */
2324 /* ".///" was stripped to "". */
2329 name
= savestring ("", 0);
2331 name
= savestring ("./", 2);
2336 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need
2337 * to remove this '\' before we can use the filename.
2338 * Savestring called because q may be read-only string constant.
2341 char *qbase
= xstrdup (q
);
2342 char *pbase
= qbase
+ (p
-q
);
2349 if (*q1
== '\\' && *(q1
+1) == ':')
2356 name
= savestring (qbase
, p1
- qbase
);
2360 name
= savestring (q
, p
- q
);
2363 /* Add it to the front of the chain. */
2364 new1
= (struct nameseq
*) xmalloc (size
);
2372 /* Look for multi-word archive references.
2373 They are indicated by a elt ending with an unmatched `)' and
2374 an elt further down the chain (i.e., previous in the file list)
2375 with an unmatched `(' (e.g., "lib(mem"). */
2380 if (new1
->name
[0] != '(' /* Don't catch "(%)" and suchlike. */
2381 && new1
->name
[strlen (new1
->name
) - 1] == ')'
2382 && strchr (new1
->name
, '(') == 0)
2384 /* NEW1 ends with a `)' but does not contain a `('.
2385 Look back for an elt with an opening `(' but no closing `)'. */
2387 struct nameseq
*n
= new1
->next
, *lastn
= new1
;
2389 while (n
!= 0 && (paren
= strchr (n
->name
, '(')) == 0)
2395 /* Ignore something starting with `(', as that cannot actually
2396 be an archive-member reference (and treating it as such
2397 results in an empty file name, which causes much lossage). */
2398 && n
->name
[0] != '(')
2400 /* N is the first element in the archive group.
2401 Its name looks like "lib(mem" (with no closing `)'). */
2405 /* Copy "lib(" into LIBNAME. */
2407 libname
= (char *) alloca (paren
- n
->name
+ 1);
2408 bcopy (n
->name
, libname
, paren
- n
->name
);
2409 libname
[paren
- n
->name
] = '\0';
2413 /* N was just "lib(", part of something like "lib( a b)".
2414 Edit it out of the chain and free its storage. */
2415 lastn
->next
= n
->next
;
2418 /* LASTN->next is the new stopping elt for the loop below. */
2423 /* Replace N's name with the full archive reference. */
2424 name
= concat (libname
, paren
, ")");
2429 if (new1
->name
[1] == '\0')
2431 /* NEW1 is just ")", part of something like "lib(a b )".
2432 Omit it from the chain and free its storage. */
2436 lastnew1
->next
= new1
->next
;
2440 free ((char *) lastn
);
2444 /* Replace also NEW1->name, which already has closing `)'. */
2445 name
= concat (libname
, new1
->name
, "");
2451 /* Trace back from NEW1 (the end of the list) until N
2452 (the beginning of the list), rewriting each name
2453 with the full archive reference. */
2457 name
= concat (libname
, new1
->name
, ")");
2466 /* No frobnication happening. Just step down the list. */
2483 /* Find the next line of text in an eval buffer, combining continuation lines
2485 Return the number of actual lines read (> 1 if continuation lines).
2486 Returns -1 if there's nothing left in the buffer.
2488 After this function, ebuf->buffer points to the first character of the
2492 /* Read a line of text from a STRING.
2493 Since we aren't really reading from a file, don't bother with linenumbers.
2496 static unsigned long
2497 readstring (struct ebuffer
*ebuf
)
2501 /* If there is nothing left in this buffer, return 0. */
2502 if (ebuf
->bufnext
>= ebuf
->bufstart
+ ebuf
->size
)
2505 /* Set up a new starting point for the buffer, and find the end of the
2506 next logical line (taking into account backslash/newline pairs). */
2508 eol
= ebuf
->buffer
= ebuf
->bufnext
;
2516 /* Find the next newline. At EOS, stop. */
2517 eol
= p
= strchr (eol
, '\n');
2520 ebuf
->bufnext
= ebuf
->bufstart
+ ebuf
->size
+ 1;
2524 /* Found a newline; if it's escaped continue; else we're done. */
2525 while (p
> bol
&& *(--p
) == '\\')
2526 backslash
= !backslash
;
2532 /* Overwrite the newline char. */
2534 ebuf
->bufnext
= eol
+1;
2540 readline (struct ebuffer
*ebuf
)
2547 /* The behaviors between string and stream buffers are different enough to
2548 warrant different functions. Do the Right Thing. */
2551 return readstring (ebuf
);
2553 /* When reading from a file, we always start over at the beginning of the
2554 buffer for each new line. */
2556 p
= start
= ebuf
->bufstart
;
2557 end
= p
+ ebuf
->size
;
2560 while (fgets (p
, end
- p
, ebuf
->fp
) != 0)
2569 /* This only happens when the first thing on the line is a '\0'.
2570 It is a pretty hopeless case, but (wonder of wonders) Athena
2571 lossage strikes again! (xmkmf puts NULs in its makefiles.)
2572 There is nothing really to be done; we synthesize a newline so
2573 the following line doesn't appear to be part of this line. */
2575 _("warning: NUL character seen; rest of line ignored"));
2580 /* Jump past the text we just read. */
2583 /* If the last char isn't a newline, the whole line didn't fit into the
2584 buffer. Get some more buffer and try again. */
2588 /* We got a newline, so add one to the count of lines. */
2591 #if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
2592 /* Check to see if the line was really ended with CRLF; if so ignore
2594 if ((p
- start
) > 1 && p
[-2] == '\r')
2602 for (p2
= p
- 2; p2
>= start
; --p2
)
2606 backslash
= !backslash
;
2615 /* It was a backslash/newline combo. If we have more space, read
2620 /* We need more space at the end of our buffer, so realloc it.
2621 Make sure to preserve the current offset of p. */
2624 unsigned long off
= p
- start
;
2626 start
= ebuf
->buffer
= ebuf
->bufstart
= (char *) xrealloc (start
,
2629 end
= start
+ ebuf
->size
;
2634 if (ferror (ebuf
->fp
))
2635 pfatal_with_name (ebuf
->floc
.filenm
);
2637 /* If we found some lines, return how many.
2638 If we didn't, but we did find _something_, that indicates we read the last
2639 line of a file with no final newline; return 1.
2640 If we read nothing, we're at EOF; return -1. */
2642 return nlines
? nlines
: p
== ebuf
->bufstart
? -1 : 1;
2645 /* Parse the next "makefile word" from the input buffer, and return info
2648 A "makefile word" is one of:
2650 w_bogus Should never happen
2652 w_static A static word; cannot be expanded
2653 w_variable A word containing one or more variables/functions
2655 w_dcolon A double-colon
2656 w_semicolon A semicolon
2657 w_varassign A variable assignment operator (=, :=, +=, or ?=)
2659 Note that this function is only used when reading certain parts of the
2660 makefile. Don't use it where special rules hold sway (RHS of a variable,
2661 in a command list, etc.) */
2663 static enum make_word_type
2664 get_next_mword (char *buffer
, char *delim
, char **startp
, unsigned int *length
)
2666 enum make_word_type wtype
= w_bogus
;
2667 char *p
= buffer
, *beg
;
2670 /* Skip any leading whitespace. */
2671 while (isblank ((unsigned char)*p
))
2683 wtype
= w_semicolon
;
2687 wtype
= w_varassign
;
2701 wtype
= w_varassign
;
2711 wtype
= w_varassign
;
2716 if (delim
&& strchr (delim
, c
))
2721 /* Did we find something? If so, return now. */
2722 if (wtype
!= w_bogus
)
2725 /* This is some non-operator word. A word consists of the longest
2726 string of characters that doesn't contain whitespace, one of [:=#],
2727 or [?+]=, or one of the chars in the DELIM string. */
2729 /* We start out assuming a static word; if we see a variable we'll
2730 adjust our assumptions then. */
2733 /* We already found the first value of "c", above. */
2748 #ifdef HAVE_DOS_PATHS
2749 /* A word CAN include a colon in its drive spec. The drive
2750 spec is allowed either at the beginning of a word, or as part
2751 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
2753 && (*p
== '/' || *p
== '\\') && isalpha ((unsigned char)p
[-2])
2754 && (p
- beg
== 2 || p
[-3] == '(')))
2763 /* This is a variable reference, so note that it's expandable.
2764 Then read it to the matching close paren. */
2772 /* This is a single-letter variable reference. */
2775 for (count
=0; *p
!= '\0'; ++p
)
2779 else if (*p
== closeparen
&& --count
< 0)
2806 if (delim
&& strchr (delim
, c
))
2824 /* Construct the list of include directories
2825 from the arguments and the default list. */
2828 construct_include_path (char **arg_dirs
)
2830 register unsigned int i
;
2831 #ifdef VAXC /* just don't ask ... */
2836 /* Table to hold the dirs. */
2838 register unsigned int defsize
= (sizeof (default_include_directories
)
2839 / sizeof (default_include_directories
[0]));
2840 register unsigned int max
= 5;
2841 register char **dirs
= (char **) xmalloc ((5 + defsize
) * sizeof (char *));
2842 register unsigned int idx
= 0;
2848 /* First consider any dirs specified with -I switches.
2849 Ignore dirs that don't exist. */
2852 while (*arg_dirs
!= 0)
2854 char *dir
= *arg_dirs
++;
2859 char *expanded
= tilde_expand (dir
);
2864 EINTRLOOP (e
, stat (dir
, &stbuf
));
2865 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2871 xrealloc ((char *) dirs
, (max
+ defsize
) * sizeof (char *));
2875 else if (dir
!= arg_dirs
[-1])
2879 /* Now add at the end the standard default dirs. */
2883 /* The environment variable $DJDIR holds the root of the
2884 DJGPP directory tree; add ${DJDIR}/include. */
2885 struct variable
*djdir
= lookup_variable ("DJDIR", 5);
2889 char *defdir
= (char *) xmalloc (strlen (djdir
->value
) + 8 + 1);
2891 strcat (strcpy (defdir
, djdir
->value
), "/include");
2892 dirs
[idx
++] = defdir
;
2897 for (i
= 0; default_include_directories
[i
] != 0; ++i
)
2901 EINTRLOOP (e
, stat (default_include_directories
[i
], &stbuf
));
2902 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2903 dirs
[idx
++] = default_include_directories
[i
];
2908 /* Now compute the maximum length of any name in it. Also add each
2909 dir to the .INCLUDE_DIRS variable. */
2912 for (i
= 0; i
< idx
; ++i
)
2914 unsigned int len
= strlen (dirs
[i
]);
2915 /* If dir name is written with a trailing slash, discard it. */
2916 if (dirs
[i
][len
- 1] == '/')
2917 /* We can't just clobber a null in because it may have come from
2918 a literal string and literal strings may not be writable. */
2919 dirs
[i
] = savestring (dirs
[i
], len
- 1);
2920 if (len
> max_incl_len
)
2923 /* Append to .INCLUDE_DIRS. */
2924 do_variable_definition (NILF
, ".INCLUDE_DIRS", dirs
[i
],
2925 o_default
, f_append
, 0);
2928 include_directories
= dirs
;
2931 /* Expand ~ or ~USER at the beginning of NAME.
2932 Return a newly malloc'd string or 0. */
2935 tilde_expand (char *name
)
2938 if (name
[1] == '/' || name
[1] == '\0')
2940 extern char *getenv ();
2945 /* Turn off --warn-undefined-variables while we expand HOME. */
2946 int save
= warn_undefined_variables_flag
;
2947 warn_undefined_variables_flag
= 0;
2949 home_dir
= allocated_variable_expand ("$(HOME)");
2951 warn_undefined_variables_flag
= save
;
2954 is_variable
= home_dir
[0] != '\0';
2958 home_dir
= getenv ("HOME");
2960 #if !defined(_AMIGA) && !defined(WINDOWS32)
2961 if (home_dir
== 0 || home_dir
[0] == '\0')
2963 extern char *getlogin ();
2964 char *logname
= getlogin ();
2968 struct passwd
*p
= getpwnam (logname
);
2970 home_dir
= p
->pw_dir
;
2973 #endif /* !AMIGA && !WINDOWS32 */
2976 char *new = concat (home_dir
, "", name
+ 1);
2982 #if !defined(_AMIGA) && !defined(WINDOWS32)
2985 struct passwd
*pwent
;
2986 char *userend
= strchr (name
+ 1, '/');
2989 pwent
= getpwnam (name
+ 1);
2993 return xstrdup (pwent
->pw_dir
);
2995 return concat (pwent
->pw_dir
, "/", userend
+ 1);
2997 else if (userend
!= 0)
3000 #endif /* !AMIGA && !WINDOWS32 */
3005 /* Given a chain of struct nameseq's describing a sequence of filenames,
3006 in reverse of the intended order, return a new chain describing the
3007 result of globbing the filenames. The new chain is in forward order.
3008 The links of the old chain are freed or used in the new chain.
3009 Likewise for the names in the old chain.
3011 SIZE is how big to construct chain elements.
3012 This is useful if we want them actually to be other structures
3013 that have room for additional info. */
3016 multi_glob (struct nameseq
*chain
, unsigned int size
)
3018 extern void dir_setup_glob ();
3019 register struct nameseq
*new = 0;
3020 register struct nameseq
*old
;
3021 struct nameseq
*nexto
;
3024 dir_setup_glob (&gl
);
3026 for (old
= chain
; old
!= 0; old
= nexto
)
3034 if (old
->name
[0] == '~')
3036 char *newname
= tilde_expand (old
->name
);
3040 old
->name
= newname
;
3045 if (ar_name (old
->name
))
3047 /* OLD->name is an archive member reference.
3048 Replace it with the archive file name,
3049 and save the member name in MEMNAME.
3050 We will glob on the archive name and then
3051 reattach MEMNAME later. */
3053 ar_parse_name (old
->name
, &arname
, &memname
);
3059 #endif /* !NO_ARCHIVES */
3061 switch (glob (old
->name
, GLOB_NOCHECK
|GLOB_ALTDIRFUNC
, NULL
, &gl
))
3063 case 0: /* Success. */
3065 register int i
= gl
.gl_pathc
;
3071 /* Try to glob on MEMNAME within the archive. */
3072 struct nameseq
*found
3073 = ar_glob (gl
.gl_pathv
[i
], memname
, size
);
3076 /* No matches. Use MEMNAME as-is. */
3077 unsigned int alen
= strlen (gl
.gl_pathv
[i
]);
3078 unsigned int mlen
= strlen (memname
);
3080 = (struct nameseq
*) xmalloc (size
);
3081 if (size
> sizeof (struct nameseq
))
3082 bzero (((char *) elt
) + sizeof (struct nameseq
),
3083 size
- sizeof (struct nameseq
));
3084 elt
->name
= (char *) xmalloc (alen
+ 1 + mlen
+ 2);
3085 bcopy (gl
.gl_pathv
[i
], elt
->name
, alen
);
3086 elt
->name
[alen
] = '(';
3087 bcopy (memname
, &elt
->name
[alen
+ 1], mlen
);
3088 elt
->name
[alen
+ 1 + mlen
] = ')';
3089 elt
->name
[alen
+ 1 + mlen
+ 1] = '\0';
3095 /* Find the end of the FOUND chain. */
3096 struct nameseq
*f
= found
;
3097 while (f
->next
!= 0)
3100 /* Attach the chain being built to the end of the FOUND
3101 chain, and make FOUND the new NEW chain. */
3109 #endif /* !NO_ARCHIVES */
3111 struct nameseq
*elt
= (struct nameseq
*) xmalloc (size
);
3112 if (size
> sizeof (struct nameseq
))
3113 bzero (((char *) elt
) + sizeof (struct nameseq
),
3114 size
- sizeof (struct nameseq
));
3115 elt
->name
= xstrdup (gl
.gl_pathv
[i
]);
3127 fatal (NILF
, _("virtual memory exhausted"));