Tech Support > Operating Systems > Linux / Variants > stupid make question
stupid make question
Posted by Robert Heller on June 26th, 2003


Frederic <fxx7792@cobalt.njit.edu>,
In a message on Thu, 26 Jun 2003 17:06:16 -0400, wrote :

F> Hi, all,
F>
F> I am modifying a big program written by somebody else.
F> When I modified some ".h" files, say a.h, then I run "make all", but I
F> found out make didn't recompile those files which included "a.h" file. In
F> my case "a.h" has some inline functions, so I have to manually remove
F> those .o files in order to get a fresh incremental build.
F>
F> My question is: is this phenomenon caused by bad-wrritten make files or I
F> misunderstood the functionality of make? Thanks.

It is bad written make files. 'Make' is not super human, you need to
list *all* of the dependencies.

There are two options:

1) *Manually* listing all of the .h files:

foo.o : foo.c a.h b.h c.h ...

2) Use the c preprocessor to generate the header dependencies:

Typical makefile fragment:

HEADERS = Character.h Record.h Dice.h Monster.h Spells.h Dressings.h Space.h
LSRCS = Character.cc Dice.cc Monster.cc Spells.cc Dressings.cc Space.cc
CXX = c++
BaseCXXFLAGS = -g -O2
DEFS = -DSTDC_HEADERS=1 -DSIZEOF_LONG=4 -DSIZEOF_INT=4 -DHAVE_BOOL=1
SHLIB_CFLAGS = -fPIC
INCLUDES = -I.
CXXFLAGS = $(DEFS) $(BaseCXXFLAGS) $(SHLIB_CFLAGS) $(INCLUDES) -c -Wall

# other defs and rules ommited

# Make sure some target depends on .depend (I usually include .depend on
# the 'all' target).

..depend: $(LSRCS) $(HEADERS)
$(CXX) -M $(CXXFLAGS) $(LSRCS) > .depend
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif

man gcc (-M):

-M [ -MG ]
Tell the preprocessor to output a rule suitable for
make describing the dependencies of each object
file. For each source file, the preprocessor out<AD>
puts one make-rule whose target is the object file
name for that source file and whose dependencies
are all the files `#include'd in it. This rule may
be a single line or may be continued with `\'-new<AD>
line if it is long. The list of rules is printed
on standard output instead of the preprocessed C
program.

`-M' implies `-E'.

`-MG' says to treat missing header files as gener<AD>
ated files and assume they live in the same direc<AD>
tory as the source file. It must be specified in
addition to `-M'.




F>
F> ================================================== =============================================
F> |Frederic |
F> | |
F> |The road goes ever on and on. |
F> | - Bilbo Baggins |
F> ================================================== =============================================
F>







Posted by Frederic on June 26th, 2003


Thank you very much. This is the most informative answer I got.

I just refreshed my make knowledge and read all the makefiles in the
directories and found out the original author simply left out all the
".h" into consideration. I am just amazed that this problem had remained
uncovered for so long(since 1995). The program is a very large scientific
computation software and a few Profs and Ph.Ds use brute-force method to develop a
program with millions of lines of code. There is no design documents at
all. Maybe because most of the original authors were using Fortran before
and Fortran doesn't have the notion of header files.




On Thu, 26 Jun 2003, Robert Heller wrote: