File: Makefile.common

package info (click to toggle)
retroarch 1.22.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 80,716 kB
  • sloc: ansic: 1,275,794; cpp: 115,470; objc: 9,973; asm: 6,624; python: 4,071; makefile: 2,867; sh: 2,828; xml: 1,408; perl: 393; java: 298; javascript: 196
file content (2779 lines) | stat: -rw-r--r-- 83,902 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
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
ROOT_DIR          := .
DEPS_DIR          := $(ROOT_DIR)/deps
LIBRETRO_COMM_DIR := $(ROOT_DIR)/libretro-common
WANT_WGL           = 0

ifeq ($(HAVE_STACK_USAGE), 1)
   DEF_FLAGS += -fstack-usage
endif

ifeq ($(HAVE_NOUNUSED), 1)
   DEF_FLAGS += $(NOUNUSED_CFLAGS)
endif

ifeq ($(HAVE_NOUNUSED_VARIABLE), 1)
   DEF_FLAGS += $(NOUNUSED_VARIABLE_CFLAGS)
endif

ifeq ($(HAVE_QT6), 1)
   CXXFLAGS += $(CXX17_CFLAGS)
else ifeq ($(HAVE_CXX11), 1)
   CXXFLAGS += $(CXX11_CFLAGS)
endif

ifeq ($(HAVE_SAPI), 1)
   LIBS += sapi.dll
endif

ifeq ($(HAVE_GL_CONTEXT),)
   HAVE_GL_CONTEXT = 0
   HAVE_GL_MODERN  = 0

   ifeq ($(HAVE_OPENGL), 1)
      HAVE_GL_CONTEXT = 1
      HAVE_GL_MODERN  = 1
   endif

   ifeq ($(HAVE_OPENGL1), 1)
      HAVE_GL_CONTEXT = 1
   endif

   ifeq ($(HAVE_OPENGLES), 1)
      HAVE_GL_CONTEXT = 1
      HAVE_GL_MODERN  = 1
   endif

   ifeq ($(HAVE_OPENGLES3), 1)
      HAVE_GL_CONTEXT = 1
      HAVE_GL_MODERN  = 1
   endif
endif

ifeq ($(HAVE_LIBRETRODB),)
   HAVE_LIBRETRODB = 1
endif

ifeq ($(HAVE_SOCKET_LEGACY), 1)
   DEFINES += -DHAVE_SOCKET_LEGACY
endif

ifeq ($(HAVE_LIBRETRODB), 1)
   DEFINES += -DHAVE_LIBRETRODB
endif

ifeq ($(HAVE_VITA2D), 1)
   DEFINES += -DHAVE_VITA2D
endif

ifeq ($(HAVE_DYLIB), 1)
   DEFINES += -DHAVE_DYLIB
endif

ifeq ($(SCALER_NO_SIMD), 1)
   DEFINES += -DSCALER_NO_SIMD
endif

ifeq ($(HAVE_PRESERVE_DYLIB),1)
   DEFINES += -DNO_DLCLOSE
endif

ifeq ($(GL_DEBUG), 1)
   DEFINES += -DGL_DEBUG
endif

ifeq ($(VULKAN_DEBUG), 1)
   DEFINES += -DVULKAN_DEBUG
endif

ifeq ($(HAVE_FLOATHARD), 1)
   DEF_FLAGS += $(FLOATHARD_CFLAGS)
   ASFLAGS   += $(FLOATHARD_CFLAGS)
endif

ifeq ($(HAVE_FLOATSOFTFP), 1)
   DEF_FLAGS += $(FLOATSOFTFP_CFLAGS)
   ASFLAGS   += $(FLOATSOFTFP_CFLAGS)
endif

ifeq ($(TDM_GCC),)
   LDCXXFLAGS += -static-libstdc++
endif

ifeq ($(HAVE_FILE_LOGGER), 1)
   DEFINES += -DHAVE_FILE_LOGGER
endif

ifeq ($(HAVE_SHADERPIPELINE), 1)
   DEFINES += -DHAVE_SHADERPIPELINE
endif

INCLUDE_DIRS += -I$(LIBRETRO_COMM_DIR)/include -I$(DEPS_DIR)

# Switches
#
ifeq ($(HAVE_NETPLAYDISCOVERY), 1)
   DEFINES += -DHAVE_NETPLAYDISCOVERY
endif

ifeq ($(HAVE_NETLOGGER), 1)
   DEFINES += -DHAVE_LOGGER
   OBJ += network/net_logger.o
endif

# System

ifneq ($(findstring BSD,$(OS)),)
   BSD_LOCAL_INC += -I/usr/local/include
   HAVE_UNIX = 1
endif

ifneq ($(findstring Darwin,$(OS)),)
   OSX := 1
   LIBS += -framework AppKit
   ARCHFLAGS=
   MINVERFLAGS=
   ifeq ($(shell uname -p),arm)
      MINVERFLAGS = -mmacosx-version-min=10.15 -stdlib=libc++ # macOS  (Metal, ARM 64bit)
   else ifeq ($(HAVE_METAL),1)
      MINVERFLAGS = -mmacosx-version-min=10.13 -stdlib=libc++  # macOS  (Metal, x86 64bit)
   else ifeq ($(shell uname -p),powerpc)
      MINVERFLAGS = -mmacosx-version-min=10.5  # macOSX (PowerPC 32-bit)
   else ifeq ($(shell uname -m),i386)
      MINVERFLAGS = -mmacosx-version-min=10.6  # macOSX (OpenGL, x86 32bit)
   else
      MINVERFLAGS = -mmacosx-version-min=10.7 -stdlib=libc++ # macOSX (OpenGL, x86 64bit)
   endif

	# Build for a specific architecture when ARCH is defined as a switch
   ifeq ($(ARCH),arm64)
      MINVERFLAGS  = -mmacosx-version-min=10.15 -stdlib=libc++ # macOS  (Metal, ARM 64bit)
      ARCHFLAGS    = -arch arm64
   else ifeq ($(ARCH),x86_64)
      ifeq ($(HAVE_METAL),1)
         MINVERFLAGS  = -mmacosx-version-min=10.13 -stdlib=libc++
      else
         MINVERFLAGS  = -mmacosx-version-min=10.7  -stdlib=libc++
      endif
      ARCHFLAGS       = -arch x86_64
   else ifeq ($(ARCH),x86)
      MINVERFLAGS     = -mmacosx-version-min=10.6
      ARCHFLAGS       = -arch x86
   else ifeq ($(ARCH),ppc)
      MINVERFLAGS     = -mmacosx-version-min=10.5
      ARCHFLAGS       = -arch ppc
   endif
   ifeq ($(BUILDBOT),1)
      ARCHFLAGS       = -target $(LIBRETRO_APPLE_PLATFORM) -isysroot $(LIBRETRO_APPLE_ISYSROOT)
   endif
   DEF_FLAGS += $(MINVERFLAGS) $(ARCHFLAGS)
   LDFLAGS   += $(MINVERFLAGS) $(ARCHFLAGS)
else
   OSX := 0
endif

ifneq ($(findstring Haiku,$(OS)),)
   LIBS += -lroot -lnetwork
   HAVE_UNIX = 1
else
   LIBS += -lm
endif

ifneq ($(findstring Linux,$(OS)),)
   LIBS += -lrt
   OBJ += input/drivers/linuxraw_input.o \
          input/common/linux_common.o \
          input/drivers_joypad/linuxraw_joypad.o
   HAVE_UNIX = 1
endif

ifeq ($(HAVE_UNIX), 1)
   OBJ += frontend/drivers/platform_unix.o

	ifeq ($(UNIX_CWD_ENV), 1)
		DEF_FLAGS += -DRARCH_UNIX_CWD_ENV
	endif
endif

ifeq ($(TARGET), retroarch_3ds)
   OBJ += frontend/drivers/platform_ctr.o
endif

ifeq ($(TARGET), retroarch_ps2)
   OBJ += frontend/drivers/platform_ps2.o
endif

# Git Version
GIT_VERSION_CACHEDIR = $(if $(OBJDIR),$(OBJDIR),$(CURDIR))
GIT_VERSION_CACHEFILE = $(GIT_VERSION_CACHEDIR)/git-version.cache

ifneq (,$(wildcard .git/index))  # Building inside a Git repository?
   GIT_VERSION := $(shell git rev-parse --short HEAD 2>/dev/null)
endif

ifneq (,$(wildcard $(GIT_VERSION_CACHEFILE)))  # Cached Git version?
   GIT_VERSION_CACHE = $(shell cat "$(GIT_VERSION_CACHEFILE)" 2>/dev/null)
endif

ifeq ($(GIT_VERSION),)
   ifneq ($(GIT_VERSION_CACHE),)  # If no Git version, use cached if found
      GIT_VERSION = $(GIT_VERSION_CACHE)
   endif
endif

ifneq ($(GIT_VERSION),)  # Enable version_git.o?
   ifneq ($(GIT_VERSION),$(GIT_VERSION_CACHE))  # Update version_git.o?
      $(shell \
         mkdir -p "$(GIT_VERSION_CACHEDIR)" && \
         echo "$(GIT_VERSION)" > "$(GIT_VERSION_CACHEFILE)" && \
         touch version_git.c)
   endif
   DEFINES += -DHAVE_GIT_VERSION -DGIT_VERSION=$(GIT_VERSION)
   OBJ += version_git.o
endif

# General object files
ifeq ($(HAVE_DR_MP3), 1)
   DEFINES += -DHAVE_DR_MP3
endif

OBJ += frontend/frontend_driver.o \
       retroarch.o \
       runloop.o \
       ui/ui_companion_driver.o \
       camera/camera_driver.o \
       record/record_driver.o \
       record/drivers/record_wav.o \
       command.o \
       msg_hash.o \
       intl/msg_hash_us.o \
       $(LIBRETRO_COMM_DIR)/queues/task_queue.o \
       tasks/task_content.o

ifeq ($(HAVE_PATCH), 1)
   DEFINES += -DHAVE_PATCH
   OBJ     += tasks/task_patch.o
   ifeq ($(HAVE_XDELTA), 1)
      DEFINES      += -DHAVE_XDELTA -DSECONDARY_DJW -DSECONDARY_LZMA -DSECONDARY_FGK
      INCLUDE_DIRS += -I$(DEPS_DIR)/xdelta3 -I$(LIBRETRO_COMM_DIR)
      LIBS         += -llzma
      OBJ          += $(DEPS_DIR)/xdelta3/xdelta3.o
      HEADERS      += xdelta3.h \
                      xdelta3-cfgs.h \
                      xdelta3-fgk.h \
                      xdelta3-hash.h \
                      xdelta3-internal.h \
                      xdelta3-list.h \
                      xdelta3-lzma.h \
                      xdelta3-second.h
      # These headers are added to the makefile because xdelta3 does weird things
      # with its #includes, which affects dependency tracking and project analysis
      # (e.g. for IDEs).
   endif
endif

OBJ += \
       save.o \
       tasks/task_save.o \
       tasks/task_movie.o \
       tasks/task_file_transfer.o \
       tasks/task_image.o \
       tasks/task_playlist_manager.o \
       tasks/task_manual_content_scan.o \
       tasks/task_core_backup.o \
       $(LIBRETRO_COMM_DIR)/encodings/encoding_utf.o \
       $(LIBRETRO_COMM_DIR)/encodings/encoding_crc32.o \
       $(LIBRETRO_COMM_DIR)/encodings/encoding_base64.o

ifeq ($(HAVE_TRANSLATE), 1)
   OBJ += tasks/task_translation.o
endif

