AC_INIT(heptagon,1.0)

AC_PROG_INSTALL

AC_PROG_MAKE_SET

AC_ARG_ENABLE(simulator,
    [  --enable-simulator      enable the graphical simulator],,
    enable_simulator=yes)

AC_ARG_ENABLE(local_stdlib,
    [  --enable-local-stdlib   use the in-sources standard library],,
    enable_local_stdlib=no)

AC_ARG_ENABLE(ctrl2ept,
    [  --enable-ctrl2ept       enable the Controllable-Nbac entity translator],,
    enable_ctrl2ept=yes)

AC_ARG_ENABLE(native,
    [  --enable-native         build native executables],,
    enable_native=no)

AC_ARG_ENABLE(byte,
    [  --enable-byte           build bytecode executables],,
    enable_byte=no)

AC_PROG_OCAML
if test "$OCAMLC" = "no"; then
  AC_MSG_ERROR([Please install the OCaml compiler])
fi

case "$OCAMLVERSION" in
  0.*|1.*|2.*|3.*)
     AC_MSG_ERROR(You need Objective Caml 4.00 or higher);;
esac

AC_PROG_CAMLP4
if test "$CAMLP4OF" = "no"; then
  AC_MSG_ERROR([Please install Camlp4 with extensions (camlp4of command)])
fi

AC_PROG_FINDLIB
if test "$OCAMLFIND" = "no"; then
  AC_MSG_ERROR([Please install OCaml findlib (the ocamlfind command)])
fi

OCAMLC_STDLIB=`$OCAMLFIND ocamlc -where`
OCAMLFIND_STDLIB=`$OCAMLFIND printconf stdlib`
if test "$OCAMLC_STDLIB" != "$OCAMLFIND_STDLIB"; then
  AC_MSG_ERROR([OCaml and OCamlfind make different assumptions about the standard library directory])
fi

AC_CHECK_PROG(MENHIR,menhir,menhir,no)
if test "$MENHIR" = no ; then
    AC_MSG_ERROR(Please install menhir.)
fi

AC_CHECK_OCAML_PKG([menhirLib])
 if test "$OCAML_PKG_menhirLib" = "no"; then
   AC_MSG_ERROR([Please install menhirLib package.])
 fi

AC_CHECK_OCAML_PKG([ocamlgraph])
 if test "$OCAML_PKG_ocamlgraph" = "no"; then
   AC_MSG_ERROR([Please install ocamlgraph package.])
 fi

AC_CHECK_OCAML_PKG([lablgtk2])
 if test "$OCAML_PKG_lablgtk2" = "no"; then
    enable_simulator=no
    AC_MSG_WARN([Could not find 'lablgtk2'. The simulator will not be built])
 fi

dnl version should be >= 0.14
AC_CHECK_OCAML_PKG([reatk.ctrlNbac])
 if test "${OCAML_PKG_reatk_ctrlNbac}" = "no"; then
   package_reatk_ctrlNbac="ocaml"; #dummy flag
   ctrln_pp="-UENABLE_CTRLN"
   enable_ctrl2ept=no
   AC_MSG_WARN([Controllable-Nbac backend and translators disabled.])
 else
   package_reatk_ctrlNbac="package(reatk.ctrlNbac)"
   ctrln_pp="-DENABLE_CTRLN"
 fi

if test "$enable_local_stdlib" = "yes"; then
    stdlib_dir=$PWD/lib
else
    stdlib_dir=$libdir/heptagon
fi

if test "$enable_byte" = "yes"; then targets="byte"; fi;
if test "$enable_native" = "yes"; then targets="$targets native"; fi;
if test "x$targets" = "x"; then targets="byte"; fi;

AC_SUBST(INSTALL)
AC_SUBST(RM)
AC_SUBST(stdlib_dir)

AC_SUBST(enable_simulator)
AC_SUBST(enable_ctrl2ept)
AC_SUBST(targets)

AC_OUTPUT(config)

AC_SUBST(package_reatk_ctrlNbac)
AC_SUBST(ctrln_pp)
AC_OUTPUT(compiler/_tags)
