Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Makefile debug target

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 01-11-2009
JerryHone JerryHone is offline
Registered User
 
Join Date: Nov 2006
Last Activity: 27 September 2016, 6:38 AM EDT
Location: UK
Posts: 256
Thanks: 1
Thanked 6 Times in 6 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 Unix and Linux 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 03:51 AM.