# HG changeset patch # User "Yann E. MORIN" # Date 1244756839 0 # Node ID d7ddcb75e0f703e2ba6d17169167356389224870 # Parent 5244f852f60139a672b49c315dede914642ac097 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 -r 5244f852f601 -r d7ddcb75e0f7 scripts/populate.in --- a/scripts/populate.in Sun May 24 16:22:03 2009 +0000 +++ b/scripts/populate.in Thu Jun 11 21:47:19 2009 +0000 @@ -13,7 +13,7 @@ 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 @@ -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_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 @@ 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 @@ 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 @@ # 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 @@ 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 @@ 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 @@ 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 @@ done done done + +# OK, we're done. Back off. popd >/dev/null