[PATCH] build-system: Parallel build all subdirs.

Chris Johns chrisj at rtems.org
Wed May 24 10:00:11 UTC 2017


---
 c/Makefile.am                                      |   4 +-
 c/src/Makefile.am                                  |   2 +-
 c/src/automake/subdirs.am                          | 117 +++++++++++++++------
 c/src/lib/Makefile.am                              |   7 +-
 c/src/lib/libbsp/Makefile.am                       |   4 +-
 c/src/lib/libbsp/arm/Makefile.am                   |   2 +-
 c/src/lib/libbsp/bfin/Makefile.am                  |   2 +-
 c/src/lib/libbsp/epiphany/Makefile.am              |   2 +-
 c/src/lib/libbsp/i386/Makefile.am                  |   2 +-
 c/src/lib/libbsp/i386/pc386/Makefile.am            |   3 +-
 c/src/lib/libbsp/lm32/Makefile.am                  |   2 +-
 c/src/lib/libbsp/m32c/Makefile.am                  |   2 +-
 c/src/lib/libbsp/m68k/Makefile.am                  |   2 +-
 c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am     |   2 +-
 c/src/lib/libbsp/mips/Makefile.am                  |   2 +-
 c/src/lib/libbsp/moxie/Makefile.am                 |   2 +-
 c/src/lib/libbsp/nios2/Makefile.am                 |   2 +-
 c/src/lib/libbsp/no_cpu/Makefile.am                |   2 +-
 c/src/lib/libbsp/or1k/Makefile.am                  |   2 +-
 c/src/lib/libbsp/powerpc/Makefile.am               |   2 +-
 .../libbsp/powerpc/motorola_powerpc/Makefile.am    |   7 +-
 c/src/lib/libbsp/sh/Makefile.am                    |   2 +-
 c/src/lib/libbsp/sparc/Makefile.am                 |   2 +-
 c/src/lib/libbsp/sparc64/Makefile.am               |   2 +-
 c/src/lib/libbsp/v850/Makefile.am                  |   2 +-
 c/src/lib/libcpu/Makefile.am                       |   2 +-
 cpukit/Makefile.am                                 |  44 ++++----
 cpukit/automake/subdirs.am                         | 104 ++++++++++++------
 cpukit/libfs/Makefile.am                           |   2 +-
 cpukit/score/Makefile.am                           |   2 +-
 cpukit/score/cpu/Makefile.am                       |   2 +-
 31 files changed, 222 insertions(+), 114 deletions(-)

diff --git a/c/Makefile.am b/c/Makefile.am
index b44db89c21..81d8b7801f 100644
--- a/c/Makefile.am
+++ b/c/Makefile.am
@@ -11,8 +11,8 @@ SUBDIRS = . $(RTEMS_BSP)
 DIST_SUBDIRS = $(RTEMS_BSP)
 
 ## Let all RTEMS' make targets depend on ${RTEMS_BSP}
-all-local: ${RTEMS_BSP}
-preinstall-am: ${RTEMS_BSP}
+all-local: $(RTEMS_BSP)
+preinstall-am: $(RTEMS_BSP)
 
 ## Pull in extra files intro the distribution
 EXTRA_DIST = ACKNOWLEDGEMENTS
diff --git a/c/src/Makefile.am b/c/src/Makefile.am
index aeec2ea1d1..8fcdd645eb 100644
--- a/c/src/Makefile.am
+++ b/c/src/Makefile.am
@@ -1,6 +1,6 @@
 ACLOCAL_AMFLAGS = -I aclocal
 
-SUBDIRS = . @BSP_SUBDIRS@
+_SUBDIRS = . @BSP_SUBDIRS@
 DIST_SUBDIRS = @BSP_SUBDIRS@
 
 clean-local:
