[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Make question: Specify which CXXFLAGS to use
From: |
Glynn Clements |
Subject: |
Re: Make question: Specify which CXXFLAGS to use |
Date: |
Wed, 13 Oct 2004 23:49:47 GMT |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through Obscurity, linux) |
"William Payne" <mikas493_no_spam@student.liu.se> writes:
> Hello, consider this Makefile:
>
> CXX = g++
> LD = g++
> CXXFLAGS_DEBUG = -Wall -W -ansi -pedantic -g -ggdb -c -o
> CXXFLAGS_RELEASE = -Wall -W -ansi -pedantic -O -c -o
> LDFLAGS_DEBUG = -mwindows -lole32 -L/usr/local/gcc-3.4.2/lib/ -o $(EXEC)
> LDFLAGS_RELEASE = -s -mwindows -lole32 -L/usr/local/gcc-3.4.2/lib/ -o
> $(EXEC)
> EXEC = debug_file_remover
> OBJECTS = \
> main_dialog_procedure.o \
> selected_directory_edit_box_procedure.o \
> winmain.o \
> debug_file_remover.res
>
> debug: $(OBJECTS)
> $(LD) $(OBJECTS) $(LDFLAGS_DEBUG)
>
> release: $(OBJECTS)
> $(LD) $(OBJECTS) $(LDFLAGS_RELEASE)
>
> %.o: %.cpp
> $(CXX) $(CXXFLAGS) $@ $<
>
> %.res: %.rc
> windres $< -O coff -o $@
>
> clean:
> rm -f $(OBJECTS) $(EXEC) *~ *.stackdump
>
> My problem is that depending on whether the user is doing "make debug" or
> "make release", I want to specify which CXXFLAGS_ to use.
> Can I have a variable, say $CXXFLAGS, that I set to either $CXXFLAGS_DEBUG
> or RELEASE as appropiate? If so, how?
It's better (and probably easier) to have separate names for the debug
and release versions of the object files, e.g.:
DEBUG_OBJECTS = $(patsubst %.o,dbg/%.o,$(OBJECTS))
RELEASE_OBJECTS = $(patsubst %.o,dbg/%.o,$(OBJECTS))
dbg/%.o: %.cpp
$(CXX) $(DEBUG_CXXFLAGS) -o $@ $<
rel/%.o: %.cpp
$(CXX) $(RELEASE_CXXFLAGS) -o $@ $<
debug: $(DEBUG_OBJECTS)
$(LD) $(LDFLAGS_DEBUG) $^
release: $(RELEASE_OBJECTS)
$(LD) $(LDFLAGS_RELEASE) $^
This has the advantage that "make debug ; make release" will do the
right thing, i.e. build each target from the correct set of .o files,
rather than building the release target from the pre-existing (debug)
versions of the .o files.
--
Glynn Clements <glynn.clements@virgin.net>