aboutsummaryrefslogtreecommitdiff
path: root/configure.in
blob: d1e410ab7098a5be99a48cdb5586ff5196364c22 (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
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT([xbmc], [12.9.91], [http://issues.xbmc.org])
AC_CONFIG_HEADERS([xbmc/config.h])
AH_TOP([#pragma once])
m4_include([m4/ax_prog_cc_for_build.m4])
m4_include([m4/ax_prog_cxx_for_build.m4])
m4_include([m4/ax_python_devel.m4])
m4_include([m4/xbmc_arch.m4])

AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign])
AC_CANONICAL_HOST

tolower(){
  echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
}

# workaround for autotools that don't set this
abs_top_srcdir=${abs_top_srcdir=$(cd $srcdir; pwd)}

# check for enabling additional players
AC_DEFUN([XB_ADD_PLAYER],
[
  AC_MSG_CHECKING([for $2])
  case $add_players in
    *$2*)
      AC_SUBST([USE_$1], 1)
      AC_DEFINE([HAS_$1], 1, [using $2])
      AC_MSG_RESULT([enabling $2])
      ;;
    *)
      AC_MSG_RESULT([$2 is not enabled])
  esac
])

# check for enabling additional codecs
AC_DEFUN([XB_ADD_CODEC],
[
  AC_MSG_CHECKING([for $2])
  case $3 in
    *$2*)
      use_codec_$2="yes"
      AC_SUBST([USE_$1], 1)
      AC_DEFINE([HAS_$1], 1, [using $2])
      AC_MSG_RESULT([enabling $2])
      ;;
    *)
      AC_MSG_RESULT([$2 is not enabled])
  esac
])

# check for library basenames
AC_DEFUN([XB_FIND_SONAME],
[
  if echo "$host" | grep -q freebsd ; then
    AC_MSG_CHECKING([for lib$2 soname])
    $1_SONAME=[`ldconfig -r | sed -n "s;.* \(/.*lib$2\.so.*\)$;\1;p" | head -n 1`]
    if test x$$1_SONAME != x ; then
      $1_SONAME=[`basename $$1_SONAME`]
    fi
  elif [[ "$host_vendor" != "apple" ]]; then
    AC_MSG_CHECKING([for lib$2 soname])
    $1_FILENAME=$($CC -nostdlib -o /dev/null $LDFLAGS -l$2 -Wl,-M 2>/dev/null | grep "^LOAD.*$2" | awk '{V=2; print $V}')
    if [[ -z $$1_FILENAME ]]; then
      #try gold linker syntax
      $1_FILENAME=$($CC -nostdlib -o /dev/null $LDFLAGS -l$2 -Wl,-t 3>&1 1>&2 2>&3 | grep "lib$2")
    fi
    if [[ ! -z $$1_FILENAME ]]; then
      $1_SONAME=$($OBJDUMP -p $$1_FILENAME | grep "SONAME.*$2" | awk '{V=2; print $V}')
    fi
  else
    AC_MSG_CHECKING([for lib$2 dylib])
    gcc_lib_path=[`$CC -print-search-dirs 2>/dev/null | fgrep libraries: | sed 's/[^=]*=\(.*\)/\1/' | sed 's/:/ /g'`]
    env_lib_path=[`echo $LDFLAGS | sed 's/-L[ ]*//g'`]
    if test "$cross_compiling" = yes; then
      host_lib_path=""
    else
      host_lib_path="/usr/lib /usr/local/lib"
    fi
    for path in $gcc_lib_path $env_lib_path $host_lib_path; do
      lib=[`ls -- $path/lib$2.dylib 2>/dev/null`]
      if test x$lib != x; then
        # we want the path/name that is embedded in the dylib 
        $1_SONAME=[`otool -L $lib | grep -v lib$2.dylib | grep lib$2 | awk '{V=1; print $V}'`]
        $1_SONAME=[`basename $$1_SONAME`]
      fi
    done
  fi
  if [[ -z "$$1_SONAME" ]]; then
    AC_MSG_RESULT([no])
    if test -z "$3" || test "x${$3}" = "xyes"; then
      AC_MSG_ERROR([Unable to determine soname of lib$2 library])
    else
      AC_MSG_WARN([Unable to determine soname of lib$2 library])
      $3=no
      AC_MSG_WARN([lib$2 support disabled])
    fi
  else
    AC_MSG_RESULT([$$1_SONAME])
    AC_SUBST($1_SONAME)
  fi
])

# Function to push and pop libs and includes for a command
AC_DEFUN([XB_PUSH_FLAGS], [
  SAVE_LIBS="$LIBS"
  SAVE_INCLUDES="$INCLUDES"
  LIBS="[$2]"
  INCLUDES="[$1]"
  [$3]
  LIBS="$SAVE_LIBS"
  INCLUDES="$SAVE_INCLUDES"
])

# General message strings
configure_debug="ERROR: this is a configure debug statement"
missing_library="Could not find a required library. Please see the README for your platform."
missing_headers="Could not find some required headers. Please see the README for your platform."
missing_program="Could not find a required program. Please see the README for your platform."
xrandr_not_found="== Could not find libXRandR. SDL will be used for resolution support. =="
xrandr_disabled="== XRandR support disabled. SDL will be used for resolution support. =="
waveform_enabled="== WAVEFORM enabled =="
waveform_disabled="== WAVEFORM disabled =="
spectrum_enabled="== SPECTRUM enabled =="
spectrum_disabled="== SPECTRUM disabled =="
goom_enabled="== GOOM enabled. =="
goom_disabled="== GOOM disabled. =="
alsa_disabled="== ALSA support disabled. =="
rsxs_enabled="== RSXS enabled. =="
rsxs_disabled="== RSXS disabled. =="
fishbmc_enabled="== FishBMC enabled. =="
fishbmc_disabled="== FishBMC disabled. =="
projectm_enabled="== ProjectM enabled. =="
projectm_disabled="== ProjectM disabled. =="
wayland_enabled="== Wayland enabled. =="
wayland_disabled="== Wayland disabled. =="
x11_enabled="== X11 enabled. =="
x11_disabled="== X11 disabled. =="
pulse_not_found="== Could not find libpulse. PulseAudio support disabled. =="
pulse_disabled="== PulseAudio support disabled. =="
dvdcss_enabled="== DVDCSS support enabled. =="
dvdcss_disabled="== DVDCSS support disabled. =="
hal_not_found="== Could not find hal. HAL support disabled. =="
halstorage_not_found="== Could not find hal-storage. HAL support disabled. =="
hal_disabled="== HAL support disabled. =="
avahi_not_found="== Could not find libavahi-common or libavahi-client. Avahi support disabled. =="
avahi_disabled="== Avahi support disabled. =="
mdnsembedded_not_found="== Could not find mDNSEmbedded. Might prevent zeroconf support. =="
mdnsembedded_disabled="== mDNSEmbedded support disabled. =="
vdpau_not_found="== Could not find libvdpau. VDPAU support disabled. =="
vdpau_disabled="== VDPAU support manually disabled. =="
vaapi_not_found="== Could not find libva. VAAPI support disabled. =="
vaapi_disabled="== VAAPI support manually disabled. =="
crystalhd_not_found="== Could not find libcrystalhd. CrystalHD support disabled. =="
crystalhd_disabled="== CrystalHD support manually disabled. =="
vtbdecoder_enabled="== VTBDecoder support enabled. =="
vtbdecoder_disabled="== VTBDecoder support manually disabled. =="
openmax_disabled="== OpenMax support manually disabled. =="
openmax_not_found="== Could not find libnvomx. OpenMax support disabled. =="
ssh_not_found="== Could not find libssh. =="
ssh_disabled="== SSH SFTP disabled. =="
librtmp_not_found="== Could not find libRTMP. RTMP support disabled. =="
librtmp_disabled="== RTMP support disabled. =="
libnfs_not_found="== Could not find libnfs. NFS client support disabled. =="
libnfs_disabled="== NFS support disabled. =="
libafpclient_not_found="== Could not find libafpclient. AFP client support disabled. =="
libafpclient_disabled="== AFP support disabled. =="
libshairport_not_found="== Could not find libshairport. =="
libshairplay_not_found="== Could not find libshairplay. =="
samba_disabled="== SAMBA support disabled. =="
libplist_not_found="== Could not find libplist. AirPlay support disabled. =="
libplist_disabled="== AirPlay support disabled. =="
alsa_not_found="== Could not find ALSA. ALSA support disabled. =="
dbus_not_found="== Could not find DBUS. DBUS support disabled. =="
libcap_disabled="== Capabilities detection support disabled. =="
libcap_not_found="== Could not find libcap. Capabilities detection support disabled. =="
gtest_enabled="== Google Test Framework will be configured. =="
gtest_disabled="== Google Test Framework will not be configured. =="

libudev_not_found="== Could not find libudev. Will use polling to check for device changes. =="
libudev_disabled="== udev support disabled. Will use polling to check for device changes. =="
libusb_not_found="== Could not find libusb. Plug and play USB device support will not be available. =="
libusb_disabled="== libusb disabled. Plug and play USB device support will not be available. =="
libusb_disabled_udev_found="== libusb disabled. =="
libcec_enabled="== libcec enabled. =="
libcec_disabled="== libcec disabled. CEC adapter support will not be available. =="

# External library message strings
external_libraries_enabled="== Use of all supported external libraries enabled. =="
external_libraries_disabled="== Use of all supported external libraries disabled. =="
dashes="------------------------"
final_message="\n  XBMC Configuration:"
final_message="\n$dashes$final_message\n$dashes"

AC_ARG_ENABLE([shared-lib],
  [AS_HELP_STRING([--enable-shared-lib],
  [build libxbmc. helpful for tests (default is no)])],
  [build_shared_lib=$enableval],
  [build_shared_lib=no])

AC_ARG_ENABLE([debug],
  [AS_HELP_STRING([--enable-debug],
  [enable debugging information (default is yes)])],
  [use_debug=$enableval],
  [use_debug=yes])

AC_ARG_WITH([arch],
  [AS_HELP_STRING([--with-arch],
  [build with given arch passing to internal ffmpeg (default is no, needed for crosscompiling)])],
  [use_arch=$withval],
  [use_arch=no])

AC_ARG_WITH([platform],
  [AS_HELP_STRING([--with-platform],
  [use a pre-configured config for common arm boards])],
  [use_platform=$withval],
  [use_platform=none])

AC_ARG_WITH([cpu],
  [AS_HELP_STRING([--with-cpu],
  [build with given cpu passing to ffmpeg (default is no)])],
  [use_cpu=$withval],
  [use_cpu=no])

AC_ARG_ENABLE([neon],
  [AS_HELP_STRING([--enable-neon],
  [enable neon passing to ffmpeg (default is no)])],
  [use_neon=$enableval],
  [use_neon=no])

AC_ARG_ENABLE([optimizations],
  [AS_HELP_STRING([--enable-optimizations],
  [enable optimization (default is yes)])],
  [use_optimizations=$enableval],
  [use_optimizations=yes])

AC_ARG_ENABLE([gl],
  [AS_HELP_STRING([--enable-gl],
  [enable OpenGL rendering (default is yes)])],
  [use_gl=$enableval],
  [use_gl=yes])

AC_ARG_ENABLE([gles],
  [AS_HELP_STRING([--enable-gles],
  [enable OpenGLES rendering (default is no)])],
  [use_gles=$enableval],
  [use_gles=no])

AC_ARG_ENABLE([sdl],
  [AS_HELP_STRING([--enable-sdl],
  [enable SDL (default is auto)])],
  [use_sdl=$enableval],
  [use_sdl=auto])

AC_ARG_ENABLE([vdpau],
  [AS_HELP_STRING([--enable-vdpau],
  [enable VDPAU decoding (default is auto)])],
  [use_vdpau=$enableval],
  [use_vdpau=auto])

AC_ARG_ENABLE([vaapi],
  [AS_HELP_STRING([--enable-vaapi],
  [enable VAAPI decoding (default is auto)])],
  [use_vaapi=$enableval],
  [use_vaapi=auto])

AC_ARG_ENABLE([crystalhd],
  [AS_HELP_STRING([--enable-crystalhd],
  [enable CrystalHD decoding (default is auto)])],
  [use_crystalhd=$enableval],
  [use_crystalhd=auto])

AC_ARG_ENABLE([vtbdecoder],
  [AS_HELP_STRING([--enable-vtbdecoder],
  [enable VTBDecoder decoding (default is auto)])],
  [use_vtbdecoder=$enableval],
  [use_vtbdecoder=auto])

AC_ARG_ENABLE([openmax],
  [AS_HELP_STRING([--enable-openmax],
  [enable OpenMax decoding (default is auto, requires OpenGLES)])],
  [use_openmax=$enableval],
  [use_openmax=auto])

AC_ARG_ENABLE([tegra],
  [AS_HELP_STRING([--enable-tegra],
  [enable Tegra2 arm (default is no)])],
  [use_tegra=$enableval],
  [use_tegra=no])

AC_ARG_ENABLE([profiling],
  [AS_HELP_STRING([--enable-profiling],
  [enable gprof profiling (default is no)])],
  [use_profiling=$enableval],
  [use_profiling=no])

AC_ARG_ENABLE([joystick],
  [AS_HELP_STRING([--enable-joystick],
  [enable SDL joystick support (default is yes)])],
  [use_joystick=$enableval],
  [use_joystick=yes])

AC_ARG_ENABLE([xrandr],
  [AS_HELP_STRING([--enable-xrandr],
  [enable XRandR support (default is yes)])],
  [use_xrandr=$enableval],
  [use_xrandr=yes])

AC_ARG_ENABLE([waveform],
  [AS_HELP_STRING([--enable-waveform],
  [enable Waveform visualisation (default is yes)])],
  [use_waveform=$enableval],
  [use_waveform=yes])

AC_ARG_ENABLE([spectrum],
  [AS_HELP_STRING([--enable-spectrum],
  [enable Spectrum visualisation (default is yes)])],
  [use_spectrum=$enableval],
  [use_spectrum=yes])

AC_ARG_ENABLE([goom],
  [AS_HELP_STRING([--enable-goom],
  [enable GOOM visualisation (default is no)])],
  [use_goom=$enableval],
  [use_goom=no])

AC_ARG_ENABLE([rsxs],
  [AS_HELP_STRING([--enable-rsxs],
  [enable really slick X screensavers (default is yes)])],
  [use_rsxs=$enableval],
  [use_rsxs=yes])

AC_ARG_ENABLE([fishbmc],
  [AS_HELP_STRING([--enable-fishbmc],
  [enable FishBMC visualisation (default is yes)])],
  [use_fishbmc=$enableval],
  [use_fishbmc=yes])

AC_ARG_ENABLE([projectm],
  [AS_HELP_STRING([--enable-projectm],
  [enable ProjectM visualisation (default is yes)])],
  [use_projectm=$enableval],
  [use_projectm=yes])

AC_ARG_ENABLE([wayland],
  [AS_HELP_STRING([--enable-wayland],
  [enable wayland (default is no) 'Linux Only'])],
  [use_wayland=$enableval],
  [use_wayland=no])

AC_ARG_ENABLE([x11],
  [AS_HELP_STRING([--enable-x11],
  [enable x11 (default is yes) 'Linux Only'])],
  [use_x11=$enableval],
  [use_x11=yes])

AC_ARG_ENABLE([ccache],
  [AS_HELP_STRING([--enable-ccache],
  [enable building with ccache feature (default is auto)])],
  [use_ccache=$enableval],
  [use_ccache=auto])

AC_ARG_ENABLE([alsa],
  [AS_HELP_STRING([--disable-alsa],
  [disable ALSA support (only for linux/freebsd)])],
  [use_alsa=$enableval],
  [use_alsa=yes])

AC_ARG_ENABLE([pulse],
  [AS_HELP_STRING([--enable-pulse],
  [enable PulseAudio support (default is auto)])],
  [use_pulse=$enableval],
  [use_pulse=auto])

AC_ARG_ENABLE([ssh],
  [AS_HELP_STRING([--disable-ssh],
  [disable SSH SFTP support (default is enabled)])],
  [use_ssh=$enableval],
  [use_ssh=yes])

AC_ARG_ENABLE([rtmp],
  [AS_HELP_STRING([--enable-rtmp],
  [enable RTMP support via librtmp (default is auto)])],
  [use_librtmp=$enableval],
  [use_librtmp=auto])

