Skip to contentSkip to conversation

Cope with unusual (?) toolchain library locations

PATCH New Malte Starostik 1 participant 3 messages Feb 27, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Cope with unusual (?) toolchain library locations

Some toolchain libraries can be outside the toolchain's sysroot. This happens e.g. with toolchains built by Gentoo's crossdev utility:

$ i686-pc-linux-uclibc-gcc -print-sysroot
/usr/i686-pc-linux-uclibc
BUT:
$ i686-pc-linux-uclibc-gcc -print-file-name=libgcc_s.so
/usr/lib/gcc/i686-pc-linux-uclibc/4.4.5/libgcc_s.so
$ i686-pc-linux-uclibc-gcc -print-file-name=libstdc++.so
/usr/lib/gcc/i686-pc-linux-uclibc/4.4.5/libstdc++.so

This patch tries to cope with this gracefully: iff the usual library locations do not contain the library we're looking for, the target compiler is consulted for its idea of where to look. In theory this output could always be used instead of find(1)ing the libs oneself, but a test with such an approach led to other problems like cross-directory symlinks as in $(SYSROOT)/usr/lib/libfoo.so -> ../../lib/libfoo.so.0 which breaks how toolchain/helpers.mk uses cp -d while coercing all libs to either $(TARGET_DIR)/lib or $(TARGET_DIR)/usr/lib. Also, there might be some .so files in $(SYSROOT)/usr/lib dir that are actually ld scripts.

---
 toolchain/helpers.mk |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
toolchain/helpers.mk +6 -1
index db7c7f1..1f19aba 100644
@@ -26,11 +26,16 @@ copy_toolchain_lib_root = \
 			  -path "./usr/lib/$${LIB}.*" -o \
 			  -path "./usr/$(TOOLCHAIN_EXTERNAL_PREFIX)/lib*/$${LIB}.*" \
 		)` ; \
+	test -z "$${LIBS}" && LIBS=`$(TARGET_CC_NO_SYSROOT) $(TARGET_CFLAGS) -print-file-name=$${LIB} | sed -n '/^\\//p'`; \
 	for FILE in $${LIBS} ; do \
 		LIB=`basename $${FILE}`; \
 		LIBDIR=`dirname $${FILE}` ; \
 		while test \! -z "$${LIB}"; do \
-			FULLPATH="$${ARCH_SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \
+			case "$${LIBDIR}" in \
+			    /*) FULLPATH="$${LIBDIR}/$${LIB}";; \
+			    *) FULLPATH="$${ARCH_SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \
+			esac; \
+			echo "$${FULLPATH}"; \
 			rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIB}; \
 			mkdir -p $(TARGET_DIR)/$${DESTDIR}; \
 			if test -h $${FULLPATH} ; then \
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/1 Cope with unusual (?) toolchain library locations

Some toolchain libraries can be outside the toolchain's sysroot. This happens e.g. with toolchains built by Gentoo's crossdev utility:

$ i686-pc-linux-uclibc-gcc -print-sysroot
/usr/i686-pc-linux-uclibc
BUT:
$ i686-pc-linux-uclibc-gcc -print-file-name=libgcc_s.so
/usr/lib/gcc/i686-pc-linux-uclibc/4.4.5/libgcc_s.so
$ i686-pc-linux-uclibc-gcc -print-file-name=libstdc++.so
/usr/lib/gcc/i686-pc-linux-uclibc/4.4.5/libstdc++.so

This patch tries to cope with this gracefully: iff the usual library locations do not contain the library we're looking for, the target compiler is consulted for its idea of where to look. In theory this output could always be used instead of find(1)ing the libs oneself, but a test with such an approach led to other problems like cross-directory symlinks as in $(SYSROOT)/usr/lib/libfoo.so -> ../../lib/libfoo.so.0 which breaks how toolchain/helpers.mk uses cp -d while coercing all libs to either $(TARGET_DIR)/lib or $(TARGET_DIR)/usr/lib. Also, there might be some .so files in $(SYSROOT)/usr/lib dir that are actually ld scripts.

---
 toolchain/helpers.mk |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
toolchain/helpers.mk +5 -1
index db7c7f1..4d7d177 100644
@@ -26,11 +26,15 @@ copy_toolchain_lib_root = \
 			  -path "./usr/lib/$${LIB}.*" -o \
 			  -path "./usr/$(TOOLCHAIN_EXTERNAL_PREFIX)/lib*/$${LIB}.*" \
 		)` ; \
+	test -z "$${LIBS}" && LIBS=`$(TARGET_CC_NO_SYSROOT) $(TARGET_CFLAGS) -print-file-name=$${LIB} | sed -n '/^\\//p'`; \
 	for FILE in $${LIBS} ; do \
 		LIB=`basename $${FILE}`; \
 		LIBDIR=`dirname $${FILE}` ; \
 		while test \! -z "$${LIB}"; do \
-			FULLPATH="$${ARCH_SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \
+			case "$${LIBDIR}" in \
+			    /*) FULLPATH="$${LIBDIR}/$${LIB}";; \
+			    *) FULLPATH="$${ARCH_SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \
+			esac; \
 			rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIB}; \
 			mkdir -p $(TARGET_DIR)/$${DESTDIR}; \
 			if test -h $${FULLPATH} ; then \
Signature · 1 line
1.7.3.4
#2 lore raw

PATCH 1/1 Cope with unusual (?) toolchain library locations

Sorry for the noisy monologue! Git and me = no friends today. What I'm replying to now should've been marked V2 of the patch and removes some debug output that slipped into the initial version.

Regards,
Malte