raj_gt1
raj_gt1

Reputation: 4691

How to extract a pattern from a makefile string variable

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?

Upvotes: 3

Views: 1120

Answers (1)

Ctx
Ctx

Reputation: 18410

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)

Upvotes: 3

Related Questions