2007-02-24 11:00:05 +00:00
|
|
|
# This file contains some usefull common functions
|
|
|
|
# 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
|
|
|
|
CT_LOG_LEVEL_DEBUG=4
|
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
|
|
|
CT_LOG_LEVEL_ALL=5
|
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
|
|
|
|
# - DEBUG: Debug messages
|
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
|
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
|
2008-07-13 10:44:26 +00:00
|
|
|
echo "${@}"
|
2007-05-28 20:57:40 +00:00
|
|
|
fi |( IFS="\n" # 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};;
|
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
|
|
|
*"make["?*"]:"*"Stop.") 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
|
|
|
|
# Usage: CT_DoExecLog <level> <[VAR=val...] command [parameters...]>
|
|
|
|
CT_DoExecLog() {
|
|
|
|
local level="$1"
|
|
|
|
shift
|
2008-07-14 15:20:11 +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
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
test "$@" || CT_Abort "$m"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test the presence of a tool, or abort if not found
|
|
|
|
# Usage: CT_HasOrAbort <tool>
|
|
|
|
CT_HasOrAbort() {
|
2008-05-20 21:32:39 +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
|
|
|
|
# "which" verbosely says there is no match (Mdk are such
|
|
|
|
# suckers...)
|
|
|
|
# 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() {
|
|
|
|
date "$1" |sed -r -e 's/%N$/000000000/;'
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
# Makes a path absolute
|
|
|
|
# Usage: CT_MakeAbsolutePath path
|
|
|
|
CT_MakeAbsolutePath() {
|
|
|
|
# Try to cd in that directory
|
|
|
|
if [ -d "$1" ]; then
|
|
|
|
CT_Pushd "$1"
|
|
|
|
pwd
|
|
|
|
CT_Popd
|
|
|
|
else
|
|
|
|
# No such directory, fail back to guessing
|
|
|
|
case "$1" in
|
|
|
|
/*) echo "$1";;
|
2008-05-20 21:32:39 +00:00
|
|
|
*) echo "$(pwd)/$1";;
|
2007-02-24 11:00:05 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Creates a temporary directory
|
|
|
|
# $1: variable to assign to
|
|
|
|
# Usage: CT_MktempDir foo
|
|
|
|
CT_MktempDir() {
|
|
|
|
# Some mktemp do not allow more than 6 Xs
|
2008-05-20 21:32:39 +00:00
|
|
|
eval "$1"=$(mktemp -q -d "${CT_BUILD_DIR}/.XXXXXX")
|
2007-02-24 11:00:05 +00:00
|
|
|
CT_TestOrAbort "Could not make temporary directory" -n "${!1}" -a -d "${!1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
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]
|
2007-05-10 21:33:35 +00:00
|
|
|
# If found, echoes the extension to stdout
|
|
|
|
# If not found, echoes nothing on stdout.
|
|
|
|
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
|
|
|
|
|
|
|
CT_Pushd "${CT_TARBALLS_DIR}"
|
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).
|
2008-07-25 10:02:43 +00:00
|
|
|
for ext in ${first_ext} .tar.gz .tar.bz2 .tgz .tar ''; do
|
2007-05-10 21:33:35 +00:00
|
|
|
if [ -f "${file}${ext}" ]; then
|
|
|
|
echo "${ext}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
CT_Popd
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2007-05-07 09:04:02 +00:00
|
|
|
# Download an URL using wget
|
|
|
|
# Usage: CT_DoGetFileWget <URL>
|
|
|
|
CT_DoGetFileWget() {
|
|
|
|
# Need to return true because it is legitimate to not find the tarball at
|
|
|
|
# some of the provided URLs (think about snapshots, different layouts for
|
|
|
|
# different gcc versions, etc...)
|
|
|
|
# Some (very old!) FTP server might not support the passive mode, thus
|
|
|
|
# retry without
|
|
|
|
# With automated download as we are doing, it can be very dangerous to use
|
|
|
|
# -c 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
|
|
|
|
# not easy to detect them, and wget does not timeout by default while
|
|
|
|
# connecting, so force a global ${CT_CONNECT_TIMEOUT}-second timeout.
|
|
|
|
wget -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary --tries=3 --passive-ftp "$1" \
|
|
|
|
|| wget -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary --tries=3 "$1" \
|
2008-04-13 18:16:58 +00:00
|
|
|
|| true
|
2007-05-07 09:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Download an URL using curl
|
|
|
|
# Usage: CT_DoGetFileCurl <URL>
|
|
|
|
CT_DoGetFileCurl() {
|
2008-05-06 20:30:49 +00:00
|
|
|
# Note: comments about wget method (above) are also valid here
|
2008-04-13 18:16:58 +00:00
|
|
|
# Plus: no good progress indicator is available with curl,
|
|
|
|
# so output is consigned to oblivion
|
2008-05-06 20:30:49 +00:00
|
|
|
curl --ftp-pasv -O --retry 3 "$1" --connect-timeout ${CT_CONNECT_TIMEOUT} >/dev/null \
|
|
|
|
|| curl -O --retry 3 "$1" --connect-timeout ${CT_CONNECT_TIMEOUT} >/dev/null \
|
2008-04-13 18:16:58 +00:00
|
|
|
|| true
|
2007-05-07 09:04:02 +00:00
|
|
|
}
|
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
_wget=$(CT_Which wget)
|
|
|
|
_curl=$(CT_Which curl)
|
2007-05-07 09:04:02 +00:00
|
|
|
# Wrapper function to call one of curl or wget
|
|
|
|
# Usage: CT_DoGetFile <URL>
|
|
|
|
CT_DoGetFile() {
|
|
|
|
case "${_wget},${_curl}" in
|
|
|
|
,) CT_DoError "Could find neither wget nor curl";;
|
2007-06-01 16:20:20 +00:00
|
|
|
,*) CT_DoGetFileCurl "$1" 2>&1 |CT_DoLog ALL;;
|
|
|
|
*) CT_DoGetFileWget "$1" 2>&1 |CT_DoLog ALL;;
|
2007-05-07 09:04:02 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# Download the file from one of the URLs passed as argument
|
2007-07-12 19:52:09 +00:00
|
|
|
# Usage: CT_GetFile <filename> [extension] <url> [url ...]
|
2007-05-07 09:04:02 +00:00
|
|
|
CT_GetFile() {
|
|
|
|
local ext
|
|
|
|
local url
|
|
|
|
local file="$1"
|
2007-07-12 19:52:09 +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
|
|
|
|
|
|
|
# Do we already have it?
|
2008-07-25 10:02:43 +00:00
|
|
|
ext=$(CT_GetFileExtension "${file}" ${first_ext})
|
2007-05-07 09:04:02 +00:00
|
|
|
if [ -n "${ext}" ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG "Already have '${file}'"
|
2007-05-10 21:33:35 +00:00
|
|
|
return 0
|
2007-05-07 09:04:02 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
CT_Pushd "${CT_TARBALLS_DIR}"
|
2007-07-12 19:52:09 +00:00
|
|
|
# We'd rather have a bzip2'ed tarball, then gzipped tarball, plain tarball,
|
|
|
|
# or, as a failover, a file without extension.
|
2007-05-18 15:54:42 +00:00
|
|
|
# Try local copy first, if it exists
|
2007-07-12 19:52:09 +00:00
|
|
|
for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG "Trying '${CT_LOCAL_TARBALLS_DIR}/${file}${ext}'"
|
2007-05-18 15:54:42 +00:00
|
|
|
if [ -r "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" -a \
|
|
|
|
"${CT_FORCE_DOWNLOAD}" != "y" ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog EXTRA "Using '${file}' from local storage"
|
2007-09-08 19:00:45 +00:00
|
|
|
ln -sv "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog ALL
|
2007-05-18 15:54:42 +00:00
|
|
|
return 0
|
2007-05-07 09:04:02 +00:00
|
|
|
fi
|
|
|
|
done
|
2008-07-19 22:45:17 +00:00
|
|
|
|
|
|
|
# Not found locally, try from the network
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog EXTRA "Retrieving '${file}' from network"
|
2008-07-19 22:45:17 +00:00
|
|
|
|
|
|
|
# Start with LAN mirror
|
|
|
|
if [ "${CT_USE_LAN_MIRROR}" = "y" ]; then
|
|
|
|
LAN_URLs=
|
|
|
|
for pat in ${CT_LAN_MIRROR_PATTERNS}; do
|
|
|
|
# Please note: we just have the file's basename in a single piece.
|
|
|
|
# So we have to just try and split it back into name and version... :-(
|
|
|
|
pat="${pat//\%pkg/${file%-*}}"
|
|
|
|
pat="${pat//\%ver/${file##*-}}"
|
|
|
|
LAN_URLs="${LAN_URLs} ${CT_LAN_MIRROR_SCHEME}://${CT_LAN_MIRROR_HOSTNAME}/${pat}"
|
|
|
|
done
|
|
|
|
for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
|
|
|
|
for url in ${LAN_URLs}; do
|
|
|
|
CT_DoLog DEBUG "Trying '${url}/${file}${ext}'"
|
|
|
|
CT_DoGetFile "${url}/${file}${ext}"
|
|
|
|
if [ -f "${file}${ext}" ]; then
|
|
|
|
if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
|
|
|
|
# No need to test if the file already exists because
|
|
|
|
# it does NOT. If it did exist, we'd have been stopped
|
|
|
|
# above, when looking for local copies.
|
|
|
|
CT_DoLog EXTRA "Saving '${file}' to local storage"
|
|
|
|
mv "${file}${ext}" "${CT_LOCAL_TARBALLS_DIR}" |CT_DoLog ALL
|
|
|
|
ln -sv "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog ALL
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# OK, available neither localy, nor from the LAN mirror (if any).
|
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
|
|
|
|
for url in "$@"; 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
|
|
|
|
if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
|
2008-07-19 22:45:17 +00:00
|
|
|
# No need to test if the file already exists because
|
|
|
|
# it does NOT. If it did exist, we'd have been stopped
|
|
|
|
# above, when looking for local copies.
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog EXTRA "Saving '${file}' to local storage"
|
2007-09-08 19:00:45 +00:00
|
|
|
mv "${file}${ext}" "${CT_LOCAL_TARBALLS_DIR}" |CT_DoLog ALL
|
|
|
|
ln -sv "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog ALL
|
2007-07-15 17:00:30 +00:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
fi
|
2007-05-18 15:54:42 +00:00
|
|
|
done
|
|
|
|
done
|
2007-05-07 09:04:02 +00:00
|
|
|
CT_Popd
|
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_Abort "Could not download '${file}', and not present in '${CT_LOCAL_TARBALLS_DIR}'"
|
2007-05-07 09:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Extract a tarball and patch the resulting sources if necessary.
|
|
|
|
# Some tarballs need to be extracted in specific places. Eg.: glibc addons
|
|
|
|
# must be extracted in the glibc directory; uCLibc locales must be extracted
|
|
|
|
# in the extra/locale sub-directory of uClibc.
|
|
|
|
CT_ExtractAndPatch() {
|
|
|
|
local file="$1"
|
2008-05-20 21:32:39 +00:00
|
|
|
local base_file=$(echo "${file}" |cut -d - -f 1)
|
|
|
|
local ver_file=$(echo "${file}" |cut -d - -f 2-)
|
2007-05-07 09:04:02 +00:00
|
|
|
local official_patch_dir
|
|
|
|
local custom_patch_dir
|
|
|
|
local libc_addon
|
2008-05-20 21:32:39 +00:00
|
|
|
local ext=$(CT_GetFileExtension "${file}")
|
|
|
|
CT_TestAndAbort "'${file}' not found in '${CT_TARBALLS_DIR}'" -z "${ext}"
|
2007-05-07 09:04:02 +00:00
|
|
|
local full_file="${CT_TARBALLS_DIR}/${file}${ext}"
|
|
|
|
|
|
|
|
CT_Pushd "${CT_SRC_DIR}"
|
|
|
|
|
|
|
|
# Add-ons need a little love, really.
|
|
|
|
case "${file}" in
|
|
|
|
glibc-[a-z]*-*)
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_TestAndAbort "Trying to extract the C-library addon/locales '${file}' when C-library not yet extracted" ! -d "${CT_LIBC_FILE}"
|
2007-05-07 09:04:02 +00:00
|
|
|
cd "${CT_LIBC_FILE}"
|
|
|
|
libc_addon=y
|
|
|
|
[ -f ".${file}.extracted" ] && return 0
|
|
|
|
touch ".${file}.extracted"
|
|
|
|
;;
|
|
|
|
uClibc-locale-*)
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_TestAndAbort "Trying to extract the C-library addon/locales '${file}' when C-library not yet extracted" ! -d "${CT_LIBC_FILE}"
|
2007-05-07 09:04:02 +00:00
|
|
|
cd "${CT_LIBC_FILE}/extra/locale"
|
|
|
|
libc_addon=y
|
|
|
|
[ -f ".${file}.extracted" ] && return 0
|
|
|
|
touch ".${file}.extracted"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# If the directory exists, then consider extraction and patching done
|
2007-05-08 12:57:52 +00:00
|
|
|
if [ -d "${file}" ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG "Already extracted '${file}'"
|
2007-05-08 12:57:52 +00:00
|
|
|
return 0
|
|
|
|
fi
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog EXTRA "Extracting '${file}'"
|
2007-05-07 09:04:02 +00:00
|
|
|
case "${ext}" in
|
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
|
|
|
.tar.bz2) tar xvjf "${full_file}" |CT_DoLog ALL;;
|
|
|
|
.tar.gz|.tgz) tar xvzf "${full_file}" |CT_DoLog ALL;;
|
|
|
|
.tar) tar xvf "${full_file}" |CT_DoLog ALL;;
|
2008-05-20 21:32:39 +00:00
|
|
|
*) CT_Abort "Don't know how to handle '${file}': unknown extension" ;;
|
2007-05-07 09:04:02 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
# Snapshots might not have the version number in the extracted directory
|
2007-07-30 20:02:13 +00:00
|
|
|
# name. This is also the case for some (odd) packages, such as D.U.M.A.
|
2007-05-07 09:04:02 +00:00
|
|
|
# Overcome this issue by symlink'ing the directory.
|
|
|
|
if [ ! -d "${file}" -a "${libc_addon}" != "y" ]; then
|
|
|
|
case "${ext}" in
|
2008-05-20 21:32:39 +00:00
|
|
|
.tar.bz2) base=$(tar tjf "${full_file}" |head -n 1 |cut -d / -f 1 || true);;
|
|
|
|
.tar.gz|.tgz) base=$(tar tzf "${full_file}" |head -n 1 |cut -d / -f 1 || true);;
|
|
|
|
.tar) base=$(tar tf "${full_file}" |head -n 1 |cut -d / -f 1 || true);;
|
2007-05-07 09:04:02 +00:00
|
|
|
esac
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_TestOrAbort "There was a problem when extracting '${file}'" -d "${base}" -o "${base}" != "${file}"
|
2007-05-07 09:04:02 +00:00
|
|
|
ln -s "${base}" "${file}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Kludge: outside this function, we wouldn't know if we had just extracted
|
|
|
|
# a libc addon, or a plain package. Apply patches now.
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog EXTRA "Patching '${file}'"
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2007-05-27 20:22:06 +00:00
|
|
|
if [ "${libc_addon}" = "y" ]; then
|
2008-05-15 20:45:18 +00:00
|
|
|
# Some addon tarballs directly contain the correct addon directory,
|
|
|
|
# while others have the addon directory named after the tarball.
|
2007-09-06 12:38:52 +00:00
|
|
|
# Fix that by always using the short name (eg: linuxthreads, ports, etc...)
|
2008-05-20 21:32:39 +00:00
|
|
|
addon_short_name=$(echo "${file}" |sed -r -e 's/^[^-]+-//; s/-[^-]+$//;')
|
2007-05-27 20:22:06 +00:00
|
|
|
[ -d "${addon_short_name}" ] || ln -s "${file}" "${addon_short_name}"
|
|
|
|
# If libc addon, we're already in the correct place
|
|
|
|
else
|
|
|
|
cd "${file}"
|
|
|
|
fi
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2007-07-01 19:04:20 +00:00
|
|
|
official_patch_dir=
|
|
|
|
custom_patch_dir=
|
|
|
|
[ "${CUSTOM_PATCH_ONLY}" = "y" ] || official_patch_dir="${CT_LIB_DIR}/patches/${base_file}/${ver_file}"
|
2007-05-07 09:04:02 +00:00
|
|
|
[ "${CT_CUSTOM_PATCH}" = "y" ] && custom_patch_dir="${CT_CUSTOM_PATCH_DIR}/${base_file}/${ver_file}"
|
|
|
|
for patch_dir in "${official_patch_dir}" "${custom_patch_dir}"; do
|
|
|
|
if [ -n "${patch_dir}" -a -d "${patch_dir}" ]; then
|
|
|
|
for p in "${patch_dir}"/*.patch; do
|
|
|
|
if [ -f "${p}" ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG "Applying patch '${p}'"
|
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
|
|
|
patch -g0 -F1 -p1 -f <"${p}" |CT_DoLog ALL
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_TestAndAbort "Failed while applying patch file '${p}'" ${PIPESTATUS[0]} -ne 0
|
2007-05-07 09:04:02 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
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
|
|
|
|
eval ${cfg}="${CT_LIB_DIR}/tools/${cfg/_/.}"
|
|
|
|
[ -e "${CT_TOP_DIR}/tools/${cfg/_/.}" ] && eval ${cfg}="${CT_TOP_DIR}/tools/${cfg/_/.}"
|
|
|
|
find . -type f -name "${cfg/_/.}" -exec cp -v "${!cfg}" {} \; |CT_DoLog ALL
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2007-05-07 09:04:02 +00:00
|
|
|
CT_Popd
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
if [ -x "${CT_TOP_DIR}/tools/config.guess" ]; then
|
|
|
|
"${CT_TOP_DIR}/tools/config.guess"
|
|
|
|
else
|
|
|
|
"${CT_LIB_DIR}/tools/config.guess"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
CT_DoConfigSub() {
|
|
|
|
if [ -x "${CT_TOP_DIR}/tools/config.sub" ]; then
|
|
|
|
"${CT_TOP_DIR}/tools/config.sub" "$@"
|
|
|
|
else
|
|
|
|
"${CT_LIB_DIR}/tools/config.sub" "$@"
|
|
|
|
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
|
|
|
|
|
|
|
# Set defaults for the system part of the tuple. Can be overriden
|
|
|
|
# by architecture-specific values.
|
|
|
|
case "${CT_LIBC}" in
|
|
|
|
glibc) CT_TARGET_SYS=gnu;;
|
|
|
|
uClibc) CT_TARGET_SYS=uclibc;;
|
2007-05-07 09:04:02 +00:00
|
|
|
esac
|
2007-09-14 21:17:59 +00:00
|
|
|
|
2007-09-14 21:50:30 +00:00
|
|
|
# Transform the ARCH into a kernel-understandable ARCH
|
|
|
|
CT_KERNEL_ARCH="${CT_ARCH}"
|
|
|
|
|
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
|
|
|
|
2007-09-14 21:17:59 +00:00
|
|
|
# Call the architecture specific settings
|
|
|
|
CT_DoArchValues
|
|
|
|
|
2007-09-15 21:44:18 +00:00
|
|
|
# Finish the target tuple construction
|
2007-05-07 09:04:02 +00:00
|
|
|
case "${CT_KERNEL}" in
|
2007-09-14 21:17:59 +00:00
|
|
|
linux*) CT_TARGET_KERNEL=linux;;
|
2007-05-07 09:04:02 +00:00
|
|
|
esac
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_TARGET=$(CT_DoConfigSub "${CT_TARGET_ARCH}-${CT_TARGET_VENDOR:-unknown}-${CT_TARGET_KERNEL}-${CT_TARGET_SYS}")
|
2007-09-15 21:44:18 +00:00
|
|
|
|
|
|
|
# Prepare the target CFLAGS
|
2008-05-21 22:00:52 +00:00
|
|
|
CT_ARCH_TARGET_CFLAGS="${CT_ARCH_ENDIAN_CFLAG}"
|
|
|
|
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
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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}"
|
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG "Saving state to restart at step '${state_name}'..."
|
2007-05-22 20:46:07 +00:00
|
|
|
rm -rf "${state_dir}"
|
|
|
|
mkdir -p "${state_dir}"
|
|
|
|
|
|
|
|
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
2007-08-12 15:18:09 +00:00
|
|
|
y) tar_opt=z; tar_ext=.gz;;
|
|
|
|
*) tar_opt=; tar_ext=;;
|
2007-05-22 20:46:07 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
CT_DoLog DEBUG " Saving environment and aliases"
|
|
|
|
# We must omit shell functions
|
|
|
|
set |awk '
|
|
|
|
BEGIN { _p = 1; }
|
2007-08-12 08:43:56 +00:00
|
|
|
$0~/^[^ ]+ \(\)/ { _p = 0; }
|
2007-05-22 20:46:07 +00:00
|
|
|
_p == 1
|
|
|
|
$0 == "}" { _p = 1; }
|
2007-08-12 08:43:56 +00:00
|
|
|
' >"${state_dir}/env.sh"
|
2007-05-22 20:46:07 +00:00
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG " Saving CT_CC_CORE_STATIC_PREFIX_DIR='${CT_CC_CORE_STATIC_PREFIX_DIR}'"
|
2007-05-27 20:22:06 +00:00
|
|
|
CT_Pushd "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
2007-08-12 15:18:09 +00:00
|
|
|
tar cv${tar_opt}f "${state_dir}/cc_core_static_prefix_dir.tar${tar_ext}" . |CT_DoLog DEBUG
|
2007-05-27 20:22:06 +00:00
|
|
|
CT_Popd
|
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG " Saving CT_CC_CORE_SHARED_PREFIX_DIR='${CT_CC_CORE_SHARED_PREFIX_DIR}'"
|
2007-05-27 20:22:06 +00:00
|
|
|
CT_Pushd "${CT_CC_CORE_SHARED_PREFIX_DIR}"
|
2007-08-12 15:18:09 +00:00
|
|
|
tar cv${tar_opt}f "${state_dir}/cc_core_shared_prefix_dir.tar${tar_ext}" . |CT_DoLog DEBUG
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_Popd
|
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG " Saving CT_PREFIX_DIR='${CT_PREFIX_DIR}'"
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_Pushd "${CT_PREFIX_DIR}"
|
2007-08-12 15:18:09 +00:00
|
|
|
tar cv${tar_opt}f "${state_dir}/prefix_dir.tar${tar_ext}" --exclude '*.log' . |CT_DoLog DEBUG
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_Popd
|
|
|
|
|
|
|
|
if [ "${CT_LOG_TO_FILE}" = "y" ]; then
|
|
|
|
CT_DoLog DEBUG " Saving log file"
|
|
|
|
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
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog INFO "Restoring state at step '${state_name}', as requested."
|
2007-05-22 20:46:07 +00:00
|
|
|
|
|
|
|
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
2007-08-12 15:18:09 +00:00
|
|
|
y) tar_opt=z; tar_ext=.gz;;
|
|
|
|
*) tar_opt=; tar_ext=;;
|
2007-05-22 20:46:07 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
CT_DoLog DEBUG " Removing previous build directories"
|
2007-05-27 20:22:06 +00:00
|
|
|
chmod -R u+rwX "${CT_PREFIX_DIR}" "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
|
|
|
rm -rf "${CT_PREFIX_DIR}" "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
|
|
|
mkdir -p "${CT_PREFIX_DIR}" "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
2007-05-22 20:46:07 +00:00
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG " Restoring CT_PREFIX_DIR='${CT_PREFIX_DIR}'"
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_Pushd "${CT_PREFIX_DIR}"
|
2007-08-16 12:13:45 +00:00
|
|
|
tar xv${tar_opt}f "${state_dir}/prefix_dir.tar${tar_ext}" |CT_DoLog DEBUG
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_Popd
|
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG " Restoring CT_CC_CORE_SHARED_PREFIX_DIR='${CT_CC_CORE_SHARED_PREFIX_DIR}'"
|
2007-05-27 20:22:06 +00:00
|
|
|
CT_Pushd "${CT_CC_CORE_SHARED_PREFIX_DIR}"
|
2007-08-12 15:18:09 +00:00
|
|
|
tar xv${tar_opt}f "${state_dir}/cc_core_shared_prefix_dir.tar${tar_ext}" |CT_DoLog DEBUG
|
2007-05-27 20:22:06 +00:00
|
|
|
CT_Popd
|
|
|
|
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog DEBUG " Restoring CT_CC_CORE_STATIC_PREFIX_DIR='${CT_CC_CORE_STATIC_PREFIX_DIR}'"
|
2007-05-27 20:22:06 +00:00
|
|
|
CT_Pushd "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
2007-08-12 15:18:09 +00:00
|
|
|
tar xv${tar_opt}f "${state_dir}/cc_core_static_prefix_dir.tar${tar_ext}" |CT_DoLog DEBUG
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_Popd
|
|
|
|
|
|
|
|
# Restore the environment, discarding any error message
|
|
|
|
# (for example, read-only bash internals)
|
|
|
|
CT_DoLog DEBUG " Restoring environment"
|
|
|
|
. "${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
|
|
|
|
CT_DoLog DEBUG " Restoring log file"
|
|
|
|
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
|
|
|
|
}
|