Makefile 用两个目标调用make 我有一个C++项目,我使用一个Mag文件来构建,它有两个目标,所以 debug: FLAGS += -g3 -DDEBUG -DSOCKET_LOG_COMMUNICATION @printf "" test: some_other_target $(COMPILER) ...

Makefile 用两个目标调用make 我有一个C++项目,我使用一个Mag文件来构建,它有两个目标,所以 debug: FLAGS += -g3 -DDEBUG -DSOCKET_LOG_COMMUNICATION @printf "" test: some_other_target $(COMPILER) ...,makefile,Makefile,我想打电话叫make make debug test 定义宏并生成测试目标。这是可能的吗?特定于目标的变量仅适用于命名的目标及其依赖项(除非该变量声明为private),因此您能够让test继承debug的变量的唯一方法是debug:test,这可能不是您想要的 一种方法是使用条件语句: ifdef debug FLAGS += -g3 -DDEBUG -DSOCKET_LOG_COMMUNICATION $(info whatever) endif test: some_other_tar

我想打电话叫make

make debug test

定义宏并生成测试目标。这是可能的吗?

特定于目标的变量仅适用于命名的目标及其依赖项(除非该变量声明为
private
),因此您能够让
test
继承
debug
的变量的唯一方法是
debug:test
,这可能不是您想要的

一种方法是使用条件语句:

ifdef debug
FLAGS += -g3 -DDEBUG -DSOCKET_LOG_COMMUNICATION
$(info whatever)
endif

test: some_other_target
    $(COMPILER) ...

并调用
make test debug=1

为什么不简单地让另一个目标
debug test
依赖于这两个目标?@πάνταῥεῖ 这就是我现在拥有的!我只是想知道这是否是实现不同编译模式的好方法: