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"
37 struct passwd
*getpwnam
PARAMS ((char *name
));
41 /* A `struct linebuffer' is a structure which holds a line of text.
42 `readline' reads a line from a stream into a linebuffer
43 and works regardless of the length of the line. */
47 /* Note: This is the number of bytes malloc'ed for `buffer'
48 It does not indicate `buffer's real length.
49 Instead, a null char indicates end-of-string. */
54 #define initbuffer(lb) (lb)->buffer = (char *) xmalloc ((lb)->size = 200)
55 #define freebuffer(lb) free ((lb)->buffer)
58 /* A `struct conditionals' contains the information describing
59 all the active conditionals in a makefile.
61 The global variable `conditionals' contains the conditionals
62 information for the current makefile. It is initialized from
63 the static structure `toplevel_conditionals' and is later changed
64 to new structures for included makefiles. */
68 unsigned int if_cmds
; /* Depth of conditional nesting. */
69 unsigned int allocated
; /* Elts allocated in following arrays. */
70 char *ignoring
; /* Are we ignoring or interepreting? */
71 char *seen_else
; /* Have we already seen an `else'? */
74 static struct conditionals toplevel_conditionals
;
75 static struct conditionals
*conditionals
= &toplevel_conditionals
;
78 /* Default directories to search for include files in */
80 static char *default_include_directories
[] =
91 /* List of directories to search for include files in */
93 static char **include_directories
;
95 /* Maximum length of an element of the above. */
97 static unsigned int max_incl_len
;
99 /* The filename and pointer to line number of the
100 makefile currently being read in. */
102 char *reading_filename
;
103 unsigned int *reading_lineno_ptr
;
105 /* The chain of makefiles read by read_makefile. */
107 static struct dep
*read_makefiles
= 0;
109 static int read_makefile
PARAMS ((char *filename
, int flags
));
110 static unsigned int readline
PARAMS ((struct linebuffer
*linebuffer
, FILE *stream
,
111 char *filename
, unsigned int lineno
));
112 static unsigned int do_define
PARAMS ((char *name
, unsigned int namelen
, enum variable_origin origin
,
113 unsigned int lineno
, FILE *infile
, char *filename
));
114 static int conditional_line
PARAMS ((char *line
, char *filename
, unsigned int lineno
));
115 static void record_files
PARAMS ((struct nameseq
*filenames
, char *pattern
, char *pattern_percent
,
116 struct dep
*deps
, unsigned int commands_started
, char *commands
,
117 unsigned int commands_idx
, int two_colon
, char *filename
,
118 unsigned int lineno
, int set_default
));
120 /* Read in all the makefiles and return the chain of their names. */
123 read_all_makefiles (makefiles
)
126 unsigned int num_makefiles
= 0;
129 puts ("Reading makefiles...");
131 /* If there's a non-null variable MAKEFILES, its value is a list of
132 files to read first thing. But don't let it prevent reading the
133 default makefiles and don't let the default goal come from there. */
141 /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
142 int save
= warn_undefined_variables_flag
;
143 warn_undefined_variables_flag
= 0;
145 value
= allocated_variable_expand ("$(MAKEFILES)");
147 warn_undefined_variables_flag
= save
;
150 /* Set NAME to the start of next token and LENGTH to its length.
151 MAKEFILES is updated for finding remaining tokens. */
154 while ((name
= find_next_token (&p
, &length
)) != 0)
158 (void) read_makefile (name
,
159 RM_NO_DEFAULT_GOAL
| RM_INCLUDED
| RM_DONTCARE
);
165 /* Read makefiles specified with -f switches. */
168 while (*makefiles
!= 0)
170 struct dep
*tail
= read_makefiles
;
171 register struct dep
*d
;
173 if (! read_makefile (*makefiles
, 0))
174 perror_with_name ("", *makefiles
);
176 /* Find the right element of read_makefiles. */
178 while (d
->next
!= tail
)
181 /* Use the storage read_makefile allocates. */
182 *makefiles
= dep_name (d
);
187 /* If there were no -f switches, try the default names. */
189 if (num_makefiles
== 0)
191 static char *default_makefiles
[] =
193 /* all lower case since readdir() (the vms version) 'lowercasifies' */
194 { "makefile.vms", "gnumakefile", "makefile", 0 };
197 { "GNUmakefile", "Makefile", "SMakefile", 0 };
198 #else /* !Amiga && !VMS */
199 { "GNUmakefile", "makefile", "Makefile", 0 };
202 register char **p
= default_makefiles
;
203 while (*p
!= 0 && !file_exists_p (*p
))
208 if (! read_makefile (*p
, 0))
209 perror_with_name ("", *p
);
213 /* No default makefile was found. Add the default makefiles to the
214 `read_makefiles' chain so they will be updated if possible. */
215 struct dep
*tail
= read_makefiles
;
216 /* Add them to the tail, after any MAKEFILES variable makefiles. */
217 while (tail
!= 0 && tail
->next
!= 0)
219 for (p
= default_makefiles
; *p
!= 0; ++p
)
221 struct dep
*d
= (struct dep
*) xmalloc (sizeof (struct dep
));
223 d
->file
= enter_file (*p
);
224 d
->file
->dontcare
= 1;
225 /* Tell update_goal_chain to bail out as soon as this file is
226 made, and main not to die if we can't make this file. */
227 d
->changed
= RM_DONTCARE
;
239 return read_makefiles
;
242 /* Read file FILENAME as a makefile and add its contents to the data base.
244 FLAGS contains bits as above.
246 FILENAME is added to the `read_makefiles' chain.
248 Returns 1 if a file was found and read, 0 if not. */
251 read_makefile (filename
, flags
)
255 static char *collapsed
= 0;
256 static unsigned int collapsed_length
= 0;
257 register FILE *infile
;
258 struct linebuffer lb
;
259 unsigned int commands_len
= 200;
260 char *commands
= (char *) xmalloc (200);
261 unsigned int commands_idx
= 0;
262 unsigned int commands_started
;
265 int ignoring
= 0, in_ignored_define
= 0;
266 int no_targets
= 0; /* Set when reading a rule without targets. */
267 char *passed_filename
= filename
;
269 struct nameseq
*filenames
= 0;
271 unsigned int lineno
= 1;
272 unsigned int nlines
= 0;
274 char *pattern
= 0, *pattern_percent
;
278 #define record_waiting_files() \
281 if (filenames != 0) \
282 record_files (filenames, pattern, pattern_percent, deps, \
283 commands_started, commands, commands_idx, \
284 two_colon, filename, lineno, \
285 !(flags & RM_NO_DEFAULT_GOAL)); \
291 #ifdef lint /* Suppress `used before set' messages. */
298 printf ("Reading makefile `%s'", filename
);
299 if (flags
& RM_NO_DEFAULT_GOAL
)
300 printf (" (no default goal)");
301 if (flags
& RM_INCLUDED
)
302 printf (" (search path)");
303 if (flags
& RM_DONTCARE
)
304 printf (" (don't care)");
305 if (flags
& RM_NO_TILDE
)
306 printf (" (no ~ expansion)");
310 /* First, get a stream to read. */
312 /* Expand ~ in FILENAME unless it came from `include',
313 in which case it was already done. */
314 if (!(flags
& RM_NO_TILDE
) && filename
[0] == '~')
316 char *expanded
= tilde_expand (filename
);
321 infile
= fopen (filename
, "r");
322 /* Save the error code so we print the right message later. */
323 makefile_errno
= errno
;
325 /* If the makefile wasn't found and it's either a makefile from
326 the `MAKEFILES' variable or an included makefile,
327 search the included makefile search path for this makefile. */
328 if (infile
== 0 && (flags
& RM_INCLUDED
) && *filename
!= '/')
330 register unsigned int i
;
331 for (i
= 0; include_directories
[i
] != 0; ++i
)
333 char *name
= concat (include_directories
[i
], "/", filename
);
334 infile
= fopen (name
, "r");
345 /* Add FILENAME to the chain of read makefiles. */
346 deps
= (struct dep
*) xmalloc (sizeof (struct dep
));
347 deps
->next
= read_makefiles
;
348 read_makefiles
= deps
;
350 deps
->file
= lookup_file (filename
);
353 deps
->file
= enter_file (savestring (filename
, strlen (filename
)));
354 if (flags
& RM_DONTCARE
)
355 deps
->file
->dontcare
= 1;
357 if (filename
!= passed_filename
)
359 filename
= deps
->file
->name
;
360 deps
->changed
= flags
;
363 /* If the makefile can't be found at all, give up entirely. */
367 /* If we did some searching, errno has the error from the last
368 attempt, rather from FILENAME itself. Restore it in case the
369 caller wants to use it in a message. */
370 errno
= makefile_errno
;
374 reading_filename
= filename
;
375 reading_lineno_ptr
= &lineno
;
377 /* Loop over lines in the file.
378 The strategy is to accumulate target names in FILENAMES, dependencies
379 in DEPS and commands in COMMANDS. These are used to define a rule
380 when the start of the next rule (or eof) is encountered. */
384 while (!feof (infile
))
387 nlines
= readline (&lb
, infile
, filename
, lineno
);
389 /* Check for a shell command line first.
390 If it is not one, we can stop treating tab specially. */
391 if (lb
.buffer
[0] == '\t')
393 /* This line is a probably shell command. */
397 /* Ignore the commands in a rule with no targets. */
400 /* If there is no preceding rule line, don't treat this line
401 as a command, even though it begins with a tab character.
402 SunOS 4 make appears to behave this way. */
407 /* Yep, this is a shell command, and we don't care. */
410 /* Append this command line to the line being accumulated. */
412 if (commands_idx
== 0)
413 commands_started
= lineno
;
415 if (len
+ 1 + commands_idx
> commands_len
)
417 commands_len
= (len
+ 1 + commands_idx
) * 2;
418 commands
= (char *) xrealloc (commands
, commands_len
);
420 bcopy (p
, &commands
[commands_idx
], len
);
422 commands
[commands_idx
++] = '\n';
428 /* This line is not a shell command line. Don't worry about tabs. */
430 if (collapsed_length
< lb
.size
)
432 collapsed_length
= lb
.size
;
435 collapsed
= (char *) xmalloc (collapsed_length
);
437 strcpy (collapsed
, lb
.buffer
);
438 /* Collapse continuation lines. */
439 collapse_continuations (collapsed
);
440 remove_comments (collapsed
);
442 /* strncmp is first to avoid dereferencing out into space. */
443 #define word1eq(s, l) (!strncmp (s, p, l) \
444 && (p[l] == '\0' || isblank (p[l])))
449 /* This line is completely empty. */
452 /* We must first check for conditional and `define' directives before
453 ignoring anything, since they control what we will do with
456 if (!in_ignored_define
457 && (word1eq ("ifdef", 5) || word1eq ("ifndef", 6)
458 || word1eq ("ifeq", 4) || word1eq ("ifneq", 5)
459 || word1eq ("else", 4) || word1eq ("endif", 5)))
461 int i
= conditional_line (p
, filename
, lineno
);
465 makefile_fatal (filename
, lineno
,
466 "invalid syntax in conditional");
469 else if (word1eq ("endef", 5))
471 if (in_ignored_define
)
472 in_ignored_define
= 0;
474 makefile_fatal (filename
, lineno
, "extraneous `endef'");
477 else if (word1eq ("define", 6))
480 in_ignored_define
= 1;
483 p2
= next_token (p
+ 6);
484 /* Let the variable name be the whole rest of the line,
485 with trailing blanks stripped (comments have already been
486 removed), so it could be a complex variable/function
487 reference that might contain blanks. */
488 p
= index (p2
, '\0');
489 while (isblank (p
[-1]))
491 lineno
= do_define (p2
, p
- p2
, o_file
,
492 lineno
, infile
, filename
);
496 else if (word1eq ("override", 8))
498 p2
= next_token (p
+ 8);
500 makefile_error (filename
, lineno
, "empty `override' directive");
501 if (!strncmp (p2
, "define", 6) && (isblank (p2
[6]) || p2
[6] == '\0'))
504 in_ignored_define
= 1;
507 p2
= next_token (p2
+ 6);
508 /* Let the variable name be the whole rest of the line,
509 with trailing blanks stripped (comments have already been
510 removed), so it could be a complex variable/function
511 reference that might contain blanks. */
512 p
= index (p2
, '\0');
513 while (isblank (p
[-1]))
515 lineno
= do_define (p2
, p
- p2
, o_override
,
516 lineno
, infile
, filename
);
520 && !try_variable_definition (filename
, lineno
,
522 makefile_error (filename
, lineno
, "empty `override' directive");
528 /* Ignore the line. We continue here so conditionals
529 can appear in the middle of a rule. */
531 else if (word1eq ("export", 6))
534 p2
= next_token (p
+ 6);
536 export_all_variables
= 1;
537 v
= try_variable_definition (filename
, lineno
, p2
, o_file
);
539 v
->export
= v_export
;
543 for (p
= find_next_token (&p2
, &len
); p
!= 0;
544 p
= find_next_token (&p2
, &len
))
546 v
= lookup_variable (p
, len
);
548 v
= define_variable (p
, len
, "", o_file
, 0);
549 v
->export
= v_export
;
553 else if (word1eq ("unexport", 8))
557 p2
= next_token (p
+ 8);
559 export_all_variables
= 0;
560 for (p
= find_next_token (&p2
, &len
); p
!= 0;
561 p
= find_next_token (&p2
, &len
))
563 v
= lookup_variable (p
, len
);
565 v
= define_variable (p
, len
, "", o_file
, 0);
566 v
->export
= v_noexport
;
569 else if (word1eq ("include", 7) || word1eq ("-include", 8)
570 || word1eq ("sinclude", 8))
572 /* We have found an `include' line specifying a nested
573 makefile to be read at this point. */
574 struct conditionals
*save
, new_conditionals
;
575 struct nameseq
*files
;
576 /* "-include" (vs "include") says no error if the file does not
577 exist. "sinclude" is an alias for this from SGI. */
578 int noerror
= p
[0] != 'i';
580 p
= allocated_variable_expand (next_token (p
+ (noerror
? 9 : 8)));
583 makefile_error (filename
, lineno
,
584 "no file name for `%sinclude'",
589 /* Parse the list of file names. */
591 files
= multi_glob (parse_file_seq (&p2
, '\0',
592 sizeof (struct nameseq
),
594 sizeof (struct nameseq
));
597 /* Save the state of conditionals and start
598 the included makefile with a clean slate. */
600 bzero ((char *) &new_conditionals
, sizeof new_conditionals
);
601 conditionals
= &new_conditionals
;
603 /* Record the rules that are waiting so they will determine
604 the default goal before those in the included makefile. */
605 record_waiting_files ();
607 /* Read each included makefile. */
610 struct nameseq
*next
= files
->next
;
611 char *name
= files
->name
;
612 free ((char *)files
);
615 if (! read_makefile (name
, (RM_INCLUDED
| RM_NO_TILDE
616 | (noerror
? RM_DONTCARE
: 0)))
618 makefile_error (filename
, lineno
,
619 "%s: %s", name
, strerror (errno
));
622 /* Free any space allocated by conditional_line. */
623 if (conditionals
->ignoring
)
624 free (conditionals
->ignoring
);
625 if (conditionals
->seen_else
)
626 free (conditionals
->seen_else
);
630 reading_filename
= filename
;
631 reading_lineno_ptr
= &lineno
;
633 else if (word1eq ("vpath", 5))
637 p2
= variable_expand (p
+ 5);
638 p
= find_next_token (&p2
, &len
);
641 pattern
= savestring (p
, len
);
642 p
= find_next_token (&p2
, &len
);
643 /* No searchpath means remove all previous
644 selective VPATH's with the same pattern. */
647 /* No pattern means remove all previous selective VPATH's. */
649 construct_vpath_list (pattern
, p
);
654 else if (try_variable_definition (filename
, lineno
, p
, o_file
))
655 /* This line has been dealt with. */
657 else if (lb
.buffer
[0] == '\t')
659 p
= collapsed
; /* Ignore comments. */
663 /* The line is completely blank; that is harmless. */
665 /* This line starts with a tab but was not caught above
666 because there was no preceding target, and the line
667 might have been usable as a variable definition.
668 But now it is definitely lossage. */
669 makefile_fatal (filename
, lineno
,
670 "commands commence before first target");
674 /* This line describes some target files. */
678 /* Record the previous rule. */
680 record_waiting_files ();
682 /* Search the line for an unquoted ; that is not after an
684 cmdleft
= find_char_unquote (lb
.buffer
, ";#", 0);
685 if (cmdleft
!= 0 && *cmdleft
== '#')
687 /* We found a comment before a semicolon. */
691 else if (cmdleft
!= 0)
692 /* Found one. Cut the line short there before expanding it. */
695 collapse_continuations (lb
.buffer
);
697 /* Expand variable and function references before doing anything
698 else so that special characters can be inside variables. */
699 p
= variable_expand (lb
.buffer
);
702 /* Look for a semicolon in the expanded line. */
703 cmdleft
= find_char_unquote (p
, ";", 0);
706 /* Cut the line short at the semicolon. */
713 makefile_fatal (filename
, lineno
,
714 "missing rule before commands");
716 /* This line contained a variable reference that
717 expanded to nothing but whitespace. */
722 /* We accept and ignore rules without targets for
723 compatibility with SunOS 4 make. */
728 filenames
= multi_glob (parse_file_seq (&p2
, ':',
729 sizeof (struct nameseq
),
731 sizeof (struct nameseq
));
733 makefile_fatal (filename
, lineno
, "missing separator");
734 /* Is this a one-colon or two-colon entry? */
735 two_colon
= *p2
== ':';
739 /* We have some targets, so don't ignore the following commands. */
742 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
744 while (p
!= 0 && p
[-1] == '\\')
746 register char *q
= &p
[-1];
747 register int backslash
= 0;
749 backslash
= !backslash
;
751 p
= index (p
+ 1, ':');
756 /* For MS-DOS, skip a "C:\...". */
757 if (p
!= 0 && p
[1] == '\\' && isalpha (p
[-1]))
761 /* Here, the situation is quite complicated. Let's have a look
762 at a couple of targets:
770 The rule is that it's only a target, if there are TWO :'s
771 OR a space around the :.
773 if (p
&& !(isspace(p
[1]) || !p
[1] || isspace(p
[-1])))
778 struct nameseq
*target
;
779 target
= parse_file_seq (&p2
, ':', sizeof (struct nameseq
), 1);
782 makefile_fatal (filename
, lineno
, "missing target pattern");
783 else if (target
->next
!= 0)
784 makefile_fatal (filename
, lineno
, "multiple target patterns");
785 pattern
= target
->name
;
786 pattern_percent
= find_percent (pattern
);
787 if (pattern_percent
== 0)
788 makefile_fatal (filename
, lineno
,
789 "target pattern contains no `%%'");
794 /* Parse the dependencies. */
795 deps
= (struct dep
*)
796 multi_glob (parse_file_seq (&p2
, '\0', sizeof (struct dep
), 1),
797 sizeof (struct dep
));
802 /* Semicolon means rest of line is a command. */
803 unsigned int len
= strlen (cmdleft
+ 1);
805 commands_started
= lineno
;
807 /* Add this command line to the buffer. */
808 if (len
+ 2 > commands_len
)
810 commands_len
= (len
+ 2) * 2;
811 commands
= (char *) xrealloc (commands
, commands_len
);
813 bcopy (cmdleft
+ 1, commands
, len
);
815 commands
[commands_idx
++] = '\n';
821 /* We get here except in the case that we just read a rule line.
822 Record now the last rule we read, so following spurious
823 commands are properly diagnosed. */
824 record_waiting_files ();
828 if (conditionals
->if_cmds
)
829 makefile_fatal (filename
, lineno
, "missing `endif'");
831 /* At eof, record the last rule. */
832 record_waiting_files ();
835 free ((char *) commands
);
838 reading_filename
= 0;
839 reading_lineno_ptr
= 0;
844 /* Execute a `define' directive.
845 The first line has already been read, and NAME is the name of
846 the variable to be defined. The following lines remain to be read.
847 LINENO, INFILE and FILENAME refer to the makefile being read.
848 The value returned is LINENO, updated for lines read here. */
851 do_define (name
, namelen
, origin
, lineno
, infile
, filename
)
853 unsigned int namelen
;
854 enum variable_origin origin
;
859 struct linebuffer lb
;
860 unsigned int nlines
= 0;
861 unsigned int length
= 100;
862 char *definition
= (char *) xmalloc (100);
863 register unsigned int idx
= 0;
866 /* Expand the variable name. */
867 char *var
= (char *) alloca (namelen
+ 1);
868 bcopy (name
, var
, namelen
);
870 var
= variable_expand (var
);
873 while (!feof (infile
))
876 nlines
= readline (&lb
, infile
, filename
, lineno
);
878 collapse_continuations (lb
.buffer
);
880 p
= next_token (lb
.buffer
);
881 if ((p
[5] == '\0' || isblank (p
[5])) && !strncmp (p
, "endef", 5))
885 if (*next_token (p
) != '\0')
886 makefile_error (filename
, lineno
,
887 "Extraneous text after `endef' directive");
888 /* Define the variable. */
890 definition
[0] = '\0';
892 definition
[idx
- 1] = '\0';
893 (void) define_variable (var
, strlen (var
), definition
, origin
, 1);
900 unsigned int len
= strlen (lb
.buffer
);
902 /* Increase the buffer size if necessary. */
903 if (idx
+ len
+ 1 > length
)
905 length
= (idx
+ len
) * 2;
906 definition
= (char *) xrealloc (definition
, length
+ 1);
909 bcopy (lb
.buffer
, &definition
[idx
], len
);
911 /* Separate lines with a newline. */
912 definition
[idx
++] = '\n';
917 makefile_fatal (filename
, lineno
, "missing `endef', unterminated `define'");
923 /* Interpret conditional commands "ifdef", "ifndef", "ifeq",
924 "ifneq", "else" and "endif".
925 LINE is the input line, with the command as its first word.
927 FILENAME and LINENO are the filename and line number in the
928 current makefile. They are used for error messages.
930 Value is -1 if the line is invalid,
931 0 if following text should be interpreted,
932 1 if following text should be ignored. */
935 conditional_line (line
, filename
, lineno
)
942 register unsigned int i
;
946 /* It's an "if..." command. */
947 notdef
= line
[2] == 'n';
950 cmdname
= line
[3] == 'd' ? "ifndef" : "ifneq";
951 line
+= cmdname
[3] == 'd' ? 7 : 6;
955 cmdname
= line
[2] == 'd' ? "ifdef" : "ifeq";
956 line
+= cmdname
[2] == 'd' ? 6 : 5;
961 /* It's an "else" or "endif" command. */
962 notdef
= line
[1] == 'n';
963 cmdname
= notdef
? "endif" : "else";
964 line
+= notdef
? 5 : 4;
967 line
= next_token (line
);
972 makefile_error (filename
, lineno
,
973 "Extraneous text after `%s' directive",
975 /* "Else" or "endif". */
976 if (conditionals
->if_cmds
== 0)
977 makefile_fatal (filename
, lineno
, "extraneous `%s'", cmdname
);
978 /* NOTDEF indicates an `endif' command. */
980 --conditionals
->if_cmds
;
981 else if (conditionals
->seen_else
[conditionals
->if_cmds
- 1])
982 makefile_fatal (filename
, lineno
, "only one `else' per conditional");
985 /* Toggle the state of ignorance. */
986 conditionals
->ignoring
[conditionals
->if_cmds
- 1]
987 = !conditionals
->ignoring
[conditionals
->if_cmds
- 1];
988 /* Record that we have seen an `else' in this conditional.
989 A second `else' will be erroneous. */
990 conditionals
->seen_else
[conditionals
->if_cmds
- 1] = 1;
992 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
993 if (conditionals
->ignoring
[i
])
998 if (conditionals
->allocated
== 0)
1000 conditionals
->allocated
= 5;
1001 conditionals
->ignoring
= (char *) xmalloc (conditionals
->allocated
);
1002 conditionals
->seen_else
= (char *) xmalloc (conditionals
->allocated
);
1005 ++conditionals
->if_cmds
;
1006 if (conditionals
->if_cmds
> conditionals
->allocated
)
1008 conditionals
->allocated
+= 5;
1009 conditionals
->ignoring
= (char *)
1010 xrealloc (conditionals
->ignoring
, conditionals
->allocated
);
1011 conditionals
->seen_else
= (char *)
1012 xrealloc (conditionals
->seen_else
, conditionals
->allocated
);
1015 /* Record that we have seen an `if...' but no `else' so far. */
1016 conditionals
->seen_else
[conditionals
->if_cmds
- 1] = 0;
1018 /* Search through the stack to see if we're already ignoring. */
1019 for (i
= 0; i
< conditionals
->if_cmds
- 1; ++i
)
1020 if (conditionals
->ignoring
[i
])
1022 /* We are already ignoring, so just push a level
1023 to match the next "else" or "endif", and keep ignoring.
1024 We don't want to expand variables in the condition. */
1025 conditionals
->ignoring
[conditionals
->if_cmds
- 1] = 1;
1029 if (cmdname
[notdef
? 3 : 2] == 'd')
1031 /* "Ifdef" or "ifndef". */
1033 register char *p
= end_of_token (line
);
1038 v
= lookup_variable (line
, i
);
1039 conditionals
->ignoring
[conditionals
->if_cmds
- 1]
1040 = (v
!= 0 && *v
->value
!= '\0') == notdef
;
1044 /* "Ifeq" or "ifneq". */
1047 char termin
= *line
== '(' ? ',' : *line
;
1049 if (termin
!= ',' && termin
!= '"' && termin
!= '\'')
1053 /* Find the end of the first string. */
1056 register int count
= 0;
1057 for (; *line
!= '\0'; ++line
)
1060 else if (*line
== ')')
1062 else if (*line
== ',' && count
<= 0)
1066 while (*line
!= '\0' && *line
!= termin
)
1074 s2
= variable_expand (s1
);
1075 /* We must allocate a new copy of the expanded string because
1076 variable_expand re-uses the same buffer. */
1078 s1
= (char *) alloca (len
+ 1);
1079 bcopy (s2
, s1
, len
+ 1);
1082 /* Find the start of the second string. */
1083 line
= next_token (line
);
1085 termin
= termin
== ',' ? ')' : *line
;
1086 if (termin
!= ')' && termin
!= '"' && termin
!= '\'')
1089 /* Find the end of the second string. */
1092 register int count
= 0;
1093 s2
= next_token (line
);
1094 for (line
= s2
; *line
!= '\0'; ++line
)
1098 else if (*line
== ')')
1109 while (*line
!= '\0' && *line
!= termin
)
1117 line
= next_token (++line
);
1119 makefile_error (filename
, lineno
,
1120 "Extraneous text after `%s' directive",
1123 s2
= variable_expand (s2
);
1124 conditionals
->ignoring
[conditionals
->if_cmds
- 1]
1125 = streq (s1
, s2
) == notdef
;
1128 /* Search through the stack to see if we're ignoring. */
1129 for (i
= 0; i
< conditionals
->if_cmds
; ++i
)
1130 if (conditionals
->ignoring
[i
])
1135 /* Remove duplicate dependencies in CHAIN. */
1138 uniquize_deps (chain
)
1141 register struct dep
*d
;
1143 /* Make sure that no dependencies are repeated. This does not
1144 really matter for the purpose of updating targets, but it
1145 might make some names be listed twice for $^ and $?. */
1147 for (d
= chain
; d
!= 0; d
= d
->next
)
1149 struct dep
*last
, *next
;
1154 if (streq (dep_name (d
), dep_name (next
)))
1156 struct dep
*n
= next
->next
;
1158 if (next
->name
!= 0 && next
->name
!= d
->name
)
1161 free ((char *) next
);
1172 /* Record a description line for files FILENAMES,
1173 with dependencies DEPS, commands to execute described
1174 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
1175 TWO_COLON is nonzero if a double colon was used.
1176 If not nil, PATTERN is the `%' pattern to make this
1177 a static pattern rule, and PATTERN_PERCENT is a pointer
1178 to the `%' within it.
1180 The links of FILENAMES are freed, and so are any names in it
1181 that are not incorporated into other data structures. */
1184 record_files (filenames
, pattern
, pattern_percent
, deps
, commands_started
,
1185 commands
, commands_idx
, two_colon
, filename
, lineno
, set_default
)
1186 struct nameseq
*filenames
;
1187 char *pattern
, *pattern_percent
;
1189 unsigned int commands_started
;
1191 unsigned int commands_idx
;
1194 unsigned int lineno
;
1197 struct nameseq
*nextf
;
1199 unsigned int max_targets
, target_idx
;
1200 char **targets
= 0, **target_percents
= 0;
1201 struct commands
*cmds
;
1203 if (commands_idx
> 0)
1205 cmds
= (struct commands
*) xmalloc (sizeof (struct commands
));
1206 cmds
->filename
= filename
;
1207 cmds
->lineno
= commands_started
;
1208 cmds
->commands
= savestring (commands
, commands_idx
);
1209 cmds
->command_lines
= 0;
1214 for (; filenames
!= 0; filenames
= nextf
)
1216 register char *name
= filenames
->name
;
1217 register struct file
*f
;
1218 register struct dep
*d
;
1220 char *implicit_percent
;
1222 nextf
= filenames
->next
;
1223 free ((char *) filenames
);
1225 implicit_percent
= find_percent (name
);
1226 implicit
|= implicit_percent
!= 0;
1228 if (implicit
&& pattern
!= 0)
1229 makefile_fatal (filename
, lineno
,
1230 "mixed implicit and static pattern rules");
1232 if (implicit
&& implicit_percent
== 0)
1233 makefile_fatal (filename
, lineno
, "mixed implicit and normal rules");
1240 targets
= (char **) xmalloc (5 * sizeof (char *));
1241 target_percents
= (char **) xmalloc (5 * sizeof (char *));
1244 else if (target_idx
== max_targets
- 1)
1247 targets
= (char **) xrealloc ((char *) targets
,
1248 max_targets
* sizeof (char *));
1250 = (char **) xrealloc ((char *) target_percents
,
1251 max_targets
* sizeof (char *));
1253 targets
[target_idx
] = name
;
1254 target_percents
[target_idx
] = implicit_percent
;
1259 /* If there are multiple filenames, copy the chain DEPS
1260 for all but the last one. It is not safe for the same deps
1261 to go in more than one place in the data base. */
1262 this = nextf
!= 0 ? copy_dep_chain (deps
) : deps
;
1265 /* If this is an extended static rule:
1266 `targets: target%pattern: dep%pattern; cmds',
1267 translate each dependency pattern into a plain filename
1268 using the target pattern and this target's name. */
1269 if (!pattern_matches (pattern
, pattern_percent
, name
))
1271 /* Give a warning if the rule is meaningless. */
1272 makefile_error (filename
, lineno
,
1273 "target `%s' doesn't match the target pattern",
1279 /* We use patsubst_expand to do the work of translating
1280 the target pattern, the target's name and the dependencies'
1281 patterns into plain dependency names. */
1282 char *buffer
= variable_expand ("");
1284 for (d
= this; d
!= 0; d
= d
->next
)
1287 char *percent
= find_percent (d
->name
);
1290 o
= patsubst_expand (buffer
, name
, pattern
, d
->name
,
1291 pattern_percent
, percent
);
1293 d
->name
= savestring (buffer
, o
- buffer
);
1299 /* Single-colon. Combine these dependencies
1300 with others in file's existing record, if any. */
1301 f
= enter_file (name
);
1303 if (f
->double_colon
)
1304 makefile_fatal (filename
, lineno
,
1305 "target file `%s' has both : and :: entries",
1308 /* If CMDS == F->CMDS, this target was listed in this rule
1309 more than once. Just give a warning since this is harmless. */
1310 if (cmds
!= 0 && cmds
== f
->cmds
)
1313 "target `%s' given more than once in the same rule.",
1316 /* Check for two single-colon entries both with commands.
1317 Check is_target so that we don't lose on files such as .c.o
1318 whose commands were preinitialized. */
1319 else if (cmds
!= 0 && f
->cmds
!= 0 && f
->is_target
)
1321 makefile_error (cmds
->filename
, cmds
->lineno
,
1322 "warning: overriding commands for target `%s'",
1324 makefile_error (f
->cmds
->filename
, f
->cmds
->lineno
,
1325 "warning: ignoring old commands for target `%s'",
1331 /* Defining .DEFAULT with no deps or cmds clears it. */
1332 if (f
== default_file
&& this == 0 && cmds
== 0)
1336 /* Defining .SUFFIXES with no dependencies
1337 clears out the list of suffixes. */
1338 if (f
== suffix_file
&& this == 0)
1343 struct dep
*nextd
= d
->next
;
1350 else if (f
->deps
!= 0)
1352 /* Add the file's old deps and the new ones in THIS together. */
1354 struct dep
*firstdeps
, *moredeps
;
1357 /* This is the rule with commands, so put its deps first.
1358 The rationale behind this is that $< expands to the
1359 first dep in the chain, and commands use $< expecting
1360 to get the dep that rule specifies. */
1366 /* Append the new deps to the old ones. */
1367 firstdeps
= f
->deps
;
1372 firstdeps
= moredeps
;
1376 while (d
->next
!= 0)
1381 f
->deps
= firstdeps
;
1386 /* If this is a static pattern rule, set the file's stem to
1387 the part of its name that matched the `%' in the pattern,
1388 so you can use $* in the commands. */
1391 static char *percent
= "%";
1392 char *buffer
= variable_expand ("");
1393 char *o
= patsubst_expand (buffer
, name
, pattern
, percent
,
1394 pattern_percent
, percent
);
1395 f
->stem
= savestring (buffer
, o
- buffer
);
1400 /* Double-colon. Make a new record
1401 even if the file already has one. */
1402 f
= lookup_file (name
);
1403 /* Check for both : and :: rules. Check is_target so
1404 we don't lose on default suffix rules or makefiles. */
1405 if (f
!= 0 && f
->is_target
&& !f
->double_colon
)
1406 makefile_fatal (filename
, lineno
,
1407 "target file `%s' has both : and :: entries",
1409 f
= enter_file (name
);
1410 /* If there was an existing entry and it was a double-colon
1411 entry, enter_file will have returned a new one, making it the
1412 prev pointer of the old one, and setting its double_colon
1413 pointer to the first one. */
1414 if (f
->double_colon
== 0)
1415 /* This is the first entry for this name, so we must
1416 set its double_colon pointer to itself. */
1417 f
->double_colon
= f
;
1423 /* Free name if not needed further. */
1424 if (f
!= 0 && name
!= f
->name
1425 && (name
< f
->name
|| name
> f
->name
+ strlen (f
->name
)))
1431 /* See if this is first target seen whose name does
1432 not start with a `.', unless it contains a slash. */
1433 if (default_goal_file
== 0 && set_default
1434 && (*name
!= '.' || index (name
, '/') != 0))
1438 /* If this file is a suffix, don't
1439 let it be the default goal file. */
1441 for (d
= suffix_file
->deps
; d
!= 0; d
= d
->next
)
1443 register struct dep
*d2
;
1444 if (*dep_name (d
) != '.' && streq (name
, dep_name (d
)))
1449 for (d2
= suffix_file
->deps
; d2
!= 0; d2
= d2
->next
)
1451 register unsigned int len
= strlen (dep_name (d2
));
1452 if (strncmp (name
, dep_name (d2
), len
))
1454 if (streq (name
+ len
, dep_name (d
)))
1465 default_goal_file
= f
;
1471 targets
[target_idx
] = 0;
1472 target_percents
[target_idx
] = 0;
1473 create_pattern_rule (targets
, target_percents
, two_colon
, deps
, cmds
, 1);
1474 free ((char *) target_percents
);
1478 /* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
1479 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
1480 Quoting backslashes are removed from STRING by compacting it into
1481 itself. Returns a pointer to the first unquoted STOPCHAR if there is
1482 one, or nil if there are none. */
1485 find_char_unquote (string
, stopchars
, blank
)
1490 unsigned int string_len
= strlen (string
);
1491 register char *p
= string
;
1495 while (*p
!= '\0' && index (stopchars
, *p
) == 0
1496 && (!blank
|| !isblank (*p
)))
1501 if (p
> string
&& p
[-1] == '\\')
1503 /* Search for more backslashes. */
1504 register int i
= -2;
1505 while (&p
[i
] >= string
&& p
[i
] == '\\')
1508 /* The number of backslashes is now -I.
1509 Copy P over itself to swallow half of them. */
1510 bcopy (&p
[i
/ 2], &p
[i
], (string_len
- (p
- string
)) - (i
/ 2) + 1);
1513 /* All the backslashes quoted each other; the STOPCHAR was
1517 /* The STOPCHAR was quoted by a backslash. Look for another. */
1520 /* No backslash in sight. */
1524 /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
1528 /* Search PATTERN for an unquoted %. */
1531 find_percent (pattern
)
1534 return find_char_unquote (pattern
, "%", 0);
1537 /* Parse a string into a sequence of filenames represented as a
1538 chain of struct nameseq's in reverse order and return that chain.
1540 The string is passed as STRINGP, the address of a string pointer.
1541 The string pointer is updated to point at the first character
1542 not parsed, which either is a null char or equals STOPCHAR.
1544 SIZE is how big to construct chain elements.
1545 This is useful if we want them actually to be other structures
1546 that have room for additional info.
1548 If STRIP is nonzero, strip `./'s off the beginning. */
1551 parse_file_seq (stringp
, stopchar
, size
, strip
)
1557 register struct nameseq
*new = 0;
1558 register struct nameseq
*new1
, *lastnew1
;
1559 register char *p
= *stringp
;
1566 stopchars
[1] = stopchar
;
1567 stopchars
[2] = '\0';
1569 stopchars
[0] = stopchar
;
1570 stopchars
[1] = '\0';
1575 /* Skip whitespace; see if any more names are left. */
1582 /* Yes, find end of next name. */
1584 p
= find_char_unquote (q
, stopchars
, 1);
1586 /* convert comma separated list to space separated */
1591 /* For MS-DOS, skip a "C:\...". */
1592 if (stopchar
== ':' && p
!= 0 && p
[1] == '\\' && isalpha (p
[-1]))
1596 if (stopchar
== ':' && p
&& *p
== ':' &&
1597 !(isspace(p
[1]) || !p
[1] || isspace(p
[-1])))
1599 p
= find_char_unquote (p
+1, stopchars
, 1);
1607 /* Skip leading `[]'s. */
1608 while (p
- q
> 2 && q
[0] == '[' && q
[1] == ']')
1610 /* Skip leading `./'s. */
1611 while (p
- q
> 2 && q
[0] == '.' && q
[1] == '/')
1614 q
+= 2; /* Skip "./". */
1615 while (q
< p
&& *q
== '/')
1616 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
1620 /* Extract the filename just found, and skip it. */
1623 /* ".///" was stripped to "". */
1628 name
= savestring ("", 0);
1630 name
= savestring ("./", 2);
1635 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need
1636 * to remove this '\' before we can use the filename.
1637 * Savestring called because q may be read-only string constant.
1640 char *qbase
= savestring(q
, strlen(q
));
1641 char *pbase
= qbase
+ (p
-q
);
1648 if (*q1
== '\\' && *(q1
+1) == ':')
1655 name
= savestring (qbase
, p1
- qbase
);
1659 name
= savestring (q
, p
- q
);
1662 /* Add it to the front of the chain. */
1663 new1
= (struct nameseq
*) xmalloc (size
);
1671 /* Look for multi-word archive references.
1672 They are indicated by a elt ending with an unmatched `)' and
1673 an elt further down the chain (i.e., previous in the file list)
1674 with an unmatched `(' (e.g., "lib(mem"). */
1679 if (new1
->name
[0] != '(' /* Don't catch "(%)" and suchlike. */
1680 && new1
->name
[strlen (new1
->name
) - 1] == ')'
1681 && index (new1
->name
, '(') == 0)
1683 /* NEW1 ends with a `)' but does not contain a `('.
1684 Look back for an elt with an opening `(' but no closing `)'. */
1686 struct nameseq
*n
= new1
->next
, *lastn
= new1
;
1688 while (n
!= 0 && (paren
= index (n
->name
, '(')) == 0)
1694 /* Ignore something starting with `(', as that cannot actually
1695 be an archive-member reference (and treating it as such
1696 results in an empty file name, which causes much lossage). */
1697 && n
->name
[0] != '(')
1699 /* N is the first element in the archive group.
1700 Its name looks like "lib(mem" (with no closing `)'). */
1704 /* Copy "lib(" into LIBNAME. */
1706 libname
= (char *) alloca (paren
- n
->name
+ 1);
1707 bcopy (n
->name
, libname
, paren
- n
->name
);
1708 libname
[paren
- n
->name
] = '\0';
1712 /* N was just "lib(", part of something like "lib( a b)".
1713 Edit it out of the chain and free its storage. */
1714 lastn
->next
= n
->next
;
1717 /* LASTN->next is the new stopping elt for the loop below. */
1722 /* Replace N's name with the full archive reference. */
1723 name
= concat (libname
, paren
, ")");
1728 if (new1
->name
[1] == '\0')
1730 /* NEW1 is just ")", part of something like "lib(a b )".
1731 Omit it from the chain and free its storage. */
1735 lastnew1
->next
= new1
->next
;
1739 free ((char *) lastn
);
1743 /* Replace also NEW1->name, which already has closing `)'. */
1744 name
= concat (libname
, new1
->name
, "");
1750 /* Trace back from NEW1 (the end of the list) until N
1751 (the beginning of the list), rewriting each name
1752 with the full archive reference. */
1756 name
= concat (libname
, new1
->name
, ")");
1765 /* No frobnication happening. Just step down the list. */
1782 /* Read a line of text from STREAM into LINEBUFFER.
1783 Combine continuation lines into one line.
1784 Return the number of actual lines read (> 1 if hacked continuation lines).
1788 readline (linebuffer
, stream
, filename
, lineno
)
1789 struct linebuffer
*linebuffer
;
1792 unsigned int lineno
;
1794 char *buffer
= linebuffer
->buffer
;
1795 register char *p
= linebuffer
->buffer
;
1796 register char *end
= p
+ linebuffer
->size
;
1797 register int len
, lastlen
= 0;
1799 register unsigned int nlines
= 0;
1800 register int backslash
;
1804 while (fgets (p
, end
- p
, stream
) != 0)
1809 /* This only happens when the first thing on the line is a '\0'.
1810 It is a pretty hopeless case, but (wonder of wonders) Athena
1811 lossage strikes again! (xmkmf puts NULs in its makefiles.)
1812 There is nothing really to be done; we synthesize a newline so
1813 the following line doesn't appear to be part of this line. */
1814 makefile_error (filename
, lineno
,
1815 "warning: NUL character seen; rest of line ignored");
1823 /* Probably ran out of buffer space. */
1824 register unsigned int p_off
= p
- buffer
;
1825 linebuffer
->size
*= 2;
1826 buffer
= (char *) xrealloc (buffer
, linebuffer
->size
);
1828 end
= buffer
+ linebuffer
->size
;
1829 linebuffer
->buffer
= buffer
;
1837 if (len
== 1 && p
> buffer
)
1838 /* P is pointing at a newline and it's the beginning of
1839 the buffer returned by the last fgets call. However,
1840 it is not necessarily the beginning of a line if P is
1841 pointing past the beginning of the holding buffer.
1842 If the buffer was just enlarged (right before the newline),
1843 we must account for that, so we pretend that the two lines
1848 for (p2
= p
- 2; --len
> 0; --p2
)
1851 backslash
= !backslash
;
1864 /* Enlarge the buffer. */
1865 register unsigned int p_off
= p
- buffer
;
1866 linebuffer
->size
*= 2;
1867 buffer
= (char *) xrealloc (buffer
, linebuffer
->size
);
1869 end
= buffer
+ linebuffer
->size
;
1870 linebuffer
->buffer
= buffer
;
1874 if (ferror (stream
))
1875 pfatal_with_name (filename
);
1880 /* Construct the list of include directories
1881 from the arguments and the default list. */
1884 construct_include_path (arg_dirs
)
1887 register unsigned int i
;
1888 #ifdef VAXC /* just don't ask ... */
1893 /* Table to hold the dirs. */
1895 register unsigned int defsize
= (sizeof (default_include_directories
)
1896 / sizeof (default_include_directories
[0]));
1897 register unsigned int max
= 5;
1898 register char **dirs
= (char **) xmalloc ((5 + defsize
) * sizeof (char *));
1899 register unsigned int idx
= 0;
1901 /* First consider any dirs specified with -I switches.
1902 Ignore dirs that don't exist. */
1905 while (*arg_dirs
!= 0)
1907 char *dir
= *arg_dirs
++;
1911 char *expanded
= tilde_expand (dir
);
1916 if (stat (dir
, &stbuf
) == 0 && S_ISDIR (stbuf
.st_mode
))
1922 xrealloc ((char *) dirs
, (max
+ defsize
) * sizeof (char *));
1926 else if (dir
!= arg_dirs
[-1])
1930 /* Now add at the end the standard default dirs. */
1932 for (i
= 0; default_include_directories
[i
] != 0; ++i
)
1933 if (stat (default_include_directories
[i
], &stbuf
) == 0
1934 && S_ISDIR (stbuf
.st_mode
))
1935 dirs
[idx
++] = default_include_directories
[i
];
1939 /* Now compute the maximum length of any name in it. */
1942 for (i
= 0; i
< idx
; ++i
)
1944 unsigned int len
= strlen (dirs
[i
]);
1945 /* If dir name is written with a trailing slash, discard it. */
1946 if (dirs
[i
][len
- 1] == '/')
1947 /* We can't just clobber a null in because it may have come from
1948 a literal string and literal strings may not be writable. */
1949 dirs
[i
] = savestring (dirs
[i
], len
- 1);
1950 if (len
> max_incl_len
)
1954 include_directories
= dirs
;
1957 /* Expand ~ or ~USER at the beginning of NAME.
1958 Return a newly malloc'd string or 0. */
1965 if (name
[1] == '/' || name
[1] == '\0')
1967 extern char *getenv ();
1972 /* Turn off --warn-undefined-variables while we expand HOME. */
1973 int save
= warn_undefined_variables_flag
;
1974 warn_undefined_variables_flag
= 0;
1976 home_dir
= allocated_variable_expand ("$(HOME)");
1978 warn_undefined_variables_flag
= save
;
1981 is_variable
= home_dir
[0] != '\0';
1985 home_dir
= getenv ("HOME");
1988 if (home_dir
== 0 || home_dir
[0] == '\0')
1990 extern char *getlogin ();
1991 char *name
= getlogin ();
1995 struct passwd
*p
= getpwnam (name
);
1997 home_dir
= p
->pw_dir
;
2003 char *new = concat (home_dir
, "", name
+ 1);
2012 struct passwd
*pwent
;
2013 char *userend
= index (name
+ 1, '/');
2016 pwent
= getpwnam (name
+ 1);
2020 return savestring (pwent
->pw_dir
, strlen (pwent
->pw_dir
));
2022 return concat (pwent
->pw_dir
, "/", userend
+ 1);
2024 else if (userend
!= 0)
2032 /* Given a chain of struct nameseq's describing a sequence of filenames,
2033 in reverse of the intended order, return a new chain describing the
2034 result of globbing the filenames. The new chain is in forward order.
2035 The links of the old chain are freed or used in the new chain.
2036 Likewise for the names in the old chain.
2038 SIZE is how big to construct chain elements.
2039 This is useful if we want them actually to be other structures
2040 that have room for additional info. */
2043 multi_glob (chain
, size
)
2044 struct nameseq
*chain
;
2047 extern void dir_setup_glob ();
2048 register struct nameseq
*new = 0;
2049 register struct nameseq
*old
;
2050 struct nameseq
*nexto
;
2053 dir_setup_glob (&gl
);
2055 for (old
= chain
; old
!= 0; old
= nexto
)
2063 if (old
->name
[0] == '~')
2065 char *newname
= tilde_expand (old
->name
);
2069 old
->name
= newname
;
2074 if (ar_name (old
->name
))
2076 /* OLD->name is an archive member reference.
2077 Replace it with the archive file name,
2078 and save the member name in MEMNAME.
2079 We will glob on the archive name and then
2080 reattach MEMNAME later. */
2082 ar_parse_name (old
->name
, &arname
, &memname
);
2088 #endif /* !NO_ARCHIVES */
2090 switch (glob (old
->name
, GLOB_NOCHECK
|GLOB_ALTDIRFUNC
, NULL
, &gl
))
2092 case 0: /* Success. */
2094 register int i
= gl
.gl_pathc
;
2100 /* Try to glob on MEMNAME within the archive. */
2101 struct nameseq
*found
2102 = ar_glob (gl
.gl_pathv
[i
], memname
, size
);
2105 /* No matches. Use MEMNAME as-is. */
2107 = (struct nameseq
*) xmalloc (size
);
2108 unsigned int alen
= strlen (gl
.gl_pathv
[i
]);
2109 unsigned int mlen
= strlen (memname
);
2110 elt
->name
= (char *) xmalloc (alen
+ 1 + mlen
+ 2);
2111 bcopy (gl
.gl_pathv
[i
], elt
->name
, alen
);
2112 elt
->name
[alen
] = '(';
2113 bcopy (memname
, &elt
->name
[alen
+ 1], mlen
);
2114 elt
->name
[alen
+ 1 + mlen
] = ')';
2115 elt
->name
[alen
+ 1 + mlen
+ 1] = '\0';
2121 /* Find the end of the FOUND chain. */
2122 struct nameseq
*f
= found
;
2123 while (f
->next
!= 0)
2126 /* Attach the chain being built to the end of the FOUND
2127 chain, and make FOUND the new NEW chain. */
2135 #endif /* !NO_ARCHIVES */
2137 struct nameseq
*elt
= (struct nameseq
*) xmalloc (size
);
2138 elt
->name
= savestring (gl
.gl_pathv
[i
],
2139 strlen (gl
.gl_pathv
[i
]));
2151 fatal ("virtual memory exhausted");