在 Makefile 中:从其他文本文件读取版本并将结果放入 Makefile 中的变量中

Sun*_*127 1 bash makefile

我有一个名为“Version.h”的文件,其内容为:

#define APP_VERSION_MAJOR   5
#define APP_VERSION_MINOR   6
#define APP_VERSION_PATCH   0
Run Code Online (Sandbox Code Playgroud)

我有一个 Makefile,我想根据“Version.h”文件在 Makefile 中分配一个变量,在本例中:

MY_APP_VERSION = 5.6.0
Run Code Online (Sandbox Code Playgroud)

我设法使用以下命令找到该行:

@echo "The result is: $$(grep "#define APP_VERSION_MINOR    " Version.h)"
Run Code Online (Sandbox Code Playgroud)

输出:

The result is: #define APP_VERSION_MINOR    6
Run Code Online (Sandbox Code Playgroud)

那么,如何将版本放入 Makefile 的变量中呢?

谢谢!

Mad*_*ist 5

要设置 make 变量,您可以执行以下操作:

getnum = $(shell sed -n 's/.*$1  *\([0-9*]\)/\1/p' Version.h)

MY_APP_VERSION := $(call getnum,MAJOR).$(call getnum,MINOR).$(call getnum,PATCH)
Run Code Online (Sandbox Code Playgroud)

但这确实调用了 sed 3 次。