1 | ## Copyright 2017 Chris Johns <chrisj@rtems.org> |
---|
2 | |
---|
3 | ## |
---|
4 | ## The following builds in parallel. The subdirectories are |
---|
5 | ## expanded into separate rules and all the targets are listed |
---|
6 | ## and make runs as many as it can. |
---|
7 | ## |
---|
8 | ## A macro is defined and evaluated once for each directory. This |
---|
9 | ## creates the instance of the rule. Use $(info ...) to print them. |
---|
10 | ## |
---|
11 | |
---|
12 | SUBDIRS_dot = $(filter .,$(_SUBDIRS)) |
---|
13 | SUBDIRS_no_dot = $(filter-out .,$(_SUBDIRS)) |
---|
14 | SUBDIRS_no_dot_no_wrapup = $(filter-out wrapup,$(SUBDIRS_no_dot)) |
---|
15 | SUBDIRS_wrapup = $(filter wrapup,$(SUBDIRS_no_dot)) |
---|
16 | |
---|
17 | SUBDIR_TARGET = $(subst /,-,$1) |
---|
18 | PREINSTALL_TARGET = preinstall-$(call SUBDIR_TARGET,$(1)) |
---|
19 | |
---|
20 | preintstall_targets = $(if "$(SUBDIRS_dot)" ".",preinstall-dot) $(foreach D,$(SUBDIRS_no_dot),$(call PREINSTALL_TARGET,$(D))) |
---|
21 | |
---|
22 | define PREINSTALL_DIR |
---|
23 | .PHONY: $1 |
---|
24 | $1: |
---|
25 | @+set fnord $(MAKEFLAGS); amf=$$$$2; \ |
---|
26 | subdir=$(2); \ |
---|
27 | subdir_label=`echo $(1) | sed -e 's/preinstall-//'`; \ |
---|
28 | target=`echo $$@ | sed -e 's/-recursive//' -e "s/-$$$${subdir_label}//"`$(3); \ |
---|
29 | echo "Making $$$$target in $$$$subdir"; \ |
---|
30 | (cd $$$$subdir && $(MAKE) $(AM_MAKEFLAGS) $$$$target) \ |
---|
31 | || case "$$$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; |
---|
32 | endef |
---|
33 | |
---|
34 | $(if "$(SUBDIRS_dot)" ".",$(eval $(call PREINSTALL_DIR,preinstall-dot,.,-am))) |
---|
35 | |
---|
36 | $(foreach D,$(SUBDIRS_no_dot),$(eval $(call PREINSTALL_DIR,$(call PREINSTALL_TARGET,$(D)),$(D)))) |
---|
37 | |
---|
38 | preinstall: $(preintstall_targets) |
---|
39 | .PHONY: preinstall |
---|
40 | |
---|
41 | define CPUKITDIR |
---|
42 | .PHONY: $1 |
---|
43 | $1: $(preintstall_targets) |
---|
44 | @+set fnord $(MAKEFLAGS); amf=$$$$2; \ |
---|
45 | subdir=$(2); \ |
---|
46 | target=`echo $(MAKECMDGOALS) | sed s/-recursive//`; \ |
---|
47 | if test "$$$$target" = "all-local-am"; then \ |
---|
48 | target="all-am"; \ |
---|
49 | fi; \ |
---|
50 | if test "$$$$target" = "all-local"; then \ |
---|
51 | target="all"; \ |
---|
52 | fi; \ |
---|
53 | echo "Making $$$$target in $$$$subdir"; \ |
---|
54 | if test "$$$$subdir" != "."; then \ |
---|
55 | cd $$$$subdir; \ |
---|
56 | $(MAKE) $(AM_MAKEFLAGS) $$$$target; \ |
---|
57 | fi; |
---|
58 | endef |
---|
59 | |
---|
60 | # |
---|
61 | # This GNU make syntax is being used to stop automake thinking the code is for |
---|
62 | # it. |
---|
63 | # |
---|
64 | $(if "$(SUBDIRS_dot)" ".",$(eval $(call CPUKITDIR,dot,.))) |
---|
65 | |
---|
66 | $(foreach D,$(SUBDIRS_no_dot),$(eval $(call CPUKITDIR,$(D),$(D)))) |
---|
67 | |
---|
68 | # |
---|
69 | # If there is a wrapup make it depend on all other directories so it is not |
---|
70 | # entered until they have finished. |
---|
71 | # |
---|
72 | $(if "$(SUBDIRS_wrapup)" "wrapup",wrapup: dot $(foreach D,$(SUBDIRS_no_dot_no_wrapup),$(D)),) |
---|
73 | |
---|
74 | all-local: preinstall $(if "$(SUBDIRS_dot)" ".",dot) $(SUBDIRS_no_dot) |
---|