Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

makefile with some flags ?

Posted on 2004-09-27
9
Medium Priority
?
726 Views
Last Modified: 2013-12-26

Hi every body ... I have a problem with my makefile
I need to have a parameter to makefile so I can ignore some lines . these lines can be in any where in the file .

Is there any way to pass this parameter which will work as flags to ignore some lines >>> Tk.
 nmake -j 16 (it can be nmake 1 mean ignore,  0 don't ignore ... as example only  )
0
Comment
Question by:albusaidi
  • 5
  • 4
9 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12158308
Hi albusaidi,

Embed the lines which can be conditionally ignored in an ifdef, e.g.

#ifdef PARAM_A
...
#endif

Now in your compilation line on makefile, use -DPARAM_A to compile the lines. Removing this flag will lead to ignoring these lines during compilation

Sunnycoder
0
 

Author Comment

by:albusaidi
ID: 12159034
Thank You Sunnycoder but you mean -DPARAM_A  or
 -PARAM_A
so my instraction will be ?
 nmake -j 16   (before)
 nmake -DPARAM_A -j 16 (new)
it is like that ???

also if I want to be by default true that means I will normally execute the make file but If i make it with parameter then will be ignored how can I do it ... TK
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 150 total points
ID: 12159063
http://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Preprocessor-Options.html#Preprocessor-Options

-D name
Predefine name as a macro, with definition 1.

-D name=definition
Predefine name as a macro, with definition definition.

nmake -DPARAM_A -j 16  should work just fine

>also if I want to be by default true that means I will normally execute the make file but If i make it with parameter then will
>be ignored how can I do it
Something like
#MYOPTIONS=
MYOPTIONS='-DPARAM_A'
gcc ... $MYOPTIONS ...

Use it in as many places as you want. If you wish to disable it, all you need to do is comment the line. Something like
MYOPTIONS=
#MYOPTIONS='-DPARAM_A'
gcc ... $MYOPTIONS ...

You can also take a decision within the makefile by using the ifeq and other conditional, but I would suggest avoiding them right now

sunnycoder
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:albusaidi
ID: 12159405
sorry but when I execute this code it always execute the if statement ..it is suppose  no execute that line un less I bass the parameter

      -D name=definition
      cc=gcc
1.o: 1.cpp

      @echo "compiling mmims_main with the $(CC) compiler"

      #ifdef kw
      @echo "\n\n************IN THE MIDDLE"
      
      #endif
      $(CC) -c 1.cpp
      @echo "END OF LINE MOHAMMED AL-BUSAIDI"
      
TK
0
 

Author Comment

by:albusaidi
ID: 12160709
I mean this src

MYOPTIONS=
#MYOPTIONS='-Dkw'
cc=gcc 1.o: 1.cpp

@echo "compiling 1.cpp with the $(CC) compiler"

#ifdef KW
@echo "*******IN THE IF***********"
#end f      
$(CC) $(MYOPTIONS) -c 1.cpp
make clean      
@echo "END OF SRC"
clean:
rm 1.o

0
 

Author Comment

by:albusaidi
ID: 12166552
No one can make it more clear ....
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12167067
You wish to ignore lines of makefile or that of source code ?
0
 

Author Comment

by:albusaidi
ID: 12167127
Ignore of makefile
and to test that I make echo line so when I
execute the makefile with the parameter or without always execute the echo line
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12167141
-D flag is used for ignoring some source code...
For your purpose, use this

http://www.gnu.org/software/make/manual/html_chapter/make_7.html#SEC79
Something like

libs_for_gcc = -lgnu
normal_libs =

foo: $(objects)
ifeq ($(CC),gcc)
        $(CC) -o foo $(objects) $(libs_for_gcc)
else
        $(CC) -o foo $(objects) $(normal_libs)
endif

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question