Package: ocaml-shine / 0.2.1-1

0001-Add-autoconf-bootstrap-files.patch Patch series | download
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
From: Stephane Glondu <steph@glondu.net>
Date: Tue, 18 Aug 2020 06:46:42 +0200
Subject: Add autoconf bootstrap files

---
 m4/base_checks.m4       | 164 ++++++++++++++++++++++++
 m4/bootstrap            |  17 +++
 m4/cpp_check_class.m4   |  24 ++++
 m4/detect_binding.m4    | 186 +++++++++++++++++++++++++++
 m4/ocaml.m4             | 329 ++++++++++++++++++++++++++++++++++++++++++++++++
 m4/ocaml_compilers.m4   |  73 +++++++++++
 m4/pkg_config.m4        |  76 +++++++++++
 m4/strict_check_tool.m4 |   7 ++
 8 files changed, 876 insertions(+)
 create mode 100644 m4/base_checks.m4
 create mode 100755 m4/bootstrap
 create mode 100644 m4/cpp_check_class.m4
 create mode 100644 m4/detect_binding.m4
 create mode 100644 m4/ocaml.m4
 create mode 100644 m4/ocaml_compilers.m4
 create mode 100644 m4/pkg_config.m4
 create mode 100644 m4/strict_check_tool.m4

diff --git a/m4/base_checks.m4 b/m4/base_checks.m4
new file mode 100644
index 0000000..c956830
--- /dev/null
+++ b/m4/base_checks.m4
@@ -0,0 +1,164 @@
+AC_DEFUN([AC_BASE_CHECKS],
+[AC_REQUIRE([AC_PROG_CC])
+dnl check that running user is not root
+AC_MSG_CHECKING([that calling user is not root])
+RUNNING_USER="$USER"
+if test -z "$RUNNING_USER"; then
+  RUNNING_USER=`whoami`
+fi
+if test $RUNNING_USER = "root"; then
+  AC_MSG_ERROR([configure script must not be run with root user!])
+else
+  AC_MSG_RESULT([ok])
+fi
+
+dnl check for base compilers
+AC_CANONICAL_HOST()
+# AC_CANONICAL_HOST needs those files
+AUTOCONF_INSTALL_FILES="config.guess config.sub install-sh m4/*.m4"
+AC_SUBST(AUTOCONF_INSTALL_FILES)
+
+AC_PROG_CC()
+AC_PROG_INSTALL()
+AC_CHECK_TOOL([AR],[ar],no)
+AC_SUBST(AR)
+AC_CHECK_OCAML_COMPILERS()
+
+
+dnl add some flags
+AC_DETECT_PIC_FLAGS()
+
+CXXFLAGS="$CXXFLAGS $PIC_FLAGS"
+CPPFLAGS="$CPPFLAGS $PIC_FLAGS"
+
+# Add prefix to compilation variables
+# if passed
+if test "x$prefix" != "xNONE"; then
+  CFLAGS="$CFLAGS -I$prefix/include"
+  LDFLAGS="$LDFLAGS -L$prefix/lib"
+  CPPFLAGS="$CPPFLAGS -I$prefix/include"
+  CXXFLAGS="$CXXFLAGS -I$prefix/include"
+fi
+])
+
+dnl Check for basic stuff
+dnl The following was stolen from mesa..
+dnl A few convenience macros for Mesa, mostly to keep all the platform
+dnl specifics out of configure.ac.
+
+dnl AC_DETECT_PIC_FLAGS()
+dnl
+dnl Find out whether to build PIC code using the option --enable-pic and
+dnl the configure enable_static/enable_shared settings. If PIC is needed,
+dnl figure out the necessary flags for the platform and compiler.
+dnl
+dnl The platform checks have been shamelessly taken from libtool and
+dnl stripped down to just what's needed for Mesa. See _LT_COMPILER_PIC in
+dnl /usr/share/aclocal/libtool.m4 or
+dnl http://git.savannah.gnu.org/gitweb/?p=libtool.git;a=blob;f=libltdl/m4/libtool.m4;hb=HEAD
+dnl
+AC_DEFUN([AC_DETECT_PIC_FLAGS],
+[AC_ARG_VAR([PIC_FLAGS], [compiler flags for PIC code])
+AC_ARG_ENABLE([pic],
+    [AS_HELP_STRING([--disable-pic],
+        [compile PIC objects @<:@default=enabled for shared builds
+        on supported platforms@:>@])],
+    [enable_pic="$enableval"
+    test "x$enable_pic" = x && enable_pic=auto],
+    [enable_pic=auto])
+dnl disable PIC by default for static builds
+if test "$enable_pic" = auto && test "$enable_static" = yes; then
+    enable_pic=no
+fi
+dnl if PIC hasn't been explicitly disabled, try to figure out the flags
+if test "$enable_pic" != no; then
+    AC_MSG_CHECKING([for $CC option to produce PIC])
+    dnl allow the user's flags to override
+    if test "x$PIC_FLAGS" = "x"; then
+        dnl see if we're using GCC
+        if test "x$GCC" = "xyes"; then
+            case "$host_os" in
+            aix*|beos*|cygwin*|irix5*|irix6*|osf3*|osf4*|osf5*)
+                dnl PIC is the default for these OSes.
+                ;;
+            mingw*|os2*|pw32*)
+                dnl This hack is so that the source file can tell whether
+                dnl it is being built for inclusion in a dll (and should
+                dnl export symbols for example).
+                PIC_FLAGS="-DDLL_EXPORT"
+                ;;
+            darwin*|rhapsody*)
+                dnl PIC is the default on this platform
+                dnl Common symbols not allowed in MH_DYLIB files
+                PIC_FLAGS="-fno-common"
+                ;;
+            hpux*)
+                dnl PIC is the default for IA64 HP-UX and 64-bit HP-UX,
+                dnl but not for PA HP-UX.
+                case $host_cpu in
+                hppa*64*|ia64*)
+                    ;;
+                *)
+                    PIC_FLAGS="-fPIC"
+                    ;;
+                esac
+                ;;
+            *)
+                dnl Everyone else on GCC uses -fPIC
+                PIC_FLAGS="-fPIC"
+                ;;
+            esac
+        else dnl !GCC
+            case "$host_os" in
+            hpux9*|hpux10*|hpux11*)
+                dnl PIC is the default for IA64 HP-UX and 64-bit HP-UX,
+                dnl but not for PA HP-UX.
+                case "$host_cpu" in
+                hppa*64*|ia64*)
+                    dnl +Z the default
+                    ;;
+                *)
+                    PIC_FLAGS="+Z"
+                    ;;
+                esac
+                ;;
+            linux*|k*bsd*-gnu)
+                case `basename "$CC"` in
+                icc*|ecc*|ifort*)
+                    PIC_FLAGS="-KPIC"
+                    ;;
+                pgcc*|pgf77*|pgf90*|pgf95*)
+                    dnl Portland Group compilers (*not* the Pentium gcc
+                    dnl compiler, which looks to be a dead project)
+                    PIC_FLAGS="-fpic"
+                    ;;
+                ccc*)
+                    dnl All Alpha code is PIC.
+                    ;;
+                xl*)
+                    dnl IBM XL C 8.0/Fortran 10.1 on PPC
+                    PIC_FLAGS="-qpic"
+                    ;;
+                *)
+                    case `$CC -V 2>&1 | sed 5q` in
+                    *Sun\ C*|*Sun\ F*)
+                        dnl Sun C 5.9 or Sun Fortran
+                        PIC_FLAGS="-KPIC"
+                        ;;
+                    esac
+                esac
+                ;;
+            solaris*)
+                PIC_FLAGS="-KPIC"
+                ;;
+            sunos4*)
+                PIC_FLAGS="-PIC"
+                ;;
+            esac
+        fi
+    fi 
+    AC_MSG_RESULT([$PIC_FLAGS])
+fi
+AC_SUBST([PIC_FLAGS])
+])dnl PIC_FLAGS
+
diff --git a/m4/bootstrap b/m4/bootstrap
new file mode 100755
index 0000000..6e07105
--- /dev/null
+++ b/m4/bootstrap
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+if [ -d m4 ]; then
+  OPTIONS="-I m4"
+  aclocal -I m4
+fi
+autoreconf -f -i $OPTIONS $1
+# autoconf maintainers have not yet implemented
+# a function to install missing files from autoconf
+# itself, so we need to fake a call to automake here..
+automake -a -c -f 2>/dev/null || true
+if [ -d examples ]; then
+  if [ -f examples/configure.ac ]; then
+    cd examples
+    autoreconf -f -i
+  fi
+fi
diff --git a/m4/cpp_check_class.m4 b/m4/cpp_check_class.m4
new file mode 100644
index 0000000..fb3d299
--- /dev/null
+++ b/m4/cpp_check_class.m4
@@ -0,0 +1,24 @@
+dnl $1: linker lib name
+dnl $2: included file
+dnl $3: tested class
+dnl $4: emitted variable
+AC_DEFUN([AC_CPP_CHECK_CLASS],
+[AC_LANG_PUSH([C++])
+ SAVED_LDFLAGS=$LDFLAGS
+ LDFLAGS="$LDFLAGS -l$1"
+ AC_MSG_CHECKING([for class $3 in $1 library])
+ AC_LINK_IFELSE(
+   [AC_LANG_PROGRAM([#include <$2>],
+     [$3 *x = NULL])],
+   [TEST_LIBS="$TEST_LIBS -l$1"] [RESULT=1],
+   [RESULT=])
+ if test -z $RESULT; then
+   AC_MSG_RESULT([not found])
+ else
+   AC_DEFINE([$4], [1], [Defined if class $3 has been found in $1 library])
+   AC_MSG_RESULT([ok])
+ fi
+ $4=$RESULT
+ AC_SUBST([$4])
+ LDFLAGS=$SAVED_LDFLAGS
+ AC_LANG_POP([C++])])
diff --git a/m4/detect_binding.m4 b/m4/detect_binding.m4
new file mode 100644
index 0000000..359eaa6
--- /dev/null
+++ b/m4/detect_binding.m4
@@ -0,0 +1,186 @@
+dnl ===========================================================================
+dnl  Helper macro to detect an optional binding
+
+m4_defun([AC_OCAML_COMPARE_VERSION],
+  [if test -z "$2" ; then
+    VERSION_OK=yes
+  else
+    AS_VERSION_COMPARE([$1],[$2],
+        [VERSION_OK=],
+        [VERSION_OK=yes],
+        [VERSION_OK=yes])
+fi])
+
+m4_defun([AC_OCAML_CHECK_DEPS],
+  [dnl
+m4_define([deps],[m4_translit([$1],['a-z'],['A-Z'])])
+DEPS_CHECK=yes
+for i in deps(); do
+  eval "dep_check=\$W_$i"
+  if test -z "${dep_check}"; then
+    DEPS_CHECK=
+    break
+  fi
+done])
+
+m4_defun([AC_MSG_RESULT_NOT],
+  [ifelse([$1],[],[AC_MSG_RESULT($2)],[AC_MSG_ERROR($2)])])
+
+m4_defun([AC_COND_PLUGIN],
+  [ifelse([$1],[],
+[AC_ARG_ENABLE([$2-dynamic-plugin],
+   AC_HELP_STRING(
+      [--enable-$2-dynamic-plugin],
+      [Compile $2 as an optional dynamic plugin.]))])])
+
+AC_DEFUN([AC_CHECK_OCAML_BINDING],[dnl
+
+m4_define([BINDING],[m4_translit([$1],['a-z.-'],['A-Z__'])])
+m4_define([binding],[m4_translit([$1],['A-Z.-'],['a-z__'])])
+
+dnl $1 = PKG_NAME
+dnl $2 = PKG_VERSION
+dnl $3 = PKG_DEPS
+dnl $4 = PKG_MANDATORY
+dnl $5 = PKG_USED (for instance sdl.mixer au lieu of sdl. Should only be used for bindings not provided by us..)
+dnl $6 = DYNAMIC_PLUGIN
+dnl $7 = PKG_CMA (used for duppy.syntax and flac.ogg when locally compiled..)
+
+if test -n "$5"; then
+  BINDING_PKGS="$5"
+else
+  BINDING_PKGS="$1"
+fi
+
+AC_ARG_WITH([binding()-dir],
+   AC_HELP_STRING(
+      [--with-binding()-dir=path],
+      [look for ocaml-binding() library in "path" (autodetected by default)]))
+
+AC_COND_PLUGIN([$6],[$1])
+
+dnl Version stuff
+m4_define([VERSION_CHECK],[ifelse([$2],[],[],[ >= $2])])
+
+AC_MSG_CHECKING([for ocaml $1 module[]VERSION_CHECK()])
+
+OCAML_CHECK="${OCAMLFIND} query $1"
+
+dnl This (horrible) macro does the following:
+dnl Detect optional binding
+dnl If builtin and provided by ocamlfind,
+dnl fills liquidsoap_ocamlcflags with "-package deps" for
+dnl each dependency
+dnl If builtin and provided by us, fills
+dnl liquidsoap_ocamlcflags with "-I /path/to/ocaml-foo/src"
+dnl and liquidsoap_ocamllfflags with "foo.cmxa"
+dnl If plugin and provided by ocamlfind,
+dnl fills plugin_packages with "deps"
+dnl If plugin and provided by us, fills
+dnl plugin_ocamlcflags with "-I /path/to/ocaml-foo/src"
+dnl and plugin_ocamllflags with "foo.cmxa"
+dnl Ultimately, plugin_ocamlcflags and plugin_ocamllflags
+dnl are added to the global $PLUGINS_DATA variable and 
+dnl $PLUGINS is updated with the name of this plugin.
+dnl W_plugin is set to "yes" for builtin compilation
+dnl and "binding" for plugin compilation.
+
+if test "x$enable_[]binding()_dynamic_plugin" = "xyes" ; then
+  BINDING()_SHARED="yes"
+  PLUGINS="$PLUGINS binding()"
+fi
+
+AC_OCAML_CHECK_DEPS([$3])
+if test -z $DEPS_CHECK; then
+  AC_MSG_RESULT([[]binding() needs $3])
+else
+  if test -z "${with_[]binding()_dir}" ; then
+     if ! ${OCAML_CHECK} > /dev/null 2>&1 ; then
+         AC_MSG_RESULT_NOT([$4],[Not found.])
+     else
+         BINDING()_version="`${OCAMLFIND} query -format "%v" $1 2>/dev/null`"
+         AC_OCAML_COMPARE_VERSION([${[]BINDING()_version}],[$2])
+         if test -z "${VERSION_OK}"; then
+           AC_MSG_RESULT_NOT([$4],[requires version >= $2 found ${[]BINDING()_version}.])
+         else
+           if test -z "${[]BINDING()_SHARED}"; then
+             BINDING()_PACKAGES="`${OCAMLFIND} query -r -separator " " -format "-package %p" $BINDING_PKGS 2>/dev/null`"
+             liquidsoap_ocamlcflags="${liquidsoap_ocamlcflags} ${[]BINDING()_PACKAGES}"
+             W_[]BINDING()=yes
+           else
+             []binding()_packages="`${OCAMLFIND} query -r -separator " " -format "%p" $BINDING_PKGS 2>/dev/null`"
+             W_[]BINDING()=[]binding()
+           fi
+           LIBS_VERSIONS="${LIBS_VERSIONS} $1=$[]BINDING()_version"
+           AC_MSG_RESULT(ok)
+         fi
+     fi
+  else
+    BINDING()_STOP_CHECK=
+    BINDING()_version=changequote({,})"[unknown version]"changequote([,])
+    BINDING()_requires=
+    if test -r ${with_[]binding()_dir}/META >/dev/null 2>&1; then
+      # Grab version
+      BINDING()_version=`cat "${with_[]binding()_dir}/META" | grep version | cut -d'=' -f 2 | tr -d ' ' | tr -d '"' | head -n 1`
+      AC_OCAML_COMPARE_VERSION([${[]BINDING()_version}],[$2])
+      if test -z "${VERSION_OK}"; then
+        AC_MSG_RESULT_NOT([$4],[requires version >= $2 found ${[]BINDING()_version}.])
+        BINDING()_STOP_CHECK=yes
+      fi
+      BINDING()_requires=`cat "${with_[]binding()_dir}/META" | grep 'requires' | cut -d '=' -f 2 | tr -d '"'`
+      BINDING()_path="${with_[]binding()_dir}"
+    else
+      BINDING()_path=`${OCAMLFIND} -query $1 2>/dev/null`
+      if ! test -z "$2"; then
+        AC_MSG_RESULT_NOT([$4],[cannot find version from META file.])
+        BINDING()_STOP_CHECK=yes
+      fi
+    fi
+    if test -z "${BINDING()_STOP_CHECK}"; then
+      BINDING()_PACKAGES="`${OCAMLFIND} query -r -separator " " -format "-package %p" $BINGING_PKGS 2>/dev/null`"
+      echo ${with_[]binding()_dir} | grep ^/ > /dev/null 2>&1 \
+          || with_[]binding()_dir=${PWD}/${with_[]binding()_dir}
+      if test -z "${[]BINDING()_SHARED}"; then
+        liquidsoap_ocamlcflags="${liquidsoap_ocamlcflags} -I ${with_[]binding()_dir} ${[]BINDING()_PACKAGES}"
+      else
+        []binding()_ocamlcflags="-I ${with_[]binding()_dir} ${[]BINDING()_PACKAGES}"
+      fi
+      # We need to recurse here because
+      # some package may not be registered using ocamlfind
+      if test -n "$7"; then
+        BINDING()_CMA=$7.${cma}
+      else
+        BINDING()_CMA=$1.${cma}
+      fi
+      for i in ${[]BINDING()_requires}; do
+        BINDING()_PACKAGES="${[]BINDING()_PACKAGES} `${OCAMLFIND} query -r -separator " " -format "-package %p" $i 2>/dev/null`"
+      done
+      if test -z "${[]BINDING()_SHARED}"; then
+        liquidsoap_ocamllflags="${liquidsoap_ocamllflags} ${[]BINDING()_PACKAGES} ${[]BINDING()_CMA}"
+        W_[]BINDING()=yes
+      else
+        []binding()_ocamllflags="${[]BINDING()_PACKAGES} ${[]BINDING()_CMA}"
+        W_[]BINDING()=[]binding()
+      fi
+      LIBS_VERSIONS="${LIBS_VERSIONS} $1=$[]BINDING()_version"
+      AC_MSG_RESULT(ok)
+    fi
+  fi
+fi
+
+AC_SUBST(W_[]BINDING())
+if test -z "${W_[]BINDING()}" ; then
+    w_[]BINDING()="no (requires $1)"
+else
+    if test -z "${[]BINDING()_SHARED}"; then
+      w_[]BINDING()=yes
+    else
+      PLUGINS_DATA="$PLUGINS_DATA
+[]binding()_ocamlcflags=${[]binding()_ocamlcflags}
+[]binding()_ocamllflags=${[]binding()_ocamllflags}
+[]binding()_packages=${[]binding()_packages}"
+      w_[]BINDING()=plugin
+    fi
+fi])
+
+
diff --git a/m4/ocaml.m4 b/m4/ocaml.m4
new file mode 100644
index 0000000..28d1350
--- /dev/null
+++ b/m4/ocaml.m4
@@ -0,0 +1,329 @@
+dnl autoconf macros for OCaml
+dnl
+dnl Copyright © 2009      Richard W.M. Jones
+dnl Copyright © 2009      Stefano Zacchiroli
+dnl Copyright © 2000-2005 Olivier Andrieu
+dnl Copyright © 2000-2005 Jean-Christophe Filliâtre
+dnl Copyright © 2000-2005 Georges Mariano
+dnl
+dnl For documentation, please read the ocaml.m4 man page.
+
+AC_DEFUN([AC_PROG_OCAML],
+[dnl
+  # checking for ocamlc
+  AC_CHECK_TOOL([OCAMLC],[ocamlc],[no])
+
+  if test "$OCAMLC" = "no"; then
+    AC_MSG_ERROR(Cannot find ocamlc.)
+  fi
+
+  AC_SUBST([OCAMLC])
+
+  OCAMLVERSION=`$OCAMLC -v | sed -n -e 's|.*version* *\(.*\)$|\1|p'`
+  AC_MSG_RESULT([OCaml version is $OCAMLVERSION])
+  # Check if version is >= 3.12.0
+  AC_MSG_CHECKING([if ocaml compiler supports first-class modules])
+  AS_VERSION_COMPARE([$OCAMLVERSION],[3.12.0],[],[OCAML_HAS_FIRST_CLASS_MODULES="yes"],[OCAML_HAS_FIRST_CLASS_MODULES="yes"])
+  if test -n "${OCAML_HAS_FIRST_CLASS_MODULES}"; then
+    AC_MSG_RESULT([yes])
+  else
+    AC_MSG_RESULT([no])
+  fi
+  AC_SUBST(OCAML_HAS_FIRST_CLASS_MODULES)
+
+  # If OCAMLLIB is set, use it
+  if test "$OCAMLLIB" = ""; then
+     OCAMLLIB=`$OCAMLC -where 2>/dev/null || $OCAMLC -v|tail -1|cut -d ' ' -f 4`
+  else
+     AC_MSG_RESULT([OCAMLLIB previously set; preserving it.])
+  fi
+  AC_MSG_RESULT([OCaml library path is $OCAMLLIB])
+
+  AC_SUBST([OCAMLVERSION])
+  AC_SUBST([OCAMLLIB])
+
+  # checking for ocamlopt
+  AC_CHECK_TOOL_STRICT([OCAMLOPT],[ocamlopt],[no])
+  OCAMLBEST=byte
+  OCAML_DYNLINK=byte-dyn
+  if test "$OCAMLOPT" = "no"; then
+    AC_MSG_WARN([Cannot find ocamlopt; bytecode compilation only.])
+  else
+    TMPVERSION=`$OCAMLOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
+    if test "$TMPVERSION" != "$OCAMLVERSION" ; then
+      AC_MSG_RESULT([versions differs from ocamlc; ocamlopt discarded.])
+        OCAMLOPT=no
+    else
+        OCAMLBEST="byte opt"
+        OCAML_DYNLINK="byte-dyn opt-dyn"
+    fi
+  fi
+
+  AC_SUBST([OCAMLBEST])
+  AC_SUBST([OCAML_DYNLINK])
+
+  # checking for ocamlc.opt
+  AC_CHECK_TOOL_STRICT([OCAMLCDOTOPT],[ocamlc.opt],[no])
+  if test "$OCAMLCDOTOPT" != "no"; then
+    TMPVERSION=`$OCAMLCDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
+    if test "$TMPVERSION" != "$OCAMLVERSION" ; then
+      AC_MSG_RESULT([versions differs from ocamlc; ocamlc.opt discarded.])
+    else
+      OCAMLC=$OCAMLCDOTOPT
+    fi
+  fi
+
+  # checking for ocamlopt.opt
+  if test "$OCAMLOPT" != "no" ; then
+     AC_CHECK_TOOL_STRICT([OCAMLOPTDOTOPT],[ocamlopt.opt],[no])
+     if test "$OCAMLOPTDOTOPT" != "no"; then
+       TMPVERSION=`$OCAMLOPTDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
+       if test "$TMPVERSION" != "$OCAMLVERSION" ; then
+         AC_MSG_RESULT([version differs from ocamlc; ocamlopt.opt discarded.])
+	else
+	 OCAMLOPT=$OCAMLOPTDOTOPT
+       fi
+    fi
+  fi
+
+  AC_SUBST([OCAMLOPT])
+
+  # checking for ocaml toplevel
+  AC_CHECK_TOOL_STRICT([OCAML],[ocaml],[no])
+
+  AC_SUBST([OCAML])
+
+  # checking for ocamldep
+  AC_CHECK_TOOL_STRICT([OCAMLDEP],[ocamldep],[no])
+  if test "$OCAMLDEP" = "no"; then
+    AC_MSG_ERROR(Cannot find ocamlmklib.)
+  else
+    AC_CHECK_TOOL_STRICT([OCAMLDEPOPT],[ocamldep.opt],[no])
+    if test "$OCAMLDEPOPT" != "no"; then
+      OCAMLDEP=$OCAMLDEPOPT
+    fi
+  fi
+
+  AC_SUBST([OCAMLDEP])
+
+  # checking for ocamlmktop
+  AC_CHECK_TOOL_STRICT([OCAMLMKTOP],[ocamlmktop],[no])
+
+  AC_SUBST([OCAMLMKTOP])
+
+  # checking for ocamlmklib
+  AC_CHECK_TOOL_STRICT([OCAMLMKLIB],[ocamlmklib],[no])
+  if test "$OCAMLMKLIB" = "no"; then
+    AC_MSG_ERROR(Cannot find ocamlmklib.)
+  fi
+
+  AC_SUBST([OCAMLMKLIB])
+
+  # checking for ocamldoc
+  AC_CHECK_TOOL([OCAMLDOC],[ocamldoc],[no])
+  if test "$OCAMLDOC" != "no"; then
+    AC_CHECK_TOOL([OCAMLDOCOPT],[ocamldoc.opt],[no])
+    if test "$OCAMLDOCOPT" != "no"; then
+      OCAMLDOC=$OCAMLDOCOPT
+    fi
+  fi
+
+  AC_SUBST([OCAMLDOC])
+
+  # checking for ocamlbuild
+  AC_CHECK_TOOL([OCAMLBUILD],[ocamlbuild],[no])
+
+  AC_SUBST([OCAMLBUILD])
+])
+
+
+AC_DEFUN([AC_PROG_OCAMLLEX],
+[dnl
+  # checking for ocamllex
+  AC_CHECK_TOOL([OCAMLLEX],[ocamllex],[no])
+  if test "$OCAMLLEX" != "no"; then
+    AC_CHECK_TOOL([OCAMLLEXDOTOPT],[ocamllex.opt],[no])
+    if test "$OCAMLLEXDOTOPT" != "no"; then
+	OCAMLLEX=$OCAMLLEXDOTOPT
+    fi
+  fi
+  AC_SUBST([OCAMLLEX])
+])
+
+AC_DEFUN([AC_PROG_OCAMLYACC],
+[dnl
+  AC_CHECK_TOOL([OCAMLYACC],[ocamlyacc],[no])
+  AC_SUBST([OCAMLYACC])
+])
+
+
+AC_DEFUN([AC_PROG_CAMLP4],
+[dnl
+  AC_REQUIRE([AC_PROG_OCAML])dnl
+
+
+  AC_ARG_ENABLE([camlp4],
+    AC_HELP_STRING([--disable-camlp4],
+                   [disable camlp4 auto-detection.]))
+
+  # checking for camlp4
+  if test "x$enable_camlp4" != "xno"; then
+    AC_CHECK_TOOL_STRICT([CAMLP4],[camlp4],[no])
+    if test "$CAMLP4" != "no"; then
+       TMPVERSION=`$CAMLP4 -v 2>&1| sed -n -e 's|.*version *\(.*\)$|\1|p' | tr -d '\r'`
+       if test "$TMPVERSION" != "$OCAMLVERSION" ; then
+  	  AC_MSG_RESULT([versions differs from ocamlc])
+          CAMLP4=no
+       fi
+    fi
+    AC_SUBST([CAMLP4])
+
+    # checking for companion tools
+    AC_CHECK_TOOL_STRICT([CAMLP4BOOT],[camlp4boot],[no])
+    AC_CHECK_TOOL_STRICT([CAMLP4O],[camlp4o],[no])
+    AC_CHECK_TOOL_STRICT([CAMLP4OF],[camlp4of],[no])
+    AC_CHECK_TOOL_STRICT([CAMLP4OOF],[camlp4oof],[no])
+    AC_CHECK_TOOL_STRICT([CAMLP4ORF],[camlp4orf],[no])
+    AC_CHECK_TOOL_STRICT([CAMLP4PROF],[camlp4prof],[no])
+    AC_CHECK_TOOL_STRICT([CAMLP4R],[camlp4r],[no])
+    AC_CHECK_TOOL_STRICT([CAMLP4RF],[camlp4rf],[no])
+  else
+    CAMLP4=no
+    CAMLP4BOOT=no
+    CAMLP4O=no
+    CAMLP4OF=no
+    CAMLP4OOF=no
+    CAMLP4ORF=no
+    CAMLP4PROF=no
+    CAMLP4R=no
+    CAMLP4RF=no
+  fi
+
+  AC_SUBST([CAMLP4BOOT])
+  AC_SUBST([CAMLP4O])
+  AC_SUBST([CAMLP4OF])
+  AC_SUBST([CAMLP4OOF])
+  AC_SUBST([CAMLP4ORF])
+  AC_SUBST([CAMLP4PROF])
+  AC_SUBST([CAMLP4R])
+  AC_SUBST([CAMLP4RF])
+])
+
+AC_DEFUN([AC_PROG_CAMLIDL],
+[dnl
+  AC_CHECK_TOOL(CAMLIDL,camlidl,no)
+  AC_SUBST(CAMLIDL)
+])
+
+AC_DEFUN([AC_PROG_FINDLIB],
+[dnl
+  AC_REQUIRE([AC_PROG_OCAML])dnl
+
+  # checking for ocamlfind
+  AC_CHECK_TOOL([OCAMLFIND],[ocamlfind],[no])
+  AC_SUBST([OCAMLFIND])
+])
+
+AC_DEFUN([AC_CHECK_OCAML_STDLIB],
+[dnl
+  AC_REQUIRE([AC_PROG_FINDLIB])dnl
+
+  AC_MSG_CHECKING([for ocaml standard library path])
+  OCAML_STDLIB=`$OCAMLFIND printconf stdlib`
+  AC_SUBST(OCAML_STDLIB)
+  AC_MSG_RESULT([$OCAML_STDLIB])
+])
+
+dnl Thanks to Jim Meyering for working this next bit out for us.
+dnl XXX We should define AS_TR_SH if it's not defined already
+dnl (eg. for old autoconf).
+AC_DEFUN([AC_CHECK_OCAML_PKG],
+[dnl
+  AC_REQUIRE([AC_PROG_FINDLIB])dnl
+
+  AC_ARG_WITH([$1-dir],AC_HELP_STRING([--with-$1-dir=path],
+              [use "path" as the location of ocaml-$1 (autodetected by default)]))
+  AC_MSG_CHECKING([for OCaml library $1])
+
+  unset found
+  unset pkg
+  found=no
+  if test -z "$with_$1_dir"; then
+    for pkg in $1 $2 ; do
+      if $OCAMLFIND query $pkg >/dev/null 2>/dev/null; then
+        AC_MSG_RESULT([found])
+        AS_TR_SH([OCAML_PKG_$1])=$pkg
+        AS_TR_SH([OCAML_DIR_$1])=`$OCAMLFIND query $1`
+        found=yes
+        break
+      fi
+    done
+  else
+    echo $with_$1_dir | grep ^/ > /dev/null 2>&1 || with_$1_dir=$PWD/$with_$1_dir
+    AS_TR_SH([OCAML_PKG_$1])=no
+    OCAML_DIR_$1="$with_$1_dir"
+    found=yes
+  fi
+  if test "$found" = "no" ; then
+    AC_MSG_RESULT([not found])
+    AS_TR_SH([OCAML_HAS_$1])=no
+    AS_TR_SH([OCAML_PKG_$1])=no
+  else
+    AS_TR_SH([OCAML_HAS_$1])=yes
+  fi
+
+  AC_SUBST(AS_TR_SH([OCAML_PKG_$1]))
+])
+
+
+AC_DEFUN([AC_CHECK_OCAML_MODULE],
+[dnl
+  AC_MSG_CHECKING([for OCaml module $2])
+
+  cat > conftest.ml <<EOF
+open $3
+EOF
+  unset found
+  for $1 in $$1 $4 ; do
+    if $OCAMLC -c -I "$$1" conftest.ml >&5 2>&5 ; then
+      found=yes
+      break
+    fi
+  done
+
+  if test "$found" ; then
+    AC_MSG_RESULT([$$1])
+  else
+    AC_MSG_RESULT([not found])
+    $1=no
+  fi
+  AC_SUBST([$1])
+])
+
+
+dnl XXX Cross-compiling
+AC_DEFUN([AC_CHECK_OCAML_WORD_SIZE],
+[dnl
+  AC_REQUIRE([AC_PROG_OCAML])dnl
+  AC_MSG_CHECKING([for OCaml compiler word size])
+  cat > conftest.ml <<EOF
+  print_endline (string_of_int Sys.word_size)
+  EOF
+  OCAML_WORD_SIZE=`$OCAML conftest.ml`
+  AC_MSG_RESULT([$OCAML_WORD_SIZE])
+  AC_SUBST([OCAML_WORD_SIZE])
+])
+
+AC_DEFUN([AC_CHECK_OCAML_OS_TYPE],
+[dnl
+  AC_REQUIRE([AC_PROG_OCAML])dnl
+  AC_MSG_CHECKING([OCaml Sys.os_type])
+
+  cat > conftest.ml <<EOF
+  print_string(Sys.os_type);;
+EOF
+
+  OCAML_OS_TYPE=`$OCAML conftest.ml`
+  AC_MSG_RESULT([$OCAML_OS_TYPE])
+  AC_SUBST([OCAML_OS_TYPE])
+])
diff --git a/m4/ocaml_compilers.m4 b/m4/ocaml_compilers.m4
new file mode 100644
index 0000000..2fa4f74
--- /dev/null
+++ b/m4/ocaml_compilers.m4
@@ -0,0 +1,73 @@
+AC_DEFUN([AC_CHECK_OCAML_COMPILERS],[
+OCAMLFIND_LDCONF=""
+AC_ARG_ENABLE([ldconf], AC_HELP_STRING([--disable-ldconf],[don't modify the dynamic loader configuration file (default is enable)]),[ac_enable_ldconf=$enableval],[ac_enable_ldconf=$enableval],[ac_enable_ldconf=yes])
+if test "$ac_enable_ldconf" = no ; then
+	AC_MSG_RESULT([disabling modification of ld.conf])
+	OCAMLFIND_LDCONF=dummy
+fi
+AC_SUBST(OCAMLFIND_LDCONF)
+
+# Check for Ocaml compilers
+
+AC_PROG_OCAML()
+
+AC_PROG_CAMLIDL()
+
+AC_PROG_OCAMLLEX()
+
+AC_PROG_OCAMLYACC()
+
+AC_PROG_CAMLP4()
+
+AC_PROG_FINDLIB()
+
+AC_CHECK_OCAML_STDLIB()
+
+# Check if caml/threads.h is present 
+AC_CHECK_HEADER([caml/threads.h],[CAML_THREADS=yes],[],[#include <caml/misc.h>])
+
+AC_ARG_ENABLE([debugging],
+   AC_HELP_STRING(
+      [--disable-debugging],
+      [disable debugging information (backtrace printing in particular)]))
+
+if test "$enable_debugging" \!= "no" ; then
+  OCAMLFLAGS="$OCAMLFLAGS -g"
+fi
+
+AC_ARG_WITH([ocaml-warnings],
+   AC_HELP_STRING(
+      [--with-ocaml-warnings=WARNINGS],
+      [Enable specific list of ocaml compiler warnings.]))
+
+if test -n "${with_ocaml_warnings}" ; then
+  OCAMLFLAGS="$OCAMLFLAGS -w +${with_ocaml_warnings}"
+else
+  OCAMLFLAGS="$OCAMLFLAGS -w +A-4@5-7@8@11@12@20-35-44-45"
+fi
+
+AC_ARG_ENABLE([profiling],
+   AC_HELP_STRING(
+      [--enable-profiling],
+      [compile to generate profiling infomation]))
+if test "x$enable_profiling" = "xyes" ; then
+  OCAMLNCFLAGS="$OCAMLNCFLAGS -p"
+fi
+AC_SUBST(OCAMLNCFLAGS)
+
+AC_ARG_ENABLE([nativecode],
+   AC_HELP_STRING(
+      [--disable-nativecode],
+      [compile in bytecode]))
+
+AC_ARG_ENABLE([custom],
+   AC_HELP_STRING(
+      [--disable-custom],
+      [disable custom mode for bytecode compilation (use if you know what you are doing)]))
+
+CAMLLIBPATH=$OCAMLLIB
+AC_SUBST(CAMLLIBPATH)
+
+AC_SUBST(CAMLIDL)
+AC_SUBST(OCAMLFLAGS)
+])
diff --git a/m4/pkg_config.m4 b/m4/pkg_config.m4
new file mode 100644
index 0000000..f940dff
--- /dev/null
+++ b/m4/pkg_config.m4
@@ -0,0 +1,76 @@
+dnl Taken an modified from:
+dnl pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
+dnl 
+dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
+dnl
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+dnl General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+dnl
+dnl As a special exception to the GNU General Public License, if you
+dnl distribute this file as part of a program that contains a
+dnl configuration script generated by Autoconf, you may include it under
+dnl the same distribution terms that you use for the rest of that program.
+
+dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
+dnl ----------------------------------
+AC_DEFUN([PKG_PROG_PKG_CONFIG],
+[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
+m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
+AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+  AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
+fi
+if test -n "$PKG_CONFIG"; then
+  _pkg_min_version=m4_default([$1], [0.9.0])
+  AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
+  if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+    AC_MSG_RESULT([yes])
+  else
+    AC_MSG_ERROR([no])
+    PKG_CONFIG=""
+  fi
+    
+fi[]dnl
+])dnl PKG_PROG_PKG_CONFIG
+
+AC_ARG_VAR([PKG_CONFIG_OPTIONS], [Additional options passed when invoking pkg-config])
+
+dnl PKG_CONFIG_CHECK_MODULE([name],[min-version])
+dnl min-version is optional
+AC_DEFUN([PKG_CONFIG_CHECK_MODULE],
+[if test -n "$2"; then
+  PKGCONFIG_CHECK_VERSION=" >= $2"
+else
+  PKGCONFIG_CHECK_VERSION=""
+fi
+AC_MSG_CHECKING([whether pkg-config knows about $1${PKGCONFIG_CHECK_VERSION}])
+if ! $PKG_CONFIG $PKG_CONFIG_OPTIONS --exists $1; then
+  AC_MSG_ERROR([$1.pc not found.. Do you need to set PKG_CONFIG_PATH?])
+else
+  if test -n "$2"; then
+    if ! $PKG_CONFIG $PKG_CONFIG_OPTIONS --atleast-version=$2 $1; then
+      $1_VERSION="`$PKG_CONFIG $PKG_CONFIG_OPTIONS --modversion $1`"
+      AC_MSG_ERROR([requires version >= $2, found ${$1_VERSION}])
+    else
+      AC_MSG_RESULT([ok])
+    fi
+  else
+    AC_MSG_RESULT([ok])
+  fi
+fi
+CFLAGS="$CFLAGS `$PKG_CONFIG $PKG_CONFIG_OPTIONS --cflags $1`"
+CPPFLAGS="$CPPFLAGS `$PKG_CONFIG $PKG_CONFIG_OPTIONS --cflags $1`"
+LIBS="$LIBS `$PKG_CONFIG $PKG_CONFIG_OPTIONS --libs-only-l $1`"
+LDFLAGS="$LDFLAGS `$PKG_CONFIG $PKG_CONFIG_OPTIONS --libs-only-L $1`"
+])
diff --git a/m4/strict_check_tool.m4 b/m4/strict_check_tool.m4
new file mode 100644
index 0000000..6a52090
--- /dev/null
+++ b/m4/strict_check_tool.m4
@@ -0,0 +1,7 @@
+AC_DEFUN([AC_CHECK_TOOL_STRICT],
+[AC_CHECK_PROG([$1], [${ac_tool_prefix}$2], [${ac_tool_prefix}$2], [$3], [$4])])
+
+AC_DEFUN([AC_PATH_TOOL_STRICT],
+[AC_PATH_PROG([$1], [${ac_tool_prefix}$2], [$3])])
+
+