1 /* Reading and parsing of makefiles for GNU Make.
2 Copyright (C) 1988,89,90,91,92,93,94,95,96 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
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 /* This is POSIX.2, but most systems using -DPOSIX probably don't have it. */
30 #include "glob/glob.h"
36 struct passwd
*getpwnam
PARAMS ((char *name
));
39 /* A `struct linebuffer' is a structure which holds a line of text.
40 `readline' reads a line from a stream into a linebuffer
41 and works regardless of the length of the line. */
45 /* Note: This is the number of bytes malloc'ed for `buffer'
46 It does not indicate `buffer's real length.
47 Instead, a null char indicates end-of-string. */
52 #define initbuffer(lb) (lb)->buffer = (char *) xmalloc ((lb)->size = 200)
53 #define freebuffer(lb) free ((lb)->buffer)
56 /* A `struct conditionals' contains the information describing
57 all the active conditionals in a makefile.
59 The global variable `conditionals' contains the conditionals
60 information for the current makefile. It is initialized from
61 the static structure `toplevel_conditionals' and is later changed
62 to new structures for included makefiles. */
66 unsigned int if_cmds
; /* Depth of conditional nesting. */
67 unsigned int allocated
; /* Elts allocated in following arrays. */
68 char *ignoring
; /* Are we ignoring or interepreting? */
69 char *seen_else
; /* Have we already seen an `else'? */
72 static struct conditionals toplevel_conditionals
;
73 static struct conditionals
*conditionals
= &toplevel_conditionals
;
76 /* Default directories to search for include files in */
78 static char *default_include_directories
[] =
89 /* List of directories to search for include files in */
91 static char **include_directories
;
93 /* Maximum length of an element of the above. */
95 static unsigned int max_incl_len
;
97 /* The filename and pointer to line number of the
98 makefile currently being read in. */
100 char *reading_filename
;
101 unsigned int *reading_lineno_ptr
;
103 /* The chain of makefiles read by read_makefile. */
105 static struct dep
*read_makefiles
= 0;
107 static int read_makefile
PARAMS ((char *filename
, int flags
));
108 static unsigned int readline
PARAMS ((struct linebuffer
*linebuffer
, FILE *stream
,
109 char *filename
, unsigned int lineno
));
110 static unsigned int do_define
PARAMS ((char *name
, unsigned int namelen
, enum variable_origin origin
,
111 unsigned int lineno
, FILE *infile
, char *filename
));
112 static int conditional_line
PARAMS ((char *line
, char *filename
, unsigned int lineno
));
113 static void record_files
PARAMS ((struct nameseq
*filenames
, char *pattern
, char *pattern_percent
,
114 struct dep
*deps
, unsigned int commands_started
, char *commands
,
115 unsigned int commands_idx
, int two_colon
, char *filename
,
116 unsigned int lineno
, int set_default
));
117 static char *find_semicolon
PARAMS ((char *s
));
119 /* Read in all the makefiles and return the chain of their names. */
122 read_all_makefiles (makefiles
)
125 unsigned int num_makefiles
= 0;
128 puts ("Reading makefiles...");
130 /* If there's a non-null variable MAKEFILES, its value is a list of
131 files to read first thing. But don't let it prevent reading the
132 default makefiles and don't let the default goal come from there. */
140 /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
141 int save
= warn_undefined_variables_flag
;
142 warn_undefined_variables_flag
= 0;
144 value
= allocated_variable_expand ("$(MAKEFILES)");
146 warn_undefined_variables_flag
= save
;
149 /* Set NAME to the start of next token and LENGTH to its length.
150 MAKEFILES is updated for finding remaining tokens. */
153 while ((name
= find_next_token (&p
, &length
)) != 0)
157 (void) read_makefile (name
,
158 RM_NO_DEFAULT_GOAL
| RM_INCLUDED
| RM_DONTCARE
);
164 /* Read makefiles specified with -f switches. */
167 while (*makefiles
!= 0)
169 struct dep
*tail
= read_makefiles
;
170 register struct dep
*d
;
172 if (! read_makefile (*makefiles
, 0))
173 perror_with_name ("", *makefiles
);
175 /* Find the right element of read_makefiles. */
177 while (d
->next
!= tail
)
180 /* Use the storage read_makefile allocates. */
181 *makefiles
= dep_name (d
);
186 /* If there were no -f switches, try the default names. */
188 if (num_makefiles
== 0)
190 static char *default_makefiles
[] =
192 /* all lower case since readdir() (the vms version) 'lowercasifies' */
193 { "makefile.vms", "gnumakefile", "makefile", 0 };
195 { "GNUmakefile", "makefile", "Makefile", 0 };
197 register char **p
= default_makefiles
;
198 while (*p
!= 0 && !file_exists_p (*p
))
203 if (! read_makefile (*p
, 0))
204 perror_with_name ("", *p
);
208 /* No default makefile was found. Add the default makefiles to the
209 `read_makefiles' chain so they will be updated if possible. */
210 struct dep
*tail
= read_makefiles
;
211 /* Add them to the tail, after any MAKEFILES variable makefiles. */
212 while (tail
!= 0 && tail
->next
!= 0)
214 for (p
= default_makefiles
; *p
!= 0; ++p
)
216 struct dep
*d
= (struct dep
*) xmalloc (sizeof (struct dep
));
218 d
->file
= enter_file (*p
);
219 d
->file
->dontcare
= 1;
220 /* Tell update_goal_chain to bail out as soon as this file is
221 made, and main not to die if we can't make this file. */
222 d
->changed
= RM_DONTCARE
;
234 return read_makefiles
;
237 /* Read file FILENAME as a makefile and add its contents to the data base.
239 FLAGS contains bits as above.
241 FILENAME is added to the `read_makefiles' chain.
243 Returns 1 if a file was found and read, 0 if not. */
246 read_makefile (filename
, flags
)
250 static char *collapsed
= 0;
251 static unsigned int collapsed_length
= 0;
252 register FILE *infile
;
253 struct linebuffer lb
;
254 unsigned int commands_len
= 200;
255 char *commands
= (char *) xmalloc (200);
256 unsigned int commands_idx
= 0;
257 unsigned int commands_started
;
260 int ignoring
= 0, in_ignored_define
= 0;
261 int no_targets
= 0; /* Set when reading a rule without targets. */
262 char *passed_filename
= filename
;
264 struct nameseq
*filenames
= 0;
266 unsigned int lineno
= 1;
267 unsigned int nlines
= 0;
269 char *pattern
= 0, *pattern_percent
;
273 #define record_waiting_files() \
276 if (filenames != 0) \
277 record_files (filenames, pattern, pattern_percent, deps, \
278 commands_started, commands, commands_idx, \
279 two_colon, filename, lineno, \
280 !(flags & RM_NO_DEFAULT_GOAL)); \
286 #ifdef lint /* Suppress `used before set' messages. */
292 printf ("Reading makefile `%s'", filename
);
293 if (flags
& RM_NO_DEFAULT_GOAL
)
294 printf (" (no default goal)");
295 if (flags
& RM_INCLUDED
)
296 printf (" (search path)");
297 if (flags
& RM_DONTCARE
)
298 printf (" (don't care)");
299 if (flags
& RM_NO_TILDE
)
300 printf (" (no ~ expansion)");
304 /* First, get a stream to read. */
306 /* Expand ~ in FILENAME unless it came from `include',
307 in which case it was already done. */
308 if (!(flags
& RM_NO_TILDE
) && filename
[0] == '~')
310 char *expanded
= tilde_expand (filename
);
315 infile
= fopen (filename
, "r");
316 /* Save the error code so we print the right message later. */
317 makefile_errno
= errno
;
319 /* If the makefile wasn't found and it's either a makefile from
320 the `MAKEFILES' variable or an included makefile,
321 search the included makefile search path for this makefile. */
322 if (infile
== 0 && (flags
& RM_INCLUDED
) && *filename
!= '/')
324 register unsigned int i
;
325 for (i
= 0; include_directories
[i
] != 0; ++i
)
327 char *name
= concat (include_directories
[i
], "/", filename
);
328 infile
= fopen (name
, "r");
339 /* Add FILENAME to the chain of read makefiles. */
340 deps
= (struct dep
*) xmalloc (sizeof (struct dep
));
341 deps
->next
= read_makefiles
;
342 read_makefiles
= deps
;
344 deps
->file
= lookup_file (filename
);
347 deps
->file
= enter_file (savestring (filename
, strlen (filename
)));
348 if (flags
& RM_DONTCARE
)
349 deps
->file
->dontcare
= 1;
351 if (filename
!= passed_filename
)
353 filename
= deps
->file
->name
;
354 deps
->changed
= flags
;
357 /* If the makefile can't be found at all, give up entirely. */
361 /* If we did some searching, errno has the error from the last
362 attempt, rather from FILENAME itself. Restore it in case the
363 caller wants to use it in a message. */
364 errno
= makefile_errno
;
368 reading_filename
= filename
;
369 reading_lineno_ptr
= &lineno
;
371 /* Loop over lines in the file.
372 The strategy is to accumulate target names in FILENAMES, dependencies
373 in DEPS and commands in COMMANDS. These are used to define a rule
374 when the start of the next rule (or eof) is encountered. */
378 while (!feof (infile
))
381 nlines
= readline (&lb
, infile
, filename
, lineno
);
383 /* Check for a shell command line first.
384 If it is not one, we can stop treating tab specially. */
385 if (lb
.buffer
[0] == '\t')
387 /* This line is a probably shell command. */
391 /* Ignore the commands in a rule with no targets. */
394 /* If there is no preceding rule line, don't treat this line
395 as a command, even though it begins with a tab character.
396 SunOS 4 make appears to behave this way. */
401 /* Yep, this is a shell command, and we don't care. */
404 /* Append this command line to the line being accumulated. */
406 if (commands_idx
== 0)
407 commands_started
= lineno
;
409 if (len
+ 1 + commands_idx
> commands_len
)
411 commands_len
= (len
+ 1 + commands_idx
) * 2;
412 commands
= (char *) xrealloc (commands
, commands_len
);
414 bcopy (p
, &commands
[commands_idx
], len
);
416 commands
[commands_idx
++] = '\n';
422 /* This line is not a shell command line. Don't worry about tabs. */
424 if (collapsed_length
< lb
.size
)
426 collapsed_length
= lb
.size
;
429 collapsed
= (char *) xmalloc (collapsed_length
);
431 strcpy (collapsed
, lb
.buffer
);
432 /* Collapse continuation lines. */
433 collapse_continuations (collapsed
);
434 remove_comments (collapsed
);
436 /* strncmp is first to avoid dereferencing out into space. */
437 #define word1eq(s, l) (!strncmp (s, p, l) \
438 && (p[l] == '\0' || isblank (p[l])))
443 /* This line is completely empty. */
446 /* We must first check for conditional and `define' directives before
447 ignoring anything, since they control what we will do with
450 if (!in_ignored_define
451 && (word1eq ("ifdef", 5) || word1eq ("ifndef", 6)
452 || word1eq ("ifeq", 4) || word1eq ("ifneq", 5)
453 || word1eq ("else", 4) || word1eq ("endif", 5)))
455 int i
= conditional_line (p
, filename
, lineno
);
459 makefile_fatal (filename
, lineno
,
460 "invalid syntax in conditional");
463 else if (word1eq ("endef", 5))
465 if (in_ignored_define
)
466 in_ignored_define
= 0;
468 makefile_fatal (filename
, lineno
, "extraneous `endef'");
471 else if (word1eq ("define", 6))
474 in_ignored_define
= 1;
477 p2
= next_token (p
+ 6);
478 /* Let the variable name be the whole rest of the line,
479 with trailing blanks stripped (comments have already been
480 removed), so it could be a complex variable/function
481 reference that might contain blanks. */
482 p
= index (p2
, '\0');
483 while (isblank (p
[-1]))
485 lineno
= do_define (p2
, p
- p2
, o_file
,
486 lineno
, infile
, filename
);
490 else if (word1eq ("override", 8))
492 p2
= next_token (p
+ 8);
494 makefile_error (filename
, lineno
, "empty `override' directive");
495 if (!strncmp (p2
, "define", 6) && (isblank (p2
[6]) || p2
[6] == '\0'))
498 in_ignored_define
= 1;
501 p2
= next_token (p2
+ 6);
502 /* Let the variable name be the whole rest of the line,
503 with trailing blanks stripped (comments have already been
504 removed), so it could be a complex variable/function
505 reference that might contain blanks. */
506 p
= index (p2
, '\0');
507 while (isblank (p
[-1]))
509 lineno
= do_define (p2
, p
- p2
, o_override
,
510 lineno
, infile
, filename
);
514 && !try_variable_definition (filename
, lineno
,
516 makefile_error (filename
, lineno
, "empty `override' directive");
522 /* Ignore the line. We continue here so conditionals
523 can appear in the middle of a rule. */
525 else if (word1eq ("export", 6))
528 p2
= next_token (p
+ 6);
530 export_all_variables
= 1;
531 v
= try_variable_definition (filename
, lineno
, p2
, o_file
);
533 v
->export
= v_export
;
537 for (p
= find_next_token (&p2
, &len
); p
!= 0;
538 p
= find_next_token (&p2
, &len
))
540 v
= lookup_variable (p
, len
);
542 v
= define_variable (p
, len
, "", o_file
, 0);
543 v
->export
= v_export
;
547 else if (word1eq ("unexport", 8))
551 p2
= next_token (p
+ 8);
553 export_all_variables
= 0;
554 for (p
= find_next_token (&p2
, &len
); p
!= 0;
555 p
= find_next_token (&p2
, &len
))
557 v
= lookup_variable (p
, len
);
559 v
= define_variable (p
, len
, "", o_file
, 0);
560 v
->export
= v_noexport
;
563 else if (word1eq ("include", 7) || word1eq ("-include", 8)
564 || word1eq ("sinclude", 8))
566 /* We have found an `include' line specifying a nested
567 makefile to be read at this point. */
568 struct conditionals
*save
, new_conditionals
;
569 struct nameseq
*files
;
570 /* "-include" (vs "include") says no error if the file does not
571 exist. "sinclude" is an alias for this from SGI. */
572 int noerror
= p
[0] != 'i';
574 p
= allocated_variable_expand (next_token (p
+ (noerror
? 9 : 8)));
577 makefile_error (filename
, lineno
,
578 "no file name for `%sinclude'",
583 /* Parse the list of file names. */
585 files
= multi_glob (parse_file_seq (&p2
, '\0',
586 sizeof (struct nameseq
),
588 sizeof (struct nameseq
));
591 /* Save the state of conditionals and start
592 the included makefile with a clean slate. */
594 bzero ((char *) &new_conditionals
, sizeof new_conditionals
);
595 conditionals
= &new_conditionals
;
597 /* Record the rules that are waiting so they will determine
598 the default goal before those in the included makefile. */
599 record_waiting_files ();
601 /* Read each included makefile. */
604 struct nameseq
*next
= files
->next
;
605 char *name
= files
->name
;
606 free ((char *)files
);
609 if (! read_makefile (name
, (RM_INCLUDED
| RM_NO_TILDE
610 | (noerror
? RM_DONTCARE
: 0)))
612 makefile_error (filename
, lineno
,
613 "%s: %s", name
, strerror (errno
));
616 /* Free any space allocated by conditional_line. */
617 if (conditionals
->ignoring
)
618 free (conditionals
->ignoring
);
619 if (conditionals
->seen_else
)
620 free (conditionals
->seen_else
);
624 reading_filename
= filename
;
625 reading_lineno_ptr
= &lineno
;
627 else if (word1eq ("vpath", 5))
631 p2
= variable_expand (p
+ 5);
632 p
= find_next_token (&p2
, &len
);
635 pattern
= savestring (p
, len
);
636 p
= find_next_token (&p2
, &len
);
637 /* No searchpath means remove all previous
638 selective VPATH's with the same pattern. */
641 /* No pattern means remove all previous selective VPATH's. */
643 construct_vpath_list (pattern
, p
);
648 else if (try_variable_definition (filename
, lineno
, p
, o_file
))
649 /* This line has been dealt with. */
651 else if (lb
.buffer
[0] == '\t')
653 p
= collapsed
; /* Ignore comments. */
657 /* The line is completely blank; that is harmless. */
659 /* This line starts with a tab but was not caught above
660 because there was no preceding target, and the line
661 might have been usable as a variable definition.
662 But now it is definitely lossage. */
663 makefile_fatal (filename
, lineno
,
664 "commands commence before first target");
668 /* This line describes some target files. */
672 /* Record the previous rule. */
674 record_waiting_files ();
676 /* Search the line for an unquoted ; that is not after an
678 cmdleft
= find_char_unquote (lb
.buffer
, ";#", 0);
679 if (cmdleft
!= 0 && *cmdleft
== '#')
681 /* We found a comment before a semicolon. */
685 else if (cmdleft
!= 0)
686 /* Found one. Cut the line short there before expanding it. */
689 collapse_continuations (lb
.buffer
);
691 /* Expand variable and function references before doing anything
692 else so that special characters can be inside variables. */
693 p
= variable_expand (lb
.buffer
);
696 /* Look for a semicolon in the expanded line. */
697 cmdleft
= find_char_unquote (p
, ";", 0);
700 /* Cut the line short at the semicolon. */
707 makefile_fatal (filename
, lineno
,
708 "missing rule before commands");
710 /* This line contained a variable reference that
711 expanded to nothing but whitespace. */
716 /* We accept and ignore rules without targets for
717 compatibility with SunOS 4 make. */
722 filenames
= multi_glob (parse_file_seq (&p2
, ':',
723 sizeof (struct nameseq
),
725 sizeof (struct nameseq
));
727 makefile_fatal (filename
, lineno
, "missing separator");
728 /* Is this a one-colon or two-colon entry? */
729 two_colon
= *p2
== ':';
733 /* We have some targets, so don't ignore the following commands. */
736 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
738 while (p
!= 0 && p
[-1] == '\\')
740 register char *q
= &p
[-1];
741 register int backslash
= 0;
743 backslash
= !backslash
;
745 p
= index (p
+ 1, ':');
750 /* For MS-DOS, skip a "C:\...". */
751 if (p
!= 0 && p
[1] == '\\' && isalpha (p
[-1]))
755 /* Here, the situation is quite complicated. Let's have a look
756 at a couple of targets:
764 The rule is that it's only a target, if there are TWO :'s
765 OR a space around the :.
767 if (p
&& !(isspace(p
[1]) || !p
[1] || isspace(p
[-1])))
772 struct nameseq
*target
;
773 target
= parse_file_seq (&p2
, ':', sizeof (struct nameseq
), 1);
776 makefile_fatal (filename
, lineno
, "missing target pattern");
777 else if (target
->next
!= 0)
778 makefile_fatal (filename
, lineno
, "multiple target patterns");
779 pattern
= target
->name
;
780 pattern_percent
= find_percent (pattern
);
781 if (pattern_percent
== 0)
782 makefile_fatal (filename
, lineno
,
783 "target pattern contains no `%%'");
788 /* Parse the dependencies. */
789 deps
= (struct dep
*)
790 multi_glob (parse_file_seq (&p2
, '\0', sizeof (struct dep
), 1),
791 sizeof (struct dep
));
796 /* Semicolon means rest of line is a command. */
797 unsigned int len
= strlen (cmdleft
+ 1);
799 commands_started
= lineno
;
801 /* Add this command line to the buffer. */
802 if (len
+ 2 > commands_len
)
804 commands_len
= (len
+ 2) * 2;
805 commands
= (char *) xrealloc (commands
, commands_len
);
807 bcopy (cmdleft
+ 1, commands
, len
);
809 commands
[commands_idx
++] = '\n';
815 /* We get here except in the case that we just read a rule line.
816 Record now the last rule we read, so following spurious
817 commands are properly diagnosed. */
818 record_waiting_files ();
822 if (conditionals
->if_cmds
)
823 makefile_fatal (filename
, lineno
, "missing `endif'");
825 /* At eof, record the last rule. */
826 record_waiting_files ();
829 free ((char *) commands
);
832 reading_filename
= 0;
833 reading_lineno_ptr
= 0;
838 /* Execute a `define' directive.
839 The first line has already been read, and NAME is the name of
840 the variable to be defined. The following lines remain to be read.
841 LINENO, INFILE and FILENAME refer to the makefile being read.
842 The value returned is LINENO, updated for lines read here. */
845 do_define (name
, namelen
, origin
, lineno
, infile
, filename
)
847 unsigned int namelen
;
848 enum variable_origin origin
;
853 struct linebuffer lb
;
854 unsigned int nlines
= 0;
855 unsigned int length
= 100;
856 char *definition
= (char *) xmalloc (100);
857 register unsigned int idx
= 0;
860 /* Expand the variable name. */
861 char *var
= (char *) alloca (namelen
+ 1);
862 bcopy (name
, var
, namelen
);
864 var
= variable_expand (var
);
867 while (!feof (infile
))
870 nlines
= readline (&lb
, infile
, filename
, lineno
);
872 collapse_continuations (lb
.buffer
);
874 p
= next_token (lb
.buffer
);
875 if ((p
[5] == '\0' || isblank (p
[5])) && !strncmp (p
, "endef", 5))
879 if (*next_token (p
) != '\0')
880 makefile_error (filename
, lineno
,
881 "Extraneous text after `endef' directive");
882 /* Define the variable. */
884 definition
[0] = '\0';
886 definition
[idx
- 1] = '\0';
887 (void) define_variable (var
, strlen (var
), definition
, origin
, 1);
894 unsigned int len
= strlen (lb
.buffer
);
896 /* Increase the buffer size if necessary. */
897 if (idx
+ len
+ 1 > length
)
899 length
= (idx
+ len
) * 2;
900 definition
= (char *) xrealloc (definition
, length
+ 1);
903 bcopy (lb
.buffer
, &definition
[idx
], len
);
905 /* Separate lines with a newline. */
906 definition
[idx
++] = '\n';
911 makefile_fatal (filename
, lineno
, "missing `endef', unterminated `define'");
917 /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
918 "ifneq", "else" and "endif".
919 LINE is the input line, with the command as its first word.
921 FILENAME and LINENO are the filename and line number in the
922 current makefile. They are used for error messages.
924 Value is -1 if the line is invalid,
925 0 if following text should be interpreted,
926 1 if following text should be ignored. */
929 conditional_line (line
, filename
, lineno
)
936 register unsigned int i
;
940 /* It's an "if..." command. */
941 notdef
= line
[2] == 'n';
944 cmdname
= line
[3] == 'd' ? "ifndef" : "ifneq";
945 line
+= cmdname
[3] == 'd' ? 7 : 6;
949 cmdname
= line
[2] == 'd' ? "ifdef" : "ifeq";
950 line
+= cmdname
[2] == 'd' ? 6 : 5;
955 /* It's an "else" or "endif" command. */
956 notdef
= line
[1] == 'n';
957 cmdname
= notdef
? "endif" : "else";
958 line
+= notdef
? 5 : 4;
961 line
= next_token (line
);
966 makefile_error (filename
, lineno
,
967 "Extraneous text after `%s' directive",
969 /* "Else" or "endif". */
970 if (conditionals
->if_cmds
== 0)
971 makefile_fatal (filename
, lineno
, "extraneous `%s'", cmdname
);
972 /* NOTDEF indicates an `endif' command. */
974 --conditionals
->if_cmds
;
975 else if (conditionals
->seen_else
[conditionals
->if_cmds
- 1])
976 makefile_fatal (filename
, lineno
, "only one `else' per conditional");
979 /* Toggle the state of ignorance. */
980 conditionals
->ignoring
[conditionals
->if_cmds
- 1]
981 = !conditionals
->ignoring
[conditionals
->if_cmds
- 1];
982 /* Record that we have seen an `else' in this conditional.
983 A second `else' will be erroneous. */
984 conditionals
->seen_else
[conditionals
->if_cmds
- 1] = 1;
986 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
987 if (conditionals
->ignoring
[i
])
992 if (conditionals
->allocated
== 0)
994 conditionals
->allocated
= 5;
995 conditionals
->ignoring
= (char *) xmalloc (conditionals
->allocated
);
996 conditionals
->seen_else
= (char *) xmalloc (conditionals
->allocated
);
999 ++conditionals
->if_cmds
;
1000 if (conditionals
->if_cmds
> conditionals
->allocated
)
1002 conditionals
->allocated
+= 5;
1003 conditionals
->ignoring
= (char *)
1004 xrealloc (conditionals
->ignoring
, conditionals
->allocated
);
1005 conditionals
->seen_else
= (char *)
1006 xrealloc (conditionals
->seen_else
, conditionals
->allocated
);
1009 /* Record that we have seen an `if...' but no `else' so far. */
1010 conditionals
->seen_else
[conditionals
->if_cmds
- 1] = 0;
1012 /* Search through the stack to see if we're already ignoring. */
1013 for (i
= 0; i
< conditionals
->if_cmds
- 1; ++i
)
1014 if (conditionals
->ignoring
[i
])
1016 /* We are already ignoring, so just push a level
1017 to match the next "else" or "endif", and keep ignoring.
1018 We don't want to expand variables in the condition. */
1019 conditionals
->ignoring
[conditionals
->if_cmds
- 1] = 1;
1023 if (cmdname
[notdef
? 3 : 2] == 'd')
1025 /* "Ifdef" or "ifndef". */
1027 register char *p
= end_of_token (line
);
1032 v
= lookup_variable (line
, i
);
1033 conditionals
->ignoring
[conditionals
->if_cmds
- 1]
1034 = (v
!= 0 && *v
->value
!= '\0') == notdef
;
1038 /* "Ifeq" or "ifneq". */
1041 char termin
= *line
== '(' ? ',' : *line
;
1043 if (termin
!= ',' && termin
!= '"' && termin
!= '\'')
1047 /* Find the end of the first string. */
1050 register int count
= 0;
1051 for (; *line
!= '\0'; ++line
)
1054 else if (*line
== ')')
1056 else if (*line
== ',' && count
<= 0)
1060 while (*line
!= '\0' && *line
!= termin
)
1068 s2
= variable_expand (s1
);
1069 /* We must allocate a new copy of the expanded string because
1070 variable_expand re-uses the same buffer. */
1072 s1
= (char *) alloca (len
+ 1);
1073 bcopy (s2
, s1
, len
+ 1);
1076 /* Find the start of the second string. */
1077 line
= next_token (line
);
1079 termin
= termin
== ',' ? ')' : *line
;
1080 if (termin
!= ')' && termin
!= '"' && termin
!= '\'')
1083 /* Find the end of the second string. */
1086 register int count
= 0;
1087 s2
= next_token (line
);
1088 for (line
= s2
; *line
!= '\0'; ++line
)
1092 else if (*line
== ')')
1103 while (*line
!= '\0' && *line
!= termin
)
1111 line
= next_token (++line
);
1113 makefile_error (filename
, lineno
,
1114 "Extraneous text after `%s' directive",
1117 s2
= variable_expand (s2
);
1118 conditionals
->ignoring
[conditionals
->if_cmds
- 1]
1119 = streq (s1
, s2
) == notdef
;
1122 /* Search through the stack to see if we're ignoring. */
1123 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
1124 if (conditionals
->ignoring
[i
])
1129 /* Remove duplicate dependencies in CHAIN. */
1132 uniquize_deps (chain
)
1135 register struct dep
*d
;
1137 /* Make sure that no dependencies are repeated. This does not
1138 really matter for the purpose of updating targets, but it
1139 might make some names be listed twice for $^ and $?. */
1141 for (d
= chain
; d
!= 0; d
= d
->next
)
1143 struct dep
*last
, *next
;
1148 if (streq (dep_name (d
), dep_name (next
)))
1150 struct dep
*n
= next
->next
;
1152 if (next
->name
!= 0 && next
->name
!= d
->name
)
1155 free ((char *) next
);
1166 /* Record a description line for files FILENAMES,
1167 with dependencies DEPS, commands to execute described
1168 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
1169 TWO_COLON is nonzero if a double colon was used.
1170 If not nil, PATTERN is the `%' pattern to make this
1171 a static pattern rule, and PATTERN_PERCENT is a pointer
1172 to the `%' within it.
1174 The links of FILENAMES are freed, and so are any names in it
1175 that are not incorporated into other data structures. */
1178 record_files (filenames
, pattern
, pattern_percent
, deps
, commands_started
,
1179 commands
, commands_idx
, two_colon
, filename
, lineno
, set_default
)
1180 struct nameseq
*filenames
;
1181 char *pattern
, *pattern_percent
;
1183 unsigned int commands_started
;
1185 unsigned int commands_idx
;
1188 unsigned int lineno
;
1191 struct nameseq
*nextf
;
1193 unsigned int max_targets
, target_idx
;
1194 char **targets
= 0, **target_percents
= 0;
1195 struct commands
*cmds
;
1197 if (commands_idx
> 0)
1199 cmds
= (struct commands
*) xmalloc (sizeof (struct commands
));
1200 cmds
->filename
= filename
;
1201 cmds
->lineno
= commands_started
;
1202 cmds
->commands
= savestring (commands
, commands_idx
);
1203 cmds
->command_lines
= 0;
1208 for (; filenames
!= 0; filenames
= nextf
)
1210 register char *name
= filenames
->name
;
1211 register struct file
*f
;
1212 register struct dep
*d
;
1214 char *implicit_percent
;
1216 nextf
= filenames
->next
;
1217 free ((char *) filenames
);
1219 implicit_percent
= find_percent (name
);
1220 implicit
|= implicit_percent
!= 0;
1222 if (implicit
&& pattern
!= 0)
1223 makefile_fatal (filename
, lineno
,
1224 "mixed implicit and static pattern rules");
1226 if (implicit
&& implicit_percent
== 0)
1227 makefile_fatal (filename
, lineno
, "mixed implicit and normal rules");
1234 targets
= (char **) xmalloc (5 * sizeof (char *));
1235 target_percents
= (char **) xmalloc (5 * sizeof (char *));
1238 else if (target_idx
== max_targets
- 1)
1241 targets
= (char **) xrealloc ((char *) targets
,
1242 max_targets
* sizeof (char *));
1244 = (char **) xrealloc ((char *) target_percents
,
1245 max_targets
* sizeof (char *));
1247 targets
[target_idx
] = name
;
1248 target_percents
[target_idx
] = implicit_percent
;
1253 /* If there are multiple filenames, copy the chain DEPS
1254 for all but the last one. It is not safe for the same deps
1255 to go in more than one place in the data base. */
1256 this = nextf
!= 0 ? copy_dep_chain (deps
) : deps
;
1259 /* If this is an extended static rule:
1260 `targets: target%pattern: dep%pattern; cmds',
1261 translate each dependency pattern into a plain filename
1262 using the target pattern and this target's name. */
1263 if (!pattern_matches (pattern
, pattern_percent
, name
))
1265 /* Give a warning if the rule is meaningless. */
1266 makefile_error (filename
, lineno
,
1267 "target `%s' doesn't match the target pattern",
1273 /* We use patsubst_expand to do the work of translating
1274 the target pattern, the target's name and the dependencies'
1275 patterns into plain dependency names. */
1276 char *buffer
= variable_expand ("");
1278 for (d
= this; d
!= 0; d
= d
->next
)
1281 char *percent
= find_percent (d
->name
);
1284 o
= patsubst_expand (buffer
, name
, pattern
, d
->name
,
1285 pattern_percent
, percent
);
1287 d
->name
= savestring (buffer
, o
- buffer
);
1293 /* Single-colon. Combine these dependencies
1294 with others in file's existing record, if any. */
1295 f
= enter_file (name
);
1297 if (f
->double_colon
)
1298 makefile_fatal (filename
, lineno
,
1299 "target file `%s' has both : and :: entries",
1302 /* If CMDS == F->CMDS, this target was listed in this rule
1303 more than once. Just give a warning since this is harmless. */
1304 if (cmds
!= 0 && cmds
== f
->cmds
)
1307 "target `%s' given more than once in the same rule.",
1310 /* Check for two single-colon entries both with commands.
1311 Check is_target so that we don't lose on files such as .c.o
1312 whose commands were preinitialized. */
1313 else if (cmds
!= 0 && f
->cmds
!= 0 && f
->is_target
)
1315 makefile_error (cmds
->filename
, cmds
->lineno
,
1316 "warning: overriding commands for target `%s'",
1318 makefile_error (f
->cmds
->filename
, f
->cmds
->lineno
,
1319 "warning: ignoring old commands for target `%s'",
1325 /* Defining .DEFAULT with no deps or cmds clears it. */
1326 if (f
== default_file
&& this == 0 && cmds
== 0)
1330 /* Defining .SUFFIXES with no dependencies
1331 clears out the list of suffixes. */
1332 if (f
== suffix_file
&& this == 0)
1337 struct dep
*nextd
= d
->next
;
1344 else if (f
->deps
!= 0)
1346 /* Add the file's old deps and the new ones in THIS together. */
1348 struct dep
*firstdeps
, *moredeps
;
1351 /* This is the rule with commands, so put its deps first.
1352 The rationale behind this is that $< expands to the
1353 first dep in the chain, and commands use $< expecting
1354 to get the dep that rule specifies. */
1360 /* Append the new deps to the old ones. */
1361 firstdeps
= f
->deps
;
1366 firstdeps
= moredeps
;
1370 while (d
->next
!= 0)
1375 f
->deps
= firstdeps
;
1380 /* If this is a static pattern rule, set the file's stem to
1381 the part of its name that matched the `%' in the pattern,
1382 so you can use $* in the commands. */
1385 static char *percent
= "%";
1386 char *buffer
= variable_expand ("");
1387 char *o
= patsubst_expand (buffer
, name
, pattern
, percent
,
1388 pattern_percent
, percent
);
1389 f
->stem
= savestring (buffer
, o
- buffer
);
1394 /* Double-colon. Make a new record
1395 even if the file already has one. */
1396 f
= lookup_file (name
);
1397 /* Check for both : and :: rules. Check is_target so
1398 we don't lose on default suffix rules or makefiles. */
1399 if (f
!= 0 && f
->is_target
&& !f
->double_colon
)
1400 makefile_fatal (filename
, lineno
,
1401 "target file `%s' has both : and :: entries",
1403 f
= enter_file (name
);
1404 /* If there was an existing entry and it was a double-colon
1405 entry, enter_file will have returned a new one, making it the
1406 prev pointer of the old one, and setting its double_colon
1407 pointer to the first one. */
1408 if (f
->double_colon
== 0)
1409 /* This is the first entry for this name, so we must
1410 set its double_colon pointer to itself. */
1411 f
->double_colon
= f
;
1417 /* Free name if not needed further. */
1418 if (f
!= 0 && name
!= f
->name
1419 && (name
< f
->name
|| name
> f
->name
+ strlen (f
->name
)))
1425 /* See if this is first target seen whose name does
1426 not start with a `.', unless it contains a slash. */
1427 if (default_goal_file
== 0 && set_default
1428 && (*name
!= '.' || index (name
, '/') != 0))
1432 /* If this file is a suffix, don't
1433 let it be the default goal file. */
1435 for (d
= suffix_file
->deps
; d
!= 0; d
= d
->next
)
1437 register struct dep
*d2
;
1438 if (*dep_name (d
) != '.' && streq (name
, dep_name (d
)))
1443 for (d2
= suffix_file
->deps
; d2
!= 0; d2
= d2
->next
)
1445 register unsigned int len
= strlen (dep_name (d2
));
1446 if (strncmp (name
, dep_name (d2
), len
))
1448 if (streq (name
+ len
, dep_name (d
)))
1459 default_goal_file
= f
;
1465 targets
[target_idx
] = 0;
1466 target_percents
[target_idx
] = 0;
1467 create_pattern_rule (targets
, target_percents
, two_colon
, deps
, cmds
, 1);
1468 free ((char *) target_percents
);
1472 /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
1473 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
1474 Quoting backslashes are removed from STRING by compacting it into
1475 itself. Returns a pointer to the first unquoted STOPCHAR if there is
1476 one, or nil if there are none. */
1479 find_char_unquote (string
, stopchars
, blank
)
1484 unsigned int string_len
= strlen (string
);
1485 register char *p
= string
;
1489 while (*p
!= '\0' && index (stopchars
, *p
) == 0
1490 && (!blank
|| !isblank (*p
)))
1495 if (p
> string
&& p
[-1] == '\\')
1497 /* Search for more backslashes. */
1498 register int i
= -2;
1499 while (&p
[i
] >= string
&& p
[i
] == '\\')
1502 /* The number of backslashes is now -I.
1503 Copy P over itself to swallow half of them. */
1504 bcopy (&p
[i
/ 2], &p
[i
], (string_len
- (p
- string
)) - (i
/ 2) + 1);
1507 /* All the backslashes quoted each other; the STOPCHAR was
1511 /* The STOPCHAR was quoted by a backslash. Look for another. */
1514 /* No backslash in sight. */
1518 /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
1522 /* Search PATTERN for an unquoted %. */
1525 find_percent (pattern
)
1528 return find_char_unquote (pattern
, "%", 0);
1531 /* Parse a string into a sequence of filenames represented as a
1532 chain of struct nameseq's in reverse order and return that chain.
1534 The string is passed as STRINGP, the address of a string pointer.
1535 The string pointer is updated to point at the first character
1536 not parsed, which either is a null char or equals STOPCHAR.
1538 SIZE is how big to construct chain elements.
1539 This is useful if we want them actually to be other structures
1540 that have room for additional info.
1542 If STRIP is nonzero, strip `./'s off the beginning. */
1545 parse_file_seq (stringp
, stopchar
, size
, strip
)
1551 register struct nameseq
*new = 0;
1552 register struct nameseq
*new1
, *lastnew1
;
1553 register char *p
= *stringp
;
1560 stopchars
[1] = stopchar
;
1561 stopchars
[2] = '\0';
1563 stopchars
[0] = stopchar
;
1564 stopchars
[1] = '\0';
1569 /* Skip whitespace; see if any more names are left. */
1576 /* Yes, find end of next name. */
1578 p
= find_char_unquote (q
, stopchars
, 1);
1580 /* convert comma separated list to space separated */
1586 /* For MS-DOS, skip a "C:\...". */
1587 if (stopchar
== ':' && p
!= 0 && p
[1] == '\\' && isalpha (p
[-1]))
1591 if (stopchar
== ':' && p
&& *p
== ':' &&
1592 !(isspace(p
[1]) || !p
[1] || isspace(p
[-1])))
1594 p
= find_char_unquote (p
+1, stopchars
, 1);
1602 /* Skip leading `[]'s. */
1603 while (p
- q
> 2 && q
[0] == '[' && q
[1] == ']')
1605 /* Skip leading `./'s. */
1606 while (p
- q
> 2 && q
[0] == '.' && q
[1] == '/')
1609 q
+= 2; /* Skip "./". */
1610 while (q
< p
&& *q
== '/')
1611 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
1615 /* Extract the filename just found, and skip it. */
1618 /* ".///" was stripped to "". */
1622 name
= savestring ("./", 2);
1626 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need
1627 * to remove this '\' before we can use the filename.
1628 * Savestring called because q may be read-only string constant.
1631 char *qbase
= savestring(q
, strlen(q
));
1632 char *pbase
= qbase
+ (p
-q
);
1639 if (*q1
== '\\' && *(q1
+1) == ':')
1646 name
= savestring (qbase
, p1
- qbase
);
1650 name
= savestring (q
, p
- q
);
1653 /* Add it to the front of the chain. */
1654 new1
= (struct nameseq
*) xmalloc (size
);
1662 /* Look for multi-word archive references.
1663 They are indicated by a elt ending with an unmatched `)' and
1664 an elt further down the chain (i.e., previous in the file list)
1665 with an unmatched `(' (e.g., "lib(mem"). */
1670 if (new1
->name
[0] != '(' /* Don't catch "(%)" and suchlike. */
1671 && new1
->name
[strlen (new1
->name
) - 1] == ')'
1672 && index (new1
->name
, '(') == 0)
1674 /* NEW1 ends with a `)' but does not contain a `('.
1675 Look back for an elt with an opening `(' but no closing `)'. */
1677 struct nameseq
*n
= new1
->next
, *lastn
= new1
;
1679 while (n
!= 0 && (paren
= index (n
->name
, '(')) == 0)
1685 /* Ignore something starting with `(', as that cannot actually
1686 be an archive-member reference (and treating it as such
1687 results in an empty file name, which causes much lossage). */
1688 && n
->name
[0] != '(')
1690 /* N is the first element in the archive group.
1691 Its name looks like "lib(mem" (with no closing `)'). */
1695 /* Copy "lib(" into LIBNAME. */
1697 libname
= (char *) alloca (paren
- n
->name
+ 1);
1698 bcopy (n
->name
, libname
, paren
- n
->name
);
1699 libname
[paren
- n
->name
] = '\0';
1703 /* N was just "lib(", part of something like "lib( a b)".
1704 Edit it out of the chain and free its storage. */
1705 lastn
->next
= n
->next
;
1708 /* LASTN->next is the new stopping elt for the loop below. */
1713 /* Replace N's name with the full archive reference. */
1714 name
= concat (libname
, paren
, ")");
1719 if (new1
->name
[1] == '\0')
1721 /* NEW1 is just ")", part of something like "lib(a b )".
1722 Omit it from the chain and free its storage. */
1726 lastnew1
->next
= new1
->next
;
1730 free ((char *) lastn
);
1734 /* Replace also NEW1->name, which already has closing `)'. */
1735 name
= concat (libname
, new1
->name
, "");
1741 /* Trace back from NEW1 (the end of the list) until N
1742 (the beginning of the list), rewriting each name
1743 with the full archive reference. */
1747 name
= concat (libname
, new1
->name
, ")");
1756 /* No frobnication happening. Just step down the list. */
1773 /* Read a line of text from STREAM into LINEBUFFER.
1774 Combine continuation lines into one line.
1775 Return the number of actual lines read (> 1 if hacked continuation lines).
1779 readline (linebuffer
, stream
, filename
, lineno
)
1780 struct linebuffer
*linebuffer
;
1783 unsigned int lineno
;
1785 char *buffer
= linebuffer
->buffer
;
1786 register char *p
= linebuffer
->buffer
;
1787 register char *end
= p
+ linebuffer
->size
;
1788 register int len
, lastlen
= 0;
1790 register unsigned int nlines
= 0;
1791 register int backslash
;
1795 while (fgets (p
, end
- p
, stream
) != 0)
1800 /* This only happens when the first thing on the line is a '\0'.
1801 It is a pretty hopeless case, but (wonder of wonders) Athena
1802 lossage strikes again! (xmkmf puts NULs in its makefiles.)
1803 There is nothing really to be done; we synthesize a newline so
1804 the following line doesn't appear to be part of this line. */
1805 makefile_error (filename
, lineno
,
1806 "warning: NUL character seen; rest of line ignored");
1814 /* Probably ran out of buffer space. */
1815 register unsigned int p_off
= p
- buffer
;
1816 linebuffer
->size
*= 2;
1817 buffer
= (char *) xrealloc (buffer
, linebuffer
->size
);
1819 end
= buffer
+ linebuffer
->size
;
1820 linebuffer
->buffer
= buffer
;
1828 if (len
== 1 && p
> buffer
)
1829 /* P is pointing at a newline and it's the beginning of
1830 the buffer returned by the last fgets call. However,
1831 it is not necessarily the beginning of a line if P is
1832 pointing past the beginning of the holding buffer.
1833 If the buffer was just enlarged (right before the newline),
1834 we must account for that, so we pretend that the two lines
1839 for (p2
= p
- 2; --len
> 0; --p2
)
1842 backslash
= !backslash
;
1855 /* Enlarge the buffer. */
1856 register unsigned int p_off
= p
- buffer
;
1857 linebuffer
->size
*= 2;
1858 buffer
= (char *) xrealloc (buffer
, linebuffer
->size
);
1860 end
= buffer
+ linebuffer
->size
;
1861 linebuffer
->buffer
= buffer
;
1865 if (ferror (stream
))
1866 pfatal_with_name (filename
);
1871 /* Construct the list of include directories
1872 from the arguments and the default list. */
1875 construct_include_path (arg_dirs
)
1878 register unsigned int i
;
1879 #ifdef VAXC /* just don't ask ... */
1884 /* Table to hold the dirs. */
1886 register unsigned int defsize
= (sizeof (default_include_directories
)
1887 / sizeof (default_include_directories
[0]));
1888 register unsigned int max
= 5;
1889 register char **dirs
= (char **) xmalloc ((5 + defsize
) * sizeof (char *));
1890 register unsigned int idx
= 0;
1892 /* First consider any dirs specified with -I switches.
1893 Ignore dirs that don't exist. */
1896 while (*arg_dirs
!= 0)
1898 char *dir
= *arg_dirs
++;
1902 char *expanded
= tilde_expand (dir
);
1907 if (stat (dir
, &stbuf
) == 0 && S_ISDIR (stbuf
.st_mode
))
1913 xrealloc ((char *) dirs
, (max
+ defsize
) * sizeof (char *));
1917 else if (dir
!= arg_dirs
[-1])
1921 /* Now add at the end the standard default dirs. */
1923 for (i
= 0; default_include_directories
[i
] != 0; ++i
)
1924 if (stat (default_include_directories
[i
], &stbuf
) == 0
1925 && S_ISDIR (stbuf
.st_mode
))
1926 dirs
[idx
++] = default_include_directories
[i
];
1930 /* Now compute the maximum length of any name in it. */
1933 for (i
= 0; i
< idx
; ++i
)
1935 unsigned int len
= strlen (dirs
[i
]);
1936 /* If dir name is written with a trailing slash, discard it. */
1937 if (dirs
[i
][len
- 1] == '/')
1938 /* We can't just clobber a null in because it may have come from
1939 a literal string and literal strings may not be writable. */
1940 dirs
[i
] = savestring (dirs
[i
], len
- 1);
1941 if (len
> max_incl_len
)
1945 include_directories
= dirs
;
1948 /* Expand ~ or ~USER at the beginning of NAME.
1949 Return a newly malloc'd string or 0. */
1956 if (name
[1] == '/' || name
[1] == '\0')
1958 extern char *getenv ();
1963 /* Turn off --warn-undefined-variables while we expand HOME. */
1964 int save
= warn_undefined_variables_flag
;
1965 warn_undefined_variables_flag
= 0;
1967 home_dir
= allocated_variable_expand ("$(HOME)");
1969 warn_undefined_variables_flag
= save
;
1972 is_variable
= home_dir
[0] != '\0';
1976 home_dir
= getenv ("HOME");
1979 if (home_dir
== 0 || home_dir
[0] == '\0')
1981 extern char *getlogin ();
1982 char *name
= getlogin ();
1986 struct passwd
*p
= getpwnam (name
);
1988 home_dir
= p
->pw_dir
;
1994 char *new = concat (home_dir
, "", name
+ 1);
2003 struct passwd
*pwent
;
2004 char *userend
= index (name
+ 1, '/');
2007 pwent
= getpwnam (name
+ 1);
2011 return savestring (pwent
->pw_dir
, strlen (pwent
->pw_dir
));
2013 return concat (pwent
->pw_dir
, "/", userend
+ 1);
2015 else if (userend
!= 0)
2022 /* Given a chain of struct nameseq's describing a sequence of filenames,
2023 in reverse of the intended order, return a new chain describing the
2024 result of globbing the filenames. The new chain is in forward order.
2025 The links of the old chain are freed or used in the new chain.
2026 Likewise for the names in the old chain.
2028 SIZE is how big to construct chain elements.
2029 This is useful if we want them actually to be other structures
2030 that have room for additional info. */
2033 multi_glob (chain
, size
)
2034 struct nameseq
*chain
;
2037 extern void dir_setup_glob ();
2038 register struct nameseq
*new = 0;
2039 register struct nameseq
*old
;
2040 struct nameseq
*nexto
;
2043 dir_setup_glob (&gl
);
2045 for (old
= chain
; old
!= 0; old
= nexto
)
2053 if (old
->name
[0] == '~')
2055 char *newname
= tilde_expand (old
->name
);
2059 old
->name
= newname
;
2064 if (ar_name (old
->name
))
2066 /* OLD->name is an archive member reference.
2067 Replace it with the archive file name,
2068 and save the member name in MEMNAME.
2069 We will glob on the archive name and then
2070 reattach MEMNAME later. */
2072 ar_parse_name (old
->name
, &arname
, &memname
);
2080 switch (glob (old
->name
, GLOB_NOCHECK
|GLOB_ALTDIRFUNC
, NULL
, &gl
))
2082 case 0: /* Success. */
2084 register int i
= gl
.gl_pathc
;
2090 /* Try to glob on MEMNAME within the archive. */
2091 struct nameseq
*found
2092 = ar_glob (gl
.gl_pathv
[i
], memname
, size
);
2095 /* No matches. Use MEMNAME as-is. */
2097 = (struct nameseq
*) xmalloc (size
);
2098 unsigned int alen
= strlen (gl
.gl_pathv
[i
]);
2099 unsigned int mlen
= strlen (memname
);
2100 elt
->name
= (char *) xmalloc (alen
+ 1 + mlen
+ 2);
2101 bcopy (gl
.gl_pathv
[i
], elt
->name
, alen
);
2102 elt
->name
[alen
] = '(';
2103 bcopy (memname
, &elt
->name
[alen
+ 1], mlen
);
2104 elt
->name
[alen
+ 1 + mlen
] = ')';
2105 elt
->name
[alen
+ 1 + mlen
+ 1] = '\0';
2111 /* Find the end of the FOUND chain. */
2112 struct nameseq
*f
= found
;
2113 while (f
->next
!= 0)
2116 /* Attach the chain being built to the end of the FOUND
2117 chain, and make FOUND the new NEW chain. */
2127 struct nameseq
*elt
= (struct nameseq
*) xmalloc (size
);
2128 elt
->name
= savestring (gl
.gl_pathv
[i
],
2129 strlen (gl
.gl_pathv
[i
]));
2141 fatal ("virtual memory exhausted");