[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Preconditions vs. Dependencies
From: |
natch |
Subject: |
Preconditions vs. Dependencies |
Date: |
Mon, 21 Nov 2005 18:24:35 -0500 |
User-agent: |
Mozilla Thunderbird 1.0.6 (Windows/20050716) |
I'm having a dependency problem that I can't find a good solution to. I
want to create files inside a directory other than that in which make is
executing. The easy solution is that the files depend on the directory
they are in, so make will not try to create the files unless the
directory is created first. However, if more than one file is created
in that directory, the timestamp on the directory is updated, and make
considers that prerequisite newer than the target. Consider the
following makefile:
DIR=outdir
FILES=$(DIR)/a $(DIR)/b $(DIR)/c
$(DIR):
mkdir $@
$(FILES): $(DIR)
touch $@
-
Starting with a clean directory, if I decide to
> make outdir/a
> make outdir/b
> make outdir/a
It will create the directory and make a, then make b, then make a again
(since creating b causes the directory to have a newer timestamp than
a). Eventually this system will settle down and consider everything up
to date (which I don't entirely understand). If I
> rm outdir/a
and ask it to
> make outdir/b
it will go ahead and make b because the directory is newer than b.
Does make allow for a solution to this problem? There's an ugly
solution involving directory creation in the target:
$(FILES):
if [ ! -d outdir ]; then mkdir outdir; fi
touch $@
But this adds a level of obscurity that I'd like to avoid. It looks
simple in this situation, but what happens with nested directories?
Such as:
DIR=outdir
SUBDIR1=sub
FILES=outdir/a outdir/sub/b
$(SUBDIR1): $(DIR)
mkdir $@
$(DIR):
mkdir $@
$(FILES): $(SUBDIR1)
This would cause make to try and remake subdir1 if outdir/a is
recreated, although this again would be unnecessary.
So existence of the directory is a precondition of the target, but not
necessarily a prerequisite. We don't care if the directory is newer
than the target, we just want to make sure it exists.
-
natch