forked from ocaml/merlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·266 lines (228 loc) · 6.53 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
#!/bin/sh
BIN_DIR=/usr/local/bin
SHARE_DIR=/usr/local/share
VIM_DIR=/usr/local/share/ocamlmerlin/vim
WITH_VIMBUFSYNC="1"
WITH_BIN_ANNOT=""
VERSION_STRING=""
if ! [ -x $(which ocamlfind) ]; then
echo "OCamlfind is missing. Please install it."
exit 1
fi
EXIT=0
if which tput > /dev/null 2>&1 ; then
COL_CLEAR=$(tput sgr0)
COL_RED=$(tput setf 4)
COL_GREEN=$(tput setf 2)
else
COL_CLEAR=
COL_RED=
COL_GREEN=
fi
check_package()
{
if ocamlfind query "$2" >/dev/null 2>/dev/null; then
printf "Found $2\t${COL_GREEN}GOOD${COL_CLEAR}\n"
else
printf "${COL_RED}BAD${COL_CLEAR} $2 is missing\n\t$3\n"
eval $1=1
fi
}
usage()
{
cat <<END
\`configure' configures your Merlin installation.
The options available for better control are as follow:
--bindir <path> where to install merlin's executable
default: /usr/local/bin
--sharedir <path> where the different editor modes will be installed
default: /usr/local/share
--prefix <path> when given, bindir will be set to '<path>/bin' and
sharedir to '<path>/share'
--vimdir <path> when given, vim bindings will be installed to '<path>'
default: /usr/local/share/ocamlmerlin/vim
--with-vimbufsync install vim vimbufsync plugin [default]
--without-vimbufsync do not install vim vimbufsync plugin
--with-bin-annot compiles merlin with '--bin-annot', useful if you plan
to work on merlin itself.
--enable-compiled-emacs-mode compiles the emacs mode.
Makes the plugin load slightly faster.
--with-version-string <str> Overwrite the version message printed by
merlin when called with -version or -vnum.
END
}
sed_file()
{
EXPR="$1"
FILE="$2"
mv "$FILE" "$FILE".org
sed -e "$EXPR" < "$FILE".org > "$FILE"
rm "$FILE".org
}
while [ -n "$1" ]; do
case "$1" in
--prefix)
shift 1
BIN_DIR="$1/bin"
SHARE_DIR="$1/share"
VIM_DIR="$SHARE_DIR/ocamlmerlin/vim"
;;
--bindir)
shift 1
BIN_DIR="$1"
;;
--sharedir)
shift 1
SHARE_DIR="$1"
;;
--vimdir)
shift 1
VIM_DIR="$1"
;;
--with-vimbufsync)
WITH_VIMBUFSYNC="1"
;;
--without-vimbufsync)
WITH_VIMBUFSYNC=""
;;
--with-bin-annot)
WITH_BIN_ANNOT="-cflags -bin-annot"
;;
--enable-compiled-emacs-mode)
ENABLE_COMPILED_EMACS_MODE=true
;;
--with-version-string)
shift 1
VERSION_STRING="$1"
;;
--help|-help|-h)
usage
exit 0
esac
shift 1
done
OCAML_VERSION="ocaml_400"
OCAML_VERSION_MESSAGE="Unknown, defaulting to 4.00.1"
OCAML_VERSION_VAL='`OCaml_4_00_1'
OCAML_VERSION_TYP='[ `OCaml_4_00_1 | `OCaml_4_01_0 | `OCaml_4_02_0 | `OCaml_4_02_1 | `OCaml_4_02_2 | `OCaml_4_03_trunk ]'
cat <<END
Merlin configuration
--------------------
END
check_package EXIT findlib "Install findlib"
check_package EXIT yojson "Install yojson"
MAGIC_VERSION=$(ocamlfind c -config | grep cmi_magic_number | cut -d' ' -f2)
FULL_VERSION=$(ocamlfind c -version)
case "$MAGIC_VERSION" in
"Caml1999I015")
OCAML_VERSION="ocaml_401"
OCAML_VERSION_MESSAGE="OCaml 4.01.0"
OCAML_VERSION_VAL='`OCaml_4_01_0'
;;
"Caml1999I017")
OCAML_VERSION="ocaml_402"
if [ "x$FULL_VERSION" = "x4.02.0" ]; then
OCAML_VERSION_MESSAGE="OCaml 4.02.0"
sed_file '/\(S\|Ignored_s\)can_next_char\|Any_ty\|| Custom/d' \
src/ocaml_402/typing/typecore.ml
OCAML_VERSION_VAL='`OCaml_4_02_0'
elif [ "x$FULL_VERSION" = "x4.02.1" ]; then
OCAML_VERSION_MESSAGE="OCaml 4.02.1"
sed_file '/Any_ty\|| Custom/d' \
src/ocaml_402/typing/typecore.ml
OCAML_VERSION_VAL='`OCaml_4_02_1'
else
OCAML_VERSION_MESSAGE="OCaml 4.02.2"
OCAML_VERSION_VAL='`OCaml_4_02_2'
fi
;;
"Caml1999I020")
OCAML_VERSION="ocaml_trunk"
OCAML_VERSION_MESSAGE="OCaml 4.03 (trunk)"
OCAML_VERSION_VAL='`OCaml_4_03_trunk'
;;
esac
# Findlib version check
if [ "x1.5.1" = "x$(ocamlfind query findlib -format '%v')" ]; then
printf "\nOld version of findlib detected (1.5.1), patching\n"
sed_file 's/Findlib\.resolve_path ~base:d ~explicit:true/Findlib.resolve_path ~base:d/' \
src/kernel/dot_merlin.ml
fi
if [ -e "src/${OCAML_VERSION}.git/.git" ]; then
OCAML_VERSION="${OCAML_VERSION}.git"
OCAML_VERSION_MESSAGE="${OCAML_VERSION_MESSAGE} (git version)"
fi
if ocamlfind ocamlopt; then
NATIVE=true
else
NATIVE=false
fi
cat <<END
System config:
OCaml ABI version: $OCAML_VERSION_MESSAGE
Native code: $NATIVE
Will install:
ocamlmerlin binary in: $BIN_DIR
vim mode in: $VIM_DIR
To customize directories, use:
./configure [--prefix <dir>] [--bindir <dir>] [--sharedir <dir>] [--vimdir <vimdir>] [--with-vimbufsync | --without-vimbufsync]
For more informations rerun with --help.
END
SYSTEM=$(ocamlfind c -config | grep system|cut -d' ' -f2)
case "$SYSTEM" in
mingw*|win*)
rm -rf "$PWD/src/ocaml" 2>&1 >/dev/null &&
cp -R "$PWD/src/$OCAML_VERSION" "$PWD/src/ocaml"
;;
*)
rm -f "$PWD/src/ocaml" 2>&1 >/dev/null &&
ln -sf "$PWD/src/$OCAML_VERSION" "$PWD/src/ocaml"
;;
esac
mkdir -p "$PWD/src/config"
OS_TYPE=$(ocamlfind c -config | grep os_type|cut -d' ' -f2)
# 64-bit Windows also has OS_TYPE = Win32
case "$OS_TYPE" in
Win32)
EXE=.exe
;;
*)
EXE=
;;
esac
if [ -d "$BIN_DIR" ]; then
cat >Makefile.config <<END
BIN_DIR=$BIN_DIR
SHARE_DIR=$SHARE_DIR
VIM_DIR=$VIM_DIR
NATIVE=$NATIVE
WITH_BIN_ANNOT=$WITH_BIN_ANNOT
WITH_VIMBUFSYNC=$WITH_VIMBUFSYNC
ENABLE_COMPILED_EMACS_MODE=$ENABLE_COMPILED_EMACS_MODE
EXE=$EXE
END
if [ -n "$VERSION_STRING" ]; then
true
elif [ -d ".git" ]; then
VERSION_STRING="git-`git rev-parse HEAD`"
elif [ -f "CHANGELOG" ]; then
VERSION_STRING=`head -n1 CHANGELOG | cut -d' ' -f2`
else
VERSION_STRING="unknown"
fi
cat >src/config/my_config.ml <<END
let version = "$VERSION_STRING";;
let ocamlversion : $OCAML_VERSION_TYP = $OCAML_VERSION_VAL;;
END
if [ "$EXIT" -eq 0 ]; then
echo "Now, type 'make' to compile then 'make install'."
else
echo "Something bad happened. Check your configuration before trying to 'make'."
fi
else
[ -d "$BIN_DIR" ] || echo "'$BIN_DIR' not found or not a directory."
[ -d "$SHARE_DIR" ] || echo "'$SHARE_DIR' not found or not a directory."
[ -d "$VIM_DIR" ] || echo "'$VIM_DIR' not found or not a directory."
echo "Please check configuration."
exit 1
fi