diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk index 21db9d7f0c..16864854b4 100644 --- a/toolchain/helpers.mk +++ b/toolchain/helpers.mk @@ -55,10 +55,19 @@ copy_toolchain_lib_root = \ # corresponding architecture variants), and we don't want to import # them. # +# If ARCH_LIB_DIR is not a singular directory component, e.g. +# 'lib32/octeon2', then symbolic links in ARCH_LIB_DIR and +# usr/ARCH_LIB_DIR may be broken because Buildroot will flatten the +# directory structure (e.g. lib32/octeon2/foo is actually stored in +# lib/foo). This is only relevant for links that contain one or more ../ +# components, as links to the current directory are always fine. +# We need to fix the broken links by removing the right amount of ../ +# dots from the link destination. +# # It is possible that ARCH_LIB_DIR does not contain the dynamic loader # (ld*.so or similar) because it (or the main symlink to it) normally -# resides in /lib while ARCH_LIB_DIR may be something else (e.g. lib64). -# Therefore, copy the dynamic loader separately. +# resides in /lib while ARCH_LIB_DIR may be something else (e.g. lib64, +# lib/, ...). Therefore, copy the dynamic loader separately. # # Then, if the selected architecture variant is not the default one # (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we : @@ -111,6 +120,14 @@ copy_toolchain_sysroot = \ $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \ fi ; \ done ; \ + relpath="$(call relpath_prefix,$${ARCH_LIB_DIR})" ; \ + if [ "$${relpath}" != "" ]; then \ + for i in $$(find -H $(STAGING_DIR)/$${ARCH_LIB_DIR} $(STAGING_DIR)/usr/$${ARCH_LIB_DIR} -type l -xtype l); do \ + LINKTARGET=`readlink $$i` ; \ + NEWLINKTARGET=$${LINKTARGET\#$$relpath} ; \ + ln -sf $${NEWLINKTARGET} $$i ; \ + done ; \ + fi ; \ if [ -e $${ARCH_SYSROOT_DIR}/lib/ld*.so ]; then \ cp -a $${ARCH_SYSROOT_DIR}/lib/ld*.so $(STAGING_DIR)/lib/ ; \ fi ; \ diff --git a/toolchain/toolchain-external/pkg-toolchain-external.mk b/toolchain/toolchain-external/pkg-toolchain-external.mk index 17773689dd..a4d010a93c 100644 --- a/toolchain/toolchain-external/pkg-toolchain-external.mk +++ b/toolchain/toolchain-external/pkg-toolchain-external.mk @@ -332,7 +332,7 @@ endef # Returns the lib subdirectory for the given compiler + flags (i.e # typically lib32 or lib64 for some toolchains) define toolchain_find_libdir -$$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?([^/]*)?)/([^/]*/)?libc.a:\2:') +$$(printf $(call toolchain_find_libc_a,$(1)) | sed -r -e 's:.*/(usr/)?(lib(32|64)?([^/]*)?(/[^/]*)?)/libc.a:\2:') endef # Returns the location of the libc.a file for the given compiler + flags @@ -448,8 +448,9 @@ create_lib_symlinks = \ $(Q)DESTDIR="$(strip $1)" ; \ ARCH_LIB_DIR="$(call toolchain_find_libdir,$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS))" ; \ if [ ! -e "$${DESTDIR}/$${ARCH_LIB_DIR}" -a ! -e "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ]; then \ - ln -snf lib "$${DESTDIR}/$${ARCH_LIB_DIR}" ; \ - ln -snf lib "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ; \ + relpath="$(call relpath_prefix,$${ARCH_LIB_DIR})" ; \ + ln -snf $${relpath}lib "$${DESTDIR}/$${ARCH_LIB_DIR}" ; \ + ln -snf $${relpath}lib "$${DESTDIR}/usr/$${ARCH_LIB_DIR}" ; \ fi define TOOLCHAIN_EXTERNAL_CREATE_STAGING_LIB_SYMLINK