Makefile:模式规则中可参数化的recepie命令
假设以下makefileMakefile:模式规则中可参数化的recepie命令,makefile,gnu-make,Makefile,Gnu Make,假设以下makefile objects = $(wildcard *.in) outputs := $(objects:.in=.txt) %.txt: %.in some-command $@ $< compile: $(outputs) objects=$(通配符*.in) 输出:=$(对象:.in=.txt) %.txt:%.in 一些命令$@$< 编译:$(输出) 这正如预期的那样有效 现在,我想添加另一个名为(例如)upgrade的目标,该目标应该执行与comp
objects = $(wildcard *.in)
outputs := $(objects:.in=.txt)
%.txt: %.in
some-command $@ $<
compile: $(outputs)
objects=$(通配符*.in)
输出:=$(对象:.in=.txt)
%.txt:%.in
一些命令$@$<
编译:$(输出)
这正如预期的那样有效
现在,我想添加另一个名为(例如)upgrade
的目标,该目标应该执行与compile
相同的操作,但将附加选项传递给some命令
(可能取决于环境变量,但这超出了这个问题的范围)
到目前为止,我发现的唯一“解决方案”是递归调用同一个makefile,并通过env变量传递附加选项。但这似乎是一个相当丑陋的黑客
我所追求的东西在make中是可能的(GNU很好,它不必是便携的)还是我只是走错了路
%.txt:%.in
@回显一些命令$(一些选项)$@$<
编译:$(输出)
升级:一些选项:=无论什么
升级:编译
太好了,正是我想要的。谢谢
%.txt: %.in
@echo some-command $(SOME_OPTIONS) $@ $<
compile: $(outputs)
upgrade: SOME_OPTIONS:=whatever
upgrade: compile