help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem about define a variable according the make command line.


From: Kun Niu
Subject: Problem about define a variable according the make command line.
Date: Sat, 14 Apr 2007 17:29:06 +0800

Dear all,

I'm sorry for the simple problem.
But it's a bit stange.

I've got two makefiles as follows:

Makefile1:

ifdef DEBUG
DFLAG=-D DEBUG
else
DFLAG=
endif
debug: all
all:
        g++ $(DFLAG) -o function_pointer function_pointer.cpp -Wall
clean:
        rm -rf *~

--------------------------------------------------------------------
Makefile2:

.DEFAULT_GOAL := all

#ifeq ($(MAKECMDGOALS),debug)
DFLAG += -D DEBUG -g
#else
DFLAG=
#endif

obj = log.o

debug: all
all: $(obj)
        libtool --mode=link g++ $(DFLAG) -o libEGE.a log.o
log.o: log.h log.cpp
        g++ -c $(DFLAG) -o log.o log.cpp

.PHONY: clean
clean: emacsclean
        rm -rf *.o libEGE.a

emacsclean:
        rm -rf *~

--------------------------------------------------------------------

To the first makefile, if I invoke make DEBUG=1, I can add the DFLAG variable to my makefile.
But to the second, though I invoke make DEBUG=1, the DFLAG variable is not set.
My system is Debian. And I'm using gnu make.
Would anyone please explain why this happens for me?

Any help would be appreciated and thanks in advance.

Sincerely,
Kun

reply via email to

[Prev in Thread] Current Thread [Next in Thread]