summaryrefslogtreecommitdiff
path: root/aconfigure.ac
blob: 75aa01bcf9b6e3e1d17f50b6583b74d46286b261 (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
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
AC_INIT(pjproject,2.x)

host_orig="$host"

AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AC_CONFIG_HEADER([pjlib/include/pj/compat/os_auto.h
		  pjlib/include/pj/compat/m_auto.h
		  pjmedia/include/pjmedia/config_auto.h
		  pjmedia/include/pjmedia-codec/config_auto.h
		  pjsip/include/pjsip/sip_autoconf.h
		 ])
AC_CONFIG_FILES([build.mak 
		 build/os-auto.mak 
		 build/cc-auto.mak
		 pjlib/build/os-auto.mak 
		 pjlib-util/build/os-auto.mak 
		 pjmedia/build/os-auto.mak
		 pjsip/build/os-auto.mak
		 third_party/build/os-auto.mak
		 third_party/build/portaudio/os-auto.mak 
		 ])


dnl
dnl Setup default CFLAGS
dnl
if test "$CFLAGS" = ""; then
  CFLAGS="-O2"
else
  CFLAGS="$CFLAGS"
fi

CXXFLAGS="$CFLAGS $CXXFLAGS"

dnl #
dnl # Configure tools
dnl #
AC_PROG_CC
AC_PROG_CXX
AC_LANG_C

AC_PROG_RANLIB
AC_CHECK_TOOLS([AR], [ar gar], :)

if test "$AR_FLAGS" = ""; then AR_FLAGS="rv"; fi
AC_SUBST(AR_FLAGS)
if test "$LD" = ""; then LD="$CC"; fi
AC_SUBST(LD)
if test "$LDOUT" = ""; then LDOUT="-o "; fi
AC_SUBST(LDOUT)
if test "$OBJEXT" = ""; then OBJEXT='o'; fi
AC_SUBST(OBJEXT)
if test "$LIBEXT" = ""; then LIBEXT='a'; fi
AC_SUBST(LIBEXT)
if test "$LIBEXT2" = ""; then LIBEXT2=""; fi
AC_SUBST(LIBEXT2)
if test "$CC_OUT" = ""; then CC_OUT="-o "; fi
AC_SUBST(CC_OUT)
if test "$CC_INC" = ""; then CC_INC="-I"; fi
AC_SUBST(CC_INC)
if test "$CC_DEF" = ""; then CC_DEF="-D"; fi
AC_SUBST(CC_DEF)
if test "$CC_OPTIMIZE" = ""; then CC_OPTIMIZE="-O2"; fi
AC_SUBST(CC_OPTIMIZE)
if test "$CC_CFLAGS" = ""; then CC_CFLAGS="-Wall"; fi
AC_SUBST(CC_CFLAGS)



AC_SUBST(ac_pjdir)
AC_SUBST(ac_build_mak_vars)

case $host in 
    *mingw* | *cygw* | *win32* | *w32* )
	if pwd -W 2&> /dev/null; then
	   ac_pjdir=`pwd -W`
	else
	   # We're probably cross-compiling mingw on Linux
	   ac_pjdir=`pwd`
	fi
	;;
    *)
	ac_pjdir=`pwd`
	;;
esac

AC_SUBST(ac_shlib_suffix)
case $target in
    *mingw* | *cygw* | *win32* | *w32* )
	ac_shlib_suffix=dll
	;;
    *darwin*)
	ac_shlib_suffix=dylib
	;;
    *)
	ac_shlib_suffix=so
	;;
esac

AC_SUBST(ac_cross_compile)
if test "$build" = "$host"; then
    ac_cross_compile=
else
    ac_cross_compile=${host_orig}-
fi

AC_CHECK_LIB(pthread,pthread_create)
AC_CHECK_LIB(wsock32,puts)
AC_CHECK_LIB(ws2_32,puts)
AC_CHECK_LIB(ole32,puts)
AC_CHECK_LIB(winmm,puts)
AC_CHECK_LIB(socket,puts)
AC_CHECK_LIB(rt,puts)
AC_CHECK_LIB(nsl,puts)
AC_CHECK_LIB(m,sin)
AC_CHECK_LIB(uuid,uuid_generate)
AC_CHECK_LIB(uuid,uuid_generate,[ac_has_uuid_lib=1])

AC_MSG_RESULT([Setting PJ_M_NAME to $target_cpu])
AC_DEFINE_UNQUOTED(PJ_M_NAME,["$target_cpu"])

dnl
dnl Memory alignment detection
dnl
AC_MSG_CHECKING([memory alignment])
case $target in
    sparc64-* | ia64-* | x86_64-* )
	AC_DEFINE(PJ_POOL_ALIGNMENT, 8)
	AC_MSG_RESULT([8 bytes])
	;;
    * )
	AC_DEFINE(PJ_POOL_ALIGNMENT, 4)
	AC_MSG_RESULT([4 bytes (default)])
	;;
esac


dnl
dnl Endianness detection
dnl
AC_C_BIGENDIAN

if test "x$ac_cv_c_bigendian" = "xyes"; then
  CFLAGS="$CFLAGS -DPJ_IS_BIG_ENDIAN=1 -DPJ_IS_LITTLE_ENDIAN=0"
else
  CFLAGS="$CFLAGS -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1"
fi

dnl
dnl Legacy macros
dnl
case $target in
    *mingw* | *cygw* | *win32* | *w32* )
	AC_DEFINE(PJ_WIN32,1)
	AC_DEFINE(PJ_WIN32_WINNT,0x0400)
	AC_DEFINE(WIN32_LEAN_AND_MEAN)
	;;
    *darwin*)
	AC_DEFINE(PJ_DARWINOS,1)
	;;
    *linux*)
	AC_DEFINE(PJ_LINUX,1)
	;;
    *rtems*)
	AC_DEFINE(PJ_RTEMS,1)
	;;
    *sunos* | *solaris* )
	AC_DEFINE(PJ_SUNOS,1)
	;;
    *)
	;;
esac




dnl # --disable-floating-point option
AC_ARG_ENABLE(floating-point,
	      AC_HELP_STRING([--disable-floating-point],
			     [Disable floating point where possible]),
	      [if test "$enable_floating_point" = "no"; then
		AC_DEFINE(PJ_HAS_FLOATING_POINT,0)
		AC_MSG_RESULT([Checking if floating point is disabled... yes])
	       fi],
	      [
		AC_DEFINE(PJ_HAS_FLOATING_POINT,1)
	        AC_MSG_RESULT([Checking if floating point is disabled... no]) 
	      ])


AC_CHECK_HEADER(arpa/inet.h,[AC_DEFINE(PJ_HAS_ARPA_INET_H,1)])
AC_CHECK_HEADER(assert.h,[AC_DEFINE(PJ_HAS_ASSERT_H,1)])
AC_CHECK_HEADER(ctype.h,[AC_DEFINE(PJ_HAS_CTYPE_H,1)])

case $target in
    *mingw* | *cygw* | *win32* | *w32* )
	AC_DEFINE(PJ_HAS_ERRNO_H,0)
	;;
    *)
	AC_CHECK_HEADER(errno.h,[AC_DEFINE(PJ_HAS_ERRNO_H,1)])
	;;
esac

AC_CHECK_HEADER(fcntl.h,[AC_DEFINE(PJ_HAS_FCNTL_H,1)])
AC_CHECK_HEADER(linux/socket.h,[AC_DEFINE(PJ_HAS_LINUX_SOCKET_H,1)])
AC_CHECK_HEADER(limits.h,[AC_DEFINE(PJ_HAS_LIMITS_H,1)])
AC_CHECK_HEADER(malloc.h,[AC_DEFINE(PJ_HAS_MALLOC_H,1)])
AC_CHECK_HEADER(netdb.h,[AC_DEFINE(PJ_HAS_NETDB_H,1)])
AC_CHECK_HEADER(netinet/in_systm.h,[AC_DEFINE(PJ_HAS_NETINET_IN_SYSTM_H,1)])
AC_CHECK_HEADER(netinet/in.h,[AC_DEFINE(PJ_HAS_NETINET_IN_H,1)])
AC_CHECK_HEADER(netinet/ip.h,[AC_DEFINE(PJ_HAS_NETINET_IP_H,1)],[],
		 [#if PJ_HAS_SYS_TYPES_H
          	  #	include <sys/types.h>
          	  #endif
		  #if PJ_HAS_NETINET_IN_SYSTM_H
          	  #	include <netinet/in_systm.h>
          	  #endif
		  #if PJ_HAS_NETINET_IN_H
          	  #	include <netinet/in.h>
          	  #endif
          	 ])
AC_CHECK_HEADER(netinet/tcp.h,[AC_DEFINE(PJ_HAS_NETINET_TCP_H,1)])
AC_CHECK_HEADER(ifaddrs.h,
		[AC_CHECK_FUNC(getifaddrs,[AC_DEFINE(PJ_HAS_IFADDRS_H,1)])])
AC_CHECK_HEADER(semaphore.h,[AC_DEFINE(PJ_HAS_SEMAPHORE_H,1)])
AC_CHECK_HEADER(setjmp.h,[AC_DEFINE(PJ_HAS_SETJMP_H,1)])
AC_CHECK_HEADER(stdarg.h,[AC_DEFINE(PJ_HAS_STDARG_H,1)])
AC_CHECK_HEADER(stddef.h,[AC_DEFINE(PJ_HAS_STDDEF_H,1)])
AC_CHECK_HEADER(stdio.h,[AC_DEFINE(PJ_HAS_STDIO_H,1)])
AC_CHECK_HEADER(stdint.h,[AC_DEFINE(PJ_HAS_STDINT_H,1)])
AC_CHECK_HEADER(stdlib.h,[AC_DEFINE(PJ_HAS_STDLIB_H,1)])
AC_CHECK_HEADER(string.h,[AC_DEFINE(PJ_HAS_STRING_H,1)])
AC_CHECK_HEADER(sys/ioctl.h,[AC_DEFINE(PJ_HAS_SYS_IOCTL_H,1)])
AC_CHECK_HEADER(sys/select.h,[AC_DEFINE(PJ_HAS_SYS_SELECT_H,1)])
AC_CHECK_HEADER(sys/socket.h,[AC_DEFINE(PJ_HAS_SYS_SOCKET_H,1)])
AC_CHECK_HEADER(sys/time.h,[AC_DEFINE(PJ_HAS_SYS_TIME_H,1)])
AC_CHECK_HEADER(sys/timeb.h,[AC_DEFINE(PJ_HAS_SYS_TIMEB_H,1)])
AC_CHECK_HEADER(sys/types.h,[AC_DEFINE(PJ_HAS_SYS_TYPES_H,1)])
AC_CHECK_HEADER(sys/filio.h,[AC_DEFINE(PJ_HAS_SYS_FILIO_H,1)])
AC_CHECK_HEADER(sys/sockio.h,[AC_DEFINE(PJ_HAS_SYS_SOCKIO_H,1)])
AC_CHECK_HEADER(sys/utsname.h,[AC_DEFINE(PJ_HAS_SYS_UTSNAME_H,1)])
AC_CHECK_HEADER(time.h,[AC_DEFINE(PJ_HAS_TIME_H,1)])
AC_CHECK_HEADER(unistd.h,[AC_DEFINE(PJ_HAS_UNISTD_H,1)])
AC_CHECK_HEADER(winsock.h,[AC_DEFINE(PJ_HAS_WINSOCK_H,1)])
AC_CHECK_HEADER(winsock2.h,[AC_DEFINE(PJ_HAS_WINSOCK2_H,1)])
AC_CHECK_HEADER(mswsock.h,[AC_DEFINE(PJ_HAS_MSWSOCK_H,1)],[],
		 [#if PJ_HAS_WINSOCK2_H
          	  #	include <winsock2.h>
		  #elif PJ_HAS_WINSOCK_H
          	  #	include <winsock.h>
          	  #endif
          	 ])
AC_CHECK_HEADER(ws2tcpip.h,[AC_DEFINE(PJ_HAS_WS2TCPIP_H,1)])
AC_CHECK_HEADER(uuid/uuid.h,[ac_has_uuid_h=1])
AC_CHECK_HEADER(net/if.h,[AC_DEFINE(PJ_HAS_NET_IF_H,1)],[],
		 [#if PJ_HAS_SYS_TYPES_H
          	  #	include <sys/types.h>
          	  #endif
		  #if PJ_HAS_SYS_SOCKET_H

          	  #	include <sys/socket.h>
          	  #endif
          	 ])
AC_MSG_RESULT([Setting PJ_OS_NAME to $target])
AC_DEFINE_UNQUOTED(PJ_OS_NAME,["$target"])

AC_MSG_RESULT([Setting PJ_HAS_ERRNO_VAR to 1])
AC_DEFINE(PJ_HAS_ERRNO_VAR,1)

AC_MSG_RESULT([Setting PJ_HAS_HIGH_RES_TIMER to 1])
AC_DEFINE(PJ_HAS_HIGH_RES_TIMER,1)

AC_MSG_RESULT([Setting PJ_HAS_MALLOC to 1])
AC_DEFINE(PJ_HAS_MALLOC,1)

AC_MSG_RESULT([Setting PJ_NATIVE_STRING_IS_UNICODE to 0])
AC_DEFINE(PJ_NATIVE_STRING_IS_UNICODE,0)

AC_MSG_RESULT([Setting PJ_ATOMIC_VALUE_TYPE to long])
AC_DEFINE(PJ_ATOMIC_VALUE_TYPE,long)

dnl # Determine if inet_aton() is available
AC_MSG_CHECKING([if inet_aton() is available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
				     #include <sys/socket.h>
				     #include <arpa/inet.h>]],
		    		  [inet_aton(0, 0);])],
		  [AC_DEFINE(PJ_SOCK_HAS_INET_ATON,1)
		   AC_MSG_RESULT(yes)],
		  [AC_MSG_RESULT(no)])

dnl # Determine if inet_pton() is available
AC_MSG_CHECKING([if inet_pton() is available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
				     #include <sys/socket.h>
				     #include <arpa/inet.h>]],
		    		  [inet_pton(0, 0, 0);])],
		  [AC_DEFINE(PJ_SOCK_HAS_INET_PTON,1)
		   AC_MSG_RESULT(yes)],
		  [AC_MSG_RESULT(no)])

dnl # Determine if inet_ntop() is available
AC_MSG_CHECKING([if inet_ntop() is available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
				     #include <sys/socket.h>
				     #include <arpa/inet.h>]],
		    		  [inet_ntop(0, 0, 0, 0);])],
		  [AC_DEFINE(PJ_SOCK_HAS_INET_NTOP,1)
		   AC_MSG_RESULT(yes)],
		  [AC_MSG_RESULT(no)])

dnl # Determine if getaddrinfo() is available
AC_MSG_CHECKING([if getaddrinfo() is available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
				     #include <sys/socket.h>
				     #include <netdb.h>]],
		    		  [getaddrinfo(0, 0, 0, 0);])],
		  [AC_DEFINE(PJ_SOCK_HAS_GETADDRINFO,1)
		   AC_MSG_RESULT(yes)],
		  [AC_MSG_RESULT(no)])

dnl # Determine if sockaddr_in has sin_len member
AC_MSG_CHECKING([if sockaddr_in has sin_len member])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
				     #include <sys/socket.h>
		    		     #include <netinet/in.h>
		    		     #include <arpa/inet.h>]],
		    		  [struct sockaddr_in a; a.sin_len=0;])],
		  [AC_DEFINE(PJ_SOCKADDR_HAS_LEN,1)
		   AC_MSG_RESULT(yes)],
		  AC_MSG_RESULT(no))

dnl # Determine if socklen_t is available
AC_MSG_CHECKING([if socklen_t is available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
                                     #include <sys/socket.h>]],
		    		   [socklen_t xxx = 0;])],
		  [AC_DEFINE(PJ_HAS_SOCKLEN_T,1)
		   AC_MSG_RESULT(yes)],
		  AC_MSG_RESULT(no))

dnl # Determine if SO_ERROR is available
AC_MSG_CHECKING([if SO_ERROR is available])
case $target in
    *mingw* | *cygw* | *win32* | *w32* )
	AC_DEFINE(PJ_HAS_SO_ERROR,1)
	AC_MSG_RESULT(yes)
	;;
    *)
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
					     #include <sys/socket.h>
					     #include <netinet/in.h>
					     #include <arpa/inet.h>]],
					  [int i=SO_ERROR;])],
			  [AC_DEFINE(PJ_HAS_SO_ERROR,1)
			   AC_MSG_RESULT(yes)],
			  AC_MSG_RESULT(no))
	;;
esac


dnl # Determine if RW-mutex is available
AC_MSG_CHECKING([if pthread_rwlock_t is available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
		    		   [pthread_rwlock_t *x;])],
		  [AC_DEFINE(PJ_EMULATE_RWMUTEX,0)
		   ac_rwmutex="yes"
  		   AC_MSG_RESULT(yes)],
		  [AC_DEFINE(PJ_EMULATE_RWMUTEX,1)
		   ac_rwmutex="no"
		   AC_MSG_RESULT(no)])

dnl # If rwmutex is not detected, check again but this time
dnl # with _POSIX_READER_WRITER_LOCKS defined (newlib needs this)
if test "$ac_rwmutex" = "no"; then
    AC_MSG_CHECKING([if pthread_rwlock_t is available with _POSIX_READER_WRITER_LOCKS])
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#define _POSIX_READER_WRITER_LOCKS
					 #include <pthread.h>]],
				       [pthread_rwlock_t *x;])],
		      [AC_DEFINE(PJ_EMULATE_RWMUTEX,0)
		       CFLAGS="$CFLAGS -D_POSIX_THREADS -D_POSIX_READER_WRITER_LOCKS"
		       AC_MSG_RESULT(yes)],
		      [AC_DEFINE(PJ_EMULATE_RWMUTEX,1)
		       AC_MSG_RESULT(no)])
fi

dnl # Do we have pthread_mutexattr_settype()?
AC_MSG_CHECKING([if pthread_mutexattr_settype() is available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
		    		   [pthread_mutexattr_settype(0,PTHREAD_MUTEX_FAST_NP);])],
		  [AC_DEFINE(PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE,1)
  		   AC_MSG_RESULT(yes)],
		  [AC_MSG_RESULT(no)])

dnl # Does pthread_mutexattr_t has "recursive" member?
AC_MSG_CHECKING([if pthread_mutexattr_t has recursive member])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
		    		   [[pthread_mutexattr_t attr;
				     attr.recursive=1;]])],
		  [AC_DEFINE(PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE,1)
  		   AC_MSG_RESULT(yes)],
		  [AC_MSG_RESULT(no)])

dnl ######################
dnl # ioqueue selection
dnl # 
AC_SUBST(ac_os_objs)
AC_MSG_CHECKING([ioqueue backend])
AC_ARG_ENABLE(epoll,
	      AC_HELP_STRING([--enable-epoll],
			     [Use /dev/epoll ioqueue on Linux (experimental)]),
	      [
		ac_os_objs=ioqueue_epoll.o
		AC_MSG_RESULT([/dev/epoll])
	      ],
	      [
		ac_os_objs=ioqueue_select.o
	        AC_MSG_RESULT([select()]) 
	      ])

AC_SUBST(ac_shared_libraries)
AC_ARG_ENABLE(shared,
	      AC_HELP_STRING([--enable-shared],
			     [Build shared libraries]),
	      [if test "$enable_shared" = "yes"; then
		[ac_shared_libraries=1]
		CFLAGS="$CFLAGS -fPIC"
		AC_MSG_RESULT([Building shared libraries... yes])
	       fi],
	      AC_MSG_RESULT([Building shared libraries... no])
	      )


dnl ######################
dnl # OS specific files
dnl #
case $target in
  *mingw* | *cygw* | *win32* | *w32* )
	ac_os_objs="$ac_os_objs file_access_win32.o file_io_win32.o os_core_win32.o os_error_win32.o os_time_win32.o os_timestamp_win32.o guid_win32.o"
	;;
  *)
	ac_os_objs="$ac_os_objs file_access_unistd.o file_io_ansi.o os_core_unix.o os_error_unix.o os_time_unix.o os_timestamp_posix.o"
	case $target in
	  arm-apple-darwin*)
		ac_os_objs="$ac_os_objs os_info_iphone.o"
		;;
	esac
	# UUID
	if test "$ac_has_uuid_lib" = "1" -a "$ac_has_uuid_h" = "1"; then
		ac_os_objs="$ac_os_objs guid_uuid.o"
	else
		ac_os_objs="$ac_os_objs guid_simple.o"
	fi
	;;
esac

case $target in
  *darwin*)
	ac_os_objs="$ac_os_objs os_core_darwin.o"
	;;
esac

dnl ##########################################
dnl #
dnl # PJMEDIA
dnl #

dnl # Use external Speex installation
AC_SUBST(ac_external_speex,0)
AC_ARG_WITH(external-speex,
    AC_HELP_STRING([--with-external-speex],
		   [Use external Speex development files, not the one in "third_party" directory. When this option is set, make sure that Speex is accessible to use (hint: use CFLAGS and LDFLAGS env var to set the include/lib paths)]),
    [
	if test "x$with_external_speex" != "xno"; then
		# Test Speex installation
		AC_MSG_CHECKING([if external Speex devkit is installed])
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <speex/speex.h>
						     #include <speex/speex_echo.h>
						     ]],
						  [speex_echo_state_init(0, 0); speex_encoder_init(0); ])],
				  [AC_MSG_RESULT(yes!!)
				   AC_DEFINE(PJMEDIA_EXTERNAL_SPEEX_CODEC, 1)
				   ac_external_speex="1"
				   ],
				  [AC_MSG_ERROR([Unable to use external Speex library. If Speex development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])])
	fi
    ]
    )

dnl # Use external GSM codec library installation
AC_SUBST(ac_external_gsm,0)
AC_ARG_WITH(external-gsm,
    AC_HELP_STRING([--with-external-gsm],
		   [Use external GSM codec library, not the one in "third_party" directory. When this option is set, make sure that the GSM include/lib files are accessible to use (hint: use CFLAGS and LDFLAGS env var to set the include/lib paths)]),
    [
	if test "x$with_external_gsm" != "xno"; then
                # Test GSM library installation
                AC_MSG_CHECKING([if external GSM devkit is installed as gsm/gsm.h])
                AC_COMPILE_IFELSE(
                    [AC_LANG_PROGRAM([[#include <gsm/gsm.h> ]], [gsm_create(); ]) ],
                    [AC_MSG_RESULT(yes!!)
                     AC_DEFINE(PJMEDIA_EXTERNAL_GSM_CODEC, 1)
                     AC_DEFINE(PJMEDIA_EXTERNAL_GSM_GSM_H, 1)
                     ac_external_gsm="1"
                    ],
                    [
                     AC_MSG_RESULT(no)
                     AC_MSG_CHECKING([if external GSM devkit is installed as gsm.h])
                     AC_COMPILE_IFELSE(
                        [AC_LANG_PROGRAM([[#include <gsm.h> ]], [gsm_create(); ]) ],
                        [AC_MSG_RESULT(yes!!)
                         AC_DEFINE(PJMEDIA_EXTERNAL_GSM_CODEC, 1)
                         AC_DEFINE(PJMEDIA_EXTERNAL_GSM_H, 1)
                         ac_external_gsm="1"
                        ],
                        [AC_MSG_ERROR([Unable to use external GSM library. If GSM development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])
                        ]
                     )
                    ]
                )
	fi
    ]
    )


dnl # Use external SRTP installation
AC_SUBST(ac_external_srtp,0)
AC_ARG_WITH(external-srtp,
    AC_HELP_STRING([--with-external-srtp],
		   [Use external SRTP development files, not the one in "third_party" directory. When this option is set, make sure that SRTP is accessible to use (hint: use CFLAGS and LDFLAGS env var to set the include/lib paths)]),
    [
	if test "x$with_external_srtp" != "xno"; then
		# Test SRTP installation
		AC_MSG_CHECKING([if external SRTP devkit is installed])
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <srtp/srtp.h>
						     ]],
						  [srtp_init();])],
				  [AC_MSG_RESULT(yes!!)
				   ac_external_srtp="1"
				   ],
				  [AC_MSG_ERROR([Unable to use SRTP. If SRTP development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])])
	fi
    ]
    )


dnl # Resample implementation
AC_SUBST(ac_pjmedia_resample,libresample)
AC_ARG_ENABLE(resample,
	      AC_HELP_STRING([--disable-resample],
			     [Disable resampling implementations]),
	      [if test "$enable_resample" = "no"; then
		[ac_pjmedia_resample=none]
		AC_MSG_RESULT([Checking if resampling is disabled...yes])
	       fi]
	      )

dnl # Sound device backend selection
AC_SUBST(ac_pjmedia_snd)
AC_ARG_ENABLE(sound,
	      AC_HELP_STRING([--disable-sound],
			     [Exclude sound (i.e. use null sound)]),
	      [if test "$enable_sound" = "no"; then
		[ac_pjmedia_snd=null]
		AC_MSG_RESULT([Checking if sound is disabled... yes])
	       fi]
	      )

dnl # Use external PortAudio installation
AC_SUBST(ac_external_pa,0)
AC_ARG_WITH(external-pa,
    AC_HELP_STRING([--with-external-pa],
		   [Use external PortAudio development files, not the one in "third_party" directory. When this option is set, make sure that PortAudio is accessible to use (hint: use CFLAGS and LDFLAGS env var to set the include/lib paths)]),
    [
	if test "x$with_external_pa" != "xno"; then
		# Test PortAudio installation
		AC_MSG_CHECKING([if external PortAudio devkit is installed])
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <portaudio.h>
						     ]],
						  [Pa_Initialize();])],
				  [AC_MSG_RESULT(yes!!)
				   ac_external_pa="1"
				   ],
				  [AC_MSG_ERROR([Unable to use PortAudio. If PortAudio development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths])])
	fi
    ]
    )

AC_SUBST(ac_pa_cflags)
AC_CHECK_HEADER(sys/soundcard.h,
	 	[ac_pa_cflags="$ac_pa_cflags -DHAVE_SYS_SOUNDCARD_H"])
