aboutsummaryrefslogtreecommitdiffstats
path: root/configure.ac
blob: f25847f6813bf07c03ee2df24c9b072b62fffd5e (plain)
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
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
# Process this file with autoconf to produce a configure script.
#
# Make sure we use autoconf 2.60 to generate the "configure" script,
# in case we want to commit it. Other than that, version 2.59 is
# perfectly fine for our purposes, so people who want to modify
# this file just have to remember to set the AC_PREREQ argument
# to something that suits their needs.

AC_PREREQ(2.60)

m4_define([PBX_VERSION],
          m4_bpatsubst(m4_esyscmd([build_tools/make_version .]),
                       [\([0-9.]*\)\(\w\|\W\)*],
                       [\1]))
AC_INIT(asterisk, PBX_VERSION, www.asterisk.org)

# cross-compile macros
AC_CANONICAL_BUILD
AC_CANONICAL_HOST

# check existence of the package
AC_CONFIG_SRCDIR([main/asterisk.c])

# specify output header file
AC_CONFIG_HEADER(include/asterisk/autoconfig.h)

AC_COPYRIGHT("Asterisk")
AC_REVISION($Revision$)

AC_GNU_SOURCE
AC_USE_SYSTEM_EXTENSIONS	# note- does not work on FreeBSD

case "${host_os}" in
     freebsd*)
     ac_default_prefix=/usr/local
     CPPFLAGS=-I/usr/local/include
     LDFLAGS=-L/usr/local/lib
     ;;

     *)
     ac_default_prefix=/usr
     if test ${sysconfdir} = '${prefix}/etc'; then
        sysconfdir=/etc
     fi
     if test ${mandir} = '${prefix}/man'; then
        mandir=/usr/share/man
     fi
     ;;
esac

if test ${localstatedir} = '${prefix}/var'; then
     localstatedir=/var
fi

BUILD_PLATFORM=${build}
BUILD_CPU=${build_cpu}
BUILD_VENDOR=${build_vendor}
BUILD_OS=${build_os}

AC_SUBST(BUILD_PLATFORM)
AC_SUBST(BUILD_CPU)
AC_SUBST(BUILD_VENDOR)
AC_SUBST(BUILD_OS)

HOST_PLATFORM=${host}
HOST_CPU=${host_cpu}
HOST_VENDOR=${host_vendor}
HOST_OS=${host_os}

AC_SUBST(HOST_PLATFORM)
AC_SUBST(HOST_CPU)
AC_SUBST(HOST_VENDOR)
AC_SUBST(HOST_OS)

case "${host_os}" in
     freebsd*)
     OSARCH=FreeBSD
     ;;
     netbsd*)
     OSARCH=NetBSD
     ;;
     openbsd*)
     OSARCH=OpenBSD
     ;;
     solaris*)
     OSARCH=SunOS
     ;;
     *)
     OSARCH=${HOST_OS}
     ;;
esac

AC_SUBST(OSARCH)

#  check for uname
AC_PATH_TOOL([UNAME], [uname], No)
if test ! x"${UNAME}" = xNo; then
   PBX_OSREV=$(${UNAME} -r)
fi
AC_SUBST(PBX_OSREV)

AH_TOP(
#ifndef ASTERISK_AUTOCONFIG_H
#define ASTERISK_AUTOCONFIG_H

#include "asterisk/buildopts.h"

)

AH_BOTTOM(
#endif
)

# cross-compile checks
if test "${cross_compiling}" = "yes"; 
then
   AC_CHECK_TOOL(CC, gcc, :)
   AC_CHECK_TOOL(CXX, g++, :)
   AC_CHECK_TOOL(LD, ld, :)
   AC_CHECK_TOOL(RANLIB, ranlib, :)
fi

# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_PROG_CPP
AC_PROG_CXXCPP
# This macro is just copied into our local acinclude.m4 from libtool.m4 so that
# the developers regenerating the configure script don't have to install libtool.
AST_PROG_LD	# note, does not work on FreeBSD
AC_PROG_AWK
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_RANLIB
AST_CHECK_GNU_MAKE

AC_PATH_TOOL([STRIP], [strip], :)
AC_PATH_TOOL([AR], [ar], :)

GNU_LD=0
if test "x$with_gnu_ld" = "xyes" ; then
   GNU_LD=1
fi
AC_SUBST(GNU_LD)

AC_PATH_PROG([GREP], [grep], :)
AC_PATH_PROG([FIND], [find], :)
AC_PATH_PROG([COMPRESS], [compress], :)
AC_PATH_PROG([BASENAME], [basename], :)
AC_PATH_PROG([ID], [id], :)
AC_PATH_PROG([DIRNAME], [dirname], :)
AC_PATH_PROG([SHELL], [sh], :)
AC_PATH_PROG([LN], [ln], :)
AC_PATH_PROG([DOT], [dot], :)
AC_PATH_PROG([WGET], [wget], :)
AC_PATH_PROG([RUBBER], [rubber], :)
if test "${WGET}" != ":" ; then
  DOWNLOAD=${WGET}
else
  AC_PATH_PROG([FETCH], [fetch], [:])
  DOWNLOAD=${FETCH}
fi
AC_SUBST(DOWNLOAD)

ACX_PTHREAD

AC_LANG(C)

AC_ARG_ENABLE(dev-mode,
	[  --enable-dev-mode    Turn on developer mode],
	[case "${enableval}" in
	      y|ye|yes) AST_DEVMODE=yes ;;
	      n|no)  AST_DEVMODE=no ;;
	      *) AC_MSG_ERROR(bad value ${enableval} for --enable-dev-mode)  ;;
	esac])
AC_SUBST(AST_DEVMODE)

# package option names should be in alphabetical order
# by the --with option name, to make things easier for the users :-)

AST_EXT_LIB_SETUP([ALSA], [Advanced Linux Sound Architecture], [asound])

# BKTR is used for backtrace support on platforms that do not
# have it natively.
AST_EXT_LIB_SETUP([BKTR], [Stack Backtrace support], [execinfo])
AST_EXT_LIB_SETUP([CAP], [POSIX 1.e capabilities], [cap])
AST_EXT_LIB_SETUP([CURL], [cURL], [curl])
AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
AST_EXT_LIB_SETUP([CRYPTO], [OpenSSL Cryptography support], [crypto])
AST_EXT_LIB_SETUP([GSM], [GSM], [gsm], [, or 'internal'])
AST_EXT_LIB_SETUP([IKSEMEL], [Iksemel Jabber Library], [iksemel])
AST_EXT_LIB_SETUP([IMAP_TK], [UW IMAP Toolkit], [imap])
AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux Library], [isdnnet])
AST_EXT_LIB_SETUP([KDE], [KDE], [kde])
AST_EXT_LIB_SETUP([LTDL], [libtool], [ltdl])
AST_EXT_LIB_SETUP([LUA], [Lua], [lua])
AST_EXT_LIB_SETUP([MISDN], [mISDN User Library], [misdn])
AST_EXT_LIB_SETUP([NBS], [Network Broadcast Sound], [nbs])
AST_EXT_LIB_SETUP([NCURSES], [ncurses], [ncurses])
AST_EXT_LIB_SETUP([NETSNMP], [Net-SNMP], [netsnmp])
AST_EXT_LIB_SETUP([NEWT], [newt], [newt])
AST_EXT_LIB_SETUP([UNIXODBC], [unixODBC], [odbc])
AST_EXT_LIB_SETUP([OGG], [OGG], [ogg])
AST_EXT_LIB_SETUP([OSPTK], [OSP Toolkit], [osptk])
AST_EXT_LIB_SETUP([OSS], [Open Sound System], [oss])
AST_EXT_LIB_SETUP([POPT], [popt], [popt])
AST_EXT_LIB_SETUP([PGSQL], [PostgreSQL], [postgres])
AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
AST_EXT_LIB_SETUP([SS7], [ISDN SS7], [ss7])
AST_EXT_LIB_SETUP([PWLIB], [PWlib], [pwlib])
AST_EXT_LIB_SETUP([OPENH323], [OpenH323], [h323])
AST_EXT_LIB_SETUP([QT], [Qt], [qt])
AST_EXT_LIB_SETUP([RADIUS], [Radius Client], [radius])
AST_EXT_LIB_SETUP([SPEEX], [Speex], [speex])
AST_EXT_LIB_SETUP([SQLITE], [SQLite], [sqlite])
AST_EXT_LIB_SETUP([SQLITE3], [SQLite], [sqlite3])
AST_EXT_LIB_SETUP([SUPPSERV], [mISDN Supplemental Services], [suppserv])
AST_EXT_LIB_SETUP([OPENSSL], [OpenSSL Secure Sockets Layer support], [ssl])
AST_EXT_LIB_SETUP([FREETDS], [FreeTDS], [tds])
AST_EXT_LIB_SETUP([TERMCAP], [Termcap], [termcap])
AST_EXT_LIB_SETUP([TINFO], [Term Info], [tinfo])
AST_EXT_LIB_SETUP([TONEZONE], [tonezone], [tonezone])
AST_EXT_LIB_SETUP([USB], [usb], [usb])
AST_EXT_LIB_SETUP([VORBIS], [Vorbis], [vorbis])
AST_EXT_LIB_SETUP([VPB], [Voicetronix API], [vpb])
AST_EXT_LIB_SETUP([ZLIB], [zlib], [z])
AST_EXT_LIB_SETUP([ZAPTEL], [Zaptel], [zaptel])
AST_EXT_LIB_SETUP([ZAPTEL_TRANSCODE], [Zaptel_transcode], [zaptel_transcode])
AST_EXT_LIB_SETUP([ZAPTEL_VLDTMF], [Zaptel_vldtmf], [zaptel_vldtmf])

# check for basic system features and functionality before
# checking for package libraries

AC_FUNC_ALLOCA
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h utime.h])

AC_SYS_LARGEFILE

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_UID_T
AC_C_INLINE
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_CHECK_MEMBERS([struct stat.st_blksize])
AC_HEADER_TIME
AC_STRUCT_TM
AC_C_VOLATILE
AC_CHECK_TYPES([ptrdiff_t])

# Checks for library functions.
AC_FUNC_CHOWN
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_ERROR_AT_LINE
AST_FUNC_FORK
AC_FUNC_FSEEKO
AC_PROG_GCC_TRADITIONAL
# XXX: these are commented out until we determine whether it matters if our malloc()
# acts exactly like glibc's or not
# AC_FUNC_MALLOC
# AC_FUNC_REALLOC
AC_FUNC_MEMCMP
AC_FUNC_MKTIME
AC_FUNC_MMAP
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_SETVBUF_REVERSED
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_FUNC_STRCOLL
AC_FUNC_STRFTIME
AC_FUNC_STRNLEN
AC_FUNC_STRTOD
AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([asprintf atexit bzero dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf])

# https support (in main/http.c) uses funopen on BSD systems,
# fopencookie on linux
AC_CHECK_FUNCS([funopen fopencookie])

# some systems already have gethostbyname_r so we don't need to build ours in main/utils.c
AC_SEARCH_LIBS(gethostbyname_r, [socket nsl])

AC_MSG_CHECKING(for gethostbyname_r with 6 arguments)
AC_LINK_IFELSE(
        AC_LANG_PROGRAM([#include <stdlib.h>
                         #include <netdb.h>],
                        [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (struct hostent **)NULL, (int *)NULL);]),
        AC_MSG_RESULT(yes)
        AC_DEFINE([HAVE_GETHOSTBYNAME_R_6], 1, [Define to 1 if your system has gethostbyname_r with 6 arguments.]),
        AC_MSG_RESULT(no)
)

AC_MSG_CHECKING(for gethostbyname_r with 5 arguments)
AC_LINK_IFELSE(
        AC_LANG_PROGRAM([#include <stdlib.h>
	                 #include <netdb.h>],
                        [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (int *)NULL);]),
        AC_MSG_RESULT(yes)
        AC_DEFINE([HAVE_GETHOSTBYNAME_R_5], 1, [Define to 1 if your system has gethostbyname_r with 5 arguments.]),
        AC_MSG_RESULT(no)
)

AC_CHECK_HEADER([byteswap.h], [AC_DEFINE_UNQUOTED([HAVE_BYTESWAP_H], 1, [Define to 1 if byteswap.h macros are available.])])

AC_MSG_CHECKING(for __swap16 variant of <sys/endian.h> byteswapping macros)
AC_LINK_IFELSE(
AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = __swap16(a);]),
AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_SYS_ENDIAN_SWAP16], 1, [Define to 1 if your sys/endian.h header file provides the __swap16 macro.]),
AC_MSG_RESULT(no)
)

AC_MSG_CHECKING(for bswap16 variant of <sys/endian.h> byteswapping macros)
AC_LINK_IFELSE(
AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = bswap16(a);]),
AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_SYS_ENDIAN_BSWAP16], 1, [Define to 1 if your sys/endian.h header file provides the bswap16 macro.]),
AC_MSG_RESULT(no)
)

if test "${cross_compiling}" = "no";
then
  AC_CHECK_FILE(/dev/urandom, AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define to 1 if your system has /dev/urandom.]))
fi

AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_INITIALIZER], [PTHREAD_RWLOCK_INITIALIZER], [pthread.h])
AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_PREFER_WRITER_NP], [PTHREAD_RWLOCK_PREFER_WRITER_NP], [pthread.h])

if test "${cross_compiling}" = "no";
then
AC_MSG_CHECKING(for working epoll support)
AC_LINK_IFELSE(
AC_LANG_PROGRAM([#include <sys/epoll.h>], [int res = epoll_create(10);
					  if (res < 0)
					     return 1;
					  close (res);
					  return 0;]),
AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_EPOLL], 1, [Define to 1 if your system has working epoll support.]),
AC_MSG_RESULT(no)
)
fi

AC_MSG_CHECKING(for compiler atomic operations)
AC_LINK_IFELSE(
AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);]),
AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides atomic operations.]),
AC_MSG_RESULT(no)
)

AST_GCC_ATTRIBUTE(pure)
AST_GCC_ATTRIBUTE(malloc)
AST_GCC_ATTRIBUTE(const)
AST_GCC_ATTRIBUTE(unused)
AST_GCC_ATTRIBUTE(always_inline)
AST_GCC_ATTRIBUTE(deprecated)

AC_MSG_CHECKING(for -ffunction-sections support)
saved_CFLAGS="${CFLAGS}"
CFLAGS="${CFLAGS} -ffunction-sections"
AC_COMPILE_IFELSE(
	AC_LANG_PROGRAM([], [int x = 1;]),
	AC_MSG_RESULT(yes)
	[saved_LDFLAGS="${LDFLAGS}"]
	[LDFLAGS="${LDFLAGS} -Wl,--gc-sections"]
	AC_MSG_CHECKING(for --gc-sections support)
	AC_LINK_IFELSE(
		AC_LANG_PROGRAM([], [int x = 1;]),
		AC_MSG_RESULT(yes)
		[GC_CFLAGS="-ffunction-sections"]
		[[GC_LDFLAGS="-Wl,--gc-sections"]],
		AC_MSG_RESULT(no)
	)
	[LDFLAGS="${saved_LDFLAGS}"],
	AC_MSG_RESULT(no)
)
CFLAGS="${saved_CFLAGS}"
AC_SUBST(GC_CFLAGS)
AC_SUBST(GC_LDFLAGS)

AC_MSG_CHECKING(for -Wdeclaration-after-statement support)
if $(${CC} -Wdeclaration-after-statement -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
	AC_MSG_RESULT(yes)
	AST_DECLARATION_AFTER_STATEMENT=-Wdeclaration-after-statement
else
	AC_MSG_RESULT(no)
	AST_DECLARATION_AFTER_STATEMENT=
fi
AC_SUBST(AST_DECLARATION_AFTER_STATEMENT)


AC_MSG_CHECKING(for sysinfo)
AC_LINK_IFELSE(
        AC_LANG_PROGRAM([#include <sys/sysinfo.h>],
                        [struct sysinfo sys_info; int uptime = sys_info.uptime]),
        AC_MSG_RESULT(yes)
        AC_DEFINE([HAVE_SYSINFO], 1, [Define to 1 if your system has sysinfo support]),
        AC_MSG_RESULT(no)
)

AC_MSG_CHECKING(for res_ninit)
AC_LINK_IFELSE(
	AC_LANG_PROGRAM([#include <resolv.h>],
			[int foo = res_ninit(NULL);]),
	AC_MSG_RESULT(yes)
	AC_DEFINE([HAVE_RES_NINIT], 1, [Define to 1 if your system has the re-entrant resolver functions.])
	AC_MSG_CHECKING(for res_ndestroy)
	AC_LINK_IFELSE(
		AC_LANG_PROGRAM([#include <resolv.h>],
				[int foo = res_ndestroy(NULL);]),
		AC_MSG_RESULT(yes)
		AC_DEFINE([HAVE_RES_NDESTROY], 1, [Define to 1 if your system has the ndestroy resolver function.]),
		AC_MSG_RESULT(no)
	),
	AC_MSG_RESULT(no)
)

AST_C_DEFINE_CHECK([RTLD_NOLOAD], [RTLD_NOLOAD], [dlfcn.h])

AST_C_DEFINE_CHECK([IP_MTU_DISCOVER], [IP_MTU_DISCOVER], [netinet/in.h])

AC_CHECK_HEADER([libkern/OSAtomic.h],
                [AC_DEFINE_UNQUOTED([HAVE_OSX_ATOMICS], 1, [Define to 1 if OSX atomic operations are supported.])])

AC_CHECK_SIZEOF(int)

# do the package library checks now

AST_EXT_LIB_CHECK([ALSA], [asound], [snd_spcm_init], [alsa/asoundlib.h], [-lm -ldl])

AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])

if test "x${host_os}" = "xlinux-gnu" ; then
  AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h])
fi

# BSD might not have exp2, and/or log2
AST_EXT_LIB_CHECK([EXP2L], [m], [exp2l])
AST_EXT_LIB_CHECK([LOG2L], [m], [log2l])
AST_EXT_LIB_CHECK([EXP10L], [m], [exp10l])
AST_EXT_LIB_CHECK([LOG10L], [m], [log10l])
AST_EXT_LIB_CHECK([SINL], [m], [sinl])
AST_EXT_LIB_CHECK([COSL], [m], [cosl])
AST_EXT_LIB_CHECK([TANL], [m], [tanl])
AST_EXT_LIB_CHECK([ASINL], [m], [asinl])
AST_EXT_LIB_CHECK([ACOSL], [m], [acosl])
AST_EXT_LIB_CHECK([ATANL], [m], [atanl])
AST_EXT_LIB_CHECK([ATAN2L], [m], [atan2l])
AST_EXT_LIB_CHECK([POWL], [m], [powl])
AST_EXT_LIB_CHECK([SQRTL], [m], [sqrtl])
AST_EXT_LIB_CHECK([RINTL], [m], [rintl])
AST_EXT_LIB_CHECK([EXPL], [m], [expl])
AST_EXT_LIB_CHECK([LOGL], [m], [logl])
AST_EXT_LIB_CHECK([REMAINDERL], [m], [remainderl])
AST_EXT_LIB_CHECK([FMODL], [m], [fmodl])
AST_EXT_LIB_CHECK([ROUNDL], [m], [roundl])
AST_EXT_LIB_CHECK([TRUNCL], [m], [truncl])
AST_EXT_LIB_CHECK([STRTOLD], [c], [strtold], [stdlib.h])
AST_EXT_LIB_CHECK([FLOORL], [m], [floorl])
AST_EXT_LIB_CHECK([CEILL], [m], [ceill])
AST_EXT_LIB_CHECK([EXP2], [m], [exp2])
AST_EXT_LIB_CHECK([LOG2], [m], [log2])
AST_EXT_LIB_CHECK([EXP10], [m], [exp10])
AST_EXT_LIB_CHECK([LOG10], [m], [log10])
AST_EXT_LIB_CHECK([SIN], [m], [sin])
AST_EXT_LIB_CHECK([COS], [m], [cos])
AST_EXT_LIB_CHECK([TAN], [m], [tan])
AST_EXT_LIB_CHECK([ASIN], [m], [asin])
AST_EXT_LIB_CHECK([ACOS], [m], [acos])
AST_EXT_LIB_CHECK([ATAN], [m], [atan])
AST_EXT_LIB_CHECK([ATAN2], [m], [atan2])
AST_EXT_LIB_CHECK([POW], [m], [pow])
AST_EXT_LIB_CHECK([SQRT], [m], [sqrt])
AST_EXT_LIB_CHECK([RINT], [m], [rint])
AST_EXT_LIB_CHECK([EXP], [m], [exp])
AST_EXT_LIB_CHECK([LOG], [m], [log])
AST_EXT_LIB_CHECK([REMAINDER], [m], [remainder])
AST_EXT_LIB_CHECK([FMOD], [m], [fmod])
AST_EXT_LIB_CHECK([ROUND], [m], [round])
AST_EXT_LIB_CHECK([TRUNC], [m], [trunc])
AST_EXT_LIB_CHECK([STRTOD], [c], [strtod], [stdlib.h])
AST_EXT_LIB_CHECK([FLOOR], [m], [floor])
AST_EXT_LIB_CHECK([CEIL], [m], [ceil])

GSM_INTERNAL="yes"
AC_SUBST(GSM_INTERNAL)
GSM_SYSTEM="yes"
if test "${USE_GSM}" != "no"; then
   if test "${GSM_DIR}" = "internal"; then
      GSM_SYSTEM="no"
   elif test "${GSM_DIR}" != ""; then
      GSM_INTERNAL="no"
   fi
   if test "${GSM_SYSTEM}" = "yes"; then
      gsmlibdir=""
      if test "x${GSM_DIR}" != "x"; then
         if test -d ${GSM_DIR}/lib; then
            gsmlibdir="-L${GSM_DIR}/lib"
         else
            gsmlibdir="-L${GSM_DIR}"
         fi
      fi
      AC_CHECK_LIB([gsm], [gsm_create], AC_DEFINE_UNQUOTED([HAVE_GSM], 1,
      [Define to indicate the GSM library]), [], ${gsmlibdir})
      if test "${ac_cv_lib_gsm_gsm_create}" = "yes"; then
         if test "x${GSM_DIR}" != "x" ; then
            AC_CHECK_HEADER([${GSM_DIR}/include/gsm.h], [GSM_HEADER_FOUND=1], [GSM_HEADER_FOUND=0])
            AC_CHECK_HEADER([${GSM_DIR}/include/gsm/gsm.h], [GSM_GSM_HEADER_FOUND=1], [GSM_GSM_HEADER_FOUND=0])
         else
            AC_CHECK_HEADER([gsm.h], [GSM_HEADER_FOUND=1], [GSM_HEADER_FOUND=0])
            AC_CHECK_HEADER([gsm/gsm.h], [GSM_GSM_HEADER_FOUND=1], [GSM_GSM_HEADER_FOUND=0])
         fi
         if test "${GSM_HEADER_FOUND}" = "0" ; then
            if test "{GSM_GSM_HEADER_FOUND}" = "0" ; then
               if test "x${GSM_MANDATORY}" = "xyes" ; then
                  AC_MSG_NOTICE([***])
                  AC_MSG_NOTICE([*** It appears that you do not have the gsm development package installed.])
                  AC_MSG_NOTICE([*** Please install it to include ${GSM_DESCRIP} support, or re-run configure])
                  AC_MSG_NOTICE([*** without explicitly specifying --with-${GSM_OPTION}])
                  exit 1
               fi
            fi
         fi
         GSM_OK=0
         if test "${GSM_HEADER_FOUND}" = "1" ; then
            AC_DEFINE_UNQUOTED([HAVE_GSM_HEADER], 1, [Define to indicate that gsm.h has no prefix for its location])
            GSM_OK=1
         else
            if test "${GSM_GSM_HEADER_FOUND}" = "1" ; then
               AC_DEFINE_UNQUOTED([HAVE_GSM_GSM_HEADER], 1, [Define to indicate that gsm.h is in gsm/gsm.h])
               GSM_OK=1
            fi
         fi
         if test "${GSM_OK}" = "1" ; then
            GSM_LIB="-lgsm"
            if test "x${GSM_DIR}" != "x"; then
               GSM_LIB="${gsmlibdir} ${GSM_LIB}"
               GSM_INCLUDE="-I${GSM_DIR}/include"
            fi
            PBX_GSM=1
            GSM_INTERNAL="no"
         fi
      fi
   fi
   if test "${GSM_INTERNAL}" = "yes"; then
      PBX_GSM=1
      AC_DEFINE_UNQUOTED([HAVE_GSM_HEADER], 1, [Define to indicate that gsm.h has no prefix for its location])
   fi
fi

AST_EXT_LIB_CHECK([IKSEMEL], [iksemel], [iks_start_sasl], [iksemel.h])

