Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match double stem in target like %/% or other way?

I need to build targets with names like,

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

I want to match the thread% and v%, because for my code, the threadNum=? and the Version=? are the Macros need to define in the compile time. so in the result, I hope to get a layout like, and the foo is the executable name

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

I've tried ways like, it doesn't work

%/%/foo: foo.cc $(HEADERS)
    $(CXX) $(CXXFLAGS) -DTHREAD=$* -o $@ $< $(LDLIBS)
like image 304
Y00 Avatar asked Jan 20 '26 04:01

Y00


2 Answers

It's pretty easy when you realise that $@ is v1/thread4/foo (say), to then pull out the bits you need.

In this case, something like:

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

YMMV of course. leading to

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}]'

giving

$ 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]'
like image 151
bobbogo Avatar answered Jan 21 '26 20:01

bobbogo


There is no way to have multiple patterns in GNU make.

If your example above is actually reflective of what you want to do, it's simple enough, though:

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)
like image 45
MadScientist Avatar answered Jan 21 '26 20:01

MadScientist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!