#!/bin/sh -e

OS=${OS:-unix}
OCAMLBUILD=ocamlbuild

case "${OS}" in
xen) EXTRA_PKG="-pkg mirage-console.xen";;
esac

ocamlbuild -use-ocamlfind $EXTRA_PKG \
  -syntax camlp4o \
  -pkg cstruct \
  -pkg cstruct.lwt \
  -pkg lwt \
  -pkg lwt.unix \
  -pkg lwt.syntax \
  -pkg mirage-types \
  ${OS}/mirage-entropy.cma ${OS}/mirage-entropy.cmxa ${OS}/mirage-entropy.cmxs

B=_build/${OS}
if [ "$1" = "true" ]; then
  ocamlfind remove mirage-entropy-${OS} || true
  ocamlfind install mirage-entropy-${OS} ${OS}/META \
    $B/entropy_${OS}.cmo $B/entropy_${OS}.cmi $B/mirage-entropy.cma \
    $B/mirage-entropy.a $B/entropy_${OS}.cmx $B/mirage-entropy.cmxa $B/mirage-entropy.cmxs
fi
