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

前端 未结 2 1856
眼角桃花
眼角桃花 2021-01-22 03:53

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

2条回答
  •  有刺的猬
    2021-01-22 04:16

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

提交回复
热议问题