Skip to content
This repository
tag: v1813
Fetching contributors…

Cannot retrieve contributors at this time

executable file 588 lines (551 sloc) 22.221 kb
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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
#!/usr/bin/env bash

set -u
set -e

SCRIPTDIR=$(dirname $0)
cd $SCRIPTDIR
SCRIPTDIR=$PWD

SCRIPTNAME=$(basename $0)

# OS independent various variables
# Warning: only put in DEFAULT_PACKAGES what should be included in our binary package
DEFAULT_PACKAGES=(ocaml findlib cryptokit camlzip ocamlgraph ulex ocaml-ssl)
ALL_PACKAGES=(ocaml findlib cryptokit camlzip ocamlgraph ulex openssl ocaml-ssl syslog jpeg libpng giflib camlimages mascot camlidl libnatpmp miniupnpc cairo-ocaml)

BUILD_DIR=$SCRIPTDIR/packages

# ##
# Bash setting and useful functions
# #####
shopt -s nullglob
msg_green () { echo "$@"; }
msg_red () { echo "$@"; }
msg_yellow () { echo "$@"; }
help () {
    cat <<EOF

installation_helper.sh
helps download, patch, build and install the dependencies of OPA.

Usage:
$0 --prefix <dir> [options] [commands]

Options:
--prefix <dir> where ocaml and libs should expect to be installed (mandatory)
--installdir <dir> where to actually do the install (by default, the value of --prefix)
--packages 'pkg list' only install the specified packages
--sudo sudo before installation commands (see disclaimer)

Commands: (default choice underlined)
fetch download the archives for the packages to
$BUILD_DIR
unzip uncompress and patch the archives
install build and install the packages
lightclean make clean in all packages' directories
clean remove all contents of the work directory

Available packages: (default choice underlined)
$(for i in ${!ALL_PACKAGES[@]}; do
if grep -q "\(^\| \)${ALL_PACKAGES[i]}\( \|$\)" <<<${DEFAULT_PACKAGES[*]}
then printf "%-18s" "${ALL_PACKAGES[i]}"
else printf "%-10s" "${ALL_PACKAGES[i]}"
fi
[ $((i%6)) -eq 5 ] && echo -ne "\n\t" || echo -ne ' '
done)

Note:
All ocaml libs are compiled with and for the ocaml in the
given prefix. Therefore, ocaml should either be already there,
or you should include it first in your --packages. Also, some
packages depend on findlib to compile correctly.

Examples:
- Install all dependencies of opa to /opt/opa:
$ $0 --prefix /opt/opa --sudo
then, pass option -ocamlopt /opt/opa/bin/ocamlopt.opt to
opalang's ./configure script

- Install all dependencies in your home, when you don't have
administration rights:
$ $0 --prefix ~/opa
then, pass option -ocamlopt ~/opa/bin/ocamlopt.opt to
opalang's ./configure script

Disclaimer:
This script is provided because we think it may be useful, but
is provided WITHOUT SUPPORT, and you should know what you are
doing, especially if you want to install to a privileged
prefix like /usr/local. Using this script to install in /usr
would be a bad idea.

EOF
}

source ../platform_helper.sh

WINTOOLS=${WINTOOLS:-}
WINOCAMLC=$WINTOOLS/windows_ocamlc
WINOCAMLOPT=$WINTOOLS/windows_ocamlopt
WINOCAMLDEP=$WINTOOLS/windows_ocamldep
WINOCAMLMKLIB=$WINTOOLS/windows_ocamlmklib
WINOCAMLLEX=$WINTOOLS/windows_ocamllex

if [ -n "${ENFORCE_WINDOWS:-}" ];
then
    msg_yellow "ENFORCE WINDOWS -> ocaml windows scripts"
    export OCAMLC=$WINOCAMLC
    export OCAMLOPT=$WINOCAMLOPT
    export OCAMLDEP=$WINOCAMLDEP
    export OCAMLMKLIB=$WINOCAMLMKLIB
    export OCAMLLEX=$WINOCAMLLEX
    export CAMLP4=camlp4
else
    OCAMLC=ocamlc.opt
    OCAMLOPT=ocamlopt.opt
    OCAMLDEP=ocamldep.opt
    OCAMLMKLIB=ocamlmklib
    CAMLP4=camlp4
fi


