-
Notifications
You must be signed in to change notification settings - Fork 6
/
configure
executable file
·514 lines (441 loc) · 12.7 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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
#! /bin/sh
# configuration script for mlgmpidl
# based on the configure script from apron
#
# generates automatically a suitable Makefile.config
##############################################
# help
#######
help()
{
cat <<EOF
usage: configure [options]
where options include:
-prefix dir installation directory
-gmp-prefix dir where to find the GMP library
-mpfr-prefix dir where to find the MPFR library
-no-ocamlfind disable OCamlfind support
-no-native-plugins do not build native plugins
-disable-profiling disable compilation of profiling version
-absolute-dylibs force absolute library names (OSX only)
Environment variables that affect configuration:
CC C compiler to use (default: gcc)
CFLAGS extra flags to pass to the C compiler
LDFLAGS extra link flags
GMP_PREFIX where to find the GMP library
MPFR_PREFIX where to find the MPFR library
EOF
exit
}
##############################################
# parse arguments
#################
mlgmpidl_prefix=/usr/local;
has_cxx=1;
has_ppl=1;
has_ocamlfind=1;
has_native_plugins=1;
enable_prof=1;
force_absolute_dylib_install_names=0;
while : ; do
case "$1" in
"")
break;;
-prefix|--prefix)
mlgmpidl_prefix="$2";
shift;;
-gmp-prefix|--gmp-prefix)
gmp_prefix="$2";
shift;;
-mpfr-prefix|--mpfr-prefix)
mpfr_prefix="$2";
shift;;
-no-ocamlfind|--no-ocamlfind)
has_ocamlfind=0;;
-no-native-plugins|--no-native-plugins)
has_native_plugins=0;;
-disable-profiling)
enable_prof=0;;
-absolute-dylibs|--absolute-dylibs)
force_absolute_dylib_install_names=1;;
-help|--help)
help;;
*)
echo "unknown option $1, try -help"
exit 2;;
esac
shift
done
##############################################
# utilities
###########
# print utility
echo_n()
{
echo "$1" | tr -d '\012'
}
info () { echo "$1"; }
err () { echo "$1"; exit 1; }
# checkcc cc opt
# checks that compiler cc can compile a simple program with option opt
# if so, add it to acc
checkcomp()
{
testcc="$1"
testopt="$2";
echo_n "checking compilation with $testcc $testopt: "
rm -f tmp.c tmp.out
echo "int main() { return 1; }" >> tmp.c
r=1
$testcc $testopt tmp.c -o tmp.out >/dev/null 2>/dev/null || r=0
if test ! -x tmp.out; then r=0; fi
rm -f tmp.c tmp.o tmp.out
if test $r -eq 0; then
echo "not working"
else
acc="$acc $testopt"
echo "working"
fi
return $r
}
# checking include file
checkinc()
{
testcc="$1"
testinc="$2"
echo_n "include $testinc: "
rm -f tmp.c tmp.o
echo "#include <$testinc>" > tmp.c
echo "int main() { return 1; }" >> tmp.c
r=1
$testcc -c tmp.c -o tmp.o >/dev/null 2>/dev/null || r=0
if test ! -f tmp.o; then r=0; fi
rm -f tmp.c tmp.o
if test $r -eq 0; then echo "not found"; else echo "found"; fi
return $r
}
# checking library
checklib()
{
testcc="$1"
testlib="$2"
echo_n "library $testlib: "
rm -f tmp.c tmp.out
echo "int main() { return 1; }" >> tmp.c
r=1
$testcc tmp.c -l$testlib -o tmp.out >/dev/null 2>/dev/null || r=0
if test ! -x tmp.out; then r=0; fi
rm -f tmp.c tmp.o tmp.out
if test $r -eq 0; then echo "not found"; else echo "found"; fi
return $r
}
# checkprefix include lib
#
# tries to find a prefix needed to get the library
checkprefix()
{
testcc="$1"
testinc="$2"
testlib="$3"
testprefix="$4"
# try without any prefix (unless the user forced a prefix)
if test "x$testprefix" = "x"
then
echo "looking for $testlib without prefix"
prefix=""
checkinc "$testcc" "$testinc"
if test $r -eq 1
then
checklib "$testcc" "$testlib"
if test $r -eq 1
then
echo "library $testlib found without prefix"
return 1
fi
fi
fi
# check with a prefix
for prefix in $testprefix /usr/local /usr "$HOME"
do
echo "looking for $testlib in prefix $prefix"
checkinc "$testcc -I$prefix/include" "$testinc"
if test $r -eq 1
then
checklib "$testcc -L$prefix/lib" "$testlib"
if test $r -eq 1
then
echo "library $testlib found with prefix $prefix"
return 1
fi
fi
done
echo "library $testlib not found"
return 0
}
# checking binaries in $PATH
searchbin()
{
if test "x$1" = "x"; then return 0; fi
echo_n "binary $1: "
IFS=':'
path=""
for i in $PATH
do
if test -z "$i"; then i='.'; fi
if test -x "$i/$1"
then
echo "found in $i"
path="$i/$1"
unset IFS
return 1
fi
done
echo "not found"
unset IFS
return 0
}
searchbinreq()
{
searchbin $1
if test $? -eq 0; then err "required program $1 not found"; fi
}
checkdirinpath()
{
dir="$1"
path="$2"
echo_n "checking whether $1 belongs to $3: "
# env bash -c '[[ ":'${path}':" == *":'${dir}':"* ]]';
# if test $? -eq 1; then echo "no"; return 1; fi
IFS=':'
found=0
for d in $path
do
if test "$d" -ef "$dir"; then found=1; fi
done
unset IFS;
if test $found -eq 0; then echo "no"; return 1; fi
echo "yes"
}
#####################################
# tests
#######
c_flags="-Wcast-qual -Wswitch -Wall -Wextra -Wundef -Wcast-align -Wno-unused -Wno-unused-parameter -Wno-unused-function -fPIC"
# C compiler
cc="none"
for i in $CC cc gcc
do
checkcomp "$i" ""
if test $? -eq 1; then cc="$i"; break; fi
done
if test "$cc" = "none"; then err "no C compiler found"; fi
acc=""
for i in $c_flags -Werror-implicit-function-declaration -Wbad-function-cast -Wstrict-prototypes -std=c99 $CFLAGS $LDFLAGS
do
checkcomp "$cc" "$i"
done
cflags=$acc
# tools
searchbinreq "ar"; ar="$path"
searchbinreq "ranlib"; ranlib="$path"
searchbinreq "sed"; sed="$path"
searchbinreq "grep"; grep="$path"
searchbinreq "perl"; perl="$path"
searchbinreq "install"; install="$path"
# C libraries
if test "x$gmp_prefix" != "x"; then GMP_PREFIX="$gmp_prefix"; fi
checkprefix "$cc $cflags" gmp.h gmp "$GMP_PREFIX"
if test $? -eq 0; then err "GMP not found, set GMP_PREFIX"; fi
gmp_prefix="$prefix"
if test "x$mpfr_prefix" != "x"; then MPFR_PREFIX="$mpfr_prefix"; fi
checkprefix "$cc $cflags" mpfr.h mpfr "$MPFR_PREFIX"
if test $? -eq 0; then err "MPFR not found, set MPFR_PREFIX"; fi
mpfr_prefix="$prefix"
# Get MPFR major version:
mpfr_cflags=""
test "x$mpfr_prefix" != "x" && mpfr_cflags="-I$mpfr_prefix/include";
mpfr_version_major=$( echo MPFR_VERSION_MAJOR \
| "$cc" $mpfr_cflags -imacros mpfr.h -E -P - \
| "$grep" '[^[:blank:]]' )
echo "library mpfr major version: $mpfr_version_major"
# OCaml environment
# check OCaml binaries
has_ocaml=1
if test $has_ocaml -eq 1; then searchbin "ocamlc.opt"; has_ocaml=$?; ocamlc="$path"; fi
if test $has_ocaml -eq 1; then searchbin "ocamlopt.opt"; has_ocaml=$?; ocamlopt="$path"; fi
if test $has_ocaml -eq 1; then searchbin "ocamldep"; has_ocaml=$?; ocamldep="$path"; fi
if test $has_ocaml -eq 1; then searchbin "ocamldoc"; has_ocaml=$?; ocamldoc="$path"; fi
if test $has_ocaml -eq 1; then searchbin "ocamlmktop"; has_ocaml=$?; ocamlmktop="$path"; fi
if test $has_ocaml -eq 1; then searchbin "ocamlmklib"; has_ocaml=$?; ocamlmklib="$path"; fi
if test $has_ocaml -ne 1; then err "OCaml not found"; fi
if test $has_ocaml -eq 1; then searchbin "camlidl"; has_ocaml=$?; camlidl="$path"; fi
if test $has_ocaml -ne 1; then err "OCamlIDL not found"; fi
# optional ocamlfind
if test $has_ocamlfind -eq 1
then
has_ocamlfind=0
if test $has_ocaml -eq 1; then searchbin "ocamlfind"; has_ocamlfind=1; ocamlfind="$path"; fi
fi
# guess prefix
if test $has_ocamlfind -eq 1
then
caml_prefix=`$ocamlfind printconf stdlib`
camlidl_prefix=`$ocamlfind query camlidl`
if test "x$camlidl_prefix" = "x"; then camlidl_prefix=`$ocamlc -where`; fi
mlgmpidl_prefix=`$ocamlfind query gmp`
if test "x$mlgmpidl_prefix" = "x"; then mlgmpidl_prefix=`$ocamlc -where`; fi
else
# sane default (but does not work with OPAM)
caml_prefix=`$ocamlc -where`
camlidl_prefix=`$ocamlc -where`
mlgmpidl_prefix=`$ocamlc -where`
fi
# check that the prefix is correct
if test $has_ocaml -eq 1
then
checkinc "$cc $cflags -I$caml_prefix" caml/mlvalues.h
has_ocaml=$?
fi
if test $has_ocaml -eq 1
then
checkinc "$cc $cflags -I$caml_prefix -I$camlidl_prefix" caml/camlidlruntime.h
has_ocaml=$?
fi
if test $has_ocaml -eq 1
then
cc_cmd="$cc $cflags -I$caml_prefix -I$mlgmpidl_prefix";
if test "x$gmp_prefix" != "x"; then cc_cmd="$cc_cmd -I$gmp_prefix/include"; fi
fi
if test $has_ocaml -ne 1; then err "OCaml not found"; fi
##############################################
# Custom tests
##############
overs=$($ocamlc -version);
case "${overs}" in
[1-2].*|3.0*|3.11.*|3.12.0)
err "OCaml version found is ${overs}: OCaml >= 3.12.1 is required.";;
*)
:;;
esac
# Profiling:
cprof_flags="";
if test $enable_prof -eq 1
then
echo -n "checking whether to enable profiling: "
case "${overs}" in
4.08.[1-9]*|4.09.*|4.[1-9]*|[5-9]*|[1-9][0-9]*)
echo "only available up to OCaml 4.08.0 (<= ${overs})";
enable_prof=0;;
*)
ocaml_prof="$($ocamlc -config | $sed -e '/^profiling:/!d; s/^[^:]*: *//;')"
if test -n "$ocaml_prof" -a "$ocaml_prof" = "false"
then
echo "not supported"
enable_prof=0
else
echo "supported"
cprof_flags="$($ocamlc -config | $sed -e '/^cc_profile:/!d; s/^[^:]*: *//;')"
if test "x${cprof_flags}" != "x"
then
echo "profiling flags provided by the ocaml system: ${cprof_flags}"
checkcomp "$cc" "${cprof_flags}"
fi
fi;;
esac
fi
# Extension for dynamic libraries
ext_dll="";
echo -n "finding extension for dynamic libraries: "
ext_dll="$($ocamlc -config | $sed -e '/^ext_dll:/!d; s/^[^:]*: *//;')"
echo $ext_dll
# Use abolute dynamic library names under OSX when explicitly asked,
# or when the installation prefix does not belong to DYLD_LIBRARY_PATH
# nor DYLD_FALLBACK_LIBRARY_PATH or
# '$(HOME)/lib:/usr/local/lib:/lib:/usr/lib' (the default fallback).
absolute_dylib_install_names=;
if test "x$(uname -s)" = "xDarwin"
then
if test $force_absolute_dylib_install_names -eq 1
then
echo "using absolute dynamic library install names as requested"
absolute_dylib_install_names=1
else
libdir="${mlgmpidl_prefix}/lib"
if test "x$DYLD_FALLBACK_LIBRARY_PATH" != "x"
then
fldpath="$DYLD_FALLBACK_LIBRARY_PATH"
else
fldpath="$HOME/lib:/usr/local/lib:/lib:/usr/lib"
fi
checkdirinpath "${libdir}" "$DYLD_LIBRARY_PATH" "DYLD_LIBRARY_PATH" || \
checkdirinpath "${libdir}" "${fldpath}" "DYLD_FALLBACK_LIBRARY_PATH"
if test $? -eq 1
then
echo "forcing absolute dynamic library install names"
absolute_dylib_install_names=1
fi
fi
else
if test $force_absolute_dylib_install_names -eq 1
then
echo "ignoring option \`-absolute-dylibs', only meaningful under OSX";
fi
fi
##############################################
# log
#####
cat <<EOF
detected configuration:
OCaml version $overs
optional OCamlFind support $has_ocamlfind
optional native plugins $has_native_plugins
optional profiling version $enable_prof
MPFR version (major) $mpfr_version_major
installation path $mlgmpidl_prefix
EOF
test "x$absolute_dylib_install_names" = "x1" && cat <<EOF
dynamic libraries shall use absolute install names
EOF
##############################################
# generation
############
cat > Makefile.config <<EOF
# generated by ./configure
HAS_SHARED = 1
HAS_OCAMLOPT = 1
ENABLE_PROF = $enable_prof
MLGMPIDL_PREFIX = $mlgmpidl_prefix
GMP_PREFIX = $gmp_prefix
MPFR_PREFIX = $mpfr_prefix
MPFR_VERSION_MAJOR = $mpfr_version_major
CC = $cc
CFLAGS = -U__STRICT_ANSI__ -DNDEBUG -O3 $cflags
CFLAGS_DEBUG = -U__STRICT_ANSI__ -UNDEBUG -O0 -g $cflags
CFLAGS_PROF = -U__STRICT_ANSI__ -UNDEBUG -O3 $cprof_flags $cflags
EXT_DLL = $ext_dll
AR = $ar
RANLIB = $ranlib
SED = $sed
PERL = $perl
INSTALL = $install
INSTALLd = $install -d
CAML_PREFIX = $caml_prefix
CAMLIDL_PREFIX = $camlidl_prefix
OCAMLC = $ocamlc
OCAMLOPT = $ocamlopt
OCAMLFLAGS = -annot -g
OCAMLOPTFLAGS = -annot -inline 20
OCAMLDEP = $ocamldep
OCAMLDOC = $ocamldoc
OCAMLMKTOP = $ocamlmktop
OCAMLMKLIB = $ocamlmklib
CAMLIDL = $camlidl
OCAMLFIND = $ocamlfind
# TODO: to be configured
LATEX = latex
DVIPDF = dvipdf
MAKEINDEX = makeindex
RM ?= rm -f
HAS_NATIVE_PLUGINS = $has_native_plugins
# OSX only:
ABSOLUTE_DYLIB_INSTALL_NAMES = $absolute_dylib_install_names
EOF