如何匹配目标中的双词干,如 %/% 或其他方式?
How to match double stem in target like %/% or other way?
我需要使用
这样的名称构建目标
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)
在 GNU make 中无法拥有多个模式。
如果您上面的示例实际上反映了您想要做的事情,那么它很简单:
VLIST := 1 2
TLIST := 4 8 16
TARGETS := $(foreach V,$(VLIST),$(foreach T,$(TLIST),v$V/thread$T/foo))
$(TARGETS): 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]'
我需要使用
这样的名称构建目标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)
在 GNU make 中无法拥有多个模式。
如果您上面的示例实际上反映了您想要做的事情,那么它很简单:
VLIST := 1 2
TLIST := 4 8 16
TARGETS := $(foreach V,$(VLIST),$(foreach T,$(TLIST),v$V/thread$T/foo))
$(TARGETS): 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]'