Solved

makefile with some flags ?

Posted on 2004-09-27
9
640 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
Comment Utility
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
Comment Utility
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 50 total points
Comment Utility
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
 

Author Comment

by:albusaidi
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:albusaidi
Comment Utility
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
Comment Utility
No one can make it more clear ....
0
 
LVL 45

Expert Comment

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

Author Comment

by:albusaidi
Comment Utility
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
Comment Utility
-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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now