Add uClibc-0.9.29 now it's out, and remove the 0.9.29-rc1.
1 # This file contains some usefull common functions
2 # Copyright 2007 Yann E. MORIN
3 # Licensed under the GPL v2. See COPYING in the root of this package
7 CT_DoLog ERROR "Build failed in step \"${CT_STEP_MESSAGE[${CT_STEP_COUNT}]}\""
8 for((step=(CT_STEP_COUNT-1); step>1; step--)); do
9 CT_DoLog ERROR " called in step \"${CT_STEP_MESSAGE[${step}]}\""
11 CT_DoLog ERROR "Error happened in \"${BASH_SOURCE[1]}\" in function \"${FUNCNAME[1]}\" (line unknown, sorry)"
12 for((depth=2; ${BASH_LINENO[$((${depth}-1))]}>0; depth++)); do
13 CT_DoLog ERROR " called from \"${BASH_SOURCE[${depth}]}\" at line # ${BASH_LINENO[${depth}-1]} in function \"${FUNCNAME[${depth}]}\""
15 CT_DoLog ERROR "Look at \"${CT_ACTUAL_LOG_FILE}\" for more info on this error."
23 # This is crosstool-ng-0.0.1
26 # The different log levels:
52 # A function to log what is happening
53 # Different log level are available:
54 # - ERROR: A serious, fatal error occurred
55 # - WARN: A non fatal, non serious error occurred, take your responsbility with the generated build
56 # - INFO: Informational messages
57 # - EXTRA: Extra informational messages
58 # - DEBUG: Debug messages
59 # Usage: CT_DoLog <level> [message]
60 # If message is empty, then stdin will be logged.
62 local max_level LEVEL level cur_l cur_L
64 eval max_level="\${CT_LOG_LEVEL_${CT_LOG_LEVEL_MAX}}"
65 # Set the maximum log level to DEBUG if we have none
66 [ -z ${max_level} ] && max_level=${CT_LOG_LEVEL_DEBUG}
69 eval level="\${CT_LOG_LEVEL_${LEVEL}}"
75 fi |( IFS="\n" # We want the full lines, even leading spaces
77 indent=$((2*CT_STEP_COUNT))
79 case "${CT_LOG_SEE_TOOLS_WARN},${line}" in
80 y,*"warning:"*) cur_L=WARN; cur_l=${CT_LOG_LEVEL_WARN};;
81 *"error:"*) cur_L=ERROR; cur_l=${CT_LOG_LEVEL_ERROR};;
82 "make["?*"]:"*"Stop.") cur_L=ERROR; cur_l=${CT_LOG_LEVEL_ERROR};;
83 *) cur_L="${LEVEL}"; cur_l="${level}";;
85 l="`printf \"[%-5s]%*s%s%s\" \"${cur_L}\" \"${indent}\" \" \" \"${line}\"`"
86 # There will always be a log file, be it /dev/null
87 echo -e "${l}" >>"${CT_ACTUAL_LOG_FILE}"
88 color="CT_${cur_L}_COLOR"
89 normal="CT_NORMAL_COLOR"
90 if [ ${cur_l} -le ${max_level} ]; then
91 echo -e "${!color}${l}${!normal}"
101 # Abort the execution with a error message
102 # Usage: CT_Abort <message>
104 CT_DoLog ERROR "$1" >&2
108 # Test a condition, and print a message if satisfied
109 # Usage: CT_Test <message> <tests>
114 test "$@" && CT_DoLog WARN "$m"
118 # Test a condition, and abort with an error message if satisfied
119 # Usage: CT_TestAndAbort <message> <tests>
123 test "$@" && CT_Abort "$m"
127 # Test a condition, and abort with an error message if not satisfied
128 # Usage: CT_TestAndAbort <message> <tests>
132 test "$@" || CT_Abort "$m"
136 # Test the presence of a tool, or abort if not found
137 # Usage: CT_HasOrAbort <tool>
139 CT_TestAndAbort "\"${1}\" not found and needed for successfull toolchain build." -z "`which \"${1}\"`"
143 # Get current date with nanosecond precision
144 # On those system not supporting nanosecond precision, faked with rounding down
145 # to the highest entire second
146 # Usage: CT_DoDate <fmt>
148 date "$1" |sed -r -e 's/%N$/000000000/;'
152 CT_STEP_MESSAGE[${CT_STEP_COUNT}]="<none>"
153 # Memorise a step being done so that any error is caught
154 # Usage: CT_DoStep <loglevel> <message>
156 local start=`CT_DoDate +%s%N`
157 CT_DoLog "$1" "================================================================="
159 CT_STEP_COUNT=$((CT_STEP_COUNT+1))
160 CT_STEP_LEVEL[${CT_STEP_COUNT}]="$1"; shift
161 CT_STEP_START[${CT_STEP_COUNT}]="${start}"
162 CT_STEP_MESSAGE[${CT_STEP_COUNT}]="$1"
166 # End the step just being done
169 local stop=`CT_DoDate +%s%N`
170 local duration=`printf "%032d" $((stop-${CT_STEP_START[${CT_STEP_COUNT}]})) |sed -r -e 's/([[:digit:]]{2})[[:digit:]]{7}$/\.\1/; s/^0+//; s/^\./0\./;'`
171 local level="${CT_STEP_LEVEL[${CT_STEP_COUNT}]}"
172 local message="${CT_STEP_MESSAGE[${CT_STEP_COUNT}]}"
173 CT_STEP_COUNT=$((CT_STEP_COUNT-1))
174 CT_DoLog "${level}" "${message}: done in ${duration}s"
178 # Pushes into a directory, and pops back
180 pushd "$1" >/dev/null 2>&1
186 # Makes a path absolute
187 # Usage: CT_MakeAbsolutePath path
188 CT_MakeAbsolutePath() {
189 # Try to cd in that directory
195 # No such directory, fail back to guessing
205 # Creates a temporary directory
206 # $1: variable to assign to
207 # Usage: CT_MktempDir foo
209 # Some mktemp do not allow more than 6 Xs
210 eval "$1"="`mktemp -q -d \"${CT_BUILD_DIR}/.XXXXXX\"`"
211 CT_TestOrAbort "Could not make temporary directory" -n "${!1}" -a -d "${!1}"
214 # Echoes the specified string on stdout until the pipe breaks.
217 # Usage: CT_DoYes "" |make oldconfig