目标特定变量作为Makefile中的先决条件

目标特定变量作为Makefile中的先决条件

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

问题描述

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

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)

当我打电话给'make target_1'时,如果不存在,我想让它成为target1_prereq。目前,似乎没有使用target1_prereq作为前提条件,即使使用正确的参数调用构建命令(do_something)。

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.

我正在使用GNU Make 3.80。

I'm using GNU Make 3.80.

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

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)


推荐答案

目标特定变量仅在目标的命令(或其他目标特定的分配)中定义;它不能用作目标的prereqs之一。我不认为有一个干净的方法来做你想要的Make,但是有几种kludgey方法,如下所示:

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中的先决条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 20:33