From c564be2675573300f84fe59b179ad1a870453925 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN\"" Date: Thu, 11 Jun 2009 21:47:19 +0000 Subject: populate: fix installing dynamic linker 'ld.so' The dynamic linker, ld.so, needs the execute bit to be set. Detect tht the library being installed is in fact ld.so and install it with 0755 instead of 0644. Fix detecting src == dst. Use a simpler command to copy src -> dst. Also change echo to printf, get rid of 'echo -n', which is highly non-portable. -------- diffstat follows -------- /trunk/scripts/populate.in | 76 43 33 0 +++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/scripts/populate.in b/scripts/populate.in index e8a3718..9bb5afb 100644 --- a/scripts/populate.in +++ b/scripts/populate.in @@ -13,7 +13,7 @@ CT_SYSROOT_DIR="$(cd "${CT_BIN_DIR}/../@@CT_TARGET@@/sys-root"; pwd)" myname=$(basename "$0") -# Use the tols discovered by crosstool-NG's ./configure: +# Use the tools discovered by crosstool-NG's ./configure: install="@@CT_install@@" grep="@@CT_grep@@" sed="@@CT_sed@@" @@ -59,7 +59,7 @@ OPTIONS -f force execution: if destination directory already exists, it will be removed first; if a specified library (above) was not found, continue. - -v Be verbose + -v Be verbose. By default, populate is absolutely silent. _EOF_ } @@ -69,7 +69,7 @@ CT_ROOT_DST_DIR= CT_LIB_LIST= CT_LIB_FILE= CT_FORCE=no -CT_ECHO=true +CT_PRINTF=: OPTIND=1 while getopts ":s:d:l:L:fvh" CT_OPT; do case "${CT_OPT}" in @@ -78,7 +78,7 @@ while getopts ":s:d:l:L:fvh" CT_OPT; do l) CT_LIB_LIST="${CT_LIB_LIST}:${OPTARG}";; L) CT_LIB_FILE="${OPTARG}";; f) CT_FORCE=y;; - v) CT_ECHO=echo;; + v) CT_PRINTF=printf;; h) doHelp exit 0 ;; @@ -104,9 +104,9 @@ if [ -d "${CT_ROOT_DST_DIR}" -a "${CT_FORCE}" != "y" ]; then echo "$myname: '${CT_ROOT_DST_DIR}': already exists" exit 1 fi -src_inode=$(ls -di "${CT_ROOT_SRC_DIR}") -dst_inode=$(ls -di "${CT_ROOT_DST_DIR}" 2>/dev/null) -if [ "${src_inode}" = "${dst_inode}" ]; then +src_inode=$(stat -c '%i' "${CT_ROOT_SRC_DIR}/.") +dst_inode=$(stat -c '%i' "${CT_ROOT_DST_DIR}/." 2>/dev/null || true) +if [ "${src_inode}" -eq "$((dst_inode+0))" ]; then echo "$myname: source and destination are the same!" exit 1 fi @@ -129,7 +129,7 @@ CT_ROOT_DST_DIR=$(cd "${CT_ROOT_DST_DIR}"; pwd) # Populate the destination directory with files form the source directory pushd "${CT_ROOT_SRC_DIR}" >/dev/null -tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -) +tar cf - . |tar xf - -C "${CT_ROOT_DST_DIR}" popd >/dev/null # A function do search for a library @@ -139,18 +139,24 @@ do_add_lib() { local libname="$1" local true_libname local dir + local mode + for dir in lib usr/lib; do - ${CT_ECHO} -n " trying in '${dir}'" + ${CT_PRINTF} " trying in '%s'" "${dir}" libfile="${CT_SYSROOT_DIR}/${dir}/${libname}" - ${CT_ECHO} ": '${libfile}'" + ${CT_PRINTF} ": '%s'\n" "${libfile}" if [ -e "${libfile}" ]; then mkdir -p "${dir}" true_libname=$("${CT_READELF}" -d "${libfile}" \ |"${grep}" "Library soname:" \ |"${sed}" -r -e 's,.+\[(.+)\] *$,\1,;' \ ) - ${CT_ECHO} " installing as '${dir}/${true_libname}'" - "${install}" -m 0644 "${libfile}" "${dir}/${true_libname}" + case "${libfile}" in + */ld*) mode=0755;; + *) mode=0644;; + esac + ${CT_PRINTF} " installing as '%s/%s', mode='%s'\n" "${dir}" "${true_libname}" "${mode}" + "${install}" -m "${mode}" "${libfile}" "${dir}/${true_libname}" return 0 break fi @@ -158,6 +164,9 @@ do_add_lib() { return 1 } +# We'll work in the copied rootfs +pushd "${CT_ROOT_DST_DIR}" >/dev/null + # First of, copy the forced libraries into the working copy if [ -n "${CT_LIB_FILE}" ]; then lib_list=$("${sed}" -r -e ':loop; s/#.*//;' \ @@ -173,44 +182,43 @@ fi CT_LIB_LIST=$(echo "${CT_LIB_LIST}:${lib_list}" \ |"${sed}" -r -e 's/^:+//; s/:+$//; s/:+/ /g;' \ ) -${CT_ECHO} "Installing forced libraries..." -pushd "${CT_ROOT_DST_DIR}" >/dev/null -for name in ${CT_LIB_LIST}; do - [ -z "${name}" ] && continue - found=0 - for libname in "lib${name}.so" "${name}.so" "${name}"; do - ${CT_ECHO} " searching for '${libname}'" - if do_add_lib "${libname}"; then - found=1 - break +if [ -n "${CT_LIB_LIST}" ]; then + ${CT_PRINTF} "Installing forced libraries...\n" + for name in ${CT_LIB_LIST}; do + [ -z "${name}" ] && continue + found=0 + for libname in "lib${name}.so" "${name}.so" "${name}"; do + ${CT_PRINTF} " searching for '%s'\n" "${libname}" + if do_add_lib "${libname}"; then + found=1 + break + fi + done + if [ ${found} -eq 0 ]; then + echo "$myname: library '${libname}' not found!" + [ "${CT_FORCE}" = y ] || exit 1 fi done - if [ ${found} -eq 0 ]; then - echo "$myname: library '${libname}' not found!" - [ "${CT_FORCE}" = y ] || exit 1 - fi -done -popd >/dev/null +fi # Parse the working copy for executables and libraries -pushd "${CT_ROOT_DST_DIR}" >/dev/null still_needed=1 while [ ${still_needed} -eq 1 ]; do - ${CT_ECHO} "Looping..." + ${CT_PRINTF} "Looping...\n" still_needed=0 for f in $(find . -type f -exec file {} \; \ |"${grep}" -E ': ELF [[:digit:]]+-bit (L|M)SB (executable|shared object),' \ |cut -d ":" -f 1 \ ); do - ${CT_ECHO} "Scanning '${f}'" + ${CT_PRINTF} "Scanning '%s'\n" "${f}" for libname in $("${CT_READELF}" -d "${f}" \ |"${grep}" -E '\(NEEDED\)[[:space:]]+Shared library:' \ |"${sed}" -r -e 's,.+\[(.+)\] *$,\1,;' \ ); do - ${CT_ECHO} " searching for '${libname}'" + ${CT_PRINTF} " searching for '%s'\n" "${libname}" if [ -e "lib/${libname}" \ -o -e "usr/lib/${libname}" ]; then - ${CT_ECHO} " already present" + ${CT_PRINTF} " already present\n" continue fi if do_add_lib "${libname}"; then @@ -221,4 +229,6 @@ while [ ${still_needed} -eq 1 ]; do done done done + +# OK, we're done. Back off. popd >/dev/null -- cgit v0.10.2-6-g49f6