PREFIX=
SUDO=
CLEAN=
FETCH=
UNZIP=
INSTALL=
LIGHTCLEAN=
while [ $# -gt 0 ]; do
    case $1 in
        --help) help; exit 0;;
        --prefix)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
PREFIX="$1"
            : ${INSTALLDIR:=$PREFIX}
            ;;
        --packages)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
PACKAGES=($1)
            ;;
        --installdir)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
INSTALLDIR="$1"
            ;;
        --sudo)
            SUDO="sudo"
            ;;
        lightclean) LIGHTCLEAN=1;;
        clean) CLEAN=1;;
        fetch) FETCH=1;;
        install) INSTALL=1;;
        unzip) UNZIP=1;;
        *)
            echo "Error: unknown argument $1"; exit 1
    esac
    shift
done

PACKAGES=("${PACKAGES[@]:-${DEFAULT_PACKAGES[@]}}")

if [ -z "$CLEAN" ] && [ -z "$FETCH" ] && [ -z "$UNZIP" ] && [ -z "$INSTALL" ] && [ -z "$LIGHTCLEAN" ]; then
    FETCH=1
    UNZIP=1
    INSTALL=1
fi
if [ -z "$PREFIX" ] && [ -n "$INSTALL" ]; then
    help
echo "Error: you must specify the installation prefix" >&2
    exit 1
fi

#FETCH=""
#CLEAN=""
#UNZIP=""

BUILD_DIR=$PWD/packages
mkdir -p $BUILD_DIR

sources () {
    case $1 in
        openssl) echo "http://www.openssl.org/source/openssl-1.0.0a.tar.gz";;
        ocaml) echo "http://caml.inria.fr/pub/distrib/ocaml-3.12/ocaml-3.12.0.tar.gz" ;;
        # Sources obtained thanks to "apt-get --print-uris source <package>"
        findlib) echo "http://download.camlcity.org/download/findlib-1.2.5.tar.gz";;
        ocaml-ssl) echo "http://downloads.sourceforge.net/project/savonet/ocaml-ssl/0.4.5/ocaml-ssl-0.4.5.tar.gz";;
        cryptokit) echo "http://forge.ocamlcore.org/frs/download.php/639/cryptokit-1.5.tar.gz";;
        ocamlgraph) echo "http://ocamlgraph.lri.fr/download/ocamlgraph-1.5.tar.gz";;
        camlzip) echo "http://forge.ocamlcore.org/frs/download.php/328/camlzip-1.04.tar.gz";;
        camlimages) echo "http://caml.inria.fr/distrib/bazar-ocaml/camlimages-3.0.2.tgz";;
        ulex) echo "http://ftp.de.debian.org/debian/pool/main/u/ulex/ulex_1.1.orig.tar.gz";;
        syslog) echo "http://homepage.mac.com/letaris/syslog-1.4.tar.gz";;
        jpeg) echo "http://www.ijg.org/files/jpegsrc.v8b.tar.gz";;
        libpng) echo "http://sourceforge.net/projects/libpng/files/libpng14/older-releases/1.4.3/libpng-1.4.3.tar.gz";;
        giflib) echo "http://downloads.sourceforge.net/project/giflib/giflib%204.x/giflib-4.1.6/giflib-4.1.6.tar.gz";;
        mascot) echo "http://mascot.x9c.fr/distrib/mascot-1.0-alpha.tar.gz";;
        camlidl) echo "http://caml.inria.fr/pub/old_caml_site/distrib/bazar-ocaml/camlidl-1.05.tar.gz";;
        libnatpmp) echo "http://miniupnp.free.fr/files/download.php?file=libnatpmp-20110103.tar.gz";;
        miniupnpc) echo "http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.5.20110418.tar.gz";;
        cairo-ocaml) echo "http://cgit.freedesktop.org/cairo-ocaml/snapshot/cairo-ocaml-1.2.0.tar.gz";;
        *) msg_red "Error: don't know about package $1" >&2; exit 2
    esac
}

package_dir () {
    local p=$1
    local dir=$(find . -maxdepth 1 -type d -name "$p-[0-9]*")
    local dir="$dir "$(find . -maxdepth 1 -type d -name "$p-master")
    echo $dir | (read a b; if [ -n "$b" ]; then
            msg_red "Error: found several source directories for $p"
            exit 12
            fi)
    echo $dir
}