AC_ARG_ENABLE([samba],
  [AS_HELP_STRING([--disable-samba],
  [disable SAMBA support (default is enabled)])],
  [use_samba=$enableval],
  [use_samba=yes])

AC_ARG_ENABLE([nfs],
  [AS_HELP_STRING([--enable-nfs],
  [enable NFS support via libnfs (default is auto)])],
  [use_libnfs=$enableval],
  [use_libnfs=auto])

AC_ARG_ENABLE([afpclient],
  [AS_HELP_STRING([--enable-afpclient],
  [enable AFP support via libafpclient (default is auto)])],
  [use_libafpclient=$enableval],
  [use_libafpclient=auto])

AC_ARG_ENABLE([airplay],
  [AS_HELP_STRING([--enable-airplay],
  [enable AirPlay support(default is auto)])],
  [use_airplay=$enableval],
  [use_airplay=auto])

AC_ARG_ENABLE([airtunes],
  [AS_HELP_STRING([--enable-airtunes],
  [enable AirTunes support(default is auto)])],
  [use_airtunes=$enableval],
  [use_airtunes=auto])

AC_ARG_ENABLE([upnp],
  [AS_HELP_STRING([--disable-upnp],
  [disable UPnP support (default is enabled)])],
  [use_upnp=$enableval],
  [use_upnp=yes])

AC_ARG_ENABLE([ffmpeg_libvorbis],
  [AS_HELP_STRING([--enable-ffmpeg-libvorbis],
  [enable FFmpeg vorbis encoding (default is no)])],
  [use_ffmpeg_libvorbis=$enableval],
  [use_ffmpeg_libvorbis=no])

AC_ARG_ENABLE([dvdcss],
  [AS_HELP_STRING([--enable-dvdcss],
  [enable DVDCSS support (default is yes)])],
  [use_dvdcss=$enableval],
  [use_dvdcss=yes])

AC_ARG_ENABLE([mid],
  [AS_HELP_STRING([--enable-mid],
  [enable MID support (default is no)])],
  [use_mid=$enableval],
  [use_mid=no])

AC_ARG_ENABLE([hal],
  [AS_HELP_STRING([--disable-hal],
  [disable HAL support (default is enabled if hal and hal-storage is found)])],
  [use_hal=$enableval],
  [use_hal=yes])

AC_ARG_ENABLE([avahi],
  [AS_HELP_STRING([--disable-avahi],
  [disable Avahi support (default is enabled if libavahi-common and libavahi-client is found)])],
  [use_avahi=$enableval],
  [use_avahi=yes])
  
  AC_ARG_ENABLE([mdnsembedded],
  [AS_HELP_STRING([--disable-mdnsembedded],
  [disable mDNSEmbedded support (default is auto)])],
  [use_mdnsembedded=$enableval],
  [use_mdnsembedded=auto])

AC_ARG_ENABLE([non-free],
  [AS_HELP_STRING([--disable-non-free],
  [disable componentents with non-compliant licenses])],
  [use_nonfree=$enableval],
  [use_nonfree=yes])

AC_ARG_ENABLE([asap-codec],
  [AS_HELP_STRING([--enable-asap-codec],
  [enable ASAP ADPCM support])],
  [use_asap=$enableval],
  [use_asap=no])

AC_ARG_ENABLE([mysql],
  [AS_HELP_STRING([--disable-mysql],
  [disable mysql])],
  [use_mysql=$enableval],
  [use_mysql=yes])

AC_ARG_ENABLE([webserver],
  [AS_HELP_STRING([--disable-webserver],
  [disable webserver])],
  [use_webserver=$enableval],
  [use_webserver=yes])

AC_ARG_ENABLE([optical-drive],
  [AS_HELP_STRING([--disable-optical-drive],
  [disable optical drive])],
  [use_optical_drive=$enableval],
  [use_optical_drive=yes])

AC_ARG_ENABLE([libbluray],
  [AS_HELP_STRING([--enable-libbluray],
  [enable libbluray support])],
  [use_libbluray=$enableval],
  [use_libbluray=auto])

AC_ARG_ENABLE([texturepacker],
  [AS_HELP_STRING([--enable-texturepacker],
  [enable texturepacker support (default is yes)])],
  [use_texturepacker=$enableval],
  [use_texturepacker=auto])

AC_ARG_WITH([lirc-device],
  [AS_HELP_STRING([--with-lirc-device=file],
  [specify the default LIRC device (default is /dev/lircd)])],
  [lirc_device=$withval],
  [lirc_device=/dev/lircd])
AC_DEFINE_UNQUOTED([LIRC_DEVICE], ["$lirc_device"], [Default LIRC device])

AC_ARG_ENABLE([udev],
  [AS_HELP_STRING([--enable-udev],
  [enable udev support (default is auto)])],
  [use_libudev=$enableval],
  [use_libudev=auto])

AC_ARG_ENABLE([libusb],
  [AS_HELP_STRING([--enable-libusb],
  [enable libusb support (default is auto)])],
  [use_libusb=$enableval],
  [use_libusb=auto])

AC_ARG_ENABLE([libcec],
  [AS_HELP_STRING([--enable-libcec],
  [enable libcec support (default is auto)])],
  [use_libcec=$enableval],
  [use_libcec=auto])

AC_ARG_ENABLE([libmp3lame],
  [AS_HELP_STRING([--enable-libmp3lame],
  [enable lame mp3 encoder support (default is auto)])],
  [use_libmp3lame=$enableval],
  [use_libmp3lame=auto])

AC_ARG_ENABLE([libvorbisenc],
  [AS_HELP_STRING([--enable-libvorbisenc],
  [enable vorbis encoder support (default is auto)])],
  [use_libvorbisenc=$enableval],
  [use_libvorbisenc=auto])

AC_ARG_ENABLE([libcap],
  [AS_HELP_STRING([--enable-libcap],
  [enable libcap support (default is auto)])],
  [use_libcap=$enableval],
  [use_libcap=auto])

AC_ARG_ENABLE([player],
  [AS_HELP_STRING([--enable-player],
  [enable additional players from a list of comma separated names, (default is none, choices are omxplayer)])],
  [add_players=$enableval],
  [add_players=no])

AC_ARG_ENABLE([gtest],
  [AS_HELP_STRING([--enable-gtest],
  [configure Google Test Framework (default is no)])],
  [configure_gtest=$enableval],
  [configure_gtest=no])

AC_ARG_ENABLE([codec],
  [AS_HELP_STRING([--enable-codec],
  [enable additional codecs from a list of comma separated names, (default is none, choices are amcodec, libstagefright)])],
  [add_codecs=$enableval],
  [add_codecs=no])

### External libraries options
AC_ARG_ENABLE([external-libraries],
  [AS_HELP_STRING([--enable-external-libraries],
  [enable use of all supported external libraries (default is no) 'Linux only'])],
  [use_external_libraries=$enableval],
  [use_external_libraries=no])

AC_ARG_ENABLE([libav-compat],
  [AS_HELP_STRING([--enable-libav-compat],
  [build a wrapper around libav to provide the functions needed by XBMC. This is
   *not* supported by XBMC developers and is provided only for convenience. (default is no) 'Linux only'])],
  [use_libav_hacks=$enableval],
  [use_libav_hacks=no])

### End of external library options

if test "x$host_vendor" != "xapple"; then
  DEFAULT_COMPILE_FLAGS="-fPIC -DPIC -D_REENTRANT"
  DEFAULT_COMPILE_FLAGS="$DEFAULT_COMPILE_FLAGS -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
fi

# Checks for programs.
PASSED_CFLAGS=$CFLAGS # Hack to override autoconf default values
AC_PROG_CC
AX_PROG_CC_FOR_BUILD
CFLAGS="$PASSED_CFLAGS $DEFAULT_COMPILE_FLAGS"
PASSED_CXXFLAGS=$CXXFLAGS # Hack to override autoconf default values
AC_PROG_CXX
AX_PROG_CXX_FOR_BUILD
CXXFLAGS="$PASSED_CXXFLAGS $DEFAULT_COMPILE_FLAGS"
AC_PROG_LIBTOOL
AC_PROG_AWK
AC_PROG_LN_S
AC_PROG_MAKE_SET
PKG_PROG_PKG_CONFIG
MAKE="${MAKE:-make}"
OBJDUMP="${OBJDUMP:-objdump}"

use_external_ffmpeg=no
use_static_ffmpeg=no

# ffmpeg needs the output of uname -s (e.x. linux, darwin) for the target_os
# there is no autoconf variable which will give
# the correct output format when doing cross compilation
# so we have to use our own var here
# defaults to the build side target_os
# and should be overridden for cross below (see android)
ffmpeg_target_os=$(tolower $(uname -s))

# host detection and setup
case $host in
  i*86*-linux-android*)
     target_platform=target_android
     ARCH="i486-linux"
     use_arch="x86"
     use_cpu="i686"
     ffmpeg_target_os=linux
     use_joystick=no
     use_gles=yes
     use_optical_drive=no
     use_sdl=no
     use_x11=no
     build_shared_lib=yes    
     ;;
  i*86*-linux-gnu*|i*86*-*-linux-uclibc*)
     ARCH="i486-linux"
     if test "$use_cpu" = "no" -a "$cross_compiling" = "yes";  then
        use_arch="x86"
        use_cpu="i686"
     fi
     use_static_ffmpeg=yes
     ;;
  x86_64-*-linux-gnu*|x86_64-*-linux-uclibc*)
     ARCH="x86_64-linux"
     if test "$use_cpu" = "no" -a "$cross_compiling" = "yes";  then
        use_arch="x86_64"
        use_cpu="x86_64"
     fi
     use_static_ffmpeg=yes
     ;;
  i386-*-freebsd*)
     ARCH="x86-freebsd"
     MAKE="gmake"
     ;;
  amd64-*-freebsd*)
     ARCH="x86_64-freebsd"
     MAKE="gmake"
     ;;
  arm-apple-darwin*)
     use_joystick=no
     use_neon=yes
     use_libcec=no
     use_crystalhd=no
     use_vtbdecoder=yes
     use_optical_drive=no
     use_dvdcss=no
     use_gles=yes
     use_cpu=cortex-a8
     ARCH="arm-osx"
     use_arch="arm"
     PYTHON_VERSION="2.6"
     PYTHON_LDFLAGS="-L${prefix}/lib -lpython2.6"
     PYTHON_CPPFLAGS="-I${prefix}/include/python2.6"
     PYTHON_SITE_PKG="${prefix}/lib/python2.6/site-packages"
     PYTHON_NOVERSIONCHECK="no-check"
     ;;
  *86*-apple-darwin*)
     use_joystick=no
     use_vtbdecoder=no
     ARCH="x86-osx"
     ;;
  powerpc-apple-darwin*)
     use_joystick=no
     use_vtbdecoder=no
     use_crystalhd=no
     ARCH="powerpc-osx"
     use_arch="ppc"
     ;;
  powerpc-*-linux-gnu*|powerpc-*-linux-uclibc*)
     ARCH="powerpc-linux"
     ;;
  powerpc64-*-linux-gnu*|powerpc64-*-linux-uclibc*)
     ARCH="powerpc64-linux"
     ;;
  arm*-*-linux-gnu*|arm*-*-linux-uclibc*)
     ARCH="arm"
     use_arch="arm"
     ffmpeg_target_os=linux
     use_joystick=no
     use_neon=yes
     use_gles=yes
     use_sdl=no
     use_x11=no
     use_wayland=no
     use_static_ffmpeg=yes
     ;;
  arm*-*linux-android*)
     target_platform=target_android
     use_arch="arm"
     use_cpu=cortex-a9
     ARCH="arm"
     ffmpeg_target_os=linux
     use_joystick=no
     use_neon=yes
     use_gles=yes
     use_optical_drive=no
     use_sdl=no
     use_x11=no
     use_wayland=no
     build_shared_lib=yes
     ;;
  *)
     AC_MSG_ERROR(unsupported host ($host))
esac
AC_SUBST([ARCH])

check_sdl_arch=[`file $NATIVE_ROOT/lib/libSDL_image.dylib | awk '{print $NF}'`]
if test "x$check_sdl_arch" = "xi386" ; then
  DARWIN_NATIVE_ARCH=-m32
elif test "x$check_sdl_arch" = "xx86_64" ; then
  DARWIN_NATIVE_ARCH=-m64
fi
AC_SUBST([DARWIN_NATIVE_ARCH])

if test "$target_platform" = "target_android" ; then
  USE_ANDROID=1
  webserver_checkdepends=yes
  CFLAGS="$CFLAGS -Wno-psabi"
  DROID_DVDLIB_SEEK64="-D_FILE_OFFSET_BITS=64 -D_OFF_T_DEFINED_ -Doff_t=off64_t -Dlseek=lseek64"
  CXXFLAGS="$CXXFLAGS -Wno-psabi"
  AC_DEFINE(HAS_EGLGLES, [1], [Define if supporting EGL based GLES Framebuffer])
fi

case $use_platform in
  raspberry-pi)
     target_platform=target_raspberry_pi
     use_neon=no
     use_arch="arm"
     use_cpu=arm1176jzf-s
     use_hardcoded_tables="yes"
     use_alsa="no"
     ARCH="arm"
     AC_DEFINE(HAS_EGLGLES, [1], [Define if supporting EGL based GLES Framebuffer])
     USE_OMXLIB=1; AC_DEFINE([HAVE_OMXLIB],[1],["Define to 1 if OMX libs is enabled"])
     CFLAGS="$CFLAGS"
     CXXFLAGS="$CXXFLAGS"
     ffmpeg_target_os=linux
     ;;
esac

XBMC_SETUP_ARCH_DEFINES()

# check for GIT_REV
AC_CHECK_PROG(HAVE_GIT,git,"yes","no",)
if test "$GIT_REV" = ""; then
  if test -f VERSION ; then
    GIT_REV=$(awk 'END{print substr($1,1,16)}' VERSION)
  elif test "$HAVE_GIT" = "yes" -a -d ${abs_top_srcdir}/.git; then
    GIT_REV=$(git --no-pager log --abbrev=7 -n 1 --pretty=format:"%h %ci" HEAD | awk '{gsub("-", "");print $2"-"$1}')
  else
    GIT_REV="Unknown"
  fi
fi
final_message="$final_message\n  git Rev.:\t${GIT_REV}"

if test "$host_vendor" = "apple"; then
  echo "#define GIT_REV \"$GIT_REV\"" > git_revision.h
else
  SDL_DEFINES="$SDL_DEFINES -D'GIT_REV=\"$GIT_REV\"'"
fi

if test "$build_shared_lib" = "yes"; then
  final_message="$final_message\n Shared lib\tYes"
  AC_SUBST(USE_LIBXBMC,1)
fi


# platform debug flags
if test "$use_debug" = "yes"; then
  final_message="$final_message\n  Debugging:\tYes"
  if test "$use_profiling" = "yes"; then
    final_message="$final_message\n  Profiling:\tYes"
    DEBUG_FLAGS="-g -pg -D_DEBUG -Wall"
  else
    final_message="$final_message\n  Profiling:\tNo"
    DEBUG_FLAGS="-g -D_DEBUG -Wall"
  fi
else
  final_message="$final_message\n  Debugging:\tNo"
  if test "$use_profiling" = "yes"; then
    final_message="$final_message\n  Profiling:\tYes"
    DEBUG_FLAGS="-pg -DNDEBUG=1"
  else
    final_message="$final_message\n  Profiling:\tNo"
    DEBUG_FLAGS="-DNDEBUG=1"
  fi
fi
CFLAGS="$CFLAGS $DEBUG_FLAGS"
CXXFLAGS="$CXXFLAGS $DEBUG_FLAGS"


if test "$use_optimizations" = "yes"; then
  final_message="$final_message\n  Optimization:\tYes"
  if test "$target_platform" = "target_raspberry_pi"; then
    CXXFLAGS="$CXXFLAGS"
    CFLAGS="$CFLAGS"
  else
    CXXFLAGS="-O2 $CXXFLAGS"
    CFLAGS="-O2 $CFLAGS"
  fi
else
  final_message="$final_message\n  Optimization:\tNo"
fi


