summaryrefslogtreecommitdiffstats
path: root/remote/setup_tools
diff options
context:
space:
mode:
authorMichael Neves2013-02-27 19:37:04 +0100
committerMichael Neves2013-02-27 19:37:04 +0100
commit459c9c02adf020d3e85d809c902196e801085a65 (patch)
treeaeec9e371eb37ea0419c05870b4a9a699c331d70 /remote/setup_tools
parentcopy modules/firmware to stage31, generate separate initramfs for squashfs (diff)
parenttihi (diff)
downloadtm-scripts-459c9c02adf020d3e85d809c902196e801085a65.tar.gz
tm-scripts-459c9c02adf020d3e85d809c902196e801085a65.tar.xz
tm-scripts-459c9c02adf020d3e85d809c902196e801085a65.zip
init and build_core merges
Diffstat (limited to 'remote/setup_tools')
-rwxr-xr-xremote/setup_tools232
1 files changed, 105 insertions, 127 deletions
diff --git a/remote/setup_tools b/remote/setup_tools
index 76f163f5..e96d8e2c 100755
--- a/remote/setup_tools
+++ b/remote/setup_tools
@@ -1,10 +1,13 @@
#!/bin/bash
-MODULE_DIR=${ROOT_DIR}/remote
+MODULE_DIR="${ROOT_DIR}/remote"
#Create tools directory if not exists
-TOOL_DIR=${MODULE_DIR}/tools
-INIT_DIR=${MODULE_DIR}/stage3.2
+TOOL_DIR="${MODULE_DIR}/tools"
+INIT_DIR="${MODULE_DIR}/stage3.2"
+
+# Keep track of processed modules
+PROCESSED_MODULES=""
initial_checks ()
{
@@ -18,20 +21,27 @@ initial_checks ()
read_config ()
{
- local TOOL_CONFIG=${TOOL_DIR}/${TOOL}/${TOOL}.conf
+ unset REQUIRED_BINARIES
+ unset REQUIRED_LIBRARIES
+ unset REQUIRED_DIRECTORIES
+ unset REQUIRED_FILES
+ unset REQUIRED_MODULES
+ unset REQUIRED_PACKAGES
+
+ local TOOL_CONFIG="${TOOL_DIR}/${TOOL}/${TOOL}.conf"
- [ ! -e ${TOOL_CONFIG} ] && perror "Config for '$TOOL' not found."
+ [ ! -e "${TOOL_CONFIG}" ] && perror "Config for '$TOOL' not found."
- . ${TOOL_CONFIG}
+ . "${TOOL_CONFIG}" || perror "Sourcing '${TOOL_CONFIG}' failed."
}
read_build ()
{
- local BUILD_SCRIPT=${TOOL_DIR}/${TOOL}/${TOOL}.build
+ local BUILD_SCRIPT="${TOOL_DIR}/${TOOL}/${TOOL}.build"
- [ ! -e ${BUILD_SCRIPT} ] && perror "Build script for specified tool not found."
+ [ ! -e "${BUILD_SCRIPT}" ] && perror "Build script for specified tool not found."
- . ${BUILD_SCRIPT}
+ . "${BUILD_SCRIPT}" || perror "Sourcing '${BUILD_SCRIPT}' failed."
}
copyfileswithdependencies ()
@@ -47,59 +57,39 @@ 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') # 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
+ local FILE_CANDIDATES=$( find . -name "${FILENAME}" -a \( -type f -o -type l \) )
+ pdebug "Candidates for $FILENAME are: $FILE_CANDIDATES"
+ local FINAL_LIST=""
+ for FILE in $FILE_CANDIDATES; do
+ local TESTFILE="$(readlink -f "$FILE")"
+ pdebug " $FILE leads to $TESTFILE"
+ [ -f "$TESTFILE" -a -x "$TESTFILE" ] && [ "x$(grep -l -E '^(.ELF|#!)' "$TESTFILE")" != "x" ] && FINAL_LIST="$FINAL_LIST $FILE"
+ done
+ FINAL_LIST=$(trim "$FINAL_LIST")
+ pdebug " Final list is $FINAL_LIST"
+ if [ -z "$FINAL_LIST" ]; then
+ pwarning "\tNo Binary found for ${FILENAME}. Skipping."
+ continue
+ fi
+ if [[ "$FINAL_LIST" == *" "* ]]; then
+ pwarning "Found more than one match for required file '$FILENAME': $FINAL_LIST"
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
+ pdebug "\tFound ${FILENAME} at ${FILE}"
fi
- done
- done
+ for FILE in $FINAL_LIST; do
+ get_link_chain "${TOOL_DIR}/${TOOL}/build/${FILE}" "${TOOL_DIR}/${TOOL}/build" >> "${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}.so\*)
do
pdebug "* $LOCATION"
- echo ${LOCATION} >> ${COPYFILES_LIST}
+ get_link_chain "${TOOL_DIR}/${TOOL}/build/${LOCATION}" "${TOOL_DIR}/${TOOL}/build" >> "${COPYFILES_LIST}"
+ get_dynamic_dependencies -l "${TOOL_DIR}/${TOOL}/build" "${LOCATION}" >> "${COPYFILES_LIST}"
done
done
@@ -112,37 +102,16 @@ copyfileswithdependencies ()
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
+ get_link_chain "${TOOL_DIR}/${TOOL}/build/${BIN}" "${TOOL_DIR}/${TOOL}/build" >> "${COPYFILES_LIST}"
+ get_dynamic_dependencies -l "${TOOL_DIR}/${TOOL}/build" "${BIN}" >> "${COPYFILES_LIST}"
done
done
[ ! -z "${REQUIRED_FILES}" ] && pinfo "Gathering required files from config file..."
for ENTRY in ${REQUIRED_FILES}
do
- echo "./${ENTRY}" >> "${COPYFILES_LIST}"
+ get_link_chain "${TOOL_DIR}/${TOOL}/build/${ENTRY}" "${TOOL_DIR}/${TOOL}/build" >> "${COPYFILES_LIST}"
+ get_dynamic_dependencies -l "${TOOL_DIR}/${TOOL}/build" "${TOOL_DIR}/${TOOL}/build/.${ENTRY}" >> "${COPYFILES_LIST}"
done
@@ -155,10 +124,6 @@ copyfileswithdependencies ()
local RET=$?
[ "x$RET" != "x0" ] && perror "Could not tar-copy to $INIT_DIR"
fi
- unset REQUIRED_BINARIES
- unset REQUIRED_LIBRARIES
- unset REQUIRED_DIRECTORIES
- unset REQUIRED_FILES
}
get_basic_libs () {
@@ -194,57 +159,73 @@ generate_stage32 () {
fi
# now iterate over given tools and copy them
- cd ${TOOL_DIR}
while (( "$#" )); do
- TOOL=$1
- 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
- # TODO: Make above work with the new logging system (add function to logging.inc to switch logfile)
- cd "${TOOL}"
- pinfo "## Reading config"
- read_config
- pinfo "## Reading build"
- read_build
- pinfo "## Installing dependencies"
- install_dependencies
- pinfo "## Fetching source"
- fetch_source
- pinfo "## Building"
- build
- # remove *.la files as they might confuse libtool/linker of other tool packages
- find "${TOOL_DIR}/${TOOL}/build" -name '*.la' -exec rm -f {} \;
- pinfo "## Copying files with dependencies"
- copyfileswithdependencies
- pinfo "## Post copy"
- post_copy
- cd ${TOOL_DIR}
-
- # reset pipes
- #[ "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
+ process_module "$1"
shift
done
+ TOOL_STR=""
+}
+
+process_module() {
+ [ "$#" -ne "1" ] && perror "process_module: want 1 param."
+ local TOOL="$1"
+ [[ "$PROCESSED_MODULES" == *"!${TOOL}!"* ]] && return # Already processed this module
+ PROCESSED_MODULES="${PROCESSED_MODULES}!${TOOL}!"
+ local TOOL_STR=""
+ pinfo ">>>>>>>>>>>>>>>>> Processing module [ $TOOL ]"
+ TOOL_STR="[${TOOL}]"
+ if [ -d "${TOOL_DIR}/${TOOL}" ];
+ then
+
+ #[ "x$DEBUG" != "x1" ] \
+ # && echo "Logging to ${TOOL_DIR}/${TOOL}/stage32.log" \
+ # && exec 6>&1 > ${TOOL_DIR}/${TOOL}/stage32.log
+ # TODO: Make above work with the new logging system (add function to logging.inc to switch logfile)
+ cd "${TOOL_DIR}/${TOOL}" || perror "Tool dir '${TOOL_DIR}/${TOOL}' seems to exist, but cd to it failed."
+ pinfo "## Reading config"
+ read_config
+ # Check if this module has a dependency that wasn't built yet:
+ if [ ! -z "$REQUIRED_MODULES" ]; then
+ pinfo "$TOOL depends on ${REQUIRED_MODULES}...."
+ for DEP in $REQUIRED_MODULES; do
+ #[[ "$DESIRED_MODULES" != *"!${DEP}!"* ]] && perror "$TOOL has dependency $DEP, but $DEP is not in current profile."
+ process_module "$DEP"
+ done
+ # Read old config again, as it got overwritten by the deps
+ cd "${TOOL_DIR}/${TOOL}" || perror "Tool dir '${TOOL_DIR}/${TOOL}' seems to exist, but cd to it failed (after building deps)."
+ read_config
+ pinfo "<<<<<<<<<<<<<<<<< Dependency modules processed, back to module [ $TOOL ]"
+ fi
+ pinfo "## Reading build"
+ read_build
+ pinfo "## Installing dependencies"
+ install_dependencies
+ pinfo "## Fetching source"
+ fetch_source
+ pinfo "## Building"
+ build
+ # remove *.la files as they might confuse libtool/linker of other tool packages
+ find "${TOOL_DIR}/${TOOL}/build" -name '*.la' -exec rm -f {} \;
+ pinfo "## Copying files with dependencies"
+ copyfileswithdependencies
+ pinfo "## Post copy"
+ post_copy
+
+ # reset pipes
+ #[ "x$DEBUG" != "x1" ] && exec 1>&6 6>&-
+ # TODO
+ pinfo "Module completed."
+ else
+ perror "Tool directory for '$TOOL' not found."
+ # maybe make this a warning instead of error?
+ fi
}
clean_tools() {
if [ "x$1" = "x" -o "x$1" = "xall" ]; then
#clean all
if [ -d ${INIT_DIR} ]; then
- pinfo "Cleaning ${INIT_DIR}..."
rm -rf "${INIT_DIR}" || perror "Error deleting $INIT_DIR"
- pinfo "done."
fi
for TOOL in $(ls ${TOOL_DIR}); do
clean_tool $TOOL
@@ -279,7 +260,4 @@ clean_tool() {
if [ -e ${TOOLDIR}/list_binaries_and_files ]; then
rm "${TOOLDIR}/list_binaries_and_files" || perror "Could not delete list_binaries_and_files"
fi
- pinfo "done."
}
-
-#generate_stage32 $@