install_generic () {
    if [ "$(which $OCAMLC)" != "$INSTALLDIR/bin/$OCAMLC" ]; then
        echo $OCAMLC x $PATH
        msg_red "Error: fresh installed ocaml not found ($(which $OCAMLC) is not $INSTALLDIR/bin/$OCAMLC)"
        exit 1
    fi
    if [ "$($OCAMLC -where)" != "$INSTALLDIR/lib/ocaml" ]; then
        msg_red "Error: fresh installed ocaml not found (ocamlc -where returned $($OCAMLC -where) instead of $INSTALLDIR/lib/ocaml"
        exit 1
    fi
    # Packages install themselves in $(ocamlc -where) automatically
    if [ -x configure ]; then ./configure "$@"; fi
    make all; r=$?
    make allopt || make opt || make all.opt || [ $r -eq 0 ]
    $SUDO make install-opt || $SUDO make install
}

package_install (){
    if [ -n "${ENFORCE_WINDOWS:-}" ];
    then
echo "INSTALLSYS WINDOWS"
        WINPREFIX=`cygpath -u $PREFIX`
        WINCAMLLIBDIR="$WINPREFIX/lib"
        OLDPATH=$PATH
        export PATH=/cygdrive/c/ocamlms/bin/:$PATH
        case $1 in
            ocaml)
# caml_sed_patch
          # PREFIX is hard coded as C:/ocamlms
                cp config/m-nt.h config/m.h
                cp config/s-nt.h config/s.h
                cp config/Makefile.msvc config/Makefile
                make -f Makefile.nt clean
# rm -rf otherlibs/labltk/
                make -f Makefile.nt world
# make -f Makefile.nt bootstrap
# make -f Makefile.nt clean
# make -f Makefile.nt world
                make -f Makefile.nt opt opt.opt
                make -f Makefile.nt install
          #missing ocamlrun.lib => replaced by libcamlrun.lib
                export PATH=$WINPREFIX/bin:${PATH}
                export OCAMLLIB=$WINCAMLLIBDIR
                export OCAMLC=$WINOCAMLC
                export OCAMLOPT=$WINOCAMLOPT
                export OCAMLDEP=$WINOCAMLDEP
                export OCAMLMKLIB=$WINOCAMLMKLIB
                export OCAMLLEX=$WINOCAMLLEX
                export CAMLP4=camlp4
                ;;
            findlib)
          #valid
                ./configure -sitelib $PREFIX/lib
                make all opt install clean
                ;;
            camlzip)
          #valid
          # library is call camlzip instead of zip
                CAMLLIBDIR=$WINCAMLLIBDIR ZLIB_LIBDIR=/windows_libs/zlib ZLIB_INCLUDE=$PWD/../../../ms_windows/zlib make -f Makefile.nt clean all allopt install
                CAMLLIBDIR=$WINCAMLLIBDIR ZLIB_LIBDIR=/windows_libs/zlib ZLIB_INCLUDE=$PWD/../../../ms_windows/zlib make -f Makefile.nt installopt || true
install -m 0644 -v zlib.cm* $WINCAMLLIBDIR/zip
                ;;
            ocamlgraph)
                ./configure --prefix $WINPREFIX # should pass all var to have cross compilation
                make -f Makefile.nt clean
          # let the time do its job :) do not merge the two or prepare to a headache
                make -f Makefile.nt byte opt install-byte install-opt
                ;;
            cryptokit)
                make -f Makefile.win32 all allopt
                make -f Makefile.win32 install
                ;;
            ocaml-ssl)
                #valid but ugly
                # just for generating the META file and Makefile
                # ,does not work with PATH because of cl.exe problems with libs
                PATH=$OLDPATH ./configure
                export OCAMLMKLIB="$OCAMLMKLIB -LC:/cygwin/windows_libs/openssl/lib"
                   # seems horrible ? simpler than patching everything
                make -e byte || true
