Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

makefile with some flags ?

Posted on 2004-09-27
9
Medium Priority
?
717 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

670 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