summaryrefslogtreecommitdiffstats
path: root/vlc/build/vlc.SlackBuild
blob: e52f28bb5dff041b3f0799420e9adfe4658dc3b8 (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
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
#!/bin/bash
# $Id$
# Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023  Eric Hameleers, Eindhoven, Netherlands
#
#   Permission to use, copy, modify, and distribute this software for
#   any purpose with or without fee is hereby granted, provided that
#   the above copyright notice and this permission notice appear in all
#   copies.
#
#   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
#   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#   IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
# -----------------------------------------------------------------------------
#
# Slackware SlackBuild script 
# ===========================
# By:         Eric Hameleers <alien@slackware.com>
# For:        vlc
# Descr:      multimedia player for various audio and video formats
# URL:        http://www.videolan.org/vlc/
# Buildneeds: apache-ant, java8, meson, ninja, python3
#             (Slackware 14.2: newer nasm)
# Needs:      (Slackware 14.2: OpenAL, SDL_sound, libxkbcommon, qt5,
#              libinput, libwacom)
#             libdvdcss for playing encrypted DVDs
# Changelog: 
# 0.8.6a-1:   15/Mar/2007 by Eric Hameleers <alien@slackware.com>
#             * Initial build.
# 0.8.6b-1:   25/apr/2007 by Eric Hameleers <alien@slackware.com>
#             * Update.
# 0.8.6c-1:   04/sep/2007 by Eric Hameleers <alien@slackware.com>
#             * Update. Allow vlc to be built without patented code (lame/amr).
# 0.8.6d-1:   12/dec/2007 by Eric Hameleers <alien@slackware.com>
#             * Update with a vulnerability bugfix. All external libraries
#               were updated to their most recent release.
#               This pkg adds support for firewire cameras, DV and DVB cards.
#               AMR audio codec is not supported in this build (I could not
#               create a vlc binary successfully).
#               Again, the resulting binary package requires no additional
#               non-Slackware packages, except for libdvdcss in case you want
#               to watch an encrypted DVD.
# 0.8.6d-2:   29/jan/2008 by Eric Hameleers <alien@slackware.com>
#             * Disable building AMR. The 0.8.6d official release does
#               not have support for AMR audio codec re-added yet.
#               Also, add the AAC en/decoder to the PATENTED software.
#               Build with dll loader support only on 32bit platform.
# 0.8.6e-1:   02/mar/2008 by Eric Hameleers <alien@slackware.com>
#             * New release fixes security issues.
# 0.8.6e-2:   23/mar/2008 by Eric Hameleers <alien@slackware.com>
#             * Update libebml; new ffmpeg,live555 snapshots
# 0.8.6f-1:   03/apr/2008 by Eric Hameleers <alien@slackware.com>
#             * New release (bugfixes). Also updated the snapshot for ffmpeg
# 0.8.6f-2:   03/apr/2008 by Eric Hameleers <alien@slackware.com>
#             * Updated the snapshot for ffmpeg
# 0.8.6g-1:   31/may/2008 by Eric Hameleers <alien@slackware.com>
#             * New release. Updated the snapshot for ffmpeg and live555,
#               updated libtheora.
# 0.8.6h-1:   10/jun/2008 by Eric Hameleers <alien@slackware.com>
#             * New release. Repaired the broken matroska support (thanks to
#               Thomas Morper who submitted a fix for the SlackBuild.
# 0.8.6h-2:   15/jun/2008 by Eric Hameleers <alien@slackware.com>
#             * Fixed the broken DTS audio codec support (did not play
#               6 channel sound here)
# 0.8.6h-3:   17/jun/2008 by Eric Hameleers <alien@slackware.com>
#             * Added Universal Plug'n'Play (upnp) client support.
#               Updated the live555 tarball to 20080605.
#               Updated the x264 snapshot- this now requires the yasm assembler
#               to be installed in order to compile successfully. If you don't
#               have/want that, set the variable REQUIRE_YASM to a value of "NO"
#               (see further down) so that the script will fall back to an older
#               x264 snapshot that does not require yasm to compile. Updated
#               libcdio to 0.80. Re-introduce AMR audio encoding to the package.
# 0.8.6i-1:   09/jul/2008 by Eric Hameleers <alien@slackware.com>
#             * New release. Also updated to the new lame-3.98.
# 0.9.1-1:    31/aug/2008 by Eric Hameleers <alien@slackware.com>
#             * The first in a new series of 0.9.x - these are source-only
#               releases for now, meaning that the developers are not yet
#               convinced 0.9.x is ready to replace 0.8.x.
#               Note that the vlc 0.9 releases fail to compile a static vlc.
#               According to the developers whis will not be fixed. Still, this
#               vlc package is without external dependencies as always ;-)
#               Updated lame to v3.89, speex to 1.2rc1 and libmpeg2 to 1.5.1.
#               Updated snapshots for ffmpeg to r14080; live555 to 2008.07.25;
#               started using libdvdread/libdvdnav releases from mplayerhq.hu.
#               For dirac video I now use the far better schroedinger instead
#               of the reference 'dirac' implementation.
#               I added documentation for all the libraries which I include.
#               Notes for package (re)builders:
#               The SlackBuild will by default use a static version of the Qt4
#               library. If you already have Qt4 installed, you may choose to
#               build vlc against that dynamic library; in that case run:
#                 # STATIC_QT4=NO ./vlc.SlackBuild
#               to build your vlc package.
#               If you already have ffmpeg installed and want to use that, run
#                 # STATIC_FFMPEG=NO ./vlc.SlackBuild
#               to build your vlc package.
#               Of course, if you have both QT4 and ffmpeg already available,
#               you can combine the above two commands to:
#                 # STATIC_QT4=NO STATIC_FFMPEG=NO ./vlc.SlackBuild
#               Lastly, it is worth noting that building any recent X264
#               library fails with Slackware 12.1 (and earlier)'s nasm.
#               Either install yasm, or let the script automatically fall back
#               to an older version of the X264 like this:
#                 # REQUIRE_YASM=NO ./vlc.SlackBuild
# 0.9.2-1:    10/sep/2008 by Eric Hameleers <alien@slackware.com>
#             * Updated to 0.9.2
# 0.9.3-1:    30/sep/2008 by Eric Hameleers <alien@slackware.com>
#             * Updated to 0.9.3
#               Fixed video playback thanks to phobos3576 of the slacky.eu
#               forum for finding the fix and Andrea Tornese for reporting it.
# 0.9.4-1:    07/oct/2008 by Eric Hameleers <alien@slackware.com>
#             * Updated to 0.9.4. Added libass to render 'formatted'
#               subtitles. Updated live555 to 2008.09.02. Updated the ffmpeg
#               snapshot to 20081007. Now default to using dynamically linked
#               QT4 (requires that you install a QT4 package yourself
#               prior to compiling VLC!)
# 0.9.5-1:    26/oct/2008 by Eric Hameleers <alien@slackware.com>
#             * Updated to 0.9.5. New snapshots for ffmpeg x264 added. QT4
#               compiled statically again because VLC is sensitive to the
#               version it builds against.
# 0.9.5-2:    29/oct/2008 by Eric Hameleers <alien@slackware.com>
#             * Re-enable embedded video display. Thanks to Thomas Morper who
#               verified that this works reliably with vlc-0.9.5 and qt-4.4.3 !
# 0.9.5-3:    05/nov/2008 by Eric Hameleers <alien@slackware.com>
#             * Updated libtheora to 1.0 and libcdio to 0.81
# 0.9.6-1:    08/nov/2008 by Eric Hameleers <alien@slackware.com>
#             * New release. Updated ffmpeg/x264 snapshots.
# 0.9.8-1:    02/dec/2008 by Eric Hameleers <alien@slackware.com>
#             * New release. Updated ffmpeg/x264/live555 versions. Added midi
#               playback support through fluidsynth
# 0.9.8a-1:   04/dec/2008 by Eric Hameleers <alien@slackware.com>
#             * VLC bugfix release... also took the opportunity to fix *my*
#               broken build of the dca and fluidsynth modules.
# 0.9.8a-2:   04/dec/2008 by Eric Hameleers <alien@slackware.com>
#             * Updated ffmpeg/x264 snapshots, and re-adding firewire support
# 0.9.8a-3:   28/dec/2008 by Eric Hameleers <alien@slackware.com>
#             * Updated ffmpeg/x264 snapshots, made it build on x86_64 with the
#               help of Attila Craciun.
# 20090307-1: 07/mar/2009 by Eric Hameleers <alien@slackware.com>
#             * Updated ffmpeg/x264/live55 snapshots, fix default font for
#               x86_64, fix DTS audio decoding on x86_64
# 0.9.9.rc2-1:18/mar/2009 by Eric Hameleers <alien@slackware.com>
#             * Building the first release candidate.
# 0.9.9.rc2-2:27/mar/2009 by Eric Hameleers <alien@slackware.com>
#             * Fix AAC decoding by removing "--with-drm"
# 0.9.9-1:    27/mar/2009 by Eric Hameleers <alien@slackware.com>
#             * Try to fix ffmeg video decoding as well as upgrade to 0.9.9;
#               apply several fixes taken from 1.0.0-git to fix x264 encoding.
# 1.0.0.pre2-1: 04/may/2009 by Eric Hameleers <alien@slackware.com>
#             * This is 1.0.0-pre2. I like it much more than the
#               'stable' 0.9.x. Furthermore, DVD playback was broken in
#               my 0.9.9 package, so I needed to release an update.
# 1.0.0.rc1-1: 11/may/2009 by Eric Hameleers <alien@slackware.com>
#             * The first release candidate for 1.0.0
# 1.0.0.rc2-1: 26/may/2009 by Eric Hameleers <alien@slackware.com>
#             * The second release candidate for 1.0.0
# 1.0.0.rc3-1: 09/jun/2009 by Eric Hameleers <alien@slackware.com>
#             * The third release candidate for 1.0.0
# 1.0.0.rc4-1: 18/jun/2009 by Eric Hameleers <alien@slackware.com>
#             * The fourth release candidate for 1.0.0.
#               Also updated live plugin to 2009.06.02
# 1.0.0-1:    06/jul/2009 by Eric Hameleers <alien@slackware.com>
#             * VLC 1.0.0 has been released!
# 1.0.1-1:    28/jul/2009 by Eric Hameleers <alien@slackware.com>
#             * An update that fixes a realrtsp vulnerability. Also updated
#               x264/live555 snapshots and added support for lua playlist,
#               metafetcher and interface plugins. By default, this script
#               no longer links Qt4 statically and instead links against an
#               already installed Qt libray.
# 1.0.1-2:    30/jul/2009 by Eric Hameleers <alien@slackware.com>
#             * Fix the swscale plugin
# 1.0.2-1:    19/sep/2009 by Eric Hameleers <alien@slackware.com>
#             * Update.
# 1.0.3-1:    31/oct/2009 by Eric Hameleers <alien@slackware.com>
#             * Update. New version of the theora encoder.
#               Other upgrades: libkate, schroedinger.
#               Downgraded libraw1394 to 1.2.0 which is the last 1.x version
#               found on sourceforge, now that the original linux1394.org site
#               has disappeared (using new download URL too).
# 1.0.3-2:    02/nov/2009 by Eric Hameleers <alien@slackware.com>
#             * Try to fix broken firewire support (libraw1394). Allow root to
#               run vlc.
# 1.0.3-3:    13/nov/2009 by Eric Hameleers <alien@slackware.com>
#             * Fix the broken fullscreen in KDE-4.3.3; added a newer snapshot
#               for live555 and x264.
# 1.0.3-4:    08/dec/2009 by Eric Hameleers <alien@slackware.com>
#             * Upgrade internal ffmpeg to latest SVN, and update the x86_64
#               assembler patch for ffmpeg to enable mmx/sse support which
#               (according to Thomas Morper who supplied the updated patch)
#               fixes choppy HD video playback. Disabled vdpau support because
#               that will not compile unless you have NVIDIA binary drivers
#               installed.
#               Also updated live555/x264 to their latest snapshots.
#               Switched to the GPL'ed opencore AMR codec (spin-off from
#               Google Android project). 
# 1.0.3-5:    10/dec/2009 by Eric Hameleers <alien@slackware.com>
#             * Make the dc1394 plugin work by patching VLC to use the new API.
# 1.0.4-1:    11/dec/2009 by Eric Hameleers <alien@slackware.com>
#             * New release. The ffmpeg/x264 snapshots were updated.
# 20091228-1: 28/dec/2009 by Eric Hameleers <alien@slackware.com>
#             * Test of git snapshot (1.1.git)
# 1.1.0.pre3-1: 01/may/2010 by Eric Hameleers <alien@slackware.com>
#             * Update to git snapshot 1.1.0.pre3. Also updated ffmpeg, live555
#               and x264 snapshots. Fixed the ffmpeg checkout so that we can
#               control what version of swscale gets used. Fixed the checkout
#               of vlc so that we can get a snapshot from any date,
#               not just HEAD. Updated fluidsynth plugin to 1.1.1. Updated
#               libdvbpci plugin to 0.1.7.
#               Updated to schroedinger 1.0.9 which is finally on par with
#               the dirac codec's speed and quality. Added projectM
#               visualisation plugin and re-enabled ggi plugin.
#               Added support for VAAPI, i.e. GPU-accelerated playback of H264.
#               Fixed the qt4 build so that it is really isolated from any
#               pre-existing qt4 installation on your computer. Used an
#               internal xulrunner sdk to build the mozilla-plugin.
#               Copy all patches used by this script into the package's
#               documentation directory.
#               If you want to control what version of VLC to checkout of GIT,
#               you should use the VERSION variable (older script used SRCVER).
# 1.1.0.pre4-1: 22/may/2010 by Eric Hameleers <alien@slackware.com>
#             * Update to git snapshot 1.1.0.pre4. Also updated ffmpeg and x264
#               snapshots. Changed from libv4l to v4l-utils.
# 20100523-1: 23/may/2010 by Eric Hameleers <alien@slackware.com>
#             * Update VLC snapshot to one that supports the new Google VP8.
#               Also apply webm patches to the ffmpeg snapshot. VLC can now
#               playback .webm files (but not encode yet as far as I know).
# 1.1.0.rc-1: 24/may/2010 by Eric Hameleers <alien@slackware.com>
#             * Update to the release candidate for 1.1.0. Fix VAAPI support
#               (now depends on external packages to supply the actual harware
#               drivers: libva (intel, als needed for nvidia & ati), and one of
#               vdpau-video (nvidia) or xvba-video (ati).
# 1.1.0.rc-2: 25/may/2010 by Eric Hameleers <alien@slackware.com>
#             * Upgrade to final release candidate (yes, sounds weird) and fix
#               a bug in displaying DVD menus
# 1.1.0.rc2-1:03/jun/2010 by Eric Hameleers <alien@slackware.com>
#             * Upgrade to 1.1.0 second release candidate.
#               Upgraded EBML/Matroska libraries to 0.8.0/0.9.0 (new release
#               after a long time).
# 20100609-1: 09/jun/2010 by Eric Hameleers <alien@slackware.com>
#             * Update VLC snapshot to try and get rid of segfaults in the
#               VAAPI routines. Also updated ffmpeg (now fully supports VP8
#               codec, so no additional patching required anymore) and x264
#               libraries, and live555.
# 1.1.0.rc3-1:11/jun/2010 by Eric Hameleers <alien@slackware.com>
#             * Upgrade to 1.1.0 third release candidate.
#               Unfortunately, I still see segfaults in VLC when VAAPI hardware
#               decoding support is activating by installing libva package...
# 1.1.0.rc3-2:13/jun/2010 by Eric Hameleers <alien@slackware.com>
#             * Add a patch to fix the VAAPI segfaults. My debugger backtrace
#               allowed fenrir to spot and repair the bug.
# 1.1.0.rc4-1:16/jun/2010 by Eric Hameleers <alien@slackware.com>
#             * Update to RC4 for the upcoming 1.1.0 release.
# 1.1.0-1:    21/jun/2010 by Eric Hameleers <alien@slackware.com>
#             * Official release of vlc 1.1.0.
#               ffmpeg was updated to 0.6 (another official release, yay);
#               x264 and libvpx were updated to a recent snapshot;
#               libebml, libmatroska, libcdio and orc were upgraded to their
#               newest versions.
# 20100714-1: 14/jul/2010 by Eric Hameleers <alien@slackware.com>
#             * Test build of what will be 1.1.1, with updated x264 and live555.
# 1.1.1-1:    20/jul/2010 by Eric Hameleers <alien@slackware.com>
#             * Official release of vlc 1.1.1.
# 1.1.3-1:    22/aug/2010 by Eric Hameleers <alien@slackware.com>
#             * Update to 1.1.3.
# 1.1.5-1:    12/nov/2010 by Eric Hameleers <alien@slackware.com>
#             * New release.
#               Enabled ncurses support.
#               Updated ffmpeg/libva/live555/schroedinger/x264 libraries.
#               Updated the xulrunner SDK used to compile the browser plugin.
# 1.1.5-2:    29/nov/2010 by Eric Hameleers <alien@slackware.com>
#             * Try to fix the segfault of goom visualization plugin on 32bit.
#               Fix projectM audio visualization for non-US locales.
# 1.1.5-3:    29/dec/2010 by Eric Hameleers <alien@slackware.com>
#             * Updated x264, libkate, libtiger, libass and libvpx, and used
#               the latest xulrunner for building the mozilla plugin.
# 20101230-1: 30/dec/2010 by Eric Hameleers <alien@slackware.com>
#             * With updated dependencies, it is time to test 1.2.0.git.
#               Starting with 1.2.0, the mozilla plugin has been separated
#               from the vlc sources and re-designed for stability. Its new
#               package name is "npapi-vlc". Upgrade an old vlc-mozplugin with
#               this new package!
# 20110827-1: 28/aug/2011 by Eric Hameleers <alien@slackware.com>
#             * With updated dependencies again. I Had to disable the stream
#               switcher because even with a patch it would give compilation
#               errors (vlc's configure does not enable it by default anyway).
# 20110910-1: 10/sep/2011 by Eric Hameleers <alien@slackware.com>
#             * Updated snapshots for vlcgit and x264.
# 20111006-1: 06/oct/2011 by Eric Hameleers <alien@slackware.com>
#             * Added (unencrypted) bluray playback support.
#               Updated the ffmpeg, lbvpx, live555, v4l and x264 support
#               libraries.
# 20111016-1: 16/oct/2011 by Eric Hameleers <alien@slackware.com>
#             * Updated internal bluray, dvdnav/dvdread, ebml/matroska,
#               live555, orc, x264 libraries.
#               Also updated to 20111016 snapshots of vlc and npapi-vlc.
# 20111114-1: 14/nov/2011 by Eric Hameleers <alien@slackware.com>
#             * Time to check out the status of 1.2.pre1 (already ten days of
#               development since that tag but still) and I took the liberty
#               to refresh a lot of the dependencies too:
#               I updated internal ass, bluray, dvbpsi, ffmpeg, fluidsynth,
#               kate, lame, live555, twolame, v4l-utils, x264 libraries.
#               Added internal fribidi library to satisfy the new libass
#               requirement.
# 20111202-1: 02/dec/2011 by Eric Hameleers <alien@slackware.com>
#             * Updated internal ffmpeg, libupnp, libmpc (switched to
#               recommended SVN tarball), x264 libraries.
#               Added librtmp and libgsm libraries to ffmpeg.
#               Froze the version of live555 to match the vlc patches.
# 20111223-1: 23/dec/2011 by Eric Hameleers <alien@slackware.com>
#             * Updated snapshot as well as internal ffmpeg, x264.
#               Patched LUA compiler to only use 32-bit LUAC file format.
#               Updated libbluray (now called 'first useable version' by the
#               developers), added builtin dvdcss support (if USE_PATENTS is
#               set to "YES")
# 2.0.0-1     17/feb/2012  by Eric Hameleers <alien@slackware.com>
#             * New release! Version 2.0 was originally named 1.2 but the
#               developers deciced that there were so many changes after 1.1.x
#               that a version bump to 2.0 would reflect this better.
#               The set of internal libraries was again updated to their most
#               recent versions. If you miss any library that I should add,
#               let me know!
# 2.0.1-1     17/mar/2012  by Eric Hameleers <alien@slackware.com>
#             * Update to 2.0.1 while keeping the internal dependencies
#               unchanged.
# 2.0.2-1     27/jun/2012  by Eric Hameleers <alien@slackware.com>
#             * New release. Further updates to internal bluray, ffmpeg, lame,
#               and x264 libraries.
# 2.0.3-1     25/jul/2012  by Eric Hameleers <alien@slackware.com>
#             * New release.
# 2.0.4-1     18/oct/2012  by Eric Hameleers <alien@slackware.com>
#             * New release. Updates to internal Shout, aacenc, amrwbenc, amr,
#               lua, upnp, v4l, x264 libraries.
#               Stop using internal xulrunner SDK to build the browser plugin,
#               Slackware's own seamonkey can do this now.
# 2.0.4-2     29/oct/2012  by Eric Hameleers <alien@slackware.com>
#             * Fix uPnP support by downgrading libupnp. Added opus encoder
#               support. Updated bluray, ffmpeg, vpx, x264 libraries. 
# 2.0.5-1     12/dec/2012  by Eric Hameleers <alien@slackware.com>
#             * Update. Rolled back the internal ffmpeg to snapshot r44967 
#               (git 82db8ee) (pre-planar) until the bugs caused by FFmpeg's
#               planar audio changes are fixed.
# 2.0.5-2     02/feb/2013  by Eric Hameleers <alien@slackware.com>
#             * Apply patch for VideoLAN-SA-1302 (critical vulnerability in
#               the ASF demuxer).
# 2.0.6-1     08/apr/2013  by Eric Hameleers <alien@slackware.com>
#             * New release. Updates to the internal ffmpeg fribidi live555
#               libvpx and x264 libraries.
# 2.0.6-2     12/apr/2013  by Eric Hameleers <alien@slackware.com>
#             * Fix the broken uPnP service discovery module which caused
#               audio stuttering in some videos.
# 2.0.7-1     28/may/2013  by Eric Hameleers <alien@slackware.com>
#             * New release. Build fixes for ARM, new snapshots for libdvdread
#               and libdvdnav (now maintained by VideoLAN) and a new attempt at
#               static linking of DVDCSS.
# 2.0.8-1     10/aug/2013  by Eric Hameleers <alien@slackware.com>
#             * New release.
# 20130818-1  19/aug/2013  by Eric Hameleers <alien@slackware.com>
#             * Pre-release. Removed the internal v4l-utils since Slackware's
#               own is good enough. Many upgrades to internal libraries:
#               ffmpeg, fluidsynth, libass, libcdio, libdc1394, libdvbpsi,
#               libebml, libmatroska, libva, opus, orc, schroedinger,
#               vcdimager, vo-amrwbenc, x264.
# 2.1.0-1     26/sep/2013  by Eric Hameleers <alien@slackware.com>
#             * New release: 2.1.0!
# 2.1.1-1     16/nov/2013  by Eric Hameleers <alien@slackware.com>
#             * Bugfix release. Internal updates for ass, ffmpeg, matroska,
#               x264; added taglib to replace the old Slackware library.
# 2.1.2-1     10/dec/2013  by Eric Hameleers <alien@slackware.com>
#             * New release. Enable 10-bit decoder in x624.
#               Updates to bluray, dvdnav, dvdread, ffmpeg, fribidi, live555,
#               opus, speex, x264.
# 2.1.2-2     11/dec/2013  by Eric Hameleers <alien@slackware.com>
#             * Add VDPAU driver.
# 2.1.2-3     13/dec/2013  by Eric Hameleers <alien@slackware.com>
#             * Fixed the unexpectedly introduced external dependency on
#               shared libvdpau libraries - vlc will now work again
#               even if you do not have libvdpau installed.
#               Also, fixed the (long) broken rtmp support.
# 2.1.2-4     20/jan/2014  by Eric Hameleers <alien@slackware.com>
#             * Fixed stuttering video in digital video streams by reverting
#               to an older libdvbpsi source. Updated the ffmpeg snapshot.
# 2.1.3-1     04/feb/2014  by Eric Hameleers <alien@slackware.com>
#             * New release with updates to internal live555 library and npapi
#               browser plugin.
#               I tried a more recent ffmpeg but that breaks mpeg4 playback
#               with vdpau gpu hardware decoding.
# 2.1.4-1     26/feb/2014  by Eric Hameleers <alien@slackware.com>
#             * New release. No updates to internal libraries.
# 2.1.5-1     02/aug/2014  by Eric Hameleers <alien@slackware.com>
#             * New release. Updates to internal libraries: ass, ffmpeg,
#               dvdnav, dvdread, live555, x264.
# 2.2.0-1     27/feb/2015  by Eric Hameleers <alien@slackware.com>
#             * First release of 2.2.
#               New libraries: asdcplib, speexdsp, x262, x265.
#               Updates for ffmpeg, libass, libbluray, libdvbpsi, libdvdcss,
#               libdvdnav, libdvdread, libebml, libmatroska, libupnp, libvdpau,
#               live, orc, speex, vo-aacenc, x264.
# 2.2.0-2     01/mar/2015  by Eric Hameleers <alien@slackware.com>
#             * Fix hardware video decoding for hybrid cards (thanks manciuleas)
# 2.2.1-1     14/apr/2015  by Eric Hameleers <alien@slackware.com>
#             * New release.
# 2.2.1-2     04/may/2015  by Eric Hameleers <alien@slackware.com>
#             * Rebuilt for -current where libkate would not compile.
# 2.2.1-3     25/jun/2015  by Eric Hameleers <alien@slackware.com>
#             * Updates for ffmpeg, libbluray, libva, libvdpau to try and fix
#               performance & tearing issues on gpu-accelerated video playback.
# 2.2.1-4     26/aug/2015  by Eric Hameleers <alien@slackware.com>
#             * Rebuilt for Slackware-current with updates to the internal
#               libbluray, ffmpeg, libva, live555 and vdpau libraries.
# 2.2.2-1     10/feb/2016  by Eric Hameleers <alien@slackware.com>
#             * New release.
# 2.2.2-2     22/feb/2016  by Eric Hameleers <alien@slackware.com>
#             * Rebuilt slackware-current version without Qt5 dependency.
# 2.2.4-1     07/jul/2016  by Eric Hameleers <alien@slackware.com>
#             * Update. New versions of internal support libraries: x262,
#               opus, libva and libmpcdec.
# 2.2.5.1-1   24/may/2017  by Eric Hameleers <alien@slackware.com>
#             * Update.
# 2.2.6-1     25/may/2017  by Eric Hameleers <alien@slackware.com>
#             * Update.
# 2.2.6-2     26/oct/2017  by Eric Hameleers <alien@slackware.com>
#             * Rebuilt for -current to fix broken TLS support.
# 2.2.8-1     29/nov/2017  by Eric Hameleers <alien@slackware.com>
#             * Update. New versions of internal support libraries:
#               bluray, dvbpsi, ebml, ffmpeg, lame, matroska, opus, ssh2,
#               vaapi, x262, x264, x265.
#               Removed: orc/schroedinger (no longer developed).
#               Removed: libggi (obsoleted, unsupported).
#               Removed: aacenc, faad2/faac libraries (not used anymore).
# 2.2.8-2     06/dec/2017  by Eric Hameleers <alien@slackware.com>
#             * Add a switch "USE_FFMPEG3" which defaults to "NO" and add
#               back the code that adds the older ffmpeg2 engine to the vlc
#               package instead of using the new ffmpeg3 snapshot.
#               Use the following command to compile a package using the
#               ffmpeg3 libraries internally:
#               USE_FFMPEG3=YES ./vlc.SlackBuild
#               Note: using the ffmpeg3 branch seems to cause segfaults
#                     in combination with hardware-assisted decoding.
# 2.2.8-3     02/jan/2018  by Eric Hameleers <alien@slackware.com>
#             * Fix hardware decoding in ffmpeg3 variant.
# 20180106-1  06/jan/2018  by Eric Hameleers <alien@slackware.com>
#             * VLC 3 is a major release update. The 20180106 git snapshot
#               is near 3.0.0-rc5.
#               - Now uses Qt5 for its GUI.
#               - Decoding engine uses ffmpeg3 codebase, so picking ffmpeg2
#                 instead is no longer an option.
#               - Updates to several internal libraries: ffmpeg, libass,
#                 libbluray, live555, libssh2, x262, x264.
#               - New internal libraries: microdns, sdm, srt.
#               - Removed libraries: aacenc, daap, faad, faac, vcdimager.
#               - Incorporating static Qt libraries into the package is
#                 no longer supported by the SlackBuild.  You need to install
#                 libxkbcommon, qt5, qt5-webkit packages separately.
# 20180120-1  21/jan/2018  by Eric Hameleers <alien@slackware.com>
#             * VLC 3.0.0 RC7 testing.
# 3.0.0-1     09/feb/2018  by Eric Hameleers <alien@slackware.com>
#             * VLC 3.0.0 released!
# 3.0.0-2     13/feb/2018  by Eric Hameleers <alien@slackware.com>
#             * Enable chromecast.
# 3.0.2-1     21/apr/2018  by Eric Hameleers <alien@slackware.com>
#             * Update.
# 3.0.2-2     19/may/2018  by Eric Hameleers <alien@slackware.com>
#             * Rebuilt due to libidn2/openssl update in -current.
#               Also updated internal libraries: asdcp, dca, dsm, dvbpsi, x265.
# 3.0.3-1     29/may/2018  by Eric Hameleers <alien@slackware.com>
#             * Update.
# 3.0.4-1     07/sep/2018  by Eric Hameleers <alien@slackware.com>
#             * Update.
# 3.0.6-1     12/jan/2019  by Eric Hameleers <alien@slackware.com>
#             * Update. Added the dav1d (AV1 video) decoder.
# 3.0.7-1     25/may/2019  by Eric Hameleers <alien@slackware.com>
#             * Update.
# 3.0.8-1     30/aug/2019  by Eric Hameleers <alien@slackware.com>
#             * Update. Also updated some of the internal libraries:
#               bluray, dav1d, ebml and matroska.
#               Removed the NPAPI plugin.
# 3.0.10-1    27/apr/2020  by Eric Hameleers <alien@slackware.com>
#             * Update. Also updated some of the internal libraries:
#               bluray, dav1d, dca, dsm, dvdnav, dvdread, ebml, fribidi, mdns.
# 3.0.11.1-1  16/sep/2020  by Eric Hameleers <alien@slackware.com>
#             * Update. Also updated internal libraries:
#               dav1d, ebml, matroska, vpx
# 3.0.12-1    23/jan/2021  by Eric Hameleers <alien@slackware.com>
#             * Update. Also updated internal libraries: bluray, dav1d.
# 3.0.16-1    03/dec/2021  by Eric Hameleers <alien@slackware.com>
#             * Update. Also updated internal libraries: bluray, dav1d,
#               dvdnav, dvdread, dvdcss, ebml, libva, matroska, opus, pcre2,
#               speexdsp, ssh2, vpx. Added patches to internal ffmpeg.
# 3.0.17.4-1  22/jul/2022  by Eric Hameleers <alien@slackware.com>
#             * Update. Also updated internal libraries: ass, bluray, dav1d,
#               dsm, dvdread, ffmpeg (to 4.4), fribidi, srt, twolame and x265.
# 3.0.18-1    15/apr/2023  by Eric Hameleers <alien@slackware.com>
#             * Update. Also updated internal libraries: bluray, dav1d, ffmpeg,
#               glew, libva, speex, upnp, vdpau, vlx and x265.
# 3.0.19-1    13/oct/2023  by Eric Hameleers <alien@slackware.com>
#             * Update. Added soxr audio-resampler and libplacebo which is
#               required for 4K HDR tone-mapping. Also updated internal
#               libraries: dav1d, ffmpeg, libva, shout, upnp, vpx.
#
# Run 'sh vlc.SlackBuild' to build a Slackware package.
# The package (.txz) plus descriptive .txt file are created in /tmp .
# Install using 'installpkg'. 
#
# -----------------------------------------------------------------------------

#
# NOTE: this SlackBuild is a monster - it tries to wrap all dependencies to
# vlc into the resulting package by building these deps as static libraries
# and then in the final stage linking vlc against all the static libraries.
# The resulting package has all the vlc functionality and does not depend on
# any software that is not present in a standard full install of Slackware.
# This makes my package quite different from all the other vlc builds that are
# floating around on the Internet.
# /Eric Hameleers/
#

# -----------------------------------------------------------------------------
# Set initial variables:

PRGNAM=vlc
BUILD=${BUILD:-1}
NPBUILD=${NPBUILD:-1}
TAG=${TAG:-"alien"}

PKGTYPE=${PKGTYPE:-"txz"}
SLACKVER=${SLACKVER:-$(cat /etc/slackware-version| cut -d' ' -f2)}

# -----------------------------------------------------------------------------
# VERSION value may be modified later!
# * If VERSION is set to "HEAD" or to any value starting with "20",
#   (i.e. a "yyyymmdd" date format like "20100319") then you get
#   a git snapshot of the 'master' branch;
# * A format of "branchname#" or "branchname#yymmdd" means you will get a
#   checkout from branch "branchname", optionally from the specified date.
# * Else we look for the tarball for $VERSION in vlc's official releases.
#
# Hint: checkout at a certain date takes a snapshot at 00:00, not 23:59)
#
# Acceptible formats:
#VERSION=${VERSION:-"3.0.0"}
#VERSION=${VERSION:-"20180103"}
#VERSION=${VERSION:-"HEAD"}
#VERSION=${VERSION:-"master#20180103"}
#VERSION=${VERSION:-"@3.0.0#20180102"}
#VERSION=${VERSION:-"master@git://git.videolan.org/vlc/vlc-3.0.git#20180102"}
#
# And then you can specify a package version explicitly if you want to
# override the default which equals "$VERSION":
#PKGVERSION="xxx"
# -----------------------------------------------------------------------------

VLCBRANCH=${VLCBRANCH:-"3.0.x"}
DEFGITURI=${GITURI:-"https://code.videolan.org/videolan/vlc.git"}
VERSION=${VERSION:-"3.0.19"}
PKGVERSION=${VERSION}
#VLCMINOR=${VLCMINOR:-"19"}
#PKGVERSION=${PKGVERSION:-"${VLCBRANCH}.${VLCMINOR}"}

DOCS="ABOUT-NLS AUTHORS COPYING COPYING.LIB ChangeLog INSTALL NEWS README THANKS"

NUMJOBS=${NUMJOBS:-"-j$(nproc)"}  # Number of parallel jobs for the compiler 

# Automatically determine the architecture we're building on:
if [ -z "$ARCH" ]; then
  case "$(uname -m)" in
    i?86) ARCH=i586 ;;
    arm*) readelf /usr/bin/file -A | egrep -q "Tag_CPU.*[4,5]" && ARCH=arm || ARCH=armv7hl ;;
    # Unless $ARCH is already set, use uname -m for all other archs:
    *) ARCH=$(uname -m) ;;
  esac
  export ARCH
fi

case "$ARCH" in
  i?86)      SLKCFLAGS="-O2 -march=${ARCH} -mtune=i686"
             SLKLDFLAGS=""; LIBDIRSUFFIX=""
             ;;
  x86_64)    SLKCFLAGS="-O2 -fPIC"
             SLKLDFLAGS="-L/usr/lib64"; LIBDIRSUFFIX="64"
             ;;
  armv7hl)   SLKCFLAGS="-O2 -fPIC -march=armv7-a -mfpu=vfpv3-d16"
             SLKLDFLAGS=""; LIBDIRSUFFIX=""
             ;;
  *)         SLKCFLAGS="-O2"
             SLKLDFLAGS=""; LIBDIRSUFFIX=""
             ;;
esac

case "$ARCH" in
    arm*) TARGET=$ARCH-slackware-linux-gnueabi ;;
    *)    TARGET=$ARCH-slackware-linux ;;
esac

# -----------------------------------------------------------------------------

# -- PATENT ALERT! --
# FFmpeg can be built with AAC encoding but this has patent & license issues.
# You can build these patended algorithms into ffmpeg, and if you are an
# ordinary end user, no one will bother you for using them.
# For the binaries based on this SlackBuild that I distribute, it is a
# different story. I am not allowed to distribute binary packages to the US
# that incorporate patented code. So here you go.
USE_PATENTS=${USE_PATENTS:-"YES"}
USE_PATENTS=$(echo $USE_PATENTS | tr 'a-z' 'A-Z')

# VLC requires Qt5 for its GUI.
# Slackware older than 15.0 does not include Qt5, so on those
# releases, we need to include the Qt5 librarieus into the package.
# In that case, define STATIC_QT5="YES", else the package will depend on
# the presence of the system version of Qt5.
# BIG FAT WARNING: STATIC QT5 DOES NOT WORK CURRENTLY
STATIC_QT5=${STATIC_QT5:-"NO"}
STATIC_QT5=$(echo $STATIC_QT5 | tr 'a-z' 'A-Z')

# VLC uses ffmpeg's avcodec for a lot of the AV processing.
# If you already have ffmpeg installed, it will speed up the compilation,
# and create a smaller vlc package, if you define STATIC_FFMPEG="NO":
# Note: I _strongly_ suggest you compile ffmpeg statically!
STATIC_FFMPEG=${STATIC_FFMPEG:-"YES"}
STATIC_FFMPEG=$(echo $STATIC_FFMPEG | tr 'a-z' 'A-Z')

# Let VLC link dynamically to libva* and libvdpau if those are present:
if pkg-config --exists libva 2>/dev/null ; then
  STATIC_LIBVA=${STATIC_LIBVA:-"NO"}
else
  STATIC_LIBVA=${STATIC_LIBVA:-"YES"}
fi

# Explicitly enable pulseaudio or it will not be picked up by ffmpeg:
if pkg-config --exists libpulse 2>/dev/null ; then
  USE_PULSE="--enable-libpulse"
else
  USE_PULSE=""
fi

# Allow override of development tools:
export CC=${CC:-"gcc"}
export CPP=${CPP:-"cpp"}
export CXX=${CXX:-"g++"}
export AR=${AR:-"gcc-ar"}
export NM=${NM:-"gcc-nm"}
export RANLIB=${RANLIB:-"gcc-ranlib"}

# -----------------------------------------------------------------------------
# We're done with the initials. Let's move on:
# -----------------------------------------------------------------------------

A52=0.7.4
AMRWBENC=0.1.3
AMR=0.1.3
ASDCPLIB=2.7.19
ASS=0.16.0
AVC1394=0.5.4
BLURAY=1.3.2
CDDB=1.3.2
CDIO=0.90
DAV1D=1.3.0
DC1394=2.2.1
DCA=0.0.7
DSM=0.4.3
DV=1.0.0
DVBPSI=1.3.2
DVDNAV=6.1.1
DVDREAD=6.1.3
DVDCSS=1.4.3
EBML=1.4.2
FFMPEG=4.4.3
FLUID=1.1.6
FRIBIDI=1.0.12
GII=1.0.2
GLEW=2.2.0
GOOM=2k4-0
GSM=1.0.16
KATE=0.4.1
LAME=3.100
LIBVA=2.20.0
LIVE=2016.11.28
LUA=5.1.5
MATROSKA=1.6.3
MDNS=0.1.2
MPCDEC=r481
MPEG2DEC=0.5.1
OPUS=1.3
PCRE2=10.39
PLACEBO=5.264.1
PROJECTM=2.0.1
PROTOBUF=3.1.0
QT5=5.7.1
RAW1394=2.0.5
SHOUT=2.4.6
SOXR=0.1.3
SPEEX=1.2.1
SPEEXDSP=1.2.1
SRT=1.4.4
SSH2=1.10.0
TAGLIB=1.11.1
THEORA=1.1.1
TIGER=0.3.4
TWOLAME=0.4.0
UPNP=1.14.15
VDPAU=1.5
VPX=1.13.1
X262=20180907
X264=20180907-2245
X265=3.5

# Where do we look for sources?
SRCDIR=$(cd $(dirname $0); pwd)

# Place to build (TMP) package (PKG) and output (OUTPUT) the program:
TMP=${TMP:-"/tmp/build"}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-"/tmp"}

# This is where we are going to temporarily install the dependencies:
VLCDEPSDIR="$TMP/tmp-$PRGNAM/vlcdeps"

# Building bluray plugin requires Apache Ant:
if ! which ant 1>/dev/null 2>/dev/null ; then
  echo "+++ ANT not present - the build will abort on compiling bluray support! +++"
  echo "+++ Press Ctrl-C within 10 seconds, install 'apache-ant' and login again. +++"
  sleep 10
fi

# Building dav1d, dsm, fribidi plugins requires meson/ninja/python3:
if ( ! which meson || ! which ninja || ! which python3 ) 1>/dev/null 2>/dev/null ; then
  echo "+++ MESON, NINJA and/or PYTHON3 not present - the build will abort on compiling dav1d encoder! +++"
  echo "+++ Press Ctrl-C within 10 seconds, install 'meson', 'ninja' and 'python3' and try again. +++"
  sleep 10
fi

# ---------------------------------------------------------------------------
# Source tarballs and source URLs.
# Sources which are not patented should have SRCPAT[n]="NO"
# Sources which are patented should have SRCPAT[n]="YES" which prevents then
#   from being downloaded and used if we build a patent-free package.
# ---------------------------------------------------------------------------

# VLC source
if [ "$VERSION" == "HEAD"  ]; then
  # We check out git's HEAD:
  BRANCH="master"
  GITURI=${DEFGITURI}
  SRCVER=$(date +%Y%m%d)
  SRCURL[0]=""
elif [ "$(echo $VERSION | cut -c1-2)" == "20"  ]; then
  # We check out git at a specific date:
  BRANCH="master"
  GITURI=${DEFGITURI}
  SRCVER=$VERSION
  SRCURL[0]=""
elif [ "$(echo $VERSION| cut -d# -f2)" != "$VERSION"  ]; then
  # VERSION has a hashmark it it (branchname@gituri#datestamp)
  BRANCH="$(echo $VERSION| cut -d# -f1 |cut -d@ -f1)"
  GITURI="$(echo $VERSION| cut -d# -f1 |cut -d@ -f2-)"
  SRCVER="$(echo $VERSION| cut -d# -f2)"
  if [ "x$GITURI" = "x$BRANCH" -o "x$GITURI" = "x" ]; then
    GITURI=${DEFGITURI}
  fi
  if [ "x$BRANCH" = "x" ]; then BRANCH="master" ; fi
  if [ "x$SRCVER" = "x" ]; then SRCVER=$(date +%Y%m%d) ; fi
  SRCURL[0]=""
else
  BRANCH=""
  GITURI=""
  SRCVER=$VERSION
  SRCURL[0]="http://download.videolan.org/pub/videolan/${PRGNAM}/${SRCVER}/${PRGNAM}-${SRCVER}.tar.xz"
fi
SOURCE[0]="$SRCDIR/sources/${PRGNAM}-${SRCVER}.tar.xz"
SRCPAT[0]="NO"
USE[0]="YES"

