PravinCG
PravinCG

Reputation: 7708

Command line variable to GNU make using sh not working

Works:

make -f Makefile.custom CFLAGS="-DFLAG_ONE -DFLAG_TWO" clean target

What does not work is

FLAGS="-DFLAG_ONE -DFLAG_TWO"
make -f Makefile.custom CFLAGS=$FLAGS clean target

Error: It starts to think that -D is an argument to make and fails.

Tried: Using escape characters

FLAGS="\"-DFLAG_ONE -DFLAG_TWO\""

Any help would be appreciated.

--UPDATE--

This is a workaround but the question still remains open.

CFLAGS="-DFLAG_ONE -DFLAG_TWO"
export CFLAGS
make -f Makefile.custom clean target

Upvotes: 0

Views: 183

Answers (2)

William Pursell
William Pursell

Reputation: 212356

Quoting is necessary:

FLAGS="-DFLAG_ONE -DFLAG_TWO"
make -f Makefile.custom CFLAGS="$FLAGS" clean target

Upvotes: 1

jacekmigacz
jacekmigacz

Reputation: 789

CFLAGS="-DFLAG_ONE -DFLAG_TWO" make -f Makefile.custom clean target

And simple Makefile:

all:
        echo ${CFLAGS}

...will print:

-DFLAG_ONE -DFLAG_TWO

...thus it does work.

Upvotes: 1

Related Questions