summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/.gitignore2
-rw-r--r--scripts/crosstool-NG.sh.in44
-rw-r--r--scripts/functions96
-rw-r--r--scripts/saveSample.sh.in52
-rw-r--r--scripts/showConfig.sh.in15
-rw-r--r--scripts/showTuple.sh.in30
6 files changed, 118 insertions, 121 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore
index 07af16d..a38259b 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -1,3 +1,3 @@
crosstool-NG.sh
saveSample.sh
-showTuple.sh
+showConfig.sh
diff --git a/scripts/crosstool-NG.sh.in b/scripts/crosstool-NG.sh.in
index ba36bc8..eeb7800 100644
--- a/scripts/crosstool-NG.sh.in
+++ b/scripts/crosstool-NG.sh.in
@@ -17,13 +17,13 @@
# most notably:
# - set trap handler on errors,
# - don't hash commands lookups,
-# - initialise logging.
. "${CT_LIB_DIR}/scripts/functions"
-# Parse the configuration file
-# It has some info about the logging facility, so include it early
-. .config.2
+# Read the sample settings
+CT_LoadConfig
+
# Yes! We can do full logging from now on!
+CT_LogEnable
# Check running as root
if [ -z "${CT_ALLOW_BUILD_AS_ROOT_SURE}" ]; then
@@ -126,8 +126,6 @@ CT_STAR_DATE_HUMAN=$(CT_DoDate +%Y%m%d.%H%M%S)
# Log real begining of build, now
CT_DoLog INFO "Build started ${CT_STAR_DATE_HUMAN}"
-# We really need to extract from ,config and not .config.2, as we
-# do want the kconfig's values, not our mangled config with arrays.
CT_DoStep DEBUG "Dumping user-supplied crosstool-NG configuration"
CT_DoExecLog DEBUG ${grep} -E '^(# )?CT_' .config
CT_EndStep
@@ -138,26 +136,6 @@ export MAKEFLAGS
CT_DoLog INFO "Building environment variables"
-# Include sub-scripts instead of calling them: that way, we do not have to
-# export any variable, nor re-parse the configuration and functions files.
-. "${CT_LIB_DIR}/scripts/build/internals.sh"
-. "${CT_LIB_DIR}/scripts/build/arch.sh"
-. "${CT_LIB_DIR}/scripts/build/companion_tools.sh"
-. "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
-. "${CT_LIB_DIR}/scripts/build/companion_libs.sh"
-. "${CT_LIB_DIR}/scripts/build/binutils/${CT_BINUTILS}.sh"
-. "${CT_LIB_DIR}/scripts/build/libc/${CT_LIBC}.sh"
-. "${CT_LIB_DIR}/scripts/build/cc.sh"
-. "${CT_LIB_DIR}/scripts/build/debug.sh"
-. "${CT_LIB_DIR}/scripts/build/test_suite.sh"
-
-# Target tuple: CT_TARGET needs a little love:
-CT_DoBuildTargetTuple
-
-# Kludge: If any of the configured options needs CT_TARGET,
-# then rescan the options file now:
-. .config.2
-
# Sanity check some directories
CT_TestAndAbort "'CT_PREFIX_DIR' is not set: where should I install?" -z "${CT_PREFIX_DIR}"
@@ -178,8 +156,8 @@ CT_PKGVERSION="crosstool-NG ${CT_VERSION}${CT_TOOLCHAIN_PKGVERSION:+ - ${CT_TOOL
# Compute the working directories names
CT_TARBALLS_DIR="${CT_WORK_DIR}/tarballs"
CT_SRC_DIR="${CT_WORK_DIR}/src"
-CT_BUILD_DIR="${CT_WORK_DIR}/${CT_TARGET}/build"
-CT_BUILDTOOLS_PREFIX_DIR="${CT_WORK_DIR}/${CT_TARGET}/buildtools"
+CT_BUILD_DIR="${CT_BUILD_TOP_DIR}/build"
+CT_BUILDTOOLS_PREFIX_DIR="${CT_BUILD_TOP_DIR}/buildtools"
CT_STATE_DIR="${CT_WORK_DIR}/${CT_TARGET}/state"
# Note about HOST_COMPLIBS_DIR: it's always gonna be in the buildtools dir, or a
# sub-dir. So we won't have to save/restore it, not even create it.
@@ -310,7 +288,6 @@ if [ -z "${CT_RESTART}" ]; then
BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
- LIBC_SYSROOT_ARG=""
# glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
# confused when $sysroot/usr/include is not present.
# Note: --prefix=/usr is magic!
@@ -329,7 +306,6 @@ if [ -z "${CT_RESTART}" ]; then
# building libgcc, and you'll have no profiling
CC_CORE_SYSROOT_ARG="--without-headers"
CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
- LIBC_SYSROOT_ARG="prefix="
fi
CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}"
CT_DoExecLog ALL mkdir -p "${CT_DEBUGROOT_DIR}"
@@ -591,8 +567,6 @@ if [ -z "${CT_RESTART}" ]; then
fi
rm -f "${testc}"
- # We need to save the real .config with kconfig's value,
- # not our mangled .config.2 with arrays.
CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"
CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/bin"
CT_DoExecLog DEBUG ${install} -m 0755 "${CT_LIB_DIR}/scripts/toolchain-config.in" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
@@ -691,12 +665,12 @@ CT_DoEnd INFO
# From now-on, it can become impossible to log any time, because
# either we're compressing the log file, or it can become RO any
-# moment... Restore original stdout, stderr and stdin
+# moment...
CT_DoLog INFO "Finishing installation (may take a few seconds)..."
-exec >&6 2>&7 <&8
+CT_LogDisable
rm -f ${CT_PREFIX_DIR}/build.log.bz2
if [ "${CT_LOG_TO_FILE}" = "y" ]; then
- cp "${tmp_log_file}" "${CT_PREFIX_DIR}/build.log"
+ cp "${CT_BUILD_LOG}" "${CT_PREFIX_DIR}/build.log"
if [ "${CT_LOG_FILE_COMPRESS}" = y ]; then
bzip2 -9 "${CT_PREFIX_DIR}/build.log"
fi
diff --git a/scripts/functions b/scripts/functions
index cbef48b..9aa4fc7 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -4,6 +4,56 @@
# Copyright 2007 Yann E. MORIN
# Licensed under the GPL v2. See COPYING in the root of this package
+CT_LoadConfig() {
+ local o
+
+ # Parse the configuration file
+ # It has some info about the logging facility, so include it early
+ # It also sets KERNEL/ARCH/... for file inclusion below. Does not handle
+ # recursive definitions yet. We don't need arrays at this point.
+ CT_TestOrAbort "Configuration file not found. Please create one." -r .config
+ . .config
+
+ # Include sub-scripts instead of calling them: that way, we do not have to
+ # export any variable, nor re-parse the configuration and functions files.
+ . "${CT_LIB_DIR}/scripts/build/internals.sh"
+ . "${CT_LIB_DIR}/scripts/build/arch.sh"
+ . "${CT_LIB_DIR}/scripts/build/companion_tools.sh"
+ . "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
+ . "${CT_LIB_DIR}/scripts/build/companion_libs.sh"
+ . "${CT_LIB_DIR}/scripts/build/binutils/${CT_BINUTILS}.sh"
+ . "${CT_LIB_DIR}/scripts/build/libc/${CT_LIBC}.sh"
+ . "${CT_LIB_DIR}/scripts/build/cc.sh"
+ . "${CT_LIB_DIR}/scripts/build/debug.sh"
+ . "${CT_LIB_DIR}/scripts/build/test_suite.sh"
+
+ # Target tuple: CT_TARGET needs a little love:
+ CT_DoBuildTargetTuple
+
+ # Kludge: If any of the configured options needs CT_TARGET,
+ # then rescan the options file now. This also handles recursive variables;
+ # but we don't want to loop forever if there's a circular reference.
+ oldvals=""
+ try=0
+ while [ "$try" -le 10 ]; do
+ . .config
+ vals=`set | ${grep} -E '^CT_'`
+ if [ "$oldvals" = "$vals" ]; then
+ break
+ fi
+ oldvals="$vals"
+ try=$[ try + 1 ]
+ done
+ if [ "$try" -gt 10 ]; then
+ CT_Abort "Variables in .config recurse too deep."
+ fi
+ # Double eval: first eval substitutes option name, second eval unescapes quotes
+ # and whitespace.
+ for o in `set | sed -rn 's/^(CT_[A-Za-z0-9_]*_ARRAY)=.*/\1/p'`; do
+ eval "eval $o=(\"\$$o\")"
+ done
+}
+
# Prepare the fault handler
CT_OnError() {
local ret=$?
@@ -48,7 +98,7 @@ CT_OnError() {
old_trap="$(trap -p ERR)"
trap -- ERR
(
- exec >&6 2>&7 <&8
+ CT_LogDisable # In this subshell
printf "\r \n\nCurrent command"
if [ -n "${cur_cmd}" ]; then
printf ":\n %s\n" "${cur_cmd}"
@@ -132,12 +182,22 @@ set +o hashall
# Log policy:
# - first of all, save stdout so we can see the live logs: fd #6
-# (also save stdin and stderr for use by CT_DEBUG_INTERACTIVE)
-exec 6>&1 7>&2 8<&0
-# - then point stdout to the log file
-tmp_log_file="${CT_TOP_DIR}/build.log"
-rm -f "${tmp_log_file}"
-exec >>"${tmp_log_file}"
+# (also save stdin and stderr for use by CT_DEBUG_INTERACTIVE)
+# FIXME: it doesn't look like anyone is overriding stdin/stderr. Do we need
+# to save/restore them?
+CT_LogEnable() {
+ exec 6>&1 7>&2 8<&0
+ CT_BUILD_LOG="${CT_TOP_DIR}/build.log"
+ CT_LOG_ENABLED=y
+ rm -f "${CT_BUILD_LOG}"
+ exec >>"${CT_BUILD_LOG}"
+}
+
+# Restore original stdout, stderr and stdin
+CT_LogDisable() {
+ exec >&6 2>&7 <&8
+ CT_LOG_ENABLED=
+}
# The different log levels:
CT_LOG_LEVEL_ERROR=0
@@ -197,14 +257,20 @@ CT_DoLog() {
*) cur_L="${LEVEL}"; cur_l="${level}";;
esac
# There will always be a log file (stdout, fd #1), be it /dev/null
- printf "[%-5s]%*s%s%s\n" "${cur_L}" "${indent}" " " "${line}"
- if [ ${cur_l} -le ${max_level} ]; then
- # Only print to console (fd #6) if log level is high enough.
- printf "${CT_LOG_PROGRESS_BAR:+\r}[%-5s]%*s%s%s\n" "${cur_L}" "${indent}" " " "${line}" >&6
- fi
- if [ "${CT_LOG_PROGRESS_BAR}" = "y" ]; then
- printf "\r[%02d:%02d] %s " $((SECONDS/60)) $((SECONDS%60)) "${_prog_bar[$((_prog_bar_cpt/10))]}" >&6
- _prog_bar_cpt=$(((_prog_bar_cpt+1)%40))
+ if [ -n "${CT_LOG_ENABLED}" ]; then
+ printf "[%-5s]%*s%s%s\n" "${cur_L}" "${indent}" " " "${line}"
+ # If log file has been set up, fd#6 is console and it only
+ # gets the most important messages.
+ if [ ${cur_l} -le ${max_level} ]; then
+ # Only print to console (fd #6) if log level is high enough.
+ printf "${CT_LOG_PROGRESS_BAR:+\r}[%-5s]%*s%s%s\n" "${cur_L}" "${indent}" " " "${line}" >&6
+ fi
+ if [ "${CT_LOG_PROGRESS_BAR}" = "y" ]; then
+ printf "\r[%02d:%02d] %s " $((SECONDS/60)) $((SECONDS%60)) "${_prog_bar[$((_prog_bar_cpt/10))]}" >&6
+ _prog_bar_cpt=$(((_prog_bar_cpt+1)%40))
+ fi
+ elif [ ${cur_l} -le ${CT_LOG_LEVEL_WARN} ]; then
+ printf "[%-5s]%*s%s%s\n" "${cur_L}" "${indent}" " " "${line}"
fi
done
)
diff --git a/scripts/saveSample.sh.in b/scripts/saveSample.sh.in
index a070dc2..646c189 100644
--- a/scripts/saveSample.sh.in
+++ b/scripts/saveSample.sh.in
@@ -10,29 +10,14 @@
# Parse the tools' paths configuration
. "${CT_LIB_DIR}/paths.sh"
-
-# We'll need the stdout later, save it
-exec 7>&1
-
. "${CT_LIB_DIR}/scripts/functions"
-# Don't care about any log file
-exec >/dev/null
-rm -f "${tmp_log_file}"
-
-# Parse the configuration file
-# Don't use CT_TestOrAbort, it prints the test string to [DEBUG]
-# Note: we just need the non-mangled .config, not .config.2
-if [ ! -f .config ]; then
- CT_Abort "Configuration file not found. Please create one."
-fi
-. .config
+CT_LoadConfig
# We can not reliably save a sample which either uses local patches
# and/or custom Linux kernel headers. Warn the user about this issue
# and continue if he/she confirms sving the sample.
if [ "${CT_CUSTOM_PATCH}" = "y" ]; then
- exec >&7
echo "You are using local patches."
echo "You will not be able to (easily) share this sample in this case."
read -p "Press Ctrl-C to stop now, or Enter to continue..."
@@ -41,17 +26,6 @@ fi
# Do not use a progress bar
unset CT_LOG_PROGRESS_BAR
-# Parse architecture and kernel specific functions
-. "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh"
-. "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
-
-# Target tuple: CT_TARGET needs a little love:
-CT_DoBuildTargetTuple
-
-# Kludge: if any of the config options needs either CT_TARGET or CT_TOP_DIR,
-# re-parse them:
-. .config
-
# Override log options
unset CT_LOG_PROGRESS_BAR CT_LOG_ERROR CT_LOG_INFO CT_LOG_EXTRA CT_LOG_DEBUG LOG_ALL
CT_LOG_WARN=y
@@ -66,16 +40,17 @@ esac
samp_dir="samples/${samp_name}"
mkdir -p "${samp_dir}"
-# Tweak the .config file
-# We need to be based on the real .config with kconfig's values,
-# not our mangled .config.2 with shell arrays
-cp .config .defconfig
-"${sed}" -r -e 's|^(CT_PREFIX_DIR)=.*|\1="${HOME}/x-tools/${CT_TARGET}"|;' \
- -e 's|^# CT_LOG_TO_FILE is not set$|CT_LOG_TO_FILE=y|;' \
- -e 's|^# CT_LOG_FILE_COMPRESS is not set$|CT_LOG_FILE_COMPRESS=y|;' \
- -e 's|^(CT_LOCAL_TARBALLS_DIR)=.*|\1="${HOME}/src"|;' \
- <.config \
- >.defconfig
+# Tweak the .config file: remove the options that we want to keep
+# at default setting in samples.
+force_default_opts=( \
+ PREFIX_DIR LOG_TO_FILE LOG_FILE_COMPRESS \
+ LOCAL_TARBALLS_DIR SAVE_TARBALLS \
+ LOG_ERROR LOG_WARN LOG_INFO LOG_EXTRA LOG_ALL LOG_DEBUG \
+ LOG_PROGRESS_BAR
+ )
+regexp=${force_default_opts[*]}
+regexp=${regexp// /|}
+grep -v -E '^(# )?CT_('"${regexp}"')' .config > .defconfig
# Function to copy a file to the sample directory
# Needed in case the file is already there (think of a previously available sample)
@@ -114,9 +89,6 @@ export KCONFIG_CONFIG="$(pwd)/.defconfig"
${CONF} --savedefconfig="${samp_dir}/crosstool.config" "${KCONFIG_TOP}"
rm -f .defconfig
-# Restore stdout now, to be interactive
-exec >&7
-
# Fill-in the reported-by info
[ -f "${samp_dir}/reported.by" ] && . "${samp_dir}/reported.by"
old_name="${reporter_name}"
diff --git a/scripts/showConfig.sh.in b/scripts/showConfig.sh.in
new file mode 100644
index 0000000..b439995
--- /dev/null
+++ b/scripts/showConfig.sh.in
@@ -0,0 +1,15 @@
+#!@@CT_bash@@
+
+# What we need:
+# - the .config file
+
+# Parse the tools' paths configuration
+. "${CT_LIB_DIR}/paths.sh"
+
+# Parse the common functions
+. "${CT_LIB_DIR}/scripts/functions"
+
+# Read the sample settings
+CT_LoadConfig
+
+eval "echo \"$1\""
diff --git a/scripts/showTuple.sh.in b/scripts/showTuple.sh.in
deleted file mode 100644
index 5389539..0000000
--- a/scripts/showTuple.sh.in
+++ /dev/null
@@ -1,30 +0,0 @@
-#!@@CT_bash@@
-
-# What we need:
-# - the .config file
-
-# Parse the tools' paths configuration
-. "${CT_LIB_DIR}/paths.sh"
-
-# We'll need the stdout later, save it
-exec 9>&1
-
-# Parse the common functions
-. "${CT_LIB_DIR}/scripts/functions"
-
-# Don't care about any log file
-exec >/dev/null
-rm -f "${tmp_log_file}"
-
-# Parse the configuration file
-. .config.2
-
-# Parse architecture and kernel specific functions
-. "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh"
-. "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
-
-# Build CT_TARGET
-CT_DoBuildTargetTuple
-
-# All this for this single echo... :-( Sigh, I'll have to re-arrange things...
-echo "${CT_TARGET}" >&9