diff --git a/c/src/automake/subdirs.am b/c/src/automake/subdirs.am
index 1e0a9a757a..3e57f0c06f 100644
--- a/c/src/automake/subdirs.am
+++ b/c/src/automake/subdirs.am
@@ -1,30 +1,87 @@
-## Borrowed from automake-1.4 and adapted to RTEMS
-
-## NOTE: This is a temporary work-around to keep
-## RTEMS's non automake standard make targets working.
-## Once automake is fully integrated these make targets
-## and this file will probably be removed
-
-preinstall-recursive:
-	@set fnord $(MAKEFLAGS); amf=$$2; \
-	dot_seen=no; \
-	target=`echo $@ | sed s/-recursive//`; \
-	list='$(SUBDIRS)'; for subdir in $$list; do \
-	  echo "Making $$target in $$subdir"; \
-	  if test "$$subdir" = "."; then \
-	    dot_seen=yes; \
-	    local_target="$$target-am"; \
-	  else \
-	    local_target="$$target"; \
-	  fi; \
-	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
-## This trick allows "-k" to keep its natural meaning when running a
-## recursive rule.
-	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
-	done; \
-	if test "$$dot_seen" = "no"; then \
-	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
-	fi; test -z "$$fail"
-
-preinstall: preinstall-recursive
-.PHONY: preinstall-recursive
+## Copyright 2017 Chris Johns <chrisj at rtems.org>
+
+##
+## The following builds in parallel. The subdirectories are
+## expanded into separate rules and all the targets are listed
+## and make runs as many as it can.
+##
+## A macro is defined and evaluated once for each directory. This
+## creates the instance of the rule. Use $(info ...) to print them.
+##
+
+SUBDIRS_dot                            = $(filter     .,$(_SUBDIRS))
+SUBDIRS_no_dot                         = $(filter-out .,$(_SUBDIRS))
+SUBDIRS_no_dot_no_wrapup               = $(filter-out wrapup,$(SUBDIRS_no_dot))
+SUBDIRS_no_dot_no_testsuites           = $(filter-out testsuites,$(SUBDIRS_no_dot))
+SUBDIRS_no_dot_no_wrapup_no_testsuites = $(filter-out testsuites,$(SUBDIRS_no_dot_no_wrapup))
+SUBDIRS_wrapup                         = $(filter     wrapup,$(SUBDIRS_no_dot))
+SUBDIRS_testsuites                     = $(filter     testsuites,$(SUBDIRS_no_dot))
+
+SUBDIR_TARGET     = $(subst /,-,$1)
+PREINSTALL_TARGET = preinstall-$(call SUBDIR_TARGET,$(1))
+
+preintstall_targets  = $(if "$(SUBDIRS_dot)" ".",preinstall-dot) $(foreach D,$(SUBDIRS_no_dot),$(call PREINSTALL_TARGET,$(D)))
+
+define PREINSTALL_DIR
+.PHONY: $1
+$1:
+	@+set fnord $(MAKEFLAGS); amf=$$$$2; \
+	subdir=$(2); \
+	subdir_label=`echo $(1) | sed -e 's/preinstall-//'`; \
+	target=`echo $$@ | sed -e 's/-recursive//' -e "s/-$$$${subdir_label}//"`$(3); \
+	echo "Making $$$$target in $$$$subdir"; \
+	(cd $$$$subdir && $(MAKE) $(AM_MAKEFLAGS) $$$$target) \
+	 || case "$$$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac;
+endef
+
+$(if "$(SUBDIRS_dot)" ".",$(eval $(call PREINSTALL_DIR,preinstall-dot,.,-am)))
+
+$(foreach D,$(SUBDIRS_no_dot),$(eval $(call PREINSTALL_DIR,$(call PREINSTALL_TARGET,$(D)),$(D))))
+
+preinstall: $(preintstall_targets)
+.PHONY: preinstall
+
+define CPUKITDIR
+.PHONY: $1
+$1: $(preintstall_targets)
+	@+set fnord $(MAKEFLAGS); amf=$$$$2; \
+	subdir=$(2); \
+	target=`echo $(MAKECMDGOALS) | sed s/-recursive//`; \
+	if test "$$$$target" = "all-local-am"; then \
+	  target="all-am"; \
+	fi; \
+	if test "$$$$target" = "all-local"; then \
+	  target="all"; \
+	fi; \
+	echo "Making $$$$target in $$$$subdir"; \
+	if test "$$$$subdir" != "."; then \
+	  cd $$$$subdir; \
+	  $(MAKE) $(AM_MAKEFLAGS) $$$$local_target; \
+	fi;
+endef
+
+#
+# This GNU make syntax is being used to stop automake thinking the code is for
+# it.
+#
+$(if "$(SUBDIRS_dot)" ".",$(eval $(call CPUKITDIR,dot,.)))
+
+$(foreach D,$(SUBDIRS_no_dot),$(eval $(call CPUKITDIR,$(D),$(D))))
+
+#
+# If there is a wrapup make it depend on all other directories except the
+# testsuite so it is not entered until everything but the testsuite has
+# finished.
+#
+$(if "$(SUBDIRS_wrapup)" "wrapup",wrapup: dot $(SUBDIRS_no_dot_no_wrapup_no_testsuites))
+
+#
+# If there is a testsuite make it depend on all other directories so it is not
+# entered until everything else has finished.
+#
+$(if "$(SUBDIRS_testsuites)" "testsuites",testsuites: dot $(SUBDIRS_no_dot_no_testsuites))
+
+#
+# The general build all rule for automake.
+#
+all-local: preinstall $(if "$(SUBDIRS_dot)" ".",dot) $(SUBDIRS_no_dot)
diff --git a/c/src/lib/Makefile.am b/c/src/lib/Makefile.am
index 5c6de71375..ff39067ae9 100644
--- a/c/src/lib/Makefile.am
+++ b/c/src/lib/Makefile.am
@@ -1,4 +1,9 @@
-SUBDIRS = libcpu libbsp
+_SUBDIRS = libcpu libbsp
 
 include $(top_srcdir)/automake/subdirs.am
 include $(top_srcdir)/automake/local.am
