My Makefile:
FULL_VERSION ?= 1.2.3
MINOR_VERSION := $(shell echo "${FULL_VERSION%.*}")
test:
echo $(MINOR_VERSION)
Running make test
gives nothing, I want to get 1.2
.
I know I can get it via sed/grep but I'm looking for a more elegant solution, seems there's nothing simpler than bash parameter expansion
Best Answer
You'd need to first store the value in a shell variable:
(assuming
$(FULL_VERSION)
doesn't contain single quotes)Now that calls
sh
, notbash
.${var%pattern}
is a standardsh
operator (comes fromksh
).If you wanted to use
bash
-specific operators, you'd need to tellmake
to callbash
instead ofsh
withBeware however that many systems don't have
bash
installed by default which would make your Makefile non-portable (but then, some systems don't have GNUmake
either and you're already using some GNUisms there)).