# ffmpeg libraries
SOURCE[1]="$SRCDIR/sources/ffmpeg-${FFMPEG}.tar.xz"
SRCURL[1]="https://ffmpeg.org/releases/ffmpeg-${FFMPEG}.tar.xz"
#SRCURL[1]=""
SRCPAT[1]="NO"
USE[1]="YES"

# AMR de/encoder libraries used in ffmpeg to encode 3GPP audio
SOURCE[2]="$SRCDIR/sources/opencore-amr-${AMR}.tar.gz"
SRCURL[2]="http://downloads.sourceforge.net/opencore-amr/opencore-amr-${AMR}.tar.gz"
SRCPAT[2]="NO"
USE[2]="YES"

# Lame is used for the audio in FLV videos; will statically link with ffmpeg
SOURCE[3]="$SRCDIR/sources/lame-$LAME.tar.gz"
SRCURL[3]="http://downloads.sourceforge.net/lame/lame-$LAME.tar.gz"
SRCPAT[3]="NO"
USE[3]="YES"

# Libtiger - A rendering library for Kate streams using Pango and Cairo
SOURCE[4]="$SRCDIR/sources/libtiger-${TIGER}.tar.gz"
SRCURL[4]="https://download.videolan.org/pub/contrib/tiger/libtiger-${TIGER}.tar.gz"
SRCPAT[4]="NO"
USE[4]="YES"

# Lua - embedded interpreter for lua playlist, metafetcher and interface plugins
SOURCE[5]="$SRCDIR/sources/lua-${LUA}.tar.gz"
SRCURL[5]="http://www.lua.org/ftp/lua-${LUA}.tar.gz"
SRCPAT[5]="NO"
USE[5]="YES"

# Kate - a karaoke/text stream overlay codec
SOURCE[6]="$SRCDIR/sources/libkate-${KATE}.tar.gz"
SRCURL[6]="https://download.videolan.org/pub/contrib/kate/libkate-${KATE}.tar.gz"
SRCPAT[6]="NO"
USE[6]="YES"

# DV video, used by most digital (firewire) camcorders:
SOURCE[7]="$SRCDIR/sources/libdv-${DV}.tar.gz"
SRCURL[7]="http://downloads.sourceforge.net/libdv/libdv-${DV}.tar.gz"
SRCPAT[7]="NO"
USE[7]="YES"

# Unicode BiDirectional algorithm library, requirement for libass.
SOURCE[8]="$SRCDIR/sources/fribidi-${FRIBIDI}.tar.xz"
SRCURL[8]="https://github.com/fribidi/fribidi/releases/download/v${FRIBIDI}/fribidi-${FRIBIDI}.tar.xz"
SRCPAT[8]="NO"
USE[8]="YES"

# HEVC (X.265) codec:
SOURCE[9]="$SRCDIR/sources/x265_${X265}.tar.gz"
SRCURL[9]="https://bitbucket.org/multicoreware/x265_git/downloads/x265_${X265}.tar.gz"
SRCPAT[9]="NO"
USE[9]="YES"

# MPEG-2 Part 2 (X.262) codec:
SOURCE[10]="$SRCDIR/sources/x262-${X262}.tar.gz"
SRCURL[10]=""
SRCPAT[10]="NO"
USE[10]="YES"

# Matroska support:
SOURCE[11]="$SRCDIR/sources/libebml-$EBML.tar.xz"
SRCURL[11]="http://dl.matroska.org/downloads/libebml/libebml-$EBML.tar.xz"
SRCPAT[11]="NO"
USE[11]="YES"

SOURCE[12]="$SRCDIR/sources/libmatroska-$MATROSKA.tar.xz"
SRCURL[12]="http://dl.matroska.org/downloads/libmatroska/libmatroska-$MATROSKA.tar.xz"
SRCPAT[12]="NO"
USE[12]="YES"

# libmpeg2
SOURCE[13]="$SRCDIR/sources/libmpeg2-$MPEG2DEC.tar.gz"
SRCURL[13]="http://libmpeg2.sourceforge.net/files/libmpeg2-$MPEG2DEC.tar.gz"
SRCPAT[13]="NO"
USE[13]="YES"

# DVD support:
SOURCE[14]="$SRCDIR/sources/libdvdnav-$DVDNAV.tar.bz2"
SRCURL[14]="http://download.videolan.org/pub/videolan/libdvdnav/${DVDNAV}/libdvdnav-${DVDNAV}.tar.bz2"
#SRCURL[14]=""
SRCPAT[14]="NO"
USE[14]="YES"

SOURCE[15]="$SRCDIR/sources/libdvdread-${DVDREAD}.tar.bz2"
SRCURL[15]="http://download.videolan.org/pub/videolan/libdvdread/${DVDREAD}/libdvdread-${DVDREAD}.tar.bz2"
#SRCURL[15]=""
SRCPAT[15]="NO"
USE[15]="YES"

# CD media read/access support (including iso/cue/nrg formats):
SOURCE[16]="$SRCDIR/sources/libcdio-${CDIO}.tar.gz"
SRCURL[16]="http://ftp.gnu.org/gnu/libcdio/libcdio-$CDIO.tar.gz"
SRCPAT[16]="NO"
USE[16]="YES"

# speex dsp implementation:
SOURCE[17]="$SRCDIR/sources/speexdsp-${SPEEXDSP}.tar.gz"
SRCURL[17]="http://downloads.us.xiph.org/releases/speex/speexdsp-${SPEEXDSP}.tar.gz"
SRCPAT[17]="NO"
USE[17]="YES"

# MP2 audio (de)coding support:
SOURCE[18]="$SRCDIR/sources/twolame-${TWOLAME}.tar.gz"
SRCURL[18]="http://downloads.sourceforge.net/twolame/twolame-$TWOLAME.tar.gz"
SRCPAT[18]="NO"
USE[18]="YES"

# Musepack (MPC) audio demuxing support:
SOURCE[19]="$SRCDIR/sources/libmpcdec-${MPCDEC}.tar.gz"
SRCURL[19]="http://download.videolan.org/pub/contrib/musepack_src_${MPCDEC}.tar.gz"
SRCPAT[19]="NO"
USE[19]="YES"

# GLEW needs to be compiled statically to prevent a clash in newer Slackware±
SOURCE[20]="$SRCDIR/sources/glew-${GLEW}.tgz"
SRCURL[20]="http://downloads.sourceforge.net/glew/${GLEW}/glew-${GLEW}.tgz"
SRCPAT[20]="NO"
USE[20]="YES"

# SFTP access through libssh2:
SOURCE[21]="$SRCDIR/sources/libssh2-${SSH2}.tar.gz"
SRCURL[21]="http://www.libssh2.org/download/libssh2-${SSH2}.tar.gz"
SRCPAT[21]="NO"
USE[21]="YES"

# CDDB lookups:
SOURCE[22]="$SRCDIR/sources/libcddb-${CDDB}.tar.bz2"
SRCURL[22]="http://downloads.sourceforge.net/libcddb/libcddb-${CDDB}.tar.bz2"
SRCPAT[22]="NO"
USE[22]="YES"

# Act as a source client to Icecast/Shoutcast:
SOURCE[23]="$SRCDIR/sources/libshout-${SHOUT}.tar.gz"
SRCURL[23]="http://downloads.us.xiph.org/releases/libshout/libshout-${SHOUT}.tar.gz"
SRCPAT[23]="NO"
USE[23]="YES"

# SPEEX is used by libshout and vlc:
SOURCE[24]="$SRCDIR/sources/speex-${SPEEX}.tar.gz"
SRCURL[24]="http://downloads.us.xiph.org/releases/speex/speex-${SPEEX}.tar.gz"
#SRCURL[24]="http://git.xiph.org/?p=speex.git;a=snapshot;h=${SPEEX};sf=tgz"
SRCPAT[24]="NO"
USE[24]="YES"

# Goom, a visualisation library for audio player
SOURCE[25]="$SRCDIR/sources/goom-${GOOM}-src.tar.gz"
SRCURL[25]="http://downloads.sourceforge.net/goom/goom-${GOOM}-src.tar.gz"
SRCPAT[25]="NO"
USE[25]="YES"

# Taglib for audio files:
SOURCE[26]="$SRCDIR/sources/taglib-${TAGLIB}.tar.gz"
SRCURL[26]="http://taglib.github.io/releases/taglib-${TAGLIB}.tar.gz"
SRCPAT[26]="NO"
USE[26]="YES"

# X264 encoder - for H264/AVC video streams
SOURCE[27]="$SRCDIR/sources/x264-snapshot-${X264}-stable.tar.bz2"
SRCURL[27]="https://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-${X264}-stable.tar.bz2"
SRCPAT[27]="NO"
USE[27]="YES"

# The A52 decoder - aka AC3
SOURCE[28]="$SRCDIR/sources/a52dec-$A52.tar.gz"
SRCURL[28]="http://liba52.sourceforge.net/files/a52dec-$A52.tar.gz"
SRCPAT[28]="NO"
USE[28]="YES"

# Live555 support:
SOURCE[29]="$SRCDIR/sources/live.${LIVE}.tar.gz"
SRCURL[29]="https://download.videolan.org/contrib/live555/live.${LIVE}.tar.gz"
SRCPAT[29]="NO"
USE[29]="YES"

# Library needed to control IEEE 1394 (firewire-) based cameras
SOURCE[30]="$SRCDIR/sources/libraw1394-${RAW1394}.tar.gz"
SRCURL[30]="http://downloads.sourceforge.net/libraw1394/libraw1394-${RAW1394}.tar.gz"
SRCPAT[30]="NO"
USE[30]="YES"

SOURCE[31]="$SRCDIR/sources/libdc1394-${DC1394}.tar.gz"
SRCURL[31]="http://downloads.sourceforge.net/libdc1394/libdc1394-${DC1394}.tar.gz"
SRCPAT[31]="NO"
USE[31]="YES"

SOURCE[32]="$SRCDIR/sources/libavc1394-${AVC1394}.tar.gz"
SRCURL[32]="http://downloads.sourceforge.net/libavc1394/libavc1394-${AVC1394}.tar.gz"
SRCPAT[32]="NO"
USE[32]="YES"

# Library designed for decoding and generation of MPEG TS and DVB PSI tables.
SOURCE[33]="$SRCDIR/sources/libdvbpsi-${DVBPSI}.tar.bz2"
SRCURL[33]="http://download.videolan.org/pub/libdvbpsi/${DVBPSI}/libdvbpsi-${DVBPSI}.tar.bz2"
SRCPAT[33]="NO"
USE[33]="YES"

# a free DTS Coherent Acoustics decoder
SOURCE[34]="$SRCDIR/sources/libdca-${DCA}.tar.bz2"
SRCURL[34]="http://download.videolan.org/pub/videolan/libdca/${DCA}/libdca-${DCA}.tar.bz2"
SRCPAT[34]="NO"
USE[34]="YES"

# VAAPI for video hardware acceleration:
SOURCE[35]="$SRCDIR/sources/libva-${LIBVA}.tar.bz2"
SRCURL[35]="https://github.com/intel/libva/releases/download/${LIBVA}/libva-${LIBVA}.tar.bz2"
SRCPAT[35]="NO"
USE[35]="YES"

# Universal Plug'n'Play
SOURCE[36]="$SRCDIR/sources/libupnp-${UPNP}.tar.bz2"
SRCURL[36]="http://downloads.sourceforge.net/pupnp/libupnp-${UPNP}.tar.bz2"
SRCPAT[36]="NO"
USE[36]="YES"

# Bluray support library (for unencrypted content):
SOURCE[37]="$SRCDIR/sources/libbluray-${BLURAY}.tar.bz2"
SRCURL[37]="https://download.videolan.org/pub/videolan/libbluray//${BLURAY}/libbluray-${BLURAY}.tar.bz2"
SRCPAT[37]="NO"
USE[37]="YES"

# Libass - portable library for SSA/ASS subtitles rendering
SOURCE[38]="$SRCDIR/sources/libass-$ASS.tar.xz"
#SRCURL[38]="http://libass.googlecode.com/files/libass-$ASS.tar.xz"
SRCURL[38]="https://github.com/libass/libass/releases/download/$ASS/libass-$ASS.tar.xz"
SRCPAT[38]="NO"
USE[38]="YES"

# FluidSynth - midi playback
SOURCE[39]="$SRCDIR/sources/fluidsynth-${FLUID}.tar.bz2"
SRCURL[39]="http://downloads.sourceforge.net/fluidsynth/fluidsynth-${FLUID}.tar.bz2"
SRCPAT[39]="NO"
USE[39]="YES"

# opus codec:
SOURCE[40]="$SRCDIR/sources/opus-${OPUS}.tar.gz"
SRCURL[40]="http://downloads.xiph.org/releases/opus/opus-${OPUS}.tar.gz"
SRCPAT[40]="NO"
USE[40]="YES"

# projectM: visualisation plugin
SOURCE[41]="$SRCDIR/sources/projectM-${PROJECTM}-Source.tar.gz"
SRCURL[41]="http://sourceforge.net/projects/projectm/files/${PROJECTM}/projectM-${PROJECTM}-Source.tar.gz/download"
SRCPAT[41]="NO"
USE[41]="YES"

# Theora encoder/decoder libraries
SOURCE[42]="$SRCDIR/sources/libtheora-${THEORA}.tar.gz"
SRCURL[42]="http://downloads.xiph.org/releases/theora/libtheora-${THEORA}.tar.gz"
SRCPAT[42]="NO"
USE[42]="YES"

# GSM support:
SOURCE[43]="$SRCDIR/sources/gsm-$GSM.tar.gz"
#SRCURL[43]="http://osxwinebuilder.googlecode.com/files/gsm-$GSM.tar.gz"
SRCURL[43]="http://www.quut.com/gsm/gsm-$GSM.tar.gz"
SRCPAT[43]="NO"
USE[43]="YES"

# Google's VP8 codec:
SOURCE[44]="$SRCDIR/sources/libvpx-${VPX}.tar.gz"
SRCURL[44]="https://github.com/webmproject/libvpx/archive/v${VPX}.tar.gz"
#SRCURL[44]=""
SRCPAT[44]="NO"
USE[44]="YES"

# AMR-WB encoder libraries used to encode 3GPP audio
SOURCE[45]="$SRCDIR/sources/vo-amrwbenc-${AMRWBENC}.tar.gz"
SRCURL[45]="http://downloads.sourceforge.net/opencore-amr/vo-amrwbenc-${AMRWBENC}.tar.gz"
SRCPAT[45]="NO"
USE[45]="YES"

# VDPAU for video hardware acceleration:
SOURCE[46]="$SRCDIR/sources/libvdpau-${VDPAU}.tar.gz"
SRCURL[46]="https://gitlab.freedesktop.org/vdpau/libvdpau/-/archive/${VDPAU}/libvdpau-${VDPAU}.tar.gz"
SRCPAT[46]="NO"
USE[46]="YES"

# DAV1D, a free AV1 decoder:
SOURCE[47]="$SRCDIR/sources/dav1d-${DAV1D}.tar.xz"
SRCURL[47]="http://download.videolan.org/pub/videolan/dav1d/${DAV1D}/dav1d-${DAV1D}.tar.xz"
SRCPAT[47]="NO"
USE[47]="YES"

# Library for AS-DCP files:
SOURCE[48]="$SRCDIR/sources/asdcplib-${ASDCPLIB}.tar.gz"
SRCURL[48]="http://download.cinecert.com/asdcplib/asdcplib-${ASDCPLIB}.tar.gz"
SRCPAT[48]="NO"
USE[48]="YES"

# MicroDNS for mDNS services discovery:
SOURCE[49]="$SRCDIR/sources/microdns-${MDNS}.tar.xz"
SRCURL[49]="https://github.com/videolabs/libmicrodns/releases/download/${MDNS}/microdns-${MDNS}.tar.xz"
SRCPAT[49]="NO"
USE[49]="YES"

# Secure Reliable Transport (srt):
SOURCE[50]="$SRCDIR/sources/srt-${SRT}.tar.gz"
SRCURL[50]="https://github.com/Haivision/srt/archive/v${SRT}.tar.gz"
SRCPAT[50]="NO"
USE[50]="YES"

# Defective SMb (dsm):
SOURCE[51]="$SRCDIR/sources/libdsm-${DSM}.tar.xz"
SRCURL[51]="https://github.com/videolabs/libdsm/releases/download/v${DSM}/libdsm-${DSM}.tar.xz"
SRCPAT[51]="NO"
USE[51]="YES"

# Protobuf:
SOURCE[52]="$SRCDIR/sources/protobuf-cpp-${PROTOBUF}.tar.gz"
SRCURL[52]="https://github.com/google/protobuf/releases/download/v${PROTOBUF}/protobuf-cpp-${PROTOBUF}.tar.gz"
SRCPAT[52]="NO"
USE[52]="YES"

# libplacebo enables HDR tone mapping in VLC:
SOURCE[53]="$SRCDIR/sources/libplacebo-${PLACEBO}.tar.gz"
#SRCURL[53]="https://code.videolan.org/videolan/libplacebo/-/archive/v${PLACEBO}/libplacebo-v${PLACEBO}.tar.gz"
SRCURL[53]=""
SRCPAT[53]="NO"
USE[53]="YES"

# Soxr resampling library (depends on ffmpeg):
SOURCE[54]="$SRCDIR/sources/soxr-${SOXR}-Source.tar.xz"
SRCURL[54]="http://downloads.sourceforge.net/project/soxr/soxr-${SOXR}-Source.tar.xz"
SRCPAT[54]="NO"
USE[54]="YES"

# PCRE2 library for Qt5Base:
SOURCE[55]="$SRCDIR/sources/pcre2-${PCRE2}.tar.gz"
SRCURL[55]="https://ftp.pcre.org/pub/pcre/pcre2-${PCRE2}.tar.gz"
SRCPAT[55]="NO"
USE[55]="NO"

# Qt5 base libraries:
SOURCE[56]="$SRCDIR/sources/qtbase-opensource-src-${QT5}.tar.xz"
SRCURL[56]="http://download.qt.io/official_releases/qt/$(echo $QT5 |cut -d. -f1,2)/${QT5}/submodules/qtbase-opensource-src-${QT5}.tar.xz"
SRCPAT[56]="NO"
USE[56]="NO"

# Qt5 SVG support:
SOURCE[57]="$SRCDIR/sources/qtsvg-opensource-src-${QT5}.tar.xz"
SRCURL[57]="http://download.qt.io/official_releases/qt/$(echo $QT5 |cut -d. -f1,2)/${QT5}/submodules/qtsvg-opensource-src-${QT5}.tar.xz"
SRCPAT[57]="NO"
USE[57]="NO"

# Qt5 platform-specific APIs for X11:
SOURCE[58]="$SRCDIR/sources/qtx11extras-opensource-src-${QT5}.tar.xz"
SRCURL[58]="http://download.qt.io/official_releases/qt/$(echo $QT5 |cut -d. -f1,2)/${QT5}/submodules/qtx11extras-opensource-src-${QT5}.tar.xz"
SRCPAT[58]="NO"
USE[58]="NO"

# CSS decoding- VLC can do without if you install an external libdvdcss package.
SOURCE[59]="$SRCDIR/sources/libdvdcss-${DVDCSS}.tar.bz2"
SRCURL[59]="http://download.videolan.org/pub/libdvdcss/${DVDCSS}/libdvdcss-${DVDCSS}.tar.bz2"
SRCPAT[59]="YES"
USE[59]="YES"

