/
configure
executable file
·210 lines (176 loc) · 5.21 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
#!/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
COL_CLEAR=$(tput sgr0)
COL_RED=$(tput setf 4)
COL_GREEN=$(tput setf 2)
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
}
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"
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"
;;
"Caml1999I017")
OCAML_VERSION="ocaml_402"
if [ "x$FULL_VERSION" = "x4.02.0" ]; then
OCAML_VERSION_MESSAGE="OCaml 4.02.0"
mv src/ocaml_402/typing/typecore.ml src/ocaml_402/typing/typecore.ml.org
sed -E '/(S|Ignored_s)can_next_char/d' \
<src/ocaml_402/typing/typecore.ml.org >src/ocaml_402/typing/typecore.ml
rm src/ocaml_402/typing/typecore.ml.org
else
OCAML_VERSION_MESSAGE="OCaml 4.02.1"
fi
;;
"Caml1999I019")
OCAML_VERSION="ocaml_trunk"
OCAML_VERSION_MESSAGE="OCaml 4.03 (trunk)"
;;
esac
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
rm -f "$PWD/src/ocaml" 2>&1 >/dev/null &&
ln -sf "$PWD/src/$OCAML_VERSION" "$PWD/src/ocaml"
mkdir -p "$PWD/src/config"
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
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
echo >src/config/my_config.ml "let version = \"$VERSION_STRING\";;"
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