1################################################################################
2#
3# toolchain-related customisation of the content of the target/ directory
4#
5################################################################################
6
7# Those customisations are added to the TARGET_FINALIZE_HOOKS, to be applied
8# just after all packages have been built.
9
10# Install the gconv modules
11ifeq ($(BR2_TOOLCHAIN_GLIBC_GCONV_LIBS_COPY),y)
12TOOLCHAIN_GLIBC_GCONV_LIBS = $(call qstrip,$(BR2_TOOLCHAIN_GLIBC_GCONV_LIBS_LIST))
13define TOOLCHAIN_GLIBC_COPY_GCONV_LIBS
14	$(Q)found_gconv=no; \
15	for d in $(TOOLCHAIN_EXTERNAL_PREFIX) ''; do \
16		[ -d "$(STAGING_DIR)/usr/lib/$${d}/gconv" ] || continue; \
17		found_gconv=yes; \
18		break; \
19	done; \
20	if [ "$${found_gconv}" = "no" ]; then \
21		printf "Unable to find gconv modules\n" >&2; \
22		exit 1; \
23	fi; \
24	if [ -z "$(TOOLCHAIN_GLIBC_GCONV_LIBS)" ]; then \
25		$(INSTALL) -m 0644 -D $(STAGING_DIR)/usr/lib/$${d}/gconv/gconv-modules \
26				      $(TARGET_DIR)/usr/lib/gconv/gconv-modules && \
27		$(INSTALL) -m 0644 $(STAGING_DIR)/usr/lib/$${d}/gconv/*.so \
28				   $(TARGET_DIR)/usr/lib/gconv \
29		|| exit 1; \
30		if [ -d $(STAGING_DIR)/usr/lib/$${d}/gconv/gconv-modules.d ]; then \
31			cp -a $(STAGING_DIR)/usr/lib/$${d}/gconv/gconv-modules.d \
32				$(TARGET_DIR)/usr/lib/gconv/ || exit 1; \
33		fi; \
34	else \
35		for l in $(TOOLCHAIN_GLIBC_GCONV_LIBS); do \
36			$(INSTALL) -m 0644 -D $(STAGING_DIR)/usr/lib/$${d}/gconv/$${l}.so \
37					      $(TARGET_DIR)/usr/lib/gconv/$${l}.so \
38			|| exit 1; \
39			$(TARGET_READELF) -d $(STAGING_DIR)/usr/lib/$${d}/gconv/$${l}.so |\
40			sort -u |\
41			sed -e '/.*(NEEDED).*\[\(.*\.so\)\]$$/!d; s//\1/;' |\
42			while read lib; do \
43				 $(INSTALL) -m 0644 -D $(STAGING_DIR)/usr/lib/$${d}/gconv/$${lib} \
44						       $(TARGET_DIR)/usr/lib/gconv/$${lib} \
45				 || exit 1; \
46			done; \
47		done; \
48		./support/scripts/expunge-gconv-modules \
49			$(STAGING_DIR)/usr/lib/$${d}/gconv \
50			"$(TOOLCHAIN_GLIBC_GCONV_LIBS)" \
51			>$(TARGET_DIR)/usr/lib/gconv/gconv-modules; \
52	fi
53endef
54TOOLCHAIN_TARGET_FINALIZE_HOOKS += TOOLCHAIN_GLIBC_COPY_GCONV_LIBS
55endif
56