-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·400 lines (361 loc) · 11.4 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
400
#!/bin/sh
# set -o pipefail
CONFIGURE_CMD_ARGS="${*}"
PACKAGE_VERSION="2.6.0-devel"
PACKAGE_DATE="UNRELEASED"
PACKAGE_STRING="gcli $PACKAGE_VERSION"
PACKAGE_BUGREPORT="https://lists.sr.ht/~herrhotzenplotz/gcli-discuss"
PACKAGE_URL="https://sr.ht/~herrhotzenplotz/gcli"
find_program() {
varname=$1
shift
printf "Checking for $varname ..." >&2
for x in $*; do
if (command -v $x >/dev/null 2>&1) && [ -x $(command -v $x) ]; then
printf " $x\n" >&2
echo $x
exit 0
fi
done
printf " not found\n" >&2
exit 1
}
die() {
printf "%s\n" "${*}"
exit 1
}
REALPATH=${REALPATH:-$(find_program realpath realpath grealpath)}
[ $? -eq 0 ] || die "error: need realpath" # exit code of find_program()
rel_srcdir="$(dirname ${0})"
srcdir="$(${REALPATH} ${rel_srcdir})"
tolower() {
tr '[:upper:]' '[:lower:]'
}
compiler_type() {
if ${1} -v 2>&1 | grep clang > /dev/null; then
echo "clang"
elif ${1} -v 2>&1 | grep '^gcc' > /dev/null; then
echo "gcc"
elif ${1} -qversion 2>&1 | grep 'IBM XL C' >/dev/null; then
echo "xlc"
elif ${1} -V 2>&1 | grep 'Studio' > /dev/null; then
echo "sunstudio"
else
echo "unknown"
fi
}
normalise_compiler_target() {
tolower | sed -e 's|x86_64|amd64|g' -e 's| ||g'
}
compiler_target() {
ccom=$1
cc=$2
case $ccom in
gcc|clang)
$cc -v 2>&1 \
| grep '^Target' \
| cut -d: -f2
;;
xlc)
# for xlc we can't easily get its target. instead we ask its
# configured assembler for the target. Right now I assume it
# is a GNU assembler. If this doesn't work for you please fix!
# I don't have access to any equipment running anything else
# and I will not beg IBM for giving me access.
xlc_config=$($cc -v 2>&1 | grep XL_CONFIG | sed 's|.*XL_CONFIG=\([^:]*\):.*|\1|')
[ -z "${xlc_config}" ] && die "xlc config file not detected"
xlc_as=$(cat $xlc_config | grep -E 'as[\t ]+.*=[ ]+' | sed 1q | cut -d= -f2 | sed 's| ||g')
[ -z "${xlc_as}" ] && die "failed to figure out assembler used by XL C"
$xlc_as --version 2>&1 | grep 'GNU assembler' >/dev/null || die "Can only derive compiler target from GNU assembler, please submit fix for your assembler"
$xlc_as --version 2>&1 | grep target | sed "s|.*\`\([^']*\)'.*|\1|"
;;
sunstudio)
# Only tested on Solaris 10 ... if this messes up on Linux or SunOS
# i86pc feel free to send a patch...
if $cc -V 2>&1 | grep SunOS_sparc > /dev/null; then
echo "sparc64-unknown-solaris"
else
echo "unknown-unknown-unknown"
fi
;;
*)
echo "unknown-unknown-unknown"
;;
esac | normalise_compiler_target
}
# args= pkgconfig-name variable-name is-mandatory
find_package() {
printf "Checking for $1 ..." >&2
if ! $PKG_CONFIG --exists $1; then
if [ "${3}" = optional ]; then
printf " not found\n"
export ${2}_FOUND=0
return
else # $3 = required
die "not found"
fi
fi
# readline and possibly other dependencies in Debian (yikes)
# return -D_XOPEN_SOURCE which breaks builds. Rip it out -
# we know what we're doing... ha!
export ${2}_CFLAGS="$($PKG_CONFIG --cflags $1 | sed 's|-D_XOPEN_SOURCE=[[:digit:]]*||g')"
export ${2}_LIBS="$($PKG_CONFIG --libs $1)"
export ${2}_FOUND=1
printf " found\n" >&2
}
usage() {
cat >&2 <<EOF
usage: ./configure [options]
Configure build directory of gcli.
OPTIONS:
--prefix=PREFIX Set installation prefix to PREFIX [DEFAULT: /usr/local]
--enable-libedit Search and use libedit for interactive editing [DEFAULT: yes]
--disable-libedit Do not use libedit
--enable-libreadline Search and use libreadline for interactive editing [DEFAULT: yes]
--disable-libreadline Disable use of libreadline
--debug Compile without optimisations, generate code with
debug information and enable additional compiler-specific
warnings and portability checks.
--release Optimise for release
--help Print this help
ENVIRONMENT:
CC Host system compiler to use [DEFAULT: cc]
CC_FOR_BUILD Build system compiler [DEFAULT: \$CC]
CFLAGS Host system C compiler flags
CFLAGS_FOR_BUILD Build system compiler flags
CPPFLAGS C Preprocessor flags for host system compiler
CPPFLAGS_FOR_BUILD C Preprocessor flags for build system compiler
PKG_CONFIG pkg-config to use [DEFAULT: autodetect]
AR Archiver to use [DEFAULT: autodetect]
RANLIB Ranlib to use [DEFAULT: autodetect]
RM rm to use [DEFAULT: autodetect]
KYUA Path to Kyua [DEFAULT: autodetect]
CCACHE Path to ccache [DEFAULT: autodetect]
INSTALL Path to install [DEFAULT: autodetect]
EOF
exit 1
}
# Install options
#
PREFIX=/usr/local
OPTIMISE=
ENABLE_LIBEDIT=1
ENABLE_LIBREADLINE=1
ENABLE_LIBLOWDOWN=1
# Parse flags
while [ $# -gt 0 ]; do
case "$1" in
--prefix=*)
PREFIX=${1##--prefix=}
shift
;;
--prefix)
PREFIX=${2}
shift; shift
;;
--enable-libedit)
ENABLE_LIBEDIT=1
shift
;;
--disable-libedit)
ENABLE_LIBEDIT=0
shift
;;
--enable-libreadline)
ENABLE_LIBREADLINE=1
shift
;;
--disable-libreadline)
ENABLE_LIBREADLINE=0
shift
;;
--enable-liblowdown)
ENABLE_LIBLOWDOWN=1
shift
;;
--disable-liblowdown)
ENABLE_LIBLOWDOWN=0
shift
;;
--debug)
OPTIMISE=debug
shift
;;
--release)
OPTIMISE=release
shift
;;
--help)
usage
;;
*)
die "error: unknown flag: $1"
;;
esac
done
###############################################################
# COMPILERS
###############################################################
# Host Compiler
printf "Checking host compiler ..."
CC=${CC:-cc}
printf " $CC\n"
# Detect the compiler type and enable dependency tracking
printf "Checking host compiler type ..."
CCOM=$(compiler_type "${CC}")
printf " $CCOM\n"
printf "Checking host compiler target ..."
HOST=$(compiler_target $CCOM "$CC $CFLAGS $CPPFLAGS")
printf " $HOST\n"
# Build compiler
printf "Checking for cross-compilation setup ..."
is_cross=0
CC_FOR_BUILD=${CC_FOR_BUILD:-${CC}}
if ! [ "${CC_FOR_BUILD}" = "${CC}" ]; then
is_cross=1
printf " yes\n"
else
printf " no\n"
fi
if [ $is_cross -eq 1 ]; then
printf "Checking build compiler type..."
CCOM_FOR_BUILD=$(compiler_type "${CC_FOR_BUILD}")
printf " ${CCOM_FOR_BUILD}\n"
printf "Checking build compiler target ..."
BUILD=$(compiler_target $CCOM_FOR_BUILD $CC_FOR_BUILD)
printf " $BUILD\n"
else
CCOM_FOR_BUILD="${CCOM}"
BUILD="${HOST}"
fi
############################################################################
# LIBRARIES
############################################################################
PKG_CONFIG=${PKG_CONFIG:-$(find_program pkg-config pkg-config pkgconf)}
[ $? -eq 0 ] || die "error: need pkg-config or pkgconf"
find_package libcurl LIBCURL required
find_package atf-c LIBATFC optional
find_package libcrypto LIBCRYPTO required
# Look for libedit if not disabled
if [ $ENABLE_LIBEDIT -eq 1 ]; then
find_package libedit LIBEDIT optional
else
LIBEDIT_FOUND=0
fi
# Now only look for readline if libedit hasn't been found/enabled
# and readline support hasn't been disabled.
if [ $LIBEDIT_FOUND -eq 1 ]; then
LIBREADLINE_FOUND=0
elif [ $ENABLE_LIBREADLINE -eq 1 ]; then
find_package readline LIBREADLINE optional
else
LIBREADLINE_FOUND=0
fi
# Lowdown
if [ $ENABLE_LIBLOWDOWN -eq 1 ]; then
find_package lowdown LIBLOWDOWN optional
else
LIBLOWDOWN_FOUND=0
fi
###################################################################
# TESTS and other programs
###################################################################
AR=${AR:-ar}
RANLIB=${RANLIB:-ranlib}
RM=${RM:-rm}
KYUA=${KYUA:-$(find_program kyua kyua)}
CCACHE=${CCACHE:-$(find_program ccache ccache)}
INSTALL=${INSTALL:-$(find_program install install ginstall)}
SHELL=${SHELL:-$(find_program sh sh zsh bash)}
[ $? -eq 0 ] || die "error: need install program"
###################################################################
# Configure Makefile
###################################################################
#
# FIXME: this escapes the source directory in case it contains
# spaces. however, both GNU and BSD make are incapable of
# handling hese situations in combination with VPATH. On
# NetBSD we get a bug where it hard-splits the path on spaces
# in a prerequisite no matter whether it is escaped or not.
ESC_SRCDIR="$(echo ${srcdir} | sed -e 's| |\\\\ |g')"
sed \
-e "s|@SRCDIR@|${ESC_SRCDIR}|g" \
-e "s|@OPTIMISE@|$OPTIMISE|g" \
-e "s|@LIBCURL_CFLAGS@|$LIBCURL_CFLAGS|g" \
-e "s|@LIBCURL_LIBS@|$LIBCURL_LIBS|g" \
-e "s|@LIBCRYPTO_CFLAGS@|$LIBCRYPTO_CFLAGS|g" \
-e "s|@LIBCRYPTO_LIBS@|$LIBCRYPTO_LIBS|g" \
-e "s|@LIBATFC_CFLAGS@|$LIBATFC_CFLAGS|g" \
-e "s|@LIBATFC_LIBS@|$LIBATFC_LIBS|g" \
-e "s|@LIBEDIT_FOUND@|$LIBEDIT_FOUND|g" \
-e "s|@LIBEDIT_CFLAGS@|$LIBEDIT_CFLAGS|g" \
-e "s|@LIBEDIT_LIBS@|$LIBEDIT_LIBS|g" \
-e "s|@LIBREADLINE_FOUND@|$LIBREADLINE_FOUND|g" \
-e "s|@LIBREADLINE_CFLAGS@|$LIBREADLINE_CFLAGS|g" \
-e "s|@LIBREADLINE_LIBS@|$LIBREADLINE_LIBS|g" \
-e "s|@LIBLOWDOWN_FOUND@|$LIBLOWDOWN_FOUND|g" \
-e "s|@LIBLOWDOWN_CFLAGS@|$LIBLOWDOWN_CFLAGS|g" \
-e "s|@LIBLOWDOWN_LIBS@|$LIBLOWDOWN_LIBS|g" \
-e "s|@CONFIGURE_CMD_ARGS@|$CONFIGURE_CMD_ARGS|g" \
-e "s|@CC@|$CC|g" \
-e "s|@CCOM@|$CCOM|g" \
-e "s|@ENV_CFLAGS@|$CFLAGS|g" \
-e "s|@ENV_CPPFLAGS@|$CPPFLAGS|g" \
-e "s|@CC_FOR_BUILD@|$CC_FOR_BUILD|g" \
-e "s|@CCOM_FOR_BUILD@|$CCOM_FOR_BUILD|g" \
-e "s|@ENV_CFLAGS_FOR_BUILD@|$CFLAGS_FOR_BUILD|g" \
-e "s|@ENV_CPPFLAGS_FOR_BUILD@|$CPPFLAGS_FOR_BUILD|g" \
-e "s|@ENV_PKG_CONFIG@|$PKG_CONFIG|g" \
-e "s|@ENV_PKG_CONFIG_PATH@|$PKG_CONFIG_PATH|g" \
-e "s|@AR@|$AR|g" \
-e "s|@CCACHE@|$CCACHE|g" \
-e "s|@RANLIB@|$RANLIB|g" \
-e "s|@RM@|$RM|g" \
-e "s|@KYUA@|$KYUA|g" \
-e "s|@INSTALL@|$INSTALL|g" \
-e "s|@SHELL@|$SHELL|g" \
-e "s|@PREFIX@|$PREFIX|g" \
-e "s|@PACKAGE_STRING@|$PACKAGE_STRING|g" \
-e "s|@PACKAGE_DATE@|$PACKAGE_DATE|g" \
-e "s|@PACKAGE_BUGREPORT@|$PACKAGE_BUGREPORT|g" \
-e "s|@PACKAGE_URL@|$PACKAGE_URL|g" \
-e "s|@PACKAGE_VERSION@|$PACKAGE_VERSION|g" \
< "${srcdir}/Makefile.in" > Makefile
echo "Writing config.h"
cat > config.h <<EOF
#define PACKAGE_STRING "$PACKAGE_STRING"
#define PACKAGE_URL "$PACKAGE_URL"
#define PACKAGE_VERSION "$PACKAGE_VERSION"
#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
#define PACKAGE_DATE "$PACKAGE_DATE"
#define HOSTOS "$HOST"
EOF
echo "Configuration summary for ${PACKAGE_STRING}:"
echo ""
echo " Build system type: ${BUILD}"
echo " Host system type: ${HOST}"
echo " optimise for: ${OPTIMISE:-none}"
echo " CC: ${CC}"
echo " CC_FOR_BUILD: ${CC_FOR_BUILD}"
echo " CFLAGS: ${CFLAGS}"
echo " CFLAGS_FOR_BUILD: ${CFLAGS_FOR_BUILD}"
echo " LIBCURL_CFLAGS: ${LIBCURL_CFLAGS}"
echo " LIBCURL_LIBS: ${LIBCURL_LIBS}"
echo " LIBATFC_CFLAGS: ${LIBATFC_CFLAGS}"
echo " LIBATFC_LIBS: ${LIBATFC_LIBS}"
if [ $LIBEDIT_FOUND -eq 1 ]; then
echo " Using libedit:"
echo " LIBEDIT_CFLAGS: ${LIBEDIT_CFLAGS}"
echo " LIBEDIT_LIBS: ${LIBEDIT_LIBS}"
elif [ $LIBREADLINE_FOUND -eq 1 ]; then
echo " Using libreadline:"
echo " LIBREADLINE_CFLAGS: ${LIBREADLINE_CFLAGS}"
echo " LIBREADLINE_LIBS: ${LIBREADLINE_LIBS}"
fi
if [ $LIBLOWDOWN_FOUND -eq 1 ]; then
echo " Using lowdown:"
echo " LIBLOWDOWN_CFLAGS: ${LIBLOWDOWN_CFLAGS}"
echo " LIBLOWDOWN_LIBS: ${LIBLOWDOWN_LIBS}"
fi
echo ""
echo "Configuration done. You may now run make."