Reputation: 4691
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
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