File: aclocal.m4

package info (click to toggle)
libgnatcoll 1.7gpl2015-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,280 kB
  • ctags: 1,124
  • sloc: ada: 134,072; python: 4,017; cpp: 1,397; ansic: 1,234; makefile: 368; sh: 152; xml: 31; sql: 6
file content (1214 lines) | stat: -rw-r--r-- 38,830 bytes parent folder | 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
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
## This file contains various m4 macros that can be included in your
## own projects to enable proper detection of the scripting languages
## In your own aclocal.m4 file, you can use syntax like
##   include(gnatcoll/aclocal.m4)

##############################################################
# Machine-specific linker switches
#   @EXTRA_LINK_SWITCHES@: list of system-specific linker
#      switches. Its syntax is compatible with GPR files.
##############################################################

AC_DEFUN(AM_SYSTEM_LINK_SWITCHES,
[
    case $build_os in
       *darwin*)   EXTRA_LINK_SWITCHES='"-Wl,-no_pie"';;
       *)          EXTRA_LINK_SWITCHES='';;
    esac
    AC_SUBST(EXTRA_LINK_SWITCHES)
])

##############################################################
# Copy a file, as part of config.status
#  AM_LINK_FILE(SOURCE,DEST)
##############################################################

AC_DEFUN(AM_LINK_FILE,
[
   AC_CONFIG_COMMANDS([$2],
                      [rm -f $2
                       cp -f $1 $2], [$3])
])

##############################################################
# Checking for build type
# The following variable is exported by configure:
#   @BUILD_TYPE@: either "Production" or "Debug"
##############################################################

AC_DEFUN(CHECK_BUILD_TYPE,
[
  AC_ARG_ENABLE(build,
    [AC_HELP_STRING(
       [--enable-build=<type>],
       [Default build type for the library (Debug, Production)])],
    BUILD_TYPE=$enableval,
    BUILD_TYPE=Production)
  AC_SUBST(BUILD_TYPE)
])

#############################################################
# Check whether gnatmake can compile, bind and link an Ada program
#    AM_TRY_ADA(gnatmake,filename,content,success,failure)
#############################################################

AC_DEFUN(AM_TRY_ADA,
[
   cat > conftest.ada <<EOF
[$3]
EOF
   if AC_TRY_COMMAND([gnatchop -q conftest.ada && $1 $2 >/dev/null 2>conftest.out])
   then
      : Success
      $4
   else
      : Failure
      $5
   fi
   rm -rf conftest.ada
])

#############################################################
# Check whether platform/GNAT supports atomic increment/decrement
# operations.
# The following variable is then set:
#     SYNC_COUNTERS_IMPL
# to either "intrinsic" or "mutex"
# Code comes from the PolyORB configure.ac
#############################################################

AC_DEFUN(AM_HAS_INTRINSIC_SYNC_COUNTERS,
[
  AC_MSG_CHECKING([whether platform supports atomic inc/dec])
  AM_TRY_ADA([gnatmake], [check.adb],
[
with Interfaces; use Interfaces;
procedure Check is
   function Sync_Add_And_Fetch
     (Ptr   : access Interfaces.Integer_32;
      Value : Interfaces.Integer_32) return Interfaces.Integer_32;
   pragma Import (Intrinsic, Sync_Add_And_Fetch, "__sync_add_and_fetch_4");
   X : aliased Interfaces.Integer_32;
   Y : Interfaces.Integer_32 := 0;
   pragma Volatile (Y);
   --  On some platforms (e.g. i386), GCC has limited support for
   --  __sync_add_and_fetch_4 for the case where the result is not used.
   --  Here we want to test for general availability, so make Y volatile to
   --  prevent the store operation from being discarded.
begin
   Y := Sync_Add_And_Fetch (X'Access, 1);
end Check;
],
[
   AC_MSG_RESULT(yes)
   SYNC_COUNTERS_IMPL="intrinsic"
],[
   AC_MSG_RESULT(no)
   SYNC_COUNTERS_IMPL="mutex"
])

   rm -f check.adb check
   AC_SUBST(SYNC_COUNTERS_IMPL)
])

#############################################################
# Check whether we have the GNAT sources available
# The following variables are exported by configure:
#   @WITH_PROJECTS@: "yes" or "no"
#   GNAT_SOURCES: "gnat_util", "copy", "no"
#############################################################

AC_DEFUN(AM_GNAT_SOURCES,
[
  AC_MSG_CHECKING(whether gnat sources are found)
  if test -d gnat_src; then
     AC_MSG_RESULT(yes)
     HAS_GNAT_SOURCES=yes
     GNAT_SOURCES=copy
  else
     AC_MSG_RESULT(no)

     AC_MSG_CHECKING(whether gnat_util exists)
     AM_HAS_GNAT_PROJECT(gnat_util)
     if test "$HAVE_GNAT_PROJECT_gnat_util" = "yes"; then
        HAS_GNAT_SOURCES=yes
        GNAT_SOURCES=gnat_util
     else
        HAS_GNAT_SOURCES=no
        GNAT_SOURCES=copy
     fi
  fi

  AC_SUBST(GNAT_SOURCES)
])

AC_DEFUN(AM_PROJECTS,
[
  # Allow the user to disable projects support so that gnatcoll does not depend
  # on the installed gnat compiler (gnat_utils project)
  AC_ARG_ENABLE(projects,
    AC_HELP_STRING(
      [--disable-projects],
      [Disable support for GNAT Projects [[default=enabled]]]),
    [WITH_PROJECTS=$enableval],
    [WITH_PROJECTS=$HAS_GNAT_SOURCES])

  AC_SUBST(WITH_PROJECTS)
])

#############################################################
# Check whether GNAT on that target supports building shared
# libraries
# The following variables are exported by configure:
#   @GNAT_BUILDS_SHARED@: either "yes" or "no"
#   @DEFAULT_LIBRARY_TYPE@: either "static" or "relocatable"
#############################################################

AC_DEFUN(AM_GNAT_BUILDS_SHARED,
[
   AC_MSG_CHECKING(whether gnat can build shared libs)

   DEFAULT_LIBRARY_TYPE=static

   AC_ARG_ENABLE(shared,
     [AC_HELP_STRING(
        [--disable-shared],
        [Disable building of shared libraries])
AC_HELP_STRING(
        [--enable-shared],
        [Build shared libraries if supported on the target
Make them the installation default])],
     [GNAT_BUILDS_SHARED=$enableval
      if test $enableval = yes; then
         DEFAULT_LIBRARY_TYPE=relocatable
      fi],
     [GNAT_BUILDS_SHARED=yes])

   if test x$GNAT_BUILDS_SHARED = xyes; then
      mkdir conftest conftest/lib
      echo "package Foo is end Foo;" > conftest/foo.ads
      cat > conftest/lib.gpr <<EOF
project Lib is
   for Source_Dirs use (".");
   for Library_Dir use "lib";
   for Library_Name use "lib";
   for Library_Kind use "relocatable";
end Lib;
EOF

      if AC_TRY_COMMAND([gprbuild -c -q -Pconftest/lib]); then
         GNAT_BUILDS_SHARED=yes
      else
         GNAT_BUILDS_SHARED=no
         DEFAULT_LIBRARY_TYPE=static
      fi
      rm -rf conftest
      AC_MSG_RESULT($GNAT_BUILDS_SHARED)
   else
      AC_MSG_RESULT([no (--disabled-shared)])
   fi

   AC_SUBST(GNAT_BUILDS_SHARED)
   AC_SUBST(DEFAULT_LIBRARY_TYPE)
])

#############################################################
# Checking for syslog
# This checks whether syslog exists on this system.
# This module can be disabled with
#    --disable-syslog
# The following variables are exported by configure:
#    @WITH_SYSLOG@: either "yes" or "no"
############################################################

AC_DEFUN(AM_PATH_SYSLOG,
[
   AC_ARG_ENABLE(syslog,
     AC_HELP_STRING(
        [--disable-syslog],
        [Disable support for syslog [[default=enabled]]]),
     [WITH_SYSLOG=$enableval],
     [WITH_SYSLOG=yes])

   if test x$WITH_SYSLOG = xyes ; then
     AC_CHECK_HEADER([syslog.h],
                     [WITH_SYSLOG=yes],
                     [WITH_SYSLOG=no])
   fi

   AC_SUBST(WITH_SYSLOG)
])

#############################################################
# Checking for iconv.
# There are multiple versions of the library (Solaris, GNU,...)
# and some of them have slightly different APIs.
# Iconv on AIX is currently not supported because it does not
# support passing an empty string to iconv_open to specify the
# locale charset.
# The following variables are exported by configure:
#   @WITH_ICONV@: either "yes" or "no"
#   @PATH_ICONV@: path to libiconv, or "" if not found
#   @INCLUDE_ICONV@: the "-I..." for iconv.h, if needed
#   @LIB_ICONV@:  either "" or "-liconv"
#############################################################

AC_DEFUN(AM_PATH_ICONV,
[
   NEED_ICONV=no
   INCLUDE_ICONV=""
   LIB_ICONV=""
   PATH_ICONV=""
   WITH_ICONV=yes
   ICONV_STATIC=no

   AC_ARG_WITH(iconv,
     [AC_HELP_STRING(
       [--with-iconv=<path>],
       [Specify the full path to the iconv library])
AC_HELP_STRING(
       [--without-iconv],
       [Disable iconv support])],
     [ICONV_PATH_WITH=$withval; NEED_ICONV=yes],
     [ICONV_PATH_WITH=yes])

   AC_MSG_CHECKING(for libiconv)
   case $ICONV_PATH_WITH in
       no)
          # Explicitly disabled by user (--with-iconv=no or --without-iconv)
          AC_MSG_RESULT([no, disabled by user])
          WITH_ICONV=no
          ;;

       static)
          WITH_ICONV=no
          ICONV_STATIC=yes
          LD_LIBRARY_PATH="/opt/local/lib:/usr/local/lib:/usr/lib:/lib:$LD_LIBRARY_PATH"
          as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
          for dir in $LD_LIBRARY_PATH ; do
              if test -f "$dir/libiconv.a"; then
                 am_path_iconv=$dir
                 WITH_ICONV=yes
                 PATH_ICONV=""
                 LIB_ICONV="$dir/libiconv.a"
                 LIBS="$LIBS $LIB_ICONV"
                 INCLUDE_ICONV="-I$dir/../include"
                 break
              fi
          done
          IFS=$as_save_IFS
          ;;

       yes)
          # Request automatic detection
          #
          # A special case for instance on Solaris: iconv.h is installed in
          # /usr/include, but (on our machines at least) also in
          # /usr/local/include. Both variants are different, and we must make
          # sure we link with the matching library. If /usr/local/lib is not
          # in LD_LIBRARY_PATH, AM_LIB_PATH will not find libiconv (part of
          # the standard library), so will not add -liconv. But the default
          # search path for cpp is such that /usr/local/include is searched
          # first (even if -I/usr/include is on the command line, since it is
          # also a default search path). So we have a discrepency. So we
          # always add the default search paths to LD_LIBRARY_PATH.

          case $target in
              *aix*)
                 WITH_ICONV=no
                 AC_MSG_RESULT([no, unsupported on AIX])
                 ;;
	      *darwin*)
                 # On OSX, we do not want to use macport's version of libiconv,
                 # which is not compatible with the system (we end up with
                 # errors like _iconv_open not found for architecture x86_64).
                 # So we force the use of /usr/lib. Note that in that case we
                 # don't want to add a -L/usr/lib. Otherwise all libraries
                 # present in that directory (libpython, ...) will be taken
                 # first at that location and so break other configure
                 # switches such --with-python.

                 LIB_ICONV="/usr/lib/libiconv.dylib"
                 INCLUDE_ICONV="-I/usr/include"
                 PATH_ICONV=""
                 ;;
              *)
                LD_LIBRARY_PATH="/usr/local/lib:/usr/lib:/usr/target/lib:$LD_LIBRARY_PATH"

                AM_LIB_PATH(iconv)
                if test x"$am_path_iconv" != x ; then
                   PATH_ICONV="-L$am_path_iconv"
                   INCLUDE_ICONV="-I$am_path_iconv/../include"
                fi
                ;;
          esac
          ;;

       *)
          # path provided by user
          am_path_iconv="$ICONV_PATH_WITH"
          PATH_ICONV="-L$am_path_iconv/lib"
          INCLUDE_ICONV="-I$am_path_iconv/include"
          ;;
   esac

   if test x"$WITH_ICONV" = x"yes" ; then
      _save_LIBS="$LIBS"
      if test x"$PATH_ICONV" = x ; then
          AC_MSG_RESULT(no special -L needed)
      else
          AC_MSG_RESULT(found in $am_path_iconv)
          LIBS="$LIBS $PATH_ICONV"
      fi

      CFLAGS="$CFLAGS $INCLUDE_ICONV"

      # The code below is similar to AC_SEARCH_LIBS(iconv_open, [iconv])
      # but allows us to also check that #include <iconv.h> is supported
      # and matches the library we link with. Otherwise, we might be
      # compiling with /usr/local/include/iconv.h (default search path)
      # but linking without -liconv (since on Solaris it is part of the
      # libc and that would be detected).

      AC_LANG_CONFTEST(
         [AC_LANG_PROGRAM(
            [#include <iconv.h>],
            [iconv_open(0,0)])])

      if test "$ICONV_STATIC" = "no" -a "$LIB_ICONV" = ""; then
         AC_MSG_CHECKING([for library containing iconv_open])
         for ac_lib in '' iconv ; do
             if test -z "$ac_lib" ; then
                switch=""
             else
                switch="-l$ac_lib"
             fi
             LIBS="$switch $LIBS"
             AC_LINK_IFELSE([],
                [WITH_ICONV=yes;
                 LIB_ICONV="$switch";
                 break],
                [WITH_ICONV=no])
         done
         AC_MSG_RESULT([$WITH_ICONV $LIB_ICONV])
      fi
      rm -f conftest.$ac_objext conftest$ac_exeext
   
      LIBS="$_save_LIBS"     # Should we leave -liconv ?

      if test x"$WITH_ICONV" = xno -a x"$NEED_ICONV" = xyes ; then
        AC_MSG_ERROR([iconv not found])
      fi
   fi

   AC_SUBST(WITH_ICONV)
   AC_SUBST(PATH_ICONV)
   AC_SUBST(LIB_ICONV)
   AC_SUBST(INCLUDE_ICONV)
])