OBJ += \
       $(LIBRETRO_COMM_DIR)/compat/fopen_utf8.o \
       $(LIBRETRO_COMM_DIR)/compat/compat_strldup.o \
       $(LIBRETRO_COMM_DIR)/lists/file_list.o \
       $(LIBRETRO_COMM_DIR)/lists/dir_list.o \
       $(LIBRETRO_COMM_DIR)/file/retro_dirent.o \
       $(LIBRETRO_COMM_DIR)/streams/stdin_stream.o \
       $(LIBRETRO_COMM_DIR)/streams/file_stream.o \
       $(LIBRETRO_COMM_DIR)/streams/file_stream_transforms.o \
       $(LIBRETRO_COMM_DIR)/streams/interface_stream.o \
       $(LIBRETRO_COMM_DIR)/streams/memory_stream.o \
       $(LIBRETRO_COMM_DIR)/streams/network_stream.o \
       $(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.o

ifeq ($(ANDROID), 1)
   OBJ += $(LIBRETRO_COMM_DIR)/vfs/vfs_implementation_saf.o
endif

OBJ += \
       $(LIBRETRO_COMM_DIR)/lists/string_list.o \
       $(LIBRETRO_COMM_DIR)/string/stdstring.o \
       $(LIBRETRO_COMM_DIR)/memmap/memalign.o \
       $(LIBRETRO_COMM_DIR)/file/nbio/nbio_stdio.o

OBJ += \
       $(LIBRETRO_COMM_DIR)/lists/linked_list.o \
       $(LIBRETRO_COMM_DIR)/lists/nested_list.o \
       $(LIBRETRO_COMM_DIR)/queues/generic_queue.o

ifneq ($(findstring Linux,$(OS)),)
	OBJ += $(LIBRETRO_COMM_DIR)/file/nbio/nbio_linux.o
endif
ifneq ($(findstring Win32,$(OS)),)
   OBJ += $(LIBRETRO_COMM_DIR)/file/nbio/nbio_windowsmmap.o
endif
ifneq ($(findstring BSD,$(OS)),)
	OBJ += $(LIBRETRO_COMM_DIR)/file/nbio/nbio_unixmmap.o
else ifneq ($(findstring Darwin,$(OS)),)
	OBJ += $(LIBRETRO_COMM_DIR)/file/nbio/nbio_unixmmap.o
endif

OBJ += \
       $(LIBRETRO_COMM_DIR)/file/nbio/nbio_intf.o \
       $(LIBRETRO_COMM_DIR)/file/file_path.o \
       $(LIBRETRO_COMM_DIR)/file/file_path_io.o \
       file_path_special.o \
       $(LIBRETRO_COMM_DIR)/hash/lrc_hash.o \
       audio/audio_driver.o \
       input/input_driver.o \
       input/common/input_hid_common.o \
       led/led_driver.o \
       gfx/video_driver.o \
       gfx/gfx_display.o \
       gfx/gfx_animation.o \
       configuration.o \
       $(LIBRETRO_COMM_DIR)/dynamic/dylib.o \
       cores/dynamic_dummy.o \
       $(LIBRETRO_COMM_DIR)/queues/message_queue.o

ifeq ($(HAVE_MENU), 1)
   OBJ += \
       gfx/gfx_thumbnail_path.o \
       gfx/gfx_thumbnail.o
endif

ifeq ($(HAVE_MICROPHONE), 1)
   DEFINES += -DHAVE_MICROPHONE
endif

ifeq ($(HAVE_REWIND), 1)
DEFINES += -DHAVE_REWIND
OBJ     += state_manager.o
endif

OBJ += \
       gfx/drivers_font_renderer/bitmapfont.o \
       gfx/drivers_font_renderer/bitmapfont_10x10.o \
       gfx/drivers_font_renderer/bitmapfont_6x10.o \
       tasks/task_autodetect.o \
       input/input_autodetect_builtin.o \
       input/input_keymaps.o \
       $(LIBRETRO_COMM_DIR)/queues/fifo_queue.o \
       $(LIBRETRO_COMM_DIR)/compat/compat_fnmatch.o \
       $(LIBRETRO_COMM_DIR)/compat/compat_posix_string.o

ifeq ($(HAVE_CHEATS), 1)
   DEFINES += -DHAVE_CHEATS
   OBJ     += cheat_manager.o
endif

ifeq ($(HAVE_CORE_INFO_CACHE), 1)
   DEFINES += -DHAVE_CORE_INFO_CACHE
endif

OBJ += \
       core_info.o \
       core_backup.o \
       core_option_manager.o \
       $(LIBRETRO_COMM_DIR)/file/config_file.o \
       $(LIBRETRO_COMM_DIR)/file/config_file_userdata.o \
       runtime_file.o \
       disk_index_file.o

ifeq ($(HAVE_SCREENSHOTS), 1)
   DEFINES += -DHAVE_SCREENSHOTS
   OBJ     += tasks/task_screenshot.o
endif

OBJ += \
       tasks/task_powerstate.o \
       $(LIBRETRO_COMM_DIR)/gfx/scaler/scaler.o \
       $(LIBRETRO_COMM_DIR)/gfx/scaler/pixconv.o \
       $(LIBRETRO_COMM_DIR)/gfx/scaler/scaler_int.o \
       $(LIBRETRO_COMM_DIR)/gfx/scaler/scaler_filter.o \
       gfx/font_driver.o

ifeq ($(HAVE_VIDEO_FILTER), 1)
DEFINES += -DHAVE_VIDEO_FILTER
OBJ     += gfx/video_filter.o
endif

ifeq ($(HAVE_WINDOW_OFFSET), 1)
DEFINES += -DHAVE_WINDOW_OFFSET
endif

OBJ     += $(LIBRETRO_COMM_DIR)/audio/resampler/audio_resampler.o

ifeq ($(HAVE_DSP_FILTER), 1)
DEFINES += -DHAVE_DSP_FILTER
OBJ     += $(LIBRETRO_COMM_DIR)/audio/dsp_filter.o
endif

OBJ += $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/sinc_resampler.o

ifeq ($(HAVE_NEAREST_RESAMPLER), 1)
   DEFINES += -DHAVE_NEAREST_RESAMPLER
   OBJ     += $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/nearest_resampler.o
endif

OBJ += \
       $(LIBRETRO_COMM_DIR)/utils/md5.o \
       playlist.o \
       $(LIBRETRO_COMM_DIR)/features/features_cpu.o \
       verbosity.o \
       $(LIBRETRO_COMM_DIR)/playlists/label_sanitization.o \
       $(LIBRETRO_COMM_DIR)/time/rtime.o \
       manual_content_scan.o \
       disk_control_interface.o

ifeq ($(HAVE_CONFIGFILE), 1)
   DEFINES += -DHAVE_CONFIGFILE
endif

ifeq ($(HAVE_BLISSBOX), 1)
   DEFINES += -DHAVE_BLISSBOX
	OBJ += tasks/task_autodetect_blissbox.o
endif

ifeq ($(HAVE_AUDIOMIXER), 1)
   DEFINES += -DHAVE_AUDIOMIXER
   OBJ += tasks/task_audio_mixer.o \
          $(LIBRETRO_COMM_DIR)/audio/audio_mix.o \
          $(LIBRETRO_COMM_DIR)/audio/audio_mixer.o
endif

ifeq ($(HAVE_BSV_MOVIE), 1)
   DEFINES += -DHAVE_BSV_MOVIE
   OBJ += input/bsv/bsvmovie.o
endif

ifeq ($(HAVE_STATESTREAM), 1)
   DEFINES += -DHAVE_STATESTREAM
   OBJ += input/bsv/uint32s_index.o
endif

ifeq ($(HAVE_RUNAHEAD), 1)
   DEFINES += -DHAVE_RUNAHEAD
   OBJ     += runahead.o
endif

ifeq ($(HAVE_CC_RESAMPLER), 1)
   DEFINES += -DHAVE_CC_RESAMPLER
   OBJ += audio/drivers_resampler/cc_resampler.o

ifeq ($(HAVE_NEON),1)
   OBJ += audio/drivers_resampler/cc_resampler_neon.o
endif
endif

ifeq ($(HAVE_LANGEXTRA), 1)
   DEFINES += -DHAVE_LANGEXTRA
   DEF_FLAGS += -finput-charset=UTF-8
endif

ifneq ($(HAVE_GETOPT_LONG), 1)
   OBJ += $(LIBRETRO_COMM_DIR)/compat/compat_getopt.o
endif

ifneq ($(HAVE_STRCASESTR), 1)
   OBJ += $(LIBRETRO_COMM_DIR)/compat/compat_strcasestr.o
endif

ifneq ($(HAVE_STRL), 1)
   OBJ += $(LIBRETRO_COMM_DIR)/compat/compat_strl.o
endif

OBJ += $(LIBRETRO_COMM_DIR)/formats/image_texture.o

ifeq ($(HAVE_IMAGEVIEWER), 1)
   DEFINES += -DHAVE_IMAGEVIEWER
   OBJ += cores/libretro-imageviewer/image_core.o
endif

ifeq ($(HAVE_D3D9), 1)
	HAVE_HLSL = 1
endif

ifeq ($(HAVE_CG), 1)
   HAVE_SHADERS_COMMON = 1
endif
ifeq ($(HAVE_GLSL), 1)
   HAVE_SHADERS_COMMON = 1
endif
ifeq ($(HAVE_HLSL), 1)
   HAVE_SHADERS_COMMON = 1
endif
ifeq ($(HAVE_SLANG), 1)
   HAVE_SHADERS_COMMON = 1
endif

# Qt WIMP GUI

ifeq ($(HAVE_OPENSSL), 1)
   DEF_FLAGS += $(OPENSSL_CFLAGS)
   LIBS += $(OPENSSL_LIBS)
endif

ifeq ($(HAVE_QT), 1)
   OBJ += ui/drivers/ui_qt.o \
          ui/drivers/qt/gridview.o \
          ui/drivers/qt/qt_dialogs.o \
          ui/drivers/qt/qt_widgets.o \
          ui/drivers/qt/qt_playlist.o \
          ui/drivers/qt/qt_downloads.o
    ifeq ($(HAVE_MENU), 1)
       OBJ += ui/drivers/qt/qt_options.o
    endif

   MOC_HEADERS += ui/drivers/ui_qt.h \
                  ui/drivers/qt/ui_qt_load_core_window.h \
                  ui/drivers/qt/gridview.h \
                  ui/drivers/qt/qt_dialogs.h \
                  ui/drivers/qt/qt_widgets.h
   ifeq ($(HAVE_MENU), 1)
      MOC_HEADERS += ui/drivers/qt/qt_options.h
   endif

   DEFINES += -DHAVE_MAIN
ifeq ($(HAVE_QT6), 1)
   CXXFLAGS += -DQT_DISABLE_DEPRECATED_BEFORE=0x060000 $(QT6CORE_CFLAGS) $(QT6GUI_CFLAGS) $(QT6WIDGETS_CFLAGS) $(QT6CONCURRENT_CFLAGS) $(QT6NETWORK_CFLAGS)
   #DEF_FLAGS += $(QT6WEBENGINE_CFLAGS)
   LIBS += $(QT6CORE_LIBS) $(QT6GUI_LIBS) $(QT6WIDGETS_LIBS) $(QT6CONCURRENT_LIBS) $(QT6NETWORK_LIBS)
   #LIBS += $(QT6WEBENGINE_LIBS)
else
   DEF_FLAGS += $(QT5CORE_CFLAGS) $(QT5GUI_CFLAGS) $(QT5WIDGETS_CFLAGS) $(QT5CONCURRENT_CFLAGS) $(QT5NETWORK_CFLAGS)
   #DEF_FLAGS += $(QT5WEBENGINE_CFLAGS)
   LIBS += $(QT5CORE_LIBS) $(QT5GUI_LIBS) $(QT5WIDGETS_LIBS) $(QT5CONCURRENT_LIBS) $(QT5NETWORK_LIBS)
   #LIBS += $(QT5WEBENGINE_LIBS)
endif

   NEED_CXX_LINKER = 1

   ifneq ($(findstring Linux,$(OS)),)
      DEF_FLAGS += -fPIC
   else ifneq ($(findstring BSD,$(OS)),)
      DEF_FLAGS += -fPIC
   endif
endif

ifeq ($(HAVE_SSA),1)
   LIBS += $(SSA_LIBS)
endif

ifeq ($(HAVE_SSE),1)
   DEF_FLAGS += $(SSE_LIBS)
endif

# LibretroDB

ifeq ($(HAVE_LIBRETRODB), 1)
   OBJ += libretro-db/bintree.o \
          libretro-db/libretrodb.o \
          libretro-db/query.o \
          libretro-db/rmsgpack.o \
          libretro-db/rmsgpack_dom.o \
          database_info.o \
          tasks/task_database.o \
          tasks/task_database_cue.o

   ifeq ($(HAVE_MENU), 1)
      OBJ += menu/menu_explore.o \
             tasks/task_menu_explore.o
   endif
endif

ifeq ($(HAVE_BUILTINBEARSSL), 1)
   HAVE_SSL = 1
   DEFINES += -DHAVE_SSL -DHAVE_BEARSSL

   # these -Is are only needed for BearSSL itself
   INCLUDE_DIRS += -Ideps/bearssl-0.6/src -Ideps/bearssl-0.6/inc
   OBJS_BEAR = deps/bearssl-0.6/src/aead/ccm.o \
               deps/bearssl-0.6/src/codec/ccopy.o \
               deps/bearssl-0.6/src/codec/dec32be.o \
               deps/bearssl-0.6/src/codec/dec32le.o \
               deps/bearssl-0.6/src/codec/dec64be.o \
               deps/bearssl-0.6/src/codec/enc32be.o \
               deps/bearssl-0.6/src/codec/enc32le.o \
               deps/bearssl-0.6/src/codec/enc64be.o \
               deps/bearssl-0.6/src/ec/ec_all_m31.o \
               deps/bearssl-0.6/src/ec/ec_c25519_m31.o \
               deps/bearssl-0.6/src/ec/ecdsa_atr.o \
               deps/bearssl-0.6/src/ec/ecdsa_i31_bits.o \
               deps/bearssl-0.6/src/ec/ecdsa_i31_vrfy_asn1.o \
               deps/bearssl-0.6/src/ec/ecdsa_i31_vrfy_raw.o \
               deps/bearssl-0.6/src/ec/ec_p256_m31.o \
               deps/bearssl-0.6/src/ec/ec_prime_i31.o \
               deps/bearssl-0.6/src/ec/ec_secp256r1.o \
               deps/bearssl-0.6/src/ec/ec_secp384r1.o \
               deps/bearssl-0.6/src/ec/ec_secp521r1.o \
               deps/bearssl-0.6/src/hash/ghash_ctmul64.o \
               deps/bearssl-0.6/src/hash/ghash_pclmul.o \
               deps/bearssl-0.6/src/hash/md5.o \
               deps/bearssl-0.6/src/hash/multihash.o \
               deps/bearssl-0.6/src/hash/sha1.o \
               deps/bearssl-0.6/src/hash/sha2big.o \
               deps/bearssl-0.6/src/hash/sha2small.o \
               deps/bearssl-0.6/src/int/i31_add.o \
               deps/bearssl-0.6/src/int/i31_bitlen.o \
               deps/bearssl-0.6/src/int/i31_decmod.o \
               deps/bearssl-0.6/src/int/i31_decode.o \
               deps/bearssl-0.6/src/int/i31_decred.o \
               deps/bearssl-0.6/src/int/i31_encode.o \
               deps/bearssl-0.6/src/int/i31_fmont.o \
               deps/bearssl-0.6/src/int/i31_iszero.o \
               deps/bearssl-0.6/src/int/i31_modpow2.o \
               deps/bearssl-0.6/src/int/i31_modpow.o \
               deps/bearssl-0.6/src/int/i31_montmul.o \
               deps/bearssl-0.6/src/int/i31_muladd.o \
               deps/bearssl-0.6/src/int/i31_ninv31.o \
               deps/bearssl-0.6/src/int/i31_rshift.o \
               deps/bearssl-0.6/src/int/i31_sub.o \
               deps/bearssl-0.6/src/int/i31_tmont.o \
               deps/bearssl-0.6/src/int/i32_div32.o \
               deps/bearssl-0.6/src/int/i62_modpow2.o \
               deps/bearssl-0.6/src/mac/hmac_ct.o \
               deps/bearssl-0.6/src/mac/hmac.o \
               deps/bearssl-0.6/src/rand/hmac_drbg.o \
               deps/bearssl-0.6/src/rand/sysrng.o \
               deps/bearssl-0.6/src/rsa/rsa_default_pkcs1_vrfy.o \
               deps/bearssl-0.6/src/rsa/rsa_default_pub.o \
               deps/bearssl-0.6/src/rsa/rsa_i31_pkcs1_vrfy.o \
               deps/bearssl-0.6/src/rsa/rsa_i31_pub.o \
               deps/bearssl-0.6/src/rsa/rsa_i62_pkcs1_vrfy.o \
               deps/bearssl-0.6/src/rsa/rsa_i62_pub.o \
               deps/bearssl-0.6/src/rsa/rsa_pkcs1_sig_unpad.o \
               deps/bearssl-0.6/src/ssl/prf_md5sha1.o \
               deps/bearssl-0.6/src/ssl/prf.o \
               deps/bearssl-0.6/src/ssl/prf_sha256.o \
               deps/bearssl-0.6/src/ssl/prf_sha384.o \
               deps/bearssl-0.6/src/ssl/ssl_client_default_rsapub.o \
               deps/bearssl-0.6/src/ssl/ssl_client_full.o \
               deps/bearssl-0.6/src/ssl/ssl_client.o \
               deps/bearssl-0.6/src/ssl/ssl_engine_default_aescbc.o \
               deps/bearssl-0.6/src/ssl/ssl_engine_default_aesccm.o \
               deps/bearssl-0.6/src/ssl/ssl_engine_default_aesgcm.o \
               deps/bearssl-0.6/src/ssl/ssl_engine_default_chapol.o \
               deps/bearssl-0.6/src/ssl/ssl_engine_default_descbc.o \
               deps/bearssl-0.6/src/ssl/ssl_engine_default_ecdsa.o \
               deps/bearssl-0.6/src/ssl/ssl_engine_default_rsavrfy.o \
               deps/bearssl-0.6/src/ssl/ssl_engine.o \
               deps/bearssl-0.6/src/ssl/ssl_hs_client.o \
               deps/bearssl-0.6/src/ssl/ssl_rec_cbc.o \
               deps/bearssl-0.6/src/ssl/ssl_rec_ccm.o \
               deps/bearssl-0.6/src/ssl/ssl_rec_chapol.o \
               deps/bearssl-0.6/src/ssl/ssl_rec_gcm.o \
               deps/bearssl-0.6/src/symcipher/aes_ct64_cbcdec.o \
               deps/bearssl-0.6/src/symcipher/aes_ct64_cbcenc.o \
               deps/bearssl-0.6/src/symcipher/aes_ct64_ctrcbc.o \
               deps/bearssl-0.6/src/symcipher/aes_ct64_ctr.o \
               deps/bearssl-0.6/src/symcipher/aes_ct64_dec.o \
               deps/bearssl-0.6/src/symcipher/aes_ct64_enc.o \
               deps/bearssl-0.6/src/symcipher/aes_ct64.o \
               deps/bearssl-0.6/src/symcipher/aes_x86ni_cbcdec.o \
               deps/bearssl-0.6/src/symcipher/aes_x86ni_cbcenc.o \
               deps/bearssl-0.6/src/symcipher/aes_x86ni_ctrcbc.o \
               deps/bearssl-0.6/src/symcipher/aes_x86ni_ctr.o \
               deps/bearssl-0.6/src/symcipher/aes_x86ni.o \
               deps/bearssl-0.6/src/symcipher/chacha20_ct.o \
               deps/bearssl-0.6/src/symcipher/chacha20_sse2.o \
               deps/bearssl-0.6/src/symcipher/des_ct_cbcdec.o \
               deps/bearssl-0.6/src/symcipher/des_ct_cbcenc.o \
               deps/bearssl-0.6/src/symcipher/des_ct.o \
               deps/bearssl-0.6/src/symcipher/des_support.o \
               deps/bearssl-0.6/src/symcipher/poly1305_ctmul.o \
               deps/bearssl-0.6/src/symcipher/poly1305_ctmulq.o \
               deps/bearssl-0.6/src/x509/x509_decoder.o \
               deps/bearssl-0.6/src/x509/x509_minimal_full.o \
               deps/bearssl-0.6/src/x509/x509_minimal.o \

   OBJ += $(OBJS_BEAR)
else ifeq ($(HAVE_BUILTINMBEDTLS), 1)
   HAVE_SSL = 1
   DEFINES += -DHAVE_SSL

   ifeq ($(DEBUG), 1)
      DEFINES += -DMBEDTLS_SSL_DEBUG_ALL
   endif

   # MinGW requires this for some reason,
	# even though the include paths are relative to the source
   INCLUDE_DIRS += -Ideps/mbedtls

   OBJS_TLS_CRYPTO = deps/mbedtls/aes.o \
                     deps/mbedtls/aesni.o \
                     deps/mbedtls/arc4.o \
                     deps/mbedtls/asn1parse.o \
                     deps/mbedtls/asn1write.o \
                     deps/mbedtls/base64.o \
                     deps/mbedtls/bignum.o \
                     deps/mbedtls/blowfish.o \
                     deps/mbedtls/camellia.o \
                     deps/mbedtls/ccm.o \
                     deps/mbedtls/cipher.o \
                     deps/mbedtls/cipher_wrap.o \
                     deps/mbedtls/ctr_drbg.o \
                     deps/mbedtls/des.o \
                     deps/mbedtls/dhm.o \
                     deps/mbedtls/ecdh.o \
                     deps/mbedtls/ecdsa.o \
                     deps/mbedtls/ecp.o \
                     deps/mbedtls/ecp_curves.o \
                     deps/mbedtls/entropy.o \
                     deps/mbedtls/entropy_poll.o \
                     deps/mbedtls/gcm.o \
                     deps/mbedtls/hmac_drbg.o \
                     deps/mbedtls/md.o \
                     deps/mbedtls/md5.o \
                     deps/mbedtls/md_wrap.o \
                     deps/mbedtls/oid.o \
                     deps/mbedtls/padlock.o \
                     deps/mbedtls/pem.o \
                     deps/mbedtls/pk.o \
                     deps/mbedtls/pk_wrap.o \
                     deps/mbedtls/pkcs12.o \
                     deps/mbedtls/pkcs5.o \
                     deps/mbedtls/pkparse.o \
                     deps/mbedtls/pkwrite.o \
                     deps/mbedtls/ripemd160.o \
                     deps/mbedtls/rsa.o \
                     deps/mbedtls/sha1.o \
                     deps/mbedtls/sha256.o \
                     deps/mbedtls/sha512.o \
                     deps/mbedtls/threading.o \
                     deps/mbedtls/timing.o \
                     deps/mbedtls/xtea.o

   OBJS_TLS_X509 = deps/mbedtls/certs.o \
                   deps/mbedtls/x509.o \
                   deps/mbedtls/x509_create.o \
                   deps/mbedtls/x509_crl.o \
                   deps/mbedtls/x509_crt.o \
                   deps/mbedtls/x509_csr.o \
                   deps/mbedtls/x509write_crt.o \
                   deps/mbedtls/x509write_csr.o

   OBJS_TLS = deps/mbedtls/debug.o \
              deps/mbedtls/net_sockets.o \
              deps/mbedtls/ssl_cache.o \
              deps/mbedtls/ssl_ciphersuites.o \
              deps/mbedtls/ssl_cli.o \
              deps/mbedtls/ssl_cookie.o \
              deps/mbedtls/ssl_srv.o \
              deps/mbedtls/ssl_ticket.o \
              deps/mbedtls/ssl_tls.o

   OBJ += $(OBJS_TLS_CRYPTO) $(OBJS_TLS_X509) $(OBJS_TLS)
else ifeq ($(HAVE_SSL), 1)
   DEFINES += -DHAVE_SSL
   LIBS += $(SYSTEMMBEDTLS_LIBS) $(SYSTEMMBEDX509_LIBS) $(SYSTEMMBEDCRYPTO_LIBS)
   DEF_FLAGS += $(SYSTEMMBEDTLS_CFLAGS) $(SYSTEMMBEDX509_CFLAGS) $(SYSTEMMBEDCRYPTO_CFLAGS)
endif

# Miscellaneous

ifeq ($(HAVE_COMMAND), 1)
   DEFINES += -DHAVE_COMMAND
endif

ifeq ($(HAVE_STDIN_CMD), 1)
   DEFINES += -DHAVE_STDIN_CMD
endif

ifeq ($(HAVE_EMSCRIPTEN), 1)
   OBJ += frontend/drivers/platform_emscripten.o \
          input/drivers/rwebinput_input.o \
          input/drivers_joypad/rwebpad_joypad.o \
          camera/drivers/rwebcam.o
   ifeq ($(HAVE_RWEBAUDIO), 1)
      OBJ += audio/drivers/rwebaudio.o
   endif
   ifeq ($(HAVE_AUDIOWORKLET), 1)
      OBJ += audio/drivers/audioworklet.o
   endif
endif

ifeq ($(HAVE_BLUETOOTH), 1)
   OBJ += bluetooth/bluetooth_driver.o
   OBJ += bluetooth/drivers/bluetoothctl.o
   OBJ += tasks/task_bluetooth.o
   ifeq ($(HAVE_DBUS), 1)
      OBJ += bluetooth/drivers/bluez.o
   endif
endif

ifeq ($(HAVE_LAKKA), 1)
   OBJ += network/drivers_wifi/connmanctl.o
   OBJ += misc/cpufreq/cpufreq.o
endif

ifeq ($(HAVE_WIFI), 1)
   OBJ += network/wifi_driver.o
   OBJ += tasks/task_wifi.o
   OBJ += network/drivers_wifi/nmcli.o
   DEFINES += -DHAVE_WIFI
endif

# Audio

ifeq ($(HAVE_COREAUDIO), 1)
   DEFINES += -DHAVE_COREAUDIO
   OBJ += audio/drivers/coreaudio.o
   HAVE_COREAUDIO_LIBS = 1
endif

ifeq ($(HAVE_COREAUDIO3), 1)
   DEFINES += -DHAVE_COREAUDIO3
   OBJ += audio/drivers/coreaudio3.o
   HAVE_COREAUDIO_LIBS = 1
   LIBS += -framework AudioToolBox -framework AVFoundation
endif

ifeq ($(HAVE_COREAUDIO_LIBS), 1)
   LIBS += -framework CoreServices -framework CoreAudio -framework AudioUnit
endif

ifeq ($(HAVE_CORETEXT), 1)
   OBJ += gfx/drivers_font_renderer/coretext.o
endif

ifeq ($(HAVE_AUDIOIO), 1)
   OBJ += audio/drivers/audioio.o
endif

ifeq ($(HAVE_OSS), 1)
   OBJ += audio/drivers/oss.o
else ifeq ($(HAVE_OSS_BSD), 1)
   OBJ += audio/drivers/oss.o
endif

ifeq ($(TARGET), retroarch_3ds)
   OBJ += audio/drivers/ctr_csnd_audio.o \
          audio/drivers/ctr_dsp_audio.o
ifeq ($(HAVE_THREADS), 1)
   OBJ += audio/drivers/ctr_dsp_thread_audio.o
endif
endif

ifeq ($(HAVE_ALSA), 1)
   OBJ += audio/drivers/alsa.o \
          audio/common/alsa.o

   ifneq ($(HAVE_HAKCHI), 1)
      ifneq ($(HAVE_SEGAM), 1)
         ifneq ($(DINGUX), 1)
            OBJ += midi/drivers/alsa_midi.o
         endif
      endif
   endif

   ifneq ($(MIYOO), 1)
      ifeq ($(HAVE_THREADS), 1)
         OBJ += audio/drivers/alsathread.o
      endif
   endif

   LIBS += $(ALSA_LIBS)
   DEF_FLAGS += $(ALSA_CFLAGS)
endif

ifeq ($(HAVE_TINYALSA), 1)
   OBJ += audio/drivers/tinyalsa.o
   DEFINES += -DHAVE_TINYALSA
endif

ifeq ($(HAVE_ROAR), 1)
   OBJ += audio/drivers/roar.o
   LIBS += $(ROAR_LIBS)
   DEF_FLAGS += $(ROAR_CFLAGS)
endif

ifeq ($(HAVE_AL), 1)
   OBJ += audio/drivers/openal.o
   ifeq ($(OSX),1)
      LIBS += -framework OpenAL
   else
      LIBS += $(AL_LIBS)
   endif
endif

ifneq ($(findstring Darwin,$(OS)),)
   OBJ += frontend/drivers/platform_darwin.o
endif

ifeq ($(HAVE_JACK),1)
   OBJ += audio/drivers/jack.o
   LIBS += $(JACK_LIBS)
   DEF_FLAGS += $(JACK_CFLAGS)
endif

ifeq ($(HAVE_PULSE), 1)
   OBJ += audio/drivers/pulse.o
   LIBS += $(PULSE_LIBS)
   DEF_FLAGS += $(PULSE_CFLAGS)
endif

ifeq ($(HAVE_PIPEWIRE), 1)
   OBJ += audio/drivers/pipewire.o \
          audio/common/pipewire.o

   ifeq ($(HAVE_PIPEWIRE_STABLE), 1)
      OBJ += camera/drivers/pipewire.o
   endif

   LIBS += $(PIPEWIRE_LIBS)
   DEF_FLAGS += $(PIPEWIRE_CFLAGS)
endif

ifeq ($(HAVE_OSS_LIB), 1)
   LIBS += -lossaudio
endif

ifeq ($(HAVE_RSOUND), 1)
   OBJ += audio/drivers/rsound.o
   DEF_FLAGS += $(RSOUND_CFLAGS)
   LIBS += $(RSOUND_LIBS)
endif

ifeq ($(HAVE_DSOUND), 1)
   OBJ += audio/drivers/dsound.o
   DEFINES += -DHAVE_DSOUND
   HAVE_DX_COMMON  = 1
   LIBS += -ldsound
endif

ifeq ($(HAVE_WASAPI), 1)
	HAVE_MMDEVAPI = 1
   OBJ += audio/drivers/wasapi.o
   DEFINES += -DHAVE_WASAPI
   LIBS += -lole32 -lksuser
endif

ifeq ($(HAVE_XAUDIO), 1)
   OBJ += audio/drivers/xaudio.o
   DEFINES += -DHAVE_XAUDIO
   LIBS += -lole32
endif

ifeq ($(HAVE_MMDEVAPI), 1)
	OBJ += audio/common/mmdevice_common.o
endif

ifeq ($(HAVE_WINMM), 1)
   OBJ += midi/drivers/winmm_midi.o
   DEFINES += -DHAVE_WINMM
   LIBS += -lwinmm
endif

ifeq ($(HAVE_COREMIDI), 1)
   OBJ += midi/drivers/coremidi.o
   DEFINES += -DHAVE_COREMIDI
   LIBS += -framework CoreMIDI
endif

# Audio Resamplers

ifeq ($(HAVE_NEON),1)
   OBJ += $(LIBRETRO_COMM_DIR)/audio/resampler/drivers/sinc_resampler_neon.o \
          memory/neon/memcpy-neon.o

   DEFINES   += -DHAVE_NEON
   ASFLAGS   += $(NEON_ASFLAGS)
   DEF_FLAGS += $(NEON_CFLAGS)
endif

OBJ += $(LIBRETRO_COMM_DIR)/audio/conversion/s16_to_float.o \
       $(LIBRETRO_COMM_DIR)/audio/conversion/float_to_s16.o \
       $(LIBRETRO_COMM_DIR)/audio/conversion/mono_to_stereo_float.o \
       $(LIBRETRO_COMM_DIR)/audio/conversion/stereo_to_mono_float.o \

ifeq ($(HAVE_RWAV), 1)
DEFINES += -DHAVE_RWAV
OBJ += $(LIBRETRO_COMM_DIR)/formats/wav/rwav.o
endif

ifeq ($(HAVE_NEON),1)
   OBJ += $(LIBRETRO_COMM_DIR)/audio/conversion/s16_to_float_neon.o \
          $(LIBRETRO_COMM_DIR)/audio/conversion/float_to_s16_neon.o
endif

HW_CONTEXT_MENU_DRIVERS=$(HAVE_MENU)

ifeq ($(HW_CONTEXT_MENU_DRIVERS),0)
   ifeq ($(HAVE_GL_CONTEXT),1)
      HW_CONTEXT_MENU_DRIVERS=1
   endif
   ifeq ($(HAVE_VULKAN),1)
      HW_CONTEXT_MENU_DRIVERS=1
   endif
endif

# XMB and MaterialUI are always enabled if supported and not explicitly disabled
ifeq ($(HW_CONTEXT_MENU_DRIVERS), 1)
   ifeq ($(HAVE_RGUI),)
      HAVE_RGUI = 1
   endif

   ifeq ($(HAVE_MATERIALUI),)
      HAVE_MATERIALUI = 1
   endif

   ifeq ($(HAVE_XMB),)
      HAVE_XMB = 1
   endif

   ifeq ($(HAVE_OZONE),)
      HAVE_OZONE = 1
   endif
else
   HAVE_RGUI        ?= 0
   HAVE_MATERIALUI  ?= 0
   HAVE_XMB         ?= 0
   HAVE_OZONE       ?= 0
endif

ifeq ($(HAVE_MENU), 1)
   DEFINES += -DHAVE_MENU
   HAVE_MENU_COMMON = 1

   ifeq ($(HAVE_GFX_WIDGETS), 1)
      DEFINES += -DHAVE_GFX_WIDGETS
   endif

   ifeq ($(HAVE_RGUI), 1)
      OBJ += menu/drivers/rgui.o
      DEFINES += -DHAVE_RGUI
   endif

   ifeq ($(HAVE_MATERIALUI), 1)
      OBJ += menu/drivers/materialui.o
      DEFINES += -DHAVE_MATERIALUI
      HAVE_ASSETS = 1
      HAVE_MENU_SCREENSAVER = 1
   endif

   ifeq ($(HAVE_XMB), 1)
      OBJ += menu/drivers/xmb.o
      DEFINES += -DHAVE_XMB
      HAVE_ASSETS = 1
      HAVE_MENU_SCREENSAVER = 1
   endif

   ifeq ($(HAVE_OZONE), 1)
      OBJ += menu/drivers/ozone.o
      DEFINES += -DHAVE_OZONE
      HAVE_ASSETS = 1
      HAVE_MENU_SCREENSAVER = 1
   endif

   ifeq ($(HAVE_MENU_SCREENSAVER), 1)
      OBJ += menu/menu_screensaver.o
   endif
endif

ifeq ($(HAVE_BLUETOOTH), 1)
   DEFINES += -DHAVE_BLUETOOTH
endif

ifeq ($(HAVE_LAKKA), 1)
   DEFINES += -DHAVE_LAKKA
   ifneq ($(HAVE_LAKKA_PROJECT),)
      DEFINES += -DHAVE_LAKKA_PROJECT=\"${HAVE_LAKKA_PROJECT}\"
   else
      $(error You asked for Lakka, but you did not specify a target device name in HAVE_LAKKA_PROJECT)
   endif
   ifneq ($(HAVE_LAKKA_SERVER),)
      DEFINES += -DHAVE_LAKKA_SERVER=\"${HAVE_LAKKA_SERVER}\"
   else
      $(error You asked for Lakka, but you did not specify update server in HAVE_LAKKA_SERVER)
   endif
endif

ifeq ($(HAVE_LAKKA_SWITCH), 1)
   DEFINES += -DHAVE_LAKKA_SWITCH
endif

ifeq ($(HAVE_MENU_COMMON), 1)
   OBJ += menu/menu_setting.o \
          menu/menu_driver.o \
          menu/cbs/menu_cbs_ok.o \
          menu/cbs/menu_cbs_cancel.o \
          menu/cbs/menu_cbs_select.o \
          menu/cbs/menu_cbs_start.o \
          menu/cbs/menu_cbs_info.o \
          menu/cbs/menu_cbs_left.o \
          menu/cbs/menu_cbs_right.o \
          menu/cbs/menu_cbs_deferred_push.o \
          menu/cbs/menu_cbs_scan.o \
          menu/cbs/menu_cbs_get_value.o \
          menu/cbs/menu_cbs_label.o \
          menu/cbs/menu_cbs_sublabel.o \
          menu/cbs/menu_cbs_title.o \
          menu/menu_displaylist.o \
          menu/menu_contentless_cores.o
endif

ifeq ($(HAVE_GFX_WIDGETS), 1)
   OBJ += gfx/gfx_widgets.o

   ifeq ($(HAVE_SCREENSHOTS), 1)
       OBJ += gfx/widgets/gfx_widget_screenshot.o
   endif

   OBJ += \
          gfx/widgets/gfx_widget_volume.o \
          gfx/widgets/gfx_widget_generic_message.o \
          gfx/widgets/gfx_widget_libretro_message.o \
          gfx/widgets/gfx_widget_progress_message.o \
          gfx/widgets/gfx_widget_load_content_animation.o
   ifeq ($(HAVE_CHEEVOS), 1)
       OBJ += gfx/widgets/gfx_widget_achievement_popup.o \
              gfx/widgets/gfx_widget_leaderboard_display.o
   endif
endif

ifeq ($(HAVE_OVERLAY), 1)
   DEFINES += -DHAVE_OVERLAY
   OBJ += tasks/task_overlay.o \
          led/drivers/led_overlay.o
endif

ifeq ($(HAVE_STB_FONT), 1)
   OBJ += gfx/drivers_font_renderer/stb.o
   OBJ += gfx/drivers_font_renderer/stb_unicode.o
   DEFINES += -DHAVE_STB_FONT
endif

ifeq ($(HAVE_FREETYPE), 1)
   OBJ += gfx/drivers_font_renderer/freetype.o
   LIBS += $(FREETYPE_LIBS)
   DEF_FLAGS += $(FREETYPE_CFLAGS)
   ifeq ($(HAVE_FREETYPE), 1)
      LIBS += $(FONTCONFIG_LIBS)
      DEF_FLAGS += $(FONTCONFIG_CFLAGS)
   endif
endif

ifeq ($(HAVE_THREADS), 1)
   OBJ += $(LIBRETRO_COMM_DIR)/rthreads/rthreads.o \
          gfx/video_thread_wrapper.o \
          audio/audio_thread_wrapper.o
   DEFINES += -DHAVE_THREADS
   ifeq ($(findstring Haiku,$(OS)),)
      LIBS += $(THREADS_LIBS)
   endif
endif

ifeq ($(HAVE_THREAD_STORAGE), 1)
   DEFINES += -DHAVE_THREAD_STORAGE
endif

ifeq ($(HAVE_VITA2D), 1)
   OBJ += $(DEPS_DIR)/libvita2d/source/vita2d.o \
          $(DEPS_DIR)/libvita2d/source/vita2d_texture.o \
          $(DEPS_DIR)/libvita2d/source/vita2d_draw.o \
          $(DEPS_DIR)/libvita2d/source/utils.o

   OBJ += $(DEPS_DIR)/libvita2d/shader/clear_v_gxp.o \
          $(DEPS_DIR)/libvita2d/shader/clear_f_gxp.o \
          $(DEPS_DIR)/libvita2d/shader/color_v_gxp.o \
          $(DEPS_DIR)/libvita2d/shader/color_f_gxp.o \
          $(DEPS_DIR)/libvita2d/shader/texture_v_gxp.o \
          $(DEPS_DIR)/libvita2d/shader/texture_f_gxp.o \
          $(DEPS_DIR)/libvita2d/shader/texture_tint_v_gxp.o \
          $(DEPS_DIR)/libvita2d/shader/texture_tint_f_gxp.o

   OBJ += gfx/drivers/vita2d_gfx.o

   INCLUDE_DIRS += -I$(DEPS_DIR)/libvita2d/include
endif

ifeq ($(TARGET), retroarch_3ds)
   OBJ += gfx/drivers/ctr_gfx.o \
          input/drivers/ctr_input.o \
          input/drivers_joypad/ctr_joypad.o
endif

ifeq ($(TARGET), retroarch_ps2)
   OBJ += gfx/drivers/ps2_gfx.o \
          input/drivers/ps2_input.o \
          input/drivers_joypad/ps2_joypad.o \
          audio/drivers/ps2_audio.o
endif

ifeq ($(TARGET), retroarch_orbis)
   OBJ +=  input/drivers/ps4_input.o \
			  input/drivers_joypad/ps4_joypad.o \
			  audio/drivers/psp_audio.o
endif

ifeq ($(TARGET), retroarch_vita)
   OBJ +=  input/drivers/psp_input.o \
			  input/drivers_joypad/psp_joypad.o \
			  audio/drivers/psp_audio.o \
			  frontend/drivers/platform_psp.o
endif

ifeq ($(TARGET), retroarch_wiiu)
   OBJ +=  gfx/drivers/gx2_gfx.o \
	   input/drivers/wiiu_input.o \
	   input/drivers_joypad/wiiu_joypad.o \
	   input/drivers_joypad/wiiu/wpad_driver.o \
	   input/drivers_joypad/wiiu/kpad_driver.o \
	   input/drivers_joypad/wiiu/pad_functions.o \
	   audio/drivers/wiiu_audio.o \
	   frontend/drivers/platform_wiiu.o

      ifeq ($(WIIU_HID),1)
         DEFINES += -DWIIU_HID
			INCLUDE_DIRS += -Iinput/include
         OBJ += input/drivers_joypad/wiiu/hidpad_driver.o
         OBJ += input/drivers_hid/wiiu_hid.o
      endif
endif

ifeq ($(TARGET), retroarch_switch)
   ifeq ($(HAVE_LIBNX), 1)
      OBJ += gfx/drivers/switch_nx_gfx.o \
             audio/drivers/switch_libnx_audren_audio.o \
             audio/drivers/switch_libnx_audren_thread_audio.o
      ifeq ($(HAVE_OPENGL), 1)
         OBJ += gfx/drivers_context/switch_ctx.o
      endif
   endif
   OBJ += audio/drivers/switch_audio.o \
          audio/drivers/switch_thread_audio.o \
          input/drivers/switch_input.o \
          input/drivers_joypad/switch_joypad.o \
          frontend/drivers/platform_switch.o
endif

ifeq ($(TARGET), retroarch_orbis)
   OBJ += gfx/drivers_context/orbis_ctx.o \
          frontend/drivers/platform_orbis.o
endif

ifeq ($(DINGUX), 1)
   OBJ += dingux/dingux_utils.o
endif

ifeq ($(HAVE_WAYLAND), 1)
 OBJ += gfx/drivers_context/wayland_ctx.o \
        input/common/wayland_common.o \
        input/drivers/wayland_input.o \
        gfx/common/wayland_common.o \
        gfx/common/wayland/fractional-scale-v1.o \
        gfx/common/wayland/viewporter.o \
        gfx/common/wayland/xdg-toplevel-icon-v1.o \
        gfx/common/wayland/xdg-shell.o \
        gfx/common/wayland/idle-inhibit-unstable-v1.o \
        gfx/common/wayland/xdg-decoration-unstable-v1.o \
        gfx/common/wayland/pointer-constraints-unstable-v1.o \
        gfx/common/wayland/relative-pointer-unstable-v1.o \
        gfx/common/wayland/cursor-shape-v1.o \
        gfx/common/wayland/tablet-unstable-v2.o \
        gfx/common/wayland/content-type-v1.o \
        gfx/common/wayland/single-pixel-buffer-v1.o

   ifeq ($(HAVE_VULKAN), 1)
      OBJ += gfx/drivers_context/wayland_vk_ctx.o
   endif

 DEF_FLAGS += $(WAYLAND_CFLAGS) $(WAYLAND_CURSOR_CFLAGS)
 LIBS += $(WAYLAND_LIBS) $(WAYLAND_CURSOR_LIBS)

 ifeq ($(HAVE_LIBDECOR), 1)
    DEFINES += -DHAVE_LIBDECOR_H
    DEF_FLAGS += $(LIBDECOR_CFLAGS)
 endif

endif

# XML
OBJ += \
       $(LIBRETRO_COMM_DIR)/formats/xml/rxml.o \
       $(LIBRETRO_COMM_DIR)/formats/logiqx_dat/logiqx_dat.o \
       deps/yxml/yxml.o

#Input

ifeq ($(HAVE_DINPUT), 1)
   HAVE_DX_COMMON  = 1
   LIBS += -ldinput8 -lole32
   DEFINES += -DHAVE_DINPUT
   OBJ += input/drivers/dinput.o
   OBJ += input/drivers_joypad/dinput_joypad.o
endif

ifeq ($(HAVE_XINPUT), 1)
   DEFINES += -DHAVE_XINPUT
   ifeq ($(HAVE_DINPUT), 1)
      OBJ += input/drivers_joypad/xinput_hybrid_joypad.o
   else
      OBJ += input/drivers_joypad/xinput_joypad.o
   endif
endif

ifeq ($(HAVE_OPENDINGUX_FBDEV), 1)
   OBJ += gfx/drivers_context/opendingux_fbdev_ctx.o
endif

ifeq ($(HAVE_X11), 1)
   OBJ += input/common/input_x11_common.o \
          input/drivers/x11_input.o \
          gfx/common/x11_common.o \
          gfx/common/xinerama_common.o \
          gfx/display_servers/dispserv_x11.o

   LIBS += $(X11_LIBS) $(XEXT_LIBS) $(XF86VM_LIBS) $(XINERAMA_LIBS) $(XRANDR_LIBS)
   DEFINES += -DHAVE_X11
   DEF_FLAGS += $(X11_CFLAGS) $(XEXT_CFLAGS) $(XF86VM_CFLAGS) $(XINERAMA_CFLAGS)
   ifeq ($(HAVE_XCB),1)
      LIBS += -lX11-xcb
   endif
   ifeq ($(HAVE_XI2),1)
      LIBS += -lXi
      DEFINES += -DHAVE_XI2
   endif
   ifeq ($(HAVE_XSCRNSAVER),1)
      LIBS += -lXss
   endif
   ifneq ($(HAVE_OPENGLES), 1)
      OBJ += gfx/drivers_context/x_ctx.o
   endif
   ifeq ($(HAVE_VULKAN), 1)
      OBJ += gfx/drivers_context/x_vk_ctx.o
   endif
endif

ifeq ($(HAVE_XCB),1)
   DEF_FLAGS += $(XCB_CFLAGS)
   LIBS      += $(XCB_LIBS)
endif

ifeq ($(HAVE_XKBCOMMON), 1)
   DEF_FLAGS += $(XKBCOMMON_CFLAGS)
   OBJ += input/drivers_keyboard/keyboard_event_xkb.o
   LIBS += $(XKBCOMMON_LIBS)
endif

ifeq ($(HAVE_DBUS), 1)
   LIBS += $(DBUS_LIBS)
   DEF_FLAGS += $(DBUS_CFLAGS)
   OBJ += gfx/common/dbus_common.o
endif

ifeq ($(HAVE_UDEV), 1)
   DEF_FLAGS += $(UDEV_CFLAGS)
   LIBS += $(UDEV_LIBS)
   OBJ += input/drivers/udev_input.o \
          input/drivers_joypad/udev_joypad.o
endif

ifeq ($(HAVE_LIBUSB), 1)
   DEFINES += -DHAVE_LIBUSB
   OBJ += input/drivers_hid/libusb_hid.o
   DEF_FLAGS += $(LIBUSB_CFLAGS)
   LIBS += $(LIBUSB_LIBS)
endif

ifeq ($(HAVE_IOHIDMANAGER), 1)
   HAVE_HID=1
   DEFINES += -DHAVE_IOHIDMANAGER
   OBJ += input/drivers_hid/iohidmanager_hid.o
   LIBS += -framework IOKit
endif

ifeq ($(HAVE_HID), 1)
   DEFINES += -DHAVE_HID
   OBJ += input/drivers_joypad/hid_joypad.o \
          input/connect/joypad_connection.o \
          input/connect/connect_ps2adapter.o \
          input/connect/connect_psxadapter.o \
          input/connect/connect_ps3.o \
          input/connect/connect_ps4.o \
          input/connect/connect_ps4_hori_mini.o \
          input/connect/connect_wii.o \
          input/connect/connect_retrode.o \
          input/connect/connect_nesusb.o \
          input/connect/connect_snesusb.o \
          input/connect/connect_wiiupro.o \
	  input/connect/connect_kade.o \
	  input/connect/connect_zerodelay_dragonrise.o \
          input/connect/connect_wiiugca.o
endif

ifeq ($(HAVE_PARPORT), 1)
   OBJ += input/drivers_joypad/parport_joypad.o
endif

ifneq ($(findstring Win32,$(OS)),)
ifeq ($(HAVE_WINRAWINPUT), 1)
   DEFINES += -DHAVE_WINRAWINPUT
   OBJ     += input/drivers/winraw_input.o
endif
endif

ifeq ($(HAVE_LIBSHAKE), 1)
ifeq ($(OSX), 1)
   DEFINES      += -DHAVE_LIBSHAKE
   INCLUDE_DIRS += -I$(DEPS_DIR)/libShake/include
   OBJ          += $(DEPS_DIR)/libShake/src/common/error.o \
                   $(DEPS_DIR)/libShake/src/common/helpers.o \
                   $(DEPS_DIR)/libShake/src/common/presets.o \
                   $(DEPS_DIR)/libShake/src/osx/shake.o
else ifeq ($(HAVE_UNIX), 1)
   DEFINES      += -DHAVE_LIBSHAKE
   INCLUDE_DIRS += -I$(DEPS_DIR)/libShake/include
   OBJ          += $(DEPS_DIR)/libShake/src/common/error.o \
                   $(DEPS_DIR)/libShake/src/common/helpers.o \
                   $(DEPS_DIR)/libShake/src/common/presets.o \
                   $(DEPS_DIR)/libShake/src/linux/shake.o
endif
endif

# Companion UI

ifneq ($(findstring Win32,$(OS)),)
   OBJ += ui/drivers/ui_win32.o
endif

# Video

OBJ += gfx/drivers_context/gfx_null_ctx.o

ifeq ($(HAVE_KMS), 1)
   HAVE_AND_WILL_USE_DRM = 1
   OBJ += gfx/drivers_context/drm_ctx.o \
		  gfx/display_servers/dispserv_kms.o

ifeq ($(HAVE_ODROIDGO2), 1)
   OBJ += gfx/drivers_context/drm_go2_ctx.o
endif
   DEF_FLAGS += $(GBM_CFLAGS) $(DRM_CFLAGS)
   LIBS += $(GBM_LIBS) $(DRM_LIBS)
endif

ifeq ($(HAVE_CACA), 1)
   DEFINES += -DHAVE_CACA
   OBJ += gfx/drivers/caca_gfx.o
   LIBS += $(CACA_LIBS)
   DEF_FLAGS += $(CACA_CFLAGS)
endif

ifeq ($(HAVE_SIXEL), 1)
   DEFINES += -DHAVE_SIXEL
   INCLUDE_DIRS += -I/usr/include/sixel
   OBJ += gfx/drivers/sixel_gfx.o
   LIBS += $(SIXEL_LIBS)
   DEF_FLAGS += $(SIXEL_CFLAGS)
endif

ifeq ($(HAVE_NETWORK_VIDEO), 1)
   ifneq ($(NETWORK_VIDEO_HOST),)
      DEFINES += -DNETWORK_VIDEO_HOST=$(NETWORK_VIDEO_HOST)
   else
      DEFINES += -DNETWORK_VIDEO_HOST=127.0.0.1
   endif

   ifneq ($(NETWORK_VIDEO_PORT),)
      DEFINES += -DNETWORK_VIDEO_PORT=$(NETWORK_VIDEO_PORT)
   else
      DEFINES += -DNETWORK_VIDEO_PORT=4953
   endif

   DEFINES += -DHAVE_NETWORK_VIDEO
   OBJ += gfx/drivers/network_gfx.o
endif

ifeq ($(HAVE_PLAIN_DRM), 1)
   OBJ += gfx/drivers/drm_gfx.o
   ifneq ($(HAVE_LAKKA), 1)
      INCLUDE_DIRS += -I/usr/include/libdrm
   endif
   LIBS += -ldrm
   HAVE_AND_WILL_USE_DRM = 1
endif

ifeq ($(HAVE_VITAGL), 1)
   DEFINES += -DHAVE_OPENGL1 -DHAVE_VITAGL
   OBJ += gfx/drivers/gl1.o \
          gfx/drivers_context/vita_ctx.o
endif

ifeq ($(HAVE_VITAGLES), 1)
   OBJ += gfx/drivers_context/vita_ctx.o
endif

ifeq ($(HAVE_GL_CONTEXT), 1)
   OBJ += gfx/common/gl_common.o
   ifeq ($(HAVE_GL_MODERN), 1)
      DEFINES += -DHAVE_OPENGL
      OBJ += gfx/drivers/gl2.o \
             $(LIBRETRO_COMM_DIR)/gfx/gl_capabilities.o
   endif

   OBJ += $(LIBRETRO_COMM_DIR)/glsym/rglgen.o

   ifeq ($(HAVE_OPENGL1), 1)
      DEFINES += -DHAVE_OPENGL1
      OBJ += gfx/drivers/gl1.o
   endif

   ifeq ($(HAVE_VIDEOCORE), 1)
      OBJ += gfx/drivers_context/vc_egl_ctx.o
   endif

   ifeq ($(HAVE_EMSCRIPTEN), 1)
      ifeq ($(HAVE_EGL), 1)
        OBJ += gfx/drivers_context/emscriptenegl_ctx.o
      endif
      OBJ += gfx/drivers_context/emscriptenwebgl_ctx.o
   endif

   ifeq ($(HAVE_MALI_FBDEV), 1)
      OBJ += gfx/drivers_context/mali_fbdev_ctx.o
   endif

   ifeq ($(HAVE_VIVANTE_FBDEV), 1)
      OBJ += gfx/drivers_context/vivante_fbdev_ctx.o
   endif

   ifeq ($(HAVE_X11), 1)
      ifeq ($(HAVE_EGL), 1)
         OBJ += gfx/drivers_context/xegl_ctx.o
      endif
   endif

   ifeq ($(HAVE_OSMESA), 1)
      OBJ  += gfx/drivers_context/osmesa_ctx.o
      LIBS += -lOSMesa
   endif

   ifeq ($(HAVE_FFMPEG), 1)
      ifneq ($(HAVE_OPENGLES), 1)
         OBJ += cores/libretro-ffmpeg/ffmpeg_fft.o
         DEFINES += -DHAVE_GL_FFT
         INCLUDE_DIRS += -I$(DEPS_DIR)
      endif
   endif


   ifeq ($(HAVE_MPV), 1)
      OBJ += cores/libretro-mpv/mpv-libretro.o
      DEFINES += -DHAVE_MPV
      INCLUDE_DIRS += -I$(DEPS_DIR)
      LIBS += -lmpv
   endif

   ifeq ($(HAVE_OPENGLES), 1)
      DEFINES += -DHAVE_OPENGLES
      LIBS += $(OPENGLES_LIBS)
      DEF_FLAGS += $(OPENGLES_CFLAGS)
      ifeq ($(HAVE_OPENGLES3), 1)
         DEFINES += -DHAVE_OPENGLES3
         OBJ += $(LIBRETRO_COMM_DIR)/glsym/glsym_es3.o
      else
         DEFINES += -DHAVE_OPENGLES2
         OBJ += $(LIBRETRO_COMM_DIR)/glsym/glsym_es2.o
      endif
   else
      DEFINES += -DHAVE_GL_SYNC
      OBJ += $(LIBRETRO_COMM_DIR)/glsym/glsym_gl.o
      GL_LIBS := $(OPENGL_LIBS)
      ifeq ($(OSX), 1)
         GL_LIBS := -framework OpenGL
      else ifneq ($(findstring Win32,$(OS)),)
         GL_LIBS := -lopengl32 -lgdi32 -lcomdlg32
    WANT_WGL=1
      endif
      LIBS += $(GL_LIBS)
   endif

endif

ifeq ($(HAVE_METAL), 1)
   DEFINES += -DHAVE_METAL
   LIBS += -framework Metal -framework MetalKit
   # Metal code relies on ARC (Automatic Reference Counting), enable it
   DEF_FLAGS += -fobjc-arc
   OBJ += \
	  gfx/common/metal/metal_renderer.o \
	  gfx/drivers/metal.o
endif

ifeq ($(HAVE_EGL), 1)
   DEFINES += -DHAVE_EGL
   DEF_FLAGS += $(EGL_CFLAGS)
   OBJ += gfx/common/egl_common.o

ifeq ($(HAVE_DYNAMIC_EGL), 1)
	DEFINES += -DHAVE_DYNAMIC_EGL
else
   LIBS += $(EGL_LIBS)
endif

endif

ifeq ($(HAVE_SDL2), 1)
   HAVE_SDL_COMMON = 1
   OBJ += gfx/drivers/sdl2_gfx.o \
	  gfx/common/sdl2_common.o
   DEF_FLAGS += $(SDL2_CFLAGS)
   LIBS += $(SDL2_LIBS)
else ifeq ($(HAVE_SDL), 1)
   HAVE_SDL_COMMON = 1
   OBJ += gfx/drivers/sdl_gfx.o
   DEF_FLAGS += $(SDL_CFLAGS)
   LIBS += $(SDL_LIBS)
else ifeq ($(HAVE_SDL_DINGUX), 1)
   HAVE_SDL_COMMON = 1
   DEF_FLAGS += -DHAVE_SDL -DHAVE_SDL_DINGUX

   ifeq ($(RS90), 1)
      OBJ += gfx/drivers/sdl_rs90_gfx.o
   else ifeq ($(MIYOO), 1)
      OBJ += gfx/drivers/sdl_rs90_gfx.o
   else
      OBJ += gfx/drivers/sdl_dingux_gfx.o
   endif

   OBJ += input/drivers/sdl_dingux_input.o \
          input/drivers_joypad/sdl_dingux_joypad.o
   DEF_FLAGS += $(SDL_DINGUX_CFLAGS)
   LIBS += $(SDL_DINGUX_LIBS)
endif

ifeq ($(HAVE_SDL_COMMON), 1)
   OBJ += input/drivers/sdl_input.o \
          input/drivers_joypad/sdl_joypad.o \
          audio/drivers/sdl_audio.o

   ifeq ($(HAVE_GL_CONTEXT), 1)
      OBJ += gfx/drivers_context/sdl_gl_ctx.o
   endif

   INCLUDE_DIRS += $(BSD_LOCAL_INC)
endif

ifeq ($(HAVE_XSHM), 1)
   OBJ += gfx/drivers/xshm_gfx.o
endif

ifeq ($(HAVE_VULKAN), 1)
   ifneq ($(findstring Win32,$(OS)),)
      WANT_WGL = 1
      # Trivial temporary workaround for MinGW and glslang.
      CXXFLAGS += -fpermissive
   endif

   CXXFLAGS += -Wno-switch -Wno-sign-compare -fno-strict-aliasing -Wno-reorder -Wno-parentheses

   OBJ += gfx/drivers/vulkan.o \
          gfx/common/vulkan_common.o \
          $(LIBRETRO_COMM_DIR)/vulkan/vulkan_symbol_wrapper.o

   ifeq ($(HAVE_SLANG), 1)
      OBJ += gfx/drivers_shader/shader_vulkan.o
   endif

   ifeq ($(HAVE_VULKAN_DISPLAY), 1)
      OBJ += gfx/drivers_context/khr_display_ctx.o
   endif
   NEED_CXX_LINKER = 1
   DEFINES += -DHAVE_VULKAN
   INCLUDE_DIRS += -Igfx/include
endif

ifeq ($(HAVE_OPENGL_CORE), 1)
   OBJ += gfx/drivers/gl3.o

   DEFINES += -DHAVE_OPENGL_CORE

   ifeq ($(HAVE_SLANG), 1)
      OBJ += gfx/drivers_shader/shader_gl3.o

      NEED_CXX_LINKER = 1
   endif
endif

ifeq ($(HAVE_OMAP), 1)
   OBJ += gfx/drivers/omap_gfx.o
endif

ifeq ($(HAVE_EXYNOS), 1)
   OBJ += gfx/drivers/exynos_gfx.o
   LIBS += $(DRM_LIBS) $(EXYNOS_LIBS)
   DEF_FLAGS += $(DRM_CFLAGS) $(EXYNOS_CFLAGS)
   HAVE_AND_WILL_USE_DRM = 1
endif

ifeq ($(HAVE_AND_WILL_USE_DRM), 1)
   OBJ += gfx/common/drm_common.o
endif

ifeq ($(HAVE_DISPMANX), 1)
   OBJ += gfx/drivers/dispmanx_gfx.o
   HAVE_VIDEOCORE = 1
endif

ifeq ($(HAVE_SUNXI), 1)
   OBJ += gfx/drivers/sunxi_gfx.o \
          gfx/include/pixman/pixman-arm-neon-asm.o
endif

ifeq ($(HAVE_VG), 1)
   OBJ += gfx/drivers/vg.o
   DEF_FLAGS += $(VG_CFLAGS)
   LIBS += $(VG_LIBS)
endif

ifeq ($(HAVE_XVIDEO), 1)
   OBJ += gfx/drivers/xvideo.o
   LIBS += $(XVIDEO_LIBS)
   DEF_FLAGS += $(XVIDEO_CFLAGS)
endif

ifeq ($(HAVE_D3D9), 1)
   HAVE_D3D_COMMON = 1
   DEFINES += -DHAVE_D3D9
   ifeq ($(HAVE_D3DX9), 1)
      HAVE_D3DX_COMMON = 1
   endif
   ifneq ($(HAVE_DYLIB), 1)
      LIBS += $(D3D9_LIBS)
      ifeq ($(HAVE_D3DX9), 1)
         LIBS += $(D3DX9_LIBS)
      endif
   endif
   HAVE_DX_COMMON  = 1
   OBJ  += gfx/drivers_font/d3d9x_w32_font.o
   ifeq ($(HAVE_CG), 1)
      LIBS += -lcgD3D9
      OBJ  += gfx/drivers/d3d9cg.o
   endif
endif

ifeq ($(HAVE_D3D10), 1)
   HAVE_D3D_COMMON = 1
   OBJ += gfx/drivers/d3d10.o
   DEFINES += -DHAVE_D3D10
endif

ifeq ($(HAVE_D3D11), 1)
   HAVE_D3D_COMMON = 1
   OBJ += gfx/drivers/d3d11.o
   DEFINES += -DHAVE_D3D11
endif

ifeq ($(HAVE_D3D12), 1)
   HAVE_D3D_COMMON = 1
   OBJ += gfx/drivers/d3d12.o
   DEFINES += -DHAVE_D3D12
endif

ifneq ($(findstring 1, $(HAVE_D3D10) $(HAVE_D3D11) $(HAVE_D3D12)),)
   INCLUDE_DIRS += -isystemgfx/include/dxsdk
   OBJ += gfx/common/d3dcompiler_common.o \
          gfx/common/dxgi_common.o
   DEF_FLAGS += -Wno-unknown-pragmas
endif

ifeq ($(HAVE_D3D8), 1)
   HAVE_D3D_COMMON = 1
   HAVE_DX_COMMON  = 1
   DEFINES += -DHAVE_D3D8
   ifeq ($(HAVE_D3DX8), 1)
      HAVE_D3DX_COMMON = 1
   endif
   ifneq ($(HAVE_DYLIB), 1)
      LIBS += $(D3D8_LIBS)
      ifeq ($(HAVE_D3DX8), 1)
         LIBS += $(D3DX8_LIBS)
      endif
   endif
endif

ifeq ($(HAVE_D3DX_COMMON), 1)
   DEFINES += -DHAVE_D3DX
endif

ifeq ($(HAVE_DX_COMMON), 1)
   LIBS += -ldxguid
endif

ifeq ($(HAVE_D3D8), 1)
   DEFINES += -DHAVE_D3D8
   OBJ += gfx/drivers/d3d8.o
endif

ifeq ($(HAVE_D3D9), 1)
   DEFINES += -DHAVE_D3D9
   OBJ += gfx/common/d3d9_common.o
endif

ifeq ($(HAVE_D3D_COMMON), 1)
   DEFINES += -DHAVE_D3D
   OBJ     += gfx/common/d3d_common.o
endif

ifeq ($(HAVE_CG), 1)
   DEFINES += -DHAVE_CG
   OBJ += gfx/drivers_shader/shader_gl_cg.o
   LIBS += $(CG_LIBS)
endif

ifeq ($(HAVE_GLSL), 1)
   DEFINES += -DHAVE_GLSL
   OBJ += gfx/drivers_shader/shader_glsl.o
endif

ifeq ($(HAVE_HLSL),1)
   DEFINES += -DHAVE_HLSL
   OBJ += gfx/drivers/d3d9hlsl.o
endif

ifeq ($(HAVE_SLANG),1)
   DEFINES += -DHAVE_SLANG
   OBJ += gfx/drivers_shader/slang_process.o
   OBJ += gfx/drivers_shader/glslang_util.o
   OBJ += gfx/drivers_shader/glslang_util_cxx.o
   OBJ += gfx/drivers_shader/slang_reflection.o
endif

ifeq ($(HAVE_SHADERS_COMMON), 1)
   OBJ += gfx/video_shader_parse.o
endif

ifeq ($(HAVE_BUILTINGLSLANG), 1)
   NEED_CXX_LINKER = 1
   HAVE_GLSLANG_COMMON = 1

   ifneq ($(findstring Win32,$(OS)),)
      GLSLANG_PLATFORM := Windows
   else
      GLSLANG_PLATFORM := Unix
   endif

   DEFINES += -DHAVE_BUILTINGLSLANG

   INCLUDE_DIRS += \
      -I$(DEPS_DIR)/glslang/glslang/glslang/OSDependent/$(GLSLANG_PLATFORM) \
      -I$(DEPS_DIR)/glslang/glslang/OGLCompilersDLL \
      -I$(DEPS_DIR)/glslang/glslang/glslang/MachineIndependent \
      -I$(DEPS_DIR)/glslang/glslang/glslang/Public \
      -I$(DEPS_DIR)/glslang/glslang/SPIRV

   GLSLANG_SOURCES := \
      gfx/drivers_shader/glslang.cpp \
		$(DEPS_DIR)/glslang/glslang/SPIRV/GlslangToSpv.cpp \
		$(DEPS_DIR)/glslang/glslang/SPIRV/InReadableOrder.cpp \
		$(DEPS_DIR)/glslang/glslang/SPIRV/Logger.cpp \
		$(DEPS_DIR)/glslang/glslang/SPIRV/SpvBuilder.cpp \
      $(wildcard $(DEPS_DIR)/glslang/glslang/glslang/GenericCodeGen/*.cpp) \
      $(wildcard $(DEPS_DIR)/glslang/glslang/OGLCompilersDLL/*.cpp) \
      $(wildcard $(DEPS_DIR)/glslang/glslang/glslang/MachineIndependent/*.cpp) \
      $(wildcard $(DEPS_DIR)/glslang/glslang/glslang/MachineIndependent/preprocessor/*.cpp) \
      $(DEPS_DIR)/glslang/glslang/glslang/OSDependent/$(GLSLANG_PLATFORM)/ossource.cpp
else ifeq ($(HAVE_GLSLANG),1)
   HAVE_GLSLANG_COMMON = 1
   GLSLANG_SOURCES := gfx/drivers_shader/glslang.cpp

   # The order of these libs are somewhat specific
   LIBS += $(GLSLANG_LIBS) \
           $(GLSLANG_MACHINEINDEPENDENT_LIBS) \
           $(GLSLANG_GENERICCODEGEN_LIBS) \
           $(GLSLANG_OSDEPENDENT_LIBS) \
           $(GLSLANG_OGLCOMPILER_LIBS) \
           $(GLSLANG_SPIRV_LIBS) \
           $(GLSLANG_SPIRV_TOOLS_OPT_LIBS) \
           $(GLSLANG_SPIRV_TOOLS_LIBS)
endif

ifeq ($(HAVE_GLSLANG_COMMON), 1)
   DEFINES += -DHAVE_GLSLANG
   OBJ += $(GLSLANG_SOURCES_C:.c=.o)
   OBJ += $(GLSLANG_SOURCES:.cpp=.o)
endif

ifeq ($(HAVE_SPIRV_CROSS), 1)
   DEFINES += -DHAVE_SPIRV_CROSS
   INCLUDE_DIRS += -I/usr/include/spirv_cross
   LIBS += -lspirv-cross-cpp -lspirv-cross-msl -lspirv-cross-glsl -lspirv-cross-c-shared -lspirv-cross-core
endif

ifeq ($(WANT_WGL), 1)
   OBJ += gfx/drivers_context/wgl_ctx.o
   ifeq ($(HAVE_VULKAN),1)
      OBJ += gfx/drivers_context/w_vk_ctx.o
   endif
   LIBS += -lcomctl32
endif

# Compression/Archive

OBJ += $(LIBRETRO_COMM_DIR)/file/archive_file.o \
       $(LIBRETRO_COMM_DIR)/streams/trans_stream.o \
       $(LIBRETRO_COMM_DIR)/streams/trans_stream_pipe.o

ifeq ($(HAVE_7ZIP),1)
   INCLUDE_DIRS += -I$(DEPS_DIR)/7zip
   HAVE_COMPRESSION = 1
   DEFINES += -DHAVE_7ZIP -D_7ZIP_ST
   7ZOBJ = $(DEPS_DIR)/7zip/7zArcIn.o \
           $(DEPS_DIR)/7zip/7zBuf.o \
           $(DEPS_DIR)/7zip/7zCrc.o \
           $(DEPS_DIR)/7zip/7zCrcOpt.o \
           $(DEPS_DIR)/7zip/7zDec.o \
           $(DEPS_DIR)/7zip/CpuArch.o \
           $(DEPS_DIR)/7zip/Delta.o \
           $(DEPS_DIR)/7zip/LzFind.o \
           $(DEPS_DIR)/7zip/LzmaDec.o \
           $(DEPS_DIR)/7zip/Lzma2Dec.o \
           $(DEPS_DIR)/7zip/LzmaEnc.o \
           $(DEPS_DIR)/7zip/Bra.o \
           $(DEPS_DIR)/7zip/Bra86.o \
           $(DEPS_DIR)/7zip/BraIA64.o \
           $(DEPS_DIR)/7zip/Bcj2.o \
           $(DEPS_DIR)/7zip/7zFile.o \
           $(DEPS_DIR)/7zip/7zStream.o

   OBJ +=  $(LIBRETRO_COMM_DIR)/file/archive_file_7z.o \
           $(7ZOBJ)
endif

ifeq ($(HAVE_ZSTD),1)
   DEFINES += -DHAVE_ZSTD -DZSTD_DISABLE_ASM
   LIBS += -lzstd
endif

ifeq ($(HAVE_IBXM), 1)
   DEFINES += -DHAVE_IBXM
   OBJ += $(DEPS_DIR)/ibxm/ibxm.o
endif

ifeq ($(HAVE_BUILTINFLAC),1)
   HAVE_FLAC = 1
   DEFINES += -DHAVE_FLAC -DHAVE_DR_FLAC  -DHAVE_STDINT_H -DHAVE_LROUND -DFLAC__HAS_OGG=0 \
              -DFLAC_PACKAGE_VERSION="\"retroarch\""
   INCLUDE_DIRS += -I$(DEPS_DIR) -I$(DEPS_DIR)/libFLAC/include
   FLACOBJ = $(DEPS_DIR)/libFLAC/bitmath.o \
             $(DEPS_DIR)/libFLAC/bitreader.o \
             $(DEPS_DIR)/libFLAC/cpu.o \
             $(DEPS_DIR)/libFLAC/crc.o \
             $(DEPS_DIR)/libFLAC/fixed.o \
             $(DEPS_DIR)/libFLAC/float.o \
             $(DEPS_DIR)/libFLAC/format.o \
             $(DEPS_DIR)/libFLAC/lpc.o \
             $(DEPS_DIR)/libFLAC/lpc_intrin_avx2.o \
             $(DEPS_DIR)/libFLAC/lpc_intrin_sse2.o \
             $(DEPS_DIR)/libFLAC/lpc_intrin_sse41.o \
             $(DEPS_DIR)/libFLAC/lpc_intrin_sse.o \
             $(DEPS_DIR)/libFLAC/md5.o \
             $(DEPS_DIR)/libFLAC/memory.o \
             $(DEPS_DIR)/libFLAC/stream_decoder.o
   ifneq ($(findstring Win32,$(OS)),)
      DEFINES += -DHAVE_FSEEKO
      # make sure not to use this on legacy Windows versions that don't have W-functions implemented
      DEFINES += -DNEED_UTF8_SUPPORT
      FLACOBJ += $(DEPS_DIR)/libFLAC/windows_unicode_filenames.o
   endif
   OBJ += $(FLACOBJ)
else ifeq ($(HAVE_FLAC),1)
   DEFINES += -DHAVE_FLAC -DHAVE_DR_FLAC
   LIBS    += $(FLAC_LIBS)
endif

ifeq ($(HAVE_BUILTINZLIB), 1)
   HAVE_ZLIB_COMMON = 1
   OBJ += $(DEPS_DIR)/libz/adler32.o \
          $(DEPS_DIR)/libz/libz-crc32.o \
          $(DEPS_DIR)/libz/compress.o \
          $(DEPS_DIR)/libz/deflate.o \
          $(DEPS_DIR)/libz/gzclose.o \
          $(DEPS_DIR)/libz/gzlib.o \
          $(DEPS_DIR)/libz/gzread.o \
          $(DEPS_DIR)/libz/gzwrite.o \
          $(DEPS_DIR)/libz/inffast.o \
          $(DEPS_DIR)/libz/inflate.o \
          $(DEPS_DIR)/libz/inftrees.o \
          $(DEPS_DIR)/libz/trees.o \
          $(DEPS_DIR)/libz/uncompr.o \
          $(DEPS_DIR)/libz/zutil.o
   INCLUDE_DIRS += -I$(LIBRETRO_COMM_DIR)/include/compat/zlib
else ifeq ($(HAVE_ZLIB),1)
   HAVE_ZLIB_COMMON = 1
   LIBS += $(ZLIB_LIBS)
endif

ifeq ($(HAVE_ZLIB_COMMON), 1)
   OBJ += $(LIBRETRO_COMM_DIR)/file/archive_file_zlib.o \
          $(LIBRETRO_COMM_DIR)/streams/trans_stream_zlib.o \
          $(LIBRETRO_COMM_DIR)/streams/rzip_stream.o
   DEFINES += -DHAVE_ZLIB
   HAVE_COMPRESSION = 1

   ifeq ($(HAVE_CHD), 1)
      INCLUDE_DIRS += -I$(LIBRETRO_COMM_DIR)/formats/libchdr
      DEFINES += -DHAVE_CHD -DWANT_SUBCODE -DWANT_RAW_DATA_SECTOR
      ifeq ($(HAVE_STATIC_CORES), 1)
         DEFINES += -Dbitstream_overflow=retroarch_internal_bitstream_overflow
         DEFINES += -Dcreate_bitstream=retroarch_internal_create_bitstream
         DEFINES += -Dbitstream_peek=retroarch_internal_bitstream_peek
         DEFINES += -Dbitstream_remove=retroarch_internal_bitstream_remove
         DEFINES += -Dbitstream_read=retroarch_internal_bitstream_read
         DEFINES += -Dbitstream_read_offset=retroarch_internal_bitstream_read_offset
         DEFINES += -Dbitstream_flush=retroarch_internal_bitstream_flush

         DEFINES += -Decc_compute_bytes=retroarch_internal_ecc_compute_bytes
         DEFINES += -Decc_verify=retroarch_internal_ecc_verify
         DEFINES += -Decc_generate=retroarch_internal_ecc_generate
         DEFINES += -Decc_clear=retroarch_internal_ecc_clear

         DEFINES += -Ds_cd_sync_header=retroarch_internal_s_cd_sync_header
         DEFINES += -Dchd_open_file=retroarch_internal_chd_open_file
         DEFINES += -Dchd_precache=retroarch_internal_chd_precache
         DEFINES += -Dchd_open=retroarch_internal_chd_open
         DEFINES += -Dchd_close=retroarch_internal_chd_close
         DEFINES += -Dchd_core_file=retroarch_internal_chd_core_file
         DEFINES += -Dchd_error_string=retroarch_internal_chd_error_string
         DEFINES += -Dchd_get_header=retroarch_internal_chd_get_header
         DEFINES += -Dchd_read=retroarch_internal_chd_read
         DEFINES += -Dchd_get_metadata=retroarch_internal_chd_get_metadata
         DEFINES += -Dchd_codec_config=retroarch_internal_chd_codec_config
         DEFINES += -Dchd_get_codec_name=retroarch_internal_chd_get_codec_name

         DEFINES += -Dcreate_huffman_decoder=retroarch_internal_create_huffman_decoder
         DEFINES += -Ddelete_huffman_decoder=retroarch_internal_delete_huffman_decoder
         DEFINES += -Dhuffman_decode_one=retroarch_internal_huffman_decode_one
         DEFINES += -Dhuffman_import_tree_rle=retroarch_internal_huffman_import_tree_rle
         DEFINES += -Dhuffman_import_tree_huffman=retroarch_internal_huffman_import_tree_huffman
         DEFINES += -Dhuffman_compute_tree_from_histo=retroarch_internal_huffman_compute_tree_from_histo
         DEFINES += -Dhuffman_build_tree=retroarch_internal_huffman_build_tree
         DEFINES += -Dhuffman_assign_canonical_codes=retroarch_internal_huffman_assign_canonical_codes
         DEFINES += -Dhuffman_build_lookup_table=retroarch_internal_huffman_build_lookup_table

         DEFINES += -Dcdzl_codec_init=retroarch_internal_cdzl_codec_init
         DEFINES += -Dcdzl_codec_free=retroarch_internal_cdzl_codec_free
         DEFINES += -Dcdzl_codec_decompress=retroarch_internal_cdzl_codec_decompress
         DEFINES += -Dzlib_codec_init=retroarch_internal_zlib_codec_init
         DEFINES += -Dzlib_codec_free=retroarch_internal_zlib_codec_free
         DEFINES += -Dzlib_codec_decompress=retroarch_internal_zlib_codec_decompress
         DEFINES += -Dzlib_fast_alloc=retroarch_internal_zlib_fast_alloc
         DEFINES += -Dzlib_fast_free=retroarch_internal_zlib_fast_free

         DEFINES += -Dchdstream_open=retroarch_internal_chdstream_open
         DEFINES += -Dchdstream_close=retroarch_internal_chdstream_close
         DEFINES += -Dchdstream_read=retroarch_internal_chdstream_read
         DEFINES += -Dchdstream_getc=retroarch_internal_chdstream_getc
         DEFINES += -Dchdstream_gets=retroarch_internal_chdstream_gets
         DEFINES += -Dchdstream_tell=retroarch_internal_chdstream_tell
         DEFINES += -Dchdstream_rewind=retroarch_internal_chdstream_rewind
         DEFINES += -Dchdstream_seek=retroarch_internal_chdstream_seek
         DEFINES += -Dchdstream_get_size=retroarch_internal_chdstream_get_size
         DEFINES += -Dchdstream_get_track_start=retroarch_internal_chdstream_get_track_start
         DEFINES += -Dchdstream_get_frame_size=retroarch_internal_chdstream_get_frame_size
         DEFINES += -Dchdstream_get_first_track_sector=retroarch_internal_chdstream_get_first_track_sector

         DEFINES += -Dflac_decoder_init=retroarch_internal_flac_decoder_init
         DEFINES += -Dflac_decoder_free=retroarch_internal_flac_decoder_free
         DEFINES += -Dflac_decoder_reset=retroarch_internal_flac_decoder_reset
         DEFINES += -Dflac_decoder_decode_interleaved=retroarch_internal_flac_decoder_decode_interleaved
         DEFINES += -Dflac_decoder_finish=retroarch_internal_flac_decoder_finish
         DEFINES += -Dflac_decoder_read_callback_static=retroarch_internal_flac_decoder_read_callback_static
         DEFINES += -Dflac_decoder_read_callback=retroarch_internal_flac_decoder_read_callback
         DEFINES += -Dflac_decoder_metadata_callback_static=retroarch_internal_flac_decoder_metadata_callback_static
         DEFINES += -Dflac_decoder_tell_callback_static=retroarch_internal_flac_decoder_tell_callback_static
         DEFINES += -Dflac_decoder_write_callback_static=retroarch_internal_flac_decoder_write_callback_static
         DEFINES += -Dflac_decoder_write_callback=retroarch_internal_flac_decoder_write_callback
         DEFINES += -Dflac_decoder_error_callback_static=retroarch_internal_flac_decoder_error_callback_static
         DEFINES += -Dcdfl_codec_init=retroarch_internal_cdfl_codec_init
         DEFINES += -Dcdfl_codec_free=retroarch_internal_cdfl_codec_free
         DEFINES += -Dcdfl_codec_decompress=retroarch_internal_cdfl_codec_decompress

         DEFINES += -Dlzma_allocator_init=retroarch_internal_lzma_allocator_init
         DEFINES += -Dlzma_allocator_free=retroarch_internal_lzma_allocator_free
         DEFINES += -Dlzma_codec_init=retroarch_internal_lzma_codec_init
         DEFINES += -Dlzma_codec_free=retroarch_internal_lzma_codec_free
         DEFINES += -Dlzma_codec_decompress=retroarch_internal_lzma_codec_decompress
         DEFINES += -Dcdlz_codec_init=retroarch_internal_cdlz_codec_init
         DEFINES += -Dcdlz_codec_free=retroarch_internal_cdlz_codec_free
         DEFINES += -Dcdlz_codec_decompress=retroarch_internal_cdlz_codec_decompress

         DEFINES += -Dzstd_codec_init=retroarch_internal_zstd_codec_init
         DEFINES += -Dzstd_codec_free=retroarch_internal_zstd_codec_free
         DEFINES += -Dzstd_codec_decompress=retroarch_internal_zstd_codec_decompress
         DEFINES += -Dcdzs_codec_init=retroarch_internal_cdzs_codec_init
         DEFINES += -Dcdzs_codec_free=retroarch_internal_cdzs_codec_free
         DEFINES += -Dcdzs_codec_decompress=retroarch_internal_cdzs_codec_decompress
      endif
      OBJ     += $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_bitstream.o \
                 $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_cdrom.o \
                 $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_chd.o \
                 $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_huffman.o \
                 $(LIBRETRO_COMM_DIR)/streams/chd_stream.o \
                 $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_zlib.o

      ifeq ($(HAVE_FLAC),1)
         OBJ += $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_flac.o \
                $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_flac_codec.o
      endif

      ifeq ($(HAVE_7ZIP), 1)
         OBJ += $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_lzma.o
      endif

      ifeq ($(HAVE_ZSTD), 1)
         OBJ += $(LIBRETRO_COMM_DIR)/formats/libchdr/libchdr_zstd.o
      endif
   endif
endif

ifeq ($(HAVE_CDROM), 1)
   ifeq ($(CDROM_DEBUG), 1)
      DEFINES += -DCDROM_DEBUG
   endif

   DEFINES += -DHAVE_CDROM
   OBJ += $(LIBRETRO_COMM_DIR)/cdrom/cdrom.o \
			 $(LIBRETRO_COMM_DIR)/vfs/vfs_implementation_cdrom.o \
			 $(LIBRETRO_COMM_DIR)/media/media_detect_cd.o \
			 tasks/task_content_disc.o
endif

ifeq ($(HAVE_RTGA), 1)
   DEFINES += -DHAVE_RTGA
   OBJ += $(LIBRETRO_COMM_DIR)/formats/tga/rtga.o
endif

ifeq ($(HAVE_RPNG), 1)
   DEFINES += -DHAVE_RPNG
   OBJ += $(LIBRETRO_COMM_DIR)/formats/png/rpng.o \
          $(LIBRETRO_COMM_DIR)/formats/png/rpng_encode.o
endif

ifeq ($(HAVE_RJPEG), 1)
   DEFINES += -DHAVE_RJPEG
   OBJ += $(LIBRETRO_COMM_DIR)/formats/jpeg/rjpeg.o
endif

ifeq ($(HAVE_RBMP), 1)
   DEFINES += -DHAVE_RBMP
   OBJ += $(LIBRETRO_COMM_DIR)/formats/bmp/rbmp.o
endif

OBJ += $(LIBRETRO_COMM_DIR)/formats/bmp/rbmp_encode.o \
       $(LIBRETRO_COMM_DIR)/formats/json/rjson.o \
       $(LIBRETRO_COMM_DIR)/formats/image_transfer.o \
       $(LIBRETRO_COMM_DIR)/formats/m3u/m3u_file.o

# Video4Linux 2

ifeq ($(HAVE_V4L2),1)
   OBJ += camera/drivers/video4linux2.o
   ifeq ($(HAVE_VIDEOPROCESSOR),1)
      DEFINES += -DHAVE_VIDEOPROCESSOR
      OBJ += cores/libretro-video-processor/video_processor_v4l2.o
   endif
   DEFINES += -DHAVE_V4L2
   LIBS += $(V4L2_LIBS)
endif

# FFmpeg

ifeq ($(HAVE_FFMPEG), 1)
   DEFINES += -DHAVE_FFMPEG
   INCLUDE_DIRS += -Iffmpeg
   DEF_FLAGS += $(FFMPEG_CFLAGS) -Wno-deprecated-declarations
   LIBS += $(FFMPEG_LIBS)

   ifeq ($(HAVE_AVCODEC), 1)
      DEFINES += -DHAVE_AVCODEC
      DEF_FLAGS += $(AVCODEC_CFLAGS)
      LIBS += $(AVCODEC_LIBS)
   endif

   ifeq ($(HAVE_AVDEVICE), 1)
      DEFINES += -DHAVE_AVDEVICE
      DEF_FLAGS += $(AVDEVICE_CFLAGS)
      LIBS += $(AVDEVICE_LIBS)
   endif

   ifeq ($(HAVE_AVFORMAT), 1)
      DEFINES += -DHAVE_AVFORMAT
      DEF_FLAGS += $(AVFORMAT_CFLAGS)
      LIBS += $(AVFORMAT_LIBS)
   endif

   ifeq ($(HAVE_AVUTIL), 1)
      DEFINES += -DHAVE_AVUTIL
      DEF_FLAGS += $(AVUTIL_CFLAGS)
      LIBS += $(AVUTIL_LIBS)
   endif

   ifeq ($(HAVE_SWSCALE), 1)
      DEFINES += -DHAVE_SWSCALE
      DEF_FLAGS += $(SWSCALE_CFLAGS)
      LIBS += $(SWSCALE_LIBS)
   endif

   ifeq ($(HAVE_SWRESAMPLE), 1)
      DEFINES += -DHAVE_SWRESAMPLE
      DEF_FLAGS += $(SWRESAMPLE_CFLAGS)
      LIBS += $(SWRESAMPLE_LIBS)
   endif
endif

ifeq ($(HAVE_FFMPEG), 1)
ifeq ($(HAVE_AVFORMAT), 1)
ifeq ($(HAVE_AVDEVICE), 1)
ifeq ($(HAVE_AVCODEC), 1)
ifeq ($(HAVE_AVUTIL), 1)
ifeq ($(HAVE_SWSCALE), 1)
   OBJ += camera/drivers/ffmpeg.o
endif
endif
endif
endif
endif
endif

# Accessibility
ifeq ($(HAVE_ACCESSIBILITY), 1)
   DEFINES += -DHAVE_ACCESSIBILITY

ifeq ($(HAVE_SAPI), 1)
ifneq ($(findstring Win32,$(OS)),)
   LIBS += -lsapi
endif
endif

endif



# Things that depend on network availability

ifeq ($(HAVE_NETWORKING), 1)
   DEFINES += -DHAVE_NETWORKING
   OBJ += $(LIBRETRO_COMM_DIR)/net/net_compat.o \
          $(LIBRETRO_COMM_DIR)/net/net_http.o \
          $(LIBRETRO_COMM_DIR)/net/net_http_parse.o \
          $(LIBRETRO_COMM_DIR)/net/net_socket.o \
          core_updater_list.o \
          network/natt.o \
          tasks/task_netplay_lan_scan.o \
          tasks/task_netplay_nat_traversal.o \
          tasks/task_netplay_find_content.o

   ifeq ($(HAVE_EMSCRIPTEN), 1)
     OBJ += tasks/task_http_emscripten.o
   else
     OBJ += tasks/task_http.o
   endif

   ifeq ($(HAVE_MENU), 1)
      OBJ += tasks/task_pl_thumbnail_download.o
   endif

   ifeq ($(HAVE_MENU_COMMON), 1)
      OBJ += tasks/task_core_updater.o
   endif

   ifneq ($(findstring Linux,$(OS)),)
      HAVE_CLOUDSYNC = 1
   endif

   ifneq ($(findstring Win,$(OS)),)
      HAVE_CLOUDSYNC = 1
   endif

   ifeq ($(HAVE_CLOUDSYNC), 1)
      DEFINES += -DHAVE_CLOUDSYNC
      OBJ += tasks/task_cloudsync.o \
             network/cloud_sync/webdav.o \
             network/cloud_sync_driver.o
   endif

   ifeq ($(HAVE_BUILTINBEARSSL), 1)
      OBJ += $(LIBRETRO_COMM_DIR)/net/net_socket_ssl_bear.o
   else ifeq ($(HAVE_SSL), 1)
      OBJ += $(LIBRETRO_COMM_DIR)/net/net_socket_ssl_mbed.o
   endif

   ifeq ($(HAVE_IFINFO), 1)
      DEFINES += -DHAVE_IFINFO
      OBJ += $(LIBRETRO_COMM_DIR)/net/net_ifinfo.o
   endif

   ifeq ($(WANT_IFADDRS), 1)
      DEFINES += -DWANT_IFADDRS
      OBJ += $(LIBRETRO_COMM_DIR)/compat/compat_ifaddrs.o
   endif

   ifneq ($(findstring Win32,$(OS)),)
      LIBS += -lws2_32 -liphlpapi
   endif

   # Netplay
   DEFINES += -DHAVE_NETWORK_CMD
   OBJ += \
	  network/netplay/netplay_frontend.o \
	  network/netplay/netplay_room_parse.o

   # RetroAchievements
   ifeq ($(HAVE_CHEEVOS), 1)
      DEFINES += -DHAVE_CHEEVOS -DRC_CLIENT_SUPPORTS_HASH
      INCLUDE_DIRS += -Ideps/rcheevos/include

      ifneq ($(HAVE_THREADS), 1)
         DEFINES += -DRC_NO_THREADS
      else ifneq (,$(filter GEKKO,$(CFLAGS)))
         # Gekko (Wii) and 3DS use custom pthread wrappers (see rthreads.c)
         DEFINES += -DRC_NO_THREADS
      else ifneq (,$(filter _3DS,$(CFLAGS)))
         DEFINES += -DRC_NO_THREADS
      endif

      OBJ += cheevos/cheevos.o \
             cheevos/cheevos_client.o \
             cheevos/cheevos_menu.o \
             $(LIBRETRO_COMM_DIR)/formats/cdfs/cdfs.o \
             deps/rcheevos/src/rc_client.o \
             deps/rcheevos/src/rc_compat.o \
             deps/rcheevos/src/rc_libretro.o \
             deps/rcheevos/src/rc_util.o \
             deps/rcheevos/src/rcheevos/alloc.o \
             deps/rcheevos/src/rcheevos/condition.o \
             deps/rcheevos/src/rcheevos/condset.o \
             deps/rcheevos/src/rcheevos/consoleinfo.o \
             deps/rcheevos/src/rcheevos/format.o \
             deps/rcheevos/src/rcheevos/lboard.o \
             deps/rcheevos/src/rcheevos/memref.o \
             deps/rcheevos/src/rcheevos/operand.o \
             deps/rcheevos/src/rcheevos/richpresence.o \
             deps/rcheevos/src/rcheevos/runtime.o \
             deps/rcheevos/src/rcheevos/runtime_progress.o \
             deps/rcheevos/src/rcheevos/trigger.o \
             deps/rcheevos/src/rcheevos/value.o \
             deps/rcheevos/src/rhash/aes.o \
             deps/rcheevos/src/rhash/cdreader.o \
             deps/rcheevos/src/rhash/hash.o \
             deps/rcheevos/src/rhash/hash_disc.o \
             deps/rcheevos/src/rhash/hash_encrypted.o \
             deps/rcheevos/src/rhash/hash_rom.o \
             deps/rcheevos/src/rhash/hash_zip.o \
             deps/rcheevos/src/rapi/rc_api_common.o \
             deps/rcheevos/src/rapi/rc_api_info.o \
             deps/rcheevos/src/rapi/rc_api_runtime.o \
             deps/rcheevos/src/rapi/rc_api_user.o \

      # RVZ/WIA disc image support for RetroAchievements
      ifeq ($(HAVE_ZSTD), 1)
         DEFINES += -DHAVE_CHEEVOS_RVZ
         OBJ += cheevos/cheevos_rvz.o
      endif

      ifeq ($(HAVE_LUA), 1)
         DEFINES += -DHAVE_LUA \
                    -DLUA_32BITS
         INCLUDE_DIRS += -Ideps/lua/src
         OBJ += deps/lua/src/lapi.o \
                deps/lua/src/lcode.o \
                deps/lua/src/lctype.o \
                deps/lua/src/ldebug.o \
                deps/lua/src/ldo.o \
                deps/lua/src/ldump.o \
                deps/lua/src/lfunc.o \
                deps/lua/src/lgc.o \
                deps/lua/src/llex.o \
                deps/lua/src/lmem.o \
                deps/lua/src/lobject.o \
                deps/lua/src/lopcodes.o \
                deps/lua/src/lparser.o \
                deps/lua/src/lstate.o \
                deps/lua/src/lstring.o \
                deps/lua/src/ltable.o \
                deps/lua/src/ltm.o \
                deps/lua/src/lundump.o \
                deps/lua/src/lvm.o \
                deps/lua/src/lzio.o \
                deps/lua/src/lauxlib.o \
                deps/lua/src/lbaselib.o \
                deps/lua/src/lbitlib.o \
                deps/lua/src/lcorolib.o \
                deps/lua/src/ldblib.o \
                deps/lua/src/liolib.o \
                deps/lua/src/lmathlib.o \
                deps/lua/src/loslib.o \
                deps/lua/src/lstrlib.o \
                deps/lua/src/ltablib.o \
                deps/lua/src/lutf8lib.o \
                deps/lua/src/loadlib.o \
                deps/lua/src/linit.o
      else
         DEFINES += -DRC_DISABLE_LUA
      endif

   endif

   ifeq ($(HAVE_DISCORD), 1)
      NEED_CXX_LINKER = 1
      HAVE_PRESENCE = 1
      DEFINES += -DHAVE_DISCORD
      INCLUDE_DIRS += -Ideps/discord-rpc/include

      ifneq ($(HAVE_THREADS), 1)
         DEFINES += -DDISCORD_DISABLE_IO_THREAD
      endif

      OBJ     += deps/discord-rpc/src/discord_rpc.o \
                 deps/discord-rpc/src/rpc_connection.o \
                 deps/discord-rpc/src/serialization.o

      OBJ     += network/discord.o

      ifneq ($(findstring Win32,$(OS)),)
         OBJ  += deps/discord-rpc/src/discord_register_win.o \
                 deps/discord-rpc/src/connection_win.o
         LIBS += -lpsapi -ladvapi32
      endif
      ifneq ($(findstring Linux,$(OS)),)
         OBJ  += deps/discord-rpc/src/discord_register_linux.o \
                 deps/discord-rpc/src/connection_unix.o
      endif
      ifneq ($(findstring Darwin,$(OS)),)
         OBJ  += deps/discord-rpc/src/discord_register_osx.o \
                 deps/discord-rpc/src/connection_unix.o
      endif
   endif

   ifeq ($(HAVE_TRANSLATE), 1)
      DEFINES += -DHAVE_TRANSLATE
   endif

   ifeq ($(HAVE_NETWORKGAMEPAD), 1)
      OBJ += cores/libretro-net-retropad/net_retropad_core.o
   endif
endif

ifneq ($(findstring FPGA,$(OS)),)
   OBJ += gfx/drivers/fpga_gfx.o
endif

ifneq ($(findstring Win32,$(OS)),)
   OBJ += media/rarch.o \
          gfx/common/win32_common.o \
          frontend/drivers/platform_win32.o \
          gfx/display_servers/dispserv_win32.o

   ifeq ($(HAVE_GDI), 1)
      OBJ += gfx/drivers/gdi_gfx.o
      LIBS += -lmsimg32
   endif
   LIBS += -lhid -lsetupapi
endif

ifeq ($(HAVE_ANGLE), 1)
	OBJ += gfx/common/angle_common.o
	DEFINES += -DHAVE_ANGLE
endif

# Record

ifeq ($(HAVE_FFMPEG), 1)
   OBJ += record/drivers/record_ffmpeg.o \
          cores/libretro-ffmpeg/ffmpeg_core.o \
          cores/libretro-ffmpeg/packet_buffer.o \
          cores/libretro-ffmpeg/video_buffer.o \
          $(LIBRETRO_COMM_DIR)/rthreads/tpool.o

   LIBS += $(AVCODEC_LIBS) $(AVFORMAT_LIBS) $(AVUTIL_LIBS) $(SWSCALE_LIBS) $(SWRESAMPLE_LIBS) $(FFMPEG_LIBS) $(AVDEVICE_LIBS)
   DEFINES += -DHAVE_FFMPEG
   DEF_FLAGS += $(AVCODEC_CFLAGS) $(AVFORMAT_CFLAGS) $(AVUTIL_CFLAGS) $(SWSCALE_CFLAGS) $(SWRESAMPLE_CFLAGS) \
                -Wno-deprecated-declarations
   INCLUDE_DIRS += -Iffmpeg
endif

# CRT mode switching
ifeq ($(HAVE_CRTSWITCHRES), 1)
   INCLUDE_DIRS += -I$(DEPS_DIR)/switchres
   OBJ += gfx/video_crt_switch.o \
          $(DEPS_DIR)/switchres/monitor.o \
          $(DEPS_DIR)/switchres/modeline.o \
          $(DEPS_DIR)/switchres/switchres.o \
          $(DEPS_DIR)/switchres/display.o \
          $(DEPS_DIR)/switchres/custom_video.o \
          $(DEPS_DIR)/switchres/log.o \
          $(DEPS_DIR)/switchres/switchres_wrapper.o \
          $(DEPS_DIR)/switchres/edid.o
   ifneq ($(findstring Win32,$(OS)),)
      OBJ += $(DEPS_DIR)/switchres/display_windows.o \
             $(DEPS_DIR)/switchres/custom_video_ati_family.o \
             $(DEPS_DIR)/switchres/custom_video_ati.o \
             $(DEPS_DIR)/switchres/custom_video_adl.o \
             $(DEPS_DIR)/switchres/custom_video_pstrip.o \
             $(DEPS_DIR)/switchres/resync_windows.o
   endif
   ifneq ($(findstring Linux,$(OS)),)
      OBJ += $(DEPS_DIR)/switchres/display_linux.o
      ifeq ($(HAVE_X11)$(HAVE_XRANDR), 11)
         OBJ += $(DEPS_DIR)/switchres/custom_video_xrandr.o
         DEFINES += -DSR_WITH_XRANDR
      endif
   endif
   ifneq ($(findstring Win32,$(OS)),)
      DEFINES += -DSR_WIN32_STATIC
   endif
   LIBS += -lstdc++
endif

ifeq ($(HAVE_COMPRESSION), 1)
   DEFINES += -DHAVE_COMPRESSION
   OBJ     += tasks/task_decompress.o
endif

ifeq ($(HAVE_COCOA), 1)
   HAVE_COCOA_COMMON = 1
endif
ifeq ($(HAVE_COCOA_METAL), 1)
   HAVE_COCOA_COMMON = 1
endif

ifeq ($(HAVE_COCOA_COMMON),1)
   DEFINES += -DHAVE_MAIN -DOSX
   OBJ += input/drivers/cocoa_input.o \
          ui/drivers/ui_cocoa.o \
          ui/drivers/cocoa/cocoa_common.o

   ifeq ($(HAVE_OPENGL), 1)
           DEFINES += -DGL_SILENCE_DEPRECATION
	   OBJ += gfx/drivers_context/cocoa_gl_ctx.o
   endif
   ifeq ($(HAVE_VULKAN), 1)
	   OBJ += gfx/drivers_context/cocoa_vk_ctx.o
   endif
endif

ifneq ($(findstring DOS,$(OS)),)
   OBJ += gfx/drivers/vga_gfx.o \
          input/drivers/dos_input.o \
          input/drivers_joypad/dos_joypad.o \
          frontend/drivers/platform_dos.o
endif

ifeq ($(HAVE_STATIC_VIDEO_FILTERS), 1)
   OBJ += gfx/video_filters/2xsai.o \
          gfx/video_filters/super2xsai.o \
          gfx/video_filters/supereagle.o \
          gfx/video_filters/2xbr.o \
          gfx/video_filters/darken.o \
          gfx/video_filters/epx.o \
          gfx/video_filters/scale2x.o \
          gfx/video_filters/blargg_ntsc_snes.o \
          gfx/video_filters/lq2x.o \
          gfx/video_filters/phosphor2x.o \
          gfx/video_filters/normal2x.o \
          gfx/video_filters/normal2x_width.o \
          gfx/video_filters/normal2x_height.o \
          gfx/video_filters/normal4x.o \
          gfx/video_filters/scanline2x.o \
          gfx/video_filters/grid2x.o \
          gfx/video_filters/grid3x.o \
          gfx/video_filters/gameboy3x.o \
          gfx/video_filters/gameboy4x.o \
          gfx/video_filters/dot_matrix_3x.o \
          gfx/video_filters/dot_matrix_4x.o \
          gfx/video_filters/upscale_1_5x.o \
          gfx/video_filters/upscale_1_66x_fast.o \
          gfx/video_filters/upscale_256x_320x240.o \
          gfx/video_filters/picoscale_256x_320x240.o \
          gfx/video_filters/upscale_240x160_320x240.o \
          gfx/video_filters/upscale_mix_240x160_320x240.o
endif

ifeq ($(WANT_IOSUHAX), 1)
   DEFINES += -DHAVE_IOSUHAX
   INCLUDE_DIRS += -I$(DEPS_DIR)/libiosuhax/include
   OBJ += $(DEPS_DIR)/libiosuhax/source/iosuhax.o \
          $(DEPS_DIR)/libiosuhax/source/iosuhax_devoptab.o \
          $(DEPS_DIR)/libiosuhax/source/iosuhax_disc_interface.o
endif

ifeq ($(WANT_LIBFAT), 1)
   DEFINES += -DHAVE_LIBFAT
   INCLUDE_DIRS += -I$(DEPS_DIR)/libfat/include
   OBJ += $(DEPS_DIR)/libfat/cache.o \
          $(DEPS_DIR)/libfat/directory.o \
          $(DEPS_DIR)/libfat/disc.o \
          $(DEPS_DIR)/libfat/fatdir.o \
          $(DEPS_DIR)/libfat/fatfile.o \
          $(DEPS_DIR)/libfat/file_allocation_table.o \
          $(DEPS_DIR)/libfat/filetime.o \
          $(DEPS_DIR)/libfat/libfat.o \
          $(DEPS_DIR)/libfat/lock.o \
          $(DEPS_DIR)/libfat/partition.o
endif

ifeq ($(HAVE_STATIC_AUDIO_FILTERS), 1)
   OBJ += libretro-common/audio/dsp_filters/chorus.o \
          libretro-common/audio/dsp_filters/crystalizer.o \
          libretro-common/audio/dsp_filters/echo.o \
          libretro-common/audio/dsp_filters/eq.o \
          libretro-common/audio/dsp_filters/iir.o \
          libretro-common/audio/dsp_filters/panning.o \
          libretro-common/audio/dsp_filters/phaser.o \
          libretro-common/audio/dsp_filters/reverb.o \
          libretro-common/audio/dsp_filters/tremolo.o \
          libretro-common/audio/dsp_filters/vibrato.o \
          libretro-common/audio/dsp_filters/wahwah.o
endif

ifeq ($(HAVE_RPILED), 1)
   OBJ += led/drivers/led_rpi.o \
          led/drivers/led_sys_linux.o
endif

ifneq ($(findstring Win32,$(OS)),)
   OBJ += led/drivers/led_win32_keyboard.o
endif

ifeq ($(HAVE_X11), 1)
   OBJ += led/drivers/led_x11_keyboard.o
endif

ifeq ($(HAVE_VITAGLES), 1)
   DEFINES += -DHAVE_VITAGLES
   INCLUDE_DIRS += -I$(DEPS_DIR)/Pigs-In-A-Blanket/include
   SOURCES := $(DEPS_DIR)/Pigs-In-A-Blanket/src
   OBJ += $(patsubst %.c,%.o,$(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)))
endif

ifeq ($(HAVE_WEBOS), 1)
  DEFINES += -DWEBOS
endif

ifeq ($(HAVE_TEST_DRIVERS), 1)
  DEFINES += -DHAVE_TEST_DRIVERS
  OBJ += input/drivers_joypad/test_joypad.o
  OBJ += input/drivers/test_input.o
endif


#####################################
### Android Play Feature Delivery ###
### (Play Store build core        ###
###  downloader)                  ###
#####################################
ifeq ($(ANDROID), 1)
   OBJ += play_feature_delivery/play_feature_delivery.o
endif

### Steam integration using mist
ifeq ($(HAVE_MIST), 1)
   HAVE_PRESENCE = 1
   DEFINES += -DHAVE_MIST
   INCLUDE_DIRS += -I$(MIST_PATH)/include
   LDFLAGS   += -L$(MIST_PATH) -lmist
   OBJ += steam/steam.o tasks/task_steam.o
endif

### Shared rich presence code for Discord and Steam

ifeq ($(HAVE_PRESENCE), 1)
   DEFINES += -DHAVE_PRESENCE
   OBJ += network/presence.o
endif

##################################
### Classic Platform specifics ###
###############WIP################
# Help at https://modmyclassic.com

ifeq ($(HAVE_CLASSIC), 1)
  DEFINES += -DHAVE_CLASSIC
endif

ifeq ($(HAVE_C_A7A7), 1)
   C_A7A7_OPT = -Ofast \
                -fno-lto \
                -fdata-sections -ffunction-sections -Wl,--gc-sections \
                -fno-stack-protector -fno-ident -fomit-frame-pointer \
                -falign-functions=1 -falign-jumps=1 -falign-loops=1 \
                -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
                -fmerge-all-constants -fno-math-errno \
                -marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
   DEF_FLAGS += $(C_A7A7_OPT)
   CC_VERSION := $(shell $(CC) -dumpversion)
   ifneq (4.9,$(firstword $(sort $(CC_VERSION) 4.9))) # if version < 4.9
      DEF_FLAGS += -march=armv7-a
   else
      DEF_FLAGS += -march=armv7ve
      # If gcc is 5.0 or later
      ifeq (5,$(firstword $(sort $(CC_VERSION) 5)))
         LDFLAGS += -static-libgcc -static-libstdc++
      endif
   endif
endif

ifeq ($(HAVE_HAKCHI), 1)
   DEFINES += -DHAVE_HAKCHI
endif

ifeq ($(HAVE_SEGAM), 1)
   DEFINES += -DHAVE_SEGAM
endif

ifeq ($(HAVE_ODROIDGO2), 1)
  DEFINES += -DHAVE_ODROIDGO2
  LIBS += -lrga -lpng -lz
  INCLUDE_DIRS += -I$(DEPS_DIR)/libgo2/include
  OBJ += $(DEPS_DIR)/libgo2/src/display.o \
         $(DEPS_DIR)/libgo2/src/queue.o \
         gfx/drivers/oga_gfx.o
endif

ifeq ($(HAVE_GAME_AI),1)
   DEFINES += -DHAVE_GAME_AI
   OBJ += ai/game_ai.o
endif

# Detect the operating system
UNAME := $(shell uname -s)

# Check if the system is MSYS2 (MINGW64 or MINGW32)
ifneq ($(findstring MINGW,$(UNAME)),)
$(info Detected MSYS2 environment)

NT_VERSION := $(shell \
  echo '#include <windows.h>' > temp.c; \
  echo '#ifdef _WIN32_WINNT' >> temp.c; \
  echo '#define GET_MACRO_VALUE(x) #x' >> temp.c; \
  echo '#define EXPAND_MACRO_VALUE(x) GET_MACRO_VALUE(x)' >> temp.c; \
  echo '#pragma message("_WIN32_WINNT=" EXPAND_MACRO_VALUE(_WIN32_WINNT))' >> temp.c; \
  echo '#endif' >> temp.c; \
  $(CC) -c temp.c 2>&1 | sed -n 's/^.*_WIN32_WINNT=\(0x[0-9A-Fa-f]\+\).*/\1/p'; \
  rm -f temp.c temp.o)

ifneq ($(NT_VERSION),)
ifeq ($(shell [ $$(( $(NT_VERSION) )) -gt $$(( 0x602 )) ] && echo true),true)
LIBS += -lxaudio2_9
endif
else
$(warning Windows NT version macro (_WIN32_WINNT) is not defined.)
endif

endif

##################################