diff options
author | Thomas De Schampheleire <thomas.de.schampheleire@gmail.com> | 2016-02-12 20:20:25 +0100 |
---|---|---|
committer | Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | 2016-04-25 22:46:28 +0200 |
commit | 2a87b64f8e8a832a351f8552eb032e4b18431949 (patch) | |
tree | 9083da562a131dee495ce4f6a50c99dc2f04ac69 /toolchain/helpers.mk | |
parent | 10e905f83dd4aebdea4c51ccbe4260f5adc6748c (diff) |
toolchain-external: align library locations in target and staging dir
The toolchain-external logic is roughly:
- populate the staging dir by rsyncing the entire ${ARCH_LIB_DIR} and
usr/${ARCH_LIB_DIR} from sysroot.
- populate the target dir by explictly copying some libraries from sysroot
into target/lib and some other libraries in target/usr/lib, the split
being hardcoded into buildroot regardless of the location in the sysroot.
This means that a library libfoo could be located in:
staging/lib/libfoo.so
target/usr/lib/libfoo.so
When debugging an application that links against this library, gdb will
fruitlessly search for 'usr/lib/libfoo.so' in staging, and then suggest to
use 'set solib-search-path' which is a hack, really.
To solve the problem, we need to make sure that libraries from the toolchain
are installed in the same relative location in staging and target.
Achieve this by:
- replacing the convoluted search for libraries using for+find in sysroot
with a simple find in staging.
- determining DESTDIR for each library individually based on the location in
staging.
- treating LIB_EXTERNAL_LIBS and USR_LIB_EXTERNAL_LIBS equivalently
These changes also allow for the removal of most arguments to
copy_toolchain_lib_root in the method itself and their callers.
Test procedure:
- set configuration for a given toolchain
- make clean toolchain
- find output/target | sort > /tmp/out-before
- apply patch
- make clean toolchain
- find output/target | sort > /tmp/out-after
- diff -u /tmp/out-before /tmp/out-after
The only changes should be some libraries moving from lib to usr/lib or vice
versa. Notable examples being libstdc++ and libatomic.
Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
Reviewed-by: Romain Naour <romain.naour@gmail.com>
Acked-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
[Thomas:
- use -L instead of -follow in the find invocation, as suggested by
Arnout.
- move the BR2_STATIC_LIBS condition as a make condition rather than
a shell condition, as suggested by Arnout.]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Diffstat (limited to 'toolchain/helpers.mk')
-rw-r--r-- | toolchain/helpers.mk | 57 |
1 files changed, 5 insertions, 52 deletions
diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk index ee878e89a..eeac7d2f2 100644 --- a/toolchain/helpers.mk +++ b/toolchain/helpers.mk @@ -6,62 +6,15 @@ # toolchain logic, and the glibc package, so care must be taken when # changing this function. # -# Most toolchains (CodeSourcery ones) have their libraries either in -# /lib or /usr/lib relative to their ARCH_SYSROOT_DIR, so we search -# libraries in: -# -# $${ARCH_LIB_DIR} -# usr/$${ARCH_LIB_DIR} -# -# Buildroot toolchains, however, have basic libraries in /lib, and -# libstdc++/libgcc_s in /usr/<target-name>/lib(64), so we also need to -# search libraries in: -# -# usr/$(TOOLCHAIN_EXTERNAL_PREFIX)/$${ARCH_LIB_DIR} -# -# Linaro toolchains have most libraries in lib/<target-name>/, so we -# need to search libraries in: -# -# $${ARCH_LIB_DIR}/$(TOOLCHAIN_EXTERNAL_PREFIX) -# -# And recent Linaro toolchains have the GCC support libraries -# (libstdc++, libgcc_s, etc.) into a separate directory, outside of -# the sysroot, that we called the "SUPPORT_LIB_DIR", into which we -# need to search as well. -# -# Thanks to ARCH_LIB_DIR we also take into account toolchains that -# have the libraries in lib64 and usr/lib64. -# -# Please be very careful to check the major toolchain sources: -# Buildroot, Crosstool-NG, CodeSourcery and Linaro before doing any -# modification on the below logic. -# -# $1: arch specific sysroot directory -# $2: support libraries directory (can be empty) -# $3: library directory ('lib' or 'lib64') from which libraries must be copied -# $4: library name -# $5: destination directory of the libary, relative to $(TARGET_DIR) +# $1: library name # copy_toolchain_lib_root = \ - ARCH_SYSROOT_DIR="$(strip $1)"; \ - SUPPORT_LIB_DIR="$(strip $2)" ; \ - ARCH_LIB_DIR="$(strip $3)" ; \ - LIB="$(strip $4)"; \ - DESTDIR="$(strip $5)" ; \ + LIB="$(strip $1)"; \ \ - for dir in \ - $${ARCH_SYSROOT_DIR}/$${ARCH_LIB_DIR}/$(TOOLCHAIN_EXTERNAL_PREFIX) \ - $${ARCH_SYSROOT_DIR}/usr/$(TOOLCHAIN_EXTERNAL_PREFIX)/$${ARCH_LIB_DIR} \ - $${ARCH_SYSROOT_DIR}/$${ARCH_LIB_DIR} \ - $${ARCH_SYSROOT_DIR}/usr/$${ARCH_LIB_DIR} \ - $${SUPPORT_LIB_DIR} ; do \ - LIBPATHS=`find $${dir} -maxdepth 1 -name "$${LIB}" 2>/dev/null` ; \ - if test -n "$${LIBPATHS}" ; then \ - break ; \ - fi \ - done ; \ - mkdir -p $(TARGET_DIR)/$${DESTDIR}; \ + LIBPATHS=`find -L $(STAGING_DIR) -name "$${LIB}" 2>/dev/null` ; \ for LIBPATH in $${LIBPATHS} ; do \ + DESTDIR=`echo $${LIBPATH} | sed "s,^$(STAGING_DIR)/,," | xargs dirname` ; \ + mkdir -p $(TARGET_DIR)/$${DESTDIR}; \ while true ; do \ LIBNAME=`basename $${LIBPATH}`; \ LIBDIR=`dirname $${LIBPATH}` ; \ |