tags:

views:

510

answers:

4

I'm new using makefiles and I have some makefiles. One of them has these statements I tried to understand but I can't.

What is this makefile doing?

# debugging support
ifeq ($(DEBUG), true)
CFLAGS+=-DDEBUG -g
endif 

ifeq ($(DEBUG), gdb)
CFLAGS+=-g
endif

ifeq ($(PROFILING), true)
CFLAGS+=-p
endif

# symbolic names debugging
ifeq ($(DEBUG_NAMES), true)
CFLAGS+=-DDEBUG_NAMES
endif 

# architecture TODO: add others
ifeq ($(ARCH), unix)
CFLAGS+=-DUNIX
endif

# TODO: GC settings
ifeq ($(HEAP), malloc)
CFLAGS+=-DHEAP_MALLOC
endif

ifeq ($(STACK), malloc)
CFLAGS+=-DSTACK_MALLOC
endif

# class loading method
ifeq ($(CLASS), external)
CFLAGS+=-DEXTERNAL_TUK
endif

# monitor allocation
ifeq ($(MONITORS), ondemand)
CFLAGS+=-DON_DEMAND_MONITORS
endif

Amri

+4  A: 

This checks for the values of environmental variables and configures the build process with specific options for the compiler ( I think ) .

Geo
Yes you are correct.
Alan
They don't have to be environmental variables; you can also give them on the command line, as in "make DEBUG=gdb ARCH=unix".
Jouni K. Seppänen
+5  A: 

Essentially the makefile is doing a bunch of checks and adding compiler flags based on the state of certain variables. For instance:

ifeq ($(DEBUG), true)

CFLAGS+=-DDEBUG -g

endif

If the DEBUG variable $(DEBUG) is set to true, then define the macro DEBUG, and set the compiler to output debug binaries (-g).

Every other statement is roughly the same pattern.

Alan
could you tell me please, what is CFLAGS options or values could be
Have a look at how CFlags is used - it is probably passed to GCC. In that case, have a look at gcc's man page (i.e type man GCC at the command line on a linux system or google for some detail)
Tom Leys
A: 

I know that the value of CFLAGS is change according the condtion, but the problem for me is I want to understand or could anyone explain what is i.e. CFLAGS+=-g, CFLAGS+=-p, .. so on because I don't know it

I'm guessing that += simply adds those arguments to the existing ones.
Geo
Look at the man page for gcc, or cc (or whatever c compiler you are using).That will explain all the various compiler options.
Alan
+1  A: 

CFLAGS is a string of arguments that will be passed to the C compiler when it is called.

If you don't know what the arguments mean, you need to look at the help for your C compiler. For example:

man cc
man gcc
cc --help
gcc --help
Dave Costa