populate: fix installing dynamic linker 'ld.so' 1.4
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Jun 11 21:47:19 2009 +0000 (2009-06-11)
branch1.4
changeset 145125d050084e98
parent 1450 0505b0d5cd63
child 1452 0c021c8900cc
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(-)
(transplanted from d7ddcb75e0f703e2ba6d17169167356389224870)
scripts/populate.in
     1.1 --- a/scripts/populate.in	Mon Aug 03 22:47:53 2009 +0200
     1.2 +++ b/scripts/populate.in	Thu Jun 11 21:47:19 2009 +0000
     1.3 @@ -13,7 +13,7 @@
     1.4  
     1.5  myname=$(basename "$0")
     1.6  
     1.7 -# Use the tols discovered by crosstool-NG's ./configure:
     1.8 +# Use the tools discovered by crosstool-NG's ./configure:
     1.9  install="@@CT_install@@"
    1.10  grep="@@CT_grep@@"
    1.11  sed="@@CT_sed@@"
    1.12 @@ -59,7 +59,7 @@
    1.13      -f  force execution: if destination directory already exists, it will be
    1.14          removed first; if a specified library (above) was not found, continue.
    1.15  
    1.16 -    -v  Be verbose
    1.17 +    -v  Be verbose. By default, populate is absolutely silent.
    1.18  
    1.19  _EOF_
    1.20  }
    1.21 @@ -69,7 +69,7 @@
    1.22  CT_LIB_LIST=
    1.23  CT_LIB_FILE=
    1.24  CT_FORCE=no
    1.25 -CT_ECHO=true
    1.26 +CT_PRINTF=:
    1.27  OPTIND=1
    1.28  while getopts ":s:d:l:L:fvh" CT_OPT; do
    1.29      case "${CT_OPT}" in
    1.30 @@ -78,7 +78,7 @@
    1.31          l)  CT_LIB_LIST="${CT_LIB_LIST}:${OPTARG}";;
    1.32          L)  CT_LIB_FILE="${OPTARG}";;
    1.33          f)  CT_FORCE=y;;
    1.34 -        v)  CT_ECHO=echo;;
    1.35 +        v)  CT_PRINTF=printf;;
    1.36          h)  doHelp
    1.37              exit 0
    1.38              ;;
    1.39 @@ -104,9 +104,9 @@
    1.40      echo "$myname: '${CT_ROOT_DST_DIR}': already exists"
    1.41      exit 1
    1.42  fi
    1.43 -src_inode=$(ls -di "${CT_ROOT_SRC_DIR}")
    1.44 -dst_inode=$(ls -di "${CT_ROOT_DST_DIR}" 2>/dev/null)
    1.45 -if [ "${src_inode}" = "${dst_inode}" ]; then
    1.46 +src_inode=$(stat -c '%i' "${CT_ROOT_SRC_DIR}/.")
    1.47 +dst_inode=$(stat -c '%i' "${CT_ROOT_DST_DIR}/." 2>/dev/null || true)
    1.48 +if [ "${src_inode}" -eq "$((dst_inode+0))" ]; then
    1.49      echo "$myname: source and destination are the same!"
    1.50      exit 1
    1.51  fi
    1.52 @@ -129,7 +129,7 @@
    1.53  
    1.54  # Populate the destination directory with files form the source directory
    1.55  pushd "${CT_ROOT_SRC_DIR}" >/dev/null
    1.56 -tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -)
    1.57 +tar cf - . |tar xf - -C "${CT_ROOT_DST_DIR}"
    1.58  popd >/dev/null
    1.59  
    1.60  # A function do search for a library
    1.61 @@ -139,18 +139,24 @@
    1.62      local libname="$1"
    1.63      local true_libname
    1.64      local dir
    1.65 +    local mode
    1.66 +
    1.67      for dir in lib usr/lib; do
    1.68 -        ${CT_ECHO} -n "    trying in '${dir}'"
    1.69 +        ${CT_PRINTF} "    trying in '%s'" "${dir}"
    1.70          libfile="${CT_SYSROOT_DIR}/${dir}/${libname}"
    1.71 -        ${CT_ECHO} ": '${libfile}'"
    1.72 +        ${CT_PRINTF} ": '%s'\n" "${libfile}"
    1.73          if [ -e "${libfile}" ]; then
    1.74              mkdir -p "${dir}"
    1.75              true_libname=$("${CT_READELF}" -d "${libfile}"          \
    1.76                             |"${grep}" "Library soname:"             \
    1.77                             |"${sed}" -r -e 's,.+\[(.+)\] *$,\1,;'   \
    1.78                            )
    1.79 -            ${CT_ECHO} "      installing as '${dir}/${true_libname}'"
    1.80 -            "${install}" -m 0644 "${libfile}" "${dir}/${true_libname}"
    1.81 +            case "${libfile}" in
    1.82 +                */ld*)  mode=0755;;
    1.83 +                *)      mode=0644;;
    1.84 +            esac
    1.85 +            ${CT_PRINTF} "      installing as '%s/%s', mode='%s'\n" "${dir}" "${true_libname}" "${mode}"
    1.86 +            "${install}" -m "${mode}" "${libfile}" "${dir}/${true_libname}"
    1.87              return 0
    1.88              break
    1.89          fi
    1.90 @@ -158,6 +164,9 @@
    1.91      return 1
    1.92  }
    1.93  
    1.94 +# We'll work in the copied rootfs
    1.95 +pushd "${CT_ROOT_DST_DIR}" >/dev/null
    1.96 +
    1.97  # First of, copy the forced libraries into the working copy
    1.98  if [ -n "${CT_LIB_FILE}" ]; then
    1.99      lib_list=$("${sed}" -r -e ':loop; s/#.*//;'         \
   1.100 @@ -173,44 +182,43 @@
   1.101  CT_LIB_LIST=$(echo "${CT_LIB_LIST}:${lib_list}"             \
   1.102                |"${sed}" -r -e 's/^:+//; s/:+$//; s/:+/ /g;' \
   1.103               )
   1.104 -${CT_ECHO} "Installing forced libraries..."
   1.105 -pushd "${CT_ROOT_DST_DIR}" >/dev/null
   1.106 -for name in ${CT_LIB_LIST}; do
   1.107 -    [ -z "${name}" ] && continue
   1.108 -    found=0
   1.109 -    for libname in "lib${name}.so" "${name}.so" "${name}"; do
   1.110 -        ${CT_ECHO} "  searching for '${libname}'"
   1.111 -        if do_add_lib "${libname}"; then
   1.112 -            found=1
   1.113 -            break
   1.114 +if [ -n "${CT_LIB_LIST}" ]; then
   1.115 +    ${CT_PRINTF} "Installing forced libraries...\n"
   1.116 +    for name in ${CT_LIB_LIST}; do
   1.117 +        [ -z "${name}" ] && continue
   1.118 +        found=0
   1.119 +        for libname in "lib${name}.so" "${name}.so" "${name}"; do
   1.120 +            ${CT_PRINTF} "  searching for '%s'\n" "${libname}"
   1.121 +            if do_add_lib "${libname}"; then
   1.122 +                found=1
   1.123 +                break
   1.124 +            fi
   1.125 +        done
   1.126 +        if [ ${found} -eq 0 ]; then
   1.127 +            echo "$myname: library '${libname}' not found!"
   1.128 +            [ "${CT_FORCE}" = y ] || exit 1
   1.129          fi
   1.130      done
   1.131 -    if [ ${found} -eq 0 ]; then
   1.132 -        echo "$myname: library '${libname}' not found!"
   1.133 -        [ "${CT_FORCE}" = y ] || exit 1
   1.134 -    fi
   1.135 -done
   1.136 -popd >/dev/null
   1.137 +fi
   1.138  
   1.139  # Parse the working copy for executables and libraries
   1.140 -pushd "${CT_ROOT_DST_DIR}" >/dev/null
   1.141  still_needed=1
   1.142  while [ ${still_needed} -eq 1 ]; do
   1.143 -    ${CT_ECHO} "Looping..."
   1.144 +    ${CT_PRINTF} "Looping...\n"
   1.145      still_needed=0
   1.146      for f in $(find . -type f -exec file {} \;                                              \
   1.147                 |"${grep}" -E ': ELF [[:digit:]]+-bit (L|M)SB (executable|shared object),'   \
   1.148                 |cut -d ":" -f 1                                                             \
   1.149                ); do
   1.150 -        ${CT_ECHO} "Scanning '${f}'"
   1.151 +        ${CT_PRINTF} "Scanning '%s'\n" "${f}"
   1.152          for libname in $("${CT_READELF}" -d "${f}"                              \
   1.153                           |"${grep}" -E '\(NEEDED\)[[:space:]]+Shared library:'  \
   1.154                           |"${sed}" -r -e 's,.+\[(.+)\] *$,\1,;'                 \
   1.155                          ); do
   1.156 -            ${CT_ECHO} "  searching for '${libname}'"
   1.157 +            ${CT_PRINTF} "  searching for '%s'\n" "${libname}"
   1.158              if [    -e "lib/${libname}"     \
   1.159                   -o -e "usr/lib/${libname}" ]; then
   1.160 -                ${CT_ECHO} "    already present"
   1.161 +                ${CT_PRINTF} "    already present\n"
   1.162                  continue
   1.163              fi
   1.164              if do_add_lib "${libname}"; then
   1.165 @@ -221,4 +229,6 @@
   1.166          done
   1.167      done
   1.168  done
   1.169 +
   1.170 +# OK, we're done. Back off.
   1.171  popd >/dev/null