+
+#
+# The libsp cannot be built until libcpu is built.
+#
+libbsp: libcpu
diff --git a/c/src/lib/libbsp/Makefile.am b/c/src/lib/libbsp/Makefile.am
index 85ddbe217b..840d52b033 100644
--- a/c/src/lib/libbsp/Makefile.am
+++ b/c/src/lib/libbsp/Makefile.am
@@ -1,6 +1,6 @@
 include $(top_srcdir)/automake/compile.am
 
-SUBDIRS = @libbsp_cpu_subdir@
+_SUBDIRS = @libbsp_cpu_subdir@
 DIST_SUBDIRS = @libbsp_cpu_subdir@
 
 EXTRA_DIST = MERGE.PROCEDURE bsp.am
@@ -42,5 +42,5 @@ include_bsp_HEADERS += shared/include/console-termios.h
 include_bsp_HEADERS += shared/include/gpio.h
 
 include $(srcdir)/preinstall.am
-include $(top_srcdir)/automake/subdirs.am
 include $(top_srcdir)/automake/local.am
+include $(top_srcdir)/automake/subdirs.am
diff --git a/c/src/lib/libbsp/arm/Makefile.am b/c/src/lib/libbsp/arm/Makefile.am
index a567a2c1c6..a8a0178560 100644
--- a/c/src/lib/libbsp/arm/Makefile.am
+++ b/c/src/lib/libbsp/arm/Makefile.am
@@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I ../../../aclocal
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
 ## Currently, the shared directory is not explicitly
 ## added but it is present in the source tree.
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include_bspdir = $(includedir)/bsp
 include_bsp_HEADERS = shared/include/linker-symbols.h
diff --git a/c/src/lib/libbsp/bfin/Makefile.am b/c/src/lib/libbsp/bfin/Makefile.am
index 140d76ee20..c25b2d3f99 100644
--- a/c/src/lib/libbsp/bfin/Makefile.am
+++ b/c/src/lib/libbsp/bfin/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
 include $(top_srcdir)/../../../automake/local.am
diff --git a/c/src/lib/libbsp/epiphany/Makefile.am b/c/src/lib/libbsp/epiphany/Makefile.am
index cdcc3fbd5c..86705a772c 100644
--- a/c/src/lib/libbsp/epiphany/Makefile.am
+++ b/c/src/lib/libbsp/epiphany/Makefile.am
@@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I ../../../aclocal
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
 ## Currently, the shared directory is not explicitly
 ## added but it is present in the source tree.
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 include $(srcdir)/preinstall.am
 include $(top_srcdir)/../../../automake/subdirs.am
 include $(top_srcdir)/../../../automake/local.am
diff --git a/c/src/lib/libbsp/i386/Makefile.am b/c/src/lib/libbsp/i386/Makefile.am
index 567f75fdbd..959646762f 100644
--- a/c/src/lib/libbsp/i386/Makefile.am
+++ b/c/src/lib/libbsp/i386/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 EXTRA_DIST =
 
diff --git a/c/src/lib/libbsp/i386/pc386/Makefile.am b/c/src/lib/libbsp/i386/pc386/Makefile.am
index d051da8ec7..8408db0095 100644
--- a/c/src/lib/libbsp/i386/pc386/Makefile.am
+++ b/c/src/lib/libbsp/i386/pc386/Makefile.am
@@ -23,7 +23,7 @@ DISTCLEANFILES = include/bspopts.h
 
 noinst_PROGRAMS =
 
-SUBDIRS = . tools
+_SUBDIRS = . tools
 
 nodist_include_bsp_HEADERS += include/bspimpl.h
 include_bsp_HEADERS  = ../../i386/shared/irq/irq.h
@@ -258,3 +258,4 @@ EXTRA_DIST += times_p5
 
 include $(srcdir)/preinstall.am
 include $(top_srcdir)/../../../../automake/local.am
+include $(top_srcdir)/../../../../automake/subdirs.am
diff --git a/c/src/lib/libbsp/lm32/Makefile.am b/c/src/lib/libbsp/lm32/Makefile.am
index 140d76ee20..c25b2d3f99 100644
--- a/c/src/lib/libbsp/lm32/Makefile.am
+++ b/c/src/lib/libbsp/lm32/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
 include $(top_srcdir)/../../../automake/local.am
diff --git a/c/src/lib/libbsp/m32c/Makefile.am b/c/src/lib/libbsp/m32c/Makefile.am
index f504c03a19..e99d8df18f 100644
--- a/c/src/lib/libbsp/m32c/Makefile.am
+++ b/c/src/lib/libbsp/m32c/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 EXTRA_DIST =
 
diff --git a/c/src/lib/libbsp/m68k/Makefile.am b/c/src/lib/libbsp/m68k/Makefile.am
index 925b543d13..634f7ff898 100644
--- a/c/src/lib/libbsp/m68k/Makefile.am
+++ b/c/src/lib/libbsp/m68k/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include_bspdir = $(includedir)/bsp
 include_bsp_HEADERS = shared/include/linker-symbols.h
diff --git a/c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am b/c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am
index 3411b27651..2ca635ba8b 100644
--- a/c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am
+++ b/c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am
@@ -13,7 +13,7 @@ nodist_include_HEADERS = include/bspopts.h
 nodist_include_bsp_HEADERS = ../../shared/include/bootcard.h
 DISTCLEANFILES = include/bspopts.h
 
-SUBDIRS = . tools
+_SUBDIRS = . tools
 
 include_HEADERS += include/coverhd.h
 include_HEADERS += include/i2c.h
diff --git a/c/src/lib/libbsp/mips/Makefile.am b/c/src/lib/libbsp/mips/Makefile.am
index d294e842ec..526453030c 100644
--- a/c/src/lib/libbsp/mips/Makefile.am
+++ b/c/src/lib/libbsp/mips/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
 include $(top_srcdir)/../../../automake/local.am
diff --git a/c/src/lib/libbsp/moxie/Makefile.am b/c/src/lib/libbsp/moxie/Makefile.am
index d8b53da543..3caad19373 100644
--- a/c/src/lib/libbsp/moxie/Makefile.am
+++ b/c/src/lib/libbsp/moxie/Makefile.am
@@ -5,7 +5,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
 include $(top_srcdir)/../../../automake/local.am
diff --git a/c/src/lib/libbsp/nios2/Makefile.am b/c/src/lib/libbsp/nios2/Makefile.am
index 140d76ee20..c25b2d3f99 100644
--- a/c/src/lib/libbsp/nios2/Makefile.am
+++ b/c/src/lib/libbsp/nios2/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
 include $(top_srcdir)/../../../automake/local.am
diff --git a/c/src/lib/libbsp/no_cpu/Makefile.am b/c/src/lib/libbsp/no_cpu/Makefile.am
index 140d76ee20..c25b2d3f99 100644
--- a/c/src/lib/libbsp/no_cpu/Makefile.am
+++ b/c/src/lib/libbsp/no_cpu/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
 include $(top_srcdir)/../../../automake/local.am
diff --git a/c/src/lib/libbsp/or1k/Makefile.am b/c/src/lib/libbsp/or1k/Makefile.am
index 0ce20e62fa..6d6feb2699 100644
--- a/c/src/lib/libbsp/or1k/Makefile.am
+++ b/c/src/lib/libbsp/or1k/Makefile.am
@@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I ../../../aclocal
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
 ## Currently, the shared directory is not explicitly
 ## added but it is present in the source tree.
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(srcdir)/preinstall.am
 include $(top_srcdir)/../../../automake/subdirs.am
diff --git a/c/src/lib/libbsp/powerpc/Makefile.am b/c/src/lib/libbsp/powerpc/Makefile.am
index a2795f2ef9..1309072f53 100644
--- a/c/src/lib/libbsp/powerpc/Makefile.am
+++ b/c/src/lib/libbsp/powerpc/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 # FIXME: This does not work
 # DIST_SUBDIRS = @all_subdirs@ support/old_exception_processing \
diff --git a/c/src/lib/libbsp/powerpc/motorola_powerpc/Makefile.am b/c/src/lib/libbsp/powerpc/motorola_powerpc/Makefile.am
index e098206083..af7a71f723 100644
--- a/c/src/lib/libbsp/powerpc/motorola_powerpc/Makefile.am
+++ b/c/src/lib/libbsp/powerpc/motorola_powerpc/Makefile.am
@@ -1,9 +1,9 @@
 ACLOCAL_AMFLAGS = -I ../../../../aclocal
 
-SUBDIRS = .
-SUBDIRS+= bootloader
+_SUBDIRS  = .
+_SUBDIRS += bootloader
 if QEMU
-SUBDIRS+= qemu_fakerom
+_SUBDIRS += qemu_fakerom
 endif
 
 include $(top_srcdir)/../../../../automake/compile.am
@@ -166,3 +166,4 @@ EXTRA_DIST += times.mcp750 times.mvme2307
 
 include $(srcdir)/preinstall.am
 include $(top_srcdir)/../../../../automake/local.am
+include $(top_srcdir)/../../../../automake/subdirs.am
diff --git a/c/src/lib/libbsp/sh/Makefile.am b/c/src/lib/libbsp/sh/Makefile.am
index 33c5db1613..35db1bb6fa 100644
--- a/c/src/lib/libbsp/sh/Makefile.am
+++ b/c/src/lib/libbsp/sh/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 EXTRA_DIST =
 EXTRA_DIST += shared/console.c
diff --git a/c/src/lib/libbsp/sparc/Makefile.am b/c/src/lib/libbsp/sparc/Makefile.am
index d17d691a55..30ea8497b5 100644
--- a/c/src/lib/libbsp/sparc/Makefile.am
+++ b/c/src/lib/libbsp/sparc/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 EXTRA_DIST =
 
diff --git a/c/src/lib/libbsp/sparc64/Makefile.am b/c/src/lib/libbsp/sparc64/Makefile.am
index d294e842ec..526453030c 100644
--- a/c/src/lib/libbsp/sparc64/Makefile.am
+++ b/c/src/lib/libbsp/sparc64/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../../../aclocal
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
 include $(top_srcdir)/../../../automake/local.am
diff --git a/c/src/lib/libbsp/v850/Makefile.am b/c/src/lib/libbsp/v850/Makefile.am
index d5747beb2f..15054fee72 100644
--- a/c/src/lib/libbsp/v850/Makefile.am
+++ b/c/src/lib/libbsp/v850/Makefile.am
@@ -6,7 +6,7 @@ ACLOCAL_AMFLAGS = -I ../../../aclocal
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
 ## Currently, the shared directory is not explicitly
 ## added but it is present in the source tree.
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 EXTRA_DIST =
 
diff --git a/c/src/lib/libcpu/Makefile.am b/c/src/lib/libcpu/Makefile.am
index 630f5256a0..38de255d1a 100644
--- a/c/src/lib/libcpu/Makefile.am
+++ b/c/src/lib/libcpu/Makefile.am
@@ -4,7 +4,7 @@ EXTRA_DIST =
 EXTRA_DIST += shared/include/cache.h
 EXTRA_DIST += shared/src/cache_manager.c
 
