help-make
[Top][All Lists]
Advanced

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

how to create a single rule to build a directory as necessary


From: Robert P. J. Day
Subject: how to create a single rule to build a directory as necessary
Date: Fri, 17 Jul 2009 04:08:09 -0400 (EDT)
User-agent: Alpine 2.00 (LFD 1167 2008-08-23)

  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?

rday
--

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

        Linux Consulting, Training and Annoying Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday
"Kernel Newbie Corner" column @ linux.com:          http://cli.gs/WG6WYX
========================================================================




reply via email to

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