if test "${USE_IMAP_TK}" != "no"; then
   if test "${IMAP_TK_DIR}" = "system" ; then
      AC_MSG_NOTICE([Checking for system c-client library...])
   elif test "${IMAP_TK_DIR}" = ""; then
      IMAP_TK_DIR=`pwd`"/../imap-2004g"
      if test  -n "${IMAP_TK_MANDATORY}"; then
	 AC_MSG_NOTICE([The --with-imap option does not search your system for installed])
	 AC_MSG_NOTICE([c-client library/header files. Since you did not provide a path])
	 AC_MSG_NOTICE([the configure script will assume you have placed built the c-client])
	 AC_MSG_NOTICE([files at ${IMAP_TK_DIR}, as outlined in the doc/imapstorage.txt file.])
      fi
   fi
   if test "${IMAP_TK_DIR}" != "system" ; then
      AC_MSG_CHECKING(for UW IMAP Toolkit c-client library)
   fi
   saved_cppflags="${CPPFLAGS}"
   saved_libs="${LIBS}"
   if test "${IMAP_TK_DIR}" = "system" ; then
      imap_ldflags=""
      imap_libs="-lc-client"
      imap_include="-DUSE_SYSTEM_IMAP"
   elif test -f ${IMAP_TK_DIR}/c-client/LDFLAGS ; then
      imap_ldflags=`cat ${IMAP_TK_DIR}/c-client/LDFLAGS`
      imap_libs="${IMAP_TK_DIR}/c-client/c-client.a"
      imap_include="-I${IMAP_TK_DIR}/c-client"
   fi
   CPPFLAGS="${CPPFLAGS} ${imap_include}"
   LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
   AC_LINK_IFELSE(
	AC_LANG_PROGRAM(
		[#ifdef USE_SYSTEM_IMAP
		#include <imap/c-client.h>
		#else
		#include "c-client.h"
		#endif
		void mm_searched (MAILSTREAM *stream,unsigned long number)
		{
		}
		void mm_exists (MAILSTREAM *stream,unsigned long number)
		{
		}
		void mm_expunged (MAILSTREAM *stream,unsigned long number)
		{
		}
		void mm_flags (MAILSTREAM *stream,unsigned long number)
		{
		}
		void mm_notify (MAILSTREAM *stream,char *string,long errflg)
		{
		}
		void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
		{
		}
		void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
		{
		}
		void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
		{
		}
		void mm_log (char *string,long errflg)
		{
		}
		void mm_dlog (char *string)
		{
		}
		void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
		{
		}
		void mm_critical (MAILSTREAM *stream)
		{
		}
		void mm_nocritical (MAILSTREAM *stream)
		{
		}
		long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
		{
		}
		void mm_fatal (char *string)
		{
		}],
		[
		MAILSTREAM *foo = mail_open(NULL, "", 0);
		]
	),
	[ac_cv_imap_tk="yes"],
	[ac_cv_imap_tk="no"]
   )
   if test "${ac_cv_imap_tk}" = "yes"; then
   AC_LINK_IFELSE(
      AC_LANG_PROGRAM(
         [#ifdef USE_SYSTEM_IMAP
	 #include <imap/c-client.h>
	 #else
	 #include "c-client.h"
	 #endif
         void mm_searched (MAILSTREAM *stream,unsigned long number)
         {
         }
         void mm_exists (MAILSTREAM *stream,unsigned long number)
         {
         }
         void mm_expunged (MAILSTREAM *stream,unsigned long number)
         {
         }
         void mm_flags (MAILSTREAM *stream,unsigned long number)
         {
         }
         void mm_notify (MAILSTREAM *stream,char *string,long errflg)
         {
         }
         void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
         {
         }
         void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
         {
         }
         void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
         {
         }
         void mm_log (char *string,long errflg)
         {
         }
         void mm_dlog (char *string)
         {
         }
         void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
         {
         }
         void mm_critical (MAILSTREAM *stream)
         {
         }
         void mm_nocritical (MAILSTREAM *stream)
         {
         }
         long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
         {
         }
         void mm_fatal (char *string)
         {
         }],
         [
         long check = mail_expunge_full(NULL, "", 0);
         ]
      ),
      [ac_cv_imap_tk2006="yes"],
      [ac_cv_imap_tk2006="no"]
  )
  fi
   CPPFLAGS="${saved_cppflags}"
   LIBS="${saved_libs}"
   if test "${ac_cv_imap_tk}" = "yes"; then
      AC_MSG_RESULT(yes) 
      IMAP_TK_LIB="${imap_libs} "`echo ${imap_ldflags}`
      IMAP_TK_INCLUDE="${imap_include}"
      PBX_IMAP_TK=1
      AC_DEFINE([HAVE_IMAP_TK], 1, [Define if your system has the UW IMAP Toolkit c-client library.])
      if test "${ac_cv_imap_tk2006}" = "yes"; then
         AC_DEFINE([HAVE_IMAP_TK2006], 1, [Define if your system has the UW IMAP Toolkit c-client library version 2006 or greater.])
      fi
   else
      AC_MSG_RESULT(no) 
   fi
fi

# Needed by unixodbc
AST_EXT_LIB_CHECK([LTDL], [ltdl], [lt_dlinit], [ltdl.h], [])

AC_LANG_PUSH(C++)

if test "${USE_KDE}" != "no"; then
   AC_MSG_CHECKING(for crashHandler in -lkdecore)
   saved_libs="${LIBS}"
   saved_cppflags="${CPPFLAGS}"
   CPPFLAGS="${CPPFLAGS} -I${KDE_DIR}/include"
   if test -d ${KDE_DIR}/lib; then
      kdelibdir="${KDE_DIR}/lib"
   else
      kdelibdir="${KDE_DIR}"
   fi
   LIBS="${LIBS} -L${kdelibdir} -lkdecore"

   AC_LINK_IFELSE(
	[AC_LANG_PROGRAM(
			[#include "kcrash.h"],
			[KCrash::defaultCrashHandler(1);])
	],
	[ac_cv_lib_kde_crash="yes"],
	[ac_cv_lib_kde_crash="no"])
		
   LIBS="${saved_libs}"
   CPPFLAGS="${saved_cppflags}"
	
   if test "${ac_cv_lib_kde_crash}" = "yes"; then
      AC_MSG_RESULT(yes) 
      KDE_LIB="-lkdecore -lkdeui"
      if test "${KDE_DIR}" != ""; then
      	 KDE_LIB="-L${kdelibdir} ${KDE_LIB}"
	 KDE_INCLUDE="-I${KDE_DIR}/include"
      fi
      PBX_KDE=1
      AC_DEFINE([HAVE_LIBKDE], 1, [Define if your system has the KDE libraries.])
   else
      AC_MSG_RESULT(no) 
   fi
fi
if test "${PBX_KDE}" = 1; then
   AC_PATH_TOOL(KDEINIT, kdeinit, No)
   if test ! x"${KDEINIT}" = xNo; then
      KDEDIR=$(${DIRNAME} ${KDEINIT})
      KDEDIR=$(${DIRNAME} ${KDEDIR})
   fi
   AC_SUBST([KDEDIR])
fi

AC_LANG_POP

AST_EXT_LIB_CHECK([MISDN], [mISDN], [mISDN_open], [mISDNuser/mISDNlib.h])

if test "${PBX_MISDN}" = 1; then
   AST_EXT_LIB_CHECK([ISDNNET], [isdnnet], [init_manager], [mISDNuser/isdn_net.h], [-lmISDN -lpthread])
   AST_EXT_LIB_CHECK([SUPPSERV], [suppserv], [encodeFac], [mISDNuser/suppserv.h])
   AST_C_DEFINE_CHECK([MISDN_FAC_RESULT], [Fac_RESULT], [mISDNuser/suppserv.h])
   AST_C_DEFINE_CHECK([MISDN_FAC_ERROR], [Fac_ERROR], [mISDNuser/suppserv.h])
   AC_CHECK_HEADER([linux/mISDNdsp.h], [AC_DEFINE_UNQUOTED([MISDN_1_2], 1, [Build chan_misdn for mISDN 1.2 or later.])])
fi

AST_EXT_LIB_CHECK([NBS], [nbs], [nbs_connect], [nbs.h])

AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [curses.h])

NETSNMP_CONFIG=No
if test "${USE_NETSNMP}" != "no"; then	
   if test "x${NETSNMP_DIR}" != "x"; then
      AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], No, [${NETSNMP_DIR}/bin])
      if test x"${NETSNMP_CONFIG}" = xNo; then
         AC_MSG_NOTICE([***])
         AC_MSG_NOTICE([*** net-snmp-config was not found in the path you specified:])
         AC_MSG_NOTICE([*** ${NETSNMP_DIR}/bin])
         AC_MSG_NOTICE([*** Either correct the installation, or run configure])
         AC_MSG_NOTICE([*** including --without-netsnmp])
         exit 1
      fi
   else
      AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], No)
   fi
fi
if test x"${NETSNMP_CONFIG}" != xNo; then
   NETSNMP_libs=`${NETSNMP_CONFIG} --agent-libs`
   
   AC_CHECK_LIB([netsnmp], [snmp_register_callback], AC_DEFINE_UNQUOTED([HAVE_NETSNMP], 1,
   [Define to indicate the Net-SNMP library]), [], ${NETSNMP_libs})

   if test "${ac_cv_lib_netsnmp_snmp_register_callback}" = "yes"; then
      NETSNMP_LIB="${NETSNMP_libs}"
      PBX_NETSNMP=1
   fi
fi

AST_EXT_LIB_CHECK([NEWT], [newt], [newtBell], [newt.h])

AST_EXT_LIB_CHECK([UNIXODBC], [odbc], [SQLConnect], [sql.h], [])

AST_EXT_LIB_CHECK([OGG], [ogg], [ogg_sync_init], [])

AST_EXT_LIB_CHECK([BKTR], [execinfo], [backtrace], [execinfo.h], [-lexecinfo])

# possible places for oss definitions
AST_EXT_LIB_CHECK([OSS], [ossaudio], [], [linux/soundcard.h])
AST_EXT_LIB_CHECK([OSS], [ossaudio], [], [sys/soundcard.h])
AST_EXT_LIB_CHECK([OSS], [ossaudio], [oss_ioctl_mixer], [soundcard.h])

PG_CONFIG=No
if test "${USE_PGSQL}" != "no"; then	
   if test "x${PGSQL_DIR}" != "x"; then
      AC_PATH_TOOL([PG_CONFIG], [pg_config], No, [${PGSQL_DIR}/bin])
      if test x"${PG_CONFIG}" = xNo; then
         AC_MSG_NOTICE([***])
         AC_MSG_NOTICE([*** pg_config was not found in the path you specified:])
         AC_MSG_NOTICE([*** ${PGSQL_DIR}/bin])
         AC_MSG_NOTICE([*** Either correct the installation, or run configure])
         AC_MSG_NOTICE([*** including --without-postgres])
         exit 1
      fi
   else
      AC_PATH_TOOL([PG_CONFIG], [pg_config], No)
   fi
fi
if test "${PG_CONFIG}" != No; then
   PGSQL_libdir=`${PG_CONFIG} --libdir`
   PGSQL_includedir=`${PG_CONFIG} --includedir`
   if test "x$?" != "x0" ; then
      if test -n "${PGSQL_MANDATORY}" ; then
         AC_MSG_NOTICE([***])
         AC_MSG_NOTICE([*** The PostgreSQL installation on this system appears to be broken.])
         AC_MSG_NOTICE([*** Either correct the installation, or run configure])
         AC_MSG_NOTICE([*** including --without-postgres])
         exit 1
	  fi
   else 
      AC_CHECK_LIB([pq], [PQexec], AC_DEFINE_UNQUOTED([HAVE_PGSQL], 1,
      [Define to indicate the PostgreSQL library]), [], -L${PGSQL_libdir} -lz)

      if test "${ac_cv_lib_pq_PQexec}" = "yes"; then
         PGSQL_LIB="-L${PGSQL_libdir} -lpq -lz"
         PGSQL_INCLUDE="-I${PGSQL_includedir}"
         PBX_PGSQL=1
      elif test -n "${PGSQL_MANDATORY}";
      then
         AC_MSG_NOTICE([***])
         AC_MSG_NOTICE([*** The PostgreSQL installation on this system appears to be broken.])
         AC_MSG_NOTICE([*** Either correct the installation, or run configure])
         AC_MSG_NOTICE([*** including --without-postgres])
         exit 1
      fi
   fi
fi

AST_EXT_LIB_CHECK([POPT], [popt], [poptStrerror], [popt.h])

AST_EXT_LIB_CHECK([PRI], [pri], [pri_keypad_facility], [libpri.h])

AST_EXT_LIB_CHECK([SS7], [ss7], [isup_cqr], [libss7.h])

if test "${USE_PWLIB}" != "no"; then
	if test -n "${PWLIB_DIR}"; then
		PWLIBDIR="${PWLIB_DIR}"
	fi
	AST_CHECK_PWLIB()
	AST_CHECK_PWLIB_VERSION([PWLib], [PWLIB], [ptbuildopts.h], [1], [9], [2])
		
	if test "${HAS_PWLIB:-unset}" != "unset"; then
		AST_CHECK_OPENH323_PLATFORM()

		PLATFORM_PWLIB="pt_${PWLIB_PLATFORM}_r"

		AST_CHECK_PWLIB_BUILD([PWLib], [PWLIB],
			[Define if your system has the PWLib libraries.],
			[#include "ptlib.h"],
			[BOOL q = PTime::IsDaylightSavings();])
	fi
fi

if test "${PBX_PWLIB}" = "1" -a "${USE_OPENH323}" != "no" ; then
	if test -n "${OPENH323_DIR}"; then
		OPENH323DIR="${OPENH323_DIR}"
	fi
	AST_CHECK_OPENH323()
	AST_CHECK_PWLIB_VERSION([OpenH323], [OPENH323], [openh323buildopts.h], [1], [17], [3])
	AST_CHECK_OPENH323_BUILD()
	PLATFORM_OPENH323="h323_${PWLIB_PLATFORM}_${OPENH323_SUFFIX}"
	AST_CHECK_PWLIB_BUILD([OpenH323], [OPENH323],
		[Define if your system has the OpenH323 libraries.],
		[#include "ptlib.h"
		#include "h323.h"
		#include "h323ep.h"],
		[H323EndPoint ep = H323EndPoint();],
		[${PWLIB_INCLUDE}], [${PWLIB_LIB}])
fi

AC_LANG_PUSH(C++)

if test "${USE_QT}" != "no"; then
   AC_MSG_CHECKING(for QDate in -lqt)
   saved_libs="${LIBS}"
   saved_cppflags="${CPPFLAGS}"
   if test "x${QT_DIR}" != "x"; then
      LIBS="${LIBS} -L${QT_DIR}/lib"
      CPPFLAGS="${CPPFLAGS} -I${QT_DIR}/include"
   fi
   LIBS="${LIBS} -lqt"
   qtlib="qt"
   AC_LINK_IFELSE(
	[
		AC_LANG_PROGRAM(
		[#include <qt3/qdatetime.h>],
		[QDate date();])
	],
	[ac_cv_lib_qt_qt_date="yes"],
	[ac_cv_lib_qt_qt_date="no"])
   LIBS="${saved_libs}"
   CPPFLAGS="${saved_cppflags}"
	
   if test "${ac_cv_lib_qt_qt_date}" = "no"; then
      saved_libs="${LIBS}"
      saved_cppflags="${CPPFLAGS}"
      if test "x${QT_DIR}" != "x"; then
      	 LIBS="${LIBS} -L${QT_DIR}/lib"
	 CPPFLAGS="${CPPFLAGS} -I${QT_DIR}/include"
      fi
      LIBS="${LIBS} -lqt-mt"
      qtlib="qt-mt"	
      AC_LINK_IFELSE(
		[
			AC_LANG_PROGRAM(
			[#include <qt3/qdatetime.h>],
			[QDate date();])
		],
		[ac_cv_lib_qt_qt_date="yes"],
		[ac_cv_lib_qt_qt_date="no"])
      LIBS="${saved_libs}"
      CPPFLAGS="${saved_cppflags}"
   fi	

   if test "${ac_cv_lib_qt_qt_date}" = "yes"; then
      AC_MSG_RESULT(yes) 
   else
      AC_MSG_RESULT(no) 
   fi
	
   if test "${ac_cv_lib_qt_qt_date}" = "yes"; then
      QT_LIB="-l${qtlib}"
      if test "${QT_DIR}" != ""; then
      	 QT_LIB="-L${QT_DIR}/lib ${QT_LIB}"
	 QT_INCLUDE="-I${QT_DIR}/include"
      fi
      PBX_QT=1
      AC_DEFINE([HAVE_QT], 1, [Define if your system has the Qt library])
      AC_PATH_TOOL(QTMOC, moc, No)
   fi
fi

AC_LANG_POP

LUA_INCLUDE="-I/usr/include/lua5.1"
LUA_LIB="-llua5.1"
AST_EXT_LIB_CHECK([LUA], [lua5.1], [luaL_newstate], [lua5.1/lua.h]) 

AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])

AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])

AST_EXT_LIB_CHECK([SQLITE], [sqlite], [sqlite_exec], [sqlite.h])

AST_EXT_LIB_CHECK([SQLITE3], [sqlite3], [sqlite3_open], [sqlite3.h])

AST_EXT_LIB_CHECK([CRYPTO], [crypto], [AES_encrypt], [openssl/aes.h])

if test "$PBX_CRYPTO" = "1";
then
    AST_EXT_LIB_CHECK([OPENSSL], [ssl], [ssl2_connect], [openssl/ssl.h], [-lcrypto])
fi

if test "$PBX_OPENSSL" = "1";
then
    AST_EXT_LIB_CHECK([OSPTK], [osptk], [OSPPCryptoDecrypt], [osp/osp.h], [-lcrypto -lssl])
fi

AST_EXT_LIB_CHECK([FREETDS], [tds], [tds_version], [tds.h])
if test "${PBX_FREETDS}" != "0";
then
    case `grep TDS_VERSION_NO ${FREETDS_DIR:-/usr}/include/tdsver.h` in
	*0.64*)
		FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_64"
	;;
    *0.63*)
        FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_63"
	;;
    *0.62*)
        FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_62"
	;;
    *)
        FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_PRE_0_62"
	;;
    esac
fi

AST_EXT_LIB_CHECK([TERMCAP], [termcap], [tgetent], [])

AST_EXT_LIB_CHECK([TINFO], [tinfo], [tgetent], [])

if test "${host_os}" != "linux-gnu" ; then
  tonezone_extra="-lm"
fi

# new tonezone, version 1.4.0
AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel/tonezone.h], [${tonezone_extra}], [140])
# other case, old tonezone (0.80)
AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel/zaptel.h], [${tonezone_extra}], [80])

AST_EXT_LIB_CHECK([USB], [usb], [usb_init], [usb.h], [])

AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc])

AC_LANG_PUSH(C++)

if test "${USE_VPB}" != "no"; then
   AC_MSG_CHECKING(for vpb_open in -lvpb)
   saved_libs="${LIBS}"
   saved_cppflags="${CPPFLAGS}"
   if test "x${VPB_DIR}" != "x"; then
      if test -d ${VPB_DIR}/lib; then
         vpblibdir=${VPB_DIR}/lib
      else
         vpblibdir=${VPB_DIR}
      fi
      LIBS="${LIBS} -L${vpblibdir}"
      CPPFLAGS="${CPPFLAGS} -I${VPB_DIR}/include"
   fi
   LIBS="${LIBS} -lvpb -lpthread"
   AC_LINK_IFELSE(
	[
	AC_LANG_PROGRAM(
	[#include <vpbapi.h>],
	[int q = vpb_open(0,0);])
	],
	[	AC_MSG_RESULT(yes) 
		ac_cv_lib_vpb_vpb_open="yes" 
	],
	[	AC_MSG_RESULT(no) 
		ac_cv_lib_vpb_vpb_open="no" 
	]
	)
   LIBS="${saved_libs}"
   CPPFLAGS="${saved_cppflags}"
   if test "${ac_cv_lib_vpb_vpb_open}" = "yes"; then
	VPB_LIB="-lvpb"
	if test "${VPB_DIR}" != ""; then
	   VPB_LIB="-L${vpblibdir}  ${VPB_LIB}"
	   VPB_INCLUDE="-I${VPB_DIR}/include"
	fi
	PBX_VPB=1
	AC_DEFINE([HAVE_VPB], 1, [Define if your system has the VoiceTronix API libraries.])
   fi
fi

AC_LANG_POP

AST_EXT_LIB_CHECK([ZLIB], [z], [compress], [zlib.h])

# Check for various zaptel features and locations.
# The version number, which goes into HAVE_ZAPTEL_VERSION,
# will be used in the system headers to determine the location
# of the zaptel.h header.

AST_C_DEFINE_CHECK([ZAPTEL], [ZT_TONE_DTMF_BASE], [zaptel/zaptel.h], [140])
AST_C_DEFINE_CHECK([ZAPTEL], [ZT_DIAL_OP_CANCEL], [zaptel/zaptel.h], [90])

# Check for VLDTMF support
AST_C_DEFINE_CHECK([ZAPTEL_VLDTMF], [ZT_EVENT_REMOVED], [zaptel/zaptel.h])

# Check for transcode support
AST_C_DEFINE_CHECK([ZAPTEL_TRANSCODE], [ZT_TCOP_ALLOCATE], [zaptel/zaptel.h])

# On FreeBSD, try old zaptel (0.80 or so) and pretend we have vldtmf
case "${host_os}" in
    freebsd*)
	AST_EXT_LIB_CHECK([ZAPTEL], [zaptel],, [zaptel.h],, [80])
	AST_EXT_LIB_CHECK([ZAPTEL_VLDTMF], [zaptel],, [zaptel/zaptel.h],, [90])
	AST_EXT_LIB_CHECK([ZAPTEL_VLDTMF], [zaptel],, [zaptel.h],, [80])

	# other case, old tonezone (0.80)
	AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel.h], [${tonezone_extra}], [80])
	;;
