Originally Posted by sam_sung
the macro LDFLAGS and CC is not defined anywhere. doesn't they need to be defined ? could u please tell me what does -O2 and -s do ?
CC is the default C compiler on the system -- it's a built-in default in make
and is gcc
on a Linux system (it can also be cc
which is a symbolic link to gcc
on most if not all Linux systems).
LDFLAGS is commonly used to define libraries required by targets you're building; e.g.,
would define the math library to the linker. Note that it doesn't hurt to have one or more LDFLAGS defined that then apply to every target (if a particular target doesn't use anything in a given library it's more or less ignored). By using the -lsomething
you're only extracting objects from a given library if needed, you're not linking the entire content of the library.
You can, of course, define multiple variants of LDFLAGS and edit their names into the compilation lines in your Makefile; you're using LDFLAGS as a convenient definition that affects all targets in one place. And, too, you can simply delete LDFLAGS from the lines that don't require any library flags or add additional libraries with an explicit -llibname
as necessary. It's something you do once when you're constructing your Makefile.
Something else that useful is multiple CFLAGS definitions for multiple platforms (if you're working with multiple platforms, that is); e.g.,
# use this one for gcc 32-bit
#CFLAGS = -O2
# use this one for Sun SPARC
#CFLAGS = -xarch=native64 -xO3 -xautopar -xbuiltin=%all -I$(BASDIR)/include
# use this one for 64-bit
CFLAGS = -O2 -FPIC -m64
You can simply uncomment the one you need or place the one you need last in the sequence -- make
uses the last definition.
Hope this helps some.