From 4cf516f84b30f2c6c1ff6bc269dd49fa06b77353 Mon Sep 17 00:00:00 2001 From: Yves Martin Date: Sat, 19 Jan 2019 20:41:03 +0100 Subject: [PATCH] framework: add parallel make compilation Interesting for large application Closes #49 --- Makefile | 1 + mk/spksrc.common.mk | 12 ++++++++++++ mk/spksrc.compile.mk | 6 +++--- mk/spksrc.cross-env.mk | 4 ++++ mk/spksrc.directories.mk | 8 ++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6de75a97bdc..9bd6fcc3acb 100644 --- a/Makefile +++ b/Makefile @@ -126,6 +126,7 @@ local.mk: @echo "DISTRIBUTOR_URL=" >> $@ @echo "REPORT_URL=" >> $@ @echo "DEFAULT_TC=" >> $@ + @echo "#PARALLEL_MAKE=max" >> $@ dsm-%: local.mk @echo "Setting default toolchain version to DSM-$*" diff --git a/mk/spksrc.common.mk b/mk/spksrc.common.mk index 04133cd252f..0b345c76d0b 100644 --- a/mk/spksrc.common.mk +++ b/mk/spksrc.common.mk @@ -48,3 +48,15 @@ LOCAL_CONFIG_MK = ../../local.mk ifneq ($(wildcard $(LOCAL_CONFIG_MK)),) include $(LOCAL_CONFIG_MK) endif + +# Relocate to set conditionally according to existing parallel options in caller +ifneq ($(PARALLEL_MAKE),) +ifeq ($(PARALLEL_MAKE),max) +NCPUS = $(shell grep -c ^processor /proc/cpuinfo) +else +NCPUS = $(PARALLEL_MAKE) +endif +ifeq ($(filter $(NCPUS),0 1),) +COMPILE_MAKE_OPTIONS = -j$(NCPUS) +endif +endif diff --git a/mk/spksrc.compile.mk b/mk/spksrc.compile.mk index f497db504f4..175a5040142 100644 --- a/mk/spksrc.compile.mk +++ b/mk/spksrc.compile.mk @@ -1,5 +1,5 @@ ### Compile rules -# Invoke make to (cross-) compile the software. +# Invoke make to (cross-) compile the software. # Target are executed in the following order: # compile_msg_target # pre_compile_target (override with PRE_COMPILE_TARGET) @@ -32,8 +32,8 @@ compile_msg: pre_compile_target: compile_msg -compile_target: $(PRE_COMPILE_TARGET) - @$(RUN) $(MAKE) +compile_target: $(PRE_COMPILE_TARGET) + @$(RUN) $(MAKE) $(COMPILE_MAKE_OPTIONS) post_compile_target: $(COMPILE_TARGET) diff --git a/mk/spksrc.cross-env.mk b/mk/spksrc.cross-env.mk index d0d3535480b..6456c994b55 100644 --- a/mk/spksrc.cross-env.mk +++ b/mk/spksrc.cross-env.mk @@ -25,3 +25,7 @@ $(TC_VARS_MK): ENV += TC=$(TC) ENV += $(TC_ENV) endif + +#ifneq ($(COMPILE_MAKE_OPTIONS),) +#ENV += MAKEFLAGS="$(COMPILE_MAKE_OPTIONS)" +#endif diff --git a/mk/spksrc.directories.mk b/mk/spksrc.directories.mk index a4b99ae472f..ba038a5143a 100644 --- a/mk/spksrc.directories.mk +++ b/mk/spksrc.directories.mk @@ -29,7 +29,15 @@ endif STAGING_DIR = $(WORK_DIR)/staging ifndef INSTALL_PREFIX +ifneq ($(strip $(SPK_NAME)),) INSTALL_PREFIX = /var/packages/$(SPK_NAME)/target +else +ifneq ($(strip $(PKG_NAME)),) +INSTALL_PREFIX = /usr/local/$(PKG_NAME) +else +INSTALL_PREFIX = /usr/local +endif +endif endif ifndef KERNEL_DIR