VirtualBox

source: kBuild/trunk/src/kmk/read.c@ 1719

Last change on this file since 1719 was 1719, checked in by bird, 17 years ago

kmk: More if conditionals code.

  • Property svn:eol-style set to native
File size: 113.2 KB
Line 
1/* Reading and parsing of makefiles for GNU Make.
2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
4Foundation, Inc.
5This file is part of GNU Make.
6
7GNU Make is free software; you can redistribute it and/or modify it under the
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 2, or (at your option) any later version.
10
11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License along with
16GNU Make; see the file COPYING. If not, write to the Free Software
17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
18
19#include "make.h"
20
21#include <assert.h>
22
23#include <glob.h>
24
25#include "dep.h"
26#include "filedef.h"
27#include "job.h"
28#include "commands.h"
29#include "variable.h"
30#include "rule.h"
31#include "debug.h"
32#include "hash.h"
33#ifdef KMK
34# include "kbuild.h"
35#endif
36#ifdef CONFIG_WITH_INCLUDEDEP
37# ifdef HAVE_FCNTL_H
38# include <fcntl.h>
39# else
40# include <sys/file.h>
41#endif
42# ifdef WINDOWS32
43# include <io.h>
44# endif
45#endif
46
47#ifndef WINDOWS32
48#ifndef _AMIGA
49#ifndef VMS
50#include <pwd.h>
51#else
52struct passwd *getpwnam (char *name);
53#endif
54#endif
55#endif /* !WINDOWS32 */
56
57/* A 'struct ebuffer' controls the origin of the makefile we are currently
58 eval'ing.
59*/
60
61struct ebuffer
62 {
63 char *buffer; /* Start of the current line in the buffer. */
64 char *bufnext; /* Start of the next line in the buffer. */
65 char *bufstart; /* Start of the entire buffer. */
66 unsigned int size; /* Malloc'd size of buffer. */
67 FILE *fp; /* File, or NULL if this is an internal buffer. */
68 struct floc floc; /* Info on the file in fp (if any). */
69 };
70
71/* Types of "words" that can be read in a makefile. */
72enum make_word_type
73 {
74 w_bogus, w_eol, w_static, w_variable, w_colon, w_dcolon, w_semicolon,
75 w_varassign
76 };
77
78
79/* A `struct conditionals' contains the information describing
80 all the active conditionals in a makefile.
81
82 The global variable `conditionals' contains the conditionals
83 information for the current makefile. It is initialized from
84 the static structure `toplevel_conditionals' and is later changed
85 to new structures for included makefiles. */
86
87struct conditionals
88 {
89 unsigned int if_cmds; /* Depth of conditional nesting. */
90 unsigned int allocated; /* Elts allocated in following arrays. */
91 char *ignoring; /* Are we ignoring or interpreting?
92 0=interpreting, 1=not yet interpreted,
93 2=already interpreted */
94 char *seen_else; /* Have we already seen an `else'? */
95 };
96
97static struct conditionals toplevel_conditionals;
98static struct conditionals *conditionals = &toplevel_conditionals;
99
100
101/* Default directories to search for include files in */
102
103static const char *default_include_directories[] =
104 {
105#ifndef KMK
106#if defined(WINDOWS32) && !defined(INCLUDEDIR)
107/* This completely up to the user when they install MSVC or other packages.
108 This is defined as a placeholder. */
109# define INCLUDEDIR "."
110#endif
111# ifdef INCLUDEDIR /* bird */
112 INCLUDEDIR,
113# else /* bird */
114 ".", /* bird */
115# endif /* bird */
116#ifndef _AMIGA
117 "/usr/gnu/include",
118 "/usr/local/include",
119 "/usr/include",
120#endif
121#endif /* !KMK */
122 0
123 };
124
125/* List of directories to search for include files in */
126
127static const char **include_directories;
128
129/* Maximum length of an element of the above. */
130
131static unsigned int max_incl_len;
132
133/* The filename and pointer to line number of the
134 makefile currently being read in. */
135
136const struct floc *reading_file = 0;
137
138/* The chain of makefiles read by read_makefile. */
139
140static struct dep *read_makefiles = 0;
141
142static int eval_makefile (const char *filename, int flags);
143static int eval (struct ebuffer *buffer, int flags);
144
145static long readline (struct ebuffer *ebuf);
146static void do_define (char *name, unsigned int namelen,
147 enum variable_origin origin, struct ebuffer *ebuf);
148static int conditional_line (char *line, int len, const struct floc *flocp);
149static void record_files (struct nameseq *filenames, const char *pattern,
150 const char *pattern_percent, struct dep *deps,
151 unsigned int cmds_started, char *commands,
152 unsigned int commands_idx, int two_colon,
153 const struct floc *flocp);
154static void record_target_var (struct nameseq *filenames, char *defn,
155 enum variable_origin origin, int enabled,
156 const struct floc *flocp);
157static enum make_word_type get_next_mword (char *buffer, char *delim,
158 char **startp, unsigned int *length);
159static void remove_comments (char *line);
160static char *find_char_unquote (char *string, int stop1, int stop2,
161 int blank, int ignorevars);
162
163
164/* Read in all the makefiles and return the chain of their names. */
165
166struct dep *
167read_all_makefiles (const char **makefiles)
168{
169 unsigned int num_makefiles = 0;
170
171 /* Create *_LIST variables, to hold the makefiles, targets, and variables
172 we will be reading. */
173
174 define_variable ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", o_file, 0);
175
176 DB (DB_BASIC, (_("Reading makefiles...\n")));
177
178 /* If there's a non-null variable MAKEFILES, its value is a list of
179 files to read first thing. But don't let it prevent reading the
180 default makefiles and don't let the default goal come from there. */
181
182 {
183 char *value;
184 char *name, *p;
185 unsigned int length;
186
187 {
188 /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
189 int save = warn_undefined_variables_flag;
190 warn_undefined_variables_flag = 0;
191
192 value = allocated_variable_expand ("$(MAKEFILES)");
193
194 warn_undefined_variables_flag = save;
195 }
196
197 /* Set NAME to the start of next token and LENGTH to its length.
198 MAKEFILES is updated for finding remaining tokens. */
199 p = value;
200
201 while ((name = find_next_token ((const char **)&p, &length)) != 0)
202 {
203 if (*p != '\0')
204 *p++ = '\0';
205 eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
206 }
207
208 free (value);
209 }
210
211 /* Read makefiles specified with -f switches. */
212
213 if (makefiles != 0)
214 while (*makefiles != 0)
215 {
216 struct dep *tail = read_makefiles;
217 register struct dep *d;
218
219 if (! eval_makefile (*makefiles, 0))
220 perror_with_name ("", *makefiles);
221
222 /* Find the right element of read_makefiles. */
223 d = read_makefiles;
224 while (d->next != tail)
225 d = d->next;
226
227 /* Use the storage read_makefile allocates. */
228 *makefiles = dep_name (d);
229 ++num_makefiles;
230 ++makefiles;
231 }
232
233 /* If there were no -f switches, try the default names. */
234
235 if (num_makefiles == 0)
236 {
237 static char *default_makefiles[] =
238#ifdef VMS
239 /* all lower case since readdir() (the vms version) 'lowercasifies' */
240# ifdef KMK
241 { "makefile.kmk", "makefile.vms", "gnumakefile.", "makefile.", 0 };
242# else
243 { "makefile.vms", "gnumakefile.", "makefile.", 0 };
244# endif
245#else
246#ifdef _AMIGA
247 /* what's the deal here? no dots? */
248# ifdef KMK
249 { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "Makefile", "SMakefile", 0 };
250# else
251 { "GNUmakefile", "Makefile", "SMakefile", 0 };
252# endif
253#else /* !Amiga && !VMS */
254# ifdef KMK
255 { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", 0 };
256# else
257 { "GNUmakefile", "makefile", "Makefile", 0 };
258# endif
259#endif /* AMIGA */
260#endif /* VMS */
261 register char **p = default_makefiles;
262 while (*p != 0 && !file_exists_p (*p))
263 ++p;
264
265 if (*p != 0)
266 {
267 if (! eval_makefile (*p, 0))
268 perror_with_name ("", *p);
269 }
270 else
271 {
272 /* No default makefile was found. Add the default makefiles to the
273 `read_makefiles' chain so they will be updated if possible. */
274 struct dep *tail = read_makefiles;
275 /* Add them to the tail, after any MAKEFILES variable makefiles. */
276 while (tail != 0 && tail->next != 0)
277 tail = tail->next;
278 for (p = default_makefiles; *p != 0; ++p)
279 {
280 struct dep *d = alloc_dep ();
281 d->file = enter_file (strcache_add (*p));
282 d->file->dontcare = 1;
283 /* Tell update_goal_chain to bail out as soon as this file is
284 made, and main not to die if we can't make this file. */
285 d->changed = RM_DONTCARE;
286 if (tail == 0)
287 read_makefiles = d;
288 else
289 tail->next = d;
290 tail = d;
291 }
292 if (tail != 0)
293 tail->next = 0;
294 }
295 }
296
297 return read_makefiles;
298}
299
300
301/* Install a new conditional and return the previous one. */
302
303static struct conditionals *
304install_conditionals (struct conditionals *new)
305{
306 struct conditionals *save = conditionals;
307
308 memset (new, '\0', sizeof (*new));
309 conditionals = new;
310
311 return save;
312}
313
314/* Free the current conditionals and reinstate a saved one. */
315
316static void
317restore_conditionals (struct conditionals *saved)
318{
319 /* Free any space allocated by conditional_line. */
320 if (conditionals->ignoring)
321 free (conditionals->ignoring);
322 if (conditionals->seen_else)
323 free (conditionals->seen_else);
324
325 /* Restore state. */
326 conditionals = saved;
327}
328
329
330static int
331eval_makefile (const char *filename, int flags)
332{
333 struct dep *deps;
334 struct ebuffer ebuf;
335 const struct floc *curfile;
336 char *expanded = 0;
337 int makefile_errno;
338 int r;
339
340 filename = strcache_add (filename);
341 ebuf.floc.filenm = filename;
342 ebuf.floc.lineno = 1;
343
344 if (ISDB (DB_VERBOSE))
345 {
346 printf (_("Reading makefile `%s'"), filename);
347 if (flags & RM_NO_DEFAULT_GOAL)
348 printf (_(" (no default goal)"));
349 if (flags & RM_INCLUDED)
350 printf (_(" (search path)"));
351 if (flags & RM_DONTCARE)
352 printf (_(" (don't care)"));
353 if (flags & RM_NO_TILDE)
354 printf (_(" (no ~ expansion)"));
355 puts ("...");
356 }
357
358 /* First, get a stream to read. */
359
360 /* Expand ~ in FILENAME unless it came from `include',
361 in which case it was already done. */
362 if (!(flags & RM_NO_TILDE) && filename[0] == '~')
363 {
364 expanded = tilde_expand (filename);
365 if (expanded != 0)
366 filename = expanded;
367 }
368
369 ebuf.fp = fopen (filename, "r");
370 /* Save the error code so we print the right message later. */
371 makefile_errno = errno;
372
373 /* If the makefile wasn't found and it's either a makefile from
374 the `MAKEFILES' variable or an included makefile,
375 search the included makefile search path for this makefile. */
376 if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
377 {
378 unsigned int i;
379 for (i = 0; include_directories[i] != 0; ++i)
380 {
381 const char *included = concat (include_directories[i], "/", filename);
382 ebuf.fp = fopen (included, "r");
383 if (ebuf.fp)
384 {
385 filename = strcache_add (included);
386 break;
387 }
388 }
389 }
390
391 /* Add FILENAME to the chain of read makefiles. */
392 deps = alloc_dep ();
393 deps->next = read_makefiles;
394 read_makefiles = deps;
395 deps->file = lookup_file (filename);
396 if (deps->file == 0)
397 deps->file = enter_file (filename);
398 filename = deps->file->name;
399 deps->changed = flags;
400 if (flags & RM_DONTCARE)
401 deps->file->dontcare = 1;
402
403 if (expanded)
404 free (expanded);
405
406 /* If the makefile can't be found at all, give up entirely. */
407
408 if (ebuf.fp == 0)
409 {
410 /* If we did some searching, errno has the error from the last
411 attempt, rather from FILENAME itself. Restore it in case the
412 caller wants to use it in a message. */
413 errno = makefile_errno;
414 return 0;
415 }
416
417 /* Add this makefile to the list. */
418 do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file,
419 f_append, 0);
420
421#ifdef KMK
422 /* Buffer the entire file or at least 256KB (footer.kmk) of it. */
423 {
424 void *stream_buf = NULL;
425 struct stat st;
426 if (!fstat (fileno (ebuf.fp), &st))
427 {
428 unsigned int stream_buf_size = 256*1024;
429 if (st.st_size < stream_buf_size)
430 stream_buf_size = (st.st_size + 0xfff) & ~0xfffU;
431 stream_buf = xmalloc (stream_buf_size);
432 setvbuf (ebuf.fp, stream_buf, _IOFBF, stream_buf_size);
433 }
434#endif
435
436 /* Evaluate the makefile */
437
438 ebuf.size = 200;
439 ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size);
440
441 curfile = reading_file;
442 reading_file = &ebuf.floc;
443
444 r = eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));
445
446 reading_file = curfile;
447
448 fclose (ebuf.fp);
449
450#ifdef KMK
451 if (stream_buf)
452 free (stream_buf);
453 }
454#endif
455 free (ebuf.bufstart);
456 alloca (0);
457 return r;
458}
459
460int
461eval_buffer (char *buffer)
462{
463 struct ebuffer ebuf;
464 struct conditionals *saved;
465 struct conditionals new;
466 const struct floc *curfile;
467 int r;
468
469 /* Evaluate the buffer */
470
471 ebuf.size = strlen (buffer);
472 ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer;
473 ebuf.fp = NULL;
474
475 ebuf.floc = *reading_file;
476
477 curfile = reading_file;
478 reading_file = &ebuf.floc;
479
480 saved = install_conditionals (&new);
481
482 r = eval (&ebuf, 1);
483
484 restore_conditionals (saved);
485
486 reading_file = curfile;
487
488 alloca (0);
489 return r;
490}
491
492#ifdef CONFIG_WITH_INCLUDEDEP
493/* no nonsense dependency file including.
494
495 Because nobody wants bogus dependency files to break their incremental
496 builds with hard to comprehend error messages, this function does not
497 use the normal eval routine but does all the parsing itself. This isn't,
498 as much work as it sounds, because the necessary feature set is very
499 limited.
500
501 eval_include_dep groks:
502
503 define var
504 endef
505
506 var [|:|?|>]= value [\]
507
508 [\]
509 file: [deps] [\]
510
511 */
512void
513eval_include_dep (const char *name, struct floc *f)
514{
515 int fd;
516 char *file_base;
517 const char *file_end, *cur, *endp;
518 struct stat st;
519 unsigned line_no;
520
521 /* open and read it into memory. ignore non-existing dependency files
522 or that we can't read. */
523 errno = 0;
524#ifdef O_BINARY
525 fd = open (name, O_RDONLY | O_BINARY, 0);
526#else
527 fd = open (name, O_RDONLY, 0);
528#endif
529 if (fd < 0)
530 {
531 int err = errno;
532 if (err == ENOENT || !file_exists_p (name))
533 return;
534 error (f, "%s: %s", name, strerror (err));
535 return;
536 }
537 if (fstat (fd, &st))
538 {
539 error (f, "%s: fstat: %s", name, strerror (errno));
540 close (fd);
541 return;
542 }
543 file_base = xmalloc (st.st_size + 1);
544 if (read (fd, file_base, st.st_size) != st.st_size)
545 {
546 error (f, "%s: read: %s", name, strerror (errno));
547 close (fd);
548 free (file_base);
549 return;
550 }
551 close (fd);
552 file_end = file_base + st.st_size;
553 file_base[st.st_size] = '\0';
554
555 /* now parse the file. */
556 line_no = 1;
557 cur = file_base;
558 while (cur < file_end)
559 {
560 /* skip empty lines */
561 while (cur < file_end && isspace ((unsigned char)*cur) && *cur != '\n')
562 ++cur;
563 if (cur >= file_end)
564 break;
565 if (*cur == '#')
566 {
567 cur = memchr (cur, '\n', file_end - cur);
568 if (!cur)
569 break;
570 }
571 if (*cur == '\\')
572 {
573 unsigned eol_len = (file_end - cur > 1 && cur[1] == '\n') ? 2
574 : (file_end - cur > 2 && cur[1] == '\r' && cur[2] == '\n') ? 3
575 : (file_end - cur == 1) ? 1 : 0;
576 if (eol_len)
577 {
578 cur += eol_len;
579 line_no++;
580 continue;
581 }
582 }
583 if (*cur == '\n')
584 {
585 cur++;
586 line_no++;
587 continue;
588 }
589
590 /* define var
591 ...
592 endef */
593 if (strneq (cur, "define ", 7))
594 {
595 const char *var;
596 unsigned var_len;
597 const char *value_start;
598 const char *value_end;
599 char *value;
600 unsigned value_len;
601 int found_endef = 0;
602
603 /* extract the variable name. */
604 cur += 7;
605 while (isblank ((unsigned char)*cur))
606 ++cur;
607 value_start = endp = memchr (cur, '\n', file_end - cur);
608 if (!endp)
609 endp = cur;
610 while (endp > cur && isspace ((unsigned char)endp[-1]))
611 --endp;
612 var_len = endp - cur;
613 if (!var_len)
614 {
615 error (f, "%s(%d): bogus define statement.", name, line_no);
616 break;
617 }
618 var = strcache_add_len (cur, var_len);
619
620 /* find the end of the variable. */
621 cur = value_end = value_start = value_start + 1;
622 ++line_no;
623 while (cur < file_end)
624 {
625 /* check for endef, don't bother with skipping leading spaces. */
626 if ( file_end - cur >= 5
627 && strneq (cur, "endef", 5))
628 {
629 endp = cur + 5;
630 while (endp < file_end && isspace ((unsigned char)*endp) && *endp != '\n')
631 endp++;
632 if (endp >= file_end || *endp == '\n')
633 {
634 found_endef = 1;
635 cur = endp >= file_end ? file_end : endp + 1;
636 break;
637 }
638 }
639
640 /* skip a line ahead. */
641 cur = value_end = memchr (cur, '\n', file_end - cur);
642 if (cur != NULL)
643 ++cur;
644 else
645 cur = value_end = file_end;
646 ++line_no;
647 }
648
649 if (!found_endef)
650 {
651 error (f, "%s(%d): missing endef, dropping the rest of the file.", name, line_no);
652 break;
653 }
654 value_len = value_end - value_start;
655 if (memchr (value_start, '\0', value_len))
656 {
657 error (f, "%s(%d): '\\0' in define, dropping the rest of the file.", name, line_no);
658 break;
659 }
660
661 /* make a copy of the value, converting \r\n to \n, and define it. */
662 value = xmalloc (value_len + 1);
663 endp = memchr (value_start, '\r', value_len);
664 if (endp)
665 {
666 const char *src = value_start;
667 char *dst = value;
668 for (;;)
669 {
670 size_t len = endp - src;
671 memcpy (dst, src, len);
672 dst += len;
673 src = endp;
674 if (src + 1 < file_end && src[1] == '\n')
675 src++; /* skip the '\r' */
676 if (src >= value_end)
677 break;
678 endp = memchr (endp + 1, '\r', src - value_end);
679 if (!endp)
680 endp = value_end;
681 }
682 value_len = dst - value;
683 }
684 else
685 memcpy (value, value_start, value_len);
686 value [value_len] = '\0';
687
688 define_variable_in_set (var, var_len, value, value_len,
689 0 /* don't duplicate */, o_file,
690 0 /* defines are recursive but this is faster */,
691 NULL /* global set */, f);
692 }
693
694 /* file: deps
695 OR
696 variable [:]= value */
697 else
698 {
699 const char *colonp;
700 const char *equalp;
701
702 /* Look for a colon and an equal sign, optimize for colon.
703 Only one file is support and the colon / equal must be on
704 the same line. */
705 colonp = memchr (cur, ':', file_end - cur);
706#ifdef HAVE_DOS_PATHS
707 while ( colonp
708 && colonp + 1 < file_end
709 && (colonp[1] == '/' || colonp[1] == '\\')
710 && colonp > cur
711 && isalpha ((unsigned char)colonp[-1])
712 && ( colonp == cur + 1
713 || strchr (" \t(", colonp[-2]) != 0))
714 colonp = memchr (colonp + 1, ':', file_end - (colonp + 1));
715#endif
716 endp = NULL;
717 if ( !colonp
718 || (endp = memchr (cur, '\n', colonp - cur)))
719 {
720 colonp = NULL;
721 equalp = memchr (cur, '=', (endp ? endp : file_end) - cur);
722 if ( !equalp
723 || (!endp && memchr (cur, '\n', equalp - cur)))
724 {
725 error (f, "%s(%d): no colon.", name, line_no);
726 break;
727 }
728 }
729 else
730 equalp = memchr (cur, '=', (colonp + 2 <= file_end
731 ? colonp + 2 : file_end) - cur);
732 if (equalp)
733 {
734 /* An assignment of some sort. */
735 const char *var;
736 unsigned var_len;
737 const char *value_start;
738 const char *value_end;
739 char *value;
740 unsigned value_len;
741 unsigned multi_line = 0;
742 enum variable_flavor flavor;
743
744 /* figure the flavor first. */
745 flavor = f_recursive;
746 if (equalp > cur)
747 {
748 if (equalp[-1] == ':')
749 flavor = f_simple;
750 else if (equalp[-1] == '?')
751 flavor = f_conditional;
752 else if (equalp[-1] == '+')
753 flavor = f_append;
754 else if (equalp[-1] == '>')
755 flavor = f_prepend;
756 }
757
758 /* extract the variable name. */
759 endp = flavor == f_recursive ? equalp : equalp - 1;
760 while (endp > cur && isblank ((unsigned char)endp[-1]))
761 --endp;
762 var_len = endp - cur;
763 if (!var_len)
764 {
765 error (f, "%s(%d): empty variable. (includedep)", name, line_no);
766 break;
767 }
768 if ( memchr (cur, '$', var_len)
769 || memchr (cur, ' ', var_len)
770 || memchr (cur, '\t', var_len))
771 {
772 error (f, "%s(%d): fancy variable name. (includedep)", name, line_no);
773 break;
774 }
775 var = strcache_add_len (cur, var_len);
776
777 /* find the start of the value. */
778 cur = equalp + 1;
779 while (cur < file_end && isblank ((unsigned char)*cur))
780 cur++;
781 value_start = cur;
782
783 /* find the end of the value / line (this isn't 101% correct). */
784 value_end = cur;
785 while (cur < file_end)
786 {
787 endp = value_end = memchr (cur, '\n', file_end - cur);
788 if (!value_end)
789 value_end = file_end;
790 if (value_end - 1 >= cur && value_end[-1] == '\r')
791 --value_end;
792 if (value_end - 1 < cur || value_end[-1] != '\\')
793 {
794 cur = endp ? endp + 1 : file_end;
795 break;
796 }
797 --value_end;
798 if (value_end - 1 >= cur && value_end[-1] == '\\')
799 {
800 error (f, "%s(%d): fancy escaping! (includedep)", name, line_no);
801 cur = NULL;
802 break;
803 }
804 if (!endp)
805 {
806 cur = file_end;
807 break;
808 }
809
810 cur = endp + 1;
811 ++multi_line;
812 ++line_no;
813 }
814 if (!cur)
815 break;
816 ++line_no;
817
818 /* make a copy of the value, converting \r\n to \n, and define it. */
819 value_len = value_end - value_start;
820 value = xmalloc (value_len + 1);
821 if (!multi_line)
822 memcpy (value, value_start, value_len);
823 else
824 {
825 /* unescape it */
826 const char *src = value_start;
827 char *dst = value;
828 while (src < value_end)
829 {
830 const char *nextp;
831
832 endp = memchr (src, '\n', value_end - src);
833 if (!endp)
834 nextp = endp = value_end;
835 else
836 nextp = endp + 1;
837 if (endp > src && endp[-1] == '\r')
838 --endp;
839 if (endp > src && endp[-1] == '\\')
840 --endp;
841
842 if (src != value_start)
843 *dst++ = '\n';
844 memcpy (dst, src, endp - src);
845 dst += endp - src;
846 src = nextp;
847 }
848 value_len = dst - value;
849 }
850 value [value_len] = '\0';
851
852 /* do the definition */
853 if (flavor == f_recursive
854 || ( flavor == f_simple
855 && !memchr (value, '$', value_len)))
856 define_variable_in_set (var, var_len, value, value_len,
857 0 /* don't duplicate */, o_file,
858 flavor == f_recursive /* recursive */,
859 NULL /* global set */, f);
860 else
861 {
862 do_variable_definition (f, var, value, o_file, flavor,
863 0 /* not target var */);
864 free (value);
865 }
866 }
867 else
868 {
869 /* file: dependencies */
870
871 struct nameseq *filenames = 0;
872 struct dep *deps = 0;
873 struct dep **nextdep = &deps;
874 struct dep *dep;
875 int next_line = 1;
876
877 /* extract the filename, ASSUME a single one. */
878 endp = colonp;
879 while (endp > cur && isblank ((unsigned char)endp[-1]))
880 --endp;
881 if (cur == endp)
882 {
883 error (f, "%s(%d): empty filename.", name, line_no);
884 break;
885 }
886 if ( memchr (cur, '$', endp - cur)
887 || memchr (cur, ' ', endp - cur)
888 || memchr (cur, '\t', endp - cur))
889 {
890 error (f, "%s(%d): multiple / fancy file name. (includedep)", name, line_no);
891 break;
892 }
893 filenames = xmalloc (sizeof (struct nameseq));
894 memset (filenames, 0, sizeof (*filenames));
895 filenames->name = strcache_add_len (cur, endp - cur);
896
897 /* parse any dependencies. */
898 cur = colonp + 1;
899 while (cur < file_end)
900 {
901 /* skip blanks and count lines. */
902 while (cur < file_end && isspace ((unsigned char)*cur) && *cur != '\n')
903 ++cur;
904 if (cur >= file_end)
905 break;
906 if (*cur == '\n')
907 {
908 cur++;
909 line_no++;
910 break;
911 }
912
913 /* continuation + eol? */
914 if (*cur == '\\')
915 {
916 unsigned eol_len = (file_end - cur > 1 && cur[1] == '\n') ? 2
917 : (file_end - cur > 2 && cur[1] == '\r' && cur[2] == '\n') ? 3
918 : (file_end - cur == 1) ? 1 : 0;
919 if (eol_len)
920 {
921 cur += eol_len;
922 line_no++;
923 continue;
924 }
925 }
926
927 /* find the end of the filename */
928 endp = cur;
929 while (endp < file_end && !isspace ((unsigned char)*endp))
930 ++endp;
931
932 /* add it to the list. */
933 *nextdep = dep = alloc_dep ();
934 dep->name = strcache_add_len (cur, endp - cur);
935 nextdep = &dep->next;
936
937 cur = endp;
938 }
939
940 /* enter the file with its dependencies. */
941 record_files (filenames, NULL, NULL, deps, 0, NULL, 0, 0, f);
942 }
943 }
944 }
945 free (file_base);
946}
947#endif /* CONFIG_WITH_INCLUDEDEP */
948
949
950
951/* Read file FILENAME as a makefile and add its contents to the data base.
952
953 SET_DEFAULT is true if we are allowed to set the default goal. */
954
955
956static int
957eval (struct ebuffer *ebuf, int set_default)
958{
959 char *collapsed = 0;
960 unsigned int collapsed_length = 0;
961 unsigned int commands_len = 200;
962 char *commands;
963 unsigned int commands_idx = 0;
964 unsigned int cmds_started, tgts_started;
965 int ignoring = 0, in_ignored_define = 0;
966 int no_targets = 0; /* Set when reading a rule without targets. */
967 struct nameseq *filenames = 0;
968 struct dep *deps = 0;
969 long nlines = 0;
970 int two_colon = 0;
971 const char *pattern = 0;
972 const char *pattern_percent;
973 struct floc *fstart;
974 struct floc fi;
975
976#define record_waiting_files() \
977 do \
978 { \
979 if (filenames != 0) \
980 { \
981 fi.lineno = tgts_started; \
982 record_files (filenames, pattern, pattern_percent, deps, \
983 cmds_started, commands, commands_idx, two_colon, \
984 &fi); \
985 } \
986 filenames = 0; \
987 commands_idx = 0; \
988 no_targets = 0; \
989 pattern = 0; \
990 } while (0)
991
992 pattern_percent = 0;
993 cmds_started = tgts_started = 1;
994
995 fstart = &ebuf->floc;
996 fi.filenm = ebuf->floc.filenm;
997
998 /* Loop over lines in the file.
999 The strategy is to accumulate target names in FILENAMES, dependencies
1000 in DEPS and commands in COMMANDS. These are used to define a rule
1001 when the start of the next rule (or eof) is encountered.
1002
1003 When you see a "continue" in the loop below, that means we are moving on
1004 to the next line _without_ ending any rule that we happen to be working
1005 with at the moment. If you see a "goto rule_complete", then the
1006 statement we just parsed also finishes the previous rule. */
1007
1008 commands = xmalloc (200);
1009
1010 while (1)
1011 {
1012 unsigned int linelen;
1013 char *line;
1014 unsigned int wlen;
1015 char *p;
1016 char *p2;
1017
1018 /* Grab the next line to be evaluated */
1019 ebuf->floc.lineno += nlines;
1020 nlines = readline (ebuf);
1021
1022 /* If there is nothing left to eval, we're done. */
1023 if (nlines < 0)
1024 break;
1025
1026 /* If this line is empty, skip it. */
1027 line = ebuf->buffer;
1028 if (line[0] == '\0')
1029 continue;
1030
1031 linelen = strlen (line);
1032
1033 /* Check for a shell command line first.
1034 If it is not one, we can stop treating tab specially. */
1035 if (line[0] == cmd_prefix)
1036 {
1037 if (no_targets)
1038 /* Ignore the commands in a rule with no targets. */
1039 continue;
1040
1041 /* If there is no preceding rule line, don't treat this line
1042 as a command, even though it begins with a tab character.
1043 SunOS 4 make appears to behave this way. */
1044
1045 if (filenames != 0)
1046 {
1047 if (ignoring)
1048 /* Yep, this is a shell command, and we don't care. */
1049 continue;
1050
1051 /* Append this command line to the line being accumulated. */
1052 if (commands_idx == 0)
1053 cmds_started = ebuf->floc.lineno;
1054
1055 if (linelen + 1 + commands_idx > commands_len)
1056 {
1057 commands_len = (linelen + 1 + commands_idx) * 2;
1058 commands = xrealloc (commands, commands_len);
1059 }
1060 memcpy (&commands[commands_idx], line, linelen);
1061 commands_idx += linelen;
1062 commands[commands_idx++] = '\n';
1063
1064 continue;
1065 }
1066 }
1067
1068 /* This line is not a shell command line. Don't worry about tabs.
1069 Get more space if we need it; we don't need to preserve the current
1070 contents of the buffer. */
1071
1072 if (collapsed_length < linelen+1)
1073 {
1074 collapsed_length = linelen+1;
1075 if (collapsed)
1076 free (collapsed);
1077 collapsed = xmalloc (collapsed_length);
1078 }
1079 strcpy (collapsed, line);
1080 /* Collapse continuation lines. */
1081 collapse_continuations (collapsed);
1082 remove_comments (collapsed);
1083
1084 /* Compare a word, both length and contents. */
1085#define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
1086 p = collapsed;
1087 while (isspace ((unsigned char)*p))
1088 ++p;
1089
1090 if (*p == '\0')
1091 /* This line is completely empty--ignore it. */
1092 continue;
1093
1094 /* Find the end of the first token. Note we don't need to worry about
1095 * ":" here since we compare tokens by length (so "export" will never
1096 * be equal to "export:").
1097 */
1098 for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2)
1099 ;
1100 wlen = p2 - p;
1101
1102 /* Find the start of the second token. If it looks like a target or
1103 variable definition it can't be a preprocessor token so skip
1104 them--this allows variables/targets named `ifdef', `export', etc. */
1105 while (isspace ((unsigned char)*p2))
1106 ++p2;
1107
1108 if ((p2[0] == ':' || p2[0] == '+' || p2[0] == '=') && p2[1] == '\0')
1109 {
1110 /* It can't be a preprocessor token so skip it if we're ignoring */
1111 if (ignoring)
1112 continue;
1113
1114 goto skip_conditionals;
1115 }
1116
1117 /* We must first check for conditional and `define' directives before
1118 ignoring anything, since they control what we will do with
1119 following lines. */
1120
1121 if (!in_ignored_define)
1122 {
1123 int i = conditional_line (p, wlen, fstart);
1124 if (i != -2)
1125 {
1126 if (i == -1)
1127 fatal (fstart, _("invalid syntax in conditional"));
1128
1129 ignoring = i;
1130 continue;
1131 }
1132 }
1133
1134 if (word1eq ("endef"))
1135 {
1136 if (!in_ignored_define)
1137 fatal (fstart, _("extraneous `endef'"));
1138 in_ignored_define = 0;
1139 continue;
1140 }
1141
1142 if (word1eq ("define"))
1143 {
1144 if (ignoring)
1145 in_ignored_define = 1;
1146 else
1147 {
1148 if (*p2 == '\0')
1149 fatal (fstart, _("empty variable name"));
1150
1151 /* Let the variable name be the whole rest of the line,
1152 with trailing blanks stripped (comments have already been
1153 removed), so it could be a complex variable/function
1154 reference that might contain blanks. */
1155 p = strchr (p2, '\0');
1156 while (isblank ((unsigned char)p[-1]))
1157 --p;
1158 do_define (p2, p - p2, o_file, ebuf);
1159 }
1160 continue;
1161 }
1162
1163 if (word1eq ("override"))
1164 {
1165 if (*p2 == '\0')
1166 error (fstart, _("empty `override' directive"));
1167
1168 if (strneq (p2, "define", 6)
1169 && (isblank ((unsigned char)p2[6]) || p2[6] == '\0'))
1170 {
1171 if (ignoring)
1172 in_ignored_define = 1;
1173 else
1174 {
1175 p2 = next_token (p2 + 6);
1176 if (*p2 == '\0')
1177 fatal (fstart, _("empty variable name"));
1178
1179 /* Let the variable name be the whole rest of the line,
1180 with trailing blanks stripped (comments have already been
1181 removed), so it could be a complex variable/function
1182 reference that might contain blanks. */
1183 p = strchr (p2, '\0');
1184 while (isblank ((unsigned char)p[-1]))
1185 --p;
1186 do_define (p2, p - p2, o_override, ebuf);
1187 }
1188 }
1189 else if (!ignoring
1190 && !try_variable_definition (fstart, p2, o_override, 0))
1191 error (fstart, _("invalid `override' directive"));
1192
1193 continue;
1194 }
1195#ifdef CONFIG_WITH_LOCAL_VARIABLES
1196
1197 if (word1eq ("local"))
1198 {
1199 if (*p2 == '\0')
1200 error (fstart, _("empty `local' directive"));
1201
1202 if (strneq (p2, "define", 6)
1203 && (isblank ((unsigned char)p2[6]) || p2[6] == '\0'))
1204 {
1205 if (ignoring)
1206 in_ignored_define = 1;
1207 else
1208 {
1209 p2 = next_token (p2 + 6);
1210 if (*p2 == '\0')
1211 fatal (fstart, _("empty variable name"));
1212
1213 /* Let the variable name be the whole rest of the line,
1214 with trailing blanks stripped (comments have already been
1215 removed), so it could be a complex variable/function
1216 reference that might contain blanks. */
1217 p = strchr (p2, '\0');
1218 while (isblank ((unsigned char)p[-1]))
1219 --p;
1220 do_define (p2, p - p2, o_local, ebuf);
1221 }
1222 }
1223 else if (!ignoring
1224 && !try_variable_definition (fstart, p2, o_local, 0))
1225 error (fstart, _("invalid `local' directive"));
1226
1227 continue;
1228 }
1229#endif /* CONFIG_WITH_LOCAL_VARIABLES */
1230
1231 if (ignoring)
1232 /* Ignore the line. We continue here so conditionals
1233 can appear in the middle of a rule. */
1234 continue;
1235
1236 if (word1eq ("export"))
1237 {
1238 /* 'export' by itself causes everything to be exported. */
1239 if (*p2 == '\0')
1240 export_all_variables = 1;
1241 else
1242 {
1243 struct variable *v;
1244
1245 v = try_variable_definition (fstart, p2, o_file, 0);
1246 if (v != 0)
1247 v->export = v_export;
1248 else
1249 {
1250 unsigned int l;
1251 const char *cp;
1252 char *ap;
1253
1254 /* Expand the line so we can use indirect and constructed
1255 variable names in an export command. */
1256 cp = ap = allocated_variable_expand (p2);
1257
1258 for (p = find_next_token (&cp, &l); p != 0;
1259 p = find_next_token (&cp, &l))
1260 {
1261 v = lookup_variable (p, l);
1262 if (v == 0)
1263 v = define_variable_loc (p, l, "", o_file, 0, fstart);
1264 v->export = v_export;
1265 }
1266
1267 free (ap);
1268 }
1269 }
1270 goto rule_complete;
1271 }
1272
1273 if (word1eq ("unexport"))
1274 {
1275 if (*p2 == '\0')
1276 export_all_variables = 0;
1277 else
1278 {
1279 unsigned int l;
1280 struct variable *v;
1281 const char *cp;
1282 char *ap;
1283
1284 /* Expand the line so we can use indirect and constructed
1285 variable names in an unexport command. */
1286 cp = ap = allocated_variable_expand (p2);
1287
1288 for (p = find_next_token (&cp, &l); p != 0;
1289 p = find_next_token (&cp, &l))
1290 {
1291 v = lookup_variable (p, l);
1292 if (v == 0)
1293 v = define_variable_loc (p, l, "", o_file, 0, fstart);
1294
1295 v->export = v_noexport;
1296 }
1297
1298 free (ap);
1299 }
1300 goto rule_complete;
1301 }
1302
1303 skip_conditionals:
1304 if (word1eq ("vpath"))
1305 {
1306 const char *cp;
1307 char *vpat;
1308 unsigned int l;
1309 cp = variable_expand (p2);
1310 p = find_next_token (&cp, &l);
1311 if (p != 0)
1312 {
1313 vpat = savestring (p, l);
1314 p = find_next_token (&cp, &l);
1315 /* No searchpath means remove all previous
1316 selective VPATH's with the same pattern. */
1317 }
1318 else
1319 /* No pattern means remove all previous selective VPATH's. */
1320 vpat = 0;
1321 construct_vpath_list (vpat, p);
1322 if (vpat != 0)
1323 free (vpat);
1324
1325 goto rule_complete;
1326 }
1327
1328#ifdef CONFIG_WITH_INCLUDEDEP
1329 if (word1eq ("includedep"))
1330 {
1331 /* We have found an `includedep' line specifying a single makefile
1332 to be read at this point. This include variation does no
1333 globbing and do not support multiple names. It's trying to save
1334 time by being dead simple as well as ignoring errors. */
1335 char *free_me = NULL;
1336 char *name = p2;
1337 char *end = strchr (name, '\0');
1338 char saved;
1339 if (memchr (name, '$', end - name))
1340 {
1341 free_me = name = allocated_variable_expand (name);
1342 while (isspace ((unsigned char)*name))
1343 ++name;
1344 end = strchr (name, '\0');
1345 }
1346
1347 while (end > name && isspace ((unsigned char)end[-1]))
1348 --end;
1349
1350 saved = *end; /* not sure if this is required... */
1351 *end = '\0';
1352 eval_include_dep (name, fstart);
1353 *end = saved;
1354
1355 if (free_me)
1356 free (free_me);
1357 goto rule_complete;
1358 }
1359#endif /* CONFIG_WITH_INCLUDEDEP */
1360
1361 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
1362 {
1363 /* We have found an `include' line specifying a nested
1364 makefile to be read at this point. */
1365 struct conditionals *save;
1366 struct conditionals new_conditionals;
1367 struct nameseq *files;
1368 /* "-include" (vs "include") says no error if the file does not
1369 exist. "sinclude" is an alias for this from SGI. */
1370 int noerror = (p[0] != 'i');
1371
1372 p = allocated_variable_expand (p2);
1373
1374 /* If no filenames, it's a no-op. */
1375 if (*p == '\0')
1376 {
1377 free (p);
1378 continue;
1379 }
1380
1381 /* Parse the list of file names. */
1382 p2 = p;
1383 files = multi_glob (parse_file_seq (&p2, '\0',
1384 sizeof (struct nameseq),
1385 1),
1386 sizeof (struct nameseq));
1387 free (p);
1388
1389 /* Save the state of conditionals and start
1390 the included makefile with a clean slate. */
1391 save = install_conditionals (&new_conditionals);
1392
1393 /* Record the rules that are waiting so they will determine
1394 the default goal before those in the included makefile. */
1395 record_waiting_files ();
1396
1397 /* Read each included makefile. */
1398 while (files != 0)
1399 {
1400 struct nameseq *next = files->next;
1401 const char *name = files->name;
1402 int r;
1403
1404 free (files);
1405 files = next;
1406
1407 r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE
1408 | (noerror ? RM_DONTCARE : 0)));
1409 if (!r && !noerror)
1410 error (fstart, "%s: %s", name, strerror (errno));
1411 }
1412
1413 /* Restore conditional state. */
1414 restore_conditionals (save);
1415
1416 goto rule_complete;
1417 }
1418
1419 if (try_variable_definition (fstart, p, o_file, 0))
1420 /* This line has been dealt with. */
1421 goto rule_complete;
1422
1423 /* This line starts with a tab but was not caught above because there
1424 was no preceding target, and the line might have been usable as a
1425 variable definition. But now we know it is definitely lossage. */
1426 if (line[0] == cmd_prefix)
1427 fatal(fstart, _("commands commence before first target"));
1428
1429 /* This line describes some target files. This is complicated by
1430 the existence of target-specific variables, because we can't
1431 expand the entire line until we know if we have one or not. So
1432 we expand the line word by word until we find the first `:',
1433 then check to see if it's a target-specific variable.
1434
1435 In this algorithm, `lb_next' will point to the beginning of the
1436 unexpanded parts of the input buffer, while `p2' points to the
1437 parts of the expanded buffer we haven't searched yet. */
1438
1439 {
1440 enum make_word_type wtype;
1441 enum variable_origin v_origin;
1442 int exported;
1443 char *cmdleft, *semip, *lb_next;
1444 unsigned int plen = 0;
1445 char *colonp;
1446 const char *end, *beg; /* Helpers for whitespace stripping. */
1447
1448 /* Record the previous rule. */
1449
1450 record_waiting_files ();
1451 tgts_started = fstart->lineno;
1452
1453 /* Search the line for an unquoted ; that is not after an
1454 unquoted #. */
1455 cmdleft = find_char_unquote (line, ';', '#', 0, 1);
1456 if (cmdleft != 0 && *cmdleft == '#')
1457 {
1458 /* We found a comment before a semicolon. */
1459 *cmdleft = '\0';
1460 cmdleft = 0;
1461 }
1462 else if (cmdleft != 0)
1463 /* Found one. Cut the line short there before expanding it. */
1464 *(cmdleft++) = '\0';
1465 semip = cmdleft;
1466
1467 collapse_continuations (line);
1468
1469 /* We can't expand the entire line, since if it's a per-target
1470 variable we don't want to expand it. So, walk from the
1471 beginning, expanding as we go, and looking for "interesting"
1472 chars. The first word is always expandable. */
1473 wtype = get_next_mword(line, NULL, &lb_next, &wlen);
1474 switch (wtype)
1475 {
1476 case w_eol:
1477 if (cmdleft != 0)
1478 fatal(fstart, _("missing rule before commands"));
1479 /* This line contained something but turned out to be nothing
1480 but whitespace (a comment?). */
1481 continue;
1482
1483 case w_colon:
1484 case w_dcolon:
1485 /* We accept and ignore rules without targets for
1486 compatibility with SunOS 4 make. */
1487 no_targets = 1;
1488 continue;
1489
1490 default:
1491 break;
1492 }
1493
1494 p2 = variable_expand_string(NULL, lb_next, wlen);
1495
1496 while (1)
1497 {
1498 lb_next += wlen;
1499 if (cmdleft == 0)
1500 {
1501 /* Look for a semicolon in the expanded line. */
1502 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
1503
1504 if (cmdleft != 0)
1505 {
1506 unsigned long p2_off = p2 - variable_buffer;
1507 unsigned long cmd_off = cmdleft - variable_buffer;
1508 char *pend = p2 + strlen(p2);
1509
1510 /* Append any remnants of lb, then cut the line short
1511 at the semicolon. */
1512 *cmdleft = '\0';
1513
1514 /* One school of thought says that you shouldn't expand
1515 here, but merely copy, since now you're beyond a ";"
1516 and into a command script. However, the old parser
1517 expanded the whole line, so we continue that for
1518 backwards-compatiblity. Also, it wouldn't be
1519 entirely consistent, since we do an unconditional
1520 expand below once we know we don't have a
1521 target-specific variable. */
1522 (void)variable_expand_string(pend, lb_next, (long)-1);
1523 lb_next += strlen(lb_next);
1524 p2 = variable_buffer + p2_off;
1525 cmdleft = variable_buffer + cmd_off + 1;
1526 }
1527 }
1528
1529 colonp = find_char_unquote(p2, ':', 0, 0, 0);
1530#ifdef HAVE_DOS_PATHS
1531 /* The drive spec brain-damage strikes again... */
1532 /* Note that the only separators of targets in this context
1533 are whitespace and a left paren. If others are possible,
1534 they should be added to the string in the call to index. */
1535 while (colonp && (colonp[1] == '/' || colonp[1] == '\\') &&
1536 colonp > p2 && isalpha ((unsigned char)colonp[-1]) &&
1537 (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
1538 colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0);
1539#endif
1540 if (colonp != 0)
1541 break;
1542
1543 wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen);
1544 if (wtype == w_eol)
1545 break;
1546
1547 p2 += strlen(p2);
1548 *(p2++) = ' ';
1549 p2 = variable_expand_string(p2, lb_next, wlen);
1550 /* We don't need to worry about cmdleft here, because if it was
1551 found in the variable_buffer the entire buffer has already
1552 been expanded... we'll never get here. */
1553 }
1554
1555 p2 = next_token (variable_buffer);
1556
1557 /* If the word we're looking at is EOL, see if there's _anything_
1558 on the line. If not, a variable expanded to nothing, so ignore
1559 it. If so, we can't parse this line so punt. */
1560 if (wtype == w_eol)
1561 {
1562 if (*p2 != '\0')
1563 /* There's no need to be ivory-tower about this: check for
1564 one of the most common bugs found in makefiles... */
1565 fatal (fstart, _("missing separator%s"),
1566 !strneq(line, " ", 8) ? ""
1567 : _(" (did you mean TAB instead of 8 spaces?)"));
1568 continue;
1569 }
1570
1571 /* Make the colon the end-of-string so we know where to stop
1572 looking for targets. */
1573 *colonp = '\0';
1574 filenames = multi_glob (parse_file_seq (&p2, '\0',
1575 sizeof (struct nameseq),
1576 1),
1577 sizeof (struct nameseq));
1578 *p2 = ':';
1579
1580 if (!filenames)
1581 {
1582 /* We accept and ignore rules without targets for
1583 compatibility with SunOS 4 make. */
1584 no_targets = 1;
1585 continue;
1586 }
1587 /* This should never be possible; we handled it above. */
1588 assert (*p2 != '\0');
1589 ++p2;
1590
1591 /* Is this a one-colon or two-colon entry? */
1592 two_colon = *p2 == ':';
1593 if (two_colon)
1594 p2++;
1595
1596 /* Test to see if it's a target-specific variable. Copy the rest
1597 of the buffer over, possibly temporarily (we'll expand it later
1598 if it's not a target-specific variable). PLEN saves the length
1599 of the unparsed section of p2, for later. */
1600 if (*lb_next != '\0')
1601 {
1602 unsigned int l = p2 - variable_buffer;
1603 plen = strlen (p2);
1604 variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1);
1605 p2 = variable_buffer + l;
1606 }
1607
1608 /* See if it's an "override" or "export" keyword; if so see if what
1609 comes after it looks like a variable definition. */
1610
1611 wtype = get_next_mword (p2, NULL, &p, &wlen);
1612
1613 v_origin = o_file;
1614 exported = 0;
1615 if (wtype == w_static)
1616 {
1617 if (word1eq ("override"))
1618 {
1619 v_origin = o_override;
1620 wtype = get_next_mword (p+wlen, NULL, &p, &wlen);
1621 }
1622 else if (word1eq ("export"))
1623 {
1624 exported = 1;
1625 wtype = get_next_mword (p+wlen, NULL, &p, &wlen);
1626 }
1627 }
1628
1629 if (wtype != w_eol)
1630 wtype = get_next_mword (p+wlen, NULL, NULL, NULL);
1631
1632 if (wtype == w_varassign)
1633 {
1634 /* If there was a semicolon found, add it back, plus anything
1635 after it. */
1636 if (semip)
1637 {
1638 unsigned int l = p - variable_buffer;
1639 *(--semip) = ';';
1640 variable_buffer_output (p2 + strlen (p2),
1641 semip, strlen (semip)+1);
1642 p = variable_buffer + l;
1643 }
1644 record_target_var (filenames, p, v_origin, exported, fstart);
1645 filenames = 0;
1646 continue;
1647 }
1648
1649 /* This is a normal target, _not_ a target-specific variable.
1650 Unquote any = in the dependency list. */
1651 find_char_unquote (lb_next, '=', 0, 0, 0);
1652
1653 /* We have some targets, so don't ignore the following commands. */
1654 no_targets = 0;
1655
1656 /* Expand the dependencies, etc. */
1657 if (*lb_next != '\0')
1658 {
1659 unsigned int l = p2 - variable_buffer;
1660 (void) variable_expand_string (p2 + plen, lb_next, (long)-1);
1661 p2 = variable_buffer + l;
1662
1663 /* Look for a semicolon in the expanded line. */
1664 if (cmdleft == 0)
1665 {
1666 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
1667 if (cmdleft != 0)
1668 *(cmdleft++) = '\0';
1669 }
1670 }
1671
1672 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
1673 p = strchr (p2, ':');
1674 while (p != 0 && p[-1] == '\\')
1675 {
1676 register char *q = &p[-1];
1677 register int backslash = 0;
1678 while (*q-- == '\\')
1679 backslash = !backslash;
1680 if (backslash)
1681 p = strchr (p + 1, ':');
1682 else
1683 break;
1684 }
1685#ifdef _AMIGA
1686 /* Here, the situation is quite complicated. Let's have a look
1687 at a couple of targets:
1688
1689 install: dev:make
1690
1691 dev:make: make
1692
1693 dev:make:: xyz
1694
1695 The rule is that it's only a target, if there are TWO :'s
1696 OR a space around the :.
1697 */
1698 if (p && !(isspace ((unsigned char)p[1]) || !p[1]
1699 || isspace ((unsigned char)p[-1])))
1700 p = 0;
1701#endif
1702#ifdef HAVE_DOS_PATHS
1703 {
1704 int check_again;
1705 do {
1706 check_again = 0;
1707 /* For DOS-style paths, skip a "C:\..." or a "C:/..." */
1708 if (p != 0 && (p[1] == '\\' || p[1] == '/') &&
1709 isalpha ((unsigned char)p[-1]) &&
1710 (p == p2 + 1 || strchr (" \t:(", p[-2]) != 0)) {
1711 p = strchr (p + 1, ':');
1712 check_again = 1;
1713 }
1714 } while (check_again);
1715 }
1716#endif
1717 if (p != 0)
1718 {
1719 struct nameseq *target;
1720 target = parse_file_seq (&p2, ':', sizeof (struct nameseq), 1);
1721 ++p2;
1722 if (target == 0)
1723 fatal (fstart, _("missing target pattern"));
1724 else if (target->next != 0)
1725 fatal (fstart, _("multiple target patterns (target `%s')"), target->name); /* bird */
1726 pattern_percent = find_percent_cached (&target->name);
1727 pattern = target->name;
1728 if (pattern_percent == 0)
1729 fatal (fstart, _("target pattern contains no `%%' (target `%s')"), target->name); /* bird */
1730 free (target);
1731 }
1732 else
1733 pattern = 0;
1734
1735 /* Strip leading and trailing whitespaces. */
1736 beg = p2;
1737 end = beg + strlen (beg) - 1;
1738 strip_whitespace (&beg, &end);
1739
1740 if (beg <= end && *beg != '\0')
1741 {
1742 /* Put all the prerequisites here; they'll be parsed later. */
1743 deps = alloc_dep ();
1744 deps->name = strcache_add_len (beg, end - beg + 1);
1745 }
1746 else
1747 deps = 0;
1748
1749 commands_idx = 0;
1750 if (cmdleft != 0)
1751 {
1752 /* Semicolon means rest of line is a command. */
1753 unsigned int l = strlen (cmdleft);
1754
1755 cmds_started = fstart->lineno;
1756
1757 /* Add this command line to the buffer. */
1758 if (l + 2 > commands_len)
1759 {
1760 commands_len = (l + 2) * 2;
1761 commands = xrealloc (commands, commands_len);
1762 }
1763 memcpy (commands, cmdleft, l);
1764 commands_idx += l;
1765 commands[commands_idx++] = '\n';
1766 }
1767
1768 /* Determine if this target should be made default. We used to do
1769 this in record_files() but because of the delayed target recording
1770 and because preprocessor directives are legal in target's commands
1771 it is too late. Consider this fragment for example:
1772
1773 foo:
1774
1775 ifeq ($(.DEFAULT_GOAL),foo)
1776 ...
1777 endif
1778
1779 Because the target is not recorded until after ifeq directive is
1780 evaluated the .DEFAULT_GOAL does not contain foo yet as one
1781 would expect. Because of this we have to move some of the logic
1782 here. */
1783
1784 if (**default_goal_name == '\0' && set_default)
1785 {
1786 const char *name;
1787 struct dep *d;
1788 struct nameseq *t = filenames;
1789
1790 for (; t != 0; t = t->next)
1791 {
1792 int reject = 0;
1793 name = t->name;
1794
1795 /* We have nothing to do if this is an implicit rule. */
1796 if (strchr (name, '%') != 0)
1797 break;
1798
1799 /* See if this target's name does not start with a `.',
1800 unless it contains a slash. */
1801 if (*name == '.' && strchr (name, '/') == 0
1802#ifdef HAVE_DOS_PATHS
1803 && strchr (name, '\\') == 0
1804#endif
1805 )
1806 continue;
1807
1808
1809 /* If this file is a suffix, don't let it be
1810 the default goal file. */
1811 for (d = suffix_file->deps; d != 0; d = d->next)
1812 {
1813 register struct dep *d2;
1814 if (*dep_name (d) != '.' && streq (name, dep_name (d)))
1815 {
1816 reject = 1;
1817 break;
1818 }
1819 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
1820 {
1821 unsigned int l = strlen (dep_name (d2));
1822 if (!strneq (name, dep_name (d2), l))
1823 continue;
1824 if (streq (name + l, dep_name (d)))
1825 {
1826 reject = 1;
1827 break;
1828 }
1829 }
1830
1831 if (reject)
1832 break;
1833 }
1834
1835 if (!reject)
1836 {
1837 define_variable_global (".DEFAULT_GOAL", 13, t->name,
1838 o_file, 0, NILF);
1839 break;
1840 }
1841 }
1842 }
1843
1844 continue;
1845 }
1846
1847 /* We get here except in the case that we just read a rule line.
1848 Record now the last rule we read, so following spurious
1849 commands are properly diagnosed. */
1850 rule_complete:
1851 record_waiting_files ();
1852 }
1853
1854#undef word1eq
1855
1856 if (conditionals->if_cmds)
1857 fatal (fstart, _("missing `endif'"));
1858
1859 /* At eof, record the last rule. */
1860 record_waiting_files ();
1861
1862 if (collapsed)
1863 free (collapsed);
1864 free (commands);
1865
1866 return 1;
1867}
1868
1869
1870
1871/* Remove comments from LINE.
1872 This is done by copying the text at LINE onto itself. */
1873
1874static void
1875remove_comments (char *line)
1876{
1877 char *comment;
1878
1879 comment = find_char_unquote (line, '#', 0, 0, 0);
1880
1881 if (comment != 0)
1882 /* Cut off the line at the #. */
1883 *comment = '\0';
1884}
1885
1886/* Execute a `define' directive.
1887 The first line has already been read, and NAME is the name of
1888 the variable to be defined. The following lines remain to be read. */
1889
1890static void
1891do_define (char *name, unsigned int namelen,
1892 enum variable_origin origin, struct ebuffer *ebuf)
1893{
1894 struct floc defstart;
1895 long nlines = 0;
1896 int nlevels = 1;
1897 unsigned int length = 100;
1898 char *definition = xmalloc (length);
1899 unsigned int idx = 0;
1900 char *p;
1901
1902 /* Expand the variable name. */
1903 char *var = alloca (namelen + 1);
1904 memcpy (var, name, namelen);
1905 var[namelen] = '\0';
1906 var = variable_expand (var);
1907
1908 defstart = ebuf->floc;
1909
1910 while (1)
1911 {
1912 unsigned int len;
1913 char *line;
1914
1915 nlines = readline (ebuf);
1916 ebuf->floc.lineno += nlines;
1917
1918 /* If there is nothing left to eval, we're done. */
1919 if (nlines < 0)
1920 break;
1921
1922 line = ebuf->buffer;
1923
1924 collapse_continuations (line);
1925
1926 /* If the line doesn't begin with a tab, test to see if it introduces
1927 another define, or ends one. */
1928
1929 /* Stop if we find an 'endef' */
1930 if (line[0] != cmd_prefix)
1931 {
1932 p = next_token (line);
1933 len = strlen (p);
1934
1935 /* If this is another 'define', increment the level count. */
1936 if ((len == 6 || (len > 6 && isblank ((unsigned char)p[6])))
1937 && strneq (p, "define", 6))
1938 ++nlevels;
1939
1940 /* If this is an 'endef', decrement the count. If it's now 0,
1941 we've found the last one. */
1942 else if ((len == 5 || (len > 5 && isblank ((unsigned char)p[5])))
1943 && strneq (p, "endef", 5))
1944 {
1945 p += 5;
1946 remove_comments (p);
1947 if (*next_token (p) != '\0')
1948 error (&ebuf->floc,
1949 _("Extraneous text after `endef' directive"));
1950
1951 if (--nlevels == 0)
1952 {
1953 /* Define the variable. */
1954 if (idx == 0)
1955 definition[0] = '\0';
1956 else
1957 definition[idx - 1] = '\0';
1958
1959 /* Always define these variables in the global set. */
1960 define_variable_global (var, strlen (var), definition,
1961 origin, 1, &defstart);
1962 free (definition);
1963 return;
1964 }
1965 }
1966 }
1967
1968 /* Otherwise add this line to the variable definition. */
1969 len = strlen (line);
1970 if (idx + len + 1 > length)
1971 {
1972 length = (idx + len) * 2;
1973 definition = xrealloc (definition, length + 1);
1974 }
1975
1976 memcpy (&definition[idx], line, len);
1977 idx += len;
1978 /* Separate lines with a newline. */
1979 definition[idx++] = '\n';
1980 }
1981
1982 /* No `endef'!! */
1983 fatal (&defstart, _("missing `endef', unterminated `define'"));
1984
1985 /* NOTREACHED */
1986 return;
1987}
1988
1989
1990/* Interpret conditional commands "ifdef", "ifndef", "ifeq",
1991 "ifneq", "if1of", "ifn1of", "else" and "endif".
1992 LINE is the input line, with the command as its first word.
1993
1994 FILENAME and LINENO are the filename and line number in the
1995 current makefile. They are used for error messages.
1996
1997 Value is -2 if the line is not a conditional at all,
1998 -1 if the line is an invalid conditional,
1999 0 if following text should be interpreted,
2000 1 if following text should be ignored. */
2001
2002static int
2003conditional_line (char *line, int len, const struct floc *flocp)
2004{
2005 char *cmdname;
2006 enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq,
2007#ifdef CONFIG_WITH_SET_CONDITIONALS
2008 c_if1of, c_ifn1of,
2009#endif
2010#ifdef CONFIG_WITH_IF_CONDITIONALS
2011 c_ifcond,
2012#endif
2013 c_else, c_endif
2014 } cmdtype;
2015 unsigned int i;
2016 unsigned int o;
2017
2018 /* Compare a word, both length and contents. */
2019#define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
2020#define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
2021
2022 /* Make sure this line is a conditional. */
2023 chkword ("ifdef", c_ifdef)
2024 else chkword ("ifndef", c_ifndef)
2025 else chkword ("ifeq", c_ifeq)
2026 else chkword ("ifneq", c_ifneq)
2027#ifdef CONFIG_WITH_SET_CONDITIONALS
2028 else chkword ("if1of", c_if1of)
2029 else chkword ("ifn1of", c_ifn1of)
2030#endif
2031#ifdef CONFIG_WITH_IF_CONDITIONALS
2032 else chkword ("if", c_ifcond)
2033#endif
2034 else chkword ("else", c_else)
2035 else chkword ("endif", c_endif)
2036 else
2037 return -2;
2038
2039 /* Found one: skip past it and any whitespace after it. */
2040 line = next_token (line + len);
2041
2042#define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
2043
2044 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
2045 if (cmdtype == c_endif)
2046 {
2047 if (*line != '\0')
2048 EXTRANEOUS ();
2049
2050 if (!conditionals->if_cmds)
2051 fatal (flocp, _("extraneous `%s'"), cmdname);
2052
2053 --conditionals->if_cmds;
2054
2055 goto DONE;
2056 }
2057
2058 /* An 'else' statement can either be simple, or it can have another
2059 conditional after it. */
2060 if (cmdtype == c_else)
2061 {
2062 const char *p;
2063
2064 if (!conditionals->if_cmds)
2065 fatal (flocp, _("extraneous `%s'"), cmdname);
2066
2067 o = conditionals->if_cmds - 1;
2068
2069 if (conditionals->seen_else[o])
2070 fatal (flocp, _("only one `else' per conditional"));
2071
2072 /* Change the state of ignorance. */
2073 switch (conditionals->ignoring[o])
2074 {
2075 case 0:
2076 /* We've just been interpreting. Never do it again. */
2077 conditionals->ignoring[o] = 2;
2078 break;
2079 case 1:
2080 /* We've never interpreted yet. Maybe this time! */
2081 conditionals->ignoring[o] = 0;
2082 break;
2083 }
2084
2085 /* It's a simple 'else'. */
2086 if (*line == '\0')
2087 {
2088 conditionals->seen_else[o] = 1;
2089 goto DONE;
2090 }
2091
2092 /* The 'else' has extra text. That text must be another conditional
2093 and cannot be an 'else' or 'endif'. */
2094
2095 /* Find the length of the next word. */
2096 for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)
2097 ;
2098 len = p - line;
2099
2100 /* If it's 'else' or 'endif' or an illegal conditional, fail. */
2101 if (word1eq("else") || word1eq("endif")
2102 || conditional_line (line, len, flocp) < 0)
2103 EXTRANEOUS ();
2104 else
2105 {
2106 /* conditional_line() created a new level of conditional.
2107 Raise it back to this level. */
2108 if (conditionals->ignoring[o] < 2)
2109 conditionals->ignoring[o] = conditionals->ignoring[o+1];
2110 --conditionals->if_cmds;
2111 }
2112
2113 goto DONE;
2114 }
2115
2116 if (conditionals->allocated == 0)
2117 {
2118 conditionals->allocated = 5;
2119 conditionals->ignoring = xmalloc (conditionals->allocated);
2120 conditionals->seen_else = xmalloc (conditionals->allocated);
2121 }
2122
2123 o = conditionals->if_cmds++;
2124 if (conditionals->if_cmds > conditionals->allocated)
2125 {
2126 conditionals->allocated += 5;
2127 conditionals->ignoring = xrealloc (conditionals->ignoring,
2128 conditionals->allocated);
2129 conditionals->seen_else = xrealloc (conditionals->seen_else,
2130 conditionals->allocated);
2131 }
2132
2133 /* Record that we have seen an `if...' but no `else' so far. */
2134 conditionals->seen_else[o] = 0;
2135
2136 /* Search through the stack to see if we're already ignoring. */
2137 for (i = 0; i < o; ++i)
2138 if (conditionals->ignoring[i])
2139 {
2140 /* We are already ignoring, so just push a level to match the next
2141 "else" or "endif", and keep ignoring. We don't want to expand
2142 variables in the condition. */
2143 conditionals->ignoring[o] = 1;
2144 return 1;
2145 }
2146
2147 if (cmdtype == c_ifdef || cmdtype == c_ifndef)
2148 {
2149 char *var;
2150 struct variable *v;
2151 char *p;
2152
2153 /* Expand the thing we're looking up, so we can use indirect and
2154 constructed variable names. */
2155 var = allocated_variable_expand (line);
2156
2157 /* Make sure there's only one variable name to test. */
2158 p = end_of_token (var);
2159 i = p - var;
2160 p = next_token (p);
2161 if (*p != '\0')
2162 return -1;
2163
2164 var[i] = '\0';
2165 v = lookup_variable (var, i);
2166
2167 conditionals->ignoring[o] =
2168 ((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef));
2169
2170 free (var);
2171 }
2172#ifdef CONFIG_WITH_IF_CONDITIONALS
2173 else if (cmdtype == c_ifcond)
2174 {
2175 int rval = ifcond (line, flocp);
2176 if (rval == -1)
2177 return rval;
2178 conditionals->ignoring[o] = rval;
2179 }
2180#endif
2181 else
2182 {
2183#ifdef CONFIG_WITH_SET_CONDITIONALS
2184 /* "ifeq", "ifneq", "if1of" or "ifn1of". */
2185#else
2186 /* "ifeq" or "ifneq". */
2187#endif
2188 char *s1, *s2;
2189 unsigned int l;
2190 char termin = *line == '(' ? ',' : *line;
2191
2192 if (termin != ',' && termin != '"' && termin != '\'')
2193 return -1;
2194
2195 s1 = ++line;
2196 /* Find the end of the first string. */
2197 if (termin == ',')
2198 {
2199 int count = 0;
2200 for (; *line != '\0'; ++line)
2201 if (*line == '(')
2202 ++count;
2203 else if (*line == ')')
2204 --count;
2205 else if (*line == ',' && count <= 0)
2206 break;
2207 }
2208 else
2209 while (*line != '\0' && *line != termin)
2210 ++line;
2211
2212 if (*line == '\0')
2213 return -1;
2214
2215 if (termin == ',')
2216 {
2217 /* Strip blanks after the first string. */
2218 char *p = line++;
2219 while (isblank ((unsigned char)p[-1]))
2220 --p;
2221 *p = '\0';
2222 }
2223 else
2224 *line++ = '\0';
2225
2226 s2 = variable_expand (s1);
2227 /* We must allocate a new copy of the expanded string because
2228 variable_expand re-uses the same buffer. */
2229 l = strlen (s2);
2230 s1 = alloca (l + 1);
2231 memcpy (s1, s2, l + 1);
2232
2233 if (termin != ',')
2234 /* Find the start of the second string. */
2235 line = next_token (line);
2236
2237 termin = termin == ',' ? ')' : *line;
2238 if (termin != ')' && termin != '"' && termin != '\'')
2239 return -1;
2240
2241 /* Find the end of the second string. */
2242 if (termin == ')')
2243 {
2244 int count = 0;
2245 s2 = next_token (line);
2246 for (line = s2; *line != '\0'; ++line)
2247 {
2248 if (*line == '(')
2249 ++count;
2250 else if (*line == ')')
2251 {
2252 if (count <= 0)
2253 break;
2254 else
2255 --count;
2256 }
2257 }
2258 }
2259 else
2260 {
2261 ++line;
2262 s2 = line;
2263 while (*line != '\0' && *line != termin)
2264 ++line;
2265 }
2266
2267 if (*line == '\0')
2268 return -1;
2269
2270 *line = '\0';
2271 line = next_token (++line);
2272 if (*line != '\0')
2273 EXTRANEOUS ();
2274
2275 s2 = variable_expand (s2);
2276#ifdef CONFIG_WITH_SET_CONDITIONALS
2277 if (cmdtype == c_if1of || cmdtype == c_ifn1of)
2278 {
2279 const char *s1_cur;
2280 unsigned int s1_len;
2281 const char *s1_iterator = s1;
2282
2283 conditionals->ignoring[o] = (cmdtype == c_if1of); /* if not found */
2284 while ((s1_cur = find_next_token (&s1_iterator, &s1_len)) != 0)
2285 {
2286 const char *s2_cur;
2287 unsigned int s2_len;
2288 const char *s2_iterator = s2;
2289 while ((s2_cur = find_next_token (&s2_iterator, &s2_len)) != 0)
2290 if (s2_len == s1_len
2291 && strneq (s2_cur, s1_cur, s1_len) )
2292 {
2293 conditionals->ignoring[o] = (cmdtype != c_if1of); /* found */
2294 break;
2295 }
2296 }
2297 }
2298 else
2299 conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
2300#else
2301 conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
2302#endif
2303 }
2304
2305 DONE:
2306 /* Search through the stack to see if we're ignoring. */
2307 for (i = 0; i < conditionals->if_cmds; ++i)
2308 if (conditionals->ignoring[i])
2309 return 1;
2310 return 0;
2311}
2312
2313
2314/* Remove duplicate dependencies in CHAIN. */
2315
2316static unsigned long
2317dep_hash_1 (const void *key)
2318{
2319 return_STRING_HASH_1 (dep_name ((struct dep const *) key));
2320}
2321
2322static unsigned long
2323dep_hash_2 (const void *key)
2324{
2325 return_STRING_HASH_2 (dep_name ((struct dep const *) key));
2326}
2327
2328static int
2329dep_hash_cmp (const void *x, const void *y)
2330{
2331 struct dep *dx = (struct dep *) x;
2332 struct dep *dy = (struct dep *) y;
2333 int cmp = strcmp (dep_name (dx), dep_name (dy));
2334
2335 /* If the names are the same but ignore_mtimes are not equal, one of these
2336 is an order-only prerequisite and one isn't. That means that we should
2337 remove the one that isn't and keep the one that is. */
2338
2339 if (!cmp && dx->ignore_mtime != dy->ignore_mtime)
2340 dx->ignore_mtime = dy->ignore_mtime = 0;
2341
2342 return cmp;
2343}
2344
2345
2346void
2347uniquize_deps (struct dep *chain)
2348{
2349 struct hash_table deps;
2350 register struct dep **depp;
2351
2352 hash_init (&deps, 500, dep_hash_1, dep_hash_2, dep_hash_cmp);
2353
2354 /* Make sure that no dependencies are repeated. This does not
2355 really matter for the purpose of updating targets, but it
2356 might make some names be listed twice for $^ and $?. */
2357
2358 depp = &chain;
2359 while (*depp)
2360 {
2361 struct dep *dep = *depp;
2362 struct dep **dep_slot = (struct dep **) hash_find_slot (&deps, dep);
2363 if (HASH_VACANT (*dep_slot))
2364 {
2365 hash_insert_at (&deps, dep, dep_slot);
2366 depp = &dep->next;
2367 }
2368 else
2369 {
2370 /* Don't bother freeing duplicates.
2371 It's dangerous and little benefit accrues. */
2372 *depp = dep->next;
2373 }
2374 }
2375
2376 hash_free (&deps, 0);
2377}
2378
2379
2380/* Record target-specific variable values for files FILENAMES.
2381 TWO_COLON is nonzero if a double colon was used.
2382
2383 The links of FILENAMES are freed, and so are any names in it
2384 that are not incorporated into other data structures.
2385
2386 If the target is a pattern, add the variable to the pattern-specific
2387 variable value list. */
2388
2389static void
2390record_target_var (struct nameseq *filenames, char *defn,
2391 enum variable_origin origin, int exported,
2392 const struct floc *flocp)
2393{
2394 struct nameseq *nextf;
2395 struct variable_set_list *global;
2396
2397 global = current_variable_set_list;
2398
2399 /* If the variable is an append version, store that but treat it as a
2400 normal recursive variable. */
2401
2402 for (; filenames != 0; filenames = nextf)
2403 {
2404 struct variable *v;
2405 const char *name = filenames->name;
2406 const char *fname;
2407 const char *percent;
2408 struct pattern_var *p;
2409
2410 nextf = filenames->next;
2411 free (filenames);
2412
2413 /* If it's a pattern target, then add it to the pattern-specific
2414 variable list. */
2415 percent = find_percent_cached (&name);
2416 if (percent)
2417 {
2418 /* Get a reference for this pattern-specific variable struct. */
2419 p = create_pattern_var (name, percent);
2420 p->variable.fileinfo = *flocp;
2421 /* I don't think this can fail since we already determined it was a
2422 variable definition. */
2423 v = parse_variable_definition (&p->variable, defn);
2424 assert (v != 0);
2425
2426 if (v->flavor == f_simple)
2427 v->value = allocated_variable_expand (v->value);
2428 else
2429 v->value = xstrdup (v->value);
2430
2431 fname = p->target;
2432 }
2433 else
2434 {
2435 struct file *f;
2436
2437 /* Get a file reference for this file, and initialize it.
2438 We don't want to just call enter_file() because that allocates a
2439 new entry if the file is a double-colon, which we don't want in
2440 this situation. */
2441 f = lookup_file (name);
2442 if (!f)
2443 f = enter_file (strcache_add (name));
2444 else if (f->double_colon)
2445 f = f->double_colon;
2446
2447 initialize_file_variables (f, 1);
2448 fname = f->name;
2449
2450 current_variable_set_list = f->variables;
2451 v = try_variable_definition (flocp, defn, origin, 1);
2452 if (!v)
2453 error (flocp, _("Malformed target-specific variable definition"));
2454 current_variable_set_list = global;
2455 }
2456
2457 /* Set up the variable to be *-specific. */
2458 v->origin = origin;
2459 v->per_target = 1;
2460 v->export = exported ? v_export : v_default;
2461
2462 /* If it's not an override, check to see if there was a command-line
2463 setting. If so, reset the value. */
2464 if (origin != o_override)
2465 {
2466 struct variable *gv;
2467 int len = strlen(v->name);
2468
2469 gv = lookup_variable (v->name, len);
2470 if (gv && (gv->origin == o_env_override || gv->origin == o_command))
2471 {
2472 if (v->value != 0)
2473 free (v->value);
2474 v->value = xstrdup (gv->value);
2475 v->origin = gv->origin;
2476 v->recursive = gv->recursive;
2477 v->append = 0;
2478 }
2479 }
2480 }
2481}
2482
2483
2484/* Record a description line for files FILENAMES,
2485 with dependencies DEPS, commands to execute described
2486 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
2487 TWO_COLON is nonzero if a double colon was used.
2488 If not nil, PATTERN is the `%' pattern to make this
2489 a static pattern rule, and PATTERN_PERCENT is a pointer
2490 to the `%' within it.
2491
2492 The links of FILENAMES are freed, and so are any names in it
2493 that are not incorporated into other data structures. */
2494
2495static void
2496record_files (struct nameseq *filenames, const char *pattern,
2497 const char *pattern_percent, struct dep *deps,
2498 unsigned int cmds_started, char *commands,
2499 unsigned int commands_idx, int two_colon,
2500 const struct floc *flocp)
2501{
2502 struct nameseq *nextf;
2503 int implicit = 0;
2504 unsigned int max_targets = 0, target_idx = 0;
2505 const char **targets = 0, **target_percents = 0;
2506 struct commands *cmds;
2507#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
2508 struct file *prev_file = 0;
2509 enum multitarget_mode { m_unsettled, m_no, m_yes, m_yes_maybe }
2510 multi_mode = !two_colon && !pattern ? m_unsettled : m_no;
2511#endif
2512
2513 /* If we've already snapped deps, that means we're in an eval being
2514 resolved after the makefiles have been read in. We can't add more rules
2515 at this time, since they won't get snapped and we'll get core dumps.
2516 See Savannah bug # 12124. */
2517 if (snapped_deps)
2518 fatal (flocp, _("prerequisites cannot be defined in command scripts"));
2519
2520 if (commands_idx > 0)
2521 {
2522 cmds = xmalloc (sizeof (struct commands));
2523 cmds->fileinfo.filenm = flocp->filenm;
2524 cmds->fileinfo.lineno = cmds_started;
2525 cmds->commands = savestring (commands, commands_idx);
2526 cmds->command_lines = 0;
2527 }
2528 else
2529 cmds = 0;
2530
2531 for (; filenames != 0; filenames = nextf)
2532 {
2533 const char *name = filenames->name;
2534 struct file *f;
2535 struct dep *this = 0;
2536 const char *implicit_percent;
2537
2538 nextf = filenames->next;
2539 free (filenames);
2540
2541 /* Check for special targets. Do it here instead of, say, snap_deps()
2542 so that we can immediately use the value. */
2543
2544 if (streq (name, ".POSIX"))
2545 posix_pedantic = 1;
2546 else if (streq (name, ".SECONDEXPANSION"))
2547 second_expansion = 1;
2548#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
2549 else if (streq (name, ".SECONDTARGETEXPANSION"))
2550 second_target_expansion = 1;
2551#endif
2552
2553 implicit_percent = find_percent_cached (&name);
2554 implicit |= implicit_percent != 0;
2555
2556 if (implicit)
2557 {
2558 if (pattern != 0)
2559 fatal (flocp, _("mixed implicit and static pattern rules"));
2560
2561 if (implicit_percent == 0)
2562 fatal (flocp, _("mixed implicit and normal rules"));
2563
2564 if (targets == 0)
2565 {
2566 max_targets = 5;
2567 targets = xmalloc (5 * sizeof (char *));
2568 target_percents = xmalloc (5 * sizeof (char *));
2569 target_idx = 0;
2570 }
2571 else if (target_idx == max_targets - 1)
2572 {
2573 max_targets += 5;
2574 targets = xrealloc ((void *)targets, max_targets * sizeof (char *));
2575 target_percents = xrealloc ((void *)target_percents,
2576 max_targets * sizeof (char *));
2577 }
2578 targets[target_idx] = name;
2579 target_percents[target_idx] = implicit_percent;
2580 ++target_idx;
2581 continue;
2582 }
2583
2584#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
2585 /* Check for the explicit multitarget mode operators. For this to be
2586 identified as an explicit multiple target rule, the first + or +|
2587 operator *must* appear between the first two files. If not found as
2588 the 2nd file or if found as the 1st file, the rule will be rejected
2589 as a potential multiple first target rule. For the subsequent files
2590 the operator is only required to switch between maybe and non-maybe
2591 mode:
2592 `primary + 2nd 3rd +| 4th-maybe + 5th-for-sure: deps; cmds'
2593
2594 The whole idea of the maybe-updated files is this:
2595 timestamp +| maybe.h: src1.c src2.c
2596 grep goes-into-maybe.h $* > timestamp
2597 cmp timestamp maybe.h || cp -f timestamp maybe.h
2598
2599 This is implemented in remake.c where we don't consider the mtime of
2600 the maybe-updated targets. */
2601 if (multi_mode != m_no && name[0] == '+'
2602 && (name[1] == '\0' || (name[1] == '|' && name[2] == '\0')))
2603 {
2604 if (!prev_file)
2605 multi_mode = m_no; /* first */
2606 else
2607 {
2608 if (multi_mode == m_unsettled)
2609 {
2610 prev_file->multi_head = prev_file;
2611
2612 /* Only the primary file needs the dependencies. */
2613 if (deps)
2614 {
2615 free_dep_chain (deps);
2616 deps = NULL;
2617 }
2618 }
2619 multi_mode = name[1] == '\0' ? m_yes : m_yes_maybe;
2620 continue;
2621 }
2622 }
2623 else if (multi_mode == m_unsettled && prev_file)
2624 multi_mode = m_no;
2625#endif
2626
2627 /* If this is a static pattern rule:
2628 `targets: target%pattern: dep%pattern; cmds',
2629 make sure the pattern matches this target name. */
2630 if (pattern && !pattern_matches (pattern, pattern_percent, name))
2631 error (flocp, _("target `%s' doesn't match the target pattern"), name);
2632 else if (deps)
2633 {
2634 /* If there are multiple filenames, copy the chain DEPS for all but
2635 the last one. It is not safe for the same deps to go in more
2636 than one place in the database. */
2637 this = nextf != 0 ? copy_dep_chain (deps) : deps;
2638 this->need_2nd_expansion = (second_expansion
2639 && strchr (this->name, '$'));
2640 }
2641
2642 if (!two_colon)
2643 {
2644 /* Single-colon. Combine these dependencies
2645 with others in file's existing record, if any. */
2646 f = enter_file (strcache_add (name));
2647
2648 if (f->double_colon)
2649 fatal (flocp,
2650 _("target file `%s' has both : and :: entries"), f->name);
2651
2652 /* If CMDS == F->CMDS, this target was listed in this rule
2653 more than once. Just give a warning since this is harmless. */
2654 if (cmds != 0 && cmds == f->cmds)
2655 error (flocp,
2656 _("target `%s' given more than once in the same rule."),
2657 f->name);
2658
2659 /* Check for two single-colon entries both with commands.
2660 Check is_target so that we don't lose on files such as .c.o
2661 whose commands were preinitialized. */
2662 else if (cmds != 0 && f->cmds != 0 && f->is_target)
2663 {
2664 error (&cmds->fileinfo,
2665 _("warning: overriding commands for target `%s'"),
2666 f->name);
2667 error (&f->cmds->fileinfo,
2668 _("warning: ignoring old commands for target `%s'"),
2669 f->name);
2670 }
2671
2672 f->is_target = 1;
2673
2674 /* Defining .DEFAULT with no deps or cmds clears it. */
2675 if (f == default_file && this == 0 && cmds == 0)
2676 f->cmds = 0;
2677 if (cmds != 0)
2678 f->cmds = cmds;
2679
2680#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
2681 /* If this is an explicit multi target rule, add it to the
2682 target chain and set the multi_maybe flag according to
2683 the current mode. */
2684
2685 if (multi_mode >= m_yes)
2686 {
2687 f->multi_maybe = multi_mode == m_yes_maybe;
2688 prev_file->multi_next = f;
2689 assert (prev_file->multi_head != 0);
2690 f->multi_head = prev_file->multi_head;
2691
2692 if (f == suffix_file)
2693 error (flocp,
2694 _(".SUFFIXES encountered in an explicit multi target rule"));
2695 }
2696 prev_file = f;
2697#endif
2698
2699 /* Defining .SUFFIXES with no dependencies clears out the list of
2700 suffixes. */
2701 if (f == suffix_file && this == 0)
2702 {
2703 free_dep_chain (f->deps);
2704 f->deps = 0;
2705 }
2706 else if (this != 0)
2707 {
2708 /* Add the file's old deps and the new ones in THIS together. */
2709
2710 if (f->deps != 0)
2711 {
2712 struct dep **d_ptr = &f->deps;
2713
2714 while ((*d_ptr)->next != 0)
2715 d_ptr = &(*d_ptr)->next;
2716
2717 if (cmds != 0)
2718 /* This is the rule with commands, so put its deps
2719 last. The rationale behind this is that $< expands to
2720 the first dep in the chain, and commands use $<
2721 expecting to get the dep that rule specifies. However
2722 the second expansion algorithm reverses the order thus
2723 we need to make it last here. */
2724 (*d_ptr)->next = this;
2725 else
2726 {
2727 /* This is the rule without commands. Put its
2728 dependencies at the end but before dependencies from
2729 the rule with commands (if any). This way everything
2730 appears in makefile order. */
2731
2732 if (f->cmds != 0)
2733 {
2734 this->next = *d_ptr;
2735 *d_ptr = this;
2736 }
2737 else
2738 (*d_ptr)->next = this;
2739 }
2740 }
2741 else
2742 f->deps = this;
2743
2744 /* This is a hack. I need a way to communicate to snap_deps()
2745 that the last dependency line in this file came with commands
2746 (so that logic in snap_deps() can put it in front and all
2747 this $< -logic works). I cannot simply rely on file->cmds
2748 being not 0 because of the cases like the following:
2749
2750 foo: bar
2751 foo:
2752 ...
2753
2754 I am going to temporarily "borrow" UPDATING member in
2755 `struct file' for this. */
2756
2757 if (cmds != 0)
2758 f->updating = 1;
2759 }
2760 }
2761 else
2762 {
2763 /* Double-colon. Make a new record even if there already is one. */
2764 f = lookup_file (name);
2765
2766 /* Check for both : and :: rules. Check is_target so
2767 we don't lose on default suffix rules or makefiles. */
2768 if (f != 0 && f->is_target && !f->double_colon)
2769 fatal (flocp,
2770 _("target file `%s' has both : and :: entries"), f->name);
2771 f = enter_file (strcache_add (name));
2772 /* If there was an existing entry and it was a double-colon entry,
2773 enter_file will have returned a new one, making it the prev
2774 pointer of the old one, and setting its double_colon pointer to
2775 the first one. */
2776 if (f->double_colon == 0)
2777 /* This is the first entry for this name, so we must set its
2778 double_colon pointer to itself. */
2779 f->double_colon = f;
2780 f->is_target = 1;
2781 f->deps = this;
2782 f->cmds = cmds;
2783 }
2784
2785 /* If this is a static pattern rule, set the stem to the part of its
2786 name that matched the `%' in the pattern, so you can use $* in the
2787 commands. */
2788 if (pattern)
2789 {
2790 static const char *percent = "%";
2791 char *buffer = variable_expand ("");
2792 const size_t buffer_offset = buffer - variable_buffer; /* bird */
2793 char *o = patsubst_expand_pat (buffer, name, pattern, percent,
2794 pattern_percent+1, percent+1);
2795 buffer = variable_buffer + buffer_offset; /* bird - variable_buffer may have been reallocated. */
2796 f->stem = strcache_add_len (buffer, o - buffer);
2797 if (this)
2798 {
2799 this->staticpattern = 1;
2800 this->stem = f->stem;
2801 }
2802 }
2803
2804 name = f->name;
2805
2806 /* If this target is a default target, update DEFAULT_GOAL_FILE. */
2807 if (streq (*default_goal_name, name)
2808 && (default_goal_file == 0
2809 || ! streq (default_goal_file->name, name)))
2810 default_goal_file = f;
2811 }
2812
2813 if (implicit)
2814 {
2815 if (deps)
2816 deps->need_2nd_expansion = second_expansion;
2817 create_pattern_rule (targets, target_percents, target_idx,
2818 two_colon, deps, cmds, 1);
2819 }
2820}
2821
2822
2823/* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
2824 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
2825 Quoting backslashes are removed from STRING by compacting it into
2826 itself. Returns a pointer to the first unquoted STOPCHAR if there is
2827 one, or nil if there are none. STOPCHARs inside variable references are
2828 ignored if IGNOREVARS is true.
2829
2830 STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */
2831
2832static char *
2833find_char_unquote (char *string, int stop1, int stop2, int blank,
2834 int ignorevars)
2835{
2836 unsigned int string_len = 0;
2837 char *p = string;
2838 register int ch; /* bird: 'optimiziations' */
2839
2840 if (ignorevars)
2841 ignorevars = '$';
2842
2843 while (1)
2844 {
2845 if (stop2 && blank)
2846 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2
2847 && ! isblank ((unsigned char) ch))
2848 ++p;
2849 else if (stop2)
2850 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2)
2851 ++p;
2852 else if (blank)
2853 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1
2854 && ! isblank ((unsigned char) ch))
2855 ++p;
2856 else
2857 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1)
2858 ++p;
2859
2860 if (ch == '\0')
2861 break;
2862
2863 /* If we stopped due to a variable reference, skip over its contents. */
2864 if (ch == ignorevars)
2865 {
2866 char openparen = p[1];
2867
2868 p += 2;
2869
2870 /* Skip the contents of a non-quoted, multi-char variable ref. */
2871 if (openparen == '(' || openparen == '{')
2872 {
2873 unsigned int pcount = 1;
2874 char closeparen = (openparen == '(' ? ')' : '}');
2875
2876 while ((ch = *p))
2877 {
2878 if (ch == openparen)
2879 ++pcount;
2880 else if (ch == closeparen)
2881 if (--pcount == 0)
2882 {
2883 ++p;
2884 break;
2885 }
2886 ++p;
2887 }
2888 }
2889
2890 /* Skipped the variable reference: look for STOPCHARS again. */
2891 continue;
2892 }
2893
2894 if (p > string && p[-1] == '\\')
2895 {
2896 /* Search for more backslashes. */
2897 int i = -2;
2898 while (&p[i] >= string && p[i] == '\\')
2899 --i;
2900 ++i;
2901 /* Only compute the length if really needed. */
2902 if (string_len == 0)
2903 string_len = strlen (string);
2904 /* The number of backslashes is now -I.
2905 Copy P over itself to swallow half of them. */
2906 memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
2907 p += i/2;
2908 if (i % 2 == 0)
2909 /* All the backslashes quoted each other; the STOPCHAR was
2910 unquoted. */
2911 return p;
2912
2913 /* The STOPCHAR was quoted by a backslash. Look for another. */
2914 }
2915 else
2916 /* No backslash in sight. */
2917 return p;
2918 }
2919
2920 /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
2921 return 0;
2922}
2923
2924/* Search PATTERN for an unquoted % and handle quoting. */
2925
2926char *
2927find_percent (char *pattern)
2928{
2929 return find_char_unquote (pattern, '%', 0, 0, 0);
2930}
2931
2932/* Search STRING for an unquoted % and handle quoting. Returns a pointer to
2933 the % or NULL if no % was found.
2934 This version is used with strings in the string cache: if there's a need to
2935 modify the string a new version will be added to the string cache and
2936 *STRING will be set to that. */
2937
2938const char *
2939find_percent_cached (const char **string)
2940{
2941 const char *p = *string;
2942 char *new = 0;
2943 int slen;
2944
2945 /* If the first char is a % return now. This lets us avoid extra tests
2946 inside the loop. */
2947 if (*p == '%')
2948 return p;
2949
2950 while (1)
2951 {
2952 while (*p != '\0' && *p != '%')
2953 ++p;
2954
2955 if (*p == '\0')
2956 break;
2957
2958 /* See if this % is escaped with a backslash; if not we're done. */
2959 if (p[-1] != '\\')
2960 break;
2961
2962 {
2963 /* Search for more backslashes. */
2964 char *pv;
2965 int i = -2;
2966
2967 while (&p[i] >= *string && p[i] == '\\')
2968 --i;
2969 ++i;
2970
2971 /* At this point we know we'll need to allocate a new string.
2972 Make a copy if we haven't yet done so. */
2973 if (! new)
2974 {
2975 slen = strlen (*string);
2976 new = alloca (slen + 1);
2977 memcpy (new, *string, slen + 1);
2978 p = new + (p - *string);
2979 *string = new;
2980 }
2981
2982 /* At this point *string, p, and new all point into the same string.
2983 Get a non-const version of p so we can modify new. */
2984 pv = new + (p - *string);
2985
2986 /* The number of backslashes is now -I.
2987 Copy P over itself to swallow half of them. */
2988 memmove (&pv[i], &pv[i/2], (slen - (pv - new)) - (i/2) + 1);
2989 p += i/2;
2990
2991 /* If the backslashes quoted each other; the % was unquoted. */
2992 if (i % 2 == 0)
2993 break;
2994 }
2995 }
2996
2997 /* If we had to change STRING, add it to the strcache. */
2998 if (new)
2999 {
3000 *string = strcache_add (*string);
3001 p = *string + (p - new);
3002 }
3003
3004 /* If we didn't find a %, return NULL. Otherwise return a ptr to it. */
3005 return (*p == '\0') ? NULL : p;
3006}
3007
3008
3009/* Parse a string into a sequence of filenames represented as a
3010 chain of struct nameseq's in reverse order and return that chain.
3011
3012 The string is passed as STRINGP, the address of a string pointer.
3013 The string pointer is updated to point at the first character
3014 not parsed, which either is a null char or equals STOPCHAR.
3015
3016 SIZE is how big to construct chain elements.
3017 This is useful if we want them actually to be other structures
3018 that have room for additional info.
3019
3020 If STRIP is nonzero, strip `./'s off the beginning. */
3021
3022struct nameseq *
3023parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip)
3024{
3025 struct nameseq *new = 0;
3026 struct nameseq *new1;
3027#ifndef NO_ARCHIVES /* bird: MSC warning */
3028 struct nameseq *lastnew1;
3029#endif
3030 char *p = *stringp;
3031
3032#ifdef VMS
3033# define VMS_COMMA ','
3034#else
3035# define VMS_COMMA 0
3036#endif
3037
3038 while (1)
3039 {
3040 const char *name;
3041 char *q;
3042
3043 /* Skip whitespace; see if any more names are left. */
3044 p = next_token (p);
3045 if (*p == '\0')
3046 break;
3047 if (*p == stopchar)
3048 break;
3049
3050 /* There are, so find the end of the next name. */
3051 q = p;
3052 p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0);
3053#ifdef VMS
3054 /* convert comma separated list to space separated */
3055 if (p && *p == ',')
3056 *p =' ';
3057#endif
3058#ifdef _AMIGA
3059 if (stopchar == ':' && p && *p == ':'
3060 && !(isspace ((unsigned char)p[1]) || !p[1]
3061 || isspace ((unsigned char)p[-1])))
3062 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);
3063#endif
3064#ifdef HAVE_DOS_PATHS
3065 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
3066 first colon which isn't followed by a slash or a backslash.
3067 Note that tokens separated by spaces should be treated as separate
3068 tokens since make doesn't allow path names with spaces */
3069 if (stopchar == ':')
3070 while (p != 0 && !isspace ((unsigned char)*p) &&
3071 (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))
3072 p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0);
3073#endif
3074 if (p == 0)
3075 p = q + strlen (q);
3076
3077 if (strip)
3078#ifdef VMS
3079 /* Skip leading `[]'s. */
3080 while (p - q > 2 && q[0] == '[' && q[1] == ']')
3081#else
3082 /* Skip leading `./'s. */
3083 while (p - q > 2 && q[0] == '.' && q[1] == '/')
3084#endif
3085 {
3086 q += 2; /* Skip "./". */
3087 while (q < p && *q == '/')
3088 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
3089 ++q;
3090 }
3091
3092 /* Extract the filename just found, and skip it. */
3093
3094 if (q == p)
3095 /* ".///" was stripped to "". */
3096#if defined(VMS)
3097 continue;
3098#elif defined(_AMIGA)
3099 name = "";
3100#else
3101 name = "./";
3102#endif
3103 else
3104#ifdef VMS
3105/* VMS filenames can have a ':' in them but they have to be '\'ed but we need
3106 * to remove this '\' before we can use the filename.
3107 * Savestring called because q may be read-only string constant.
3108 */
3109 {
3110 char *qbase = xstrdup (q);
3111 char *pbase = qbase + (p-q);
3112 char *q1 = qbase;
3113 char *q2 = q1;
3114 char *p1 = pbase;
3115
3116 while (q1 != pbase)
3117 {
3118 if (*q1 == '\\' && *(q1+1) == ':')
3119 {
3120 q1++;
3121 p1--;
3122 }
3123 *q2++ = *q1++;
3124 }
3125 name = strcache_add_len (qbase, p1 - qbase);
3126 free (qbase);
3127 }
3128#else
3129 name = strcache_add_len (q, p - q);
3130#endif
3131
3132 /* Add it to the front of the chain. */
3133 new1 = xmalloc (size);
3134 new1->name = name;
3135 new1->next = new;
3136 new = new1;
3137 }
3138
3139#ifndef NO_ARCHIVES
3140
3141 /* Look for multi-word archive references.
3142 They are indicated by a elt ending with an unmatched `)' and
3143 an elt further down the chain (i.e., previous in the file list)
3144 with an unmatched `(' (e.g., "lib(mem"). */
3145
3146 new1 = new;
3147 lastnew1 = 0;
3148 while (new1 != 0)
3149 if (new1->name[0] != '(' /* Don't catch "(%)" and suchlike. */
3150 && new1->name[strlen (new1->name) - 1] == ')'
3151 && strchr (new1->name, '(') == 0)
3152 {
3153 /* NEW1 ends with a `)' but does not contain a `('.
3154 Look back for an elt with an opening `(' but no closing `)'. */
3155
3156 struct nameseq *n = new1->next, *lastn = new1;
3157 char *paren = 0;
3158 while (n != 0 && (paren = strchr (n->name, '(')) == 0)
3159 {
3160 lastn = n;
3161 n = n->next;
3162 }
3163 if (n != 0
3164 /* Ignore something starting with `(', as that cannot actually
3165 be an archive-member reference (and treating it as such
3166 results in an empty file name, which causes much lossage). */
3167 && n->name[0] != '(')
3168 {
3169 /* N is the first element in the archive group.
3170 Its name looks like "lib(mem" (with no closing `)'). */
3171
3172 char *libname;
3173
3174 /* Copy "lib(" into LIBNAME. */
3175 ++paren;
3176 libname = alloca (paren - n->name + 1);
3177 memcpy (libname, n->name, paren - n->name);
3178 libname[paren - n->name] = '\0';
3179
3180 if (*paren == '\0')
3181 {
3182 /* N was just "lib(", part of something like "lib( a b)".
3183 Edit it out of the chain and free its storage. */
3184 lastn->next = n->next;
3185 free (n);
3186 /* LASTN->next is the new stopping elt for the loop below. */
3187 n = lastn->next;
3188 }
3189 else
3190 {
3191 /* Replace N's name with the full archive reference. */
3192 n->name = strcache_add (concat (libname, paren, ")"));
3193 }
3194
3195 if (new1->name[1] == '\0')
3196 {
3197 /* NEW1 is just ")", part of something like "lib(a b )".
3198 Omit it from the chain and free its storage. */
3199 if (lastnew1 == 0)
3200 new = new1->next;
3201 else
3202 lastnew1->next = new1->next;
3203 lastn = new1;
3204 new1 = new1->next;
3205 free (lastn);
3206 }
3207 else
3208 {
3209 /* Replace also NEW1->name, which already has closing `)'. */
3210 new1->name = strcache_add (concat (libname, new1->name, ""));
3211 new1 = new1->next;
3212 }
3213
3214 /* Trace back from NEW1 (the end of the list) until N
3215 (the beginning of the list), rewriting each name
3216 with the full archive reference. */
3217
3218 while (new1 != n)
3219 {
3220 new1->name = strcache_add (concat (libname, new1->name, ")"));
3221 lastnew1 = new1;
3222 new1 = new1->next;
3223 }
3224 }
3225 else
3226 {
3227 /* No frobnication happening. Just step down the list. */
3228 lastnew1 = new1;
3229 new1 = new1->next;
3230 }
3231 }
3232 else
3233 {
3234 lastnew1 = new1;
3235 new1 = new1->next;
3236 }
3237
3238#endif
3239
3240 *stringp = p;
3241 return new;
3242}
3243
3244
3245/* Find the next line of text in an eval buffer, combining continuation lines
3246 into one line.
3247 Return the number of actual lines read (> 1 if continuation lines).
3248 Returns -1 if there's nothing left in the buffer.
3249
3250 After this function, ebuf->buffer points to the first character of the
3251 line we just found.
3252 */
3253
3254/* Read a line of text from a STRING.
3255 Since we aren't really reading from a file, don't bother with linenumbers.
3256 */
3257
3258static unsigned long
3259readstring (struct ebuffer *ebuf)
3260{
3261 char *eol;
3262
3263 /* If there is nothing left in this buffer, return 0. */
3264 if (ebuf->bufnext >= ebuf->bufstart + ebuf->size)
3265 return -1;
3266
3267 /* Set up a new starting point for the buffer, and find the end of the
3268 next logical line (taking into account backslash/newline pairs). */
3269
3270 eol = ebuf->buffer = ebuf->bufnext;
3271
3272 while (1)
3273 {
3274 int backslash = 0;
3275 char *bol = eol;
3276 char *p;
3277
3278 /* Find the next newline. At EOS, stop. */
3279 eol = p = strchr (eol , '\n');
3280 if (!eol)
3281 {
3282 ebuf->bufnext = ebuf->bufstart + ebuf->size + 1;
3283 return 0;
3284 }
3285
3286 /* Found a newline; if it's escaped continue; else we're done. */
3287 while (p > bol && *(--p) == '\\')
3288 backslash = !backslash;
3289 if (!backslash)
3290 break;
3291 ++eol;
3292 }
3293
3294 /* Overwrite the newline char. */
3295 *eol = '\0';
3296 ebuf->bufnext = eol+1;
3297
3298 return 0;
3299}
3300
3301static long
3302readline (struct ebuffer *ebuf)
3303{
3304 char *p;
3305 char *end;
3306 char *start;
3307 long nlines = 0;
3308
3309 /* The behaviors between string and stream buffers are different enough to
3310 warrant different functions. Do the Right Thing. */
3311
3312 if (!ebuf->fp)
3313 return readstring (ebuf);
3314
3315 /* When reading from a file, we always start over at the beginning of the
3316 buffer for each new line. */
3317
3318 p = start = ebuf->bufstart;
3319 end = p + ebuf->size;
3320 *p = '\0';
3321
3322 while (fgets (p, end - p, ebuf->fp) != 0)
3323 {
3324 char *p2;
3325 unsigned long len;
3326 int backslash;
3327
3328 len = strlen (p);
3329 if (len == 0)
3330 {
3331 /* This only happens when the first thing on the line is a '\0'.
3332 It is a pretty hopeless case, but (wonder of wonders) Athena
3333 lossage strikes again! (xmkmf puts NULs in its makefiles.)
3334 There is nothing really to be done; we synthesize a newline so
3335 the following line doesn't appear to be part of this line. */
3336 error (&ebuf->floc,
3337 _("warning: NUL character seen; rest of line ignored"));
3338 p[0] = '\n';
3339 len = 1;
3340 }
3341
3342 /* Jump past the text we just read. */
3343 p += len;
3344
3345 /* If the last char isn't a newline, the whole line didn't fit into the
3346 buffer. Get some more buffer and try again. */
3347 if (p[-1] != '\n')
3348 goto more_buffer;
3349
3350 /* We got a newline, so add one to the count of lines. */
3351 ++nlines;
3352
3353#if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
3354 /* Check to see if the line was really ended with CRLF; if so ignore
3355 the CR. */
3356 if ((p - start) > 1 && p[-2] == '\r')
3357 {
3358 --p;
3359 p[-1] = '\n';
3360 }
3361#endif
3362
3363 backslash = 0;
3364 for (p2 = p - 2; p2 >= start; --p2)
3365 {
3366 if (*p2 != '\\')
3367 break;
3368 backslash = !backslash;
3369 }
3370
3371 if (!backslash)
3372 {
3373 p[-1] = '\0';
3374 break;
3375 }
3376
3377 /* It was a backslash/newline combo. If we have more space, read
3378 another line. */
3379 if (end - p >= 80)
3380 continue;
3381
3382 /* We need more space at the end of our buffer, so realloc it.
3383 Make sure to preserve the current offset of p. */
3384 more_buffer:
3385 {
3386 unsigned long off = p - start;
3387 ebuf->size *= 2;
3388 start = ebuf->buffer = ebuf->bufstart = xrealloc (start, ebuf->size);
3389 p = start + off;
3390 end = start + ebuf->size;
3391 *p = '\0';
3392 }
3393 }
3394
3395 if (ferror (ebuf->fp))
3396 pfatal_with_name (ebuf->floc.filenm);
3397
3398 /* If we found some lines, return how many.
3399 If we didn't, but we did find _something_, that indicates we read the last
3400 line of a file with no final newline; return 1.
3401 If we read nothing, we're at EOF; return -1. */
3402
3403 return nlines ? nlines : p == ebuf->bufstart ? -1 : 1;
3404}
3405
3406
3407/* Parse the next "makefile word" from the input buffer, and return info
3408 about it.
3409
3410 A "makefile word" is one of:
3411
3412 w_bogus Should never happen
3413 w_eol End of input
3414 w_static A static word; cannot be expanded
3415 w_variable A word containing one or more variables/functions
3416 w_colon A colon
3417 w_dcolon A double-colon
3418 w_semicolon A semicolon
3419 w_varassign A variable assignment operator (=, :=, +=, >=, or ?=)
3420
3421 Note that this function is only used when reading certain parts of the
3422 makefile. Don't use it where special rules hold sway (RHS of a variable,
3423 in a command list, etc.) */
3424
3425static enum make_word_type
3426get_next_mword (char *buffer, char *delim, char **startp, unsigned int *length)
3427{
3428 enum make_word_type wtype = w_bogus;
3429 char *p = buffer, *beg;
3430 char c;
3431
3432 /* Skip any leading whitespace. */
3433 while (isblank ((unsigned char)*p))
3434 ++p;
3435
3436 beg = p;
3437 c = *(p++);
3438 switch (c)
3439 {
3440 case '\0':
3441 wtype = w_eol;
3442 break;
3443
3444 case ';':
3445 wtype = w_semicolon;
3446 break;
3447
3448 case '=':
3449 wtype = w_varassign;
3450 break;
3451
3452 case ':':
3453 wtype = w_colon;
3454 switch (*p)
3455 {
3456 case ':':
3457 ++p;
3458 wtype = w_dcolon;
3459 break;
3460
3461 case '=':
3462 ++p;
3463 wtype = w_varassign;
3464 break;
3465 }
3466 break;
3467
3468 case '+':
3469 case '?':
3470#ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
3471 case '>':
3472#endif
3473 if (*p == '=')
3474 {
3475 ++p;
3476 wtype = w_varassign;
3477 break;
3478 }
3479
3480 default:
3481 if (delim && strchr (delim, c))
3482 wtype = w_static;
3483 break;
3484 }
3485
3486 /* Did we find something? If so, return now. */
3487 if (wtype != w_bogus)
3488 goto done;
3489
3490 /* This is some non-operator word. A word consists of the longest
3491 string of characters that doesn't contain whitespace, one of [:=#],
3492 or [?+]=, or one of the chars in the DELIM string. */
3493
3494 /* We start out assuming a static word; if we see a variable we'll
3495 adjust our assumptions then. */
3496 wtype = w_static;
3497
3498 /* We already found the first value of "c", above. */
3499 while (1)
3500 {
3501 char closeparen;
3502 int count;
3503
3504 switch (c)
3505 {
3506 case '\0':
3507 case ' ':
3508 case '\t':
3509 case '=':
3510 goto done_word;
3511
3512 case ':':
3513#ifdef HAVE_DOS_PATHS
3514 /* A word CAN include a colon in its drive spec. The drive
3515 spec is allowed either at the beginning of a word, or as part
3516 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
3517 if (!(p - beg >= 2
3518 && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
3519 && (p - beg == 2 || p[-3] == '(')))
3520#endif
3521 goto done_word;
3522
3523 case '$':
3524 c = *(p++);
3525 if (c == '$')
3526 break;
3527
3528 /* This is a variable reference, so note that it's expandable.
3529 Then read it to the matching close paren. */
3530 wtype = w_variable;
3531
3532 if (c == '(')
3533 closeparen = ')';
3534 else if (c == '{')
3535 closeparen = '}';
3536 else
3537 /* This is a single-letter variable reference. */
3538 break;
3539
3540 for (count=0; *p != '\0'; ++p)
3541 {
3542 if (*p == c)
3543 ++count;
3544 else if (*p == closeparen && --count < 0)
3545 {
3546 ++p;
3547 break;
3548 }
3549 }
3550 break;
3551
3552 case '?':
3553 case '+':
3554#ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
3555 case '>':
3556#endif
3557 if (*p == '=')
3558 goto done_word;
3559 break;
3560
3561 case '\\':
3562 switch (*p)
3563 {
3564 case ':':
3565 case ';':
3566 case '=':
3567 case '\\':
3568 ++p;
3569 break;
3570 }
3571 break;
3572
3573 default:
3574 if (delim && strchr (delim, c))
3575 goto done_word;
3576 break;
3577 }
3578
3579 c = *(p++);
3580 }
3581 done_word:
3582 --p;
3583
3584 done:
3585 if (startp)
3586 *startp = beg;
3587 if (length)
3588 *length = p - beg;
3589 return wtype;
3590}
3591
3592
3593/* Construct the list of include directories
3594 from the arguments and the default list. */
3595
3596void
3597construct_include_path (const char **arg_dirs)
3598{
3599#ifdef VAXC /* just don't ask ... */
3600 stat_t stbuf;
3601#else
3602 struct stat stbuf;
3603#endif
3604 const char **dirs;
3605 const char **cpp;
3606 unsigned int idx;
3607
3608 /* Compute the number of pointers we need in the table. */
3609 idx = sizeof (default_include_directories) / sizeof (const char *);
3610 if (arg_dirs)
3611 for (cpp = arg_dirs; *cpp != 0; ++cpp)
3612 ++idx;
3613
3614#ifdef __MSDOS__
3615 /* Add one for $DJDIR. */
3616 ++idx;
3617#endif
3618#ifdef KMK
3619 /* Add one for the kBuild directory. */
3620 ++idx;
3621#endif
3622
3623 dirs = xmalloc (idx * sizeof (const char *));
3624
3625 idx = 0;
3626 max_incl_len = 0;
3627
3628 /* First consider any dirs specified with -I switches.
3629 Ignore any that don't exist. Remember the maximum string length. */
3630
3631 if (arg_dirs)
3632 while (*arg_dirs != 0)
3633 {
3634 const char *dir = *(arg_dirs++);
3635 char *expanded = 0;
3636 int e;
3637
3638 if (dir[0] == '~')
3639 {
3640 expanded = tilde_expand (dir);
3641 if (expanded != 0)
3642 dir = expanded;
3643 }
3644
3645 EINTRLOOP (e, stat (dir, &stbuf));
3646 if (e == 0 && S_ISDIR (stbuf.st_mode))
3647 {
3648 unsigned int len = strlen (dir);
3649 /* If dir name is written with trailing slashes, discard them. */
3650 while (len > 1 && dir[len - 1] == '/')
3651 --len;
3652 if (len > max_incl_len)
3653 max_incl_len = len;
3654 dirs[idx++] = strcache_add_len (dir, len);
3655 }
3656
3657 if (expanded)
3658 free (expanded);
3659 }
3660
3661 /* Now add the standard default dirs at the end. */
3662
3663#ifdef __MSDOS__
3664 {
3665 /* The environment variable $DJDIR holds the root of the DJGPP directory
3666 tree; add ${DJDIR}/include. */
3667 struct variable *djdir = lookup_variable ("DJDIR", 5);
3668
3669 if (djdir)
3670 {
3671 unsigned int len = strlen (djdir->value) + 8;
3672 char *defdir = alloca (len + 1);
3673
3674 strcat (strcpy (defdir, djdir->value), "/include");
3675 dirs[idx++] = strcache_add (defdir);
3676
3677 if (len > max_incl_len)
3678 max_incl_len = len;
3679 }
3680 }
3681#endif
3682#ifdef KMK
3683 /* Add $(KBUILD_PATH). */
3684 {
3685 size_t len = strlen (get_kbuild_path ());
3686 dirs[idx++] = strcache_add_len (get_kbuild_path (), len);
3687 if (len > max_incl_len)
3688 max_incl_len = len;
3689 }
3690#endif
3691
3692 for (cpp = default_include_directories; *cpp != 0; ++cpp)
3693 {
3694 int e;
3695
3696 EINTRLOOP (e, stat (*cpp, &stbuf));
3697 if (e == 0 && S_ISDIR (stbuf.st_mode))
3698 {
3699 unsigned int len = strlen (*cpp);
3700 /* If dir name is written with trailing slashes, discard them. */
3701 while (len > 1 && (*cpp)[len - 1] == '/')
3702 --len;
3703 if (len > max_incl_len)
3704 max_incl_len = len;
3705 dirs[idx++] = strcache_add_len (*cpp, len - 1);
3706 }
3707 }
3708
3709 dirs[idx] = 0;
3710
3711 /* Now add each dir to the .INCLUDE_DIRS variable. */
3712
3713 for (cpp = dirs; *cpp != 0; ++cpp)
3714 do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp,
3715 o_default, f_append, 0);
3716
3717 include_directories = dirs;
3718}
3719
3720
3721/* Expand ~ or ~USER at the beginning of NAME.
3722 Return a newly malloc'd string or 0. */
3723
3724char *
3725tilde_expand (const char *name)
3726{
3727#ifndef VMS
3728 if (name[1] == '/' || name[1] == '\0')
3729 {
3730 extern char *getenv ();
3731 char *home_dir;
3732 int is_variable;
3733
3734 {
3735 /* Turn off --warn-undefined-variables while we expand HOME. */
3736 int save = warn_undefined_variables_flag;
3737 warn_undefined_variables_flag = 0;
3738
3739 home_dir = allocated_variable_expand ("$(HOME)");
3740
3741 warn_undefined_variables_flag = save;
3742 }
3743
3744 is_variable = home_dir[0] != '\0';
3745 if (!is_variable)
3746 {
3747 free (home_dir);
3748 home_dir = getenv ("HOME");
3749 }
3750# if !defined(_AMIGA) && !defined(WINDOWS32)
3751 if (home_dir == 0 || home_dir[0] == '\0')
3752 {
3753 extern char *getlogin ();
3754 char *logname = getlogin ();
3755 home_dir = 0;
3756 if (logname != 0)
3757 {
3758 struct passwd *p = getpwnam (logname);
3759 if (p != 0)
3760 home_dir = p->pw_dir;
3761 }
3762 }
3763# endif /* !AMIGA && !WINDOWS32 */
3764 if (home_dir != 0)
3765 {
3766 char *new = xstrdup (concat (home_dir, "", name + 1));
3767 if (is_variable)
3768 free (home_dir);
3769 return new;
3770 }
3771 }
3772# if !defined(_AMIGA) && !defined(WINDOWS32)
3773 else
3774 {
3775 struct passwd *pwent;
3776 char *userend = strchr (name + 1, '/');
3777 if (userend != 0)
3778 *userend = '\0';
3779 pwent = getpwnam (name + 1);
3780 if (pwent != 0)
3781 {
3782 if (userend == 0)
3783 return xstrdup (pwent->pw_dir);
3784 else
3785 return xstrdup (concat (pwent->pw_dir, "/", userend + 1));
3786 }
3787 else if (userend != 0)
3788 *userend = '/';
3789 }
3790# endif /* !AMIGA && !WINDOWS32 */
3791#endif /* !VMS */
3792 return 0;
3793}
3794
3795/* Given a chain of struct nameseq's describing a sequence of filenames,
3796 in reverse of the intended order, return a new chain describing the
3797 result of globbing the filenames. The new chain is in forward order.
3798 The links of the old chain are freed or used in the new chain.
3799 Likewise for the names in the old chain.
3800
3801 SIZE is how big to construct chain elements.
3802 This is useful if we want them actually to be other structures
3803 that have room for additional info. */
3804
3805struct nameseq *
3806multi_glob (struct nameseq *chain, unsigned int size)
3807{
3808 void dir_setup_glob (glob_t *);
3809 struct nameseq *new = 0;
3810 struct nameseq *old;
3811 struct nameseq *nexto;
3812 glob_t gl;
3813#if defined(KMK) || defined(__EMX__) /* speed optimization */
3814 int rc;
3815#endif
3816
3817 dir_setup_glob (&gl);
3818
3819 for (old = chain; old != 0; old = nexto)
3820 {
3821 const char *gname;
3822#ifndef NO_ARCHIVES
3823 char *arname = 0;
3824 char *memname = 0;
3825#endif
3826 nexto = old->next;
3827 gname = old->name;
3828
3829 if (gname[0] == '~')
3830 {
3831 char *newname = tilde_expand (old->name);
3832 if (newname != 0)
3833 gname = newname;
3834 }
3835
3836#ifndef NO_ARCHIVES
3837 if (ar_name (gname))
3838 {
3839 /* OLD->name is an archive member reference. Replace it with the
3840 archive file name, and save the member name in MEMNAME. We will
3841 glob on the archive name and then reattach MEMNAME later. */
3842 ar_parse_name (gname, &arname, &memname);
3843 gname = arname;
3844 }
3845#endif /* !NO_ARCHIVES */
3846
3847#if defined(KMK) || defined(__EMX__) /* speed optimization */
3848 if (!strpbrk(gname, "*?["))
3849 {
3850 gl.gl_pathc = 1;
3851 gl.gl_pathv = (char **)&gname;
3852 rc = 0;
3853 }
3854 else
3855 rc = glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl);
3856 switch (rc)
3857#else
3858 switch (glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))
3859#endif
3860 {
3861 case 0: /* Success. */
3862 {
3863 int i = gl.gl_pathc;
3864 while (i-- > 0)
3865 {
3866#ifndef NO_ARCHIVES
3867 if (memname != 0)
3868 {
3869 /* Try to glob on MEMNAME within the archive. */
3870 struct nameseq *found
3871 = ar_glob (gl.gl_pathv[i], memname, size);
3872 if (! found)
3873 {
3874 /* No matches. Use MEMNAME as-is. */
3875 unsigned int alen = strlen (gl.gl_pathv[i]);
3876 unsigned int mlen = strlen (memname);
3877 char *name;
3878 struct nameseq *elt = xmalloc (size);
3879 memset (elt, '\0', size);
3880
3881 name = alloca (alen + 1 + mlen + 2);
3882 memcpy (name, gl.gl_pathv[i], alen);
3883 name[alen] = '(';
3884 memcpy (name+alen+1, memname, mlen);
3885 name[alen + 1 + mlen] = ')';
3886 name[alen + 1 + mlen + 1] = '\0';
3887 elt->name = strcache_add (name);
3888 elt->next = new;
3889 new = elt;
3890 }
3891 else
3892 {
3893 /* Find the end of the FOUND chain. */
3894 struct nameseq *f = found;
3895 while (f->next != 0)
3896 f = f->next;
3897
3898 /* Attach the chain being built to the end of the FOUND
3899 chain, and make FOUND the new NEW chain. */
3900 f->next = new;
3901 new = found;
3902 }
3903 }
3904 else
3905#endif /* !NO_ARCHIVES */
3906 {
3907 struct nameseq *elt = xmalloc (size);
3908 memset (elt, '\0', size);
3909 elt->name = strcache_add (gl.gl_pathv[i]);
3910 elt->next = new;
3911 new = elt;
3912 }
3913 }
3914#if defined(KMK) || defined(__EMX__) /* speed optimization */
3915 if (gl.gl_pathv != (char **)&gname)
3916#endif
3917 globfree (&gl);
3918 free (old);
3919 break;
3920 }
3921
3922 case GLOB_NOSPACE:
3923 fatal (NILF, _("virtual memory exhausted"));
3924 break;
3925
3926 default:
3927 old->next = new;
3928 new = old;
3929 break;
3930 }
3931
3932#ifndef NO_ARCHIVES
3933 if (arname)
3934 free (arname);
3935#endif
3936 }
3937
3938 return new;
3939}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette