1dnl autoconf macros for OCaml 2dnl 3dnl Copyright (C) 2009 Richard W.M. Jones 4dnl Copyright (C) 2009 Stefano Zacchiroli 5dnl Copyright (C) 2000-2005 Olivier Andrieu 6dnl Copyright (C) 2000-2005 Jean-Christophe Filliatre 7dnl Copyright (C) 2000-2005 Georges Mariano 8dnl 9dnl For documentation, please read the ocaml.m4 man page. 10dnl 11dnl All rights reserved. 12dnl 13dnl Redistribution and use in source and binary forms, with or without 14dnl modification, are permitted provided that the following conditions are 15dnl met: 16dnl 17dnl * Redistributions of source code must retain the above copyright 18dnl notice, this list of conditions and the following disclaimer. 19dnl * Redistributions in binary form must reproduce the above copyright 20dnl notice, this list of conditions and the following disclaimer in the 21dnl documentation and/or other materials provided with the distribution. 22dnl * The names of the contributors may not be used to endorse or promote 23dnl products derived from this software without specific prior written 24dnl permission. 25dnl 26dnl THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' 27dnl AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 28dnl THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29dnl PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 30dnl BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 33dnl BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 34dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 35dnl OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 36dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 38AC_DEFUN([AC_PROG_OCAML], 39[dnl 40 # checking for ocamlc 41 AC_CHECK_TOOL([OCAMLC],[ocamlc],[no]) 42 43 if test "$OCAMLC" != "no"; then 44 OCAMLVERSION=`$OCAMLC -v | sed -n -e 's|.*version* *\(.*\)$|\1|p'` 45 AC_MSG_RESULT([OCaml version is $OCAMLVERSION]) 46 OCAMLLIB=`$OCAMLC -where 2>/dev/null || $OCAMLC -v|tail -1|cut -d ' ' -f 4` 47 AC_MSG_RESULT([OCaml library path is $OCAMLLIB]) 48 49 AC_SUBST([OCAMLVERSION]) 50 AC_SUBST([OCAMLLIB]) 51 52 # checking for ocamlopt 53 AC_CHECK_TOOL([OCAMLOPT],[ocamlopt],[no]) 54 OCAMLBEST=byte 55 if test "$OCAMLOPT" = "no"; then 56 AC_MSG_WARN([Cannot find ocamlopt; bytecode compilation only.]) 57 else 58 TMPVERSION=`$OCAMLOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' ` 59 if test "$TMPVERSION" != "$OCAMLVERSION" ; then 60 AC_MSG_RESULT([versions differs from ocamlc; ocamlopt discarded.]) 61 OCAMLOPT=no 62 else 63 OCAMLBEST=opt 64 fi 65 fi 66 67 AC_SUBST([OCAMLBEST]) 68 69 # checking for ocamlc.opt 70 AC_CHECK_TOOL([OCAMLCDOTOPT],[ocamlc.opt],[no]) 71 if test "$OCAMLCDOTOPT" != "no"; then 72 TMPVERSION=`$OCAMLCDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' ` 73 if test "$TMPVERSION" != "$OCAMLVERSION" ; then 74 AC_MSG_RESULT([versions differs from ocamlc; ocamlc.opt discarded.]) 75 else 76 OCAMLC=$OCAMLCDOTOPT 77 fi 78 fi 79 80 # checking for ocamlopt.opt 81 if test "$OCAMLOPT" != "no" ; then 82 AC_CHECK_TOOL([OCAMLOPTDOTOPT],[ocamlopt.opt],[no]) 83 if test "$OCAMLOPTDOTOPT" != "no"; then 84 TMPVERSION=`$OCAMLOPTDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' ` 85 if test "$TMPVERSION" != "$OCAMLVERSION" ; then 86 AC_MSG_RESULT([version differs from ocamlc; ocamlopt.opt discarded.]) 87 else 88 OCAMLOPT=$OCAMLOPTDOTOPT 89 fi 90 fi 91 fi 92 93 AC_SUBST([OCAMLOPT]) 94 fi 95 96 AC_SUBST([OCAMLC]) 97 98 # checking for ocamldep 99 AC_CHECK_TOOL([OCAMLDEP],[ocamldep],[no]) 100 101 # checking for ocamlmktop 102 AC_CHECK_TOOL([OCAMLMKTOP],[ocamlmktop],[no]) 103 104 # checking for ocamlmklib 105 AC_CHECK_TOOL([OCAMLMKLIB],[ocamlmklib],[no]) 106 107 # checking for ocamldoc 108 AC_CHECK_TOOL([OCAMLDOC],[ocamldoc],[no]) 109 110 # checking for ocamlbuild 111 AC_CHECK_TOOL([OCAMLBUILD],[ocamlbuild],[no]) 112]) 113 114 115AC_DEFUN([AC_PROG_OCAMLLEX], 116[dnl 117 # checking for ocamllex 118 AC_CHECK_TOOL([OCAMLLEX],[ocamllex],[no]) 119 if test "$OCAMLLEX" != "no"; then 120 AC_CHECK_TOOL([OCAMLLEXDOTOPT],[ocamllex.opt],[no]) 121 if test "$OCAMLLEXDOTOPT" != "no"; then 122 OCAMLLEX=$OCAMLLEXDOTOPT 123 fi 124 fi 125 AC_SUBST([OCAMLLEX]) 126]) 127 128AC_DEFUN([AC_PROG_OCAMLYACC], 129[dnl 130 AC_CHECK_TOOL([OCAMLYACC],[ocamlyacc],[no]) 131 AC_SUBST([OCAMLYACC]) 132]) 133 134 135AC_DEFUN([AC_PROG_CAMLP4], 136[dnl 137 AC_REQUIRE([AC_PROG_OCAML])dnl 138 139 # checking for camlp4 140 AC_CHECK_TOOL([CAMLP4],[camlp4],[no]) 141 if test "$CAMLP4" != "no"; then 142 TMPVERSION=`$CAMLP4 -v 2>&1| sed -n -e 's|.*version *\(.*\)$|\1|p'` 143 if test "$TMPVERSION" != "$OCAMLVERSION" ; then 144 AC_MSG_RESULT([versions differs from ocamlc]) 145 CAMLP4=no 146 fi 147 fi 148 AC_SUBST([CAMLP4]) 149 150 # checking for companion tools 151 AC_CHECK_TOOL([CAMLP4BOOT],[camlp4boot],[no]) 152 AC_CHECK_TOOL([CAMLP4O],[camlp4o],[no]) 153 AC_CHECK_TOOL([CAMLP4OF],[camlp4of],[no]) 154 AC_CHECK_TOOL([CAMLP4OOF],[camlp4oof],[no]) 155 AC_CHECK_TOOL([CAMLP4ORF],[camlp4orf],[no]) 156 AC_CHECK_TOOL([CAMLP4PROF],[camlp4prof],[no]) 157 AC_CHECK_TOOL([CAMLP4R],[camlp4r],[no]) 158 AC_CHECK_TOOL([CAMLP4RF],[camlp4rf],[no]) 159 AC_SUBST([CAMLP4BOOT]) 160 AC_SUBST([CAMLP4O]) 161 AC_SUBST([CAMLP4OF]) 162 AC_SUBST([CAMLP4OOF]) 163 AC_SUBST([CAMLP4ORF]) 164 AC_SUBST([CAMLP4PROF]) 165 AC_SUBST([CAMLP4R]) 166 AC_SUBST([CAMLP4RF]) 167]) 168 169 170AC_DEFUN([AC_PROG_FINDLIB], 171[dnl 172 AC_REQUIRE([AC_PROG_OCAML])dnl 173 174 # checking for ocamlfind 175 AC_CHECK_TOOL([OCAMLFIND],[ocamlfind],[no]) 176 AC_SUBST([OCAMLFIND]) 177]) 178 179 180dnl Thanks to Jim Meyering for working this next bit out for us. 181dnl XXX We should define AS_TR_SH if it's not defined already 182dnl (eg. for old autoconf). 183AC_DEFUN([AC_CHECK_OCAML_PKG], 184[dnl 185 AC_REQUIRE([AC_PROG_FINDLIB])dnl 186 187 AC_MSG_CHECKING([for OCaml findlib package $1]) 188 189 unset found 190 unset pkg 191 found=no 192 for pkg in $1 $2 ; do 193 if $OCAMLFIND query $pkg >/dev/null 2>/dev/null; then 194 AC_MSG_RESULT([found]) 195 AS_TR_SH([OCAML_PKG_$1])=$pkg 196 found=yes 197 break 198 fi 199 done 200 if test "$found" = "no" ; then 201 AC_MSG_RESULT([not found]) 202 AS_TR_SH([OCAML_PKG_$1])=no 203 fi 204 205 AC_SUBST(AS_TR_SH([OCAML_PKG_$1])) 206]) 207 208 209AC_DEFUN([AC_CHECK_OCAML_MODULE], 210[dnl 211 AC_MSG_CHECKING([for OCaml module $2]) 212 213 cat > conftest.ml <<EOF 214open $3 215EOF 216 unset found 217 for $1 in $$1 $4 ; do 218 if $OCAMLC -c -I "$$1" conftest.ml >&5 2>&5 ; then 219 found=yes 220 break 221 fi 222 done 223 224 if test "$found" ; then 225 AC_MSG_RESULT([$$1]) 226 else 227 AC_MSG_RESULT([not found]) 228 $1=no 229 fi 230 AC_SUBST([$1]) 231]) 232 233 234dnl XXX Cross-compiling 235AC_DEFUN([AC_CHECK_OCAML_WORD_SIZE], 236[dnl 237 AC_MSG_CHECKING([for OCaml compiler word size]) 238 cat > conftest.ml <<EOF 239 print_endline (string_of_int Sys.word_size) 240 EOF 241 OCAML_WORD_SIZE=`ocaml conftest.ml` 242 AC_MSG_RESULT([$OCAML_WORD_SIZE]) 243 AC_SUBST([OCAML_WORD_SIZE]) 244]) 245