[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make always builds everything

From: Paul Smith
Subject: Re: make always builds everything
Date: Sun, 13 Nov 2011 11:12:28 -0500

On Sat, 2011-11-12 at 18:42 -0600, Edgar wrote:
> I'm relatively new to make, but for the life of me I can't get make to 
> work the way it is supposed to by only rebuilding what is necessary. It 
> always rebuilds everything all over again and I don't know what I am 
> doing wrong. Hopefully someone here can take a look at my makefiles and 
> tell me what is wrong.

Generally we prefer that you create a small, completely self-contained
example that shows the problem and post that here, instead of referring
us to a large and complex build environment and asking us to debug it.

One excellent reason for this is that by trying to generate a minimal
example of the problem, probably 80% of the time you'll figure it out
for yourself and end up not needing to ask for help at all.

However, I took a quick jump over to your thread at and
immediately saw your problem.

All your rules have extra prerequisites on them:

        $(OBJDIR)/%.d : src/%.c makebuilddirs $(FIXDFILES)
        $(OBJDIR)/%.o : src/%.c $(OBJDIR)/%.d
        makebuilddirs :
                -$(MKDIR) $(LIBDIR)
                -$(MKDIR) $(subst /,$(SLASH),$(OBJDIR))

Here we see that all .o's depend on the .d files and all .d files depend
on a target "makebuilddirs".  That target creates directories, but the
target itself (a file named "makebuilddirs") is never created.  That
means that the target "makebuilddirs" is never up to date, and that
means that the .d target is always out of date, and that means that
the .o target is always out of date, and that means make will always
rebuild it.

Every time you run make it "rebuilds" the makebuilddirs target and that
causes every other target in your makefile which depends on it (or
depends on something that depends on it) to be rebuilt.

If you run make with the -d flag (debugging) you'll see what is going
on.  It does generate a lot of output, I know, but it's not too hard to
understand if you study it for a few minutes.  Creating a small example
is also an excellent way to reduce the amount of output that -d gives to
a more manageable level.


 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

[Prev in Thread] Current Thread [Next in Thread]