Abel Cheung
Abel Cheung

Reputation: 516

text substitution on version strings with GNU make

This question is specific to GNU make. Given a version string in makefile, say:

VER = 1.23.345.6

Is it possible to strip off trailing component(s) from the string? Let's say desired result is the first 2 components, that is (major.minor):

VERPREFIX = 1.23

Although it can be achieved with $(shell) using command line programs that supports regular expression (such as sed or perl), I'd wonder if native text filtering functions in GNU make can achieve same result.

Upvotes: 0

Views: 161

Answers (1)

MadScientist
MadScientist

Reputation: 100946

Try:

# Create a variable $S containing a space
E :=
S := $E $E

# Get the first and second elements of a version string
VERPREFIX := $(subst $S,.,$(wordlist 1,2,$(subst .,$S,$(VER))))

Upvotes: 1

Related Questions