2007-07-08 17:44:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This script will populate the root directory with libs from the sysroot.
|
|
|
|
# (C) 2007 Yann E. MORIN
|
|
|
|
# Licensed under the GPL v2
|
|
|
|
|
|
|
|
CT_READELF="@@CT_READELF@@"
|
|
|
|
CT_SYSROOT_DIR="@@CT_SYSROOT_DIR@@"
|
|
|
|
|
|
|
|
myname=$(basename "$0")
|
|
|
|
|
|
|
|
doHelp() {
|
|
|
|
cat <<_EOF_
|
2007-07-14 13:09:17 +00:00
|
|
|
$myname [-f] [-v] -s source_root -d destination_root
|
2007-07-08 17:44:59 +00:00
|
|
|
|
|
|
|
-s dir
|
|
|
|
use 'dir' as the un-populated (source) root directory
|
|
|
|
|
|
|
|
-d dir
|
|
|
|
use 'dir' as the place to put the populated root directory
|
|
|
|
|
2007-07-14 20:43:51 +00:00
|
|
|
-f force execution: if destination directory already exists,
|
|
|
|
it will be removed first.
|
|
|
|
|
2007-07-08 17:44:59 +00:00
|
|
|
-v Be verbose
|
|
|
|
_EOF_
|
|
|
|
}
|
|
|
|
|
|
|
|
CT_ROOT_SRC_DIR=
|
|
|
|
CT_ROOT_DST_DIR=
|
2007-07-14 21:21:55 +00:00
|
|
|
CT_FORCE=no
|
2007-07-08 17:44:59 +00:00
|
|
|
CT_ECHO=true
|
2007-07-14 21:21:55 +00:00
|
|
|
while getopts ":s:d:fvh" CT_OPT; do
|
2007-07-08 17:44:59 +00:00
|
|
|
case "${CT_OPT}" in
|
|
|
|
s) CT_ROOT_SRC_DIR="${OPTARG}";;
|
|
|
|
d) CT_ROOT_DST_DIR="${OPTARG}";;
|
2007-07-14 21:21:55 +00:00
|
|
|
f) CT_FORCE=y;;
|
2007-07-08 17:44:59 +00:00
|
|
|
v) CT_ECHO=echo;;
|
|
|
|
h) doHelp
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
:) echo "$myname: \"-${OPTARG}\" takes exactly one argument."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
?) echo "$myname: unknown option \"-${OPTARG}\"."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Sanity checks
|
|
|
|
if [ -z "${CT_ROOT_SRC_DIR}" -o -z "${CT_ROOT_DST_DIR}" ]; then
|
|
|
|
doHelp
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ ! -d "${CT_ROOT_SRC_DIR}" ]; then
|
|
|
|
echo "$myname: \"${CT_ROOT_SRC_DIR}\": no such file or directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
2007-07-14 21:21:55 +00:00
|
|
|
if [ -d "${CT_ROOT_DST_DIR}" -a "${CT_FORCE}" != "y" ]; then
|
2007-07-08 17:44:59 +00:00
|
|
|
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
|
|
|
|
echo "$myname: source and destination are the same!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get rid of potentially older destination directory
|
|
|
|
if [ -d "${CT_ROOT_DST_DIR}" ]; then
|
|
|
|
mv "${CT_ROOT_DST_DIR}" "${CT_ROOT_DST_DIR}.$$"
|
2007-08-07 18:05:41 +00:00
|
|
|
setsid nohup rm -rf "${CT_ROOT_DST_DIR}.$$" >/dev/null 2>&1 &
|
2007-07-08 17:44:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Create the working copy
|
|
|
|
mkdir -p "${CT_ROOT_DST_DIR}"
|
|
|
|
|
|
|
|
# Make all path absolute
|
2007-07-14 13:09:17 +00:00
|
|
|
CT_ROOT_SRC_DIR=$(cd "${CT_ROOT_SRC_DIR}"; pwd)
|
|
|
|
CT_ROOT_DST_DIR=$(cd "${CT_ROOT_DST_DIR}"; pwd)
|
2007-07-08 17:44:59 +00:00
|
|
|
|
|
|
|
cd "${CT_ROOT_SRC_DIR}"
|
|
|
|
tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -)
|
|
|
|
|
|
|
|
# Parse the working copy for executables and libraries
|
|
|
|
cd "${CT_ROOT_DST_DIR}"
|
|
|
|
still_needed=1
|
|
|
|
while [ ${still_needed} -eq 1 ]; do
|
|
|
|
${CT_ECHO} "Looping..."
|
|
|
|
still_needed=0
|
|
|
|
for f in $(find . -type f -exec file {} \; |egrep ': ELF [[:digit:]]+-bit .SB (executable|shared object),' |cut -d ":" -f 1); do
|
|
|
|
${CT_ECHO} "Scanning \"${f}\""
|
|
|
|
for libname in $("${CT_READELF}" -d "${f}" |egrep '(NEEDED)' |sed -r -e 's,.+\[(.+)\] *$,\1,;'); do
|
|
|
|
${CT_ECHO} " searching for \"${libname}\""
|
2007-07-14 21:21:55 +00:00
|
|
|
if [ -e "lib/${libname}" \
|
|
|
|
-o -e "usr/lib/${libname}" ]; then
|
2007-07-08 17:44:59 +00:00
|
|
|
${CT_ECHO} " already present"
|
|
|
|
continue
|
|
|
|
fi
|
2007-07-14 13:09:17 +00:00
|
|
|
# Need to scan .. for libgcc_s et al.
|
2007-07-08 17:44:59 +00:00
|
|
|
for dir in . usr ..; do
|
|
|
|
${CT_ECHO} -n " trying in \"${dir}\""
|
|
|
|
tgt_dir="${dir}"
|
|
|
|
[ "${tgt_dir}" = ".." ] && tgt_dir="usr"
|
|
|
|
libfile="${CT_SYSROOT_DIR}/${dir}/lib/${libname}"
|
|
|
|
${CT_ECHO} ": \"${libfile}\""
|
|
|
|
if [ -e "${libfile}" ]; then
|
2007-07-14 21:21:55 +00:00
|
|
|
mkdir -p "${dir}/lib"
|
2007-07-08 17:44:59 +00:00
|
|
|
${CT_ECHO} " installing \"${tgt_dir}/lib/${libname}\""
|
2007-07-14 21:21:55 +00:00
|
|
|
cp "${libfile}" "${tgt_dir}/lib/${libname}"
|
2007-07-08 17:44:59 +00:00
|
|
|
still_needed=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|