arfbtwn
arfbtwn

Reputation: 328

Choosing Arguments with GNU Make

Consider this short Makefile:

ARGS       := -foo
my_ARGS    := -bar
their_ARGS :=

all: your.foo my.foo their.foo

%.foo:
    @echo $*: $(call _choose_,ARGS,$*)

_isndef_ = $(findstring undefined,$(origin $1))
_choose_ = $(value $(if $(call _isndef_,$2_$1),$1,$2_$1))

It correctly outputs:

your: -foo
my: -bar
their:

My Questions:

Upvotes: 0

Views: 161

Answers (1)

MadScientist
MadScientist

Reputation: 100956

Why not use variable name construction? It would be just simply:

ARGS       := -foo
my_ARGS    := -bar
their_ARGS :=

all: your.foo my.foo their.foo

%.foo:
        @echo $*: $(or $($*_ARGS),$(ARGS))

More info here for example: http://make.mad-scientist.net/constructed-macro-names/

If you want to "override with empty" you can use target-specific variables:

ARGS := -foo

my.foo:    ARGS := -bar
their.foo: ARGS :=

all: your.foo my.foo their.foo

%.foo:
        @echo $*: $(ARGS)

Upvotes: 1

Related Questions