~npalix/coccinelle/upstream

3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
1
dnl  changes from the original for coccinelle:
2
dnl    replaced AC_CHECK_TOOL with AC_PATH_TOOL to obtain full paths
3
dnl    removed some of the AC_REQUIRE calls
4
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
5
dnl autoconf macros for OCaml
6
dnl
7
dnl Copyright © 2009      Richard W.M. Jones
8
dnl Copyright © 2009      Stefano Zacchiroli
9
dnl Copyright © 2000-2005 Olivier Andrieu
10
dnl Copyright © 2000-2005 Jean-Christophe Filliâtre
11
dnl Copyright © 2000-2005 Georges Mariano
12
dnl
13
dnl For documentation, please read the ocaml.m4 man page.
14
15
AC_DEFUN([AC_PROG_OCAML],
16
[dnl
17
  # checking for ocamlc
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
18
  AC_PATH_TOOL([OCAMLC],[ocamlc],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
19
20
  if test "$OCAMLC" != "no"; then
21
     OCAMLVERSION=`$OCAMLC -v | sed -n -e 's|.*version* *\(.*\)$|\1|p'`
22
     AC_MSG_RESULT([OCaml version is $OCAMLVERSION])
23
     # If OCAMLLIB is set, use it
24
     if test "$OCAMLLIB" = ""; then
25
        OCAMLLIB=`$OCAMLC -where 2>/dev/null || $OCAMLC -v|tail -1|cut -d ' ' -f 4`
26
     else
27
        AC_MSG_RESULT([OCAMLLIB previously set; preserving it.])
28
     fi
29
     AC_MSG_RESULT([OCaml library path is $OCAMLLIB])
30
31
     AC_SUBST([OCAMLVERSION])
32
     AC_SUBST([OCAMLLIB])
33
34
     # checking for ocamlopt
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
35
     AC_PATH_TOOL([OCAMLOPT],[ocamlopt],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
36
     OCAMLBEST=byte
37
     if test "$OCAMLOPT" = "no"; then
38
	AC_MSG_WARN([Cannot find ocamlopt; bytecode compilation only.])
39
     else
40
	TMPVERSION=`$OCAMLOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
41
	if test "$TMPVERSION" != "$OCAMLVERSION" ; then
42
	    AC_MSG_RESULT([versions differs from ocamlc; ocamlopt discarded.])
43
	    OCAMLOPT=no
44
	else
45
	    OCAMLBEST=opt
46
	fi
47
     fi
48
49
     AC_SUBST([OCAMLBEST])
50
51
     # checking for ocamlc.opt
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
52
     AC_PATH_TOOL([OCAMLCDOTOPT],[ocamlc.opt],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
53
     if test "$OCAMLCDOTOPT" != "no"; then
54
	TMPVERSION=`$OCAMLCDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
55
	if test "$TMPVERSION" != "$OCAMLVERSION" ; then
56
	    AC_MSG_RESULT([versions differs from ocamlc; ocamlc.opt discarded.])
57
	else
58
	    OCAMLC=$OCAMLCDOTOPT
59
	fi
60
     fi
61
62
     # checking for ocamlopt.opt
63
     if test "$OCAMLOPT" != "no" ; then
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
64
	AC_PATH_TOOL([OCAMLOPTDOTOPT],[ocamlopt.opt],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
65
	if test "$OCAMLOPTDOTOPT" != "no"; then
66
	   TMPVERSION=`$OCAMLOPTDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
67
	   if test "$TMPVERSION" != "$OCAMLVERSION" ; then
68
	      AC_MSG_RESULT([version differs from ocamlc; ocamlopt.opt discarded.])
69
	   else
70
	      OCAMLOPT=$OCAMLOPTDOTOPT
71
	   fi
72
        fi
73
     fi
74
75
     AC_SUBST([OCAMLOPT])
76
  fi
77
78
  AC_SUBST([OCAMLC])
79
80
  # checking for ocaml toplevel
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
81
  AC_PATH_TOOL([OCAML],[ocaml],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
82
83
  # checking for ocamldep
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
84
  AC_PATH_TOOL([OCAMLDEP],[ocamldep],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
85
86
  # checking for ocamlmktop
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
87
  AC_PATH_TOOL([OCAMLMKTOP],[ocamlmktop],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
88
89
  # checking for ocamlmklib
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
90
  AC_PATH_TOOL([OCAMLMKLIB],[ocamlmklib],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
91
92
  # checking for ocamldoc
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
93
  AC_PATH_TOOL([OCAMLDOC],[ocamldoc],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
94
])
95
96
97
AC_DEFUN([AC_PROG_OCAMLLEX],
98
[dnl
99
  # checking for ocamllex
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
100
  AC_PATH_TOOL([OCAMLLEX],[ocamllex],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
101
  if test "$OCAMLLEX" != "no"; then
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
102
    AC_PATH_TOOL([OCAMLLEXDOTOPT],[ocamllex.opt],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
103
    if test "$OCAMLLEXDOTOPT" != "no"; then
104
	OCAMLLEX=$OCAMLLEXDOTOPT
105
    fi
106
  fi
107
  AC_SUBST([OCAMLLEX])
108
])
109
110
AC_DEFUN([AC_PROG_OCAMLYACC],
111
[dnl
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
112
  AC_PATH_TOOL([OCAMLYACC],[ocamlyacc],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
113
  AC_SUBST([OCAMLYACC])
114
])
115
116
117
AC_DEFUN([AC_PROG_FINDLIB],
118
[dnl
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
119
  dnl  AC_REQUIRE([AC_PROG_OCAML])dnl
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
120
121
  # checking for ocamlfind
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
122
  AC_PATH_TOOL([OCAMLFIND],[ocamlfind],[no])
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
123
  AC_SUBST([OCAMLFIND])
124
])
125
126
127
dnl Thanks to Jim Meyering for working this next bit out for us.
128
dnl XXX We should define AS_TR_SH if it's not defined already
129
dnl (eg. for old autoconf).
130
AC_DEFUN([AC_CHECK_OCAML_PKG],
131
[dnl
3519 by Arie Middelkoop
Configurability of runtime ocaml paths.
132
  dnl  AC_REQUIRE([AC_PROG_FINDLIB])dnl
3508 by Arie Middelkoop
perl script 'configure' replaces with an autoconf version.
133
134
  AC_MSG_CHECKING([for OCaml findlib package $1])
135
136
  unset found
137
  unset pkg
138
  found=no
139
  for pkg in $1 $2 ; do
140
    if $OCAMLFIND query $pkg >/dev/null 2>/dev/null; then
141
      AC_MSG_RESULT([found])
142
      AS_TR_SH([OCAML_PKG_$1])=$pkg
143
      found=yes
144
      break
145
    fi
146
  done
147
  if test "$found" = "no" ; then
148
    AC_MSG_RESULT([not found])
149
    AS_TR_SH([OCAML_PKG_$1])=no
150
  fi
151
152
  AC_SUBST(AS_TR_SH([OCAML_PKG_$1]))
153
])
154
155
156
AC_DEFUN([AC_CHECK_OCAML_MODULE],
157
[dnl
158
  AC_MSG_CHECKING([for OCaml module $2])
159
160
  cat > conftest.ml <<EOF
161
open $3
162
EOF
163
  unset found
164
  for $1 in $$1 $4 ; do
165
    if $OCAMLC -c -I "$$1" conftest.ml >&5 2>&5 ; then
166
      found=yes
167
      break
168
    fi
169
  done
170
171
  if test "$found" ; then
172
    AC_MSG_RESULT([$$1])
173
  else
174
    AC_MSG_RESULT([not found])
175
    $1=no
176
  fi
177
  AC_SUBST([$1])
178
])
179
180
181
dnl XXX Cross-compiling
182
AC_DEFUN([AC_CHECK_OCAML_WORD_SIZE],
183
[dnl
184
  AC_REQUIRE([AC_PROG_OCAML])dnl
185
  AC_MSG_CHECKING([for OCaml compiler word size])
186
  cat > conftest.ml <<EOF
187
  print_endline (string_of_int Sys.word_size)
188
  EOF
189
  OCAML_WORD_SIZE=`$OCAML conftest.ml`
190
  AC_MSG_RESULT([$OCAML_WORD_SIZE])
191
  AC_SUBST([OCAML_WORD_SIZE])
192
])
193
194
AC_DEFUN([AC_CHECK_OCAML_OS_TYPE],
195
[dnl
196
  AC_REQUIRE([AC_PROG_OCAML])dnl
197
  AC_MSG_CHECKING([OCaml Sys.os_type])
198
199
  cat > conftest.ml <<EOF
200
  print_string(Sys.os_type);;
201
EOF
202
203
  OCAML_OS_TYPE=`$OCAML conftest.ml`
204
  AC_MSG_RESULT([$OCAML_OS_TYPE])
205
  AC_SUBST([OCAML_OS_TYPE])
206
])