mirror of
https://github.com/crosstool-ng/crosstool-ng.git
synced 2025-06-01 15:20:54 +00:00
populate:
- add an option to force installation of listed libraries, - add an option to read a file listing libraries of which to force installation. /trunk/tools/populate.in | 126 104 22 0 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 104 insertions(+), 22 deletions(-)
This commit is contained in:
parent
93c2e1f7fb
commit
1fa683894f
@ -13,29 +13,62 @@ myname=$(basename "$0")
|
|||||||
|
|
||||||
doHelp() {
|
doHelp() {
|
||||||
cat <<_EOF_
|
cat <<_EOF_
|
||||||
$myname [-f] [-v] -s source_root -d destination_root
|
NAME
|
||||||
|
$myname - populate the target root file system
|
||||||
|
|
||||||
-s dir
|
SYNOPSIS
|
||||||
use 'dir' as the un-populated (source) root directory
|
$myname OPTIONS -s source_root -d destination_root
|
||||||
|
|
||||||
-d dir
|
DESCRIPTION
|
||||||
use 'dir' as the place to put the populated root directory
|
$myname will 'populate' your target root file system ('src_dir') with
|
||||||
|
libraries from the toolchain (eg. libc.so...), storing the result into
|
||||||
|
'dst_dir'.
|
||||||
|
|
||||||
-f force execution: if destination directory already exists,
|
OPTIONS
|
||||||
it will be removed first.
|
-s src_dir
|
||||||
|
use 'src_dir' as the un-populated (source) root directory
|
||||||
|
|
||||||
|
-d dst_dir
|
||||||
|
use 'dst_dir' as the place to put the populated root directory
|
||||||
|
|
||||||
|
-l name1[:name2[...]]
|
||||||
|
Always add the specified shared library/ies name1, name2... from the
|
||||||
|
toolchain (in the sys-root). Actual library names are searched as
|
||||||
|
follows (where 'name' is replaced with the given name) in the
|
||||||
|
sys-root directory:
|
||||||
|
- libname.so
|
||||||
|
- name.so
|
||||||
|
- name
|
||||||
|
If the file is found, then the SONAME of the library is used, and the
|
||||||
|
library is copied with that name. If the library was not found, this
|
||||||
|
yields an error (unless -f was given).
|
||||||
|
|
||||||
|
-L file
|
||||||
|
Read 'file' for a list of shared libraries to always add from the
|
||||||
|
toolchain. The file should contain one library name per line; text
|
||||||
|
after a # is ignored until the end of the line; spaces are ignored;
|
||||||
|
empty lines are ignored. Libraries are searched for as with -l.
|
||||||
|
|
||||||
|
-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
|
||||||
|
|
||||||
_EOF_
|
_EOF_
|
||||||
}
|
}
|
||||||
|
|
||||||
CT_ROOT_SRC_DIR=
|
CT_ROOT_SRC_DIR=
|
||||||
CT_ROOT_DST_DIR=
|
CT_ROOT_DST_DIR=
|
||||||
|
CT_LIB_LIST=
|
||||||
|
CT_LIB_FILE=
|
||||||
CT_FORCE=no
|
CT_FORCE=no
|
||||||
CT_ECHO=true
|
CT_ECHO=true
|
||||||
while getopts ":s:d:fvh" CT_OPT; do
|
while getopts ":s:d:l:L:fvh" CT_OPT; do
|
||||||
case "${CT_OPT}" in
|
case "${CT_OPT}" in
|
||||||
s) CT_ROOT_SRC_DIR="${OPTARG}";;
|
s) CT_ROOT_SRC_DIR="${OPTARG}";;
|
||||||
d) CT_ROOT_DST_DIR="${OPTARG}";;
|
d) CT_ROOT_DST_DIR="${OPTARG}";;
|
||||||
|
l) CT_LIB_LIST="${CT_LIB_LIST}:${OPTARG}";;
|
||||||
|
L) CT_LIB_FILE="${OPTARG}";;
|
||||||
f) CT_FORCE=y;;
|
f) CT_FORCE=y;;
|
||||||
v) CT_ECHO=echo;;
|
v) CT_ECHO=echo;;
|
||||||
h) doHelp
|
h) doHelp
|
||||||
@ -70,6 +103,12 @@ if [ "${src_inode}" = "${dst_inode}" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check existence of the forced libraries file
|
||||||
|
if [ -n "${CT_LIB_FILE}" -a ! \( -f "${CT_LIB_FILE}" -a -r "${CT_LIB_FILE}" \) ]; then
|
||||||
|
echo "$myname: forced libraries file '${CT_LIB_FILE}' not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Get rid of potentially older destination directory
|
# Get rid of potentially older destination directory
|
||||||
if [ -d "${CT_ROOT_DST_DIR}" ]; then
|
if [ -d "${CT_ROOT_DST_DIR}" ]; then
|
||||||
mv "${CT_ROOT_DST_DIR}" "${CT_ROOT_DST_DIR}.$$"
|
mv "${CT_ROOT_DST_DIR}" "${CT_ROOT_DST_DIR}.$$"
|
||||||
@ -83,11 +122,60 @@ mkdir -p "${CT_ROOT_DST_DIR}"
|
|||||||
CT_ROOT_SRC_DIR=$(cd "${CT_ROOT_SRC_DIR}"; pwd)
|
CT_ROOT_SRC_DIR=$(cd "${CT_ROOT_SRC_DIR}"; pwd)
|
||||||
CT_ROOT_DST_DIR=$(cd "${CT_ROOT_DST_DIR}"; pwd)
|
CT_ROOT_DST_DIR=$(cd "${CT_ROOT_DST_DIR}"; pwd)
|
||||||
|
|
||||||
cd "${CT_ROOT_SRC_DIR}"
|
pushd "${CT_ROOT_SRC_DIR}" >/dev/null
|
||||||
tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -)
|
tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -)
|
||||||
|
popd >/dev/null
|
||||||
|
|
||||||
|
# A function do search for a library
|
||||||
|
# Usage: do_add_lib libname
|
||||||
|
# returns: 0 if library was found and added, !0 otherwise
|
||||||
|
do_add_lib() {
|
||||||
|
local libname="$1"
|
||||||
|
local ret=1
|
||||||
|
local true_libname
|
||||||
|
for dir in . usr; do
|
||||||
|
${CT_ECHO} -n " trying in '${dir}'"
|
||||||
|
libfile="${CT_SYSROOT_DIR}/${dir}/lib/${libname}"
|
||||||
|
${CT_ECHO} ": '${libfile}'"
|
||||||
|
if [ -e "${libfile}" ]; then
|
||||||
|
mkdir -p "${dir}/lib"
|
||||||
|
true_libname=$("${CT_READELF}" -d "${libfile}" |egrep "SONAME" |sed -r -e 's,.+\[(.+)\] *$,\1,;')
|
||||||
|
${CT_ECHO} " installing as '${dir}/lib/${true_libname}'"
|
||||||
|
cat "${libfile}" >"${dir}/lib/${true_libname}"
|
||||||
|
ret=0
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return ${ret}
|
||||||
|
}
|
||||||
|
|
||||||
|
# First of, copy the forced libraries into the working copy
|
||||||
|
if [ -n "${CT_LIB_FILE}" ]; then
|
||||||
|
lib_list=$(sed -r -e ':loop; s/#.*//; s/[[:space:]]+//g; s/([^:])$/\1:/; /$/N; s/\n//; tloop;' "${CT_LIB_FILE}")
|
||||||
|
CT_LIB_LIST=$(echo "${CT_LIB_LIST}:${lib_list}" |sed -r -e 's/:+/:/g; s/^:+//; s/:+$//;')
|
||||||
|
fi
|
||||||
|
CT_LIB_LIST="${CT_LIB_LIST//:/ }"
|
||||||
|
${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
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ ${found} -eq 0 ]; then
|
||||||
|
echo "$myname: library '${libname}' not found!"
|
||||||
|
[ "${CT_FORCE}" = y ] || exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
popd >/dev/null
|
||||||
|
|
||||||
# Parse the working copy for executables and libraries
|
# Parse the working copy for executables and libraries
|
||||||
cd "${CT_ROOT_DST_DIR}"
|
pushd "${CT_ROOT_DST_DIR}" >/dev/null
|
||||||
still_needed=1
|
still_needed=1
|
||||||
while [ ${still_needed} -eq 1 ]; do
|
while [ ${still_needed} -eq 1 ]; do
|
||||||
${CT_ECHO} "Looping..."
|
${CT_ECHO} "Looping..."
|
||||||
@ -101,18 +189,12 @@ while [ ${still_needed} -eq 1 ]; do
|
|||||||
${CT_ECHO} " already present"
|
${CT_ECHO} " already present"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
for dir in . usr; do
|
if do_add_lib "${libname}"; then
|
||||||
${CT_ECHO} -n " trying in '${dir}'"
|
still_needed=1
|
||||||
libfile="${CT_SYSROOT_DIR}/${dir}/lib/${libname}"
|
else
|
||||||
${CT_ECHO} ": '${libfile}'"
|
echo "$myname: library '${libname}' not found!"
|
||||||
if [ -e "${libfile}" ]; then
|
fi
|
||||||
mkdir -p "${dir}/lib"
|
|
||||||
${CT_ECHO} " installing '${dir}/lib/${libname}'"
|
|
||||||
cp "${libfile}" "${dir}/lib/${libname}"
|
|
||||||
still_needed=1
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
popd >/dev/null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user