简体   繁体   中英

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 run make 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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM