1OCAML.M4(1) Autoconf macros OCAML.M4(1)
2
3
4
6 ocaml.m4 - Autoconf macros for OCaml
7
9 AC_PROG_OCAML
10 AC_PROG_FINDLIB
11 AC_PROG_OCAMLLEX
12 AC_PROG_OCAMLYACC
13 AC_PROG_CAMLP4
14 AC_CHECK_OCAML_PKG([name])
15 AC_CHECK_OCAML_MODULE(VARIABLE,NAME,MODULE,INCLUDE-PATHS)
16 AC_CHECK_OCAML_WORD_SIZE
17
19 ocaml.m4 is a file containing standard, useful autoconf macros for
20 detecting the OCaml, findlib, OCaml packages, and so on in your
21 autoconf-generated ./configure scripts.
22
23 To begin using these macros, you will need to copy the "ocaml.m4" file
24 (usually located at "/usr/share/aclocal/ocaml.m4") to the autoconf
25 macros directory in your project. Normally this is the "m4/" directory
26 in your project, but the directory can be changed using the
27 "AC_CONFIG_MACRO_DIR(DIR)" directive. If you have just created the
28 "m4/" directory, then you may also need to do:
29
30 aclocal -I m4
31
32 You can then add any of the macros described below to your
33 "configure.ac" (or "configure.in"). Almost every OCaml project should
34 use "AC_PROG_OCAML" first and probably "AC_PROG_FINDLIB" right after
35 it.
36
37 This manual page does not describe how to use autoconf. For that you
38 should read the detailed autoconf info file ("info autoconf").
39
41 This macro detects which tools of the usual OCaml toolchain are
42 available. It defines and substitutes the following variables:
43
44 OCAMLC set to the name of the bytecode compiler
45 (eg. "ocamlc" or "ocamlc.opt"), or "no" if
46 no OCaml installation was found
47 OCAMLOPT the name of the native-code compiler, eg. "ocamlopt",
48 "ocamlopt.opt" or "no"
49 OCAMLBEST "byte" (if only the bytecode compiler is available)
50 or "opt" (if both bytecode and native code compilers
51 are available)
52 OCAMLDEP the name of the dependency resolver, eg. "ocamldep"
53 OCAMLMKTOP the name of ocamlmktop
54 OCAMLMKLIB the name of ocamlmklib
55 OCAMLDOC the name of ocamldoc
56 OCAMLBUILD the name of ocamlbuild
57 OCAMLLIB the OCaml library path (eg. C</usr/lib/ocaml/>)
58 OCAMLVERSION the compiler version (eg. C<3.11.0>)
59
60 Detecting if OCaml is installed
61 Unlike old versions of these macros, "AC_PROG_OCAML" does not exit if
62 no OCaml installation is detected. Therefore if you want to detect if
63 OCaml is installed you have to do something like this:
64
65 AC_PROG_OCAML
66 if test "$OCAMLC" = "no"; then
67 AC_MSG_ERROR([You must install the OCaml compiler])
68 fi
69
70 This behaviour and usage pattern are consistent with other macros of
71 the "AC_PROG_*") family.
72
73 Cross-compiling
74 If the configure script is invoked for cross-compiling then
75 "AC_PROG_OCAML" will detect the cross-compiler versions of the OCaml
76 compiler, eg. "OCAMLC=i686-pc-mingw32-ocamlc" etc. This happens
77 automatically, and for most purposes you don't need to worry about it.
78
80 This macro checks for the presence of the ocamlfind program (part of
81 findlib). It defines and substitutes "OCAMLFIND" to the name of the
82 ocamlfind program, or "no" if not found.
83
84 Note that this macro does not fail if ocamlfind is not found. If you
85 want to force the user to install findlib, you should do:
86
87 AC_PROG_FINDLIB
88 if test "$OCAMLFIND" = "no"; then
89 AC_MSG_ERROR([You must install OCaml findlib (the ocamlfind command)])
90 fi
91
92 See also "AC_CHECK_OCAML_PKG".
93
95 This checks for the ocamllex program and sets "OCAMLLEX" to the name of
96 the program (eg. "ocamllex" or "ocamllex.opt"), or "no" if not found.
97
99 This checks for the ocamlyacc program and sets "OCAMLYACC" to the name
100 of the program, or "no" if not found.
101
103 This checks for camlp4, and checks that the version matches the
104 compiler version found previously. It sets "CAMLP4" to the name of the
105 basic camlp4 program, or "no" if not found.
106
107 The macro also checks for other tools of the camlp4 suite like camlp4o,
108 camlp4orf, etc. For each of them, a fully capitalized variable is set
109 to the tool name (or "no" if not found); all variable are substituted
110 for when filling .in files. The full list of tools and respective
111 variable names is as follows:
112
113 camlp4 CAMLP4
114 camlp4boot CAMLP4BOOT
115 camlp4o CAMLP4O
116 camlp4of CAMLP4OF
117 camlp4oof CAMLP4OOF
118 camlp4orf CAMLP4ORF
119 camlp4prof CAMLP4PROF
120 camlp4r CAMLP4R
121 camlp4rf CAMLP4RF
122
124 This is the main macro that can be used to detect the presence of OCaml
125 findlib packages. This macro uses ocamlfind to look up findlib
126 packages (and thus requires that findlib itself has been installed, and
127 that the package has been properly packaged with a META file etc.) If
128 you want to find an OCaml findlib package which hasn't been installed
129 with findlib then you should try using "AC_CHECK_OCAML_MODULE" instead.
130
131 AC_CHECK_OCAML_PKG([name])
132
133 checks for an OCaml findlib package with the given name. If found, it
134 defines and substitutes the variable "OCAML_PKG_name" where the "name"
135 part is substituted for the package name by replacing all dashes with
136 underscores.
137
138 For example,
139
140 AC_CHECK_OCAML_PKG([xml-light])
141
142 will set "OCAML_PKG_xml_light" to either "xml-light" or "no".
143
144 To have the configure script fail if a package is not installed, do:
145
146 AC_CHECK_OCAML_PKG([foo])
147 if test "$OCAML_PKG_foo" = "no"; then
148 AC_MSG_ERROR([Please install OCaml findlib module 'foo'.])
149 fi
150
151 In your Makefile.in, use the substitution variable in conjunction with
152 ocamlfind, eg:
153
154 .ml.cmo:
155 $(OCAMLFIND) ocamlc -package @OCAML_PKG_foo@ -c $< -o $@
156
157 Note that also in the substitution variable dashes are replaced with
158 underscores.
159
160 Checking for alternative findlib package names
161 In the (unlikely) case where the same library corresponds to different
162 findlib package names on different systems, you can improve portability
163 by checking for the alternative names passing a second argument to
164 "AC_CHECK_OCAML_PKG":
165
166 AC_CHECK_OCAML_PKG(PKGNAME,ALTERNATIVE-NAMES)
167
168 The behaviour is the same as before if "PKGNAME" is found. Otherwise
169 all names in "ALTERNATIVE-NAMES" are tested in turn as findlib package
170 names. If one is found, it is set as the value set by the macro and
171 substituted in .in files; otherwise "no" is set.
172
173 Note that the variable name is determined by "PKGNAME", while the value
174 depends on the actual alternative name found.
175
176 For example, to detect the camlzip findlib package, either called "zip"
177 or "camlzip", and to store the found value in the "OCAML_PKG_zip"
178 variable you can do in your configure.ac:
179
180 AC_CHECK_OCAML_PKG(zip,camlzip)
181
182 and have a portable Makefile.in build line such as:
183
184 .ml.cmo:
185 $(OCAMLFIND) ocamlc -package @OCAML_PKG_zip@ -c $< -o $@
186
188 "AC_CHECK_OCAML_MODULE" is the hairier alternative to
189 "AC_CHECK_OCAML_PKG". You should always use "AC_CHECK_OCAML_PKG" and
190 ocamlfind/findlib if possible.
191
192 The parameters are:
193
194 VARIABLE
195 This is the environment variable that is set. It will either be
196 set to the include path, or to "no" if the module was not found.
197
198 NAME
199 This is the name of the module we are looking for. This parameter
200 is just used for printing messages, and does not affect how the
201 module is found.
202
203 MODULE
204 This should be an OCaml module name, representing the module name
205 being looked up. You can put sub-modules here, eg.
206 "CalendarLib.Date"
207
208 INCLUDE-PATHS
209 This is the default list of include directories to search, eg.
210 "+calendar"
211
212 For example, the following code will check for the OCaml Calendar
213 module, and will distinguish between version 1 and version 2 of this
214 module (which have incompatible APIs).
215
216 AC_CHECK_OCAML_PKG(calendar)
217 AC_CHECK_OCAML_MODULE(is_calendar2,calendar,[CalendarLib.Date],[+calendar])
218
219 After the above code has run, variables "OCAML_PKG_calendar" and
220 "is_calendar2" will be set as follows:
221
222 OCAML_PKG_calendar is_calendar2 Result
223
224 yes +calendar Calendar v2 is installed
225 yes no Calendar v1 is installed
226 no no No Calendar module installed
227
229 This checks the word size of the OCaml compiler, and sets
230 "OCAML_WORD_SIZE" to either 32 or 64.
231
233 autoconf(1), <http://ocaml-autoconf.forge.ocamlcore.org>,
234 <http://caml.inria.fr/>
235
237 · /usr/share/aclocal/ocaml.m4
238
240 Various people have contributed to these macros over many years:
241
242 · Olivier Andrieu
243
244 · Jean-Christophe Filliatre
245
246 · Richard W.M. Jones
247
248 · Georges Mariano
249
250 · Jim Meyering
251
252 · Stefano Zacchiroli
253
255 Copyright X 2009 Richard W.M. Jones
256 Copyright X 2009 Stefano Zacchiroli
257 Copyright X 2000-2005 Olivier Andrieu
258 Copyright X 2000-2005 Jean-Christophe Filliatre
259 Copyright X 2000-2005 Georges Mariano
260
261 All rights reserved.
262
263 Redistribution and use in source and binary forms, with or without modification,
264 are permitted provided that the following conditions are met:
265
266 * Redistributions of source code must retain the above copyright notice, this
267 list of conditions and the following disclaimer.
268 * Redistributions in binary form must reproduce the above copyright notice,
269 this list of conditions and the following disclaimer in the documentation
270 and/or other materials provided with the distribution.
271 * The names of the contributors may not be used to endorse or promote
272 products derived from this software without specific prior written
273 permission.
274
275 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
276 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
277 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
278 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
279 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
280 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
281 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
282 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
283 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
284 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
285
287 Please report bugs to the authors at the project page:
288 <http://forge.ocamlcore.org/projects/ocaml-autoconf/>, using the forge
289 bug tracker <http://forge.ocamlcore.org/tracker/?group_id=69>.
290
291
292
293ocaml-autoconf-1.0 2009-10-12 OCAML.M4(1)