2009-02-26 120 views

回答

5

我似乎记得能够调用make递归,沿着线的东西:我已经做了类似的技巧使子目录中

all: 
    -mkdir $(TEMPDIR) 
    $(MAKE) $(MLAGS) old_all 
    -rm -rf $(TEMPDIR) 

old_all: ... rest of stuff. 

all: 
    @for i in $(SUBDIRS); do \ 
     echo "make all in $$i..."; \ 
     (cd $$i; $(MAKE) $(MLAGS) all); \ 
    done 

刚才检查,并这工作正常:

$ cat Makefile 
all: 
    -mkdir tempdir 
    -echo hello >tempdir/hello 
    -echo goodbye >tempdir/goodbye 
    $(MAKE) $(MFLAGS) old_all 
    -rm -rf tempdir 

old_all: 
    ls -al tempdir 

$ make all 
mkdir tempdir 
echo hello >tempdir/hello 
echo goodbye >tempdir/goodbye 
make old_all 
make[1]: Entering directory '/home/pax' 
ls -al tempdir 
total 2 
drwxr-xr-x+ 2 allachan None 0 Feb 26 15:00 . 
drwxrwxrwx+ 4 allachan None 0 Feb 26 15:00 .. 
-rw-r--r-- 1 allachan None 8 Feb 26 15:00 goodbye 
-rw-r--r-- 1 allachan None 6 Feb 26 15:00 hello 
make[1]: Leaving directory '/home/pax' 
rm -rf tempdir 

$ ls -al tempdir 
ls: cannot access tempdir: No such file or directory 
9

用GNU做,至少,

TMPDIR := $(shell mktemp -d) 

会得到您的临时目录中。除了明显的rmdir "$(TMPDIR)"作为all目标的一部分之外,我无法想出最后清理它的好方法。

+0

如果所有的目标都是最新的,那么评估`TMPDIR`将会创建目录,`all`的规则将永远不会被执行删除它。 – 2010-09-27 14:17:58

+1

@Josh Kelley:.PHONY会照顾到这一点。 – derobert 2010-09-29 05:07:46

+0

你说得对,对不起。 – 2010-09-29 12:15:27

3

这些以前的答案要么没有工作,要么显得过于复杂。这是一个更直截了当的例子,我能弄清楚:

PACKAGE := "audit" 
all: 
    $(eval TMP := $(shell mktemp -d)) 
    @mkdir $(TMP)/$(PACKAGE) 
    rm -rf $(TMP)