#############################################################
# Search for a library anywhere on LD_LIBRARY_PATH
# This will return the empty string if not found, and the directory
# otherwise.
# This can be used to add -Ldir parameters on the command line: if
# the library was found with AC_CHECK_LIB but not this macro, this
# means it is in the standard search path and no command line switch
# is required.
#    AM_LIB_PATH(libname)
# Sets am_path_<libname> to the path
#############################################################

AC_DEFUN(AM_LIB_PATH,
[
   am_path_$1=""
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
   for lib_dir in $LD_LIBRARY_PATH /usr /usr/local /opt/local
   do
      IFS=$as_save_IFS
      _AS_ECHO_LOG([Testing $lib_dir/lib$1${SO_EXT}])
      if test -f "$lib_dir/lib$1${SO_EXT}"; then
         am_path_$1=$lib_dir
         break
      fi
   done
   IFS=$as_save_IFS
])

#############################################################
# Checking for postgreSQL
# This checks whether the libpq exists on this system
# This module can be disabled with
#    --with-postgresql=path
# The following variables are exported by configure:
#   @WITH_POSTGRES@: whether postgres was detected
#   @PATH_LIBPQ@: path to libpq, or "" if not found
#   @HAS_PQPREPARE@: whether the version of postgreSQL has PQprepare ()
#############################################################

