forked from alokmenghrajani/opalang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·739 lines (654 loc) · 19.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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
#!/usr/bin/env bash
set -u
set -e
: ${OPA_SOURCE_DIR:=$(dirname $0)}
if [ "${OPA_SOURCE_DIR#/}" = "$OPA_SOURCE_DIR" ]; then OPA_SOURCE_DIR=$PWD/$OPA_SOURCE_DIR; fi
help() {
cat >&2 <<EOF
opalang configure script. Options:
-prefix <dir> the final installation prefix
-release configure for building in release mode
-noassert configure for building in noassert mode
-ocamldir <dir> where to find the ocaml libraries
-ocamlopt <path> the ocaml compiler to use
-ocamlfind <path> use the given ocamlfind to locate libraries
-no-ocamlfind don't use ocamlfind
-camlidl enable features based on camlidl
-dbm enable features based on dbm
-help shows this message
EOF
# --no-<lib> if available
}
cd "$OPA_SOURCE_DIR"
NO_CAMLIDL=1
NO_DBM=1
while [ $# -gt 0 ]; do
case "$1" in
-prefix)
if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument" >&2; exit 1; fi
shift
PREFIX=$1
;;
-release)
IS_RELEASE=1
;;
-noassert)
OCAMLBUILD_FLAGS="${OCAMLBUILD_FLAGS:-} -tag noassert"
;;
-ocamldir)
if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument" >&2; exit 1; fi
shift
OCAMLLIB=$1
;;
-ocamlopt)
if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument" >&2; exit 1; fi
shift
OCAMLOPT=$1
;;
-ocamlfind)
if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument" >&2; exit 1; fi
shift
OCAMLFIND=$1
;;
-no-ocamlfind)
NO_OCAMLFIND=1
;;
-camlidl)
NO_CAMLIDL=0
;;
-dbm)
NO_DBM=0
;;
-no-camlidl)
NO_CAMLIDL=1
;;
-no-dbm)
NO_DBM=1
;;
-h|-help|--help)
help
exit 0;;
*)
echo "Error: unknown option $1" >&2
echo
help
exit 2
esac
shift
done
: ${PREFIX:=${MLSTATELIBS:-}}
: ${PREFIX:=/usr/local}
: ${IS_RELEASE:=}
CONFIG_LOG=$PWD/config.log
echo -n >$CONFIG_LOG
echo-check() { echo -n "Checking $*... " >&2 ; echo "# CHECK-START: $*" >>$CONFIG_LOG; }
echo-ok() {
local opts=; if [ "X$1" = "X-n" ]; then shift; opts="-n"; fi
echo $opts "[1m$*[0m" >&2 ; echo $opts -e "# CHECK-OK: $*\n" >>$CONFIG_LOG;
}
echo-ok-tag() { echo "[1m[32mOK[0m" >&2 ; echo -e "# CHECK-OK\n" >>$CONFIG_LOG; }
echo-err() { echo "[1m[31m$*[0m" >&2 ; echo -e "# CHECK-FAIL: $*\n" >>$CONFIG_LOG; }
echo-skip() { echo "[1m[33m$*[0m" >&2 ; echo -e "# CHECK-SKIP: $*\n" >>$CONFIG_LOG; }
# check OS
echo-check your OS
EXT_LIB="a"
EXT_OBJ="o"
EXT_SHARED="so"
case $(uname) in
CYGWIN*)
echo-ok Windows/cygwin
EXT_LIB="lib"
EXT_SHARED="dll"
IS_WINDOWS=1;;
Darwin*)
echo-ok MacOS
IS_MAC=1;;
Linux*|GNU/kFreeBSD)
echo-ok Linux
IS_LINUX=1;;
FreeBSD)
echo-ok FreeBSD
IS_FREEBSD=1;;
*)
echo-err "Not sure, probably Unix / Linux"
IS_LINUX=1
esac
echo-check your architecture
case $(uname -m) in
x86_64|amd64)
echo-ok x86_64;;
i?86)
echo-ok ix86;;
*)
echo-err "$(uname -m)"
echo "Sorry, this architecture is unsupported at the moment." >&2
exit 1
esac
lastresort_hint() {
cat <<EOF
If you have trouble meeting the required dependencies with your distribution,
you may want to have a look at the script installation_helper.sh in the
dependencies/ directory to build them from source.
EOF
}
trap lastresort_hint ERR
# specific platform checks
if [ -n "${IS_MAC:-}" ]; then
echo-check for gsed
if which gsed > /dev/null 2>&1; then echo-ok ok
else
echo-err Not found
echo "gsed is needed to build OPA."
if which port >/dev/null 2>&1; then
echo -e " You should run:\n\tsudo port install gsed"
# else #todo# [add useful suggestion here]
fi
exit 1
fi >&2
echo-check for GNU coreutils
if which gtail gmktemp gsort greadlink >/dev/null 2>&1; then echo-ok ok
else
echo-err Not found
echo "GNU coreutils are needed to build OPA."
if which port >/dev/null 2>&1; then
echo -e " You should run:\n\tsudo port install coreutils"
# else #todo# [add useful suggestion here]
fi
exit 1
fi >&2
. ./platform_helper.sh
fi
if [ -n "${IS_FREEBSD:-}" ]; then
echo-check gmake
if which gmake >/dev/null 2>&1; then echo-ok ok
else
echo-err Not found
echo "Please install port devel/gmake."
exit 1
fi >&2
fi
# check ocaml version and location
echo-check ocamlopt
if OCAMLOPT=${OCAMLOPT:-$(which ocamlopt.opt)} || OCAMLOPT=${OCAMLOPT:-$(which ocamlopt)}
then echo-ok $OCAMLOPT
else
echo-err Not found
echo "Ocaml 3.12 or newer is required. It's usually found in package 'ocaml'."
false
fi
OCAMLOPT_DIR=$(dirname $(which $OCAMLOPT))
echo-check ocamlbuild
: ${OCAMLBUILD:=$OCAMLOPT_DIR/ocamlbuild}
if [ -n "$IS_RELEASE" ]; then
OCAMLBUILD_FLAGS="${OCAMLBUILD_FLAGS:-} -tag release -tag noassert"
else
OCAMLBUILD_FLAGS="${OCAMLBUILD_FLAGS:-} -tag debug"
fi
if [ -x "$OCAMLBUILD" ]
then echo-ok $OCAMLBUILD
else
echo-err Not found
echo "Ocamlbuild is required. It should come with your ocaml distribution."
false
fi
echo-check ocamldir
: ${OCAMLLIB:=$($OCAMLOPT -where)}
echo-ok $OCAMLLIB
export OCAMLLIB
echo-check ocaml version
OCAML_VERSION=$($OCAMLOPT -version)
OCAML_VERSION_MAJOR=${OCAML_VERSION%%.*}
OCAML_VERSION_MIDDLE=${OCAML_VERSION%.*}
OCAML_VERSION_MIDDLE=${OCAML_VERSION_MIDDLE#*.}
if [ $OCAML_VERSION_MAJOR -eq 3 ] && [ $OCAML_VERSION_MIDDLE -ge 12 ]; then
echo-ok $OCAML_VERSION
else
echo-err $OCAML_VERSION
echo "Ocaml 3.12 or newer is required"
false
fi
echo-check your ocaml setup
check-ocaml () {
local DIR=$(mktemp -d /tmp/opa-configure.XXXXX)
trap "rm -rf /tmp/${DIR#/tmp/}" EXIT
cd $DIR
cat >test.ml <<EOF
let p = Unix.getpid()
let _ = Printf.printf "%s, %s %dbit" Sys.ocaml_version Sys.os_type Sys.word_size
let _ =
exit Sys.word_size
EOF
echo "# $OCAMLBUILD $OCAMLBUILD_FLAGS -tag use_unix test.native" >> $CONFIG_LOG
R=0; $OCAMLBUILD $OCAMLBUILD_FLAGS -tag use_unix test.native >test.log 2>&1 || R=$?
cat test.log >> $CONFIG_LOG
if [ $R -ne 0 ]; then
echo-err "could not compile"
echo "----------"
tail -n 5 test.log | sed 's/^/ /'
echo "----------"
echo "Your ocaml installation seems broken, please fix it"
false
fi >&2
set +e
RET=$(_build/test.native);
R=$?
set -e
case $R in
32)
OCAML_WORD_SIZE=32
echo-ok $RET
;;
64)
OCAML_WORD_SIZE=64
echo-ok $RET
;;
*)
echo-err $RET
echo "Your ocaml seems to be neither a 64bit or a 32bit version. Please install a native 64 bit package."
false
esac >&2
rm -rf /tmp/${DIR#/tmp/}
trap - EXIT
cd "$OPA_SOURCE_DIR"
}
check-ocaml
echo-check for camlp4
: ${CAMLP4O:=$OCAMLOPT_DIR/camlp4o}
: ${CAMLP4ORF:=$OCAMLOPT_DIR/camlp4orf}
if [ -x "$CAMLP4O" ] && [ -x "$CAMLP4ORF" ]
then echo-ok $CAMLP4O
else
echo-err Not found
echo "You need camlp4 to build this package. It is usually found in packages camlp4, camlp4-extra"
false
fi
# check tools:
# (*) stuff marked with * could maybe be optional and restrict the build correspondingly
# - checking for perl
echo-check for perl 5
if perl -v 2>/dev/null | grep -q 'v5\.'; then
echo-ok found
else
echo-err Not found
echo "You need Perl v5 to build this package ; it's usually found in package perl-base"
exit 1
fi >&2
# - checking for java
echo-check for java
if which java &>/dev/null; then
echo-ok found
else
echo-err Not found
exit 1
fi
# - checking camlidl *
echo-check for camlidl
if [ "X$NO_CAMLIDL" = "X1" ]; then
HAS_CAMLIDL=
CAMLIDL=
echo-ok Disabled
elif
[ -e $OCAMLLIB/libcamlidl.a ] &&
CAMLIDL=${CAMLIDL:-$OCAMLOPT_DIR)/camlidl} && [ -x "$CAMLIDL" ] ||
CAMLIDL=$(which camlidl)
then
HAS_CAMLIDL=1
echo-ok $CAMLIDL
else
HAS_CAMLIDL=
echo-skip "Not found (but optional)"
fi
# check C libs:
# we depend on libssl, libzip and others, but through
# ocaml libs, so no need to check them directly
check-c-lib () (
local OPTIONAL=""
if [ $1 = "-opt" ]; then OPTIONAL=1; shift; fi
local LIB=$1; shift
[ $# -gt 0 ]
local INCLUDES=("$@")
local LIBNAME=$(basename "$LIB")
local LIBDIR=$(dirname "$LIB")
local INCLUDE_DIR
for d in {"$OCAMLLIB/..","$OCAMLLIB",/usr/lib,/usr/local/lib}{/$LIBDIR,}; do
if [ -e $d/lib$LIBNAME.a ]; then
LD_DIR=$(readlink -f $d)
INCLUDE_DIR=$LD_DIR/
INCLUDE_DIR=${INCLUDE_DIR%/lib/*}/include
break
fi
done
if [ -z "${LD_DIR:-}" ]; then
echo "could not find lib$LIBNAME.a" >>$CONFIG_LOG
if [ -n "$OPTIONAL" ]; then echo-skip "Not found (but optional)"
else echo-err Not found
fi
return 1
fi >&2
echo-ok -n "$LD_DIR/lib$LIBNAME.a, "
# Now checking compile, link & run
local DIR=$(mktemp -d /tmp/opa-configure.XXXXX)
trap "rm -rf /tmp/${DIR#/tmp/}" EXIT
cd $DIR
{
for i in "${INCLUDES[@]}"; do echo '#include <'$i'>'; done
echo 'int main () { return 0; }'
} >test_$LIBNAME.c
echo "# gcc -L$LD_DIR -I$INCLUDE_DIR -l$LIBNAME test_$LIBNAME.c -o test_$LIBNAME" >> $CONFIG_LOG
R=0; gcc -L$LD_DIR -I$INCLUDE_DIR -l$LIBNAME test_$LIBNAME.c -o test_$LIBNAME >check_$LIBNAME.log 2>&1 || R=$?
cat check_$LIBNAME.log >> $CONFIG_LOG
if [ $R -ne 0 ]; then
echo-err "could not compile"
echo "----------"
tail -n 5 check_${LIBNAME}.log | sed 's/^/ /'
echo "----------"
return 1
fi >&2
if ! ./test_$LIBNAME >> $CONFIG_LOG 2>&1; then
echo-err "compiled program doesn't work"
return 1
fi
echo-ok-tag
echo "$LIBNAME $LD_DIR $INCLUDE_DIR"
)
HAS_LIBNATPMP=
LIBNATPMP=("")
HAS_MINIUPNPC=
MINIUPNPC=("")
if [ -n "$HAS_CAMLIDL" ]; then
# - checking libnatpmp *
echo-check libnatpmp
if LIBNATPMP=($(check-c-lib -opt libnatpmp/natpmp netinet/in.h arpa/inet.h libnatpmp/getgateway.h libnatpmp/natpmp.h)); then
HAS_LIBNATPMP=1
else
LIBNATPMP=("")
fi
# - checking miniupnpc *
echo-check miniupnpc
if MINIUPNPC=($(check-c-lib -opt miniupnpc/miniupnpc miniupnpc/miniwget.h miniupnpc/miniupnpc.h miniupnpc/upnpcommands.h)); then
HAS_MINIUPNPC=1
else
MINIUPNPC=("")
fi
fi
# check ocaml libs:
# probably, first try with ocamlfind then fallback to
# custom check ; ensure consistency with function
# "get_ocamlfind_directory" in build/myocamlbuild_prefix.ml
echo-check for ocamlfind
if [ -n "${NO_OCAMLFIND:-}" ]; then
OCAMLFIND=
echo-skip Disabled
elif [ -z "${OCAMLFIND:-}" ]; then
OCAMLFIND=$OCAMLOPT_DIR/ocamlfind
if [ ! -x "$OCAMLFIND" ]; then
OCAMLFIND=$OCAMLLIB/../../bin/ocamlfind
fi
if [ ! -x "$OCAMLFIND" ]; then
echo-skip "Not found (but optional)"
OCAMLFIND=
else
echo-ok $OCAMLFIND
fi
elif [ -x "$OCAMLFIND" ]; then
echo-ok $OCAMLFIND
else
echo-err "Not found"
echo "You specified $OCAMLFIND on the command-line, but it doesn't exist or isn't executable" >&2
OCAMLFIND=
fi
EXTRA_TAGS="-tag use_unix"
check-ocaml-lib () {
local MODULE=$1; shift
local LIB=$1; shift
local LIBDIR=$1; shift
[ $# -eq 0 ]
local DIR=$(mktemp -d /tmp/opa-configure.XXXXX)
trap "rm -rf /tmp/${DIR#/tmp/}" EXIT
cd $DIR
echo "module M = $MODULE" >check_${LIB}.ml
local libdir_ins=""
if [ "$LIBDIR" != "$OCAMLLIB" ]; then libdir_ins=' ~dir:"'$LIBDIR'"'; fi
cat >myocamlbuild.ml <<EOF
let _ = Ocamlbuild_plugin.dispatch (function
| Ocamlbuild_plugin.After_rules ->
Ocamlbuild_plugin.ocaml_lib ~extern:true$libdir_ins ~tag_name:"use_my_lib" "$LIB"
| _ -> ()
)
EOF
echo "# $OCAMLBUILD $OCAMLBUILD_FLAGS $EXTRA_TAGS -tag use_my_lib check_${LIB}.native" >> $CONFIG_LOG
R=0; $OCAMLBUILD $OCAMLBUILD_FLAGS $EXTRA_TAGS -tag use_my_lib check_${LIB}.native >check_${LIB}.log 2>&1 || R=$?
cat check_${LIB}.log >> $CONFIG_LOG
if [ $R -ne 0 ]; then
echo-err "could not compile"
echo "----------"
tail -n 5 check_${LIB}.log | sed 's/^/ /'
echo "----------"
echo "The installation of $LIB seems broken, please fix it (did it come with a different ocaml compiler ?)"
return 1
else
echo-ok-tag
fi >&2
rm -rf /tmp/${DIR#/tmp/}
trap - EXIT
cd "$OPA_SOURCE_DIR"
}
check-cmxa () {
local DIR=$1; shift
[ $# -gt 0 ]
local canonical_name=$1
while [ $# -gt 0 ] && [ ! -e "$DIR/$(basename $1).cmxa" ]; do shift; done
if [ $# -eq 0 ]; then
echo-err "Not found"
echo "Please fix your installation of $canonical_name in $LIBDIR: no proper cmxa file was found there." >&2
return 1
fi
echo $1
}
locate-ocaml-lib () {
local OPTIONAL=""
if [ "$1" = "-opt" ]; then OPTIONAL=1; shift; fi
local MODULE=$1; shift # one module that the lib contains, to check
[ $# -gt 0 ] # remaining args: possible lib names (may be usual_dir/libname)
echo-check for $(basename $1)
local LIBDIR=""
local LIB
local LIB_NAMES=("$@")
while [ $# -gt 0 ] && [ -z "$LIBDIR" ]; do
LIB=$(basename $1)
USUAL_DIR=$(dirname $1)
[ "$USUAL_DIR" = "." ] && USUAL_DIR=$LIB
if [ -n "$OCAMLFIND" ] &&
LIBDIR=$("$OCAMLFIND" query "$LIB" 2>/dev/null)
then
LIB=$(check-cmxa $LIBDIR $LIB "${LIB_NAMES[@]}") || return 1
echo-ok -n "ocamlfind:$LIBDIR, "
elif [ -d "$OCAMLLIB"/"$USUAL_DIR" ]
then
LIB=$(check-cmxa "$OCAMLLIB"/"$USUAL_DIR" $LIB "${LIB_NAMES[@]}") \
|| return 1
echo-ok -n "+$USUAL_DIR, "
LIBDIR=+"$USUAL_DIR"
elif [ -e "$OCAMLLIB"/"$LIB".cmxa ]
then
echo-ok -n "$LIB.cmxa, "
LIBDIR="$OCAMLLIB"
fi
shift
done
if [ -z "$LIBDIR" ]; then
if [ -n "$OPTIONAL" ]; then
echo-skip "Not found (but optional)"
else
echo-err "Not found"
fi
return 1
fi
check-ocaml-lib "$MODULE" "$LIB" "$LIBDIR" || return 1
echo "$LIBDIR/$LIB"
}
# for libs which are needed (fatal warning)
LIBS_NOT_FOUND=()
lib-not-found () {
local lib=$1; shift
local package=$1; shift
LIBS_NOT_FOUND[${#LIBS_NOT_FOUND[@]}]="$lib (might be found in package $package)"
}
# - checking ocaml-ssl
if ! CONFIG_LIB_OCAMLSSL=$(locate-ocaml-lib "Ssl" "ssl")
then lib-not-found "ocaml_ssl" "libssl-ocaml-dev"
fi
# - checking cryptokit
if ! CONFIG_LIB_CRYPTOKIT=$(EXTRA_TAGS="$EXTRA_TAGS -tag use_nums" locate-ocaml-lib "Cryptokit" "cryptokit")
then lib-not-found "cryptokit" "libcryptokit-ocaml-dev"
fi
# - checking camlzip
if ! CONFIG_LIB_CAMLZIP=$(locate-ocaml-lib "Zip" "camlzip" "zip")
then lib-not-found "camlzip" "libzip-ocaml-dev"
fi
# - checking ocamlgraph
if ! CONFIG_LIB_OCAMLGRAPH=$(locate-ocaml-lib "Graph" "ocamlgraph/graph")
then lib-not-found "ocamlgraph" "libocamlgraph-ocaml-dev"
fi
# - checking ulex
if ! CONFIG_LIB_ULEX=$(locate-ocaml-lib "Ulexing" "ulex" "ulexing")
then lib-not-found "ulex" "ocaml-ulex"
fi
# - checking dbm
: ${NO_DBM:=""}
if [ "X$NO_DBM" = "X1" ]; then
HAS_DBM=
else
HAS_DBM="1"
if ! CONFIG_LIB_DBM=$(locate-ocaml-lib -opt "Dbm" "dbm")
then HAS_DBM=
fi
fi
# # - checking camlimages *
# CONFIG_LIB_CAMLIMAGES=$(EXTRA_TAGS="$EXTRA_TAGS -tag use_graphics" locate-ocaml-lib "Jpeg" "camlimages") || true
if [ ${#LIBS_NOT_FOUND[@]} -ne 0 ]; then
echo
echo "Not configured. You need the following libraries installed:" >&2
for lib in "${LIBS_NOT_FOUND[@]}"; do
echo " - $lib" >&2
done
false
fi
# Output the configuration
dir_opt() {
local DIR=$(dirname "$1"); shift; [ $# -eq 0 ]
if [ "$DIR" = "$OCAMLLIB" ]; then echo 'None'
else echo 'Some "'$DIR'"'
fi
}
camlbool() { [ $# -eq 1 ]; if [ -n "$1" ]; then echo true; else echo false; fi; }
camlstrtuple() {
echo -n '"'$1'"'; shift
while [ $# -gt 0 ]; do
echo -n ', "'$1'"'; shift
done
}
camlopt() {
local cond=$1; shift
local val=$1; shift
[ $# -eq 0 ]
if [ -n "$cond" ]; then echo 'Some ('$val')'
else echo 'None'
fi
}
ALL_TAGS_LIST="camlidl libnatpmp miniupnpc dbm"
TAGS_LIST=""
for tag in $ALL_TAGS_LIST; do
hasvar=HAS_$(tr '[:lower:]' '[:upper:]' <<<"$tag")
if [ -n "${!hasvar}" ]; then TAGS_LIST="$TAGS_LIST\"$tag\"; "; fi
done
# See config.mli for the documentation and spec of these variables
cat >config.ml <<EOF
let prefix = "$PREFIX"
let ocamllib = "$OCAMLLIB"
let ocamlopt = "$OCAMLOPT"
let ocamlbuild = "$OCAMLBUILD"
let ocamlbuild_flags = "$OCAMLBUILD_FLAGS"
let camlp4o = "$CAMLP4O"
let camlp4orf = "$CAMLP4ORF"
let camlidl = $(camlopt "$HAS_CAMLIDL" '"'"$CAMLIDL"'"')
let libnatpmp = $(camlopt "$HAS_LIBNATPMP" "$(camlstrtuple "${LIBNATPMP[@]}")")
let miniupnpc = $(camlopt "$HAS_MINIUPNPC" "$(camlstrtuple "${MINIUPNPC[@]}")")
let has_dbm = $(camlbool "$HAS_DBM")
let available = [ $TAGS_LIST]
let all_tags = [ $(for t in $ALL_TAGS_LIST; do echo -n "\"$t\"; "; done)]
let is_release = $(camlbool "$IS_RELEASE")
type os = Linux | Mac | Win32 | Cygwin | FreeBSD
let os =
$(if [ -n "${IS_LINUX:-}" ]; then echo Linux
elif [ -n "${IS_MAC:-}" ]; then echo Mac
elif [ -n "${IS_FREEBSD:-}" ]; then echo FreeBSD
else echo 'match Sys.os_type with "Win32" -> Win32 | "Cygwin" -> Cygwin | _ -> assert false'
fi)
let makebinary =
$(if [ -n "${IS_FREEBSD:-}" ];
then echo '"gmake"'
else echo '"make"'
fi)
module Libdir = struct
let ssl = $(dir_opt "$CONFIG_LIB_OCAMLSSL")
let cryptokit = $(dir_opt "$CONFIG_LIB_CRYPTOKIT")
let camlzip_name = "$(basename "$CONFIG_LIB_CAMLZIP")"
let camlzip = $(dir_opt "$CONFIG_LIB_CAMLZIP")
let graph = $(dir_opt "$CONFIG_LIB_OCAMLGRAPH")
let ulex = $(dir_opt "$CONFIG_LIB_ULEX")
end
let ext_lib = "$EXT_LIB"
let ext_obj = "$EXT_OBJ"
let ext_shared = "$EXT_SHARED"
EOF
cat >config.sh <<EOF
PREFIX="$PREFIX"
OCAMLLIB="$OCAMLLIB"
OCAMLOPT="$OCAMLOPT"
OCAMLBUILD="$OCAMLBUILD"
OCAMLBUILD_FLAGS="$OCAMLBUILD_FLAGS"
CAMLP4O="$CAMLP4O"
CAMLP4ORF="$CAMLP4ORF"
OCAML_WORD_SIZE="$OCAML_WORD_SIZE"
HAS_CAMLIDL="$HAS_CAMLIDL"
CAMLIDL="$CAMLIDL"
HAS_LIBNATPMP="$HAS_LIBNATPMP"
LIBNATPMP=(${LIBNATPMP[@]})
HAS_MINIUPNPC="$HAS_MINIUPNPC"
MINIUPNPC=(${MINIUPNPC[@]})
HAS_DBM="$HAS_DBM"
IS_RELEASE="$IS_RELEASE"
IS_LINUX="${IS_LINUX:-}"
IS_WINDOWS="${IS_WINDOWS:-}"
IS_MAC="${IS_MAC:-}"
IS_FREEBSD="${IS_FREEBSD:-}"
OS=$(if [ -n "${IS_LINUX:-}" ]; then echo '"Linux"'
elif [ -n "${IS_MAC:-}" ]; then echo '"Mac"'
elif [ -n "${IS_WINDOWS:-}" ]; then echo '"Win32"'
elif [ -n "${IS_FREEBSD:-}" ]; then echo '"FreeBSD"'
else echo "Error: OS inconsistency" >&2; exit 2
fi)
LIB_OCAMLSSL_DIR="$(dirname "$CONFIG_LIB_OCAMLSSL")"
LIB_CRYPTOKIT_DIR="$(dirname "$CONFIG_LIB_CRYPTOKIT")"
LIB_CAMLZIP_NAME="$(basename "$CONFIG_LIB_CAMLZIP")"
LIB_CAMLZIP_DIR="$(dirname "$CONFIG_LIB_CAMLZIP")"
LIB_OCAMLGRAPH_DIR="$(dirname "$CONFIG_LIB_OCAMLGRAPH")"
LIB_ULEX_DIR="$(dirname "$CONFIG_LIB_ULEX")"
EXT_LIB="$EXT_LIB"
EXT_OBJ="$EXT_OBJ"
EXT_SHARED="$EXT_SHARED"
EOF
sed 's/=["(]\(.*\)[)"]$/ := \1/' config.sh > config.make
if [ -n "${IS_MAC:-}" ]; then
echo "INSTALL := gcp -u -L" >>config.make
fi
if [ -n "${IS_FREEBSD:-}" ]; then
echo "INSTALL := cp" >>config.make
fi
{
echo
echo "Congrats, you're all set. Installation will be done in:"
echo " [1m$PREFIX[0m"
echo
} >&2