Ensure runhaskell is rebuild in stage2
[ghc-hetmet.git] / mk / recurse.mk
1
2 ##################################################################
3 #
4 #               Recursive stuff
5 #
6 ##################################################################
7
8 # Here are the diabolically clever rules that
9
10 # (a) for each "recursive target" <t>
11 #     propagates "make <t>" to directories in SUBDIRS
12 #
13 # (b) when SUBDIRS is empty,
14 #     for each "multi-way-target" <t>
15 #     calls "make way=w <t>" for each w in $(WAYS)
16 #
17 #     This has the effect of making the standard target
18 #     in each of the specified ways (as well as in the normal way
19
20 # Controlling variables
21 #       WAYS    = extra (beyond the normal way) ways to build things in
22 #       SUBDIRS = subdirectories to recurse into
23
24 # No ways, so iterate over the SUBDIRS
25
26 # note about recursively invoking make: we'd like make to drop all the
27 # way back to the top level if it fails in any of the
28 # sub(sub-...)directories.  This is done by setting the -e flag to the
29 # shell during the loop, which causes an immediate failure if any of
30 # the shell commands fail.
31
32 # One exception: if the user gave the -i or -k flag to make in the
33 # first place, we'd like to reverse this behaviour.  So we check for
34 # these flags, and set the -e flag appropriately.  NOTE: watch out for
35 # the --no-print-directory flag which is passed to recursive
36 # invocations of make.
37 #
38 ifeq "$(way)" ""
39 ifneq "$(SUBDIRS)" ""
40
41 # we override the 'boot', 'all' and 'install' targets in the top
42 # level Makefile. Some of the sub-projects also set 'boot' to empty.
43
44 ifeq "$(NO_ALL_TARGET)" "YES"
45 ALL_TARGET     =
46 else
47 ALL_TARGET     = all
48 endif
49
50 ifeq "$(NO_BOOT_TARGET)" "YES"
51 BOOT_TARGET    =
52 else
53 BOOT_TARGET    = boot
54 endif
55
56 ifeq "$(NO_INSTALL_TARGET)" "YES"
57 INSTALL_TARGET =
58 INSTALL_DOCS_TARGET =
59 else
60 INSTALL_TARGET = install
61 INSTALL_DOCS_TARGET = install-docs
62 endif
63
64 $(ALL_TARGET) docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
65         @echo "------------------------------------------------------------------------"
66         @echo "== Recursively making \`$@' in $(SUBDIRS) ..."
67         @echo "PWD = $(shell pwd)"
68         @echo "------------------------------------------------------------------------"
69 # Don't rely on -e working, instead we check exit return codes from sub-makes.
70         @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
71         if [ $$x_on_err -eq 0 ]; \
72             then echo "Won't exit on error due to MFLAGS: ${MFLAGS}"; \
73         fi; \
74         for i in $(SUBDIRS); do \
75           echo "------------------------------------------------------------------------"; \
76           echo "== $(MAKE) $@ $(MFLAGS);"; \
77           echo " in $(shell pwd)/$$i"; \
78           echo "------------------------------------------------------------------------"; \
79           $(MAKE) --no-print-directory -C $$i $(MFLAGS) $@; \
80           if [ $$? -eq 0 -o $$x_on_err -eq 0 ]; \
81               then echo "Finished making $@ in $$i": $$?; \
82               else echo "Failed making $@ in $$i": $$?; exit 1; \
83           fi; \
84         done
85         @echo "------------------------------------------------------------------------"
86         @echo "== Finished making \`$@' in $(SUBDIRS) ..."
87         @echo "PWD = $(shell pwd)"
88         @echo "------------------------------------------------------------------------"
89
90 endif
91 endif
92
93 #
94 # Selectively building subdirectories.
95 #
96 #
97 ifneq "$(SUBDIRS)" ""
98 $(SUBDIRS) ::
99           $(MAKE) -C $@ $(MFLAGS)
100 endif
101