假设我有以下文件:
.: 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.src
和include/01*.inc
进行编译(类似于02.exe
和03.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.src
,02.src
和03.src
重命名为01-first.src
,02-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
答案 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