forked from alavrik/piqi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·147 lines (122 loc) · 3.84 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
#!/bin/sh
# "prefix" path for installing "piqi" and "piqic-ocaml" executables
PREFIX=/usr/local
# path for installing Piqi OCaml libraries. If not set, the ocamlfind
# destination directory path will be used. Such path is determined by
# OCAMLFIND_DESTDIR environment variable or by ocamlfind config. You can run
# "ocamlfind printconf destdir" to see the current setting.
OCAML_LIBDIR=
usage() {
echo "
Configuration:
-h, --help display this help and exit
--toolchain NAME cross-compile toolchain name, e.g. windows
Installation directories:
--prefix PREFIX install piqi executables in PREFIX/bin/
[/usr/local]
--ocaml-libdir DIR install OCaml libraries to DIR
[\`ocamlfind printconf destdir\`]
"
}
while [ "$#" != "0" ]
do
opt="$1"
case "$opt" in
--*=*)
opt_value=`expr "X$opt" : '[^=]*=\(.*\)'`
;;
--*)
shift
opt_value="$1"
;;
esac
case "$opt" in
--prefix | --prefix=*)
PREFIX="$opt_value"
;;
--toolchain | --toolchain=*)
TOOLCHAIN="$opt_value"
;;
--ocaml-libdir | --ocaml-libdir=*)
OCAML_LIBDIR="$opt_value"
;;
-h|-help|--help)
usage
exit 0
;;
*)
echo "configure: run 'configure -h' to get help" 1>&2
exit 1
;;
esac
shift
done
OCAMLFIND=ocamlfind
OF=`which $OCAMLFIND`
if [ $? -ne 0 ]
then
echo "configure: error: failed to find ${OCAMLFIND}. See INSTALL for details" 1>&2
exit 1
fi
echo "found $OCAMLFIND: $OF"
M=Makefile.config
# configure options
echo "# Makefile.config generated by ./configure" > $M
echo >> $M
echo "PIQI_PREFIX=$PREFIX" >> $M
echo "PIQI_OCAML_DESTDIR=$OCAML_LIBDIR" >> $M
echo >> $M
# build environment
echo "export PIQI_ROOT := `pwd`" >> $M
# temporary build directory
echo "export PIQI_BUILD := \$(PIQI_ROOT)/build" >> $M
# path to .piqi files
echo "export PIQI_PATH := \$(PIQI_ROOT)" >> $M
# path to the "piqi" executable
echo "export PIQI := \$(PIQI_ROOT)/src/piqi" >> $M
echo >> $M
if [ -n "$TOOLCHAIN" ] # cross-compilation
then
echo "export OCAMLFIND_TOOLCHAIN := $TOOLCHAIN" >> $M
echo "export AR = \$(shell ocamlfind -toolchain $TOOLCHAIN ocamlopt -c -ccopt --print-prog-name=ar .c 2>/dev/null)" >> $M
echo "export EXE := .exe" >> $M
echo "STRIP = \$(shell ocamlfind -toolchain $TOOLCHAIN ocamlopt -c -ccopt --print-prog-name=strip .c 2>/dev/null)" >> $M
# skipping everything else in cross-compilation mode; namely, we have to
# cross-compile deps that come with the package
echo "export SYSTEM := unix" >> $M
# figure out which dependencies we need to build
echo "checking whether necessary dependencies are already installed..."
export OCAMLFIND_TOOLCHAIN=$TOOLCHAIN
for i in xmlm easy-format base64
do
dir="`$OCAMLFIND query $i 2>/dev/null`"
if [ $? -eq 0 ]
then
echo "$i is installed in $dir"
echo "SKIP-$i = 1" >> $M
else
echo "$i is not installed; it will be built during \"make deps\""
fi
done
else
# detecting the type of OCaml toolchain
system="`ocamlc -config 2>/dev/null | grep system | sed 's/system: //'`"
echo "export SYSTEM := $system" >> $M
echo >> $M
echo "detected $system OCaml toolchain"
fi
OCAML_VERSION=`$OCAMLFIND ocamlc -version`
if [ $? -ne 0 ]
then
echo "configure: error: failed to get OCaml version" 1>&2
exit 1
fi
echo "ocaml version: $OCAML_VERSION"
case $OCAML_VERSION in
3.*|4.00.*|4.01.*|4.02.*)
echo "configure: error: OCaml version ($OCAML_VERSION) is too old -- need >= 4.03; See INSTALL for details" 1>&2
exit 1
;;
esac
echo "configure OK"
# ex: sw=4 ts=4 et