AC_DEFUN(AM_PATH_POSTGRES,
[
   NEED_PSQL=no
   AC_ARG_WITH(postgresql,
     [AC_HELP_STRING(
       [--with-postgresql=<path>],
       [Specify the full path to the PostgreSQL installation])
AC_HELP_STRING(
       [--without-postgresql],
       [Disable PostgreSQL support])],
     [POSTGRESQL_PATH_WITH=$withval; NEED_PSQL=yes],
     POSTGRESQL_PATH_WITH=yes)

   PATH_LIBPQ=""
   if test x"$POSTGRESQL_PATH_WITH" = xno ; then
      AC_MSG_CHECKING(for PostgreSQL)
      AC_MSG_RESULT(no, use --with-postgresql if needed)
      WITH_POSTGRES=no

   else
     if test x"$POSTGRESQL_PATH_WITH" = xyes ; then
       PATH_LIBPQ=`pg_config 2>/dev/null | grep ^LIBDIR | cut -d\  -f3`
       if test x"$PATH_LIBPQ" != x ; then
          PATH_LIBPQ="-L$PATH_LIBPQ"
          LIB_PQ="-lpq"
       else
          AM_LIB_PATH(pq)
          if test x"$am_path_pq" != x ; then
             PATH_LIBPQ="-L$am_path_pq"
             LIB_PQ="-lpq"
          fi
       fi
       AC_CHECK_LIB(pq,PQreset,WITH_POSTGRES=yes,WITH_POSTGRES=no,[$PATH_LIBPQ])

     else
       WITH_POSTGRES=yes

       # Did the user provide a path to a static libpq ?

       if test -f "$POSTGRESQL_PATH_WITH" -a `basename "$POSTGRESQL_PATH_WITH"` = "libpq.a" ; then
          PATH_LIBPQ=""
          LIB_PQ="$POSTGRESQL_PATH_WITH -lssl -lcrypto"

       elif test -f "$POSTGRESQL_PATH_WITH/libpq.so" -o -f "$POSTGRESQL_PATH_WITH/libpq.dll" -o -f "$POSTGRESQL_PATH_WITH/libpq.dylib" ; then
          PATH_LIBPQ="-L$POSTGRESQL_PATH_WITH"
          LIB_PQ="-lpq"
       elif test -f "$POSTGRESQL_PATH_WITH/lib/libpq.so" -o -f "$POSTGRESQL_PATH_WITH/lib/libpq.dll" -o -f "$POSTGRESQL_PATH_WITH/lib/libpq.dylib" ; then
          PATH_LIBPQ="-L$POSTGRESQL_PATH_WITH/lib"
          LIB_PQ="-lpq"
       else
          AC_MSG_CHECKING(for PostgreSQL)
          AC_MSG_RESULT(not found in $POSTGRESQL_PATH_WITH)
          WITH_POSTGRES=no
       fi
     fi

     if test x"$WITH_POSTGRES" = xno -a x"$NEED_PSQL" = xyes ; then
       AC_MSG_ERROR([PostgreSQL not found])
     fi
   fi

   if test x"$WITH_POSTGRES" = xyes ; then
     AC_CHECK_LIB(pq,PQprepare,HAS_PQPREPARE=yes,HAS_PQPREPARE=no,[$PATH_LIBPQ])
   else
     HAS_PQPREPARE=no
   fi

   AC_SUBST(WITH_POSTGRES)
   AC_SUBST(PATH_LIBPQ)
   AC_SUBST(LIB_PQ)
   AC_SUBST(HAS_PQPREPARE)
])

j############################################################
# Checking for sqlite
# This checks whether sqlite is installed on the system. It can
# be disabled with
#    -with-sqlite=no
# The following variables are exported by configure:
#    @WITH_SQLITE@: whether sqlite is detected
#    @PATH_LIBSQLITE@: path to libsqlite3
#############################################################

AC_DEFUN(AM_PATH_SQLITE,
[
   NEED_SQLITE=no
   AC_ARG_WITH(sqlite,
     [AC_HELP_STRING(
        [--with-sqlite=<path>],
        [Specify the full path to the sqlite installation, or "embedded" (default)])
AC_HELP_STRING(
        [--without-sqlite],
        [Disable sqlite support])],
     [SQLITE_PATH_WITH=$withval; NEED_SQLITE=yes],
     SQLITE_PATH_WITH=yes)

   PATH_LIBSQLITE=""
   if test x"$SQLITE_PATH_WITH" = xembedded -o x"$SQLITE_PATH_WITH" = xyes ; then
      AC_MSG_CHECKING(for sqlite)
      AC_MSG_RESULT(embedded, use --with-sqlite to use a dynamic lib)
      WITH_SQLITE=embedded

   else
      if test x"$SQLITE_PATH_WITH" = xno ; then
        AC_MSG_CHECKING(for sqlite)
        AC_MSG_RESULT(no, use --with-sqlite to use a dynamic lib)
        WITH_SQLITE=no
      else
         if test x"$SQLITE_PATH_WITH" != xyes ; then
           if test -d $SQLITE_PATH_WITH/lib; then
              PATH_LIBSQLITE="-L$SQLITE_PATH_WITH/lib"
           elif test -d $SQLITE_PATH_WITH/lib64; then
              PATH_LIBSQLITE="-L$SQLITE_PATH_WITH/lib64"
           else
              PATH_LIBSQLITE="-L$SQLITE_PATH_WITH"
           fi
         fi

         # Requires at least version 3.7.14
         AC_CHECK_LIB(sqlite3, sqlite3_close_v2,
                      [WITH_SQLITE=yes],
                      [WITH_SQLITE=no],
                      $SQLITE_CFLAGS $PATH_LIBSQLITE)

         if test x"$WITH_SQLITE" = xno ; then
            AC_MSG_CHECKING(for sqlite)
            AC_MSG_RESULT(embedded, use --with-sqlite to use a dynamic lib)
            WITH_SQLITE=embedded
         fi
      fi
   fi

   case "${host}" in
      *solaris2.10 )
          SQLITE_CFLAGS='"-std=c99"'
          ;;
      *)
          SQLITE_CFLAGS=''
          ;;
   esac

   AC_SUBST(WITH_SQLITE)
   AC_SUBST(PATH_LIBSQLITE)
   AC_SUBST(SQLITE_CFLAGS)

])

#############################################################
# Checking for gmp
# This checks whether the gnu multiprecision library is available.
# The result can be forced by using the
#    --with-gmp=path
# The following variables are exported on exit:
#   @GMP_CFLAGS@:  Compiler flags
#   @GMP_LIBS@:    Extra command line switches for the linker
#   @WITH_GMP@:    "yes" or "no" depending on whether gmp is available
#############################################################

AC_DEFUN(AM_PATH_GMP,
[
   AC_ARG_WITH(gmp,
     [AC_HELP_STRING(
       [--with-gmp=<path>],
       [Specify the full path of the gmp install])
AC_HELP_STRING(
       [--without-gmp],
       [Disable support for gmp])],
     GMP_PATH_WITH=$withval,
     GMP_PATH_WITH=yes)

   GMP_CFLAGS=""
   GMP_LIBS=""
   if test x"$GMP_PATH_WITH" = xno ; then
      AC_MSG_CHECKING(for gmp)
      AC_MSG_RESULT(no, use --with-gmp if needed)
      WITH_GMP=no

   else
     if test x"$GMP_PATH_WITH" = xyes ; then
       AC_CHECK_LIB(gmp,__gmpz_init,WITH_GMP=yes,WITH_GMP=no)
       AC_CHECK_HEADER(gmp.h, [], [WITH_GMP=no])
       GMP_LIBS="-lgmp"
     else
       GMP_LIBS="-L$GMP_PATH_WITH/lib -lgmp"
       GMP_CFLAGS="-I$GMP_PATH_WITH/include"
       WITH_GMP=yes
     fi
   fi

   AC_SUBST(WITH_GMP)
   AC_SUBST(GMP_CFLAGS)
   AC_SUBST(GMP_LIBS)
])

#############################################################
# Checking for readline
#############################################################

AC_DEFUN(AM_CHECK_READLINE,
[
   AC_ARG_ENABLE(readline,
     [AC_HELP_STRING(
        [--disable-readline],
        [Disable support for readline])],
     WITH_READLINE=$enableval,
     WITH_READLINE="")

   if test "$WITH_GPL" = "no" ; then
      AC_MSG_CHECKING(for readline)
      AC_MSG_RESULT([no, this is a pure GPL library (see --enable-gpl)])
      WITH_READLINE=no
   elif test "$WITH_READLINE" = "" ; then
      AC_CHECK_LIB(readline,readline,WITH_READLINE=yes,WITH_READLINE=no)
   elif test "$WITH_READLINE" = "yes" ; then
      AC_CHECK_LIB(readline,readline,WITH_READLINE=yes,WITH_READLINE=no)
      if test "$WITH_READLINE" = "no" ; then
         AC_MSG_ERROR([Readline not found])
      fi
   fi

   AC_SUBST(WITH_READLINE)
])

#############################################################
# Checking for mmap
# The following variables are exported:
#   @WITH_MMAP@: either "yes" or "no"
#############################################################

AC_DEFUN(AM_MMAP,
[
   AC_FUNC_MMAP

   if test $ac_cv_func_mmap_fixed_mapped = yes; then
      WITH_MMAP=yes
   else
      WITH_MMAP=no
   fi
   AC_SUBST(WITH_MMAP)
])

#############################################################
# Checking for python
# This checks whether python is available on the system, and if yes
# what the paths are. The result can be forced by using the
#    --with-python=path
# command line switch
# The following variables are exported by configure on exit:
#    @PYTHON_BASE@:    Either "no" or the directory that contains python
#    @PYTHON_VERSION@: Version of python detected
#    @PYTHON_CFLAGS@:  Compiler flags to use for python code
#    @PYTHON_DIR@:     Directory for libpython.so
#    @PYTHON_LIBS@:    extra command line switches to pass to the linker.
#    @WITH_PYTHON@: either "yes" or "no" depending on whether
#                      python support is available.
#############################################################

