gpt4 book ai didi

makefile - GNU 制作 : build all sources in a different directory

转载 作者:行者123 更新时间:2023-12-01 02:49:51 25 4
gpt4 key购买 nike

鉴于:

programs := apps/prog1 apps/prog2        # the actual list is quite long
sources := src/prog1.cpp src/prog2.cpp # showing only 2 files

制作文件有 2 个目标 releasedebug .每个目标都应该在 bin/ 中构建每个程序目录并将目标名称附加到文件名。

例如,建筑 release应该创建 bin/prog1_releasebin/prog2_release .

如何编写静态模式规则来做到这一点?

谢谢。

最佳答案

这样做(在 GNUMake 3.81 中):

BINS := $(patsubst apps/%,bin/%,$(programs))   # bin/prog1 bin/prog2 ...
release_bins := $(addsuffix _release,$(BINS)) # bin/prog1_release ...
debug_bins := $(addsuffix _debug,$(BINS)) # bin/prog1_debug ...

$(release_bins): bin/%_release: src/%.cpp
#build the binaries according to the release rule

$(debug_bins): bin/%_debug: src/%.cpp
#build the binaries according to the debug rule

release: $(release_bins)

debug: $(debug_bins)

.PHONY: release debug

# If it turns out that one of the progs needs something else too:
bin/prog20_debug: somethingElse.cpp

(有一些方法可以使这更简洁一些,但要以清晰为代价。)

关于makefile - GNU 制作 : build all sources in a different directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5778495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com