Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract a pattern from a makefile string variable

Tags:

makefile

In a Makefile, I have a variable DPDK_CUSTOM_REPO_VERSION which is defined as follows:

DPDK_CUSTOM_REPO_VERSION="dpdk-19.08-devel"

How to Extract 19.08 from above string into another variable DPDK_VERSION?

like image 474
raj_gt1 Avatar asked Dec 20 '25 18:12

raj_gt1


1 Answers

The string processing abilities of the make-command are somewhat limited, but you can try the following:

Replace all occurrences of - with space:

$(subst -, ,$(DPDK_CUSTOM_REPO_VERSION)

resulting in dpdk 19.08 devel and take the second word:

$(word 2, $(subst -, ,$(DPDK_CUSTOM_REPO_VERSION)))

This should yield the correct result, if the pattern doesn't change significantly. Put it together to:

DPDK_CUSTOM_REPO_VERSION="dpdk-19.08-devel"
DPDK_VERSION=$(word 2,$(subst -, ,$(DPDK_CUSTOM_REPO_VERSION)))

test:
        echo $(DPDK_VERSION)
like image 80
Ctx Avatar answered Dec 23 '25 17:12

Ctx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!