AC_DEFUN(AM_PATH_PYTHON,
[
   NEED_PYTHON=no

   AC_ARG_WITH(python,
     [AC_HELP_STRING(
       [--with-python=<path>],
       [Specify the prefix of the Python installation])
AC_HELP_STRING(
       [--without-python],
       [Disable python support])],
     [PYTHON_PATH_WITH=$withval; NEED_PYTHON=$PYTHON_PATH_WITH],
     PYTHON_PATH_WITH=yes)
   AC_ARG_WITH(python-exec,
     [AC_HELP_STRING(
        [--with-python-exec=<path>],
        [forces a specific python executable (python3 for instance)])],
     [PYTHON_EXEC=$withval])
   AC_ARG_ENABLE(shared-python,
     AC_HELP_STRING(
       [--enable-shared-python],
       [Link with shared python library instead of static]),
     PYTHON_SHARED=$enableval,
     PYTHON_SHARED=no)

   if test "$PYTHON_EXEC" = ""; then
      PYTHON_EXEC="python"
   fi

   WITH_PYTHON=yes
   if test x"$PYTHON_PATH_WITH" = xno ; then
      AC_MSG_CHECKING(for python)
      AC_MSG_RESULT(no, use --with-python if needed)
      PYTHON_BASE=no
      WITH_PYTHON=no

   else
      AC_PATH_PROG(PYTHON, ${PYTHON_EXEC}, no, $PYTHON_PATH_WITH/bin:$PYTHON_PATH_WITH:$PATH)
      if test x"$PYTHON" = xno ; then
         PYTHON_BASE=no
         WITH_PYTHON=no
      else
        AC_MSG_CHECKING(for python >= 2.0)
        if test x"$PYTHON_PATH_WITH" != xyes ; then
           PYTHON_BASE=$PYTHON_PATH_WITH
        else
           PYTHON_BASE=`$PYTHON -c 'import sys; print(sys.prefix)' `
        fi

        PYTHON_MAJOR_VERSION=`$PYTHON -c 'import sys; print(sys.version_info[[0]])' 2>/dev/null`
        PYTHON_MINOR_VERSION=`$PYTHON -c 'import sys; print(sys.version_info[[1]])' 2>/dev/null`
        if test $PYTHON_MAJOR_VERSION -lt 2 ; then
           AC_MSG_RESULT(no, need at least version 2.0)
           PYTHON_BASE=no
           WITH_PYTHON=no
        else
           case "${host}" in
             # On windows, there are two possible types of installation for
             # python, where the layout of directories are different. Even when
             # running cygwin, we might want to link with a mingwin version of
             # python for easier redistribution of the application.

             *-*mingw32* | *cygwin* )
               if test -d ${PYTHON_BASE}/lib/python${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}/config; then
                 PYTHON_WIN32=no
               else
                 PYTHON_WIN32=yes
               fi
               ;;
             *)
               PYTHON_WIN32=no
               ;;
           esac

           if test x$PYTHON_WIN32 = xyes; then
             PYTHON_VERSION=$PYTHON_MAJOR_VERSION$PYTHON_MINOR_VERSION
             PYTHON_DIR=${PYTHON_BASE}/libs
           else
             PYTHON_VERSION=$PYTHON_MAJOR_VERSION.$PYTHON_MINOR_VERSION
             if test x$PYTHON_SHARED = xyes; then
                PYTHON_DIR=${PYTHON_BASE}/lib
             else
                PYTHON_DIR=${PYTHON_BASE}/lib/python${PYTHON_VERSION}/config
             fi
           fi

           AC_MSG_RESULT(yes (version $PYTHON_MAJOR_VERSION.$PYTHON_MINOR_VERSION))
        fi
      fi
   fi

   if test x"$PYTHON_BASE" != xno; then
      # Find the libs that are required to link with python. We first try
      # with python-config --libs, but this might not exist on the platform, or
      # might be incorrect, so we also have hard-coded fallbacks.

      if test $PYTHON_MAJOR_VERSION != 2; then
         PYCONFIG=python${PYTHON_MAJOR_VERSION}-config
      else
         PYCONFIG=python-config
      fi

      AC_PATH_PROG(PYTHON_CONFIG, ${PYCONFIG}, no, $PYTHON_PATH_WITH/bin:$PYTHON_PATH_WITH:$PATH)

      AC_MSG_CHECKING(if we can link with python (using python-config))
      if test x"$PYTHON_CONFIG" != xno ; then
         # We cannot use python-config --ldflags, which generates additional
         # switches not properly recognized by GNAT's linker on some systems,
         # for instance "-u _PyMac_Error" on OSX. So we add the "-L..." switch
         # explicitly
         PYTHON_LIBS=`$PYTHON_CONFIG --libs`
         PYTHON_LIBS="-L${PYTHON_DIR} ${PYTHON_LIBS}"

         case $build_os in
             *darwin*)  ;;
             *-*mingw32* | *cygwin* ) ;;
             *linux*) PYTHON_LIBS="${PYTHON_LIBS} -export-dynamic" ;;
         esac

         PYTHON_CFLAGS=`$PYTHON_CONFIG --includes`
      else
         PYTHON_LIBS=""
         PYTHON_CFLAGS=""
      fi

      SAVE_CFLAGS="${CFLAGS}"
      SAVE_LIBS="${LIBS}"
      CFLAGS="${SAVE_CFLAGS} ${PYTHON_CFLAGS}"
      LIBS="${SAVE_LIBS} ${PYTHON_LIBS}"


      AC_LINK_IFELSE(
        [AC_LANG_PROGRAM([
/*    will only work with gcc, but needed to use it with the mingwin python */
#define PY_LONG_LONG long long
#include <Python.h>
],[   Py_Initialize();])],
        [AC_MSG_RESULT(yes)],

        [
         AC_MSG_RESULT(no)
         AC_MSG_CHECKING(if we can link with python)
         # hard-code python dependencies
         if test \( -f ${PYTHON_DIR}/libpython${PYTHON_VERSION}.a \) -a \( ! x$PYTHON_SHARED = xyes \) ; then
            PYTHON_LIBS="${PYTHON_DIR}/libpython${PYTHON_VERSION}.a"
         else
            PYTHON_LIBS="-L${PYTHON_DIR} -lpython${PYTHON_VERSION}"
         fi

         case "${host}" in
            hppa*-hp-hpux1* )
               PYTHON_LIBS="-Wl,-E -lm ${PYTHON_LIBS}"
               ;;
            powerpc-ibm-aix5.* | powerpc-*-darwin* | *-darwin*)
               PYTHON_LIBS="-ldl -lm ${PYTHON_LIBS}"
               ;;
            *-sunos5.5* | *-solaris2.5* | *-sunos5* | *-solaris* )
               PYTHON_LIBS="-lresolv -lsocket -lnsl -ldl -lm ${PYTHON_LIBS}"
               ;;
            *linux* )
               PYTHON_LIBS="-Wl,-export-dynamic -lm -ldl ${PYTHON_LIBS}"
               ;;
            ia64-*hp-hpux11* )
               PYTHON_LIBS="-ldld -ldl -lm -Wl,-E ${PYTHON_LIBS}"
               ;;
            *-freebsd* )
               PYTHON_LIBS="-lm -lutil ${PYTHON_LIBS}"
               ;;
         esac

         if test x$PYTHON_WIN32 = xyes; then
            PYTHON_CFLAGS="-I${PYTHON_BASE}/include"
         else
            PYTHON_CFLAGS="-I${PYTHON_BASE}/include/python${PYTHON_VERSION}"
         fi

         # -lutil is almost always needed, for forkpty()
         CFLAGS="${SAVE_CFLAGS} ${PYTHON_CFLAGS}"
         LIBS="${SAVE_LIBS} ${PYTHON_LIBS}"

         AC_LINK_IFELSE(
           [AC_LANG_PROGRAM([
/* will only work with gcc, but needed to use it with the mingwin python */
#define PY_LONG_LONG long long
#include <Python.h>
],[Py_Initialize();])],
           [AC_MSG_RESULT(yes)],
           [LIBS="${LIBS} -lutil"
            AC_LINK_IFELSE(
             [AC_LANG_PROGRAM([
/* will only work with gcc, but needed to use it with the mingwin python */
#define PY_LONG_LONG long long
#include <Python.h>
],[Py_Initialize();])],
             [PYTHON_LIBS="${PYTHON_LIBS} -lutil"
            AC_MSG_RESULT(yes)],

            [LIBS="${LIBS} -lpthread -lutil -lz"
             AC_LINK_IFELSE(
               [AC_LANG_PROGRAM([
/* will only work with gcc, but needed to use it with the mingwin python */
#define PY_LONG_LONG long long
#include <Python.h>],[Py_Initialize();])],
               [PYTHON_LIBS="${PYTHON_LIBS} -lpthread -lutil -lz"
                AC_MSG_RESULT(yes)],

               [LIBS="${LIBS} -lpthread -lssl -lutil -lz"
                AC_LINK_IFELSE(
                  [AC_LANG_PROGRAM([
   /* will only work with gcc, but needed to use it with the mingwin python */
   #define PY_LONG_LONG long long
   #include <Python.h>],[Py_Initialize();])],
                  [PYTHON_LIBS="${PYTHON_LIBS} -lpthread -lssl -lutil -lz"
                   AC_MSG_RESULT(yes)],

               [AC_MSG_RESULT(no, [can't compile and link python example])
                WITH_PYTHON=no
                PYTHON_BASE=[]
                PYTHON_LIBS=[]])])])

        ])])

     # Restore an environment python-free, so that further tests are not
     # impacted in case we did not find python

     CFLAGS="${SAVE_CFLAGS}"
     LIBS="${SAVE_LIBS}"
   fi

   if test x"$WITH_PYTHON" = xno -a x"$NEED_PYTHON" != xno ; then
     AC_MSG_ERROR([Python not found])
   fi

   AC_SUBST(PYTHON_BASE)
   AC_SUBST(PYTHON_VERSION)
   AC_SUBST(PYTHON_DIR)
   AC_SUBST(PYTHON_LIBS)
   AC_SUBST(PYTHON_CFLAGS)
   AC_SUBST(WITH_PYTHON)
])

###########################################################################
## Checking for pygobject
##
###########################################################################

AC_DEFUN(AM_PATH_PYGOBJECT,
[
    AC_ARG_ENABLE(pygobject,
      AC_HELP_STRING(
        [--disable-pygobject],
        [Disable support for PyGobject [[default=enabled]]]),
      [WITH_PYGOBJECT=$enableval],
      [WITH_PYGOBJECT=$WITH_PYTHON])

    AC_MSG_CHECKING(for pygobject)

    if test "$PKG_CONFIG" = "" -o "$PKG_CONFIG" = "no" ; then
       AC_MSG_RESULT(no (pkg-config not found))
       WITH_PYGOBJECT=no

    elif test "$GTK_VERSION" = "no" ; then
       AC_MSG_RESULT(no (gtk+ not found))
       WITH_PYGOBJECT=no

    elif test x"$WITH_PYGOBJECT" = x -o x"$WITH_PYGOBJECT" = xno ; then
       AC_MSG_RESULT(no (disabled by user))
       WITH_PYGOBJECT=no

    else
       for version in 3.0 2.0 ; do
           module="pygobject-$version"
           $PKG_CONFIG $module --exists
           if test $? = 0 ; then
               break;
           fi
           module=""
       done

       if test "$module" = "" ; then
          AC_MSG_RESULT(no)
          WITH_PYGOBJECT=no
       else
          PYGOBJECT_INCLUDE=`$PKG_CONFIG $module --cflags`
          PYGOBJECT_LIB=`$PKG_CONFIG $module --libs`
          AC_MSG_RESULT(yes ($version))
          WITH_PYGOBJECT=yes
          PYGOBJECT_INCLUDE="$PYGOBJECT_INCLUDE -DPYGOBJECT"
       fi
    fi

    AC_SUBST(WITH_PYGOBJECT)
    AC_SUBST(PYGOBJECT_INCLUDE)
    AC_SUBST(PYGOBJECT_LIB)
])

###########################################################################
## Checking for pygtk
##   $1=minimum pygtk version required
## This function checks whether pygtk exists on the system, and has a recent
## enough version. It exports the following variables:
##    @WITH_PYGTK@:    "yes" or "no"
##    @PYGTK_PREFIX@:  installation directory of pygtk
##    @PYGTK_INCLUDE@: cflags to use when compiling a pygtk application
## This function must be called after the variable PKG_CONFIG has been set,
## ie probably after gtk+ itself has been detected. Python must also have been
## detected first.
###########################################################################


AC_DEFUN(AM_PATH_PYGTK,
[
    AC_ARG_ENABLE(pygtk,
      AC_HELP_STRING(
        [--disable-pygtk],
        [Disable support for PyGTK [[default=enabled]]]),
      [WITH_PYGTK=$enableval],
      [WITH_PYGTK=$WITH_PYTHON])

    if test "$PKG_CONFIG" = "" -o "$PKG_CONFIG" = "no" ; then
       AC_MSG_CHECKING(for pygtk)
       AC_MSG_RESULT(no (pkg-config not found))
       WITH_PYGTK=no

    elif test "$GTK_VERSION" != "2.0" ; then
       AC_MSG_CHECKING(for pygtk)
       AC_MSG_RESULT(no (incompatible gtk+ version))
       WITH_PYGTK=no

    else
       min_pygtk_version=ifelse([$1], ,2.8,$1)
       module=pygtk-2.0
       AC_MSG_CHECKING(for pygtk - version >= $min_pygtk_version)

       if test x"$WITH_PYGTK" = x -o x"$WITH_PYGTK" = xno ; then
          AC_MSG_RESULT(no)
          PYGTK_PREFIX=""
          PYGTK_INCLUDE=""
          WITH_PYGTK=no

       elif test "$PYTHON_BASE" != "no" ; then
          $PKG_CONFIG $module --exists
          if test $? != 0 ; then
             AC_MSG_RESULT(no)
             WITH_PYGTK=no

          else
             pygtk_version=`$PKG_CONFIG $module --modversion`
             $PKG_CONFIG $module --atleast-version=$min_pygtk_version
             if test $? = 0 ; then
                PYGTK_INCLUDE="`$PKG_CONFIG $module --cflags` -DPYGTK"
                PYGTK_PREFIX=`$PKG_CONFIG $module --variable=prefix`
                AC_MSG_RESULT(yes (version $pygtk_version))
                WITH_PYGTK=yes
             else
                AC_MSG_RESULT(no (found $pygtk_version))
                PYGTK_PREFIX=""
                PYGTK_INCLUDE=""
                WITH_PYGTK=no
             fi
          fi

       else
          AC_MSG_RESULT(no since python not found)
          PYGTK_PREFIX=""
          PYGTK_INCLUDE=""
          WITH_PYGTK=no
       fi
    fi

    AC_SUBST(PYGTK_PREFIX)
    AC_SUBST(PYGTK_INCLUDE)
    AC_SUBST(WITH_PYGTK)
])

##########################################################################
## Compute the extension for shared libraries
##########################################################################

AC_DEFUN(AM_SO_SUFFIX,
[
    case $build_os in
      *darwin*) SO_EXT=.dylib ;;
      *cygwin*|*mingw*)  SO_EXT=.dll ;;
      *)        SO_EXT=.so ;;
    esac
    AC_SUBST(SO_EXT)
])

##########################################################################
## Converts a list of space-separated words into a list suitable for
## inclusion in .gpr files
##   $1=the list
##   $2=exported name
##########################################################################

AC_DEFUN(AM_TO_GPR,
[
   value=[$1]

   # Special handling on darwin for gcc 4.5 and 4.7
   case "$build_os" in
      *darwin*)
         value=`echo $value | sed -e "s/-framework \([[^ ]]*\)/-Wl,-framework -Wl,\1/g"`
   esac

   output=$2
   result=""
   for v in $value; do
      if test "$result" != ""; then
         result="$result, "
      fi
      result="$result\"$v\""
   done
   $2=$result
   AC_SUBST($2)

])

