Skip to content
This repository

Add support for building opam #15

Merged
merged 5 commits into from over 1 year ago

2 participants

Edward J. Schwartz Hezekiah M. Carty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 3 changed files with 83 additions and 20 deletions. Show diff stats Hide diff stats

  1. +8 6 README.md
  2. +11 13 RECIPES.md
  3. +64 1 ocamlbrew
14 README.md
Source Rendered
@@ -54,6 +54,7 @@ ocamlbrew can be configured with several environment variables.
54 54 -p [patch] Patch to apply to OCaml
55 55 -a Install everything with no prompts
56 56 -o Install OCaml only, no prompts
  57 + -r Install OCaml and opam only, no prompts
57 58 -f Install OCaml, findlib and odb.ml only, no prompts
58 59 -x Install OCaml, findlib, odb.ml, oasis, no prompts
59 60 -s [path] Install OCaml from Subversion [path]
@@ -65,12 +66,12 @@ Subversion paths should be relative to `http://caml.inria.fr/svn/ocaml/`
65 66
66 67 #### After installation
67 68
68   -ocamlbrew will provide instructions on how to setup the newly installed OCaml
69   -environment once all build and installation steps are complete. After
70   -following those instructions, depending on the options selected at ocamlbrew
71   -startup, the [OCaml][] toolchain, [ocamlfind][findlib], [odb.ml][odb],
72   -[oasis][], [utop][], and [ocamlscript][] will be available from the shell
73   -environment.
  69 +ocamlbrew will provide instructions on how to setup the newly
  70 +installed OCaml environment once all build and installation steps are
  71 +complete. After following those instructions, depending on the
  72 +options selected at ocamlbrew startup, the [OCaml][] toolchain,
  73 +[ocamlfind][findlib], [odb.ml][odb], [oasis][], [opam][], [utop][],
  74 +and [ocamlscript][] will be available from the shell environment.
74 75
75 76 ### License
76 77
@@ -81,6 +82,7 @@ ocamlbrew is distributed under the MIT license. See LICENSE for details.
81 82 [odb]: https://github.com/thelema/odb
82 83 [oasis]: http://oasis.forge.ocamlcore.org/
83 84 [oasis-db]: http://oasis.ocamlcore.org/dev/home
  85 +[opam]: http://opam.ocamlpro.com/
84 86 [Batteries]: http://batteries.forge.ocamlcore.org/
85 87 [React]: http://erratique.ch/software/react
86 88 [Lwt]: http://ocsigen.org/lwt/
24 RECIPES.md
Source Rendered
@@ -19,29 +19,25 @@ Unless otherwise noted, each of the recipes below will install under
19 19 # Equivalent to: ./ocamlbrew -t -f
20 20 # Specify that we want to pull from Subversion trunk and we only want
21 21 # OCaml, findlib, and odb.ml
22   - export OCAMLBREW_FLAGS="-t -f"
23   - curl -kL https://raw.github.com/hcarty/ocamlbrew/master/ocamlbrew-install | bash
  22 + curl -kL https://raw.github.com/hcarty/ocamlbrew/master/ocamlbrew-install | env OCAMLBREW_FLAGS="-t -f" bash
24 23
25 24 ### OCaml 3.12.1 release version, no other tools
26 25
27 26 # Equivalent to: ./ocamlbrew -s release/3.12.1 -o
28 27 # Specify an explicit Subversion path to pull from and we want OCaml only
29   - export OCAMLBREW_FLAGS="-s release/3.12.1 -o"
30   - curl -kL https://raw.github.com/hcarty/ocamlbrew/master/ocamlbrew-install | bash
  28 + curl -kL https://raw.github.com/hcarty/ocamlbrew/master/ocamlbrew-install | env OCAMLBREW_FLAGS="-s release/3.12.1 -o" bash
31 29
32 30 ### Install to a custom brew root
33 31
34 32 # Build and install under /opt/ocamlbrew
35   - export OCAMLBREW_BASE=/opt/ocamlbrew
36 33 # Equivalent to: ./ocamlbrew -a
37   - curl -kL https://raw.github.com/hcarty/ocamlbrew/master/ocamlbrew-install | bash
  34 + curl -kL https://raw.github.com/hcarty/ocamlbrew/master/ocamlbrew-install | env OCAMLBREW_BASE="/opt/ocamlbrew" bash
