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, 2007 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 3 of the License, or (at your option) any later
12 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with
17 this program. If not, see <http://www.gnu.org/licenses/>. */
40 struct passwd
*getpwnam (char *name
);
43 #endif /* !WINDOWS32 */
45 /* A 'struct ebuffer' controls the origin of the makefile we are currently
51 char *buffer
; /* Start of the current line in the buffer. */
52 char *bufnext
; /* Start of the next line in the buffer. */
53 char *bufstart
; /* Start of the entire buffer. */
54 unsigned int size
; /* Malloc'd size of buffer. */
55 FILE *fp
; /* File, or NULL if this is an internal buffer. */
56 struct floc floc
; /* Info on the file in fp (if any). */
59 /* Track the modifiers we can have on variable assignments */
63 unsigned int assign_v
:1;
64 unsigned int define_v
:1;
65 unsigned int export_v
:1;
66 unsigned int override_v
:1;
67 unsigned int private_v
:1;
70 /* Types of "words" that can be read in a makefile. */
73 w_bogus
, w_eol
, w_static
, w_variable
, w_colon
, w_dcolon
, w_semicolon
,
78 /* A `struct conditionals' contains the information describing
79 all the active conditionals in a makefile.
81 The global variable `conditionals' contains the conditionals
82 information for the current makefile. It is initialized from
83 the static structure `toplevel_conditionals' and is later changed
84 to new structures for included makefiles. */
88 unsigned int if_cmds
; /* Depth of conditional nesting. */
89 unsigned int allocated
; /* Elts allocated in following arrays. */
90 char *ignoring
; /* Are we ignoring or interpreting?
91 0=interpreting, 1=not yet interpreted,
92 2=already interpreted */
93 char *seen_else
; /* Have we already seen an `else'? */
96 static struct conditionals toplevel_conditionals
;
97 static struct conditionals
*conditionals
= &toplevel_conditionals
;
100 /* Default directories to search for include files in */
102 static const char *default_include_directories
[] =
104 #if defined(WINDOWS32) && !defined(INCLUDEDIR)
105 /* This completely up to the user when they install MSVC or other packages.
106 This is defined as a placeholder. */
107 # define INCLUDEDIR "."
112 "/usr/local/include",
118 /* List of directories to search for include files in */
120 static const char **include_directories
;
122 /* Maximum length of an element of the above. */
124 static unsigned int max_incl_len
;
126 /* The filename and pointer to line number of the
127 makefile currently being read in. */
129 const struct floc
*reading_file
= 0;
131 /* The chain of makefiles read by read_makefile. */
133 static struct dep
*read_makefiles
= 0;
135 static int eval_makefile (const char *filename
, int flags
);
136 static int eval (struct ebuffer
*buffer
, int flags
);
138 static long readline (struct ebuffer
*ebuf
);
139 static struct variable
*do_define (char *name
, enum variable_origin origin
,
140 struct ebuffer
*ebuf
);
141 static int conditional_line (char *line
, int len
, const struct floc
*flocp
);
142 static void record_files (struct nameseq
*filenames
, const char *pattern
,
143 const char *pattern_percent
, struct dep
*deps
,
144 unsigned int cmds_started
, char *commands
,
145 unsigned int commands_idx
, int two_colon
,
146 const struct floc
*flocp
);
147 static void record_target_var (struct nameseq
*filenames
, char *defn
,
148 enum variable_origin origin
,
149 struct vmodifiers
*vmod
,
150 const struct floc
*flocp
);
151 static enum make_word_type
get_next_mword (char *buffer
, char *delim
,
152 char **startp
, unsigned int *length
);
153 static void remove_comments (char *line
);
154 static char *find_char_unquote (char *string
, int stop1
, int stop2
,
155 int blank
, int ignorevars
);
158 /* Compare a word, both length and contents.
159 P must point to the word to be tested, and WLEN must be the length.
161 #define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
164 /* Read in all the makefiles and return the chain of their names. */
167 read_all_makefiles (const char **makefiles
)
169 unsigned int num_makefiles
= 0;
171 /* Create *_LIST variables, to hold the makefiles, targets, and variables
172 we will be reading. */
174 define_variable ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", o_file
, 0);
176 DB (DB_BASIC
, (_("Reading makefiles...\n")));
178 /* If there's a non-null variable MAKEFILES, its value is a list of
179 files to read first thing. But don't let it prevent reading the
180 default makefiles and don't let the default goal come from there. */
188 /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
189 int save
= warn_undefined_variables_flag
;
190 warn_undefined_variables_flag
= 0;
192 value
= allocated_variable_expand ("$(MAKEFILES)");
194 warn_undefined_variables_flag
= save
;
197 /* Set NAME to the start of next token and LENGTH to its length.
198 MAKEFILES is updated for finding remaining tokens. */
201 while ((name
= find_next_token ((const char **)&p
, &length
)) != 0)
205 eval_makefile (name
, RM_NO_DEFAULT_GOAL
|RM_INCLUDED
|RM_DONTCARE
);
211 /* Read makefiles specified with -f switches. */
214 while (*makefiles
!= 0)
216 struct dep
*tail
= read_makefiles
;
217 register struct dep
*d
;
219 if (! eval_makefile (*makefiles
, 0))
220 perror_with_name ("", *makefiles
);
222 /* Find the right element of read_makefiles. */
224 while (d
->next
!= tail
)
227 /* Use the storage read_makefile allocates. */
228 *makefiles
= dep_name (d
);
233 /* If there were no -f switches, try the default names. */
235 if (num_makefiles
== 0)
237 static char *default_makefiles
[] =
239 /* all lower case since readdir() (the vms version) 'lowercasifies' */
240 { "makefile.vms", "gnumakefile.", "makefile.", 0 };
243 { "GNUmakefile", "Makefile", "SMakefile", 0 };
244 #else /* !Amiga && !VMS */
245 { "GNUmakefile", "makefile", "Makefile", 0 };
248 register char **p
= default_makefiles
;
249 while (*p
!= 0 && !file_exists_p (*p
))
254 if (! eval_makefile (*p
, 0))
255 perror_with_name ("", *p
);
259 /* No default makefile was found. Add the default makefiles to the
260 `read_makefiles' chain so they will be updated if possible. */
261 struct dep
*tail
= read_makefiles
;
262 /* Add them to the tail, after any MAKEFILES variable makefiles. */
263 while (tail
!= 0 && tail
->next
!= 0)
265 for (p
= default_makefiles
; *p
!= 0; ++p
)
267 struct dep
*d
= alloc_dep ();
268 d
->file
= enter_file (strcache_add (*p
));
269 d
->file
->dontcare
= 1;
270 /* Tell update_goal_chain to bail out as soon as this file is
271 made, and main not to die if we can't make this file. */
272 d
->changed
= RM_DONTCARE
;
284 return read_makefiles
;
287 /* Install a new conditional and return the previous one. */
289 static struct conditionals
*
290 install_conditionals (struct conditionals
*new)
292 struct conditionals
*save
= conditionals
;
294 memset (new, '\0', sizeof (*new));
300 /* Free the current conditionals and reinstate a saved one. */
303 restore_conditionals (struct conditionals
*saved
)
305 /* Free any space allocated by conditional_line. */
306 if (conditionals
->ignoring
)
307 free (conditionals
->ignoring
);
308 if (conditionals
->seen_else
)
309 free (conditionals
->seen_else
);
312 conditionals
= saved
;
316 eval_makefile (const char *filename
, int flags
)
320 const struct floc
*curfile
;
325 filename
= strcache_add (filename
);
326 ebuf
.floc
.filenm
= filename
;
327 ebuf
.floc
.lineno
= 1;
329 if (ISDB (DB_VERBOSE
))
331 printf (_("Reading makefile `%s'"), filename
);
332 if (flags
& RM_NO_DEFAULT_GOAL
)
333 printf (_(" (no default goal)"));
334 if (flags
& RM_INCLUDED
)
335 printf (_(" (search path)"));
336 if (flags
& RM_DONTCARE
)
337 printf (_(" (don't care)"));
338 if (flags
& RM_NO_TILDE
)
339 printf (_(" (no ~ expansion)"));
343 /* First, get a stream to read. */
345 /* Expand ~ in FILENAME unless it came from `include',
346 in which case it was already done. */
347 if (!(flags
& RM_NO_TILDE
) && filename
[0] == '~')
349 expanded
= tilde_expand (filename
);
354 ebuf
.fp
= fopen (filename
, "r");
355 /* Save the error code so we print the right message later. */
356 makefile_errno
= errno
;
358 /* If the makefile wasn't found and it's either a makefile from
359 the `MAKEFILES' variable or an included makefile,
360 search the included makefile search path for this makefile. */
361 if (ebuf
.fp
== 0 && (flags
& RM_INCLUDED
) && *filename
!= '/')
364 for (i
= 0; include_directories
[i
] != 0; ++i
)
366 const char *included
= concat (include_directories
[i
], "/", filename
);
367 ebuf
.fp
= fopen (included
, "r");
370 filename
= strcache_add (included
);
376 /* Add FILENAME to the chain of read makefiles. */
378 deps
->next
= read_makefiles
;
379 read_makefiles
= deps
;
380 deps
->file
= lookup_file (filename
);
382 deps
->file
= enter_file (filename
);
383 filename
= deps
->file
->name
;
384 deps
->changed
= flags
;
385 if (flags
& RM_DONTCARE
)
386 deps
->file
->dontcare
= 1;
391 /* If the makefile can't be found at all, give up entirely. */
395 /* If we did some searching, errno has the error from the last
396 attempt, rather from FILENAME itself. Restore it in case the
397 caller wants to use it in a message. */
398 errno
= makefile_errno
;
402 /* Set close-on-exec to avoid leaking the makefile to children, such as
405 CLOSE_ON_EXEC (fileno (ebuf
.fp
));
408 /* Add this makefile to the list. */
409 do_variable_definition (&ebuf
.floc
, "MAKEFILE_LIST", filename
, o_file
,
412 /* Evaluate the makefile */
415 ebuf
.buffer
= ebuf
.bufnext
= ebuf
.bufstart
= xmalloc (ebuf
.size
);
417 curfile
= reading_file
;
418 reading_file
= &ebuf
.floc
;
420 r
= eval (&ebuf
, !(flags
& RM_NO_DEFAULT_GOAL
));
422 reading_file
= curfile
;
426 free (ebuf
.bufstart
);
432 eval_buffer (char *buffer
)
435 struct conditionals
*saved
;
436 struct conditionals
new;
437 const struct floc
*curfile
;
440 /* Evaluate the buffer */
442 ebuf
.size
= strlen (buffer
);
443 ebuf
.buffer
= ebuf
.bufnext
= ebuf
.bufstart
= buffer
;
447 ebuf
.floc
= *reading_file
;
449 ebuf
.floc
.filenm
= NULL
;
451 curfile
= reading_file
;
452 reading_file
= &ebuf
.floc
;
454 saved
= install_conditionals (&new);
458 restore_conditionals (saved
);
460 reading_file
= curfile
;
466 /* Check LINE to see if it's a variable assignment.
468 It might use one of the modifiers "export", "override", "private", or it
469 might be one of the conditional tokens like "ifdef", "include", etc.
471 If it's not a variable assignment, VMOD.V_ASSIGN is 0. Returns LINE.
473 Returns a pointer to the first non-modifier character, and sets VMOD
474 based on the modifiers found if any, plus V_ASSIGN is 1.
477 parse_var_assignment (const char *line
, struct vmodifiers
*vmod
)
480 memset (vmod
, '\0', sizeof (*vmod
));
482 /* Find the start of the next token. If there isn't one we're done. */
483 line
= next_token (line
);
492 enum variable_flavor flavor
;
494 p2
= parse_variable_definition (p
, &flavor
);
496 /* If this is a variable assignment, we're done. */
500 /* It's not a variable; see if it's a modifier. */
501 p2
= end_of_token (p
);
504 if (word1eq ("export"))
506 else if (word1eq ("override"))
507 vmod
->override_v
= 1;
508 else if (word1eq ("private"))
510 else if (word1eq ("define"))
512 /* We can't have modifiers after 'define' */
518 /* Not a variable or modifier: this is not a variable assignment. */
521 /* It was a modifier. Try the next word. */
527 /* Found a variable assignment. */
534 /* Read file FILENAME as a makefile and add its contents to the data base.
536 SET_DEFAULT is true if we are allowed to set the default goal. */
540 eval (struct ebuffer
*ebuf
, int set_default
)
543 unsigned int collapsed_length
= 0;
544 unsigned int commands_len
= 200;
546 unsigned int commands_idx
= 0;
547 unsigned int cmds_started
, tgts_started
;
548 int ignoring
= 0, in_ignored_define
= 0;
549 int no_targets
= 0; /* Set when reading a rule without targets. */
550 struct nameseq
*filenames
= 0;
551 struct dep
*deps
= 0;
554 const char *pattern
= 0;
555 const char *pattern_percent
;
559 #define record_waiting_files() \
562 if (filenames != 0) \
564 fi.lineno = tgts_started; \
565 record_files (filenames, pattern, pattern_percent, deps, \
566 cmds_started, commands, commands_idx, two_colon, \
576 cmds_started
= tgts_started
= 1;
578 fstart
= &ebuf
->floc
;
579 fi
.filenm
= ebuf
->floc
.filenm
;
581 /* Loop over lines in the file.
582 The strategy is to accumulate target names in FILENAMES, dependencies
583 in DEPS and commands in COMMANDS. These are used to define a rule
584 when the start of the next rule (or eof) is encountered.
586 When you see a "continue" in the loop below, that means we are moving on
587 to the next line _without_ ending any rule that we happen to be working
588 with at the moment. If you see a "goto rule_complete", then the
589 statement we just parsed also finishes the previous rule. */
591 commands
= xmalloc (200);
595 unsigned int linelen
;
600 struct vmodifiers vmod
;
602 /* At the top of this loop, we are starting a brand new line. */
603 /* Grab the next line to be evaluated */
604 ebuf
->floc
.lineno
+= nlines
;
605 nlines
= readline (ebuf
);
607 /* If there is nothing left to eval, we're done. */
611 /* If this line is empty, skip it. */
616 linelen
= strlen (line
);
618 /* Check for a shell command line first.
619 If it is not one, we can stop treating tab specially. */
620 if (line
[0] == cmd_prefix
)
623 /* Ignore the commands in a rule with no targets. */
626 /* If there is no preceding rule line, don't treat this line
627 as a command, even though it begins with a recipe prefix.
628 SunOS 4 make appears to behave this way. */
633 /* Yep, this is a shell command, and we don't care. */
636 /* Append this command line to the line being accumulated.
637 Strip command prefix chars that appear after newlines. */
638 if (commands_idx
== 0)
639 cmds_started
= ebuf
->floc
.lineno
;
641 if (linelen
+ commands_idx
> commands_len
)
643 commands_len
= (linelen
+ commands_idx
) * 2;
644 commands
= xrealloc (commands
, commands_len
);
646 p
= &commands
[commands_idx
];
652 if (p2
[0] == '\n' && p2
[1] == cmd_prefix
)
666 /* This line is not a shell command line. Don't worry about whitespace.
667 Get more space if we need it; we don't need to preserve the current
668 contents of the buffer. */
670 if (collapsed_length
< linelen
+1)
672 collapsed_length
= linelen
+1;
675 /* Don't need xrealloc: we don't need to preserve the content. */
676 collapsed
= xmalloc (collapsed_length
);
678 strcpy (collapsed
, line
);
679 /* Collapse continuation lines. */
680 collapse_continuations (collapsed
);
681 remove_comments (collapsed
);
683 /* Get rid if starting space (including formfeed, vtab, etc.) */
685 while (isspace ((unsigned char)*p
))
688 /* See if this is a variable assignment. We need to do this early, to
689 allow variables with names like 'ifdef', 'export', 'private', etc. */
690 p
= parse_var_assignment(p
, &vmod
);
694 enum variable_origin origin
= vmod
.override_v
? o_override
: o_file
;
696 /* If we're ignoring then we're done now. */
700 in_ignored_define
= 1;
705 v
= do_define (p
, origin
, ebuf
);
707 v
= try_variable_definition (fstart
, p
, origin
, 0);
712 v
->export
= v_export
;
716 /* This line has been dealt with. */
720 /* If this line is completely empty, ignore it. */
724 p2
= end_of_token (p
);
726 p2
= next_token (p2
);
728 /* If we're in an ignored define, skip this line (but maybe get out). */
729 if (in_ignored_define
)
731 /* See if this is an endef line (plus optional comment). */
732 if (word1eq ("endef") && (*p2
== '\0' || *p2
== '#'))
733 in_ignored_define
= 0;
738 /* Check for conditional state changes. */
740 int i
= conditional_line (p
, wlen
, fstart
);
744 fatal (fstart
, _("invalid syntax in conditional"));
751 /* Nothing to see here... move along. */
755 /* Manage the "export" keyword used outside of variable assignment
756 as well as "unexport". */
757 if (word1eq ("export") || word1eq ("unexport"))
759 int exporting
= *p
== 'u' ? 0 : 1;
761 /* (un)export by itself causes everything to be (un)exported. */
763 export_all_variables
= exporting
;
770 /* Expand the line so we can use indirect and constructed
771 variable names in an (un)export command. */
772 cp
= ap
= allocated_variable_expand (p2
);
774 for (p
= find_next_token (&cp
, &l
); p
!= 0;
775 p
= find_next_token (&cp
, &l
))
777 struct variable
*v
= lookup_variable (p
, l
);
779 v
= define_variable_loc (p
, l
, "", o_file
, 0, fstart
);
780 v
->export
= exporting
? v_export
: v_noexport
;
788 /* Handle the special syntax for vpath. */
789 if (word1eq ("vpath"))
794 cp
= variable_expand (p2
);
795 p
= find_next_token (&cp
, &l
);
798 vpat
= xstrndup (p
, l
);
799 p
= find_next_token (&cp
, &l
);
800 /* No searchpath means remove all previous
801 selective VPATH's with the same pattern. */
804 /* No pattern means remove all previous selective VPATH's. */
806 construct_vpath_list (vpat
, p
);
813 /* Handle include and variants. */
814 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
816 /* We have found an `include' line specifying a nested
817 makefile to be read at this point. */
818 struct conditionals
*save
;
819 struct conditionals new_conditionals
;
820 struct nameseq
*files
;
821 /* "-include" (vs "include") says no error if the file does not
822 exist. "sinclude" is an alias for this from SGI. */
823 int noerror
= (p
[0] != 'i');
825 p
= allocated_variable_expand (p2
);
827 /* If no filenames, it's a no-op. */
834 /* Parse the list of file names. */
836 files
= multi_glob (parse_file_seq (&p2
, '\0',
837 sizeof (struct nameseq
),
839 sizeof (struct nameseq
));
842 /* Save the state of conditionals and start
843 the included makefile with a clean slate. */
844 save
= install_conditionals (&new_conditionals
);
846 /* Record the rules that are waiting so they will determine
847 the default goal before those in the included makefile. */
848 record_waiting_files ();
850 /* Read each included makefile. */
853 struct nameseq
*next
= files
->next
;
854 const char *name
= files
->name
;
860 r
= eval_makefile (name
, (RM_INCLUDED
| RM_NO_TILDE
861 | (noerror
? RM_DONTCARE
: 0)));
863 error (fstart
, "%s: %s", name
, strerror (errno
));
866 /* Restore conditional state. */
867 restore_conditionals (save
);
872 /* This line starts with a tab but was not caught above because there
873 was no preceding target, and the line might have been usable as a
874 variable definition. But now we know it is definitely lossage. */
875 if (line
[0] == cmd_prefix
)
876 fatal(fstart
, _("recipe commences before first target"));
878 /* This line describes some target files. This is complicated by
879 the existence of target-specific variables, because we can't
880 expand the entire line until we know if we have one or not. So
881 we expand the line word by word until we find the first `:',
882 then check to see if it's a target-specific variable.
884 In this algorithm, `lb_next' will point to the beginning of the
885 unexpanded parts of the input buffer, while `p2' points to the
886 parts of the expanded buffer we haven't searched yet. */
889 enum make_word_type wtype
;
890 char *cmdleft
, *semip
, *lb_next
;
891 unsigned int plen
= 0;
893 const char *end
, *beg
; /* Helpers for whitespace stripping. */
895 /* Record the previous rule. */
897 record_waiting_files ();
898 tgts_started
= fstart
->lineno
;
900 /* Search the line for an unquoted ; that is not after an
902 cmdleft
= find_char_unquote (line
, ';', '#', 0, 1);
903 if (cmdleft
!= 0 && *cmdleft
== '#')
905 /* We found a comment before a semicolon. */
909 else if (cmdleft
!= 0)
910 /* Found one. Cut the line short there before expanding it. */
914 collapse_continuations (line
);
916 /* We can't expand the entire line, since if it's a per-target
917 variable we don't want to expand it. So, walk from the
918 beginning, expanding as we go, and looking for "interesting"
919 chars. The first word is always expandable. */
920 wtype
= get_next_mword(line
, NULL
, &lb_next
, &wlen
);
925 fatal(fstart
, _("missing rule before recipe"));
926 /* This line contained something but turned out to be nothing
927 but whitespace (a comment?). */
932 /* We accept and ignore rules without targets for
933 compatibility with SunOS 4 make. */
941 p2
= variable_expand_string(NULL
, lb_next
, wlen
);
948 /* Look for a semicolon in the expanded line. */
949 cmdleft
= find_char_unquote (p2
, ';', 0, 0, 0);
953 unsigned long p2_off
= p2
- variable_buffer
;
954 unsigned long cmd_off
= cmdleft
- variable_buffer
;
955 char *pend
= p2
+ strlen(p2
);
957 /* Append any remnants of lb, then cut the line short
961 /* One school of thought says that you shouldn't expand
962 here, but merely copy, since now you're beyond a ";"
963 and into a command script. However, the old parser
964 expanded the whole line, so we continue that for
965 backwards-compatiblity. Also, it wouldn't be
966 entirely consistent, since we do an unconditional
967 expand below once we know we don't have a
968 target-specific variable. */
969 (void)variable_expand_string(pend
, lb_next
, (long)-1);
970 lb_next
+= strlen(lb_next
);
971 p2
= variable_buffer
+ p2_off
;
972 cmdleft
= variable_buffer
+ cmd_off
+ 1;
976 colonp
= find_char_unquote(p2
, ':', 0, 0, 0);
977 #ifdef HAVE_DOS_PATHS
978 /* The drive spec brain-damage strikes again... */
979 /* Note that the only separators of targets in this context
980 are whitespace and a left paren. If others are possible,
981 they should be added to the string in the call to index. */
982 while (colonp
&& (colonp
[1] == '/' || colonp
[1] == '\\') &&
983 colonp
> p2
&& isalpha ((unsigned char)colonp
[-1]) &&
984 (colonp
== p2
+ 1 || strchr (" \t(", colonp
[-2]) != 0))
985 colonp
= find_char_unquote(colonp
+ 1, ':', 0, 0, 0);
990 wtype
= get_next_mword(lb_next
, NULL
, &lb_next
, &wlen
);
996 p2
= variable_expand_string(p2
, lb_next
, wlen
);
997 /* We don't need to worry about cmdleft here, because if it was
998 found in the variable_buffer the entire buffer has already
999 been expanded... we'll never get here. */
1002 p2
= next_token (variable_buffer
);
1004 /* If the word we're looking at is EOL, see if there's _anything_
1005 on the line. If not, a variable expanded to nothing, so ignore
1006 it. If so, we can't parse this line so punt. */
1010 /* There's no need to be ivory-tower about this: check for
1011 one of the most common bugs found in makefiles... */
1012 fatal (fstart
, _("missing separator%s"),
1013 (cmd_prefix
== '\t' && !strneq(line
, " ", 8))
1014 ? "" : _(" (did you mean TAB instead of 8 spaces?)"));
1018 /* Make the colon the end-of-string so we know where to stop
1019 looking for targets. */
1021 filenames
= multi_glob (parse_file_seq (&p2
, '\0',
1022 sizeof (struct nameseq
),
1024 sizeof (struct nameseq
));
1029 /* We accept and ignore rules without targets for
1030 compatibility with SunOS 4 make. */
1034 /* This should never be possible; we handled it above. */
1035 assert (*p2
!= '\0');
1038 /* Is this a one-colon or two-colon entry? */
1039 two_colon
= *p2
== ':';
1043 /* Test to see if it's a target-specific variable. Copy the rest
1044 of the buffer over, possibly temporarily (we'll expand it later
1045 if it's not a target-specific variable). PLEN saves the length
1046 of the unparsed section of p2, for later. */
1047 if (*lb_next
!= '\0')
1049 unsigned int l
= p2
- variable_buffer
;
1051 variable_buffer_output (p2
+plen
, lb_next
, strlen (lb_next
)+1);
1052 p2
= variable_buffer
+ l
;
1055 p2
= parse_var_assignment (p2
, &vmod
);
1058 /* If there was a semicolon found, add it back, plus anything
1062 unsigned int l
= p
- variable_buffer
;
1064 variable_buffer_output (p2
+ strlen (p2
),
1065 semip
, strlen (semip
)+1);
1066 p
= variable_buffer
+ l
;
1068 record_target_var (filenames
, p2
,
1069 vmod
.override_v
? o_override
: o_file
,
1075 /* This is a normal target, _not_ a target-specific variable.
1076 Unquote any = in the dependency list. */
1077 find_char_unquote (lb_next
, '=', 0, 0, 0);
1079 /* We have some targets, so don't ignore the following commands. */
1082 /* Expand the dependencies, etc. */
1083 if (*lb_next
!= '\0')
1085 unsigned int l
= p2
- variable_buffer
;
1086 (void) variable_expand_string (p2
+ plen
, lb_next
, (long)-1);
1087 p2
= variable_buffer
+ l
;
1089 /* Look for a semicolon in the expanded line. */
1092 cmdleft
= find_char_unquote (p2
, ';', 0, 0, 0);
1094 *(cmdleft
++) = '\0';
1098 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
1099 p
= strchr (p2
, ':');
1100 while (p
!= 0 && p
[-1] == '\\')
1102 register char *q
= &p
[-1];
1103 register int backslash
= 0;
1104 while (*q
-- == '\\')
1105 backslash
= !backslash
;
1107 p
= strchr (p
+ 1, ':');
1112 /* Here, the situation is quite complicated. Let's have a look
1113 at a couple of targets:
1121 The rule is that it's only a target, if there are TWO :'s
1122 OR a space around the :.
1124 if (p
&& !(isspace ((unsigned char)p
[1]) || !p
[1]
1125 || isspace ((unsigned char)p
[-1])))
1128 #ifdef HAVE_DOS_PATHS
1133 /* For DOS-style paths, skip a "C:\..." or a "C:/..." */
1134 if (p
!= 0 && (p
[1] == '\\' || p
[1] == '/') &&
1135 isalpha ((unsigned char)p
[-1]) &&
1136 (p
== p2
+ 1 || strchr (" \t:(", p
[-2]) != 0)) {
1137 p
= strchr (p
+ 1, ':');
1140 } while (check_again
);
1145 struct nameseq
*target
;
1146 target
= parse_file_seq (&p2
, ':', sizeof (struct nameseq
), 1);
1149 fatal (fstart
, _("missing target pattern"));
1150 else if (target
->next
!= 0)
1151 fatal (fstart
, _("multiple target patterns"));
1152 pattern_percent
= find_percent_cached (&target
->name
);
1153 pattern
= target
->name
;
1154 if (pattern_percent
== 0)
1155 fatal (fstart
, _("target pattern contains no `%%'"));
1161 /* Strip leading and trailing whitespaces. */
1163 end
= beg
+ strlen (beg
) - 1;
1164 strip_whitespace (&beg
, &end
);
1166 if (beg
<= end
&& *beg
!= '\0')
1168 /* Put all the prerequisites here; they'll be parsed later. */
1169 deps
= alloc_dep ();
1170 deps
->name
= strcache_add_len (beg
, end
- beg
+ 1);
1178 /* Semicolon means rest of line is a command. */
1179 unsigned int l
= strlen (cmdleft
);
1181 cmds_started
= fstart
->lineno
;
1183 /* Add this command line to the buffer. */
1184 if (l
+ 2 > commands_len
)
1186 commands_len
= (l
+ 2) * 2;
1187 commands
= xrealloc (commands
, commands_len
);
1189 memcpy (commands
, cmdleft
, l
);
1191 commands
[commands_idx
++] = '\n';
1194 /* Determine if this target should be made default. We used to do
1195 this in record_files() but because of the delayed target recording
1196 and because preprocessor directives are legal in target's commands
1197 it is too late. Consider this fragment for example:
1201 ifeq ($(.DEFAULT_GOAL),foo)
1205 Because the target is not recorded until after ifeq directive is
1206 evaluated the .DEFAULT_GOAL does not contain foo yet as one
1207 would expect. Because of this we have to move the logic here. */
1209 if (set_default
&& default_goal_var
->value
[0] == '\0')
1213 struct nameseq
*t
= filenames
;
1215 for (; t
!= 0; t
= t
->next
)
1220 /* We have nothing to do if this is an implicit rule. */
1221 if (strchr (name
, '%') != 0)
1224 /* See if this target's name does not start with a `.',
1225 unless it contains a slash. */
1226 if (*name
== '.' && strchr (name
, '/') == 0
1227 #ifdef HAVE_DOS_PATHS
1228 && strchr (name
, '\\') == 0
1234 /* If this file is a suffix, don't let it be
1235 the default goal file. */
1236 for (d
= suffix_file
->deps
; d
!= 0; d
= d
->next
)
1238 register struct dep
*d2
;
1239 if (*dep_name (d
) != '.' && streq (name
, dep_name (d
)))
1244 for (d2
= suffix_file
->deps
; d2
!= 0; d2
= d2
->next
)
1246 unsigned int l
= strlen (dep_name (d2
));
1247 if (!strneq (name
, dep_name (d2
), l
))
1249 if (streq (name
+ l
, dep_name (d
)))
1262 define_variable_global (".DEFAULT_GOAL", 13, t
->name
,
1272 /* We get here except in the case that we just read a rule line.
1273 Record now the last rule we read, so following spurious
1274 commands are properly diagnosed. */
1276 record_waiting_files ();
1281 if (conditionals
->if_cmds
)
1282 fatal (fstart
, _("missing `endif'"));
1284 /* At eof, record the last rule. */
1285 record_waiting_files ();
1295 /* Remove comments from LINE.
1296 This is done by copying the text at LINE onto itself. */
1299 remove_comments (char *line
)
1303 comment
= find_char_unquote (line
, '#', 0, 0, 0);
1306 /* Cut off the line at the #. */
1310 /* Execute a `define' directive.
1311 The first line has already been read, and NAME is the name of
1312 the variable to be defined. The following lines remain to be read. */
1314 static struct variable
*
1315 do_define (char *name
, enum variable_origin origin
, struct ebuffer
*ebuf
)
1318 enum variable_flavor flavor
;
1319 struct floc defstart
;
1321 unsigned int length
= 100;
1322 char *definition
= xmalloc (length
);
1323 unsigned int idx
= 0;
1326 defstart
= ebuf
->floc
;
1328 p
= parse_variable_definition (name
, &flavor
);
1330 /* No assignment token, so assume recursive. */
1331 flavor
= f_recursive
;
1334 if (*(next_token (p
)) != '\0')
1335 error (&defstart
, _("extraneous text after `define' directive"));
1337 /* Chop the string before the assignment token to get the name. */
1338 p
[flavor
== f_recursive
? -1 : -2] = '\0';
1341 /* Expand the variable name and find the beginning (NAME) and end. */
1342 var
= allocated_variable_expand (name
);
1343 name
= next_token (var
);
1345 fatal (&defstart
, _("empty variable name"));
1346 p
= name
+ strlen (name
) - 1;
1347 while (p
> name
&& isblank ((unsigned char)*p
))
1351 /* Now read the value of the variable. */
1356 long nlines
= readline (ebuf
);
1358 /* If there is nothing left to be eval'd, there's no 'endef'!! */
1360 fatal (&defstart
, _("missing `endef', unterminated `define'"));
1362 ebuf
->floc
.lineno
+= nlines
;
1363 line
= ebuf
->buffer
;
1365 collapse_continuations (line
);
1367 /* If the line doesn't begin with a tab, test to see if it introduces
1368 another define, or ends one. Stop if we find an 'endef' */
1369 if (line
[0] != cmd_prefix
)
1371 p
= next_token (line
);
1374 /* If this is another 'define', increment the level count. */
1375 if ((len
== 6 || (len
> 6 && isblank ((unsigned char)p
[6])))
1376 && strneq (p
, "define", 6))
1379 /* If this is an 'endef', decrement the count. If it's now 0,
1380 we've found the last one. */
1381 else if ((len
== 5 || (len
> 5 && isblank ((unsigned char)p
[5])))
1382 && strneq (p
, "endef", 5))
1385 remove_comments (p
);
1386 if (*(next_token (p
)) != '\0')
1388 _("extraneous text after `endef' directive"));
1395 /* Add this line to the variable definition. */
1396 len
= strlen (line
);
1397 if (idx
+ len
+ 1 > length
)
1399 length
= (idx
+ len
) * 2;
1400 definition
= xrealloc (definition
, length
+ 1);
1403 memcpy (&definition
[idx
], line
, len
);
1405 /* Separate lines with a newline. */
1406 definition
[idx
++] = '\n';
1409 /* We've got what we need; define the variable. */
1411 definition
[0] = '\0';
1413 definition
[idx
- 1] = '\0';
1415 v
= do_variable_definition (&defstart
, name
, definition
, origin
, flavor
, 0);
1421 /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
1422 "ifneq", "else" and "endif".
1423 LINE is the input line, with the command as its first word.
1425 FILENAME and LINENO are the filename and line number in the
1426 current makefile. They are used for error messages.
1428 Value is -2 if the line is not a conditional at all,
1429 -1 if the line is an invalid conditional,
1430 0 if following text should be interpreted,
1431 1 if following text should be ignored. */
1434 conditional_line (char *line
, int len
, const struct floc
*flocp
)
1437 enum { c_ifdef
, c_ifndef
, c_ifeq
, c_ifneq
, c_else
, c_endif
} cmdtype
;
1441 /* Compare a word, both length and contents. */
1442 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
1443 #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
1445 /* Make sure this line is a conditional. */
1446 chkword ("ifdef", c_ifdef
)
1447 else chkword ("ifndef", c_ifndef
)
1448 else chkword ("ifeq", c_ifeq
)
1449 else chkword ("ifneq", c_ifneq
)
1450 else chkword ("else", c_else
)
1451 else chkword ("endif", c_endif
)
1455 /* Found one: skip past it and any whitespace after it. */
1456 line
= next_token (line
+ len
);
1458 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
1460 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
1461 if (cmdtype
== c_endif
)
1466 if (!conditionals
->if_cmds
)
1467 fatal (flocp
, _("extraneous `%s'"), cmdname
);
1469 --conditionals
->if_cmds
;
1474 /* An 'else' statement can either be simple, or it can have another
1475 conditional after it. */
1476 if (cmdtype
== c_else
)
1480 if (!conditionals
->if_cmds
)
1481 fatal (flocp
, _("extraneous `%s'"), cmdname
);
1483 o
= conditionals
->if_cmds
- 1;
1485 if (conditionals
->seen_else
[o
])
1486 fatal (flocp
, _("only one `else' per conditional"));
1488 /* Change the state of ignorance. */
1489 switch (conditionals
->ignoring
[o
])
1492 /* We've just been interpreting. Never do it again. */
1493 conditionals
->ignoring
[o
] = 2;
1496 /* We've never interpreted yet. Maybe this time! */
1497 conditionals
->ignoring
[o
] = 0;
1501 /* It's a simple 'else'. */
1504 conditionals
->seen_else
[o
] = 1;
1508 /* The 'else' has extra text. That text must be another conditional
1509 and cannot be an 'else' or 'endif'. */
1511 /* Find the length of the next word. */
1512 for (p
= line
+1; *p
!= '\0' && !isspace ((unsigned char)*p
); ++p
)
1516 /* If it's 'else' or 'endif' or an illegal conditional, fail. */
1517 if (word1eq("else") || word1eq("endif")
1518 || conditional_line (line
, len
, flocp
) < 0)
1522 /* conditional_line() created a new level of conditional.
1523 Raise it back to this level. */
1524 if (conditionals
->ignoring
[o
] < 2)
1525 conditionals
->ignoring
[o
] = conditionals
->ignoring
[o
+1];
1526 --conditionals
->if_cmds
;
1532 if (conditionals
->allocated
== 0)
1534 conditionals
->allocated
= 5;
1535 conditionals
->ignoring
= xmalloc (conditionals
->allocated
);
1536 conditionals
->seen_else
= xmalloc (conditionals
->allocated
);
1539 o
= conditionals
->if_cmds
++;
1540 if (conditionals
->if_cmds
> conditionals
->allocated
)
1542 conditionals
->allocated
+= 5;
1543 conditionals
->ignoring
= xrealloc (conditionals
->ignoring
,
1544 conditionals
->allocated
);
1545 conditionals
->seen_else
= xrealloc (conditionals
->seen_else
,
1546 conditionals
->allocated
);
1549 /* Record that we have seen an `if...' but no `else' so far. */
1550 conditionals
->seen_else
[o
] = 0;
1552 /* Search through the stack to see if we're already ignoring. */
1553 for (i
= 0; i
< o
; ++i
)
1554 if (conditionals
->ignoring
[i
])
1556 /* We are already ignoring, so just push a level to match the next
1557 "else" or "endif", and keep ignoring. We don't want to expand
1558 variables in the condition. */
1559 conditionals
->ignoring
[o
] = 1;
1563 if (cmdtype
== c_ifdef
|| cmdtype
== c_ifndef
)
1569 /* Expand the thing we're looking up, so we can use indirect and
1570 constructed variable names. */
1571 var
= allocated_variable_expand (line
);
1573 /* Make sure there's only one variable name to test. */
1574 p
= end_of_token (var
);
1581 v
= lookup_variable (var
, i
);
1583 conditionals
->ignoring
[o
] =
1584 ((v
!= 0 && *v
->value
!= '\0') == (cmdtype
== c_ifndef
));
1590 /* "ifeq" or "ifneq". */
1593 char termin
= *line
== '(' ? ',' : *line
;
1595 if (termin
!= ',' && termin
!= '"' && termin
!= '\'')
1599 /* Find the end of the first string. */
1603 for (; *line
!= '\0'; ++line
)
1606 else if (*line
== ')')
1608 else if (*line
== ',' && count
<= 0)
1612 while (*line
!= '\0' && *line
!= termin
)
1620 /* Strip blanks after the first string. */
1622 while (isblank ((unsigned char)p
[-1]))
1629 s2
= variable_expand (s1
);
1630 /* We must allocate a new copy of the expanded string because
1631 variable_expand re-uses the same buffer. */
1633 s1
= alloca (l
+ 1);
1634 memcpy (s1
, s2
, l
+ 1);
1637 /* Find the start of the second string. */
1638 line
= next_token (line
);
1640 termin
= termin
== ',' ? ')' : *line
;
1641 if (termin
!= ')' && termin
!= '"' && termin
!= '\'')
1644 /* Find the end of the second string. */
1648 s2
= next_token (line
);
1649 for (line
= s2
; *line
!= '\0'; ++line
)
1653 else if (*line
== ')')
1666 while (*line
!= '\0' && *line
!= termin
)
1674 line
= next_token (++line
);
1678 s2
= variable_expand (s2
);
1679 conditionals
->ignoring
[o
] = (streq (s1
, s2
) == (cmdtype
== c_ifneq
));
1683 /* Search through the stack to see if we're ignoring. */
1684 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
1685 if (conditionals
->ignoring
[i
])
1690 /* Remove duplicate dependencies in CHAIN. */
1692 static unsigned long
1693 dep_hash_1 (const void *key
)
1695 return_STRING_HASH_1 (dep_name ((struct dep
const *) key
));
1698 static unsigned long
1699 dep_hash_2 (const void *key
)
1701 return_STRING_HASH_2 (dep_name ((struct dep
const *) key
));
1705 dep_hash_cmp (const void *x
, const void *y
)
1707 struct dep
*dx
= (struct dep
*) x
;
1708 struct dep
*dy
= (struct dep
*) y
;
1709 int cmp
= strcmp (dep_name (dx
), dep_name (dy
));
1711 /* If the names are the same but ignore_mtimes are not equal, one of these
1712 is an order-only prerequisite and one isn't. That means that we should
1713 remove the one that isn't and keep the one that is. */
1715 if (!cmp
&& dx
->ignore_mtime
!= dy
->ignore_mtime
)
1716 dx
->ignore_mtime
= dy
->ignore_mtime
= 0;
1723 uniquize_deps (struct dep
*chain
)
1725 struct hash_table deps
;
1726 register struct dep
**depp
;
1728 hash_init (&deps
, 500, dep_hash_1
, dep_hash_2
, dep_hash_cmp
);
1730 /* Make sure that no dependencies are repeated. This does not
1731 really matter for the purpose of updating targets, but it
1732 might make some names be listed twice for $^ and $?. */
1737 struct dep
*dep
= *depp
;
1738 struct dep
**dep_slot
= (struct dep
**) hash_find_slot (&deps
, dep
);
1739 if (HASH_VACANT (*dep_slot
))
1741 hash_insert_at (&deps
, dep
, dep_slot
);
1746 /* Don't bother freeing duplicates.
1747 It's dangerous and little benefit accrues. */
1752 hash_free (&deps
, 0);
1755 /* Record target-specific variable values for files FILENAMES.
1756 TWO_COLON is nonzero if a double colon was used.
1758 The links of FILENAMES are freed, and so are any names in it
1759 that are not incorporated into other data structures.
1761 If the target is a pattern, add the variable to the pattern-specific
1762 variable value list. */
1765 record_target_var (struct nameseq
*filenames
, char *defn
,
1766 enum variable_origin origin
, struct vmodifiers
*vmod
,
1767 const struct floc
*flocp
)
1769 struct nameseq
*nextf
;
1770 struct variable_set_list
*global
;
1772 global
= current_variable_set_list
;
1774 /* If the variable is an append version, store that but treat it as a
1775 normal recursive variable. */
1777 for (; filenames
!= 0; filenames
= nextf
)
1780 const char *name
= filenames
->name
;
1782 const char *percent
;
1783 struct pattern_var
*p
;
1785 nextf
= filenames
->next
;
1788 /* If it's a pattern target, then add it to the pattern-specific
1790 percent
= find_percent_cached (&name
);
1793 /* Get a reference for this pattern-specific variable struct. */
1794 p
= create_pattern_var (name
, percent
);
1795 p
->variable
.fileinfo
= *flocp
;
1796 /* I don't think this can fail since we already determined it was a
1797 variable definition. */
1798 v
= assign_variable_definition (&p
->variable
, defn
);
1802 if (v
->flavor
== f_simple
)
1803 v
->value
= allocated_variable_expand (v
->value
);
1805 v
->value
= xstrdup (v
->value
);
1813 /* Get a file reference for this file, and initialize it.
1814 We don't want to just call enter_file() because that allocates a
1815 new entry if the file is a double-colon, which we don't want in
1817 f
= lookup_file (name
);
1819 f
= enter_file (strcache_add (name
));
1820 else if (f
->double_colon
)
1821 f
= f
->double_colon
;
1823 initialize_file_variables (f
, 1);
1826 current_variable_set_list
= f
->variables
;
1827 v
= try_variable_definition (flocp
, defn
, origin
, 1);
1829 fatal (flocp
, _("Malformed target-specific variable definition"));
1830 current_variable_set_list
= global
;
1833 /* Set up the variable to be *-specific. */
1835 v
->private_var
= vmod
->private_v
;
1836 v
->export
= vmod
->export_v
? v_export
: v_default
;
1838 /* If it's not an override, check to see if there was a command-line
1839 setting. If so, reset the value. */
1840 if (v
->origin
!= o_override
)
1842 struct variable
*gv
;
1843 int len
= strlen(v
->name
);
1845 gv
= lookup_variable (v
->name
, len
);
1846 if (gv
&& (gv
->origin
== o_env_override
|| gv
->origin
== o_command
))
1850 v
->value
= xstrdup (gv
->value
);
1851 v
->origin
= gv
->origin
;
1852 v
->recursive
= gv
->recursive
;
1859 /* Record a description line for files FILENAMES,
1860 with dependencies DEPS, commands to execute described
1861 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
1862 TWO_COLON is nonzero if a double colon was used.
1863 If not nil, PATTERN is the `%' pattern to make this
1864 a static pattern rule, and PATTERN_PERCENT is a pointer
1865 to the `%' within it.
1867 The links of FILENAMES are freed, and so are any names in it
1868 that are not incorporated into other data structures. */
1871 record_files (struct nameseq
*filenames
, const char *pattern
,
1872 const char *pattern_percent
, struct dep
*deps
,
1873 unsigned int cmds_started
, char *commands
,
1874 unsigned int commands_idx
, int two_colon
,
1875 const struct floc
*flocp
)
1877 struct nameseq
*nextf
;
1879 unsigned int max_targets
= 0, target_idx
= 0;
1880 const char **targets
= 0, **target_percents
= 0;
1881 struct commands
*cmds
;
1883 /* If we've already snapped deps, that means we're in an eval being
1884 resolved after the makefiles have been read in. We can't add more rules
1885 at this time, since they won't get snapped and we'll get core dumps.
1886 See Savannah bug # 12124. */
1888 fatal (flocp
, _("prerequisites cannot be defined in recipes"));
1890 if (commands_idx
> 0)
1892 cmds
= xmalloc (sizeof (struct commands
));
1893 cmds
->fileinfo
.filenm
= flocp
->filenm
;
1894 cmds
->fileinfo
.lineno
= cmds_started
;
1895 cmds
->commands
= xstrndup (commands
, commands_idx
);
1896 cmds
->command_lines
= 0;
1901 for (; filenames
!= 0; filenames
= nextf
)
1903 const char *name
= filenames
->name
;
1905 struct dep
*this = 0;
1906 const char *implicit_percent
;
1908 nextf
= filenames
->next
;
1911 /* Check for special targets. Do it here instead of, say, snap_deps()
1912 so that we can immediately use the value. */
1914 if (streq (name
, ".POSIX"))
1916 else if (streq (name
, ".SECONDEXPANSION"))
1917 second_expansion
= 1;
1919 implicit_percent
= find_percent_cached (&name
);
1920 implicit
|= implicit_percent
!= 0;
1925 fatal (flocp
, _("mixed implicit and static pattern rules"));
1927 if (implicit_percent
== 0)
1928 fatal (flocp
, _("mixed implicit and normal rules"));
1933 targets
= xmalloc (5 * sizeof (char *));
1934 target_percents
= xmalloc (5 * sizeof (char *));
1937 else if (target_idx
== max_targets
- 1)
1940 targets
= xrealloc (targets
, max_targets
* sizeof (char *));
1941 target_percents
= xrealloc (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 (strcache_add (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 recipe for target `%s'"),
1990 error (&f
->cmds
->fileinfo
,
1991 _("warning: ignoring old recipe 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
;
2023 /* This is the rule with commands, so put its deps
2024 last. The rationale behind this is that $< expands to
2025 the first dep in the chain, and commands use $<
2026 expecting to get the dep that rule specifies. However
2027 the second expansion algorithm reverses the order thus
2028 we need to make it last here. */
2029 (*d_ptr
)->next
= this;
2030 /* This is a hack. I need a way to communicate to
2031 snap_deps() that the last dependency line in this
2032 file came with commands (so that logic in snap_deps()
2033 can put it in front and all this $< -logic works). I
2034 cannot simply rely on file->cmds being not 0 because
2035 of the cases like the following:
2041 I am going to temporarily "borrow" UPDATING member in
2042 `struct file' for this. */
2047 /* This is a rule without commands. If we already have
2048 a rule with commands and prerequisites (see "hack"
2049 comment above), put these prereqs at the end but
2050 before prereqs from the rule with commands. This way
2051 everything appears in makefile order. */
2054 this->next
= *d_ptr
;
2058 (*d_ptr
)->next
= 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 (strcache_add (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 const char *percent
= "%";
2095 char *buffer
= variable_expand ("");
2096 char *o
= patsubst_expand_pat (buffer
, name
, pattern
, percent
,
2097 pattern_percent
+1, percent
+1);
2098 f
->stem
= strcache_add_len (buffer
, o
- buffer
);
2101 this->staticpattern
= 1;
2102 this->stem
= f
->stem
;
2112 deps
->need_2nd_expansion
= second_expansion
;
2113 create_pattern_rule (targets
, target_percents
, target_idx
,
2114 two_colon
, deps
, cmds
, 1);
2118 /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
2119 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
2120 Quoting backslashes are removed from STRING by compacting it into
2121 itself. Returns a pointer to the first unquoted STOPCHAR if there is
2122 one, or nil if there are none. STOPCHARs inside variable references are
2123 ignored if IGNOREVARS is true.
2125 STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */
2128 find_char_unquote (char *string
, int stop1
, int stop2
, int blank
,
2131 unsigned int string_len
= 0;
2140 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
&& *p
!= stop2
2141 && ! isblank ((unsigned char) *p
))
2144 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
&& *p
!= stop2
)
2147 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
2148 && ! isblank ((unsigned char) *p
))
2151 while (*p
!= '\0' && *p
!= ignorevars
&& *p
!= stop1
)
2157 /* If we stopped due to a variable reference, skip over its contents. */
2158 if (*p
== ignorevars
)
2160 char openparen
= p
[1];
2164 /* Skip the contents of a non-quoted, multi-char variable ref. */
2165 if (openparen
== '(' || openparen
== '{')
2167 unsigned int pcount
= 1;
2168 char closeparen
= (openparen
== '(' ? ')' : '}');
2172 if (*p
== openparen
)
2174 else if (*p
== closeparen
)
2184 /* Skipped the variable reference: look for STOPCHARS again. */
2188 if (p
> string
&& p
[-1] == '\\')
2190 /* Search for more backslashes. */
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 memmove (&p
[i
], &p
[i
/2], (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 % and handle quoting. */
2221 find_percent (char *pattern
)
2223 return find_char_unquote (pattern
, '%', 0, 0, 0);
2226 /* Search STRING for an unquoted % and handle quoting. Returns a pointer to
2227 the % or NULL if no % was found.
2228 This version is used with strings in the string cache: if there's a need to
2229 modify the string a new version will be added to the string cache and
2230 *STRING will be set to that. */
2233 find_percent_cached (const char **string
)
2235 const char *p
= *string
;
2239 /* If the first char is a % return now. This lets us avoid extra tests
2246 while (*p
!= '\0' && *p
!= '%')
2252 /* See if this % is escaped with a backslash; if not we're done. */
2257 /* Search for more backslashes. */
2261 while (&p
[i
] >= *string
&& p
[i
] == '\\')
2265 /* At this point we know we'll need to allocate a new string.
2266 Make a copy if we haven't yet done so. */
2269 slen
= strlen (*string
);
2270 new = alloca (slen
+ 1);
2271 memcpy (new, *string
, slen
+ 1);
2272 p
= new + (p
- *string
);
2276 /* At this point *string, p, and new all point into the same string.
2277 Get a non-const version of p so we can modify new. */
2278 pv
= new + (p
- *string
);
2280 /* The number of backslashes is now -I.
2281 Copy P over itself to swallow half of them. */
2282 memmove (&pv
[i
], &pv
[i
/2], (slen
- (pv
- new)) - (i
/2) + 1);
2285 /* If the backslashes quoted each other; the % was unquoted. */
2291 /* If we had to change STRING, add it to the strcache. */
2294 *string
= strcache_add (*string
);
2295 p
= *string
+ (p
- new);
2298 /* If we didn't find a %, return NULL. Otherwise return a ptr to it. */
2299 return (*p
== '\0') ? NULL
: p
;
2302 /* Parse a string into a sequence of filenames represented as a
2303 chain of struct nameseq's in reverse order and return that chain.
2305 The string is passed as STRINGP, the address of a string pointer.
2306 The string pointer is updated to point at the first character
2307 not parsed, which either is a null char or equals STOPCHAR.
2309 SIZE is how big to construct chain elements.
2310 This is useful if we want them actually to be other structures
2311 that have room for additional info.
2313 If STRIP is nonzero, strip `./'s off the beginning. */
2316 parse_file_seq (char **stringp
, int stopchar
, unsigned int size
, int strip
)
2318 struct nameseq
*new = 0;
2319 struct nameseq
*new1
, *lastnew1
;
2323 # define VMS_COMMA ','
2325 # define VMS_COMMA 0
2333 /* Skip whitespace; see if any more names are left. */
2340 /* There are, so find the end of the next name. */
2342 p
= find_char_unquote (q
, stopchar
, VMS_COMMA
, 1, 0);
2344 /* convert comma separated list to space separated */
2349 if (stopchar
== ':' && p
&& *p
== ':'
2350 && !(isspace ((unsigned char)p
[1]) || !p
[1]
2351 || isspace ((unsigned char)p
[-1])))
2352 p
= find_char_unquote (p
+1, stopchar
, VMS_COMMA
, 1, 0);
2354 #ifdef HAVE_DOS_PATHS
2355 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
2356 first colon which isn't followed by a slash or a backslash.
2357 Note that tokens separated by spaces should be treated as separate
2358 tokens since make doesn't allow path names with spaces */
2359 if (stopchar
== ':')
2360 while (p
!= 0 && !isspace ((unsigned char)*p
) &&
2361 (p
[1] == '\\' || p
[1] == '/') && isalpha ((unsigned char)p
[-1]))
2362 p
= find_char_unquote (p
+ 1, stopchar
, VMS_COMMA
, 1, 0);
2369 /* Skip leading `[]'s. */
2370 while (p
- q
> 2 && q
[0] == '[' && q
[1] == ']')
2372 /* Skip leading `./'s. */
2373 while (p
- q
> 2 && q
[0] == '.' && q
[1] == '/')
2376 q
+= 2; /* Skip "./". */
2377 while (q
< p
&& *q
== '/')
2378 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
2382 /* Extract the filename just found, and skip it. */
2385 /* ".///" was stripped to "". */
2388 #elif defined(_AMIGA)
2395 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need
2396 * to remove this '\' before we can use the filename.
2397 * xstrdup called because q may be read-only string constant.
2400 char *qbase
= xstrdup (q
);
2401 char *pbase
= qbase
+ (p
-q
);
2408 if (*q1
== '\\' && *(q1
+1) == ':')
2415 name
= strcache_add_len (qbase
, p1
- qbase
);
2419 name
= strcache_add_len (q
, p
- q
);
2422 /* Add it to the front of the chain. */
2423 new1
= xmalloc (size
);
2424 memset (new1
, '\0', size
);
2432 /* Look for multi-word archive references.
2433 They are indicated by a elt ending with an unmatched `)' and
2434 an elt further down the chain (i.e., previous in the file list)
2435 with an unmatched `(' (e.g., "lib(mem"). */
2440 if (new1
->name
[0] != '(' /* Don't catch "(%)" and suchlike. */
2441 && new1
->name
[strlen (new1
->name
) - 1] == ')'
2442 && strchr (new1
->name
, '(') == 0)
2444 /* NEW1 ends with a `)' but does not contain a `('.
2445 Look back for an elt with an opening `(' but no closing `)'. */
2447 struct nameseq
*n
= new1
->next
, *lastn
= new1
;
2449 while (n
!= 0 && (paren
= strchr (n
->name
, '(')) == 0)
2455 /* Ignore something starting with `(', as that cannot actually
2456 be an archive-member reference (and treating it as such
2457 results in an empty file name, which causes much lossage). */
2458 && n
->name
[0] != '(')
2460 /* N is the first element in the archive group.
2461 Its name looks like "lib(mem" (with no closing `)'). */
2465 /* Copy "lib(" into LIBNAME. */
2467 libname
= alloca (paren
- n
->name
+ 1);
2468 memcpy (libname
, n
->name
, paren
- n
->name
);
2469 libname
[paren
- n
->name
] = '\0';
2473 /* N was just "lib(", part of something like "lib( a b)".
2474 Edit it out of the chain and free its storage. */
2475 lastn
->next
= n
->next
;
2477 /* LASTN->next is the new stopping elt for the loop below. */
2482 /* Replace N's name with the full archive reference. */
2483 n
->name
= strcache_add (concat (libname
, paren
, ")"));
2486 if (new1
->name
[1] == '\0')
2488 /* NEW1 is just ")", part of something like "lib(a b )".
2489 Omit it from the chain and free its storage. */
2493 lastnew1
->next
= new1
->next
;
2500 /* Replace also NEW1->name, which already has closing `)'. */
2501 new1
->name
= strcache_add (concat (libname
, new1
->name
, ""));
2505 /* Trace back from NEW1 (the end of the list) until N
2506 (the beginning of the list), rewriting each name
2507 with the full archive reference. */
2511 new1
->name
= strcache_add (concat (libname
, new1
->name
, ")"));
2518 /* No frobnication happening. Just step down the list. */
2535 /* Find the next line of text in an eval buffer, combining continuation lines
2537 Return the number of actual lines read (> 1 if continuation lines).
2538 Returns -1 if there's nothing left in the buffer.
2540 After this function, ebuf->buffer points to the first character of the
2544 /* Read a line of text from a STRING.
2545 Since we aren't really reading from a file, don't bother with linenumbers.
2548 static unsigned long
2549 readstring (struct ebuffer
*ebuf
)
2553 /* If there is nothing left in this buffer, return 0. */
2554 if (ebuf
->bufnext
>= ebuf
->bufstart
+ ebuf
->size
)
2557 /* Set up a new starting point for the buffer, and find the end of the
2558 next logical line (taking into account backslash/newline pairs). */
2560 eol
= ebuf
->buffer
= ebuf
->bufnext
;
2568 /* Find the next newline. At EOS, stop. */
2569 eol
= p
= strchr (eol
, '\n');
2572 ebuf
->bufnext
= ebuf
->bufstart
+ ebuf
->size
+ 1;
2576 /* Found a newline; if it's escaped continue; else we're done. */
2577 while (p
> bol
&& *(--p
) == '\\')
2578 backslash
= !backslash
;
2584 /* Overwrite the newline char. */
2586 ebuf
->bufnext
= eol
+1;
2592 readline (struct ebuffer
*ebuf
)
2599 /* The behaviors between string and stream buffers are different enough to
2600 warrant different functions. Do the Right Thing. */
2603 return readstring (ebuf
);
2605 /* When reading from a file, we always start over at the beginning of the
2606 buffer for each new line. */
2608 p
= start
= ebuf
->bufstart
;
2609 end
= p
+ ebuf
->size
;
2612 while (fgets (p
, end
- p
, ebuf
->fp
) != 0)
2621 /* This only happens when the first thing on the line is a '\0'.
2622 It is a pretty hopeless case, but (wonder of wonders) Athena
2623 lossage strikes again! (xmkmf puts NULs in its makefiles.)
2624 There is nothing really to be done; we synthesize a newline so
2625 the following line doesn't appear to be part of this line. */
2627 _("warning: NUL character seen; rest of line ignored"));
2632 /* Jump past the text we just read. */
2635 /* If the last char isn't a newline, the whole line didn't fit into the
2636 buffer. Get some more buffer and try again. */
2640 /* We got a newline, so add one to the count of lines. */
2643 #if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
2644 /* Check to see if the line was really ended with CRLF; if so ignore
2646 if ((p
- start
) > 1 && p
[-2] == '\r')
2654 for (p2
= p
- 2; p2
>= start
; --p2
)
2658 backslash
= !backslash
;
2667 /* It was a backslash/newline combo. If we have more space, read
2672 /* We need more space at the end of our buffer, so realloc it.
2673 Make sure to preserve the current offset of p. */
2676 unsigned long off
= p
- start
;
2678 start
= ebuf
->buffer
= ebuf
->bufstart
= xrealloc (start
, ebuf
->size
);
2680 end
= start
+ ebuf
->size
;
2685 if (ferror (ebuf
->fp
))
2686 pfatal_with_name (ebuf
->floc
.filenm
);
2688 /* If we found some lines, return how many.
2689 If we didn't, but we did find _something_, that indicates we read the last
2690 line of a file with no final newline; return 1.
2691 If we read nothing, we're at EOF; return -1. */
2693 return nlines
? nlines
: p
== ebuf
->bufstart
? -1 : 1;
2696 /* Parse the next "makefile word" from the input buffer, and return info
2699 A "makefile word" is one of:
2701 w_bogus Should never happen
2703 w_static A static word; cannot be expanded
2704 w_variable A word containing one or more variables/functions
2706 w_dcolon A double-colon
2707 w_semicolon A semicolon
2708 w_varassign A variable assignment operator (=, :=, +=, or ?=)
2710 Note that this function is only used when reading certain parts of the
2711 makefile. Don't use it where special rules hold sway (RHS of a variable,
2712 in a command list, etc.) */
2714 static enum make_word_type
2715 get_next_mword (char *buffer
, char *delim
, char **startp
, unsigned int *length
)
2717 enum make_word_type wtype
= w_bogus
;
2718 char *p
= buffer
, *beg
;
2721 /* Skip any leading whitespace. */
2722 while (isblank ((unsigned char)*p
))
2734 wtype
= w_semicolon
;
2738 wtype
= w_varassign
;
2752 wtype
= w_varassign
;
2762 wtype
= w_varassign
;
2767 if (delim
&& strchr (delim
, c
))
2772 /* Did we find something? If so, return now. */
2773 if (wtype
!= w_bogus
)
2776 /* This is some non-operator word. A word consists of the longest
2777 string of characters that doesn't contain whitespace, one of [:=#],
2778 or [?+]=, or one of the chars in the DELIM string. */
2780 /* We start out assuming a static word; if we see a variable we'll
2781 adjust our assumptions then. */
2784 /* We already found the first value of "c", above. */
2799 #ifdef HAVE_DOS_PATHS
2800 /* A word CAN include a colon in its drive spec. The drive
2801 spec is allowed either at the beginning of a word, or as part
2802 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
2804 && (*p
== '/' || *p
== '\\') && isalpha ((unsigned char)p
[-2])
2805 && (p
- beg
== 2 || p
[-3] == '(')))
2814 /* This is a variable reference, so note that it's expandable.
2815 Then read it to the matching close paren. */
2823 /* This is a single-letter variable reference. */
2826 for (count
=0; *p
!= '\0'; ++p
)
2830 else if (*p
== closeparen
&& --count
< 0)
2857 if (delim
&& strchr (delim
, c
))
2875 /* Construct the list of include directories
2876 from the arguments and the default list. */
2879 construct_include_path (const char **arg_dirs
)
2881 #ifdef VAXC /* just don't ask ... */
2890 /* Compute the number of pointers we need in the table. */
2891 idx
= sizeof (default_include_directories
) / sizeof (const char *);
2893 for (cpp
= arg_dirs
; *cpp
!= 0; ++cpp
)
2897 /* Add one for $DJDIR. */
2901 dirs
= xmalloc (idx
* sizeof (const char *));
2906 /* First consider any dirs specified with -I switches.
2907 Ignore any that don't exist. Remember the maximum string length. */
2910 while (*arg_dirs
!= 0)
2912 const char *dir
= *(arg_dirs
++);
2918 expanded
= tilde_expand (dir
);
2923 EINTRLOOP (e
, stat (dir
, &stbuf
));
2924 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2926 unsigned int len
= strlen (dir
);
2927 /* If dir name is written with trailing slashes, discard them. */
2928 while (len
> 1 && dir
[len
- 1] == '/')
2930 if (len
> max_incl_len
)
2932 dirs
[idx
++] = strcache_add_len (dir
, len
);
2939 /* Now add the standard default dirs at the end. */
2943 /* The environment variable $DJDIR holds the root of the DJGPP directory
2944 tree; add ${DJDIR}/include. */
2945 struct variable
*djdir
= lookup_variable ("DJDIR", 5);
2949 unsigned int len
= strlen (djdir
->value
) + 8;
2950 char *defdir
= alloca (len
+ 1);
2952 strcat (strcpy (defdir
, djdir
->value
), "/include");
2953 dirs
[idx
++] = strcache_add (defdir
);
2955 if (len
> max_incl_len
)
2961 for (cpp
= default_include_directories
; *cpp
!= 0; ++cpp
)
2965 EINTRLOOP (e
, stat (*cpp
, &stbuf
));
2966 if (e
== 0 && S_ISDIR (stbuf
.st_mode
))
2968 unsigned int len
= strlen (*cpp
);
2969 /* If dir name is written with trailing slashes, discard them. */
2970 while (len
> 1 && (*cpp
)[len
- 1] == '/')
2972 if (len
> max_incl_len
)
2974 dirs
[idx
++] = strcache_add_len (*cpp
, len
);
2980 /* Now add each dir to the .INCLUDE_DIRS variable. */
2982 for (cpp
= dirs
; *cpp
!= 0; ++cpp
)
2983 do_variable_definition (NILF
, ".INCLUDE_DIRS", *cpp
,
2984 o_default
, f_append
, 0);
2986 include_directories
= dirs
;
2989 /* Expand ~ or ~USER at the beginning of NAME.
2990 Return a newly malloc'd string or 0. */
2993 tilde_expand (const char *name
)
2996 if (name
[1] == '/' || name
[1] == '\0')
2998 extern char *getenv ();
3003 /* Turn off --warn-undefined-variables while we expand HOME. */
3004 int save
= warn_undefined_variables_flag
;
3005 warn_undefined_variables_flag
= 0;
3007 home_dir
= allocated_variable_expand ("$(HOME)");
3009 warn_undefined_variables_flag
= save
;
3012 is_variable
= home_dir
[0] != '\0';
3016 home_dir
= getenv ("HOME");
3018 # if !defined(_AMIGA) && !defined(WINDOWS32)
3019 if (home_dir
== 0 || home_dir
[0] == '\0')
3021 extern char *getlogin ();
3022 char *logname
= getlogin ();
3026 struct passwd
*p
= getpwnam (logname
);
3028 home_dir
= p
->pw_dir
;
3031 # endif /* !AMIGA && !WINDOWS32 */
3034 char *new = xstrdup (concat (home_dir
, "", name
+ 1));
3040 # if !defined(_AMIGA) && !defined(WINDOWS32)
3043 struct passwd
*pwent
;
3044 char *userend
= strchr (name
+ 1, '/');
3047 pwent
= getpwnam (name
+ 1);
3051 return xstrdup (pwent
->pw_dir
);
3053 return xstrdup (concat (pwent
->pw_dir
, "/", userend
+ 1));
3055 else if (userend
!= 0)
3058 # endif /* !AMIGA && !WINDOWS32 */
3063 /* Given a chain of struct nameseq's describing a sequence of filenames,
3064 in reverse of the intended order, return a new chain describing the
3065 result of globbing the filenames. The new chain is in forward order.
3066 The links of the old chain are freed or used in the new chain.
3067 Likewise for the names in the old chain.
3069 SIZE is how big to construct chain elements.
3070 This is useful if we want them actually to be other structures
3071 that have room for additional info. */
3074 multi_glob (struct nameseq
*chain
, unsigned int size
)
3076 void dir_setup_glob (glob_t
*);
3077 struct nameseq
*new = 0;
3078 struct nameseq
*old
;
3079 struct nameseq
*nexto
;
3082 dir_setup_glob (&gl
);
3084 for (old
= chain
; old
!= 0; old
= nexto
)
3087 const char **nlist
= 0;
3097 if (gname
[0] == '~')
3099 char *newname
= tilde_expand (old
->name
);
3105 if (ar_name (gname
))
3107 /* OLD->name is an archive member reference. Replace it with the
3108 archive file name, and save the member name in MEMNAME. We will
3109 glob on the archive name and then reattach MEMNAME later. */
3110 ar_parse_name (gname
, &arname
, &memname
);
3113 #endif /* !NO_ARCHIVES */
3115 r
= glob (gname
, GLOB_NOSORT
|GLOB_ALTDIRFUNC
, NULL
, &gl
);
3119 fatal (NILF
, _("virtual memory exhausted"));
3124 nlist
= (const char **)gl
.gl_pathv
;
3128 /* Not a match or another error; keep this name. */
3134 /* For each matched element, add it to the list. */
3139 /* Try to glob on MEMNAME within the archive. */
3140 struct nameseq
*found
3141 = ar_glob (nlist
[i
], memname
, size
);
3144 /* No matches. Use MEMNAME as-is. */
3145 unsigned int alen
= strlen (nlist
[i
]);
3146 unsigned int mlen
= strlen (memname
);
3148 struct nameseq
*elt
= xmalloc (size
);
3149 memset (elt
, '\0', size
);
3151 name
= alloca (alen
+ 1 + mlen
+ 2);
3152 memcpy (name
, nlist
[i
], alen
);
3154 memcpy (name
+alen
+1, memname
, mlen
);
3155 name
[alen
+ 1 + mlen
] = ')';
3156 name
[alen
+ 1 + mlen
+ 1] = '\0';
3157 elt
->name
= strcache_add (name
);
3163 /* Find the end of the FOUND chain. */
3164 struct nameseq
*f
= found
;
3165 while (f
->next
!= 0)
3168 /* Attach the chain being built to the end of the FOUND
3169 chain, and make FOUND the new NEW chain. */
3175 #endif /* !NO_ARCHIVES */
3177 struct nameseq
*elt
= xmalloc (size
);
3178 memset (elt
, '\0', size
);
3179 elt
->name
= strcache_add (nlist
[i
]);