summaryrefslogtreecommitdiff
path: root/mk/recurse.mk
blob: 2bb370deeb8f5940654f2d691e078ffa32f63099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

##################################################################
#
# 		Recursive stuff
#
##################################################################

# Here are the diabolically clever rules that
# 
# (a) for each "recursive target" <t>
#     propagates "make <t>" to directories in SUBDIRS
#
# (b) when SUBDIRS is empty,
#     for each "multi-way-target" <t>
#     calls "make way=w <t>" for each w in $(WAYS)
#
#     This has the effect of making the standard target
#     in each of the specified ways (as well as in the normal way

# Controlling variables
#	WAYS    = extra (beyond the normal way) ways to build things in
# 	SUBDIRS = subdirectories to recurse into

# No ways, so iterate over the SUBDIRS

# note about recursively invoking make: we'd like make to drop all the
# way back to the top level if it fails in any of the
# sub(sub-...)directories.  This is done by setting the -e flag to the
# shell during the loop, which causes an immediate failure if any of
# the shell commands fail.

# One exception: if the user gave the -i or -k flag to make in the
# first place, we'd like to reverse this behaviour.  So we check for
# these flags, and set the -e flag appropriately.  NOTE: watch out for
# the --no-print-directory flag which is passed to recursive
# invocations of make.
#
ifeq "$(way)" ""
ifneq "$(SUBDIRS)" ""

# we override the 'boot', 'all' and 'install' targets in the top
# level Makefile. Some of the sub-projects also set 'boot' to empty.

ifeq "$(NO_ALL_TARGET)" "YES"
ALL_TARGET     =
else
ALL_TARGET     = all
endif

ifeq "$(NO_BOOT_TARGET)" "YES"
BOOT_TARGET    =
else
BOOT_TARGET    = boot
endif

ifeq "$(NO_INSTALL_TARGET)" "YES"
INSTALL_TARGET =
INSTALL_DOCS_TARGET =
else
INSTALL_TARGET = install
INSTALL_DOCS_TARGET = install-docs
endif

$(ALL_TARGET) docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
	@echo "------------------------------------------------------------------------"
	@echo "== Recursively making \`$@' in $(SUBDIRS) ..."
	@echo "PWD = $(shell pwd)"
	@echo "------------------------------------------------------------------------"
# Don't rely on -e working, instead we check exit return codes from sub-makes.
	@case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
	if [ $$x_on_err -eq 0 ]; \
	    then echo "Won't exit on error due to MFLAGS: ${MFLAGS}"; \
	fi; \
	for i in $(SUBDIRS); do \
	  echo "------------------------------------------------------------------------"; \
	  echo "== $(MAKE) $@ $(MFLAGS);"; \
	  echo " in $(shell pwd)/$$i"; \
	  echo "------------------------------------------------------------------------"; \
	  $(MAKE) --no-print-directory -C $$i $(MFLAGS) $@ CLEAN_ALL_STAGES=YES; \
	  if [ $$? -eq 0 -o $$x_on_err -eq 0 ]; \
	      then echo "Finished making $@ in $$i": $$?; \
	      else echo "Failed making $@ in $$i": $$?; exit 1; \
	  fi; \
	done
	@echo "------------------------------------------------------------------------"
	@echo "== Finished making \`$@' in $(SUBDIRS) ..."
	@echo "PWD = $(shell pwd)"
	@echo "------------------------------------------------------------------------"

endif
endif

#
# Selectively building subdirectories.
#
#
ifneq "$(SUBDIRS)" ""
$(SUBDIRS) ::
	  $(MAKE) -C $@ $(MFLAGS)
endif