##############################################################
# Usage: AM_HAS_GNAT_PROJECT(project)
# Check whether a given project file is available, and set
# HAVE_GNAT_PROJECT_<project> to "yes" or "no" accordingly.
# (from PolyORB ada.m4)
##############################################################

AC_DEFUN([AM_HAS_GNAT_PROJECT],
[
cat > conftest.gpr <<EOF
with "[$1]";
project Conftest is for Source_Files use (); end Conftest;
EOF
if AC_TRY_COMMAND([gnat ls -Pconftest.gpr system.ads > /dev/null 2>conftest.out])
then
  HAVE_GNAT_PROJECT_$1=yes
else
  HAVE_GNAT_PROJECT_$1=no
fi
AC_MSG_RESULT($HAVE_GNAT_PROJECT_$1)
AC_SUBST(HAVE_GNAT_PROJECT_$1)
])

##########################################################################
## Detects GTK and GtkAda
## Input:
##   If CONFIGURE_SWITCH_WITH_GTK is set, it specifies the default value
##     for gtk. Otherwise, configure will choose the most recent version.
## This exports the following variables
##     @PKG_CONFIG@: path to pkg-config, or "no" if not found
##     @GTK_GCC_FLAGS@: cflags to pass to the compiler. It isn't call
##                      GTK_CFLAGS for compatibility reasons with GPS
##     @WITH_GTK@: Either "yes" or "no", depending on whether gtk+ was found
##     @GTK_VERSION@: one of 2.0, 3.0 or "no"
##########################################################################

