help-make
[Top][All Lists]
Advanced

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

Re: Copying files and making directories


From: Paul D. Smith
Subject: Re: Copying files and making directories
Date: Wed, 7 Aug 2002 19:24:26 -0400

%% Richard Cooper <address@hidden> writes:

  rc> 1) To build anything that is a directory, mkdir it.

  rc> 2) Anything that is a directory is dependant on its parent directory

  rc> 3) This is a generalisation of (2): Anything that has a path in its name
  rc> depends on that path, i.e. A/B/foo.c is dependant on A/B/

  rc> 4) If A is dependant on B and they have the same filenames but different
  rc> paths then A is build by copying B to A

  rc> Are these possible to express? If they are any help with writing
  rc> them would be gratefully received.

It may be possible to express some form of #3, but ultimately I think
that you are going about this all wrong.

In general attempting to auto-create directories by making them
prerequisites, etc. is doomed to failure.  Directories are so different
from files, in the way they work (when their time-last-modified is set)
and how they're used that it only makes sense in limited circumstances.


A much better idea is to use the $(shell ...) function to pre-create
them.

Suppose you can compute a list of directories that will need to exist;
maybe even something like:

  DIRS := $(dir $(SRCS))

or something.  Then you can create them "behind make's back" with
something like this:

  _x := $(shell for d in . $(DIRS); do [ -d $$d ] || mkdir -p $$d; done)

This happens when the makefile is being read in, long before make ever
thinks about whether to build a target or not, and it ensures your
directories are all ready and waiting.

The only bad part is that it creates all directories, even ones you
might not use.  But, that's usually not a big deal.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "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]