简体   繁体   中英

How to define a variable and then compile in a target [Makefile]

Having a Makefile i just want to adjust a variable and then compile, if i call a specific target. I have a working solution, how ever, it is not a nice one.

How i compile:

make

How i want to change a variable:

make debug

What needs to happen (how it works somehow):

debug:
    @make TAG=debug

I basically call make in a make process, which does the work, but doesn't seem to be correct either. I am looking for something like:

debug:
    TAG=debug
    jump to first line and do the job
TAG=release

build:
    @echo $(TAG)

debug: TAG=debug
debug: build

release: build

Usage:

> make
release
> make release
release
> make debug
debug

Update: Using TAG in build prerequesites:

TAG=release

pre:
    @echo pre build $(TAG)

build: pre
    @echo $(TAG)

debug: TAG=debug
debug: build

release: build

Output:

~/workspace (master) $ make build
pre release
release
~/workspace (master) $ make debug
pre debug
debug
~/workspace (master) $ make release
pre release
release

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