diff --git a/tools/quartus/generic.sh b/tools/quartus/generic.sh new file mode 100755 index 0000000000000000000000000000000000000000..25ea0f76d3e5a484e53e467306dbecc5f829207e --- /dev/null +++ b/tools/quartus/generic.sh @@ -0,0 +1,256 @@ +# This file contains a lot of +# convenience functions and +# definitions. +# +# You will notice that mostly the caller +# has little or no influence on the function +# call; this is done on purpose. +# +# (at least some of) The scripts which +# build on/make decisions based on the values +# returned from these functions are either +# run as root or run with root privilege. +# +# For the moment I (HV) decided to eliminate +# as much user-input-error as possible, +# giving the user as little possibility +# of passing in 'the wrong thing' before +# ruining something. +# + +# make sure that use of unset vars triggers an error (-u) +# and automatically export to subsequent commands (-a) +# DS: no longer using set -u as it renders some tests +#(e.g. test -z $1) unusable. +#set -ua +set -a +#exits on any error in pipeline, not just the last error +set -o pipefail + +# only set variables if we didn't set them before +if [ "${generic_read:-not_set}" = "not_set" ]; then + +# display a (colourfull ...) error message. +# the script will be terminated immediately +# exit with <errorcode> (default=1) +# usage: unb_error <caller> <message> [<errorcode>] +unb_error() { + caller=${1:-""} + msg=${2:-""} + exitcode=${3:-1} + if [ -z "${caller}" -o -z "${msg}" ]; then + echo "usage: unb_error <caller's name> <message> [<exitcode>]" + exit 1 + fi + caller=`basename ${caller} | tr [a-z] [A-Z]` + echo -en '\E[40;36m'"\033[1m[${caller}]\033[0m " + echo -e '\E[40;31m'"\033[1mERROR - ${msg}. \033[0m " + tput sgr0 + exit ${exitcode} +} + +# Non-exiting version of unb_error in case we wish to accumulate errors and +# call an exiting unb_error after displaying accumulated errors. +unb_error_noexit() { + caller=${1:-""} + msg=${2:-""} + if [ -z "${caller}" -o -z "${msg}" ]; then + echo "usage: unb_error <caller's name> <message> [<exitcode>]" + exit 1 + fi + caller=`basename ${caller} | tr [a-z] [A-Z]` + echo -en '\E[40;36m'"\033[1m[${caller}]\033[0m " + echo -e '\E[40;31m'"\033[1mERROR - ${msg}. \033[0m " + tput sgr0 +} + +unb_warning() { + caller=${1:-""} + msg=${2:-""} + exitcode=${3:-1} + if [ -z "${caller}" -o -z "${msg}" ]; then + echo "usage: unb_warning <caller's name> <message> [<exitcode>]" + exit 1 + fi + caller=`basename ${caller} | tr [a-z] [A-Z]` + echo -en '\E[40;36m'"\033[1m[${caller}]\033[0m " + echo -e '\E[40;35m'"\033[1mWARNING - ${msg}. \033[0m " + tput sgr0 + return 0 +} + + +# usage: unb_info <caller> <message> +unb_info() { + caller=${1:-""} + shift + if [ -z "${caller}" -o -z "$*" ]; then + echo "usage: unb_info <scriptname> <msg1> [<msg2> .. <msgN>]" + exit 1 + fi + caller=`basename ${caller} | tr [a-z] [A-Z]` + echo -e '\E[40;36m'"\033[1m[${caller}] $* \033[0m " + tput sgr0 + return 0 +} + +# usage: +# unb_exec <calling script> [OPTS] <command to run> +# OPTS: +# [msg=<override defaultmsg>] +# msg=no => suppress displaying of messages +# if command fails, do display the +# command that failed +# [expect=<expected exit code>] (default: 0) +# exits with same exitcode as the command +unb_exec() { + # step one: extract calling scriptname, which is $1 + caller=$1; shift + # anything left is supposedly the command to exec + args + # prepare the "msg" to display + msg= + output= + expect=0 + # unless someone gave msg="...." as orginal 2nd arg + # (and now, since the first "shift", it is 1st) + for ac ; do + case ${ac} in + output=*) + # well allrighty then, override default msg + output=`echo "${ac}" | sed 's/^output=//'` + shift + ;; + msg=*) + # well allrighty then, override default msg + msg=`echo "${ac}" | sed 's/^msg=//'` + shift + ;; + expect=*) + expect=`echo "${ac}" | sed 's/^expect=//'` + shift + ;; + * ) + # first non-option argument; stop for loop! + break + ;; + esac + done + if [ -z "${msg}" ]; then + msg="Running \"$*\"" + fi + # show usr what we're up to + if [ "${msg}" != "no" ]; then + unb_info ${caller} "${msg}" + fi + # and let's actually do it! + if [ "${output}" = "no" ]; then + $* >/dev/null 2>/dev/null + else + $* + fi + + exitcode=$? + if [ "${exitcode}" -ne "${expect}" ]; then + if [ "${msg}" == "no" ]; then + echo "****** Failed command ****" + echo $* + exit ${exitcode} + fi + unb_error ${caller} "\"${msg}\" failed" $? + fi +} + +# format the date in a specific form +# if changing the format, make sure +# that dateindent has the same length +# again (dateindent used for pretty +# printing multiline stuff without +# having to print the date in every line) +date="/bin/date +'%d %m %Y %T'" +# format dd mm yyyy HH:MM:ss +dateindent=' ' + +# +# Some generic, often used functions +# + +# return the current date/time in a +# predefined format - see above +# Use eg as +# echo "`timestamp` Aaargh - Failed to clobber!" +timestamp() { + eval ${date} +} + + +# strip both leading/trailing whitespace +# characters +strip_ws() { + rv= + if [ -n "$1" ]; then + # actually, you can do it in one go [when you + # finally read the fine manual of sed ;)] + cmd="echo '$1' | ${sed} 's/^ \{0,\}//;s/ \{0,\}$//'" + rv=`eval ${cmd}` + fi + echo ${rv} +} + +# escape special characters +escape_chars() { + rv= + cmd="echo '${1}' | ${sed} 's#\([].,*[() \\\\/]\)#\\\\\1#g'" + rv=`eval ${cmd}` + echo ${rv} +} + +# write all arguments to the logfile +dbglogfile="/tmp/dbglogfile" +dbglog() { + touch ${dbglogfile} + txt= + for ac do + txt="${txt} ${ac}" + done + echo ${txt} >> ${dbglogfile} +} + +# if the argument is a single string +# return 1 otherwise return 0 +# Single string meaning +# 'series of characters without +# space' +# Leading/trailing whitespace is +# ignored in the comparison +# +# Note: an empty string will +# NOT be matched as +# a single string and +# hence returns '0' +is_single_string() { + rv=0 + if [ -n "$1" ]; then + ltrem=`strip_ws "$1"` + # now see what happens if we remove remaining ws + cmd="echo '${ltrem}' | ${sed} 's/ //g'" + sstr=`eval ${cmd}` + if [ "${sstr}" = "${ltrem}" ]; then + rv=1 + fi + fi + echo ${rv} +} + + +# Mark the fact that we read this file... +generic_read="yes" + +# this is the final fi of the 'include guard' +fi + +# Add to the $PATH, only once to avoid double entries +pathadd() { + if [[ ":$PATH:" != *":$1:"* ]]; then + export PATH="${PATH:+"$PATH:"}$1" + fi +} diff --git a/tools/quartus/run_all_qsys b/tools/quartus/run_all_qsys index 05056ff9b567a3a31fee13a8fc74a17fda943f22..3db7158caed041a794491734cc871feefe4c2d04 100755 --- a/tools/quartus/run_all_qsys +++ b/tools/quartus/run_all_qsys @@ -45,7 +45,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_all_sopc b/tools/quartus/run_all_sopc index bc880f4a67d1b4a03de8d76a5cb9d76485cc6138..da8d1335791dae8afbf3109d92dcb31e80cb486d 100755 --- a/tools/quartus/run_all_sopc +++ b/tools/quartus/run_all_sopc @@ -46,7 +46,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_app b/tools/quartus/run_app index 6da1d68dc1f8862ba410bca72481675677faa233..941d14628b2d39f54303375b62a746e6d2604109 100755 --- a/tools/quartus/run_app +++ b/tools/quartus/run_app @@ -45,7 +45,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_app_clean b/tools/quartus/run_app_clean index 8f194ec833dd2ae1041bc47a7059f87b6a7c8ce6..75c45a093e06d62f40f0e16bb4949ec207684583 100755 --- a/tools/quartus/run_app_clean +++ b/tools/quartus/run_app_clean @@ -45,7 +45,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_bsp b/tools/quartus/run_bsp index 55b1ef7d700d4fdbd91632dc6581d54c41aa01b0..628b5429c3982007851d4f881cf22720e496e873 100755 --- a/tools/quartus/run_bsp +++ b/tools/quartus/run_bsp @@ -17,7 +17,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_mif b/tools/quartus/run_mif index c0421cbb976aa66fdc2d611a6d98fb34c25609bf..2592020ce181ca0da0528b5cd5582c91bfb9b1f4 100755 --- a/tools/quartus/run_mif +++ b/tools/quartus/run_mif @@ -43,7 +43,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_qcomp b/tools/quartus/run_qcomp index 704d394738c3d5e8e8a50ff8e05aff02ff90ce18..a7341c5f73a26ea3a2e1f8fceb49f1e04a412b13 100755 --- a/tools/quartus/run_qcomp +++ b/tools/quartus/run_qcomp @@ -46,7 +46,7 @@ set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_qsys b/tools/quartus/run_qsys index bb534f2e64c3469f090b5ead6ffa81e662b6c9a1..c0751d760ecb1551f0b85d93c5b4cdb42991399f 100755 --- a/tools/quartus/run_qsys +++ b/tools/quartus/run_qsys @@ -37,7 +37,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_rbf b/tools/quartus/run_rbf index a98d2e9bbf3151736b6e256232fa80a29dd8d6cb..a38aa8669381c815904585559ba33f39be46fbe6 100755 --- a/tools/quartus/run_rbf +++ b/tools/quartus/run_rbf @@ -36,7 +36,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_reg b/tools/quartus/run_reg index f96f36f8a48bb648f83435b36f2ec486e4e68352..f5c5d313023ddc343480ff93f6f3b58d4f1055ba 100755 --- a/tools/quartus/run_reg +++ b/tools/quartus/run_reg @@ -36,7 +36,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_regtest_synth b/tools/quartus/run_regtest_synth index f2a1cdbfd1c7fe460dbec9f3989da328abed8bf0..a18e6e1656f4889fdece6aa55346bdc51dfa20c9 100755 --- a/tools/quartus/run_regtest_synth +++ b/tools/quartus/run_regtest_synth @@ -33,7 +33,7 @@ ############################################################################### # Source generic.sh for functions such as unb_info ############################################################################### -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh ############################################################################### # We're assuming the local 'SVN' dir is up to date. Copy it to a timestamped diff --git a/tools/quartus/run_sof b/tools/quartus/run_sof index faf276d20b2fd6a6b4db66219731d4e00073740b..34011399b01c19dfb095890effbebf6b7732ac3b 100755 --- a/tools/quartus/run_sof +++ b/tools/quartus/run_sof @@ -33,7 +33,7 @@ fi # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_sopc b/tools/quartus/run_sopc index 651669bf87d419748ea503ec3b5af5ac7e9f6d30..b9090a8ebfa8af65ad34d1fd7ccd49aead344343 100755 --- a/tools/quartus/run_sopc +++ b/tools/quartus/run_sopc @@ -39,7 +39,7 @@ fi set -u # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset} diff --git a/tools/quartus/run_term b/tools/quartus/run_term index 36fa82d85f7ffe9f3a4d2e22b0249633a1f377c5..8fef2ceb3736aade146a0763c299ee90b7c8b7bd 100755 --- a/tools/quartus/run_term +++ b/tools/quartus/run_term @@ -32,7 +32,7 @@ if [ ! $1 ]; then fi # read generic functions/definitions -. ${UNB}/Firmware/software/build/generic.sh +. ${RADIOHDL}/tools/quartus/generic.sh toolset=$1 . ${RADIOHDL}/tools/quartus/set_quartus ${toolset}