# Use the src_checkout() function if no downloadable tarball exists.
# This function checks out sources from SVN/CVS and creates a tarball of them.
src_checkout() {
  # Param #1 : index in the SOURCE[] array.
  # Param #2 : full path to where SOURCE[$1] tarball should be created.
  # Determine the tarball extension:
  PEXT=$(echo "${2}" | sed -r -e 's/.*[^.].(tar.xz|tar.gz|tar.bz2|tgz).*/\1/')
  case "$PEXT" in
    "tar.xz") TARCOMP="J" ;;
    "tar.gz") TARCOMP="z" ;;
    "tgz") TARCOMP="z" ;;
    "tar.bz2") TARCOMP="j" ;;
    *) echo "Archive can only have extension 'tar.xz', '.tar.gz' '.tar.bz2' or '.tgz'" ; exit 1 ;;
  esac
  case ${1} in
  0) # vlc-$SRCVER
     mkdir vlc_temp_checkout_$$ \
       && cd vlc_temp_checkout_$$

       if [ "$VERSION" = "HEAD" -o "$VERSION" = "HEAD@" -o "$VERSION" = "master@" ]; then
         # Checkout without downloading version history (fast!):
         echo "Checking out HEAD from '$GITURI':"
         git clone --depth=1 ${GITURI} vlc-${SRCVER}
       else
         # Checkout code from a certain branch and/or date; this will take a
         # long time because we have to clone the complete git-repository first:
         echo "Checking out $BRANCH at date $SRCVER from '$GITURI':"
         git clone ${GITURI} vlc-${SRCVER} \
         && cd vlc-${SRCVER} \
         && git checkout $BRANCH \
         && git checkout $(git rev-list -n 1 --before="`date -d $SRCVER`" $BRANCH) \
         && cd ..
       fi
       chown -R root:root . \
       && tar -${TARCOMP}cf ${2} vlc-${SRCVER}
       # 20110824: vlc from git won't compile unless there is .git directory
       # && tar --exclude .git -${TARCOMP}cf ${2} vlc-${SRCVER}
     cd ..
     rm -rf vlc_temp_checkout_$$
     # If VERSION was "HEAD" we still want a date to appear in the pkgname:
     VERSION=${SRCVER}
     ;;
  1) # We clone the git of ffmpeg at a certain hash:
     mkdir ffmpeg-${FFMPEG} \
       && cd ffmpeg-${FFMPEG} \
       && git clone git://git.videolan.org/ffmpeg.git . \
       && git checkout $FFMPEG \
       && chown -R root:root . \
       && cd .. \
       && tar --exclude .git -${TARCOMP}cf ${2} ffmpeg-${FFMPEG}
     rm -rf ffmpeg-${FFMPEG}
     ;;
  10) # We clone the git of x262 at a certain date:
     mkdir x262-${X262} \
       && cd x262-${X262} \
       && git clone git://git.videolan.org/x262.git . \
       && git checkout $(git rev-list -n 1 --before="`date -d $X262`" master) \
       && chown -R root:root . \
       && cd .. \
       && tar --exclude .git -${TARCOMP}cf ${2} x262-${X262}
     rm -rf x262-${X262}
     ;;
 14) # libdvdnav-$DVDNAV
     # We clone the git of libdvdnav at a certain date:
     mkdir libdvdnav-${DVDNAV} \
      && cd libdvdnav-${DVDNAV} \
      && git clone git://git.videolan.org/libdvdnav/ . \
      && git checkout $(git rev-list -n 1 --before="`date -d $DVDNAV`" master) \
      && chown -R root:root . \
      && cd .. \
      && tar --exclude .git -${TARCOMP}cf ${2} libdvdnav-${DVDNAV}
     rm -rf libdvdnav-${DVDREAD}
     ;;
 15) # libdvdread-$DVDREAD
     # We clone the git of libdvdread at a certain date:
     mkdir libdvdread-${DVDREAD} \
      && cd libdvdread-${DVDREAD} \
      && git clone git://git.videolan.org/libdvdread/ . \
      && git checkout $(git rev-list -n 1 --before="`date -d $DVDREAD`" master)\
      && chown -R root:root . \
      && cd .. \
      && tar --exclude .git -${TARCOMP}cf ${2} libdvdread-${DVDREAD}
     rm -rf libdvdread-${DVDREAD}
     ;;
  17) # We clone the git of speexdsp at a certain date:
     mkdir speexdsp-${SPEEXDSP} \
       && cd speexdsp-${SPEEXDSP} \
       && git clone https://git.xiph.org/speexdsp.git . \
       && git checkout $(git rev-list -n 1 --before="`date -d $SPEEXDSP`" master) \
       && chown -R root:root . \
       && cd .. \
       && tar --exclude .git -${TARCOMP}cf ${2} speexdsp-${SPEEXDSP}
     rm -rf speexdsp-${SPEEXDSP}
     ;;
 19) # libmpcdec-$MPCDEC
     local SVNURL=http://svn.musepack.net/libmpc/trunk/
     if [ "$(echo ${MPCDEC}|cut -c1)" == 'r' ]; then # revision instead of date
       REV=$(echo ${MPCDEC} | cut -c2-)
     else
       REV="{${MPCDEC}}"
     fi
     mkdir libmpcdec-${MPCDEC} \
       && cd libmpcdec-${MPCDEC} \
       && svn checkout --revision $REV $SVNURL . \
       && chown -R root:root . \
       && cd .. \
       && tar --exclude .svn -${TARCOMP}cf ${2} libmpcdec-${MPCDEC}
     rm -rf libmpcdec-${MPCDEC}
     unset SVNURL
     ;;
  37) # We clone the git of libbluray at a certain date:
     mkdir libbluray-${BLURAY} \
       && cd libbluray-${BLURAY} \
       && git clone git://git.videolan.org/libbluray.git . \
       && git checkout $(git rev-list -n 1 --before="`date -d $BLURAY`" master) \
       && chown -R root:root . \
       && cd .. \
       && tar --exclude .git -${TARCOMP}cf ${2} libbluray-${BLURAY}
     rm -rf libbluray-${BLURAY}
     ;;
  44) # We clone the git of libvpx at a certain date:
     mkdir libvpx-${VPX} \
       && cd libvpx-${VPX} \
       && git clone git://review.webmproject.org/libvpx.git . \
       && git checkout $(git rev-list -n 1 --before="`date -d $VPX`" master) \
       && chown -R root:root . \
       && cd .. \
       && tar --exclude .git -${TARCOMP}cf ${2} libvpx-${VPX}
     rm -rf libvpx-${VPX}
     ;;
  53) # We clone the git of libplacebo including submodules:
     mkdir libplacebo-${PLACEBO} \
       && cd libplacebo-${PLACEBO} \
       && git clone https://code.videolan.org/videolan/libplacebo . \
       && git checkout tags/v${PLACEBO} -b v${PLACEBO} \
       && git submodule update --init --recursive \
       && chown -R root:root . \
       && cd .. \
       && tar --exclude .git -${TARCOMP}cf ${2} libplacebo-${PLACEBO}
     rm -rf libplacebo-${PLACEBO}
     ;;
  *) # Do nothing
     ;;
  esac
}

if [ "${USE_PATENTS}" == "YES" ]; then
  echo ""
  echo "**"
  echo "** This build uses patented code (AAC encoder)"
  echo "** Run the command 'USE_PATENTS=NO $0 $*' to avoid patent issues."
  echo "**"
  echo ""
  sleep 1
fi

##
## --- with a little luck, you won't have to edit below this point --- ##
##

# Exit the script on errors:
set -e
trap 'echo "$0 FAILED at line $LINENO!" | tee $OUTPUT/error-${PRGNAM}.log' ERR
# Catch unitialized variables:
set -u
P1=${1:-1}

# Create working directories:
mkdir -p $TMP/tmp-$PRGNAM # location to build the source
mkdir -p $PKG             # place for the package to be built
rm -rf $PKG/*             # We always erase old package's contents:
mkdir -p $OUTPUT          # place for the package to be saved

if [ "$P1" != "--oldbuild" -a  "$P1" != "--download" ]; then
  # If the "--oldbuild" parameter is present, we keep
  #  the old build files and continue;
  # By default we remove the remnants of previous build and continue:
  echo -e "**\n**  Cleaning up old build ...\n**"
  rm -rf $TMP/tmp-$PRGNAM/*
  rm -f $OUTPUT/*${PRGNAM}*.log   # Delete old logfiles
fi

# We may not need to download and unpack the Qt5 sources:
if [ "$STATIC_QT5" != "NO" ]; then
  echo "**"
  echo "** Building with a static QT5..."
  echo "**"
  USE[55]="YES"
  USE[56]="YES"
  USE[57]="YES"
  USE[58]="YES"
fi

# We may not need to download and unpack the ffmpeg sources:
if [ "$STATIC_FFMPEG" != "YES" ]; then
  echo "**"
  echo "** Not building static FFMPEG and its internal dependencies..."
  echo "**"
  USE[1]="NO" # ffmpeg
  USE[2]="NO" # opencore-amr
  USE[3]="NO" # lame
  USE[42]="NO" # theora
  USE[43]="NO" # gsm
  USE[44]="NO" # vpx
  USE[45]="NO" # vo-amrwb
fi

# Source file availability:
for (( i = 0; i < ${#SOURCE[*]}; i++ )) ; do
  # Do we actually use this source?
  [ "${USE[$i]}" = "YES" ] || continue
  # Only download patented code if we are allowing it:
  if [ "${USE_PATENTS}" == "YES" -o "${SRCPAT[$i]}" != "YES" ]; then
    if ! [ -f ${SOURCE[$i]} ]; then
      echo "Source '$(basename ${SOURCE[$i]})' not available yet..."
      # Check if the $SRCDIR is writable at all - if not, download to $OUTPUT
      [ -w "$SRCDIR" ] || SOURCE[$i]="$OUTPUT/$(basename ${SOURCE[$i]})"
      if ! [ "x${SRCURL[$i]}" == "x" ]; then
        echo "Will download file to $(dirname $SOURCE[$i])"
        if ! $(wget --no-check-certificate -nv -T 20 -O "${SOURCE[$i]}" "${SRCURL[$i]}"); then
          echo "Downloading '$(basename ${SOURCE[$i]})' failed.. aborting the build."
          mv -f "${SOURCE[$i]}" "${SOURCE[$i]}".FAIL
          exit 1
        fi
      else
        # Try if we have a SVN/CVS download routine for ${SOURCE[$i]}
        echo "Will checkout sources to $(dirname $SOURCE[$i])"
        src_checkout $i "${SOURCE[$i]}" 2>&1 |tee $OUTPUT/checkout-$(basename ${SOURCE[$i]}).log
      fi
      if [ ! -f "${SOURCE[$i]}" -o ! -s "${SOURCE[$i]}" ]; then
        echo "File '$(basename ${SOURCE[$i]})' not available.. aborting the build."
        exit 1
      fi
    fi
  fi
done

if [ "$P1" == "--download" ]; then
  echo "Download complete."
  exit 0
fi

# Package building:
echo "++"
echo "|| $PRGNAM-$VERSION"
echo "++"

cd $TMP/tmp-$PRGNAM
if [ "$P1" != "--oldbuild" ]; then
  echo "Extracting the source archive(s) for $PRGNAM..."
  for (( i = 0; i < ${#SOURCE[*]}; i++ )) ; do
    # Do we actually use this source?
    [ "${USE[$i]}" = "YES" ] || continue
    # Only extract and use patented code if we are allowing it:
    if [ "${USE_PATENTS}" == "YES" -o "${SRCPAT[$i]}" != "YES" ]; then
      if $(file ${SOURCE[$i]} | grep -iq ": zip"); then
        unzip ${SOURCE[$i]}
      else
        tar -xf ${SOURCE[$i]}
      fi
    fi
  done
  chown -R root:root *
  chmod -R u+w,go+r-w,a+X-s *
fi

# Building the source code:
echo Building ...

# We will be installing static libs into the following directory:
mkdir -p $VLCDEPSDIR/usr/{bin,doc,include,lib${LIBDIRSUFFIX},man}

# -----------------------------------------------------------------------------
# Helper function to expose private libs:
# -----------------------------------------------------------------------------
pkg_static ()
{
PCFILE="$1"

TEMPOUTL=$(mktemp -t alien.XXXXXX)
TEMPOUTR=$(mktemp -t alien.XXXXXX)

mv "${PCFILE}" "${PCFILE}.orig"
touch "${PCFILE}"
cat "${PCFILE}.orig" | while read LINE; do
  lpub="${LINE#Libs:}"
  lpriv="${LINE#Libs.private:}"
  rpub="${LINE#Requires:}"
  rpriv="${LINE#Requires.private:}"
  if test "$lpub" != "$LINE"; then
    echo "$lpub" >> $TEMPOUTL
  elif test "$lpriv" != "$LINE"; then
    echo "$lpriv" >> $TEMPOUTL
  elif test "$rpub" != "$LINE"; then
    echo "$rpub" >> $TEMPOUTR
  elif test "$rpriv" != "$LINE"; then
    echo "$rpriv" >> $TEMPOUTR
  else
    echo "$LINE" >> ${PCFILE}
  fi
done
echo "Libs: $(echo $(cat $TEMPOUTL))" >> ${PCFILE}
echo "Requires: $(echo $(cat $TEMPOUTR))" >> ${PCFILE}

rm -f $TEMPOUTL $TEMPOUTR
}


# -----------------------------------------------------------------------------
# Compile theora libraries
# The ffmpeg will use these
# -----------------------------------------------------------------------------
make_theora()
{
echo -e "**\n**  theora ...\n**"
cd $TMP/tmp-$PRGNAM/libtheora-${THEORA}

# Don't build documentation and other crap:
sed -i -e "s/doc tests / /" Makefile*

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --disable-examples \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_theora.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_theora.log
# Install theora into a temp location so ffmpeg can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_theora.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libtheora/
cp AUTHORS CHANGES COPYING LICENSE README \
  $VLCDEPSDIR/doc/libtheora/ || true
cd -
}

# -----------------------------------------------------------------------------
# Compile lame libraries
# The ffmpeg will use these
# -----------------------------------------------------------------------------
make_lame()
{
echo -e "**\n**  lame ...\n**"
cd $TMP/tmp-$PRGNAM/lame-${LAME}

## Fix compiler error introduced by gcc-4.9 on 32-bit:
#if [ "$(gcc --version|grep '^gcc'|cut -d' ' -f3|cut -d. -f1,2)" = "4.9" ]; then
#  case $(uname -m) in
#    i?86) sed -i -e '/xmmintrin\.h/d' configure ;;
#  esac
#fi
#
## Fix compilation on x86 (xmmintrin.h error: inlining failed)
#cat $SRCDIR/patches/lame_x86-xmmintrin.patch | patch -p1 --verbose \
#  2>&1 | tee $OUTPUT/patch-${PRGNAM}_lame.log

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-mp3rtp \
  --enable-nasm \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_lame.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_lame.log
# Install lame into a temp location so ffmpeg can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_lame.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/lame/
cp API COPYING ChangeLog* DEFINES HACKING LICENSE README* STYLEGUIDE TODO \
  $VLCDEPSDIR/doc/lame/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile amr wideband/narrowband library
# The ffmpeg will use these
# -----------------------------------------------------------------------------
make_amr()
{
echo -e "**\n**  amr ...\n**"
cd $TMP/tmp-$PRGNAM/opencore-amr-${AMR}
LDFLAGS="$SLKLDFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
CFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --mandir=$VLCDEPSDIR/usr/man \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_amr.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_amr.log
make install PREFIX=$VLCDEPSDIR/usr LIBDIR=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  2>&1 | tee -a $OUTPUT/make-${PRGNAM}_amr.log
# Add DOCS to the vlcdeps to have it added to vlc package later:          
mkdir -p $VLCDEPSDIR/doc/amr
cp -a AUTHORS COPYING ChangeLog LICENSE NEWS README \
  $VLCDEPSDIR/doc/amr || true
cd -
}

# -----------------------------------------------------------------------------
# Compile VisualOn amr wideband encoder library
# The ffmpeg will use these
# -----------------------------------------------------------------------------
make_amrwbenc()
{
echo -e "**\n**  amrwbenc ...\n**"
cd $TMP/tmp-$PRGNAM/vo-amrwbenc-${AMRWBENC}
LDFLAGS="$SLKLDFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
CFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --mandir=$VLCDEPSDIR/usr/man \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_amrwbenc.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_amrwbenc.log
make install $VLCDEPSDIR/PREFIX=/usr LIBDIR=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  2>&1 | tee -a $OUTPUT/make-${PRGNAM}_amrwbenc.log
# Add DOCS to the vlcdeps to have it added to vlc package later:          
mkdir -p $VLCDEPSDIR/doc/amrwbenc
cp -a COPYING ChangeLog README \
  $VLCDEPSDIR/doc/amrwbenc || true
cd -
}

# -----------------------------------------------------------------------------
# Compile gsm
# -----------------------------------------------------------------------------
make_gsm()
{
echo -e "**\n**  gsm  ...\n**"
GSMMAJ=$(echo $GSM | cut -d. -f1,2)
GSMPL=$(echo $GSM | cut -d. -f3)
mv $TMP/tmp-$PRGNAM/gsm-${GSMMAJ}-pl${GSMPL} $TMP/tmp-$PRGNAM/gsm-${GSM}
cd $TMP/tmp-$PRGNAM/gsm-${GSM}
# Without this, x86_64 builds will fail:
sed -i -e "/^CCFLAGS/s,-O2 ,$SLKCFLAGS ," \
       -e "s,^# LDFLAGS.*,LDFLAGS = $SLKLDFLAGS," Makefile
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_gsm.log
# Install gsm into a temp location so ffmpeg can pickup the library
#make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_gsm.log
mkdir -p $VLCDEPSDIR/usr/{bin,include/gsm,lib${LIBDIRSUFFIX}}
cp bin/* $VLCDEPSDIR/usr/bin/
cp inc/gsm.h $VLCDEPSDIR/usr/include/gsm/
ln -sf gsm/gsm.h $VLCDEPSDIR/usr/include/gsm.h
cp lib/* $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/
# Add DOCS to the vlcdeps to have it added to vlc package later:          
mkdir -p $VLCDEPSDIR/doc/gsm
cp -a COPYRIGHT ChangeLog* INSTALL MACHINES MANIFEST README \
  $VLCDEPSDIR/doc/gsm || true
cd -
}


# -----------------------------------------------------------------------------
# Compile ffmpeg 3.x with support for AMR, LAME, XVID, RTMP, ...
# Later, we will statically link VLC to the generated libavcodec libraries
# -----------------------------------------------------------------------------
make_ffmpeg()
{
echo -e "**\n**  ffmpeg ...\n**"
OLDDIR=$(pwd)
cd $TMP/tmp-$PRGNAM
# Take care of snaphot directory:
if [ -d ffmpeg-export-* ]; then
  rm -rf ffmpeg-${FFMPEG}
  mv ffmpeg-export-* ffmpeg-${FFMPEG}
fi

# Only use patented code if we are allowing it:
if [ "${USE_PATENTS}" == "YES" ]; then
  USE_PATENTED="--enable-encoder=aac \
                --enable-nonfree"
else
  USE_PATENTED="--disable-encoder=aac"
fi

cd $TMP/tmp-$PRGNAM/ffmpeg-${FFMPEG}

# Apply patches:
touch $OUTPUT/patch-${PRGNAM}_ffmpeg.log
# Fix assembly with binutils >= 2.41:
cat $SRCDIR/patches/ffmpeg_binutils241.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ffmpeg.log
# Prevent a crash in DVXA in interlaced VC-1:
cat $SRCDIR/patches/ffmpeg_dxva_vc1_crash.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ffmpeg.log
# Fix SAR not set early enough when starting the decoder:
cat $SRCDIR/patches/ffmpeg_h264_early_SAR.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ffmpeg.log
# Apply VLC's own patches:
cat $SRCDIR/patches/0001-avcodec-dxva2_hevc-add-support-for-parsing-HEVC-Rang.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ffmpeg.log
cat $SRCDIR/patches/0002-avcodec-hevcdec-allow-HEVC-444-8-10-12-bits-decoding.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ffmpeg.log
cat $SRCDIR/patches/0003-avcodec-hevcdec-allow-HEVC-422-10-12-bits-decoding-w.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ffmpeg.log
cat $SRCDIR/patches/0001-avcodec-mpeg12dec-don-t-call-hw-end_frame-when-start.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ffmpeg.log
cat $SRCDIR/patches/0002-avcodec-mpeg12dec-don-t-end-a-slice-without-first_sl.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ffmpeg.log

if pkg-config --exists libopenjp2 1>/dev/null 2>/dev/null ; then
  USE_OPENJPEG="--enable-libopenjpeg"
else
  USE_OPENJPEG=""
fi

if [ "$ARCH" = "x86_64" ]; then
  ARCHOPTS="--arch=x86_64 --enable-pic"
elif [ "$ARCH" = "i586" ]; then
  ARCHOPTS="--arch=x86"
elif [ "$ARCH" = "armv7hl" ]; then
  ARCHOPTS="--arch=arm --enable-pic --disable-runtime-cpudetect --cpu=cortex-a8 --enable-neon"
else
  ARCHOPTS=""
fi

## Prevent static linking issues:
#sed -i -e "s/pkg_config --libs/pkg_config --static --libs/" \
#  configure

# Stamp the version into the source:
[ -f version.sh ] && sed -i -e "s/UNKNOWN/$FFMPEG/" version.sh

TMPDIR="$TMP" \
CFLAGS="$SLKCFLAGS --std=gnu99" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
PKG_CONFIG_PATH="${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --shlibdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  ${USE_PATENTED} \
  ${USE_PULSE} \
  ${USE_OPENJPEG} \
  --disable-avdevice \
  --disable-avfilter \
  --disable-avisynth \
  --disable-bsfs \
  --disable-encoder=vorbis \
  --disable-decoder=opus \
  --disable-devices \
  --disable-filters \
  --disable-debug \
  --disable-doc \
  --disable-iconv \
  --disable-nvenc \
  --disable-programs \
  --disable-protocol=concat \
  --disable-shared \
  --disable-swresample \
  --enable-gpl \
  --enable-version3 \
  --enable-libgsm \
  --enable-libmp3lame \
  --enable-libopencore-amrnb \
  --enable-libopencore-amrwb \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvo-amrwbenc \
  --enable-libvpx \
  --enable-bsf=vp9_superframe \
  --enable-bzlib \
  --enable-postproc \
  --enable-pthreads \
  --enable-zlib \
  --enable-static \
  $ARCHOPTS \
  --target-os=linux \
  --extra-cflags="-I${VLCDEPSDIR}/usr/include" \
  --extra-ldflags="-L${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX} -ldl" \
  --extra-libs="-lm -lpthread" \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_ffmpeg.log

  # Do not add '-fPIC -DPIC' to extra-cflags or "can't find
  # a register in class 'GENERAL_REGS' while reloading 'asm'" occurs
  # --enable-libogg \ Newer ffmpeg no longer need this.
  # --enable-libxvid \ generates vlc linker errors, so we use ffmpeg's
  #   native xvid encoder implementation instead
  #--enable-libvorbis \  # Use ffmpeg's native support
  #--disable-vhook \
  #--logfile=$OUTPUT/ffmpeg.conf.log \
  # Remove this in 0.6.1 to avoid "error: libavcodec/cbrt_tables.h: No such file or directory"
  # (compile issue has been fixed in ffmpeg-git but I'll stick to 0.6.1 for now):
  # --enable-hardcoded-tables \
  # Since vlc-1.1 this is no longer needed... neither is rtmpdump, becausee
  # ffmpeg has an internal implementation:
  #--disable-protocols \
  #--disable-devices \
  #--disable-network \
  #--enable-librtmp \
  # Let VLC do the hardware decoding:
  #--enable-vaapi \
  #--enable-vdpau \

make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_ffmpeg.log
[ $? -ne 0 ] && return 1

# Install ffmpeg into a temp location so vlc can pickup the libraries
make install-libs install-headers \
  2>&1 | tee -a $OUTPUT/make-${PRGNAM}_ffmpeg.log

# If we compiled vaapi support:
if ! find $VLCDEPSDIR/usr/include/vaapi*.h 1>/dev/null 2>/dev/null ; then
  cp libavcodec/vaapi*.h $VLCDEPSDIR/usr/include/
fi

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/ffmpeg/
cp COPYING* CREDITS Changelog MAINTAINERS \
  $VLCDEPSDIR/doc/ffmpeg/ || true

cd $OLDDIR
}


# -----------------------------------------------------------------------------
# ADDITIONAL CODECS AND INPUT LIBRARIES FOR VLC
# -----------------------------------------------------------------------------


# -----------------------------------------------------------------------------
# Compile a52 libraries
# -----------------------------------------------------------------------------
make_a52()
{
echo -e "**\n**  a52 ...\n**"
cd $TMP/tmp-$PRGNAM/a52dec-${A52}
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_a52.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_a52.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/a52dec/
cp AUTHORS COPYING ChangeLog HISTORY INSTALL NEWS README TODO \
  $VLCDEPSDIR/doc/a52dec/ || true
cd -
}

# -----------------------------------------------------------------------------
# Compile live555
# -----------------------------------------------------------------------------
make_live555()
{
echo -e "**\n**  live555 ...\n**"
cd $TMP/tmp-$PRGNAM/live

# Force the use of our CFLAGS
sed -i -e "s|-O2|${SLKCFLAGS}|g" config.linux

# Be compatible with glibc >= 2.26:
sed -i -e 's/#include <xlocale.h>.*/#include <locale.h>/' \
  liveMedia/include/Locale.hh

