+AC_CHECK_PROG([HAVE_PERLDOC], perldoc, perldoc)
+AM_CONDITIONAL([HAVE_PERLDOC], [test "x$HAVE_PERLDOC" = "xperldoc"])
+
+dnl Check for recommended ocaml-gettext tool.
+AC_CHECK_PROG([OCAML_GETTEXT], ocaml-gettext, ocaml-gettext)
+AM_CONDITIONAL([HAVE_OCAML_GETTEXT],[test "x$OCAML_GETTEXT" = "xocaml-gettext"])
+
+dnl Check for GNU gettext tools (optional).
+AC_CHECK_PROG([XGETTEXT],[xgettext],[xgettext],[no])
+AC_CHECK_PROG([MSGCAT],[msgcat],[msgcat],[no])
+AC_CHECK_PROG([MSGFMT],[msgfmt],[msgfmt],[no])
+AC_CHECK_PROG([MSGMERGE],[msgmerge],[msgmerge],[no])
+
+dnl Check they are the GNU gettext tools.
+AC_MSG_CHECKING([msgfmt is GNU tool])
+if $MSGFMT --version >/dev/null 2>&1 && $MSGFMT --version | grep -q 'GNU gettext
+'; then
+ msgfmt_is_gnu=yes
+else
+ msgfmt_is_gnu=no
+fi
+AC_MSG_RESULT([$msgfmt_is_gnu])
+AM_CONDITIONAL([HAVE_GNU_GETTEXT],
+ [test "x$XGETTEXT" != "xno" && test "x$MSGCAT" != "xno" && test "x$MSGFMT" != "xno" && test "x$MSGMERGE" != "xno" && test "x$msgfmt_is_gnu" != "xno"])
+
+dnl Check for gettext.
+AM_GNU_GETTEXT([external])
+
+dnl Write gettext modules for the programs.
+dnl http://www.le-gall.net/sylvain+violaine/documentation/ocaml-gettext/html/reference-manual/ch03s04.html
+AC_MSG_NOTICE([creating src/opt_gettext.ml])
+rm -f src/opt_gettext.ml
+echo "(* This file is generated automatically by ./configure. *)" > src/opt_gettext.ml
+if test "x$OCAML_PKG_gettext" != "xno"; then
+ # Gettext module is available, so use it.
+ cat <<EOT >>src/opt_gettext.ml
+module Gettext = Gettext.Program (
+ struct
+ let textdomain = "virt-top"
+ let codeset = None
+ let dir = None
+ let dependencies = [[]]
+ end
+) (GettextStub.Native)
+EOT
+else
+ # No gettext module is available, so fake the translation functions.
+ cat <<EOT >>src/opt_gettext.ml
+module Gettext = struct
+ external s_ : string -> string = "%identity"
+ external f_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format
+ = "%identity"
+ let sn_ : string -> string -> int -> string
+ = fun s p n -> if n = 1 then s else p
+ let fn_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format -> int
+ -> ('a -> 'b, 'c, 'd) format
+ = fun s p n -> if n = 1 then s else p
+end
+EOT
+fi