gpt4 book ai didi

makefile - 如何匹配目标中的双词干,如 %/% 或其他方式?

转载 作者:行者123 更新时间:2023-12-05 03:57:42 25 4
gpt4 key购买 nike

我需要用像这样的名字来构建目标,

v1/thread4/foo  v1/thread8/foo v1/thread16/foo
v2/thread4/foo v2/thread8/foo v2/thread16/foo

我想匹配 thread%v%,因为对于我的代码,threadNum=?和版本=?是编译时需要定义的宏。所以在结果中,我希望得到这样的布局,foo 是可执行文件的名称

v1-|thead4/foo
|thead8/foo
|thead16/foo
v2-|thead4/foo
|thead8/foo
|thead16/foo

各种方法都试过了,还是不行

%/%/foo: foo.cc $(HEADERS)
$(CXX) $(CXXFLAGS) -DTHREAD=$* -o $@ $< $(LDLIBS)

最佳答案

当你意识到 $@v1/thread4/foo 时就很容易了(比方说),然后拉出你需要的部分。

在这种情况下,类似于:

v = $(firstword $(subst /, ,$@))
thread = $(notdir ${@D})

当然是 YMMV。导致

targets := \
v1/thread4/foo v1/thread8/foo v1/thread16/foo \
v2/thread4/foo v2/thread8/foo v2/thread16/foo

all: ${targets}

v = $(firstword $(subst /, ,$@))
thread = $(notdir ${@D})

${targets}:
: '$@: v [$v] thread [${thread}]'

给予

$ make
: 'v1/thread4/foo: v [v1] thread [thread4]'
: 'v1/thread8/foo: v [v1] thread [thread8]'
: 'v1/thread16/foo: v [v1] thread [thread16]'
: 'v2/thread4/foo: v [v2] thread [thread4]'
: 'v2/thread8/foo: v [v2] thread [thread8]'
: 'v2/thread16/foo: v [v2] thread [thread16]'

关于makefile - 如何匹配目标中的双词干,如 %/% 或其他方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58404646/

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