diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2020-05-05 10:25:03 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2020-05-09 16:11:50 +0200 |
commit | 89607b4ad17d2cf4457e265dda226ac2e48221c9 (patch) | |
tree | a52845c150401c2ff912097e65c11ae215d83a56 | |
parent | c3381ccd5d945a916a301e310441bfd701468f38 (diff) | |
download | ptxdist-89607b4ad17d2cf4457e265dda226ac2e48221c9.tar.gz ptxdist-89607b4ad17d2cf4457e265dda226ac2e48221c9.tar.xz |
ptxdist: refactor wrapper & icecc setup
This just moves the code. No functional changes. This makes it possible to
overwrite the wrapper and icecc setup in the BSP if necessary.
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rwxr-xr-x | bin/ptxdist | 306 | ||||
-rw-r--r-- | scripts/lib/ptxd_lib_icecc.sh | 122 | ||||
-rw-r--r-- | scripts/lib/ptxd_lib_wrapper.sh | 215 |
3 files changed, 350 insertions, 293 deletions
diff --git a/bin/ptxdist b/bin/ptxdist index fc3d63778..137bd2f24 100755 --- a/bin/ptxdist +++ b/bin/ptxdist @@ -529,312 +529,32 @@ check_dirs() { done } -# -# Check for defined icecc -# Check for a usefull icecc version and setup the environment -# -check_compiler_icecc() { - if [ -z "${PTXDIST_ICECC}" ]; then - return - fi - local icecc_dir="${sysroot_host}/lib/icecc" - if [ -n "${toolchain}" -a "$(readlink -f "${icecc_dir}/toolchain")" != "${toolchain}" ]; then - rm -rf "${icecc_dir}" - fi - "${wrapper_dir}/real/gcc" --version > "${PTXDIST_TEMPDIR}/host-gcc-version" 2>&1 - "${wrapper_dir}/real/${compiler_prefix}gcc" --version > "${PTXDIST_TEMPDIR}/target-gcc-version" 2>&1 - if [ -d "${icecc_dir}" ]; then - if ! diff -q "${PTXDIST_TEMPDIR}/host-gcc-version" "${icecc_dir}/host-gcc-version" >& /dev/null || \ - ! diff -q "${PTXDIST_TEMPDIR}/target-gcc-version" "${icecc_dir}/target-gcc-version" >& /dev/null; then - rm -rf "${icecc_dir}" - fi - fi - if [ ! -d "${icecc_dir}" ]; then - if ! "${PTXDIST_ICECC}" --version | grep -q 'ICECC 1\.'; then - ptxd_bailout "PTXdist only supports icecc 1.x" - fi - mkdir -p "${icecc_dir}/target" "${icecc_dir}/host" && - ( - echo "Creating icecc host environment..." - if file -L "${wrapper_dir}/real/gcc" | grep script; then - ptxd_bailout "'$(readlink "${wrapper_dir}/real/gcc")' must not be a script if icecc is used!" - fi - cd "${icecc_dir}/host" - "${PTXDIST_ICECC_CREATE_ENV}" --gcc \ - "${wrapper_dir}/real/gcc" \ - "${wrapper_dir}/real/g++" > "${PTXDIST_TEMPDIR}/icecc.log" 2>&1 || \ - { - cat "${PTXDIST_TEMPDIR}/icecc.log" - ptxd_bailout "Failed to create icecc host environment!" - } - ln -s "$(readlink -f "${wrapper_dir}/real/gcc")" "${icecc_dir}/gcc" - - if [ -n "${compiler_prefix}" ]; then - echo "Creating icecc target environment..." - cd "${icecc_dir}/target" - local -a args - if [ -e "${wrapper_dir}/real/${compiler_prefix}clang" ]; then - args[${#args[@]}]="--clang" - args[${#args[@]}]="${wrapper_dir}/real/${compiler_prefix}clang" - fi - "${PTXDIST_ICECC_CREATE_ENV}" "${args[@]}" --gcc \ - "${wrapper_dir}/real/${compiler_prefix}gcc" \ - "${wrapper_dir}/real/${compiler_prefix}g++" > "${PTXDIST_TEMPDIR}/icecc.log" 2>&1 || \ - { - cat "${PTXDIST_TEMPDIR}/icecc.log" - ptxd_bailout "Failed to create icecc target environment!" - } - if [ ${#args[*]} -gt 0 ]; then - tar --strip-components=2 -xf *.tar.gz usr/bin/as && - ./as --verbose --version > env.log 2>&1 && - ${compiler_prefix}as --verbose --version > real.log 2>&1 - if ! cmp -s env.log real.log; then - echo "Broken icecc-create-env, disabling icecc clang support!" - rm *.tar.gz - "${PTXDIST_ICECC_CREATE_ENV}" --gcc \ - "${wrapper_dir}/real/${compiler_prefix}gcc" \ - "${wrapper_dir}/real/${compiler_prefix}g++" > "${PTXDIST_TEMPDIR}/icecc.log" 2>&1 || \ - { - cat "${PTXDIST_TEMPDIR}/icecc.log" - ptxd_bailout "Failed to create icecc target environment!" - } - fi - rm as env.log real.log - fi - ln -s "${toolchain}" "${icecc_dir}/toolchain" - fi - ) && - mv "${PTXDIST_TEMPDIR}/host-gcc-version" "${PTXDIST_TEMPDIR}/target-gcc-version" "${icecc_dir}/" - fi && - - ptxd_get_path "${icecc_dir}/host"/*.tar.gz && - export ICECC_VERSION_HOST="${ptxd_reply}" && - if [ -n "${compiler_prefix}" ]; then - ptxd_get_path "${icecc_dir}/target"/*.tar.gz && - export ICECC_VERSION_TARGET="${ptxd_reply}" - if tar -tf "${ICECC_VERSION_TARGET}" | grep -q clang; then - export PTXDIST_ICECC_CLANG=1 - fi - fi && - if "${PTXDIST_ICECC}" --help | grep -q ICECC_REMOTE_CPP; then - export PTXDIST_ICECC_REMOTE_CPP=1 - fi -} # # Check for defined compiler # This only should be done when we build userland (chicken egg problem) # check_compiler() { - local cc_ptr cc cc_abs cc_default cc_alternate - local wrapper_dir sysroot_host - local toolchain compiler_prefix - - sysroot_host="$(ptxd_get_ptxconf PTXCONF_SYSROOT_HOST)" - wrapper_dir="${sysroot_host}/lib/wrapper" - mkdir -p -- "${wrapper_dir}/real" || - ptxd_bailout "cannot create dir: '${wrapper_dir}/real'" + local wrapper_dir sysroot_host - ptxd_replace_copy_from_path PTXDIST_PATH \ - scripts/wrapper/libwrapper.sh "${wrapper_dir}/libwrapper.sh" + sysroot_host="$(ptxd_get_ptxconf PTXCONF_SYSROOT_HOST)" + wrapper_dir="${sysroot_host}/lib/wrapper" - for cc_ptr in \ - PTXCONF_SETUP_HOST_CPP \ - PTXCONF_SETUP_HOST_CC \ - PTXCONF_SETUP_HOST_CXX \ - ; do - cc="${!cc_ptr}" - if [ -z "${cc}" ]; then - echo - echo "${PTXDIST_LOG_PROMPT}error: undefined host ${cc_ptr##*_} compiler" - echo "${PTXDIST_LOG_PROMPT}error: run 'ptxdist setup' and enter the 'Developer Options' menu" - echo "${PTXDIST_LOG_PROMPT}error: and specify the compiler" - echo - exit 1 - fi - - cc_abs="$(which "${cc}" 2>/dev/null)" - if [ \! -x "${cc_abs}" ]; then - echo - echo "${PTXDIST_LOG_PROMPT}error: your host ${cc_ptr##*_} compiler: '${cc}'" - echo "${PTXDIST_LOG_PROMPT}error: cannot be found or isn't executable" - echo "${PTXDIST_LOG_PROMPT}error: run 'ptxdist setup' and enter the 'Developer Options' menu" - echo "${PTXDIST_LOG_PROMPT}error: and specify the compiler" - echo - exit 1 - fi - - case "${cc_ptr}" in - PTXCONF_SETUP_HOST_CPP) - cc_default=cpp - unset cc_alternate - ;; - PTXCONF_SETUP_HOST_CC) - cc_default=gcc - cc_alternate=cc - ;; - PTXCONF_SETUP_HOST_CXX) - cc_default=g++ - cc_alternate=c++ - ;; - esac - - ptxd_replace_link "${cc_abs}" "${wrapper_dir}/real/${cc_default}" && - ptxd_replace_copy_from_path PTXDIST_PATH "scripts/wrapper/host-${cc_default}-wrapper" \ - "${wrapper_dir}/${cc_default}" && - - if [ -n "${cc_alternate}" ]; then - ptxd_replace_link "${cc_default}" "${wrapper_dir}/${cc_alternate}" && - ptxd_replace_link "${cc_default}" "${wrapper_dir}/real/${cc_alternate}" - fi || { - rm -rf "${wrapper_dir}" - ptxd_bailout "unable to create compiler wrapper link" - } - done - - ptxd_replace_copy_from_path PTXDIST_PATH "scripts/wrapper/python-wrapper" \ - "${wrapper_dir}/python-wrapper" && - for python in python2 python2-config python3 python3-config; do - if type -P "${python}" > /dev/null; then - ptxd_replace_link "python-wrapper" "${wrapper_dir}/${python}" || \ - ptxd_bailout "Unable to create ${python} wrapper link" - ptxd_replace_link "python-wrapper" "${wrapper_dir}/${python/[23]}" || \ - ptxd_bailout "Unable to create ${python/[23]} wrapper link" - fi - done && - - for tool in ar as nm objcopy objdump ranlib readelf size strip ; do - tool_abs="$(which "${tool}" 2>/dev/null)" - ptxd_replace_link "${tool_abs}" "${wrapper_dir}/${tool}" || \ - ptxd_bailout "Unable to create host ${tool} wrapper link" - done - - if ptxd_get_ptxconf PTXCONF_BUILD_TOOLCHAIN >/dev/null; then - PATH="${wrapper_dir}:${PATH}" - check_compiler_icecc - return - fi + ptxd_lib_setup_host_wrapper && + ptxd_lib_setup_host_icecc && - # - # Three things should be checked - # 1) Correct compiler name - # 2) Correct vendor if the vendor string is given - # 3) Correct compiler version if a specific compiler version is given - # - - compiler_prefix="$(ptxd_get_ptxconf PTXCONF_COMPILER_PREFIX)" - local vendor_should - vendor_should="$(ptxd_get_ptxconf PTXCONF_CROSSCHAIN_VENDOR)" && { - # yea! A toolchain vendor was specified in the ptxconfig file. - # - # We have two options now: - # a) the provided toolchain is an OSELAS.Toolchain which contains a - # 'ptxconfig', so test the PTXCONF_PROJECT string therein. - # b) the provided toolchain is a crosstool-ng one which contains a - # ${compiler_prefix}-ct-ng.config, so test the - # CT_TOOLCHAIN_PKGVERSION therein. - # - - if [ ! -d "${PTXDIST_TOOLCHAIN}" ]; then - echo - echo "${PTXDIST_LOG_PROMPT}error: specify '${PTXDIST_TOOLCHAIN#${PTXDIST_WORKSPACE}/}' with 'ptxdist toolchain [<path>]'" - echo "${PTXDIST_LOG_PROMPT}error: or leave PTXCONF_CROSSCHAIN_VENDOR empty to disable toolchain check" - echo - exit 1 - fi - - local ptxdist_vendor_def="$(readlink -f "${PTXDIST_TOOLCHAIN}/ptxconfig")" - local ct_vendor_def="$(readlink -f "${PTXDIST_TOOLCHAIN}/${compiler_prefix}ct-ng.config")" - - local vendor_is - if [ "${ptxdist_vendor_def}" -a -e "${ptxdist_vendor_def}" ]; then - vendor_is="$(source "${ptxdist_vendor_def}" && echo ${PTXCONF_PROJECT})" - elif [ "${ct_vendor_def}" -a -x "${ct_vendor_def}" ]; then - vendor_is=$(${ct_vendor_def} | awk ' \ - /^#\s+crosstool-NG.*Configuration$/ { \ - printf("%s %s", $2, $3) \ - }; \ - /^CT_TOOLCHAIN_PKGVERSION=/ { \ - gsub(/\"/, ""); \ - split($0,ary,"="); \ - if (ary[1]) { \ - printf(" - %s", ary[2]); \ - } \ - }') - else - echo - echo "${PTXDIST_LOG_PROMPT}error: toolchain doesn't point to an OSELAS.Toolchain nor a crosstools-ng toolchain" - echo "${PTXDIST_LOG_PROMPT}error: leave PTXCONF_CROSSCHAIN_VENDOR empty to disable vendor check" - echo - exit 1 - fi - - # both vendor strings are present. Check them - case "${vendor_is}" in - "${vendor_should}"*) - ;; - *) - echo - echo "${PTXDIST_LOG_PROMPT}error: wrong toolchain vendor: Cannot continue! Vendor is '${vendor_is}'," - echo "${PTXDIST_LOG_PROMPT}error: specified: ${vendor_should}" - echo "${PTXDIST_LOG_PROMPT}error: found: ${vendor_is}" - echo - exit 1 - ;; - esac - } + if ! ptxd_get_ptxconf PTXCONF_BUILD_TOOLCHAIN >/dev/null; then + local toolchain compiler_prefix - local compiler_ver_should toolchain="$(readlink -f "${PTXDIST_TOOLCHAIN}")" - compiler_ver_should="$(ptxd_get_ptxconf PTXCONF_CROSSCHAIN_CHECK)" && { - local compiler="${compiler_prefix}gcc" - local compiler_ver_is="$(${toolchain}/${compiler} -dumpversion 2> /dev/null || true)" + compiler_prefix="$(ptxd_get_ptxconf PTXCONF_COMPILER_PREFIX)" - if [ -z "${compiler_ver_is}" ]; then - echo - echo "${PTXDIST_LOG_PROMPT}error: Compiler '${compiler}' not found. Check PATH or" - echo "${PTXDIST_LOG_PROMPT}error: use 'ptxdist toolchain [</path/to/toolchain>]'." - echo - exit 1 - fi + ptxd_lib_setup_toolchain && + ptxd_lib_setup_target_wrapper && + ptxd_lib_setup_target_icecc + fi && - if [ "${compiler_ver_is}" != "${compiler_ver_should}" ]; then - echo - echo "${PTXDIST_LOG_PROMPT}error: Compiler version ${compiler_ver_should} expected," - echo "${PTXDIST_LOG_PROMPT}error: but ${compiler_ver_is} found." - echo - exit 1 - fi - } - - ptxd_replace_link "${toolchain}" "${PTXDIST_PLATFORMDIR}/selected_toolchain" && - for cc in gcc g++ cpp ld gdb; do - ptxd_replace_link "${toolchain}/${compiler_prefix}${cc}" "${wrapper_dir}/real/${compiler_prefix}${cc}" && - ptxd_replace_copy_from_path PTXDIST_PATH "scripts/wrapper/${cc}-wrapper" \ - "${wrapper_dir}/${compiler_prefix}${cc}" - done && - for cc in clang clang++; do - if [ ! -e "${toolchain}/${cc}" ]; then - continue - fi - ptxd_replace_link "${toolchain}/${cc}" "${wrapper_dir}/real/${compiler_prefix}${cc}" && - ptxd_replace_copy_from_path PTXDIST_PATH "scripts/wrapper/${cc}-wrapper" \ - "${wrapper_dir}/${compiler_prefix}${cc}" - done - for tool in "${toolchain}/${compiler_prefix}"* ; do - local toolname="$(basename "${tool}")" - if [ ! -e "${wrapper_dir}/${toolname}" -o -h "${wrapper_dir}/${toolname}" ]; then - ptxd_replace_link "${tool}" "${wrapper_dir}/${toolname}" - fi - done && - for tool in "${wrapper_dir}/${compiler_prefix}"* ; do - local toolname="$(basename "${tool}")" - if [ -e "${tool}" -a ! -e "${toolchain}/${toolname}" ]; then - rm -f "${tool}" - fi - done && - PATH="${wrapper_dir}:${PATH}" && - check_compiler_icecc + PATH="${wrapper_dir}:${PATH}" } diff --git a/scripts/lib/ptxd_lib_icecc.sh b/scripts/lib/ptxd_lib_icecc.sh new file mode 100644 index 000000000..3682201f0 --- /dev/null +++ b/scripts/lib/ptxd_lib_icecc.sh @@ -0,0 +1,122 @@ +#!/bin/bash +# +# Copyright (C) 2020 by Michael Olbrich <m.olbrich@pengutronix.de> +# +# For further information about the PTXdist project and license conditions +# see the README file. +# + +# +# Check for defined icecc +# Check for a usefull icecc version and setup the host environment +# +ptxd_lib_setup_host_icecc() { + local icecc_dir="${sysroot_host}/lib/icecc" + + if [ -z "${PTXDIST_ICECC}" ]; then + return + fi + + "${wrapper_dir}/real/gcc" --version > "${PTXDIST_TEMPDIR}/host-gcc-version" 2>&1 + if [ -d "${icecc_dir}/host" -a -f "${icecc_dir}/host-gcc-version" ]; then + if ! diff -q "${PTXDIST_TEMPDIR}/host-gcc-version" "${icecc_dir}/host-gcc-version" >& /dev/null; then + rm -rf "${icecc_dir}/host" "${icecc_dir}/host-gcc-version" "${icecc_dir}/gcc" + fi + fi + if [ ! -d "${icecc_dir}/host" ]; then + if ! "${PTXDIST_ICECC}" --version | grep -q 'ICECC 1\.'; then + ptxd_bailout "PTXdist only supports icecc 1.x" + fi + mkdir -p "${icecc_dir}/host" && + ( + echo "Creating icecc host environment..." + if file -L "${wrapper_dir}/real/gcc" | grep script; then + ptxd_bailout "'$(readlink "${wrapper_dir}/real/gcc")' must not be a script if icecc is used!" + fi + cd "${icecc_dir}/host" + "${PTXDIST_ICECC_CREATE_ENV}" --gcc \ + "${wrapper_dir}/real/gcc" \ + "${wrapper_dir}/real/g++" > "${PTXDIST_TEMPDIR}/icecc.log" 2>&1 || \ + { + cat "${PTXDIST_TEMPDIR}/icecc.log" + ptxd_bailout "Failed to create icecc host environment!" + } + ln -s "$(readlink -f "${wrapper_dir}/real/gcc")" "${icecc_dir}/gcc" + ) && + mv "${PTXDIST_TEMPDIR}/host-gcc-version" "${icecc_dir}/" + fi && + + ptxd_get_path "${icecc_dir}/host"/*.tar.gz && + export ICECC_VERSION_HOST="${ptxd_reply}" && + + if "${PTXDIST_ICECC}" --help | grep -q ICECC_REMOTE_CPP; then + export PTXDIST_ICECC_REMOTE_CPP=1 + fi +} +export -f ptxd_lib_setup_host_icecc + +# +# Check for defined icecc +# Setup the host environment +# +ptxd_lib_setup_target_icecc() { + local icecc_dir="${sysroot_host}/lib/icecc" + + if [ -z "${PTXDIST_ICECC}" ]; then + return + fi + if [ -z "${toolchain}" -o "$(readlink -f "${icecc_dir}/toolchain")" != "${toolchain}" ]; then + rm -rf "${icecc_dir}/target" "${icecc_dir}/target-gcc-version" "${icecc_dir}/toolchain" + fi + "${wrapper_dir}/real/${compiler_prefix}gcc" --version > "${PTXDIST_TEMPDIR}/target-gcc-version" 2>&1 + if [ -d "${icecc_dir}/target" -a -f "${icecc_dir}/host-gcc-version" ]; then + if ! diff -q "${PTXDIST_TEMPDIR}/target-gcc-version" "${icecc_dir}/target-gcc-version" >& /dev/null; then + rm -rf "${icecc_dir}/target" "${icecc_dir}/target-gcc-version" "${icecc_dir}/toolchain" + fi + fi + if [ ! -d "${icecc_dir}/target" ]; then + mkdir -p "${icecc_dir}/target" && + ( + echo "Creating icecc target environment..." + cd "${icecc_dir}/target" + local -a args + if [ -e "${wrapper_dir}/real/${compiler_prefix}clang" ]; then + args[${#args[@]}]="--clang" + args[${#args[@]}]="${wrapper_dir}/real/${compiler_prefix}clang" + fi + "${PTXDIST_ICECC_CREATE_ENV}" "${args[@]}" --gcc \ + "${wrapper_dir}/real/${compiler_prefix}gcc" \ + "${wrapper_dir}/real/${compiler_prefix}g++" > "${PTXDIST_TEMPDIR}/icecc.log" 2>&1 || \ + { + cat "${PTXDIST_TEMPDIR}/icecc.log" + ptxd_bailout "Failed to create icecc target environment!" + } + if [ ${#args[*]} -gt 0 ]; then + tar --strip-components=2 -xf *.tar.gz usr/bin/as && + ./as --verbose --version > env.log 2>&1 && + ${compiler_prefix}as --verbose --version > real.log 2>&1 + if ! cmp -s env.log real.log; then + echo "Broken icecc-create-env, disabling icecc clang support!" + rm *.tar.gz + "${PTXDIST_ICECC_CREATE_ENV}" --gcc \ + "${wrapper_dir}/real/${compiler_prefix}gcc" \ + "${wrapper_dir}/real/${compiler_prefix}g++" > "${PTXDIST_TEMPDIR}/icecc.log" 2>&1 || \ + { + cat "${PTXDIST_TEMPDIR}/icecc.log" + ptxd_bailout "Failed to create icecc target environment!" + } + fi + rm as env.log real.log + fi + ln -s "${toolchain}" "${icecc_dir}/toolchain" + ) && + mv "${PTXDIST_TEMPDIR}/target-gcc-version" "${icecc_dir}/" + fi && + + ptxd_get_path "${icecc_dir}/target"/*.tar.gz && + export ICECC_VERSION_TARGET="${ptxd_reply}" + if tar -tf "${ICECC_VERSION_TARGET}" | grep -q clang; then + export PTXDIST_ICECC_CLANG=1 + fi +} +export -f ptxd_lib_setup_target_icecc diff --git a/scripts/lib/ptxd_lib_wrapper.sh b/scripts/lib/ptxd_lib_wrapper.sh new file mode 100644 index 000000000..5eb97327e --- /dev/null +++ b/scripts/lib/ptxd_lib_wrapper.sh @@ -0,0 +1,215 @@ +#!/bin/bash +# +# Copyright (C) 2020 by Michael Olbrich <m.olbrich@pengutronix.de> +# +# For further information about the PTXdist project and license conditions +# see the README file. +# + +ptxd_lib_setup_host_wrapper() { + local cc_ptr cc cc_abs cc_default cc_alternate + + mkdir -p -- "${wrapper_dir}/real" || + ptxd_bailout "cannot create dir: '${wrapper_dir}/real'" + + ptxd_replace_copy_from_path PTXDIST_PATH \ + scripts/wrapper/libwrapper.sh "${wrapper_dir}/libwrapper.sh" + + for cc_ptr in \ + PTXCONF_SETUP_HOST_CPP \ + PTXCONF_SETUP_HOST_CC \ + PTXCONF_SETUP_HOST_CXX \ + ; do + cc="${!cc_ptr}" + if [ -z "${cc}" ]; then + echo + echo "${PTXDIST_LOG_PROMPT}error: undefined host ${cc_ptr##*_} compiler" + echo "${PTXDIST_LOG_PROMPT}error: run 'ptxdist setup' and enter the 'Developer Options' menu" + echo "${PTXDIST_LOG_PROMPT}error: and specify the compiler" + echo + exit 1 + fi + + cc_abs="$(which "${cc}" 2>/dev/null)" + if [ \! -x "${cc_abs}" ]; then + echo + echo "${PTXDIST_LOG_PROMPT}error: your host ${cc_ptr##*_} compiler: '${cc}'" + echo "${PTXDIST_LOG_PROMPT}error: cannot be found or isn't executable" + echo "${PTXDIST_LOG_PROMPT}error: run 'ptxdist setup' and enter the 'Developer Options' menu" + echo "${PTXDIST_LOG_PROMPT}error: and specify the compiler" + echo + exit 1 + fi + + case "${cc_ptr}" in + PTXCONF_SETUP_HOST_CPP) + cc_default=cpp + unset cc_alternate + ;; + PTXCONF_SETUP_HOST_CC) + cc_default=gcc + cc_alternate=cc + ;; + PTXCONF_SETUP_HOST_CXX) + cc_default=g++ + cc_alternate=c++ + ;; + esac + + ptxd_replace_link "${cc_abs}" "${wrapper_dir}/real/${cc_default}" && + ptxd_replace_copy_from_path PTXDIST_PATH "scripts/wrapper/host-${cc_default}-wrapper" \ + "${wrapper_dir}/${cc_default}" && + + if [ -n "${cc_alternate}" ]; then + ptxd_replace_link "${cc_default}" "${wrapper_dir}/${cc_alternate}" && + ptxd_replace_link "${cc_default}" "${wrapper_dir}/real/${cc_alternate}" + fi || { + rm -rf "${wrapper_dir}" + ptxd_bailout "unable to create compiler wrapper link" + } + done + + ptxd_replace_copy_from_path PTXDIST_PATH "scripts/wrapper/python-wrapper" \ + "${wrapper_dir}/python-wrapper" && + for python in python2 python2-config python3 python3-config; do + if type -P "${python}" > /dev/null; then + ptxd_replace_link "python-wrapper" "${wrapper_dir}/${python}" || \ + ptxd_bailout "Unable to create ${python} wrapper link" + ptxd_replace_link "python-wrapper" "${wrapper_dir}/${python/[23]}" || \ + ptxd_bailout "Unable to create ${python/[23]} wrapper link" + fi + done && + + for tool in ar as nm objcopy objdump ranlib readelf size strip ; do + tool_abs="$(which "${tool}" 2>/dev/null)" + ptxd_replace_link "${tool_abs}" "${wrapper_dir}/${tool}" || \ + ptxd_bailout "Unable to create host ${tool} wrapper link" + done +} +export -f ptxd_lib_setup_host_wrapper + + +ptxd_lib_setup_toolchain() { + local vendor_should compiler_ver_should + # + # Three things should be checked + # 1) Correct compiler name + # 2) Correct vendor if the vendor string is given + # 3) Correct compiler version if a specific compiler version is given + # + + vendor_should="$(ptxd_get_ptxconf PTXCONF_CROSSCHAIN_VENDOR)" && { + local ptxdist_vendor_def ct_vendor_def vendor_is + # yea! A toolchain vendor was specified in the ptxconfig file. + # + # We have two options now: + # a) the provided toolchain is an OSELAS.Toolchain which contains a + # 'ptxconfig', so test the PTXCONF_PROJECT string therein. + # b) the provided toolchain is a crosstool-ng one which contains a + # ${compiler_prefix}-ct-ng.config, so test the + # CT_TOOLCHAIN_PKGVERSION therein. + # + + if [ ! -d "${PTXDIST_TOOLCHAIN}" ]; then + echo + echo "${PTXDIST_LOG_PROMPT}error: specify '${PTXDIST_TOOLCHAIN#${PTXDIST_WORKSPACE}/}' with 'ptxdist toolchain [<path>]'" + echo "${PTXDIST_LOG_PROMPT}error: or leave PTXCONF_CROSSCHAIN_VENDOR empty to disable toolchain check" + echo + exit 1 + fi + + ptxdist_vendor_def="$(readlink -f "${PTXDIST_TOOLCHAIN}/ptxconfig")" + ct_vendor_def="$(readlink -f "${PTXDIST_TOOLCHAIN}/${compiler_prefix}ct-ng.config")" + + if [ "${ptxdist_vendor_def}" -a -e "${ptxdist_vendor_def}" ]; then + vendor_is="$(source "${ptxdist_vendor_def}" && echo ${PTXCONF_PROJECT})" + elif [ "${ct_vendor_def}" -a -x "${ct_vendor_def}" ]; then + vendor_is=$(${ct_vendor_def} | awk ' \ + /^#\s+crosstool-NG.*Configuration$/ { \ + printf("%s %s", $2, $3) \ + }; \ + /^CT_TOOLCHAIN_PKGVERSION=/ { \ + gsub(/\"/, ""); \ + split($0,ary,"="); \ + if (ary[1]) { \ + printf(" - %s", ary[2]); \ + } \ + }') + else + echo + echo "${PTXDIST_LOG_PROMPT}error: toolchain doesn't point to an OSELAS.Toolchain nor a crosstools-ng toolchain" + echo "${PTXDIST_LOG_PROMPT}error: leave PTXCONF_CROSSCHAIN_VENDOR empty to disable vendor check" + echo + exit 1 + fi + + # both vendor strings are present. Check them + case "${vendor_is}" in + "${vendor_should}"*) + ;; + *) + echo + echo "${PTXDIST_LOG_PROMPT}error: wrong toolchain vendor: Cannot continue! Vendor is '${vendor_is}'," + echo "${PTXDIST_LOG_PROMPT}error: specified: ${vendor_should}" + echo "${PTXDIST_LOG_PROMPT}error: found: ${vendor_is}" + echo + exit 1 + ;; + esac + } + + compiler_ver_should="$(ptxd_get_ptxconf PTXCONF_CROSSCHAIN_CHECK)" && { + local compiler compiler_ver_is + + compiler="${compiler_prefix}gcc" + compiler_ver_is="$(${toolchain}/${compiler} -dumpversion 2> /dev/null || true)" + + if [ -z "${compiler_ver_is}" ]; then + echo + echo "${PTXDIST_LOG_PROMPT}error: Compiler '${compiler}' not found. Check PATH or" + echo "${PTXDIST_LOG_PROMPT}error: use 'ptxdist toolchain [</path/to/toolchain>]'." + echo + exit 1 + fi + + if [ "${compiler_ver_is}" != "${compiler_ver_should}" ]; then + echo + echo "${PTXDIST_LOG_PROMPT}error: Compiler version ${compiler_ver_should} expected," + echo "${PTXDIST_LOG_PROMPT}error: but ${compiler_ver_is} found." + echo + exit 1 + fi + } + + ptxd_replace_link "${toolchain}" "${PTXDIST_PLATFORMDIR}/selected_toolchain" +} +export -f ptxd_lib_setup_toolchain + +ptxd_lib_setup_target_wrapper() { + for cc in gcc g++ cpp ld gdb; do + ptxd_replace_link "${toolchain}/${compiler_prefix}${cc}" "${wrapper_dir}/real/${compiler_prefix}${cc}" && + ptxd_replace_copy_from_path PTXDIST_PATH "scripts/wrapper/${cc}-wrapper" \ + "${wrapper_dir}/${compiler_prefix}${cc}" + done && + for cc in clang clang++; do + if [ ! -e "${toolchain}/${cc}" ]; then + continue + fi + ptxd_replace_link "${toolchain}/${cc}" "${wrapper_dir}/real/${compiler_prefix}${cc}" && + ptxd_replace_copy_from_path PTXDIST_PATH "scripts/wrapper/${cc}-wrapper" \ + "${wrapper_dir}/${compiler_prefix}${cc}" + done + for tool in "${toolchain}/${compiler_prefix}"* ; do + local toolname="$(basename "${tool}")" + if [ ! -e "${wrapper_dir}/${toolname}" -o -h "${wrapper_dir}/${toolname}" ]; then + ptxd_replace_link "${tool}" "${wrapper_dir}/${toolname}" + fi + done && + for tool in "${wrapper_dir}/${compiler_prefix}"* ; do + local toolname="$(basename "${tool}")" + if [ -e "${tool}" -a ! -e "${toolchain}/${toolname}" ]; then + rm -f "${tool}" + fi + done +} +export -f ptxd_lib_setup_target_wrapper |