# Live555 is not useable with vlc unless linked statically.
# We need this patch for the tarballs around end september 2009:
if ! $(grep -q Bstatic config.linux) ; then
  sed -i -e 's/\(LIBRARY_LINK =\).*/\1 $(LD) -o/g' \
         -e 's/\(LIBRARY_LINK_OPTS =\).*/\1 $(LINK_OPTS) -r -Bstatic/g' \
         config.linux
fi

# Borrowing from VLC contribs:
# Change permissions to patch and sed the source
chmod -R u+w .
# Remove hardcoded cc, c++, ar variables
sed -e "s%cc%${CC}%" -e "s%c++%${CXX}%" -e "s%LIBRARY_LINK =.*ar%LIBRARY_LINK = ${AR}%" -i.orig config.linux
# We want 64bits offsets and PIC on Linux
sed -e 's%-D_FILE_OFFSET_BITS=64%-D_FILE_OFFSET_BITS=64\ -fPIC\ -DPIC%' -i.orig config.linux

# Apply patches:
touch $OUTPUT/patch-${PRGNAM}_live.log
cat $SRCDIR/patches/live555_no_null_reference.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_live.log
cat $SRCDIR/patches/live555_expose_server_string.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_live.log

./genMakefiles linux 2>&1 | tee $OUTPUT/configure-${PRGNAM}_live.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_live.log
# Move the live555 stuff into place for vlc to pick it up:
mkdir -p $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $VLCDEPSDIR/usr/include
cp \
  groupsock/libgroupsock.a \
  liveMedia/libliveMedia.a \
  UsageEnvironment/libUsageEnvironment.a \
  BasicUsageEnvironment/libBasicUsageEnvironment.a \
  $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/
