help-make
[Top][All Lists]
Advanced

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

how to handle build directory prerequisites


From: Justin Chen-Wells
Subject: how to handle build directory prerequisites
Date: Mon, 18 Nov 2002 16:05:55 -0500

Hi--

What's the right way to handle dependency on a build directory? 
I want to make sure my build directory gets created before I try
and generate files there.

My first attempt looks like this:

        BUILD_DIR=build

        all: $(BUILD_DIR)/foo $(BUILD_DIR)/bar

        $(BUILD_DIR):
                mkdir $(BUILD_DIR)

        $(BUILD_DIR)/foo: $(BUILD_DIR)
                echo "hello" > $(BUILD_DIR)/foo

        $(BUILD_DIR)/bar: $(BUILD_DIR)
                sleep 1
                echo "hi there" > $(BUILD_DIR)/bar


That works, but it isn't perfect. The trouble is when you run make
a second time it does unnecessary work. Writing files into the
build directory touches its timestamp (on my platform anyway). The
build directory winds up being newer than some of its contents, so
make regenerates the contents.

I looked through the manual but I couldn't see anything that would
help me here. I'm sorry if I just missed it, or I'm missing 
something obvious.

I guess what I want is to have make ignore the timestamp for 
$(BUILD_DIR) only, invoking that rule only if it fails to exist.

Justin





reply via email to

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