[Top][All Lists]

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

RE: Trying to get rid of one redundand rule

From: Paul D. Smith
Subject: RE: Trying to get rid of one redundand rule
Date: Tue, 14 Jun 2005 13:32:54 -0400

%% <address@hidden> writes:

  af> The generated files $(BLDDIR)/rcompl.cpp and rcomp.cpp are
  af> _SOURCE_ files too.

No.  You're thinking of them as source files in the C/C++ sense, because
they contain C/C++ source code.

Make doesn't care about that: it doesn't know a C file from a socket.
Make just knows about targets.

To make, a "source file" is a file that make can't build (there are no
rules to build it).  That kind of file simply must exist before make
starts, or you get an error ("don't know how to build ...").  Those are
source files, to make.

Anything make can rebuild, is not a source file.

  af> PS: Here is my Makefile again

This makefile is too specialized to be used by anyone to reproduce your
problem; it relies on lots of files, etc. that exist only on your

I do have one comment, though:

  af> $(OBJECT): $(BLDDIR)/stamp $(BLDDIR)/rcomp.hpp

  af> $(BLDDIR)/stamp:
  af>   mkdir -p $(dir $@)
  af>   touch $@

This is not a good way to get the object directory created, at all.
First, if you ever wanted to try to use -j to get parallelism, your
makefile will break.

Second, there is a (mis-)feature in GNU make 3.80 and all previous
versions, where any pattern rule that references an absolute pathname is
deleted if that directory doesn't exist.  See this from the GNU make
ChangeLog (for the next release):

>       * rule.c (count_implicit_rule_limits): Don't delete patterns which
>       refer to absolute pathnames in directories that don't exist: some
>       portion of the makefile could create those directories before we
>       match the pattern.  Fixes bugs #775 and #108.

The "general" way to handle creation of directories is to use $(shell
...) in an immediate context: this way the directory is created as the
makefile is read in:

    __dummy := $(shell mkdir -p $(BLDDIR))

The (minor) downside to this is the directory will always be created,
even if no .o file is created.  If you want to avoid that you need to
get much more fancy.

 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]