Add a utility to populate a root directory with libraries from the toolchain.
1.1 --- a/scripts/build/cc_gcc.sh Sun Jul 08 11:02:38 2007 +0000
1.2 +++ b/scripts/build/cc_gcc.sh Sun Jul 08 17:44:59 2007 +0000
1.3 @@ -137,5 +137,9 @@
1.4 # ;;
1.5 #esac
1.6
1.7 + # Create a symlink ${CT_TARGET}-cc to ${CT_TARGET}-gcc to always be able
1.8 + # to call the C compiler with the same, somewhat canonical name.
1.9 + ln -s "${CT_TARGET}-gcc" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc"
1.10 +
1.11 CT_EndStep
1.12 }
2.1 --- a/scripts/crosstool.sh Sun Jul 08 11:02:38 2007 +0000
2.2 +++ b/scripts/crosstool.sh Sun Jul 08 17:44:59 2007 +0000
2.3 @@ -423,6 +423,12 @@
2.4 prev_step="${step}"
2.5 done
2.6
2.7 + # Install the /populator/
2.8 + sed -r -e 's,@@CT_READELF@@,'"${CT_PREFIX_DIR}/bin/${CT_TARGET}-readelf"',g;' \
2.9 + -e 's,@@CT_SYSROOT_DIR@@,'"${CT_SYSROOT_DIR}"',g;' \
2.10 + "${CT_LIB_DIR}/tools/populate.in" >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
2.11 + chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
2.12 +
2.13 # Create the aliases to the target tools
2.14 if [ -n "${CT_TARGET_ALIAS}" ]; then
2.15 CT_DoLog EXTRA "Creating symlinks from \"${CT_TARGET}-*\" to \"${CT_TARGET_ALIAS}-*\""
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tools/populate.in Sun Jul 08 17:44:59 2007 +0000
3.3 @@ -0,0 +1,124 @@
3.4 +#!/bin/bash
3.5 +
3.6 +# This script will populate the root directory with libs from the sysroot.
3.7 +# (C) 2007 Yann E. MORIN
3.8 +# Licensed under the GPL v2
3.9 +
3.10 +CT_READELF="@@CT_READELF@@"
3.11 +CT_SYSROOT_DIR="@@CT_SYSROOT_DIR@@"
3.12 +
3.13 +myname=$(basename "$0")
3.14 +
3.15 +doHelp() {
3.16 + cat <<_EOF_
3.17 +$myname [ -f ] < -s source_root > < -d destination_root >
3.18 +
3.19 + -f force execution: if destination directory already exists,
3.20 + it will be removed first.
3.21 +
3.22 + -s dir
3.23 + use 'dir' as the un-populated (source) root directory
3.24 +
3.25 + -d dir
3.26 + use 'dir' as the place to put the populated root directory
3.27 +
3.28 + -v Be verbose
3.29 +_EOF_
3.30 +}
3.31 +
3.32 +CT_FORCE=no
3.33 +CT_ROOT_SRC_DIR=
3.34 +CT_ROOT_DST_DIR=
3.35 +CT_ECHO=true
3.36 +while getopts ":fs:d:vh" CT_OPT; do
3.37 + case "${CT_OPT}" in
3.38 + f) CT_FORCE=yes;;
3.39 + s) CT_ROOT_SRC_DIR="${OPTARG}";;
3.40 + d) CT_ROOT_DST_DIR="${OPTARG}";;
3.41 + v) CT_ECHO=echo;;
3.42 + h) doHelp
3.43 + exit 0
3.44 + ;;
3.45 + :) echo "$myname: \"-${OPTARG}\" takes exactly one argument."
3.46 + exit 1
3.47 + ;;
3.48 + ?) echo "$myname: unknown option \"-${OPTARG}\"."
3.49 + exit 1
3.50 + ;;
3.51 + esac
3.52 +done
3.53 +
3.54 +# Sanity checks
3.55 +if [ -z "${CT_ROOT_SRC_DIR}" -o -z "${CT_ROOT_DST_DIR}" ]; then
3.56 + doHelp
3.57 + exit 1
3.58 +fi
3.59 +if [ ! -d "${CT_ROOT_SRC_DIR}" ]; then
3.60 + echo "$myname: \"${CT_ROOT_SRC_DIR}\": no such file or directory"
3.61 + exit 1
3.62 +fi
3.63 +if [ -d "${CT_ROOT_DST_DIR}" -a "${CT_FORCE}" != "yes" ]; then
3.64 + echo "$myname: \"${CT_ROOT_DST_DIR}\": already exists"
3.65 + exit 1
3.66 +fi
3.67 +src_inode=$(ls -di "${CT_ROOT_SRC_DIR}")
3.68 +dst_inode=$(ls -di "${CT_ROOT_DST_DIR}" 2>/dev/null)
3.69 +if [ "${src_inode}" = "${dst_inode}" ]; then
3.70 + echo "$myname: source and destination are the same!"
3.71 + exit 1
3.72 +fi
3.73 +
3.74 +# Get rid of potentially older destination directory
3.75 +if [ -d "${CT_ROOT_DST_DIR}" ]; then
3.76 + mv "${CT_ROOT_DST_DIR}" "${CT_ROOT_DST_DIR}.$$"
3.77 + nohup rm -rf "${CT_ROOT_DST_DIR}.$$" >/dev/null 2>&1 &
3.78 +fi
3.79 +
3.80 +# Create the working copy
3.81 +mkdir -p "${CT_ROOT_DST_DIR}"
3.82 +
3.83 +# Make all path absolute
3.84 +case "${CT_ROOT_SRC_DIR}" in
3.85 + /*) ;;
3.86 + *) CT_ROOT_SRC_DIR=$(cd "${CT_ROOT_SRC_DIR}"; pwd)
3.87 +esac
3.88 +case "${CT_ROOT_DST_DIR}" in
3.89 + /*) ;;
3.90 + *) CT_ROOT_DST_DIR=$(cd "${CT_ROOT_DST_DIR}"; pwd)
3.91 +esac
3.92 +
3.93 +cd "${CT_ROOT_SRC_DIR}"
3.94 +tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -)
3.95 +
3.96 +# Parse the working copy for executables and libraries
3.97 +cd "${CT_ROOT_DST_DIR}"
3.98 +still_needed=1
3.99 +while [ ${still_needed} -eq 1 ]; do
3.100 + ${CT_ECHO} "Looping..."
3.101 + still_needed=0
3.102 + for f in $(find . -type f -exec file {} \; |egrep ': ELF [[:digit:]]+-bit .SB (executable|shared object),' |cut -d ":" -f 1); do
3.103 + ${CT_ECHO} "Scanning \"${f}\""
3.104 + for libname in $("${CT_READELF}" -d "${f}" |egrep '(NEEDED)' |sed -r -e 's,.+\[(.+)\] *$,\1,;'); do
3.105 + ${CT_ECHO} " searching for \"${libname}\""
3.106 + if [ -e "${CT_ROOT_DST_DIR}/lib/${libname}" \
3.107 + -o -e "${CT_ROOT_DST_DIR}/usr/lib/${libname}" ]; then
3.108 + ${CT_ECHO} " already present"
3.109 + continue
3.110 + fi
3.111 + for dir in . usr ..; do
3.112 + ${CT_ECHO} -n " trying in \"${dir}\""
3.113 + tgt_dir="${dir}"
3.114 + [ "${tgt_dir}" = ".." ] && tgt_dir="usr"
3.115 + libfile="${CT_SYSROOT_DIR}/${dir}/lib/${libname}"
3.116 + ${CT_ECHO} ": \"${libfile}\""
3.117 + if [ -e "${libfile}" ]; then
3.118 + mkdir -p "${CT_ROOT_DST_DIR}/${dir}/lib"
3.119 + ${CT_ECHO} " installing \"${tgt_dir}/lib/${libname}\""
3.120 + cp "${libfile}" "${CT_ROOT_DST_DIR}/${tgt_dir}/lib/${libname}"
3.121 + still_needed=1
3.122 + break
3.123 + fi
3.124 + done
3.125 + done
3.126 + done
3.127 +done