Makefile:根据二进制文件的名称以不同方式运行二进制文件

发布于 2024-12-08 22:13:23 字数 497 浏览 0 评论 0原文

我的 Makefile 中有这个:

BINS = $(shell echo *.bin)

.PHONY: $(BINS)
run: $(BINS)

*.bin:
    ./$@

我将其运行为 make -j 8

这样它会查找所有以 .bin 结尾的文件,并使用 make 的 -j 选项并行运行它们(Makefile 在后台运行进程

我需要修改makefile,以便将 mpi*.bin 类型的所有文件运行为 mpirun -np 2 ./mpi*.bin,并将其余可执行文件运行为 ./.bin感谢

您的帮助。

I have this in my Makefile:

BINS = $(shell echo *.bin)

.PHONY: $(BINS)
run: $(BINS)

*.bin:
    ./$@

I run it as make -j 8

This way it looks for all files ending with .bin, and runs them in parallel using make's -j option (Makefile run processes in background)

I need to modify the makefile so that it runs all files of the type mpi*.bin as mpirun -np 2 ./mpi*.bin, and the remaining executable files as ./<filename>.bin

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捂风挽笑 2024-12-15 22:13:23

这是我用来测试我的答案的一个简单示例:

touch {a,b,c,d}.bin mpi{a,b,c,d}.bin

创建一些空的测试文件,以及基于您的 Makefile:

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

我确信有一种方法可以抑制这些警告或做得更好,但这种方法似乎有效。

Here is a simple example I used to test my answer:

touch {a,b,c,d}.bin mpi{a,b,c,d}.bin

to create some empty test files, and my Makefile based on yours:

BINS = $(shell echo *.bin)

.PHONY: $(BINS)
run: $(BINS)

*.bin:
    echo "bin file: " ./$@

mpi*.bin:
    echo "mpi file: " ./$@

It is key here that the rule for the prefixed files follows the non-prefixed rule. If not, the prefixed rule will be overridden.

This seems to work for distinguishing between the prefixed and non-prefixed files, but gives the following output:

~/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

I'm sure that there's a way to suppress those warnings or do it better, but this approach seems to work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文