Jenny M
Jenny M

Reputation: 1023

makefile increase argument value on each target call

Ive make file with the version that I want to increase automatically the patch value every time by one when I runmake pr

TAG = 0.0.1


pr:
    docker build -t $(REGISTRY)/$(APP):$(TAG) .

I want to every time that I’ll run make pr it will increase the number, Its ok that only the last number will be increased

Like make pr

TAG = 0.0.2

After another 8 times

TAG = 0.0.10

Another 90

TAG = 0.0.100

Upvotes: 0

Views: 40

Answers (2)

Beta
Beta

Reputation: 99134

You could use a shell variable instead of a Make variable:

pr:
    read TAG < nnn; docker build -t $(REGISTRY)/$(APP):0.0.$$TAG; echo $$((TAG+1)) > nnn

EDIT: this assumes a file named nnn that contains "1" initially.

Upvotes: 1

ensc
ensc

Reputation: 6994

With GNU make you can do:

TAG = 0.0.${PR}

-include .pr.mk

PR ?= 0

pr: FORCE
    @echo ${TAG}

.pr.mk:
    @rm -f $@
    @echo "PR=$$(( ${PR} + 1 ))" > $@

FORCE:
.PHONY: FORCE .pr.mk

Upvotes: 1

Related Questions