-
Notifications
You must be signed in to change notification settings - Fork 5
/
configure
executable file
·399 lines (348 loc) · 10.1 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#!/bin/sh
. package/info
usage () {
cat <<EOF
Usage: $0 [OPTION]... [TARGET]
Defaults for the options are specified in brackets.
System types:
--target=TARGET configure to run on target TARGET [detected]
--host=TARGET same as --target
Installation directories:
--prefix=PREFIX main installation prefix [/usr/local]
--exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
Fine tuning of the installation directories:
--bindir=BINDIR user executables [EPREFIX/bin]
Dependencies:
--with-sysdeps=DIR use sysdeps in DIR [PREFIX/lib/skalibs/sysdeps]
--with-include=DIR add DIR to the list of searched directories for headers
--with-lib=DIR add DIR to the list of searched directories for static libraries
--with-dynlib=DIR add DIR to the list of searched directories for shared libraries
If no --prefix option is given, by default sysdeps will be fetched from
/usr/lib/skalibs/sysdeps.
Optional features:
--disable-allstatic do not prefer linking against static libraries [enabled]
--enable-static-libc make entirely static binaries [disabled]
--enable-all-pic build everything as PIC [enabled iff toolchain builds PIE]
EOF
exit 0
}
# Helper functions
# If your system does not have printf, you can comment this, but it is
# generally not a good idea to use echo.
# See http://www.etalabs.net/sh_tricks.html
echo () {
IFS=" "
printf %s\\n "$*"
}
quote () {
tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
$1
EOF
echo "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#" -e "s|\*/|* /|g"
}
fail () {
echo "$*"
exit 1
}
fnmatch () {
eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac"
}
cmdexists () {
type "$1" >/dev/null 2>&1
}
trycc () {
test -z "$CC_AUTO" && cmdexists "$1" && CC_AUTO="$*"
}
stripdir () {
while eval "fnmatch '*/' \"\${$1}\"" ; do
eval "$1=\${$1%/}"
done
}
tryflag () {
echo "checking whether compiler accepts $2 ..."
echo "typedef int x;" > "$tmpc"
if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST "$2" -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
echo " ... yes"
eval "$1=\"\${$1} \$2\""
eval "$1=\${$1# }"
return 0
else
echo " ... no"
return 1
fi
}
tryldflag () {
echo "checking whether linker accepts $2 ..."
echo "typedef int x;" > "$tmpc"
if $CC_AUTO $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -nostdlib "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
echo " ... yes"
eval "$1=\"\${$1} \$2\""
eval "$1=\${$1# }"
return 0
else
echo " ... no"
return 1
fi
}
tryinclude () {
macro="$1"
header="$2"
echo "Checking whether system has <$header>"
echo "#include <$header>" > "$tmpc"
echo "int main(void) { return 0; }" >> "$tmpc"
if $CC_AUTO $CPPFLAGS_AUTO $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
echo " ... yes"
eval "$macro=true"
else
echo " ... no"
eval "$macro=false"
fi
}
# Actual script
CC_AUTO=
CPPFLAGS_AUTO="-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -iquote src/include-local -Isrc/include"
CPPFLAGS_POST="$CPPFLAGS"
CPPFLAGS=
CFLAGS_AUTO="-pipe -Wall"
CFLAGS_POST="$CFLAGS"
CFLAGS=-O2
LDFLAGS_AUTO=
LDFLAGS_POST="$LDFLAGS"
LDFLAGS=
LDFLAGS_NOSHARED=
LDFLAGS_SHARED=-shared
prefix=/usr/local
exec_prefix='$prefix'
bindir='$exec_prefix/bin'
sysdeps='$prefix/lib/skalibs/sysdeps'
manualsysdeps=false
allpic=detect
slashpackage=false
abspath=false
home=
exthome=
allstatic=true
evenmorestatic=false
addincpath=''
addlibspath=''
addlibdpath=''
vpaths=''
vpathd=''
build=
ssl=
for arg ; do
case "$arg" in
--help) usage ;;
--prefix=*) prefix=${arg#*=} ;;
--exec-prefix=*) exec_prefix=${arg#*=} ;;
--dynlibdir=*) dynlibdir=${arg#*=} ;;
--bindir=*) bindir=${arg#*=} ;;
--with-sysdeps=*) sysdeps=${arg#*=} manualsysdeps=true ;;
--with-include=*) var=${arg#*=} ; stripdir var ; addincpath="$addincpath -I$var" ;;
--with-lib=*) var=${arg#*=} ; stripdir var ; addlibspath="$addlibspath -L$var" ; vpaths="$vpaths $var" ;;
--with-dynlib=*) var=${arg#*=} ; stripdir var ; addlibdpath="$addlibdpath -L$var" ; vpathd="$vpathd $var" ;;
--enable-allstatic|--enable-allstatic=yes) allstatic=true ;;
--disable-allstatic|--enable-allstatic=no) allstatic=false ; evenmorestatic=false ;;
--enable-static-libc|--enable-static-libc=yes) allstatic=true ; evenmorestatic=true ;;
--disable-static-libc|--enable-static-libc=no) evenmorestatic=false ;;
--enable-all-pic|--enable-all-pic=yes) allpic=true ;;
--disable-all-pic|--enable-all-pic=no) allpic=false ;;
--enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
--host=*|--target=*) target=${arg#*=} ;;
--build=*) build=${arg#*=} ;;
-* ) echo "$0: unknown option $arg" ;;
*=*) ;;
*) target=$arg ;;
esac
done
# Add /usr in the default default case
if test -z "$prefix" ; then
if test "$libdir" = '$prefix/lib/$package' ; then
libdir=/usr/lib/$package
fi
if test "$includedir" = '$prefix/include' ; then
includedir=/usr/include
fi
if test "$sysdeps" = '$prefix/lib/skalibs/sysdeps' ; then
sysdeps=/usr/lib/skalibs/sysdeps
fi
fi
# Expand installation directories
stripdir prefix
for i in exec_prefix bindir sysdeps ; do
eval tmp=\${$i}
eval $i=$tmp
stripdir $i
done
# Get usable temp filenames
i=0
set -C
while : ; do
i=$(($i+1))
tmpc="./tmp-configure-$$-$PPID-$i.c"
tmpe="./tmp-configure-$$-$PPID-$i.tmp"
2>|/dev/null > "$tmpc" && break
2>|/dev/null > "$tmpe" && break
test "$i" -gt 50 && fail "$0: cannot create temporary files"
done
set +C
trap 'rm -f "$tmpc" "$tmpe"' EXIT ABRT INT QUIT TERM HUP
# Find a C compiler to use
if test -n "$target" && test x${build} != x${target} ; then
cross=${target}-
else
cross=
fi
echo "checking for C compiler..."
trycc ${cross}${CC}
trycc ${cross}gcc
trycc ${cross}clang
trycc ${cross}cc
test -n "$CC_AUTO" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
echo " ... $CC_AUTO"
echo "checking whether C compiler works... "
echo "typedef int x;" > "$tmpc"
if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -c -o /dev/null "$tmpc" 2>"$tmpe" ; then
echo " ... yes"
else
echo " ... no. Compiler output follows:"
cat < "$tmpe"
exit 1
fi
echo "checking target system type..."
if test -z "$target" ; then
if test -n "$build" ; then
target=$build ;
else
target=$($CC_AUTO -dumpmachine 2>/dev/null) || target=unknown
fi
fi
echo " ... $target"
if test ! -d $sysdeps || test ! -f $sysdeps/target ; then
echo "$0: error: $sysdeps is not a valid sysdeps directory"
exit 1
fi
if [ "x$target" != "x$(cat $sysdeps/target)" ] ; then
echo "$0: error: target $target does not match the contents of $sysdeps/target"
exit 1
fi
if test $allpic = detect ; then
echo "Checking whether we need to build everything as PIC..."
if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -dM -E - < /dev/null | grep -qF __PIE__ ; then
allpic=true
echo " ... yes"
else
allpic=false
echo " ... no"
fi
fi
if $allpic ; then
tryflag CFLAGS_AUTO -fPIC
fi
spawn_lib=$(cat $sysdeps/spawn.lib)
socket_lib=$(cat $sysdeps/socket.lib)
sysclock_lib=$(cat $sysdeps/sysclock.lib)
tainnow_lib=$(cat $sysdeps/tainnow.lib)
timer_lib=$(cat $sysdeps/timer.lib)
util_lib=$(cat $sysdeps/util.lib)
tryflag CFLAGS_AUTO -std=c99
tryflag CPPFLAGS_AUTO -Wall
tryflag CPPFLAGS_AUTO -Wextra
tryflag CPPFLAGS_AUTO -Werror
CPPFLAGS_AUTO="${CPPFLAGS_AUTO}${addincpath}"
tryinclude POSIXPLZ "skalibs/posixplz.h"
if $evenmorestatic ; then
LDFLAGS_NOSHARED=-static
fi
LDFLAGS_SHARED="${LDFLAGS_SHARED}${addlibdpath}"
if $allstatic ; then
LDFLAGS_NOSHARED="${LDFLAGS_NOSHARED}${addlibspath}"
else
LDFLAGS_NOSHARED="${LDFLAGS_NOSHARED}${addlibdpath}"
fi
if test -z "$vpaths" ; then
while read dep ; do
base=$(basename $dep) ;
vpaths="$vpaths /usr/lib/$base"
addlibspath="$addlibspath -L/usr/lib/$base"
done < package/deps-build
fi
echo "creating config.mak..."
cmdline=$(quote "$0")
for i ; do cmdline="$cmdline $(quote "$i")" ; done
exec 3>&1 1>config.mak
cat << EOF
# This file was generated by:
# $cmdline
# Any changes made here will be lost if configure is re-run.
target := $target
package := $package
prefix := $prefix
exec_prefix := $exec_prefix
dynlibdir := $dynlibdir
libexecdir := $libexecdir
bindir := $bindir
libdir := $libdir
includedir := $includedir
sysdeps := $sysdeps
version := $version
home := $home
exthome := $exthome
SPAWN_LIB := ${spawn_lib}
SOCKET_LIB := ${socket_lib}
SYSCLOCK_LIB := ${sysclock_lib}
TAINNOW_LIB := ${tainnow_lib}
TIMER_LIB := ${timer_lib}
UTIL_LIB := ${util_lib}
CC := ${CC_AUTO##${cross}}
CPPFLAGS_AUTO := $CPPFLAGS_AUTO
CPPFLAGS := $CPPFLAGS $CPPFLAGS_POST
CFLAGS_AUTO := $CFLAGS_AUTO
CFLAGS := $CFLAGS $CFLAGS_POST
LDFLAGS_AUTO := $LDFLAGS_AUTO
LDFLAGS := $LDFLAGS $LDFLAGS_POST
LDFLAGS_SHARED := $LDFLAGS_SHARED
LDFLAGS_NOSHARED := $LDFLAGS_NOSHARED
CROSS_COMPILE := $cross
vpath lib%.a$vpaths
vpath lib%.so$vpathd
EOF
if $allstatic ; then
echo ".LIBPATTERNS := lib%.a"
echo "DO_ALLSTATIC := 1"
else
echo ".LIBPATTERNS := lib%.so"
fi
if $allpic ; then
echo "STATIC_LIBS_ARE_PIC := 1"
else
echo "STATIC_LIBS_ARE_PIC :="
fi
if test -n $ssl ; then
echo "SSL_IMPL := $ssl"
else
echo "SSL_IMPL :="
fi
exec 1>&3 3>&-
echo " ... done."
echo "creating src/include/${package}/config.h..."
mkdir -p -m 0755 src/include/${package}
exec 3>&1 1> src/include/${package}/config.h
cat <<EOF
/* ISC license. */
/* Generated by: $cmdline */
#ifndef ${package_macro_name}_CONFIG_H
#define ${package_macro_name}_CONFIG_H
#define ${package_macro_name}_VERSION "$version"
EOF
echo "#define ${package_macro_name}_BINPREFIX \"\""
echo "#define ${package_macro_name}_EXTBINPREFIX \"\""
if $POSIXPLZ ; then
echo "#define ${package_macro_name}_HASPOSIXPLZ"
else
echo "#undef ${package_macro_name}_HASPOSIXPLZ"
fi
echo
echo "#endif"
exec 1>&3 3>&-
echo " ... done."