Makefile: Parallelize glibc locale generation
PATCH v4 1/1 Makefile: Parallelize glibc locale generation
Parallelizes locale generation based on BR2_JLEVEL setting.
Locale generation always runs during the finalize stage and can consume a significant amount of time. Parallelizing it greatly reduces that time on multi-core machines.
To parallelize it, we first invoke localedef for every locale in parallel with the --no-archive option. This creates the intermediate locale data instead of writing to the finally archive directly.
Then, we invoke localedef again once to create the archive from the intermediate compiled locale data files.
We have to do it this way because localedef does not do any locking when writing to the archive file, so calling it without --no-archive concurrently could result in a corrupt archive file or an archive file that is missing some locales.
--- Makefile | 29 +++++++--------------- support/misc/gen-glibc-locales.mk | 41 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 support/misc/gen-glibc-locales.mk
Makefile +9 -20
@@ -661,32 +661,21 @@ endef TARGET_FINALIZE_HOOKS += TOOLCHAIN_ECLIPSE_REGISTER endif -# Generate locale data. Basically, we call the localedef program -# (built by the host-localedef package) for each locale. The input -# data comes preferably from the toolchain, or if the toolchain does -# not have them (Linaro toolchains), we use the ones available on the -# host machine. +# Generate locale data. ifeq ($(BR2_TOOLCHAIN_USES_GLIBC),y) GLIBC_GENERATE_LOCALES = $(call qstrip,$(BR2_GENERATE_LOCALE)) ifneq ($(GLIBC_GENERATE_LOCALES),) PACKAGES += host-localedef define GENERATE_GLIBC_LOCALES - $(Q)mkdir -p $(TARGET_DIR)/usr/lib/locale/ - $(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 \ - $(HOST_DIR)/bin/localedef \ - --prefix=$(TARGET_DIR) \ - --$(call LOWERCASE,$(BR2_ENDIAN))-endian \ - -i $${inputfile} -f $${charmap} \ - $${locale} ; \ - done + $(TARGET_CONFIGURE_OPTS) \ + $(MAKE) -j$(PARALLEL_JOBS) -f support/misc/gen-glibc-locales.mk \ + HOST_DIR=$(HOST_DIR) \ + TARGET_DIR=$(TARGET_DIR) \ + STAGING_DIR=$(STAGING_DIR) \ + ENDIAN=$(call LOWERCASE,$(BR2_ENDIAN)) \ + LOCALES="$(GLIBC_GENERATE_LOCALES)" \ + Q=$(Q) endef TARGET_FINALIZE_HOOKS += GENERATE_GLIBC_LOCALES endif
support/misc/gen-glibc-locales.mk new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.27.0