makefile problem

Nicholas Leippe nick at
Wed Feb 16 10:55:26 MST 2005

On Wednesday 16 February 2005 04:32 am, nikhil d purwant wrote:
> hi people
>      so i got a good answer to my question about makefile the other day
> thanks the concerned people. now can anybody please explain me following
> lines from the makefile i have i know it has to do something with the
> ipmlicit rules but i'm not being able to figure out exactly what it is (the
> appending the part of the makefile
> ----------------------------------------------------------------------
> INCLUDEDIR =some path
> CC= gcc
> arrg.o:
>     $(CC) -c $(CFLAGS) arrg.c
> ----------------------------------------------------------------------
> also any pointers to understand modules and loading them and unloading them
> etc.

Understanding make files requires knowledge of many components. For example, 
in the above you are compiling a C source file into a program, thus make is 
given a rule instructing it how to determine when a component is out-of-date 
and needs to be rebuilt.  The rule is accompanied by a list of instructions 
for it to execute to cause the program to be compiled.  Each instruction is
first parsed by make, which does variable expansion, then passed to a shell
for execution.

Thus, for this, you also need to understand how to compile the program, which 
includes the flags needed for the preprocessor, compiler, and linker.

The CFLAGS line is simply assigning the string with all the -DXXX and stuff to 
the make variable 'CFLAGS', which is referenced below in the instruction via 
the '$(CFLAGS)'.

Because make is often used for these tasks, there are 'built-in' defaults that 
can handle many of the common cases for you, assuming you are using the 
common tools.

These defaults include rules, (which include guessing target filenames and 
source filenames based on relations and name extensions), as well as default 
lists of instructions for the default rules.  The rule above 'arrg.o:' is
making use of one of make's default rules, here make will look for any 
corresponding arrg.c arrg.C arrg.c++ arrg.<other
known language extension>, use the first one it finds, check to see if the 
source file is newer, and then invoke the instruction list if so.

C preprocessors, compilers, and linkers typically look for flags from 
predefined, psuedo-standard environment variables.  CFLAGS is one of them.  
The value in the variable is something that the compiler chain needs to 
understand, not make.  Make does, however, have some built-in defaults for 
many of these, but it doesn't necessarily know what they mean.

The default rules and instructions assume that the user is simply using these 
psuedo-standard environment variables, and provides default make variables 
that match, for convenience.

IOW, make's $(CFLAGS) is not necessarily the environment CFLAGS variable--you 
could use it to store anything you want, and use it anywhere you want if you 
write your own rules and instruction lists.  However, if you let make use its
defaults, it will assume CFLAGS corresponds, and pass its contents to the C 
compiler in the built-in, default C compiler instruction.

Sorry if I'm getting too verbose, or telling you something you already

If you're going to be getting into makefiles heavily, or even moderately,
I'd highly suggest simply reading straight through the entire info file at 
least once--it doesn't take all that long.  Then, the forest view will help 
you know where to look when you need details.

Additionally, it may help to familiarize yourself with the c compiler's 
invocation.  Usually 'gcc --help' and 'ld --help' will give you all you 
really need to know.

Also, you may find subscribing to the gnu make mailing list helpful.  I have 
found them to be very responsive, and always helpful.


Nicholas Leippe
Sales Team Automation, LLC
1335 West 1650 North, Suite C
Springville, UT  84663 +1 801.853.4090

More information about the PLUG mailing list