-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure
executable file
·222 lines (200 loc) · 5.54 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env bash
#
# Homemade configure script for jomon. This is not generated by autoconf.
#
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
NORMAL=$(tput sgr0)
if [ -z "$CC" ]; then
CC="gcc"
fi
GEOIP_PATH="/usr/share/GeoIP"
GEOIP_DB="GeoIPCity.dat"
BUILD=".build_$$"
PREFIX="/usr/local"
HAVE_GEOIP=1
HAVE_OBSTACK=1
HAVE_STRLCPY=1
VERSION=$(git describe --abbrev=0)
VERSION=${VERSION:1}
INDENT=40
OK="${GREEN}OK$NORMAL"
FAIL="${RED}FAIL$NORMAL"
usage()
{
echo "Usage: ./configure [option]"
echo ""
echo " --disable-geoip : Build without libGeoIP"
echo " --set-geoip-path <path> : Set the default GeoIP path"
echo " [$GEOIP_PATH]"
echo " --prefix <PREFIX> : Install files in PREFIX"
echo " [$PREFIX]"
echo " -h, --help : Display help"
exit 0
}
check_gcc()
{
printf "[*] %-*s" "$INDENT" "Checking for $CC... "
echo "int main() { return 0; }" > "$BUILD.c"
$CC "$BUILD.c" -o "$BUILD" &> /dev/null
if [ ! -x "$BUILD" ]; then
printf "[$FAIL]\n\n"
if [[ $CC == "gcc" || $CC == "clang" ]]; then
printf "You need a functioning install of $CC. "
printf "This can be installed with \"pacman -S $CC\" or equivalent "
printf "command for your distribution.\n"
fi
rm -f "$BUILD.c" "$BUILD"
exit 1;
fi
rm -f "$BUILD.c" "$BUILD"
printf "[$OK]\n"
}
check_ncurses()
{
printf "[*] %-*s" "$INDENT" "Checking for libncurses... "
echo -e "#include <ncurses.h>\nint main() { initscr(); endwin(); }" > "$BUILD.c"
$CC "$BUILD.c" -o "$BUILD" -lncurses &> /dev/null
if [ ! -x "$BUILD" ]; then
printf "[$FAIL]\n\n"
printf "You need a functioning install of libncurses. "
printf "This can be installed with \"pacman -S ncurses\" or equivalent "
printf "command for your distribution.\n"
rm -f "$BUILD.c" "$BUILD"
exit 1
fi
rm -f "$BUILD.c" "$BUILD"
printf "[$OK]\n"
}
check_geoip()
{
printf "[*] %-*s" "$INDENT" "Checking for libGeoIP... "
cat >> "$BUILD.c" <<EOF
#include <GeoIP.h>
int main()
{
GeoIP *gip = GeoIP_open("$GEOIP_PATH/$GEOIP_DB", GEOIP_STANDARD);
GeoIP_delete(gip);
}
EOF
$CC "$BUILD.c" -o "$BUILD" -lGeoIP &> /dev/null
if [ ! -x "$BUILD" ]; then
printf "[$FAIL]\n\n"
printf "You need a functioning install of libGeoIP. "
printf "This can be installed with \"pacman -S geoip geoip-database "
printf "geoip-database-extra\" or equivalent command for your distribution.\n"
printf "To build without geoip you can use \"--disable-geoip\". Use -h "
printf "for help.\n"
rm -f "$BUILD.c" "$BUILD"
exit 1
fi
rm -f "$BUILD.c" "$BUILD"
printf "[$OK]\n"
}
check_re2c()
{
printf "[*] %-*s" "$INDENT" "Checking for re2c... "
command -v re2c >/dev/null ||
{
printf "[$FAIL]\n\n"
printf "re2c needs to be installed. This can be installed with ";
printf "\"pacman -S re2c\" or equivalent command for your distribution.\n";
exit 1;
}
printf "[$OK]\n"
}
check_python3()
{
printf "[*] %-*s" "$INDENT" "Checking for python3... "
command -v python3 >/dev/null ||
{
printf "[$FAIL]\n\n"
printf "python3 needs to be installed. This can be installed with ";
printf "\"pacman -S python\" or equivalent command for your distribution.\n";
exit 1;
}
printf "[$OK]\n"
}
check_missing()
{
echo -e "#include <obstack.h>\nint main() { struct obstack s; }" > "$BUILD.c"
$CC "$BUILD.c" -o "$BUILD" &> /dev/null
if [ ! -x "$BUILD" ]; then
HAVE_OBSTACK=0
fi
rm -f "$BUILD"
cat > "$BUILD.c" <<EOF
#include <string.h>
int main()
{
char dst[5];
strlcpy(dst, "test", sizeof(dst));
}
EOF
$CC "$BUILD.c" -o "$BUILD" &> /dev/null
if [ ! -x "$BUILD" ]; then
HAVE_STRLCPY=0
fi
rm -f "$BUILD.c" "$BUILD"
}
generate_config()
{
echo "[*] Generating config..."
echo "/* Autogenerated - do not edit */" > config.h
echo >> config.h
echo "#ifndef CONFIG_H" >> config.h
echo "#define CONFIG_H" >> config.h
echo >> config.h
echo "# Autogenerated - do not edit" > config.mk
echo >> config.mk
echo "CC=$CC" >> config.mk
echo "HAVE_GEOIP=$HAVE_GEOIP" >> config.mk
if [[ "$HAVE_GEOIP" == 1 ]]; then
echo "#define HAVE_GEOIP" >> config.h
echo "#define GEOIP_PATH \"$GEOIP_PATH/$GEOIP_DB\"" >> config.h
fi
if [[ "$HAVE_OBSTACK" == 1 ]]; then
echo "#define HAVE_OBSTACK" >> config.h
fi
if [[ "$HAVE_STRLCPY" == 1 ]]; then
echo "#define HAVE_STRLCPY" >> config.h
fi
echo "PREFIX=$PREFIX" >> config.mk
echo "HAVE_OBSTACK=$HAVE_OBSTACK" >> config.mk
echo "HAVE_STRLCPY=$HAVE_STRLCPY" >> config.mk
echo "VERSION=\"$VERSION\"" >> config.mk
echo >> config.h
echo "#endif" >> config.h
}
while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
usage
;;
--disable-geoip)
HAVE_GEOIP=0
;;
--set-geoip-path)
shift
GEOIP_PATH=$1
;;
--prefix)
shift
PREFIX=$1
;;
*)
echo "Invalid option. Use -h for help"
exit 1;
;;
esac
shift
done
check_gcc
check_ncurses
if [[ "$HAVE_GEOIP" == 1 ]]; then
check_geoip
fi
check_re2c
check_python3
check_missing
generate_config