tags:

views:

40

answers:

2

I am using a makefile in which if I pass options in the command line like

make OPT1=opt1 OPT1=2

I get a different behavior than if I edit Makefile and write there

OPT1=opt1
OPT2=opt2

and then then run

make

on the command line.

The behavior I want is the one where I use the options in the command line.Right now I am using an alias but I am interested in knowing if this can be done purely with the Makefile alone.

Thanks.

+1  A: 

Does your make file use the origin command on these variables to decide whether to overwrite them? This returns the, well, origin of a variable, e.g. "environment" or "command line", and maybe the makefile is written to do something different in these cases.

pythonic metaphor
A: 

The way I end up solving this was the following:

mv Makefile Makefile.aux

then create a now Makefile with the contents

OPT1=true
OPT2=false

DEFAULT_OPTS=--no-print-directory OPT1=$(OPT1) OPT2=$(OPT2)

.PHONY : $(MAKECMDGOALS)
$(MAKECMDGOALS):
        $(MAKE) -f Makefile.aux $(DEFAULT_OPTS) $(MAKEFLAGS) $(MAKECMDGOALS)

.PHONY: all
all:
        $(MAKE) -f Makefile.aux $(DEFAULT_OPTS) $(MAKEFLAGS) $(MAKECMDGOALS)

The reason I use --no-print-directory is because if I use this method without this option it will print an extra message in the beggining and in the end of the compilation.

skeept