[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Hierarchical make: How to avoid unnecessarily going into certain direct
From: |
Peng Yu |
Subject: |
Hierarchical make: How to avoid unnecessarily going into certain directories? |
Date: |
Sat, 31 Jul 2010 01:21:54 -0500 |
Hi,
My questions is how to more efficiently run make in hierarchy of
directories. Let me give the following example to demonstrate what I
mean.
I have the following two directories leaf/ and internal/, each of
which has a Makefile as shown below. Note that the targets in leaf/
don't depend any files that are not in leaf/; targets in internal/
depend on targets in leaf/.
To make sure everything is updated, I have a Makefile (also shown
below). Note that I have to set ".PHONY: leaf/.dir", because GNU Make
has to go into this directory to test if anything need to be made. But
the problem is that GNU Make always go to internal/ to check if
anything need to be updated, even if the time stamps of leaf/.dir and
internal/.dir can be used to determine if make need to go to
internal/.
I guess this is because that once make has an dependence graph build
internally, it is not going to check if it actually need to update a
rule, but rather it propagates the updates. I'm wondering if there is
a way to change my Makefiles or supply some options to make to avoid
go into internal/ if it is unnecessary?
$ ls leaf/
input1.txt input2.txt Makefile
$ ls internal/
Makefile
$ cat leaf/Makefile
.PHONY: all clean
all:.dir
.INTERMEDIATE: all-dir
.dir: all-dir
touch $@
all-dir: result1.txt
result1.txt: input1.txt
touch $@
all-dir: result2.txt
result2.txt: input2.txt
touch $@
clean:
$(RM) .dir result1.txt result2.txt
$ cat internal/Makefile
.PHONY: all clean
all:.dir
.INTERMEDIATE: all-dir
.dir: all-dir
touch $@
all-dir: result1.txt
result1.txt: ../leaf/result1.txt
touch $@
all-dir: result2.txt
result2.txt: ../leaf/result2.txt
touch $@
clean:
$(RM) .dir result1.txt result2.txt
$ cat Makefile
.PHONY: all clean
# I need set leaf/.dir as .PHONY, because I always
# need to go in this directory to test
# if anything needed to be updated.
# But internal/.dir is always going to be updated.
# I think this is because GNU Make doesn't check
# the rule "internal/.dir: leaf/.dir" need be updated or not
# , because it assumes that leaf/.dir is remade so internal/.dir
# should be remade.
#
.PHONY: leaf/.dir
all: leaf/.dir
leaf/.dir:
$(MAKE) -C $(dir $@)
all: internal/.dir
internal/.dir: leaf/.dir
$(MAKE) -C $(dir $@)
clean:
$(MAKE) -C leaf clean; $(MAKE) -C internal clean
$ make
make -C leaf/
make[1]: Entering directory `/tmp/hierachy/leaf'
touch result1.txt
touch result2.txt
touch .dir
make[1]: Leaving directory `/tmp/hierachy/leaf'
make -C internal/
make[1]: Entering directory `/tmp/hierachy/internal'
touch result1.txt
touch result2.txt
touch .dir
make[1]: Leaving directory `/tmp/hierachy/internal'
$ make
make -C leaf/
make[1]: Entering directory `/tmp/hierachy/leaf'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/tmp/hierachy/leaf'
make -C internal/
make[1]: Entering directory `/tmp/hierachy/internal'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/tmp/hierachy/internal'
####
Note that make still goes into internal to check if anything should be
made, even if it doesn't have to.
--
Regards,
Peng
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Hierarchical make: How to avoid unnecessarily going into certain directories?,
Peng Yu <=