1 /* Reading and parsing of makefiles for GNU Make.
2 Copyright (C) 1988-2016 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
34 #else /* !WINDOWS32 */
39 struct passwd *getpwnam (char *name);
42 #endif /* !WINDOWS32 */
44 /* A 'struct ebuffer' controls the origin of the makefile we are currently
50 char *buffer; /* Start of the current line in the buffer. */
51 char *bufnext; /* Start of the next line in the buffer. */
52 char *bufstart; /* Start of the entire buffer. */
53 unsigned int size; /* Malloc'd size of buffer. */
54 FILE *fp; /* File, or NULL if this is an internal buffer. */
55 floc floc; /* Info on the file in fp (if any). */
58 /* Track the modifiers we can have on variable assignments */
62 unsigned int assign_v:1;
63 unsigned int define_v:1;
64 unsigned int undefine_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 floc *reading_file = 0;
131 /* The chain of files read by read_all_makefiles. */
133 static struct goaldep *read_files = 0;
135 static struct goaldep *eval_makefile (const char *filename, int flags);
136 static void eval (struct ebuffer *buffer, int flags);
138 static long readline (struct ebuffer *ebuf);
139 static void do_undefine (char *name, enum variable_origin origin,
140 struct ebuffer *ebuf);
141 static struct variable *do_define (char *name, enum variable_origin origin,
142 struct ebuffer *ebuf);
143 static int conditional_line (char *line, int len, const floc *flocp);
144 static void record_files (struct nameseq *filenames, const char *pattern,
145 const char *pattern_percent, char *depstr,
146 unsigned int cmds_started, char *commands,
147 unsigned int commands_idx, int two_colon,
148 char prefix, const floc *flocp);
149 static void record_target_var (struct nameseq *filenames, char *defn,
150 enum variable_origin origin,
151 struct vmodifiers *vmod,
153 static enum make_word_type get_next_mword (char *buffer, char *delim,
154 char **startp, unsigned int *length);
155 static void remove_comments (char *line);
156 static char *find_char_unquote (char *string, int map);
157 static char *unescape_char (char *string, int c);
160 /* Compare a word, both length and contents.
161 P must point to the word to be tested, and WLEN must be the length.
163 #define word1eq(s) (wlen == CSTRLEN (s) && strneq (s, p, CSTRLEN (s)))
166 /* Read in all the makefiles and return a chain of targets to rebuild. */
169 read_all_makefiles (const char **makefiles)
171 unsigned int num_makefiles = 0;
173 /* Create *_LIST variables, to hold the makefiles, targets, and variables
174 we will be reading. */
176 define_variable_cname ("MAKEFILE_LIST", "", o_file, 0);
178 DB (DB_BASIC, (_("Reading makefiles...\n")));
180 /* If there's a non-null variable MAKEFILES, its value is a list of
181 files to read first thing. But don't let it prevent reading the
182 default makefiles and don't let the default goal come from there. */
190 /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
191 int save = warn_undefined_variables_flag;
192 warn_undefined_variables_flag = 0;
194 value = allocated_variable_expand ("$(MAKEFILES)");
196 warn_undefined_variables_flag = save;
199 /* Set NAME to the start of next token and LENGTH to its length.
200 MAKEFILES is updated for finding remaining tokens. */
203 while ((name = find_next_token ((const char **)&p, &length)) != 0)
207 eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
213 /* Read makefiles specified with -f switches. */
216 while (*makefiles != 0)
218 struct goaldep *d = eval_makefile (*makefiles, 0);
221 perror_with_name ("", *makefiles);
223 /* Reuse the storage allocated for the read_file. */
224 *makefiles = dep_name (d);
229 /* If there were no -f switches, try the default names. */
231 if (num_makefiles == 0)
233 static const char *default_makefiles[] =
235 /* all lower case since readdir() (the vms version) 'lowercasifies' */
236 /* TODO: Above is not always true, this needs more work */
237 { "makefile.vms", "gnumakefile", "makefile", 0 };
240 { "GNUmakefile", "Makefile", "SMakefile", 0 };
241 #else /* !Amiga && !VMS */
243 { "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 };
244 #else /* !Amiga && !VMS && !WINDOWS32 */
245 { "GNUmakefile", "makefile", "Makefile", 0 };
246 #endif /* !Amiga && !VMS && !WINDOWS32 */
249 const char **p = default_makefiles;
250 while (*p != 0 && !file_exists_p (*p))
255 eval_makefile (*p, 0);
257 perror_with_name ("", *p);
261 /* No default makefile was found. Add the default makefiles to the
262 'read_files' chain so they will be updated if possible. */
263 struct goaldep *tail = read_files;
264 /* Add them to the tail, after any MAKEFILES variable makefiles. */
265 while (tail != 0 && tail->next != 0)
267 for (p = default_makefiles; *p != 0; ++p)
269 struct goaldep *d = alloc_goaldep ();
270 d->file = enter_file (strcache_add (*p));
271 /* Tell update_goal_chain to bail out as soon as this file is
272 made, and main not to die if we can't make this file. */
273 d->flags = RM_DONTCARE;
288 /* Install a new conditional and return the previous one. */
290 static struct conditionals *
291 install_conditionals (struct conditionals *new)
293 struct conditionals *save = conditionals;
295 memset (new, '\0', sizeof (*new));
301 /* Free the current conditionals and reinstate a saved one. */
304 restore_conditionals (struct conditionals *saved)
306 /* Free any space allocated by conditional_line. */
307 free (conditionals->ignoring);
308 free (conditionals->seen_else);
311 conditionals = saved;
314 static struct goaldep *
315 eval_makefile (const char *filename, int flags)
317 struct goaldep *deps;
323 ebuf.floc.filenm = filename; /* Use the original file name. */
324 ebuf.floc.lineno = 1;
325 ebuf.floc.offset = 0;
327 if (ISDB (DB_VERBOSE))
329 printf (_("Reading makefile '%s'"), filename);
330 if (flags & RM_NO_DEFAULT_GOAL)
331 printf (_(" (no default goal)"));
332 if (flags & RM_INCLUDED)
333 printf (_(" (search path)"));
334 if (flags & RM_DONTCARE)
335 printf (_(" (don't care)"));
336 if (flags & RM_NO_TILDE)
337 printf (_(" (no ~ expansion)"));
341 /* First, get a stream to read. */
343 /* Expand ~ in FILENAME unless it came from 'include',
344 in which case it was already done. */
345 if (!(flags & RM_NO_TILDE) && filename[0] == '~')
347 expanded = tilde_expand (filename);
352 ENULLLOOP (ebuf.fp, fopen (filename, "r"));
354 /* Save the error code so we print the right message later. */
355 makefile_errno = errno;
357 /* Check for unrecoverable errors: out of mem or FILE slots. */
358 switch (makefile_errno)
368 const char *err = strerror (makefile_errno);
369 OS (fatal, reading_file, "%s", err);
373 /* If the makefile wasn't found and it's either a makefile from
374 the 'MAKEFILES' variable or an included makefile,
375 search the included makefile search path for this makefile. */
376 if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
379 for (i = 0; include_directories[i] != 0; ++i)
381 const char *included = concat (3, include_directories[i],
383 ebuf.fp = fopen (included, "r");
392 /* Now we have the final name for this makefile. Enter it into
394 filename = strcache_add (filename);
396 /* Add FILENAME to the chain of read makefiles. */
397 deps = alloc_goaldep ();
398 deps->next = read_files;
400 deps->file = lookup_file (filename);
402 deps->file = enter_file (filename);
403 filename = deps->file->name;
408 /* If the makefile can't be found at all, give up entirely. */
412 /* If we did some searching, errno has the error from the last
413 attempt, rather from FILENAME itself. Store it in case the
414 caller wants to use it in a message. */
415 errno = makefile_errno;
419 /* Set close-on-exec to avoid leaking the makefile to children, such as
422 CLOSE_ON_EXEC (fileno (ebuf.fp));
425 /* Add this makefile to the list. */
426 do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file,
429 /* Evaluate the makefile */
432 ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size);
434 curfile = reading_file;
435 reading_file = &ebuf.floc;
437 eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));
439 reading_file = curfile;
443 free (ebuf.bufstart);
451 eval_buffer (char *buffer, const floc *flocp)
454 struct conditionals *saved;
455 struct conditionals new;
458 /* Evaluate the buffer */
460 ebuf.size = strlen (buffer);
461 ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer;
466 else if (reading_file)
467 ebuf.floc = *reading_file;
470 ebuf.floc.filenm = NULL;
471 ebuf.floc.lineno = 1;
472 ebuf.floc.offset = 0;
475 curfile = reading_file;
476 reading_file = &ebuf.floc;
478 saved = install_conditionals (&new);
482 restore_conditionals (saved);
484 reading_file = curfile;
489 /* Check LINE to see if it's a variable assignment or undefine.
491 It might use one of the modifiers "export", "override", "private", or it
492 might be one of the conditional tokens like "ifdef", "include", etc.
494 If it's not a variable assignment or undefine, VMOD.V_ASSIGN is 0.
497 Returns a pointer to the first non-modifier character, and sets VMOD
498 based on the modifiers found if any, plus V_ASSIGN is 1.
501 parse_var_assignment (const char *line, struct vmodifiers *vmod)
504 memset (vmod, '\0', sizeof (*vmod));
506 /* Find the start of the next token. If there isn't one we're done. */
518 p2 = parse_variable_definition (p, &v);
520 /* If this is a variable assignment, we're done. */
524 /* It's not a variable; see if it's a modifier. */
525 p2 = end_of_token (p);
528 if (word1eq ("export"))
530 else if (word1eq ("override"))
531 vmod->override_v = 1;
532 else if (word1eq ("private"))
534 else if (word1eq ("define"))
536 /* We can't have modifiers after 'define' */
541 else if (word1eq ("undefine"))
543 /* We can't have modifiers after 'undefine' */
544 vmod->undefine_v = 1;
549 /* Not a variable or modifier: this is not a variable assignment. */
552 /* It was a modifier. Try the next word. */
558 /* Found a variable assignment or undefine. */
564 /* Read file FILENAME as a makefile and add its contents to the data base.
566 SET_DEFAULT is true if we are allowed to set the default goal. */
569 eval (struct ebuffer *ebuf, int set_default)
572 unsigned int collapsed_length = 0;
573 unsigned int commands_len = 200;
575 unsigned int commands_idx = 0;
576 unsigned int cmds_started, tgts_started;
577 int ignoring = 0, in_ignored_define = 0;
578 int no_targets = 0; /* Set when reading a rule without targets. */
579 struct nameseq *filenames = 0;
583 char prefix = cmd_prefix;
584 const char *pattern = 0;
585 const char *pattern_percent;
589 #define record_waiting_files() \
592 if (filenames != 0) \
594 fi.lineno = tgts_started; \
596 record_files (filenames, pattern, pattern_percent, depstr, \
597 cmds_started, commands, commands_idx, two_colon, \
607 cmds_started = tgts_started = 1;
609 fstart = &ebuf->floc;
610 fi.filenm = ebuf->floc.filenm;
612 /* Loop over lines in the file.
613 The strategy is to accumulate target names in FILENAMES, dependencies
614 in DEPS and commands in COMMANDS. These are used to define a rule
615 when the start of the next rule (or eof) is encountered.
617 When you see a "continue" in the loop below, that means we are moving on
618 to the next line. If you see record_waiting_files(), then the statement
619 we are parsing also finishes the previous rule. */
621 commands = xmalloc (200);
625 unsigned int linelen;
630 struct vmodifiers vmod;
632 /* At the top of this loop, we are starting a brand new line. */
633 /* Grab the next line to be evaluated */
634 ebuf->floc.lineno += nlines;
635 nlines = readline (ebuf);
637 /* If there is nothing left to eval, we're done. */
643 /* If this is the first line, check for a UTF-8 BOM and skip it. */
644 if (ebuf->floc.lineno == 1 && line[0] == (char)0xEF
645 && line[1] == (char)0xBB && line[2] == (char)0xBF)
650 if (ebuf->floc.filenm)
651 printf (_("Skipping UTF-8 BOM in makefile '%s'\n"),
654 printf (_("Skipping UTF-8 BOM in makefile buffer\n"));
658 /* If this line is empty, skip it. */
662 linelen = strlen (line);
664 /* Check for a shell command line first.
665 If it is not one, we can stop treating cmd_prefix specially. */
666 if (line[0] == cmd_prefix)
669 /* Ignore the commands in a rule with no targets. */
672 /* If there is no preceding rule line, don't treat this line
673 as a command, even though it begins with a recipe prefix.
674 SunOS 4 make appears to behave this way. */
679 /* Yep, this is a shell command, and we don't care. */
682 if (commands_idx == 0)
683 cmds_started = ebuf->floc.lineno;
685 /* Append this command line to the line being accumulated.
686 Skip the initial command prefix character. */
687 if (linelen + commands_idx > commands_len)
689 commands_len = (linelen + commands_idx) * 2;
690 commands = xrealloc (commands, commands_len);
692 memcpy (&commands[commands_idx], line + 1, linelen - 1);
693 commands_idx += linelen - 1;
694 commands[commands_idx++] = '\n';
699 /* This line is not a shell command line. Don't worry about whitespace.
700 Get more space if we need it; we don't need to preserve the current
701 contents of the buffer. */
703 if (collapsed_length < linelen+1)
705 collapsed_length = linelen+1;
707 /* Don't need xrealloc: we don't need to preserve the content. */
708 collapsed = xmalloc (collapsed_length);
710 strcpy (collapsed, line);
711 /* Collapse continuation lines. */
712 collapse_continuations (collapsed);
713 remove_comments (collapsed);
715 /* Get rid if starting space (including formfeed, vtab, etc.) */
719 /* See if this is a variable assignment. We need to do this early, to
720 allow variables with names like 'ifdef', 'export', 'private', etc. */
721 p = parse_var_assignment (p, &vmod);
725 enum variable_origin origin = vmod.override_v ? o_override : o_file;
727 /* If we're ignoring then we're done now. */
731 in_ignored_define = 1;
735 /* Variable assignment ends the previous rule. */
736 record_waiting_files ();
740 do_undefine (p, origin, ebuf);
743 else if (vmod.define_v)
744 v = do_define (p, origin, ebuf);
746 v = try_variable_definition (fstart, p, origin, 0);
751 v->export = v_export;
755 /* This line has been dealt with. */
759 /* If this line is completely empty, ignore it. */
763 p2 = end_of_token (p);
767 /* If we're in an ignored define, skip this line (but maybe get out). */
768 if (in_ignored_define)
770 /* See if this is an endef line (plus optional comment). */
771 if (word1eq ("endef") && STOP_SET (*p2, MAP_COMMENT|MAP_NUL))
772 in_ignored_define = 0;
777 /* Check for conditional state changes. */
779 int i = conditional_line (p, wlen, fstart);
783 O (fatal, fstart, _("invalid syntax in conditional"));
790 /* Nothing to see here... move along. */
794 /* Manage the "export" keyword used outside of variable assignment
795 as well as "unexport". */
796 if (word1eq ("export") || word1eq ("unexport"))
798 int exporting = *p == 'u' ? 0 : 1;
800 /* Export/unexport ends the previous rule. */
801 record_waiting_files ();
803 /* (un)export by itself causes everything to be (un)exported. */
805 export_all_variables = exporting;
812 /* Expand the line so we can use indirect and constructed
813 variable names in an (un)export command. */
814 cp = ap = allocated_variable_expand (p2);
816 for (p = find_next_token (&cp, &l); p != 0;
817 p = find_next_token (&cp, &l))
819 struct variable *v = lookup_variable (p, l);
821 v = define_variable_global (p, l, "", o_file, 0, fstart);
822 v->export = exporting ? v_export : v_noexport;
830 /* Handle the special syntax for vpath. */
831 if (word1eq ("vpath"))
837 /* vpath ends the previous rule. */
838 record_waiting_files ();
840 cp = variable_expand (p2);
841 p = find_next_token (&cp, &l);
844 vpat = xstrndup (p, l);
845 p = find_next_token (&cp, &l);
846 /* No searchpath means remove all previous
847 selective VPATH's with the same pattern. */
850 /* No pattern means remove all previous selective VPATH's. */
852 construct_vpath_list (vpat, p);
858 /* Handle include and variants. */
859 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
861 /* We have found an 'include' line specifying a nested
862 makefile to be read at this point. */
863 struct conditionals *save;
864 struct conditionals new_conditionals;
865 struct nameseq *files;
866 /* "-include" (vs "include") says no error if the file does not
867 exist. "sinclude" is an alias for this from SGI. */
868 int noerror = (p[0] != 'i');
870 /* Include ends the previous rule. */
871 record_waiting_files ();
873 p = allocated_variable_expand (p2);
875 /* If no filenames, it's a no-op. */
882 /* Parse the list of file names. Don't expand archive references! */
884 files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
888 /* Save the state of conditionals and start
889 the included makefile with a clean slate. */
890 save = install_conditionals (&new_conditionals);
892 /* Record the rules that are waiting so they will determine
893 the default goal before those in the included makefile. */
894 record_waiting_files ();
896 /* Read each included makefile. */
899 struct nameseq *next = files->next;
900 int flags = (RM_INCLUDED | RM_NO_TILDE
901 | (noerror ? RM_DONTCARE : 0)
902 | (set_default ? 0 : RM_NO_DEFAULT_GOAL));
904 struct goaldep *d = eval_makefile (files->name, flags);
908 d->error = (unsigned short)errno;
916 /* Restore conditional state. */
917 restore_conditionals (save);
922 /* Handle the load operations. */
923 if (word1eq ("load") || word1eq ("-load"))
925 /* A 'load' line specifies a dynamic object to load. */
926 struct nameseq *files;
927 int noerror = (p[0] == '-');
929 /* Load ends the previous rule. */
930 record_waiting_files ();
932 p = allocated_variable_expand (p2);
934 /* If no filenames, it's a no-op. */
941 /* Parse the list of file names.
942 Don't expand archive references or strip "./" */
944 files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
948 /* Load each file. */
951 struct nameseq *next = files->next;
952 const char *name = files->name;
953 struct goaldep *deps;
956 /* Load the file. 0 means failure. */
957 r = load_file (&ebuf->floc, &name, noerror);
958 if (! r && ! noerror)
959 OS (fatal, &ebuf->floc, _("%s: failed to load"), name);
964 /* Return of -1 means a special load: don't rebuild it. */
968 /* It succeeded, so add it to the list "to be rebuilt". */
969 deps = alloc_goaldep ();
970 deps->next = read_files;
972 deps->file = lookup_file (name);
974 deps->file = enter_file (name);
975 deps->file->loaded = 1;
981 /* This line starts with a tab but was not caught above because there
982 was no preceding target, and the line might have been usable as a
983 variable definition. But now we know it is definitely lossage. */
984 if (line[0] == cmd_prefix)
985 O (fatal, fstart, _("recipe commences before first target"));
987 /* This line describes some target files. This is complicated by
988 the existence of target-specific variables, because we can't
989 expand the entire line until we know if we have one or not. So
990 we expand the line word by word until we find the first ':',
991 then check to see if it's a target-specific variable.
993 In this algorithm, 'lb_next' will point to the beginning of the
994 unexpanded parts of the input buffer, while 'p2' points to the
995 parts of the expanded buffer we haven't searched yet. */
998 enum make_word_type wtype;
999 char *cmdleft, *semip, *lb_next;
1000 unsigned int plen = 0;
1002 const char *end, *beg; /* Helpers for whitespace stripping. */
1004 /* Record the previous rule. */
1006 record_waiting_files ();
1007 tgts_started = fstart->lineno;
1009 /* Search the line for an unquoted ; that is not after an
1011 cmdleft = find_char_unquote (line, MAP_SEMI|MAP_COMMENT|MAP_VARIABLE);
1012 if (cmdleft != 0 && *cmdleft == '#')
1014 /* We found a comment before a semicolon. */
1018 else if (cmdleft != 0)
1019 /* Found one. Cut the line short there before expanding it. */
1020 *(cmdleft++) = '\0';
1023 collapse_continuations (line);
1025 /* We can't expand the entire line, since if it's a per-target
1026 variable we don't want to expand it. So, walk from the
1027 beginning, expanding as we go, and looking for "interesting"
1028 chars. The first word is always expandable. */
1029 wtype = get_next_mword (line, NULL, &lb_next, &wlen);
1034 O (fatal, fstart, _("missing rule before recipe"));
1035 /* This line contained something but turned out to be nothing
1036 but whitespace (a comment?). */
1041 /* We accept and ignore rules without targets for
1042 compatibility with SunOS 4 make. */
1050 p2 = variable_expand_string (NULL, lb_next, wlen);
1057 /* Look for a semicolon in the expanded line. */
1058 cmdleft = find_char_unquote (p2, MAP_SEMI);
1062 unsigned long p2_off = p2 - variable_buffer;
1063 unsigned long cmd_off = cmdleft - variable_buffer;
1064 char *pend = p2 + strlen (p2);
1066 /* Append any remnants of lb, then cut the line short
1067 at the semicolon. */
1070 /* One school of thought says that you shouldn't expand
1071 here, but merely copy, since now you're beyond a ";"
1072 and into a command script. However, the old parser
1073 expanded the whole line, so we continue that for
1074 backwards-compatibility. Also, it wouldn't be
1075 entirely consistent, since we do an unconditional
1076 expand below once we know we don't have a
1077 target-specific variable. */
1078 (void)variable_expand_string (pend, lb_next, (long)-1);
1079 lb_next += strlen (lb_next);
1080 p2 = variable_buffer + p2_off;
1081 cmdleft = variable_buffer + cmd_off + 1;
1085 colonp = find_char_unquote (p2, MAP_COLON);
1086 #ifdef HAVE_DOS_PATHS
1087 /* The drive spec brain-damage strikes again... */
1088 /* Note that the only separators of targets in this context
1089 are whitespace and a left paren. If others are possible,
1090 they should be added to the string in the call to index. */
1091 while (colonp && (colonp[1] == '/' || colonp[1] == '\\') &&
1092 colonp > p2 && isalpha ((unsigned char)colonp[-1]) &&
1093 (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
1094 colonp = find_char_unquote (colonp + 1, MAP_COLON);
1099 wtype = get_next_mword (lb_next, NULL, &lb_next, &wlen);
1105 p2 = variable_expand_string (p2, lb_next, wlen);
1106 /* We don't need to worry about cmdleft here, because if it was
1107 found in the variable_buffer the entire buffer has already
1108 been expanded... we'll never get here. */
1111 p2 = next_token (variable_buffer);
1113 /* If the word we're looking at is EOL, see if there's _anything_
1114 on the line. If not, a variable expanded to nothing, so ignore
1115 it. If so, we can't parse this line so punt. */
1121 /* There's no need to be ivory-tower about this: check for
1122 one of the most common bugs found in makefiles... */
1123 if (cmd_prefix == '\t' && strneq (line, " ", 8))
1124 O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)"));
1126 O (fatal, fstart, _("missing separator"));
1129 /* Make the colon the end-of-string so we know where to stop
1130 looking for targets. Start there again once we're done. */
1132 filenames = PARSE_SIMPLE_SEQ (&p2, struct nameseq);
1138 /* We accept and ignore rules without targets for
1139 compatibility with SunOS 4 make. */
1143 /* This should never be possible; we handled it above. */
1144 assert (*p2 != '\0');
1147 /* Is this a one-colon or two-colon entry? */
1148 two_colon = *p2 == ':';
1152 /* Test to see if it's a target-specific variable. Copy the rest
1153 of the buffer over, possibly temporarily (we'll expand it later
1154 if it's not a target-specific variable). PLEN saves the length
1155 of the unparsed section of p2, for later. */
1156 if (*lb_next != '\0')
1158 unsigned int l = p2 - variable_buffer;
1160 variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1);
1161 p2 = variable_buffer + l;
1164 p2 = parse_var_assignment (p2, &vmod);
1167 /* If there was a semicolon found, add it back, plus anything
1171 unsigned int l = p2 - variable_buffer;
1173 collapse_continuations (semip);
1174 variable_buffer_output (p2 + strlen (p2),
1175 semip, strlen (semip)+1);
1176 p2 = variable_buffer + l;
1178 record_target_var (filenames, p2,
1179 vmod.override_v ? o_override : o_file,
1185 /* This is a normal target, _not_ a target-specific variable.
1186 Unquote any = in the dependency list. */
1187 find_char_unquote (lb_next, MAP_EQUALS);
1189 /* Remember the command prefix for this target. */
1190 prefix = cmd_prefix;
1192 /* We have some targets, so don't ignore the following commands. */
1195 /* Expand the dependencies, etc. */
1196 if (*lb_next != '\0')
1198 unsigned int l = p2 - variable_buffer;
1199 (void) variable_expand_string (p2 + plen, lb_next, (long)-1);
1200 p2 = variable_buffer + l;
1202 /* Look for a semicolon in the expanded line. */
1205 cmdleft = find_char_unquote (p2, MAP_SEMI);
1207 *(cmdleft++) = '\0';
1211 /* Is this a static pattern rule: 'target: %targ: %dep; ...'? */
1212 p = strchr (p2, ':');
1213 while (p != 0 && p[-1] == '\\')
1217 while (*q-- == '\\')
1218 backslash = !backslash;
1220 p = strchr (p + 1, ':');
1225 /* Here, the situation is quite complicated. Let's have a look
1226 at a couple of targets:
1234 The rule is that it's only a target, if there are TWO :'s
1235 OR a space around the :.
1237 if (p && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1])))
1240 #ifdef HAVE_DOS_PATHS
1245 /* For DOS-style paths, skip a "C:\..." or a "C:/..." */
1246 if (p != 0 && (p[1] == '\\' || p[1] == '/') &&
1247 isalpha ((unsigned char)p[-1]) &&
1248 (p == p2 + 1 || strchr (" \t:(", p[-2]) != 0)) {
1249 p = strchr (p + 1, ':');
1252 } while (check_again);
1257 struct nameseq *target;
1258 target = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_COLON, NULL,
1262 O (fatal, fstart, _("missing target pattern"));
1263 else if (target->next != 0)
1264 O (fatal, fstart, _("multiple target patterns"));
1265 pattern_percent = find_percent_cached (&target->name);
1266 pattern = target->name;
1267 if (pattern_percent == 0)
1268 O (fatal, fstart, _("target pattern contains no '%%'"));
1274 /* Strip leading and trailing whitespaces. */
1276 end = beg + strlen (beg) - 1;
1277 strip_whitespace (&beg, &end);
1279 /* Put all the prerequisites here; they'll be parsed later. */
1280 if (beg <= end && *beg != '\0')
1281 depstr = xstrndup (beg, end - beg + 1);
1288 /* Semicolon means rest of line is a command. */
1289 unsigned int l = strlen (cmdleft);
1291 cmds_started = fstart->lineno;
1293 /* Add this command line to the buffer. */
1294 if (l + 2 > commands_len)
1296 commands_len = (l + 2) * 2;
1297 commands = xrealloc (commands, commands_len);
1299 memcpy (commands, cmdleft, l);
1301 commands[commands_idx++] = '\n';
1304 /* Determine if this target should be made default. We used to do
1305 this in record_files() but because of the delayed target recording
1306 and because preprocessor directives are legal in target's commands
1307 it is too late. Consider this fragment for example:
1311 ifeq ($(.DEFAULT_GOAL),foo)
1315 Because the target is not recorded until after ifeq directive is
1316 evaluated the .DEFAULT_GOAL does not contain foo yet as one
1317 would expect. Because of this we have to move the logic here. */
1319 if (set_default && default_goal_var->value[0] == '\0')
1322 struct nameseq *t = filenames;
1324 for (; t != 0; t = t->next)
1327 const char *name = t->name;
1329 /* We have nothing to do if this is an implicit rule. */
1330 if (strchr (name, '%') != 0)
1333 /* See if this target's name does not start with a '.',
1334 unless it contains a slash. */
1335 if (*name == '.' && strchr (name, '/') == 0
1336 #ifdef HAVE_DOS_PATHS
1337 && strchr (name, '\\') == 0
1343 /* If this file is a suffix, don't let it be
1344 the default goal file. */
1345 for (d = suffix_file->deps; d != 0; d = d->next)
1347 register struct dep *d2;
1348 if (*dep_name (d) != '.' && streq (name, dep_name (d)))
1353 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
1355 unsigned int l = strlen (dep_name (d2));
1356 if (!strneq (name, dep_name (d2), l))
1358 if (streq (name + l, dep_name (d)))
1371 define_variable_global (".DEFAULT_GOAL", 13, t->name,
1381 /* We get here except in the case that we just read a rule line.
1382 Record now the last rule we read, so following spurious
1383 commands are properly diagnosed. */
1384 record_waiting_files ();
1389 if (conditionals->if_cmds)
1390 O (fatal, fstart, _("missing 'endif'"));
1392 /* At eof, record the last rule. */
1393 record_waiting_files ();
1400 /* Remove comments from LINE.
1401 This is done by copying the text at LINE onto itself. */
1404 remove_comments (char *line)
1408 comment = find_char_unquote (line, MAP_COMMENT);
1411 /* Cut off the line at the #. */
1415 /* Execute a 'undefine' directive.
1416 The undefine line has already been read, and NAME is the name of
1417 the variable to be undefined. */
1420 do_undefine (char *name, enum variable_origin origin, struct ebuffer *ebuf)
1424 /* Expand the variable name and find the beginning (NAME) and end. */
1425 var = allocated_variable_expand (name);
1426 name = next_token (var);
1428 O (fatal, &ebuf->floc, _("empty variable name"));
1429 p = name + strlen (name) - 1;
1430 while (p > name && ISBLANK (*p))
1434 undefine_variable_global (name, p - name + 1, origin);
1438 /* Execute a 'define' directive.
1439 The first line has already been read, and NAME is the name of
1440 the variable to be defined. The following lines remain to be read. */
1442 static struct variable *
1443 do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf)
1446 struct variable var;
1449 unsigned int length = 100;
1450 char *definition = xmalloc (length);
1451 unsigned int idx = 0;
1454 defstart = ebuf->floc;
1456 p = parse_variable_definition (name, &var);
1458 /* No assignment token, so assume recursive. */
1459 var.flavor = f_recursive;
1462 if (var.value[0] != '\0')
1463 O (error, &defstart, _("extraneous text after 'define' directive"));
1465 /* Chop the string before the assignment token to get the name. */
1466 var.name[var.length] = '\0';
1469 /* Expand the variable name and find the beginning (NAME) and end. */
1470 n = allocated_variable_expand (name);
1471 name = next_token (n);
1472 if (name[0] == '\0')
1473 O (fatal, &defstart, _("empty variable name"));
1474 p = name + strlen (name) - 1;
1475 while (p > name && ISBLANK (*p))
1479 /* Now read the value of the variable. */
1484 long nlines = readline (ebuf);
1486 /* If there is nothing left to be eval'd, there's no 'endef'!! */
1488 O (fatal, &defstart, _("missing 'endef', unterminated 'define'"));
1490 ebuf->floc.lineno += nlines;
1491 line = ebuf->buffer;
1493 collapse_continuations (line);
1495 /* If the line doesn't begin with a tab, test to see if it introduces
1496 another define, or ends one. Stop if we find an 'endef' */
1497 if (line[0] != cmd_prefix)
1499 p = next_token (line);
1502 /* If this is another 'define', increment the level count. */
1503 if ((len == 6 || (len > 6 && ISBLANK (p[6])))
1504 && strneq (p, "define", 6))
1507 /* If this is an 'endef', decrement the count. If it's now 0,
1508 we've found the last one. */
1509 else if ((len == 5 || (len > 5 && ISBLANK (p[5])))
1510 && strneq (p, "endef", 5))
1513 remove_comments (p);
1514 if (*(next_token (p)) != '\0')
1515 O (error, &ebuf->floc,
1516 _("extraneous text after 'endef' directive"));
1523 /* Add this line to the variable definition. */
1524 len = strlen (line);
1525 if (idx + len + 1 > length)
1527 length = (idx + len) * 2;
1528 definition = xrealloc (definition, length + 1);
1531 memcpy (&definition[idx], line, len);
1533 /* Separate lines with a newline. */
1534 definition[idx++] = '\n';
1537 /* We've got what we need; define the variable. */
1539 definition[0] = '\0';
1541 definition[idx - 1] = '\0';
1543 v = do_variable_definition (&defstart, name,
1544 definition, origin, var.flavor, 0);
1550 /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
1551 "ifneq", "else" and "endif".
1552 LINE is the input line, with the command as its first word.
1554 FILENAME and LINENO are the filename and line number in the
1555 current makefile. They are used for error messages.
1557 Value is -2 if the line is not a conditional at all,
1558 -1 if the line is an invalid conditional,
1559 0 if following text should be interpreted,
1560 1 if following text should be ignored. */
1563 conditional_line (char *line, int len, const floc *flocp)
1565 const char *cmdname;
1566 enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype;
1570 /* Compare a word, both length and contents. */
1571 #define word1eq(s) (len == CSTRLEN (s) && strneq (s, line, CSTRLEN (s)))
1572 #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
1574 /* Make sure this line is a conditional. */
1575 chkword ("ifdef", c_ifdef)
1576 else chkword ("ifndef", c_ifndef)
1577 else chkword ("ifeq", c_ifeq)
1578 else chkword ("ifneq", c_ifneq)
1579 else chkword ("else", c_else)
1580 else chkword ("endif", c_endif)
1584 /* Found one: skip past it and any whitespace after it. */
1588 #define EXTRATEXT() OS (error, flocp, _("extraneous text after '%s' directive"), cmdname)
1589 #define EXTRACMD() OS (fatal, flocp, _("extraneous '%s'"), cmdname)
1591 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
1592 if (cmdtype == c_endif)
1597 if (!conditionals->if_cmds)
1600 --conditionals->if_cmds;
1605 /* An 'else' statement can either be simple, or it can have another
1606 conditional after it. */
1607 if (cmdtype == c_else)
1611 if (!conditionals->if_cmds)
1614 o = conditionals->if_cmds - 1;
1616 if (conditionals->seen_else[o])
1617 O (fatal, flocp, _("only one 'else' per conditional"));
1619 /* Change the state of ignorance. */
1620 switch (conditionals->ignoring[o])
1623 /* We've just been interpreting. Never do it again. */
1624 conditionals->ignoring[o] = 2;
1627 /* We've never interpreted yet. Maybe this time! */
1628 conditionals->ignoring[o] = 0;
1632 /* It's a simple 'else'. */
1635 conditionals->seen_else[o] = 1;
1639 /* The 'else' has extra text. That text must be another conditional
1640 and cannot be an 'else' or 'endif'. */
1642 /* Find the length of the next word. */
1643 for (p = line+1; ! STOP_SET (*p, MAP_SPACE|MAP_NUL); ++p)
1647 /* If it's 'else' or 'endif' or an illegal conditional, fail. */
1648 if (word1eq ("else") || word1eq ("endif")
1649 || conditional_line (line, len, flocp) < 0)
1653 /* conditional_line() created a new level of conditional.
1654 Raise it back to this level. */
1655 if (conditionals->ignoring[o] < 2)
1656 conditionals->ignoring[o] = conditionals->ignoring[o+1];
1657 --conditionals->if_cmds;
1663 if (conditionals->allocated == 0)
1665 conditionals->allocated = 5;
1666 conditionals->ignoring = xmalloc (conditionals->allocated);
1667 conditionals->seen_else = xmalloc (conditionals->allocated);
1670 o = conditionals->if_cmds++;
1671 if (conditionals->if_cmds > conditionals->allocated)
1673 conditionals->allocated += 5;
1674 conditionals->ignoring = xrealloc (conditionals->ignoring,
1675 conditionals->allocated);
1676 conditionals->seen_else = xrealloc (conditionals->seen_else,
1677 conditionals->allocated);
1680 /* Record that we have seen an 'if...' but no 'else' so far. */
1681 conditionals->seen_else[o] = 0;
1683 /* Search through the stack to see if we're already ignoring. */
1684 for (i = 0; i < o; ++i)
1685 if (conditionals->ignoring[i])
1687 /* We are already ignoring, so just push a level to match the next
1688 "else" or "endif", and keep ignoring. We don't want to expand
1689 variables in the condition. */
1690 conditionals->ignoring[o] = 1;
1694 if (cmdtype == c_ifdef || cmdtype == c_ifndef)
1700 /* Expand the thing we're looking up, so we can use indirect and
1701 constructed variable names. */
1702 var = allocated_variable_expand (line);
1704 /* Make sure there's only one variable name to test. */
1705 p = end_of_token (var);
1712 v = lookup_variable (var, i);
1714 conditionals->ignoring[o] =
1715 ((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef));
1721 /* "ifeq" or "ifneq". */
1724 char termin = *line == '(' ? ',' : *line;
1726 if (termin != ',' && termin != '"' && termin != '\'')
1730 /* Find the end of the first string. */
1734 for (; *line != '\0'; ++line)
1737 else if (*line == ')')
1739 else if (*line == ',' && count <= 0)
1743 while (*line != '\0' && *line != termin)
1751 /* Strip blanks after the first string. */
1753 while (ISBLANK (p[-1]))
1760 s2 = variable_expand (s1);
1761 /* We must allocate a new copy of the expanded string because
1762 variable_expand re-uses the same buffer. */
1764 s1 = alloca (l + 1);
1765 memcpy (s1, s2, l + 1);
1768 /* Find the start of the second string. */
1771 termin = termin == ',' ? ')' : *line;
1772 if (termin != ')' && termin != '"' && termin != '\'')
1775 /* Find the end of the second string. */
1779 s2 = next_token (line);
1780 for (line = s2; *line != '\0'; ++line)
1784 else if (*line == ')')
1797 while (*line != '\0' && *line != termin)
1809 s2 = variable_expand (s2);
1810 conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
1814 /* Search through the stack to see if we're ignoring. */
1815 for (i = 0; i < conditionals->if_cmds; ++i)
1816 if (conditionals->ignoring[i])
1822 /* Record target-specific variable values for files FILENAMES.
1823 TWO_COLON is nonzero if a double colon was used.
1825 The links of FILENAMES are freed, and so are any names in it
1826 that are not incorporated into other data structures.
1828 If the target is a pattern, add the variable to the pattern-specific
1829 variable value list. */
1832 record_target_var (struct nameseq *filenames, char *defn,
1833 enum variable_origin origin, struct vmodifiers *vmod,
1836 struct nameseq *nextf;
1837 struct variable_set_list *global;
1839 global = current_variable_set_list;
1841 /* If the variable is an append version, store that but treat it as a
1842 normal recursive variable. */
1844 for (; filenames != 0; filenames = nextf)
1847 const char *name = filenames->name;
1848 const char *percent;
1849 struct pattern_var *p;
1851 nextf = filenames->next;
1852 free_ns (filenames);
1854 /* If it's a pattern target, then add it to the pattern-specific
1856 percent = find_percent_cached (&name);
1859 /* Get a reference for this pattern-specific variable struct. */
1860 p = create_pattern_var (name, percent);
1861 p->variable.fileinfo = *flocp;
1862 /* I don't think this can fail since we already determined it was a
1863 variable definition. */
1864 v = assign_variable_definition (&p->variable, defn);
1868 if (v->flavor == f_simple)
1869 v->value = allocated_variable_expand (v->value);
1871 v->value = xstrdup (v->value);
1877 /* Get a file reference for this file, and initialize it.
1878 We don't want to just call enter_file() because that allocates a
1879 new entry if the file is a double-colon, which we don't want in
1881 f = lookup_file (name);
1883 f = enter_file (strcache_add (name));
1884 else if (f->double_colon)
1885 f = f->double_colon;
1887 initialize_file_variables (f, 1);
1889 current_variable_set_list = f->variables;
1890 v = try_variable_definition (flocp, defn, origin, 1);
1892 O (fatal, flocp, _("Malformed target-specific variable definition"));
1893 current_variable_set_list = global;
1896 /* Set up the variable to be *-specific. */
1898 v->private_var = vmod->private_v;
1899 v->export = vmod->export_v ? v_export : v_default;
1901 /* If it's not an override, check to see if there was a command-line
1902 setting. If so, reset the value. */
1903 if (v->origin != o_override)
1905 struct variable *gv;
1906 int len = strlen (v->name);
1908 gv = lookup_variable (v->name, len);
1910 && (gv->origin == o_env_override || gv->origin == o_command))
1913 v->value = xstrdup (gv->value);
1914 v->origin = gv->origin;
1915 v->recursive = gv->recursive;
1922 /* Record a description line for files FILENAMES,
1923 with dependencies DEPS, commands to execute described
1924 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
1925 TWO_COLON is nonzero if a double colon was used.
1926 If not nil, PATTERN is the '%' pattern to make this
1927 a static pattern rule, and PATTERN_PERCENT is a pointer
1928 to the '%' within it.
1930 The links of FILENAMES are freed, and so are any names in it
1931 that are not incorporated into other data structures. */
1934 record_files (struct nameseq *filenames, const char *pattern,
1935 const char *pattern_percent, char *depstr,
1936 unsigned int cmds_started, char *commands,
1937 unsigned int commands_idx, int two_colon,
1938 char prefix, const floc *flocp)
1940 struct commands *cmds;
1942 const char *implicit_percent;
1945 /* If we've already snapped deps, that means we're in an eval being
1946 resolved after the makefiles have been read in. We can't add more rules
1947 at this time, since they won't get snapped and we'll get core dumps.
1948 See Savannah bug # 12124. */
1950 O (fatal, flocp, _("prerequisites cannot be defined in recipes"));
1952 /* Determine if this is a pattern rule or not. */
1953 name = filenames->name;
1954 implicit_percent = find_percent_cached (&name);
1956 /* If there's a recipe, set up a struct for it. */
1957 if (commands_idx > 0)
1959 cmds = xmalloc (sizeof (struct commands));
1960 cmds->fileinfo.filenm = flocp->filenm;
1961 cmds->fileinfo.lineno = cmds_started;
1962 cmds->fileinfo.offset = 0;
1963 cmds->commands = xstrndup (commands, commands_idx);
1964 cmds->command_lines = 0;
1965 cmds->recipe_prefix = prefix;
1970 /* If there's a prereq string then parse it--unless it's eligible for 2nd
1971 expansion: if so, snap_deps() will do it. */
1976 depstr = unescape_char (depstr, ':');
1977 if (second_expansion && strchr (depstr, '$'))
1979 deps = alloc_dep ();
1980 deps->name = depstr;
1981 deps->need_2nd_expansion = 1;
1982 deps->staticpattern = pattern != 0;
1986 deps = split_prereqs (depstr);
1989 /* We'll enter static pattern prereqs later when we have the stem.
1990 We don't want to enter pattern rules at all so that we don't
1991 think that they ought to exist (make manual "Implicit Rule Search
1992 Algorithm", item 5c). */
1993 if (! pattern && ! implicit_percent)
1994 deps = enter_prereqs (deps, NULL);
1998 /* For implicit rules, _all_ the targets must have a pattern. That means we
1999 can test the first one to see if we're working with an implicit rule; if
2000 so we handle it specially. */
2002 if (implicit_percent)
2004 struct nameseq *nextf;
2005 const char **targets, **target_pats;
2009 O (fatal, flocp, _("mixed implicit and static pattern rules"));
2011 /* Count the targets to create an array of target names.
2012 We already have the first one. */
2013 nextf = filenames->next;
2014 free_ns (filenames);
2017 for (c = 1; nextf; ++c, nextf = nextf->next)
2019 targets = xmalloc (c * sizeof (const char *));
2020 target_pats = xmalloc (c * sizeof (const char *));
2023 target_pats[0] = implicit_percent;
2028 name = filenames->name;
2029 implicit_percent = find_percent_cached (&name);
2031 if (implicit_percent == 0)
2032 O (fatal, flocp, _("mixed implicit and normal rules"));
2035 target_pats[c] = implicit_percent;
2038 nextf = filenames->next;
2039 free_ns (filenames);
2043 create_pattern_rule (targets, target_pats, c, two_colon, deps, cmds, 1);
2049 /* Walk through each target and create it in the database.
2050 We already set up the first target, above. */
2053 struct nameseq *nextf = filenames->next;
2055 struct dep *this = 0;
2057 free_ns (filenames);
2059 /* Check for special targets. Do it here instead of, say, snap_deps()
2060 so that we can immediately use the value. */
2061 if (streq (name, ".POSIX"))
2064 define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0);
2065 /* These default values are based on IEEE Std 1003.1-2008. */
2066 define_variable_cname ("ARFLAGS", "-rv", o_default, 0);
2067 define_variable_cname ("CC", "c99", o_default, 0);
2068 define_variable_cname ("CFLAGS", "-O", o_default, 0);
2069 define_variable_cname ("FC", "fort77", o_default, 0);
2070 define_variable_cname ("FFLAGS", "-O 1", o_default, 0);
2071 define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0);
2073 else if (streq (name, ".SECONDEXPANSION"))
2074 second_expansion = 1;
2075 #if !defined (__MSDOS__) && !defined (__EMX__)
2076 else if (streq (name, ".ONESHELL"))
2080 /* If this is a static pattern rule:
2081 'targets: target%pattern: prereq%pattern; recipe',
2082 make sure the pattern matches this target name. */
2083 if (pattern && !pattern_matches (pattern, pattern_percent, name))
2085 _("target '%s' doesn't match the target pattern"), name);
2087 /* If there are multiple targets, copy the chain DEPS for all but the
2088 last one. It is not safe for the same deps to go in more than one
2089 place in the database. */
2090 this = nextf != 0 ? copy_dep_chain (deps) : deps;
2092 /* Find or create an entry in the file database for this target. */
2095 /* Single-colon. Combine this rule with the file's existing record,
2097 f = enter_file (strcache_add (name));
2098 if (f->double_colon)
2100 _("target file '%s' has both : and :: entries"), f->name);
2102 /* If CMDS == F->CMDS, this target was listed in this rule
2103 more than once. Just give a warning since this is harmless. */
2104 if (cmds != 0 && cmds == f->cmds)
2106 _("target '%s' given more than once in the same rule"),
2109 /* Check for two single-colon entries both with commands.
2110 Check is_target so that we don't lose on files such as .c.o
2111 whose commands were preinitialized. */
2112 else if (cmds != 0 && f->cmds != 0 && f->is_target)
2114 size_t l = strlen (f->name);
2115 error (&cmds->fileinfo, l,
2116 _("warning: overriding recipe for target '%s'"),
2118 error (&f->cmds->fileinfo, l,
2119 _("warning: ignoring old recipe for target '%s'"),
2123 /* Defining .DEFAULT with no deps or cmds clears it. */
2124 if (f == default_file && this == 0 && cmds == 0)
2129 /* Defining .SUFFIXES with no dependencies clears out the list of
2131 if (f == suffix_file && this == 0)
2133 free_dep_chain (f->deps);
2139 /* Double-colon. Make a new record even if there already is one. */
2140 f = lookup_file (name);
2142 /* Check for both : and :: rules. Check is_target so we don't lose
2143 on default suffix rules or makefiles. */
2144 if (f != 0 && f->is_target && !f->double_colon)
2146 _("target file '%s' has both : and :: entries"), f->name);
2148 f = enter_file (strcache_add (name));
2149 /* If there was an existing entry and it was a double-colon entry,
2150 enter_file will have returned a new one, making it the prev
2151 pointer of the old one, and setting its double_colon pointer to
2153 if (f->double_colon == 0)
2154 /* This is the first entry for this name, so we must set its
2155 double_colon pointer to itself. */
2156 f->double_colon = f;
2163 /* If this is a static pattern rule, set the stem to the part of its
2164 name that matched the '%' in the pattern, so you can use $* in the
2165 commands. If we didn't do it before, enter the prereqs now. */
2168 static const char *percent = "%";
2169 char *buffer = variable_expand ("");
2170 char *o = patsubst_expand_pat (buffer, name, pattern, percent,
2171 pattern_percent+1, percent+1);
2172 f->stem = strcache_add_len (buffer, o - buffer);
2175 if (! this->need_2nd_expansion)
2176 this = enter_prereqs (this, f->stem);
2178 this->stem = f->stem;
2182 /* Add the dependencies to this file entry. */
2185 /* Add the file's old deps and the new ones in THIS together. */
2190 struct dep *d = this;
2192 /* If this rule has commands, put these deps first. */
2193 while (d->next != 0)
2201 struct dep *d = f->deps;
2203 /* A rule without commands: put its prereqs at the end. */
2204 while (d->next != 0)
2213 /* All done! Set up for the next one. */
2219 /* Reduce escaped percents. If there are any unescaped it's an error */
2220 name = filenames->name;
2221 if (find_percent_cached (&name))
2223 _("*** mixed implicit and normal rules: deprecated syntax"));
2227 /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
2228 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
2229 Quoting backslashes are removed from STRING by compacting it into
2230 itself. Returns a pointer to the first unquoted STOPCHAR if there is
2231 one, or nil if there are none. STOPCHARs inside variable references are
2232 ignored if IGNOREVARS is true.
2234 STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */
2237 find_char_unquote (char *string, int map)
2239 unsigned int string_len = 0;
2242 /* Always stop on NUL. */
2247 while (! STOP_SET (*p, map))
2253 /* If we stopped due to a variable reference, skip over its contents. */
2254 if (STOP_SET (*p, MAP_VARIABLE))
2256 char openparen = p[1];
2258 /* Check if '$' is the last character in the string. */
2259 if (openparen == '\0')
2264 /* Skip the contents of a non-quoted, multi-char variable ref. */
2265 if (openparen == '(' || openparen == '{')
2267 unsigned int pcount = 1;
2268 char closeparen = (openparen == '(' ? ')' : '}');
2272 if (*p == openparen)
2274 else if (*p == closeparen)
2284 /* Skipped the variable reference: look for STOPCHARS again. */
2288 if (p > string && p[-1] == '\\')
2290 /* Search for more backslashes. */
2292 while (&p[i] >= string && p[i] == '\\')
2295 /* Only compute the length if really needed. */
2296 if (string_len == 0)
2297 string_len = strlen (string);
2298 /* The number of backslashes is now -I.
2299 Copy P over itself to swallow half of them. */
2300 memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
2303 /* All the backslashes quoted each other; the STOPCHAR was
2307 /* The STOPCHAR was quoted by a backslash. Look for another. */
2310 /* No backslash in sight. */
2314 /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
2318 /* Unescape a character in a string. The string is compressed onto itself. */
2321 unescape_char (char *string, int c)
2333 /* We found a backslash. See if it's escaping our character. */
2338 if (*e != c || l%2 == 0)
2340 /* It's not; just take it all without unescaping. */
2344 // If we hit the end of the string, we're done
2350 /* It is, and there's >1 backslash. Take half of them. */
2366 /* Search PATTERN for an unquoted % and handle quoting. */
2369 find_percent (char *pattern)
2371 return find_char_unquote (pattern, MAP_PERCENT);
2374 /* Search STRING for an unquoted % and handle quoting. Returns a pointer to
2375 the % or NULL if no % was found.
2376 This version is used with strings in the string cache: if there's a need to
2377 modify the string a new version will be added to the string cache and
2378 *STRING will be set to that. */
2381 find_percent_cached (const char **string)
2383 const char *p = *string;
2387 /* If the first char is a % return now. This lets us avoid extra tests
2394 while (! STOP_SET (*p, MAP_PERCENT|MAP_NUL))
2400 /* See if this % is escaped with a backslash; if not we're done. */
2405 /* Search for more backslashes. */
2409 while (&p[i] >= *string && p[i] == '\\')
2413 /* At this point we know we'll need to allocate a new string.
2414 Make a copy if we haven't yet done so. */
2417 slen = strlen (*string);
2418 new = alloca (slen + 1);
2419 memcpy (new, *string, slen + 1);
2420 p = new + (p - *string);
2424 /* At this point *string, p, and new all point into the same string.
2425 Get a non-const version of p so we can modify new. */
2426 pv = new + (p - *string);
2428 /* The number of backslashes is now -I.
2429 Copy P over itself to swallow half of them. */
2430 memmove (&pv[i], &pv[i/2], (slen - (pv - new)) - (i/2) + 1);
2433 /* If the backslashes quoted each other; the % was unquoted. */
2439 /* If we had to change STRING, add it to the strcache. */
2442 *string = strcache_add (*string);
2443 p = *string + (p - new);
2446 /* If we didn't find a %, return NULL. Otherwise return a ptr to it. */
2447 return (*p == '\0') ? NULL : p;
2450 /* Find the next line of text in an eval buffer, combining continuation lines
2452 Return the number of actual lines read (> 1 if continuation lines).
2453 Returns -1 if there's nothing left in the buffer.
2455 After this function, ebuf->buffer points to the first character of the
2459 /* Read a line of text from a STRING.
2460 Since we aren't really reading from a file, don't bother with linenumbers.
2464 readstring (struct ebuffer *ebuf)
2468 /* If there is nothing left in this buffer, return 0. */
2469 if (ebuf->bufnext >= ebuf->bufstart + ebuf->size)
2472 /* Set up a new starting point for the buffer, and find the end of the
2473 next logical line (taking into account backslash/newline pairs). */
2475 eol = ebuf->buffer = ebuf->bufnext;
2480 const char *bol = eol;
2483 /* Find the next newline. At EOS, stop. */
2484 p = eol = strchr (eol , '\n');
2487 ebuf->bufnext = ebuf->bufstart + ebuf->size + 1;
2491 /* Found a newline; if it's escaped continue; else we're done. */
2492 while (p > bol && *(--p) == '\\')
2493 backslash = !backslash;
2499 /* Overwrite the newline char. */
2501 ebuf->bufnext = eol+1;
2507 readline (struct ebuffer *ebuf)
2514 /* The behaviors between string and stream buffers are different enough to
2515 warrant different functions. Do the Right Thing. */
2518 return readstring (ebuf);
2520 /* When reading from a file, we always start over at the beginning of the
2521 buffer for each new line. */
2523 p = start = ebuf->bufstart;
2524 end = p + ebuf->size;
2527 while (fgets (p, end - p, ebuf->fp) != 0)
2536 /* This only happens when the first thing on the line is a '\0'.
2537 It is a pretty hopeless case, but (wonder of wonders) Athena
2538 lossage strikes again! (xmkmf puts NULs in its makefiles.)
2539 There is nothing really to be done; we synthesize a newline so
2540 the following line doesn't appear to be part of this line. */
2541 O (error, &ebuf->floc,
2542 _("warning: NUL character seen; rest of line ignored"));
2547 /* Jump past the text we just read. */
2550 /* If the last char isn't a newline, the whole line didn't fit into the
2551 buffer. Get some more buffer and try again. */
2555 /* We got a newline, so add one to the count of lines. */
2558 #if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
2559 /* Check to see if the line was really ended with CRLF; if so ignore
2561 if ((p - start) > 1 && p[-2] == '\r')
2564 memmove (p-1, p, strlen (p) + 1);
2569 for (p2 = p - 2; p2 >= start; --p2)
2573 backslash = !backslash;
2582 /* It was a backslash/newline combo. If we have more space, read
2587 /* We need more space at the end of our buffer, so realloc it.
2588 Make sure to preserve the current offset of p. */
2591 unsigned long off = p - start;
2593 start = ebuf->buffer = ebuf->bufstart = xrealloc (start, ebuf->size);
2595 end = start + ebuf->size;
2600 if (ferror (ebuf->fp))
2601 pfatal_with_name (ebuf->floc.filenm);
2603 /* If we found some lines, return how many.
2604 If we didn't, but we did find _something_, that indicates we read the last
2605 line of a file with no final newline; return 1.
2606 If we read nothing, we're at EOF; return -1. */
2608 return nlines ? nlines : p == ebuf->bufstart ? -1 : 1;
2611 /* Parse the next "makefile word" from the input buffer, and return info
2614 A "makefile word" is one of:
2616 w_bogus Should never happen
2618 w_static A static word; cannot be expanded
2619 w_variable A word containing one or more variables/functions
2621 w_dcolon A double-colon
2622 w_semicolon A semicolon
2623 w_varassign A variable assignment operator (=, :=, ::=, +=, ?=, or !=)
2625 Note that this function is only used when reading certain parts of the
2626 makefile. Don't use it where special rules hold sway (RHS of a variable,
2627 in a command list, etc.) */
2629 static enum make_word_type
2630 get_next_mword (char *buffer, char *delim, char **startp, unsigned int *length)
2632 enum make_word_type wtype = w_bogus;
2633 char *p = buffer, *beg;
2636 /* Skip any leading whitespace. */
2637 while (ISBLANK (*p))
2649 wtype = w_semicolon;
2653 wtype = w_varassign;
2666 wtype = w_varassign;
2673 wtype = w_varassign;
2684 wtype = w_varassign;
2689 if (delim && strchr (delim, c))
2694 /* Did we find something? If so, return now. */
2695 if (wtype != w_bogus)
2698 /* This is some non-operator word. A word consists of the longest
2699 string of characters that doesn't contain whitespace, one of [:=#],
2700 or [?+!]=, or one of the chars in the DELIM string. */
2702 /* We start out assuming a static word; if we see a variable we'll
2703 adjust our assumptions then. */
2706 /* We already found the first value of "c", above. */
2721 #ifdef HAVE_DOS_PATHS
2722 /* A word CAN include a colon in its drive spec. The drive
2723 spec is allowed either at the beginning of a word, or as part
2724 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
2726 && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
2727 && (p - beg == 2 || p[-3] == '(')))
2738 /* This is a variable reference, so note that it's expandable.
2739 Then read it to the matching close paren. */
2747 /* This is a single-letter variable reference. */
2750 for (count=0; *p != '\0'; ++p)
2754 else if (*p == closeparen && --count < 0)
2781 if (delim && strchr (delim, c))
2799 /* Construct the list of include directories
2800 from the arguments and the default list. */
2803 construct_include_path (const char **arg_dirs)
2805 #ifdef VAXC /* just don't ask ... */
2814 /* Compute the number of pointers we need in the table. */
2815 idx = sizeof (default_include_directories) / sizeof (const char *);
2817 for (cpp = arg_dirs; *cpp != 0; ++cpp)
2821 /* Add one for $DJDIR. */
2825 dirs = xmalloc (idx * sizeof (const char *));
2830 /* First consider any dirs specified with -I switches.
2831 Ignore any that don't exist. Remember the maximum string length. */
2834 while (*arg_dirs != 0)
2836 const char *dir = *(arg_dirs++);
2842 expanded = tilde_expand (dir);
2847 EINTRLOOP (e, stat (dir, &stbuf));
2848 if (e == 0 && S_ISDIR (stbuf.st_mode))
2850 unsigned int len = strlen (dir);
2851 /* If dir name is written with trailing slashes, discard them. */
2852 while (len > 1 && dir[len - 1] == '/')
2854 if (len > max_incl_len)
2856 dirs[idx++] = strcache_add_len (dir, len);
2862 /* Now add the standard default dirs at the end. */
2866 /* The environment variable $DJDIR holds the root of the DJGPP directory
2867 tree; add ${DJDIR}/include. */
2868 struct variable *djdir = lookup_variable ("DJDIR", 5);
2872 unsigned int len = strlen (djdir->value) + 8;
2873 char *defdir = alloca (len + 1);
2875 strcat (strcpy (defdir, djdir->value), "/include");
2876 dirs[idx++] = strcache_add (defdir);
2878 if (len > max_incl_len)
2884 for (cpp = default_include_directories; *cpp != 0; ++cpp)
2888 EINTRLOOP (e, stat (*cpp, &stbuf));
2889 if (e == 0 && S_ISDIR (stbuf.st_mode))
2891 unsigned int len = strlen (*cpp);
2892 /* If dir name is written with trailing slashes, discard them. */
2893 while (len > 1 && (*cpp)[len - 1] == '/')
2895 if (len > max_incl_len)
2897 dirs[idx++] = strcache_add_len (*cpp, len);
2903 /* Now add each dir to the .INCLUDE_DIRS variable. */
2905 for (cpp = dirs; *cpp != 0; ++cpp)
2906 do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp,
2907 o_default, f_append, 0);
2909 include_directories = dirs;
2912 /* Expand ~ or ~USER at the beginning of NAME.
2913 Return a newly malloc'd string or 0. */
2916 tilde_expand (const char *name)
2919 if (name[1] == '/' || name[1] == '\0')
2925 /* Turn off --warn-undefined-variables while we expand HOME. */
2926 int save = warn_undefined_variables_flag;
2927 warn_undefined_variables_flag = 0;
2929 home_dir = allocated_variable_expand ("$(HOME)");
2931 warn_undefined_variables_flag = save;
2934 is_variable = home_dir[0] != '\0';
2938 home_dir = getenv ("HOME");
2940 # if !defined(_AMIGA) && !defined(WINDOWS32)
2941 if (home_dir == 0 || home_dir[0] == '\0')
2943 char *logname = getlogin ();
2947 struct passwd *p = getpwnam (logname);
2949 home_dir = p->pw_dir;
2952 # endif /* !AMIGA && !WINDOWS32 */
2955 char *new = xstrdup (concat (2, home_dir, name + 1));
2961 # if !defined(_AMIGA) && !defined(WINDOWS32)
2964 struct passwd *pwent;
2965 char *userend = strchr (name + 1, '/');
2968 pwent = getpwnam (name + 1);
2972 return xstrdup (pwent->pw_dir);
2974 return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1));
2976 else if (userend != 0)
2979 # endif /* !AMIGA && !WINDOWS32 */
2984 /* Parse a string into a sequence of filenames represented as a chain of
2985 struct nameseq's and return that chain. Optionally expand the strings via
2988 The string is passed as STRINGP, the address of a string pointer.
2989 The string pointer is updated to point at the first character
2990 not parsed, which either is a null char or equals STOPCHAR.
2992 SIZE is how big to construct chain elements.
2993 This is useful if we want them actually to be other structures
2994 that have room for additional info.
2996 PREFIX, if non-null, is added to the beginning of each filename.
2998 FLAGS allows one or more of the following bitflags to be set:
2999 PARSEFS_NOSTRIP - Do no strip './'s off the beginning
3000 PARSEFS_NOAR - Do not check filenames for archive references
3001 PARSEFS_NOGLOB - Do not expand globbing characters
3002 PARSEFS_EXISTS - Only return globbed files that actually exist
3003 (cannot also set NOGLOB)
3004 PARSEFS_NOCACHE - Do not add filenames to the strcache (caller frees)
3008 parse_file_seq (char **stringp, unsigned int size, int stopmap,
3009 const char *prefix, int flags)
3011 /* tmp points to tmpbuf after the prefix, if any.
3012 tp is the end of the buffer. */
3013 static char *tmpbuf = NULL;
3015 int cachep = NONE_SET (flags, PARSEFS_NOCACHE);
3017 struct nameseq *new = 0;
3018 struct nameseq **newp = &new;
3019 #define NEWELT(_n) do { \
3020 const char *__n = (_n); \
3021 *newp = xcalloc (size); \
3022 (*newp)->name = (cachep ? strcache_add (__n) : xstrdup (__n)); \
3023 newp = &(*newp)->next; \
3030 /* Always stop on NUL. */
3033 if (size < sizeof (struct nameseq))
3034 size = sizeof (struct nameseq);
3036 if (NONE_SET (flags, PARSEFS_NOGLOB))
3037 dir_setup_glob (&gl);
3039 /* Get enough temporary space to construct the largest possible target. */
3041 static int tmpbuf_len = 0;
3042 int l = strlen (*stringp) + 1;
3045 tmpbuf = xrealloc (tmpbuf, l);
3051 /* Parse STRING. P will always point to the end of the parsed content. */
3056 const char **nlist = 0;
3067 /* Skip whitespace; at the end of the string or STOPCHAR we're done. */
3069 if (STOP_SET (*p, stopmap))
3072 /* There are names left, so find the end of the next name.
3073 Throughout this iteration S points to the start. */
3075 p = find_char_unquote (p, stopmap|MAP_VMSCOMMA|MAP_BLANK);
3077 /* convert comma separated list to space separated */
3082 if (p && STOP_SET (*p, stopmap & MAP_COLON)
3083 && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1])))
3084 p = find_char_unquote (p+1, stopmap|MAP_VMSCOMMA|MAP_BLANK);
3086 #ifdef HAVE_DOS_PATHS
3087 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
3088 first colon which isn't followed by a slash or a backslash.
3089 Note that tokens separated by spaces should be treated as separate
3090 tokens since make doesn't allow path names with spaces */
3091 if (stopmap | MAP_COLON)
3092 while (p != 0 && !ISSPACE (*p) &&
3093 (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))
3094 p = find_char_unquote (p + 1, stopmap|MAP_VMSCOMMA|MAP_BLANK);
3099 /* Strip leading "this directory" references. */
3100 if (NONE_SET (flags, PARSEFS_NOSTRIP))
3102 /* Skip leading '[]'s. should only be one set or bug somwhere else */
3103 if (p - s > 2 && s[0] == '[' && s[1] == ']')
3105 /* Skip leading '<>'s. should only be one set or bug somwhere else */
3106 if (p - s > 2 && s[0] == '<' && s[1] == '>')
3109 /* Skip leading './'s. */
3110 while (p - s > 2 && s[0] == '.' && s[1] == '/')
3112 /* Skip "./" and all following slashes. */
3118 /* Extract the filename just found, and skip it.
3119 Set NAME to the string, and NLEN to its length. */
3123 /* The name was stripped to empty ("./"). */
3125 /* PDS-- This cannot be right!! */
3138 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need
3139 * to remove this '\' before we can use the filename.
3140 * xstrdup called because S may be read-only string constant.
3145 if (s[0] == '\\' && s[1] == ':')
3153 memcpy (tp, s, nlen);
3158 /* At this point, TP points to the element and NLEN is its length. */
3161 /* If this is the start of an archive group that isn't complete, set up
3162 to add the archive prefix for future files. A file list like:
3163 "libf.a(x.o y.o z.o)" needs to be expanded as:
3164 "libf.a(x.o) libf.a(y.o) libf.a(z.o)"
3166 TP == TMP means we're not already in an archive group. Ignore
3167 something starting with '(', as that cannot actually be an
3168 archive-member reference (and treating it as such results in an empty
3169 file name, which causes much lossage). Also if it ends in ")" then
3170 it's a complete reference so we don't need to treat it specially.
3172 Finally, note that archive groups must end with ')' as the last
3173 character, so ensure there's some word ending like that before
3174 considering this an archive group. */
3175 if (NONE_SET (flags, PARSEFS_NOAR)
3176 && tp == tmpbuf && tp[0] != '(' && tp[nlen-1] != ')')
3178 char *n = strchr (tp, '(');
3181 /* This looks like the first element in an open archive group.
3182 A valid group MUST have ')' as the last character. */
3188 /* Find the end of this word. We don't want to unquote and
3189 we don't care about quoting since we're looking for the
3190 last char in the word. */
3191 while (! STOP_SET (*e, stopmap|MAP_BLANK|MAP_VMSCOMMA))
3193 /* If we didn't move, we're done now. */
3198 /* Found the end, so this is the first element in an
3199 open archive group. It looks like "lib(mem".
3200 Reset TP past the open paren. */
3201 nlen -= (n + 1) - tp;
3204 /* We can stop looking now. */
3210 /* If we have just "lib(", part of something like "lib( a b)",
3211 go to the next item. */
3217 /* If we are inside an archive group, make sure it has an end. */
3220 if (tp[nlen-1] == ')')
3222 /* This is the natural end; reset TP. */
3225 /* This is just ")", something like "lib(a b )": skip it. */
3231 /* Not the end, so add a "fake" end. */
3238 /* If we're not globbing we're done: add it to the end of the chain.
3239 Go to the next item in the string. */
3240 if (ANY_SET (flags, PARSEFS_NOGLOB))
3242 NEWELT (concat (2, prefix, tmpbuf));
3246 /* If we get here we know we're doing glob expansion.
3247 TP is a string in tmpbuf. NLEN is no longer used.
3248 We may need to do more work: after this NAME will be set. */
3251 /* Expand tilde if applicable. */
3252 if (tmpbuf[0] == '~')
3254 tildep = tilde_expand (tmpbuf);
3260 /* If NAME is an archive member reference replace it with the archive
3261 file name, and save the member name in MEMNAME. We will glob on the
3262 archive name and then reattach MEMNAME later. */
3263 if (NONE_SET (flags, PARSEFS_NOAR) && ar_name (name))
3265 ar_parse_name (name, &arname, &memname);
3268 #endif /* !NO_ARCHIVES */
3270 /* glob() is expensive: don't call it unless we need to. */
3271 if (NONE_SET (flags, PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL)
3278 switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
3286 nlist = (const char **)gl.gl_pathv;
3290 /* If we want only existing items, skip this one. */
3291 if (ANY_SET (flags, PARSEFS_EXISTS))
3299 /* By default keep this name. */
3305 /* For each matched element, add it to the list. */
3310 /* Try to glob on MEMNAME within the archive. */
3311 struct nameseq *found = ar_glob (nlist[i], memname, size);
3313 /* No matches. Use MEMNAME as-is. */
3314 NEWELT (concat (5, prefix, nlist[i], "(", memname, ")"));
3317 /* We got a chain of items. Attach them. */
3319 (*newp)->next = found;
3323 /* Find and set the new end. Massage names if necessary. */
3327 found->name = xstrdup (concat (2, prefix, name));
3329 found->name = strcache_add (concat (2, prefix, name));
3331 if (found->next == 0)
3334 found = found->next;
3336 newp = &found->next;
3340 #endif /* !NO_ARCHIVES */
3341 NEWELT (concat (2, prefix, nlist[i]));