Makefile debug target | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Makefile debug target

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-11-2009
StevenR StevenR is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 12 January 2009, 6:43 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Makefile debug target

Hello,

I'm having a problem with a makefile script i'm trying to write.
I want to compile a C++ program in two possible ways: "make"
(default target, main) and "make debug". When i supply the debug
target, exactly the same as main should be built, but then with the
DEBUG flag (-g -D DEBUG).

This sounds really logical, but i can't find the answer anywhere
in the forums.

This is the script:

CXX=g++
CXXFLAGS=-ansi -std=c++98 -Wall -W
DEBUG=-g -D DEBUG
OBJS=main.o NgramCreator.o

main: $(OBJS)
$(CXX) $(OBJS) -o $@
$(OBJS): NgramCreator.h
$(CXX) $(CXXFLAGS) $(DEBUG) -c $*.cpp

clean:
rm -f *~ *.o main *.gch


I don't have a clue how to do this, can anybody help me?

Thanks

Steven
Sponsored Links
    #2  
Old 01-11-2009
JerryHone JerryHone is offline
Registered User
 
Join Date: Nov 2006
Last Activity: 3 September 2014, 1:57 PM EDT
Location: UK
Posts: 254
Thanks: 1
Thanked 5 Times in 5 Posts
Call the same makefile recursively in the debug target including the required flags. Don't set $(DEBUG) as a macro, but pass it in on the recursive call. Something like...

Quote:
CXX=g++
CXXFLAGS=-ansi -std=c++98 -Wall -W $(DEBUG)
# DEBUG=-g -D DEBUG
OBJS=main.o NgramCreator.o

main: $(OBJS)
$(CXX) $(OBJS) -o $@
$(OBJS): NgramCreator.h
$(CXX) $(CXXFLAGS) $(DEBUG) -c $*.cpp

debug:
$(MAKE) $(MAKEFILE) DEBUG="-g -D DEBUG"
HTH

Jerry
Sponsored Links
    #3  
Old 01-12-2009
StevenR StevenR is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 12 January 2009, 6:43 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
It worked

Hi,

It worked great! Thanks!

Steven
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Makefile problem - How to run module load in a Makefile hernandinho UNIX for Advanced & Expert Users 2 04-13-2009 11:20 AM
Oracle 9i install: Error in invoking target install of makefile chris2005 HP-UX 5 02-21-2007 09:45 AM
tar - Selecting target dir GNMIKE UNIX for Dummies Questions & Answers 3 11-05-2005 06:52 AM
Makefile:57: *** multiple target patterns. Stop. nileshborate Solaris 0 09-20-2005 11:19 AM
vi, c/source/target g? yls177 UNIX for Dummies Questions & Answers 7 12-02-2002 11:46 AM



All times are GMT -4. The time now is 05:27 PM.