diff options
Diffstat (limited to 'hook-functions')
-rw-r--r-- | hook-functions | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/hook-functions b/hook-functions index 12faeff..6c75b5f 100644 --- a/hook-functions +++ b/hook-functions @@ -55,24 +55,55 @@ manual_add_modules() done } -# $1 is source -# $2 is relative destination +# $1 is the source path (e.g. /usr/bin/time) +# $2 is the relative destination (e.g. /usr or /usr/time) +# +# The destination is interpreted in the same way "cp" would, meaning +# (assuming /bin is a directory): +# +# "copy_exec /usr/bin/time /bin" -> /bin/time +# "copy_exec /usr/bin/time /bin/mytime" -> /bin/mytime +# +# If $2 is left out, the same destination path as for the source arg will +# be used and directories will be created as needed, so: +# +# "copy_exec /usr/bin/time" -> /usr/bin/time +# copy_exec() { - final_destination=${DESTDIR}/${2}/`basename ${1}` + local source target destination final_destination x nonoptlib + local libname dirname + + source="${1}" + if [ -n "${2}" ]; then + target="${2}" + else + if [ ! -e "${DESTDIR}/$(dirname "${1}")" ]; then + mkdir -p "${DESTDIR}/$(dirname "${1}")" + fi + target="${1}" + fi + + if [ -d "${DESTDIR}/${target}" ]; then + destination="${target}/$(basename "${source}")" + else + destination="${target}" + fi + final_destination="${DESTDIR}/${destination}" + if [ -L "$final_destination" ]; then - if ! [ `readlink ${final_destination}` = "${1}" ]; then - echo "W:copy_exec: Not copying ${1} to \$DESTDIR${2}/`basename ${1}`, which is already a copy of `readlink ${final_destination}`" >&2 + if [ $(readlink "${final_destination}") != "${source}" ]; then + echo "W:copy_exec: Not copying ${source} to \$DESTDIR${destination}, which is already a copy of $(readlink ${final_destination})" >&2 return fi else - ln -s ${1} ${DESTDIR}/${2} - if [ -n "${verbose}" ] && [ "${verbose}" = "y" ]; then - echo "Adding binary ${1}" + ln -s ${source} ${DESTDIR}/${destination} + if [ "${verbose}" = "y" ]; then + echo "Adding binary ${source}" fi fi # Copy the dependant libraries - for x in $(ldd ${1} 2>/dev/null | sed -e ' + for x in $(ldd ${source} 2>/dev/null | sed -e ' /\//!d; /linux-gate/d; /=>/ {s/.*=>[[:blank:]]*\([^[:blank:]]*\).*/\1/}; @@ -80,19 +111,19 @@ copy_exec() { # Try to use non-optimised libraries where possible. # We assume that all HWCAP libraries will be in tls. - nonoptlib=$(echo ${x} | sed -e 's#/lib/tls.*/\(lib.*\)#/lib/\1#') + nonoptlib=$(echo "${x}" | sed -e 's#/lib/tls.*/\(lib.*\)#/lib/\1#') - if [ -e ${nonoptlib} ]; then - x=${nonoptlib} + if [ -e "${nonoptlib}" ]; then + x="${nonoptlib}" fi - libname=$(basename ${x}) - dirname=$(dirname ${x}) + libname=$(basename "${x}") + dirname=$(dirname "${x}") - mkdir -p ${DESTDIR}/${dirname} - if [ ! -e ${DESTDIR}/${dirname}/${libname} ]; then - ln -s ${x} ${DESTDIR}/${dirname} - if [ -n "${verbose}" ] && [ "${verbose}" = "y" ]; then + mkdir -p "${DESTDIR}/${dirname}" + if [ ! -e "${DESTDIR}/${dirname}/${libname}" ]; then + ln -s "${x}" "${DESTDIR}/${dirname}" + if [ "${verbose}" = "y" ]; then echo "Adding library ${x}" fi fi |