conditional compilation

  • Thread starter onkar.n.mahajan
  • Start date
O

onkar.n.mahajan

Hi All ,
I want to compile some part of the file depending on some
parameter set in the Makefile (using cc compiler ).

for instance

#ifdef CONDITION
//include this part of the code in compilation
#endif


I need to only set/unset the option in Makefile. Is it possible to do
this ?

One example will be of great help.

Thanks
 
R

Rouben Rostamian

I want to compile some part of the file depending on some
parameter set in the Makefile (using cc compiler ).
for instance
#ifdef CONDITION
//include this part of the code in compilation
#endif
I need to only set/unset the option in Makefile. Is it possible to do
this ?

In the Makefile set:

CFLAGS = -DCONDITION -whatever-other-flags
 
R

Richard Tobin

I want to compile some part of the file depending on some
parameter set in the Makefile (using cc compiler ).

for instance

#ifdef CONDITION
//include this part of the code in compilation
#endif


I need to only set/unset the option in Makefile. Is it possible to do
this ?

Most compilers accept a flag -Dname=value (or just -Dname if you don't
care what value it is). Something like

cc -DCONDITION -c myfile.c

You may wish to put all your compiler flags in a Make variable, instead
of repeating them on each cc line, e.g.

CFLAGS= -O -g -DCONDITION
...
cc $(CFLAGS) -c myfile.c

(Actually CFLAGS is a special variable name; if you don't specify a
rule for compiling C programs it will use $(CFLAGS) anyway.)

Different versions of the Make program vary somewhat; if you want
to do anything fancy you should probably find a group devoted to
the particular variety you're using.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top