Shell 在Makefile中拆分和剪切字符串
我正在制作一个MakefileShell 在Makefile中拆分和剪切字符串,shell,awk,sed,makefile,cut,Shell,Awk,Sed,Makefile,Cut,我正在制作一个Makefile version := v39.0.12.8 // format rules: va.b.c.d 我想得到基于格式的版本a,在本例中是39。 如何做到这一点?可能通过sed/cut/awk,但我不熟悉这些shell命令 e、 g 这可以通过make功能实现,如下所示: $ cat Makefile version := v39.0.12.8 version_tuple := $(subst ., ,$(version:v%=%)) version_a :
version := v39.0.12.8 // format rules: va.b.c.d
我想得到基于格式的版本a,在本例中是39。
如何做到这一点?可能通过sed/cut/awk,但我不熟悉这些shell命令
e、 g
这可以通过make功能实现,如下所示:
$ cat Makefile
version := v39.0.12.8
version_tuple := $(subst ., ,$(version:v%=%))
version_a := $(word 1,$(version_tuple))
version_b := $(word 2,$(version_tuple))
version_c := $(word 3,$(version_tuple))
version_d := $(word 4,$(version_tuple))
all:
echo version_tuple = $(version_tuple)
echo version_a = $(version_a)
echo version_b = $(version_b)
echo version_c = $(version_c)
echo version_d = $(version_d)
输出:
$ make -s
version_tuple = 39 0 12 8
version_a = 39
version_b = 0
version_c = 12
version_d = 8
这可以通过make功能实现,如下所示:
$ cat Makefile
version := v39.0.12.8
version_tuple := $(subst ., ,$(version:v%=%))
version_a := $(word 1,$(version_tuple))
version_b := $(word 2,$(version_tuple))
version_c := $(word 3,$(version_tuple))
version_d := $(word 4,$(version_tuple))
all:
echo version_tuple = $(version_tuple)
echo version_a = $(version_a)
echo version_b = $(version_b)
echo version_c = $(version_c)
echo version_d = $(version_d)
输出:
$ make -s
version_tuple = 39 0 12 8
version_a = 39
version_b = 0
version_c = 12
version_d = 8
使用,您可以在您的版本号上执行:
include gmtt/gmtt.mk
version := v39.0.12.8
matchresult := $(call glob-match,$(version),v*.*.*.*)
$(info [$(matchresult)])
major := $(word 2,$(matchresult))
minor := $(word 4,$(matchresult))
bugfix := $(word 6,$(matchresult))
buildcnt := $(word 8,$(matchresult))
$(info Major = $(major))
$(info Minor = $(minor))
$(info Bugfix = $(bugfix))
$(info Buildcnt = $(buildcnt))
$(if $(call int-ge,$(major),39),$(info Major is 39 or higher!))
使用,您可以在您的版本号上执行:
include gmtt/gmtt.mk
version := v39.0.12.8
matchresult := $(call glob-match,$(version),v*.*.*.*)
$(info [$(matchresult)])
major := $(word 2,$(matchresult))
minor := $(word 4,$(matchresult))
bugfix := $(word 6,$(matchresult))
buildcnt := $(word 8,$(matchresult))
$(info Major = $(major))
$(info Minor = $(minor))
$(info Bugfix = $(bugfix))
$(info Buildcnt = $(buildcnt))
$(if $(call int-ge,$(major),39),$(info Major is 39 or higher!))
这可能有助于GNU make:这可能有助于GNU make: