Index: c/Makefile.am
===================================================================
--- c/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -12,6 +12,6 @@
 
 ## 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
Index: c/src/Makefile.am
===================================================================
--- c/src/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -1,5 +1,5 @@
 ACLOCAL_AMFLAGS = -I aclocal
 
-SUBDIRS = . @BSP_SUBDIRS@
+_SUBDIRS = . @BSP_SUBDIRS@
 DIST_SUBDIRS = @BSP_SUBDIRS@
 
Index: c/src/automake/subdirs.am
===================================================================
--- c/src/automake/subdirs.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/automake/subdirs.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -1,30 +1,87 @@
-## Borrowed from automake-1.4 and adapted to RTEMS
+## Copyright 2017 Chris Johns <chrisj@rtems.org>
 
-## 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
+##
+## 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.
+##
 
-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"
+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))
 
-preinstall: preinstall-recursive
-.PHONY: preinstall-recursive
+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)
Index: c/src/lib/Makefile.am
===================================================================
--- c/src/lib/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -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
Index: c/src/lib/libbsp/Makefile.am
===================================================================
--- c/src/lib/libbsp/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -1,5 +1,5 @@
 include $(top_srcdir)/automake/compile.am
 
-SUBDIRS = @libbsp_cpu_subdir@
+_SUBDIRS = @libbsp_cpu_subdir@
 DIST_SUBDIRS = @libbsp_cpu_subdir@
 
@@ -43,4 +43,4 @@
 
 include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
 include $(top_srcdir)/automake/subdirs.am
-include $(top_srcdir)/automake/local.am
Index: c/src/lib/libbsp/arm/Makefile.am
===================================================================
--- c/src/lib/libbsp/arm/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/arm/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -4,5 +4,5 @@
 ## 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
Index: c/src/lib/libbsp/bfin/Makefile.am
===================================================================
--- c/src/lib/libbsp/bfin/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/bfin/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
Index: c/src/lib/libbsp/epiphany/Makefile.am
===================================================================
--- c/src/lib/libbsp/epiphany/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/epiphany/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -3,5 +3,5 @@
 ## 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
Index: c/src/lib/libbsp/i386/Makefile.am
===================================================================
--- c/src/lib/libbsp/i386/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/i386/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 EXTRA_DIST =
Index: c/src/lib/libbsp/i386/pc386/Makefile.am
===================================================================
--- c/src/lib/libbsp/i386/pc386/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/i386/pc386/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -24,5 +24,5 @@
 noinst_PROGRAMS =
 
-SUBDIRS = . tools
+_SUBDIRS = . tools
 
 nodist_include_bsp_HEADERS += include/bspimpl.h
@@ -259,2 +259,3 @@
 include $(srcdir)/preinstall.am
 include $(top_srcdir)/../../../../automake/local.am
+include $(top_srcdir)/../../../../automake/subdirs.am
Index: c/src/lib/libbsp/lm32/Makefile.am
===================================================================
--- c/src/lib/libbsp/lm32/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/lm32/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
Index: c/src/lib/libbsp/m32c/Makefile.am
===================================================================
--- c/src/lib/libbsp/m32c/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/m32c/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 EXTRA_DIST =
Index: c/src/lib/libbsp/m68k/Makefile.am
===================================================================
--- c/src/lib/libbsp/m68k/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/m68k/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include_bspdir = $(includedir)/bsp
Index: c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am
===================================================================
--- c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -14,5 +14,5 @@
 DISTCLEANFILES = include/bspopts.h
 
-SUBDIRS = . tools
+_SUBDIRS = . tools
 
 include_HEADERS += include/coverhd.h
Index: c/src/lib/libbsp/mips/Makefile.am
===================================================================
--- c/src/lib/libbsp/mips/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/mips/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
Index: c/src/lib/libbsp/moxie/Makefile.am
===================================================================
--- c/src/lib/libbsp/moxie/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/moxie/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -6,5 +6,5 @@
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
Index: c/src/lib/libbsp/nios2/Makefile.am
===================================================================
--- c/src/lib/libbsp/nios2/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/nios2/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
Index: c/src/lib/libbsp/no_cpu/Makefile.am
===================================================================
--- c/src/lib/libbsp/no_cpu/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/no_cpu/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
Index: c/src/lib/libbsp/or1k/Makefile.am
===================================================================
--- c/src/lib/libbsp/or1k/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/or1k/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -4,5 +4,5 @@
 ## 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
