diff options
author | Marc Kleine-Budde <mkl@pengutronix.de> | 2013-11-01 12:05:35 +0100 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2013-11-01 12:35:52 +0100 |
commit | 572b66604143242ed5efc4afa6835d844fb7bf78 (patch) | |
tree | d437fcf93df470e594fd42b9abc7dddee599b579 | |
parent | a6ffb880e7a7436cb8bc4b81f010d869f1efb520 (diff) | |
download | ptxdist-572b66604143242ed5efc4afa6835d844fb7bf78.tar.gz ptxdist-572b66604143242ed5efc4afa6835d844fb7bf78.tar.xz |
scripts: backport toolchain sysroot detection from mainline
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | scripts/lib/ptxd_make_00-init.sh | 37 | ||||
-rw-r--r-- | scripts/libptxdist.sh | 24 |
2 files changed, 55 insertions, 6 deletions
diff --git a/scripts/lib/ptxd_make_00-init.sh b/scripts/lib/ptxd_make_00-init.sh index 245b43157..498be9ed6 100644 --- a/scripts/lib/ptxd_make_00-init.sh +++ b/scripts/lib/ptxd_make_00-init.sh @@ -41,29 +41,54 @@ ptxd_init_arch() { # +# run cross-gcc with flags +# +ptxd_cross_cc() { + local compiler_prefix extra_cppflags extra_cflags + compiler_prefix="$(ptxd_get_ptxconf PTXCONF_COMPILER_PREFIX)" + extra_cppflags="$(ptxd_get_ptxconf PTXCONF_TARGET_EXTRA_CPPFLAGS)" + extra_cflags="$(ptxd_get_ptxconf PTXCONF_TARGET_EXTRA_CFLAGS)" + + ${compiler_prefix}gcc ${extra_cppflags} ${extra_cflags} "${@}" +} +export -f ptxd_cross_cc + +# +# run cross-gcc with flags and -v +# +ptxd_cross_cc_v() { + echo 'int main(void){return 0;}' | \ + ptxd_cross_cc -x c -o /dev/null -v - 2>&1 +} +export -f ptxd_cross_cc_v + +# # figure out the toolchain's sysroot # # out: PTXDIST_SYSROOT_TOOLCHAIN # ptxd_init_sysroot_toolchain() { - local compiler_prefix="$(ptxd_get_ptxconf PTXCONF_COMPILER_PREFIX)" - # # no compiler prefix specified means using plain "gcc" # which comes from the distribution, so no sysroot here # + local compiler_prefix="$(ptxd_get_ptxconf PTXCONF_COMPILER_PREFIX)" if [ -z "${compiler_prefix}" ]; then PTXDIST_SYSROOT_TOOLCHAIN="/" else local sysroot - sysroot="$(echo 'int main(void){return 0;}' | \ - ${compiler_prefix}gcc -x c -o /dev/null -v - 2>&1 | \ + sysroot="$(ptxd_cross_cc -print-sysroot 2> /dev/null)" && + [ -n "${sysroot}" ] || + sysroot="$(ptxd_cross_cc_v | \ sed -ne "/.*collect2.*/s,.*--sysroot=\([^[:space:]]*\).*,\1,p" && \ - check_pipe_status)" + check_pipe_status)" && + [ -n "${sysroot}" ] || + sysroot="$(ptxd_lib_sysroot \ + "$(ptxd_cross_cc -print-file-name=libc.so 2> /dev/null)")" if [ $? -ne 0 -o -z "${sysroot}" ]; then - return 1 + ptxd_bailout "Could not detect toolchain sysroot! The toolchain is broken or not configured correctly." fi PTXDIST_SYSROOT_TOOLCHAIN="$(ptxd_abspath "${sysroot}")" || return diff --git a/scripts/libptxdist.sh b/scripts/libptxdist.sh index a508a8428..7c65765a8 100644 --- a/scripts/libptxdist.sh +++ b/scripts/libptxdist.sh @@ -543,6 +543,30 @@ export -f check_pipe_status # +# $1: lib_path # cannolocilized path to lib or link +# +ptxd_lib_sysroot() { + local lib_path lib lib_dir prefix tmp + + lib_path="${1}" + lib="$(basename "${lib_path}")" + lib_dir="$(dirname "${lib_path}")" + + # try to identify sysroot part of that path + for prefix in {/usr,}/lib{64,32,}{/tls,/gconv,} ""; do + tmp="${lib_dir%${prefix}}" + if test "${lib_dir}" != "${tmp}"; then + echo "${tmp}" + return + fi + done + + return 1 +} +export -f ptxd_lib_sysroot + + +# # split ipkg filename into it's parts # # input format: |