Coccinelle release 1.0.0-rc12
[bpt/coccinelle.git] / configure.ac
CommitLineData
feec80c3
C
1dnl standard initialization (we only use autoconf not automake)
2AC_INIT([coccinelle], [`cat ./version`], [cocci@diku.dk], [], [http://coccinelle.lip6.fr/])
3AC_SUBST([COCCI_VERSION], [$(cat ./version)])
4AC_SUBST([COCCI_SRCDIR], [$(pwd)])
5AC_MSG_NOTICE([configuring coccinelle $COCCI_VERSION in $COCCI_SRCDIR])
6
7AC_CONFIG_SRCDIR([cocci.ml]) dnl this file must be present in our src directory
8AC_COCCI_CONFVERSION
9
10dnl reminder that this configure depends on macros generated by aclocal
11AC_MSG_NOTICE([this configure program uses pkg-config m4 macros])
12AC_MSG_NOTICE([this configure program uses ocaml m4 macros (see setup/ocaml.m4)])
13AC_MSG_NOTICE([this configure program uses custom m4 macros (see setup/cocci.m4)])
14AC_MSG_NOTICE([some fake substitutions for required but unavailable programs may be used (see setup/fake*)])
15
16
17dnl
18dnl Note: the conditionals in this configure script are tricky.
19dnl The approach taken here is that many tools can be enabled/disabled
20dnl and paths can be given explicitly via commandline parameters or
21dnl environment variables.
22dnl
23
24
25dnl
26dnl Basic tools
27dnl
28
29AC_MSG_NOTICE([verifying basic tools])
30
31AC_PROG_INSTALL
32AC_PROG_MKDIR_P
33AC_PROG_CPP
34AC_PATH_PROG([TAR],[tar])
35AC_PATH_PROG([PATCH],[patch])
36
37dnl pkg config is required
38AC_COCCI_TOOL([PKG_CONFIG],[pkg-config],[$COCCI_SRCDIR/setup/fake-subst.sh pkg-config])
39AS_IF([test "x$PKG_CONFIG" = xno],
40[dnl
41 AC_MSG_ERROR([A suitable pkg-config could not be found.])
42])
43
44dnl ocaml compile
45AC_PROG_OCAML
46AC_CHECK_OCAMLVERSION([OCAMLATLEAST310],[3.10])
47AC_CHECK_OCAMLVERSION([OCAMLATLEAST311],[3.11])
48
49AS_IF([test "x$OCAMLC" = xno -o "x$OCAMLDEP" = xno -o "x$OCAMLDOC" = xno -o "x$OCAMLMKLIB" = xno],
50[dnl
51 AC_MSG_ERROR([You must install the OCaml compiler])
52])
53AS_IF([test "x$OCAMLATLEAST310" = xno],[AC_MSG_NOTICE([a more recent OCaml installation may be required])])
54
55dnl ocaml tools
56AC_PROG_CAMLP4
57AC_COCCI_TOOL([OCAMLLEX],[ocamllex],[])
58AC_COCCI_TOOL([OCAMLYACC],[ocamlyacc],[])
59AC_COCCI_TOOL([OCAMLFIND],[ocamlfind],[$COCCI_SRCDIR/setup/fake-subst.sh ocamlfind])
60
61dnl enforce ocaml tool requirements
62AS_IF([test "x$OCAMLLEX" = xno],
63[dnl
64 AC_MSG_ERROR([the OCaml Lexer needs to be installed (the ocamllex command). It should be part of your OCaml distribution.])
65])
66
67AS_IF([test "x$OCAMLYACC" = xno],
68[dnl
69 AC_MSG_ERROR([The OCaml parser generated needs to be installed (the ocamlyacc command). It should be part of your OCaml distribution.])
70])
71
72AS_IF([test "x$OCAMLFIND" = xno],
73[dnl
74 AC_MSG_ERROR([A suitable OCaml findlib (the ocamlfind command) could not be found.])
75])
76
77dnl these variables are substituted for in the code: this guarantees a default for them.
78AC_COCCI_RUNTIME_CMD([OCAMLFIND],[ocamlfind])
79AC_COCCI_RUNTIME_CMD([OCAMLC],[ocamlc])
80AC_COCCI_RUNTIME_CMD([OCAMLOPT],[ocamlopt])
81AC_COCCI_RUNTIME_CMD([OCAMLDEP],[ocamldep])
82AC_COCCI_RUNTIME_CMD([CAMLP4],[camlp4])
83AC_COCCI_RUNTIME_CMD([CAMLP4O],[camlp4o])
84
85AC_CACHE_SAVE
86
87
88dnl
89dnl Basic ocaml modules
90dnl
91
92AC_MSG_NOTICE([verifying basic ocaml modules])
93
94dnl default dir with the bundled ocaml packages
95AC_COCCI_SET_EXTERNAL_DIR([$COCCI_SRCDIR/bundles])
96
97dnl set some defaults
98dnl add a line for each package that is
99dnl configured via AC_CHECK_COCCI_EXTPKG
100dnl or AC_REQ_COCCI_EXTPKG
101AC_COCCI_INIT_PKG_EMPTY([sexplib])
102AC_COCCI_INIT_PKG_EMPTY([menhirLib])
103AC_COCCI_INIT_PKG_EMPTY([extlib])
104AC_COCCI_INIT_PKG_EMPTY([dynlink])
105AC_COCCI_INIT_PKG_EMPTY([pcre])
106AC_COCCI_INIT_PKG_EMPTY([pycaml])
107AC_COCCI_INIT_PKG_EMPTY([camlp4])
108
109dnl required ocaml packages
110AC_MSG_NOTICE([the following OCaml packages should be provided by your ocaml installation])
111AC_REQ_COCCI_STDPKG([unix])
112AC_REQ_COCCI_STDPKG([bigarray])
113AC_REQ_COCCI_STDPKG([num])
114AC_REQ_COCCI_STDPKG([str])
115AC_REQ_COCCI_STDPKG([threads])
116
117dnl required modules (Some are available locally too)
118AC_REQ_COCCI_EXTPKG([dynlink])
119AC_REQ_COCCI_EXTPKG([camlp4])
120AC_REQ_COCCI_EXTPKG([sexplib])
121AC_REQ_COCCI_EXTPKG([menhirLib])
122AC_REQ_COCCI_EXTPKG([extlib])
123
124
125AC_CACHE_SAVE
126
127
128dnl
129dnl Handling of optional features
130dnl
131
132AC_MSG_NOTICE([verifying optional features])
133
134
135dnl menhir handling
136dnl variables:
137dnl with_menhir: whether or not menhir must be used
138AC_COCCI_TOOL([MENHIR],[menhir],[$COCCI_SRCDIR/setup/fake-menhir.sh menhir])
139AS_IF([test "x$SUBSTITUTED_MENHIR" = xyes],
140[dnl
141 AC_MSG_NOTICE([pregenerated parsers will be required as substitute for Menhir])
142])
143
144
145dnl ocaml script handling
146dnl variables:
147dnl enable_ocaml: whether to enable ocaml scripts
148AC_ARG_ENABLE([ocaml], AS_HELP_STRING([--enable-ocaml], [enable ocaml scripting (default: auto)]))
149AS_IF([test "x$OCAML_PKG_dynlink" = xno],
150[dnl
151 AS_IF([test -z "$enable_ocaml"],
152 [dnl
153 AC_SUBST([enable_ocaml],[no])
154 AC_MSG_NOTICE([ocaml scripting is disabled because the 'dynlink' package is not installed])
155 ], [test "x$enable_ocaml" != xno],
156 [dnl
157 AC_MSG_ERROR([the OCaml package dynlink is required for ocaml scripting])
158 ])
159])
160
161dnl too old ocaml version, disable dynlink by default
162AS_IF([test "x$OCAMLATLEAST311" = xno],
163[dnl
164 AC_SUBST([enable_ocaml],[no])
165 AC_MSG_NOTICE([ocaml scripting has been disabled because your OCaml version may not support dynamic linking properly])
166])
167
168dnl scripting requirement on ocamlfind
169AS_IF([test -n "$SUBSTITUTED_OCAMLFIND"],
170[dnl
171 AS_IF([test -z "$enable_ocaml"],
172 [dnl this is perhaps a bit too strict
173 AC_SUBST([enable_ocaml],[no])
174 AC_MSG_NOTICE([ocaml scripting is disabled because it depends on ocamlfind])
175 ], [test "x$enable_ocaml" != xno],
176 [dnl
177 AC_MSG_NOTICE([warning: ocamlfind is not found but may be required if ocaml scripts are used])
178 ])
179])
180
181dnl scripting requirement on camlp4
182AS_IF([test "x$CAMLP4" = xno],
183[dnl
184 AS_IF([test -z "$enable_ocaml"],
185 [dnl this is perhaps a bit too strict
186 AC_SUBST([enable_ocaml],no)
187 AC_MSG_NOTICE([ocaml scripting is disabled because it depends on camlp4])
188 ], [test "x$enable_ocaml" != xno],
189 [dnl
190 AC_MSG_NOTICE([warning: camlp4 is not found but may be required if ocaml scripts are used])
191 ])
192])
193
194AS_IF([test "x$enable_ocaml" = xno],
195[dnl
196 AC_COCCI_INIT_PKG_EMPTY([dynlink]) dnl prevent linking with it
197 AC_SUBST(OCAMLCOCCI_MODULE,[No_prepare_ocamlcocci])
198 AC_SUBST(OCAMLCOCCI_FILE,[no_prepare_ocamlcocci.ml])
199],
200[dnl
201 AC_SUBST([enable_ocaml],[yes])
202 AC_SUBST(OCAMLCOCCI_MODULE,[Yes_prepare_ocamlcocci])
203 AC_SUBST(OCAMLCOCCI_FILE,[yes_prepare_ocamlcocci.ml])
204])
205
206
207dnl python handling
208dnl variables:
209dnl with_python: whether to enable the python feature (and what version)
210dnl OCAML_PKG_pycaml: if "local" use local pycaml package
211AC_ARG_VAR([PYTHON], [path to python when the version is determined automatically])
212AC_ARG_ENABLE([python], [AS_HELP_STRING([--enable-python], [enable python scripting (yes/no) (default: auto)])])
213AS_IF([test "x$enable_python" != xno],
214[dnl
215 dnl an explicitly set --with-python disablees by default the global pycaml
216 AS_IF([test -n "$enable_python" -a -z "$enable_pycaml"],
217 [dnl if explicit python given:
218 AC_MSG_NOTICE([skipped the selection of a global pycaml module because --enable-python is given explicitly but --enable-pycaml is not.])
219 AC_SUBST([enable_pycaml],[no])
220 ])
221
222 dnl sets "$PYVER" if python is available
223 AC_COCCI_PYVER
224
225 AS_IF([test -z "$PYVER"],
226 [dnl PYVER undetermined
227 AS_IF([test "x$enable_python" = xyes],
228 [dnl
229 AC_MSG_ERROR([python scripting is enabled explicitly but the version of python could not be determined])
230 ])
231 ],
232 [dnl
233 PKG_CHECK_MODULES([PYTHON], [python-$PYVER],[AC_SUBST(HAVE_PYTHON,[yes])],[AC_SUBST(HAVE_PYTHON,[no])])
234
235 AS_IF([test "x$HAVE_PYTHON" != xyes -a "x$enable_python" != xyes],
236 [dnl fallback if the above failed
237 AC_MSG_NOTICE([trying the default python version as fallback])
238 PKG_CHECK_MODULES([PYTHON], [python],[AC_SUBST(HAVE_PYTHON,[yes])],[AC_SUBST(HAVE_PYTHON,[no])])
239 ])
240 ])
241])
242
243AS_IF([test -z "$enable_python"],
244[dnl
245 AS_IF([test "x$HAVE_PYTHON" = xyes],
246 [dnl
247 AC_SUBST([enable_python],[yes])
248 ],
249 [dnl
250 AC_SUBST([enable_python],[no])
251 ])
252])
253
254AS_IF([test "x$enable_python" != xno],
255[dnl
256 AS_IF([test "x$HAVE_PYTHON" = xyes],
257 [dnl
258 AC_MSG_NOTICE([support for python scripts is enabled])
259 ],
260 [dnl
261 AC_MSG_ERROR([the python scripts feature is enabled but the pkg-config python library is not found])
262 ])
263
264 AC_REQ_COCCI_EXTPKG([pycaml])
265 AC_SUBST([PYCOCCI_MODULE], [Yes_pycocci])
266 AC_SUBST([PYCOCCI_FILE],[yes_pycocci.ml])
267],
268[dnl
269 AC_COCCI_INIT_PKG_EMPTY([pycaml])
270 AC_SUBST([PYCOCCI_MODULE], [No_pycocci])
271 AC_SUBST([PYCOCCI_FILE],[no_pycocci.ml])
272])
273
274
275dnl pcre handling
276dnl variables:
277dnl enable_pcre: whether to enable the pcre feature
278dnl OCAML_PKG_pcre: if "local" use str package
279AC_ARG_ENABLE([pcre-syntax], AS_HELP_STRING([--enable-pcre-syntax], [enable pcre regular expression syntax (default: auto)]))
280AS_IF([test "x$enable_pcre_syntax" != "xno"],
281[dnl
282 PKG_CHECK_MODULES([PCRE], [libpcre],[AC_SUBST([HAVE_PCRE],[yes])],[AC_SUBST([HAVE_PCRE],[no])])
283 AS_IF([test -z "$enable_pcre_syntax" -a "x$HAVE_PCRE" != xyes],
284 [dnl
285 AC_SUBST([enable_pcre_syntax],[no])
286 ],
287 [dnl
288 AC_CHECK_COCCI_EXTPKG([pcre]) dnl will set $enable_pcre to 'yes', 'no', or 'local'
289 enable_pcre_syntax=$enable_pcre
290 ])
291])
292
293AS_IF([test "x$enable_pcre_syntax" != xno],
294[dnl
295 AS_IF([test "x$HAVE_PCRE" = xyes],
296 [dnl
297 AC_MSG_NOTICE([support for pcre syntax is enabled])
298 ],
299 [dnl
300 AC_MSG_ERROR([the pcre feature is enabled but the pkg-config libpcre library is not found])
301 ])
302
303 AC_SUBST([REGEXP_MODULE], [Regexp_pcre])
304 AC_SUBST([REGEXP_FILE], [regexp_pcre.ml])
305],
306[dnl
307 AC_COCCI_INIT_PKG_EMPTY([pcre])
308 AC_SUBST([REGEXP_MODULE], [Regexp_str])
309 AC_SUBST([REGEXP_FILE], [regexp_str.ml])
310])
311
312
313AC_CACHE_SAVE
314
315
316dnl obtain the value of $prefix
317AS_IF([test "$prefix" = "NONE"],[prefix=$ac_default_prefix])
318
319
320dnl
321dnl backwards compatibility
322dnl
323
324dnl defines some variables needed by the Make infrastructure
325AC_SUBST(SHAREDIR,["${prefix}/share/coccinelle"])
326
327AS_IF([test "x$enable_python" != xno],
328[dnl
329 AC_SUBST(FEATURE_PYTHON,[1])
330],
331[dnl
332 AC_SUBST(FEATURE_PYTHON,[0])
333])
334
335AS_IF([test "x$enable_ocaml" != xno],
336[dnl
337 AC_SUBST(FEATURE_OCAML,[1])
338],
339[dnl
340 AC_SUBST(FEATURE_OCAML,[0])
341])
342
343dnl dynlink stuff depending on the OCaml version and whether it is enabled
344AS_IF([test "x$OCAMLATLEAST311" = xyes -a "x$enable_ocaml" = xyes],
345[dnl
346 AC_SUBST([DYNLINK_IS_NATIVE],[Dynlink.is_native])
347],
348[dnl
349 AC_SUBST([DYNLINK_IS_NATIVE],[false])
350])
351
352dnl in case of the compilation of the manual
353AC_COCCI_TOOL([PDFLATEX],[pdflatex],[$COCCI_SRCDIR/setup/fake-pdflatex.sh pdflatex])
354
355
356dnl
357dnl determine the default make target
358dnl if ocamlopt is availabe, the default is both
359dnl the bytecode version and the optimized version
360dnl of coccinelle.
361dnl
362
363AC_ARG_ENABLE([release], [AS_HELP_STRING([--enable-release], [build with a release configuration (yes,no, default: no)])])
364
365AS_IF([test "x$OCAMLOPT" = xno],
366[dnl
367 AS_IF([test "x$enable_release" = xyes],
368 [dnl
369 AC_MSG_ERROR([a release build is requested, but ocamlopt is not available])
370 ])
371
372 AC_SUBST([enable_release],[no])
373])
374
375AS_IF([test "x$OCAMLVERSION" = x3.11.2 -a "x$enable_release" != xyes],
376[dnl the optimized version may not be buildable with ocaml 3.11.2 (know bug), hence disable it by default
377 AC_MSG_NOTICE([the optimized version of coccinelle will not be build by default due to OCaml version $OCAMLVERSION and --enable-build-all is not given to override this decision])
378 AC_SUBST([enable_release],[no])
379])
380
381AS_IF([test -z "$enable_release"],
382[dnl
383 AC_MSG_NOTICE([choosing the development Makefile configuration because the release configuration is not explicitly requested.])
384 AC_SUBST([enable_release], [no])
385])
386
387AS_IF([test "x$enable_release" = xyes],
388[dnl include the optimized version by default
389 AC_SUBST([MAKETARGET_ALL], [all-release])
390], [test "x$enable_release" = xno],
391[dnl otherwise, exclude the optimized version
392 AC_SUBST([MAKETARGET_ALL], [all-dev])
393],
394[dnl custom target given
395 AC_SUBST([MAKETARGET_ALL], ["$enable_release"])
396])
397
398dnl which spatch will be constructed
399AS_IF([test "x$enable_release" != xno],[SPATCHNAME=spatch.opt],[SPATCHNAME=spatch])
400
401
402dnl
403dnl generating configuration
404dnl
405
406AC_CONFIG_FILES([Makefile.config])
407AC_CONFIG_FILES([version.ml])
408AC_CONFIG_FILES([commons/commands.ml])
409AC_CONFIG_FILES([globals/config.ml])
410AC_CONFIG_FILES([globals/regexp.ml])
411AC_CONFIG_FILES([python/pycocci.ml])
412AC_CONFIG_FILES([ocaml/prepare_ocamlcocci.ml])
413AC_CONFIG_FILES([scripts/spatch.sh])
414AC_CONFIG_FILES([docs/spatch.1])
415
416AC_OUTPUT
417
418AC_MSG_NOTICE([configuration completed])
419
420cat << EOF
421------------------------------------------------------------------------------
422Summary
423
424findlib: $OCAMLFIND
425menhir: $MENHIR
426menhirLib module: $OCAML_PKG_menhirLib
427
428ocaml scripting: $enable_ocaml
429python scripting: $enable_python
430pycaml module: $enable_pycaml
431
432pcre regexes: $enable_pcre_syntax
433pcre module: $enable_pcre
434pcre library: $HAVE_PCRE
435
436release config: $enable_release
437
438EOF
439
440cat << EOF
441------------------------------------------------------------------------------
442Coccinelle can now be compiled and installed.
443
444
445If you compile coccinelle again after source code changes or
446configuration changes, you may need to run first:
447 \$ make clean
448
449To compile coccinelle, run:
450 \$ make all
451
452To install coccinelle, run:
453 \$ make install
454
455Then, to test coccinelle run for example:
456 \$ $SPATCHNAME -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c
457EOF
458
459if test "x$enable_python" != "xno"; then
460cat << EOF
461------------------------------------------------------------------------------
462You may need to set some environment variables so that the python
463libraries are found. The frontend 'spatch' sets the following variables:
464
465 \$ export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
466 \$ export PYTHONPATH=\$PYTHONPATH:$prefix/share/coccinelle/python
467
468EOF
469fi
470
471cat << EOF
472------------------------------------------------------------------------------
473EOF