AC_CHECK_HEADER(linux/soundcard.h,
	 	[ac_pa_cflags="$ac_pa_cflags -DHAVE_LINUX_SOUNDCARD_H"])
AC_CHECK_HEADER(machine/soundcard.h,
	 	[ac_pa_cflags="$ac_pa_cflags -DHAVE_MACHINE_SOUNDCARD_H"])

if test "x$ac_cv_c_bigendian" = "xyes"; then
  ac_pa_cflags="$ac_pa_cflags -DPA_BIG_ENDIAN"
else
  ac_pa_cflags="$ac_pa_cflags -DPA_LITTLE_ENDIAN"
fi

if test "$enable_sound" = "no"; then
  true;
else
 case $target in
  arm-apple-darwin*)
	LIBS="$LIBS -framework CoreAudio -framework CoreFoundation -framework AudioToolbox -framework CFNetwork -framework UIKit"
	AC_MSG_RESULT([Checking sound device backend... AudioUnit])
	;;
  *darwin*)
	LIBS="$LIBS -framework CoreAudio -framework CoreServices -framework AudioUnit -framework AudioToolbox"
	if test "`uname -r`" = "6.8"; then
		#ac_pa_cflags="$ac_pa_cflags -DPA_OLD_CORE_AUDIO -DMOSX_USE_NON_ATOMIC_FLAG_BITS"
		#AC_MSG_RESULT([Setting additional PortAudio CFLAGS.. -DPA_OLD_CORE_AUDIO -DMOSX_USE_NON_ATOMIC_FLAG_BITS])
		ac_pjmedia_snd=pa_old_darwinos
		AC_MSG_RESULT([Checking sound device backend... old coreaudio])
	else
		ac_pjmedia_snd=pa_darwinos
		AC_MSG_RESULT([Checking sound device backend... coreaudio])
	fi
	;;
  *cygwin* | *mingw*)
	ac_pjmedia_snd=pa_win32
	AC_MSG_RESULT([Checking sound device backend... win32 sound])
	;;
  *rtems*)
	ac_pjmedia_snd=null
	AC_MSG_RESULT([Checking sound device backend... null sound])
	;;
  *)
	dnl # Check if ALSA is available
	ac_pjmedia_snd=pa_unix
	AC_CHECK_HEADER(alsa/version.h,
			[AC_SUBST(ac_pa_use_alsa,1)
			 LIBS="$LIBS -lasound"
			],
		        [AC_SUBST(ac_pa_use_alsa,0)])
	AC_MSG_RESULT([Checking sound device backend... unix])

	dnl # Check if OSS is disabled
	AC_SUBST(ac_pa_use_oss,1)
	AC_ARG_ENABLE(oss,
		      AC_HELP_STRING([--disable-oss],
				     [Disable OSS audio (default: not disabled)]),
		      [
			if test "$enable_oss" = "no"; then
			 [ac_pa_use_oss=0]
			 AC_MSG_RESULT([Checking if OSS audio is disabled... yes])
			fi
		      ])
	;;
 esac
fi

AC_SUBST(ac_pjmedia_video)

dnl # --disable-video option
AC_ARG_ENABLE(video,
	      AC_HELP_STRING([--disable-video],
	      		     [Disable video feature]),
	      [if test "$enable_video" = "no"; then
	        #AC_DEFINE(PJMEDIA_HAS_VIDEO,0)
                AC_MSG_RESULT([Video is disabled]) 
                enable_sdl="no"
                enable_ffmpeg="no"
		enable_v4l2="no"
               fi],
	      [])

case $target in
 arm-apple-darwin*)
 	LIBS="$LIBS -framework UIKit"
	;;
 *darwin*)
 	LIBS="$LIBS -framework Foundation -framework AppKit"
	;;
esac

if test "$enable_video" = "no"; then
  true;
else
 case $target in
  arm-apple-darwin*)
	ac_pjmedia_video=iphone_os
	AC_SUBST(ac_pjmedia_video_has_ios)
	AC_SUBST(ac_ios_cflags)
	SAVED_LIBS="$LIBS"
	LIBS="-framework AVFoundation -framework CoreGraphics -framework QuartzCore -framework CoreVideo -framework CoreMedia"
	AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [])],[ac_pjmedia_video_has_ios=yes],[ac_pjmedia_video_has_ios=no])
	LIBS="$SAVED_LIBS"
	if test "$ac_pjmedia_video_has_ios" = "yes"; then
	  ac_ios_cflags="-DPJMEDIA_VIDEO_DEV_HAS_IOS=1"
	  LIBS="$LIBS -framework AVFoundation -framework CoreGraphics -framework QuartzCore -framework CoreVideo -framework CoreMedia"
	  AC_MSG_RESULT([Checking if AVFoundation framework is available... yes])
	else
	  AC_MSG_RESULT([Checking if AVFoundation framework is available... no])
	fi
	;;
  *darwin*)
	ac_pjmedia_video=mac_os
	AC_SUBST(ac_pjmedia_video_has_qt)
	AC_SUBST(ac_qt_cflags)
	SAVED_LIBS="$LIBS"
	LIBS="-framework QTKit"
	AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [])],[ac_pjmedia_video_has_qt=yes],[ac_pjmedia_video_has_qt=no])
	LIBS="$SAVED_LIBS"
	if test "$ac_pjmedia_video_has_qt" = "yes"; then
	  ac_qt_cflags="-DPJMEDIA_VIDEO_DEV_HAS_QT=1"
	  LIBS="$LIBS -framework QTKit -framework QuartzCore -framework OpenGL"
	  AC_MSG_RESULT([Checking if QTKit framework is available... yes])
	else
	  AC_MSG_RESULT([Checking if QTKit framework is available... no])
	fi
	;;
 esac
fi

AC_ARG_ENABLE(ext_sound,
	      AC_HELP_STRING([--enable-ext-sound],
			     [PJMEDIA will not provide any sound device backend]),
	      [if test "$enable_ext_sound" = "yes"; then
		[ac_pjmedia_snd=external]
		AC_MSG_RESULT([Checking if external sound is set... yes])
	       fi]
	      )

dnl # Include resampling small filter
AC_SUBST(ac_no_small_filter)
AC_ARG_ENABLE(small-filter,
	      AC_HELP_STRING([--disable-small-filter],
			     [Exclude small filter in resampling]),
	      [if test "$enable_small_filter" = "no"; then
		[ac_no_small_filter='-DPJMEDIA_HAS_SMALL_FILTER=0']
		AC_MSG_RESULT([Checking if small filter is disabled... yes])
	       fi],
	      AC_MSG_RESULT([Checking if small filter is disabled... no]))

dnl # Include resampling large filter
AC_SUBST(ac_no_large_filter)
AC_ARG_ENABLE(large-filter,
	      AC_HELP_STRING([--disable-large-filter],
			     [Exclude large filter in resampling]),
	      [if test "$enable_large_filter" = "no"; then
		[ac_no_large_filter='-DPJMEDIA_HAS_LARGE_FILTER=0']
		AC_MSG_RESULT([Checking if large filter is disabled... yes])
	       fi],
	      AC_MSG_RESULT([Checking if large filter is disabled... no]))

dnl # Include Speex AEC
AC_SUBST(ac_no_speex_aec)
AC_ARG_ENABLE(speex-aec,
	      AC_HELP_STRING([--disable-speex-aec],
			     [Exclude Speex Acoustic Echo Canceller/AEC]),
	      [if test "$enable_speex_aec" = "no"; then
		[ac_no_speex_aec='-DPJMEDIA_HAS_SPEEX_AEC=0']
		AC_MSG_RESULT([Checking if Speex AEC is disabled...yes])
	       fi],
	      AC_MSG_RESULT([Checking if Speex AEC is disabled...no]))

dnl # Include G711 codec
AC_SUBST(ac_no_g711_codec)
AC_ARG_ENABLE(g711-codec,
	      AC_HELP_STRING([--disable-g711-codec],
			     [Exclude G.711 codecs from the build]),
	      [if test "$enable_g711_codec" = "no"; then
		[ac_no_g711_codec=1]
		AC_DEFINE(PJMEDIA_HAS_G711_CODEC,0)
		AC_MSG_RESULT([Checking if G.711 codec is disabled...yes])
	       fi],
	      AC_MSG_RESULT([Checking if G.711 codec is disabled...no]))


dnl # Include L16 codec
AC_SUBST(ac_no_l16_codec)
AC_ARG_ENABLE(l16-codec,
	      AC_HELP_STRING([--disable-l16-codec],
			     [Exclude Linear/L16 codec family from the build]),
	      [if test "$enable_l16_codec" = "no"; then
		[ac_no_l16_codec=1]
		AC_DEFINE(PJMEDIA_HAS_L16_CODEC,0)
		AC_MSG_RESULT([Checking if L16 codecs are disabled...yes])
	       fi],
	      AC_MSG_RESULT([Checking if L16 codec is disabled...no]))


