forked from xR3b0rn/libxmlmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
182 lines (161 loc) · 3.65 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
# defaults
prefix=/usr/local
VERSION="0.6.0"
ERRORS=0
# Parse Arguments
Usage()
{
echo "$0 [options]"
echo ""
echo "Options:"
echo " --help|-h Print this usage note."
echo " --prefix|-p Insallation prefix."
}
while :
do
case $1 in
-h | --help)
Usage
exit 0
;;
-p | --prefix)
file=$2 # You might want to check if you really got FILE
shift 2
;;
--prefix=*)
prefix=${1#*=} # Delete everything up till "="
shift
;;
-*)
echo "unknown option: $1" >&2
echo ""
Usage
exit 0
;;
*) # no more options. Stop while loop
break
;;
esac
done
# test
# 1: the rest running
echo_test()
{
printf "%-40s" "$1"
}
# 1: result to display
echo_result()
{
printf "%10s\n" "$1"
}
# 1: command to check
check_tool()
{
echo_test "checking for $1 "
if command -v $1 >/dev/null 2>&1; then
echo_result "yes"
else
echo_result "no"
ERRORS=1
fi
}
# 1: name
# 2: module signature
check_pkg_module()
{
echo_test "checking for $2 "
if pkg-config "$2" --modversion >/dev/null 2>&1; then
echo_result "`pkg-config "$2" --modversion`"
export $1_CFLAGS="`pkg-config --cflags "$2"`"
export $1_LIBS="`pkg-config --libs "$2"`"
else
echo_result "no"
ERRORS=1
fi
}
# 1: header
# 2: compiler flags
check_header_c()
{
echo_test "checking for header $1 "
echo "#include <$1>" > conftest.c
if gcc -c conftest.c $CFLAGS $2 >/dev/null 2>&1; then
echo_result "yes"
else
echo_result "no"
ERRORS=1
fi
rm -f conftest.c conftest.o
}
# 1: lib to check
# 2: compiler flags
# 3: linker flags
check_lib_c()
{
echo_test "checking for library $1 "
echo "int main(int argc, char* argv[]) { }" >> conftest.c
if gcc conftest.c $CFLAGS -l$1 $2 $3 $LDFLAGS -o conftest.exe >/dev/null 2>&1; then
echo_result "yes"
else
echo_result "no"
ERRORS=1
fi
rm -f conftest.c conftest.exe
}
# 1: variable to hold result
# 2: libs to check for
# 3: compiler flags
# 4: linker flags
check_libs_c()
{
local LIBS=$2
local FOUND=0
for LIB in $LIBS; do
echo_test "checking for library $LIB "
echo "int main(int argc, char* argv[]) { }" >> conftest.c
if gcc conftest.c $CFLAGS -l$LIB $3 $4 $LDFLAGS -o conftest.exe >/dev/null 2>&1; then
echo_result "yes"
export $1=$LIB
FOUND=1
break
else
echo_result "no"
fi
rm -f conftest.c conftest.exe
done
if test $FOUND = 0; then
ERRORS=1
fi
}
# actual checks
check_tool "g++"
check_tool "make"
check_tool "pkg-config"
check_pkg_module "XML2" "libxml-2.0 >= 2.9.0"
#output
export_variable()
{
echo $1=${!1} >> config.mk
}
if test $ERRORS = 0; then
rm -f config.mk
echo ""
echo "Writing config.mk"
echo "CONFIG_MK_INCLUDED = 1" >> config.mk
echo "prefix ?= $prefix" >> config.mk
export_variable VERSION
export_variable XML2_CFLAGS
export_variable XML2_LIBS
echo "Writing libxmlmm.pc"
prefix_e=`echo "$prefix" | sed -e 's/[]\\\/()$*.^|[]/\\\\&/g'`
VERSION_e=`echo "$VERSION" | sed -e 's/[]\\\/()$*.^|[]/\\\\&/g'`
sed -e "s/@prefix@/$prefix_e/g" -e "s/@VERSION@/$VERSION_e/g" libxmlmm.pc.in > libxmlmm.pc
echo ""
echo "Everything OK."
echo ""
else
echo ""
echo "There where errors. Check output."
echo ""
fi