AC_DEFUN(AM_PATH_GTK,
[
   AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
   if test "$PKG_CONFIG" = "no" ; then
      WITH_GTK=no
      GTK_VERSION=no
   else
      AC_ARG_WITH(gtk,
         AC_HELP_STRING(
       [--with-gtk=version],
       [Specify the version of GTK to support (3.0 or 2.0)])
AC_HELP_STRING(
       [--without-gtk],
       [Disable support for GTK]),
         [WITH_GTK=$withval],
         [
            AC_MSG_CHECKING(for default gtk+ version)
            # Detect the version we should use, from the system
            for WITH_GTK in "$CONFIGURE_SWITCH_WITH_GTK" "3.0" "2.0" "no"; do
                if test "$WITH_GTK" != ""; then
                   GTK_PREFIX=`$PKG_CONFIG gtk+-${WITH_GTK} --variable=prefix`
                   if test "$GTK_PREFIX" != ""; then
                      break
                   fi
                fi
            done
            AC_MSG_RESULT($WITH_GTK)
         ])

      if test "$WITH_GTK" != "no"; then
          AC_MSG_CHECKING(for gtk+ ${WITH_GTK})
          GTK_PREFIX=`$PKG_CONFIG gtk+-${WITH_GTK} --variable=prefix`
          AC_MSG_RESULT($GTK_PREFIX)
          GTK_GCC_FLAGS=`$PKG_CONFIG gtk+-${WITH_GTK} --cflags`
          GTK_GCC_LIBS=`$PKG_CONFIG gtk+-${WITH_GTK} --libs`
          if test x"$GTK_GCC_FLAGS" != x ; then
             AC_MSG_CHECKING(for gtkada.gpr)
             AM_HAS_GNAT_PROJECT(gtkada)
             HAVE_GTKADA=$HAVE_GNAT_PROJECT_gtkada
             GTK_VERSION=$WITH_GTK
             WITH_GTK=${HAVE_GTKADA}
          else
             GTK_VERSION=no
             WITH_GTK=no
          fi
      fi
   fi

   AC_SUBST(PKG_CONFIG)
   AC_SUBST(GTK_GCC_FLAGS)
   AC_SUBST(GTK_GCC_LIBS)
   AC_SUBST(WITH_GTK)
   AC_SUBST(GTK_VERSION)
])