-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·304 lines (268 loc) · 8.04 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
#!/bin/sh
#
# Thanks to liburing (https://github.com/axboe/liburing)
#
cc=${CC:-gcc}
cxx=${CXX:-g++}
ld=${LD:-$cc}
CONFIG_LINUX=y
USER_CFLAGS=${CFLAGS}
USER_CXXFLAGS=${CXXFLAGS}
USER_LDFLAGS=${LDFLAGS}
USER_LIB_LDFLAGS=${LIB_LDFLAGS}
for opt do
optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
case "$opt" in
--help|-h) show_help=yes
;;
--prefix=*) prefix="$optarg"
;;
--includedir=*) includedir="$optarg"
;;
--libdir=*) libdir="$optarg"
;;
--libdevdir=*) libdevdir="$optarg"
;;
--mandir=*) mandir="$optarg"
;;
--datadir=*) datadir="$optarg"
;;
--cc=*) cc="$optarg"
;;
--cxx=*) cxx="$optarg"
;;
--ld=*) ld="$optarg"
;;
--cflags=*) USER_CFLAGS="$optarg"
;;
--cxxflags=*) USER_CXXFLAGS="$optarg"
;;
--ldflags=*) USER_LDFLAGS="$optarg"
;;
--lib-ldflags=*) USER_LIB_LDFLAGS="$optarg"
;;
--32-bit) USE_32_BIT=y
;;
--gui) CONFIG_GUI=y
;;
*)
echo "ERROR: unknown option $opt"
echo "Try '$0 --help' for more information"
exit 1
;;
esac
done
if test "$USE_32_BIT" = "y"; then
USER_CFLAGS="-m32 ${USER_CFLAGS}";
USER_CXXFLAGS="-m32 ${USER_CXXFLAGS}";
USER_LDFLAGS="-m32 ${USER_LDFLAGS}";
fi
if test -z "$prefix"; then
prefix=/usr
fi
if test -z "$includedir"; then
includedir="$prefix/include"
fi
if test -z "$libdir"; then
libdir="$prefix/lib"
fi
if test -z "$libdevdir"; then
libdevdir="$prefix/lib"
fi
if test -z "$mandir"; then
mandir="$prefix/man"
fi
if test -z "$datadir"; then
datadir="$prefix/share"
fi
if test x"$libdir" = x"$libdevdir"; then
relativelibdir=""
else
relativelibdir="$libdir/"
fi
if test "$show_help" = "yes"; then
cat <<EOF
Usage: configure [options]
Options: [defaults in brackets after descriptions]
--help print this message
--prefix=PATH install in PATH [$prefix]
--includedir=PATH install headers in PATH [$includedir]
--libdir=PATH install runtime libraries in PATH [$libdir]
--libdevdir=PATH install development libraries in PATH [$libdevdir]
--mandir=PATH install man pages in PATH [$mandir]
--datadir=PATH install shared data in PATH [$datadir]
--cc=CMD use CMD as the C compiler
--cxx=CMD use CMD as the C++ compiler
--ld=CMD use CMD as the linker
--cflags=FLAGS set C compiler flags
--cxxflags=FLAGS set C++ compiler flags
--ldflags=FLAGS set linker flags
--lib-ldflags=FLAGS set library linker flags (end of the command)
--32-bit set 32-bit build flags
--gui compile with GUI support (GTK-3)
EOF
exit 0
fi
TMPC="$(mktemp --tmpdir tmpfile-XXXXXXXXX.c)"
TMPC2="$(mktemp --tmpdir tmpfile-XXXXXXXXX-2.c)"
TMPO="$(mktemp --tmpdir tmpfile-XXXXXXXXX.o)"
TMPE="$(mktemp --tmpdir tmpfile-XXXXXXXXX.exe)"
# NB: do not call "exit" in the trap handler; this is buggy with some shells;
# see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM
config_host_mak="config-host.mak"
config_host_h="config-host.h"
rm -rf config.log
rm -rf $config_host_mak
rm -rf $config_host_h
fatal() {
echo $@
echo "Configure failed, check config.log and/or the above output"
rm -rf $config_host_mak
rm -rf $config_host_h
exit 1
}
# Print result for each configuration test
print_config() {
printf "%-30s%s\n" "$1" "$2"
}
# Default CFLAGS
CFLAGS="${USER_CFLAGS}";
CXXFLAGS="${USER_CFLAGS}";
LDFLAGS="${USER_LDFLAGS}";
LIB_LDFLAGS="${USER_LIB_LDFLAGS}";
# Print configure header at the top of $config_host_h
echo "/*" > $config_host_h
echo " * Automatically generated by configure - do not modify" >> $config_host_h
printf " * Configured with:" >> $config_host_h
printf " * '%s'" "$0" "$@" >> $config_host_h
echo "" >> $config_host_h
echo " */" >> $config_host_h
echo "# Automatically generated by configure - do not modify" > $config_host_mak
printf "# Configured with:" >> $config_host_mak
printf " '%s'" "$0" "$@" >> $config_host_mak
echo >> $config_host_mak
do_cxx() {
# Run the compiler, capturing its output to the log.
echo $cxx "$@" >> config.log
$cxx "$@" >> config.log 2>&1 || return $?
return 0
}
do_cc() {
# Run the compiler, capturing its output to the log.
echo $cc "$@" >> config.log
$cc "$@" >> config.log 2>&1 || return $?
# Test passed. If this is an --enable-werror build, rerun
# the test with -Werror and bail out if it fails. This
# makes warning-generating-errors in configure test code
# obvious to developers.
if test "$werror" != "yes"; then
return 0
fi
# Don't bother rerunning the compile if we were already using -Werror
case "$*" in
*-Werror*)
return 0
;;
esac
echo $cc -Werror "$@" >> config.log
$cc -Werror "$@" >> config.log 2>&1 && return $?
echo "ERROR: configure test passed without -Werror but failed with -Werror."
echo "This is probably a bug in the configure script. The failing command"
echo "will be at the bottom of config.log."
fatal "You can run configure with --disable-werror to bypass this check."
}
compile_prog() {
local_cflags="$1";
local_ldflags="$2 $LIBS";
echo "Compiling test case $3" >> config.log;
do_cc -D_GNU_SOURCE $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags;
}
compile_prog_cxx() {
local_cflags="$1";
local_ldflags="$2 $LIBS";
echo "Compiling test case $3" >> config.log;
do_cxx -D_GNU_SOURCE $CXXFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags;
}
has() {
type "$1" >/dev/null 2>&1
}
output_mak() {
echo "$1=$2" >> $config_host_mak
}
output_sym() {
output_mak "$1" "y"
echo "#define $1" >> $config_host_h
}
print_and_output_mak() {
print_config "$1" "$2"
output_mak "$1" "$2"
}
print_and_output_mak "prefix" "$prefix"
print_and_output_mak "includedir" "$includedir"
print_and_output_mak "libdir" "$libdir"
print_and_output_mak "libdevdir" "$libdevdir"
print_and_output_mak "relativelibdir" "$relativelibdir"
print_and_output_mak "mandir" "$mandir"
print_and_output_mak "datadir" "$datadir"
########################################################################
#
# Get the compiler type. We only support GCC and Clang!
#
if printf "" | "$cc" -dM -E - | grep __clang__ >> config.log; then
CC_TYPE=__clang
else
if printf "" | "$cc" -dM -E - | grep __GNUC__ >> config.log; then
CC_TYPE=__gcc
else
echo "CC is not supported, current CC is \"$cc\"";
exit 1;
fi
fi
print_config "CC_TYPE" "$CC_TYPE";
echo "CC_TYPE := $CC_TYPE" >> $config_host_mak;
if printf "" | "$cxx" -dM -E - | grep __clang__ >> config.log; then
CXX_TYPE=__clang
else
if printf "" | "$cxx" -dM -E - | grep __GNUC__ >> config.log; then
CXX_TYPE=__gcc
else
echo "CXX is not supported, current CXX is \"$cxx\"";
exit 1;
fi
fi
print_config "CXX_TYPE" "$CXX_TYPE";
echo "CXX_TYPE := $CXX_TYPE" >> $config_host_mak;
########################################################################
########################################################################
#
# Get current git commit sha1.
#
GIT_HASH=$(git log --pretty="%H" -1)
if test ! -z "$GIT_HASH"; then
echo "GIT_HASH := $GIT_HASH" >> $config_host_mak;
echo "EXTRAVERSION := \$(EXTRAVERSION)-\$(GIT_HASH)" >> $config_host_mak;
print_config "GIT_HASH" "$GIT_HASH";
else
print_config "GIT_HASH" "cannot get commit sha1";
fi
########################################################################
if test "$CONFIG_LINUX" = "y"; then
output_sym "CONFIG_LINUX";
fi;
print_config "CONFIG_LINUX" "$CONFIG_LINUX";
echo "CC := $cc" >> $config_host_mak;
print_config "CC" "$cc";
echo "CXX := $cxx" >> $config_host_mak;
print_config "CXX" "$cxx";
echo "LD := $ld" >> $config_host_mak;
print_config "LD" "$ld";
echo "CFLAGS := $CFLAGS" >> $config_host_mak;
print_config "USER_CFLAGS" "$USER_CFLAGS";
echo "CXXFLAGS := $CXXFLAGS" >> $config_host_mak;
print_config "USER_CXXFLAGS" "$USER_CXXFLAGS";
echo "LDFLAGS := $LDFLAGS" >> $config_host_mak;
print_config "USER_LDFLAGS" "$USER_LDFLAGS";
echo "LIB_LDFLAGS := $LIB_LDFLAGS" >> $config_host_mak;
print_config "USER_LIB_LDFLAGS" "$USER_LIB_LDFLAGS";
echo "---------------------------------------------------------------";