summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--helper/binutil.inc122
-rwxr-xr-xremote/setup_tools127
2 files changed, 201 insertions, 48 deletions
diff --git a/helper/binutil.inc b/helper/binutil.inc
new file mode 100644
index 00000000..b97ab0f8
--- /dev/null
+++ b/helper/binutil.inc
@@ -0,0 +1,122 @@
+#!/bin/bash
+#
+# Common functions to copy binaries and their dependancies.
+#
+############################################################
+#
+# Usage: get_dynamic_dependencies <binary_list>
+# (the list must be seperated by spaces)
+#
+# Ouput:
+# Will simply echo list of required libraries
+
+# List of libraries to exclude from
+BLACKLIST="ld-linux linux-gate linux-vdso libc.so"
+LOCALSEARCH=0
+LOCALSEARCHDIR=""
+
+get_dynamic_dependencies() {
+
+ if [ "x$1" == "x-l" ]; then
+ LOCALSEARCH=1
+ pdebug "Local search activated."
+ shift
+ [ ! -d $1 ] && perror "Directory given does not exist, exiting."
+ LOCALSEARCHDIR=$1
+ shift
+ pdebug "Looking in: $LOCALSEARCHDIR"
+ fi
+
+ while [ $# != 0 ]; do
+ local BINARY=$1
+ shift
+
+ pdebug "Processing ${BINARY} ..."
+
+ local LDD_OUT="ldd_output"
+ if ldd $BINARY > $LDD_OUT; then
+ # Case 1: dynamic
+ for LIB in $(cat $LDD_OUT | grep -v $(echo $BLACKLIST|sed 's/ /\\|/g') | awk '{print $1 $2 $3}'); do
+ # split the entry into an array, ex:
+ # libm.so.6 => /lib/libm.so.6 would be split into:
+ # liblink[0] liblink[1]
+ local liblink=(${LIB//=>/ })
+ pdebug " Searching for ${liblink[0]}..."
+ lib_search
+ done
+ else
+ # Case 2: not a dynamic
+ pdebug "$BINARY not a dynamic, skipping."
+ continue
+ fi
+ rm $LDD_OUT
+ done
+}
+
+lib_search(){
+
+ # if activated, start by searching the lib locally
+ if [ "x$LOCALSEARCH" == "x1" ]; then
+ cd $LOCALSEARCHDIR
+ local LOCAL_MATCHES=$(find . -name "${liblink[0]}") # | awk -F '.' '{print $1}')".so\*)
+ cd - &>/dev/null
+ if [ "x${LOCAL_MATCHES}" != "x" ]; then
+ for llib in ${LOCAL_MATCHES}; do
+ pdebug "\tFound locally, copying ${LOCALSEARCHDIR}/${llib}"
+ get_link_chain "${LOCALSEARCHDIR}"/"${llib}"
+
+ done
+ # found the libs, we are done
+ return
+ fi
+ # mark local search as done
+ LOCALSEARCH=0
+ fi
+
+ # search the lib on the system since it was not found earlier
+ if [ ! -z ${liblink[1]} ] && [ "x${liblink[1]}" != "xnot" ]; then
+ pdebug "\tNot found locally but in system, copying ${liblink[1]}"
+ # get chain of symlink for that lib
+ get_link_chain ${liblink[1]}
+ else
+ pwarning "Lib '${liblink[0]}' from required dir '$ENTRY' neither found in build directory nor on this system."
+ pwarning "If this lib is not supplied by another module, this module will probably fail in your final system"
+ fi
+}
+############################################################
+#
+# Usage: get_link_chain <link>
+#
+# <link> must be in absolute form
+#
+# Output:
+# Lists the symlink chain until a hardlink is found.
+get_link_chain() {
+
+ # the first parameter must be absolute
+ [[ "$1" == /* ]] || perror "get_link_chain() requires absolute paths."
+
+ # canonalize
+ local LINK=$(canonicalize $1)
+
+ # write the first link in the chain
+ # we strip the LOCALSEARCHDIR if it was found locally
+ [ "x$LOCALSEARCH" == "x1" ] && echo "./${LINK#$LOCALSEARCHDIR}" || echo ${LINK}
+
+ # now we check for symlinks
+ local TRY=0
+ while [ -L $LINK ] && [ $TRY -lt 10 ]; do
+ let TRY=TRY+1
+
+ # save the directory prefix
+ CURRENTDIR=$(dirname ${LINK})
+ # first follow the link
+ LINK=$(readlink $LINK)
+
+ pdebug "Processing $LINK"
+ # $LINK can be absolute or relative, check cases
+ [[ "$LINK" == /* ]] || LINK=$(canonicalize "$CURRENTDIR"/"${LINK}")
+ [ "x$LOCALSEARCH" == "x1" ] && echo "./${LINK#$LOCALSEARCHDIR}" || echo ${LINK}
+ done
+
+}
diff --git a/remote/setup_tools b/remote/setup_tools
index 67099197..76f163f5 100755
--- a/remote/setup_tools
+++ b/remote/setup_tools
@@ -47,24 +47,59 @@ copyfileswithdependencies ()
[ ! -z "${REQUIRED_BINARIES}" ] && pinfo "Gathering required binaries from config file..."
for FILENAME in ${REQUIRED_BINARIES}
do
- FILE=$(find . -name ${FILENAME} -type f -executable | xargs grep -l '^.ELF'|head -1) # FIXME: What happens on multiple matches? Maybe add " | head -1"
- if [ -z "$FILE" ]; then
- pwarning "\tNo Binary found for ${FILENAME}. Skipping."
- continue
+ FILE=$(find . -name ${FILENAME} -type f -executable | xargs grep -l '^.ELF') # FIXME: What happens on multiple matches? Maybe add " | head -1"
+ if [ -z "$FILE" ]; then
+ pwarning "\tNo Binary found for ${FILENAME}. Skipping."
+ continue
+ fi
+ pdebug "\tFound ${FILENAME} at ${FILE}"
+ echo "${FILE}" >> "${COPYFILES_LIST}"
+ # fetch dependencies
+ # quick fix to exclude libc*, else it copies unneeded libs...
+ # workaround for
+ ldd ${FILE} &>/dev/null
+ ldd_exit_code=$?
+ if [ "x$ldd_exit_code" != "x0" ];
+ then
+ pdebug "\tldd $FILE failed."
+ continue
+ fi
+ for i in $(ldd "${FILE}" | awk '{print $1 $2 $3}' | grep -v ld-linux | grep -v libc.so | grep -v linux-gate | grep -v linux-vdso)
+ do
+ arrIN=(${i//=>/ })
+ pdebug "* ${arrIN[0]}"
+ LOCAL_MATCHES=$(find . -name "$(echo ${arrIN[0]} | awk -F '.' '{print $1}')".so\*)
+ if [ "x${LOCAL_MATCHES}" != "x" ];
+ then
+ for llib in ${LOCAL_MATCHES};
+ do
+ pdebug " at ${llib}"
+ echo ${llib} >> "${COPYFILES_LIST}"
+ done
+ else
+ if [ -e ${arrIN[1]} ];
+ then
+ echo ${arrIN[1]} >> "${COPYFILES_LIST}"
+
+ if [ ! -L ${arrIN[1]} ];
+ then
+ pdebug " at ${arrIN[1]}"
+ else
+ pdebug " at ${arrIN[1]} -> $(readlink -f ${arrIN[1]})"
+ echo $(readlink -f ${arrIN[1]}) >> ${COPYFILES_LIST}
+ fi
+ fi
fi
- pdebug "\tFound ${FILENAME} at ${FILE}"
- echo "${FILE}" >> "${COPYFILES_LIST}"
- get_dynamic_dependencies -l "${TOOL_DIR}/${TOOL}/build" "$FILE" >> "${COPYFILES_LIST}"
+ done
done
[ ! -z "${REQUIRED_LIBRARIES}" ] && pinfo "Gathering required libraries from config file..."
for LIB in ${REQUIRED_LIBRARIES}
do
- for LOCATION in $(find . -name ${LIB})
+ for LOCATION in $(find . -name ${LIB}*)
do
pdebug "* $LOCATION"
- echo "${LOCATION}" >> ${COPYFILES_LIST}
- get_dynamic_dependencies -l "${TOOL_DIR}/${TOOL}/build" ${LOCATION} >> ${COPYFILES_LIST}
+ echo ${LOCATION} >> ${COPYFILES_LIST}
done
done
@@ -74,39 +109,34 @@ copyfileswithdependencies ()
do
pdebug "* ./$ENTRY"
echo "./${ENTRY}" >> "${COPYFILES_LIST}"
- get_dynamic_dependencies -l "${TOOL_DIR}/${TOOL}/build" ${ENTRY} >> ${COPYFILES_LIST}
-
-
- #as as \n
- #echo "./${ENTRY}" >> "${COPYFILES_LIST}"
- #for BIN in $(find "./${ENTRY}" -type f -not -name '*.a' | xargs grep -l '^.ELF')
- #do
- # pdebug " Searching libs for ${BIN}..."
-# for i in $(ldd ${BIN} | awk '{print $1 $2 $3}' | grep -v ld-linux | grep -v libc.so | grep -v linux-gate | grep -v linux-vdso)
-# do
-# arrIN=(${i//=>/ })
-# pdebug " Searching for ${arrIN[0]}...($i)"
-# local LOCAL_MATCHES=$(find . -name "$(echo ${arrIN[0]} | awk -F '.' '{print $1}')".so\*)
-# if [ "x${LOCAL_MATCHES}" != "x" ];
-# then
-# for llib in ${LOCAL_MATCHES};
-# do
-# pdebug " Found locally, copying ${llib}"
-# echo ${llib} >> "${COPYFILES_LIST}"
-# done
-# else
-# if [ ! -z ${arrIN[1]} ] && [ "x${arrIN[1]}" != "xnot" ];
-# then
-# pdebug " Not found locally but in system, copying ${arrIN[1]}"
-# echo ${arrIN[1]} >> "${COPYFILES_LIST}"
-# [ -L ${arrIN[1]} ] && echo $(readlink -f "${arrIN[1]}") >> "${COPYFILES_LIST}"
-# else
-# pwarning "Lib '${arrIN[0]}' from required dir '$ENTRY' neither found in build directory nor on this system."
-# pwarning "If this lib is not supplied by another module, this module will probably fail in your final system"
-# fi
-# fi
-# done
-# done
+ for BIN in $(find "./${ENTRY}" -type f -not -name '*.a' | xargs grep -l '^.ELF')
+ do
+ pdebug " Searching libs for ${BIN}..."
+ for i in $(ldd ${BIN} | awk '{print $1 $2 $3}' | grep -v ld-linux | grep -v libc.so | grep -v linux-gate | grep -v linux-vdso)
+ do
+ arrIN=(${i//=>/ })
+ pdebug " Searching for ${arrIN[0]}...($i)"
+ local LOCAL_MATCHES=$(find . -name "$(echo ${arrIN[0]} | awk -F '.' '{print $1}')".so\*)
+ if [ "x${LOCAL_MATCHES}" != "x" ];
+ then
+ for llib in ${LOCAL_MATCHES};
+ do
+ pdebug " Found locally, copying ${llib}"
+ echo ${llib} >> "${COPYFILES_LIST}"
+ done
+ else
+ if [ ! -z ${arrIN[1]} ] && [ "x${arrIN[1]}" != "xnot" ];
+ then
+ pdebug " Not found locally but in system, copying ${arrIN[1]}"
+ echo ${arrIN[1]} >> "${COPYFILES_LIST}"
+ [ -L ${arrIN[1]} ] && echo $(readlink -f "${arrIN[1]}") >> "${COPYFILES_LIST}"
+ else
+ pwarning "Lib '${arrIN[0]}' from required dir '$ENTRY' neither found in build directory nor on this system."
+ pwarning "If this lib is not supplied by another module, this module will probably fail in your final system"
+ fi
+ fi
+ done
+ done
done
[ ! -z "${REQUIRED_FILES}" ] && pinfo "Gathering required files from config file..."
@@ -167,10 +197,11 @@ generate_stage32 () {
cd ${TOOL_DIR}
while (( "$#" )); do
TOOL=$1
- TOOL_STR=""
- pinfo ">>>>>>>>>>>>>>>> Processing module [ $TOOL ]"
- TOOL_STR="[${TOOL}]"
- if [ -d ${TOOL} ]; then
+ if [ -d ${TOOL} ];
+ then
+ TOOL_STR="[${TOOL}]"
+ pinfo "## ## Processing module ## ##"
+
#[ "x$DEBUG" != "x1" ] \
# && echo "Logging to ${TOOL_DIR}/${TOOL}/stage32.log" \
# && exec 6>&1 > ${TOOL_DIR}/${TOOL}/stage32.log
@@ -198,13 +229,13 @@ generate_stage32 () {
#[ "x$DEBUG" != "x1" ] && exec 1>&6 6>&-
# TODO
pinfo "## ## Module completed ## ##"
+ TOOL_STR=""
else
perror "Tool directory for '$TOOL' not found."
# maybe make this a warning instead of error?
fi
shift
done
- TOOL_STR=""
}
clean_tools() {