Makefile:根据二进制文件的名称,以不同的方式运行它们
我的Makefile中有以下内容:Makefile:根据二进制文件的名称,以不同的方式运行它们,makefile,Makefile,我的Makefile中有以下内容: BINS = $(shell echo *.bin) .PHONY: $(BINS) run: $(BINS) *.bin: ./$@ 我以make-j8 这样,它会查找以.bin结尾的所有文件,并使用make的-j选项()并行运行它们 我需要修改makefile,使其以mpirun-np 2./mpi*.bin的形式运行mpi*.bin类型的所有文件,并以/.bin的形式运行其余的可执行文件 谢谢你的帮助。下面是一个我用来测试答案的简单例子:
BINS = $(shell echo *.bin)
.PHONY: $(BINS)
run: $(BINS)
*.bin:
./$@
我以make-j8
这样,它会查找以.bin结尾的所有文件,并使用make的-j选项()并行运行它们
我需要修改makefile,使其以mpirun-np 2./mpi*.bin
的形式运行mpi*.bin类型的所有文件,并以/.bin
的形式运行其余的可执行文件
谢谢你的帮助。下面是一个我用来测试答案的简单例子:
touch {a,b,c,d}.bin mpi{a,b,c,d}.bin
要创建一些空测试文件,以及基于您的生成文件,请执行以下操作:
BINS = $(shell echo *.bin)
.PHONY: $(BINS)
run: $(BINS)
*.bin:
echo "bin file: " ./$@
mpi*.bin:
echo "mpi file: " ./$@
这里的关键是,前缀文件的规则遵循非前缀规则。否则,前缀规则将被覆盖
这似乎有助于区分带前缀和不带前缀的文件,但会提供以下输出:
~/tmp$ make
Makefile:10: warning: overriding commands for target `mpia.bin'
Makefile:7: warning: ignoring old commands for target `mpia.bin'
Makefile:10: warning: overriding commands for target `mpib.bin'
Makefile:7: warning: ignoring old commands for target `mpib.bin'
Makefile:10: warning: overriding commands for target `mpic.bin'
Makefile:7: warning: ignoring old commands for target `mpic.bin'
Makefile:10: warning: overriding commands for target `mpid.bin'
Makefile:7: warning: ignoring old commands for target `mpid.bin'
echo "bin file: " ./a.bin
bin file: ./a.bin
echo "bin file: " ./b.bin
bin file: ./b.bin
echo "bin file: " ./c.bin
bin file: ./c.bin
echo "bin file: " ./d.bin
bin file: ./d.bin
echo "mpi file: " ./mpia.bin
mpi file: ./mpia.bin
echo "mpi file: " ./mpib.bin
mpi file: ./mpib.bin
echo "mpi file: " ./mpic.bin
mpi file: ./mpic.bin
echo "mpi file: " ./mpid.bin
mpi file: ./mpid.bin
我确信有一种方法可以抑制这些警告或做得更好,但这种方法似乎有效