esac

EDITLINE_LIB=""
if test "x$TERMCAP_LIB" != "x" ; then
  EDITLINE_LIB="$TERMCAP_LIB"
elif test "x$TINFO_LIB" != "x" ; then
  EDITLINE_LIB="$TINFO_LIB"
elif test "x$CURSES_LIB" != "x" ; then
  EDITLINE_LIB="$CURSES_LIB"
elif test "x$NCURSES_LIB" != "x" ; then
  EDITLINE_LIB="$NCURSES_LIB"
else
  AC_MSG_ERROR(*** termcap support not found)
fi
AC_SUBST(EDITLINE_LIB)

AC_CHECK_HEADER([h323.h], [PBX_H323=1], [PBX_H323=0])
AC_SUBST(PBX_H323)

AC_CHECK_HEADER([linux/compiler.h],
                [AC_DEFINE_UNQUOTED([HAVE_LINUX_COMPILER_H], 1, [Define to 1 if your system has linux/compiler.h.])])

AC_CHECK_HEADER([linux/ixjuser.h], [PBX_IXJUSER=1], [PBX_IXJUSER=0], [
				   #include <linux/version.h>
				   #ifdef HAVE_LINUX_COMPILER_H
				   #include <linux/compiler.h>
				   #endif
				   ])
AC_SUBST(PBX_IXJUSER)

PBX_GTK=0
AC_CHECK_TOOL(GTKCONFIG, gtk-config, No)
if test ! "x${GTKCONFIG}" = xNo; then
   GTK_INCLUDE=$(${GTKCONFIG} --cflags gthread)
   GTK_LIB=$(${GTKCONFIG} --libs gthread)
   PBX_GTK=1
   AC_DEFINE([HAVE_GTK], 1, [Define if your system has the GTK libraries.])
fi
AC_SUBST(PBX_GTK)
AC_SUBST(GTK_INCLUDE)
AC_SUBST(GTK_LIB)

PBX_GTK2=0
AC_CHECK_TOOL(PKGCONFIG, pkg-config, No)
if test ! "x${PKGCONFIG}" = xNo; then
   GTK2_INCLUDE=$(${PKGCONFIG} gtk+-2.0 --cflags 2>/dev/null)
   GTK2_LIB=$(${PKGCONFIG} gtk+-2.0 --libs)
   PBX_GTK2=1
   AC_DEFINE([HAVE_GTK2], 1, [Define if your system has the GTK2 libraries.])
fi
AC_SUBST(PBX_GTK2)
AC_SUBST(GTK2_INCLUDE)
AC_SUBST(GTK2_LIB)

if test "${USE_CURL}" != "no"; then
   AC_PATH_TOOL([CURL_CONFIG], [curl-config], No)
   if test ! x"${CURL_CONFIG}" = xNo; then
   # check for version
      if test $(printf "%d" 0x$(${CURL_CONFIG} --vernum)) -ge $(printf "%d" 0x070907); then
         CURL_INCLUDE=$(${CURL_CONFIG} --cflags)
         CURL_LIB=$(${CURL_CONFIG} --libs)

         AC_MSG_CHECKING(for curl_version() in curl/curl.h)
         saved_cppflags="${CPPFLAGS}"
         CPPFLAGS="${CPPFLAGS} ${CURL_INCLUDE}"
         AC_COMPILE_IFELSE(
            [AC_LANG_PROGRAM(
                [#include <curl/curl.h>],
                    [curl_version();])
            ],[
                AC_MSG_RESULT(yes)
                ac_cv_curl_h="yes"
            ],[
                AC_MSG_RESULT(no)
                ac_cv_curl_h="no"
            ]
	 )
	 CPPFLAGS="${saved_cppflags}"
         if test "${ac_cv_curl_h}" = "yes"; then
             PBX_CURL=1
             AC_DEFINE([HAVE_CURL], 1, [Define if your system has the curl libraries.])
         fi
      fi
   fi
fi

AC_CONFIG_FILES([build_tools/menuselect-deps makeopts channels/h323/Makefile])
AST_CHECK_MANDATORY

AC_OUTPUT

if test "x${silent}" != "xyes" ; then
echo
echo "               .\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$=..      "
echo "            .\$7\$7..          .7\$\$7:.    "
echo "          .\$\$:.                 ,\$7.7   "
echo "        .\$7.     7\$\$\$\$           .\$\$77  "
echo "     ..\$\$.       \$\$\$\$\$            .\$\$\$7 "
echo "    ..7\$   .?.   \$\$\$\$\$   .?.       7\$\$\$."
echo "   \$.\$.   .\$\$\$7. \$\$\$\$7 .7\$\$\$.      .\$\$\$."
echo " .777.   .\$\$\$\$\$\$77\$\$\$77\$\$\$\$\$7.      \$\$\$,"
echo " \$\$\$~      .7\$\$\$\$\$\$\$\$\$\$\$\$\$7.       .\$\$\$."
echo ".\$\$7          .7\$\$\$\$\$\$\$7:          ?\$\$\$."
echo "\$\$\$          ?7\$\$\$\$\$\$\$\$\$\$I        .\$\$\$7 "
echo "\$\$\$       .7\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$      :\$\$\$. "
echo "\$\$\$       \$\$\$\$\$\$7\$\$\$\$\$\$\$\$\$\$\$\$    .\$\$\$.  "
echo "\$\$\$        \$\$\$   7\$\$\$7  .\$\$\$    .\$\$\$.   "
echo "\$\$\$\$             \$\$\$\$7         .\$\$\$.    "
echo "7\$\$\$7            7\$\$\$\$        7\$\$\$      "
echo " \$\$\$\$\$                        \$\$\$       "
echo "  \$\$\$\$7.                       \$\$  (TM)     "
echo "   \$\$\$\$\$\$\$.           .7\$\$\$\$\$\$  \$\$      "
echo "     \$\$\$\$\$\$\$\$\$\$\$\$7\$\$\$\$\$\$\$\$\$.\$\$\$\$\$\$      "
echo "       \$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$.                "
echo
fi

AC_MSG_NOTICE(Package configured for: )
AC_MSG_NOTICE( OS type  : $host_os)
AC_MSG_NOTICE( Host CPU : $host_cpu)
if test "${cross_compiling}" = "yes"; then
   AC_MSG_NOTICE( Cross Compilation = YES)
fi