Skip to content
Newer
Older
100755 513 lines (459 sloc) 14.2 KB
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
1 #!/usr/bin/env bash
6b65425 @hcarty Initial ocamlbrew commit
authored
2
3 # Fail if we try to use an undefined value
4 set -u
5 # Quit on errors
1e81733 @hcarty Update error handling to (hopefully) display error messages properly
authored
6 set -o pipefail
7 set -o errtrace
6b65425 @hcarty Initial ocamlbrew commit
authored
8
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
9 #
10 # Display usage message then quit
11 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
12 function help_then_exit() {
e1ff28c @hcarty Add --help and --all command line arguments
authored
13 echo Usage: "$0" [flags]
14 echo
15 echo "Possible flags:"
804ab8d @hcarty Add -c flag for passing configuration options to OCaml's configure sc…
authored
16 echo "-h Display this message"
17 echo "-b [path] Use [path] as \$OCAMLBREW_BASE"
18 echo "-c \"[flags]\" Flags to pass to OCaml's configure"
3249325 @hcarty Experimental support for applying patches to OCaml before building
authored
19 echo "-p [patch] Patch to apply to OCaml"
804ab8d @hcarty Add -c flag for passing configuration options to OCaml's configure sc…
authored
20 echo "-a Install everything with no prompts"
21 echo "-o Install OCaml only, no prompts"
20e84fa @hcarty Correct the help message for -f; Update README.md's flag info
authored
22 echo "-f Install OCaml, findlib and odb.ml only, no prompts"
89b7d73 @hcarty Add -x flag to install OCaml, findlib, odb.ml, oasis. Closes issue #10
authored
23 echo "-x Install OCaml, findlib, odb.ml, oasis, no prompts"
804ab8d @hcarty Add -c flag for passing configuration options to OCaml's configure sc…
authored
24 echo "-s [path] Install OCaml from Subversion [path]"
25 echo "-t Install OCaml from Subversion trunk"
26 echo "-n [name] Install under \$OCAMLBREW_BASE/[name]"
4d1adc4 @hcarty Support OCaml installations from SVN; Use getopts for argument handling
authored
27 echo
20a936d @hcarty Add the ability to specify $OCAMLBREW_BASE from the command line
authored
28 echo "The build and installation will occur under \$OCAMLBREW_BASE"
3249325 @hcarty Experimental support for applying patches to OCaml before building
authored
29 echo
0462bc3 @hcarty Add some new default build sets; Custom install basename; Quoting cle…
authored
30 echo "Subversion path should be relative to $OCAML_SVN_ROOT"
3249325 @hcarty Experimental support for applying patches to OCaml before building
authored
31 echo
32 echo "OCaml patches can be absolute paths on the file system, or relative"
33 echo "to the OCaml source root"
e1ff28c @hcarty Add --help and --all command line arguments
authored
34 exit 1
35 }
36
1e81733 @hcarty Update error handling to (hopefully) display error messages properly
authored
37 function undo_redirect() {
38 exec 2>&4 1>&3
39 }
40
41 function error_message() {
42 echo Something errored out, please check the log file for details:
43 echo "$OCAMLBREW_LOGFILE"
44 echo Exiting...
45 }
46
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
47 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
48 # Print a message when quitting due to an error
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
49 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
50 function handle_error() {
1e81733 @hcarty Update error handling to (hopefully) display error messages properly
authored
51 undo_redirect
52 error_message
53 exit 1
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
54 }
55
56 #
57 # Initialize output redirection
58 #
59 function init_redirect() {
1e81733 @hcarty Update error handling to (hopefully) display error messages properly
authored
60 exec 3>&1 4>&2
61 exec 1>"$OCAMLBREW_LOGFILE" 2>&1
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
62 }
63
64 #
65 # Output which should be displayed on screen and logged
66 #
67 function say() {
68 echo "$*" >&3
69 echo "$*"
70 }
71
72 #
73 # Read input without logging the input prompt
74 #
75 function prompt() {
76 echo -n "$*" >&3
77 read
2408ca2 @hcarty Print a notice to check the log file if an error occurs
authored
78 }
79
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
80 #
e595721 @hcarty Initialize variables in the right order, otherwise some combinations …
authored
81 # Initialize lots and lots of global build and installation variables
82 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
83 function init_variables() {
e595721 @hcarty Initialize variables in the right order, otherwise some combinations …
authored
84 # Installation prefix for the software being installed
85 : ${OCAMLBREW_BASE="$HOME"/ocamlbrew}
86 # By default, there is no custom OCaml installation directory name
87 : ${OCAMLBREW_NAME=""}
88 # Specific installation set options
89 : ${INSTALL_ALL="false"}
90 : ${INSTALL_OCAML_ONLY="false"}
91 : ${INSTALL_OCAML_FINDLIB_ONLY="false"}
89b7d73 @hcarty Add -x flag to install OCaml, findlib, odb.ml, oasis. Closes issue #10
authored
92 : ${INSTALL_OASIS_ONLY="false"}
e595721 @hcarty Initialize variables in the right order, otherwise some combinations …
authored
93 : ${OCAMLBREW_INSTALL_SVN="false"}
94
95 # Set configuration options such as installation and build locations here
96
97 # OCaml from Subversion
98 : ${OCAMLBREW_SVN_PATH=trunk}
99
100 # The version of OCaml we are installing and download URL
26e7264 @hcarty OCaml 4.00.0 is now the default version
authored
101 : ${OCAML_MAJOR_VERSION=4}
102 : ${OCAML_MINOR_VERSION=00}
6869326 @hcarty Bump default OCaml version to 4.00.1
authored
103 : ${OCAML_PATCH_VERSION=1}
e595721 @hcarty Initialize variables in the right order, otherwise some combinations …
authored
104 : ${OCAML_VERSION=$OCAML_MAJOR_VERSION.$OCAML_MINOR_VERSION.$OCAML_PATCH_VERSION}
105 : ${OCAML_URL=http://caml.inria.fr/pub/distrib/ocaml-$OCAML_MAJOR_VERSION.$OCAML_MINOR_VERSION/ocaml-$OCAML_VERSION.tar.gz}
106
107 # findlib version we are installing and download URL
108 : ${FINDLIB_MAJOR_VERSION=1}
aadbdcd @hcarty Bump to latest findlib version; Works with OCaml svn version/4.00
authored
109 : ${FINDLIB_MINOR_VERSION=3}
7ef9a4c @hcarty Update to use findlib 1.3.3
authored
110 : ${FINDLIB_PATCH_VERSION=3}
e595721 @hcarty Initialize variables in the right order, otherwise some combinations …
authored
111 : ${FINDLIB_VERSION=$FINDLIB_MAJOR_VERSION.$FINDLIB_MINOR_VERSION.$FINDLIB_PATCH_VERSION}
112 : ${FINDLIB_URL=http://download.camlcity.org/download/findlib-$FINDLIB_VERSION.tar.gz}
113
0ab313e @hcarty Fix OCaml patch support
authored
114 OCAML_PATCH=""
115
e595721 @hcarty Initialize variables in the right order, otherwise some combinations …
authored
116 if [ "$OCAMLBREW_NAME" != "" ]; then
117 # Install path based on a custom directory name
118 OCAML_BASE="$OCAMLBREW_BASE"/"$OCAMLBREW_NAME"
119 elif [ "$OCAMLBREW_INSTALL_SVN" = "true" ]; then
120 # Install path based on location in the Subversion tree
121 OCAML_BASE="$OCAMLBREW_BASE"/ocaml-svn/"$OCAMLBREW_SVN_PATH"
122 else
123 # Install path based on release version of OCaml
124 OCAML_BASE="$OCAMLBREW_BASE"/ocaml-"$OCAML_VERSION"
125 fi
126 # Parent directory where software will be built
127 : ${BUILD_DIR="$OCAML_BASE"/build}
128
804ab8d @hcarty Add -c flag for passing configuration options to OCaml's configure sc…
authored
129 # Configuration flags for OCaml
130 : ${OCAML_CONFIG_FLAGS=""}
131
e595721 @hcarty Initialize variables in the right order, otherwise some combinations …
authored
132 # Output will be redirected to this file
df3a20c @avsm further mktemp portability fix
avsm authored
133 : ${OCAMLBREW_LOGFILE=`mktemp -t ocamlbrew.XXXXXXXXXX`}
e595721 @hcarty Initialize variables in the right order, otherwise some combinations …
authored
134 }
135
136 #
e1ff28c @hcarty Add --help and --all command line arguments
authored
137 # Handle command line arguments
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
138 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
139 function parse_opts() {
89b7d73 @hcarty Add -x flag to install OCaml, findlib, odb.ml, oasis. Closes issue #10
authored
140 while getopts "hb:c:p:aofxs:tn:" OPTION; do
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
141 case $OPTION in
142 h)
143 help_then_exit ;;
20a936d @hcarty Add the ability to specify $OCAMLBREW_BASE from the command line
authored
144 b)
145 OCAMLBREW_BASE="$OPTARG"
146 ;;
804ab8d @hcarty Add -c flag for passing configuration options to OCaml's configure sc…
authored
147 c)
85dd3a9 @hcarty Make it a bit easier to pass -c arguments from $OCAMLBREW_FLAGS
authored
148 OCAML_CONFIG_FLAGS="$(tr [=] [\ ] <<< "$OPTARG")"
804ab8d @hcarty Add -c flag for passing configuration options to OCaml's configure sc…
authored
149 ;;
3249325 @hcarty Experimental support for applying patches to OCaml before building
authored
150 p)
151 OCAML_PATCH="$OPTARG"
152 ;;
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
153 a)
154 INSTALL_ALL="true"
155 ;;
156 o)
157 INSTALL_OCAML_ONLY="true"
158 ;;
159 f)
160 INSTALL_OCAML_FINDLIB_ONLY="true"
161 ;;
89b7d73 @hcarty Add -x flag to install OCaml, findlib, odb.ml, oasis. Closes issue #10
authored
162 x)
163 INSTALL_OASIS_ONLY="true"
164 ;;
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
165 s)
166 OCAMLBREW_INSTALL_SVN="true"
167 OCAMLBREW_SVN_PATH="$OPTARG"
168 ;;
169 t)
170 OCAMLBREW_INSTALL_SVN="true"
171 ;;
172 n)
173 OCAMLBREW_NAME="$OPTARG"
174 ;;
175 ?)
176 help_then_exit ;;
177 esac
178 done
179 }
180
181 #
182 # Display greeting, optional prompts, and summary message
183 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
184 function greet() {
185 say Welcome to ocamlbrew!
186 say
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
187 if [ "$OCAMLBREW_INSTALL_SVN" = "true" ]; then
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
188 say Working with "$OCAML_SVN_ROOT""$OCAMLBREW_SVN_PATH"
e1ff28c @hcarty Add --help and --all command line arguments
authored
189 else
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
190 say Working with "$OCAML_URL"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
191 fi
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
192 say Software will be built and installed under "$OCAML_BASE"
193 say Output will be written to "$OCAMLBREW_LOGFILE"
33aea52 @hcarty Explicitly state that the log file can be followed for more information.
authored
194 say You can \"tail -f "$OCAMLBREW_LOGFILE"\" in another terminal to track
195 say the build process.
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
196 say
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
197
198 SHOW_CONTINUE_PROMPT="true"
199 FINDLIB_INSTALL="false"
200 ODB_INSTALL="false"
201 OASIS_INSTALL="false"
202 UTOP_INSTALL="false"
203 BATTERIES_INSTALL="false"
115aaad @hcarty Add ocamlscript as an installable option - untested
authored
204 OCAMLSCRIPT_INSTALL="false"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
205 if [ "$INSTALL_ALL" = "true" ]; then
206 SHOW_CONTINUE_PROMPT="false"
207 FINDLIB_INSTALL="true"
208 ODB_INSTALL="true"
209 OASIS_INSTALL="true"
210 UTOP_INSTALL="true"
211 BATTERIES_INSTALL="true"
115aaad @hcarty Add ocamlscript as an installable option - untested
authored
212 OCAMLSCRIPT_INSTALL="true"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
213 elif [ "$INSTALL_OCAML_ONLY" = "true" ]; then
214 # Nothing to do, the defaults get us here
215 SHOW_CONTINUE_PROMPT="false"
216 OCAML_ONLY="true"
217 elif [ "$INSTALL_OCAML_FINDLIB_ONLY" = "true" ]; then
218 SHOW_CONTINUE_PROMPT="false"
e1ff28c @hcarty Add --help and --all command line arguments
authored
219 FINDLIB_INSTALL="true"
220 ODB_INSTALL="true"
89b7d73 @hcarty Add -x flag to install OCaml, findlib, odb.ml, oasis. Closes issue #10
authored
221 elif [ "$INSTALL_OASIS_ONLY" = "true" ]; then
222 SHOW_CONTINUE_PROMPT="false"
223 FINDLIB_INSTALL="true"
224 ODB_INSTALL="true"
225 OASIS_INSTALL="true"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
226 else
227 # Ask the user what components they would like to install
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
228 prompt "Would you like to install findlib? (y/n) "
c7fe72a @hcarty Slight modification to work on old(er) bash versions
authored
229 reply_lower="$(tr [A-Z] [a-z] <<< "$REPLY")"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
230 if [ "$reply_lower" != "y" ]; then
231 FINDLIB_INSTALL="false"
232 ODB_INSTALL="false"
e1ff28c @hcarty Add --help and --all command line arguments
authored
233 OASIS_INSTALL="false"
234 UTOP_INSTALL="false"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
235 BATTERIES_INSTALL="false"
115aaad @hcarty Add ocamlscript as an installable option - untested
authored
236 OCAMLSCRIPT_INSTALL="false"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
237 else
238 FINDLIB_INSTALL="true"
239 ODB_INSTALL="true"
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
240 prompt "Would you like to install oasis? (y/n) "
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
241 reply_lower="$(tr [A-Z] [a-z] <<< "$REPLY")"
242 if [ "$reply_lower" = "y" ]; then
243 OASIS_INSTALL="true"
244 else
245 OASIS_INSTALL="false"
246 fi
247
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
248 prompt "Would you like to install utop? (y/n) "
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
249 reply_lower="$(tr [A-Z] [a-z] <<< "$REPLY")"
250 if [ "$reply_lower" = "y" ]; then
251 UTOP_INSTALL="true"
252 else
253 UTOP_INSTALL="false"
254 fi
255
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
256 prompt "Would you like to install Batteries? (y/n) "
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
257 reply_lower="$(tr [A-Z] [a-z] <<< "$REPLY")"
258 if [ "$reply_lower" = "y" ]; then
259 BATTERIES_INSTALL="true"
260 else
261 BATTERIES_INSTALL="false"
262 fi
115aaad @hcarty Add ocamlscript as an installable option - untested
authored
263
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
264 prompt "Would you like to install ocamlscript? (y/n) "
115aaad @hcarty Add ocamlscript as an installable option - untested
authored
265 reply_lower="$(tr [A-Z] [a-z] <<< "$REPLY")"
266 if [ "$reply_lower" = "y" ]; then
267 OCAMLSCRIPT_INSTALL="true"
268 else
269 OCAMLSCRIPT_INSTALL="false"
270 fi
e1ff28c @hcarty Add --help and --all command line arguments
authored
271 fi
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
272 fi
273
274 # Print a summary of what we are going to do, then continue
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
275 say This script is about to:
276 say Install OCaml
277 if "$FINDLIB_INSTALL" = "true"; then say and install findlib; fi
278 if "$ODB_INSTALL" = "true"; then say and install odb; fi
279 if "$OASIS_INSTALL" = "true"; then say and install oasis; fi
280 if "$UTOP_INSTALL" = "true"; then say and install utop; fi
281 if "$BATTERIES_INSTALL" = "true"; then say and install Batteries; fi
282 if "$OCAMLSCRIPT_INSTALL" = "true"; then say and install ocamlscript; fi
283 say
e1ff28c @hcarty Add --help and --all command line arguments
authored
284
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
285 if [ "$SHOW_CONTINUE_PROMPT" = "true" ]; then
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
286 prompt "Continue (y/n)? "
c7fe72a @hcarty Slight modification to work on old(er) bash versions
authored
287 reply_lower="$(tr [A-Z] [a-z] <<< "$REPLY")"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
288 if [ "$reply_lower" != "y" ]; then
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
289 say Exiting...
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
290 rm -f "$OCAMLBREW_LOGFILE"
291 exit 1
e1ff28c @hcarty Add --help and --all command line arguments
authored
292 fi
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
293 fi
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
294 }
295
296 #
297 # Create the build directory
298 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
299 function setup_build_dir() {
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
300 # Create and move to the build directory
301 mkdir -p "$BUILD_DIR"
302 pushd "$BUILD_DIR"
303 }
304
305 #
306 # Handle OCaml brewing
307 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
308 function brew_ocaml() {
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
309 case $1 in
310 retrieve)
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
311 say Retrieving OCaml
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
312 if [ "$OCAMLBREW_INSTALL_SVN" = "true" ]; then
313 mkdir build
314 svn checkout "$OCAML_SVN_ROOT""$OCAMLBREW_SVN_PATH" build
315 cd build
316 else
317 curl -O "$OCAML_URL"
318 tar xzf ocaml-$OCAML_VERSION.tar.gz
319 cd ocaml-$OCAML_VERSION
320 fi
321 ;;
322 build)
3249325 @hcarty Experimental support for applying patches to OCaml before building
authored
323 if [ -n "$OCAML_PATCH" ]; then
324 say Patching OCaml with "$OCAML_PATCH"
325 patch -p0 < "$OCAML_PATCH"
326 fi
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
327 say Building OCaml
804ab8d @hcarty Add -c flag for passing configuration options to OCaml's configure sc…
authored
328 ./configure -prefix "$OCAML_BASE" $OCAML_CONFIG_FLAGS
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
329 make world.opt
330 ;;
331 install)
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
332 say Installing OCaml
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
333 make install
559b5fc @hcarty Revert compiler lib installation for OCaml 3.x
authored
334 # Install the compiler libraries as well. They are needed for utop and some
335 # other projects.
336 if [ "$OCAML_MAJOR_VERSION" = "3" ]; then
337 mkdir -p "$OCAML_BASE"/lib/ocaml/compiler-libs/typing
338 mkdir -p "$OCAML_BASE"/lib/ocaml/compiler-libs/parsing
339 mkdir -p "$OCAML_BASE"/lib/ocaml/compiler-libs/utils
340 cp typing/*.cmi "$OCAML_BASE"/lib/ocaml/compiler-libs/typing/
341 cp parsing/*.cmi "$OCAML_BASE"/lib/ocaml/compiler-libs/parsing/
342 cp utils/*.cmi "$OCAML_BASE"/lib/ocaml/compiler-libs/utils/
343 fi
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
344 cd ..
345 ;;
346 esac
347 }
348
349 #
350 # Handle findlib brewing
351 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
352 function brew_findlib() {
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
353 case $1 in
354 retrieve)
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
355 say Retrieving findlib
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
356 curl -O "$FINDLIB_URL"
357 ;;
358 build)
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
359 say Extracting and building findlib
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
360 tar xzf findlib-$FINDLIB_VERSION.tar.gz
361 cd findlib-$FINDLIB_VERSION
362 ./configure
363 make all opt
364 ;;
365 install)
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
366 say Installing and configuring findlib
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
367 make install
368 # Extra configuration for OCaml libraries with C stubs, as recommended by the
369 # findlib documentation.
370 mkdir `ocamlfind printconf destdir`/stublibs
371 echo `ocamlfind printconf destdir`/stublibs >> `ocamlfind printconf ldconf`
372 ;;
373 esac
374 }
375
376 #
377 # Handle odb brewing
378 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
379 function brew_odb() {
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
380 case $1 in
381 retrieve)
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
382 say Retrieving the latest version of odb.ml
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
383 cd "$OCAML_BASE"/bin
4b7eb64 @hcarty Ignore github's certificate when grabbing odb.ml
authored
384 curl -kO https://raw.github.com/thelema/odb/master/odb.ml
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
385 chmod +x odb.ml
386 ;;
387 configure)
7f2f6c7 @hcarty odb is not configured to install to default site-lib; update odb support
authored
388
389 # The default location for odb builds
390 : ${ODB_BUILD_DIR="$BUILD_DIR"/odb}
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
391
392 # Create a sourceable environment
393 {
7f2f6c7 @hcarty odb is not configured to install to default site-lib; update odb support
authored
394 echo export OCAML_BASE="$OCAML_BASE"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
395 echo export ODB_BUILD_DIR="$ODB_BUILD_DIR"
396 } >> "$OCAML_BASE"/etc/ocamlbrew.bashrc
7f2f6c7 @hcarty odb is not configured to install to default site-lib; update odb support
authored
397
398 # Source it!
399 source "$OCAML_BASE"/etc/ocamlbrew.bashrc
400
401 # Create our build directory
402 mkdir -p "$ODB_BUILD_DIR"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
403 ;;
404 esac
405 }
406
407 #
408 # Install packages with odb, potentially with some extra setup
409 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
410 function install_with_odb() {
411 say Installing "$1" with odb.ml
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
412 case $1 in
413 oasis)
414 odb.ml oUnit fileutils
415 odb.ml oasis
416 ;;
417 utop)
418 # React is an optional dependency of Lwt
419 odb.ml react
420 # Make sure Lwt is built with React support
421 odb.ml --configure-flags --enable-react lwt
422 odb.ml utop
423 ;;
424 *)
425 odb.ml "$1"
426 ;;
427 esac
428 }
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
429
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
430 #
431 # Print a friendly closing message
432 #
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
433 function closing_message() {
434 say
435 say "You may want to add the following line to your ~/.bashrc so that OCaml is
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
436 readily available to use:
6b65425 @hcarty Initial ocamlbrew commit
authored
437
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
438 source $OCAML_BASE/etc/ocamlbrew.bashrc
6b65425 @hcarty Initial ocamlbrew commit
authored
439
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
440 Enjoy!"
441 }
442
443 # Print out a message to let the user know they should check the output log
444 # when an error occurs
18ed39b @hcarty Only trap ERR, not EXIT
authored
445 trap "handle_error" ERR
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
446
447 ################################
448 # This is where the fun begins #
449 ################################
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
450
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
451 # Root for Subversion checkouts
452 OCAML_SVN_ROOT="http://caml.inria.fr/svn/ocaml/"
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
453
454 # Preparation
455 parse_opts "$@"
e595721 @hcarty Initialize variables in the right order, otherwise some combinations …
authored
456 init_variables
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
457 init_redirect
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
458 greet
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
459 setup_build_dir
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
460
461 # OCaml
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
462 brew_ocaml "retrieve"
463 brew_ocaml "build"
464 brew_ocaml "install"
6b65425 @hcarty Initial ocamlbrew commit
authored
465
466 # Setup the path so that OCaml is visible
467 PATH="$OCAML_BASE"/bin:$PATH
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
468 # Make sure we have an etc directory to put configuration files in
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
469 mkdir -p "$OCAML_BASE"/etc
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
470 # Create a sourceable environment
471 echo export PATH="$OCAML_BASE"/bin:\$PATH > "$OCAML_BASE"/etc/ocamlbrew.bashrc
6b65425 @hcarty Initial ocamlbrew commit
authored
472
473 # findlib
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
474 if [ "$FINDLIB_INSTALL" = "true" ]; then
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
475 brew_findlib "retrieve"
476 brew_findlib "build"
477 brew_findlib "install"
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
478 fi
6b65425 @hcarty Initial ocamlbrew commit
authored
479
480 # odb
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
481 if [ "$ODB_INSTALL" = "true" ]; then
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
482 brew_odb "retrieve"
483 brew_odb "configure"
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
484 fi
6b65425 @hcarty Initial ocamlbrew commit
authored
485
486 # oasis
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
487 if [ "$OASIS_INSTALL" = "true" ]; then
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
488 install_with_odb "oasis"
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
489 fi
6b65425 @hcarty Initial ocamlbrew commit
authored
490
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
491 # utop
492 if [ "$UTOP_INSTALL" = "true" ]; then
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
493 install_with_odb "utop"
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
494 fi
ebd0501 @hcarty odb's build and install trees are under $OCAML_BASE now
authored
495
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
496 # Batteries
497 if [ "$BATTERIES_INSTALL" = "true" ]; then
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
498 install_with_odb "batteries"
049e2f1 @hcarty Make each installed component optional; Simplify final instructions
authored
499 fi
6b65425 @hcarty Initial ocamlbrew commit
authored
500
115aaad @hcarty Add ocamlscript as an installable option - untested
authored
501 # ocamlscript
502 if [ "$OCAMLSCRIPT_INSTALL" = "true" ]; then
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
503 install_with_odb "ocamlscript"
115aaad @hcarty Add ocamlscript as an installable option - untested
authored
504 fi
505
6b65425 @hcarty Initial ocamlbrew commit
authored
506 # All done!
507
f28b46a @hcarty Reorganize messages; Change how logging works so to make code a bit c…
authored
508 say Done!
509 popd
6b65425 @hcarty Initial ocamlbrew commit
authored
510
3d62375 @hcarty Experimental refactoring - break up ocamlbrew into a number of functions
authored
511 closing_message
6b65425 @hcarty Initial ocamlbrew commit
authored
512
Something went wrong with that request. Please try again.