%和*一起在依赖行上

Jon*_*off 5 makefile gnu-make

我很长一段时间一直在使用像这样的奇怪规则,但突然之间他们正在打破一个新的环境.

有没有一种强有力的方法来做到这一点?

all: test.1.out

test.%.out: %/test*.out
    /bin/cp -f $< $@
Run Code Online (Sandbox Code Playgroud)

在我的盒子上(ubuntu):

alishan:~/Dropbox/make_insanity> make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu
alishan:~/Dropbox/make_insanity> make
/bin/cp -f 1/test.out test.1.out
Run Code Online (Sandbox Code Playgroud)

在其他人的Mac,ubuntu机器,ubuntu虚拟机上使用这种代码没问题.不知道他们所有的make版本,但它似乎好的代码.

清除后在我的mageia服务器上的同一目录中.

[dushoff@yushan make_insanity]$ make --version
GNU Make 3.82
Built for x86_64-mageia-linux-gnu
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[dushoff@yushan make_insanity]$ make
make: *** No rule to make target `test.1.out', needed by `all'.  Stop.
[dushoff@yushan make_insanity]$ 
Run Code Online (Sandbox Code Playgroud)

更改任何%*以适当的文字"修复"的问题,当然不会产生预期的普遍性.

Mik*_*han 1

我不太确定,但我想你想要

test.<name>.out
Run Code Online (Sandbox Code Playgroud)

由制成

<name>/test.out
Run Code Online (Sandbox Code Playgroud)

(如果存在)。如果这是正确的,您可以通过从目标名称对每个目标的先决条件名称进行逆向工程来可靠地完成此操作,例如

targs := test.1.out test.a.out

define src_of =
$(patsubst .%,%,$(suffix $(basename $(1))))/$(basename $(basename $(1)))$(suffix $(1))
endef

all: $(targs)

test.%.out: $(call src_of,test.%.out)
    cp -f $< $@

clean:
    rm -f *.*.out
Run Code Online (Sandbox Code Playgroud)

不可否认,这有点拗口。

因此,如果我们在满足先决条件的情况下预先安排一个演示:

$ ls -LR
.:
1  a  Makefile

./1:
test.out

./a:
test.out
$ make
cp -f 1/test.out test.1.out
cp -f a/test.out test.a.out
Run Code Online (Sandbox Code Playgroud)