dnl # Include GSM codec
AC_SUBST(ac_no_gsm_codec)
AC_ARG_ENABLE(gsm-codec,
	      AC_HELP_STRING([--disable-gsm-codec],
			     [Exclude GSM codec in the build]),
	      [if test "$enable_gsm_codec" = "no"; then
		[ac_no_gsm_codec=1]
		AC_DEFINE(PJMEDIA_HAS_GSM_CODEC,0)
		AC_MSG_RESULT([Checking if GSM codec is disabled...yes])
	       fi],
	      AC_MSG_RESULT([Checking if GSM codec is disabled...no]))

dnl # Include G.722 codec
AC_SUBST(ac_no_g722_codec)
AC_ARG_ENABLE(g722-codec,
	      AC_HELP_STRING([--disable-g722-codec],
			     [Exclude G.722 codec in the build]),
	      [if test "$enable_g722_codec" = "no"; then
		[ac_no_g722_codec=1]
		AC_DEFINE(PJMEDIA_HAS_G722_CODEC,0)
		AC_MSG_RESULT([Checking if G.722 codec is disabled...yes])
	       fi],
	      AC_MSG_RESULT([Checking if G.722 codec is disabled...no]))

dnl # Include G722.1 codec
AC_SUBST(ac_no_g7221_codec)
AC_ARG_ENABLE(g7221-codec,
	      AC_HELP_STRING([--disable-g7221-codec],
			     [Exclude G.7221 codec in the build]),
	      [if test "$enable_g7221_codec" = "no"; then
		[ac_no_g7221_codec=1]
		AC_DEFINE(PJMEDIA_HAS_G7221_CODEC,0)
		AC_MSG_RESULT([Checking if G.722.1 codec is disabled...yes])
	       fi],
	      AC_MSG_RESULT([Checking if G.722.1 codec is disabled...no]))

dnl # Include Speex codec
AC_SUBST(ac_no_speex_codec)
AC_ARG_ENABLE(speex-codec,
	      AC_HELP_STRING([--disable-speex-codec],
			     [Exclude Speex codecs in the build]),
	      [if test "$enable_speex_codec" = "no"; then
		[ac_no_speex_codec=1]
		AC_DEFINE(PJMEDIA_HAS_SPEEX_CODEC,0)
		AC_MSG_RESULT([Checking if Speex codec is disabled...yes])
	       fi],
	      AC_MSG_RESULT([Checking if Speex codec is disabled...no]))

dnl # Include iLBC codec
AC_SUBST(ac_no_ilbc_codec)
AC_ARG_ENABLE(ilbc-codec,
	      AC_HELP_STRING([--disable-ilbc-codec],
			     [Exclude iLBC codec in the build]),
	      [if test "$enable_ilbc_codec" = "no"; then
		[ac_no_ilbc_codec=1]
		AC_DEFINE(PJMEDIA_HAS_ILBC_CODEC,0)
		AC_MSG_RESULT([Checking if iLBC codec is disabled...yes])
	       fi],
	      AC_MSG_RESULT([Checking if iLBC codec is disabled...no]))

dnl # Include libsamplerate
AC_ARG_ENABLE(libsamplerate,
	      AC_HELP_STRING([--enable-libsamplerate],
			     [Link with libsamplerate when available.]),
	      [ AC_CHECK_LIB(samplerate,src_new) ]
	      [ac_pjmedia_resample=libsamplerate],
	      AC_MSG_RESULT([Skipping libsamplerate detection])
	     )

AC_SUBST(ac_resample_dll)
AC_ARG_ENABLE(resample_dll,
	      AC_HELP_STRING([--enable-resample-dll],
			     [Build libresample as shared library]),
	      [if test "$enable_resample_dll" = "yes"; then
		[ac_resample_dll=1]
		AC_MSG_RESULT([Building libresample as shared library... yes])
	       fi],
	      AC_MSG_RESULT([Building libresample as shared library... no])
	      )

dnl # SDL alt prefix
AC_ARG_WITH(sdl,
    AC_HELP_STRING([--with-sdl=DIR],
		   [Specify alternate libSDL prefix]),
    [],
    [with_sdl=no]
    )

dnl # Do not use default SDL installation if we are cross-compiling
if test "x$ac_cross_compile" != "x" -a "x$with_sdl" = "xno"; then
    enable_sdl=no
fi

dnl # SDL
AC_ARG_ENABLE(sdl,
	      AC_HELP_STRING([--disable-sdl],
			     [Disable SDL (default: not disabled)]),
	      [
		if test "$enable_sdl" = "no"; then
		  AC_MSG_RESULT([Checking if SDL is disabled... yes])
		fi
	      ],
	      [
		  if test "x$with_sdl" != "xno" -a "x$with_sdl" != "x"; then
			AC_MSG_RESULT([Using SDL prefix... $with_sdl])
			AC_PATH_PROGS(SDL_CONFIG,sdl2-config sdl-config,,$with_sdl/bin)
                  else
			AC_PATH_PROGS(SDL_CONFIG, sdl2-config sdl-config)
		  fi
		  
		  AC_MSG_CHECKING([SDL availability])
		  if test "x$SDL_CONFIG" = "x"; then
			AC_MSG_RESULT([not found])
		  elif (sh -c "$SDL_CONFIG --version" | grep -e '^1\.3' -e '^2\.') then
			AC_SUBST(ac_sdl_cflags)
			AC_SUBST(ac_sdl_ldflags)
			ac_sdl_cflags=`$SDL_CONFIG --cflags`
			ac_sdl_cflags="-DPJMEDIA_VIDEO_DEV_HAS_SDL=1 $ac_sdl_cflags"
			ac_sdl_ldflags=`$SDL_CONFIG --libs`
			LIBS="$LIBS $ac_sdl_ldflags"
		  else
			AC_MSG_RESULT([Unsupported SDL version])
		  fi
	      ])


AC_ARG_WITH(ffmpeg,
    AC_HELP_STRING([--with-ffmpeg=DIR],
		   [Specify alternate FFMPEG prefix]),
    [],
    [with_ffmpeg=no]
    )

dnl # Do not use default ffmpeg installation if we are cross-compiling
if test "x$ac_cross_compile" != "x" -a "x$with_ffmpeg" = "xno"; then
    enable_ffmpeg=no
fi

dnl # FFMPEG stuffs
AC_ARG_ENABLE(ffmpeg,
	      AC_HELP_STRING([--disable-ffmpeg],
			     [Disable ffmpeg (default: not disabled)]),
	      [
	        AC_SUBST(ac_has_ffmpeg,0)
		if test "$enable_ffmpeg" = "no"; then
			AC_MSG_RESULT([Checking if ffmpeg is disabled... yes])
		fi
	      ],
	      [
		AC_SUBST(ac_ffmpeg_cflags)
		AC_SUBST(ac_ffmpeg_ldflags)

		FFMPEG_PREFIX=""
		AC_SUBST(SAVED_PKG_CONFIG_PATH)
		SAVED_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
    		if test "x$with_ffmpeg" != "xno" -a "x$with_ffmpeg" != "x"; then
			FFMPEG_PREFIX=$with_ffmpeg
			AC_MSG_RESULT([Using ffmpeg prefix... $FFMPEG_PREFIX])
			export PKG_CONFIG_PATH=$FFMPEG_PREFIX/lib/pkgconfig
		fi

		AC_CHECK_PROGS(PKG_CONFIG,pkg-config "python pkgconfig.py",none)

		if test "$PKG_CONFIG" != "none"; then
			AC_MSG_CHECKING([ffmpeg packages])
			av_pkg=""
			if $PKG_CONFIG --exists libdevice; then
				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVDEVICE=1"
				av_pkg="$av_pkg libdevice"
			fi
			if $PKG_CONFIG --exists libavformat; then
				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVFORMAT=1"
				av_pkg="$av_pkg libavformat"
			fi
			if $PKG_CONFIG --exists libavcodec; then
				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCODEC=1"
				av_pkg="$av_pkg libavcodec"
			fi
			if $PKG_CONFIG --exists libswscale; then
				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBSWSCALE=1"
				av_pkg="$av_pkg libswscale"
			fi
			if $PKG_CONFIG --exists libavutil; then
				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVUTIL=1"
				av_pkg="$av_pkg libavutil"
			fi
			if $PKG_CONFIG --exists libavcore; then
				ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCORE=1"
				av_pkg="$av_pkg libavcore"
			fi
			
			if test "x$av_pkg" == "x"; then
			   AC_MSG_RESULT([none detected (check the prefix)! **])
			else
			   AC_MSG_RESULT([$av_pkg])
			fi
			
			ac_ffmpeg_cflags="$ac_ffmpeg_cflags `$PKG_CONFIG --cflags $av_pkg`"
			ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags `$PKG_CONFIG --libs $av_pkg`"

		else
			dnl #
			dnl # Use hardcoded values to configure ffmpeg
			dnl #
			
			AC_MSG_RESULT([*** Warning: neither pkg-config nor python is available, ffmpeg dependency cannot be calculated. If ffmpeg libraries are not detected, you need to specify the correct CFLAGS and LDFLAGS settings for ffmpeg prior to invoking configure ***])
			
			LIBS="-L$FFMPEG_PREFIX/lib $LIBS"
			LDFLAGS="-L$FFMPEG_PREFIX/lib $LDFLAGS"
			CFLAGS="-I$FFMPEG_PREFIX/include $CFLAGS"
			
			AC_CHECK_LIB(avdevice,
				     avdevice_version,
				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVDEVICE=1"
				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavdevice"
				     ]
				     )
			AC_CHECK_LIB(avutil,
				     av_malloc,
				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVUTIL=1"
				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavutil"
				     ]
				     )
			AC_CHECK_LIB(avcodec,
				     avcodec_init,
				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCODEC=1"
				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavcodec"
				     ],
				     [],
				     [-lavutil]
				     )
			AC_CHECK_LIB(avformat,
				     av_register_all,
				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVFORMAT=1"
				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavformat"
				     ],
				     [],
				     [-lavcodec -lavutil]
				     )
			AC_CHECK_LIB(swscale,
				     sws_scale,
				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBSWSCALE=1"
				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lswscale"
				     ],
				     [],
				     [-lavutil]
				     )
			AC_CHECK_LIB(avcore,
				     avcore_version,
				     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCORE=1"
				      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavcore"
				     ]
				     )
			
		fi
		
		LIBS="$LIBS $ac_ffmpeg_ldflags"
		export PKG_CONFIG_PATH=$SAVED_PKG_CONFIG_PATH
	      ]
	      )

