-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure
executable file
·268 lines (238 loc) · 5.46 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
#!/bin/sh
#
# Configure script for Nux Utilities
#
config_files="Makefile lib/Makefile"
CC_list="gcc clang cc"
configure_options="$@"
subst_variables="CC
CFLAGS
CPPFLAGS
AR
VERSION
builddir
srcdir
top_srcdir
prefix
exec_prefix
bindir
sbindir
sysconfdir
libdir
includedir
datarootdir
mandir
program_prefix
build
host
host_cpu"
#
# Default values
#
srcdir=
top_srcdir=
builddir=
prefix=/usr/local
exec_prefix='${prefix}'
bindir='${exec_prefix}/bin'
sbindir='${exec_prefix}/sbin'
sysconfdir='${prefix}/etc'
libdir='${exec_prefix}/lib'
includedir='${prefix}/include'
datarootdir='${prefix}/share'
mandir='${datarootdir}/man'
program_prefix=
build=
host=
host_cpu=
CONFTEST=conftest.c
#
# Helper functions
#
usage() {
cat << EOF
Usage: $0 [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g. CC, CFLAGS, etc), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for options are specified in brackets.
Installation directories:
--prefix=PREFIX architecture-independent installation prefix
[/usr/local]
--exec-prefix=EPREFIX architecture-dependent installation prefix [PREFIX]
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system manager executables [EPREFIX/sbin]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR include files [PREFIX/include]
--datarootdir=DIR read-only architecture-independent data root
[PREFIX/share]
--mandir=DIR man documentation [DATAROOTDIR/man]
Program names:
--program-prefix=PREFIX prepend PREFIX to the installed program names
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to run on HOST [BUILD]
Some influential environment variables:
CC C compiler command [detected]
CFLAGS C compiler flags, e.g. -Werror
CPPFLAGS C preprocessor flags, e.g. -I<include dir>
AR Archiver command [detected]
Use these variables to override the choices made by 'configure'.
EOF
}
msg_error() {
printf "%s: %s\n" "$0" "$*"
exit 1
}
msg_checking() {
printf "checking %s... " "$*"
}
msg_result() {
printf "%s\n" "$*"
}
check_tool() {
# $1 -> variable name
# $2 -> program to check for
tool_name="$2"
if test -n "$host"; then
tool_name="${host}-${tool_name}"
fi
if type "${tool_name}" > /dev/null 2>&1; then
eval "$1=\"\${tool_name}\""
else
eval "$1=\"unknown\""
fi
}
run_cmd() {
$1 > /dev/null 2>&1
}
add_cflag() {
msg_checking "whether compiler accepts $1"
cat << EOF > $CONFTEST
int main (void) {
return 0;
}
EOF
if $CC $CFLAGS $1 -c -o /dev/null $CONFTEST > /dev/null 2>&1 ; then
msg_result "yes"
CFLAGS="$CFLAGS $1"
eval "CFLAGS=\${CFLAGS# }"
else
msg_result "no"
msg_error "compiler does not accept $1"
fi
rm -f $CONFTEST
}
create_file() {
printf "creating %s\n" "$*"
}
#
# Start of script
#
for arg ; do
case "$arg" in
--help|-h) usage; exit 0 ;;
--prefix=*) prefix=${arg#*=} ;;
--exec-prefix=*) exec_prefix=${arg#*=} ;;
--bindir=*) bindir=${arg#*=} ;;
--sbindir=*) sbindir=${arg#*=} ;;
--sysconfdir=*) sysconfdir=${arg#*=} ;;
--libdir=*) libdir=${arg#*=} ;;
--includedir=*) includedir=${arg#*=} ;;
--datarootdir=*) datarootdir=${arg#*=} ;;
--mandir=*) mandir=${arg#*=} ;;
--program-prefix=*) program_prefix=${arg#*=} ;;
--build=*) build=${arg#*=} ;;
--host=*) host=${arg#*=} ;;
-*) msg_error "unknown option '$arg'"; exit 1 ;;
CC=*) CC=${arg#*=} ;;
CFLAGS=*) CFLAGS=${arg#*=} ;;
CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
AR=*) AR=${arg#*=} ;;
*=*) ;;
*) msg_error "unknown argument '$arg'" ;;
esac
done
#
# Get the source dir for out-of-tree builds
#
top_srcdir="${0%/configure}"
abs_srcdir="$(cd $top_srcdir && pwd)" || msg_error "invalid source directory '$top_srcdir'"
if test "$abs_srcdir" = "$(pwd)"; then
top_srcdir="."
fi
builddir="."
#
# Find an appropriate C compiler
#
msg_checking "for compiler"
if test -z $CC; then
for tryCC in $CC_list; do
check_tool "CC" "$tryCC"
if test "x$CC" != "xunknown"; then
break
fi
done
fi
msg_result "$CC"
if test "x$CC" = "xunknown"; then
msg_error "could not find a supported compiler"
fi
#
# Check that the compiler can actually assemble programs
#
msg_checking "whether the compiler works"
cat << EOF > $CONFTEST
int main (void) {
return 0;
}
EOF
if run_cmd "$CC -c -o /dev/null $CONFTEST" ; then
msg_result "yes"
else
msg_result "no"
msg_error "compiler cannot create executables"
fi
rm -f $CONFTEST
#
# Check other tools
#
msg_checking "for ar"
check_tool "AR" "ar"
msg_result "$AR"
if test "x$AR" = "xunknown"; then
msg_error "could not find ranlib"
fi
#
# Check the host architecture
#
msg_checking "host system type"
if test -z "$host"; then
host=$($CC -dumpmachine 2> /dev/null) || host="unknown"
fi
msg_result "$host"
case $host in
x86_64-*) host_cpu="x86_64" ;;
unknown) msg_error "unable to detect host architecture; try $0 --host=..." ;;
*) msg_error "unknown or unsupported host '$host'" ;;
esac
#
# Miscellaneous checks
#
add_cflag "-Wall"
add_cflag "-Werror"
VERSION=$(cat ${top_srcdir}/Version)
for config_file in $config_files; do
create_file "$config_file"
subdir="$(dirname $config_file)"
if test ! -d $subdir; then
mkdir -p $subdir
fi
for subst_var in $subst_variables; do
eval "subst_val=\"\${$subst_var}\""
subst_val=$(echo $subst_val | sed 's/\//\\\//g')
sed_scripts="$sed_scripts s/@${subst_var}@/${subst_val}/g; "
done
sed "$sed_scripts" $top_srcdir/$config_file.in > $builddir/$config_file
done