Link to home
Start Free TrialLog in
Avatar of albusaidi
albusaidi

asked on

makefile with some flags ?


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  )
Avatar of sunnycoder
sunnycoder
Flag of India image

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
Avatar of albusaidi
albusaidi

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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

No one can make it more clear ....
You wish to ignore lines of makefile or that of source code ?
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
-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