38 35
39 36 ### Install OCaml trunk to a full customized directory
40 37
41 38 # Build and install under /opt/ocamlbrew/
42 39 # Equivalent to: ./ocamlbrew -t -f -b /opt/ocamlbrew -n trunk
43   - export OCAMLBREW_FLAGS="-t -f -b /opt/ocamlbrew -n trunk"
44   - curl -kL https://raw.github.com/hcarty/ocamlbrew/master/ocamlbrew-install | bash
  40 + curl -kL https://raw.github.com/hcarty/ocamlbrew/master/ocamlbrew-install | env OCAMLBREW_FLAGS="-t -f -b /opt/ocamlbrew -n trunk" bash
45 41
46 42 ### Download ocamlbrew and run it locally
47 43
@@ -54,17 +50,19 @@ install each available package.
54 50 # ... and run, optionally configuring the environment first
55 51 bash ocamlbrew
56 52
57   -You will be provided with several prompts asking which software to install.
58   -[OCaml][] is always installed, with [findlib][], [oasis][], [Batteries][],
59   -[utop][], and [ocamlscript][] optionally included as well. If they are
60   -requested, [oasis][], [Batteries][], [utop][], and [ocamlscript][] are all
61   -installed using [oasis-db][] via [odb][].
  53 +You will be provided with several prompts asking which software to
  54 +install. [OCaml][] is always installed, with [findlib][], [oasis][],
  55 +[opam][], [Batteries][], [utop][], and [ocamlscript][] optionally
  56 +included as well. If they are requested, [oasis][], [Batteries][],
  57 +[utop][], and [ocamlscript][] are all installed using [oasis-db][] via
  58 +[odb][].
62 59
63 60 [OCaml]: http://caml.inria.fr/ocaml/release.en.html
64 61 [findlib]: http://projects.camlcity.org/projects/findlib.html
65 62 [odb]: https://github.com/thelema/odb
66 63 [oasis]: http://oasis.forge.ocamlcore.org/
67 64 [oasis-db]: http://oasis.ocamlcore.org/dev/home
  65 +[opam]: http://opam.ocamlpro.com/
