X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=build%2Ffunctions.sh;fp=build%2Ffunctions.sh;h=c330d939f44826723a84816a4739d3b8a4c74a70;hp=0000000000000000000000000000000000000000;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hpb=85783316365181491a3e3c0c63659972477cebba diff --git a/build/functions.sh b/build/functions.sh new file mode 100755 index 0000000..c330d93 --- /dev/null +++ b/build/functions.sh @@ -0,0 +1,93 @@ + + +# Print error message to stderr and exit. The error message can either be +# given as parameters or from stdin. +die() +{ + echo -n "fatal: " >/dev/stderr + if [ "x$*" != x ] + then + echo $* >/dev/stderr + else + while read line; + do + echo $line >/dev/stderr + done + fi + exit 1 +} + +# Parse an argument from an option in the form --option=argument. +parse_argument() +{ + echo $(echo $2 | sed -e "s/--$1=\\(.*\\)$/\\1/") + return $? +} + +# Insert all the escapes necessary to correctly quote a string for use in a +# shell command. +quote_string() +{ + for arg in "$@" + do + echo $1 | sed -e "s/'/\\'/g" \ + -e 's/"/\\"/g' \ + -e 's/|/\\|/g' \ + -e 's/&/\\&/g' \ + -e 's/;/\\;/g' \ + -e 's/;/\\;/g' \ + -e 's/(/\\(/g' \ + -e 's/)/\\)/g' \ + -e 's//\\>/g' \ + -e 's/ /\\ /g' \ + -e "s/\t/\\\t/g" \ + -e 's/\$/\\\$/g' + done +} + +# Add a definition to the compiler flags. The optional second parameter is +# the unquoted value. +define() +{ + if test "x$2" = x + then + defines="$defines -D$1" + else + defines="$defines -D$1=$2" + fi +} + +# Add a definition to the compiler flags with a quoted value. +define_string() +{ + arg=$(quote_string "$2") + define "$1" "\\\"$arg\\\"" +} + +undefine() +{ + for arg in "$@" + do + defines="$defines -U$arg" + done +} + +is_defined() +{ + for arg in "$@" + do + echo "$defines" | grep -e "-D$arg" 2>&1 >/dev/null || return 1 + done + return 0 +} + +is_undefined() +{ + for arg in "$@" + do + echo "$defines" | grep -e "-U$arg" 2>&1 >/dev/null || return 1 + done + return 0 +} +