目标特定变量作为

目标特定变量作为

本文介绍了目标特定变量作为 Makefile 中的先决条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个具有类似目标负载的 GNU make Makefile,其中构建命令在它们之间略有不同.我正在尝试使用 target-特定变量来表示这些变化.其中一些变量值指的是我想用作先决条件的文件.例如:

target_1:special_filename=target1_prereqtarget_2:special_filename=target2_prereqtarget_1 target_2: common_filename $(special_filename)do_something common_filename --a-weird-option=$(special_filename)

当我调用make target_1"时,如果它不存在,我希望它生成 target1_prereq.目前,它似乎没有使用 target1_prereq 作为先决条件,即使使用正确的参数调用构建命令 (do_something).

我使用的是 GNU Make 3.80.

来自真实系统的更多并发症.一些变量本身基于其他变量的值.手动指定先决条件不会扩展.一个稍微复杂一点的例子:

target_1:special_filename_base=target1_prereqtarget_2:special_filename_base=target2_prereqsome_filename_a = $(special_filename_base).extasome_filename_b = $(special_filename_base).extbtarget_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)
解决方案

特定于目标的变量仅在目标的命令(或其他特定于目标的赋值)中定义;它不能用作目标的先决条件之一.我认为在 Make 中没有一种干净的方法可以做你想做的事,但有几种笨拙的方法,例如:

扩展名 = .exta .extbtarget_1: $(addprefix target1_prereq,$(EXTENSIONS))target_2: $(addprefix target2_prereq,$(EXTENSIONS))target_1 target_2:common_filenamedo_something common_filename --a-weird-option=$(filter %.exta,$^) --second=$(filter %.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,$^)

这篇关于目标特定变量作为 Makefile 中的先决条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 07:21