模式匹配具有多个可执行目标的Makefile [英] Pattern matching Makefile with multiple executable targets

查看:128
本文介绍了模式匹配具有多个可执行目标的Makefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成文件,该文件可构建多个可执行目标prog0 ... prog99.每个可执行文件的所有编译器和链接选项均相同:

I have a makefile that builds multiple executable targets prog0...prog99. All the compiler and link options are the same for each executable:

prog0: prog0.cpp prog0.h
   $(CC) $(CFLAGS) prog0 prog0.cpp $(LINKFLAGS)

prog1: prog1.cpp prog1.h
   $(CC) $(CFLAGS) prog1 prog1.cpp $(LINKFLAGS)
.
.
.
.
prog99: prog99.cpp prog99.h
   $(CC) $(CFLAGS) prog99 prog99.cpp $(LINKFLAGS)

我想知道是否有一种类似于构建目标文件的模式匹配技术可以应用到上面,以减少makefile的重复.

I was wondering if there is a pattern matching technique similar to building object files that could be applied to the above, so as to reduce the repetition of the makefile.

推荐答案

是的,当然:

prog%: prog%.cpp prog%.h
    $(CC) $(CFLAGS) $@ $< $(LINKFLAGS)

这篇关于模式匹配具有多个可执行目标的Makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