if (p == 0)
break; /* No more words */
- /* If the dependency name has %, substitute the stem.
- Watch out, we are going to do something tricky here. If
- we just replace % with the stem value, later, when we do
- the second expansion, we will re-expand this stem value
- once again. This is not good especially if you have
- certain characters in your stem (like $).
-
- Instead, we will replace % with $* and allow the second
- expansion to take care of it for us. This way (since $*
- is a simple variable) there won't be additional
- re-expansion of the stem. */
+ /* Is there a pattern in this prerequisite? */
for (p2 = p; p2 < p + len && *p2 != '%'; ++p2)
;
- if (p2 < p + len)
+ if (dep->need_2nd_expansion)
{
- register unsigned int i = p2 - p;
- bcopy (p, depname, i);
- bcopy ("$*", depname + i, 2);
- bcopy (p2 + 1, depname + i + 2, len - i - 1);
- depname[len + 2 - 1] = '\0';
+ /* If the dependency name has %, substitute the stem.
- if (check_lastslash)
- add_dir = 1;
+ Watch out, we are going to do something tricky
+ here. If we just replace % with the stem value,
+ later, when we do the second expansion, we will
+ re-expand this stem value once again. This is not
+ good especially if you have certain characters in
+ your stem (like $).
- had_stem = 1;
+ Instead, we will replace % with $* and allow the
+ second expansion to take care of it for us. This way
+ (since $* is a simple variable) there won't be
+ additional re-expansion of the stem. */
+
+ if (p2 < p + len)
+ {
+ register unsigned int i = p2 - p;
+ bcopy (p, depname, i);
+ bcopy ("$*", depname + i, 2);
+ bcopy (p2 + 1, depname + i + 2, len - i - 1);
+ depname[len + 2 - 1] = '\0';
+
+ if (check_lastslash)
+ add_dir = 1;
+
+ had_stem = 1;
+ }
+ else
+ {
+ bcopy (p, depname, len);
+ depname[len] = '\0';
+ }
+
+ p2 = variable_expand_for_file (depname, file);
}
else
{
- bcopy (p, depname, len);
- depname[len] = '\0';
- }
+ if (p2 < p + len)
+ {
+ register unsigned int i = p2 - p;
+ bcopy (p, depname, i);
+ bcopy (stem_str, depname + i, stemlen);
+ bcopy (p2 + 1, depname + i + stemlen, len - i - 1);
+ depname[len + stemlen - 1] = '\0';
+
+ if (check_lastslash)
+ add_dir = 1;
+
+ had_stem = 1;
+ }
+ else
+ {
+ bcopy (p, depname, len);
+ depname[len] = '\0';
+ }
- p2 = variable_expand_for_file (depname, file);
+ p2 = depname;
+ }
/* Parse the dependencies. */
# Test #1: automatic variables.
#
run_make_test('
+.SECONDEXPANSION:
.DEFAULT: ; @echo $@
foo.a: bar baz
# Test #2: target/pattern -specific variables.
#
run_make_test('
+.SECONDEXPANSION:
foo.x:
foo.%: $$(%_a) $$(%_b) bar
# Test #3: order of prerequisites.
#
run_make_test('
+.SECONDEXPANSION:
.DEFAULT: ; @echo $@
all: foo bar baz
# Test #4: stem splitting logic.
#
run_make_test('
+.SECONDEXPANSION:
$(dir)/tmp/bar.o:
$(dir)/tmp/foo/bar.c: ; @echo $@
# Test #5: stem splitting logic and order-only prerequisites.
#
run_make_test('
+.SECONDEXPANSION:
$(dir)/tmp/foo.o: $(dir)/tmp/foo.c
$(dir)/tmp/foo.c: ; @echo $@
bar.h: ; @echo $@
# Test #6: lack of implicit prerequisites.
#
run_make_test('
+.SECONDEXPANSION:
foo.o: foo.c
foo.c: ; @echo $@
# Test #7: Test stem from the middle of the name.
#
run_make_test('
+.SECONDEXPANSION:
foobarbaz:
foo%baz: % $$*.1
# Test #8: Make sure stem triple-expansion does not happen.
#
run_make_test('
+.SECONDEXPANSION:
foo$$bar:
f%r: % $$*.1
'',
"baz\$bar\ndone baz\$bar");
+
+# Test implicit rules with '$' in the name (see se_implicit)
+# Use the '$' in the pattern.
+
+run_make_test(q!
+%.foo : %$$bar ; @echo 'done $<'
+test.foo:
+test$$bar: ; @echo '$@'
+!,
+ '',
+ "test\$bar\ndone test\$bar");
+
+# Make sure that subdirectories built as prerequisites are actually handled
+# properly... this time with '$'
+
+run_make_test(q!
+
+all: dir/subdir/file.$$a
+
+dir/subdir: ; @echo mkdir -p '$@'
+
+dir/subdir/file.$$b: dir/subdir ; @echo touch '$@'
+
+dir/subdir/%.$$a: dir/subdir/%.$$b ; @echo 'cp $< $@'
+!,
+ '', "mkdir -p dir/subdir\ntouch dir/subdir/file.\$b\ncp dir/subdir/file.\$b dir/subdir/file.\$a\n");
+
1;