[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to create a single rule to build a directory as necessary
From: |
Kristof Provost |
Subject: |
Re: how to create a single rule to build a directory as necessary |
Date: |
Fri, 17 Jul 2009 13:51:06 +0200 |
User-agent: |
Mutt/1.5.14 (2007-03-31) |
On 2009-07-17 04:08:09 (-0400), Robert P. J. Day <address@hidden> wrote:
>
> let's see if i can explain this even remotely clearly. i'm looking
> at the Makefile for the linux kernel, and there are a number of rules
> related to files under the "include/config" directory, many of which
> require that directory to already exist (for the purposes of, say,
> copying a new file under there).
>
> as i read it, for simplicity, rather than have to check for the
> existence of that directory every single time in every rule, let's say
> there are two major targets in the Makefile, with the following
> dependency:
>
> t1:
> t2: t1
>
> all the directory-related stuff happens in the rule for t2 and beyond
> but, to take care of that requirement that include/config needs to
> exist, it's created (with mkdir, naturally) as the last action in t1:,
> for *no* good reason, i might add, other than to set things up for t2.
>
> it seems like a simple solution, and it certainly cuts down on all
> that checking that happens in t2 if you can assume that that directory
> is guaranteed to exist. however, it turns out that the very existence
> of that empty directory screws up some *other* operations, since other
> rules look for the existence of that directory and, if they find it,
> happily assume that it's been fully processed, which of course it
> *hasn't* -- it was simply created prematurely to make subsequent rules
> simpler.
>
> is there a way to write rules that will invoke both a wildcard and
> specific pattern to build that directory *only* when it's needed? i'm
> thinking of something along the lines of:
>
> include/config/%:
> mkdir -p include/config
>
> include/config/fred:
> rule specifically for fred
>
> target: include/config/fred
> ... etc etc ...
>
> does that make sense? if something depends on, say,
> include/config/fred, i want an implicit rule to make sure the
> directory exists, *then* process the fred-specific rule. that means i
> no longer need to create that directory ahead of time, which would
> make some other steps work properly.
>
> thoughts? did i explain this adequately?
Making directories with GNU make has a couple of gotchas.
See http://www.cmcrossroads.com/content/view/6936/120/ for the full
explanation.
I think the main issue here is that the timestamp on a directory is
updated whenever files are added/removed from it. That would lead to
make performing unnecessary rebuilds.
The entire 'Ask Mr. Make' series is worth reading if you're dealing with
advanced make.
See http://www.cmcrossroads.com/content/category/8/147/268/.
Regards,
Kristof