# platform specific flags
if echo "$ARCH" | grep -q "freebsd" ; then
  LOCALBASE="${LOCALBASE:-/usr/local}"
  CFLAGS="$CFLAGS -I$LOCALBASE/include"
  CXXFLAGS="$CXXFLAGS -I$LOCALBASE/include"
  CPPFLAGS="$CPPFLAGS -I$LOCALBASE/include"
  LDFLAGS="$LDFLAGS -L$LOCALBASE/lib"
  FFMPEG_EXTRACFLAGS="-I$LOCALBASE/include"
fi
if test "$host_vendor" = "apple" ; then
  # standard xbmc paths
  INCLUDES="$INCLUDES -I\$(abs_top_srcdir)/xbmc/osx"
  if test "$use_arch" != "arm"; then
    LIBS="$LIBS -framework ApplicationServices"
    LIBS="$LIBS -framework AudioUnit"
    LIBS="$LIBS -framework AudioToolbox"
    LIBS="$LIBS -framework Cocoa"
    LIBS="$LIBS -framework CoreAudio"
    LIBS="$LIBS -framework CoreVideo"
    LIBS="$LIBS -framework CoreServices"
    LIBS="$LIBS -framework CoreFoundation"
    LIBS="$LIBS -framework DiskArbitration"
    LIBS="$LIBS -framework IOKit"
    LIBS="$LIBS -framework IOSurface"
    LIBS="$LIBS -framework QuartzCore"
    LIBS="$LIBS -framework SystemConfiguration"
    LIBS="$LIBS -framework VideoDecodeAcceleration"
  fi
  USE_EXTERNAL_FFMPEG=1
elif test "$target_platform" = "target_raspberry_pi"; then
  ARCH="arm"
  use_arch="arm"
elif test "$use_arch" = "arm"; then
  CFLAGS="$CFLAGS -mno-apcs-stack-check"
  CXXFLAGS="$CXXFLAGS -mno-apcs-stack-check"
  FFMPEG_EXTRACFLAGS=""
  if test "$use_tegra" = "yes"; then
    # Compile for ARMv7a architecture, need to test gcc for vfpv3-d16 support 
    SAVE_CFLAGS="$CFLAGS"
    CFLAGS="-mfpu=vfpv3-d16"
    AC_COMPILE_IFELSE(
      [AC_LANG_SOURCE([int foo;])],
      [ CFLAGS="$SAVE_CFLAGS -Wno-psabi -Wa,-march=armv7a -mtune=cortex-a9 -mfpu=vfpv3-d16 -mthumb-interwork"
        CXXFLAGS="$CXXFLAGS -Wno-psabi -Wa,-march=armv7a -mtune=cortex-a9 -mfpu=vfpv3-d16 -mthumb-interwork"
        FFMPEG_EXTRACFLAGS="$FFMPEG_EXTRACFLAGS -mtune=cortex-a9 -mfpu=vfpv3-d16"
        use_cpu=cortex-a9],
      [ CFLAGS="$SAVE_CFLAGS -Wa,-march=armv6 -mtune=cortex-a8 -mthumb-interwork"
        CXXFLAGS="$CXXFLAGS -Wa,-march=armv6 -mtune=cortex-a8 -mthumb-interwork"    
        use_cpu=cortex-a8])
  else
    if test "$use_neon" = "yes"; then 
      CFLAGS="$CFLAGS -mfpu=neon -mvectorize-with-neon-quad"
      CXXFLAGS="$CXXFLAGS -mfpu=neon -mvectorize-with-neon-quad"
      FFMPEG_EXTRACFLAGS="$FFMPEG_EXTRACFLAGS -mfpu=neon"
    fi
  fi
fi
if test "$use_static_ffmpeg" = "yes"; then
  USE_STATIC_FFMPEG=1
  AC_DEFINE([USE_STATIC_FFMPEG], [1], [link ffmpeg statically])
  # ffmpeg may depend on gnutls and vorbisenc, we add those libs at the end of linker
  # command in order to resolve any missing symbols
  GNUTLS_ALL_LIBS=`${PKG_CONFIG} --static --libs-only-l --silence-errors gnutls`
  VORBISENC_ALL_LIBS=`${PKG_CONFIG} --static --libs-only-l --silence-errors vorbisenc`
fi 

# Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_CHOWN
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_ERROR_AT_LINE
AC_FUNC_FSEEKO
AC_PROG_GCC_TRADITIONAL
AC_FUNC_LSTAT
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
AC_FUNC_MEMCMP
AC_FUNC_MKTIME
AC_FUNC_MMAP
# Boxee is apparently having compile problems
# if HAVE_REALLOC is defined.  Sort this later.
#AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_SETVBUF_REVERSED
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_FUNC_STRCOLL
AC_FUNC_STRFTIME
AC_FUNC_STRTOD
AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([atexit dup2 fdatasync floor fs_stat_dev ftime ftruncate getcwd gethostbyaddr gethostbyname gethostname getpagesize getpass gettimeofday inet_ntoa lchown localeconv memchr memmove memset mkdir modf munmap pow rmdir select setenv setlocale socket sqrt strcasecmp strchr strcspn strdup strerror strncasecmp strpbrk strrchr strspn strstr strtol strtoul sysinfo tzset utime posix_fadvise])

# Check for various sizes
AC_CHECK_SIZEOF([int])
AC_CHECK_SIZEOF([size_t])

# Check for intrinsics
AC_MSG_CHECKING([for __sync_add_and_fetch(temp, 1)])
AC_TRY_LINK([],[long* temp=0; long ret=__sync_add_and_fetch(temp, 1);],
                [have_builtin_sync_add_and_fetch=yes],
                [have_builtin_sync_add_and_fetch=no])
AC_MSG_RESULT($have_builtin_sync_add_and_fetch)
if test "x$have_builtin_sync_add_and_fetch" = "xyes"; then
    AC_DEFINE(HAS_BUILTIN_SYNC_ADD_AND_FETCH, 1,
        [Define to 1 if your compiler supports the __sync_add_and_fetch() intrinsic.])
fi

AC_MSG_CHECKING([for __sync_sub_and_fetch(temp, 1)])
AC_TRY_LINK([],[long* temp=0; long ret=__sync_sub_and_fetch(temp, 1);],
                [have_builtin_sync_sub_and_fetch=yes],
                [have_builtin_sync_sub_and_fetch=no])
AC_MSG_RESULT($have_builtin_sync_sub_and_fetch)
if test "x$have_builtin_sync_sub_and_fetch" = "xyes"; then
    AC_DEFINE(HAS_BUILTIN_SYNC_SUB_AND_FETCH, 1,
        [Define to 1 if your compiler supports the __sync_sub_and_fetch() intrinsic.])
fi

AC_MSG_CHECKING([for __sync_val_compare_and_swap(temp, 1, 1)])
AC_TRY_LINK([],[long *temp = 0; long ret=__sync_val_compare_and_swap(temp, 1, 1);],
                [have_builtin_sync_val_compare_and_swap=yes],
                [have_builtin_sync_val_compare_and_swap=no])
AC_MSG_RESULT($have_builtin_sync_val_compare_and_swap)
if test "x$have_builtin_sync_val_compare_and_swap" = "xyes"; then
    AC_DEFINE(HAS_BUILTIN_SYNC_VAL_COMPARE_AND_SWAP, 1,
        [Define to 1 if your compiler supports the __sync_val_compare_and_swap() intrinsic.])
fi