68 66 [Batteries]: http://batteries.forge.ocamlcore.org/
69 67 [React]: http://erratique.ch/software/react
70 68 [Lwt]: http://ocsigen.org/lwt/
65 ocamlbrew
@@ -20,6 +20,7 @@ function help_then_exit() {
20 20 echo "-p [patch] Patch to apply to OCaml"
21 21 echo "-a Install everything with no prompts"
22 22 echo "-o Install OCaml only, no prompts"
  23 + echo "-r Install OCaml and opam only, no prompts"
23 24 echo "-f Install OCaml, findlib and odb.ml only, no prompts"
24 25 echo "-x Install OCaml, findlib, odb.ml, oasis, no prompts"
25 26 echo "-s [path] Install OCaml from Subversion [path]"
@@ -91,6 +92,7 @@ function init_variables() {
91 92 : ${INSTALL_OCAML_ONLY="false"}
92 93 : ${INSTALL_OCAML_FINDLIB_ONLY="false"}
93 94 : ${INSTALL_OASIS_ONLY="false"}
  95 + : ${INSTALL_OPAM_ONLY="false"}
94 96 : ${OCAMLBREW_INSTALL_SVN="false"}
95 97
96 98 # Set configuration options such as installation and build locations here
@@ -112,6 +114,13 @@ function init_variables() {
112 114 : ${FINDLIB_VERSION=$FINDLIB_MAJOR_VERSION.$FINDLIB_MINOR_VERSION.$FINDLIB_PATCH_VERSION}
113 115 : ${FINDLIB_URL=http://download.camlcity.org/download/findlib-$FINDLIB_VERSION.tar.gz}
114 116
  117 + # opam version we are installing and download URL
  118 + : ${OPAM_MAJOR_VERSION=0}
  119 + : ${OPAM_MINOR_VERSION=9}
  120 + : ${OPAM_PATCH_VERSION=1}
  121 + : ${OPAM_VERSION=$OPAM_MAJOR_VERSION.$OPAM_MINOR_VERSION.$OPAM_PATCH_VERSION}
  122 + : ${OPAM_URL=https://github.com/OCamlPro/opam/archive/$OPAM_VERSION.tar.gz}
  123 +
115 124 OCAML_PATCH=""
116 125
117 126 if [ "$OCAMLBREW_NAME" != "" ]; then
@@ -138,7 +147,7 @@ function init_variables() {
138 147 # Handle command line arguments
139 148 #
140 149 function parse_opts() {
141   - while getopts "hb:c:p:aofxs:tn:v:" OPTION; do
  150 + while getopts "hb:c:p:aorfxs:tn:v:" OPTION; do
142 151 case $OPTION in
143 152 h)
144 153 help_then_exit ;;
@@ -157,6 +166,9 @@ function parse_opts() {
157 166 o)
158 167 INSTALL_OCAML_ONLY="true"
159 168 ;;
  169 + r)
  170 + INSTALL_OPAM_ONLY="true"
  171 + ;;
160 172 f)
161 173 INSTALL_OCAML_FINDLIB_ONLY="true"
162 174 ;;
@@ -206,6 +218,7 @@ function greet() {
206 218 FINDLIB_INSTALL="false"
207 219 ODB_INSTALL="false"
208 220 OASIS_INSTALL="false"
  221 + OPAM_INSTALL="false"
209 222 UTOP_INSTALL="false"
210 223 BATTERIES_INSTALL="false"
211 224 OCAMLSCRIPT_INSTALL="false"
@@ -214,6 +227,7 @@ function greet() {
214 227 FINDLIB_INSTALL="true"
215 228 ODB_INSTALL="true"
216 229 OASIS_INSTALL="true"
  230 + OPAM_INSTALL="true"
217 231 UTOP_INSTALL="true"
218 232 BATTERIES_INSTALL="true"
219 233 OCAMLSCRIPT_INSTALL="true"
@@ -230,6 +244,9 @@ function greet() {
230 244 FINDLIB_INSTALL="true"
231 245 ODB_INSTALL="true"
232 246 OASIS_INSTALL="true"
  247 + elif [ "$INSTALL_OPAM_ONLY" = "true" ]; then
  248 + SHOW_CONTINUE_PROMPT="false"
  249 + OPAM_INSTALL="true"
233 250 else
234 251 # Ask the user what components they would like to install
235 252 prompt "Would you like to install findlib? (y/n) "
@@ -276,6 +293,14 @@ function greet() {
276 293 OCAMLSCRIPT_INSTALL="false"
277 294 fi
278 295 fi
  296 +
  297 + prompt "Would you like to install opam? (y/n) "
  298 + reply_lower="$(tr [A-Z] [a-z] <<< "$REPLY")"
  299 + if [ "$reply_lower" = "y" ]; then
  300 + OPAM_INSTALL="true"
  301 + else
  302 + OPAM_INSTALL="false"
  303 + fi
279 304 fi
280 305
281 306 # Print a summary of what we are going to do, then continue
@@ -284,6 +309,7 @@ function greet() {
284 309 if "$FINDLIB_INSTALL" = "true"; then say and install findlib; fi
285 310 if "$ODB_INSTALL" = "true"; then say and install odb; fi
286 311 if "$OASIS_INSTALL" = "true"; then say and install oasis; fi
  312 + if "$OPAM_INSTALL" = "true"; then say and install opam; fi
287 313 if "$UTOP_INSTALL" = "true"; then say and install utop; fi
288 314 if "$BATTERIES_INSTALL" = "true"; then say and install Batteries; fi
289 315 if "$OCAMLSCRIPT_INSTALL" = "true"; then say and install ocamlscript; fi
@@ -412,6 +438,36 @@ function brew_odb() {
412 438 }
413 439
414 440 #
  441 +# Handle opam brewing
  442 +#
  443 +function brew_opam() {
  444 + case $1 in
  445 + retrieve)
  446 + say Retrieving the latest version of opam
  447 + curl -LO $OPAM_URL
  448 + tar xzf $OPAM_VERSION.tar.gz
  449 + cd opam-$OPAM_VERSION
  450 + ;;
  451 + configure)
  452 + say Configuring opam
  453 + ./configure --prefix="$OCAML_BASE"
  454 + ;;
  455 + build)
  456 + say Building opam
  457 + make
  458 + make install
  459 + {
  460 + echo export OPAMROOT="$OCAML_BASE/.opam"
  461 + echo 'eval `opam config env`'
  462 + } >> "$OCAML_BASE"/etc/ocamlbrew.bashrc
  463 +
  464 + # Initialize opam
  465 + OPAMROOT="$OCAML_BASE/.opam" opam init
  466 + ;;
  467 + esac
  468 +}
  469 +
  470 +#
415 471 # Install packages with odb, potentially with some extra setup
416 472 #
417 473 function install_with_odb() {
@@ -495,6 +551,13 @@ if [ "$OASIS_INSTALL" = "true" ]; then
495 551 install_with_odb "oasis"
496 552 fi
497 553
  554 +# opam
  555 +if [ "$OPAM_INSTALL" = "true" ]; then
  556 + brew_opam "retrieve"
  557 + brew_opam "configure"
  558 + brew_opam "build"
  559 +fi
  560 +
498 561 # utop
499 562 if [ "$UTOP_INSTALL" = "true" ]; then
500 563 install_with_odb "utop"

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.