makefile根据来源

时间:2017-06-04 04:33:28

标签: makefile

假设我有以下文件:

.:           include/  01.src  02.src  03.src  Makefile

./include:   01.inc  02-source1.inc  02-source2.inc

我有以下Makefile(来源:Complex pattern rule in Makefile):

exe = ${patsubst %.src, %.exe, ${wildcard *.src}}

all : ${exe}

.SECONDEXPANSION:
${exe} : %.exe : %.src $${wildcard include/%*.inc}
    @echo compile $@ using $^

这表示01.exe将使用01.srcinclude/01*.inc进行编译(类似于02.exe03.exe)。实际上,输出:

compile 01.exe using 01.src include/01.inc
compile 02.exe using 02.src include/02-source1.inc include/02-source2.inc
compile 03.exe using 03.src

我的问题是:如果01.src02.src03.src重命名为01-first.src02-second.src,我该如何修改此Makefile,和03-third.src所需的输出是:

compile 01-first.exe using 01-first.src include/01.inc
compile 02-second.exe using 02-second.src include/02-source1.inc include/02-source2.inc
compile 03-third.exe using 03-third.src

1 个答案:

答案 0 :(得分:1)

试试这个:

${exe} : %.exe : %.src $${wildcard include/$$(shell echo % | head -c 2)*.inc}
    @echo compile $@ using $^

输出:

compile 03-third.exe using 03-third.src
compile 02-second.exe using 02-second.src include/02-source1.inc include/02-source2.inc
compile 01-first.exe using 01-first.src include/01.inc