File: ocaml.m4.pod

package info (click to toggle)
ocaml-tools 20120103-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 260 kB
  • ctags: 97
  • sloc: makefile: 253; ml: 250
file content (339 lines) | stat: -rw-r--r-- 10,645 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
=encoding utf8

=head1 NAME

ocaml.m4 - Autoconf macros for OCaml

=head1 SUMMARY

 AC_PROG_OCAML
 AC_PROG_FINDLIB
 AC_PROG_OCAMLLEX
 AC_PROG_OCAMLYACC
 AC_PROG_CAMLP4
 AC_CHECK_OCAML_PKG([name])
 AC_CHECK_OCAML_MODULE(VARIABLE,NAME,MODULE,INCLUDE-PATHS)
 AC_CHECK_OCAML_WORD_SIZE

=head1 DESCRIPTION

B<ocaml.m4> is a file containing standard, useful autoconf macros for
detecting the OCaml, findlib, OCaml packages, and so on in your
autoconf-generated ./configure scripts.

To begin using these macros, you will need to copy the C<ocaml.m4>
file (usually located at C</usr/share/aclocal/ocaml.m4>) to the
autoconf macros directory in your project.  Normally this is the
C<m4/> directory in your project, but the directory can be changed
using the C<AC_CONFIG_MACRO_DIR(DIR)> directive.  If you have just
created the C<m4/> directory, then you may also need to do:

 aclocal -I m4

You can then add any of the macros described below to your
C<configure.ac> (or C<configure.in>). Almost every OCaml project
should use C<AC_PROG_OCAML> first and probably C<AC_PROG_FINDLIB>
right after it.

This manual page does not describe how to use autoconf.  For that you
should read the detailed autoconf info file (C<info autoconf>).

=head1 AC_PROG_OCAML

This macro detects which tools of the usual OCaml toolchain are
available. It defines and substitutes the following variables:

 OCAMLC          set to the name of the bytecode compiler
                   (eg. "ocamlc" or "ocamlc.opt"), or "no" if
                   no OCaml installation was found
 OCAMLOPT        the name of the native-code compiler, eg. "ocamlopt",
                   "ocamlopt.opt" or "no"
 OCAMLBEST       "byte" (if only the bytecode compiler is available)
                   or "opt" (if both bytecode and native code compilers
		   are available)
 OCAMLDEP        the name of the dependency resolver, eg. "ocamldep"
 OCAMLMKTOP      the name of ocamlmktop
 OCAMLMKLIB      the name of ocamlmklib
 OCAMLDOC        the name of ocamldoc
 OCAMLBUILD      the name of ocamlbuild
 OCAMLLIB        the OCaml library path (eg. C</usr/lib/ocaml/>)
 OCAMLVERSION    the compiler version (eg. C<3.11.0>)

=head2 Detecting if OCaml is installed

Unlike old versions of these macros, C<AC_PROG_OCAML> does I<not> exit
if no OCaml installation is detected.  Therefore if you want to detect
if OCaml is installed you have to do something like this:

 AC_PROG_OCAML
 if test "$OCAMLC" = "no"; then
   AC_MSG_ERROR([You must install the OCaml compiler])
 fi

This behaviour and usage pattern are consistent with other macros of
the C<AC_PROG_*>) family.

=head2 Cross-compiling

If the configure script is invoked for cross-compiling then
C<AC_PROG_OCAML> will detect the cross-compiler versions of the OCaml
compiler, eg. C<OCAMLC=i686-pc-mingw32-ocamlc> etc.  This happens
automatically, and for most purposes you don't need to worry about it.

=head1 AC_PROG_FINDLIB

This macro checks for the presence of the ocamlfind program (part of
findlib).  It defines and substitutes C<OCAMLFIND> to the name of the
ocamlfind program, or C<no> if not found.

Note that this macro does not fail if ocamlfind is not found.  If you
want to force the user to install findlib, you should do:

 AC_PROG_FINDLIB
 if test "$OCAMLFIND" = "no"; then
   AC_MSG_ERROR([You must install OCaml findlib (the ocamlfind command)])
 fi

See also C<AC_CHECK_OCAML_PKG>.

=head1 AC_PROG_OCAMLLEX

This checks for the ocamllex program and sets C<OCAMLLEX> to the name
of the program (eg. C<ocamllex> or C<ocamllex.opt>), or C<no> if not
found.

=head1 AC_PROG_OCAMLYACC

This checks for the ocamlyacc program and sets C<OCAMLYACC> to the
name of the program, or C<no> if not found.

=head1 AC_PROG_CAMLP4

This checks for camlp4, and checks that the version matches the
compiler version found previously.  It sets C<CAMLP4> to the name of
the basic camlp4 program, or C<no> if not found.

The macro also checks for other tools of the camlp4 suite like
camlp4o, camlp4orf, etc. For each of them, a fully capitalized
variable is set to the tool name (or C<no> if not found); all variable
are substituted for when filling .in files. The full list of tools and
respective variable names is as follows:

 camlp4        CAMLP4
 camlp4boot    CAMLP4BOOT
 camlp4o       CAMLP4O
 camlp4of      CAMLP4OF
 camlp4oof     CAMLP4OOF
 camlp4orf     CAMLP4ORF
 camlp4prof    CAMLP4PROF
 camlp4r       CAMLP4R
 camlp4rf      CAMLP4RF

=head1 AC_CHECK_OCAML_PKG

