1.1 --- a/tools/populate.in Thu Aug 07 22:34:32 2008 +0000
1.2 +++ b/tools/populate.in Mon Nov 24 12:13:36 2008 +0000
1.3 @@ -13,29 +13,62 @@
1.4
1.5 doHelp() {
1.6 cat <<_EOF_
1.7 -$myname [-f] [-v] -s source_root -d destination_root
1.8 +NAME
1.9 + $myname - populate the target root file system
1.10
1.11 - -s dir
1.12 - use 'dir' as the un-populated (source) root directory
1.13 +SYNOPSIS
1.14 + $myname OPTIONS -s source_root -d destination_root
1.15
1.16 - -d dir
1.17 - use 'dir' as the place to put the populated root directory
1.18 +DESCRIPTION
1.19 + $myname will 'populate' your target root file system ('src_dir') with
1.20 + libraries from the toolchain (eg. libc.so...), storing the result into
1.21 + 'dst_dir'.
1.22
1.23 - -f force execution: if destination directory already exists,
1.24 - it will be removed first.
1.25 +OPTIONS
1.26 + -s src_dir
1.27 + use 'src_dir' as the un-populated (source) root directory
1.28 +
1.29 + -d dst_dir
1.30 + use 'dst_dir' as the place to put the populated root directory
1.31 +
1.32 + -l name1[:name2[...]]
1.33 + Always add the specified shared library/ies name1, name2... from the
1.34 + toolchain (in the sys-root). Actual library names are searched as
1.35 + follows (where 'name' is replaced with the given name) in the
1.36 + sys-root directory:
1.37 + - libname.so
1.38 + - name.so
1.39 + - name
1.40 + If the file is found, then the SONAME of the library is used, and the
1.41 + library is copied with that name. If the library was not found, this
1.42 + yields an error (unless -f was given).
1.43 +
1.44 + -L file
1.45 + Read 'file' for a list of shared libraries to always add from the
1.46 + toolchain. The file should contain one library name per line; text
1.47 + after a # is ignored until the end of the line; spaces are ignored;
1.48 + empty lines are ignored. Libraries are searched for as with -l.
1.49 +
1.50 + -f force execution: if destination directory already exists, it will be
1.51 + removed first; if a specified library (above) was not found, continue.
1.52
1.53 -v Be verbose
1.54 +
1.55 _EOF_
1.56 }
1.57
1.58 CT_ROOT_SRC_DIR=
1.59 CT_ROOT_DST_DIR=
1.60 +CT_LIB_LIST=
1.61 +CT_LIB_FILE=
1.62 CT_FORCE=no
1.63 CT_ECHO=true
1.64 -while getopts ":s:d:fvh" CT_OPT; do
1.65 +while getopts ":s:d:l:L:fvh" CT_OPT; do
1.66 case "${CT_OPT}" in
1.67 s) CT_ROOT_SRC_DIR="${OPTARG}";;
1.68 d) CT_ROOT_DST_DIR="${OPTARG}";;
1.69 + l) CT_LIB_LIST="${CT_LIB_LIST}:${OPTARG}";;
1.70 + L) CT_LIB_FILE="${OPTARG}";;
1.71 f) CT_FORCE=y;;
1.72 v) CT_ECHO=echo;;
1.73 h) doHelp
1.74 @@ -70,6 +103,12 @@
1.75 exit 1
1.76 fi
1.77
1.78 +# Check existence of the forced libraries file
1.79 +if [ -n "${CT_LIB_FILE}" -a ! \( -f "${CT_LIB_FILE}" -a -r "${CT_LIB_FILE}" \) ]; then
1.80 + echo "$myname: forced libraries file '${CT_LIB_FILE}' not found!"
1.81 + exit 1
1.82 +fi
1.83 +
1.84 # Get rid of potentially older destination directory
1.85 if [ -d "${CT_ROOT_DST_DIR}" ]; then
1.86 mv "${CT_ROOT_DST_DIR}" "${CT_ROOT_DST_DIR}.$$"
1.87 @@ -83,11 +122,60 @@
1.88 CT_ROOT_SRC_DIR=$(cd "${CT_ROOT_SRC_DIR}"; pwd)
1.89 CT_ROOT_DST_DIR=$(cd "${CT_ROOT_DST_DIR}"; pwd)
1.90
1.91 -cd "${CT_ROOT_SRC_DIR}"
1.92 +pushd "${CT_ROOT_SRC_DIR}" >/dev/null
1.93 tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -)
1.94 +popd >/dev/null
1.95 +
1.96 +# A function do search for a library
1.97 +# Usage: do_add_lib libname
1.98 +# returns: 0 if library was found and added, !0 otherwise
1.99 +do_add_lib() {
1.100 + local libname="$1"
1.101 + local ret=1
1.102 + local true_libname
1.103 + for dir in . usr; do
1.104 + ${CT_ECHO} -n " trying in '${dir}'"
1.105 + libfile="${CT_SYSROOT_DIR}/${dir}/lib/${libname}"
1.106 + ${CT_ECHO} ": '${libfile}'"
1.107 + if [ -e "${libfile}" ]; then
1.108 + mkdir -p "${dir}/lib"
1.109 + true_libname=$("${CT_READELF}" -d "${libfile}" |egrep "SONAME" |sed -r -e 's,.+\[(.+)\] *$,\1,;')
1.110 + ${CT_ECHO} " installing as '${dir}/lib/${true_libname}'"
1.111 + cat "${libfile}" >"${dir}/lib/${true_libname}"
1.112 + ret=0
1.113 + break
1.114 + fi
1.115 + done
1.116 + return ${ret}
1.117 +}
1.118 +
1.119 +# First of, copy the forced libraries into the working copy
1.120 +if [ -n "${CT_LIB_FILE}" ]; then
1.121 + lib_list=$(sed -r -e ':loop; s/#.*//; s/[[:space:]]+//g; s/([^:])$/\1:/; /$/N; s/\n//; tloop;' "${CT_LIB_FILE}")
1.122 + CT_LIB_LIST=$(echo "${CT_LIB_LIST}:${lib_list}" |sed -r -e 's/:+/:/g; s/^:+//; s/:+$//;')
1.123 +fi
1.124 +CT_LIB_LIST="${CT_LIB_LIST//:/ }"
1.125 +${CT_ECHO} "Installing forced libraries..."
1.126 +pushd "${CT_ROOT_DST_DIR}" >/dev/null
1.127 +for name in ${CT_LIB_LIST}; do
1.128 + [ -z "${name}" ] && continue
1.129 + found=0
1.130 + for libname in "lib${name}.so" "${name}.so" "${name}"; do
1.131 + ${CT_ECHO} " searching for '${libname}'"
1.132 + if do_add_lib "${libname}"; then
1.133 + found=1
1.134 + break
1.135 + fi
1.136 + done
1.137 + if [ ${found} -eq 0 ]; then
1.138 + echo "$myname: library '${libname}' not found!"
1.139 + [ "${CT_FORCE}" = y ] || exit 1
1.140 + fi
1.141 +done
1.142 +popd >/dev/null
1.143
1.144 # Parse the working copy for executables and libraries
1.145 -cd "${CT_ROOT_DST_DIR}"
1.146 +pushd "${CT_ROOT_DST_DIR}" >/dev/null
1.147 still_needed=1
1.148 while [ ${still_needed} -eq 1 ]; do
1.149 ${CT_ECHO} "Looping..."
1.150 @@ -101,18 +189,12 @@
1.151 ${CT_ECHO} " already present"
1.152 continue
1.153 fi
1.154 - for dir in . usr; do
1.155 - ${CT_ECHO} -n " trying in '${dir}'"
1.156 - libfile="${CT_SYSROOT_DIR}/${dir}/lib/${libname}"
1.157 - ${CT_ECHO} ": '${libfile}'"
1.158 - if [ -e "${libfile}" ]; then
1.159 - mkdir -p "${dir}/lib"
1.160 - ${CT_ECHO} " installing '${dir}/lib/${libname}'"
1.161 - cp "${libfile}" "${dir}/lib/${libname}"
1.162 - still_needed=1
1.163 - break
1.164 - fi
1.165 - done
1.166 + if do_add_lib "${libname}"; then
1.167 + still_needed=1
1.168 + else
1.169 + echo "$myname: library '${libname}' not found!"
1.170 + fi
1.171 done
1.172 done
1.173 done
1.174 +popd >/dev/null