dnl # Video for Linux 2
AC_ARG_ENABLE(v4l2,
	      AC_HELP_STRING([--disable-v4l2],
			     [Disable Video4Linux2 (default: not disabled)]),
	      [
		if test "$enable_v4l2" = "no"; then
		  AC_MSG_RESULT([Checking if V4L2 is disabled... yes])
		fi
	      ],
	      [
	        AC_SUBST(ac_v4l2_cflags)
	        AC_SUBST(ac_v4l2_ldflags)
		AC_CHECK_LIB(v4l2,
			     v4l2_open,
			     [ac_v4l2_cflags="-DPJMEDIA_VIDEO_DEV_HAS_V4L2=1"
			      ac_v4l2_ldflags="-lv4l2"
			      LIBS="$LIBS -lv4l2"
			     ]
			     )
	      ])

dnl ########################################################
dnl # Intel IPP support
dnl #
AC_ARG_ENABLE(ipp,
    AC_HELP_STRING([--enable-ipp],
		   [Enable Intel IPP support. Specify the Intel IPP package and samples location using IPPROOT and IPPSAMPLES env var or with --with-ipp and --with-ipp-samples options]),
    [],
    [enable_ipp=no]
    )

AC_ARG_WITH(ipp,
    AC_HELP_STRING([--with-ipp=DIR],
		   [Specify the Intel IPP location]),
    [],
    [with_ipp=no]
    )

AC_ARG_WITH(ipp-samples,
    AC_HELP_STRING([--with-ipp-samples=DIR],
		   [Specify the Intel IPP samples location]),
    [],
    [with_ipp_samples=no]
    )

AC_ARG_WITH(ipp-arch,
    AC_HELP_STRING([--with-ipp-arch=ARCH],
		   [Specify the Intel IPP ARCH suffix, e.g. "64" or "em64t. Default is blank for IA32"]),
    [],
    [with_ipp_arch=no]
    )

