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


makefile with some flags ?

Posted on 2004-09-27
Medium Priority
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  )
Question by:albusaidi
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
LVL 45

Expert Comment

ID: 12158308
Hi albusaidi,

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

#ifdef PARAM_A

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


Author Comment

ID: 12159034
Thank You Sunnycoder but you mean -DPARAM_A  or
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
LVL 45

Accepted Solution

sunnycoder earned 150 total points
ID: 12159063

-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
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
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

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

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

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

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

      #ifdef kw
      @echo "\n\n************IN THE MIDDLE"
      $(CC) -c 1.cpp

Author Comment

ID: 12160709
I mean this src

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"
rm 1.o


Author Comment

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

Expert Comment

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

Author Comment

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
LVL 45

Expert Comment

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

libs_for_gcc = -lgnu
normal_libs =

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


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