我需要什么:
all: release debug
release: compile
debug: compile
compile:
if parent_target_name = release:
$(CXXFLAGS) = for rel
else: $(CXXFLAGS) = for deb
问题: 如何检查调用当前目标的目标的名称?
我已经看到了这个问题GNU Make get parent target name,但没有帮助。
答案 0 :(得分:0)
您可能正在寻找的是Target-specific Variable Values。如果您仔细阅读本手册的这一部分,将会看到它们如何传播到先决条件。
仅说明它们如何工作:
.PHONY: all release debug compile
all:
$(MAKE) release
$(MAKE) debug
release: CXXFLAGS = for rel
debug: CXXFLAGS = for deb
release debug: compile
@echo 'building $@ with CXXFLAGS = $(CXXFLAGS)'
compile: a b c
@echo 'building $@ with CXXFLAGS = $(CXXFLAGS)'
a b c:
@echo 'building $@ with CXXFLAGS = $(CXXFLAGS)'
演示:
$ make --no-print-directory all
make release
building a with CXXFLAGS = for rel
building b with CXXFLAGS = for rel
building c with CXXFLAGS = for rel
building compile with CXXFLAGS = for rel
building release with CXXFLAGS = for rel
make debug
building a with CXXFLAGS = for deb
building b with CXXFLAGS = for deb
building c with CXXFLAGS = for deb
building compile with CXXFLAGS = for deb
building debug with CXXFLAGS = for deb