1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripts/saveSample.sh.in Sun Feb 01 23:12:30 2009 +0000
1.3 @@ -0,0 +1,110 @@
1.4 +#!@@CT_bash@@
1.5 +
1.6 +# This script is responsible for saving the current configuration into a
1.7 +# sample to be used later on as a pre-configured target.
1.8 +
1.9 +# What we need to save:
1.10 +# - the .config file
1.11 +# - the uClibc .config file if uClibc selected
1.12 +# - info about who reported the sample
1.13 +
1.14 +# Parse the tools' paths configuration
1.15 +. "${CT_LIB_DIR}/paths.mk"
1.16 +
1.17 +# We'll need the stdout later, save it
1.18 +exec 7>&1
1.19 +
1.20 +. "${CT_LIB_DIR}/scripts/functions"
1.21 +
1.22 +# Don't care about any log file
1.23 +exec >/dev/null
1.24 +rm -f "${tmp_log_file}"
1.25 +
1.26 +# Parse the configuration file
1.27 +CT_TestOrAbort "Configuration file not found. Please create one." -f .config
1.28 +. .config
1.29 +
1.30 +# Do not use a progress bar
1.31 +unset CT_LOG_PROGRESS_BAR
1.32 +
1.33 +# Parse architecture and kernel specific functions
1.34 +. "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh"
1.35 +. "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
1.36 +
1.37 +# Target tuple: CT_TARGET needs a little love:
1.38 +CT_DoBuildTargetTuple
1.39 +
1.40 +# Kludge: if any of the config options needs either CT_TARGET or CT_TOP_DIR,
1.41 +# re-parse them:
1.42 +. .config
1.43 +
1.44 +# Override log options
1.45 +unset CT_LOG_PROGRESS_BAR CT_LOG_ERROR CT_LOG_INFO CT_LOG_EXTRA CT_LOG_DEBUG LOG_ALL
1.46 +CT_LOG_WARN=y
1.47 +CT_LOG_LEVEL_MAX="WARN"
1.48 +
1.49 +# Create the sample directory
1.50 +if [ ! -d "samples/${CT_TARGET}" ]; then
1.51 + mkdir -p "samples/${CT_TARGET}"
1.52 +fi
1.53 +
1.54 +# Save the crosstool-NG config file
1.55 +"${sed}" -r -e 's|^(CT_PREFIX_DIR)=.*|\1="${HOME}/x-tools/${CT_TARGET}"|;' \
1.56 + -e 's|^# CT_LOG_TO_FILE is not set$|CT_LOG_TO_FILE=y|;' \
1.57 + -e 's|^# CT_LOG_FILE_COMPRESS is not set$|CT_LOG_FILE_COMPRESS=y|;' \
1.58 + -e 's|^(CT_LOCAL_TARBALLS_DIR)=.*|\1="${HOME}/src"|;' \
1.59 + <.config \
1.60 + >"samples/${CT_TARGET}/crosstool.config"
1.61 +
1.62 +# Function to copy a file to the sample directory
1.63 +# Needed in case the file is already there (think of a previously available sample)
1.64 +# Usage: CT_DoAddFileToSample <source> <dest>
1.65 +CT_DoAddFileToSample() {
1.66 + source="$1"
1.67 + dest="$2"
1.68 + inode_s=$(ls -i "${source}" |"${awk}" '{ print $1; }')
1.69 + inode_d=$(ls -i "${dest}" 2>/dev/null |"${awk}" '{ print $1; }' || true)
1.70 + if [ "${inode_s}" != "${inode_d}" ]; then
1.71 + cp "${source}" "${dest}"
1.72 + fi
1.73 +}
1.74 +
1.75 +if [ "${CT_TOP_DIR}" = "${CT_LIB_DIR}" ]; then
1.76 + samp_top_dir="\${CT_LIB_DIR}"
1.77 +else
1.78 + samp_top_dir="\${CT_TOP_DIR}"
1.79 +fi
1.80 +
1.81 +# Save the uClibc .config file
1.82 +if [ -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" ]; then
1.83 + # We save the file, and then point the saved sample to this file
1.84 + CT_DoAddFileToSample "${CT_LIBC_UCLIBC_CONFIG_FILE}" "samples/${CT_TARGET}/${CT_LIBC}-${CT_LIBC_VERSION}.config"
1.85 + "${sed}" -r -i -e 's|^(CT_LIBC_UCLIBC_CONFIG_FILE=).+$|\1"'"${samp_top_dir}"'/samples/${CT_TARGET}/${CT_LIBC}-${CT_LIBC_VERSION}.config"|;' \
1.86 + "samples/${CT_TARGET}/crosstool.config"
1.87 +else
1.88 + # remove any dangling files
1.89 + for f in "samples/${CT_TARGET}/${CT_LIBC}-"*.config; do
1.90 + if [ -f "${f}" ]; then rm -f "${f}"; fi
1.91 + done
1.92 +fi
1.93 +
1.94 +# Restore stdout now, to be interactive
1.95 +exec >&7
1.96 +
1.97 +# Fill-in the reported-by info
1.98 +[ -f "samples/${CT_TARGET}/reported.by" ] && . "samples/${CT_TARGET}/reported.by"
1.99 +old_name="${reporter_name}"
1.100 +old_url="${reporter_url}"
1.101 +read -p "Reporter name [${reporter_name}]: " reporter_name
1.102 +read -p "Reporter URL [${reporter_url}]: " reporter_url
1.103 +if [ -n "${reporter_comment}" ]; then
1.104 + echo "Old comment if you need to copy-paste:"
1.105 + printf "${reporter_comment}\n"
1.106 +fi
1.107 +echo "Reporter comment (Ctrl-D to finish):"
1.108 +reporter_comment=$(cat)
1.109 +
1.110 +( echo "reporter_name=\"${reporter_name:=${old_name}}\""
1.111 + echo "reporter_url=\"${reporter_url:=${old_url}}\""
1.112 + printf "reporter_comment=\"${reporter_comment}\"\n"
1.113 +) >"samples/${CT_TARGET}/reported.by"