+#
+# Parallel build support
+#
+# The variable $(PROFILE)_PARALLEL_SUBDIRS should be set to the list of directories
+# which could be built in parallel. These directories are built after the directories in
+# $(PROFILE)_SUBDIRS.
+# Parallel building is currently only supported for the 'all' target.
+#
+# Each directory's Makefile may define DEP_LIBS and DEP_DIRS to specify the libraries and
+# directories it depends on.
+#
+ifneq ($(PROFILE_PARALLEL_SUBDIRS),)
+dep_dirs = .dep_dirs-$(PROFILE)
+$(dep_dirs):
+ @echo "Creating $@..."
+ list='$(PROFILE_PARALLEL_SUBDIRS)'; \
+ echo > $@; \
+ for d in $$list; do \
+ $(MAKE) -C $$d gen-deps DEPS_TARGET_DIR=$$d DEPS_FILE=$(abspath $@); \
+ done
+-include $(dep_dirs)
+endif
+
+.PHONY: gen-deps
+# The gen-deps target is in library.make/executable.make so it can pick up
+# DEP_LIBS/DEP_DIRS
+
+clean-dep-dir:
+ $(RM) $(dep_dirs)
+
+clean-local: clean-dep-dir
+
+ifdef ENABLE_PARALLEL_SUBDIR_BUILD
+.PHONY: do-all-parallel $(PROFILE_PARALLEL_SUBDIRS)
+
+do-all-parallel: $(PROFILE_PARALLEL_SUBDIRS)
+
+$(PROFILE_PARALLEL_SUBDIRS):
+ @set . $$MAKEFLAGS; \
+ cd $@ && $(MAKE)
+endif
+