# Check for u16string/u32string declarations
AC_LANG_PUSH([C++])
AC_CHECK_TYPES([std::u16string, std::u32string], [], [], [[#include <string>]])
AC_CHECK_TYPES([char16_t, char32_t])
AC_CHECK_SIZEOF([wchar_t])
AC_LANG_POP([C++])

# Add top source directory for all builds so we can use config.h
INCLUDES="-I\$(abs_top_srcdir) $INCLUDES" 

# Check inotify availability
AC_CHECK_HEADER([sys/inotify.h], AC_DEFINE([HAVE_INOTIFY],[1],[Define if we have inotify]),)

# Checks for boost headers using CXX instead of CC
AC_LANG_PUSH([C++])
AC_CHECK_HEADER([boost/shared_ptr.hpp],, AC_MSG_ERROR($missing_library))
AC_LANG_POP([C++])

# Python
if test -z "$PYTHON_NOVERSIONCHECK"; then
  AX_PYTHON_DEVEL([>= 2.4])
  PYTHON_VERSION=$ac_python_version
fi

if test -z "$PYTHON_VERSION"; then
  AC_MSG_ERROR([Can't find a Python version.])
else
  LIBS="$LIBS $PYTHON_LDFLAGS"
  AC_MSG_NOTICE([Using Python $PYTHON_VERSION])
fi

# Wayland
if test "$use_wayland" = "yes" && test "$host_vendor" != "apple"; then
  AC_MSG_NOTICE($wayland_enabled)
  PKG_CHECK_MODULES([WAYLAND_CLIENT],    [wayland-client],
    [INCLUDES="$INCLUDES $WAYLAND_CLIENT_CFLAGS";
     WAYLAND_CLIENT_LIBRARY_LINE=`LIBRARY=\`${PKG_CONFIG} --libs-only-l wayland-client\`; echo ${LIBRARY:2}`;
     XB_FIND_SONAME([WAYLAND_CLIENT_LIBRARY], ${WAYLAND_CLIENT_LIBRARY_LINE})],
     AC_MSG_ERROR($missing_library))
  PKG_CHECK_MODULES([WAYLAND_EGL],    [wayland-egl],
    [INCLUDES="$INCLUDES $WAYLAND_EGL_CFLAGS";
     WAYLAND_EGL_LIBRARY_LINE=`LIBRARY=\`${PKG_CONFIG} --libs-only-l wayland-egl\`; echo ${LIBRARY:2:11}`
     XB_FIND_SONAME([WAYLAND_EGL_LIBRARY], ${WAYLAND_EGL_LIBRARY_LINE})],
    AC_MSG_ERROR($missing_library))
  PKG_CHECK_MODULES([XKBCOMMON],    [xkbcommon],
    [INCLUDES="$INCLUDES $XKBCOMMON_CFLAGS";
     XKBCOMMON_LIBRARY_LINE=`LIBRARY=\`${PKG_CONFIG} --libs-only-l xkbcommon\`; echo ${LIBRARY:2}`;
     XB_FIND_SONAME([XKBCOMMON_LIBRARY], $XKBCOMMON_LIBRARY_LINE)],
    AC_MSG_ERROR($missing_library))
  AC_DEFINE([HAVE_WAYLAND], [1], [Define to 1 if you have Wayland libs installed.])
  AC_DEFINE([HAVE_XKBCOMMON], [1], [Define to 1 if you have libxkbcommon installed.])

  # If we are also building with tests then we want to build
  # wayland tests as well
  if test "$configure_gtest" = "yes"; then
    have_weston_sdk=no;
    PKG_CHECK_MODULES([PIXMAN],
                      [pixman-1],have_pixman=yes,
                      [AC_MSG_WARN($missing_library); have_pixman=no])
    PKG_CHECK_MODULES([WESTON],
                      [weston >= 1.1.90],[have_weston_sdk=yes],
                      [have_weston_sdk=no; AC_MSG_WARN($missing_library)])

    AC_CHECK_PROG(WAYLAND_SCANNER, wayland-scanner, "wayland-scanner", "no")
    if test "x$WAYLAND_SCANNER" == "xno"; then
      AC_MSG_WARN($missing_program)
    else
      if test "x$have_weston_sdk" == "xyes" && test "x$have_pixman" = "xyes"; then
        AC_SUBST(WAYLAND_TEST_INCLUDES,"$WAYLAND_CLIENT_CFLAGS $XKBCOMMON_CFLAGS $PIXMAN_CFLAGS $WESTON_CFLAGS")
        AC_SUBST(WAYLAND_TEST_LIBS,"$WAYLAND_CLIENT_LIBS $XKBCOMMON_LIBS $PIXMAN_LIBS $WESTON_LIBS")
        AC_DEFINE([HAVE_WESTON_SDK], [1], [Define to 1 if Weston SDK is installed.])
        AC_SUBST(USE_WAYLAND_TEST_EXTENSION, 1)
      fi
      AC_SUBST(WAYLAND_SCANNER)
      AC_DEFINE([HAVE_WAYLAND_XBMC_PROTO],[1],["Define to 1 if the wayland test-protocol will be built"])
    fi
  fi

  # Disable SDL and X11 builds
  use_sdl=no
  use_joystick=no
  use_x11=no

  # Wayland requires the EGL "window system" which in turn only supports
  # the OpenGL ES API, so enable gles support
  use_gles=yes
else
  AC_MSG_RESULT($wayland_disabled)
fi

# Checks for platforms libraries.
if test "$use_gles" = "yes"; then
  use_gl="no"
  # GLES overwrites GL if both set to yes.
  if test "$host_vendor" = "apple" ; then
    AC_DEFINE([HAVE_LIBEGL],[1],["Define to 1 if you have the `EGL' library (-lEGL)."])
    AC_DEFINE([HAVE_LIBGLESV2],[1],["Define to 1 if you have the `GLESv2' library (-lGLESv2)."])
    AC_MSG_RESULT(== WARNING: OpenGLES support is assumed.)
  else
    if test "$target_platform" = "target_raspberry_pi"; then
      AC_DEFINE([HAVE_LIBEGL],[1],["Define to 1 if you have the `EGL' library (-lEGL)."])
      AC_DEFINE([HAVE_LIBGLESV2],[1],["Define to 1 if you have the `GLESv2' library (-lGLESv2)."])
      AC_MSG_RESULT(== WARNING: OpenGLES support is assumed.)
      LIBS="$LIBS -lEGL -lGLESv2 -lbcm_host -lvcos -lvchiq_arm"
    else
      AC_CHECK_LIB([EGL],   [main],, AC_MSG_ERROR($missing_library))
      AC_CHECK_LIB([GLESv2],[main],, AC_MSG_ERROR($missing_library))
    fi
  fi
else
  if test "$use_gl" = "yes"; then
    if test "$host_vendor" = "apple" ; then
      # linking to OpenGL.framework instead of libGL, libGLU so AC_CHECK_LIB will fail
      LIBS="$LIBS -framework OpenGL"
      AC_DEFINE([HAVE_LIBGL],[1],["Define to 1 if you have the `GL' library (-lGL)."])
      AC_MSG_RESULT(== WARNING: OpenGL support is assumed.)
      AC_DEFINE([HAVE_LIBGLU],[1],["Define to 1 if you have the `GLU' library (-lGLU)."])
      AC_MSG_RESULT(== WARNING: OpenGLU support is assumed.)
      AC_CHECK_LIB([GLEW],[main],, AC_MSG_ERROR($missing_library))
    else
      AC_CHECK_LIB([GL],  [main],, AC_MSG_ERROR($missing_library))
      AC_CHECK_LIB([GLEW],[main],, AC_MSG_ERROR($missing_library))
      AC_CHECK_LIB([GLU], [main],, AC_MSG_ERROR($missing_library))
    fi
  else
    AC_MSG_RESULT(== WARNING: OpenGL support is disabled. XBMC will run VERY slow. ==)
    AC_CHECK_LIB([SDL_gfx],[main])
  fi
fi

# platform common libraries
if test "$use_mysql" = "yes"; then
  AC_PATH_PROG(MYSQL_CONFIG, mysql_config,"no")
  if test "x$MYSQL_CONFIG" != "xno"; then
    AC_DEFINE([HAVE_MYSQL],[1],["Define to 1 if you have the `mysql' library (-lmysqlclient)."])
    INCLUDES="$INCLUDES `$MYSQL_CONFIG --include`"
    MYSQL_LIBS=`$MYSQL_CONFIG --libs`
    LIBS="$LIBS $MYSQL_LIBS"
    AC_SUBST(MYSQL_LIBS)
  else
    AC_MSG_ERROR($missing_program)
  fi
fi
AC_CHECK_HEADER([ass/ass.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([mpeg2dec/mpeg2.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([mpeg2dec/mpeg2convert.h],, AC_MSG_ERROR($missing_library),
  AC_INCLUDES_DEFAULT()
  [#include <mpeg2dec/mpeg2.h>])
AC_CHECK_HEADER([mad.h],,            AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([jpeglib.h],,        AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([samplerate.h],,     AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([ogg/ogg.h],,        AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([vorbis/vorbisfile.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([libmodplug/modplug.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([curl/curl.h],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([FLAC/stream_decoder.h],, AC_MSG_ERROR($missing_library))

# we need to check for the header because if it exists we set the openssl
# and gcrypt MT callback hooks. This is mostly so that libcurl operates 
# in MT manner correctly.
AC_MSG_CHECKING([for CRYPTO_set_locking_callback(0)])
AC_TRY_LINK([],[CRYPTO_set_locking_callback(0);],
                [have_curl_static=yes],
                [have_curl_static=no])
AC_MSG_RESULT($have_curl_static)
AC_CHECK_HEADER([openssl/crypto.h], AC_DEFINE([HAVE_OPENSSL],[1],[Define if we have openssl]),)
AC_CHECK_HEADER([gcrypt.h], gcrypt_headers_available=yes,gcrypt_headers_available=no)
if test "$gcrypt_headers_available" = "yes"; then
   # if we have the headers then we must have the lib
   AC_CHECK_LIB([gpg-error],[main],, AC_MSG_ERROR($missing_library))
   AC_CHECK_LIB([gcrypt],[gcry_control],, AC_MSG_ERROR($missing_library))
   AC_DEFINE([HAVE_GCRYPT],[1],[Define if we have gcrypt])
fi
PKG_CHECK_MODULES([GNUTLS], [gnutls], [have_gnutls=yes];AC_DEFINE([HAVE_GNUTLS], [1], [Define if we have gnutls]), AC_MSG_WARN("gnutls not found, ffmpeg TLS support disabled"))

AC_CHECK_LIB([bz2],         [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([jpeg],        [main],, AC_MSG_ERROR($missing_library)) # check for cximage
AC_CHECK_LIB([tiff],        [main],, AC_MSG_ERROR($missing_library))
if echo "$ARCH" | grep -q freebsd; then
AC_CHECK_LIB([pthread],     [main],LIBS="-pthread $LIBS", AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([pthread],     [pthread_set_name_np],
  AC_DEFINE([HAVE_PTHREAD_SET_NAME_NP],[1],["Define to 1 if pthread has pthread_set_name_np"]),
  AC_MSG_RESULT([Could not find pthread_set_name_np in pthread]))
else
if test "$target_platform" != "target_android" ; then
  AC_CHECK_LIB([pthread],     [main],, AC_MSG_ERROR($missing_library))
  AC_CHECK_LIB([pthread],     [pthread_setname_np],
    AC_DEFINE([HAVE_PTHREAD_SETNAME_NP],[1],["Define to 1 if pthread has pthread_setname_np"]),
    AC_MSG_RESULT([Could not find pthread_setname_np in pthread]))
fi
fi
AC_CHECK_LIB([lzo2],        [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([z],           [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([crypto],      [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([ssl],         [main],, AC_MSG_ERROR($missing_library))
if test "$use_mysql" = "yes"; then
  AC_CHECK_LIB([mysqlclient], [main],, AC_MSG_ERROR($missing_library))
fi
AC_CHECK_LIB([bluetooth],   [hci_devid],, AC_MSG_RESULT([Could not find suitable version of libbluetooth]))
AC_CHECK_LIB([yajl],        [main],, AC_MSG_ERROR($missing_library))
AC_CHECK_LIB([tinyxml],     [main],, AC_MSG_ERROR($missing_library))
if test "$target_platform" = "target_android" ; then
  AC_CHECK_LIB([android],     [main],, AC_MSG_ERROR($missing_library))
  AC_CHECK_LIB([log],         [__android_log_vprint],, AC_MSG_ERROR($missing_library))
  AC_CHECK_LIB([jnigraphics],     [main],, AC_MSG_ERROR($missing_library))
fi
PKG_CHECK_MODULES([LIBXML], [libxml-2.0],
  [INCLUDES="$INCLUDES $LIBXML_CFLAGS"; LIBS="$LIBS $LIBXML_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([LIBXSLT], [libxslt],
  [INCLUDES="$INCLUDES $LIBXSLT_CFLAGS"; LIBS="$LIBS $LIBXSLT_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([FRIBIDI],    [fribidi],
  [INCLUDES="$INCLUDES $FRIBIDI_CFLAGS"; LIBS="$LIBS $FRIBIDI_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([SQLITE3],    [sqlite3],
  [INCLUDES="$INCLUDES $SQLITE3_CFLAGS"; LIBS="$LIBS $SQLITE3_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([PNG],        [libpng],
  [INCLUDES="$INCLUDES $PNG_CFLAGS"; LIBS="$LIBS $PNG_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([PCRECPP],    [libpcrecpp],
  [INCLUDES="$INCLUDES $PCRECPP_CFLAGS"; LIBS="$LIBS $PCRECPP_LIBS"]; \
  AC_DEFINE([HAVE_LIBPCRECPP],[1],["Define to 1 if libpcrecpp is installed"]),
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([PCRE],       [libpcre],
  [INCLUDES="$INCLUDES $PCRE_CFLAGS"; LIBS="$LIBS $PCRE_LIBS"]; \
  AC_DEFINE([HAVE_LIBPCRE],[1],["Define to 1 if libpcre is installed"]),
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([SAMPLERATE], [samplerate],
  [INCLUDES="$INCLUDES $SAMPLERATE_CFLAGS"; LIBS="$LIBS $SAMPLERATE_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([FREETYPE2],  [freetype2],
  [INCLUDES="$INCLUDES $FREETYPE2_CFLAGS"; LIBS="$LIBS $FREETYPE2_LIBS"],
  AC_MSG_ERROR($missing_library))
PKG_CHECK_MODULES([TAGLIB],  [taglib >= 1.8],
  [INCLUDES="$INCLUDES $TAGLIB_CFLAGS"; LIBS="$LIBS $TAGLIB_LIBS"],
  AC_MSG_ERROR($missing_library))

if test "$use_optical_drive" = "yes"; then
  PKG_CHECK_MODULES([CDIO],       [libcdio],
    [INCLUDES="$INCLUDES $CDIO_CFLAGS"; LIBS="$LIBS $CDIO_LIBS"],
    AC_MSG_ERROR($missing_library))
fi

if test "$target_platform" = "target_android" ; then
PKG_CHECK_MODULES([ZIP],       [libzip],
  [INCLUDES="$INCLUDES $ZIP_CFLAGS"; LIBS="$LIBS $ZIP_LIBS"],
  AC_MSG_ERROR($missing_library))
fi

# check for libbluray
AS_CASE([x$use_libbluray],
  [xyes],[
    PKG_CHECK_MODULES([LIBBLURAY],[libbluray >= 0.2.1],[use_libbluray="yes"], AC_MSG_ERROR($missing_library))
  ],
  [xauto],[
    PKG_CHECK_MODULES([LIBBLURAY],[libbluray >= 0.2.1],[use_libbluray="yes"], [use_libbluray="no"])
  ])

AS_CASE([x$use_libbluray],
  [xyes],[
    INCLUDES="$INCLUDES $LIBBLURAY_CFLAGS";
    XB_FIND_SONAME([BLURAY], [bluray], [use_libbluray])
    AC_DEFINE([HAVE_LIBBLURAY], 1, [System has libbluray library])
    AC_SUBST([HAVE_LIBBLURAY], 1)
    AC_CHECK_LIB([bluray], [bd_register_argb_overlay_proc],
      AC_CHECK_DECL([BD_EVENT_IDLE],
        AC_DEFINE([HAVE_LIBBLURAY_BDJ], 1, [System has libbluray library with bdj support]),,
        [[#include <libbluray/bluray.h>]]))
  ],[
    AC_SUBST([HAVE_LIBBLURAY], 0)
  ]
)

#Check to see if libs are needed for functions that are often built-in to libc
AC_SEARCH_LIBS([iconv_open],iconv,,AC_SEARCH_LIBS([libiconv_open],iconv,,AC_MSG_ERROR($missing_library)))
AC_SEARCH_LIBS([dlopen],dl)
AC_SEARCH_LIBS([clock_gettime],rt)
AC_SEARCH_LIBS([dn_expand],  resolv)
AC_SEARCH_LIBS([_dn_expand], resolv)
AC_SEARCH_LIBS([__dn_expand],resolv)

# platform dependent libraries
if test "$host_vendor" = "apple" ; then
  if test "$use_arch" != "arm"; then
    AC_CHECK_LIB([SDL],      [main],, AC_MSG_ERROR($missing_library))
    AC_DEFINE([HAVE_SDL],[1],["Define to 1 if using sdl"])
  fi
else
if test "$target_platform" != "target_android" ; then
  AC_CHECK_LIB([jasper],     [main],, AC_MSG_ERROR($missing_library)) # check for cximage
fi
if test "x$use_alsa" != "xno"; then
  PKG_CHECK_MODULES([ALSA],  [alsa],
    [INCLUDES="$INCLUDES $ALSA_CFLAGS"; LIBS="$LIBS $ALSA_LIBS"; use_alsa=yes],
    AC_MSG_NOTICE($alsa_not_found); use_alsa=no)
fi
  PKG_CHECK_MODULES([DBUS],    [dbus-1],
    [INCLUDES="$INCLUDES $DBUS_CFLAGS"; LIBS="$LIBS $DBUS_LIBS"; use_dbus=yes]; \
    AC_DEFINE([HAVE_DBUS],[1],["Define to 1 if dbus is installed"]),
    AC_MSG_NOTICE($missing_library); use_dbus=no)
  if test "x$use_sdl" != "xno"; then
    PKG_CHECK_MODULES([SDL],   [sdl],
      [INCLUDES="$INCLUDES $SDL_CFLAGS"; LIBS="$LIBS $SDL_LIBS"],
      AC_MSG_ERROR($missing_library))
    AC_CHECK_LIB([SDL_image],  [main],, AC_MSG_ERROR($missing_library))
    AC_DEFINE([HAVE_SDL],[1],["Define to 1 if using sdl"])
  fi
fi

XB_FIND_SONAME([MAD],         [mad])
XB_FIND_SONAME([OGG],         [ogg])
XB_FIND_SONAME([CURL],        [curl])
XB_FIND_SONAME([FLAC],        [FLAC])
XB_FIND_SONAME([VORBIS],      [vorbis])
XB_FIND_SONAME([VORBISFILE],  [vorbisfile])
XB_FIND_SONAME([MODPLUG],     [modplug])
XB_FIND_SONAME([ASS],         [ass])
XB_FIND_SONAME([MPEG2],       [mpeg2])

# Audio encoders
if test "x$use_libmp3lame" != "xno"; then
  XB_FIND_SONAME([LAMEENC], [mp3lame], [use_libmp3lame])
  if test "x$use_libmp3lame" != "xno"; then
    AC_CHECK_HEADER([lame/lame.h],, AC_MSG_ERROR($missing_headers))
  fi
fi
AS_CASE([x$use_libmp3lame],
  [xno],[
    AC_SUBST([HAVE_LIBMP3LAME], 0)
  ],
  [
    AC_DEFINE([HAVE_LIBMP3LAME], 1, [System has libmp3lame library])
    AC_SUBST([HAVE_LIBMP3LAME], 1)
  ]
)
if test "x$use_libvorbisenc" != "xno"; then
  XB_FIND_SONAME([VORBISENC], [vorbisenc], [use_libvorbisenc])
  if test "x$use_libvorbisenc" != "xno"; then
    AC_CHECK_HEADER([vorbis/vorbisenc.h],, AC_MSG_ERROR($missing_headers))
  fi
fi
AS_CASE([x$use_libvorbisenc],
  [xno],[
    AC_SUBST([HAVE_LIBVORBISENC], 0)
  ],[
    AC_DEFINE([HAVE_LIBVORBISENC], 1, [System has libvorbisenc library])
    AC_SUBST([HAVE_LIBVORBISENC], 1)
  ]
)

# WebServer
if test "$use_webserver" = "yes"; then
  AC_CHECK_LIB([microhttpd],  [main],, AC_MSG_ERROR($missing_library))
fi

# Optical
if test "$use_optical_drive" = "yes"; then
  AC_DEFINE([HAS_DVD_DRIVE], [1], [Define to 1 to have optical drive support])
fi

# Alsa
if test "$use_alsa" = "yes" && test "$host_vendor" != "apple"; then
  PKG_CHECK_MODULES([ALSA],  [alsa],
    [INCLUDES="$INCLUDES $ALSA_CFLAGS"; LIBS="$LIBS $ALSA_LIBS"],
    AC_MSG_ERROR($missing_library))
  AC_DEFINE([HAS_ALSA], [1], [Define to 0 to disable ALSA support])
else
  use_alsa="no"
  AC_MSG_RESULT($alsa_disabled)
fi

# PulseAudio
if test "x$use_pulse" != "xno"; then
  if test "$host_vendor" = "apple" ; then
    if test "x$use_pulse" = "xyes"; then
      AC_MSG_ERROR($pulse_disabled)
    else
      use_pulse="no"
      AC_MSG_RESULT($pulse_disabled)
    fi
    USE_PULSE=0
  else
    PKG_CHECK_MODULES([PULSE], [libpulse >= 1.0],
      [INCLUDES="$INCLUDES $PULSE_CFLAGS"; LIBS="$LIBS $PULSE_LIBS"; USE_PULSE=1;
        HAVE_LIBPULSE=1; AC_DEFINE([HAVE_LIBPULSE],[1],[Pulse audio enabled])],
      [pulse_found="no"; USE_PULSE=0; HAVE_LIBPULSE=0])

    if test "$pulse_found" = "no"; then
      if test "x$use_pulse" = "xyes"; then
        AC_MSG_ERROR($pulse_not_found)
      else
        AC_MSG_RESULT($pulse_disabled)
      fi
    fi
  fi
else
  AC_MSG_RESULT($pulse_disabled)
  USE_PULSE=0
fi

# HAL
if test "$host_vendor" = "apple" ; then
  use_hal="no"
  AC_MSG_RESULT($hal_disabled)
else
  if test "$use_hal" = "yes"; then
    PKG_CHECK_MODULES([HAL], [hal],
      [INCLUDES="$INCLUDES $HAL_CFLAGS"; LIBS="$LIBS $HAL_LIBS"],
      use_hal=no;AC_MSG_RESULT($hal_not_found))
    PKG_CHECK_MODULES([HAL_STORAGE], [hal-storage],
      [INCLUDES="$INCLUDES $HAL_STORAGE_CFLAGS"; LIBS="$LIBS $HAL_STORAGE_LIBS"],
      use_hal=no;AC_MSG_RESULT($halstorage_not_found))
  else
    AC_MSG_RESULT($hal_disabled)
  fi
  if test "$use_hal" = "yes"; then
    AC_DEFINE([HAS_HAL], [1], [Define to 1 if you have HAL installed])
  fi
fi

# avahi
if test "$host_vendor" = "apple" ; then
  use_avahi="no"
  AC_MSG_RESULT($avahi_disabled)
else
  if test "$use_avahi" = "yes"; then
    AC_CHECK_LIB([avahi-common], [main],,
      use_avahi=no;AC_MSG_RESULT($avahi_not_found))
    if test "$use_avahi" = "yes"; then
      #either both libs or none
      AC_CHECK_LIB([avahi-client], [main],,
        use_avahi=no;AC_MSG_RESULT($avahi_not_found))
    fi
  else
    AC_MSG_RESULT($avahi_disabled)
  fi
fi

# mdnsembedded
if test "$use_mdnsembedded" != "no"; then
  AC_CHECK_LIB([mDNSEmbedded], [embedded_mDNSInit],,
    [if test "$use_mdnsembedded" = "yes"; then
      AC_MSG_ERROR($mdnsembedded_not_found)
      USE_MDNSEMBEDDED=0
    elif test "$use_mdnsembedded" != "no"; then
      AC_MSG_NOTICE($mdnsembedded_not_found)
      use_mdnsembedded="no"
      USE_MDNSEMBEDDED=0
    fi
   ])
  if test $use_mdnsembedded != "no"; then
    USE_MDNSEMBEDDED=1
  fi
else
  AC_MSG_RESULT($mdnsembedded_disabled)
  USE_MDNSEMBEDDED=0
fi
AC_SUBST(USE_MDNSEMBEDDED)

# X11
if test "$use_x11" = "yes" && test "$host_vendor" != "apple"; then
  AC_MSG_NOTICE($x11_enabled)
  PKG_CHECK_MODULES([X11],    [x11],
    [INCLUDES="$INCLUDES $X11_CFLAGS"; LIBS="$LIBS $X11_LIBS"],
    AC_MSG_ERROR($missing_library))
  PKG_CHECK_MODULES([XEXT],  [xext],
    [INCLUDES="$INCLUDES $XEXT_CFLAGS"; LIBS="$LIBS $XEXT_LIBS"],
    AC_MSG_ERROR($missing_library))
  AC_DEFINE([HAVE_X11], [1], [Define to 1 if you have X11 libs installed.])
else
  AC_MSG_RESULT($x11_disabled)
fi

# XRandR
if test "$host_vendor" = "apple" || test "$use_x11" = "no"; then
  use_xrandr="no"
  AC_MSG_RESULT($xrandr_disabled)
else
  if test "$use_xrandr" = "yes" ; then
    AC_CHECK_LIB([Xrandr], [main],,
      use_xrandr="no";AC_MSG_RESULT($xrandr_not_found))
  else
    AC_MSG_RESULT($xrandr_disabled)
  fi
fi

# WAVEFORM
if test "$use_waveform" = "yes"; then
  AC_MSG_NOTICE($waveform_enabled)
    DISABLE_WAVEFORM=0
else
  AC_MSG_NOTICE($waveform_disabled)
  DISABLE_WAVEFORM=1
fi

# SPECTRUM
if test "$use_spectrum" = "yes"; then
  AC_MSG_NOTICE($spectrum_enabled)
    DISABLE_SPECTRUM=0
else
  AC_MSG_NOTICE($spectrum_disabled)
  DISABLE_SPECTRUM=1
fi

# GOOM
if test "$host_vendor" = "apple" ; then
  AC_MSG_NOTICE($goom_disabled)
  DISABLE_GOOM=1
else
  if test "$use_goom" = "yes" && test "$use_gl" = "yes"; then
    AC_MSG_NOTICE($goom_enabled)
    DISABLE_GOOM=0
  else
    AC_MSG_NOTICE($goom_disabled)
    DISABLE_GOOM=1
  fi
fi

# RSXS
if test "$use_rsxs" = "no" || test "$use_gl" = "no"; then
  AC_MSG_NOTICE($rsxs_disabled)
  DISABLE_RSXS=1
else
  AC_MSG_NOTICE($rsxs_enabled)
  DISABLE_RSXS=0
  # darwin osx can do rsxs but does not use x11, so do not pkg-config check for them
  if test "$host_vendor" != "apple" ; then
    PKG_CHECK_MODULES([XT],    [xt],
      [INCLUDES="$INCLUDES $XT_CFLAGS"; LIBS="$LIBS $XT_LIBS"],
      AC_MSG_ERROR($missing_library))
    PKG_CHECK_MODULES([XMU],   [xmu],
      [INCLUDES="$INCLUDES $XMU_CFLAGS"; LIBS="$LIBS $XMU_LIBS"],
      AC_MSG_ERROR($missing_library))
  fi
fi

# FISHBMC
if test "$use_fishbmc" = "no" || test "$use_gl" = "no"; then
  AC_MSG_NOTICE($fishbmc_disabled)   
  DISABLE_FISHBMC=1
  use_fishbmc="no"
else
  AC_MSG_NOTICE($fishbmc_enabled)
  DISABLE_FISHBMC=0
fi

# PROJECTM
if test "$use_projectm" = "no" || test "$use_gl" = "no"; then
  AC_MSG_NOTICE($projectm_disabled)
  DISABLE_PROJECTM=1
  use_projectm="no"
else
  AC_MSG_NOTICE($projectm_enabled)
  DISABLE_PROJECTM=0
fi

# skin touched
use_skin_touched=no
if [[ -f "addons/skin.touched/addon.xml" ]]; then 
  use_skin_touched=yes
  USE_SKIN_TOUCHED=1
  AC_DEFINE([HAS_SKIN_TOUCHED], [1], [Whether to build skin touched.])
else
  USE_SKIN_TOUCHED=0
fi

# libssh
if test "x$use_ssh" = "xno"; then
  AC_MSG_NOTICE($ssh_disabled)
  use_libssh="no"
else
  AC_CHECK_LIB([ssh], [sftp_tell64],, AC_MSG_ERROR($ssh_not_found))
  AC_DEFINE([HAVE_LIBSSH], [1], [Whether to use libSSH library.])
fi

# libcurl
if test "x$have_curl_static" = "xyes"; then
  AC_DEFINE([HAS_CURL_STATIC], [1], [Whether OpenSSL inside libcurl is static.])
fi

# libRTMP
if test "$use_librtmp" != "no"; then
  AC_CHECK_HEADERS([librtmp/log.h librtmp/amf.h librtmp/rtmp.h],,
   [if test "$use_librtmp" = "yes"; then
      AC_MSG_ERROR($librtmp_not_found)
    elif test "$use_librtmp" != "no"; then
      AC_MSG_NOTICE($librtmp_not_found)
      use_librtmp="no"
    fi
   ])
  if test "$use_librtmp" != "no"; then
    XB_FIND_SONAME([RTMP], [rtmp], [use_librtmp])
  fi
  if test "$use_librtmp" != "no"; then
    AC_DEFINE([HAS_LIBRTMP], [1], [Whether to use libRTMP library.])
  fi
else
  AC_MSG_NOTICE($librtmp_disabled)
fi

# samba
if test "x$use_samba" != "xno"; then
  PKG_CHECK_MODULES([SAMBA], [smbclient],
    [INCLUDES="$INCLUDES $SAMBA_CFLAGS"; LIBS="$LIBS $SAMBA_LIBS"],
    [AC_CHECK_LIB([smbclient], [main],,
      use_samba=no;AC_MSG_ERROR($missing_library))
      USE_LIBSMBCLIENT=0
    ])
else
  AC_MSG_RESULT($samba_disabled)
  USE_LIBSMBCLIENT=0
fi

if test "x$use_samba" != "xno"; then
  AC_DEFINE([HAVE_LIBSMBCLIENT], [1], [Define to 1 if you have Samba installed])
  USE_LIBSMBCLIENT=1
fi

# libnfs
if test "$use_libnfs" != "no"; then
  AC_CHECK_HEADERS([nfsc/libnfs.h],,
   [if test "$use_libnfs" = "yes"; then
      AC_MSG_ERROR($libnfs_not_found)
      USE_LIBNFS=0
    elif test "$use_libnfs" != "no"; then
      AC_MSG_NOTICE($libnfs_not_found)
      use_libnfs="no"
      USE_LIBNFS=0
    fi
   ])
  if test "$use_libnfs" != "no"; then
    XB_FIND_SONAME([NFS], [nfs], [use_libnfs])
  fi
  if test "$use_libnfs" != "no"; then
    AC_DEFINE([HAVE_LIBNFS], [1], [Whether to use libnfs library.])
    USE_LIBNFS=1
  fi
else
  USE_LIBNFS=0
  AC_MSG_NOTICE($libnfs_disabled)
fi

# libafpclient
USE_LIBAFPCLIENT=0
if test "x$use_libafpclient" != "xno"; then
  AC_CHECK_HEADERS([afpfs-ng/libafpclient.h],,
   [if test "x$use_libafpclient" = "xyes"; then
      AC_MSG_ERROR($libafpclient_not_found)
    elif test "x$use_libafpclient" != "xno"; then
      AC_MSG_NOTICE($libafpclient_not_found)
      use_libafpclient="no"
    fi
   ])
  if test "x$use_libafpclient" != "xno"; then
    XB_FIND_SONAME([AFPCLIENT], [afpclient], [use_libafpclient])
    AC_DEFINE([HAVE_LIBAFPCLIENT], [1], [Whether to use libafpclient library.])
    USE_LIBAFPCLIENT=1
  fi
else
  AC_MSG_NOTICE($libafpclient_disabled)
fi

# libplist for airplay feature
USE_AIRPLAY=0
if test "$use_airplay" != "no"; then
  AC_CHECK_HEADER([plist/plist.h],,
   [if test "$use_airplay" = "yes"; then
      AC_MSG_ERROR($libplist_not_found)
    elif test "$use_airplay" != "no"; then
      AC_MSG_NOTICE($libplist_not_found)
      use_airplay="no"
    fi
   ])

  if test "$use_airplay" != "no"; then
    XB_FIND_SONAME([PLIST], [plist], [use_airplay])
    USE_AIRPLAY=1
    AC_DEFINE([HAVE_LIBPLIST],[1],["Define to 1 if you have libplist."])
  fi
fi

# libshairplay for AirTunes (prefered lib)
USE_AIRTUNES=0
if test "x$use_airtunes" != "xno"; then
  AC_CHECK_HEADERS([shairplay/raop.h],USE_AIRTUNES=1,
   [AC_MSG_NOTICE($libshairplay_not_found)
   ])

  if test "x$USE_AIRTUNES" != "x0"; then
    XB_FIND_SONAME([SHAIRPLAY], [shairplay], [USE_AIRTUNES])
    USE_LIBSHAIRPLAY=1
    AC_CHECK_MEMBERS([struct raop_callbacks_s.cls],,,
                     [[#include <shairplay/raop.h>]])
    AC_DEFINE([HAVE_LIBSHAIRPLAY],[1],["Define to 1 if you have libshairplay."])
  fi

  #libshairport - as a fallback for AirTunes
  if test "x$USE_AIRTUNES" == "x0"; then
    AC_CHECK_HEADERS([shairport/shairport.h],USE_AIRTUNES=1,
     [AC_MSG_NOTICE($libshairport_not_found)
     ])

    if test "x$USE_AIRTUNES" != "x0"; then
      XB_FIND_SONAME([SHAIRPORT], [shairport], [USE_AIRTUNES])
      AC_CHECK_MEMBERS([struct AudioOutput.ao_set_metadata],,,
                       [[#include <shairport/shairport.h>]])
      AC_DEFINE([HAVE_LIBSHAIRPORT],[1],["Define to 1 if you have libshairport."])
    fi
  fi

  if test "x$USE_AIRTUNES" == "x0"; then
    if test "x$use_airtunes" == "xyes"; then
      AC_MSG_ERROR("No airtunes library could be found. (libshairport/libshairplay)")
    fi
    use_airtunes="no"
  fi
fi

# libudev
USE_LIBUDEV=0
if test "$host_vendor" = "apple" ; then
  use_libudev="no"
  AC_MSG_NOTICE($libudev_disabled)
else
  if test "$use_libudev" = "auto"; then
    PKG_CHECK_MODULES([UDEV],[libudev],,[use_libudev="no";AC_MSG_RESULT($libudev_not_found)])
  elif test "$use_libudev" = "yes" ; then
    PKG_CHECK_MODULES([UDEV],[libudev],,[use_libudev="no";AC_MSG_ERROR($libudev_not_found)])
  else
    AC_MSG_NOTICE($libudev_disabled)
  fi

  if test "x$use_libudev" != "xno"; then
    USE_LIBUDEV=1;INCLUDES="$INCLUDES $UDEV_CFLAGS";LIBS="$LIBS $UDEV_LIBS"
    AC_DEFINE([HAVE_LIBUDEV],[1],["Define to 1 if libudev is installed"])
  fi
fi

# libusb
USE_LIBUSB=0

# if libudev is available, we don't need libusb
if test "x$use_libudev" != "xno"; then
  use_libusb="no"
  AC_MSG_NOTICE($libusb_disabled_udev_found)
else
  if test "$host_vendor" = "apple" ; then
    use_libusb="no"
    AC_MSG_NOTICE($libusb_disabled)
  else
    if echo "$ARCH" | grep -q freebsd ; then
      AC_CHECK_LIB([usb],[main],
	  	[use_libusb="yes";USB_LIBS="-lusb"],
		[use_libusb="no";AC_MSG_RESULT($libusb_not_found)])
    elif test "$use_libusb" = "auto"; then
      PKG_CHECK_MODULES([USB],[libusb],,[use_libusb="no";AC_MSG_RESULT($libusb_not_found)])
    elif test "$use_libusb" = "yes"; then
      PKG_CHECK_MODULES([USB],[libusb],,[use_libusb="no";AC_MSG_ERROR($libusb_not_found)])
    else
      AC_MSG_NOTICE($libusb_disabled)
    fi
  
    if test "x$use_libusb" != "xno"; then
      USE_LIBUSB=1;INCLUDES="$INCLUDES $USB_CFLAGS";LIBS="$LIBS $USB_LIBS"
      AC_DEFINE([HAVE_LIBUSB],[1],["Define to 1 if libusb is installed"])
    fi
  fi
fi

# libcec
USE_LIBCEC=0
if test "x$use_libcec" != "xno"; then
  # libcec is dyloaded, so we need to check for its headers and link any depends.
  if test "x$use_libcec" != "xno"; then
    if test "x$use_libcec" != "xauto"; then
      PKG_CHECK_MODULES([CEC],[libcec >= 2.1.0],,[use_libcec="no";AC_MSG_ERROR($libcec_disabled)])
    else
      PKG_CHECK_MODULES([CEC],[libcec >= 2.1.0],,[use_libcec="no";AC_MSG_RESULT($libcec_disabled)])
    fi

    if test "x$use_libcec" != "xno"; then
      INCLUDES="$INCLUDES $CEC_CFLAGS"
      USE_LIBCEC=1;AC_DEFINE([HAVE_LIBCEC],[1],["Define to 1 if libcec is installed"])
      XB_FIND_SONAME([LIBCEC],[cec],[use_libcec])
      AC_MSG_NOTICE($libcec_enabled)
    else
      use_libcec="no"
      AC_MSG_NOTICE($libcec_disabled)
    fi
  fi
else
  use_libcec="no"
  AC_MSG_NOTICE($libcec_disabled)
fi

# libcap
if test "$use_libcap" != "no"; then
  AC_CHECK_HEADERS([sys/capability.h],,
   [if test "$use_libcap" = "yes"; then
      AC_MSG_ERROR($libcap_not_found)
    elif test "$use_libcap" != "no"; then
      AC_MSG_NOTICE($libcap_not_found)
      use_libcap="no"
    fi
   ])
  if test "$use_libcap" != "no"; then
    AC_CHECK_LIB([cap], main, LIBS="$LIBS -lcap", use_libcap=no)
  fi
  if test "$use_libcap" != "no"; then
    AC_DEFINE([HAVE_LIBCAP], [1], [Whether to use libcap library.])
  fi
else
  AC_MSG_NOTICE($libcap_disabled)
fi

### External libraries checks

# Hacks for supporting libav

USE_LIBAV_HACKS=0
if test "$use_libav_hacks" = "yes"; then
    export PKG_CONFIG_PATH="${srcdir}/lib/xbmc-libav-hacks/pkgconfig/:$PKG_CONFIG_PATH"
    USE_LIBAV_HACKS=1
    AC_DEFINE([USE_LIBAV_HACKS], [1], [Whether to use libav compatibility hacks.])
fi

# External FFmpeg
if test "$use_external_ffmpeg" = "yes"; then
  FFMPEG_LIBNAMES="libavcodec libavfilter libavformat libavutil libpostproc libswscale libswresample"

  PKG_CHECK_MODULES([FFMPEG], [$FFMPEG_LIBNAMES],
                    [INCLUDES="$INCLUDES $FFMPEG_CFLAGS"; LIBS="$LIBS $FFMPEG_LIBS"],
                    AC_MSG_ERROR($missing_library))

  # in case the headers are in a custom directory
  SAVE_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$CPPFLAGS $FFMPEG_CFLAGS"

  AC_CHECK_HEADERS([libavcodec/avcodec.h libavfilter/avfilter.h libavformat/avformat.h libavutil/avutil.h libpostproc/postprocess.h libswscale/swscale.h],,
  [AC_MSG_ERROR($missing_headers)])

  AC_MSG_NOTICE($external_ffmpeg_enabled)
  USE_EXTERNAL_FFMPEG=1
  AC_DEFINE([USE_EXTERNAL_FFMPEG], [1], [Whether to use external FFmpeg libraries.])

  CPPFLAGS="$SAVE_CPPFLAGS"
else
  AC_MSG_NOTICE($external_ffmpeg_disabled)
  USE_EXTERNAL_FFMPEG=0
fi

echo "Checking for SWIG installation"
AC_PATH_PROG(SWIG_EXE, swig, "none")
if test "$SWIG_EXE" = "none"; then
  AC_PATH_PROG(SWIG20_EXE, swig2.0, "none")
  if test "$SWIG20_EXE" != "none" ; then
    SWIG_EXE=$SWIG20_EXE
  fi
fi
if test "$SWIG_EXE" = "none"; then
  AC_MSG_ERROR($missing_program)
fi
final_message="$final_message\n  SWIG Available:\tYes"

echo "Checking for a jre installation"
AC_PATH_PROG(JAVA_EXE, java, "none")
if test "$JAVA_EXE" = "none"; then
  AC_MSG_ERROR($missing_program)
fi
final_message="$final_message\n  JRE Available:\tYes"

echo "Checking for doxygen installation"
AC_PATH_PROG(DOXYGEN_EXE, doxygen, "none")
if test "$DOXYGEN_EXE" = "none"; then
  AC_MSG_WARN([Unable to find doxygen installation. Will not be able to make docstrings for the python api])
  final_message="$final_message\n  Doxygen Available:\tNo"
  USE_DOXYGEN=0
else
  final_message="$final_message\n  Doxygen Available:\tYes"
  USE_DOXYGEN=1
fi

# VDPAU
if test "x$use_vdpau" != "xno"; then
  if test "$host_vendor" = "apple" ; then
    if test "x$use_vdpau" = "xyes"; then
      AC_MSG_ERROR([VDPAU not supported on this platform])
    else
      use_vdpau="no"
      AC_MSG_NOTICE($vdpau_disabled)
    fi
    USE_VDPAU=0
  else
    USE_VDPAU=1
    AC_CHECK_HEADER([vdpau/vdpau.h],AC_DEFINE([HAVE_LIBVDPAU], [],
      [Define to 1 if you have the 'vdpau' library (-lvdpau).]),
    [if test "x$use_vdpau" = "xyes"; then
      USE_VDPAU=0
      AC_MSG_ERROR([$vdpau_not_found])
    else
      use_vdpau="no"
      USE_VDPAU=0
      AC_MSG_RESULT($vdpau_not_found)
    fi])
  fi
else
  USE_VDPAU=0
  AC_MSG_NOTICE($vdpau_disabled)
fi

# VAAPI
if test "x$use_vaapi" != "xno"; then
  if test "$host_vendor" = "apple" ; then
    if test "x$use_vaapi" = "xyes"; then
      AC_MSG_ERROR([VAAPI not supported on this platform])
    else
      use_vaapi="no"
      AC_MSG_NOTICE($vaapi_disabled)
    fi
    USE_VAAPI=0
  else
    initial_val=$use_vaapi
    AC_CHECK_LIB([va], main, :, use_vaapi=no)
    if test "x$use_vaapi" != "xno"; then
      AC_CHECK_LIB([va-glx], main, LIBS="-lva -lva-glx $LIBS", use_vaapi=no, -lva)
    fi

    if test "x$use_vaapi" = "xno"; then
      if test "x$initial_val" = "xyes"; then
        AC_MSG_ERROR($vaapi_not_found)
      else
        AC_MSG_RESULT($vaapi_not_found)
      fi
      USE_VAAPI=0
    else
      AC_DEFINE([HAVE_LIBVA], [1], [Define to 1 if you have the 'vaapi' libraries (-lva AND -lva-glx)])
      USE_VAAPI=1
    fi
  fi
else
  AC_MSG_NOTICE($vaapi_disabled)
  USE_VAAPI=0
fi

# CrystalHD
if test "x$use_crystalhd" != "xno"; then
  SAVE_CFLAGS="$CFLAGS"
  CFLAGS="-D__LINUX_USER__"
  AC_CHECK_HEADER([libcrystalhd/libcrystalhd_if.h], [],
    [ if test "x$use_crystalhd" = "xyes"; then
        AC_MSG_ERROR($crystalhd_not_found)
      else
        use_crystalhd=no
        AC_MSG_RESULT($crystalhd_not_found)
      fi
      USE_CRYSTALHD=0
    ])
    CFLAGS="$SAVE_CFLAGS"
    if test "$host_vendor" != "apple"; then
      XB_FIND_SONAME([CRYSTALHD], [crystalhd], [use_crystalhd])
    fi
    if test "x$use_crystalhd" != "xno"; then
      SAVE_CFLAGS="$CFLAGS"
      CFLAGS="-D__LINUX_USER__ -lcrystalhd"
      # check for new crystalhd lib
      AC_COMPILE_IFELSE(
        [AC_LANG_SOURCE([#include <libcrystalhd/bc_dts_types.h>
          #include <libcrystalhd/bc_dts_defs.h>
          PBC_INFO_CRYSTAL bCrystalInfo;])],
        [ AC_DEFINE([HAVE_LIBCRYSTALHD], [2], [Define to 2 if you have the 'New Broadcom Crystal HD' library.]) ], 
        [ AC_DEFINE([HAVE_LIBCRYSTALHD], [1], [Define to 1 if you have the 'Old Broadcom Crystal HD' library.]) ])
      CFLAGS="$SAVE_CFLAGS"
      USE_CRYSTALHD=1
    fi
else
  AC_MSG_NOTICE($crystalhd_disabled)
  USE_CRYSTALHD=0
fi

# VTBDecoder
if test "x$use_vtbdecoder" != "xno"; then
  if test "$host_vendor" = "apple" ; then
    HAVE_VIDEOTOOLBOXDECODER=1
    AC_DEFINE([HAVE_VIDEOTOOLBOXDECODER], [1], [Define to 1 if you have the 'VTBDecoder' library.])
    AC_MSG_NOTICE($vtbdecoder_enabled)
  else
    if test "x$use_vtbdecoder" = "xyes"; then
      AC_MSG_ERROR([VTB Decoder not supported on this platform])
    else
      use_vtbdecoder="no"
      AC_MSG_NOTICE($vtbdecoder_disabled)
    fi
  fi
else
  AC_MSG_NOTICE($vtbdecoder_disabled)
fi

# OpenMax
if test "$host_vendor" = "apple" ; then
  use_openmax="no"
  USE_OPENMAX=0
  AC_MSG_NOTICE($openmax_disabled)
elif test "$target_platform" = "target_raspberry_pi"; then
  use_openmax="no"
  USE_OPENMAX=0
  AC_MSG_NOTICE($openmax_disabled)
else
  if test "$use_gles" = "yes" && test "$use_openmax" = "auto"; then
    PKG_CHECK_MODULES([OPENMAX], [libomxil-bellagio],
                      USE_OPENMAX=1;[INCLUDES="$INCLUDES $OPENMAX_CFLAGS"; LIBS="$LIBS $OPENMAX_LIBS"],
                      use_openmax=no;USE_OPENMAX=0;AC_MSG_RESULT($openmax_not_found))
  elif test "$use_gles" = "yes" && test "$use_openmax" = "yes"; then
    PKG_CHECK_MODULES([OPENMAX], [libomxil-bellagio],
                      USE_OPENMAX=1;[INCLUDES="$INCLUDES $OPENMAX_CFLAGS"; LIBS="$LIBS $OPENMAX_LIBS"],
                      AC_MSG_ERROR($openmax_not_found))
  else
    AC_MSG_NOTICE($openmax_disabled)
    use_openmax=no
    USE_OPENMAX=0
  fi
fi

# yajl version check (yajl_version.h was added in yajl 2.0)
AC_CHECK_HEADERS([yajl/yajl_version.h], [], [
AC_DEFINE(YAJL_MAJOR, 1, [yajl version 1])
], [])

# additional internal players
case $add_players in
  *omxplayer*)
      XB_ADD_PLAYER([OMXPLAYER], [omxplayer])
      ;;
esac

# additional internal codecs
# remember to convert commas to spaces
for codecs in `echo $add_codecs | sed 's/,/ /g'`; do
  case $codecs in
    *amcodec*)
        AC_CHECK_HEADER([amcodec/codec_error.h],, AC_MSG_ERROR($missing_headers))
        XB_ADD_CODEC([LIBAMCODEC], [amcodec], [$codecs])
        ;;
    *libstagefright*)
        XB_ADD_CODEC([LIBSTAGEFRIGHT], [libstagefright], [$codecs])
        ;;
    *)
  esac
done

# platform specific bin utilities
if test "$build_vendor" != "apple" ; then
  AC_CHECK_PROG(HAVE_GAWK,gawk,"yes","no",)
  if test "$HAVE_GAWK" = "no" ; then
    AC_MSG_ERROR($missing_program)
  fi
fi

if test "$use_arch" != "arm" ; then
  AC_CHECK_PROG(HAVE_CMAKE,cmake,"yes","no",)
  if test "$HAVE_CMAKE" = "no" ; then
    AC_MSG_ERROR($missing_program)
  fi
fi

AC_CHECK_PROG(HAVE_GPERF,gperf,"yes","no",)
if test "$HAVE_GPERF" = "no" ; then
  AC_MSG_ERROR($missing_program)
fi

AC_CHECK_PROG(HAVE_UNZIP,unzip,"yes","no",)
if test "$HAVE_UNZIP" = "no" ; then
  AC_MSG_ERROR($missing_program)
fi

AC_CHECK_PROG(HAVE_ZIP,zip,"yes","no",)
if test "$HAVE_ZIP" = "no" ; then
  AC_MSG_ERROR($missing_program)
fi

if test "$ARCH" = "i486-linux" || test "$ARCH" = "x86-freebsd"; then
  AC_CHECK_PROG(HAVE_NASM,nasm,"yes","no",)
  if test "$HAVE_NASM" = "no" ; then
    AC_MSG_ERROR($missing_program)
  fi
fi

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([arpa/inet.h fcntl.h float.h inttypes.h limits.h locale.h \
  malloc.h memory.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h \
  strings.h sys/file.h sys/ioctl.h sys/mount.h sys/param.h sys/socket.h \
  sys/time.h sys/timeb.h sys/vfs.h termios.h unistd.h utime.h wchar.h wctype.h])
AC_CHECK_HEADERS([cdio/iso9660.h],,AC_MSG_ERROR([$missing_headers]))

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STAT
AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_UID_T
AC_C_INLINE
AC_TYPE_INT8_T
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_C_RESTRICT
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_CHECK_MEMBERS([struct stat.st_rdev])
AC_HEADER_TIME
AC_STRUCT_TM
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_C_BIGENDIAN

if test "$cross_compiling" = "yes"; then
  final_message="$final_message\n  Crosscomp.:\tYes"
  if [[ -d "$NATIVE_ROOT" ]]; then
    CFLAGS_FOR_BUILD="$CFLAGS_FOR_BUILD -I$NATIVE_ROOT/include"
    CXXFLAGS_FOR_BUILD="$CXXFLAGS_FOR_BUILD -I$NATIVE_ROOT/include"
    LDFLAGS_FOR_BUILD="$LDFLAGS_FOR_BUILD -L$NATIVE_ROOT/lib"
    if test "$host_vendor" != "apple" ; then
      LDFLAGS_FOR_BUILD="$LDFLAGS_FOR_BUILD -Wl,-rpath=$NATIVE_ROOT/lib"
    fi
    final_message="$final_message\n  Native Root:\t$NATIVE_ROOT"
  fi
else
  final_message="$final_message\n  Crosscomp.:\tNo"
fi

final_message="$final_message\n  target ARCH:\t$use_arch"
final_message="$final_message\n  target CPU:\t$use_cpu"

if test "$use_gles" = "yes"; then
  final_message="$final_message\n  OpenGLES:\tYes"
  USE_OPENGLES=1
  USE_OPENGL=0
else
  USE_OPENGLES=0
  if test "$use_gl" = "yes"; then
    final_message="$final_message\n  OpenGL:\tYes"
    USE_OPENGL=1
  else
    final_message="$final_message\n  OpenGL:\tNo (Very Slow)"
    SDL_DEFINES="$SDL_DEFINES -DHAS_SDL_2D"
    USE_OPENGL=0
  fi
fi

if test "$use_alsa" = "yes"; then
  USE_ALSA=1
  AC_DEFINE([USE_ALSA],[1],["Define to 1 if alsa is installed"])
  final_message="$final_message\n  ALSA:\t\tYes"
else
  USE_ALSA=0
  final_message="$final_message\n  ALSA:\t\tNo"
fi

if test "$use_dbus" = "yes"; then
  final_message="$final_message\n  DBUS:\t\tYes"
else
  final_message="$final_message\n  DBUS:\t\tNo"
fi

if test "x$use_vdpau" != "xno"; then
  final_message="$final_message\n  VDPAU:\tYes"
else
  final_message="$final_message\n  VDPAU:\tNo"
fi

if test "x$use_vaapi" != "xno"; then
  final_message="$final_message\n  VAAPI:\tYes"
else
  final_message="$final_message\n  VAAPI:\tNo"
fi

if test "x$use_crystalhd" != "xno"; then
  final_message="$final_message\n  CrystalHD:\tYes"
else
  final_message="$final_message\n  CrystalHD:\tNo"
fi

if test "x$use_vtbdecoder" != "xno"; then
  final_message="$final_message\n  VTBDecoder:\tYes"
else
  final_message="$final_message\n  VTBDecoder:\tNo"
fi

if test "$use_openmax" != "no"; then
  final_message="$final_message\n  OpenMax:\tYes"
else
  final_message="$final_message\n  OpenMax:\tNo"
fi

if test "$use_joystick" = "yes"; then
  final_message="$final_message\n  Joystick:\tYes"
  SDL_DEFINES="$SDL_DEFINES -DHAS_SDL_JOYSTICK"
else
  final_message="$final_message\n  Joystick:\tNo"
fi

if test "$use_xrandr" = "yes"; then
  final_message="$final_message\n  XRandR:\tYes"
  USE_XRANDR=1
else
  final_message="$final_message\n  XRandR:\tNo"
  USE_XRANDR=0
fi

if test "$use_waveform" = "yes"; then
  final_message="$final_message\n  Waveform:\tYes"
else
  final_message="$final_message\n  Waveform:\tNo"
fi

if test "$use_spectrum" = "yes"; then
  final_message="$final_message\n  Spectrum:\tYes"
else
  final_message="$final_message\n  Spectrum:\tNo"
fi

if test "$use_goom" = "yes"; then
  final_message="$final_message\n  GOOM:\t\tYes"
else
  final_message="$final_message\n  GOOM:\t\tNo"
fi

if test "$use_rsxs" = "yes"; then
  final_message="$final_message\n  RSXS:\t\tYes"
else
  final_message="$final_message\n  RSXS:\t\tNo"
fi

if test "$use_fishbmc" = "yes"; then
  final_message="$final_message\n  FishBMC:\tYes"
else
  final_message="$final_message\n  FishBMC:\tNo"
fi

if test "$use_projectm" = "yes"; then
  final_message="$final_message\n  ProjectM:\tYes"
else
  final_message="$final_message\n  ProjectM:\tNo"
fi

if test "$use_skin_touched" = "yes"; then
  final_message="$final_message\n  Skin Touched:\tYes"
else
  final_message="$final_message\n  Skin Touched:\tNo"
fi

if test "$use_x11" = "yes"; then
  final_message="$final_message\n  X11:\t\tYes"
else
  final_message="$final_message\n  X11:\t\tNo"
fi

if test "$use_wayland" = "yes"; then
  final_message="$final_message\n  Wayland:\tYes"
  USE_WAYLAND=1
  USE_XKBCOMMON=1
else
  final_message="$final_message\n  Wayland:\tNo"
fi

if test "$use_libbluray" = "yes"; then
  final_message="$final_message\n  Bluray:\tYes"
else
  final_message="$final_message\n  Bluray:\tNo"
fi

if test "x$use_texturepacker" != "xno"; then
  final_message="$final_message\n  TexturePacker:Yes"
  USE_TEXTUREPACKER=1
else
  final_message="$final_message\n  TexturePacker:No"
  USE_TEXTUREPACKER=0
fi

if test "$use_mid" = "yes"; then
  final_message="$final_message\n  MID Support:\tYes"
  SDL_DEFINES="$SDL_DEFINES -DMID"
else
  final_message="$final_message\n  MID Support:\tNo"
fi

ORIGCC=$CC
ORIGCXX=$CXX
if test "x$use_ccache" != "xno"; then
  AC_PATH_PROG(CCACHE,ccache,none)
  if test "$ac_cv_path_CCACHE" = "none"; then
    if test "x$use_ccache" = "xyes"; then
      AC_MSG_ERROR([ccache not found.]);
    else
      AC_MSG_NOTICE([ccache not found. Falling back to default CC])
      final_message="$final_message\n  ccache:\tNo"
    fi
  else
    CC="$ac_cv_path_CCACHE $CC"
    CXX="$ac_cv_path_CCACHE $CXX"
    AC_MSG_NOTICE(enabling ccache)
    final_message="$final_message\n  ccache:\tYes"
  fi
else
  final_message="$final_message\n  ccache:\tNo"
fi

if test "$use_alsa" = "yes"; then
  final_message="$final_message\n  ALSA Support:\tYes"
else
  final_message="$final_message\n  ALSA Support:\tNo"
fi

if test "x$use_pulse" != "xno"; then
  XBMC_STANDALONE_SH_PULSE=tools/Linux/xbmc-standalone.sh.pulse
  final_message="$final_message\n  PulseAudio:\tYes"
else
  XBMC_STANDALONE_SH_PULSE=/dev/null
  final_message="$final_message\n  PulseAudio:\tNo"
fi

if test "$use_hal" = "yes"; then
  final_message="$final_message\n  HAL Support:\tYes"
else
  final_message="$final_message\n  HAL Support:\tNo"
fi

# DVDCSS
if test "$use_dvdcss" = "yes"; then
  AC_MSG_NOTICE($dvdcss_enabled)
  final_message="$final_message\n  DVDCSS:\tYes"
  BUILD_DVDCSS=1
  SKIP_CONFIG_DVDCSS=0
  DVDREAD_CFLAGS="-D_XBMC -DHAVE_DVDCSS_DVDCSS_H"
else
  AC_MSG_NOTICE($dvdcss_disabled)
  final_message="$final_message\n  DVDCSS:\tNo"
  BUILD_DVDCSS=0
  SKIP_CONFIG_DVDCSS=1
  DVDREAD_CFLAGS="-D_XBMC -UHAVE_DVDCSS_DVDCSS_H"
fi
if test "$host_vendor" = "apple"; then
 DVDREAD_CFLAGS="$DVDREAD_CFLAGS -D__DARWIN__"
fi

# Google Test Framework
if test "$configure_gtest" = "yes"; then
  AC_MSG_NOTICE($gtest_enabled)
  final_message="$final_message\n  Google Test Framework Configured:\tYes"
  GTEST_CONFIGURED=1
  SKIP_CONFIG_GTEST=0
else
  AC_MSG_NOTICE($gtest_disabled)
  final_message="$final_message\n  Google Test Framework Configured:\tNo"
  GTEST_CONFIGURED=0
  SKIP_CONFIG_GTEST=1
fi

if test "$use_avahi" = "yes"; then
  final_message="$final_message\n  Avahi:\tYes"
else
  final_message="$final_message\n  Avahi:\tNo"
fi

if test "$use_mdnsembedded" != "no"; then
  final_message="$final_message\n  mDNSEmbedded:\tYes"
else
  final_message="$final_message\n  mDNSEmbedded:\tNo"
fi

if test "$use_nonfree" = "yes"; then
  final_message="$final_message\n  Non-free:\tYes"
  HAVE_XBMC_NONFREE=1
  AC_DEFINE([HAVE_XBMC_NONFREE], [1], [Define to 1 to enable non-free components.])
else
  HAVE_XBMC_NONFREE=0
  final_message="$final_message\n  Non-free:\tNo"
fi

if test "$use_asap" = "yes"; then
  AC_CHECK_PROGS(HAVE_GDC,gdc-4.4 gdc-4.3 gdc,"no")
  if test "$HAVE_GDC" = "no"; then
    AC_MSG_ERROR($missing_program);
  fi
  AC_CHECK_PROG(HAVE_FPC,fpc,"yes","no")
  if test "$HAVE_FPC" = "no"; then
    AC_MSG_ERROR($missing_program);
  fi
  USE_ASAP_CODEC=1
  AC_DEFINE([USE_ASAP_CODEC], [1], [Define to 1 to enable ASAP codec.])
  final_message="$final_message\n  ASAP Codec:\tYes"
else
  USE_ASAP_CODEC=0
  final_message="$final_message\n  ASAP Codec:\tNo"
fi

if test "$use_mysql" = "yes"; then
  final_message="$final_message\n  MySQL:\tYes"
  USE_MYSQL=1
else
  final_message="$final_message\n  MySQL:\tNo"
  USE_MYSQL=0
fi
if test "$use_webserver" = "yes"; then
  final_message="$final_message\n  Webserver:\tYes"
  USE_WEB_SERVER=1
else
  final_message="$final_message\n  Webserver:\tNo"
  USE_WEB_SERVER=0
fi

if test "$use_libssh" != "no"; then
  final_message="$final_message\n  libssh support:\tYes"
else
  final_message="$final_message\n  libssh support:\tNo"
fi

if test "$use_librtmp" != "no"; then
  final_message="$final_message\n  libRTMP support:\tYes"
else
  final_message="$final_message\n  libRTMP support:\tNo"
fi

if test "x$use_samba" != "xno"; then
  final_message="$final_message\n  libsmbclient support:\tYes"
else
  final_message="$final_message\n  libsmbclient support:\tNo"
fi

if test "$use_libnfs" != "no"; then
  final_message="$final_message\n  libnfs client support:Yes"
else
  final_message="$final_message\n  libnfs client support:No"
fi

if test "x$use_libafpclient" != "xno"; then
  final_message="$final_message\n  libafpclient support:\tYes"
else  
  final_message="$final_message\n  libafpclient support:\tNo"
fi

if test "$use_airplay" != "no"; then
  final_message="$final_message\n  AirPlay support:\tYes"
else
  final_message="$final_message\n  AirPLay support:\tNo"
fi

if test "x$use_airtunes" != "xno"; then
  if test "x$USE_LIBSHAIRPLAY" == "x1"; then
    final_message="$final_message\n  AirTunes support (libshairplay):\tYes"  
  else
    final_message="$final_message\n  AirTunes support (libshairport):\tYes"
  fi
else
  final_message="$final_message\n  AirTunes support:\tNo"
fi

if test "x$use_upnp" != "xno"; then
  final_message="$final_message\n  UPnP support:\t\tYes"
  USE_UPNP=1
  AC_DEFINE([USE_UPNP], [1], [Define to 1 to enable UPnP support.])
else
  USE_UPNP=0
  final_message="$final_message\n  UPnP support:\t\tNo"
fi

if test "$use_optical_drive" = "yes"; then
  final_message="$final_message\n  Optical drive:\tYes"
else
  final_message="$final_message\n  Optical drive:\tNo"
fi

if test "x$use_libudev" != "xno"; then
  final_message="$final_message\n  libudev support:\tYes"
else
  final_message="$final_message\n  libudev support:\tNo"
fi

if test "x$use_libusb" != "xno"; then
  final_message="$final_message\n  libusb support:\tYes"
else
  final_message="$final_message\n  libusb support:\tNo"
fi

if test "x$use_libcec" != "xno"; then
  final_message="$final_message\n  libcec support:\tYes"
else
  final_message="$final_message\n  libcec support:\tNo"
fi

if test "x$use_libmp3lame" != "xno"; then
  final_message="$final_message\n  libmp3lame support:\tYes"
else
  final_message="$final_message\n  libmp3lame support:\tNo"
fi

if test "x$use_libvorbisenc" != "xno"; then
  final_message="$final_message\n  libvorbisenc support:\tYes"
else
  final_message="$final_message\n  libvorbisenc support:\tNo"
fi

if test "x$use_libcap" != "xno"; then
  final_message="$final_message\n  libcap support:\tYes"
else
  final_message="$final_message\n  libcap support:\tNo"
fi

if test "x$add_players" != "xno"; then
  final_message="$final_message\n  additional players:\tYes, $add_players"
else
  final_message="$final_message\n  additional players:\tNo"
fi

if test "x$add_codecs" != "xno"; then
  final_message="$final_message\n  additional codecs:\tYes, $add_codecs"
else
  final_message="$final_message\n  additional codecs:\tNo"
fi

### External libraries messages

if test "$use_external_ffmpeg" = "yes"; then
  final_message="$final_message\n  External FFmpeg:\tYes"
else
  final_message="$final_message\n  External FFmpeg:\tNo"
fi

if test "$host_vendor" = "apple" ; then
  # built internal but referenced as external, we link directly to them.
  # this MUST be the last thing before OUTPUT_FILES as they do not
  # exist until after we build FFMpeg.
  LIBS="$LIBS -L\$(abs_top_srcdir)/lib/ffmpeg/libavcodec -lavcodec"
  LIBS="$LIBS -L\$(abs_top_srcdir)/lib/ffmpeg/libavfilter -lavfilter"
  LIBS="$LIBS -L\$(abs_top_srcdir)/lib/ffmpeg/libswresample -lswresample"
  LIBS="$LIBS -L\$(abs_top_srcdir)/lib/ffmpeg/libavformat -lavformat"
  LIBS="$LIBS -L\$(abs_top_srcdir)/lib/ffmpeg/libavutil -lavutil"
  LIBS="$LIBS -L\$(abs_top_srcdir)/lib/ffmpeg/libpostproc -lpostproc"
  LIBS="$LIBS -L\$(abs_top_srcdir)/lib/ffmpeg/libswscale -lswscale"
fi

USE_PVR_ADDONS=0
DISABLE_PVR_ADDON_CONFIG=1
if [[ -f "pvr-addons/Makefile.am" ]]; then
  final_message="$final_message\n  PVR add-ons:\t\tYes"
  USE_PVR_ADDONS=1
  DISABLE_PVR_ADDON_CONFIG=0
else
  final_message="$final_message\n  PVR add-ons:\t\tNo"
fi

OUTPUT_FILES="Makefile \
    Makefile.include \
    addons/skin.confluence/media/Makefile \
    xbmc/Makefile \
    xbmc/cdrip/Makefile \
    xbmc/cores/Makefile \
    xbmc/cores/VideoRenderers/Makefile \
    xbmc/cores/dvdplayer/Makefile \
    lib/Makefile \
    lib/libdvd/Makefile \
    xbmc/cores/DllLoader/Makefile \
    xbmc/cores/DllLoader/exports/Makefile \
    xbmc/cores/dvdplayer/DVDCodecs/Makefile \
    xbmc/cores/dvdplayer/DVDCodecs/Audio/Makefile \
    xbmc/cores/dvdplayer/DVDCodecs/Overlay/Makefile \
    xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile \
    xbmc/cores/dvdplayer/DVDDemuxers/Makefile \
    xbmc/cores/dvdplayer/DVDSubtitles/Makefile \
    xbmc/cores/AudioEngine/Makefile \
    xbmc/cores/paplayer/Makefile \
    xbmc/cores/omxplayer/Makefile \
    lib/timidity/Makefile \
    lib/asap/Makefile \
    lib/nosefart/Makefile \
    lib/libsidplay2/Makefile \
    lib/vgmstream/Makefile \
    lib/snesapu/SNES/SNESAPU/Makefile \
    lib/stsound/StSoundLibrary/Makefile \
    xbmc/cores/playercorefactory/Makefile \
    xbmc/music/karaoke/Makefile \
    xbmc/osx/Makefile \
    xbmc/guilib/Makefile \
    xbmc/input/linux/Makefile \
    xbmc/interfaces/Makefile \
    xbmc/network/Makefile \
    xbmc/network/upnp/Makefile \
    lib/libRTV/Makefile \
    lib/libexif/Makefile \
    lib/libXDAAP/Makefile \
    lib/cmyth/Makefile \
    lib/libhdhomerun/Makefile \
    lib/libsquish/Makefile \
    lib/cximage-6.0/Makefile \
    lib/libUPnP/Makefile \
    xbmc/DllPaths_generated.h \
    xbmc/DllPaths_generated_android.h \
    xbmc/freebsd/Makefile \
    xbmc/linux/Makefile \
    xbmc/filesystem/Makefile \
    xbmc/screensavers/rsxs-0.9/xbmc/Makefile \
    xbmc/visualizations/XBMCProjectM/Makefile \
    xbmc/visualizations/Goom/Makefile \
    xbmc/visualizations/OpenGLSpectrum/Makefile \
    xbmc/visualizations/fishBMC/Makefile \
    xbmc/visualizations/WaveForm/Makefile \
    xbmc/windowing/Makefile \
    xbmc/windowing/egl/Makefile \
    lib/addons/library.xbmc.addon/Makefile \
    lib/addons/library.xbmc.codec/Makefile \
    lib/addons/library.xbmc.gui/Makefile \
    lib/addons/library.xbmc.pvr/Makefile \
    xbmc/visualizations/EGLHelpers/Makefile \
    tools/Linux/xbmc.sh \
    tools/Linux/xbmc-standalone.sh \
    tools/TexturePacker/Makefile \
    tools/EventClients/Clients/OSXRemote/Makefile \
    xbmc/peripherals/bus/Makefile \
    xbmc/peripherals/devices/Makefile \
    xbmc/android/activity/Makefile \
    xbmc/android/loader/Makefile \
    xbmc/android/jni/Makefile \
    xbmc/utils/Makefile \
    xbmc/main/Makefile \
    project/cmake/xbmc-config.cmake"

if test "$use_wayland" = "yes"; then
OUTPUT_FILES="$OUTPUT_FILES xbmc/windowing/tests/wayland/Makefile"
fi

if test "$use_skin_touched" = "yes"; then
OUTPUT_FILES="$OUTPUT_FILES addons/skin.touched/media/Makefile"
fi

if test "$use_codec_libstagefright" = "yes"; then
OUTPUT_FILES="$OUTPUT_FILES xbmc/cores/dvdplayer/DVDCodecs/Video/libstagefrightICS/Makefile"
fi

OUTPUT_FILES="$OUTPUT_FILES \
  xbmc/interfaces/python/Makefile \
  xbmc/interfaces/python/test/Makefile"

# Line below is used so we can use AM_INIT_AUTOMAKE. The corresponding
# .dummy.am does nothing.
AC_CONFIG_FILES([.dummy])

AC_CONFIG_FILES([${OUTPUT_FILES}])
OUTPUT_FILES="$OUTPUT_FILES \
  .dummy"
AC_SUBST(CFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(INCLUDES)
AC_SUBST(LDFLAGS)
AC_SUBST(CXX_FOR_BUILD)
AC_SUBST(CC_FOR_BUILD)
AC_SUBST(CFLAGS_FOR_BUILD)
AC_SUBST(CXXFLAGS_FOR_BUILD)
AC_SUBST(LDFLAGS_FOR_BUILD)
AC_SUBST(SDL_DEFINES)
AC_SUBST(BUILD_DVDCSS)
AC_SUBST(DISABLE_WAVEFORM)
AC_SUBST(DISABLE_SPECTRUM)
AC_SUBST(DISABLE_GOOM)
AC_SUBST(DISABLE_RSXS)
AC_SUBST(DISABLE_FISHBMC)
AC_SUBST(DISABLE_PROJECTM)
AC_SUBST(USE_SKIN_TOUCHED)
AC_SUBST(USE_EXTERNAL_FFMPEG)
AC_SUBST(USE_STATIC_FFMPEG)
AC_SUBST(USE_LIBAV_HACKS)
AC_SUBST(PYTHON_VERSION)
AC_SUBST(OUTPUT_FILES)
AC_SUBST(HAVE_XBMC_NONFREE)
AC_SUBST(USE_ASAP_CODEC)
AC_SUBST(LIBCURL_BASENAME)
AC_SUBST(LIBFLAC_BASENAME)
AC_SUBST(LIBVORBISFILE_BASENAME)
AC_SUBST(LIBMODPLUG_BASENAME)
AC_SUBST(LIBMAD_BASENAME)
AC_SUBST(LIBOGG_BASENAME)
AC_SUBST(LIBVORBISENC_BASENAME)
AC_SUBST(LIBVORBIS_BASENAME)
AC_SUBST(LIBASS_BASENAME)
AC_SUBST(LIBMEPG2_BASENAME)
AC_SUBST_FILE(XBMC_STANDALONE_SH_PULSE)
AC_SUBST(USE_OPENGL)
AC_SUBST(USE_OPENGLES)
AC_SUBST(USE_VDPAU)
AC_SUBST(USE_VAAPI)
AC_SUBST(USE_CRYSTALHD)
AC_SUBST(USE_LIBSMBCLIENT)
AC_SUBST(USE_LIBNFS)
AC_SUBST(USE_LIBAFPCLIENT)
AC_SUBST(USE_AIRPLAY)
AC_SUBST(USE_OPENMAX)
AC_SUBST(USE_PULSE)
AC_SUBST(HAVE_LIBPULSE)
AC_SUBST(USE_XRANDR)
AC_SUBST(USE_ALSA)
AC_SUBST(USE_TEXTUREPACKER)
AC_SUBST(USE_AIRTUNES)
AC_SUBST(USE_LIBUDEV)
AC_SUBST(USE_LIBUSB)
AC_SUBST(USE_LIBCEC)
AC_SUBST(USE_MYSQL)
AC_SUBST(USE_WAYLAND)
AC_SUBST(USE_WEB_SERVER)
AC_SUBST(USE_UPNP)
AC_SUBST(USE_XKBCOMMON)
AC_SUBST(USE_OMXLIB)
AC_SUBST(USE_ANDROID)
AC_SUBST(GTEST_CONFIGURED)
AC_SUBST(USE_DOXYGEN)
AC_SUBST(USE_PVR_ADDONS)
AC_SUBST(GNUTLS_ALL_LIBS)
AC_SUBST(VORBISENC_ALL_LIBS)

# pushd and popd are not available in other shells besides bash, so implement
# our own pushd/popd functions
XB_DIRSTACK="$PWD"
xb_pushd()
{
  local dirname="$1"
  if [[ -d "$dirname" ]] && [[ -x "$dirname" ]]; then
    cd "$dirname"
    XB_DIRSTACK="$dirname ${XB_DIRSTACK:-$PWD}"
    return 0
  else
    AC_MSG_ERROR(xb_pushd: unable to change to $dirname)
  fi
}
xb_popd()
{
  if [[ -n "$XB_DIRSTACK" ]]; then
    XB_DIRSTACK="${XB_DIRSTACK#* }"
    cd "${XB_DIRSTACK%% *}"
    return 0
  else
    AC_MSG_ERROR(xb_popd: unable to go back to previous directory)
  fi
}

# Function to run the configure scripts in our submodules
# Consists of three paramaters, the path to the submodule, the configure command
# with appropriate arguments, and a third parameter set to 1 if we are to skip
# running the script, anything else if not.
AC_DEFUN([XB_CONFIG_MODULE],[
AC_CONFIG_COMMANDS_POST([
if [[ $3 != "1" ]]; then
    if [[ -d $1 ]]; then
      xb_pushd $1
      $2
      if [[ $? -ne 0 ]]; then
        xb_popd
        AC_MSG_ERROR([[Submodule $1 failed to configure]])
      else
        xb_popd
      fi
    else
      AC_MSG_ERROR([[Submodule $1 does not exist]])
    fi
else
    AC_MSG_NOTICE([[Skipping configuration of submodule $1.]])
fi
])
])

XB_CONFIG_MODULE([lib/ffmpeg], [
  if test "$host_vendor" = "apple" ; then
    ffmpg_config="--target-os=$ffmpeg_target_os"
    # handle disables first, we do individual enables later
    ffmpg_config="$ffmpg_config --disable-muxers   --disable-encoders"
    ffmpg_config="$ffmpg_config --disable-devices  --disable-doc"
    ffmpg_config="$ffmpg_config --disable-ffplay   --disable-ffmpeg"
    ffmpg_config="$ffmpg_config --disable-ffprobe  --disable-ffserver"
    ffmpg_config="$ffmpg_config --enable-vda       --disable-crystalhd"
    ffmpg_config="$ffmpg_config --disable-decoder=mpeg_xvmc"

    # handle conditional enables/disables
    if test "$use_debug" = "no"; then
      ffmpg_config="$ffmpg_config --disable-debug"
    fi
    if test "$use_cpu"  != "no";  then
      ffmpg_config="$ffmpg_config --cpu=$use_cpu"
    fi
    if test "$use_arch" != "no"; then
      ffmpg_config="$ffmpg_config --arch=$use_arch --enable-cross-compile"
    fi
    if test "$use_arch"  = "arm"; then
      ffmpg_config="$ffmpg_config --enable-pic"
      ffmpg_config="$ffmpg_config --disable-armv5te --disable-armv6t2"
      if test "$use_neon"  = "yes"; then
        ffmpg_config="$ffmpg_config --enable-neon"
      else
        ffmpg_config="$ffmpg_config --disable-neon"
      fi
    else
      ffmpg_config="$ffmpg_config --disable-amd3dnow"
    fi
    if test "$use_ffmpeg_libvorbis" = "yes"; then
      ffmpg_config="$ffmpg_config --enable-libvorbis --enable-muxer=ogg --enable-encoder=libvorbis"
    else
      ffmpg_config="$ffmpg_config --disable-libvorbis"
    fi
    if test "$have_gnutls" = "yes"; then
      ffmpg_config="$ffmpg_config --enable-gnutls"
    fi

    # handle individual enables
    ffmpg_config="$ffmpg_config --enable-gpl"
    ffmpg_config="$ffmpg_config --enable-postproc"
    ffmpg_config="$ffmpg_config --enable-static      --enable-pthreads"
    ffmpg_config="$ffmpg_config --enable-muxer=spdif --enable-muxer=adts --enable-muxer=asf --enable-muxer=ipod"
    ffmpg_config="$ffmpg_config --enable-encoder=ac3 --enable-encoder=aac --enable-encoder=wmav2"
    ffmpg_config="$ffmpg_config --enable-protocol=http"
    ffmpg_config="$ffmpg_config --enable-runtime-cpudetect"

    # ffmpeg will not compile with llvm-gcc-4.2, use clang instead
    case $CC in
      *llvm-gcc-4.2*)
        ffmpg_config="$ffmpg_config --cc=clang" ;;
      *)
        ffmpg_config="$ffmpg_config --cc=$CC" ;;
    esac
    
    # extra-cflags must be passed alone or it gets expanded wrong by the ffmpeg configure
    FFMPEG_EXTRACFLAGS="$CFLAGS $FFMPEG_EXTRACFLAGS -w -D_DARWIN_C_SOURCE -Dattribute_deprecated="

    LDFLAGS="$LDFLAGS" ./configure --extra-cflags="$FFMPEG_EXTRACFLAGS" $ffmpg_config --as="$AS"

    # if using llvm-gcc-4.2 as assembler, -MMD is not enough to generate
    # dependency files in the right place, replace it with something that works
    case $AS in
      *llvm-gcc-4.2*)
        sed -ie "s#AS_DEPFLAGS=-MMD#AS_DEPFLAGS=-MMD -MF \$(\@:.o=.d) -MT \$\@#" config.mak ;;
    esac

    # ffmpeg will use yasm found at ${prefix}/bin during configure
    # but then hardcodes 'yasm' in config.mak, fix it.
    sed -ie "s#YASM=yasm#YASM=${YASM}#" config.mak
    sed -ie "s#YASMDEP=yasm#YASMDEP=${YASM}#" config.mak
    sed -ie "s# -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 # #" config.mak
  else
    CFLAGS="" \
    CPPFLAGS="" \
    CXXFLAGS="" \
    LDFLAGS="$(echo "$LDFLAGS" | sed "s/-Wl,-Bsymbolic-functions//g")" \
    ./configure \
      --extra-cflags="$PASSED_CFLAGS $FFMPEG_EXTRACFLAGS" \
      `if test "$use_debug" = "no"; then echo --disable-debug; fi` \
      `if test "$cross_compiling" = "yes"; then echo --enable-cross-compile; fi` \
      `if test "$use_arch" != "no"; then echo --arch=$use_arch; fi`\
      `if test "$use_cpu" != "no"; then echo --cpu=$use_cpu; fi`\
      `if test "$use_neon" = "yes"; then echo --enable-neon; else echo --disable-neon; fi`\
      --target-os=$ffmpeg_target_os \
      --disable-muxers \
      --enable-muxer=spdif \
      --enable-muxer=adts \
      --enable-muxer=asf \
      --enable-muxer=ipod \
      --disable-encoders \
      --enable-encoder=ac3 \
      --enable-encoder=aac \
      --enable-encoder=wmav2 \
      `if test "$use_ffmpeg_libvorbis" = "yes"; then echo --enable-libvorbis --enable-muxer=ogg --enable-encoder=libvorbis; else echo --disable-libvorbis; fi` \
      --disable-decoder=mpeg_xvmc \
      --disable-devices \
      --disable-ffprobe \
      --disable-ffplay \
      --disable-ffserver \
      --disable-ffmpeg \
      --disable-crystalhd \
      `if test "$use_static_ffmpeg" = "yes"; then echo --enable-static --disable-shared; else echo --disable-static --enable-shared; fi` \
      --disable-doc \
      --enable-postproc \
      --enable-gpl \
      `if test "x$use_vdpau" != "xno"; then echo --enable-vdpau; else echo --disable-vdpau; fi` \
      `if test "x$use_vaapi" != "xno"; then echo --enable-vaapi; else echo --disable-vaapi; fi` \
      `if test "$use_optimizations" != "no"; then echo --enable-optimizations; else echo --disable-optimizations; fi` \
      --enable-protocol=http \
      `if test "$have_gnutls" = "yes"; then echo --enable-gnutls; fi` \
      --enable-pthreads \
      --enable-runtime-cpudetect \
      `if test "$use_hardcoded_tables" = "yes"; then echo --enable-hardcoded-tables; else echo --disable-hardcoded-tables; fi`\
      `if test "$target_platform" = "target_android"; then echo "--custom-libname-with-major=\\$(SLIBPREF)\\$(FULLNAME)-\\$(LIBMAJOR)-${ARCH}\\$(SLIBSUF)"; \
       else echo "--custom-libname-with-major=\\$(FULLNAME)-\\$(LIBMAJOR)-${ARCH}\\$(SLIBSUF)"; fi` \
      `case $host_cpu in i?86*) echo --disable-pic ;; *) echo --enable-pic ;; esac` \
      --cc="$CC" &&
      sed -i -e "s#define HAVE_SYMVER 1#define HAVE_SYMVER 0#" config.h &&
      sed -i -e "s#define HAVE_SYMVER_GNU_ASM 1#define HAVE_SYMVER_GNU_ASM 0#" config.h
  fi
], [$USE_EXTERNAL_FFMPEG])

XB_CONFIG_MODULE([lib/libdvd/libdvdcss], [
  ./configure \
    CC="$CC" \
    CXX="$CXX" \
    CFLAGS="$CFLAGS $DROID_DVDLIB_SEEK64" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --disable-doc \
    --enable-static \
    --with-pic
], [$SKIP_CONFIG_DVDCSS])

XB_CONFIG_MODULE([lib/libdvd/libdvdread], [
  ./configure2 \
    --extra-cflags="$CFLAGS $DVDREAD_CFLAGS -I`pwd`/../libdvdcss/src $DROID_DVDLIB_SEEK64" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --enable-static \
    --disable-shared \
    --disable-strip \
    --disable-opts \
    --cc="$CC" &&
  mkdir -p `pwd`/../includes/dvdread
  cp `pwd`/../libdvdread/src/*.h `pwd`/../includes/dvdread
  cp `pwd`/../libdvdread/src/dvdread/*.h `pwd`/../includes/dvdread
], [0])

XB_CONFIG_MODULE([lib/libdvd/libdvdnav], [
  ./configure2 \
    --extra-cflags="$CFLAGS $DVDREAD_CFLAGS -I`pwd`/../includes $DROID_DVDLIB_SEEK64" \
    --extra-ldflags="-L`pwd`/../libdvdread/obj" \
    --with-dvdread-config="`pwd`/../dvdread-config" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --enable-static \
    --disable-shared \
    --cc="$CC"
], [0])

XB_CONFIG_MODULE([xbmc/visualizations/XBMCProjectM/libprojectM],[
  set -x
  rm -f CMakeCache.txt &&                              \
  CC="$ORIGCC" CXX="$ORIGCXX" LDFLAGS="$LDFLAGS" cmake \
    -DCMAKE_BUILD_TYPE=None -DUSE_FTGL:BOOL=OFF        \
    -DCMAKE_C_FLAGS:STRING="${CPPFLAGS} ${CFLAGS}"     \
    -DCMAKE_CXX_FLAGS:STRING="${CPPFLAGS} ${CXXFLAGS}" \
    -DCMAKE_INSTALL_PREFIX="${prefix}"                 \
    -DCMAKE_INSTALL_LIBDIR:PATH="${libdir}"            \
    -DINCLUDE_INSTALL_DIR:PATH="${includedir}"         \
    -DLIB_INSTALL_DIR:PATH="${libdir}"                 \
    -DSYSCONF_INSTALL_DIR:PATH="${sysconfdir}"         \
    -DSHARE_INSTALL_PREFIX:PATH="${datadir}" . &&
  if test "$host_vendor" = "apple" ; then
    # cmake has hardcoded paths to macports which bork our darwin depends cross/ppc, remove them
    sed -ie "s|-L/opt/local/lib| |" CMakeFiles/projectM.dir/link.txt
    sed -ie "s|-L/opt/local/lib| |" CMakeFiles/projectM.dir/flags.make
    sed -ie "s|-I/opt/local/include| |" CMakeFiles/projectM.dir/flags.make
  fi
  set +x
], [$DISABLE_PROJECTM])

XB_CONFIG_MODULE([xbmc/visualizations/Goom/goom2k4-0],[
  ./configure  \
    CFLAGS="$CFLAGS" \ 
    CXXFLAGS="$CXXFLAGS" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --disable-shared \
    --enable-static \
    --with-pic
], [$DISABLE_GOOM])

XB_CONFIG_MODULE([xbmc/screensavers/rsxs-0.9/], [
  if test "$host_vendor" = "apple"; then
    # clang treats inlines different
    case $CC in
      *clang*)
        TEMPCFLAGS="$CFLAGS";;
      *)
        TEMPCFLAGS="${CFLAGS} -fgnu89-inline";;
    esac
  else
    TEMPCFLAGS="$CFLAGS";
  fi
  ./configure \
    CC="$CC" \
    CXX="$CXX" \
    CFLAGS="$TEMPCFLAGS" \ 
    CXXFLAGS="$CXXFLAGS" \
    `if test "$host_vendor" = "apple"; then echo --with-png=${prefix} --x-includes=/usr/X11/include --x-libraries=/usr/X11/lib; fi` \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \      
    --without-xscreensaver \
    --disable-sound \
    --disable-cyclone \
    --disable-fieldlines \
    --disable-flocks \
    --disable-flux \
    --disable-helios \
    --disable-hyperspace \
    --disable-lattice \
    --disable-skyrocket
  if echo "$ARCH" | grep -q freebsd ; then
    sed -i.back "s;\(STDBOOL_H = \)stdbool.h;\1;" lib/Makefile
  fi
], [$DISABLE_RSXS])

XB_CONFIG_MODULE([lib/cpluff], [
  ./configure --disable-nls \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias CFLAGS="$CFLAGS" CC="$CC" CXX="$CXX" LDFLAGS="$LDFLAGS" LIBS=""
    #LDFLAGS="$LDFLAGS -Wl,-read_only_relocs,suppress"    
], [0])

XB_CONFIG_MODULE([lib/gtest], [
  ./configure \
    CC="$CC" \
    CXX="$CXX" \
    CFLAGS="$CFLAGS" \
    --prefix="${prefix}" --includedir="${includedir}" --libdir="${libdir}" --datadir="${datadir}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \
    --disable-shared \
    --enable-static \
    --with-pthreads
], [$SKIP_CONFIG_GTEST])

XB_CONFIG_MODULE([pvr-addons], [
  ./configure \
    --prefix="${prefix}" \
    --host=$host_alias \
    --build=$build_alias \
    --target=$target_alias \
    CC="$CC" \
    CXX="$CXX" \
    CFLAGS="$CFLAGS" \
    CXXFLAGS="$CXXFLAGS"
], [$DISABLE_PVR_ADDON_CONFIG])

AC_OUTPUT

final_message="$final_message\n  prefix:\t$prefix\n$dashes"
echo -e "$final_message\n"