1 dnl autoconf macros for OCaml
3 dnl Copyright © 2009 Richard W.M. Jones
4 dnl Copyright © 2009 Stefano Zacchiroli
5 dnl Copyright © 2000-2005 Olivier Andrieu
6 dnl Copyright © 2000-2005 Jean-Christophe Filliâtre
7 dnl Copyright © 2000-2005 Georges Mariano
9 dnl For documentation, please read the ocaml.m4 man page.
11 AC_DEFUN([AC_PROG_OCAML],
14 AC_CHECK_TOOL([OCAMLC],[ocamlc],[no])
16 if test "$OCAMLC" != "no"; then
17 OCAMLVERSION=`$OCAMLC -v | sed -n -e 's|.*version* *\(.*\)$|\1|p'`
18 AC_MSG_RESULT([OCaml version is $OCAMLVERSION])
19 # If OCAMLLIB is set, use it
20 if test "$OCAMLLIB" = ""; then
21 OCAMLLIB=`$OCAMLC -where 2>/dev/null || $OCAMLC -v|tail -1|cut -d ' ' -f 4`
23 AC_MSG_RESULT([OCAMLLIB previously set; preserving it.])
25 AC_MSG_RESULT([OCaml library path is $OCAMLLIB])
27 AC_SUBST([OCAMLVERSION])
30 # checking for ocamlopt
31 AC_CHECK_TOOL([OCAMLOPT],[ocamlopt],[no])
33 if test "$OCAMLOPT" = "no"; then
34 AC_MSG_WARN([Cannot find ocamlopt; bytecode compilation only.])
36 TMPVERSION=`$OCAMLOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
37 if test "$TMPVERSION" != "$OCAMLVERSION" ; then
38 AC_MSG_RESULT([versions differs from ocamlc; ocamlopt discarded.])
47 # checking for ocamlc.opt
48 AC_CHECK_TOOL([OCAMLCDOTOPT],[ocamlc.opt],[no])
49 if test "$OCAMLCDOTOPT" != "no"; then
50 TMPVERSION=`$OCAMLCDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
51 if test "$TMPVERSION" != "$OCAMLVERSION" ; then
52 AC_MSG_RESULT([versions differs from ocamlc; ocamlc.opt discarded.])
58 # checking for ocamlopt.opt
59 if test "$OCAMLOPT" != "no" ; then
60 AC_CHECK_TOOL([OCAMLOPTDOTOPT],[ocamlopt.opt],[no])
61 if test "$OCAMLOPTDOTOPT" != "no"; then
62 TMPVERSION=`$OCAMLOPTDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
63 if test "$TMPVERSION" != "$OCAMLVERSION" ; then
64 AC_MSG_RESULT([version differs from ocamlc; ocamlopt.opt discarded.])
66 OCAMLOPT=$OCAMLOPTDOTOPT
76 # checking for ocaml toplevel
77 AC_CHECK_TOOL([OCAML],[ocaml],[no])
79 # checking for ocamldep
80 AC_CHECK_TOOL([OCAMLDEP],[ocamldep],[no])
82 # checking for ocamlmktop
83 AC_CHECK_TOOL([OCAMLMKTOP],[ocamlmktop],[no])
85 # checking for ocamlmklib
86 AC_CHECK_TOOL([OCAMLMKLIB],[ocamlmklib],[no])
88 # checking for ocamldoc
89 AC_CHECK_TOOL([OCAMLDOC],[ocamldoc],[no])
91 # checking for ocamlbuild
92 AC_CHECK_TOOL([OCAMLBUILD],[ocamlbuild],[no])
96 AC_DEFUN([AC_PROG_OCAMLLEX],
98 # checking for ocamllex
99 AC_CHECK_TOOL([OCAMLLEX],[ocamllex],[no])
100 if test "$OCAMLLEX" != "no"; then
101 AC_CHECK_TOOL([OCAMLLEXDOTOPT],[ocamllex.opt],[no])
102 if test "$OCAMLLEXDOTOPT" != "no"; then
103 OCAMLLEX=$OCAMLLEXDOTOPT
109 AC_DEFUN([AC_PROG_OCAMLYACC],
111 AC_CHECK_TOOL([OCAMLYACC],[ocamlyacc],[no])
112 AC_SUBST([OCAMLYACC])
116 AC_DEFUN([AC_PROG_CAMLP4],
118 AC_REQUIRE([AC_PROG_OCAML])dnl
120 # checking for camlp4
121 AC_CHECK_TOOL([CAMLP4],[camlp4],[no])
122 if test "$CAMLP4" != "no"; then
123 TMPVERSION=`$CAMLP4 -v 2>&1| sed -n -e 's|.*version *\(.*\)$|\1|p'`
124 if test "$TMPVERSION" != "$OCAMLVERSION" ; then
125 AC_MSG_RESULT([versions differs from ocamlc])
131 # checking for companion tools
132 AC_CHECK_TOOL([CAMLP4BOOT],[camlp4boot],[no])
133 AC_CHECK_TOOL([CAMLP4O],[camlp4o],[no])
134 AC_CHECK_TOOL([CAMLP4OF],[camlp4of],[no])
135 AC_CHECK_TOOL([CAMLP4OOF],[camlp4oof],[no])
136 AC_CHECK_TOOL([CAMLP4ORF],[camlp4orf],[no])
137 AC_CHECK_TOOL([CAMLP4PROF],[camlp4prof],[no])
138 AC_CHECK_TOOL([CAMLP4R],[camlp4r],[no])
139 AC_CHECK_TOOL([CAMLP4RF],[camlp4rf],[no])
140 AC_SUBST([CAMLP4BOOT])
143 AC_SUBST([CAMLP4OOF])
144 AC_SUBST([CAMLP4ORF])
145 AC_SUBST([CAMLP4PROF])
151 AC_DEFUN([AC_PROG_FINDLIB],
153 AC_REQUIRE([AC_PROG_OCAML])dnl
155 # checking for ocamlfind
156 AC_CHECK_TOOL([OCAMLFIND],[ocamlfind],[no])
157 AC_SUBST([OCAMLFIND])
161 dnl Thanks to Jim Meyering for working this next bit out for us.
162 dnl XXX We should define AS_TR_SH if it's not defined already
163 dnl (eg. for old autoconf).
164 AC_DEFUN([AC_CHECK_OCAML_PKG],
166 AC_REQUIRE([AC_PROG_FINDLIB])dnl
168 AC_MSG_CHECKING([for OCaml findlib package $1])
173 for pkg in $1 $2 ; do
174 if $OCAMLFIND query $pkg >/dev/null 2>/dev/null; then
175 AC_MSG_RESULT([found])
176 AS_TR_SH([OCAML_PKG_$1])=$pkg
181 if test "$found" = "no" ; then
182 AC_MSG_RESULT([not found])
183 AS_TR_SH([OCAML_PKG_$1])=no
186 AC_SUBST(AS_TR_SH([OCAML_PKG_$1]))
190 AC_DEFUN([AC_CHECK_OCAML_MODULE],
192 AC_MSG_CHECKING([for OCaml module $2])
194 cat > conftest.ml <<EOF
198 for $1 in $$1 $4 ; do
199 if $OCAMLC -c -I "$$1" conftest.ml >&5 2>&5 ; then
205 if test "$found" ; then
208 AC_MSG_RESULT([not found])
215 dnl XXX Cross-compiling
216 AC_DEFUN([AC_CHECK_OCAML_WORD_SIZE],
218 AC_REQUIRE([AC_PROG_OCAML])dnl
219 AC_MSG_CHECKING([for OCaml compiler word size])
220 cat > conftest.ml <<EOF
221 print_endline (string_of_int Sys.word_size)
223 OCAML_WORD_SIZE=`$OCAML conftest.ml`
224 AC_MSG_RESULT([$OCAML_WORD_SIZE])
225 AC_SUBST([OCAML_WORD_SIZE])
228 AC_DEFUN([AC_CHECK_OCAML_OS_TYPE],
230 AC_REQUIRE([AC_PROG_OCAML])dnl
231 AC_MSG_CHECKING([OCaml Sys.os_type])
233 cat > conftest.ml <<EOF
234 print_string(Sys.os_type);;
237 OCAML_OS_TYPE=`$OCAML conftest.ml`
238 AC_MSG_RESULT([$OCAML_OS_TYPE])
239 AC_SUBST([OCAML_OS_TYPE])