cp \
  groupsock/include/*.hh \
  groupsock/include/*.h \
  liveMedia/include/*.hh \
  UsageEnvironment/include/*.hh \
  BasicUsageEnvironment/include/*.hh \
  $VLCDEPSDIR/usr/include/
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/live555/
cp COPYING README \
  $VLCDEPSDIR/doc/live555/ || true
cd -
}

# -----------------------------------------------------------------------------
# Compile ebml
# -----------------------------------------------------------------------------
make_ebml()
{
echo -e "**\n**  ebml ...\n**"
OLDDIR=$(pwd)
cd $TMP/tmp-$PRGNAM/libebml-$EBML

# Apply patches:
touch $OUTPUT/patch-${PRGNAM}_ebml.log
#cat $SRCDIR/patches/ebml_maxread.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ebml.log
#cat $SRCDIR/patches/ebml_unknown-check.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ebml.log
#cat $SRCDIR/patches/ebml_null-compare.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ebml.log
#cat $SRCDIR/patches/ebml_infinite-start.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ebml.log
#if [ $(gcc -dumpversion |cut -d'.' -f1) -ge 7 ]; then
#  cat $SRCDIR/patches/ebml_gcc7.patch | patch -p1 --verbose \
#    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ebml.log
#else
#  cat $SRCDIR/patches/ebml_limits.patch | patch -p1 --verbose \
#    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ebml.log
#fi
if [ $(gcc -dumpversion |cut -d'.' -f1) -ge 11 ]; then
  cat $SRCDIR/patches/ebml_gcc11.patch | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ebml.log
fi

export CFLAGS="$SLKCFLAGS"
export CXXFLAGS="$SLKCFLAGS -fexceptions -fvisibility=hidden"
export LDFLAGS="$SLKLDFLAGS"

mkdir build
( cd build
  cmake .. \
    -DCMAKE_INSTALL_PREFIX=${VLCDEPSDIR}/usr \
    -DLIB_SUFFIX=${LIBDIRSUFFIX} \
    -DBUILD_SHARED_LIBS=OFF \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_ebml.log
  make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_ebml.log
  # Install into a temp directory where vlc & matroska can pick it up:
  make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_ebml.log
)
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libebml/
cp ChangeLog LICENSE.LGPL \
  $VLCDEPSDIR/doc/libebml/ || true
cd $OLDDIR
}

# -----------------------------------------------------------------------------
# Compile matroska
# -----------------------------------------------------------------------------
make_matroska()
{
echo -e "**\n**  matroska ...\n**"
OLDDIR=$(pwd)
cd $TMP/tmp-$PRGNAM/libmatroska-$MATROSKA

## Apply patches:
#touch $OUTPUT/patch-${PRGNAM}_matroska.log
## Fix writing on NULL memory:
#cat $SRCDIR/patches/matroska_dont-write-to-null-memory.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_matroska.log
## Do not use invalid lace sizes:
#cat $SRCDIR/patches/matroska_invalid-lace-sizes.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_matroska.log

export CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS"
export PKG_CONFIG_PATH="${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/pkgconfig"

pkg_static "libmatroska.pc.in"

mkdir build
( cd build
  cmake .. \
    -DCMAKE_INSTALL_PREFIX=${VLCDEPSDIR}/usr \
    -DLIB_SUFFIX=${LIBDIRSUFFIX} \
    -DBUILD_SHARED_LIBS=OFF \
    2>&1 | tee $OUTPUT/configure-${PRGNAM}_matroska.log
  make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_matroska.log
  # Install into a temp directory where vlc can pick it up:
  make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_matroska.log
)
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libmatroska/
cp ChangeLog LICENSE.LGPL \
  $VLCDEPSDIR/doc/libmatroska/ || true
cd $OLDDIR
}


# -----------------------------------------------------------------------------
# Compile libmpeg2
# -----------------------------------------------------------------------------
make_libmpeg2()
{
echo -e "**\n**  libmpeg2 ...\n**"
cd $TMP/tmp-$PRGNAM/libmpeg2-$MPEG2DEC
if [ ! -r configure ]; then
  sh bootstrap
fi
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_libmpeg2.log
  #--without-x \
  #--disable-sdl \
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_libmpeg2.log
# Install libmpeg2 into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_mbpeg2.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libmpeg2/
cp AUTHORS COPYING ChangeLog NEWS README TODO \
  $VLCDEPSDIR/doc/libmpeg2/ || true
cd -
}

# -----------------------------------------------------------------------------
# Compile libmpcdec
# -----------------------------------------------------------------------------
make_mpcdec()
{
echo -e "**\n**  libmpcdec ...\n**"
cd $TMP/tmp-$PRGNAM/musepack_src_$MPCDEC

# Prevent a dependency on libreplaygain and libcuefile:
sed -i \
  -e 's,^add_subdirectory(mpcgain),,g' \
  -e 's,^add_subdirectory(mpcchap),,g' \
  CMakeLists.txt

# We want to use our own CFLAGS please:
sed -i \
  -e 's/set(CMAKE_C_FLAGS "\(.*\)")$/add_definitions(\1)/' \
  CMakeLists.txt

mkdir build
cd build
  CFLAGS="$SLKCFLAGS" \
  CXXFLAGS="$SLKCFLAGS -std=gnu++98" \
  LDFLAGS="$SLKLDFLAGS" \
  cmake .. \
    -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DLIB_SUFFIX=${LIBDIRSUFFIX} \
    -DSHARED=OFF \
    2>&1 | tee $OUTPUT/cmake-${PRGNAM}_mpcdec.log
  make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_mpcdec.log
  # Install mpcdec into a temp location so vlc can pickup the library
  # (with the move to 'cmake', the install target does not work any longer):
  mkdir -p $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}
  install -m0644 libmpcdec/libmpcdec_static.a \
    $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libmpcdec.a
cd -
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libmpcdec/
cp libmpcdec/{AUTHORS,COPYING,ChangeLog,README} \
  $VLCDEPSDIR/doc/libmpcdec/ || true
}

# -----------------------------------------------------------------------------
# Compile libdvdnav
# -----------------------------------------------------------------------------
make_dvdnav()
{
echo -e "**\n**  libdvdnav  ...\n**"
cd $TMP/tmp-$PRGNAM/libdvdnav-$DVDNAV

pkg_static "misc/dvdnav.pc.in"

autoreconf -vif

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
PATH="$VLCDEPSDIR/usr/bin:$PATH" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_dvdnav.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_dvdnav.log
# Install libdvdnav into a temp location so vlc can pickup the library
make install m4datadir=$VLCDEPSDIR/usr/share/aclocal \
  2>&1 | tee -a $OUTPUT/make-${PRGNAM}_dvdnav.log
## Make a symlink which vlc-20080730 needs:
#( cd $VLCDEPSDIR/usr/include
#  ln -s dvdread libdvdread
#)
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libdvdnav/
cp AUTHORS COPYING ChangeLog README TODO \
  $VLCDEPSDIR/doc/libdvdnav/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile libdvdcss
# -----------------------------------------------------------------------------
make_dvdcss()
{
echo -e "**\n**  libdvdcss  ...\n**"
cd $TMP/tmp-$PRGNAM/libdvdcss-$DVDCSS
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --disable-doc \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_dvdcss.log
  # Shared library needed so that libdvdread can query the library
  #--disable-shared \
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_dvdcss.log
# Install libdvdcss into a temp location so libdvdread can pickup the library
echo -e "\n**\n**\n"
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_dvdcss.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libdvdcss/
cp AUTHORS COPYING ChangeLog NEWS README \
  $VLCDEPSDIR/doc/libdvdcss/ || true
cd -
}

# -----------------------------------------------------------------------------
# Compile libdvdread
# -----------------------------------------------------------------------------
make_dvdread()
{
echo -e "**\n**  libdvdread  ...\n**"
cd $TMP/tmp-$PRGNAM/libdvdread-$DVDREAD


if [ "${USE_PATENTS}" == "YES" ]; then
  # If we allow patented software, we also link libdvdcss statically into
  # libdvdread. Otherwise, you can just install libdvdcss additionally
  # and the dvdread library will find and load dvdcss support at runtime.
  #CSS_LIBS="$VLCDEPSDIR/usr/lib$LIBDIRSUFFIX/libdvdcss.a -static" \
  DO_CSS="--with-libdvdcss"
else
  #CSS_LIBS=""
  DO_CSS=""
fi

# Remove offending line which does not get expanded by autoreconf:
sed -i -e '/CC_CHECK_CFLAGS_APPEND/d' configure.ac
# Fool it into not building apidocs and throwing errors as a result
# (sub-optimal code guys... why remove "--disable-apidocs"):
sed -i -e 's/\[doxygen\]/[doxygen_fubar]/' configure.ac

if [ -x autogen.sh ]; then
  ./autogen.sh noconfig \
    2>&1 | tee $OUTPUT/configure-${PRGNAM}_dvdread.log
else
  autoreconf -vif \
    2>&1 | tee $OUTPUT/configure-${PRGNAM}_dvdread.log
fi

#CSS_LIBS="${CSS_LIBS}" \
CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  ${DO_CSS} \
  --build=$TARGET \
  2>&1 | tee -a $OUTPUT/configure-${PRGNAM}_dvdread.log
# Prevent documentation from being generated:
touch ChangeLog stamp-doxygen
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_dvdread.log
# Install libdvdread into a temp location so libdvdnav can pickup the library
echo -e "\n**\n**\n"
make install m4datadir=$VLCDEPSDIR/usr/share/aclocal \
  2>&1 | tee -a $OUTPUT/make-${PRGNAM}_dvdread.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libdvdread/
cp AUTHORS COPYING ChangeLog NEWS README* TODO \
  $VLCDEPSDIR/doc/libdvdread/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile libcddb
# -----------------------------------------------------------------------------
make_cddb()
{
echo -e "**\n**  libcddb  ...\n**"
cd $TMP/tmp-$PRGNAM/libcddb-$CDDB
CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_cddb.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_cddb.log
# Install libcddb into a temp location so cdio and vlc can pickup the library
echo -e "\n**\n**\n"
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_cddb.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libcddb/
cp ABOUT-NLS AUTHORS COPYING ChangeLog NEWS README THANKS TODO \
  $VLCDEPSDIR/doc/libcddb/ || true
cd -
}

# -----------------------------------------------------------------------------
# Compile libcdio
# -----------------------------------------------------------------------------
make_cdio()
{
echo -e "**\n**  libcdio  ...\n**"
cd $TMP/tmp-$PRGNAM/libcdio-$CDIO
CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --enable-joliet \
  --enable-rock \
  --disable-cddb \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_cdio.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_cdio.log
# Install libcdio into a temp location so vlc can pickup the library
echo -e "\n**\n**\n"
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_cdio.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libcdio/
cp AUTHORS COPYING ChangeLog NEWS README* THANKS TODO \
  $VLCDEPSDIR/doc/libcdio/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile twolame
# -----------------------------------------------------------------------------
make_twolame()
{
echo -e "**\n**  twolame  ...\n**"
cd $TMP/tmp-$PRGNAM/twolame-$TWOLAME
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_twolame.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_twolame.log
# Install twolame into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_twolame.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/twolame/
cp AUTHORS COPYING ChangeLog NEWS README \
  $VLCDEPSDIR/doc/twolame/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile libupnp
# -----------------------------------------------------------------------------
make_upnp()
{
echo -e "**\n**  libupnp  ...\n**"
cd $TMP/tmp-$PRGNAM/libupnp-$UPNP

# Apply patches:
touch $OUTPUT/patch-${PRGNAM}_upnp.log
# Fix some libupnp bugs:
cat $SRCDIR/patches/libupnp_pthread.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_upnp.log
cat $SRCDIR/patches/libupnp_miniserver.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_upnp.log

autoreconf -vif \
  2>&1 | tee $OUTPUT/autoreconf-${PRGNAM}_upnp.log

CFLAGS="$SLKCFLAGS -DUPNP_STATIC_LIB" \
CXXFLAGS="$SLKCFLAGS -DUPNP_STATIC_LIB" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-ipv6 \
  --enable-static \
  --disable-shared \
  --disable-samples \
  --disable-debug \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_upnp.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_upnp.log
# Install libupnp into a temp location so vlc can pickup the library
echo -e "\n**\n**\n"
# The 'make install' will install into $VLCDEPSDIR :
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_upnp.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libupnp/
cp COPYING ChangeLog THANKS \
  $VLCDEPSDIR/doc/libupnp/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile srt
# -----------------------------------------------------------------------------
make_srt()
{
echo -e "**\n**  srt  ...\n**"
cd $TMP/tmp-$PRGNAM/srt-${SRT}

## Apply patches:
#touch $OUTPUT/patch-${PRGNAM}_srt.log
#cat $SRCDIR/patches/srt_fix_pc.patch \
#  | patch -p1 --verbose 2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_srt.log
#cat $SRCDIR/patches/srt_add_implicit_link_libraries.patch \
#  | patch -p1 --verbose 2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_srt.log

pkg_static "scripts/srt.pc.in"

# Adapt for x86_64 library paths:
sed -e "s,DESTINATION lib,&${LIBDIRSUFFIX}," \
    -e "s,lib/pkgconfig,lib${LIBDIRSUFFIX}/pkgconfig," \
    -i CMakeLists.txt

mkdir build
cd build
  CFLAGS="$SLKCFLAGS" \
  CXXFLAGS="$SLKCFLAGS" \
  LDFLAGS="$SLKLDFLAGS" \
  cmake .. \
    -DCMAKE_INSTALL_PREFIX=${VLCDEPSDIR}/usr \
    -DLIB_SUFFIX=${LIBDIRSUFFIX} \
    -DENABLE_SHARED=OFF \
    -DUSE_GNUTLS=ON \
    -DENABLE_CXX11=OFF \
    2>&1 | tee $OUTPUT/cmake-${PRGNAM}_srt.log
  make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_srt.log
  # Install srt into a temp location so vlc can pickup the library
  make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_srt.log
cd ..

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/srt/
cp CONTRIBUTING* LICENSE README* $VLCDEPSDIR/doc/srt/  || true
cd ..
}


# -----------------------------------------------------------------------------
# Compile dsm
# -----------------------------------------------------------------------------
make_dsm()
{
echo -e "**\n**  dsm  ...\n**"
cd $TMP/tmp-$PRGNAM/libdsm-${DSM}
export CFLAGS="$SLKCFLAGS"
export CXXFLAGS="$SLKCFLAGS"
export LDFLAGS="$SLKLDFLAGS"
mkdir meson-build
cd meson-build
  meson setup \
    --default-library=static \
    --prefix=$VLCDEPSDIR/usr \
    --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
    -Dauto_features=disabled -Dbinaries=false \
    .. 2>&1 | tee $OUTPUT/configure-${PRGNAM}_dsm.log
  ninja 2>&1 | tee $OUTPUT/make-${PRGNAM}_dsm.log
cd - 1>/dev/null

pkg_static "libdsm.pc.in"

# Install into a temp location so vlc can pickup the library
echo -e "\n**\n**\n"
ninja install -C meson-build 2>&1 | tee  $OUTPUT/install-${PRGNAM}_dsm.log

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/dsm/
cp AUTHORS COPYING NEWS $VLCDEPSDIR/doc/dsm/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile speex codec
# -----------------------------------------------------------------------------
make_speex()
{
echo -e "**\n**  speex  ...\n**"
cd $TMP/tmp-$PRGNAM/speex-$SPEEX

## We are using a git tarball now, we need to accommodate a bit:
#cat $SRCDIR/patches/speex_automake.patch | patch -p1 --verbose \
#  2>&1 | tee $OUTPUT/patch-${PRGNAM}_speex.log
#cat $SRCDIR/patches/speex_no-ogg.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_speex.log
#
#autoreconf -vif

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --disable-binaries \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_speex.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_speex.log
# Install speex into a temp location so libshout and vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_speex.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/speex/
cp AUTHORS COPYING ChangeLog NEWS README* TODO \
  $VLCDEPSDIR/doc/speex/  || true
cd -
}

# -----------------------------------------------------------------------------
# Compile speex dsp
# -----------------------------------------------------------------------------
make_speexdsp()
{
echo -e "**\n**  speexdsp  ...\n**"
cd $TMP/tmp-$PRGNAM/speexdsp-$SPEEXDSP

touch $OUTPUT/configure-${PRGNAM}_speexdsp.log

mkdir -p m4
autoreconf -vif \
  2>&1 | tee -a $OUTPUT/configure-${PRGNAM}_speexdsp.log

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --enable-resample-full-sinc-table \
  --disable-examples \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee -a $OUTPUT/configure-${PRGNAM}_speexdsp.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_speexdsp.log

pkg_static "speexdsp.pc"

# Install speexdsp into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_speexdsp.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/speexdsp/
cp AUTHORS* COPYING ChangeLog NEWS README* TODO \
  $VLCDEPSDIR/doc/speexdsp/  || true
cd -
}

# -----------------------------------------------------------------------------
# Compile libshout
# -----------------------------------------------------------------------------
make_shout()
{
echo -e "**\n**  libshout  ...\n**"
cd $TMP/tmp-$PRGNAM/libshout-$SHOUT

pkg_static "shout.pc.in"

touch $OUTPUT/patch-${PRGNAM}_shout.log
# Don't try to pull in openssl:
cat $SRCDIR/patches/libshout_no_openssl.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_shout.log
# Build fixes:
cat $SRCDIR/patches/libshout_stdio.patch  | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_shout.log
cat $SRCDIR/patches/libshout_strings.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_shout.log

# Prevent libtool error:
autoreconf -vif \
  2>&1 | tee $OUTPUT/autoreconf-${PRGNAM}_shout.log

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CPPFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --without-openssl \
  --enable-speex \
  --enable-static \
  --disable-shared \
  --disable-examples \
  --disable-tools \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_shout.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_shout.log
# Install libshout into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_shout.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libshout/
cp COPYING NEWS README \
  $VLCDEPSDIR/doc/libshout/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile goom
# -----------------------------------------------------------------------------
make_goom()
{
echo -e "**\n**  goom  ...\n**"
# First, fix a blatant bug in the archive:
find $TMP/tmp-$PRGNAM/goom${GOOM} -type d -exec chmod 755 {} \;
cd $TMP/tmp-$PRGNAM/goom${GOOM}

# I think MMX is crashing the goom plugin on 32-bit:
cat $SRCDIR/patches/goom-2k4-0.nommx.patch | patch -p1 --verbose \
  2>&1 | tee $OUTPUT/patch-${PRGNAM}_goom.log

# Do not install the xmms plugin to the root filesystem:
cat $SRCDIR/patches/goom2k4-xmmslibdir.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_goom.log

# Do not build the xmms plugin in the first place (GTK related errors):
cat $SRCDIR/patches/goom-2k4-0.noxmms.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_goom.log

# Eliminate a double include:
sed -i \
  -e "/^goom2_library_include_HEADERS =/s/goom_tools.h //g" \
  -e "/^goom2_library_include_HEADERS =/s/$/ goom_tools.h/" \
  src/Makefile.am

# Squash the automake errors:
autoreconf -vif -I m4

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_goom.log

make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_goom.log
# Install libgoom into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_goom.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/goom/
cp AUTHORS COPYING ChangeLog KNOWNBUGS NEWS README \
  $VLCDEPSDIR/doc/goom/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile glew
# -----------------------------------------------------------------------------
make_glew()
{
echo -e "**\n**  glew  ...\n**"
cd $TMP/tmp-$PRGNAM/glew-${GLEW}

CFLAGS="$SLKCFLAGS -DGLEW_STATIC" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
  make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_glew.log
# Install libGLEW into a temp location so vlc can pickup the library
make GLEW_DEST=$VLCDEPSDIR/usr install \
  2>&1 | tee -a $OUTPUT/make-${PRGNAM}_glew.log
# We must get rid of these:
rm $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libGLEW.so*
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/glew/
cp LICENSE* README* doc/* \
  $VLCDEPSDIR/doc/glew/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile projectM
# -----------------------------------------------------------------------------
make_projectm()
{
echo -e "**\n**  projectm  ...\n**"
cd $TMP/tmp-$PRGNAM/projectM-${PROJECTM}-Source

touch $OUTPUT/patch-${PRGNAM}_projectm.log
# Fix linking - get rid of unresolved symbols at runtime:
cat $SRCDIR/patches/projectM_static.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_projectm.log
# Fix building with gcc 6 and higher:
cat $SRCDIR/patches/projectM-${PROJECTM}_gcc.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_projectm.log

# We need to redefine the presets etc path:
sed -i -e "s#share/projectM#share/vlc/projectM#" $(grep -lr 'share/projectM' .)

mkdir build
cd build
  # I would need this to statically link to my libGLEW.a however it causes symbol errors:
  # libprojectM.a(projectM.cpp.o): relocation R_X86_64_32S against `_ZTV8projectM' can not be used when making a shared object; recompile with -fPIC
  #CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
  #CPPFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
  #LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
  #PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
  CFLAGS="$SLKCFLAGS" \
  CXXFLAGS="$SLKCFLAGS" \
  LDFLAGS="$SLKLDFLAGS" \
  cmake \
    -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
    -DUSE_FTGL:BOOL=OFF \
    -DUSE_NATIVE_GLEW:BOOL=OFF \
    -DINCLUDE-PROJECTM-LIBVISUAL:BOOL=OFF \
    -DINCLUDE-PROJECTM-PULSEAUDIO:BOOL=OFF \
    -DINCLUDE-PROJECTM-QT:BOOL=OFF \
    -DDISABLE_NATIVE_PRESETS:BOOL=ON \
    -DBUILD_PROJECTM_STATIC:BOOL=ON \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DLIB_SUFFIX=${LIBDIRSUFFIX} \
    .. \
    2>&1 | tee $OUTPUT/cmake-${PRGNAM}_projectm.log
  make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_projectm.log
  # Install projectm into a temp location so vlc can pickup the library
  make install DESTDIR=$VLCDEPSDIR \
    2>&1 | tee -a $OUTPUT/make-${PRGNAM}_projectm.log
  ## These are being forgotten...
  cp Renderer/libRenderer.a MilkdropPresetFactory/libMilkdropPresetFactory.a \
    $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/
cd ..
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/projectm/
cp COPYING ChangeLog $VLCDEPSDIR/doc/projectm/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile x262
# -----------------------------------------------------------------------------
make_x262()
{
echo -e "**\n**  x262  ...\n**"

case "$ARCH" in
  x86_64|arm*)
    ARCHOPTS="--enable-pic" ;;
  *)
    ARCHOPTS="" ;;
esac

cd $TMP/tmp-$PRGNAM/x262-$X262

# The sources are not yet too mature (copied from x264):
sed -i -e "s/x264/x262/g" configure
sed -i -e "s/x264_config/x262_config/g" *.h Makefile *.c

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-cli \
  --disable-avs \
  --disable-lavf \
  --disable-ffms \
  $ARCHOPTS \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_x262.log

# Compensate more for lack of maturity:
sed -i -e "s/x264.pc/x262.pc/g" Makefile
sed -i -e "s/x264.h/x262.h/g" Makefile

make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_x262.log

# Compensate even a bit more for lack of maturity:
cp x264.h x262.h

# Install x262 into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_x262.log

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/x262/
cp AUTHORS COPYING \
  $VLCDEPSDIR/doc/x264/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile x264
# -----------------------------------------------------------------------------
make_x264()
{
echo -e "**\n**  x264  ...\n**"

case "$ARCH" in
  x86_64|arm*)
    ARCHOPTS="--enable-pic" ;;
  *)
    ARCHOPTS="" ;;
esac

cd $TMP/tmp-$PRGNAM/x264-snapshot-${X264}-stable
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-cli \
  --disable-avs \
  --disable-lavf \
  --disable-ffms \
  --disable-opencl \
  $ARCHOPTS \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_x264.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_x264.log
# Install x264 into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_x264.log

echo -e "**\n**  x264  ...\n**"
echo -e "\n** 10-bit\n**" >> $OUTPUT/configure-${PRGNAM}_x264.log
echo -e "\n** 10-bit\n**" >> $OUTPUT/make-${PRGNAM}_x264.log

# Now add a x62410b (10-bit decoder) to the depsdir:
make clean
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-cli \
  --disable-avs \
  --disable-lavf \
  --disable-ffms \
  --disable-opencl \
  --bit-depth=10 \
  $ARCHOPTS \
  2>&1 | tee -a $OUTPUT/configure-${PRGNAM}_x264.log
sed -i -e 's/libx264/libx26410b/g' Makefile config.mak
sed -i -e 's/x264/x26410b/g' x264.pc
mv x264.pc x26410b.pc
sed -i -e 's/x264.pc/x26410b.pc/g' Makefile
make ${NUMJOBS} 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_x264.log
# Install x26410b into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_x264.log

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/x264/
cp AUTHORS COPYING \
  $VLCDEPSDIR/doc/x264/  || true
cd -
}

# -----------------------------------------------------------------------------
# Compile dv
# -----------------------------------------------------------------------------
make_dv()
{
echo -e "**\n**  dv  ...\n**"
cd $TMP/tmp-$PRGNAM/libdv-${DV}
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --disable-gtk \
  --disable-xv \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_dv.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_dv.log
# Install dv into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_dv.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libdv/
cp AUTHORS COPYING COPYRIGHT ChangeLog NEWS README* TODO \
  $VLCDEPSDIR/doc/libdv/  || true
cd -
}

# -----------------------------------------------------------------------------
# Compile libdvbpsi library
# -----------------------------------------------------------------------------
make_dvbpsi()
{
echo -e "**\n**  dvbpsi ...\n**"
cd $TMP/tmp-$PRGNAM/libdvbpsi-${DVBPSI}
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --disable-debug \
  --enable-release \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_dvbpsi.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_dvbpsi.log
# Install dvbpsi into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_dvbpsi.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libdvbpsi/
cp AUTHORS COPYING ChangeLog NEWS README \
  $VLCDEPSDIR/doc/libdvbpsi/  || true
cd -
}

# -----------------------------------------------------------------------------
# Compile libdca library
# -----------------------------------------------------------------------------
make_dca()
{
echo -e "**\n**  dca ...\n**"
cd $TMP/tmp-$PRGNAM/libdca-${DCA}

pkg_static "libdca/libdca.pc.in"

[ ! -x configure ] && autoreconf -vif \
  2>&1 | tee $OUTPUT/bootstrap-${PRGNAM}_dca.log

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --disable-debug \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_dca.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_dca.log
# Install dca into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_dca.log
# Fix a broken symlink:
( cd $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}
  if [ -L libdts.a ] ; then
    rm -f libdts.a ; ln -s libdca.a libdts.a
  fi
)
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libdca/
cp AUTHORS COPYING ChangeLog NEWS README TODO \
  $VLCDEPSDIR/doc/libdca/  || true
cd -
}

# -----------------------------------------------------------------------------
# Compile avc1394 raw1394 and dc1394 libraries
# VLC will use these
# -----------------------------------------------------------------------------
make_1394()
{
echo -e "**\n**  1394 ...\n**"
OLDDIR=$(pwd)
cd $TMP/tmp-$PRGNAM/libraw1394-${RAW1394}

# Or else vlc compilation fails with "error: redefinition of typedef 'byte_t'"
patch -p0 --verbose < $SRCDIR/patches/libraw1394_typedef.patch \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_raw1394.log

[ ! -x configure ] && ./autogen.sh

# Seems I need this ugly prefix or else I have to dig into the problem of vlc
# incorrectly interpreting *.la contents...
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --mandir=$VLCDEPSDIR/usr/man \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_raw1394.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_raw1394.log
# Install libraw1394 into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_raw1394.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libraw1394/
cp AUTHORS COPYING.LIB ChangeLog NEWS README \
  $VLCDEPSDIR/doc/libraw1394/  || true

echo -e "**\n**"

cd $TMP/tmp-$PRGNAM/libavc1394-${AVC1394}

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CPPFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
LIBRAW1394_CFLAGS="-I$VLCDEPSDIR/usr/include" \
LIBRAW1394_LIBS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} -lraw1394" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_avc1394.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_avc1394.log
# Install libavc1394 into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_avc1394.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libavc1394/
cp AUTHORS COPYING ChangeLog NEWS README TODO \
  $VLCDEPSDIR/doc/libavc1394/  || true

echo -e "**\n**"

cd $TMP/tmp-$PRGNAM/libdc1394-${DC1394}

## Skip building the examples - those cause errors:
#cat $SRCDIR/patches/libdc1394-noexamples.patch | patch -p1 --verbose \
#  2>&1 | tee $OUTPUT/patch-${PRGNAM}_dc1394.log

# Make sure that the static libdc1394 is found in the vlcdeps:
CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CPPFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} -lraw1394 $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --disable-examples \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_dc1394.log
  # Building the examples fails on kernel >= 2.6.38 because that deprecated
  # the v4l1 interface. You'll get the error "dc1394_vloopback.c:49:28:
  # fatal error: linux/videodev.h: No such file or directory"
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_dc1394.log
# Install libdc1394 into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_dc1394.log
# Fix the pkgconfig file to get rid of unresolved symbols at runtime:
sed -i -e "/^Libs:/s/$/ -lavc1394 -lraw1394/" $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig/libdc1394-2.pc
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libdc1394/
cp AUTHORS COPYING ChangeLog NEWS README \
  $VLCDEPSDIR/doc/libdc1394/  || true

cd $OLDDIR
}


# -----------------------------------------------------------------------------
# Compile fribidi
# -----------------------------------------------------------------------------
make_fribidi()
{
echo -e "**\n**  fribidi  ...\n**"
cd $TMP/tmp-$PRGNAM/fribidi-$FRIBIDI

# Apply patches:
touch $OUTPUT/patch-${PRGNAM}_fribidi.log
## Do not build tests and binaries:
#cat $SRCDIR/patches/fribidi_nobins.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_fribidi.log

meson build \
  --default-library=static \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  -Ddocs=false -Dbin=false -Dtests=false \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_fribidi.log
# Install fribidi into a temp location so vlc can pickup the library
echo -e "\n**\n**\n"
ninja install -C build 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_fribidi.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/fribidi/
cp AUTHORS COPYING NEWS README THANKS TODO \
  $VLCDEPSDIR/doc/fribidi/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile libass
# -----------------------------------------------------------------------------
make_ass()
{
echo -e "**\n**  ass  ...\n**"
cd $TMP/tmp-$PRGNAM/libass-$ASS

## Make it find libiconv if present:
#cat $SRCDIR/patches/libass_fix_iconv.patch | patch -p1 --verbose \
#  2>&1 | tee $OUTPUT/patch-${PRGNAM}_ass.log

# And since we patched the configure:
autoreconf -vif

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_ass.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_ass.log
# Install libass into a temp location so vlc can pickup the library
echo -e "\n**\n**\n"
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_ass.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libass/
cp COPYING Changelog $VLCDEPSDIR/doc/libass/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile taglib
# -----------------------------------------------------------------------------
make_taglib()
{
echo -e "**\n**  taglib  ...\n**"
cd $TMP/tmp-$PRGNAM/taglib-${TAGLIB}

CXX=gcc \
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
cmake . \
  -DCMAKE_INSTALL_PREFIX=/usr \
  -DLIB_SUFFIX=${LIBDIRSUFFIX} \
  -DBUILD_SHARED_LIBS=OFF \
  -DWITH_ASF:BOOL=ON \
  -DWITH_MP4:BOOL=ON \
  2>&1 | tee $OUTPUT/cmake-${PRGNAM}_taglib.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_taglib.log
# Install taglib into a temp location so vlc can pickup the library
make install DESTDIR=$VLCDEPSDIR \
  2>&1 | tee -a $OUTPUT/make-${PRGNAM}_taglib.log

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/taglib/
cp AUTHORS COPYING* $VLCDEPSDIR/doc/taglib/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile fluidsynth
# -----------------------------------------------------------------------------
make_fluid()
{
echo -e "**\n**  fluidsynth  ...\n**"
cd $TMP/tmp-$PRGNAM/fluidsynth-$FLUID
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --enable-double \
  --disable-jack-support \
  --without-readline \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_fluid.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_fluid.log
# Install fluid into a temp location so vlc can pickup the library
echo -e "\n**\n**\n"
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_fluid.log
# Fix a missing link dependency (resolves 'unknown symbols' runtime):
sed -i -e "/^Libs:/s/$/ -lasound -pthread -lgthread-2.0 -lrt -lglib-2.0/" $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig/fluidsynth.pc
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/fluidsynth/
cp AUTHORS COPYING ChangeLog NEWS README THANKS TODO \
  $VLCDEPSDIR/doc/fluidsynth/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile kate
# -----------------------------------------------------------------------------
make_kate()
{
echo -e "**\n**  kate ...\n**"
cd $TMP/tmp-$PRGNAM/libkate-${KATE}

## Compatibility patch for libpng14:
#cat $SRCDIR/patches/libkate_png14.patch | patch -p0 --verbose \
#  2>&1 | tee $OUTPUT/patch-${PRGNAM}_kate.log

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
LEXLIB="/usr/lib${LIBDIRSUFFIX}/libfl.a" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --disable-valgrind \
  --disable-doc \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_kate.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_kate.log
# Install kate into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_kate.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libkate/
cp AUTHORS COPYING README THANKS \
  $VLCDEPSDIR/doc/libkate/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile libtiger
# -----------------------------------------------------------------------------
make_tiger()
{
echo -e "**\n**  tiger ...\n**"
cd $TMP/tmp-$PRGNAM/libtiger-${TIGER}

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --disable-doc \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_tiger.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_tiger.log
# Install tiger into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_tiger.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libtiger/
cp AUTHORS COPYING README THANKS \
  $VLCDEPSDIR/doc/libtiger/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile lua
# -----------------------------------------------------------------------------
make_lua()
{
echo -e "**\n**  lua ...\n**"
cd $TMP/tmp-$PRGNAM/lua-${LUA}

# Use 32-bits LUAC file format on all platforms. In other words,
# 64-bits platform will support 32-bits LUAC files and reject 64-bits LUAC
# files. This should ease cross-compilation and copying luac files manually.
cat $SRCDIR/patches/luac-32bits.patch | patch -p1 --verbose \
  2>&1 | tee $OUTPUT/patch-${PRGNAM}_lua.log

# Make it use our CFLAGS:
sed -i "s/-DLUA_USE_LINUX/\"-DLUA_USE_LINUX $SLKCFLAGS\"/g" src/Makefile

# Fix paths (lib64 for x86_64):
sed -i -e "s#/lib#/lib${LIBDIRSUFFIX}#" Makefile
sed -i -e "s#/usr/local#/usr#" Makefile

MYLDFLAGS="$SLKLDFLAGS -ld" make linux ${NUMJOBS} \
  2>&1 | tee $OUTPUT/make-${PRGNAM}_lua.log
# Install lua into a temp location so vlc can pickup the library
make install INSTALL_TOP=$VLCDEPSDIR/usr \
  2>&1 | tee -a $OUTPUT/make-${PRGNAM}_lua.log
# Install a pkg-config file:
install -D -m 0644 etc/lua.pc $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig/lua.pc
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/lua
cp COPYRIGHT HISTORY README $VLCDEPSDIR/doc/lua/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile libva
# -----------------------------------------------------------------------------
make_libva()
{
echo -e "**\n**  libva ...\n**"
cd $TMP/tmp-$PRGNAM/libva-$LIBVA

#
# == NOTE ON VAAPI ==
#
# VAAPI can enable hardware accelerated playback for MPEG-2/4, H.264/AVC
# and VC-1 video on certain graphics hardware. 
# The VAAPI support in this VLC package depends on VA drivers that you have to
# install yourself for your specific hardware. The drivers should go into
# directory /usr/lib${LIBDIRSUFFIX}/dri .
# If you install my libva package you can get MPEG-2 hardware acceleration on
# Intel graphics.
# If you additionally install my libva-vdpau-driver package, then you get
# hardware acceleration on Nvidia graphics (with nvidia's binary driver).
# If you own an Ati card and use the fglrx driver, then you can achieve
# hardware acceleration by installing the xvba-video driver from here:
# http://www.splitted-desktop.com/~gbeauchesne/xvba-video/ (since I do not own
# Ati hardware I can not build a package for xvba-video myself)
#

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=/usr \
  --libdir=/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_libva.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_libva.log
# Strip the static lib to prevent linking errors in 64-bit,
find . -name "*.a" | xargs strip --strip-unneeded
# Install libva into a temp location so vlc can pickup the library
echo -e "\n**\n**\n"
make install DESTDIR=$VLCDEPSDIR 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_libva.log
# Remove the .so and .la files; we want static linking.
rm -f $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libva*.so*
rm -f $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libva*.la
# Fix the pkgconfig file to get rid of unresolved symbols at link time:
sed -i -e "/^Libs:/s/$/ -lX11 -lXext -lXfixes -ldrm -ldl/" \
  $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig/libva*.pc
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libva/
cp COPYING NEWS $VLCDEPSDIR/doc/libva/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile libvdpau
# -----------------------------------------------------------------------------
make_vdpau()
{
echo -e "**\n**  vdpau ...\n**"
cd $TMP/tmp-$PRGNAM/libvdpau-$VDPAU

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=/usr \
  --libdir=/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-documentation \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_vdpau.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_vdpau.log
# Strip the static lib to prevent linking errors in 64-bit,
find . -name "*.a" | xargs strip --strip-unneeded
# Install vdpau into a temp location so vlc can pickup the library
echo -e "\n**\n**\n"
make install DESTDIR=$VLCDEPSDIR 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_vdpau.log
# Remove the .so and .la files; we want static linking.
rm -f $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libvdpau*.so*
rm -f $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libvdpau*.la
rm -f $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/vdpau/libvdpau*.so*
rm -f $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/vdpau/libvdpau*.la
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/vdpau/
cp AUTHORS COPYING ChangeLog NEWS README $VLCDEPSDIR/doc/vdpau/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile VP8
# -----------------------------------------------------------------------------
make_vpx()
{
echo -e "**\n**  vpx  ...\n**"
cd $TMP/tmp-$PRGNAM/libvpx-${VPX}

case "$ARCH" in
  i?86)
    ARCHOPTS="--target=x86-linux-gcc"
    ;;
  x86_64)
    ARCHOPTS="--target=${ARCH}-linux-gcc --enable-pic"
    ;;
  armv7hl)
    ARCHOPTS="--target=armv7-linux-gcc --enable-pic"
    cat $SRCDIR/patches/libvpx_fix-armhf-link.patch | patch -p1 --verbose
    export AS=as
    export AR=ar
    export CROSS="${TARGET}-"
    ;;
  arm*)
    ARCHOPTS="--target=armv5te-linux-gcc --enable-pic"
    export AS=as
    export AR=ar
    export CROSS="${TARGET}-"
    ;;
  *)
    ARCHOPTS="--target=${ARCH}-linux-gcc"
    ;;
esac

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --disable-install-bins \
  --disable-install-srcs \
  --disable-install-libs \
  --disable-debug-libs \
  --disable-debug \
  --disable-docs \
  --disable-examples \
  --disable-unit-tests \
  --enable-postproc \
  --enable-runtime-cpu-detect \
  $ARCHOPTS \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_vpx.log
  #--disable-examples \ causes errors
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_vpx.log
# Install libvpx into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_vpx.log
# The build system vor libvpx is not yet mature:
cp -a --parents vpx/*.h ${VLCDEPSDIR}/usr/include/
cp -a libvpx.a ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}
cp -a libvpx_g.a ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/vpx/
cp AUTHORS CHANGELOG LICENSE README \
  $VLCDEPSDIR/doc/vpx/  || true
cd -
}

# -----------------------------------------------------------------------------
# Compile ogg opus libraries
# -----------------------------------------------------------------------------
make_opus()
{
echo -e "**\n**  opus ...\n**"
cd $TMP/tmp-$PRGNAM/opus-${OPUS}

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --disable-doc \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_opus.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_opus.log
# Install opus into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_opus.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/opus/
cp AUTHORS COPYING ChangeLog NEWS README \
  $VLCDEPSDIR/doc/opus/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile dav1d libraries
# -----------------------------------------------------------------------------
make_dav1d()
{
echo -e "**\n**  dav1d ...\n**"
cd $TMP/tmp-$PRGNAM/dav1d-${DAV1D}

# Needs a newer nasm to make it compile on 14.2!
meson build \
  --prefix $VLCDEPSDIR/usr \
  --default-library static \
  --backend ninja \
  --buildtype release \
  -Dlibdir=lib${LIBDIRSUFFIX} \
  -Denable_tests=false -Denable_tools=false \
  2>&1 | tee $OUTPUT/make-${PRGNAM}_opus.log
# Install dav1d into a temp location so vlc can pickup the library
cd build
  ninja install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_dav1d.log
cd - 1>/dev/null
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/dav1d/
cp COPYING NEWS *.md doc/PATENTS \
  $VLCDEPSDIR/doc/dav1d/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile microdns
# -----------------------------------------------------------------------------
make_microdns()
{
echo -e "**\n**  microdns ...\n**"
cd $TMP/tmp-$PRGNAM/microdns-${MDNS}

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
meson build \
  -Dauto_features=disabled \
  --default-library=static \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_microdns.log
# Install microdns into a temp location so vlc can pickup the library
ninja install -C build 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_microdns.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/microdns/
cp AUTHORS COPYING NEWS \
  $VLCDEPSDIR/doc/microdns/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile libbluray
# -----------------------------------------------------------------------------
make_bluray()
{
echo -e "**\n**  bluray ...\n**"
cd $TMP/tmp-$PRGNAM/libbluray-${BLURAY}

# Apply patches:
touch $OUTPUT/patch-${PRGNAM}_bluray.log
# Add bdjo header:
cat $SRCDIR/patches/bluray_bdjo-data-header.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_bluray.log

# Fix 64bit library path:
sed -i -e "s|/usr/lib/libbluray|/usr/lib${LIBDIRSUFFIX}/libbluray|" \
  src/libbluray/bdj/bdj.c

# Make it stop whining about automake-1.16 on Slackware 14.2:
autoreconf -vif \
  2>&1 | tee $OUTPUT/bootstrap-${PRGNAM}_bluray.log

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --disable-doxygen-doc \
  --disable-examples \
  --disable-silent-rules \
  --disable-shared \
  --enable-static \
  --with-libxml2 \
  --enable-bdjava-jar \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_bluray.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_bluray.log
# Install libbluray into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_bluray.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libbluray/
cp COPYING README* $VLCDEPSDIR/doc/libbluray/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile asdclpib - AS-DCP File Access Library
# -----------------------------------------------------------------------------
make_asdcplib()
{
echo -e "**\n**  asdcplib ...\n**"
cd $TMP/tmp-$PRGNAM/asdcplib-${ASDCPLIB}

# Apply patches:
touch $OUTPUT/patch-${PRGNAM}_asdcplib.log
cat $SRCDIR/patches/asdcplib_nettle.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_asdcplib.log

# The patch touches configure.ac:
#[ ! -x configure ] && sh bootstrap
autoreconf -vif \
  2>&1 | tee $OUTPUT/reconf-${PRGNAM}_asdcplib.log

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS -std=gnu++98" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --disable-shared \
  --enable-dev-headers \
  --enable-freedist \
  --enable-static \
  --with-nettle \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_asdcplib.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_asdcplib.log
# Install asdcplib into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_asdcplib.log
# Add a .pc file otherwise VLC will not find the library:
mkdir -p $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig
cat <<EOT > $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig/asdcplib.pc
prefix=$VLCDEPSDIR/usr
exec_prefix=\${prefix}
includedir=\${prefix}/include
libdir=\${exec_prefix}/lib${LIBDIRSUFFIX}

Name: asdcplib
Description: The asdcp library
Version: ${ASDCPLIB}
Cflags: -I\${includedir}
Libs: -L\${libdir} -lasdcp -lkumu -lnettle -lgmp
EOT
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/asdcplib/
cp COPYING* README* $VLCDEPSDIR/doc/asdcplib/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile x265
# -----------------------------------------------------------------------------
make_x265()
{
echo -e "**\n**  x265  ...\n**"
# We use videolan's contribs repository now:
cd $TMP/tmp-$PRGNAM/x265_${X265}

pkg_static "source/x265.pc.in"

# Set the compiler flags:
CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS"

# We follow the build instructions at:
# https://github.com/videolan/x265/blob/master/build/linux/multilib.sh
# See also https://bitbucket.org/multicoreware/x265/wiki/Home :
# Build 10bit and 12bit only on x86_64 for which assembler code exists.
if [ "$ARCH" = "x86_64" ]; then
  mkdir build-12
  cd build-12
    cmake ../source \
      -DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
      -DCMAKE_C_FLAGS_RELEASE:STRING="$SLKCFLAGS" \
      -DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \
      -DCMAKE_CXX_FLAGS_RELEASE:STRING="$SLKCFLAGS" \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DLIB_INSTALL_DIR=lib${LIBDIRSUFFIX} \
      -DHIGH_BIT_DEPTH=ON \
      -DMAIN12=ON \
      -DEXPORT_C_API=OFF \
      -DENABLE_CLI=OFF \
      -DENABLE_SHARED=OFF \
      -DCMAKE_BUILD_TYPE=Release \
    2>&1 | tee $OUTPUT/configure-${PRGNAM}_x265.log
    make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_x265.log
  cd -
  mkdir build-10
  cd build-10
    cmake ../source \
      -DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
      -DCMAKE_C_FLAGS_RELEASE:STRING="$SLKCFLAGS" \
      -DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \
      -DCMAKE_CXX_FLAGS_RELEASE:STRING="$SLKCFLAGS" \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DLIB_INSTALL_DIR=lib${LIBDIRSUFFIX} \
      -DHIGH_BIT_DEPTH=ON \
      -DEXPORT_C_API=OFF \
      -DENABLE_CLI=OFF \
      -DENABLE_SHARED=OFF \
      -DCMAKE_BUILD_TYPE=Release \
    2>&1 | tee -a $OUTPUT/configure-${PRGNAM}_x265.log
    make ${NUMJOBS} 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_x265.log
  cd -
  mkdir build-8
  cd build-8
    ln -s ../build-10/libx265.a libx265_main10.a
    ln -s ../build-12/libx265.a libx265_main12.a
    cmake ../source \
      -DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
      -DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DLIB_INSTALL_DIR=lib${LIBDIRSUFFIX} \
      -DEXTRA_LIB="x265_main10.a;x265_main12.a" \
      -DEXTRA_LINK_FLAGS="-L." \
      -DLINKED_10BIT=ON \
      -DLINKED_12BIT=ON \
      -DENABLE_SHARED=OFF \
      -DCMAKE_BUILD_TYPE=Release \
    2>&1 | tee -a $OUTPUT/configure-${PRGNAM}_x265.log
    make ${NUMJOBS} 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_x265.log
    # Rename the 8bit library, then combine all three into libx265.a using ar:
    mv libx265.a libx265_main.a
    ar -M <<EOF
CREATE libx265.a
ADDLIB libx265_main.a
ADDLIB libx265_main10.a
ADDLIB libx265_main12.a
SAVE
END
EOF
else
  mkdir build-8
  cd build-8
    cmake ../source \
      -DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
      -DCMAKE_C_FLAGS_RELEASE:STRING="$SLKCFLAGS" \
      -DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \
      -DCMAKE_CXX_FLAGS_RELEASE:STRING="$SLKCFLAGS" \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DLIB_INSTALL_DIR=lib${LIBDIRSUFFIX} \
      -DENABLE_SHARED=OFF \
      -DCMAKE_BUILD_TYPE=Release \
    2>&1 | tee $OUTPUT/configure-${PRGNAM}_x265.log
    make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_x265.log
fi

# We were left in the final build directory:
# Install x265 into a temp location so vlc can pickup the library
make install DESTDIR=$VLCDEPSDIR \
  2>&1 | tee -a $OUTPUT/make-${PRGNAM}_x265.log
cd ..

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/x265/
cp COPYING* build/README* $VLCDEPSDIR/doc/x265/  || true
}

# -----------------------------------------------------------------------------
# Compile libssh2
# -----------------------------------------------------------------------------
make_ssh2()
{
echo -e "**\n**  ssh2 ...\n**"
cd $TMP/tmp-$PRGNAM/libssh2-${SSH2}

# Apply patches:
touch $OUTPUT/patch-${PRGNAM}_ssh2.log
cat $SRCDIR/patches/libssh2_notests.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_ssh2.log

pkg_static "libssh2.pc.in"

autoreconf -vif \
  2>&1 | tee $OUTPUT/reconf-${PRGNAM}_ssh2.log

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS -lz -lgpg-error" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --enable-static \
  --disable-shared \
  --disable-examples-build \
  --with-crypto=libgcrypt \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_ssh2.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_ssh2.log
# Install ssh2 into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_ssh2.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libssh2/
cp COPYING ChangeLog NEWS README \
  $VLCDEPSDIR/doc/libssh2/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile protobuf - required for chromecast
# -----------------------------------------------------------------------------
make_protobuf()
{
echo -e "**\n**  protobuf ...\n**"
cd $TMP/tmp-$PRGNAM/protobuf-${PROTOBUF}

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS -std=gnu++98" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --disable-shared \
  --enable-static \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_protobuf.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_protobuf.log
# Install protobuf into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_protobuf.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/protobuf/
cp LICENSE *.txt $VLCDEPSDIR/doc/protobuf/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile pcre2
# -----------------------------------------------------------------------------
make_pcre2()
{
echo -e "**\n**  pcre2 ...\n**"
cd $TMP/tmp-$PRGNAM/pcre2-${PCRE2}

CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS" \
CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS -std=gnu++98" \
LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  --disable-shared \
  --disable-silent-rules \
  --enable-static \
  --enable-static=no \
  --enable-pcre2-16 \
  --enable-pcre2-32 \
  --enable-jit \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_pcre2.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_pcre2.log
# Install pcre2 into a temp location so qtbase can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_pcre2.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/pcre2/
cp AUTHORS COPYING ChangeLog HACKING LICENCE NEWS README \
  $VLCDEPSDIR/doc/pcre2/  || true
cd -
}


# -----------------------------------------------------------------------------
# Compile libplacebo
# -----------------------------------------------------------------------------
make_placebo()
{
echo -e "**\n**  placebo ...\n**"
cd $TMP/tmp-$PRGNAM/libplacebo-${PLACEBO}

# Our meson is too old but still useable:
cat $SRCDIR/patches/libplacebo_meson.patch | patch -p0 --verbose \
  2>&1 | tee $OUTPUT/patch-${PRGNAM}_placebo.log

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
meson build \
  -Dbuildtype=release \
  --default-library=static \
  --prefix=$VLCDEPSDIR/usr \
  --libdir=$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_placebo.log
# Install libplacebo into a temp location so vlc can pickup the library
ninja install -C build 2>&1 | tee $OUTPUT/make-${PRGNAM}_placebo.log
# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/libplacebo/
cp LICENSE README.md \
  $VLCDEPSDIR/doc/libplacebo/ || true
cd -
}


# -----------------------------------------------------------------------------
# Compile soxr
# -----------------------------------------------------------------------------
make_soxr()
{
echo -e "**\n**  soxr  ...\n**"
cd $TMP/tmp-$PRGNAM/soxr-${SOXR}-Source

echo > $OUTPUT/patch-${PRGNAM}_soxr.log
# Find our own ffmpeg instead of the system version:
cat $SRCDIR/patches/soxr_find_ffmpeg.patch |patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_soxr.log
# Allow static compilation into vlc:
cat $SRCDIR/patches/soxr_expose_privatelibs.patch |patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_soxr.log

pkg_static "src/soxr.pc.in"

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
LDFLAGS="$SLKLDFLAGS" \
cmake . \
  -DCMAKE_INSTALL_PREFIX=${VLCDEPSDIR}/usr \
  -DLIB_SUFFIX=${LIBDIRSUFFIX} \
  -DBUILD_SHARED_LIBS=OFF \
  -DBUILD_EXAMPLES=OFF \
  -DBUILD_TESTS=OFF \
  -DWITH_LSR_BINDINGS=OFF \
  -DWITH_OPENMP=OFF \
  -DWITH_AVFFT=ON \
  -Wno-dev \
  2>&1 | tee $OUTPUT/cmake-${PRGNAM}_soxr.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_soxr.log
# Install soxr into a temp location so vlc can pickup the library
make install 2>&1 | tee -a $OUTPUT/make-${PRGNAM}_soxr.log

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/soxr/
cp COPYING* LICENCE NEWS README $VLCDEPSDIR/doc/soxr/  || true
cd - 1>/dev/null
}


# -----------------------------------------------------------------------------
# Compile qt5 base - for the GUI
# -----------------------------------------------------------------------------
make_qt5base()
{
echo -e "**\n**  qt5base ...\n**"

RETDIR=$(pwd)
# If we build a static Qt5 gui, unset the QT-related environment variables,
# so that a pre-existing Qt will not be picked up and create errors later:
unset QTDIR
unset QT5DIR
NEWPATH="$VLCDEPSDIR/usr/bin"
for elem in $(echo $PATH | cut -d: --output-delimiter=' ' -f1-) ; do
  if ! $(echo "$elem"| grep -q /qt) ; then
    NEWPATH="$NEWPATH:$elem"
  fi
done
export PATH="$NEWPATH"

export CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export OPENSOURCE_CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS"
export PKG_CONFIG_PATH="${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/pkgconfig"
export PKG_CONFIG="/usr/bin/pkg-config --static"

# qtbase:
cd $TMP/tmp-$PRGNAM/$(ls --indicator-style=none | grep qtbase-*-${QT5})

# Apply patches:
touch $OUTPUT/patch-${PRGNAM}_qtbase.log

# Don't tag binaries in static mode (causes this error on linking vlc library
# dynamically - "version node not found for symbol qt_version_tag@Qt_5.5":
cat $SRCDIR/patches/qtbase_dont_tag_static_binaries.patch |patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_qtbase.log

# Fix missing private includes:
sed -e '/CMAKE_NO_PRIVATE_INCLUDES\ \=\ true/d' \
  -i mkspecs/features/create_cmake.prf

# Use our custom compiler and linker flags:
#sed -i -e "s,-O2,$CFLAGS," mkspecs/common/g++-base.conf || exit 1
sed -i -e "s,-O2,$CFLAGS," mkspecs/common/gcc-base.conf || exit 1
sed -i -e "s,-O3,$CFLAGS," mkspecs/common/gcc-base.conf || exit 1
sed -i -e "/^QMAKE_LFLAGS\s/s,+=,+= $LDFLAGS,g" mkspecs/common/gcc-base.conf || exit 1

./configure \
  -platform linux-g++ \
  -confirm-license \
  -opensource \
  -prefix $VLCDEPSDIR/usr \
  -libdir $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} \
  -headerdir $VLCDEPSDIR/usr/include/qt5 \
  -datadir $VLCDEPSDIR/usr/share/qt5 \
  -archdatadir $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/qt5 \
  -release \
  -static \
  -icu \
  -qpa xcb \
  -qt-xcb \
  -qt-xkbcommon-x11 \
  -qt-libjpeg \
  -system-harfbuzz -system-libpng -system-pcre -system-zlib \
  -no-gif \
  -no-openssl -no-opengl -no-dbus -no-qml-debug \
  -no-sql-odbc -no-sql-sqlite \
  -no-compile-examples -nomake examples -nomake tests \
  -no-separate-debug-info \
  -no-pch \
  -no-shared \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}_qt5base.log
  #-no-pkg-config \
  #-no-use-gold-linker \
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_qt5base.log

# Install into a temp location so vlc can find it (INSTALL_ROOT not needed):
make install \
    2>&1 | tee $OUTPUT/install-${PRGNAM}_qt5base.log

# Move the plugins that VLC needs into libdir, and # add these static
# plugin libraries to .pc files to prevent runtime error
# "plugins are disabled in static builds"
# (only seen when starting vlc as 'QT_DEBUG_PLUGINS=1 vlc'):
mv ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/qt5/plugins/platforms/libqxcb.* \
  ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/
rm -rf ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/qt5/plugins
sed -i -e 's/ -lQt5Gui/ -lfontconfig -lX11 -lxcb -lqxcb -lQt5XcbQpa -lQt5PlatformSupport -lQt5Gui/g' \
  ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/pkgconfig/Qt5Gui.pc

# Link includes to match what VLC expects
mkdir -p ${VLCDEPSDIR}/usr/include/QtGui/qpa
ln -s \
 ${VLCDEPSDIR}/usr/include/qt5/QtGui/${QT5}/QtGui/qpa/qplatformnativeinterface.h \
 ${VLCDEPSDIR}/usr/include/QtGui/qpa/

# Prevent weirdness later on:
unset PKG_CONFIG

# Remove unwanted library:
rm -f $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libQt5Bootstrap*

# Remove all .la files:
find "$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}" -type f -name '*.la' \
  -exec rm -f {} \;

# Fix the path in prl files:
find "$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}" -type f -name '*.prl' \
  -exec sed -i -e '/^QMAKE_PRL_BUILD_DIR/d;s/\(QMAKE_PRL_LIBS =\).*/\1/' {} \;

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/qtt5base/
cp *GPL_EXCEPTION* INSTALL LICENSE* README* \
  $VLCDEPSDIR/doc/qt5base/  || true