Index: c/src/lib/libbsp/powerpc/Makefile.am
===================================================================
--- c/src/lib/libbsp/powerpc/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/powerpc/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 # FIXME: This does not work
Index: c/src/lib/libbsp/powerpc/motorola_powerpc/Makefile.am
===================================================================
--- c/src/lib/libbsp/powerpc/motorola_powerpc/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/powerpc/motorola_powerpc/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -1,8 +1,8 @@
 ACLOCAL_AMFLAGS = -I ../../../../aclocal
 
-SUBDIRS = .
-SUBDIRS+= bootloader
+_SUBDIRS  = .
+_SUBDIRS += bootloader
 if QEMU
-SUBDIRS+= qemu_fakerom
+_SUBDIRS += qemu_fakerom
 endif
 
@@ -167,2 +167,3 @@
 include $(srcdir)/preinstall.am
 include $(top_srcdir)/../../../../automake/local.am
+include $(top_srcdir)/../../../../automake/subdirs.am
Index: c/src/lib/libbsp/sh/Makefile.am
===================================================================
--- c/src/lib/libbsp/sh/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/sh/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 EXTRA_DIST =
Index: c/src/lib/libbsp/sparc/Makefile.am
===================================================================
--- c/src/lib/libbsp/sparc/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/sparc/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 # Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 EXTRA_DIST =
Index: c/src/lib/libbsp/sparc64/Makefile.am
===================================================================
--- c/src/lib/libbsp/sparc64/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/sparc64/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 
 ## Descend into the @RTEMS_BSP_FAMILY@ directory
-SUBDIRS = @RTEMS_BSP_FAMILY@
+_SUBDIRS = @RTEMS_BSP_FAMILY@
 
 include $(top_srcdir)/../../../automake/subdirs.am
Index: c/src/lib/libbsp/v850/Makefile.am
===================================================================
--- c/src/lib/libbsp/v850/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libbsp/v850/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -7,5 +7,5 @@
 ## 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 =
Index: c/src/lib/libcpu/Makefile.am
===================================================================
--- c/src/lib/libcpu/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ c/src/lib/libcpu/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -5,5 +5,5 @@
 EXTRA_DIST += shared/src/cache_manager.c
 
-SUBDIRS = @libcpu_cpu_subdir@
+_SUBDIRS = @libcpu_cpu_subdir@
 DIST_SUBDIRS = @libcpu_cpu_subdir@
 
Index: cpukit/Makefile.am
===================================================================
--- cpukit/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ cpukit/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -5,28 +5,28 @@
 
 # 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
Index: cpukit/automake/subdirs.am
===================================================================
--- cpukit/automake/subdirs.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ cpukit/automake/subdirs.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -1,30 +1,74 @@
-## Borrowed from automake-1.4 and adapted to RTEMS
+## Copyright 2017 Chris Johns <chrisj@rtems.org>
 
-## 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
+##
+## 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.
+##
 
-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"
+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))
 
-preinstall: preinstall-recursive
-.PHONY: preinstall-recursive
+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)
Index: cpukit/libfs/Makefile.am
===================================================================
--- cpukit/libfs/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ cpukit/libfs/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 include $(top_srcdir)/automake/compile.am
 
-SUBDIRS = src/nfsclient
+_SUBDIRS = src/nfsclient
 
 EXTRA_DIST = README
Index: cpukit/score/Makefile.am
===================================================================
--- cpukit/score/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ cpukit/score/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -2,5 +2,5 @@
 include $(top_srcdir)/automake/compile.am
 
-SUBDIRS = cpu
+_SUBDIRS = cpu
 
 ## include
Index: cpukit/score/cpu/Makefile.am
===================================================================
--- cpukit/score/cpu/Makefile.am	(revision 86ae03c691214bea398c8351c9e658114ab84a36)
+++ cpukit/score/cpu/Makefile.am	(revision a748603cb4565d395db1acf812cb1aee2f0642d9)
@@ -1,3 +1,3 @@
-SUBDIRS = @RTEMS_CPU@
+_SUBDIRS = @RTEMS_CPU@
 
 DIST_SUBDIRS =
