[Buildroot] [PATCH v3 1/1] Makefile: Parallelize glibc locale generation

From: Gleb Mazovetskiy <hidden>
Date: 2021-01-03 15:10:00
Subsystem: kernel build + files below scripts/ (unless maintained elsewhere), the rest · Maintainers: Nathan Chancellor, Nicolas Schier, Linus Torvalds

Parallelizes locale generation based on `BR2_JLEVEL` setting.

Uses `-P` (`--max-procs`) GNU xargs extension
together with the standard `-n` xargs option (`--max-args`).

Signed-off-by: Gleb Mazovetskiy <redacted>
---
 Makefile | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/Makefile b/Makefile
index 4d334adcd6..4ef82df31b 100644
--- a/Makefile
+++ b/Makefile
@@ -673,20 +673,26 @@ PACKAGES += host-localedef
 
 define GENERATE_GLIBC_LOCALES
 	$(Q)mkdir -p $(TARGET_DIR)/usr/lib/locale/
+	$(Q)echo "Generating locale data: $(GLIBC_GENERATE_LOCALES)"
 	$(Q)for locale in $(GLIBC_GENERATE_LOCALES) ; do \
-		inputfile=`echo $${locale} | cut -f1 -d'.'` ; \
-		charmap=`echo $${locale} | cut -f2 -d'.' -s` ; \
-		if test -z "$${charmap}" ; then \
-			charmap="UTF-8" ; \
-		fi ; \
-		echo "Generating locale $${inputfile}.$${charmap}" ; \
-		I18NPATH=$(STAGING_DIR)/usr/share/i18n:/usr/share/i18n \
+		echo -i ; \
+		echo $${locale%%.*} ; \
+		echo -f ; \
+		echo $${locale} | cut -f2 -d'.' || echo UTF-8 ; \
+		echo $${locale} ; \
+	done \
+	| I18NPATH=$(STAGING_DIR)/usr/share/i18n:/usr/share/i18n \
+	xargs -P $(PARALLEL_JOBS) -n 5 \
 		$(HOST_DIR)/bin/localedef \
 			--prefix=$(TARGET_DIR) \
-			--$(call LOWERCASE,$(BR2_ENDIAN))-endian \
-			-i $${inputfile} -f $${charmap} \
-			$${locale} ; \
-	done
+			--$(call LOWERCASE,$(call qstrip,$(BR2_ENDIAN)))-endian \
+			--no-archive
+	$(Q)echo "Adding locales to archive"
+	$(Q)find $(TARGET_DIR)/usr/lib/locale/ -maxdepth 1 -mindepth 1 -type d -print0 \
+	| sort -z | xargs -x -0 $(HOST_DIR)/bin/localedef \
+			--prefix=$(TARGET_DIR) \
+			--$(call LOWERCASE,$(call qstrip,$(BR2_ENDIAN)))-endian \
+			--replace --add-to-archive
 endef
 TARGET_FINALIZE_HOOKS += GENERATE_GLIBC_LOCALES
 endif
-- 
2.27.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help