cd $RETDIR
}


# -----------------------------------------------------------------------------
# Compile qt5svg
# -----------------------------------------------------------------------------
make_qt5svg()
{
echo -e "**\n**  qt5svg ...\n**"

RETDIR=$(pwd)
# If we build a static Qt5 gui, unset the QT-related environment variables,
# so that a pre-existing Qt will not be picked up and create errors later:
unset QTDIR
unset QT5DIR
NEWPATH="$VLCDEPSDIR/usr/bin"
for elem in $(echo $PATH | cut -d: --output-delimiter=' ' -f1-) ; do
  if ! $(echo "$elem"| grep -q /qt) ; then
    NEWPATH="$NEWPATH:$elem"
  fi
done
export PATH="$NEWPATH"

export CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export OPENSOURCE_CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS"
export PKG_CONFIG_PATH="${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/pkgconfig"
export QTDIR="${VLCDEPSDIR}/usr"
#export QT_PLUGIN_PATH="${QTDIR}/lib${LIBDIRSUFFIX}/qt5/plugins"

# qtsvg:
cd $TMP/tmp-$PRGNAM/$(ls --indicator-style=none | grep qtsvg-*-${QT5})

## Make sure our private Qt5 headers are used:
#cat $SRCDIR/patches/qtsvg_use_private_qtzlib.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}_qt5svg.log

# Make and install:
qmake \
  2>&1 | tee $OUTPUT/qmake-${PRGNAM}_qt5svg.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_qt5svg.log
make install 2>&1 | tee $OUTPUT/install-${PRGNAM}_qt5svg.log

# Move static libraries into place, and fix up the .pc file
# so that they get linked into VLC later,:
mv ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/qt5/plugins/iconengines/libqsvgicon.* \
   ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/qt5/plugins/imageformats/libqsvg.* \
  ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/
rm -rf ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/qt5/plugins
sed -i ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/pkgconfig/Qt5Svg.pc \
  -e '/Libs:/  s/-lQt5Svg/-lqsvg -lqsvgicon -lQt5Svg/ '

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/qt5svg/
cp *GPL_EXCEPTION* LICENSE* \
  $VLCDEPSDIR/doc/qt5svg/  || true
cd $RETDIR
}


# -----------------------------------------------------------------------------
# Compile qt5x11extras
# -----------------------------------------------------------------------------
make_qt5x11extras()
{
echo -e "**\n**  qt5x11extras ...\n**"

RETDIR=$(pwd)
# If we build a static Qt5 gui, unset the QT-related environment variables,
# so that a pre-existing Qt will not be picked up and create errors later:
unset QTDIR
unset QT5DIR
NEWPATH="$VLCDEPSDIR/usr/bin"
for elem in $(echo $PATH | cut -d: --output-delimiter=' ' -f1-) ; do
  if ! $(echo "$elem"| grep -q /qt) ; then
    NEWPATH="$NEWPATH:$elem"
  fi
done
export PATH="$NEWPATH"

export CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export OPENSOURCE_CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export LDFLAGS="-L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS"
export PKG_CONFIG_PATH="${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/pkgconfig"
export QTDIR="${VLCDEPSDIR}/usr"
#export QT_PLUGIN_PATH="${QTDIR}/lib${LIBDIRSUFFIX}/qt5/plugins"

# qtx11extras:
cd $TMP/tmp-$PRGNAM/$(ls --indicator-style=none | grep qtx11extras-*-${QT5})

# Make and install:
qmake \
  2>&1 | tee $OUTPUT/qmake-${PRGNAM}_qt5x11extras.log
make ${NUMJOBS} 2>&1 | tee $OUTPUT/make-${PRGNAM}_qt5x11extras.log
make install 2>&1 | tee $OUTPUT/install-${PRGNAM}_qt5x11extras.log

# Add DOCS to the vlcdeps to have it added to vlc package later:
mkdir -p $VLCDEPSDIR/doc/qt5x11extras/
cp *GPL_EXCEPTION* LICENSE* \
  $VLCDEPSDIR/doc/qt5x11extras/  || true
cd $RETDIR
}


