1.1 --- a/scripts/crosstool.sh Thu Dec 11 18:15:41 2008 +0000
1.2 +++ b/scripts/crosstool.sh Thu Dec 11 18:16:54 2008 +0000
1.3 @@ -492,7 +492,7 @@
1.4 if [ "${CT_BARE_METAL}" != "y" ]; then
1.5 CT_DoLog EXTRA "Installing the populate helper"
1.6 sed -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \
1.7 - "${CT_LIB_DIR}/tools/populate.in" \
1.8 + "${CT_LIB_DIR}/scripts/populate.in" \
1.9 >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
1.10 chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
1.11 fi
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/scripts/populate.in Thu Dec 11 18:16:54 2008 +0000
2.3 @@ -0,0 +1,200 @@
2.4 +#!/bin/bash
2.5 +
2.6 +# This script will populate the root directory with libs from the sysroot.
2.7 +# (C) 2007 Yann E. MORIN
2.8 +# Licensed under the GPL v2
2.9 +
2.10 +# Detect where the toolchain is:
2.11 +BIN_DIR="$(cd "$(dirname "$0")"; pwd)"
2.12 +CT_READELF="${BIN_DIR}/@@CT_TARGET@@-readelf"
2.13 +CT_SYSROOT_DIR="${BIN_DIR}/../@@CT_TARGET@@/sys-root"
2.14 +
2.15 +myname=$(basename "$0")
2.16 +
2.17 +doHelp() {
2.18 + cat <<_EOF_
2.19 +NAME
2.20 + $myname - populate the target root file system
2.21 +
2.22 +SYNOPSIS
2.23 + $myname OPTIONS -s source_root -d destination_root
2.24 +
2.25 +DESCRIPTION
2.26 + $myname will 'populate' your target root file system ('src_dir') with
2.27 + libraries from the toolchain (eg. libc.so...), storing the result into
2.28 + 'dst_dir'.
2.29 +
2.30 +OPTIONS
2.31 + -s src_dir
2.32 + use 'src_dir' as the un-populated (source) root directory
2.33 +
2.34 + -d dst_dir
2.35 + use 'dst_dir' as the place to put the populated root directory
2.36 +
2.37 + -l name1[:name2[...]]
2.38 + Always add the specified shared library/ies name1, name2... from the
2.39 + toolchain (in the sys-root). Actual library names are searched as
2.40 + follows (where 'name' is replaced with the given name) in the
2.41 + sys-root directory:
2.42 + - libname.so
2.43 + - name.so
2.44 + - name
2.45 + If the file is found, then the SONAME of the library is used, and the
2.46 + library is copied with that name. If the library was not found, this
2.47 + yields an error (unless -f was given).
2.48 +
2.49 + -L file
2.50 + Read 'file' for a list of shared libraries to always add from the
2.51 + toolchain. The file should contain one library name per line; text
2.52 + after a # is ignored until the end of the line; spaces are ignored;
2.53 + empty lines are ignored. Libraries are searched for as with -l.
2.54 +
2.55 + -f force execution: if destination directory already exists, it will be
2.56 + removed first; if a specified library (above) was not found, continue.
2.57 +
2.58 + -v Be verbose
2.59 +
2.60 +_EOF_
2.61 +}
2.62 +
2.63 +CT_ROOT_SRC_DIR=
2.64 +CT_ROOT_DST_DIR=
2.65 +CT_LIB_LIST=
2.66 +CT_LIB_FILE=
2.67 +CT_FORCE=no
2.68 +CT_ECHO=true
2.69 +while getopts ":s:d:l:L:fvh" CT_OPT; do
2.70 + case "${CT_OPT}" in
2.71 + s) CT_ROOT_SRC_DIR="${OPTARG}";;
2.72 + d) CT_ROOT_DST_DIR="${OPTARG}";;
2.73 + l) CT_LIB_LIST="${CT_LIB_LIST}:${OPTARG}";;
2.74 + L) CT_LIB_FILE="${OPTARG}";;
2.75 + f) CT_FORCE=y;;
2.76 + v) CT_ECHO=echo;;
2.77 + h) doHelp
2.78 + exit 0
2.79 + ;;
2.80 + :) echo "$myname: '-${OPTARG}' takes exactly one argument."
2.81 + exit 1
2.82 + ;;
2.83 + ?) echo "$myname: unknown option '-${OPTARG}'."
2.84 + exit 1
2.85 + ;;
2.86 + esac
2.87 +done
2.88 +
2.89 +# Sanity checks
2.90 +if [ -z "${CT_ROOT_SRC_DIR}" -o -z "${CT_ROOT_DST_DIR}" ]; then
2.91 + doHelp
2.92 + exit 1
2.93 +fi
2.94 +if [ ! -d "${CT_ROOT_SRC_DIR}" ]; then
2.95 + echo "$myname: '${CT_ROOT_SRC_DIR}': no such file or directory"
2.96 + exit 1
2.97 +fi
2.98 +if [ -d "${CT_ROOT_DST_DIR}" -a "${CT_FORCE}" != "y" ]; then
2.99 + echo "$myname: '${CT_ROOT_DST_DIR}': already exists"
2.100 + exit 1
2.101 +fi
2.102 +src_inode=$(ls -di "${CT_ROOT_SRC_DIR}")
2.103 +dst_inode=$(ls -di "${CT_ROOT_DST_DIR}" 2>/dev/null)
2.104 +if [ "${src_inode}" = "${dst_inode}" ]; then
2.105 + echo "$myname: source and destination are the same!"
2.106 + exit 1
2.107 +fi
2.108 +
2.109 +# Check existence of the forced libraries file
2.110 +if [ -n "${CT_LIB_FILE}" -a ! \( -f "${CT_LIB_FILE}" -a -r "${CT_LIB_FILE}" \) ]; then
2.111 + echo "$myname: forced libraries file '${CT_LIB_FILE}' not found!"
2.112 + exit 1
2.113 +fi
2.114 +
2.115 +# Get rid of potentially older destination directory
2.116 +if [ -d "${CT_ROOT_DST_DIR}" ]; then
2.117 + mv "${CT_ROOT_DST_DIR}" "${CT_ROOT_DST_DIR}.$$"
2.118 + setsid nohup rm -rf "${CT_ROOT_DST_DIR}.$$" >/dev/null 2>&1 &
2.119 +fi
2.120 +
2.121 +# Create the working copy
2.122 +mkdir -p "${CT_ROOT_DST_DIR}"
2.123 +
2.124 +# Make all path absolute
2.125 +CT_ROOT_SRC_DIR=$(cd "${CT_ROOT_SRC_DIR}"; pwd)
2.126 +CT_ROOT_DST_DIR=$(cd "${CT_ROOT_DST_DIR}"; pwd)
2.127 +
2.128 +pushd "${CT_ROOT_SRC_DIR}" >/dev/null
2.129 +tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -)
2.130 +popd >/dev/null
2.131 +
2.132 +# A function do search for a library
2.133 +# Usage: do_add_lib libname
2.134 +# returns: 0 if library was found and added, !0 otherwise
2.135 +do_add_lib() {
2.136 + local libname="$1"
2.137 + local ret=1
2.138 + local true_libname
2.139 + for dir in . usr; do
2.140 + ${CT_ECHO} -n " trying in '${dir}'"
2.141 + libfile="${CT_SYSROOT_DIR}/${dir}/lib/${libname}"
2.142 + ${CT_ECHO} ": '${libfile}'"
2.143 + if [ -e "${libfile}" ]; then
2.144 + mkdir -p "${dir}/lib"
2.145 + true_libname=$("${CT_READELF}" -d "${libfile}" |egrep "SONAME" |sed -r -e 's,.+\[(.+)\] *$,\1,;')
2.146 + ${CT_ECHO} " installing as '${dir}/lib/${true_libname}'"
2.147 + cat "${libfile}" >"${dir}/lib/${true_libname}"
2.148 + ret=0
2.149 + break
2.150 + fi
2.151 + done
2.152 + return ${ret}
2.153 +}
2.154 +
2.155 +# First of, copy the forced libraries into the working copy
2.156 +if [ -n "${CT_LIB_FILE}" ]; then
2.157 + lib_list=$(sed -r -e ':loop; s/#.*//; s/[[:space:]]+//g; s/([^:])$/\1:/; /$/N; s/\n//; tloop;' "${CT_LIB_FILE}")
2.158 + CT_LIB_LIST=$(echo "${CT_LIB_LIST}:${lib_list}" |sed -r -e 's/:+/:/g; s/^:+//; s/:+$//;')
2.159 +fi
2.160 +CT_LIB_LIST="${CT_LIB_LIST//:/ }"
2.161 +${CT_ECHO} "Installing forced libraries..."
2.162 +pushd "${CT_ROOT_DST_DIR}" >/dev/null
2.163 +for name in ${CT_LIB_LIST}; do
2.164 + [ -z "${name}" ] && continue
2.165 + found=0
2.166 + for libname in "lib${name}.so" "${name}.so" "${name}"; do
2.167 + ${CT_ECHO} " searching for '${libname}'"
2.168 + if do_add_lib "${libname}"; then
2.169 + found=1
2.170 + break
2.171 + fi
2.172 + done
2.173 + if [ ${found} -eq 0 ]; then
2.174 + echo "$myname: library '${libname}' not found!"
2.175 + [ "${CT_FORCE}" = y ] || exit 1
2.176 + fi
2.177 +done
2.178 +popd >/dev/null
2.179 +
2.180 +# Parse the working copy for executables and libraries
2.181 +pushd "${CT_ROOT_DST_DIR}" >/dev/null
2.182 +still_needed=1
2.183 +while [ ${still_needed} -eq 1 ]; do
2.184 + ${CT_ECHO} "Looping..."
2.185 + still_needed=0
2.186 + for f in $(find . -type f -exec file {} \; |egrep ': ELF [[:digit:]]+-bit .SB (executable|shared object),' |cut -d ":" -f 1); do
2.187 + ${CT_ECHO} "Scanning '${f}'"
2.188 + for libname in $("${CT_READELF}" -d "${f}" |egrep '(NEEDED)' |sed -r -e 's,.+\[(.+)\] *$,\1,;'); do
2.189 + ${CT_ECHO} " searching for '${libname}'"
2.190 + if [ -e "lib/${libname}" \
2.191 + -o -e "usr/lib/${libname}" ]; then
2.192 + ${CT_ECHO} " already present"
2.193 + continue
2.194 + fi
2.195 + if do_add_lib "${libname}"; then
2.196 + still_needed=1
2.197 + else
2.198 + echo "$myname: library '${libname}' not found!"
2.199 + fi
2.200 + done
2.201 + done
2.202 +done
2.203 +popd >/dev/null
3.1 --- a/tools/populate.in Thu Dec 11 18:15:41 2008 +0000
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,200 +0,0 @@
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 -# Detect where the toolchain is:
3.11 -BIN_DIR="$(cd "$(dirname "$0")"; pwd)"
3.12 -CT_READELF="${BIN_DIR}/@@CT_TARGET@@-readelf"
3.13 -CT_SYSROOT_DIR="${BIN_DIR}/../@@CT_TARGET@@/sys-root"
3.14 -
3.15 -myname=$(basename "$0")
3.16 -
3.17 -doHelp() {
3.18 - cat <<_EOF_
3.19 -NAME
3.20 - $myname - populate the target root file system
3.21 -
3.22 -SYNOPSIS
3.23 - $myname OPTIONS -s source_root -d destination_root
3.24 -
3.25 -DESCRIPTION
3.26 - $myname will 'populate' your target root file system ('src_dir') with
3.27 - libraries from the toolchain (eg. libc.so...), storing the result into
3.28 - 'dst_dir'.
3.29 -
3.30 -OPTIONS
3.31 - -s src_dir
3.32 - use 'src_dir' as the un-populated (source) root directory
3.33 -
3.34 - -d dst_dir
3.35 - use 'dst_dir' as the place to put the populated root directory
3.36 -
3.37 - -l name1[:name2[...]]
3.38 - Always add the specified shared library/ies name1, name2... from the
3.39 - toolchain (in the sys-root). Actual library names are searched as
3.40 - follows (where 'name' is replaced with the given name) in the
3.41 - sys-root directory:
3.42 - - libname.so
3.43 - - name.so
3.44 - - name
3.45 - If the file is found, then the SONAME of the library is used, and the
3.46 - library is copied with that name. If the library was not found, this
3.47 - yields an error (unless -f was given).
3.48 -
3.49 - -L file
3.50 - Read 'file' for a list of shared libraries to always add from the
3.51 - toolchain. The file should contain one library name per line; text
3.52 - after a # is ignored until the end of the line; spaces are ignored;
3.53 - empty lines are ignored. Libraries are searched for as with -l.
3.54 -
3.55 - -f force execution: if destination directory already exists, it will be
3.56 - removed first; if a specified library (above) was not found, continue.
3.57 -
3.58 - -v Be verbose
3.59 -
3.60 -_EOF_
3.61 -}
3.62 -
3.63 -CT_ROOT_SRC_DIR=
3.64 -CT_ROOT_DST_DIR=
3.65 -CT_LIB_LIST=
3.66 -CT_LIB_FILE=
3.67 -CT_FORCE=no
3.68 -CT_ECHO=true
3.69 -while getopts ":s:d:l:L:fvh" CT_OPT; do
3.70 - case "${CT_OPT}" in
3.71 - s) CT_ROOT_SRC_DIR="${OPTARG}";;
3.72 - d) CT_ROOT_DST_DIR="${OPTARG}";;
3.73 - l) CT_LIB_LIST="${CT_LIB_LIST}:${OPTARG}";;
3.74 - L) CT_LIB_FILE="${OPTARG}";;
3.75 - f) CT_FORCE=y;;
3.76 - v) CT_ECHO=echo;;
3.77 - h) doHelp
3.78 - exit 0
3.79 - ;;
3.80 - :) echo "$myname: '-${OPTARG}' takes exactly one argument."
3.81 - exit 1
3.82 - ;;
3.83 - ?) echo "$myname: unknown option '-${OPTARG}'."
3.84 - exit 1
3.85 - ;;
3.86 - esac
3.87 -done
3.88 -
3.89 -# Sanity checks
3.90 -if [ -z "${CT_ROOT_SRC_DIR}" -o -z "${CT_ROOT_DST_DIR}" ]; then
3.91 - doHelp
3.92 - exit 1
3.93 -fi
3.94 -if [ ! -d "${CT_ROOT_SRC_DIR}" ]; then
3.95 - echo "$myname: '${CT_ROOT_SRC_DIR}': no such file or directory"
3.96 - exit 1
3.97 -fi
3.98 -if [ -d "${CT_ROOT_DST_DIR}" -a "${CT_FORCE}" != "y" ]; then
3.99 - echo "$myname: '${CT_ROOT_DST_DIR}': already exists"
3.100 - exit 1
3.101 -fi
3.102 -src_inode=$(ls -di "${CT_ROOT_SRC_DIR}")
3.103 -dst_inode=$(ls -di "${CT_ROOT_DST_DIR}" 2>/dev/null)
3.104 -if [ "${src_inode}" = "${dst_inode}" ]; then
3.105 - echo "$myname: source and destination are the same!"
3.106 - exit 1
3.107 -fi
3.108 -
3.109 -# Check existence of the forced libraries file
3.110 -if [ -n "${CT_LIB_FILE}" -a ! \( -f "${CT_LIB_FILE}" -a -r "${CT_LIB_FILE}" \) ]; then
3.111 - echo "$myname: forced libraries file '${CT_LIB_FILE}' not found!"
3.112 - exit 1
3.113 -fi
3.114 -
3.115 -# Get rid of potentially older destination directory
3.116 -if [ -d "${CT_ROOT_DST_DIR}" ]; then
3.117 - mv "${CT_ROOT_DST_DIR}" "${CT_ROOT_DST_DIR}.$$"
3.118 - setsid nohup rm -rf "${CT_ROOT_DST_DIR}.$$" >/dev/null 2>&1 &
3.119 -fi
3.120 -
3.121 -# Create the working copy
3.122 -mkdir -p "${CT_ROOT_DST_DIR}"
3.123 -
3.124 -# Make all path absolute
3.125 -CT_ROOT_SRC_DIR=$(cd "${CT_ROOT_SRC_DIR}"; pwd)
3.126 -CT_ROOT_DST_DIR=$(cd "${CT_ROOT_DST_DIR}"; pwd)
3.127 -
3.128 -pushd "${CT_ROOT_SRC_DIR}" >/dev/null
3.129 -tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -)
3.130 -popd >/dev/null
3.131 -
3.132 -# A function do search for a library
3.133 -# Usage: do_add_lib libname
3.134 -# returns: 0 if library was found and added, !0 otherwise
3.135 -do_add_lib() {
3.136 - local libname="$1"
3.137 - local ret=1
3.138 - local true_libname
3.139 - for dir in . usr; do
3.140 - ${CT_ECHO} -n " trying in '${dir}'"
3.141 - libfile="${CT_SYSROOT_DIR}/${dir}/lib/${libname}"
3.142 - ${CT_ECHO} ": '${libfile}'"
3.143 - if [ -e "${libfile}" ]; then
3.144 - mkdir -p "${dir}/lib"
3.145 - true_libname=$("${CT_READELF}" -d "${libfile}" |egrep "SONAME" |sed -r -e 's,.+\[(.+)\] *$,\1,;')
3.146 - ${CT_ECHO} " installing as '${dir}/lib/${true_libname}'"
3.147 - cat "${libfile}" >"${dir}/lib/${true_libname}"
3.148 - ret=0
3.149 - break
3.150 - fi
3.151 - done
3.152 - return ${ret}
3.153 -}
3.154 -
3.155 -# First of, copy the forced libraries into the working copy
3.156 -if [ -n "${CT_LIB_FILE}" ]; then
3.157 - lib_list=$(sed -r -e ':loop; s/#.*//; s/[[:space:]]+//g; s/([^:])$/\1:/; /$/N; s/\n//; tloop;' "${CT_LIB_FILE}")
3.158 - CT_LIB_LIST=$(echo "${CT_LIB_LIST}:${lib_list}" |sed -r -e 's/:+/:/g; s/^:+//; s/:+$//;')
3.159 -fi
3.160 -CT_LIB_LIST="${CT_LIB_LIST//:/ }"
3.161 -${CT_ECHO} "Installing forced libraries..."
3.162 -pushd "${CT_ROOT_DST_DIR}" >/dev/null
3.163 -for name in ${CT_LIB_LIST}; do
3.164 - [ -z "${name}" ] && continue
3.165 - found=0
3.166 - for libname in "lib${name}.so" "${name}.so" "${name}"; do
3.167 - ${CT_ECHO} " searching for '${libname}'"
3.168 - if do_add_lib "${libname}"; then
3.169 - found=1
3.170 - break
3.171 - fi
3.172 - done
3.173 - if [ ${found} -eq 0 ]; then
3.174 - echo "$myname: library '${libname}' not found!"
3.175 - [ "${CT_FORCE}" = y ] || exit 1
3.176 - fi
3.177 -done
3.178 -popd >/dev/null
3.179 -
3.180 -# Parse the working copy for executables and libraries
3.181 -pushd "${CT_ROOT_DST_DIR}" >/dev/null
3.182 -still_needed=1
3.183 -while [ ${still_needed} -eq 1 ]; do
3.184 - ${CT_ECHO} "Looping..."
3.185 - still_needed=0
3.186 - for f in $(find . -type f -exec file {} \; |egrep ': ELF [[:digit:]]+-bit .SB (executable|shared object),' |cut -d ":" -f 1); do
3.187 - ${CT_ECHO} "Scanning '${f}'"
3.188 - for libname in $("${CT_READELF}" -d "${f}" |egrep '(NEEDED)' |sed -r -e 's,.+\[(.+)\] *$,\1,;'); do
3.189 - ${CT_ECHO} " searching for '${libname}'"
3.190 - if [ -e "lib/${libname}" \
3.191 - -o -e "usr/lib/${libname}" ]; then
3.192 - ${CT_ECHO} " already present"
3.193 - continue
3.194 - fi
3.195 - if do_add_lib "${libname}"; then
3.196 - still_needed=1
3.197 - else
3.198 - echo "$myname: library '${libname}' not found!"
3.199 - fi
3.200 - done
3.201 - done
3.202 -done
3.203 -popd >/dev/null