how to enable #ifdef macro in the command line of make?


 
Thread Tools Search this Thread
Operating Systems Linux how to enable #ifdef macro in the command line of make?
# 1  
Old 12-29-2007
how to enable #ifdef macro in the command line of make?

[Keyword] Linux, C++, make, macro

In source code, we used some #ifdef macros. How can I enable #ifdef macro in the command line of "make" (NOTE: I do NOT want to change source code or makefile to define that macro from time to time).

e.g. test.cpp:
...
#ifdef TEST1
// code segment for test1
...
#endif
...
#ifdef TEST2
// code segment for test2
...
#endif
....

Question: How can I enable either macro via command line of make?
e.g. make ????? -> enable TEST1
make ????? -> enable TEST2

Thanks in advance!
# 2  
Old 12-29-2007
Compilers normally use the -D flags

eg

Code:
test.o: test.cpp
     $(CC) $(CFLAGS) -DTEST1 test.cpp -o $@

# 3  
Old 12-29-2007
if u wish to do it outside makefile
make CFLAGS=-DMACRO

dont forget that inside your make file u are using the CFLAGS macro while compilation
# 4  
Old 12-29-2007
hi porter & uvrakesh, i got it. thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Enable 'make uninstall' hook?

Heyas I'm currently trying to make 'make uninstall' work properly, as it doesnt remove empty directories. To do so, i've applied: uninstall-hook: if test -d $docdir; then rmdir $docdir; fi As stated (example) in automake - 'make uninstall': Howto remove empty directories - Stack... (2 Replies)
Discussion started by: sea
2 Replies

2. Homework & Coursework Questions

Make a file accept only two arguments from the command line

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) The script is executed in the Korn shell. 2) Name the shell script file is asg6s. 3) The asg6s file is... (7 Replies)
Discussion started by: ProgMan2015
7 Replies

3. Programming

Make a file accept only two arguments from the command line

DELETED (2 Replies)
Discussion started by: ProgMan2015
2 Replies

4. UNIX for Dummies Questions & Answers

Why cant I use enable command

Why can I not use the enable command? *sofiazoe* (2 Replies)
Discussion started by: anglenasalt
2 Replies

5. Shell Programming and Scripting

How to use ifdef for bash variables in csh environment?

Hi Guys, I have a a bash script and i am exporting a variable in it. I am calling a csh script from this bash script. The variable "ABC" will be visible in csh script. ks.bash export ABC = abc ./kp.csh ab.csh echo $ABC setenv ABC =cde (i want to assign this value to ABC only if... (4 Replies)
Discussion started by: vdhingra123
4 Replies

6. Shell Programming and Scripting

Homework: Make a one-line Unix command - using pipe(s)

Task A: Make a one-line Unix command - using pipe(s) - to display the number of files in your home directory including the hidden files that begin with '.' Task B:Make a one-line Unix command - using pipe(s) - to display the number of unique zip codes in famous.dat (hint: use -u on sort) Task... (1 Reply)
Discussion started by: wises
1 Replies

7. Shell Programming and Scripting

How to make command line interactive?

I have a file with stats for different month, I use the cat and grep combination to search for different month. cat <file> | grep "April" cat <file> | grep "May" cat <file> | grep "June" etc. How do you make this command interactive. So that I can give the values for the search. Thanks... (7 Replies)
Discussion started by: purelltab
7 Replies

8. Homework & Coursework Questions

I need to make a script that has 4 command line arguments to function properly.

I have no idea what the following means. The teacher is too advanced for me to understand fully. We literally went from running a few commands over the last few months to starting shell scripting. I am not a programmer, I am more hardware oriented. I wish I knew what this question was asking... (3 Replies)
Discussion started by: Wookard
3 Replies

9. Programming

Make-question - redefine a macro, using another macro..?

I think there is no problem to use any macro in a new macro definishion, but I have a problem with that. I can not understand why? I have a *.mak file that inludes file with many definitions and rules. ############################################## include dstndflt.mak ... One of the... (2 Replies)
Discussion started by: alex_5161
2 Replies

10. Shell Programming and Scripting

Surrounding a chunk of code by #ifdef and #endif

Hello the great gurus :) I'm quite new to this, so perhaps I'm asking a simple and trivial question (which is good, because you'll answer for sure :)))) Anyway. I have an amount of *.c files (about 100), and what I want to do, is to surround a specific function call with #ifdef and #endif. ... (6 Replies)
Discussion started by: xxxaxa
6 Replies
Login or Register to Ask a Question