Nested variables in a Makefile to provide conditional support to docker

  docker, makefile

I have variables set in an env file called by my Makefile. I would like to choose a set variable based on an environment condition. Is there a way to nest two variables to make a new variable?

Example env file

FILE_VERSION_11=11.0.4

Execution

VER=11 make build

Example Makefile (Not working obviously)

.PHONY: all
.PHONY: build
.PHONY: clean
.PHONY: help
.PHONY: test

include env

build: ## Build
build:
  docker image build --pull -t container:file-version-$(VER) 
  --build-arg FILE_VERSION=$(FILE_VERSION_$VER)

Hoping to have the $(FILE_VERSION) variable now be rewritten as $(FILE_VERSION_11) so that 11.0.4 can be passed to the docker build via the FILE_VERSION_11 env variable.

Source: StackOverflow

LEAVE A COMMENT