# 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 }