[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: creating directories through dependency
From: |
Philip Guenther |
Subject: |
Re: creating directories through dependency |
Date: |
Tue, 9 Jan 2007 01:42:52 -0700 |
On 1/9/07, Michal Nowikowski <address@hidden> wrote:
I have a problem of chicken-and-egg type. Makefile:
---
BUILDDIR=build
$(BUILDDIR):
mkdir -p $(BUILDDIR)
$(objs):%.o:%.c $(BUILDDIR)
$(CC) -c $< -o $(BUILDDIR)/$@
---
In this situation BUILDDIR is created before sources are compiled.
But when everything is compiled and I re-run make it tries to recompile
some source files because make claims that BUILDDIR is newer then
some object files. It is like that because BUILDDIR had been changing when
new object file were generated and put into it.
How to solve this problem i.e. avoid recompiling files during subsequent
make run?
There are a number of ways to solve this. Here are the (IMHO) best two:
1) use an order-only dependency (requires GNU make version 3.80 or later):
put the dependency on $(BUILDDIR) after a '|', like this:
$(objs):%.o:%.c | $(BUILDDIR)
2) just create the directory at the start of the run and don't put any
dependencies on
it at all. The only difference is that $(BUILDDIR) will be
created even when it wasn't
really needed for the particular target(s) being requested. On
the plus side, it
requires less memory and work from make.
$(shell mkdir -p $(BUILDDIR))
Philip Guenther
Re: creating directories through dependency, Danny Boelens, 2007/01/09