source: rtems/c/src/automake/subdirs.am @ 7ec982bf

Last change on this file since 7ec982bf was 7ec982bf, checked in by Chris Johns <chrisj@…>, on May 26, 2017 at 12:35:17 AM

build-system: Fix the targets support for the parallel build.

  • Property mode set to 100644
File size: 3.0 KB
Line 
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
12SUBDIRS_dot                            = $(filter     .,$(_SUBDIRS))
13SUBDIRS_no_dot                         = $(filter-out .,$(_SUBDIRS))
14SUBDIRS_no_dot_no_wrapup               = $(filter-out wrapup,$(SUBDIRS_no_dot))
15SUBDIRS_no_dot_no_testsuites           = $(filter-out testsuites,$(SUBDIRS_no_dot))
16SUBDIRS_no_dot_no_wrapup_no_testsuites = $(filter-out testsuites,$(SUBDIRS_no_dot_no_wrapup))
17SUBDIRS_wrapup                         = $(filter     wrapup,$(SUBDIRS_no_dot))
18SUBDIRS_testsuites                     = $(filter     testsuites,$(SUBDIRS_no_dot))
19
20SUBDIR_TARGET     = $(subst /,-,$1)
21PREINSTALL_TARGET = preinstall-$(call SUBDIR_TARGET,$(1))
22
23preintstall_targets  = $(if "$(SUBDIRS_dot)" ".",preinstall-dot) $(foreach D,$(SUBDIRS_no_dot),$(call PREINSTALL_TARGET,$(D)))
24
25define PREINSTALL_DIR
26.PHONY: $1
27$1:
28        @+set fnord $(MAKEFLAGS); amf=$$$$2; \
29        subdir=$(2); \
30        subdir_label=`echo $(1) | sed -e 's/preinstall-//'`; \
31        target=`echo $$@ | sed -e 's/-recursive//' -e "s/-$$$${subdir_label}//"`$(3); \
32        echo "Making $$$$target in $$$$subdir"; \
33        (cd $$$$subdir && $(MAKE) $(AM_MAKEFLAGS) $$$$target) \
34         || case "$$$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac;
35endef
36
37$(if "$(SUBDIRS_dot)" ".",$(eval $(call PREINSTALL_DIR,preinstall-dot,.,-am)))
38
39$(foreach D,$(SUBDIRS_no_dot),$(eval $(call PREINSTALL_DIR,$(call PREINSTALL_TARGET,$(D)),$(D))))
40
41preinstall: $(preintstall_targets)
42.PHONY: preinstall
43
44define CPUKITDIR
45.PHONY: $1
46$1: $(preintstall_targets)
47        @+set fnord $(MAKEFLAGS); amf=$$$$2; \
48        subdir=$(2); \
49        target=`echo $(MAKECMDGOALS) | sed s/-recursive//`; \
50        if test "$$$$target" = "all-local-am"; then \
51          target="all-am"; \
52        fi; \
53        if test "$$$$target" = "all-local"; then \
54          target="all"; \
55        fi; \
56        echo "Making $$$$target in $$$$subdir"; \
57        if test "$$$$subdir" != "."; then \
58          cd $$$$subdir; \
59          $(MAKE) $(AM_MAKEFLAGS) $$$$target; \
60        fi;
61endef
62
63#
64# This GNU make syntax is being used to stop automake thinking the code is for
65# it.
66#
67$(if "$(SUBDIRS_dot)" ".",$(eval $(call CPUKITDIR,dot,.)))
68
69$(foreach D,$(SUBDIRS_no_dot),$(eval $(call CPUKITDIR,$(D),$(D))))
70
71#
72# If there is a wrapup make it depend on all other directories except the
73# testsuite so it is not entered until everything but the testsuite has
74# finished.
75#
76$(if "$(SUBDIRS_wrapup)" "wrapup",wrapup: dot $(SUBDIRS_no_dot_no_wrapup_no_testsuites))
77
78#
79# If there is a testsuite make it depend on all other directories so it is not
80# entered until everything else has finished.
81#
82$(if "$(SUBDIRS_testsuites)" "testsuites",testsuites: dot $(SUBDIRS_no_dot_no_testsuites))
83
84#
85# The general build all rule for automake.
86#
87all-local: preinstall $(if "$(SUBDIRS_dot)" ".",dot) $(SUBDIRS_no_dot)
Note: See TracBrowser for help on using the repository browser.