if test "x$enable_ipp" != "xno"; then
    dnl # 
    dnl # Verifying Intel IPP path
    dnl #
    AC_MSG_CHECKING([Intel IPP location])

    if test "x$with_ipp" != "xno" -a "x$with_ipp" != "x"; then
	AC_MSG_RESULT([$with_ipp])
	IPPROOT=$with_ipp
    elif test "x$IPPROOT" = "x"; then
	if test -d /opt/intel/ipp; then
	    IPPROOT=`ls -d /opt/intel/ipp/*/* | head -1`
	    AC_MSG_RESULT([autodetected in $IPPROOT])
	fi
    else
	AC_MSG_RESULT([$IPPROOT])
    fi

    if test "x$with_ipp_arch" != "xno"; then
	IPP_SUFFIX=$with_ipp_arch
	AC_MSG_RESULT([IPP arch suffix is set to $IPP_SUFFIX])
    else
	IPP_SUFFIX=""
	AC_MSG_RESULT([IPP arch suffix is set to empty])
    fi

    if test x$IPPROOT = x; then
	AC_MSG_ERROR([the location is neither specified nor can be guessed. Please specify with IPPROOT env var or with --with-ipp option])
    elif test ! -d $IPPROOT; then
	AC_MSG_ERROR([not found])
    elif test ! -d $IPPROOT/include; then
	AC_MSG_ERROR([directory doesn't seem to be valid])
    else
	# IPP directory looks okay.
	# Remove trailing backslash
	IPPROOT=`echo $IPPROOT | sed 's/\/$//'`

	SAVED_CFLAGS="$CFLAGS"
	SAVED_LDFLAGS="$LDFLAGS"
	SAVED_LIBS="$LIBS"

	IPP_CFLAGS="-I$IPPROOT/include"
	IPP_LIBS="-lippsc${IPP_SUFFIX} -lipps${IPP_SUFFIX} -lippcore${IPP_SUFFIX}"

#
	# Some differences between Mac OS X and Linux
	case $target in 
	    *darwin* )
		IPP_LDFLAGS="-L$IPPROOT/Libraries -L$IPPROOT/lib"
		;;
	    *)
	    	# Find out where the libraries live.
		IPP7_ARCH=""
		if test -d $IPPROOT/lib/intel64; then
		   IPP7_ARCH="intel64"
		elif test -d $IPPROOT/lib/ia32; then
		   IPP7_ARCH="ia32"
		elif test -d $IPPROOT/lib/mic; then
		   IPP7_ARCH="mic"
		fi

		if test -z "$IPP7_ARCH"; then
		   # IPP6 (and possibly below)
		   IPP_LDFLAGS="-L$IPPROOT/sharedlib"
		   IPP_LIBS="$IPP_LIBS  -lippsr${IPP_SUFFIX} -lguide"
		else
		   # IPP7
		   if ! test -d $IPPROOT/../compiler; then
			AC_MSG_ERROR([Cannot find $IPPROOT/../compiler directory. Please set IPPROOT variable correctly])
		   fi
		   IPP_CFLAGS="$IPP_CFLAGS"
		   IPP_LDFLAGS="-L$IPPROOT/lib/intel64 -L$IPPROOT/../compiler/lib/$IPP7_ARCH"
		   IPP_LIBS="$IPP_LIBS -liomp5"
		fi
		;;
	esac

	#IPP_LDFLAGS="-L$IPPROOT/sharedlib"
	#Static:
	#IPP_LIBS="-lippscmerged -lippsrmerged -lippsmerged -lippcore"

	CFLAGS="$CFLAGS $IPP_CFLAGS"
	LDFLAGS="$LDFLAGS $IPP_LDFLAGS"
	LIBS="$IPP_LIBS $LIBS"


	AC_MSG_CHECKING([Intel IPP usability])
	AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <ippcore.h>
					   ]],
					   [ippStaticInit();])],
		  [AC_MSG_RESULT(ok)],
		  [AC_MSG_FAILURE([Error: unable to recognize your IPP installation. Make sure the paths and ARCH suffix are set correctly, run with --help for more info])])

	CFLAGS="$SAVED_CFLAGS"
	LDFLAGS="$SAVED_LDFLAGS"
	LIBS="$SAVED_LIBS"
    fi

    dnl # 
    dnl # Verifying Intel IPP samples path
    dnl #
    AC_MSG_CHECKING([Intel IPP samples location])

    if test "x$with_ipp_samples" != "xno" -a "x$with_ipp_samples" != "x"; then
	AC_MSG_RESULT([$with_ipp_samples])
	IPPSAMPLES=$with_ipp_samples
    elif test "x$IPPSAMPLES" = "x"; then
	if test -d /opt/intel/ipp-samples; then
	    IPPSAMPLES=/opt/intel/ipp-samples
	    AC_MSG_RESULT([autodetected in $IPPSAMPLES])
	fi
    else
	AC_MSG_RESULT([$IPPSAMPLES])
    fi

    if test x$IPPSAMPLES = x; then
	AC_MSG_ERROR([the location is neither specified nor can be guessed. Please specify with IPPSAMPLES env var or with --with-ipp-samples option])
    elif test ! -d $IPPSAMPLES; then
	AC_MSG_ERROR([not found])
    elif test ! -d $IPPSAMPLES/speech-codecs; then
	AC_MSG_ERROR([directory doesn't seem to be valid])
    else
	# Remove trailing backslash
	IPPSAMPLES=`echo $IPPSAMPLES | sed 's/\/$//'`
	
	# Guess the libusc.a/libspeech.a build location
	AC_MSG_CHECKING([Intel IPP USC build location])
	if test -d $IPPSAMPLES/speech-codecs/bin; then
	    IPPVER=5 
	    IPPSAMP_DIR=`ls -d $IPPSAMPLES/speech-codecs/bin/*gcc*/lib | head -1`
	elif test -d $IPPSAMPLES/speech-codecs/_bin; then
	    IPPVER=6
	    if test -d $IPPSAMPLES/speech-codecs/_bin/*gcc*; then
		# gcc compiler
	    	IPPSAMP_DIR=`ls -d $IPPSAMPLES/speech-codecs/_bin/*gcc*/lib | head -1`
	    elif test -d $IPPSAMPLES/speech-codecs/_bin/*icc*; then
		# icc compiler
	    	IPPSAMP_DIR=`ls -d $IPPSAMPLES/speech-codecs/_bin/*icc*/lib | head -1`
	    else
		AC_MSG_FAILURE([Unable to find to find built binaries under $IPPSAMPLES/speech-codecs/{bin,_bin}. Have you built the IPP samples?])
	    fi
	else
	    AC_MSG_FAILURE([unable to find $IPPSAMPLES/speech-codecs/bin/*gcc*/lib or $IPPSAMPLES/speech-codecs/_bin/*gcc*/lib directory. Have you built the samples?])
	fi

	# Test the directory
	if test ! -d $IPPSAMP_DIR; then
	    AC_MSG_FAILURE([There's something wrong with this script, directory $IPPSAMP_DIR does not exist])
	    exit 1;
	fi

    	if test "x$IPPVER" = "x5"; then
	    IPPSAMP_LIBS="libusc.a"
	    IPPSAMP_LDLIBS="-lusc"
	elif test "x$IPPVER" = "x6"; then
	    IPPSAMP_LIBS="libspeech.a"
	    IPPSAMP_LDLIBS="-lspeech"
	else
	    AC_MSG_FAILURE([bug in this script: unsupported IPP version])
	fi

	if test ! -f $IPPSAMP_DIR/$IPPSAMP_LIBS; then
	    AC_MSG_FAILURE([$IPPSAMP_LIBS doesn't exist in $IPPSAMP_DIR])
	fi

	AC_MSG_RESULT([$IPPSAMP_DIR])

	SAVED_CFLAGS="$CFLAGS"
	SAVED_LDFLAGS="$LDFLAGS"
	SAVED_LIBS="$LIBS"

	IPPSAMP_INC="-I$IPPSAMPLES/speech-codecs/core/usc/include"
	CFLAGS="$CFLAGS $IPPSAMP_INC"
	LDFLAGS="$LDFLAGS -L$IPPSAMP_DIR"
	LIBS="$IPPSAMP_LDLIBS $LIBS"

	AC_MSG_CHECKING([Intel IPP USC usability])
	AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <usc.h>
					   ]],
					   [extern USC_Fxns USC_G729AFP_Fxns;])],
		  [AC_MSG_RESULT(ok)],
		  [AC_MSG_FAILURE(failed)])

	CFLAGS="$SAVED_CFLAGS"
	LDFLAGS="$IPP_LDFLAGS $SAVED_LDFLAGS"
	LIBS="$IPP_LIBS $SAVED_LIBS"

	IPP_CFLAGS="$IPP_CFLAGS $IPPSAMP_INC"
	IPP_LDFLAGS="$IPP_LDFLAGS -L$IPPSAMP_DIR"
	IPP_LIBS="$IPPSAMP_LDLIBS $IPP_LIBS"
    fi

    CFLAGS="$CFLAGS $IPP_CFLAGS"
    LDFLAGS="$LDFLAGS $IPP_LDFLAGS"
    LIBS="$LIBS $IPP_LIBS"

    ac_build_mak_vars="$ac_build_mak_vars\n\
export IPP_CFLAGS=$IPP_CFLAGS\n\
export IPP_LDFLAGS=$IPP_LDFLAGS\n\
export IPP_LIBS=$IPP_LIBS"
else
    AC_MSG_RESULT([Skipping Intel IPP settings (not wanted)])
fi


dnl ##########################################
dnl #
dnl # PJSIP CONFIG
dnl #

dnl # SSL alt prefix
AC_ARG_WITH(ssl,
    AC_HELP_STRING([--with-ssl=DIR],
		   [Specify alternate libssl prefix]),
    [],
    [with_ssl=no]
    )

dnl # Do not use default SSL installation if we are cross-compiling
if test "x$ac_cross_compile" != "x" -a "x$with_ssl" = "xno"; then
    enable_ssl=no
fi

dnl # Include SSL support
AC_SUBST(ac_no_ssl)
AC_ARG_ENABLE(ssl,
	      AC_HELP_STRING([--disable-ssl],
			     [Exclude SSL support the build (default: autodetect)])
	      ,
	      [
		if test "$enable_ssl" = "no"; then
		 [ac_no_ssl=1]
		 AC_MSG_RESULT([Checking if SSL support is disabled... yes])
	        fi
	      ],
	      [
		AC_MSG_RESULT([checking for OpenSSL installations..])
                if test "x$with_ssl" != "xno" -a "x$with_ssl" != "x"; then
                    CFLAGS="$CFLAGS -I$with_ssl/include"
                    LDFLAGS="$LDFLAGS -L$with_ssl/lib"
                    AC_MSG_RESULT([Using SSL prefix... $with_ssl])
                fi
		AC_SUBST(openssl_h_present)
		AC_SUBST(libssl_present)
		AC_SUBST(libcrypto_present)
		AC_CHECK_HEADER(openssl/ssl.h,[openssl_h_present=1])
		AC_CHECK_LIB(crypto,ERR_load_BIO_strings,[libcrypto_present=1 && LIBS="$LIBS -lcrypto"])
		AC_CHECK_LIB(ssl,SSL_library_init,[libssl_present=1 && LIBS="$LIBS -lssl"])
		if test "x$openssl_h_present" = "x1" -a "x$libssl_present" = "x1" -a "x$libcrypto_present" = "x1"; then
	        	AC_MSG_RESULT([OpenSSL library found, SSL support enabled])
			# PJSIP_HAS_TLS_TRANSPORT setting follows PJ_HAS_SSL_SOCK
			#AC_DEFINE(PJSIP_HAS_TLS_TRANSPORT, 1)
			AC_DEFINE(PJ_HAS_SSL_SOCK, 1)
		else
			AC_MSG_RESULT([** OpenSSL libraries not found, disabling SSL support **])
		fi
	      ])

dnl # Obsolete option --with-opencore-amrnb
AC_ARG_WITH(opencore-amrnb,
    AC_HELP_STRING([--with-opencore-amrnb=DIR],
		   [This option is obsolete and replaced by --with-opencore-amr=DIR]),
    [AC_MSG_ERROR(This option is obsolete and replaced by --with-opencore-amr=DIR)],
    []
    )

dnl # opencore-amr alt prefix
AC_ARG_WITH(opencore-amr,
    AC_HELP_STRING([--with-opencore-amr=DIR],
		   [Specify alternate libopencore-amr prefix]),
    [],
    [with_opencore_amr=no]
    )

dnl # Do not use default opencore-amr installation if we are cross-compiling
if test "x$ac_cross_compile" != "x" -a "x$with_opencore_amr" = "xno"; then
    enable_opencore_amr=no
fi

dnl # vo-amrwbenc alt prefix
AC_ARG_WITH(opencore-amrwbenc,
    AC_HELP_STRING([--with-opencore-amrwbenc=DIR],
		   [Specify alternate libvo-amrwbenc prefix]),
    [],
    [with_opencore_amrwbenc=no]
    )

dnl # Do not use default vo-amrwbenc installation if we are cross-compiling
if test "x$ac_cross_compile" != "x" -a "x$with_opencore_amrwbenc" = "xno"; then
    enable_opencore_amrwbenc=no
fi


dnl # Include opencore-amr support
AC_SUBST(ac_no_opencore_amrnb)
AC_SUBST(ac_no_opencore_amrwb)
AC_ARG_ENABLE(opencore_amr,
	      AC_HELP_STRING([--disable-opencore-amr],
			     [Exclude OpenCORE AMR support from the build (default: autodetect)])
	      ,
	      [
		if test "$enable_opencore_amr" = "no"; then
		 [ac_no_opencore_amrnb=1]
		 [ac_no_opencore_amrwb=1]
		 AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC,0)
		 AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRWB_CODEC,0)
		 AC_MSG_RESULT([Checking if OpenCORE AMR support is disabled... yes])
	        fi
	      ],
	      [
		AC_MSG_RESULT([checking for OpenCORE AMR installations..])
                if test "x$with_opencore_amr" != "xno" -a "x$with_opencore_amr" != "x"; then
                    CFLAGS="$CFLAGS -I$with_opencore_amr/include"
                    LDFLAGS="$LDFLAGS -L$with_opencore_amr/lib"
                    AC_MSG_RESULT([Using OpenCORE AMR prefix... $with_opencore_amr])
                fi
                if test "x$with_opencore_amrwbenc" != "xno" -a "x$with_opencore_amrwbenc" != "x"; then
                    CFLAGS="$CFLAGS -I$with_opencore_amrwbenc/include"
                    LDFLAGS="$LDFLAGS -L$with_opencore_amrwbenc/lib"
                    AC_MSG_RESULT([Using OpenCORE AMRWB-enc prefix... $with_opencore_amrwbenc])
                fi
		AC_SUBST(opencore_amrnb_h_present)
		AC_SUBST(opencore_amrnb_present)
		AC_CHECK_HEADER(opencore-amrnb/interf_enc.h,[opencore_amrnb_h_present=1])
		AC_CHECK_LIB(opencore-amrnb,Encoder_Interface_init,[opencore_amrnb_present=1 && LIBS="$LIBS -lopencore-amrnb"])
		if test "x$opencore_amrnb_h_present" = "x1" -a "x$opencore_amrnb_present" = "x1"; then
	        	AC_MSG_RESULT([OpenCORE AMR-NB library found, AMR-NB support enabled])
	        	AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC,1)
		else
			[ac_no_opencore_amrnb=1]
			AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC,0)
		fi
		AC_SUBST(opencore_amrwb_enc_h_present)
		AC_SUBST(opencore_amrwb_enc_present)
		AC_SUBST(opencore_amrwb_dec_h_present)
		AC_SUBST(opencore_amrwb_dec_present)
		AC_CHECK_HEADER(vo-amrwbenc/enc_if.h,[opencore_amrwb_enc_h_present=1])
		AC_CHECK_HEADER(opencore-amrwb/dec_if.h,[opencore_amrwb_dec_h_present=1])
		AC_CHECK_LIB(opencore-amrwb,D_IF_init,[opencore_amrwb_dec_present=1 && LIBS="$LIBS -lopencore-amrwb"])
		AC_CHECK_LIB(vo-amrwbenc,E_IF_init,[opencore_amrwb_enc_present=1 && LIBS="$LIBS -lvo-amrwbenc"])
		if test "x$opencore_amrwb_enc_h_present" = "x1" -a "x$opencore_amrwb_dec_h_present" = "x1" -a "x$opencore_amrwb_enc_present" = "x1" -a "x$opencore_amrwb_dec_present" = "x1"; then
	        	AC_MSG_RESULT([OpenCORE AMR-WB library found, AMR-WB support enabled])
	        	AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRWB_CODEC,1)
		else
			[ac_no_opencore_amrwb=1]
			AC_DEFINE(PJMEDIA_HAS_OPENCORE_AMRWB_CODEC,0)
		fi

	      ])

dnl # SILK prefix
AC_ARG_WITH(silk,
    AC_HELP_STRING([--with-silk=DIR],
		   [Specify alternate SILK prefix]),
    [],
    [with_silk=no]
    )

dnl # Do not use default SILK installation if we are cross-compiling
if test "x$ac_cross_compile" != "x" -a "x$with_silk" = "xno"; then
    enable_silk=no
fi

dnl # Include SILK support
AC_SUBST(ac_no_silk)
AC_ARG_ENABLE(silk,
	      AC_HELP_STRING([--disable-silk],
			     [Exclude SILK support from the build (default: autodetect)])
	      ,
	      [
		if test "$enable_silk" = "no"; then
		 [ac_no_silk=1]
		 AC_DEFINE(PJMEDIA_HAS_SILK_CODEC,0)
		 AC_MSG_RESULT([Checking if SILK support is disabled... yes])
	        fi
	      ],
	      [
		AC_MSG_RESULT([checking for SILK installations..])
                if test "x$with_silk" != "xno" -a "x$with_silk" != "x"; then
                    CFLAGS="$CFLAGS -I$with_silk/interface"
		    CPPFLAGS="$CPPFLAGS -I$with_silk/interface"
                    LDFLAGS="$LDFLAGS -L$with_silk"
                    AC_MSG_RESULT([Using SILK prefix... $with_silk])
                fi                
		AC_SUBST(silk_h_present)
		AC_SUBST(silk_present)
		AC_CHECK_HEADER(SKP_Silk_SDK_API.h,[silk_h_present=1])
		AC_CHECK_LIB(SKP_SILK_SDK,SKP_Silk_SDK_get_version,[silk_present=1 && LIBS="$LIBS -lSKP_SILK_SDK"])
		if test "x$silk_h_present" = "x1" -a "x$silk_present" = "x1"; then
	        	AC_MSG_RESULT([SILK library found, SILK support enabled])
	        	AC_DEFINE(PJMEDIA_HAS_SILK_CODEC,1)
		else
			[ac_no_silk=1]
			AC_DEFINE(PJMEDIA_HAS_SILK_CODEC,0)
		fi
	      ])


dnl ##########################################
dnl #
dnl # MANUAL CONFIG
dnl #


dnl # Determine if select() requires nfds to be filled up with
dnl # correct value (max_fd+1). If zero, nfds will be filled up with
dnl # PJ_FD_SETSIZE
AC_MSG_CHECKING([if select() needs correct nfds])
case $target in
  *rtems*) AC_DEFINE(PJ_SELECT_NEEDS_NFDS,1)
	   AC_MSG_RESULT(yes)
	;;
  *) AC_DEFINE(PJ_SELECT_NEEDS_NFDS,0)
     AC_MSG_RESULT([no (default)])
     AC_MSG_RESULT([** Decided that select() doesn't need correct nfds (please check)])
	;;
esac

dnl # Determine if pj_thread_create() should enforce thread stack size when
dnl # creating thread. Default is zero, to allow OS to allocate appropriate
dnl # thread's stack size.
AC_MSG_CHECKING([if pj_thread_create() should enforce stack size])
case $target in
  *rtems*) AC_DEFINE(PJ_THREAD_SET_STACK_SIZE,1)
	   AC_MSG_RESULT(yes)
	;;
  *) AC_DEFINE(PJ_THREAD_SET_STACK_SIZE,0)
     AC_MSG_RESULT([no (default)])
	;;
esac

dnl # Determine if pj_thread_create() should allocate thread's stack from
dnl # the pool. Default is zero, to let OS allocate thread's stack.
AC_MSG_CHECKING([if pj_thread_create() should allocate stack])
case $target in
  *rtems*) AC_DEFINE(PJ_THREAD_ALLOCATE_STACK,1)
	   AC_MSG_RESULT(yes)
	;;
  *) AC_DEFINE(PJ_THREAD_ALLOCATE_STACK,0)
     AC_MSG_RESULT([no (default)])
	;;
esac

dnl # This value specifies the value set in errno by the OS when a non-blocking
dnl # socket recv() can not return immediate data.
case $target in
  *mingw* | *cygw* | *win32* | *w32* )
	AC_DEFINE(PJ_BLOCKING_ERROR_VAL,WSAEWOULDBLOCK)
	;;
  *) AC_DEFINE(PJ_BLOCKING_ERROR_VAL,EAGAIN)
     AC_MSG_RESULT([** Setting non-blocking recv() retval to EAGAIN (please check)])
	;;
esac

dnl # This value specifies the value set in errno by the OS when a non-blocking
dnl # socket connect() can not get connected immediately.
case $target in
  *mingw* | *cygw* | *win32* | *w32* )
	AC_DEFINE(PJ_BLOCKING_CONNECT_ERROR_VAL,WSAEWOULDBLOCK)
	;;
  *) AC_DEFINE(PJ_BLOCKING_CONNECT_ERROR_VAL,EINPROGRESS)
     AC_MSG_RESULT([** Setting non-blocking connect() retval to EINPROGRESS (please check)])
	;;
esac


AC_SUBST(target)
AC_SUBST(ac_linux_poll,select)
AC_SUBST(ac_host,unix)
AC_SUBST(ac_main_obj)
case $target in
  *rtems*)
	ac_main_obj=main_rtems.o
	;;
  *)
	ac_main_obj=main.o
	;;
esac
AC_SUBST(CC)

ac_build_mak_vars=`echo $ac_build_mak_vars | sed 's/\\\\n/\n/g'`
AC_OUTPUT()


AC_MSG_RESULT([

Configurations for current target have been written to 'build.mak', and 'os-auto.mak' in various build directories, and pjlib/include/pj/compat/os_auto.h.

Further customizations can be put in:
  - 'user.mak'
  - 'pjlib/include/pj/config_site.h'

The next step now is to run 'make dep' and 'make'.
])