Unix Programming - Compiling different version for a program with make

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2005 > Compiling different version for a program with make





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Compiling different version for a program with make
pmatos

2005-02-20, 6:20 pm

Hi all,

I'd like to generate different versions of a program with make. For
example:
make optimized should compile with flags -03 -march=athlon-xp and make
debug should compile with -ggdb. Is there a nice way to achieve this
without hardcoding the flags? For example, setting up CXXFLAGS
depending on the target passed to make?

Cheers,

Paulo Matos

John Smith

2005-02-20, 6:20 pm

> For example, setting up CXXFLAGS
> depending on the target passed to make?
>


The easiest way is to add another variable like:

target.o: target.c
gcc $(CFLAGS) ... $(CEXTRA) -o blah ...

and from shell you type:

make CEXTRA=-march=athlon-xp

If you don't write anything besides "make" then it evaluates to nothing.

-- John


Paul Pluzhnikov

2005-02-20, 6:20 pm

"pmatos" <pocm@sat.inesc-id.pt> writes:

> For example, setting up CXXFLAGS
> depending on the target passed to make?


The "canonical" way to do what you want is with recursive make invocation:

CXXFLAGS = -ggdb
all: foo.exe
foo.exe:
$(CXX) $(CXXFLAGS) foo.o -o $@
optimized:
$(MAKE) all CXXFLAGS='-03 -march=athlon-xp'


However, GNU and Solaris make allow for target-specific variables, e.g.

debug: CXXFLAGS = -ggdb
optimize: CXXFLAGS = -03 -march=athlon-xp

debug optimize:
$(CXX) $(CXXFLAGS) foo.o -o foo.exe

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com