This is the main macro that can be used to detect the presence of
OCaml findlib packages.  This macro uses ocamlfind to look up findlib
packages (and thus requires that findlib itself has been installed,
and that the package has been properly packaged with a META file etc.)
If you want to find an OCaml findlib package which hasn't been
installed with findlib then you should try using
C<AC_CHECK_OCAML_MODULE> instead.

 AC_CHECK_OCAML_PKG([name])

checks for an OCaml findlib package with the given name. If found, it
defines and substitutes the variable C<OCAML_PKG_name> where the
C<name> part is substituted for the package name by replacing all
dashes with underscores.

For example,

 AC_CHECK_OCAML_PKG([xml-light])

will set C<OCAML_PKG_xml_light> to either C<xml-light> or C<no>.

To have the configure script fail if a package is not installed, do:

 AC_CHECK_OCAML_PKG([foo])
 if test "$OCAML_PKG_foo" = "no"; then
   AC_MSG_ERROR([Please install OCaml findlib module 'foo'.])
 fi

In your Makefile.in, use the substitution variable in conjunction with
ocamlfind, eg:

 .ml.cmo:
   $(OCAMLFIND) ocamlc -package @OCAML_PKG_foo@ -c $< -o $@

Note that also in the substitution variable dashes are replaced with
underscores.

=head2 Checking for alternative findlib package names

In the (unlikely) case where the same library corresponds to different
findlib package names on different systems, you can improve
portability by checking for the alternative names passing a second
argument to C<AC_CHECK_OCAML_PKG>:

 AC_CHECK_OCAML_PKG(PKGNAME,ALTERNATIVE-NAMES)

The behaviour is the same as before if C<PKGNAME> is found. Otherwise
all names in C<ALTERNATIVE-NAMES> are tested in turn as findlib
package names. If one is found, it is set as the value set by the
macro and substituted in .in files; otherwise C<no> is set.

Note that the variable name is determined by C<PKGNAME>, while the
value depends on the actual alternative name found.

For example, to detect the camlzip findlib package, either called
C<zip> or C<camlzip>, and to store the found value in the
C<OCAML_PKG_zip> variable you can do in your configure.ac:

 AC_CHECK_OCAML_PKG(zip,camlzip)

and have a portable Makefile.in build line such as:

 .ml.cmo:
   $(OCAMLFIND) ocamlc -package @OCAML_PKG_zip@ -c $< -o $@

=head1 AC_CHECK_OCAML_MODULE(VARIABLE,NAME,MODULE,INCLUDE-PATHS)

C<AC_CHECK_OCAML_MODULE> is the hairier alternative to
C<AC_CHECK_OCAML_PKG>.  You should always use C<AC_CHECK_OCAML_PKG>
and ocamlfind/findlib if possible.

The parameters are:

=over

=item VARIABLE

This is the environment variable that is set.  It will either be set
to the include path, or to C<no> if the module was not found.

=item NAME

This is the name of the module we are looking for.  This parameter is
just used for printing messages, and does not affect how the module is
found.

=item MODULE

This should be an OCaml module name, representing the module name
being looked up.  You can put sub-modules here, eg.
C<CalendarLib.Date>

=item INCLUDE-PATHS

This is the default list of include directories to search, eg.
C<+calendar>

=back

For example, the following code will check for the OCaml Calendar
module, and will distinguish between version 1 and version 2 of this
module (which have incompatible APIs).

 AC_CHECK_OCAML_PKG(calendar)
 AC_CHECK_OCAML_MODULE(is_calendar2,calendar,[CalendarLib.Date],[+calendar])

After the above code has run, variables C<OCAML_PKG_calendar> and
C<is_calendar2> will be set as follows:

 OCAML_PKG_calendar  is_calendar2  Result
 
 yes                 +calendar     Calendar v2 is installed
 yes                 no            Calendar v1 is installed
 no                  no            No Calendar module installed

=head1 AC_CHECK_OCAML_WORD_SIZE

This checks the word size of the OCaml compiler, and sets
C<OCAML_WORD_SIZE> to either C<32> or C<64>.

=head1 SEE ALSO

L<autoconf(1)>,
L<http://ocaml-autoconf.forge.ocamlcore.org>,
L<http://caml.inria.fr/>

=head1 FILES

=over

=item *

/usr/share/aclocal/ocaml.m4

=back

=head1 AUTHORS

Various people have contributed to these macros over many years:

=over

=item *

Olivier Andrieu

=item *

Jean-Christophe Filliâtre

=item *

Richard W.M. Jones

=item *

Georges Mariano

=item *

Jim Meyering

=item *

Stefano Zacchiroli

=back

=head1 LICENSE

 Copyright © 2009      Richard W.M. Jones
 Copyright © 2009      Stefano Zacchiroli
 Copyright © 2000-2005 Olivier Andrieu
 Copyright © 2000-2005 Jean-Christophe Filliâtre
 Copyright © 2000-2005 Georges Mariano
 
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without modification,
 are permitted provided that the following conditions are met:
 
 * Redistributions of source code must retain the above copyright notice, this
 list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution.
 * The names of the contributors may not be used to endorse or promote
 products derived from this software without specific prior written
 permission.
 
 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=head1 REPORTING BUGS

Please report bugs to the authors at the project page:
L<http://forge.ocamlcore.org/projects/ocaml-autoconf/>, using the
forge bug tracker L<http://forge.ocamlcore.org/tracker/?group_id=69>.