make -e opt || true
make -e install || true
cp src/*.lib $PREFIX/lib/ssl # because ocamlfind ignores .lib files
                ;;
            camlidl)
                sed -ie "s%^OCAMLLIB=.*%OCAMLLIB=$WINPREFIX/lib/ocaml%; s%^BINDIR=.*%BINDIR=$WINPREFIX/bin%" \
                    config/Makefile.win32 > config/Makefile
                make all
                make install
                ;;
            libnatpmp)
                make -f Makefile.windows all
                TMPP=$PREFIX/lib/libnatpmp
                mkdir -p $TMPP
                cp libnatpmp.a $TMPP
                TMPP=$PREFIX/include/libnatpmp
                mkdir -p $TMPP
                cp *.h $TMPP
                ;;
            miniupnpc)
                INSTALLPREFIX=$PREFIX make -f Makefile.windows all
                TMPP=$PREFIX/lib/miniupnpc
                mkdir -p $TMPP
                cp libminiupnpc.a $TMPP
                TMPP=$PREFIX/include/miniupnpc
                mkdir -p $TMPP
                cp *.h $TMPP
                ;;
            ulex)
                rm -f myocamlbuild.ml
                install_generic
                ;;
            cairo-ocaml)
                aclocal -I support
                autoconf
                ./configure --prefix $PREFIX --without-gtk --without-libsvg_cairo --without-libpangocairo
                make
                make install
                ;;
            *)
                msg_yellow "Install $1 by hand"
                msg_yellow "TODO : check $1 installation"
                exit 1
                ;;
        esac
    else
        case $1 in
            ocaml)
                [ $IS_WINDOWS ] && CYGOPT="-tk-no-x11 -no-tk"
                ./configure -prefix $PREFIX ${CYGOPT:-}
                make world # clean world
                make bootstrap
                if [ $IS_LINUX ] || [ $IS_MAC ] || [ $IS_FREEBSD ]; then
                    make opt && make opt.opt
                fi
                PREFIX=$INSTALLDIR $SUDO make install -e
                ;;
            camlzip)
                make all allopt
                $SUDO make install installopt
                $SUDO install -m 0644 -v zlib.cm* $($OCAMLC -where)/zip
                ;;
            ocaml-ssl)
                $SUDO $INSTALLDIR/bin/ocamlfind remove -destdir $INSTALLDIR/lib/ocaml ssl || true
install_generic
                ;;
cryptokit)
# very ugly way to uninstall previous cryptokit...
msg_yellow "Uninstalling potential previous cryptokit (moving it..)"
$SUDO mkdir -pv $INSTALLDIR/lib/ocaml/cryptokit.bak
$SUDO mv -v $INSTALLDIR/lib/ocaml/cryptokit.* $INSTALLDIR/lib/ocaml/cryptokit.bak/ || true
$SUDO mv -v $INSTALLDIR/lib/ocaml/stublibs/dllcryptokit.so $INSTALLDIR/lib/ocaml/stublibs/dllcryptokit.so.bak || true
ocaml setup.ml -configure
ocaml setup.ml -build
$SUDO ocaml setup.ml -uninstall
$SUDO ocaml setup.ml -install
;;
            findlib)
                install_generic -sitelib $INSTALLDIR/lib/ocaml
                ;;
            camlimages)
                touch src/oXpm.cmi || true # camlimages wants that even if we tell him not...
                ./configure --with-ocamlfind=no --enable-native-library --enable-bytecode-library --with-jpeg --with-png --with-gif --without-lablgtk --without-lablgtk2 --without-freetype --without-xpm --without-tiff --without-x --without-gs --prefix $INSTALLDIR \
                    CFLAGS=-I$INSTALLDIR/include LDFLAGS=-L$INSTALLDIR/lib
                make
                $SUDO make install
                ;;
            ulex)
                $SUDO $INSTALLDIR/bin/ocamlfind remove -destdir $INSTALLDIR/lib/ocaml ulex || true
rm -f myocamlbuild.ml
                make all.opt
                # the following is copy pasted from ulex's Makefile
                # because install depends on all (it just does't work
                # when your rights for compiling and installing are not compatible)
                cd _build && $SUDO make -f ../Makefile realinstall
                ;;
            jpeg)
                ./configure --prefix $PREFIX
                make
                $SUDO make install
                ;;
            libpng)
                ./configure --prefix $PREFIX
                make
                $SUDO make install
                ;;
            giflib)
                ./configure --prefix $PREFIX
                make
                $SUDO make install
                ;;
            mascot)
                sh configure -ocaml-prefix $INSTALLDIR
                $SUDO make all install -e
                ;;
            camlidl)
                sed -e "s%^OCAMLLIB=.*%OCAMLLIB=$INSTALLDIR/lib/ocaml%; s%^BINDIR=.*%BINDIR=$INSTALLDIR/bin%" \
                    config/Makefile.unix > config/Makefile
                make -e all
                $SUDO make -e install
                ;;
            libnatpmp)
                make -e
                # custom installation
                LIBDIR=$INSTALLDIR/lib/ocaml
                $SUDO mkdir -p $LIBDIR
                $SUDO cp libnatpmp.a $LIBDIR
                INCLUDE=$INSTALLDIR/include/libnatpmp
                $SUDO mkdir -p $INCLUDE
                $SUDO cp *.h $INCLUDE
                ;;
            miniupnpc)
                INSTALLPREFIX=$INSTALLDIR make -e
                LIBDIR=$INSTALLDIR/lib/ocaml
                $SUDO mkdir -p $LIBDIR
                $SUDO cp libminiupnpc.a $LIBDIR
                INCLUDE=$INSTALLDIR/include/miniupnpc
                $SUDO mkdir -p $INCLUDE
                $SUDO cp *.h $INCLUDE
                ;;
            cairo-ocaml)
                aclocal -I support
                autoconf
                ./configure --prefix $PREFIX --without-gtk --without-libsvg_cairo --without-libpangocairo
                make
                $SUDO make install
                ;;
            *)
                install_generic
        esac
    fi
}

if [ -n "$CLEAN" ]; then
    msg_yellow "$SCRIPTNAME: Cleaning source"
    for p in "${PACKAGES[@]}"; do
        msg_green "[ PACKAGE: $p (clean-up) ]"
        dir=$(package_dir $p)
        rm -rf $BUILD_DIR/$dir
    done
    msg_green "Remove building directory $BUILD_DIR"
    rm -fr $BUILD_DIR/*
fi

if [ -n "$LIGHTCLEAN" ]; then
    msg_yellow "Cleaning packages configurations"
    cd $BUILD_DIR/
    for p in "${PACKAGES[@]}"; do
        dir=$(package_dir $p)
        if [ -z $dir ]; then
            msg_green "[ PACKAGE: $p (skip clean) ]"
        else
            msg_green "[ PACKAGE: $p (make clean) ]"
            echo "dir: $dir"
            cd $dir
            make clean
            cd -
        fi
    done
    msg_green "make general configuration clean done."
    cd $SCRIPTDIR
fi

if [ -n "$FETCH" ]; then
    msg_green "$SCRIPTNAME: Downloading packages"
    cd $BUILD_DIR
    for p in "${PACKAGES[@]}"; do
        msg_green "[ PACKAGE: $p (download) ]"
        src=$(sources $p)
        wget -N "$src"
        ## some lib are downloaded via a php script, we need to clean the string from 'source' a little
        tgz0=$(basename "$src")
        tgz=${tgz0#download.php\?file=}
        [ "$tgz0" != "$tgz" ] && [ -f "$tgz0" ] && mv "$tgz0" "$tgz"
        ## remove existing extracted directories
        packfile=$(tar -tzf $tgz 2>/dev/null | head -n 1)
        packdir=$(pwd)/${packfile%%/*}
        rm -rf $BUILD_DIR/${packdir#$BUILD_DIR}
    done
    cd $SCRIPTDIR
fi

if [ -n "$UNZIP" ]; then
    msg_green "$SCRIPTNAME: Uncompressing & patching"
    cd $BUILD_DIR
    for p in "${PACKAGES[@]}"; do
        msg_green "[ PACKAGE: $p (uncompressing) ]"
        echo "Uncompressing..."
        ## retrieve the file name
        tgz=$(basename "$(sources $p)")
        tgz=${tgz#download.php\?file=}
        ## uncompress
        tar -xzf $tgz
        ## patch
        packdir=$(pwd)/$(package_dir $p)
        cd $packdir
        if [ $IS_WINDOWS ]; then
            for df in $SCRIPTDIR/patches/${p}_*.patch.windows; do
                echo "Applying patch $df from $packdir"
                patch -Np1 < $df || (msg_red "Error: patch $df did not apply"; exit 3)
            done
        fi
        for df in $SCRIPTDIR/patches/${p}_*.patch; do
            echo "Applying patch $df from $packdir"
            patch -Np1 < $df || (msg_red "Error: patch $df did not apply"; exit 3)
        done
        echo "Uncompressed $SCRIPTNAME to $packdir"
        cd $BUILD_DIR
    done
    cd $SCRIPTDIR
fi

setup_local_ocaml () {
    #
    # Here we attempt to relocate ocaml, which is not an easy task. Beware the hacks.
    # (no $SUDO here, relocation is not supposed to be needed if we are already
    # installing to a privileged place)
    if [ -d $INSTALLDIR/lib/ocaml ] && [ "$PREFIX" != "$INSTALLDIR" ]; then
        # Update ld.conf for the temporary location
        # (this is reverted last thing in this script)
        HAS_PATCHED_OCAML_LD_CONF=1
        sed -i "s%^$PREFIX%$INSTALLDIR%" $INSTALLDIR/lib/ocaml/ld.conf
        # The following are not needed in our binary package, so we
        # don't care about reverting the changes (we clean them up
        # before making the package)
        #
        # The bytecode exes refer to an interpreter that is not installed (<prefix>/bin/ocamlrun).
        sed -i '1s%#!'$PREFIX'/bin/ocamlrun%#!'$INSTALLDIR'/bin/ocamlrun%' $INSTALLDIR/bin/*
        # ocamlmklib doesn't play nice, we wrap them to add options
        if [ ! -e $INSTALLDIR/bin/ocamlmklib-bin ]; then
            mv $INSTALLDIR/bin/ocamlmklib $INSTALLDIR/bin/ocamlmklib-bin
            echo -e '#!/bin/sh\nexec '$INSTALLDIR/bin/ocamlmklib-bin' -ocamlc '$INSTALLDIR/bin/ocamlc' -ocamlopt '$INSTALLDIR/bin/ocamlopt' "$@"' >$INSTALLDIR/bin/ocamlmklib
            chmod a+x $INSTALLDIR/bin/ocamlmklib
        fi
        # camlp4 needs a shared library (dllunix, what for ??) that
        # isn't yet in normal library search paths
        for f in $INSTALLDIR/bin/camlp4*; do
            if [ $f = ${f%.opt} ] && [ ! -e $f-bin ]; then
                mv $f $f-bin
                echo -e '#!/bin/sh\nLD_LIBRARY_PATH='$INSTALLDIR/lib/ocaml/stublibs':$LD_LIBRARY_PATH exec '$f-bin' "$@"' >$f
                chmod a+x $f
            fi
        done
    fi
    msg_yellow "Extending path to find the proper ocaml (at $INSTALLDIR/bin)"
    export PATH=$INSTALLDIR/bin:$PATH
    # export LD_LIBRARY_PATH=$INSTALLDIR/lib/ocaml:$INSTALLDIR/lib/ocaml/stublibs/$LD_LIBRARY_PATH
    msg_yellow "Setting OCAMLLIB to the proper location ($INSTALLDIR/lib/ocaml)"
    export OCAMLLIB=$INSTALLDIR/lib/ocaml
    export OCAMLOPT=$INSTALLDIR/bin/ocamlopt.opt
    export OCAMLFIND_INSTFLAGS="-destdir $INSTALLDIR/lib/ocaml"
}

if [ -n "$INSTALL" ]; then
    msg_green "$SCRIPTNAME: Building & install"
    for i in ${!PACKAGES[@]}; do
        if [ -z "${setup_done:-}" ] && ! grep -q "\(^\| \)ocaml\( \|$\)" <<<${PACKAGES[*]:$i}; then
            setup_local_ocaml
            setup_done=1
        fi
        p="${PACKAGES[$i]}"
        cd $BUILD_DIR
        msg_yellow "entering build directory $BUILD_DIR"
        msg_green "[ PACKAGE: $p (building and installing) ]"
        dir=$(package_dir $p)
        echo "Directory: $dir"
        cd $dir
        echo "Package: $p"
        package_install $p
        cd $SCRIPTDIR
        msg_yellow "leaving build directory"
    done
fi

if [ -n "${HAS_PATCHED_OCAML_LD_CONF:-}" ]; then
    msg_yellow "Reverting temporary modification of ocaml's ld.conf used for building the libs"
    sed -i "s%^$INSTALLDIR%$PREFIX%" $INSTALLDIR/lib/ocaml/ld.conf
fi

msg_green "$SCRIPTNAME: done"
Something went wrong with that request. Please try again.