我有以下Makefile:
all: foo/bar/baz
foo/%:
@echo $(VAR)
cp $@.in $@
# This works
foo/bar/%: VAR := Hello world
# This doesn't
foo/bar/%: foo/bar/%.in
foo/bar/baz.in:
touch $@
当我运行它时,输出是
Hello world
cp foo/bar/baz.in foo/bar/baz
cp: cannot stat ‘foo/bar/baz.in’: No such file or directory
Makefile:4: recipe for target 'foo/bar/baz' failed
make: *** [foo/bar/baz] Error 1
换句话说,pattern-specific variable rule有效,但声明额外先决条件的等效语法并不适用。我该怎么做呢?
真正的用例是在构建之前复制标头。我写了
obj/subdir/%.o: CPPFLAGS += -Igen/include
obj/subdir/%.o: | gen/include
gen/include:
# Copy the headers
但标题不会被复制。