LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-12-2010, 04:16 PM   #1
mosca
Member
 
Registered: Apr 2004
Location: Sweden
Distribution: Debian
Posts: 41

Rep: Reputation: Disabled
makefile: change compilation flags by changing target name


Hi,
I'm a kind of a newbie with makefiles and I'd like to create a target named "debug" or something similar which will use some special optimization flags useful when debugging (for example -ggdb). At the moment my makefile is neat (which I like) and looks like

Code:
SRC = $(wildcard *.cxx) 
OBJ = $(SRC:.cxx=.o)

INCDIR = -I.
LIB = -lm 
LIBDIR = 

CXX = g++
LD = $(CXX)

CXXFLAGS = -Wextra -Wall -W #-pedantic #-Weffc++
CXXFLAGS += -ansi -pg -ggdb3 #-std=c++0x
CXXFLAGS += -O3 -march=native
LDFLAGS = -ggdb3  -pg 


.SUFFIXES : .o .cxx .hxx

.cxx.o :
	$(CXX) $(CXXFLAGS) $(INCDIR) -c $< -o $*.o

# targets
a.out : $(OBJ)
	$(LD) $(LDFLAGS) $(OBJ) $(LIBDIR) $(LIB) -o $@

files : 
	@echo $(SRC)

all : clean depend a.out

clean :
	/bin/rm -f *.o a.out gmon.out 

depend :
	gccmakedep -- $(INCDIR) -- $(SRC)
Now, I'd like to have a debug target that uses different CXXFLAGS. How can one do that?

Thanks!
 
Old 11-12-2010, 05:16 PM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
you can use tests in your makefile like "ifeq"
Code:
ifeq ($(DEBUG), YES)
    CFLAGS+=-g
fi
then call with "make DEBUG=YES"
 
Old 11-13-2010, 06:05 PM   #3
mosca
Member
 
Registered: Apr 2004
Location: Sweden
Distribution: Debian
Posts: 41

Original Poster
Rep: Reputation: Disabled
Thanks, that'll work for me.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Target Change and re-compilation?? bvramesh Linux - Software 1 01-27-2010 10:17 PM
makefile subdirectory target sancho1980 Linux - General 1 08-18-2008 05:25 PM
strange target name containing % in Makefile George2 Programming 2 04-25-2006 06:28 AM
Makefile question - multiple compilation flags benobi Programming 7 08-11-2005 01:42 PM
Compilation flags and linker warnings alanwolfen Programming 4 02-24-2005 08:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration