]> Dogcows Code - chaz/yoink/blob - build/functions.sh
c330d939f44826723a84816a4739d3b8a4c74a70
[chaz/yoink] / build / functions.sh
1
2
3 # Print error message to stderr and exit. The error message can either be
4 # given as parameters or from stdin.
5 die()
6 {
7 echo -n "fatal: " >/dev/stderr
8 if [ "x$*" != x ]
9 then
10 echo $* >/dev/stderr
11 else
12 while read line;
13 do
14 echo $line >/dev/stderr
15 done
16 fi
17 exit 1
18 }
19
20 # Parse an argument from an option in the form --option=argument.
21 parse_argument()
22 {
23 echo $(echo $2 | sed -e "s/--$1=\\(.*\\)$/\\1/")
24 return $?
25 }
26
27 # Insert all the escapes necessary to correctly quote a string for use in a
28 # shell command.
29 quote_string()
30 {
31 for arg in "$@"
32 do
33 echo $1 | sed -e "s/'/\\'/g" \
34 -e 's/"/\\"/g' \
35 -e 's/|/\\|/g' \
36 -e 's/&/\\&/g' \
37 -e 's/;/\\;/g' \
38 -e 's/;/\\;/g' \
39 -e 's/(/\\(/g' \
40 -e 's/)/\\)/g' \
41 -e 's/</\\</g' \
42 -e 's/>/\\>/g' \
43 -e 's/ /\\ /g' \
44 -e "s/\t/\\\t/g" \
45 -e 's/\$/\\\$/g'
46 done
47 }
48
49 # Add a definition to the compiler flags. The optional second parameter is
50 # the unquoted value.
51 define()
52 {
53 if test "x$2" = x
54 then
55 defines="$defines -D$1"
56 else
57 defines="$defines -D$1=$2"
58 fi
59 }
60
61 # Add a definition to the compiler flags with a quoted value.
62 define_string()
63 {
64 arg=$(quote_string "$2")
65 define "$1" "\\\"$arg\\\""
66 }
67
68 undefine()
69 {
70 for arg in "$@"
71 do
72 defines="$defines -U$arg"
73 done
74 }
75
76 is_defined()
77 {
78 for arg in "$@"
79 do
80 echo "$defines" | grep -e "-D$arg" 2>&1 >/dev/null || return 1
81 done
82 return 0
83 }
84
85 is_undefined()
86 {
87 for arg in "$@"
88 do
89 echo "$defines" | grep -e "-U$arg" 2>&1 >/dev/null || return 1
90 done
91 return 0
92 }
93
This page took 0.030714 seconds and 3 git commands to generate.