-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·274 lines (240 loc) · 7.77 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/sh
# TODO: fix the ldconfig finding in print_config so we can use set -e again
# set -e
prefix=/usr/local
debugsym=false
completion=true
utf8=true
build_static=true
build_shared=true
build_executable=true
termux_build=false
NAME="tekstitv"
MAJOR_VERSION=`awk '/TEKSTITV_MAJOR_VERSION/{print $3}' include/tekstitv.h`
MINOR_VERSION=`awk '/TEKSTITV_MINOR_VERSION/{print $3}' include/tekstitv.h`
BIN_LINKS="-lcurl"
CFLAGS="-std=c99 -Wall -Wextra -Wno-unused-parameter -Wformat-security -Wno-unused-result -Wstrict-prototypes -pedantic -fPIC"
TARGETS=""
INSTALLS=""
UNINSTALLS=""
print_config() {
print_found() {
printf "$1"
if [ -z "$2" ]; then printf "not found\n"; else printf "found\n"; fi
}
print_use() {
printf "$1"
if $2 ; then printf "true\n"; else printf "false\n"; fi
}
printf "configuring: $NAME version $MAJOR_VERSION.$MINOR_VERSION\n\n"
printf "finding compiler... "
compiler=""
version=""
compilerpath=`which gcc`
# Test gcc first
if [ "$compilerpath" ]; then
compiler="gcc"
fi
# Test clang if gcc is not found
# Or test if gcc is actually symbolic link to gcc
realgcc=`gcc --version | head -1 | cut -d" " -f1`
if [ -z "$compiler" -o $realgcc = "clang" ]; then
compilerpath=`which clang`
if [ "$compilerpath" ]; then
compiler="clang"
fi
fi
# Fail if gcc nor clang is found
if [ -z "$compiler" ]; then
printf "\nError! Neither gcc nor clang was found.\n"
exit 1
fi
# Find compiler version
if [ "$compiler" = "gcc" ]; then
version=`gcc --version | head -1 | cut -d" " -f4`
elif [ "$compiler" = "clang" ]; then
version=`clang --version | head -1 | cut -d" " -f3`
fi
printf "\nusing $compiler. version: $version\n\n"
echo "finding libraries..."
if [ "$termux_build" = true ]; then
dpkg_list=`dpkg --list`
curl=`echo $dpkg_list | grep libcurl`
print_found "finding curl... " $curl
ncurses=`echo $dpkg_list | grep ncurses`
print_found "finding ncurses... " $ncurses
ncursesw=`echo $dpkg_list | grep ncursesw`
print_found "finding ncursesw... " $ncursesw
else
ldconf=`which ldconfig`
if [ -z "$ldconf" ]; then
ldconf="/sbin/ldconfig -p"
else
ldconf="ldconfig -p"
fi
ldconf=`$ldconf`
curl=`echo $ldconf | grep curl\.so`
print_found "finding curl... " $curl
ncurses=`echo $ldconf | grep ncurses\.so`
print_found "finding ncurses... " $ncurses
ncursesw=`echo $ldconf | grep ncursesw\.so`
print_found "finding ncursesw... " $ncursesw
fi
printf "\nconfiguration:\n"
print_use "using utf-8... " $utf8
print_use "using debugging... " $debugsym
print_use "building for termux... " $termux_build
print_use "building executable... " $build_executable
print_use "building static libary... " $build_static
print_use "building shared library... " $build_shared
print_use "installing bash completion... " $completion
printf "\nbuilding:\n"
echo "build path: `pwd`/build"
echo "library links: $BIN_LINKS"
echo "compiler flags: $CFLAGS"
printf "\ninstallation:\n"
if $build_executable; then echo "binary installation directory: $bindir"; fi
if $build_static || $build_shared; then
echo "library installation directory: $libdir"
echo "include hearder installation directory: $includedir"
fi
if $completion; then echo "completion installation directory: $completiondir"; fi
}
print_usage() {
printf 'Usage: ./configure [options]\n'
printf 'Options:\n'
printf '\t--prefix=<path>\t\tinstallation prefix. (Default: /usr/local)\n'
printf '\t--libdir=<path>\t\tobject code libraries (Default: $prefix/lib)\n'
printf '\t--bindir=<path>\t\tuser executables (Default: $prefix/bin)\n'
printf '\t--includedir=<path>\tC header files (Default: $prefix/include)\n'
printf '\t--completiondir=<path>\twhere to install completion (Default: /etc/bash_completion.d)\n'
printf '\t--disable-completion\tdo not install the bash completion (Default: enabled)\n'
printf '\t--enable-debug\t\tenable debugging (Default: disbled)\n'
printf '\t--disable-utf8\t\tdisable utf-8 support from parser library (Default enabled)\n'
printf '\t--disable-lib-build\tdo not build any libraries (Default enabled)\n'
printf '\t--disable-static-lib\tdo not build static libraries (Default enabled)\n'
printf '\t--disable-shared-lib\tdo not build shared libraries (Default enabled)\n'
printf '\t--disable-executable\tdo not build the tekstitv executable (Default enabled)\n'
exit 0
}
for arg in "$@"; do
case "$arg" in
--prefix=*)
prefix=`echo $arg | sed 's/--prefix=//'`
;;
--libdir=*)
libdir=`echo $arg | sed 's/--libdir=//'`
;;
--bindir=*)
bindir=`echo $arg | sed 's/--bindir=//'`
;;
--includedir=*)
includedir=`echo $arg | sed 's/--includedir=//'`
;;
--completiondir=*)
completiondir=`echo $arg | sed 's/--completiondir=//'`
;;
--disable-completion)
completion=false
;;
--enable-debug)
debugsym=true
;;
--termux-build)
termux_build=true
;;
--disable-lib-build)
build_static=false
build_shared=false
;;
--disable-static-lib)
build_static=false
;;
--disable-shared-lib)
build_shared=false
;;
--disable-executable)
build_executable=false
;;
--disable-utf8)
utf8=false
;;
--help)
print_usage
;;
*)
echo "Invalid option: " $arg
print_usage
;;
esac
done
if [ -z $libdir ]; then
libdir=$prefix/lib
fi
if [ -z $bindir ]; then
bindir=$prefix/bin
fi
if [ -z $includedir ]; then
includedir=$prefix/include
fi
if [ -z $completiondir ]; then
completiondir=/etc/bash_completion.d
fi
if ! $build_shared && ! $build_static && ! $build_executable; then
echo "Error: cannot disable all builds"
print_usage
fi
if $build_shared; then
TARGETS="$TARGETS shared"
INSTALLS="$INSTALLS install_shared"
UNINSTALLS="$UNINSTALLS uninstall_shared"
fi
if $build_static; then
TARGETS="$TARGETS static"
INSTALLS="$INSTALLS install_static"
UNINSTALLS="$UNINSTALLS uninstall_static"
fi
if $build_shared || $build_static; then
INSTALLS="$INSTALLS install_headers"
UNINSTALLS="$UNINSTALLS uninstall_headers"
fi
if $build_executable; then
TARGETS="$TARGETS executable"
INSTALLS="$INSTALLS install_executable"
UNINSTALLS="$UNINSTALLS uninstall_executable"
if $utf8; then
BIN_LINKS="$BIN_LINKS -lncursesw"
else
BIN_LINKS="$BIN_LINKS -lncurses"
fi
fi
if $completion; then
INSTALLS="$INSTALLS install_completion"
UNINSTALLS="$UNINSTALLS uninstall_completion"
fi
if $debugsym; then
CFLAGS="$CFLAGS -g -DDEBUG"
else
CFLAGS="$CFLAGS -Werror -O3 -flto"
fi
if ! $utf8; then
CFLAGS="$CFLAGS -DDISABLE_UTF_8"
fi
# Print configuration so user can see possible config errors easier
print_config
printf '\nGenerating makefile ...\n'
echo "BIN_NAME = $NAME" > Makefile
echo "MAJOR_VERSION = $MAJOR_VERSION" >> Makefile
echo "MINOR_VERSION = $MINOR_VERSION" >> Makefile
echo "PREFIX = $prefix" >> Makefile
echo "LIBDIR = $libdir" >> Makefile
echo "BINDIR = $bindir" >> Makefile
echo "COMPLETIONDIR = $completiondir" >> Makefile
echo "INCLUDEDIR = $includedir" >> Makefile
echo "CFLAGS = $CFLAGS" >> Makefile
echo "BIN_LINKS = $BIN_LINKS" >> Makefile
echo "TARGETS = $TARGETS" >> Makefile
echo "INSTALLS = $INSTALLS" >> Makefile
echo "UNINSTALLS = $UNINSTALLS" >> Makefile
cat Makefile.in >> Makefile
echo 'Configuration complete, type make to build.'