makefile - GNU Makefile 中当前目标的父目标名称
问题描述
我需要的:
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但它没有帮助。
解决方案
您可能正在寻找的是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
推荐阅读
- facebook - 在 Facebook 调试器上获取 404 共享链接,尽管它显示了所有元标记
- java - 即使在抛出标记为 rollBackFor 的异常之后,是否可以防止外部事务上下文回滚?
- javascript - javascript - 一次替换多个文本
- json - 如何在 golang 或一般类型的语言中处理 JSON 响应中的不同类型
- c# - 我可以在 System.Speech.Synthesis 中使用 Microsoft 语音以外的语音吗
- python - 如何用 Python 制作一个有生命的游戏?
- postgresql - 在函数中加密密码不起作用 - postgres
- c# - 即使站点未运行或导致站点始终处于活动状态,也使计时器工作
- c# - 如何将文件(内容)从 Angular 5 应用程序传递到 C# .NET Web Api 2?
- c# - 在卸载 Wix 时删除整个用户帐户足迹