我有一个很大的makefile,我已经配置了几个虚假目标。一种用调试标志编译程序,一种用优化标志编译,等等。
我遇到的一个问题是,当您之前使用一个目标但后来指定另一个目标时,它不知道它需要使用新的一组标志重新编译所有文件。
例如,我使用调试目标编译所有内容。编译后我测试程序。没有看到任何问题,我尝试使用优化目标运行 make,但它什么也没编译,因为根据 Make 的计算,一切都是最新的。
我只是想使目标文件的位置取决于选择的目标,但除此之外我什么都没有。
有什么办法可以优雅地处理这个问题吗?
# Assuming you already know the type of new build
# and it is stored in this variable.
BUILD_TYPE := release
ifneq ($(MAKECMDGOALS),__clean)
# This file stores the type of the last build.
-include .last_build_type.mk
ifneq ($(__last_build_type),$(BUILD_TYPE))
.PHONY : .last_build_type.mk
.last_build_type.mk :
@$(MAKE) __clean
@echo '__last_build_type := $(BUILD_TYPE)' > $@
endif
else
.PHONY : __clean
__clean : clean # Delegate the job to your real 'clean' target.
endif
这种事情会被makepp自动捕获。