Jayesh Bhoi
Jayesh Bhoi

Reputation: 25915

Pass macro value at command line

Hi i have some code and compiled using make file.Let me see you peace of code in which i got trouble.

#if (TEST_MACRO == 1)
printf("Use test configuration");
//some code
#else
printf("Use actual configuration");
//some code
#endif

And in make file have added that macro using

CFLAGS = -DTEST_MACRO 

Now I compiled program using

make mytarget TEST_MACRO=0

Then also it going to execute test configuration code.

So my question is that is default value of macro in makefile is 1? If yes then how to make it 0?

I tried something like

CFLAGS = -DTEST_MACRO=0

But in this case it always going to execute actual configuration even i pass value 1.

Can any one help me?

Upvotes: 0

Views: 988

Answers (1)

Ed Heal
Ed Heal

Reputation: 60037

Use ifdef instead - easier to use.

i.e.

#ifdef TEST_MACRO
....
#else
...
#endif

Then compile with -DTEST_MACRO to add. To compile without do not use -DTEST_MACRO

Upvotes: 3

Related Questions