# -----------------------------------------------------------------------------
# VLC
# -----------------------------------------------------------------------------
make_vlc()
{
echo -e "**\n**  VLC ...\n**"
OLDDIR=$(pwd)
cd $TMP/tmp-$PRGNAM

# Determine the actual version of the program, and
# optionally the development branch it came from:

if [ ! -d {PRGNAM}-${SRCVER} ]; then
  NEWVER=$(ls -1 -d --indicator-style=none vlc-* 2>/dev/null)
  if [ -n "$NEWVER" ]; then
    echo "##"
    echo -n "## Changing vlc VERSION from '$VERSION' to "
    SRCVER=$(echo $NEWVER | cut -d- -f2-)
    VERSION=$(echo $SRCVER | tr '-' '.')
    echo "'$VERSION'"
    echo "##"
  else
    echo "Can not determine which version of VLC I should build!"
    exit 1
  fi
fi
if [ "$BRANCH" != "master" -a "x$BRANCH" != "x" ]; then
  VERSION=$(echo "${BRANCH}_${VERSION}" | tr - _)
fi

cd $TMP/tmp-$PRGNAM/${PRGNAM}-${SRCVER}

# Apply patches:
echo "" >$OUTPUT/patch-${PRGNAM}.log

# Make it possible to compile Qt5 statically for Linux:
cat $SRCDIR/patches/vlc_qt5static.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log

# Fix SDL header location:
sed -i -e "s#SDL_image.h#SDL/&#" -e "s#SDL.h#SDL/&#" $(grep -lr "SDL*.h" .)

# Only enable DLL loader on ELF ix86 platforms:
if [ "$ARCH" == "i486" -o "$ARCH" == "i686" ]; then
  DO_LOADER="--enable-loader"
else
  DO_LOADER=""
fi

if [ "$STATIC_FFMPEG" == "YES" ]; then
  # Fix runtime errors about missing symbols:
  ## vlc-cache-gen trips over at the end of the build, when we add LIBS
  ## to avoid missing symbols in the avcodec plugin at runtime: 
  if ! grep -q " -ldrm" ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/pkgconfig/libavcodec.pc ; then
    sed -i "/^Libs: /s/$/ -lvdpau -lva-drm -lva-x11 -lva -lX11 -lXext -lXfixes -lm -ldrm/" \
      ${VLCDEPSDIR}/usr/lib${LIBDIRSUFFIX}/pkgconfig/libavcodec.pc
  fi
fi

# If we built a static projectM support library, let's use it properly:
if [ -d $VLCDEPSDIR/usr/share/vlc/projectM ]; then
  sed -i -e "s#share/projectM#share/vlc/projectM#" \
    $(grep -lr 'share/projectM' .)
  sed -i -e "s#usr/share/fonts/truetype/ttf-dejavu#usr/share/fonts/TTF#" \
    $(grep -lr 'usr/share/fonts/truetype/ttf-dejavu' .)
fi

sh bootstrap

export PATH="$VLCDEPSDIR/usr/bin:$PATH"

export CPPFLAGS="-I$VLCDEPSDIR/usr/include"
export CFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"
export CXXFLAGS="-I$VLCDEPSDIR/usr/include $SLKCFLAGS"

if [ "$STATIC_QT5" = "YES" ]; then
  export QTDIR="${VLCDEPSDIR}/usr"
  export QT_PLUGIN_PATH="${QTDIR}/lib${LIBDIRSUFFIX}/qt5/plugins"
  # If we build a static Qt5 gui, make sure that any pre-existing
  # Qt5 installation will not be picked up and create errors later:
  NEWPATH=""
  for elem in $(echo $PATH | cut -d: --output-delimiter=' ' -f1-) ; do
    if ! $(echo "$elem"| grep -q /qt) ; then
      NEWPATH="$NEWPATH:$elem"
    fi
  done
  export PATH="$NEWPATH"
  # All the library additions in LDFLAGS are needed to quell missing symbol
  # errors when linking to the Qt5 libraries:
  if which pcre2-config 1>/dev/null 2>&1 ; then
    PCRECONFIG="pcre2-config"
  else
    PCRECONFIG="pcre-config"
  fi
  export LDFLAGS="-Wl,-Bsymbolic -L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} -lpng -lz -lharfbuzz $(icu-config --ldflags) $($PCRECONFIG --libs16) $SLKLDFLAGS"
else
  export LDFLAGS="-Wl,-Bsymbolic -L$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX} $SLKLDFLAGS"
fi

# Slackware > 14.2 switched to ncurses 6.x:
NCURSESWCONF=$(which ncursesw5-config 2>/dev/null || which ncursesw6-config 2>/dev/null)

NCURSES_CFLAGS="$(${NCURSESWCONF} --cflags) -I/usr/include" \
NCURSES_LIBS="$(${NCURSESWCONF} --libs)" \
PROJECTM_LIBS="-lprojectM $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libMilkdropPresetFactory.a $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libRenderer.a -lGLU -lGLEW -lGL" \
PROJECTM2_LIBS="-lprojectM $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libMilkdropPresetFactory.a $VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/libRenderer.a -lGLU -lGLEW -lGL" \
LUAC="$VLCDEPSDIR/usr/bin/luac" \
PKG_CONFIG_PATH="$VLCDEPSDIR/usr/lib${LIBDIRSUFFIX}/pkgconfig" \
./configure \
  --prefix=/usr \
  --libdir=/usr/lib${LIBDIRSUFFIX} \
  --sysconfdir=/etc \
  --mandir=/usr/man \
  --docdir=/usr/doc/vlc-$PKGVERSION \
  --localstatedir=/var \
  --without-contrib \
  --disable-rpath \
  --disable-debug \
  --disable-aom \
  --disable-freerdp \
  --disable-jack \
  --disable-zvbi \
  --enable-alsa \
  --enable-chromecast \
  --enable-shared \
  --enable-optimize-memory=no \
  --enable-ncurses \
  --enable-lua \
  --enable-dc1394 \
  --enable-dvbpsi \
  --enable-dvdnav \
  --enable-libcddb \
  --enable-projectm \
  --enable-svg \
  --enable-telx \
  --enable-libass \
  --enable-caca \
  --enable-aa \
  --enable-dsm \
  --enable-sftp \
  --enable-microdns \
  --enable-srt \
  --enable-upnp \
  --enable-flac \
  --enable-shout \
  --enable-live555 \
  --enable-realrtsp \
  --enable-soxr \
  --enable-speex \
  --enable-opus \
  --enable-x262 \
  --enable-x264 \
  --enable-x265 \
  --enable-a52 \
  --with-a52=$TMP/tmp-$PRGNAM/a52dec-$A52 \
  --enable-twolame \
  --enable-ogg \
  --enable-vorbis \
  --enable-theora \
  --enable-swscale \
  --enable-avcodec \
  --enable-avformat \
  --enable-libva \
  --enable-vdpau \
  ${DO_LOADER} \
  --enable-run-as-root \
  --with-default-font-family="Sans Bold" \
  --with-default-font="/usr/share/fonts/TTF/DejaVuSans-Bold.ttf" \
  --with-default-monospace-font="/usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf" \
  --program-prefix= \
  --program-suffix= \
  --build=$TARGET \
  2>&1 | tee $OUTPUT/configure-${PRGNAM}.log

  # Enabled by default:
  #--enable-dca \
  #--with-dca-tree=$TMP/tmp-$PRGNAM/libdca-$DCA \

  # Libdvdnav is now the default (which uses libdvdread in turn)
  #--enable-dvdread \
  #--with-dvdread-tree=$TMP/tmp-$PRGNAM/libdvdread-$DVDREAD \
  #--enable-goom \
  #--with-goom-tree=$TMP/tmp-$PRGNAM/goom$GOOM \

  # Sometimes skins support breaks and we'll have to disable it:
  #--disable-skins2 \

  # Got errors about missing sdt.h in ./modules/access/dvb/access.c
  #--with-dvbpsi-tree=$TMP/tmp-$PRGNAM/libdvbpsi5-${DVBPSI} \

  # Leave this out so that linking the static x264.a into a shared
  # library works on x86_64: 
  #--with-x264-tree=$TMP/tmp-$PRGNAM/x264-snapshot-$X264 \

  # Without these, we get also rid of "unknown symbols" runtime
  #--with-dv-raw1394=$TMP/tmp-$PRGNAM/libraw1394-${RAW1394} \
  #--with-dv-avc1394=$TMP/tmp-$PRGNAM/libavc1394-${AVC1394} \

  # Deprecated:
  #--enable-ffmpeg \
  #--with-ffmpeg-tree=$TMP/tmp-$PRGNAM/ffmpeg-${FFMPEG} \
  #--enable-daap \
  #--disable-gnomevfs \
  #--disable-musicbrainz \
  #--disable-arts \
  #--enable-esd \
  #--enable-vcdx \
  #--with-speex-tree=$TMP/tmp-$PRGNAM/speex-$SPEEX \
  #--disable-galaktos \
  #--with-twolame-tree=$TMP/tmp-$PRGNAM/twolame-$TWOLAME \
  #--with-dv-raw1394-tree=$TMP/tmp-$PRGNAM/libraw1394-${RAW1394} \
  #--with-dv-avc1394-tree=$TMP/tmp-$PRGNAM/libavc1394-${AVC1394} \
  #--disable-testsuite \
  #--enable-release \
  #--enable-libcdio \
  #--enable-cddax \
  #--disable-snapshot \
  #--with-dvdnav-config-path=$VLCDEPSDIR/usr/bin \
  #--enable-svgalib \
  #--enable-v4l \
  #--enable-id3tag \

  # VLC 2.1 wants OSS4 which we do not have:
  #--enable-oss \

  # Now finds the required libraries without manual tweaking:
  #AVCODEC_LIBS="-lavcodec -lbz2 -lz ${DO_FFMPEG_LIBS_PAT} -ldl -ltheora -lvorbisenc -lswscale -lavutil -lvorbis -lm -logg" \
  #AVCODEC_CFLAGS="" \

# Now, we are ready for the compile:
make ${NUMJOBS} VERBOSE=1 2>&1 | tee $OUTPUT/make-${PRGNAM}.log

cd $OLDDIR
}

# -----------------------------------------------------------------------------
# These routines do all the work of setting up the package contents
# and creating the actual Slackware packages in $OUTPUT
# -----------------------------------------------------------------------------

build_vlcpkg()
{
# I want to be able to override the package version:
PKGVERSION=${PKGVERSION:-$VERSION}

echo -e "**\n**  building the $PRGNAM package (version $PKGVERSION) ...\n**"
#
# Install all the needed stuff to the package dir
#
cd $TMP/tmp-$PRGNAM/${PRGNAM}-${SRCVER}

make DESTDIR=$PKG install 2>&1 |tee $OUTPUT/install-${PRGNAM}.log

# We don't want the mozilla plugin here:
[ -d $PKG/usr/lib${LIBDIRSUFFIX}/mozilla ] && rm -rf $PKG/usr/lib${LIBDIRSUFFIX}/mozilla

# Copy the projectM presets and other requirements into the package if we
# are adding support for it:
if [ -d $VLCDEPSDIR/usr/share/vlc/projectM ]; then
  cp -a $VLCDEPSDIR/usr/share/vlc/projectM $PKG/usr/share/vlc/
  # Add missing directory:
  mkdir $PKG/usr/share/vlc/projectM/textures
  # Replace fonts with symlinks to preserve space:
  rm $PKG/usr/share/vlc/projectM/fonts/*
  ln -sf /usr/share/fonts/TTF/DejaVuSans.ttf $PKG/usr/share/vlc/projectM/fonts/Vera.ttf
  ln -sf /usr/share/fonts/TTF/DejaVuSansMono.ttf $PKG/usr/share/vlc/projectM/fonts/VeraMono.ttf
fi

# Create an empty plugin cache configuration file, so that
# it will be deleted too in the event of a 'removepkg':
touch $PKG/usr/lib${LIBDIRSUFFIX}/vlc/plugins/plugins.dat

# Add this to the doinst.sh:
mkdir -p $PKG/install
cat <<EOINS > $PKG/install/doinst.sh
# Update the desktop database:
if [ -x usr/bin/update-desktop-database ]; then
  chroot . /usr/bin/update-desktop-database usr/share/applications > /dev/null
2>&1
fi

# Update hicolor theme cache:
if [ -d usr/share/icons/hicolor ]; then
  if [ -x /usr/bin/gtk-update-icon-cache ]; then
    chroot . /usr/bin/gtk-update-icon-cache -f -t usr/share/icons/hicolor 1> /dev/null 2> /dev/null
  fi
fi

# Update the mime database:
if [ -x usr/bin/update-mime-database ]; then
  chroot . /usr/bin/update-mime-database usr/share/mime >/dev/null 2>&1
fi

# Remove old cache data and regenerate the file:
chroot . <<EOCR 2>/dev/null
cd /usr/lib${LIBDIRSUFFIX}/vlc
find . -name "plugins*.dat" -exec rm -f {} \;
echo "Generating VLC plugins cache data..."
DISPLAY="" ./vlc-cache-gen /usr/lib${LIBDIRSUFFIX}/vlc/plugins
EOCR

EOINS

## Add the icons to be used in menu entries:
#mkdir -p $PKG/usr/share/pixmaps
#convert share/vlc512x512.png -resize 64x64 $PKG/usr/share/pixmaps/vlc.png
#for res in 16 32 48 64 128; do
#  mkdir -p  $PKG/usr/share/icons/hicolor/${res}x${res}/apps
#  convert share/vlc512x512.png -resize ${res}x${res} \
#    $PKG/usr/share/icons/hicolor/${res}x${res}/apps/vlc.png
#done

# Add the man page:
mkdir -p $PKG/usr/man/man1
gzip -9c doc/vlc.1 > $PKG/usr/man/man1/vlc.1.gz

# Add a vlc log syntax definition file for vim:
mkdir -p $PKG/usr/share/vim/vimfiles/syntax
install -m644 extras/analyser/vlc.vim $PKG/usr/share/vim/vimfiles/syntax/

# Remove traces of our temporary install location from libtool files:
find $PKG/usr/lib${LIBDIRSUFFIX} -name "*.la" -o -name "*.pc" \
  | xargs sed -i -e "s#$VLCDEPSDIR##g"

# Add package documentation:
mkdir -p $PKG/usr/doc/$PRGNAM-$PKGVERSION
mv $PKG/usr/share/doc/vlc/* $PKG/usr/doc/$PRGNAM-$PKGVERSION || true
rm -rf $PKG/usr/share/doc
cp -a $DOCS $PKG/usr/doc/$PRGNAM-$PKGVERSION || true
# Add all the supporting packages' documentation too:
cp -a $VLCDEPSDIR/doc/* $PKG/usr/doc/$PRGNAM-$PKGVERSION || true
# Add the SlackBuild as well as all patches we used to create the package:
cat $SRCDIR/$(basename $0) > $PKG/usr/doc/$PRGNAM-$PKGVERSION/$PRGNAM.SlackBuild
cp -a $SRCDIR/patches $PKG/usr/doc/$PRGNAM-$PKGVERSION/
find $PKG/usr/doc -type f -exec chmod 644 {} \;
chown -R root:root $PKG/usr/doc/$PRGNAM-$PKGVERSION/*

# Compress the man page(s):
if [ -d $PKG/usr/man ]; then
  find $PKG/usr/man -type f -name "*.?" -exec gzip -9f {} \;
  for i in $(find $PKG/usr/man -type l -name "*.?") ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
fi

# Strip binaries:
find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" \
  | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

# Don't ship .la files:
rm -f $PKG/{,usr/}lib${LIBDIRSUFFIX}/*.la || true

# Add a package description:
mkdir -p $PKG/install
cat $SRCDIR/slack-desc > $PKG/install/slack-desc
if [ -f $SRCDIR/doinst.sh ]; then
  cat $SRCDIR/doinst.sh >> $PKG/install/doinst.sh
fi
if [ -f $SRCDIR/slack-required ]; then
  # Slackware added libinput, libwacom and Qt5 in 14.2+ (pre-15.0)
  OSVER=$(cat /etc/slackware-version |cut -d' ' -f2)
  if [ "$OSVER" != "14.2+" ] &&  [ $(echo $OSVER |cut -d. -f1) -lt 15 ] ; then
    cat $SRCDIR/slack-required > $PKG/install/slack-required
  fi
fi

# Build the package:
cd $PKG
makepkg --linkadd y --chown n $OUTPUT/${PRGNAM}-$(echo $PKGVERSION |tr '-' '.')-${ARCH}-${BUILD}${TAG}.${PKGTYPE} 2>&1 | tee $OUTPUT/makepkg-${PRGNAM}.log
cd $OUTPUT
md5sum ${PRGNAM}-$(echo $PKGVERSION |tr '-' '.')-${ARCH}-${BUILD}${TAG}.${PKGTYPE} > ${PRGNAM}-$(echo $PKGVERSION |tr '-' '.')-${ARCH}-${BUILD}${TAG}.${PKGTYPE}.md5
cd -
cat $PKG/install/slack-desc | grep "^${PRGNAM}" > $OUTPUT/${PRGNAM}-$(echo $PKGVERSION |tr '-' '.')-${ARCH}-${BUILD}${TAG}.txt
if [ -f $PKG/install/slack-required ]; then
  cat $PKG/install/slack-required > $OUTPUT/${PRGNAM}-$(echo $PKGVERSION |tr '-' '.')-${ARCH}-${BUILD}${TAG}.dep
fi

}

# -----------------------------------------------------------------------------
# OK - we wrapped the separate components into convenience functions
# - now call them one by one:
# -----------------------------------------------------------------------------

if echo "$*" | grep -qw -- --unwrapvlcdeps ; then
  # We use a tarball with precompiled binaries instead of compiling all
  # dependencies at this moment (saves time when all we change is VLC code):
  if [ "${USE_PATENTS}" == "YES" ]; then
    DEPSFILE="$SRCDIR/$PRGNAM-vlcdeps_restricted-${SLACKVER}-$ARCH.tar.bz2"
  else
    DEPSFILE="$SRCDIR/$PRGNAM-vlcdeps_unrestricted-${SLACKVER}-$ARCH.tar.bz2"
  fi
  [ ! -f $DEPSFILE ] && DEPSFILE="$SRCDIR/$PRGNAM-vlcdeps-${SLACKVER}-$ARCH.tar.bz2"
  cd $TMP/tmp-$PRGNAM
  echo "Extracting tarball '$(basename $DEPSFILE)' with pre-compiled library code..."
  tar -xf $DEPSFILE
  find . -name "*.la" -o -name "*.pc" | xargs sed -i -e "s#/vlcdepsdir#$TMP/tmp-$PRGNAM#g"
  cd -

else
  #if [ "xy" == "x" ]; then

  # Qt5 is used for the vlc gui:
  if [ "$STATIC_QT5" = "YES" ]; then
    #make_pcre2
    make_qt5base
    make_qt5svg
    #make_qt5x11extras
  fi

  # This first, which resolves weird build failures on ARM (assembly fails)
  make_x265
  make_x264
  make_x262

  if [ "${STATIC_LIBVA}" = "YES" ]; then
    # VLC supports VAAPI & VDPAU directly since 2.1.
    # If anyone can fix the 'unresolved symbols' in several vlc plugins when
    # libva is compiled before ffmpeg, let me know!
    make_libva
    make_vdpau
  fi

  # CD image support:
  make_cdio

  # vlc wants this, but cdio chokes with "cannot find -lcddb" so build it after
  # cdio (which only used cddb for the cd-info binary which we don't use):
  make_cddb

  # DVD support:
  # Only use patented code if we are allowing it:
  if [ "${USE_PATENTS}" == "YES" ]; then
    make_dvdcss
  fi
  make_dvdread
  make_dvdnav

  if [ "$STATIC_FFMPEG" == "YES" ]; then
    # Needed before ffmpeg:
    make_vpx
    make_theora
    make_amr
    make_amrwbenc
    make_gsm
    make_lame

    # ffmpeg uses the above static libraries:
    make_ffmpeg
  fi

  # Additional libraries that vlc will use:
  make_fribidi
  make_dav1d
  make_a52
  make_dca
  make_ebml
  make_matroska
  make_libmpeg2
  make_mpcdec
  make_twolame
  make_upnp
  make_srt
  make_dsm
  make_microdns
  make_live555
  make_taglib
  make_asdcplib
  make_ass
  make_fluid
  make_1394
  make_kate
  make_tiger
  make_lua
  make_bluray
  make_opus
  make_ssh2
  make_protobuf
  make_placebo
  make_soxr

  # Visualisations:
  # FIXME: getting symbol errors but we need a static libGLEW:
  #make_glew
  make_goom
  make_projectm

  # Digital video:
  make_dv
  make_dvbpsi

  # Speex before shout and vlc:
  make_speex
  make_speexdsp
  make_shout

  #fi # End  ( "xy" == "x" )
fi

if echo "$*" | grep -qw -- --wrapvlcdeps ; then
  # Wrap the vlcdeps tree with all pre-compiled dependencies into a tarball:
  cd $TMP/tmp-$PRGNAM
  find . -name "*.la" -o -name "*.pc" | xargs sed -i -e "s#$TMP/tmp-$PRGNAM#/vlcdepsdir#g"
  tar -jcf $OUTPUT/$PRGNAM-vlcdeps-${SLACKVER}-$ARCH.tar.bz2 \
    vlcdeps \
    a52dec-$A52 \

  echo "Created vlcdeps binary tarball in '$OUTPUT/$PRGNAM-vlcdeps-${SLACKVER}-$ARCH.tar.bz2'..."
  cd -
else
  # Compile VLC using all the precompiled static libs in $VLCDEPSDIR :
  make_vlc

  # Wrap VLC into a Slackware package:
  build_vlcpkg "$*"
fi