opam_config.sh 1.87 KB
Newer Older
1 2
#!/bin/sh

3 4
# Do not change these variables directly. Use options to modify the behavior of
# the script (see usage).
5 6 7
VERBOSE="false"
WITHOCAML="false"
OCAMLFOLDER="ocaml"
8
PACKAGES="pcre-ocaml ocamlnet pxp ocurl ocaml-expat ocamlsdl ounit"
9 10 11

usage ()
{
Julien Lopez's avatar
Julien Lopez committed
12 13 14
    echo "Usage: $0 [OPTION]... [MLVERSION]"
    echo "Configures opam for the compilation of CDuce."
    echo "Switches the OCaml version of opam if MLVERSION is provided."
15
    echo "Example: $0 --verbose --mliface=ocaml 4.01.0"
Julien Lopez's avatar
Julien Lopez committed
16
    echo "Valid options are:"
17 18 19
    echo -e "\t-v, --verbose\tactivate verbose mode"
    echo -e "\t--mliface=DIR\tcheckout the OCaml sources in DIR to MLVERSION"
    echo -e "\t-h, --help\tdisplay this help and exit"
20 21
}

22 23
# Parse options

24
while test $# -ge 1; do
25
    if test $1 = "-v" || test $1 = "--verbose"; then VERBOSE="true";
Julien Lopez's avatar
Julien Lopez committed
26
    elif echo $1 | grep -qse "--mliface=.*"; then
27
	WITHOCAML="true"; OCAMLFOLDER=`echo $1 | cut -d '=' -f 2`;
Julien Lopez's avatar
Julien Lopez committed
28 29
    elif test $1 = "-h" || test $1 = "--help"; then usage; exit 0;
    elif echo $1 | grep -qse "-.*"; then usage; exit 1;
30 31 32 33
    else break; fi;
    shift;
done

34 35
# Switching opam's version of OCaml

Julien Lopez's avatar
Julien Lopez committed
36
if test $# -ge 1; then
37

Julien Lopez's avatar
Julien Lopez committed
38
    echo -n "Switching to version $1 of OCaml..."
39 40
    opam switch $1 > /dev/null 2>&1

Julien Lopez's avatar
Julien Lopez committed
41 42 43
    if test $? -ne 0; then
	echo "failed. This version doesn't seem to exist."; exit 2;
    fi
44

Julien Lopez's avatar
Julien Lopez committed
45
    echo "done."
46

Julien Lopez's avatar
Julien Lopez committed
47 48
    echo "# To complete the configuration of OPAM, you need to run:"
    echo "eval \`opam config env\`"
49 50
fi

51 52
# Installing packages

53
echo "Installing mandatory packages to compile CDuce."
54 55 56
for i in $PACKAGES; do opam install $i; done

# Checkout git repository of OCaml sources to appropriate version.
57

58
if test $WITHOCAML = "true" && test $# -ge 1; then
59
    if test -d $OCAMLFOLDER; then
Julien Lopez's avatar
Julien Lopez committed
60 61
	cd $OCAMLFOLDER; git checkout $1 > /dev/null 2>&1
	echo "OCaml sources updated to version $1."
62 63 64 65
    else
	echo "Couldn't find $OCAMLFOLDER. The interface will not be built."
    fi
fi