]> Dogcows Code - chaz/yoink/blobdiff - build/functions.sh
testing new non-autotools build system
[chaz/yoink] / build / functions.sh
diff --git a/build/functions.sh b/build/functions.sh
new file mode 100755 (executable)
index 0000000..c330d93
--- /dev/null
@@ -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/ /\\ /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
+}
+
This page took 0.020241 seconds and 4 git commands to generate.