2010-10-22 20:02:49 +00:00
|
|
|
# This file contains some usefull common functions -*- sh -*-
|
2007-02-24 11:00:05 +00:00
|
|
|
# Copyright 2007 Yann E. MORIN
|
|
|
|
# Licensed under the GPL v2. See COPYING in the root of this package
|
|
|
|
|
2007-05-27 20:22:06 +00:00
|
|
|
# Prepare the fault handler
|
2007-02-24 11:00:05 +00:00
|
|
|
CT_OnError() {
|
|
|
|
ret=$?
|
2008-07-26 09:22:42 +00:00
|
|
|
# Bail out early in subshell, the upper level shell will act accordingly.
|
|
|
|
[ ${BASH_SUBSHELL} -eq 0 ] || exit $ret
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog ERROR "Build failed in step '${CT_STEP_MESSAGE[${CT_STEP_COUNT}]}'"
|
2007-02-24 11:00:05 +00:00
|
|
|
for((step=(CT_STEP_COUNT-1); step>1; step--)); do
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog ERROR " called in step '${CT_STEP_MESSAGE[${step}]}'"
|
2007-02-24 11:00:05 +00:00
|
|
|
done
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog ERROR "Error happened in '${BASH_SOURCE[1]}' in function '${FUNCNAME[1]}' (line unknown, sorry)"
|
2007-02-24 11:00:05 +00:00
|
|
|
for((depth=2; ${BASH_LINENO[$((${depth}-1))]}>0; depth++)); do
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog ERROR " called from '${BASH_SOURCE[${depth}]}' at line # ${BASH_LINENO[${depth}-1]} in function '${FUNCNAME[${depth}]}'"
|
2007-02-24 11:00:05 +00:00
|
|
|
done
|
2008-05-20 21:32:39 +00:00
|
|
|
[ "${CT_LOG_TO_FILE}" = "y" ] && CT_DoLog ERROR "Look at '${CT_LOG_FILE}' for more info on this error."
|
2007-05-17 16:22:51 +00:00
|
|
|
CT_STEP_COUNT=1
|
|
|
|
CT_DoEnd ERROR
|
2007-02-24 11:00:05 +00:00
|
|
|
exit $ret
|
|
|
|
}
|
2007-05-27 20:22:06 +00:00
|
|
|
|
|
|
|
# Install the fault handler
|
2007-02-24 11:00:05 +00:00
|
|
|
trap CT_OnError ERR
|
|
|
|
|
2007-05-27 20:22:06 +00:00
|
|
|
# Inherit the fault handler in subshells and functions
|
2007-02-24 11:00:05 +00:00
|
|
|
set -E
|
2007-05-27 20:22:06 +00:00
|
|
|
|
|
|
|
# Make pipes fail on the _first_ failed command
|
|
|
|
# Not supported on bash < 3.x, but we need it, so drop the obsoleting bash-2.x
|
2007-02-24 11:00:05 +00:00
|
|
|
set -o pipefail
|
|
|
|
|
2007-05-27 20:22:06 +00:00
|
|
|
# Don't hash commands' locations, and search every time it is requested.
|
|
|
|
# This is slow, but needed because of the static/shared core gcc which shall
|
|
|
|
# always match to shared if it exists, and only fallback to static if the
|
|
|
|
# shared is not found
|
|
|
|
set +o hashall
|
|
|
|
|
2007-06-16 22:23:53 +00:00
|
|
|
# Log policy:
|
|
|
|
# - first of all, save stdout so we can see the live logs: fd #6
|
|
|
|
exec 6>&1
|
|
|
|
# - then point stdout to the log file (temporary for now)
|
|
|
|
tmp_log_file="${CT_TOP_DIR}/log.$$"
|
|
|
|
exec >>"${tmp_log_file}"
|
|
|
|
|
2007-02-24 11:00:05 +00:00
|
|
|
# The different log levels:
|
|
|
|
CT_LOG_LEVEL_ERROR=0
|
|
|
|
CT_LOG_LEVEL_WARN=1
|
|
|
|
CT_LOG_LEVEL_INFO=2
|
|
|
|
CT_LOG_LEVEL_EXTRA=3
|
2010-10-22 20:02:57 +00:00
|
|
|
CT_LOG_LEVEL_CFG=4
|
|
|
|
CT_LOG_LEVEL_FILE=5
|
2010-10-22 20:02:49 +00:00
|
|
|
CT_LOG_LEVEL_STATE=6
|
|
|
|
CT_LOG_LEVEL_ALL=7
|
|
|
|
CT_LOG_LEVEL_DEBUG=8
|
2007-02-24 11:00:05 +00:00
|
|
|
|
2008-11-28 23:33:04 +00:00
|
|
|
# Make it easy to use \n and !
|
2008-11-28 17:51:39 +00:00
|
|
|
CR=$(printf "\n")
|
2008-11-28 23:33:04 +00:00
|
|
|
BANG='!'
|
2008-11-28 17:51:39 +00:00
|
|
|
|
2007-02-24 11:00:05 +00:00
|
|
|
# A function to log what is happening
|
|
|
|
# Different log level are available:
|
|
|
|
# - ERROR: A serious, fatal error occurred
|
|
|
|
# - WARN: A non fatal, non serious error occurred, take your responsbility with the generated build
|
|
|
|
# - INFO: Informational messages
|
|
|
|
# - EXTRA: Extra informational messages
|
2010-10-22 20:02:57 +00:00
|
|
|
# - CFG: Output of various "./configure"-type scripts
|
|
|
|
# - FILE: File / archive unpacking.
|
2010-10-22 20:02:49 +00:00
|
|
|
# - STATE: State save & restore
|
Huge fixes to glibc build, so that we can build at least (and at last):
- use ports addon even when installing headers,
- use optimisation (-O) when installing headers, to avoid unnecessary warnings (thanks Robert P. J. DAY for pointing this out!),
- lowest kernel version to use is only X.Y.Z, not X.Y.Z.T,
- a bit of preparations for NPTL (RSN I hope),
- fix fixing the linker scripts (changing the backup file is kind of useless and stupid);
Shut uClibc finish step: there really is nothing to do;
Add a patch for glibc-2.3.6 weak aliases handling on some archs (ARM and ALPHA at least);
Did not catch the make errors: fixed the pattern matching in scripts/functions;
Introduce a new log level, ALL:
- send components' build messages there,
- DEBUG log level is destined only for crosstool-NG debug messages,
- migrate sub-actions to use appropriate log levels;
Update the armeb-unknown-linux-gnu sample:
- it builds!
- uses gcc-4.0.4 and glibc-2.3.6,
- updated to latest config options set.
2007-05-08 17:48:32 +00:00
|
|
|
# - ALL: Component's build messages
|
2010-10-22 20:02:49 +00:00
|
|
|
# - DEBUG: Internal debug messages
|
2007-02-24 11:00:05 +00:00
|
|
|
# Usage: CT_DoLog <level> [message]
|
|
|
|
# If message is empty, then stdin will be logged.
|
|
|
|
CT_DoLog() {
|
2007-04-23 20:30:34 +00:00
|
|
|
local max_level LEVEL level cur_l cur_L
|
|
|
|
local l
|
2007-02-24 11:00:05 +00:00
|
|
|
eval max_level="\${CT_LOG_LEVEL_${CT_LOG_LEVEL_MAX}}"
|
|
|
|
# Set the maximum log level to DEBUG if we have none
|
Huge fixes to glibc build, so that we can build at least (and at last):
- use ports addon even when installing headers,
- use optimisation (-O) when installing headers, to avoid unnecessary warnings (thanks Robert P. J. DAY for pointing this out!),
- lowest kernel version to use is only X.Y.Z, not X.Y.Z.T,
- a bit of preparations for NPTL (RSN I hope),
- fix fixing the linker scripts (changing the backup file is kind of useless and stupid);
Shut uClibc finish step: there really is nothing to do;
Add a patch for glibc-2.3.6 weak aliases handling on some archs (ARM and ALPHA at least);
Did not catch the make errors: fixed the pattern matching in scripts/functions;
Introduce a new log level, ALL:
- send components' build messages there,
- DEBUG log level is destined only for crosstool-NG debug messages,
- migrate sub-actions to use appropriate log levels;
Update the armeb-unknown-linux-gnu sample:
- it builds!
- uses gcc-4.0.4 and glibc-2.3.6,
- updated to latest config options set.
2007-05-08 17:48:32 +00:00
|
|
|
[ -z "${max_level}" ] && max_level=${CT_LOG_LEVEL_DEBUG}
|
2007-02-24 11:00:05 +00:00
|
|
|
|
2007-04-23 20:30:34 +00:00
|
|
|
LEVEL="$1"; shift
|
2007-02-24 11:00:05 +00:00
|
|
|
eval level="\${CT_LOG_LEVEL_${LEVEL}}"
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
cat -
|
|
|
|
else
|
2010-08-26 21:36:54 +00:00
|
|
|
printf "%s\n" "${*}"
|
2008-11-28 17:51:39 +00:00
|
|
|
fi |( IFS="${CR}" # We want the full lines, even leading spaces
|
2008-05-20 21:32:39 +00:00
|
|
|
_prog_bar_cpt=0
|
|
|
|
_prog_bar[0]='/'
|
|
|
|
_prog_bar[1]='-'
|
|
|
|
_prog_bar[2]='\'
|
|
|
|
_prog_bar[3]='|'
|
2007-02-24 11:00:05 +00:00
|
|
|
indent=$((2*CT_STEP_COUNT))
|
|
|
|
while read line; do
|
2007-04-23 20:30:34 +00:00
|
|
|
case "${CT_LOG_SEE_TOOLS_WARN},${line}" in
|
|
|
|
y,*"warning:"*) cur_L=WARN; cur_l=${CT_LOG_LEVEL_WARN};;
|
2007-05-20 13:48:26 +00:00
|
|
|
y,*"WARNING:"*) cur_L=WARN; cur_l=${CT_LOG_LEVEL_WARN};;
|
2007-04-23 20:30:34 +00:00
|
|
|
*"error:"*) cur_L=ERROR; cur_l=${CT_LOG_LEVEL_ERROR};;
|
2008-10-12 11:09:57 +00:00
|
|
|
*"make["*"]: *** ["*) cur_L=ERROR; cur_l=${CT_LOG_LEVEL_ERROR};;
|
2007-04-23 20:30:34 +00:00
|
|
|
*) cur_L="${LEVEL}"; cur_l="${level}";;
|
|
|
|
esac
|
2008-05-20 21:32:39 +00:00
|
|
|
# There will always be a log file (stdout, fd #1), be it /dev/null
|
|
|
|
printf "[%-5s]%*s%s%s\n" "${cur_L}" "${indent}" " " "${line}"
|
2007-04-23 20:30:34 +00:00
|
|
|
if [ ${cur_l} -le ${max_level} ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
# Only print to console (fd #6) if log level is high enough.
|
|
|
|
printf "\r[%-5s]%*s%s%s\n" "${cur_L}" "${indent}" " " "${line}" >&6
|
2007-05-09 13:11:04 +00:00
|
|
|
fi
|
|
|
|
if [ "${CT_LOG_PROGRESS_BAR}" = "y" ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
printf "\r[%02d:%02d] %s " $((SECONDS/60)) $((SECONDS%60)) "${_prog_bar[$((_prog_bar_cpt/10))]}" >&6
|
|
|
|
_prog_bar_cpt=$(((_prog_bar_cpt+1)%40))
|
2007-02-24 11:00:05 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
)
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2008-05-25 22:25:50 +00:00
|
|
|
# Execute an action, and log its messages
|
2009-03-13 10:34:53 +00:00
|
|
|
# Usage: [VAR=val...] CT_DoExecLog <level> <command [parameters...]>
|
2008-05-25 22:25:50 +00:00
|
|
|
CT_DoExecLog() {
|
|
|
|
local level="$1"
|
|
|
|
shift
|
2009-09-06 14:49:20 +00:00
|
|
|
CT_DoLog DEBUG "==> Executing: '${*}'"
|
2008-07-14 21:56:58 +00:00
|
|
|
"${@}" 2>&1 |CT_DoLog "${level}"
|
2008-05-25 22:25:50 +00:00
|
|
|
}
|
|
|
|
|
2007-05-17 16:22:51 +00:00
|
|
|
# Tail message to be logged whatever happens
|
|
|
|
# Usage: CT_DoEnd <level>
|
|
|
|
CT_DoEnd()
|
|
|
|
{
|
2007-05-29 19:56:21 +00:00
|
|
|
local level="$1"
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_STOP_DATE=$(CT_DoDate +%s%N)
|
|
|
|
CT_STOP_DATE_HUMAN=$(CT_DoDate +%Y%m%d.%H%M%S)
|
2008-06-20 11:58:13 +00:00
|
|
|
if [ "${level}" != "ERROR" ]; then
|
2008-06-19 15:31:04 +00:00
|
|
|
CT_DoLog "${level:-INFO}" "Build completed at ${CT_STOP_DATE_HUMAN}"
|
|
|
|
fi
|
2007-05-17 16:22:51 +00:00
|
|
|
elapsed=$((CT_STOP_DATE-CT_STAR_DATE))
|
|
|
|
elapsed_min=$((elapsed/(60*1000*1000*1000)))
|
2008-05-20 21:32:39 +00:00
|
|
|
elapsed_sec=$(printf "%02d" $(((elapsed%(60*1000*1000*1000))/(1000*1000*1000))))
|
|
|
|
elapsed_csec=$(printf "%02d" $(((elapsed%(1000*1000*1000))/(10*1000*1000))))
|
2007-05-29 19:56:21 +00:00
|
|
|
CT_DoLog ${level:-INFO} "(elapsed: ${elapsed_min}:${elapsed_sec}.${elapsed_csec})"
|
2007-05-17 16:22:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 15:50:34 +00:00
|
|
|
# Remove entries referring to . and other relative paths
|
2010-07-29 17:30:37 +00:00
|
|
|
# Usage: CT_SanitizePath
|
|
|
|
CT_SanitizePath() {
|
|
|
|
local new
|
2010-07-30 15:50:34 +00:00
|
|
|
local p
|
2010-07-29 17:30:37 +00:00
|
|
|
local IFS=:
|
|
|
|
for p in $PATH; do
|
2010-07-30 15:50:34 +00:00
|
|
|
# Only accept absolute paths;
|
|
|
|
# Note: as a special case the empty string in PATH is equivalent to .
|
|
|
|
if [ -n "${p}" -a -z "${p%%/*}" ]; then
|
2010-07-29 17:30:37 +00:00
|
|
|
new="${new}${new:+:}${p}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
PATH="${new}"
|
|
|
|
}
|
|
|
|
|
2007-05-17 16:22:51 +00:00
|
|
|
# Abort the execution with an error message
|
2007-02-24 11:00:05 +00:00
|
|
|
# Usage: CT_Abort <message>
|
|
|
|
CT_Abort() {
|
2007-05-23 21:08:24 +00:00
|
|
|
CT_DoLog ERROR "$1"
|
2007-02-24 11:00:05 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test a condition, and print a message if satisfied
|
|
|
|
# Usage: CT_Test <message> <tests>
|
|
|
|
CT_Test() {
|
|
|
|
local ret
|
|
|
|
local m="$1"
|
|
|
|
shift
|
2010-04-13 20:54:57 +00:00
|
|
|
CT_DoLog DEBUG "Testing '! ( $* )'"
|
2007-02-24 11:00:05 +00:00
|
|
|
test "$@" && CT_DoLog WARN "$m"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test a condition, and abort with an error message if satisfied
|
|
|
|
# Usage: CT_TestAndAbort <message> <tests>
|
|
|
|
CT_TestAndAbort() {
|
|
|
|
local m="$1"
|
|
|
|
shift
|
2010-04-13 20:54:57 +00:00
|
|
|
CT_DoLog DEBUG "Testing '! ( $* )'"
|
2007-02-24 11:00:05 +00:00
|
|
|
test "$@" && CT_Abort "$m"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test a condition, and abort with an error message if not satisfied
|
|
|
|
# Usage: CT_TestAndAbort <message> <tests>
|
|
|
|
CT_TestOrAbort() {
|
|
|
|
local m="$1"
|
|
|
|
shift
|
2010-04-13 20:54:57 +00:00
|
|
|
CT_DoLog DEBUG "Testing '$*'"
|
2007-02-24 11:00:05 +00:00
|
|
|
test "$@" || CT_Abort "$m"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test the presence of a tool, or abort if not found
|
|
|
|
# Usage: CT_HasOrAbort <tool>
|
|
|
|
CT_HasOrAbort() {
|
2008-08-09 17:40:44 +00:00
|
|
|
CT_TestAndAbort "'${1}' not found and needed for successful toolchain build." -z "$(CT_Which "${1}")"
|
2007-02-24 11:00:05 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2007-07-07 09:58:14 +00:00
|
|
|
# Search a program: wrap "which" for those system where
|
2009-03-04 18:25:58 +00:00
|
|
|
# "which" verbosely says there is no match (Mandriva is
|
|
|
|
# such a sucker...)
|
2007-07-07 09:58:14 +00:00
|
|
|
# Usage: CT_Which <filename>
|
|
|
|
CT_Which() {
|
|
|
|
which "$1" 2>/dev/null || true
|
|
|
|
}
|
|
|
|
|
2007-02-24 11:00:05 +00:00
|
|
|
# Get current date with nanosecond precision
|
|
|
|
# On those system not supporting nanosecond precision, faked with rounding down
|
|
|
|
# to the highest entire second
|
|
|
|
# Usage: CT_DoDate <fmt>
|
|
|
|
CT_DoDate() {
|
2010-02-02 23:24:24 +00:00
|
|
|
date "$1" |sed -r -e 's/N$/000000000/;'
|
2007-02-24 11:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CT_STEP_COUNT=1
|
|
|
|
CT_STEP_MESSAGE[${CT_STEP_COUNT}]="<none>"
|
|
|
|
# Memorise a step being done so that any error is caught
|
|
|
|
# Usage: CT_DoStep <loglevel> <message>
|
|
|
|
CT_DoStep() {
|
2008-05-20 21:32:39 +00:00
|
|
|
local start=$(CT_DoDate +%s%N)
|
2007-02-24 11:00:05 +00:00
|
|
|
CT_DoLog "$1" "================================================================="
|
|
|
|
CT_DoLog "$1" "$2"
|
|
|
|
CT_STEP_COUNT=$((CT_STEP_COUNT+1))
|
|
|
|
CT_STEP_LEVEL[${CT_STEP_COUNT}]="$1"; shift
|
|
|
|
CT_STEP_START[${CT_STEP_COUNT}]="${start}"
|
|
|
|
CT_STEP_MESSAGE[${CT_STEP_COUNT}]="$1"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# End the step just being done
|
|
|
|
# Usage: CT_EndStep
|
|
|
|
CT_EndStep() {
|
2008-05-20 21:32:39 +00:00
|
|
|
local stop=$(CT_DoDate +%s%N)
|
|
|
|
local duration=$(printf "%032d" $((stop-${CT_STEP_START[${CT_STEP_COUNT}]})) |sed -r -e 's/([[:digit:]]{2})[[:digit:]]{7}$/\.\1/; s/^0+//; s/^\./0\./;')
|
2008-06-19 15:31:04 +00:00
|
|
|
local elapsed=$(printf "%02d:%02d" $((SECONDS/60)) $((SECONDS%60)))
|
2007-02-24 11:00:05 +00:00
|
|
|
local level="${CT_STEP_LEVEL[${CT_STEP_COUNT}]}"
|
|
|
|
local message="${CT_STEP_MESSAGE[${CT_STEP_COUNT}]}"
|
|
|
|
CT_STEP_COUNT=$((CT_STEP_COUNT-1))
|
2008-06-19 15:31:04 +00:00
|
|
|
CT_DoLog "${level}" "${message}: done in ${duration}s (at ${elapsed})"
|
2007-02-24 11:00:05 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Pushes into a directory, and pops back
|
|
|
|
CT_Pushd() {
|
|
|
|
pushd "$1" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
CT_Popd() {
|
|
|
|
popd >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Creates a temporary directory
|
|
|
|
# $1: variable to assign to
|
|
|
|
# Usage: CT_MktempDir foo
|
|
|
|
CT_MktempDir() {
|
|
|
|
# Some mktemp do not allow more than 6 Xs
|
2009-01-04 12:43:54 +00:00
|
|
|
eval "$1"=$(mktemp -q -d "${CT_BUILD_DIR}/tmp.XXXXXX")
|
2007-02-24 11:00:05 +00:00
|
|
|
CT_TestOrAbort "Could not make temporary directory" -n "${!1}" -a -d "${!1}"
|
2008-08-11 12:22:47 +00:00
|
|
|
CT_DoLog DEBUG "Made temporary directory '${!1}'"
|
|
|
|
return 0
|
2007-02-24 11:00:05 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 20:10:50 +00:00
|
|
|
# Removes one or more directories, even if it is read-only, or its parent is
|
2009-01-12 21:35:23 +00:00
|
|
|
# Usage: CT_DoForceRmdir dir [...]
|
|
|
|
CT_DoForceRmdir() {
|
2009-01-20 20:10:50 +00:00
|
|
|
local dir
|
|
|
|
local mode
|
|
|
|
for dir in "${@}"; do
|
|
|
|
[ -d "${dir}" ] || continue
|
2010-05-19 16:22:32 +00:00
|
|
|
case "$CT_SYS_OS" in
|
2010-07-17 22:34:38 +00:00
|
|
|
Linux|CYGWIN*)
|
2010-05-19 16:22:32 +00:00
|
|
|
mode="$(stat -c '%a' "$(dirname "${dir}")")"
|
|
|
|
;;
|
|
|
|
Darwin|*BSD)
|
|
|
|
mode="$(stat -f '%Lp' "$(dirname "${dir}")")"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
CT_Abort "Unhandled host OS $CT_SYS_OS"
|
|
|
|
;;
|
|
|
|
esac
|
2009-02-01 17:04:00 +00:00
|
|
|
CT_DoExecLog ALL chmod u+w "$(dirname "${dir}")"
|
|
|
|
CT_DoExecLog ALL chmod -R u+w "${dir}"
|
2009-01-20 20:10:50 +00:00
|
|
|
CT_DoExecLog ALL rm -rf "${dir}"
|
2009-02-01 17:04:00 +00:00
|
|
|
CT_DoExecLog ALL chmod ${mode} "$(dirname "${dir}")"
|
2009-01-20 20:10:50 +00:00
|
|
|
done
|
2009-01-12 21:35:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-24 11:00:05 +00:00
|
|
|
# Echoes the specified string on stdout until the pipe breaks.
|
|
|
|
# Doesn't fail
|
|
|
|
# $1: string to echo
|
|
|
|
# Usage: CT_DoYes "" |make oldconfig
|
|
|
|
CT_DoYes() {
|
|
|
|
yes "$1" || true
|
|
|
|
}
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2009-05-27 21:07:37 +00:00
|
|
|
# Add the specified directory to LD_LIBRARY_PATH, and export it
|
|
|
|
# If the specified patch is already present, just export
|
|
|
|
# $1: path to add
|
|
|
|
# $2: add as 'first' or 'last' path, 'first' is assumed if $2 is empty
|
|
|
|
# Usage CT_SetLibPath /some/where/lib [first|last]
|
|
|
|
CT_SetLibPath() {
|
|
|
|
local path="$1"
|
|
|
|
local pos="$2"
|
|
|
|
|
|
|
|
case ":${LD_LIBRARY_PATH}:" in
|
|
|
|
*:"${path}":*) ;;
|
|
|
|
*) case "${pos}" in
|
|
|
|
last)
|
|
|
|
CT_DoLog DEBUG "Adding '${path}' at end of LD_LIBRARY_PATH"
|
|
|
|
LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}${path}"
|
|
|
|
;;
|
|
|
|
first|"")
|
|
|
|
CT_DoLog DEBUG "Adding '${path}' at start of LD_LIBRARY_PATH"
|
|
|
|
LD_LIBRARY_PATH="${path}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
CT_Abort "Incorrect position '${pos}' to add '${path}' to LD_LIBRARY_PATH"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
CT_DoLog DEBUG "==> LD_LIBRARY_PATH='${LD_LIBRARY_PATH}'"
|
|
|
|
export LD_LIBRARY_PATH
|
|
|
|
}
|
|
|
|
|
2007-05-10 21:33:35 +00:00
|
|
|
# Get the file name extension of a component
|
2008-07-25 10:02:43 +00:00
|
|
|
# Usage: CT_GetFileExtension <component_name-component_version> [extension]
|
2009-11-29 23:05:45 +00:00
|
|
|
# If found, echoes the extension to stdout, and return 0
|
|
|
|
# If not found, echoes nothing on stdout, and return !0.
|
2007-05-10 21:33:35 +00:00
|
|
|
CT_GetFileExtension() {
|
|
|
|
local ext
|
|
|
|
local file="$1"
|
2008-07-25 10:02:43 +00:00
|
|
|
shift
|
|
|
|
local first_ext="$1"
|
2007-05-10 21:33:35 +00:00
|
|
|
|
2007-06-16 18:04:05 +00:00
|
|
|
# we need to also check for an empty extension for those very
|
|
|
|
# peculiar components that don't have one (such as sstrip from
|
|
|
|
# buildroot).
|
2010-01-14 19:54:47 +00:00
|
|
|
for ext in ${first_ext} .tar.gz .tar.bz2 .tgz .tar /.git ''; do
|
|
|
|
if [ -e "${CT_TARBALLS_DIR}/${file}${ext}" ]; then
|
2007-05-10 21:33:35 +00:00
|
|
|
echo "${ext}"
|
2009-11-29 23:05:45 +00:00
|
|
|
exit 0
|
2007-05-10 21:33:35 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2009-11-29 23:05:45 +00:00
|
|
|
exit 1
|
2007-05-10 21:33:35 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 16:49:15 +00:00
|
|
|
# Try to retrieve the specified URL (HTTP or FTP)
|
|
|
|
# Usage: CT_DoGetFile <URL>
|
|
|
|
# This functions always returns true (0), as it can be legitimate not
|
|
|
|
# to find the requested URL (think about snapshots, different layouts
|
|
|
|
# for different gcc versions, etc...).
|
|
|
|
CT_DoGetFile() {
|
2010-11-28 23:26:39 +00:00
|
|
|
local dest="${1##*/}"
|
|
|
|
local tmp="${dest}.tmp-dl"
|
2010-11-16 16:49:15 +00:00
|
|
|
# OK, just look if we have them...
|
|
|
|
# We are sure at least one is available, ./configure checked for it.
|
|
|
|
local _curl=$(CT_Which curl)
|
|
|
|
local _wget=$(CT_Which wget)
|
|
|
|
_curl="${_curl:-false}"
|
|
|
|
_wget="${_wget:-false}"
|
|
|
|
|
2010-11-28 23:26:39 +00:00
|
|
|
# Remove potential left-over from a previous run
|
|
|
|
rm -f "${tmp}"
|
|
|
|
|
2007-05-07 09:04:02 +00:00
|
|
|
# Some (very old!) FTP server might not support the passive mode, thus
|
2010-11-16 16:49:15 +00:00
|
|
|
# retry without.
|
|
|
|
# We also retry a few times, in case there is a transient error (eg. behind
|
|
|
|
# a dynamic IP that changes during the transfer...)
|
|
|
|
# With automated download as we are doing, it can be very dangerous to
|
|
|
|
# continue the downloads. It's far better to simply overwrite the
|
|
|
|
# destination file.
|
2008-05-06 20:30:49 +00:00
|
|
|
# Some company networks have firewalls to connect to the internet, but it's
|
2009-01-04 12:43:54 +00:00
|
|
|
# not easy to detect them, and wget does not timeout by default while
|
2008-05-06 20:30:49 +00:00
|
|
|
# connecting, so force a global ${CT_CONNECT_TIMEOUT}-second timeout.
|
2010-11-16 16:49:15 +00:00
|
|
|
# For curl, no good progress indicator is available. So, be silent.
|
2010-11-28 23:26:39 +00:00
|
|
|
if CT_DoExecLog ALL "${_curl}" --ftp-pasv --retry 3 --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f -s -o "${tmp}" "$1" \
|
|
|
|
|| CT_DoExecLog ALL "${_curl}" --retry 3 --connect-timeout ${CT_CONNECT_TIMEOUT} -L -f -s -o "${tmp}" "$1" \
|
|
|
|
|| CT_DoExecLog ALL "${_wget}" --passive-ftp --tries=3 -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary -O "${tmp}" "$1" \
|
|
|
|
|| CT_DoExecLog ALL "${_wget}" --tries=3 -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary -O "${tmp}" "$1" \
|
|
|
|
; then
|
|
|
|
# One of them succeeded, good!
|
|
|
|
mv "${tmp}" "${dest}"
|
|
|
|
else
|
|
|
|
# Woops...
|
|
|
|
rm -f "${tmp}"
|
|
|
|
fi
|
2007-05-07 09:04:02 +00:00
|
|
|
}
|
|
|
|
|
2009-01-04 12:43:54 +00:00
|
|
|
# This function tries to retrieve a tarball form a local directory
|
|
|
|
# Usage: CT_GetLocal <basename> [.extension]
|
|
|
|
CT_GetLocal() {
|
|
|
|
local basename="$1"
|
|
|
|
local first_ext="$2"
|
|
|
|
local ext
|
|
|
|
|
|
|
|
# Do we already have it in *our* tarballs dir?
|
2009-11-29 23:05:45 +00:00
|
|
|
if ext="$( CT_GetFileExtension "${basename}" ${first_ext} )"; then
|
2009-01-04 12:43:54 +00:00
|
|
|
CT_DoLog DEBUG "Already have '${basename}'"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${CT_LOCAL_TARBALLS_DIR}" ]; then
|
|
|
|
CT_DoLog DEBUG "Trying to retrieve an already downloaded copy of '${basename}'"
|
|
|
|
# We'd rather have a bzip2'ed tarball, then gzipped tarball, plain tarball,
|
|
|
|
# or, as a failover, a file without extension.
|
|
|
|
for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
|
|
|
|
CT_DoLog DEBUG "Trying '${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}'"
|
|
|
|
if [ -r "${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}" -a \
|
|
|
|
"${CT_FORCE_DOWNLOAD}" != "y" ]; then
|
|
|
|
CT_DoLog DEBUG "Got '${basename}' from local storage"
|
|
|
|
CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}" "${CT_TARBALLS_DIR}/${basename}${ext}"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# This function saves the specified to local storage if possible,
|
|
|
|
# and if so, symlinks it for later usage
|
|
|
|
# Usage: CT_SaveLocal </full/path/file.name>
|
|
|
|
CT_SaveLocal() {
|
|
|
|
local file="$1"
|
|
|
|
local basename="${file##*/}"
|
|
|
|
|
|
|
|
if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
|
2009-01-12 18:54:34 +00:00
|
|
|
CT_DoLog EXTRA "Saving '${basename}' to local storage"
|
2009-01-04 12:43:54 +00:00
|
|
|
# The file may already exist if downloads are forced: remove it first
|
|
|
|
CT_DoExecLog ALL rm -f "${CT_LOCAL_TARBALLS_DIR}/${basename}"
|
|
|
|
CT_DoExecLog ALL mv -f "${file}" "${CT_LOCAL_TARBALLS_DIR}"
|
|
|
|
CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${basename}" "${file}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-05-07 09:04:02 +00:00
|
|
|
# Download the file from one of the URLs passed as argument
|
2009-01-04 12:43:54 +00:00
|
|
|
# Usage: CT_GetFile <basename> [.extension] <url> [url ...]
|
2007-05-07 09:04:02 +00:00
|
|
|
CT_GetFile() {
|
|
|
|
local ext
|
2009-01-31 13:15:18 +00:00
|
|
|
local url URLS LAN_URLS
|
2007-05-07 09:04:02 +00:00
|
|
|
local file="$1"
|
2009-01-04 12:43:54 +00:00
|
|
|
local first_ext
|
2007-05-07 09:04:02 +00:00
|
|
|
shift
|
2008-07-24 06:42:29 +00:00
|
|
|
# If next argument starts with a dot, then this is not an URL,
|
|
|
|
# and we can consider that it is a preferred extension.
|
2007-07-12 19:52:09 +00:00
|
|
|
case "$1" in
|
2008-07-24 06:42:29 +00:00
|
|
|
.*) first_ext="$1"
|
2007-07-12 19:52:09 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2009-01-04 12:43:54 +00:00
|
|
|
# Does it exist localy?
|
|
|
|
CT_GetLocal "${file}" ${first_ext} && return 0 || true
|
|
|
|
# No, it does not...
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2008-08-01 09:23:58 +00:00
|
|
|
# Try to retrieve the file
|
2008-08-12 07:47:19 +00:00
|
|
|
CT_DoLog EXTRA "Retrieving '${file}'"
|
2007-05-07 09:04:02 +00:00
|
|
|
CT_Pushd "${CT_TARBALLS_DIR}"
|
2008-08-01 09:23:58 +00:00
|
|
|
|
2009-01-31 13:15:18 +00:00
|
|
|
URLS="$@"
|
|
|
|
|
2008-10-31 18:27:27 +00:00
|
|
|
# Add URLs on the LAN mirror
|
|
|
|
LAN_URLS=
|
|
|
|
if [ "${CT_USE_MIRROR}" = "y" ]; then
|
2009-04-19 16:58:21 +00:00
|
|
|
CT_TestOrAbort "Please set the mirror base URL" -n "${CT_MIRROR_BASE_URL}"
|
|
|
|
LAN_URLS="${LAN_URLS} ${CT_MIRROR_BASE_URL}/${file%-*}"
|
|
|
|
LAN_URLS="${LAN_URLS} ${CT_MIRROR_BASE_URL}"
|
2008-10-31 18:27:27 +00:00
|
|
|
|
2009-01-12 18:54:34 +00:00
|
|
|
if [ "${CT_PREFER_MIRROR}" = "y" ]; then
|
|
|
|
CT_DoLog DEBUG "Pre-pending LAN mirror URLs"
|
2009-01-31 13:15:18 +00:00
|
|
|
URLS="${LAN_URLS} ${URLS}"
|
2009-01-12 18:54:34 +00:00
|
|
|
else
|
|
|
|
CT_DoLog DEBUG "Appending LAN mirror URLs"
|
2009-01-31 13:15:18 +00:00
|
|
|
URLS="${URLS} ${LAN_URLS}"
|
2009-01-12 18:54:34 +00:00
|
|
|
fi
|
2008-07-19 22:45:17 +00:00
|
|
|
fi
|
|
|
|
|
2008-10-31 18:27:27 +00:00
|
|
|
# Scan all URLs in turn, and try to grab a tarball from there
|
2010-01-14 19:54:47 +00:00
|
|
|
# Do *not* try git trees (ext=/.git), this is handled in a specific
|
|
|
|
# wrapper, below
|
2007-07-12 19:52:09 +00:00
|
|
|
for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
|
2007-05-18 15:54:42 +00:00
|
|
|
# Try all urls in turn
|
2008-10-31 18:27:27 +00:00
|
|
|
for url in ${URLS}; do
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG "Trying '${url}/${file}${ext}'"
|
2007-07-15 17:00:30 +00:00
|
|
|
CT_DoGetFile "${url}/${file}${ext}"
|
|
|
|
if [ -f "${file}${ext}" ]; then
|
2008-08-17 14:13:00 +00:00
|
|
|
CT_DoLog DEBUG "Got '${file}' from the Internet"
|
2009-01-04 12:43:54 +00:00
|
|
|
CT_SaveLocal "${CT_TARBALLS_DIR}/${file}${ext}"
|
2007-07-15 17:00:30 +00:00
|
|
|
return 0
|
|
|
|
fi
|
2007-05-18 15:54:42 +00:00
|
|
|
done
|
|
|
|
done
|
2007-05-07 09:04:02 +00:00
|
|
|
CT_Popd
|
|
|
|
|
2008-08-01 09:23:58 +00:00
|
|
|
CT_Abort "Could not retrieve '${file}'."
|
2007-05-07 09:04:02 +00:00
|
|
|
}
|
|
|
|
|
2009-01-04 12:43:54 +00:00
|
|
|
# Checkout from CVS, and build the associated tarball
|
|
|
|
# The tarball will be called ${basename}.tar.bz2
|
|
|
|
# Prerequisite: either the server does not require password,
|
|
|
|
# or the user must already be logged in.
|
|
|
|
# 'tag' is the tag to retrieve. Must be specified, but can be empty.
|
|
|
|
# If dirname is specified, then module will be renamed to dirname
|
|
|
|
# prior to building the tarball.
|
2009-10-26 18:49:50 +00:00
|
|
|
# Usage: CT_GetCVS <basename> <url> <module> <tag> [dirname[=subdir]]
|
|
|
|
# Note: if '=subdir' is given, then it is used instead of 'module'.
|
2009-01-04 12:43:54 +00:00
|
|
|
CT_GetCVS() {
|
|
|
|
local basename="$1"
|
|
|
|
local uri="$2"
|
|
|
|
local module="$3"
|
|
|
|
local tag="${4:+-r ${4}}"
|
|
|
|
local dirname="$5"
|
|
|
|
local tmp_dir
|
|
|
|
|
|
|
|
# Does it exist localy?
|
|
|
|
CT_GetLocal "${basename}" && return 0 || true
|
|
|
|
# No, it does not...
|
|
|
|
|
|
|
|
CT_DoLog EXTRA "Retrieving '${basename}'"
|
|
|
|
|
|
|
|
CT_MktempDir tmp_dir
|
|
|
|
CT_Pushd "${tmp_dir}"
|
|
|
|
|
|
|
|
CT_DoExecLog ALL cvs -z 9 -d "${uri}" co -P ${tag} "${module}"
|
2009-10-26 18:49:50 +00:00
|
|
|
if [ -n "${dirname}" ]; then
|
|
|
|
case "${dirname}" in
|
|
|
|
*=*)
|
2009-10-26 21:00:30 +00:00
|
|
|
CT_DoExecLog DEBUG mv "${dirname#*=}" "${dirname%%=*}"
|
|
|
|
CT_DoExecLog ALL tar cjf "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${dirname%%=*}"
|
2009-10-26 18:49:50 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
CT_DoExecLog ALL mv "${module}" "${dirname}"
|
|
|
|
CT_DoExecLog ALL tar cjf "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${dirname:-${module}}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2009-01-04 12:43:54 +00:00
|
|
|
CT_SaveLocal "${CT_TARBALLS_DIR}/${basename}.tar.bz2"
|
|
|
|
|
|
|
|
CT_Popd
|
2009-03-08 11:14:54 +00:00
|
|
|
CT_DoExecLog ALL rm -rf "${tmp_dir}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check out from SVN, and build the associated tarball
|
|
|
|
# The tarball will be called ${basename}.tar.bz2
|
|
|
|
# Prerequisite: either the server does not require password,
|
|
|
|
# or the user must already be logged in.
|
|
|
|
# 'rev' is the revision to retrieve
|
|
|
|
# Usage: CT_GetSVN <basename> <url> [rev]
|
|
|
|
CT_GetSVN() {
|
|
|
|
local basename="$1"
|
|
|
|
local uri="$2"
|
|
|
|
local rev="$3"
|
|
|
|
|
|
|
|
# Does it exist localy?
|
|
|
|
CT_GetLocal "${basename}" && return 0 || true
|
|
|
|
# No, it does not...
|
|
|
|
|
|
|
|
CT_DoLog EXTRA "Retrieving '${basename}'"
|
|
|
|
|
|
|
|
CT_MktempDir tmp_dir
|
|
|
|
CT_Pushd "${tmp_dir}"
|
|
|
|
|
|
|
|
CT_DoExecLog ALL svn export ${rev:+-r ${rev}} "${uri}" "${basename}"
|
|
|
|
CT_DoExecLog ALL tar cjf "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${basename}"
|
|
|
|
CT_SaveLocal "${CT_TARBALLS_DIR}/${basename}.tar.bz2"
|
|
|
|
|
|
|
|
CT_Popd
|
2009-01-04 12:43:54 +00:00
|
|
|
CT_DoExecLog ALL rm -rf "${tmp_dir}"
|
|
|
|
}
|
|
|
|
|
2010-01-14 19:54:47 +00:00
|
|
|
# Clone a git tree
|
|
|
|
# Tries the given URLs in turn until one can get cloned. No tarball will be created.
|
|
|
|
# Prerequisites: either the server does not require password,
|
|
|
|
# or the user has already taken any action to authenticate to the server.
|
|
|
|
# The cloned tree will *not* be stored in the local tarballs dir!
|
|
|
|
# Usage: CT_GetGit <basename> <url [url ...]>
|
|
|
|
CT_GetGit() {
|
|
|
|
local basename="$1"; shift
|
|
|
|
local url
|
|
|
|
local cloned=0
|
|
|
|
|
|
|
|
# Do we have it in our tarballs dir?
|
|
|
|
if [ -d "${CT_TARBALLS_DIR}/${basename}/.git" ]; then
|
|
|
|
CT_DoLog EXTRA "Updating git tree '${basename}'"
|
|
|
|
CT_Pushd "${CT_TARBALLS_DIR}/${basename}"
|
|
|
|
CT_DoExecLog ALL git pull
|
|
|
|
CT_Popd
|
|
|
|
else
|
|
|
|
CT_DoLog EXTRA "Retrieving git tree '${basename}'"
|
|
|
|
for url in "${@}"; do
|
|
|
|
CT_DoLog ALL "Trying to clone from '${url}'"
|
|
|
|
CT_DoForceRmdir "${CT_TARBALLS_DIR}/${basename}"
|
|
|
|
if git clone "${url}" "${CT_TARBALLS_DIR}/${basename}" 2>&1 |CT_DoLog ALL; then
|
|
|
|
cloned=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
CT_TestOrAbort "Could not clone '${basename}'" ${cloned} -ne 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-01-05 23:02:43 +00:00
|
|
|
# Extract a tarball
|
2007-05-07 09:04:02 +00:00
|
|
|
# Some tarballs need to be extracted in specific places. Eg.: glibc addons
|
|
|
|
# must be extracted in the glibc directory; uCLibc locales must be extracted
|
2009-01-04 22:17:53 +00:00
|
|
|
# in the extra/locale sub-directory of uClibc. This is taken into account
|
|
|
|
# by the caller, that did a 'cd' into the correct path before calling us
|
|
|
|
# and sets nochdir to 'nochdir'.
|
2010-01-14 19:54:47 +00:00
|
|
|
# Note also that this function handles the git trees!
|
|
|
|
# Usage: CT_Extract <basename> [nochdir] [options]
|
|
|
|
# where 'options' are dependent on the source (eg. git branch/tag...)
|
2009-01-05 23:02:43 +00:00
|
|
|
CT_Extract() {
|
2010-01-12 18:24:03 +00:00
|
|
|
local nochdir="$1"
|
|
|
|
local basename
|
2009-11-29 23:05:45 +00:00
|
|
|
local ext
|
|
|
|
|
2010-01-12 18:24:03 +00:00
|
|
|
if [ "${nochdir}" = "nochdir" ]; then
|
|
|
|
shift
|
|
|
|
nochdir="$(pwd)"
|
|
|
|
else
|
|
|
|
nochdir="${CT_SRC_DIR}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
basename="$1"
|
|
|
|
shift
|
|
|
|
|
2009-11-29 23:05:45 +00:00
|
|
|
if ! ext="$(CT_GetFileExtension "${basename}")"; then
|
2010-01-14 19:54:47 +00:00
|
|
|
CT_Abort "'${basename}' not found in '${CT_TARBALLS_DIR}'"
|
2009-11-29 23:05:45 +00:00
|
|
|
fi
|
2009-01-05 23:02:43 +00:00
|
|
|
local full_file="${CT_TARBALLS_DIR}/${basename}${ext}"
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2010-01-09 16:31:25 +00:00
|
|
|
# Check if already extracted
|
|
|
|
if [ -e "${CT_SRC_DIR}/.${basename}.extracted" ]; then
|
|
|
|
CT_DoLog DEBUG "Already extracted '${basename}'"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2009-11-30 20:34:50 +00:00
|
|
|
# Check if previously partially extracted
|
|
|
|
if [ -e "${CT_SRC_DIR}/.${basename}.extracting" ]; then
|
|
|
|
CT_DoLog ERROR "The '${basename}' sources were partially extracted."
|
|
|
|
CT_DoLog ERROR "Please remove first:"
|
|
|
|
CT_DoLog ERROR " - the source dir for '${basename}', in '${CT_SRC_DIR}'"
|
|
|
|
CT_DoLog ERROR " - the file '${CT_SRC_DIR}/.${basename}.extracting'"
|
|
|
|
CT_Abort "I'll stop now to avoid any carnage..."
|
|
|
|
fi
|
|
|
|
CT_DoExecLog DEBUG touch "${CT_SRC_DIR}/.${basename}.extracting"
|
|
|
|
|
2010-01-12 18:24:03 +00:00
|
|
|
CT_Pushd "${nochdir}"
|
2009-01-05 23:02:43 +00:00
|
|
|
|
|
|
|
CT_DoLog EXTRA "Extracting '${basename}'"
|
2007-05-07 09:04:02 +00:00
|
|
|
case "${ext}" in
|
2010-10-22 20:02:57 +00:00
|
|
|
.tar.bz2) CT_DoExecLog FILE tar xvjf "${full_file}";;
|
|
|
|
.tar.gz|.tgz) CT_DoExecLog FILE tar xvzf "${full_file}";;
|
|
|
|
.tar) CT_DoExecLog FILE tar xvf "${full_file}";;
|
2010-01-14 19:54:47 +00:00
|
|
|
/.git) CT_ExtractGit "${basename}" "${@}";;
|
|
|
|
*) CT_Abort "Don't know how to handle '${basename}${ext}': unknown extension";;
|
2007-05-07 09:04:02 +00:00
|
|
|
esac
|
2009-01-05 23:02:43 +00:00
|
|
|
|
2009-02-10 08:52:13 +00:00
|
|
|
# Some tarballs have read-only files... :-(
|
2009-03-15 20:06:40 +00:00
|
|
|
# Because of nochdir, we don't know where we are, so chmod all
|
|
|
|
# the src tree
|
2009-03-27 21:30:47 +00:00
|
|
|
CT_DoExecLog DEBUG chmod -R u+w "${CT_SRC_DIR}"
|
2009-02-10 08:52:13 +00:00
|
|
|
|
2010-01-14 19:54:47 +00:00
|
|
|
# Don't mark as being extracted for git
|
|
|
|
case "${ext}" in
|
|
|
|
/.git) ;;
|
|
|
|
*) CT_DoExecLog DEBUG touch "${CT_SRC_DIR}/.${basename}.extracted";;
|
|
|
|
esac
|
2009-11-30 20:34:50 +00:00
|
|
|
CT_DoExecLog DEBUG rm -f "${CT_SRC_DIR}/.${basename}.extracting"
|
2009-01-05 23:02:43 +00:00
|
|
|
|
2010-01-12 18:24:03 +00:00
|
|
|
CT_Popd
|
2009-01-05 23:02:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-14 19:54:47 +00:00
|
|
|
# Create a working git clone
|
|
|
|
# Usage: CT_ExtractGit <basename> [ref]
|
|
|
|
# where 'ref' is the reference to use:
|
|
|
|
# the full name of a branch, like "remotes/origin/branch_name"
|
|
|
|
# a date as understandable by git, like "YYYY-MM-DD[ hh[:mm[:ss]]]"
|
|
|
|
# a tag name
|
|
|
|
CT_ExtractGit() {
|
|
|
|
local basename="${1}"
|
|
|
|
local ref="${2}"
|
|
|
|
local clone_dir
|
|
|
|
local ref_type
|
|
|
|
|
|
|
|
# pushd now to be able to get git revlist in case ref is a date
|
|
|
|
clone_dir="${CT_TARBALLS_DIR}/${basename}"
|
|
|
|
CT_Pushd "${clone_dir}"
|
|
|
|
|
|
|
|
# What kind of reference is ${ref} ?
|
|
|
|
if [ -z "${ref}" ]; then
|
|
|
|
# Don't update the clone, keep as-is
|
|
|
|
ref_type=none
|
|
|
|
elif git tag |grep -E "^${ref}$" >/dev/null 2>&1; then
|
|
|
|
ref_type=tag
|
|
|
|
elif git branch -a --no-color |grep -E "^. ${ref}$" >/dev/null 2>&1; then
|
|
|
|
ref_type=branch
|
|
|
|
elif date -d "${ref}" >/dev/null 2>&1; then
|
|
|
|
ref_type=date
|
|
|
|
ref=$(git rev-list -n1 --before="${ref}")
|
|
|
|
else
|
|
|
|
CT_Abort "Reference '${ref}' is an incorrect git reference: neither tag, branch nor date"
|
|
|
|
fi
|
|
|
|
|
|
|
|
CT_DoExecLog DEBUG rm -f "${CT_SRC_DIR}/${basename}"
|
|
|
|
CT_DoExecLog ALL ln -sf "${clone_dir}" "${CT_SRC_DIR}/${basename}"
|
|
|
|
|
|
|
|
case "${ref_type}" in
|
|
|
|
none) ;;
|
2010-10-22 20:02:57 +00:00
|
|
|
*) CT_DoExecLog FILE git checkout "${ref}";;
|
2010-01-14 19:54:47 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
CT_Popd
|
|
|
|
}
|
|
|
|
|
2009-01-05 23:02:43 +00:00
|
|
|
# Patches the specified component
|
2010-01-12 18:24:03 +00:00
|
|
|
# See CT_Extract, above, for explanations on 'nochdir'
|
2010-04-11 21:18:10 +00:00
|
|
|
# Usage: CT_Patch [nochdir] <packagename> <packageversion>
|
|
|
|
# If the package directory is *not* packagename-packageversion, then
|
|
|
|
# the caller must cd into the proper directory first, and call us
|
|
|
|
# with nochdir
|
2009-01-05 23:02:43 +00:00
|
|
|
CT_Patch() {
|
2010-01-12 18:24:03 +00:00
|
|
|
local nochdir="$1"
|
2010-04-11 21:18:10 +00:00
|
|
|
local pkgname
|
|
|
|
local version
|
|
|
|
local pkgdir
|
2010-01-12 18:24:03 +00:00
|
|
|
local base_file
|
|
|
|
local ver_file
|
2009-08-31 10:05:52 +00:00
|
|
|
local d
|
|
|
|
local -a patch_dirs
|
|
|
|
local bundled_patch_dir
|
|
|
|
local local_patch_dir
|
2009-01-05 23:02:43 +00:00
|
|
|
|
2010-01-12 18:24:03 +00:00
|
|
|
if [ "${nochdir}" = "nochdir" ]; then
|
|
|
|
shift
|
2010-04-13 18:05:47 +00:00
|
|
|
pkgname="$1"
|
|
|
|
version="$2"
|
|
|
|
pkgdir="${pkgname}-${version}"
|
2010-01-12 18:24:03 +00:00
|
|
|
nochdir="$(pwd)"
|
|
|
|
else
|
2010-04-13 18:05:47 +00:00
|
|
|
pkgname="$1"
|
|
|
|
version="$2"
|
|
|
|
pkgdir="${pkgname}-${version}"
|
2010-04-11 21:18:10 +00:00
|
|
|
nochdir="${CT_SRC_DIR}/${pkgdir}"
|
2010-01-12 18:24:03 +00:00
|
|
|
fi
|
|
|
|
|
2009-01-05 23:02:43 +00:00
|
|
|
# Check if already patched
|
2010-04-11 21:18:10 +00:00
|
|
|
if [ -e "${CT_SRC_DIR}/.${pkgdir}.patched" ]; then
|
|
|
|
CT_DoLog DEBUG "Already patched '${pkgdir}'"
|
2009-01-05 23:02:43 +00:00
|
|
|
return 0
|
2007-05-07 09:04:02 +00:00
|
|
|
fi
|
|
|
|
|
2009-03-27 21:30:47 +00:00
|
|
|
# Check if already partially patched
|
2010-04-11 21:18:10 +00:00
|
|
|
if [ -e "${CT_SRC_DIR}/.${pkgdir}.patching" ]; then
|
|
|
|
CT_DoLog ERROR "The '${pkgdir}' sources were partially patched."
|
2009-03-27 21:30:47 +00:00
|
|
|
CT_DoLog ERROR "Please remove first:"
|
2010-04-11 21:18:10 +00:00
|
|
|
CT_DoLog ERROR " - the source dir for '${pkgdir}', in '${CT_SRC_DIR}'"
|
|
|
|
CT_DoLog ERROR " - the file '${CT_SRC_DIR}/.${pkgdir}.extracted'"
|
|
|
|
CT_DoLog ERROR " - the file '${CT_SRC_DIR}/.${pkgdir}.patching'"
|
2009-03-27 21:30:47 +00:00
|
|
|
CT_Abort "I'll stop now to avoid any carnage..."
|
|
|
|
fi
|
2010-04-11 21:18:10 +00:00
|
|
|
touch "${CT_SRC_DIR}/.${pkgdir}.patching"
|
2009-03-27 21:30:47 +00:00
|
|
|
|
2010-01-12 18:24:03 +00:00
|
|
|
CT_Pushd "${nochdir}"
|
2009-01-04 22:17:53 +00:00
|
|
|
|
2010-04-11 21:18:10 +00:00
|
|
|
CT_DoLog EXTRA "Patching '${pkgdir}'"
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2010-04-11 21:18:10 +00:00
|
|
|
bundled_patch_dir="${CT_LIB_DIR}/patches/${pkgname}/${version}"
|
|
|
|
local_patch_dir="${CT_LOCAL_PATCH_DIR}/${pkgname}/${version}"
|
2009-08-31 10:05:52 +00:00
|
|
|
|
|
|
|
case "${CT_PATCH_ORDER}" in
|
|
|
|
bundled) patch_dirs=("${bundled_patch_dir}");;
|
|
|
|
local) patch_dirs=("${local_patch_dir}");;
|
|
|
|
bundled,local) patch_dirs=("${bundled_patch_dir}" "${local_patch_dir}");;
|
2009-08-31 10:51:53 +00:00
|
|
|
local,bundled) patch_dirs=("${local_patch_dir}" "${bundled_patch_dir}");;
|
2009-11-16 19:15:45 +00:00
|
|
|
none) patch_dirs=;;
|
2009-08-31 10:05:52 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
for d in "${patch_dirs[@]}"; do
|
|
|
|
CT_DoLog DEBUG "Looking for patches in '${d}'..."
|
|
|
|
if [ -n "${d}" -a -d "${d}" ]; then
|
|
|
|
for p in "${d}"/*.patch; do
|
2007-05-07 09:04:02 +00:00
|
|
|
if [ -f "${p}" ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG "Applying patch '${p}'"
|
2010-01-31 11:07:44 +00:00
|
|
|
CT_DoExecLog ALL patch --no-backup-if-mismatch -g0 -F1 -p1 -f <"${p}"
|
2007-05-07 09:04:02 +00:00
|
|
|
fi
|
|
|
|
done
|
2009-08-31 10:47:58 +00:00
|
|
|
if [ "${CT_PATCH_SINGLE}" = "y" ]; then
|
|
|
|
break
|
|
|
|
fi
|
2007-05-07 09:04:02 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2008-05-15 20:45:18 +00:00
|
|
|
if [ "${CT_OVERIDE_CONFIG_GUESS_SUB}" = "y" ]; then
|
|
|
|
CT_DoLog ALL "Overiding config.guess and config.sub"
|
|
|
|
for cfg in config_guess config_sub; do
|
2008-12-16 18:12:34 +00:00
|
|
|
eval ${cfg}="${CT_LIB_DIR}/scripts/${cfg/_/.}"
|
|
|
|
[ -e "${CT_TOP_DIR}/scripts/${cfg/_/.}" ] && eval ${cfg}="${CT_TOP_DIR}/scripts/${cfg/_/.}"
|
2008-08-09 17:46:56 +00:00
|
|
|
# Can't use CT_DoExecLog because of the '{} \;' to be passed un-mangled to find
|
2008-05-15 20:45:18 +00:00
|
|
|
find . -type f -name "${cfg/_/.}" -exec cp -v "${!cfg}" {} \; |CT_DoLog ALL
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2010-04-12 22:07:00 +00:00
|
|
|
CT_DoExecLog DEBUG touch "${CT_SRC_DIR}/.${pkgdir}.patched"
|
|
|
|
CT_DoExecLog DEBUG rm -f "${CT_SRC_DIR}/.${pkgdir}.patching"
|
2009-01-05 23:02:43 +00:00
|
|
|
|
2010-01-12 18:24:03 +00:00
|
|
|
CT_Popd
|
2007-05-07 09:04:02 +00:00
|
|
|
}
|
|
|
|
|
2007-07-01 19:04:20 +00:00
|
|
|
# Two wrappers to call config.(guess|sub) either from CT_TOP_DIR or CT_LIB_DIR.
|
|
|
|
# Those from CT_TOP_DIR, if they exist, will be be more recent than those from CT_LIB_DIR.
|
|
|
|
CT_DoConfigGuess() {
|
2008-12-16 18:12:34 +00:00
|
|
|
if [ -x "${CT_TOP_DIR}/scripts/config.guess" ]; then
|
|
|
|
"${CT_TOP_DIR}/scripts/config.guess"
|
2007-07-01 19:04:20 +00:00
|
|
|
else
|
2008-12-16 18:12:34 +00:00
|
|
|
"${CT_LIB_DIR}/scripts/config.guess"
|
2007-07-01 19:04:20 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
CT_DoConfigSub() {
|
2008-12-16 18:12:34 +00:00
|
|
|
if [ -x "${CT_TOP_DIR}/scripts/config.sub" ]; then
|
|
|
|
"${CT_TOP_DIR}/scripts/config.sub" "$@"
|
2007-07-01 19:04:20 +00:00
|
|
|
else
|
2008-12-16 18:12:34 +00:00
|
|
|
"${CT_LIB_DIR}/scripts/config.sub" "$@"
|
2007-07-01 19:04:20 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-08-15 16:18:35 +00:00
|
|
|
# Compute the target tuple from what is provided by the user
|
|
|
|
# Usage: CT_DoBuildTargetTuple
|
2007-05-07 09:04:02 +00:00
|
|
|
# In fact this function takes the environment variables to build the target
|
2007-08-15 16:18:35 +00:00
|
|
|
# tuple. It is needed both by the normal build sequence, as well as the
|
2007-05-07 09:04:02 +00:00
|
|
|
# sample saving sequence.
|
2007-08-15 16:18:35 +00:00
|
|
|
CT_DoBuildTargetTuple() {
|
2007-09-14 21:17:59 +00:00
|
|
|
# Set the endianness suffix, and the default endianness gcc option
|
2007-05-07 09:04:02 +00:00
|
|
|
case "${CT_ARCH_BE},${CT_ARCH_LE}" in
|
2007-09-14 21:17:59 +00:00
|
|
|
y,) target_endian_eb=eb
|
|
|
|
target_endian_el=
|
2007-09-15 21:44:18 +00:00
|
|
|
CT_ARCH_ENDIAN_CFLAG="-mbig-endian"
|
2008-05-21 22:00:52 +00:00
|
|
|
CT_ARCH_ENDIAN_LDFLAG="-EB"
|
2007-09-14 21:17:59 +00:00
|
|
|
;;
|
|
|
|
,y) target_endian_eb=
|
|
|
|
target_endian_el=el
|
2007-09-15 21:44:18 +00:00
|
|
|
CT_ARCH_ENDIAN_CFLAG="-mlittle-endian"
|
2008-05-21 22:00:52 +00:00
|
|
|
CT_ARCH_ENDIAN_LDFLAG="-EL"
|
2007-09-14 21:17:59 +00:00
|
|
|
;;
|
2007-05-07 09:04:02 +00:00
|
|
|
esac
|
2007-09-14 21:17:59 +00:00
|
|
|
|
2008-10-23 13:45:48 +00:00
|
|
|
# Build the default architecture tuple part
|
|
|
|
CT_TARGET_ARCH="${CT_ARCH}"
|
|
|
|
|
2007-09-14 21:17:59 +00:00
|
|
|
# Set defaults for the system part of the tuple. Can be overriden
|
|
|
|
# by architecture-specific values.
|
|
|
|
case "${CT_LIBC}" in
|
2008-08-11 12:22:47 +00:00
|
|
|
*glibc) CT_TARGET_SYS=gnu;;
|
2007-09-14 21:17:59 +00:00
|
|
|
uClibc) CT_TARGET_SYS=uclibc;;
|
2009-10-21 20:51:39 +00:00
|
|
|
*) CT_TARGET_SYS=elf;;
|
2007-05-07 09:04:02 +00:00
|
|
|
esac
|
2007-09-14 21:17:59 +00:00
|
|
|
|
2007-09-15 21:44:18 +00:00
|
|
|
# Set the default values for ARCH, ABI, CPU, TUNE, FPU and FLOAT
|
2008-05-14 17:39:18 +00:00
|
|
|
unset CT_ARCH_ARCH_CFLAG CT_ARCH_ABI_CFLAG CT_ARCH_CPU_CFLAG CT_ARCH_TUNE_CFLAG CT_ARCH_FPU_CFLAG CT_ARCH_FLOAT_CFLAG
|
|
|
|
unset CT_ARCH_WITH_ARCH CT_ARCH_WITH_ABI CT_ARCH_WITH_CPU CT_ARCH_WITH_TUNE CT_ARCH_WITH_FPU CT_ARCH_WITH_FLOAT
|
2007-09-15 21:44:18 +00:00
|
|
|
[ "${CT_ARCH_ARCH}" ] && { CT_ARCH_ARCH_CFLAG="-march=${CT_ARCH_ARCH}"; CT_ARCH_WITH_ARCH="--with-arch=${CT_ARCH_ARCH}"; }
|
|
|
|
[ "${CT_ARCH_ABI}" ] && { CT_ARCH_ABI_CFLAG="-mabi=${CT_ARCH_ABI}"; CT_ARCH_WITH_ABI="--with-abi=${CT_ARCH_ABI}"; }
|
|
|
|
[ "${CT_ARCH_CPU}" ] && { CT_ARCH_CPU_CFLAG="-mcpu=${CT_ARCH_CPU}"; CT_ARCH_WITH_CPU="--with-cpu=${CT_ARCH_CPU}"; }
|
2007-10-30 19:13:51 +00:00
|
|
|
[ "${CT_ARCH_TUNE}" ] && { CT_ARCH_TUNE_CFLAG="-mtune=${CT_ARCH_TUNE}"; CT_ARCH_WITH_TUNE="--with-tune=${CT_ARCH_TUNE}"; }
|
2007-09-15 21:44:18 +00:00
|
|
|
[ "${CT_ARCH_FPU}" ] && { CT_ARCH_FPU_CFLAG="-mfpu=${CT_ARCH_FPU}"; CT_ARCH_WITH_FPU="--with-fpu=${CT_ARCH_FPU}"; }
|
2008-01-16 21:51:18 +00:00
|
|
|
[ "${CT_ARCH_FLOAT_SW}" ] && { CT_ARCH_FLOAT_CFLAG="-msoft-float"; CT_ARCH_WITH_FLOAT="--with-float=soft"; }
|
2007-09-15 21:44:18 +00:00
|
|
|
|
2008-10-23 13:45:48 +00:00
|
|
|
# Build the default kernel tuple part
|
|
|
|
CT_TARGET_KERNEL="${CT_KERNEL}"
|
2008-10-23 13:00:45 +00:00
|
|
|
|
2008-10-23 13:45:48 +00:00
|
|
|
# Overide the default values with the components specific settings
|
2008-10-23 13:00:45 +00:00
|
|
|
CT_DoArchTupleValues
|
2008-10-23 13:45:48 +00:00
|
|
|
CT_DoKernelTupleValues
|
2007-09-14 21:17:59 +00:00
|
|
|
|
2007-09-15 21:44:18 +00:00
|
|
|
# Finish the target tuple construction
|
2010-04-09 19:04:27 +00:00
|
|
|
CT_TARGET="${CT_TARGET_ARCH}"
|
|
|
|
CT_TARGET="${CT_TARGET}${CT_TARGET_VENDOR:+-${CT_TARGET_VENDOR}}"
|
|
|
|
CT_TARGET="${CT_TARGET}${CT_TARGET_KERNEL:+-${CT_TARGET_KERNEL}}"
|
|
|
|
CT_TARGET="${CT_TARGET}${CT_TARGET_SYS:+-${CT_TARGET_SYS}}"
|
2008-12-09 22:02:20 +00:00
|
|
|
|
|
|
|
# Sanity checks
|
|
|
|
__sed_alias=""
|
|
|
|
if [ -n "${CT_TARGET_ALIAS_SED_EXPR}" ]; then
|
|
|
|
__sed_alias=$(echo "${CT_TARGET}" |sed -r -e "${CT_TARGET_ALIAS_SED_EXPR}")
|
|
|
|
fi
|
|
|
|
case ":${CT_TARGET_VENDOR}:${CT_TARGET_ALIAS}:${__sed_alias}:" in
|
|
|
|
:*" "*:*:*:) CT_Abort "Don't use spaces in the vendor string, it breaks things.";;
|
|
|
|
:*"-"*:*:*:) CT_Abort "Don't use dashes in the vendor string, it breaks things.";;
|
|
|
|
:*:*" "*:*:) CT_Abort "Don't use spaces in the target alias, it breaks things.";;
|
|
|
|
:*:*:*" "*:) CT_Abort "Don't use spaces in the target sed transform, it breaks things.";;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Canonicalise it
|
|
|
|
CT_TARGET=$(CT_DoConfigSub "${CT_TARGET}")
|
2007-09-15 21:44:18 +00:00
|
|
|
# Prepare the target CFLAGS
|
2008-08-07 15:18:18 +00:00
|
|
|
CT_ARCH_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_ARCH_ENDIAN_CFLAG}"
|
2008-05-21 22:00:52 +00:00
|
|
|
CT_ARCH_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_ARCH_ARCH_CFLAG}"
|
2007-09-16 17:59:18 +00:00
|
|
|
CT_ARCH_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_ARCH_ABI_CFLAG}"
|
|
|
|
CT_ARCH_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_ARCH_CPU_CFLAG}"
|
|
|
|
CT_ARCH_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_ARCH_TUNE_CFLAG}"
|
|
|
|
CT_ARCH_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_ARCH_FPU_CFLAG}"
|
|
|
|
CT_ARCH_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_ARCH_FLOAT_CFLAG}"
|
2008-05-21 22:00:52 +00:00
|
|
|
|
|
|
|
# Now on for the target LDFLAGS
|
2008-08-07 15:18:18 +00:00
|
|
|
CT_ARCH_TARGET_LDFLAGS="${CT_ARCH_TARGET_LDFLAGS} ${CT_ARCH_ENDIAN_LDFLAG}"
|
2007-05-07 09:04:02 +00:00
|
|
|
}
|
2007-05-22 20:46:07 +00:00
|
|
|
|
|
|
|
# This function does pause the build until the user strikes "Return"
|
|
|
|
# Usage: CT_DoPause [optional_message]
|
|
|
|
CT_DoPause() {
|
|
|
|
local foo
|
|
|
|
local message="${1:-Pausing for your pleasure}"
|
|
|
|
CT_DoLog INFO "${message}"
|
2008-05-20 21:32:39 +00:00
|
|
|
read -p "Press 'Enter' to continue, or Ctrl-C to stop..." foo >&6
|
2007-05-22 20:46:07 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2010-04-13 18:52:38 +00:00
|
|
|
# This function creates a tarball of the specified directory, but
|
|
|
|
# only if it exists
|
|
|
|
# Usage: CT_DoTarballIfExists <dir> <tarball_basename> [extra_tar_options [...]]
|
|
|
|
CT_DoTarballIfExists() {
|
|
|
|
local dir="$1"
|
|
|
|
local tarball="$2"
|
|
|
|
shift 2
|
|
|
|
local -a extra_tar_opts=( "$@" )
|
2010-04-13 19:47:34 +00:00
|
|
|
local -a compress
|
2010-04-13 18:52:38 +00:00
|
|
|
|
|
|
|
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
2010-04-13 19:47:34 +00:00
|
|
|
y) compress=( gzip -c -3 - ); tar_ext=.gz;;
|
|
|
|
*) compress=( cat - ); tar_ext=;;
|
2010-04-13 18:52:38 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -d "${dir}" ]; then
|
|
|
|
CT_DoLog DEBUG " Saving '${dir}'"
|
2010-04-13 19:47:34 +00:00
|
|
|
{ tar c -C "${dir}" -v -f - "${extra_tar_opts[@]}" . \
|
|
|
|
|"${compress[@]}" >"${tarball}.tar${tar_ext}" ;
|
2010-10-22 20:02:49 +00:00
|
|
|
} 2>&1 |sed -r -e 's/^/ /;' |CT_DoLog STATE
|
2010-04-13 18:52:38 +00:00
|
|
|
else
|
2010-10-22 20:02:49 +00:00
|
|
|
CT_DoLog STATE " Not saving '${dir}': does not exist"
|
2010-04-13 18:52:38 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# This function extracts a tarball to the specified directory, but
|
|
|
|
# only if the tarball exists
|
2010-10-22 20:02:49 +00:00
|
|
|
# Usage: CT_DoExtractTarballIfExists <tarball_basename> <dir> [extra_tar_options [...]]
|
2010-04-13 18:52:38 +00:00
|
|
|
CT_DoExtractTarballIfExists() {
|
|
|
|
local tarball="$1"
|
|
|
|
local dir="$2"
|
|
|
|
shift 2
|
|
|
|
local -a extra_tar_opts=( "$@" )
|
2010-04-13 19:47:34 +00:00
|
|
|
local -a uncompress
|
2010-04-13 18:52:38 +00:00
|
|
|
|
|
|
|
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
2010-04-13 19:47:34 +00:00
|
|
|
y) uncompress=( gzip -c -d ); tar_ext=.gz;;
|
|
|
|
*) uncompress=( cat ); tar_ext=;;
|
2010-04-13 18:52:38 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -f "${tarball}.tar${tar_ext}" ]; then
|
|
|
|
CT_DoLog DEBUG " Restoring '${dir}'"
|
|
|
|
CT_DoForceRmdir "${dir}"
|
|
|
|
CT_DoExecLog DEBUG mkdir -p "${dir}"
|
2010-04-13 19:47:34 +00:00
|
|
|
{ "${uncompress[@]}" "${tarball}.tar${tar_ext}" \
|
|
|
|
|tar x -C "${dir}" -v -f - "${extra_tar_opts[@]}" ;
|
2010-10-22 20:02:49 +00:00
|
|
|
} 2>&1 |sed -r -e 's/^/ /;' |CT_DoLog STATE
|
2010-04-13 18:52:38 +00:00
|
|
|
else
|
2010-10-22 20:02:49 +00:00
|
|
|
CT_DoLog STATE " Not restoring '${dir}': does not exist"
|
2010-04-13 18:52:38 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# This function saves the state of the toolchain to be able to restart
|
|
|
|
# at any one point
|
|
|
|
# Usage: CT_DoSaveState <next_step_name>
|
|
|
|
CT_DoSaveState() {
|
|
|
|
[ "${CT_DEBUG_CT_SAVE_STEPS}" = "y" ] || return 0
|
|
|
|
local state_name="$1"
|
|
|
|
local state_dir="${CT_STATE_DIR}/${state_name}"
|
|
|
|
|
2009-03-24 17:37:52 +00:00
|
|
|
# Log this to the log level required by the user
|
|
|
|
CT_DoLog ${CT_LOG_LEVEL_MAX} "Saving state to restart at step '${state_name}'..."
|
2009-01-12 18:54:34 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
rm -rf "${state_dir}"
|
|
|
|
mkdir -p "${state_dir}"
|
|
|
|
|
2010-10-22 20:02:49 +00:00
|
|
|
CT_DoLog STATE " Saving environment and aliases"
|
2008-07-27 14:25:19 +00:00
|
|
|
# We must omit shell functions, and some specific bash variables
|
|
|
|
# that break when restoring the environment, later. We could do
|
2009-04-20 21:10:03 +00:00
|
|
|
# all the processing in the awk script, but a sed is easier...
|
|
|
|
set |awk '
|
2008-10-29 22:27:30 +00:00
|
|
|
BEGIN { _p = 1; }
|
|
|
|
$0~/^[^ ]+ \(\)/ { _p = 0; }
|
|
|
|
_p == 1
|
|
|
|
$0 == "}" { _p = 1; }
|
|
|
|
' |sed -r -e '/^BASH_(ARGC|ARGV|LINENO|SOURCE|VERSINFO)=/d;
|
2008-07-27 14:25:19 +00:00
|
|
|
/^(UID|EUID)=/d;
|
|
|
|
/^(FUNCNAME|GROUPS|PPID|SHELLOPTS)=/d;' >"${state_dir}/env.sh"
|
2007-05-22 20:46:07 +00:00
|
|
|
|
2010-10-03 21:10:46 +00:00
|
|
|
if [ "${CT_COMPLIBS_BACKUP}" = "y" ]; then
|
2010-04-13 18:52:38 +00:00
|
|
|
CT_DoTarballIfExists "${CT_COMPLIBS_DIR}" "${state_dir}/complibs_dir"
|
2010-04-11 13:37:53 +00:00
|
|
|
fi
|
2010-04-13 18:52:38 +00:00
|
|
|
CT_DoTarballIfExists "${CT_CONFIG_DIR}" "${state_dir}/config_dir"
|
|
|
|
CT_DoTarballIfExists "${CT_CC_CORE_STATIC_PREFIX_DIR}" "${state_dir}/cc_core_static_prefix_dir"
|
|
|
|
CT_DoTarballIfExists "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${state_dir}/cc_core_shared_prefix_dir"
|
|
|
|
CT_DoTarballIfExists "${CT_PREFIX_DIR}" "${state_dir}/prefix_dir" --exclude '*.log'
|
2007-05-22 20:46:07 +00:00
|
|
|
|
|
|
|
if [ "${CT_LOG_TO_FILE}" = "y" ]; then
|
2010-10-22 20:02:49 +00:00
|
|
|
CT_DoLog STATE " Saving log file"
|
2007-05-22 20:46:07 +00:00
|
|
|
exec >/dev/null
|
|
|
|
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
|
|
|
y) gzip -3 -c "${CT_LOG_FILE}" >"${state_dir}/log.gz";;
|
|
|
|
*) cat "${CT_LOG_FILE}" >"${state_dir}/log";;
|
|
|
|
esac
|
|
|
|
exec >>"${CT_LOG_FILE}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-05-27 20:22:06 +00:00
|
|
|
# This function restores a previously saved state
|
2007-05-22 20:46:07 +00:00
|
|
|
# Usage: CT_DoLoadState <state_name>
|
|
|
|
CT_DoLoadState(){
|
|
|
|
local state_name="$1"
|
|
|
|
local state_dir="${CT_STATE_DIR}/${state_name}"
|
2007-05-25 19:30:42 +00:00
|
|
|
local old_RESTART="${CT_RESTART}"
|
|
|
|
local old_STOP="${CT_STOP}"
|
2007-05-22 20:46:07 +00:00
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_TestOrAbort "The previous build did not reach the point where it could be restarted at '${CT_RESTART}'" -d "${state_dir}"
|
2007-05-28 20:57:40 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# We need to do something special with the log file!
|
|
|
|
if [ "${CT_LOG_TO_FILE}" = "y" ]; then
|
|
|
|
exec >"${state_dir}/tail.log"
|
|
|
|
fi
|
2009-03-24 17:37:52 +00:00
|
|
|
|
|
|
|
# Log this to the log level required by the user
|
|
|
|
CT_DoLog ${CT_LOG_LEVEL_MAX} "Restoring state at step '${state_name}', as requested."
|
2007-05-22 20:46:07 +00:00
|
|
|
|
2010-04-13 18:52:38 +00:00
|
|
|
CT_DoExtractTarballIfExists "${state_dir}/prefix_dir" "${CT_PREFIX_DIR}"
|
|
|
|
CT_DoExtractTarballIfExists "${state_dir}/cc_core_shared_prefix_dir" "${CT_CC_CORE_SHARED_PREFIX_DIR}"
|
|
|
|
CT_DoExtractTarballIfExists "${state_dir}/cc_core_static_prefix_dir" "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
|
|
|
CT_DoExtractTarballIfExists "${state_dir}/config_dir" "${CT_CONFIG_DIR}"
|
2010-10-03 21:10:46 +00:00
|
|
|
if [ "${CT_COMPLIBS_BACKUP}" = "y" ]; then
|
2010-04-13 18:52:38 +00:00
|
|
|
CT_DoExtractTarballIfExists "${state_dir}/complibs_dir" "${CT_COMPLIBS_DIR}"
|
2010-04-11 13:37:53 +00:00
|
|
|
fi
|
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# Restore the environment, discarding any error message
|
|
|
|
# (for example, read-only bash internals)
|
2010-10-22 20:02:49 +00:00
|
|
|
CT_DoLog STATE " Restoring environment"
|
2007-05-22 20:46:07 +00:00
|
|
|
. "${state_dir}/env.sh" >/dev/null 2>&1 || true
|
|
|
|
|
2007-05-25 19:30:42 +00:00
|
|
|
# Restore the new RESTART and STOP steps
|
|
|
|
CT_RESTART="${old_RESTART}"
|
|
|
|
CT_STOP="${old_STOP}"
|
|
|
|
unset old_stop old_restart
|
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
if [ "${CT_LOG_TO_FILE}" = "y" ]; then
|
2010-10-22 20:02:49 +00:00
|
|
|
CT_DoLog STATE " Restoring log file"
|
2007-05-22 20:46:07 +00:00
|
|
|
exec >/dev/null
|
|
|
|
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
|
|
|
y) zcat "${state_dir}/log.gz" >"${CT_LOG_FILE}";;
|
|
|
|
*) cat "${state_dir}/log" >"${CT_LOG_FILE}";;
|
|
|
|
esac
|
|
|
|
cat "${state_dir}/tail.log" >>"${CT_LOG_FILE}"
|
|
|
|
exec >>"${CT_LOG_FILE}"
|
|
|
|
rm -f "${state_dir}/tail.log"
|
|
|
|
fi
|
|
|
|
}
|