首页 > 解决方案 > makefile 中的版本匹配

问题描述

我是新手。假设我有一个有目标的makefile,目标将根据版本启动不同的编译命令:从版本1.xx到版本3.xx,它将启动命令1。而版本4.xx或更高版本,它将启动命令 2。

run-%: %.txt
   <if %.txt is in between 1.x.x and 3.x.x, kick off command 1 with %.txt as input>
   <else kick off command 2 with %x.txt as input>

用户将像这样运行它:

make run-2.2.0

make 是否提供某种模式匹配?

标签: makefile

解决方案


[1-3]如果这就是您所说的“模式匹配”,那么没有什么比得上 glob 的了。不幸的是,您所能做的就是编写多个规则:

run-1.%: 1.%.txt
    <command1>
run-2.%: 2.%.txt
    <command1>
run-3.%: 3.%.txt
    <command1>

run-%: %.txt
    <command2>

推荐阅读