1 /* Variable function expansion for GNU Make.
2 Copyright (C) 1988, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 static char *string_glob ();
27 /* Store into VARIABLE_BUFFER at O the result of scanning TEXT and replacing
28 each occurrence of SUBST with REPLACE. TEXT is null-terminated. SLEN is
29 the length of SUBST and RLEN is the length of REPLACE. If BY_WORD is
30 nonzero, substitutions are done only on matches which are complete
31 whitespace-delimited words. If SUFFIX_ONLY is nonzero, substitutions are
32 done only at the ends of whitespace-delimited words. */
35 subst_expand (o
, text
, subst
, replace
, slen
, rlen
, by_word
, suffix_only
)
38 char *subst
, *replace
;
39 unsigned int slen
, rlen
;
40 int by_word
, suffix_only
;
42 register char *t
= text
;
45 if (slen
== 0 && !by_word
&& !suffix_only
)
47 /* The first occurrence of "" in any string is its end. */
48 o
= variable_buffer_output (o
, t
, strlen (t
));
50 o
= variable_buffer_output (o
, replace
, rlen
);
54 while ((p
= sindex (t
, 0, subst
, slen
)) != 0)
56 /* Output everything before this occurrence of the string to replace. */
58 o
= variable_buffer_output (o
, t
, p
- t
);
60 /* If we're substituting only by fully matched words,
61 or only at the ends of words, check that this case qualifies. */
63 && ((p
> t
&& !isblank (p
[-1]))
64 || (p
[slen
] != '\0' && !isblank (p
[slen
]))))
66 && (p
[slen
] != '\0' && !isblank (p
[slen
]))))
67 /* Struck out. Output the rest of the string that is
68 no longer to be replaced. */
69 o
= variable_buffer_output (o
, subst
, slen
);
71 /* Output the replacement string. */
72 o
= variable_buffer_output (o
, replace
, rlen
);
74 /* Advance T past the string to be replaced. */
78 /* Output everything left on the end. */
80 o
= variable_buffer_output (o
, t
, strlen (t
));
86 /* Store into VARIABLE_BUFFER at O the result of scanning TEXT
87 and replacing strings matching PATTERN with REPLACE.
88 If PATTERN_PERCENT is not nil, PATTERN has already been
89 run through find_percent, and PATTERN_PERCENT is the result.
90 If REPLACE_PERCENT is not nil, REPLACE has already been
91 run through find_percent, and REPLACE_PERCENT is the result. */
94 patsubst_expand (o
, text
, pattern
, replace
, pattern_percent
, replace_percent
)
97 register char *pattern
, *replace
;
98 register char *pattern_percent
, *replace_percent
;
100 register int pattern_prepercent_len
, pattern_postpercent_len
;
101 register int replace_prepercent_len
, replace_postpercent_len
;
106 /* We call find_percent on REPLACE before checking PATTERN so that REPLACE
107 will be collapsed before we call subst_expand if PATTERN has no %. */
108 if (replace_percent
== 0)
109 replace_percent
= find_percent (replace
);
110 if (replace_percent
!= 0)
112 /* Record the length of REPLACE before and after the % so
113 we don't have to compute these lengths more than once. */
114 replace_prepercent_len
= replace_percent
- replace
;
115 replace_postpercent_len
= strlen (replace_percent
+ 1);
118 /* We store the length of the replacement
119 so we only need to compute it once. */
120 replace_prepercent_len
= strlen (replace
);
122 if (pattern_percent
== 0)
123 pattern_percent
= find_percent (pattern
);
124 if (pattern_percent
== 0)
125 /* With no % in the pattern, this is just a simple substitution. */
126 return subst_expand (o
, text
, pattern
, replace
,
127 strlen (pattern
), strlen (replace
), 1, 0);
129 /* Record the length of PATTERN before and after the %
130 so we don't have to compute it more than once. */
131 pattern_prepercent_len
= pattern_percent
- pattern
;
132 pattern_postpercent_len
= strlen (pattern_percent
+ 1);
134 while ((t
= find_next_token (&text
, &len
)) != 0)
138 /* Is it big enough to match? */
139 if (len
< pattern_prepercent_len
+ pattern_postpercent_len
)
142 /* Does the prefix match? */
143 if (!fail
&& pattern_prepercent_len
> 0
145 || t
[pattern_prepercent_len
- 1] != pattern_percent
[-1]
146 || strncmp (t
+ 1, pattern
+ 1, pattern_prepercent_len
- 1)))
149 /* Does the suffix match? */
150 if (!fail
&& pattern_postpercent_len
> 0
151 && (t
[len
- 1] != pattern_percent
[pattern_postpercent_len
]
152 || t
[len
- pattern_postpercent_len
] != pattern_percent
[1]
153 || strncmp (&t
[len
- pattern_postpercent_len
],
154 &pattern_percent
[1], pattern_postpercent_len
- 1)))
158 /* It didn't match. Output the string. */
159 o
= variable_buffer_output (o
, t
, len
);
162 /* It matched. Output the replacement. */
164 /* Output the part of the replacement before the %. */
165 o
= variable_buffer_output (o
, replace
, replace_prepercent_len
);
167 if (replace_percent
!= 0)
169 /* Output the part of the matched string that
170 matched the % in the pattern. */
171 o
= variable_buffer_output (o
, t
+ pattern_prepercent_len
,
172 len
- (pattern_prepercent_len
173 + pattern_postpercent_len
));
174 /* Output the part of the replacement after the %. */
175 o
= variable_buffer_output (o
, replace_percent
+ 1,
176 replace_postpercent_len
);
180 /* Output a space, but not if the replacement is "". */
181 if (fail
|| replace_prepercent_len
> 0
182 || (replace_percent
!= 0 && len
+ replace_postpercent_len
> 0))
184 o
= variable_buffer_output (o
, " ", 1);
189 /* Kill the last space. */
195 /* Handle variable-expansion-time functions such as $(dir foo/bar) ==> foo/ */
197 /* These enumeration constants distinguish the
198 various expansion-time built-in functions. */
226 /* Greater than the length of any function name. */
227 #define MAXFUNCTIONLEN 11
229 /* The function names and lengths of names, for looking them up. */
235 enum function function
;
238 { "subst", 5, function_subst
},
239 { "addsuffix", 9, function_addsuffix
},
240 { "addprefix", 9, function_addprefix
},
241 { "dir", 3, function_dir
},
242 { "notdir", 6, function_notdir
},
243 { "suffix", 6, function_suffix
},
244 { "basename", 8, function_basename
},
245 { "wildcard", 8, function_wildcard
},
246 { "firstword", 9, function_firstword
},
247 { "word", 4, function_word
},
248 { "words", 5, function_words
},
249 { "findstring", 10, function_findstring
},
250 { "strip", 5, function_strip
},
251 { "join", 4, function_join
},
252 { "patsubst", 8, function_patsubst
},
253 { "filter", 6, function_filter
},
254 { "filter-out", 10, function_filter_out
},
255 { "foreach", 7, function_foreach
},
256 { "sort", 4, function_sort
},
257 { "origin", 6, function_origin
},
258 { "shell", 5, function_shell
},
259 { 0, 0, function_invalid
}
262 /* Return 1 if PATTERN matches WORD, 0 if not. */
265 pattern_matches (pattern
, percent
, word
)
266 register char *pattern
, *percent
, *word
;
268 unsigned int sfxlen
, wordlen
;
272 unsigned int len
= strlen (pattern
) + 1;
273 char *new = (char *) alloca (len
);
274 bcopy (pattern
, new, len
);
276 percent
= find_percent (pattern
);
278 return streq (pattern
, word
);
281 sfxlen
= strlen (percent
+ 1);
282 wordlen
= strlen (word
);
284 if (wordlen
< (percent
- pattern
) + sfxlen
285 || strncmp (pattern
, word
, percent
- pattern
))
288 return !strcmp (percent
+ 1, word
+ (wordlen
- sfxlen
));
291 int shell_function_pid
= 0, shell_function_completed
;
293 /* Perform the function specified by FUNCTION on the text at TEXT.
294 END is points to the end of the argument text (exclusive).
295 The output is written into VARIABLE_BUFFER starting at O. */
297 /* Note this absorbs a semicolon and is safe to use in conditionals. */
298 #define BADARGS(func) \
299 if (reading_filename != 0) \
300 makefile_fatal (reading_filename, *reading_lineno_ptr, \
301 "insufficient arguments to function `%s'", \
304 fatal ("insufficient arguments to function `%s'", func)
307 expand_function (o
, function
, text
, end
)
309 enum function function
;
317 char endparen
= *end
, startparen
= *end
== ')' ? '(' : '{';
332 /* Expand the command line. */
333 text
= expand_argument (text
, end
);
335 /* Construct the argument list. */
336 argv
= construct_command_argv (text
, (char *) NULL
, (struct file
*) 0);
340 /* Using a target environment for `shell' loses in cases like:
341 export var = $(shell echo foobie)
342 because target_environment hits a loop trying to expand $(var)
343 to put it in the environment. This is even more confusing when
344 var was not explicitly exported, but just appeared in the
345 calling environment. */
349 /* Construct the environment. */
350 envp
= target_environment ((struct file
*) 0);
353 /* For error messages. */
354 if (reading_filename
!= 0)
356 error_prefix
= (char *) alloca (strlen (reading_filename
) + 100);
357 sprintf (error_prefix
,
358 "%s:%u: ", reading_filename
, *reading_lineno_ptr
);
363 if (pipe (pipedes
) < 0)
365 perror_with_name (error_prefix
, "pipe");
371 perror_with_name (error_prefix
, "fork");
373 child_execute_job (0, pipedes
[1], argv
, envp
);
376 /* We are the parent. */
382 /* Free the storage only the child needed. */
384 free ((char *) argv
);
385 for (i
= 0; envp
[i
] != 0; ++i
)
387 free ((char *) envp
);
389 /* Record the PID for reap_children. */
390 shell_function_pid
= pid
;
391 shell_function_completed
= 0;
394 /* Set up and read from the pipe. */
397 buffer
= (char *) xmalloc (maxlen
+ 1);
399 /* Close the write side of the pipe. */
400 (void) close (pipedes
[1]);
402 /* Read from the pipe until it gets EOF. */
409 buffer
= (char *) xrealloc (buffer
, maxlen
+ 1);
413 cc
= read (pipedes
[0], &buffer
[i
], maxlen
- i
);
418 while (cc
> 0 || errno
== EINTR
);
423 /* Close the read side of the pipe. */
424 (void) close (pipedes
[0]);
426 /* Loop until child_handler sets shell_function_completed
427 to the status of our child shell. */
428 while (shell_function_completed
== 0)
429 reap_children (1, 0);
431 shell_function_pid
= 0;
433 /* The child_handler function will set shell_function_completed
434 to 1 when the child dies normally, or to -1 if it
435 dies with status 127, which is most likely an exec fail. */
437 if (shell_function_completed
== -1)
439 /* This most likely means that the execvp failed,
440 so we should just write out the error message
441 that came in over the pipe from the child. */
442 fputs (buffer
, stderr
);
447 /* The child finished normally. Replace all
448 newlines in its output with spaces, and put
449 that in the variable output buffer. */
452 if (buffer
[i
- 1] == '\n')
457 while ((p
= index (p
, '\n')) != 0)
459 o
= variable_buffer_output (o
, buffer
, i
);
470 case function_origin
:
471 /* Expand the argument. */
472 text
= expand_argument (text
, end
);
475 register struct variable
*v
= lookup_variable (text
, strlen (text
));
477 o
= variable_buffer_output (o
, "undefined", 9);
486 o
= variable_buffer_output (o
, "default", 7);
489 o
= variable_buffer_output (o
, "environment", 11);
492 o
= variable_buffer_output (o
, "file", 4);
495 o
= variable_buffer_output (o
, "environment override", 20);
498 o
= variable_buffer_output (o
, "command line", 12);
501 o
= variable_buffer_output (o
, "override", 8);
504 o
= variable_buffer_output (o
, "automatic", 9);
513 /* Expand the argument. */
514 text
= expand_argument (text
, end
);
517 char **words
= (char **) xmalloc (10 * sizeof (char *));
518 unsigned int nwords
= 10;
519 register unsigned int wordi
= 0;
522 /* Chop TEXT into words and put them in WORDS. */
524 while ((p
= find_next_token (&t
, &len
)) != 0)
526 if (wordi
>= nwords
- 1)
529 words
= (char **) xrealloc ((char *) words
,
530 nwords
* sizeof (char *));
532 words
[wordi
++] = savestring (p
, len
);
537 /* Now sort the list of words. */
538 qsort ((char *) words
, wordi
, sizeof (char *), alpha_compare
);
540 /* Now write the sorted list. */
541 for (i
= 0; i
< wordi
; ++i
)
543 len
= strlen (words
[i
]);
544 if (i
== wordi
- 1 || strlen (words
[i
+ 1]) != len
545 || strcmp (words
[i
], words
[i
+ 1]))
547 o
= variable_buffer_output (o
, words
[i
], len
);
548 o
= variable_buffer_output (o
, " ", 1);
552 /* Kill the last space. */
556 free ((char *) words
);
562 case function_foreach
:
564 /* Get three comma-separated arguments but
565 expand only the first two. */
567 register struct variable
*v
;
570 for (p
= text
; p
< end
; ++p
)
572 if (*p
== startparen
)
574 else if (*p
== endparen
)
576 else if (*p
== ',' && count
<= 0)
581 var
= expand_argument (text
, p
);
585 for (p
= p2
; p
< end
; ++p
)
587 if (*p
== startparen
)
589 else if (*p
== endparen
)
591 else if (*p
== ',' && count
<= 0)
596 list
= expand_argument (p2
, p
);
599 text
= savestring (p
, end
- p
);
601 push_new_variable_scope ();
602 v
= define_variable (var
, strlen (var
), "", o_automatic
, 0);
604 while ((p
= find_next_token (&p3
, &len
)) != 0)
610 result
= allocated_variable_expand (text
);
613 o
= variable_buffer_output (o
, result
, strlen (result
));
614 o
= variable_buffer_output (o
, " ", 1);
619 /* Kill the last space. */
622 pop_variable_scope ();
630 case function_filter
:
631 case function_filter_out
:
638 } *words
, *wordtail
, *wp
;
640 /* Get two comma-separated arguments and expand each one. */
642 for (p
= text
; p
< end
; ++p
)
644 if (*p
== startparen
)
646 else if (*p
== endparen
)
648 else if (*p
== ',' && count
<= 0)
652 BADARGS (function
== function_filter
? "filter" : "filter-out");
653 p2
= expand_argument (text
, p
);
655 text
= expand_argument (p
+ 1, end
);
657 /* Chop TEXT up into words and then run each pattern through. */
658 words
= wordtail
= 0;
660 while ((p
= find_next_token (&p3
, &len
)) != 0)
662 struct word
*w
= (struct word
*) alloca (sizeof (struct word
));
680 /* Run each pattern through the words, killing words. */
682 while ((p
= find_next_token (&p3
, &len
)) != 0)
688 percent
= find_percent (p
);
689 for (wp
= words
; wp
!= 0; wp
= wp
->next
)
690 wp
->matched
|= (percent
== 0 ? streq (p
, wp
->word
)
691 : pattern_matches (p
, percent
, wp
->word
));
696 /* Output the words that matched (or didn't, for filter-out). */
697 for (wp
= words
; wp
!= 0; wp
= wp
->next
)
698 if (function
== function_filter
? wp
->matched
: !wp
->matched
)
700 o
= variable_buffer_output (o
, wp
->word
, strlen (wp
->word
));
701 o
= variable_buffer_output (o
, " ", 1);
705 /* Kill the last space. */
714 case function_patsubst
:
715 /* Get three comma-separated arguments and expand each one. */
717 for (p
= text
; p
< end
; ++p
)
719 if (*p
== startparen
)
721 else if (*p
== endparen
)
723 else if (*p
== ',' && count
<= 0)
727 BADARGS ("patsubst");
731 for (++p
; p
< end
; ++p
)
733 if (*p
== startparen
)
735 else if (*p
== endparen
)
737 else if (*p
== ',' && count
<= 0)
741 BADARGS ("patsubst");
743 text
= expand_argument (text
, p2
);
744 p3
= expand_argument (p2
+ 1, p
);
745 p2
= expand_argument (p
+ 1, end
);
747 o
= patsubst_expand (o
, p2
, text
, p3
, (char *) 0, (char *) 0);
755 /* Get two comma-separated arguments and expand each one. */
757 for (p
= text
; p
< end
; ++p
)
759 if (*p
== startparen
)
761 else if (*p
== endparen
)
763 else if (*p
== ',' && count
<= 0)
768 text
= expand_argument (text
, p
);
770 p
= expand_argument (p
+ 1, end
);
773 /* Write each word of the first argument directly followed
774 by the corresponding word of the second argument.
775 If the two arguments have a different number of words,
776 the excess words are just output separated by blanks. */
777 register char *tp
, *pp
;
782 unsigned int tlen
, plen
;
784 tp
= find_next_token (&p2
, &tlen
);
786 o
= variable_buffer_output (o
, tp
, tlen
);
788 pp
= find_next_token (&p3
, &plen
);
790 o
= variable_buffer_output (o
, pp
, plen
);
792 if (tp
!= 0 || pp
!= 0)
794 o
= variable_buffer_output (o
, " ", 1);
798 while (tp
!= 0 || pp
!= 0);
800 /* Kill the last blank. */
809 /* Expand the argument. */
810 text
= expand_argument (text
, end
);
813 while ((p
= find_next_token (&p2
, &i
)) != 0)
815 o
= variable_buffer_output (o
, p
, i
);
816 o
= variable_buffer_output (o
, " ", 1);
820 /* Kill the last space. */
826 case function_wildcard
:
827 text
= expand_argument (text
, end
);
829 p
= string_glob (text
);
830 o
= variable_buffer_output (o
, p
, strlen (p
));
836 /* Get three comma-separated arguments and expand each one. */
838 for (p
= text
; p
< end
; ++p
)
840 if (*p
== startparen
)
842 else if (*p
== endparen
)
844 else if (*p
== ',' && count
<= 0)
852 for (++p
; p
< end
; ++p
)
854 if (*p
== startparen
)
856 else if (*p
== endparen
)
858 else if (*p
== ',' && count
<= 0)
864 text
= expand_argument (text
, p2
);
865 p3
= expand_argument (p2
+ 1, p
);
866 p2
= expand_argument (p
+ 1, end
);
868 o
= subst_expand (o
, p2
, text
, p3
, strlen (text
), strlen (p3
), 0, 0);
875 case function_firstword
:
876 /* Expand the argument. */
877 text
= expand_argument (text
, end
);
879 /* Find the first word in TEXT. */
881 p
= find_next_token (&p2
, &i
);
883 o
= variable_buffer_output (o
, p
, i
);
889 /* Get two comma-separated arguments and expand each one. */
891 for (p
= text
; p
< end
; ++p
)
893 if (*p
== startparen
)
895 else if (*p
== endparen
)
897 else if (*p
== ',' && count
<= 0)
902 text
= expand_argument (text
, p
);
904 p3
= expand_argument (p
+ 1, end
);
906 /* Check the first argument. */
907 for (p2
= text
; *p2
!= '\0'; ++p2
)
908 if (*p2
< '0' || *p2
> '9')
910 if (reading_filename
!= 0)
911 makefile_fatal (reading_filename
, *reading_lineno_ptr
,
912 "non-numeric first argument to `word' function");
914 fatal ("non-numeric first argument to `word' function");
917 i
= (unsigned int) atoi (text
);
920 if (reading_filename
!= 0)
921 makefile_fatal (reading_filename
, *reading_lineno_ptr
,
922 "the `word' function takes a one-origin \
925 fatal ("the `word' function takes a one-origin index argument");
929 while ((p
= find_next_token (&p2
, &len
)) != 0)
933 o
= variable_buffer_output (o
, p
, len
);
940 /* Expand the argument. */
941 text
= expand_argument (text
, end
);
945 while (find_next_token (&p2
, (unsigned int *) 0) != 0)
950 sprintf (buf
, "%d", i
);
951 o
= variable_buffer_output (o
, buf
, strlen (buf
));
957 case function_findstring
:
958 /* Get two comma-separated arguments and expand each one. */
960 for (p
= text
; p
< end
; ++p
)
962 if (*p
== startparen
)
964 else if (*p
== endparen
)
966 else if (*p
== ',' && count
<= 0)
970 BADARGS ("findstring");
971 text
= expand_argument (text
, p
);
973 p
= expand_argument (p
+ 1, end
);
975 /* Find the first occurrence of the first string in the second. */
977 if (sindex (p
, 0, text
, i
) != 0)
978 o
= variable_buffer_output (o
, text
, i
);
984 case function_addsuffix
:
985 case function_addprefix
:
986 /* Get two comma-separated arguments and expand each one. */
988 for (p
= text
; p
< end
; ++p
)
990 if (*p
== startparen
)
992 else if (*p
== endparen
)
994 else if (*p
== ',' && count
<= 0)
998 BADARGS (function
== function_addsuffix
? "addsuffix" : "addprefix");
999 text
= expand_argument (text
, p
);
1002 p2
= expand_argument (p
+ 1, end
);
1005 while ((p
= find_next_token (&p3
, &len
)) != 0)
1007 if (function
== function_addprefix
)
1008 o
= variable_buffer_output (o
, text
, i
);
1009 o
= variable_buffer_output (o
, p
, len
);
1010 if (function
== function_addsuffix
)
1011 o
= variable_buffer_output (o
, text
, i
);
1012 o
= variable_buffer_output (o
, " ", 1);
1016 /* Kill last space. */
1024 case function_basename
:
1025 /* Expand the argument. */
1026 text
= expand_argument (text
, end
);
1029 while ((p2
= find_next_token (&p3
, &len
)) != 0)
1032 while (p
>= p2
&& *p
!= (function
== function_dir
? '/' : '.'))
1036 if (function
== function_dir
)
1038 o
= variable_buffer_output (o
, p2
, p
- p2
);
1040 else if (function
== function_dir
)
1041 o
= variable_buffer_output (o
, "./", 2);
1043 /* The entire name is the basename. */
1044 o
= variable_buffer_output (o
, p2
, len
);
1046 o
= variable_buffer_output (o
, " ", 1);
1050 /* Kill last space. */
1056 case function_notdir
:
1057 case function_suffix
:
1058 /* Expand the argument. */
1059 text
= expand_argument (text
, end
);
1062 while ((p2
= find_next_token (&p3
, &len
)) != 0)
1065 while (p
>= p2
&& *p
!= (function
== function_notdir
? '/' : '.'))
1069 if (function
== function_notdir
)
1071 o
= variable_buffer_output (o
, p
, len
- (p
- p2
));
1073 else if (function
== function_notdir
)
1074 o
= variable_buffer_output (o
, p2
, len
);
1076 if (function
== function_notdir
|| p
>= p2
)
1078 o
= variable_buffer_output (o
, " ", 1);
1083 /* Kill last space. */
1093 /* Check for a function invocation in *STRINGP. *STRINGP points at the
1094 opening ( or { and is not null-terminated. If a function invocation
1095 is found, expand it into the buffer at *OP, updating *OP, incrementing
1096 *STRINGP past the reference and returning nonzero. If not, return zero. */
1099 handle_function (op
, stringp
)
1104 register unsigned int code
;
1105 unsigned int maxlen
;
1106 char *beg
= *stringp
+ 1;
1109 endref
= lindex (beg
, beg
+ MAXFUNCTIONLEN
, '\0');
1110 maxlen
= endref
!= 0 ? endref
- beg
: MAXFUNCTIONLEN
;
1112 for (code
= 0; function_table
[code
].name
!= 0; ++code
)
1114 if (maxlen
< function_table
[code
].len
)
1116 endref
= beg
+ function_table
[code
].len
;
1117 if (isblank (*endref
)
1118 && !strncmp (function_table
[code
].name
, beg
,
1119 function_table
[code
].len
))
1122 if (function_table
[code
].name
!= 0)
1124 /* We have found a call to an expansion-time function.
1125 Find the end of the arguments, and do the function. */
1127 char openparen
= beg
[-1], closeparen
= openparen
== '(' ? ')' : '}';
1132 /* Space after function name isn't part of the args. */
1133 p
= next_token (endref
);
1136 /* Count nested use of whichever kind of parens we use,
1137 so that nested calls and variable refs work. */
1139 for (; *p
!= '\0'; ++p
)
1141 if (*p
== openparen
)
1143 else if (*p
== closeparen
&& --count
< 0)
1149 static const char errmsg
[]
1150 = "unterminated call to function `%s': missing `%c'";
1151 if (reading_filename
== 0)
1152 fatal (errmsg
, function_table
[code
].name
, closeparen
);
1154 makefile_fatal (reading_filename
, *reading_lineno_ptr
, errmsg
,
1155 function_table
[code
].name
, closeparen
);
1158 /* We found the end; expand the function call. */
1160 *op
= expand_function (*op
, function_table
[code
].function
, argbeg
, p
);
1168 /* Glob-expand LINE. The returned pointer is
1169 only good until the next call to string_glob. */
1175 static char *result
= 0;
1176 static unsigned int length
;
1177 register struct nameseq
*chain
;
1178 register unsigned int idx
;
1180 chain
= multi_glob (parse_file_seq
1181 (&line
, '\0', sizeof (struct nameseq
),
1182 /* We do not want parse_file_seq to strip `./'s.
1183 That would break examples like:
1184 $(patsubst ./%.c,obj/%.o,$(wildcard ./*.c)). */
1186 sizeof (struct nameseq
));
1191 result
= (char *) xmalloc (100);
1197 register char *name
= chain
->name
;
1198 unsigned int len
= strlen (name
);
1200 struct nameseq
*next
= chain
->next
;
1201 free ((char *) chain
);
1204 /* multi_glob will pass names without globbing metacharacters
1205 through as is, but we want only files that actually exist. */
1206 if (file_exists_p (name
))
1208 if (idx
+ len
+ 1 > length
)
1210 length
+= (len
+ 1) * 2;
1211 result
= (char *) xrealloc (result
, length
);
1213 bcopy (name
, &result
[idx
], len
);
1215 result
[idx
++] = ' ';
1221 /* Kill the last space and terminate the string. */
1225 result
[idx
- 1] = '\0';