-
Notifications
You must be signed in to change notification settings - Fork 2
/
opam-boot
executable file
·118 lines (106 loc) · 2.91 KB
/
opam-boot
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
#!/usr/bin/env bash
set -e
# Sensible defaults:
: ${OPAM_VERSION:="1.2.2"}
: ${OCAML_VERSION:="4.02.3"}
: ${OBJ:=`pwd`/_obj}
while [[ $# > 0 ]]; do
key="$1"
case $key in
--opam)
OPAM_VERSION="$2"
shift # past argument
;;
--ocaml)
OCAML_VERSION="$2"
shift # past argument
;;
--obj)
OBJ="$2"
shift # past argument
;;
build)
BUILD="$2"
shift # past argument
;;
*)
echo "Usage: $0 [--opam $OPAM_VERSION] [--ocaml $OCAML_VERSION] [--obj $OBJ] [build <name>]"
echo ""
echo "Construct an OCaml build environment from scratch with the given version"
echo "of OPAM, the given OCaml version and place it in the given obj directory."
echo ""
echo "If the [build <name>] argument is given then a package is built from an opam"
echo "file in the current directory and named <name>."
exit 0
;;
esac
shift
done
ORIGINAL_DIR=`pwd`
mkdir -p ${OBJ}
ENV=${OBJ}/opam-env.sh
if [ -e ${ENV} ]; then
. ${ENV}
fi
echo "export OPAMROOT=\"${OBJ}/opamroot\"" > ${ENV}
chmod a+x ${ENV}
mkdir -p ${OBJ}
PATH=${OBJ}/bin:$PATH
AVAILABLE_OPAM_VERSION=`opam --version 2>/dev/null || true`
AVAILABLE_OCAML_VERSION=`ocamlc -version 2>/dev/null || true`
FILE=opam-full-${OPAM_VERSION}.tar.gz
URL=https://github.com/ocaml/opam/releases/download/${OPAM_VERSION}/${FILE}
if [ "$OPAM_VERSION" = "$AVAILABLE_OPAM_VERSION" ]; then
echo OPAM $OPAM_VERSION is already available.
else
echo OPAM $OPAM_VERSION will be installed locally.
cd ${OBJ}
if [ ! -e ${FILE} ]; then
curl -OL ${URL}
fi
tar -zxf ${FILE}
cd opam-full-${OPAM_VERSION}
if [ "" != "$AVAILABLE_OCAML_VERSION" ]; then
# TODO: check whether available OCaml is new enough
echo OCaml $AVAILABLE_OCAML_VERSION is available to compile OPAM.
./configure --prefix=${OBJ}
make lib-ext
make
else
echo OCaml is not available, performing a local installation
make cold CONFIGURE_ARGS="--prefix=${OBJ}"
fi
make install
echo "export PATH=$OBJ/bin:\$PATH" >> ${ENV}
cd ${OBJ}
fi
export OPAMYES=1
export OPAMJOBS=2
. ${ENV}
if [ ! -d "${OPAMROOT}" ]; then
if [ "$OCAML_VERSION" = "$AVAILABLE_OCAML_VERSION" ]; then
opam init -n
else
opam init -n --comp=$OCAML_VERSION
fi
else
if [ "$OCAML_VERSION" != "$AVAILABLE_OCAML_VERSION" ]; then
echo Switching to OCaml $OCAML_VERSION
opam switch $OCAML_VERSION
fi
fi
echo "eval \`opam config env\`" >> ${ENV}
. ${ENV}
AVAILABLE_OPAM_VERSION=`opam --version 2>/dev/null || true`
AVAILABLE_OCAML_VERSION=`ocamlc -version 2>/dev/null || true`
echo The build environment in ${OBJ} now has:
echo OPAM version $AVAILABLE_OPAM_VERSION
echo OCaml verion $AVAILABLE_OCAML_VERSION
echo To use the new environment, source the file:
echo ${OBJ}/opam-env.sh
if [ "" != "${BUILD}" ]; then
echo Attempting to build ${BUILD} using a local opam file
cd ${ORIGINAL_DIR}
opam pin add -k git ${BUILD} .
opam install ${BUILD} -y
fi