~npalix/coccinelle/upstream

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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
dnl  run 'autoreconf' to obtain aclocal.m4, and update configure and setup/pkg.m4
dnl  run 'automake -acf' to update setup/{install-sh,missing}

dnl  standard initialization (we only use autoconf not automake)
AC_PREREQ([2.68])
AC_INIT([coccinelle], m4_esyscmd([./version.sh]), [cocci@systeme.lip6.fr], [], [http://coccinelle.lip6.fr/])

AC_CONFIG_MACRO_DIR([setup])
AC_CONFIG_AUX_DIR([setup])
AC_SUBST([CONFIGURE_FLAGS], ["$*"])
AC_SUBST([COCCI_VERSION], ["$PACKAGE_VERSION"])
AC_SUBST([COCCI_SRCDIR], ["$(pwd)"])
AC_MSG_NOTICE([configuring coccinelle $COCCI_VERSION in $COCCI_SRCDIR])
AM_INIT_AUTOMAKE

AC_CONFIG_SRCDIR([cocci.ml])    dnl  this file must be present in our src directory
AC_COCCI_CONFVERSION

dnl  reminder that this configure depends on macros generated by aclocal
AC_MSG_NOTICE([this configure program uses pkg-config m4 macros])
AC_MSG_NOTICE([this configure program uses ocaml m4 macros (see setup/ocaml.m4)])
AC_MSG_NOTICE([this configure program uses custom m4 macros (see setup/cocci.m4)])
AC_MSG_NOTICE([some fake substitutions for required but unavailable programs may be used (see setup/fake*)])


dnl
dnl  Note: the conditionals in this configure script are tricky.
dnl  The approach taken here is that many tools can be enabled/disabled
dnl  and paths can be given explicitly via commandline parameters or
dnl  environment variables.
dnl


dnl
dnl  Basic tools
dnl

AC_MSG_NOTICE([verifying basic tools])

AC_PROG_INSTALL
AC_PROG_MKDIR_P
AC_PROG_CPP
AC_PATH_PROG([BASH],[bash])
AC_PATH_PROG([TAR],[tar])
AC_PATH_PROG([PATCH],[patch])
AC_PATH_PROG([ECHO],[echo])

dnl  ensures that INSTALL points to an absolute install-sh when that one is configured.
AS_IF([test "$INSTALL" = "setup/install-sh -c" -o "$INSTALL" = "./setup-install-sh -c"],
[dnl
  AC_SUBST([INSTALL], ["$COCCI_SRCDIR/$INSTALL"])
])

dnl  the same for MKDIR_P
AS_IF([test "$MKDIR_P" = "setup/install-sh -c -d" -o "$INSTALL" = "./setup-install-sh -c -d"],
[dnl
  AC_SUBST([MKDIR_P], ["$COCCI_SRCDIR/$MKDIR_P"])
])

dnl Try to ensure that ECHO will support -e option to handle \t and \n
AS_IF([test "`$ECHO --version`" =  "--version"],
[dnl
  AC_SUBST([ECHO],["$COCCI_SRCDIR/setup/echo.sh"])
])
 
dnl  patchelf is an optional dependency and in principle not used for building coccinelle
AC_PATH_PROG([PATCHELF],[patchelf])

dnl  pkg config is required, but we have an alternative script for it
AC_COCCI_TOOL([PKG_CONFIG],[pkg-config])
AS_IF([test "x$PKG_CONFIG" = xno],
[dnl  no specific pkg-config configured
  AC_SUBST([PKG_CONFIG_ORIG],[pkg-config])
],
[dnl  a specific pkg-config configured
  AC_SUBST([PKG_CONFIG_ORIG],[$PKG_CONFIG])
])

dnl  always use the wrapper around pkg-config
AC_SUBST([PKG_CONFIG],["$COCCI_SRCDIR/setup/fake-subst.sh $PKG_CONFIG_ORIG"])


dnl  ocaml compiler configuration
AC_PROG_OCAML
AC_CHECK_OCAMLVERSION([OCAMLATLEAST312],[3.12])
AS_IF([test "x$OCAMLATLEAST312" = xno],[AC_MSG_ERROR([OCaml >= 3.12 is required to compile Coccinelle])])
AC_CHECK_OCAMLVERSION([OCAMLATLEAST4020],[4.02])
AC_CHECK_OCAMLVERSION([OCAMLATLEAST4030],[4.03])
AC_CHECK_OCAMLVERSION([OCAMLATLEAST50],[5.0])
AC_SUBST([OCAMLCORIG],["$OCAMLC"])

AS_IF([test "x$OCAMLC" = xno -o "x$OCAMLDEP" = xno -o "x$OCAMLMKLIB" = xno],
[dnl
  AC_MSG_ERROR([It seems a few components of the OCaml distribution could not be found. Make sure the following tools are installed and in your path: ocamlc, ocamldep, ocamlmklib.])
])

dnl  ocaml tools
AC_COCCI_TOOL([OCAMLLEX],[ocamllex],[])
AC_COCCI_TOOL([OCAMLYACC],[ocamlyacc],[])
AC_COCCI_TOOL([OCAMLFIND],[ocamlfind],[$COCCI_SRCDIR/setup/fake-subst.sh ocamlfind])
AC_COCCI_TOOL([OCAMLPROF],[ocamlprof],[])

dnl  enforce ocaml tool requirements
AS_IF([test "x$OCAMLLEX" = xno],
[dnl
  AC_MSG_ERROR([the OCaml Lexer needs to be installed (the ocamllex command). It should be part of your OCaml distribution.])
])

AS_IF([test "x$OCAMLYACC" = xno],
[dnl
  AC_MSG_ERROR([The OCaml parser generated needs to be installed (the ocamlyacc command). It should be part of your OCaml distribution.])
])

AS_IF([test "x$OCAMLFIND" = xno],
[dnl
  AC_MSG_ERROR([A suitable OCaml findlib (the ocamlfind command) could not be found.])
])

dnl  these runtime commands can also be passed as runtime flags to spatch.
AC_COCCI_RUNTIME_CMD([OCAMLFIND],[ocamlfind])
AC_COCCI_RUNTIME_CMD([OCAMLC],[ocamlc])
AC_COCCI_RUNTIME_CMD([OCAMLOPT],[ocamlopt])
AC_COCCI_RUNTIME_CMD([OCAMLDEP],[ocamldep])

dnl  AC_CACHE_SAVE


dnl
dnl  Basic ocaml modules
dnl

AC_MSG_NOTICE([verifying basic ocaml modules])

dnl  default dir with the bundled ocaml packages
AC_COCCI_SET_EXTERNAL_DIR([$COCCI_SRCDIR/bundles])

dnl  set some defaults
dnl  add a line for each package that is
dnl  configured via AC_CHECK_COCCI_EXTPKG
dnl  or AC_REQ_COCCI_EXTPKG
AC_COCCI_INIT_PKG_EMPTY([dynlink])
AC_COCCI_INIT_PKG_EMPTY([pcre])
AC_COCCI_INIT_PKG_EMPTY([bytes]) dnl for recent versions of pcre on old OCaml
AC_COCCI_INIT_PKG_EMPTY([pyml])
AC_COCCI_INIT_PKG_EMPTY([stdcompat])
AC_COCCI_INIT_PKG_EMPTY([parmap])

dnl  required ocaml packages
AC_MSG_NOTICE([the following OCaml packages should be provided by your ocaml installation])
AC_REQ_COCCI_STDPKG([unix])
AS_IF([test "x$OCAMLATLEAST50" = xno],[AC_REQ_COCCI_STDPKG([bigarray])])
AC_REQ_COCCI_STDPKG([str])

dnl  required modules (Some are available locally too)
AC_REQ_COCCI_EXTPKG([dynlink])
AC_REQ_COCCI_EXTPKG([parmap])
AC_REQ_COCCI_EXTPKG([stdcompat])

AS_IF([test "x$enable_stdcompat" = "xyes"],
  [AC_MSG_CHECKING([if installed stdcompat provides In_channel])
   echo "Stdcompat.In_channel.stdin" > configure_test.ml
   AS_IF([$OCAMLFIND c -package stdcompat -c configure_test.ml >/dev/null 2>/dev/null],
     [AC_MSG_RESULT([yes])],
     [AC_MSG_RESULT([no])
      AC_SUBST([enable_stdcompat], [local])
      AC_SUBST([MAKE_stdcompat],[$COCCI_SRCDIR/bundles/stdcompat])
      AC_SUBST([PATH_stdcompat],[$COCCI_SRCDIR/bundles/stdcompat])])
   rm -f configure_test.ml configure_test.cmo configure_test.cmi configure_test.cmt])

dnl  AC_CACHE_SAVE


dnl
dnl  Handling of optional features
dnl

AC_MSG_NOTICE([verifying optional features])

dnl  test if the optimized version of dynlink is available
AS_IF([test "x$OCAML_PKG_dynlink" != xno -a -f "$PATH_dynlink/dynlink.cmxa"],
[dnl  yes
  AC_SUBST([OPTIMIZED_dynlink], [yes])
],
[dnl  no
  AC_SUBST([OPTIMIZED_dynlink], [no])
])


dnl  menhir handling
dnl  variables:
dnl    with_menhir: whether or not menhir must be used
AC_SUBST([PATH_menhirLib_bundle], [$COCCI_SRCDIR/bundles/menhirLib])
AC_SUBST([PATH_menhir_bundle], [$PATH_menhirLib_bundle/menhir])

AC_COCCI_TOOL([MENHIR],[menhir],[$PATH_menhir_bundle])

AS_IF([test "x$SUBSTITUTED_MENHIR" != xyes],
[dnl
  AC_SUBST([MAKE_menhirLib],[])
  AS_IF([$MENHIR --help | grep suggest-menhirLib >/dev/null],
    [dnl
      AC_MSG_NOTICE([system menhir will be used])
      AC_SUBST([PATH_menhirLib],[`$MENHIR --suggest-menhirLib`])
    ],
    [dnl
      AS_IF([test -n "$OCAMLFIND"],
        [dnl
          AC_MSG_NOTICE([system menhir will be used])
          AC_SUBST([PATH_menhirLib],[`$OCAMLFIND query menhirLib`])
        ],
        [dnl
          AC_MSG_NOTICE(
            [system menhirLib cannot be found: bundled menhir will be used instead])
          AC_SUBST([MENHIR], [$PATH_menhir_bundle])
          AC_SUBST([SUBSTITUTED_MENHIR], [yes])
        ])
    ])
])

AC_SUBST([FEATURE_menhirLib], [1])

AS_IF([test "x$SUBSTITUTED_MENHIR" = xyes],
[dnl
  AC_SUBST([PATH_menhirLib], [$PATH_menhirLib_bundle])
  AC_SUBST([MAKE_menhirLib], [$PATH_menhirLib])
])

AC_SUBST([FLAGS_menhirLib], [])
AC_SUBST([OPTFLAGS_menhirLib], [])
AC_SUBST([MODULES_menhirLib], [])
AC_SUBST([MODULESOPT_menhirLib], [])

AC_MSG_CHECKING([if menhir supports -O 1])

dnl lower menhir optimization level if menhir version allows it
dnl (i.e. >=20211230)
AS_IF([$MENHIR -O 1 --version >/dev/null 2>/dev/null],
  [dnl
    AC_MSG_RESULT([yes])
    AC_SUBST([DEFAULT_MENHIR_FLAGS], [["-O 1"]])],
  [dnl
    AC_MSG_RESULT([no])
    AC_SUBST([DEFAULT_MENHIR_FLAGS], [])])

dnl  ocaml script handling
dnl  variables:
dnl    enable_ocaml: whether to enable ocaml scripts
AC_ARG_ENABLE([ocaml], AS_HELP_STRING([--enable-ocaml], [enable ocaml scripting (default: auto)]))
AS_IF([test "x$OCAML_PKG_dynlink" = xno],
[dnl
  AS_IF([test -z "$enable_ocaml"],
  [dnl
    AC_SUBST([enable_ocaml], [no])
    AC_MSG_NOTICE([ocaml scripting is disabled because the 'dynlink' package is not installed])
  ], [test "x$enable_ocaml" != xno],
  [dnl
    AC_MSG_ERROR([the OCaml package dynlink is required for ocaml scripting])
  ])
])

dnl  no optimized version, disable dynlink by default
AS_IF([test "x$OPTIMIZED_dynlink" = xno],
[dnl
  AS_IF([test -z "$enable_ocaml"],
  [dnl
    AC_SUBST([enable_ocaml], [no])
    AC_MSG_NOTICE([ocaml scripting has been disabled by default because the optimized version of dynlink is not available])
  ], [test "x$enable_ocaml" = xyes],
  [dnl
    AC_MSG_NOTICE([warning: the optimized version of dynlink is not available, thus ocaml scripting may not work])
  ])
])

dnl  scripting requirement on ocamlfind
AS_IF([test -n "$SUBSTITUTED_OCAMLFIND"],
[dnl
  AS_IF([test -z "$enable_ocaml"],
  [dnl  this is perhaps a bit too strict
    AC_SUBST([enable_ocaml],[no])
    AC_MSG_NOTICE([ocaml scripting is disabled because it depends on ocamlfind])
  ], [test "x$enable_ocaml" != xno],
  [dnl
    AC_MSG_NOTICE([warning: ocamlfind is not found but may be required when ocaml scripts are used])
  ])
])

AS_IF([test "x$enable_ocaml" = xno],
[dnl
  AC_COCCI_INIT_PKG_EMPTY([dynlink])    dnl  prevent linking with it
  AC_SUBST([OCAMLCOCCI_MODULE], [No_prepare_ocamlcocci])
  AC_SUBST([OCAMLCOCCI_FILE], [no_prepare_ocamlcocci.ml])
],
[dnl
  AC_SUBST([enable_ocaml], [yes])
  AC_SUBST([OCAMLCOCCI_MODULE], [Yes_prepare_ocamlcocci])
  AC_SUBST([OCAMLCOCCI_FILE], [yes_prepare_ocamlcocci.ml])
])


dnl  python handling
dnl  variables:
dnl    with_python: whether to enable the python feature (and what version)
AC_ARG_ENABLE([python], [AS_HELP_STRING([--enable-python], [enable python scripting (yes/no) (default: auto)])])

AC_ARG_WITH([python], [AS_HELP_STRING([--with-python], [which python interpreter to use (default: python)])])

AS_IF([test -n "$with_python" -a "$with_python" != "yes"],
[dnl
  AC_SUBST([PYTHON], ["$with_python"])
],
[dnl
  AC_SUBST([PYTHON], ["python"])
])

AS_IF([test "x$enable_python" != xno],
[dnl
  AC_CHECK_COCCI_EXTPKG([pyml])  dnl  will set $enable_pyml to 'yes', 'no', or 'local'

  AS_IF([test "x$enable_pyml" = "xyes"],
    AS_IF([test "x$enable_stdcompat" = "xlocal"],
      [AC_MSG_NOTICE([pyml bundle will be used instead to be compatible with stdcompat bundle])
       AC_SUBST([enable_pyml],[local])],
      [AC_MSG_CHECKING([if installed pyml provides Class.init with list of parent classes])
       [[echo "Py.Class.init ~parents:[]" > configure_test.ml]]
       AS_IF([$OCAMLFIND c -package pyml -c configure_test.ml > /dev/null 2>/dev/null],
         [AC_MSG_RESULT([yes])],
         [AC_MSG_RESULT([no])
          AC_SUBST([enable_pyml],[local])])
       rm -f configure_test.ml configure_test.cmo configure_test.cmi configure_test.cmt])
    AS_IF([test "x$enable_pyml" = "xlocal"],
      [AC_SUBST([MODULES_pyml],[$COCCI_SRCDIR/bundles/pyml/pyml.cma])
       AC_SUBST([MAKE_pyml],[$COCCI_SRCDIR/bundles/pyml])
       AC_SUBST([PATH_pyml],[$COCCI_SRCDIR/bundles/pyml])])
  )])

AS_IF([test -z "$enable_python"],
[dnl
  AS_IF([test "x$enable_pyml" != xno],
  [dnl
    AC_SUBST([enable_python], [yes])
  ],
  [dnl
    AC_SUBST([enable_python], [no])
  ])
])

AS_IF([test "x$enable_python" != xno],
[dnl
  AC_SUBST([PYCOCCI_MODULE], [Yes_pycocci])
  AC_SUBST([PYCOCCI_FILE],[yes_pycocci.ml])
],
[dnl
  AC_SUBST([PYCOCCI_MODULE], [No_pycocci])
  AC_SUBST([PYCOCCI_FILE],[no_pycocci.ml])
])


dnl  pcre handling
dnl  variables:
dnl    enable_pcre: whether to enable the pcre feature
dnl    OCAML_PKG_pcre: if "local" use str package
AC_ARG_ENABLE([pcre-syntax], AS_HELP_STRING([--enable-pcre-syntax], [enable pcre regular expression syntax (default: auto)]))
AS_IF([test "x$enable_pcre_syntax" != "xno"],
[dnl
  PKG_CHECK_MODULES([PCRE], [libpcre],[AC_SUBST([HAVE_PCRE],[yes])],[AC_SUBST([HAVE_PCRE],[no])])
  AS_IF([test -z "$enable_pcre_syntax" -a "x$HAVE_PCRE" != xyes],
  [dnl
    AC_SUBST([enable_pcre_syntax], [no])
  ],
  [dnl
    AS_IF([test "x$enable_pcre" = "xno"], [AC_SUBST([enable_pcre], [local])])
    AC_CHECK_COCCI_EXTPKG([pcre])  dnl  will set $enable_pcre to 'yes', 'no', or 'local'
    AS_IF([test "x$enable_pcre" = "xyes"],
    [dnl
      AC_MSG_CHECKING([if pcre depends on bytes])
      AS_IF([test "x`$OCAMLFIND query -r -format '%p' pcre 2>/dev/null | grep bytes`" = "xbytes"],
      [dnl
        AC_MSG_RESULT([yes])
        AC_MSG_CHECKING([if bytes is an actual module])
        AS_IF([test -f "`$OCAMLFIND query bytes`/bytes.cma"],
        [dnl
          AC_MSG_RESULT([yes])
          AC_CHECK_COCCI_EXTPKG([bytes])
        ],
        [dnl
          AC_MSG_RESULT([no])
        ])
      ],
      [dnl
        AC_MSG_RESULT([no])
      ])
    ])
  ])
])

AS_IF([test "x$enable_pcre_syntax" != xno],
[dnl
  AS_IF([test "x$HAVE_PCRE" = xyes],
  [dnl
    AC_MSG_NOTICE([support for pcre syntax is enabled])
  ],
  [dnl
    AC_MSG_ERROR([the pcre feature is enabled but the pkg-config libpcre library is not found])
  ])

  AC_SUBST([REGEXP_MODULE], [Regexp_pcre])
  AC_SUBST([REGEXP_FILE], [regexp_pcre.ml])
],
[dnl
  AC_COCCI_INIT_PKG_EMPTY([pcre])
  AC_SUBST([REGEXP_MODULE], [Regexp_str])
  AC_SUBST([REGEXP_FILE], [regexp_str.ml])
])


dnl  AC_CACHE_SAVE


dnl  obtain the value of $prefix
AS_IF([test "$prefix" = "NONE"],[prefix=$ac_default_prefix])


dnl
dnl  backwards compatibility
dnl

dnl  defines some variables needed by the Make infrastructure
AC_SUBST([LIBDIR],["${libdir}/coccinelle"])

AS_IF([test "x$enable_python" != xno],
[dnl
  AC_SUBST([FEATURE_PYTHON], [1])
],
[dnl
  AC_SUBST([FEATURE_PYTHON], [0])
])

AS_IF([test "x$enable_ocaml" != xno],
[dnl
  AC_SUBST([FEATURE_OCAML], [1])
],
[dnl
  AC_SUBST([FEATURE_OCAML], [0])
])

dnl  dynlink stuff depending on the OCaml version and whether it is enabled
AS_IF([test "x$enable_ocaml" = xyes -a "x$OCAMLOPT" != xno],
[dnl
  AC_SUBST([DYNLINK_IS_NATIVE], [Dynlink.is_native])
],
[dnl
  AC_SUBST([DYNLINK_IS_NATIVE], [false])
])

AS_IF([test "x$OCAMLATLEAST4020" = xno  ],
[dnl
  AC_SUBST([GET_TEMP_DIR_NAME_EXPR], ["Filename.temp_dir_name"])
],
[dnl
  AC_SUBST([GET_TEMP_DIR_NAME_EXPR], ["(Filename.get_temp_dir_name ())"])
])


dnl  in case of the compilation of the manual
AC_COCCI_TOOL([PDFLATEX],[pdflatex],[$COCCI_SRCDIR/setup/fake-pdflatex.sh pdflatex])


dnl  determine whether to build the optimizing version
AC_ARG_ENABLE([opt], [AS_HELP_STRING([--enable-opt], [build an optimized spatch (yes,no, default: auto)])])
AS_IF([test "x$OCAMLOPT" = xno -a "x$enable_opt" != xno],
[dnl
  AS_IF([test "x$enable_opt" = xyes],
  [dnl
    AC_MSG_ERROR([the optimized version of coccinelle is requested explicitly, but ocamlopt is absent])
  ],
  [dnl
    AC_MSG_NOTICE([the optimized version of coccinelle will not be build because ocamlopt is not present])
    AC_SUBST([enable_opt], [no])
  ])
])

dnl  disable the optimized target when dynlinking is enabled but the optimized version of dynlink is not available
AS_IF([test "x$OPTIMIZED_dynlink" = xno -a "x$enable_ocaml" = xyes],
[dnl
  AS_IF([test -z "$enable_opt"],
  [dnl
    AC_MSG_NOTICE([the optimized version of coccinelle will not be build by default because ocaml scripting is enabled but the required optimized dynlink package is not present])
    AC_SUBST([enable_opt], [no])
  ], [test "x$enable_opt" = xyes],
  [dnl
    AC_MSG_ERROR([the optimized version of coccinelle in combination with ocaml scripting requires the optimized version of the dynlik package, which is not present])
  ])
])

dnl  set the default enable-opt setting
AS_IF([test -z "$enable_opt"],
[dnl
  AC_SUBST([enable_opt], ["yes"])
])

dnl  variables depending on whether we build the optimized spatch
AS_IF([test "x$enable_opt" = xyes],
[dnl  default target for the optimized version
  AC_SUBST([SPATCHNAME], [spatch.opt])
  AC_SUBST([MAKETARGET_SPATCH], [opt-only])
],
[dnl  default target for the bytecode version
  AC_SUBST([SPATCHNAME], [spatch])
  AC_SUBST([MAKETARGET_SPATCH], [byte-only])
])

dnl bash-completion directory
dnl (reported by Himanshu Jha,
dnl  solution inspired from https://www.swansontec.com/bash-completion.html )
dnl --with-bash-completion enables bash-completion (this is the default),
dnl   and allows the user to give a path. By default, path is given by
dnl   pkg-config if available, or $datarootdir/bash-completion/completions
dnl   otherwise
dnl --without-bash-completion disables bash-completion

AC_ARG_WITH([bash-completion],
    AS_HELP_STRING([--with-bash-completion[=PATH]],
        [Install the bash auto-completion script in this directory.\
         @<:@default=yes@:>@]),
    [],
    [AC_SUBST([with_bash_completion], [yes])])

AS_IF([test "x$with_bash_completion" = "xyes"],
    [dnl
      AS_IF([test "x$prefix" = "x/usr/local"],
      [dnl
       PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0],
        [AC_SUBST([BASH_COMPLETION_DIR],
                [[`pkg-config --variable=completionsdir bash-completion`]])],
        [AC_SUBST([BASH_COMPLETION_DIR],
                [$datarootdir/bash-completion/completions])])],
      [AC_SUBST([BASH_COMPLETION_DIR],
                [$datarootdir/bash-completion/completions])])],
    [dnl
     AC_SUBST([BASH_COMPLETION_DIR], [$with_bash_completion])])

AS_IF([test "$MAKE_stdcompat"],
  AC_CONFIG_SUBDIRS(bundles/stdcompat/stdcompat-current))

AS_IF([test "$MAKE_parmap"],
  AC_CONFIG_SUBDIRS(bundles/parmap))

AS_IF([test "$MAKE_pcre"],
  [AS_IF([test "x$OCAMLATLEAST4030" = xno  ],
    [AC_SUBST([CAMLnoreturn_start], [])
     AC_SUBST([CAMLnoreturn_end], [])],
    [AC_SUBST([CAMLnoreturn_start], [CAMLnoreturn_start])
     AC_SUBST([CAMLnoreturn_end], [CAMLnoreturn_end])])
   AS_IF([test "x$OCAMLATLEAST4020" = xno  ],
    [AC_SUBST([intnat], [value])
     AC_SUBST([Val_int], [Val_int])
     AC_SUBST([Val_Val_int], [])
     AC_SUBST([Int_val], [Int_val])
     AC_SUBST([Int_val_val], [])
     AC_SUBST([noalloc], [])
     AC_SUBST([untagged], [])
     AC_SUBST([CAMLnoreturn_start], [])
     AC_SUBST([CAMLnoreturn_end], [])],
    [AC_SUBST([intnat], [intnat])
     AC_SUBST([Val_int], [])
     AC_SUBST([Val_Val_int], [Val_int])
     AC_SUBST([Int_val], [])
     AC_SUBST([Int_val_val], [Int_val])
     AC_SUBST([noalloc], [[[@@noalloc]]])
     AC_SUBST([untagged], [[[@untagged]]])])
  AC_CONFIG_FILES([
    bundles/pcre/pcre-ocaml/src/pcre.ml
    bundles/pcre/pcre-ocaml/src/pcre_stubs.c
  ])])

dnl
dnl  generating configuration
dnl

AC_CONFIG_FILES([
  Makefile.config
  version.ml
  commons/commands.ml
  globals/config.ml globals/regexp.ml python/pycocci.ml
  ocaml/prepare_ocamlcocci.ml
  scripts/spatch.sh
  tools/spgen/scripts/spgen.sh
  docs/spatch.1
  setup/Makefile
])

AC_OUTPUT

AC_MSG_NOTICE([configuration completed])

cat << EOF
------------------------------------------------------------------------------
Summary

configure flags:  $CONFIGURE_FLAGS
findlib:          $OCAMLFIND	(an actual version is strongly recommended)
menhir:           $MENHIR
                  (for local package use --without-menhir,
                   install the menhir package otherwise)

ocaml scripting:  $enable_ocaml	(overridable with --enable-ocaml)
python scripting: $enable_python	(overridable with --enable-python)

pcre regexes:     $enable_pcre_syntax	(overridable with --enable-pcre-syntax)
pcre module:      $enable_pcre	(for local package use --disable-pcre)
pcre library:     $HAVE_PCRE	(requires the libpcre-ocaml-dev package)

optimized spatch: $enable_opt	(overridable with --disable-opt)

bash-completion:  $BASH_COMPLETION_DIR
                  (overridable with --with-bash-completion)

------------------------------------------------------------------------------
Coccinelle can now be compiled and installed.


If you compile coccinelle again after source code changes or
configuration changes, you may need to run first:
  \$ make clean

To compile coccinelle, run:
  \$ make

To install coccinelle, run:
  \$ make install

Then, to test coccinelle, run for example:
  \$ spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c

Or when coccinelle is not installed yet:
  \$ COCCINELLE_HOME=$(pwd) ./scripts/spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c
EOF

if test "x$enable_python" != "xno"; then
cat << EOF
------------------------------------------------------------------------------
You may need to set some environment variables so that the python
libraries are found. The frontend 'spatch' sets the following variables:

  \$ export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
  \$ export PYTHONPATH=\$PYTHONPATH:$libdir/coccinelle/python

EOF
fi

cat << EOF
------------------------------------------------------------------------------
EOF