-SUBDIRS = @libcpu_cpu_subdir@
+_SUBDIRS = @libcpu_cpu_subdir@
 DIST_SUBDIRS = @libcpu_cpu_subdir@
 
 include $(top_srcdir)/automake/subdirs.am
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index 3206ee2123..ae5ed9b19e 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -4,30 +4,30 @@ include $(top_srcdir)/automake/compile.am
 include $(top_srcdir)/automake/multilib.am
 
 # librtemscpu
-SUBDIRS = . score rtems sapi posix
-SUBDIRS += dev
-SUBDIRS += dtc/libfdt
-SUBDIRS += libcrypt
-SUBDIRS += libcsupport libblock libfs
-SUBDIRS += libdrvmgr
-SUBDIRS += libnetworking librpc
-SUBDIRS += libpci
-SUBDIRS += libi2c
-SUBDIRS += libmisc
-SUBDIRS += libmd
-SUBDIRS += libgnat
-SUBDIRS += libdl
-SUBDIRS += libstdthreads
-SUBDIRS += libdebugger
-SUBDIRS += wrapup
-
-SUBDIRS += zlib
+_SUBDIRS = . score rtems sapi posix
+_SUBDIRS += dev
+_SUBDIRS += dtc/libfdt
+_SUBDIRS += libcrypt
+_SUBDIRS += libcsupport libblock libfs
+_SUBDIRS += libdrvmgr
+_SUBDIRS += libnetworking librpc
+_SUBDIRS += libpci
+_SUBDIRS += libi2c
+_SUBDIRS += libmisc
+_SUBDIRS += libmd
+_SUBDIRS += libgnat
+_SUBDIRS += libdl
+_SUBDIRS += libstdthreads
+_SUBDIRS += libdebugger
+_SUBDIRS += wrapup
+
+_SUBDIRS += zlib
 
 # applications
-SUBDIRS += ftpd
-SUBDIRS += telnetd
-SUBDIRS += pppd
-SUBDIRS += mghttpd
+_SUBDIRS += ftpd
+_SUBDIRS += telnetd
+_SUBDIRS += pppd
+_SUBDIRS += mghttpd
 
 noinst_DATA = preinstall-stamp
 preinstall-stamp:
diff --git a/cpukit/automake/subdirs.am b/cpukit/automake/subdirs.am
index 1e0a9a757a..723aec8af2 100644
--- a/cpukit/automake/subdirs.am
+++ b/cpukit/automake/subdirs.am
@@ -1,30 +1,74 @@
-## Borrowed from automake-1.4 and adapted to RTEMS
-
-## NOTE: This is a temporary work-around to keep
-## RTEMS's non automake standard make targets working.
-## Once automake is fully integrated these make targets
-## and this file will probably be removed
-
-preinstall-recursive:
-	@set fnord $(MAKEFLAGS); amf=$$2; \
-	dot_seen=no; \
-	target=`echo $@ | sed s/-recursive//`; \
-	list='$(SUBDIRS)'; for subdir in $$list; do \
-	  echo "Making $$target in $$subdir"; \
-	  if test "$$subdir" = "."; then \
-	    dot_seen=yes; \
-	    local_target="$$target-am"; \
-	  else \
-	    local_target="$$target"; \
-	  fi; \
-	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
-## This trick allows "-k" to keep its natural meaning when running a
-## recursive rule.
-	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
-	done; \
-	if test "$$dot_seen" = "no"; then \
-	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
-	fi; test -z "$$fail"
-
-preinstall: preinstall-recursive
-.PHONY: preinstall-recursive
+## Copyright 2017 Chris Johns <chrisj at rtems.org>
+
+##
+## The following builds in parallel. The subdirectories are
+## expanded into separate rules and all the targets are listed
+## and make runs as many as it can.
+##
+## A macro is defined and evaluated once for each directory. This
+## creates the instance of the rule. Use $(info ...) to print them.
+##
+
+SUBDIRS_dot              = $(filter     .,$(_SUBDIRS))
+SUBDIRS_no_dot           = $(filter-out .,$(_SUBDIRS))
+SUBDIRS_no_dot_no_wrapup = $(filter-out wrapup,$(SUBDIRS_no_dot))
+SUBDIRS_wrapup           = $(filter     wrapup,$(SUBDIRS_no_dot))
+
+SUBDIR_TARGET     = $(subst /,-,$1)
+PREINSTALL_TARGET = preinstall-$(call SUBDIR_TARGET,$(1))
+
+preintstall_targets  = $(if "$(SUBDIRS_dot)" ".",preinstall-dot) $(foreach D,$(SUBDIRS_no_dot),$(call PREINSTALL_TARGET,$(D)))
+
+define PREINSTALL_DIR
+.PHONY: $1
+$1:
+	@+set fnord $(MAKEFLAGS); amf=$$$$2; \
+	subdir=$(2); \
+	subdir_label=`echo $(1) | sed -e 's/preinstall-//'`; \
+	target=`echo $$@ | sed -e 's/-recursive//' -e "s/-$$$${subdir_label}//"`$(3); \
+	echo "Making $$$$target in $$$$subdir"; \
+	(cd $$$$subdir && $(MAKE) $(AM_MAKEFLAGS) $$$$target) \
+	 || case "$$$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac;
+endef
+
+$(if "$(SUBDIRS_dot)" ".",$(eval $(call PREINSTALL_DIR,preinstall-dot,.,-am)))
+
+$(foreach D,$(SUBDIRS_no_dot),$(eval $(call PREINSTALL_DIR,$(call PREINSTALL_TARGET,$(D)),$(D))))
+
+preinstall: $(preintstall_targets)
+.PHONY: preinstall
+
+define CPUKITDIR
+.PHONY: $1
+$1: $(preintstall_targets)
+	@+set fnord $(MAKEFLAGS); amf=$$$$2; \
+	subdir=$(2); \
+	target=`echo $(MAKECMDGOALS) | sed s/-recursive//`; \
+	if test "$$$$target" = "all-local-am"; then \
+	  target="all-am"; \
+	fi; \
+	if test "$$$$target" = "all-local"; then \
+	  target="all"; \
+	fi; \
+	echo "Making $$$$target in $$$$subdir"; \
+	if test "$$$$subdir" != "."; then \
+	  cd $$$$subdir; \
+	  $(MAKE) $(AM_MAKEFLAGS) $$$$local_target; \
+	fi;
+endef
+
+#
+# This GNU make syntax is being used to stop automake thinking the code is for
+# it.
+#
+$(if "$(SUBDIRS_dot)" ".",$(eval $(call CPUKITDIR,dot,.)))
+
+$(foreach D,$(SUBDIRS_no_dot),$(eval $(call CPUKITDIR,$(D),$(D))))
+
+#
+# If there is a wrapup make it depend on all other directories so it is not
+# entered until they have finished.
+#
+$(if "$(SUBDIRS_wrapup)" "wrapup",wrapup: dot $(foreach D,$(SUBDIRS_no_dot_no_wrapup),$(D)),)
+
+all-local: preinstall $(if "$(SUBDIRS_dot)" ".",dot) $(SUBDIRS_no_dot)
diff --git a/cpukit/libfs/Makefile.am b/cpukit/libfs/Makefile.am
index 89e7581b28..2a09aaa62d 100644
--- a/cpukit/libfs/Makefile.am
+++ b/cpukit/libfs/Makefile.am
@@ -1,7 +1,7 @@
 include $(top_srcdir)/automake/multilib.am
 include $(top_srcdir)/automake/compile.am
 
-SUBDIRS = src/nfsclient
+_SUBDIRS = src/nfsclient
 
 EXTRA_DIST = README
 
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 0288c5393a..a3de792fdf 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -1,7 +1,7 @@
 include $(top_srcdir)/automake/multilib.am
 include $(top_srcdir)/automake/compile.am
 
-SUBDIRS = cpu
+_SUBDIRS = cpu
 
 ## include
 
diff --git a/cpukit/score/cpu/Makefile.am b/cpukit/score/cpu/Makefile.am
index 1f57984105..51835109fb 100644
--- a/cpukit/score/cpu/Makefile.am
+++ b/cpukit/score/cpu/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = @RTEMS_CPU@
+_SUBDIRS = @RTEMS_CPU@
 
 DIST_SUBDIRS =
 DIST_SUBDIRS += arm
-- 
2.12.1



More information about the devel mailing list