特定目标变量为prerequisites在一个Makefile [英] Target-specific Variables as Prerequisites in a Makefile
问题描述
我想写一个GNU使Makefile文件里面有类似的目标,在构建命令它们之间略有不同的负载。
我试图使用特定目标变量来重新present这些变化。其中的一些变量值的参考我想为prerequisites使用的文件。例如:
target_1:special_filename = target1_ preREQ
target_2:special_filename = target2_ preREQtarget_1 target_2:common_filename $(special_filename)
do_something common_filename --a-怪异选项= $(special_filename)
当我称之为做target_1',我想它做target1_ preREQ如果它不存在。目前,它似乎并没有使用target1_ preREQ为prerequisite,即使build命令(do_something)被调用合适的参数。
我使用GNU做3.80。
编辑:
一些并发症多从实际系统。是一些变量本身基于其它变量的值。手动指定prerequisites无法扩展。
稍微复杂一点的例子:
target_1:special_filename_base = target1_ preREQ
target_2:special_filename_base = target2_ preREQsome_filename_a = $(special_filename_base).exta
some_filename_b = $(special_filename_base).extbtarget_1 target_2:common_filename $(special_filename_b)$(special_filename_a)
do_something common_filename --a-怪异选项= $(special_filename_a)--second = $(special_filename_b)
一个特定目标变量在目标的命令只能定义(或其他特定目标的任务);它不能被用作靶的prereqs之一。我不认为有一个干净的方式做你制作想要的东西,但有几个kludgey方式,如下面的:
EXTENSIONS = .exta .extb
target_1:$(添加preFIX target1_ preREQ,$(扩展))
target_2:$(添加preFIX target2_ preREQ,$(扩展))target_1 target_2:common_filename
do_something common_filename --a-怪异选项= $(过滤%.exta,$ ^)--second = $(过滤%.extb,$ ^)
I'm trying to write a GNU make Makefile which has a load of similar targets, where the build commands vary slightly between them. I'm trying to use target-specific variables to represent these variations. Some of these variable values refer to files I want to use as prerequisites. For example:
target_1:special_filename=target1_prereq
target_2:special_filename=target2_prereq
target_1 target_2: common_filename $(special_filename)
do_something common_filename --a-weird-option=$(special_filename)
When I call 'make target_1', I want it to make target1_prereq if it doesn't exist. At the moment, it doesn't seem to use target1_prereq as a prerequisite, even though the build command (do_something) is called with the right parameter.
I'm using GNU Make 3.80.
Edit: A few more complications from the real system. Some of the variables are themselves based on the values of other variables. Manually specifying the prerequisites wouldn't scale. A slightly more complicated example:
target_1:special_filename_base=target1_prereq
target_2:special_filename_base=target2_prereq
some_filename_a = $(special_filename_base).exta
some_filename_b = $(special_filename_base).extb
target_1 target_2: common_filename $(special_filename_b) $(special_filename_a)
do_something common_filename --a-weird-option=$(special_filename_a) --second=$(special_filename_b)
A target-specific variable is defined only in the target's commands (or in other target-specific assignments); it can't be used as one of the target's prereqs. I don't think there's a clean way to do what you want in Make, but there are several kludgey approaches, such as the following:
EXTENSIONS = .exta .extb target_1: $(addprefix target1_prereq,$(EXTENSIONS)) target_2: $(addprefix target2_prereq,$(EXTENSIONS)) target_1 target_2: common_filename do_something common_filename --a-weird-option=$(filter %.exta,$^) --second=$(filter %.extb,$^)
这篇关于特定目标变量为prerequisites在一个Makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!