summaryrefslogtreecommitdiffstats
path: root/Config.kmk
blob: 687c1c2253e5492f9510ae3e407ccd65fc7b4445 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
# $Id: Config.kmk $
## @file
# The global build configuration file for VBox.
#
# This file gets included by all makefiles through the
# include $(KBUILD_PATH)/header.kmk statement.
#

#
# Copyright (C) 2006-2020 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#

# Marker.
VBOX_ROOT_CONFIG_KMK_INCLUDED = 1


#
# kBuild stuff
#

# Build with umask 022 (requires kBuild r2556 to work, harmless on earlier).
$(set-umask 022)

# Add our own directories to the search paths.
KBUILD_TOOL_PATHS = $(KBUILD_DEVTOOLS)/kBuildTools/
KBUILD_UNIT_PATHS = $(KBUILD_DEVTOOLS)/kBuildUnits/

# Modify the build types.
KBUILD_BLD_TYPES = release profile debug kprofile

## 'strict' builds
# Same as release builds, except that RT_STRICT and VBOX_STRICT are defined,
# meaning all assertions are in action. (Appending means '.strict' props take
# precedence in argument lists.)
KBUILD_BLD_TYPES += strict
BLD_TYPE_strict_EXTENDS = release
BLD_TYPE_strict_EXTENDS_BY = appending

## 'dbgopt' builds
# Same as debug builds, except that compiler optimizations are enabled.  This
# intended for cases where all the debug facitities (logging, assertions, ++)
# is wanted but actual source level debugging as important as execution speed.
KBUILD_BLD_TYPES += dbgopt
BLD_TYPE_dbgopt_EXTENDS = debug
BLD_TYPE_dbgopt_EXTENDS_BY = overriding

# Temporary hack for kBuild ticket #83.
## @todo kBuild: remove after closing ticket #83.
PROPS_ACCUMULATE_L_LNK       += INTERMEDIATES
PROPS_PROGRAMS_ACCUMULATE_L  += INTERMEDIATES
PROPS_LIBRARIES_ACCUMULATE_L += INTERMEDIATES
PROPS_DLLS_ACCUMULATE_L      += INTERMEDIATES
PROPS_SYSMODS_ACCUMULATE_L   += INTERMEDIATES
PROPS_MISCBINS_ACCUMULATE_L  += INTERMEDIATES

# Misc names used by the install paths below.
VBOX_PUEL_MANGLED_NAME := Oracle_VM_VirtualBox_Extension_Pack

# Install paths
## @todo This will change after 4.1 is branched off!
# What is now 'bin' and 'lib' will be moved down under 'staged/', except on
# darwin where it's currently called 'dist' which will be renamed to 'staged'.
# When running 'kmk install' files will be copied to 'dist/', on unix systems
# this will be done in FHS fashion assuming /usr/local or /usr as 'prefix'.
#
# Changes related to this are marked VBOX_WITH_NEW_LAYOUT.
ifndef VBOX_WITH_NEW_LAYOUT
 PATH_INS             = $(PATH_OUT)/dist
 PATH_STAGE           = $(PATH_OUT)
 INST_DEBUG          := stage/debug/
endif

ifeq ($(KBUILD_TARGET),darwin)
 ifndef VBOX_WITH_NEW_LAYOUT
  INST_DIST           = dist/
 else
  INST_DIST          :=
 endif
 INST_SDK             = $(INST_DIST)sdk/

 # the bundles
 INST_VIRTUALBOX      = $(INST_DIST)VirtualBox.app/
 INST_VBOXDRV         = $(INST_DIST)VBoxDrv.kext/
 INST_VBOXNETFLT      = $(INST_DIST)VBoxNetFlt.kext/
 INST_VBOXNETADP      = $(INST_DIST)VBoxNetAdp.kext/
 INST_VBOXUSB         = $(INST_DIST)VBoxUSB.kext/

 # put everything in the VirtualBox app bundle.
 INST_BIN             = $(INST_VIRTUALBOX)Contents/MacOS/
 INST_DLL             = $(INST_BIN)
 INST_SYS             = $(INST_BIN)
 INST_TESTCASE        = $(INST_BIN)testcase/
 INST_ADDITIONS       = $(INST_DIST)additions/
 INST_ADDITIONS_ISO   = $(INST_BIN)
 INST_UNATTENDED_TEMPLATES = $(INST_BIN)UnattendedTemplates/

 INST_VBOXDBG_SYMS    = $(INST_VIRTUALBOX)Contents/Resources/VBoxDbgSyms/

 # other paths
 INST_LIB             = lib/
 INST_ADDITIONS_LIB   = $(INST_LIB)additions/
 VBOX_INST_DTRACE_LIB = $(INST_BIN)dtrace/lib/
 VBOX_INST_DTRACE_TST = $(INST_BIN)dtrace/testcase/
 VBOX_INST_TOOLS      = $(INST_BIN)tools/

else

 INST_BIN             = bin/
 INST_DIST            = $(INST_BIN)
 INST_SDK             = $(INST_BIN)sdk/

 INST_VIRTUALBOX      = $(INST_BIN)
 INST_VBOXDRV         = $(INST_BIN)
 INST_VBOXNETFLT      = $(INST_BIN)
 INST_VBOXNETADP      = $(INST_BIN)
 INST_VBOXUSB         = $(INST_BIN)

 INST_DLL             = $(INST_BIN)
 INST_SYS             = $(INST_BIN)
 INST_TESTCASE        = $(INST_BIN)testcase/
 INST_ADDITIONS       = $(INST_BIN)additions/
 INST_ADDITIONS_ISO   = $(INST_ADDITIONS)
 INST_UNATTENDED_TEMPLATES = $(INST_BIN)UnattendedTemplates/

 INST_LIB             = lib/
 INST_ADDITIONS_LIB   = $(INST_LIB)additions/
 VBOX_INST_DTRACE_LIB = $(INST_BIN)dtrace/lib/
 VBOX_INST_DTRACE_TST = $(INST_BIN)dtrace/testcase/

 INST_VBOXDBG_SYMS    = $(INST_BIN)VBoxDbgSyms/
 VBOX_INST_TOOLS      = $(INST_BIN)tools/
endif


INST_VALIDATIONKIT    = validationkit/
INST_TESTBOXSCRIPT    = testboxscript/

INST_DOC              = doc/
INST_EXTPACK          = $(INST_BIN)ExtensionPacks/
INST_EXTPACK_CERTS    = $(INST_BIN)ExtPackCertificates/
INST_EXTPACK_PUEL     = $(INST_EXTPACK)$(VBOX_PUEL_MANGLED_NAME)/
INST_PACKAGES         = packages/

VBOX_PATH_SDK         = $(patsubst %/,%,$(PATH_STAGE)/$(INST_SDK))
VBOX_PATH_DIST        = $(patsubst %/,%,$(PATH_STAGE)/$(INST_DIST))
VBOX_PATH_VALIDATIONKIT = $(patsubst %/,%,$(PATH_STAGE)/$(INST_VALIDATIONKIT))
VBOX_PATH_ADDITIONS   = $(patsubst %/,%,$(PATH_STAGE)/$(INST_ADDITIONS))
VBOX_PATH_ADDITIONS_ISO = $(patsubst %/,%,$(PATH_STAGE)/$(INST_ADDITIONS_ISO))
VBOX_PATH_ADDITIONS_LIB = $(patsubst %/,%,$(PATH_STAGE)/$(INST_ADDITIONS_LIB))
VBOX_PATH_EXTPACK_PUEL= $(patsubst %/,%,$(PATH_STAGE)/$(INST_EXTPACK_PUEL))
VBOX_PATH_PACKAGES    = $(patsubst %/,%,$(PATH_STAGE)/$(INST_PACKAGES))
VBOX_PATH_TOOLS       = $(patsubst %/,%,$(PATH_STAGE)/$(VBOX_INST_TOOLS))


# Delete targets on failure.
.DELETE_ON_ERROR:

# Notify about important kBuild updates.
if  $(KBUILD_VERSION_MAJOR) == 0 \
 && (   $(KBUILD_VERSION_MINOR) >= 2 \
     || (   $(KBUILD_VERSION_MINOR) == 1 \
         && $(KBUILD_VERSION_PATCH) >= 999))
 VBOX_MIN_KMK_REVISION        := 3093
 VBOX_MIN_KBUILD_KMK_REVISION := $(if-expr "$(KBUILD_HOST)" == "win",3097,$(if-expr "$(KBUILD_HOST).$(KBUILD_HOST_ARCH)" == "solaris.sparc64",2511,3074))
 if $(KMK_REVISION) >= $(VBOX_MIN_KMK_REVISION)
  if $(KBUILD_KMK_REVISION) >= $(VBOX_MIN_KBUILD_KMK_REVISION)
   # OK.
  else
   $(error You must update kBuild! Requires kBuild binaries $(VBOX_MIN_KBUILD_KMK_REVISION) or later, kmk says $(KBUILD_KMK_REVISION) ($(KBUILD_VERSION)))
  endif
 else
  $(error You must update kBuild! Requires kBuild revision $(VBOX_MIN_KMK_REVISION) or later, found $(KMK_REVISION) ($(KBUILD_VERSION)))
 endif
else
 $(error You must update kBuild! Requires 0.1.999 or later, found $(KBUILD_VERSION))
endif

#
# Define USERNAME early on.
#
ifndef USERNAME
 ifdef USER
  USERNAME = $(USER)
 else
  $(warning Warning: You must have USERNAME or USER in your environment.)
 endif
endif

#
# Detect the darwin host version number so we can disable stuff that doesn't
# currently build on Lion.
#
ifeq ($(KBUILD_HOST),darwin)
 VBOX_DARWIN_HOST_VERSION := $(subst ., ,$(shell uname -r))
 VBOX_DARWIN_HOST_VERSION_MAJOR := $(expr $(word 1, $(VBOX_DARWIN_HOST_VERSION)) - 4)
 VBOX_DARWIN_HOST_VERSION_MINOR := $(word 2, $(VBOX_DARWIN_HOST_VERSION))
 VBOX_DARWIN_HOST_VERSION_PATCH := $(word 3, $(VBOX_DARWIN_HOST_VERSION))
 VBOX_DARWIN_HOST_VERSION := 10.$(VBOX_DARWIN_HOST_VERSION_MAJOR).$(VBOX_DARWIN_HOST_VERSION_MINOR)
endif

include $(PATH_ROOT)/Version.kmk

# The raw version string. This *must not* contain any other information/fields than
# major, minor and build revision (as it is now) -- also will be used for host/guest version
# comparison.
VBOX_VERSION_STRING_RAW = $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD)

# VBOX_VERSION_STRING without the publisher.
VBOX_VERSION_STRING_NO_PUB = $(VBOX_VERSION_STRING_RAW)$(addprefix _,$(VBOX_VERSION_PRERELEASE))

# Full version string (may include more than just x.y.z, but no spaces or other problematic chars).
# Note! The BETA[n],ALPHA[n],RC[n] indicators should be inserted before the
#       publisher so that RTStrVersionCompare have a chance of comparing
#       prerelease from different publishers correctly.
VBOX_VERSION_STRING = $(VBOX_VERSION_STRING_NO_PUB)$(VBOX_BUILD_PUBLISHER)


## Make a numeric value from the major, minor and build numbers (params)
VBOX_FULL_VERSION_MAKE = $(expr ($1 << 24) | ($2 << 16) | $3)

## Checks if the current VBox version is higher or equal to the major, minor and
# build numbers given as parameters.
# @returns 1 if true, 0 if false.  For use with 'if'.
VBOX_VERSION_PREREQ = $(expr $(call VBOX_FULL_VERSION_MAKE,$(VBOX_VERSION_MAJOR),$(VBOX_VERSION_MINOR),$(VBOX_VERSION_BUILD)) \
			     >= $(call VBOX_FULL_VERSION_MAKE,$1,$2,$3))


# Force the additions.sh script to get an exact additions build when we're doing the release.
ifeq ($(int-mod $(VBOX_VERSION_BUILD),2),0)
  ifeq ($(VBOX_VERSION_PRERELEASE),)
    VBOX_RELEASE_EXACT_MATCH=1
  endif
endif
ifneq ($(VBOX_RELEASE_EXACT_MATCH),)
 export VBOX_ADDITIONS_SH_MODE     = release
 export VBOX_DOCUMENTATION_SH_MODE = release
 export VBOX_EFI_SH_MODE           = release
 export VBOX_EXTPACKS_SH_MODE      = release
endif

# Some info on the vendor
VBOX_VENDOR       = Oracle Corporation
VBOX_VENDOR_SHORT = Oracle
VBOX_PRODUCT      = Oracle VM VirtualBox
# Not all could be done automatically. Here is a list of known places which
# have to be updated manually, please keep this up to date:
#	src/VBox/Devices/PC/PXE/client/uinit.asm
#	src/VBox/RDP/webclient/flash/com/sun/network/rdp/Version.as
#	src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp
#	src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsLanguage.cpp
#	src/VBox/Frontends/VirtualBox/nls/*.ts
#	debian/control
#	src/VBox/Installer/linux/{debian,rpm}
#	src/VBox/Installer/linux/virtualbox.desktop
#	src/VBox/Additions/WINNT/Installer/ISO/ReadmeDrivers.txt
#	*/*.inf, */*.rc

# Maybe we want set this manually.
VBOX_C_YEAR = $(date-utc %Y)

#
# The VirtualBox package type.
#
ifeq ($(KBUILD_TARGET),win)
  VBOX_PACKAGE_OS = WINDOWS
else ifeq ($(KBUILD_TARGET),linux)
  VBOX_PACKAGE_OS = LINUX
else ifeq ($(KBUILD_TARGET),darwin)
  VBOX_PACKAGE_OS = DARWIN
else ifeq ($(KBUILD_TARGET),solaris)
  VBOX_PACKAGE_OS = SOLARIS
else ifeq ($(KBUILD_TARGET),os2)
  VBOX_PACKAGE_OS = OS2
else ifeq ($(KBUILD_TARGET),haiku)
  VBOX_PACKAGE_OS = HAIKU
else if1of ($(KBUILD_TARGET), dragonfly freebsd netbsd openbsd)
  VBOX_PACKAGE_OS = BSD
else
  $(error Cannot determine VBOX_PACKAGE_OS)
endif
ifeq ($(KBUILD_TARGET_ARCH),x86)
  VBOX_PACKAGE_ARCH = 32BITS
else
  VBOX_PACKAGE_ARCH = 64BITS
endif
# distribution, mostly for Linux/Solaris where we support different distributions
# this strip will be overridden by the Linux packaging scripts
VBOX_PACKAGE_DIST ?= GENERIC
# Full string
VBOX_PACKAGE_STRING = $(VBOX_PACKAGE_OS)_$(VBOX_PACKAGE_ARCH)_$(VBOX_PACKAGE_DIST)

# Supported VirtualBox host architectures.
VBOX_SUPPORTED_HOST_ARCHS := amd64

#
# The VirtualBox Configuration Defaults.
#
# We try to document all the build configuration options here, thing which
# aren't enabled by default is left commented out just to show that they
# exist and which value they should have (usually 1, but anyway).
#

# Select new Xcode based on host OS X version.
ifeq ($(KBUILD_HOST),darwin)
 if !defined(VBOX_WITH_NEW_XCODE) && !defined(VBOX_WITHOUT_NEW_XCODE) && $(KBUILD_HOST_VERSION_MAJOR) >= 13 # (OS X 10.9 Mavericks)
  VBOX_WITH_NEW_XCODE = 1
 endif
endif

## @name Additions
## @{
# This indicates that additions (of some kind or another) is being _built_.
# VBOX_WITHOUT_ADDITIONS overrides it.
VBOX_WITH_ADDITIONS = 1
# Build the optional ring-0 part of the additions for syntax checking.
# On linux we build this as a test case instead.
ifneq ($(KBUILD_TARGET), linux)
 VBOX_WITH_ADDITION_DRIVERS = 1
endif
# Build X11 additions. Can be disabled separately.
if1of ($(KBUILD_TARGET), dragonfly freebsd linux netbsd openbsd solaris)
 VBOX_WITH_X11_ADDITIONS = 1
endif
# Enable the building of shared folders in the windows additions.
VBOX_WITH_WIN32_ADDITIONS_SHAREDFOLDERS = 1
# Take the binaries of the OS/2 Additions.
VBOX_WITH_OS2_ADDITIONS_BIN = 1
# Use additions from the build server.
#VBOX_WITH_ADDITIONS_FROM_BUILD_SERVER = 1
# Include additions in the package
VBOX_WITH_ADDITIONS_PACKING = 1
# Only build the additions (for the additions build server).
#VBOX_ONLY_ADDITIONS = 1
ifdef VBOX_ADDITIONS_ONLY # typical mistake.
 $(error It is VBOX_ONLY_ADDITIONS=1 not VBOX_ADDITIONS_ONLY!)
endif
# Don't bother with additions, overrides VBOX_WITH_ADDITIONS.
# This is not used by makefiles, only Config.kmk, see below.
ifdef VBOX_ONLY_SDK
 VBOX_WITHOUT_ADDITIONS = 1
endif
# Don't create the additions ISO.
# (Used by the additions build server, don't invert it.)
#VBOX_WITHOUT_ADDITIONS_ISO = 1
## @}
# Set build options right for building the Additions as an RPM package.
# VBOX_ONLY_RPM_ADDITIONS = 1
ifdef VBOX_ONLY_RPM_ADDITIONS
 VBOX_ONLY_ADDITIONS=1
 VBOX_ONLY_ADDITIONS_WITHOUT_RTISOMAKER=1
 # We build the RPMs using public sources.
 VBOX_OSE=1
 # We want to re-use parts of the packing pass, but not all.
 VBOX_WITHOUT_LINUX_GUEST_PACKAGE=1
 VBOX_WITHOUT_ADDITIONS_ISO=1
endif

## @name Documentation
## @{
# The documentation
VBOX_WITH_DOCS = 1
# Use documentation from the build server.
#VBOX_WITH_DOCS_FROM_BUILD_SERVER = 1
# Include documentation in the package
VBOX_WITH_DOCS_PACKING = 1
# Include CHM when building docs (unset in LocalConfig.kmk to suppress CHM)
if1of ($(KBUILD_TARGET), win)
 VBOX_WITH_DOCS_CHM = 1
endif
# By default only include translations in documentation-only builds
ifdef VBOX_ONLY_DOCS
 ifndef VBOX_NO_DOCS_TRANSLATIONS
  VBOX_WITH_DOCS_TRANSLATIONS = 1
 endif
endif
# Default languages
VBOX_MANUAL_LANGUAGES = en_US
ifdef VBOX_WITH_DOCS_TRANSLATIONS
 VBOX_MANUAL_ADD_LANGUAGES = fr_FR
endif
# Don't bother with documentation, overrides VBOX_WITH_DOCS.
# This is not used by makefiles, only Config.kmk, see below.
#VBOX_WITHOUT_DOCS = 1
# Only build the documentation (for the documentation build server).
#VBOX_ONLY_DOCS = 1
ifdef VBOX_DOCS_ONLY # typical mistake.
 $(error It is VBOX_ONLY_DOCS=1 not VBOX_DOCS_ONLY!)
endif
## @}

## @name VMM related settings.
## @{
# Enable safe STR (store task register) emulation for raw-mode.
VBOX_WITH_SAFE_STR = 1
# Enable support for 64-bit guests.
VBOX_WITH_64_BITS_GUESTS = 1
# Enable multi-core VCPUs.
VBOX_WITH_MULTI_CORE = 1
# Activate this to force the VM to pre-allocate the guest RAM before startup
VBOX_WITH_PREALLOC_RAM_BY_DEFAULT =
# Enable the debugger.
VBOX_WITH_DEBUGGER = 1
# Enable the debugger GUI.
VBOX_WITH_DEBUGGER_GUI = 1
# Enables the third step using IEM (the interpreter).
VBOX_WITH_3RD_IEM_STEP = 1
# Nested hardware virtualization (64-bit hosts only).
ifeq ($(KBUILD_TARGET_ARCH),amd64)
 # Enables SVM nested hardware virtualization support.
 VBOX_WITH_NESTED_HWVIRT_SVM = 1
 # Enables VMX nested hardware virtualization support.
 VBOX_WITH_NESTED_HWVIRT_VMX = 1
 # Enables nested hardware virtualization support but only in IEM.
 #VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM = 1
 ifdef VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM
  if !defined(VBOX_WITH_NESTED_HWVIRT_SVM) && !defined(VBOX_WITH_NESTED_HWVIRT_VMX)
   $(error VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM defined without enabling nested VMX or nested SVM support)
  endif
 endif
endif
# Enable native NEM on windows.
if1of ($(KBUILD_TARGET), win)
 VBOX_WITH_NATIVE_NEM = 1
endif
# Enables mapping guest RAM into host kernel space.
if1of ($(KBUILD_TARGET), darwin linux solaris win)
 VBOX_WITH_RAM_IN_KERNEL := 1
endif
## @}


## @name Devices, Drivers, ...
## @{
# Build the Host Guest Communication Manager component.
VBOX_WITH_HGCM = 1
## Build the bugcheck detection code.
#VBOX_WITH_GUEST_BUGCHECK_DETECTION =
# Enable the USB feature. This includes VBOX_WITH_VUSB!
VBOX_WITH_USB = 1
# Enable the USB 1.1 controller plus virtual USB HID devices.
VBOX_WITH_VUSB = 1
# Enable the USB 2.0 controller.
VBOX_WITH_EHCI = 1
# Enable the ISCSI feature.
VBOX_WITH_ISCSI = 1
# Enable INIP support in the ISCSI feature.
VBOX_WITH_INIP = 1
# Enables lwip as a core of NAT service
VBOX_WITH_LWIP_NAT = 1
# Enables compilation of NAT service
VBOX_WITH_NAT_SERVICE = 1
# Enable the E1000 feature.
VBOX_WITH_E1000 = 1
# Enable the Virtio feature.
VBOX_WITH_VIRTIO = 1
# Enable the Virtio SCSI device.
VBOX_WITH_VIRTIO_SCSI = 1
# HDA emulation is Intel HDA by default.
VBOX_WITH_INTEL_HDA = 1
ifn1of ($(KBUILD_TARGET), win darwin)
 # Enable OSS audio support.
 VBOX_WITH_AUDIO_OSS = 1
endif
if1of ($(KBUILD_TARGET), linux)
 # Enable ALSA audio support.
 VBOX_WITH_AUDIO_ALSA = 1
endif
if1of ($(KBUILD_TARGET), linux)
 # Enable PulseAudio audio support.
 VBOX_WITH_AUDIO_PULSE = 1
endif
# Enable building debugging backend.
# Only will be used at runtime when "VBoxInternal2/Audio/Debug/Enabled" (VM / global) is set.
VBOX_WITH_AUDIO_DEBUG = 1
ifdef VBOX_WITH_VALIDATIONKIT ## @todo r=bird: test is too early!
 VBOX_WITH_AUDIO_VALIDATIONKIT = 1
endif
# Enables the audio endpoint detection on Windows hosts.
VBOX_WITH_AUDIO_MMNOTIFICATION_CLIENT = 1
# Enable PCI passthrough support.
# (disabled with 6.1, since it's not complete/useful enough)
VBOX_WITH_PCI_PASSTHROUGH =
# Enable statically linked dbus support.
if1of ($(KBUILD_TARGET), linux solaris)
 VBOX_WITH_DBUS = 1
endif
# Enable building PAM modules.
if1of ($(KBUILD_TARGET), linux solaris)
 VBOX_WITH_PAM = 1
endif
# Enable internal networking.
VBOX_WITH_INTERNAL_NETWORKING = 1
# Enable vmsvga (svga2) graphics device variant, 2D part
VBOX_WITH_VMSVGA = 1
# Enable vmsvga (svga2) graphics device variant, 3D part
if1of ($(KBUILD_TARGET), darwin linux win)
 VBOX_WITH_VMSVGA3D = 1
endif
# Enable the generic 3D settings support if at least one 3D capable solution is enabled
ifdef VBOX_WITH_VMSVGA3D
 VBOX_WITH_3D_ACCELERATION = 1
endif
# Enable Host Guest Shared Memory Interface.
VBOX_WITH_HGSMI = 1
# Enable Video 2D Acceleration.
if1of ($(KBUILD_TARGET), darwin linux win freebsd)
 VBOX_WITH_VIDEOHWACCEL = 1
endif
# Enable Wddm Video driver for Vista+ guests.
VBOX_WITH_WDDM = 1
# Lazy developer!!
VBOXWDDM_WITH_VBVA = 1
# Lazy developer!!
ifdef VBOX_WITH_WDDM
 VBOX_WITH_VDMA = 1
else ifdef VBOX_WITH_VDMA
  undef VBOX_WITH_VDMA
endif
# Gallium based WDDM driver
if1of ($(KBUILD_TARGET), win)
 VBOX_WITH_MESA3D = 1
endif
# Disable the Intel PXE ROM (uses Etherboot).
VBOX_WITH_INTEL_PXE =
# Enable EFI support
VBOX_WITH_EFI = 1
# Embed the EFI firmwares in VBoxDD2.dll/dylib/so.
VBOX_WITH_EFI_IN_DD2 = 1
# Fetch EFI firmware image from the build server
#VBOX_WITH_EFIFW_FROM_BUILD_SERVER = 1
# Include the EFI firmware into the package
ifndef VBOX_WITH_EFI_IN_DD2
 VBOX_WITH_EFIFW_PACKING = 1
endif
# Enable setuid wrapper for Solaris host DVD.
#VBOX_WITH_SUID_WRAPPER = 1
# Enable the virtual SATA/AHCI controller
VBOX_WITH_AHCI = 1
# Enable the new async completion manager
VBOX_WITH_PDM_ASYNC_COMPLETION = 1
ifdef VBOX_WITH_USB
 VBOX_WITH_VUSB = 1
 VBOX_WITH_XHCI_IMPL=1
endif
ifdef VBOX_WITH_EHCI
 VBOX_WITH_EHCI_IMPL = 1
endif
ifdef VBOX_WITH_PCI_PASSTHROUGH
 ## @bugref{9218}: Disabled awaiting conversion of the device to new PDM device style.
 #VBOX_WITH_PCI_PASSTHROUGH_IMPL = 1
endif
ifndef VBOX_WITHOUT_HOSTWEBCAM
 VBOX_WITH_USB_VIDEO_IMPL = 1
endif
# Enable the hal/sysfs USB code on Linux.
ifeq ($(KBUILD_TARGET),linux)
 VBOX_USB_WITH_SYSFS = 1
 # Disabled for now
 # VBOX_USB_WITH_DBUS = 1
 VBOX_USB_WITH_INOTIFY = 1
endif
# Enable performance API.
VBOX_WITH_RESOURCE_USAGE_API = 1
# Use VBoxVolInfo for getting FS dependecies.
if1of ($(KBUILD_TARGET), linux)
 VBOX_WITH_DEVMAPPER = 1
endif
# Enable unattended installation API
VBOX_WITH_UNATTENDED = 1
# Enable BusLogic SCSI host adapter
VBOX_WITH_BUSLOGIC = 1
# Enable LsiLogic SCSI host adapter
VBOX_WITH_LSILOGIC = 1
# Enable SCSI drivers
VBOX_WITH_SCSI = 1
# Enable this setting to force a fallback to default DMI data on configuration errors
VBOX_BIOS_DMI_FALLBACK =
# Enable the builtin PXE ROM
VBOX_WITH_PXE_ROM = 1
# Enable MSI support in devices
VBOX_WITH_MSI_DEVICES = 1
# Enable host network interface API.
if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
 VBOX_WITH_HOSTNETIF_API = 1
endif
# Emulated USB smart card reader
VBOX_WITH_USB_CARDREADER = 1
# Disk crypt plugin
VBOX_WITH_PLUGIN_CRYPT = 1
# Make disk crypt plugin use IPRT for crypto.
VD_WITH_IPRT_CRYPTO = 1
# VirtualKD stub/loader device, only relevant on Windows host
VBOX_WITH_VIRTUALKD = 1
# NVMe device emulation
VBOX_WITH_NVME_IMPL = 1
# Storage related debug drivers
VBOX_WITH_DRV_DISK_INTEGRITY = 1
# Enables new LPC device implementation.
VBOX_WITH_NEW_LPC_DEVICE = 1
# Enables the new serial port implementation
VBOX_WITH_NEW_SERIAL = 1
## @}

# legacy
ifdef VBOX_ONLY_TESTSUITE
 $(warning VBOX_ONLY_TESTSUITE was renamed to VBOX_ONLY_VALIDATIONKIT)
 VBOX_ONLY_VALIDATIONKIT = $(VBOX_ONLY_TESTSUITE)
endif

## @name Other Component
## @{
# Build the installer.
VBOX_WITH_INSTALLER = 1
VBOX_WITH_GUEST_INSTALLER_UNICODE = 1
# The kernel driver/module and related runtime libraries.
# On Linux we build this as a test case instead.
ifneq ($(KBUILD_TARGET), linux)
 VBOX_WITH_VBOXDRV = 1
endif
# The main api.
VBOX_WITH_MAIN = 1
# Enables proxy stub for MS COM (speeds up setting IPC for objects).
# (The VBOX_MIDL_PROXY_CLSID and VBOX_MIDL_PROXY_CLSID_IS are just two
#  representations of the class ID for the proxy stub.)
VBOX_WITH_MIDL_PROXY_STUB = 1
VBOX_MIDL_PROXY_CLSID    := {0bb3b78c-1807-4249-5ba5-ea42d66af0bf}
VBOX_MIDL_PROXY_CLSID_IS := {0x0bb3b78c,0x1807,0x4249,{0x5b,0xa5,0xea,0x42,0xd6,0x6a,0xf0,0xbf}}
# Whether to also ship 32-bit main API on 64-bit systems.
if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), solaris.amd64 win.amd64)
 if !defined(VBOX_ONLY_VALIDATIONKIT) && !defined(VBOX_ONLY_ADDITIONS) && !defined(VBOX_ONLY_DOCS) && !defined(VBOX_ONLY_EXTPACKS)
  VBOX_WITH_32_ON_64_MAIN_API = 1
 endif
endif
# Whether to generate a database of USB vendor IDs and device IDs into VBoxSVC.
VBOX_WITH_MAIN_USB_ID_DATABASE = 1
## The recompiler - Dropped in 6.1.
#if !defined(VBOX_WITH_NEW_XCODE) || "$(KBUILD_TARGET)" != "darwin"
# VBOX_WITH_REM = 1
#endif
# Set this to prefix all C symbols in XPCOM, to avoid dynamic linking problems
# caused by our XPCOM library polluting the symbol namespace for system libs.
if1of ($(KBUILD_TARGET), linux solaris)
 VBOX_WITH_XPCOM_NAMESPACE_CLEANUP = 1
endif
# The webservices api.
VBOX_WITH_WEBSERVICES = 1
VBOX_WITH_WEBSERVICES_SSL = 1
# The Qt GUI.
VBOX_WITH_QTGUI = 1
# Indicates the Qt is Cocoa based on the Mac.
ifeq ($(KBUILD_TARGET),darwin)
 VBOX_WITH_COCOA_QT = 1
endif
# VBox Ballooning Control frontend.
VBOX_WITH_FE_BALLOONCTRL = 1
# VBox Autostart Service.
VBOX_WITH_FE_AUTOSTART = 1
# VBox Bug Report tool.
VBOX_WITH_FE_BUGREPORT = 1
# The SDL based GUI.
VBOX_WITH_VBOXSDL = 1
# Build VBoxSDL with secure label support.
ifeq ($(filter win.amd64,$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)),) # too much work with freetype and all that.
VBOX_WITH_SECURELABEL = 1
endif
# The headless frontend.
VBOX_WITH_HEADLESS = 1
# Enable the build of VRDP server.
VBOX_WITH_VRDP = 1
# Build the VRDP authentication modules.
VBOX_WITH_VRDP_AUTHMOD = 1
# Build enhanced version of rdesktop.
VBOX_WITH_VRDP_RDESKTOP = 1
# Make VRDP use IPRT for SSL.
VRDP_WITH_IPRT_SSL = 1
# Make VRDP use IPRT for crypto.
VRDP_WITH_IPRT_CRYPTO = 1
## The Direct Framebuffer GUI.
#VBOX_WITH_VBOXFB = 1
# Enables the Python<->XPCOM, Python<->COM and (WS enabled) Python<->WS bindings.
VBOX_WITH_PYTHON ?= 1
# Enables the PERL<->WS binding (if WS enabled).
#VBOX_WITH_PERL ?= 1
# Enables the PHP<->WS binding (if WS enabled).
VBOX_WITH_PHP ?= 1
if1of ($(KBUILD_TARGET), darwin linux solaris)
 # Enable Java<->XPCOM bridge + glue code
 VBOX_WITH_JXPCOM ?= 1
endif
if1of ($(KBUILD_TARGET), )
 # Enable Java<->MSCOM glue, bridge is provided by an external lib (Jacob)
 VBOX_WITH_JMSCOM ?= 1
endif
if1of ($(KBUILD_TARGET), darwin linux solaris)
 # Enable Java<->JAX-WS bridge
 VBOX_WITH_JWS ?= 1
endif
# Use XPIDL instead of XSLT stylesheet
VBOX_WITH_JAVA_SUPPORT_IN_XPIDL ?=
# Build against multiple Python versions present in the system
VBOX_WITH_MULTIVERSION_PYTHON ?= 1
# Enable the kchmviewer.
VBOX_WITH_KCHMVIEWER = 1
# Build the Validation Kit.
VBOX_WITH_VALIDATIONKIT = 1
# Build the testcases.
VBOX_WITH_TESTCASES = 1
# Enable this to build vditool even if VBOX_WITH_TESTCASES is disabled
VBOX_WITH_VDITOOL =
# Enable this to build vbox-img even if VBOX_WITH_TESTCASES is disabled
VBOX_WITH_VBOX_IMG =
# Enables recording support.
VBOX_WITH_RECORDING = 1
# Enable VPX (VP8 / VP9 codec), required for video capturing.
VBOX_WITH_LIBVPX = 1
# Enables audio support for recording (depends on VBOX_WITH_RECORDING).
VBOX_WITH_AUDIO_RECORDING = 1
# Enables libopus (Opus), required for encoding audio into the recorded data.
VBOX_WITH_LIBOPUS = 1
# Enable SEE (+ AVX) optimizations for Opus.
VBOX_WITH_OPUS_SSE = 1
# Enable shared folders
VBOX_WITH_SHARED_FOLDERS = 1
# Enable shared clipboard
VBOX_WITH_SHARED_CLIPBOARD = 1
# Enable shared clipboard (file) transfers
#if1of ($(KBUILD_TARGET), win linux)
# VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS = 1
#endif
# Enable the host/guest information service (aka guest properties).
VBOX_WITH_GUEST_PROPS = 1
# Enable this to prevent the guest from writing guest properties.
VBOX_WITH_GUEST_PROPS_RDONLY_GUEST =
# Compile the host channel
VBOX_WITH_HOST_CHANNEL = 1
# Enable the guest control service.
if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
 VBOX_WITH_GUEST_CONTROL = 1
endif
# Enable ballooning
VBOX_WITH_MEMBALLOON = 1
# Enable cURL (required for the network part of the GUI)
VBOX_WITH_LIBCURL = 1
# Enable Host=>Guest Drag'n'Drop
if1of ($(KBUILD_TARGET), darwin linux solaris win)
 VBOX_WITH_DRAG_AND_DROP = 1
 if1of ($(KBUILD_TARGET), darwin linux solaris win)
  VBOX_WITH_DRAG_AND_DROP_GH = $(VBOX_WITH_DRAG_AND_DROP)
 endif
 ifdef VBOX_WITH_DRAG_AND_DROP_GH
  ifeq ($(KBUILD_TARGET),darwin)
   # On OS X (Darwin) this needs to be set in order to get proper
   # guest->host support.
   # Note: Setting this requires Qt also having this feature enabled!
   VBOX_WITH_DRAG_AND_DROP_PROMISES = $(VBOX_WITH_DRAG_AND_DROP)
  endif
 endif
endif
# Enable audio support for VRDE.
VBOX_WITH_AUDIO_VRDE = 1
# Use the VRDE external authentication library from VBoxSVC.
if1of ($(KBUILD_TARGET), win)
 VBOX_WITH_VRDEAUTH_IN_VBOXSVC = 1
endif
# Enables use of merge modules in the windows installer. This will increase
# the overall installer size significantly because merge modules are not able
# to use a common .cab file to reduce their size.
#VBOX_WITH_MSM_INSTALL = 1
## @}


## @name Networking
## @{
# Use VBoxNetFlt for host interface networking.
if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
 VBOX_WITH_NETFLT = 1
 ifeq ($(KBUILD_TARGET),solaris)
  # requires snv_159+.
  VBOX_WITH_NETFLT_CROSSBOW = 1
 endif
 # Use VBoxNetAdp for host only networking.
 if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
  VBOX_WITH_NETADP = 1
 endif
endif
# Enables the UDP tunnel transport.
VBOX_WITH_UDPTUNNEL = 1
# Enable the netshaper support
VBOX_WITH_NETSHAPER = 1
# Enable Virtual Distributed Ethernet or not.
if1of ($(KBUILD_TARGET), freebsd linux)
 VBOX_WITH_VDE = 1
endif
# Use new VBoxNetDhcpd instead of old VBoxNetDHCP
VBOX_WITH_DHCPD = 1
# Experimental suport for cloud network integration
VBOX_WITH_CLOUD_NET = 1
## @}


## @name Extension pack
## @{
# Enables the extension pack feature.
VBOX_WITH_EXTPACK = 1
# Enables separating code into the Oracle VM VirtualBox Extension Pack, dubbed PUEL.
VBOX_WITH_EXTPACK_PUEL = 1
# Enables building+packing the Oracle VM VirtualBox Extension Pack, includes VBOX_WITH_EXTPACK_PUEL
VBOX_WITH_EXTPACK_PUEL_BUILD = 1
# Enable the BusMouse sample extension pack.
#VBOX_WITH_EXTPACK_BUSMOUSESAMPLE = 1
# Enable the VNC server extension pack (GPL only).
#VBOX_WITH_EXTPACK_VNC = 1
# Enables the VBoxDTrace extension pack.
VBOX_WITH_EXTPACK_VBOXDTRACE = 1
## @}

## @name Misc
## @{
# Enable to compile with OpenSSL 1.0 (only relevant for Windows, see src/VBox/Runtime/Makefile.kmk)
#VBOX_WITH_OPENSSL_PRE_1_1 = 1
# Enables all the doxgen bits.
VBOX_WITH_ALL_DOXYGEN_TARGETS = 1
# Set this to skip installing the redistributable compiler runtime.
#VBOX_WITHOUT_COMPILER_REDIST = 1
# Enables VMMR0.r0 (++) loading using the native loader on solaris.
# Good for debugging and analysis.  Experimental.
#VBOX_WITH_NATIVE_SOLARIS_LOADING = 1
# Set this to enable user mode dtrace probes.
if1of ($(KBUILD_TARGET), darwin linux solaris)
 VBOX_WITH_DTRACE_R3 = 1
 VBOX_WITH_DTRACE_R3_MAIN = 1
endif
# Set this to enable kernel driver dtrace probes.
if1of ($(KBUILD_TARGET), darwin solaris)
 VBOX_WITH_DTRACE_R0DRV = 1
endif
# Set this to enable dtrace probes in platform agnostic kernel code.
ifn1of ($(KBUILD_TARGET), os2)
 VBOX_WITH_DTRACE_R0 = 1
endif
# Set this to enable dtrace probes raw-mode context code.
if1of ($(KBUILD_TARGET), linux solaris)
 VBOX_WITH_DTRACE_RC = 1
endif
# Set this to enable support for dtrace probes in guest code.
#VBOX_WITH_DTRACE_GST = 1
# Set this to indicate that the host ships with DTrace.
if1of ($(KBUILD_TARGET), darwin solaris)
 VBOX_WITH_NATIVE_DTRACE = 1
endif
# Makes it possible to run some of the testcases and tools on older
# windows versions (only define when buildling win.x86).
#VBOX_WITH_MORE_NT4_COMPAT_BINARIES = 1
# Set this to enable building of the vboximg-mount FUSE mounting utility.
if1of ($(KBUILD_TARGET), darwin linux)
 VBOX_WITH_VBOXIMGMOUNT = 1
endif
# Set this to enable packaging the fuse related bits into our installer.
if1of ($(KBUILD_TARGET), darwin)
 VBOX_WITH_FUSE_PACKING = 1
endif
## @}


## @name Compiler and linker config
## @{
# For treating compiler and linker warnings as errors where possible.
if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), darwin.x86 darwin.amd64 linux.x86 linux.amd64 win.x86 win.amd64)
 VBOX_WITH_WARNINGS_AS_ERRORS = 1
endif
# Whether we can use Open Watcom to build stuff.
if1of ($(KBUILD_TARGET), darwin linux os2 win)
 VBOX_WITH_OPEN_WATCOM = 1
endif
## @}


## @name Hardening
## @{
# Enables hardening.
# Most developers will want to disable this in their LocalConfig.kmk.
VBOX_WITH_HARDENING = 1
# Where the application files are (going to be) installed.
#VBOX_PATH_APP_PRIVATE       = /usr/lib/virtualbox
ifdef VBOX_WITH_HARDENING
 if1of ($(KBUILD_TARGET), linux solaris)
  VBOX_PATH_APP_PRIVATE      = /opt/VirtualBox
 else ifeq ($(KBUILD_TARGET),darwin)
  VBOX_PATH_APP_PRIVATE      = /Applications/VirtualBox.app/Contents/MacOS
 else ifeq ($(KBUILD_TARGET),freebsd)
  VBOX_PATH_APP_PRIVATE      = /usr/local/lib/virtualbox
 else ifeq ($(KBUILD_TARGET),haiku)
  VBOX_PATH_APP_PRIVATE      = /boot/system/apps/VirtualBox
 endif
endif
# Where the architecture specific application files are (going to be) installed.
#VBOX_PATH_APP_PRIVATE_ARCH  = /usr/lib/virtualbox
ifdef VBOX_WITH_HARDENING
 if1of ($(KBUILD_TARGET), solaris)
  VBOX_PATH_APP_PRIVATE_ARCH_TOP = $(VBOX_PATH_APP_PRIVATE)
  VBOX_PATH_APP_PRIVATE_ARCH = $(VBOX_PATH_APP_PRIVATE_ARCH_TOP)/$(if-expr $(KBUILD_TARGET_ARCH) == "amd64",amd64,i386)
 else ifdef VBOX_PATH_APP_PRIVATE
  VBOX_PATH_APP_PRIVATE_ARCH = $(VBOX_PATH_APP_PRIVATE)
 endif
endif
# Where the shared libraries are (going to be) installed.
#VBOX_PATH_SHARED_LIBS       = /usr/lib
ifdef VBOX_WITH_HARDENING
 if1of ($(KBUILD_TARGET), solaris)
  VBOX_PATH_SHARED_LIBS      = $(VBOX_PATH_APP_PRIVATE)/$(if-expr $(KBUILD_TARGET_ARCH) == "amd64",amd64,i386)
 else ifdef VBOX_PATH_APP_PRIVATE
  VBOX_PATH_SHARED_LIBS      = $(VBOX_PATH_APP_PRIVATE)
 endif
endif
# Where the documentation is (going to be) installed.
#VBOX_PATH_APP_DOCS         = /usr/share/doc/virtualbox
ifdef VBOX_WITH_HARDENING
 ifdef VBOX_PATH_APP_PRIVATE
  VBOX_PATH_APP_DOCS         = $(VBOX_PATH_APP_PRIVATE)
 endif
endif
# The DT_RPATH/DT_RUNPATH to embed into the binaries (ELF).
# (This one is used for all binaries, there is no need to adjust this
# depending on the location of the object.)
#VBOX_WITH_RUNPATH = /usr/lib/virtualbox
ifdef VBOX_WITH_HARDENING
 if1of ($(KBUILD_TARGET), solaris)
  VBOX_WITH_RUNPATH = $(VBOX_PATH_APP_PRIVATE)/$(if-expr $(KBUILD_TARGET_ARCH) == "amd64",amd64,i386)
 else if1of ($(KBUILD_TARGET), freebsd linux)
  VBOX_WITH_RUNPATH = $(VBOX_PATH_APP_PRIVATE)
 endif
endif
# Enable use of the $ORIGIN DT_RPATH/DT_RUNPATH feature (ELF).
# Because of the setuid usage on all ELF platforms when hardening the build
# things gets a bit complicated since the $ORIGIN+setuid policy differs.
#VBOX_WITH_ORIGIN = 1
ifndef VBOX_WITH_HARDENING
 if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd solaris) # duplicated further down
  VBOX_WITH_ORIGIN = 1
 endif
endif
# Enable the system wide support service/daemon.
# Very sketchy work in progress.
#VBOX_WITH_SUPSVC = 1

# Continue to support Vista w/o any service pack, at least for now.
VBOX_WITH_VISTA_NO_SP = 1
# Enable image verification on darwin @bugref{9232}.
VBOX_WITH_DARWIN_R0_DARWIN_IMAGE_VERIFICATION = 1
## @}


# Strip binaries of release and profile builds before packing them into the installer
# archive. When building .deb/.rpms, don't strip the symbols as they are required for
# the debug packages containing symbols for gdb located in /usr/lib/debug.
# In rpm Additions we also need to do part of packing without strip.
ifndef VBOX_ONLY_RPM_ADDITIONS
 VBOX_DO_STRIP := $(if $(filter release profile,$(KBUILD_TYPE)),1,)
endif


#
# Config items for enabling work in progress.
#
# It's good pratice to add stuff here even if it is currently disabled by
# default.
#
# Note! Please, do *not* add stuff to the global DEFS unless it is *really*
#       necessary!  The other guys will hate for it you when they have to
#       recompile everything when the feature is enabled or disabled.  Put
#       the ifdefs in target or template definitions.
#

# Mask all Local APIC interrupt vectors which are set up to NMI mode when switching
# to/from the guest in raw mode. Modern Linux kernels use the performance counter
# to raise an NMI from time to time.
if1of ($(KBUILD_TARGET), linux)
 VBOX_WITH_VMMR0_DISABLE_LAPIC_NMI = 1
endif
## For testing deadlock detection and lock order validation.
# If issues are found, create high priority defects and temporarily comment
# the next line.
VBOX_WITH_STRICT_LOCKS = 1
## VBoxSDS is the bridge windows service that sits between
# VirtualBox object client and VBoxSVC that fixes problem
# when multiple VBoxSVC starts for the same user
# it is enabled for windows build only
ifeq  ($(KBUILD_TARGET),win)
 VBOX_WITH_SDS = 1
endif


#
# Branding
#
VBOX_BRAND_BIOS_LOGO                 := $(PATH_ROOT)/src/VBox/Devices/Graphics/BIOS/puel_logo.bmp
VBOX_BRAND_LICENSE_HTML              := $(PATH_ROOT)/doc/License-gpl-2.0.html
VBOX_BRAND_LICENSE_RTF               := $(PATH_ROOT)/doc/License-gpl-2.0.rtf
VBOX_BRAND_LICENSE_TXT               := $(PATH_ROOT)/doc/License-gpl-2.0.txt
VBOX_BRAND_LICENSE_VER               :=
VBOX_BRAND_GUI_ABOUT_PNG             := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/about.png
VBOX_BRAND_GUI_ABOUT_X2_PNG          := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/about_x2.png
VBOX_BRAND_GUI_ABOUT_X3_PNG          := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/about_x3.png
VBOX_BRAND_GUI_ABOUT_X4_PNG          := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/about_x4.png
VBOX_BRAND_GUI_ABOUT_16PX_PNG        := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/about_16px.png
VBOX_BRAND_GUI_ABOUT_16PX_X2_PNG     := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/about_16px_x2.png
VBOX_BRAND_GUI_ABOUT_16PX_X3_PNG     := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/about_16px_x3.png
VBOX_BRAND_GUI_ABOUT_16PX_X4_PNG     := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/about_16px_x4.png
VBOX_BRAND_GUI_VBOX_16PX_PNG         := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/VirtualBox_16px.png
VBOX_BRAND_GUI_VBOX_20PX_PNG         := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/VirtualBox_20px.png
VBOX_BRAND_GUI_VBOX_32PX_PNG         := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/VirtualBox_32px.png
VBOX_BRAND_GUI_VBOX_40PX_PNG         := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/VirtualBox_40px.png
VBOX_BRAND_GUI_VBOX_48PX_PNG         := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/VirtualBox_48px.png
VBOX_BRAND_GUI_VBOX_64PX_PNG         := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/NonOSE/VirtualBox_64px.png
VBOX_BRAND_GUI_VBOX_SVG              := $(PATH_ROOT)/src/VBox/Artwork/NonOSE/virtualbox.svg
VBOX_BRAND_WIN_INST_DLGJPG           := $(PATH_ROOT)/src/VBox/Installer/win/Binary/Dialog.jpg
VBOX_BRAND_WIN_INST_EXT              :=
VBOX_BRAND_WIN_ADD_INST_DLGBMP       := $(PATH_ROOT)/src/VBox/Additions/WINNT/Installer/welcome.bmp
VBOX_BRAND_DARWIN_DISKIMAGE_DS_STORE := $(PATH_ROOT)/src/VBox/Installer/darwin/DiskImage/DS_Store
VBOX_BRAND_DARWIN_DISKIMAGE_BG       := $(PATH_ROOT)/src/VBox/Installer/darwin/DiskImage/vbox_folder.tiff
VBOX_BRAND_DARWIN_INSTALLER_BG       := $(PATH_ROOT)/src/VBox/Installer/darwin/VirtualBox_mpkg/background.tif

#
# Skip stuff.
#

ifdef VBOX_ONLY_EXTPACKS
 # Clear some VBOX_WITH_XXX variables instead of adding ifdefs all over the place.
 VBOX_WITH_DEBUGGER =
 VBOX_WITH_ADDITIONS =
 VBOX_WITH_VBOXDRV =
 VBOX_WITH_TESTCASES =
endif

# VBOX_QUICK can be used by core developers to speed to the build
ifdef VBOX_QUICK
 # undefine variables by assigning blank.
 VBOX_WITH_ADDITIONS=
 VBOX_WITH_VALIDATIONKIT=
 VBOX_WITH_TESTCASES=
 VBOX_WITH_VBOXSDL=
 VBOX_WITH_HEADLESS=
 VBOX_WITH_VRDP=
 VBOX_WITH_DOCS=
 VBOX_WITH_WEBSERVICES=
 VBOX_WITH_32_ON_64_MAIN_API=
endif # VBOX_QUICK

ifeq ($(KBUILD_TARGET),darwin)
 # Don't bother with SDL ttf for now.
 VBOX_WITH_SECURELABEL=
 # We'll use the native html/help viewer.
 VBOX_WITH_KCHMVIEWER=
 VBOX_WITH_VRDP_RDESKTOP=
 # Permanent (no working SDL).
 VBOX_WITH_VBOXSDL=
endif

ifeq ($(KBUILD_TARGET),freebsd)
 VBOX_WITH_DOCS=
endif

ifeq ($(KBUILD_TARGET),haiku)
 # Don't bother with SDL ttf for now.
 VBOX_WITH_SECURELABEL=
 # We'll use the native html/help viewer.
 VBOX_WITH_KCHMVIEWER=
 VBOX_WITH_VRDP_RDESKTOP=
 # Permanent (no working SDL).
 VBOX_WITH_VBOXSDL=
 VBOX_WITH_DOCS=
 VBOX_WITH_VBOXDRV=
 VBOX_WITH_VRDP=
 VBOX_WITH_HEADLESS=
 VBOX_WITH_VBOXSDL=
 VBOX_WITH_QTGUI=
# VBOX_WITH_MAIN=
 VBOX_WITH_DOCS=
 VBOX_WITH_ISCSI=
 VBOX_WITH_INIP=
 VBOX_WITH_INTERNAL_NETWORKING=
 VBOX_WITH_PDM_ASYNC_COMPLETION=
 VBOX_WITH_KCHMVIEWER=
 VBOX_WITH_HARDENING=
endif


ifeq ($(KBUILD_TARGET),os2)
 VBOX_WITH_WEBSERVICES=
 VBOX_WITH_INSTALLER=
 VBOX_WITH_SECURELABEL=
 VBOX_WITH_VRDP_AUTHMOD=
 VBOX_WITH_VRDP_RDESKTOP=
 VBOX_WITH_VALIDATIONKIT=
 VBOX_WITH_QTGUI=
 VBOX_WITH_USB=
 VBOX_WITH_EHCI=
 VBOX_WITH_DOCS=
 VBOX_WITH_PDM_ASYNC_COMPLETION=
 VBOX_WITH_KCHMVIEWER=
 VBOX_WITH_HARDENING=
endif

ifeq ($(KBUILD_TARGET),solaris)
 VBOX_WITH_SECURELABEL=
endif

ifeq ($(KBUILD_TARGET),win)
 VBOX_WITH_VRDP_RDESKTOP=
 VBOX_WITH_KCHMVIEWER=
endif

ifn1of ($(KBUILD_TARGET_ARCH), x86 amd64)
 VBOX_WITH_ADDITION_DRIVERS=
 VBOX_WITH_DEBUGGER=
 VBOX_WITH_DOCS=
 VBOX_WITH_EHCI=
 VBOX_WITH_HARDENING=
 VBOX_WITH_HEADLESS=
 VBOX_WITH_HGCM=
 VBOX_WITH_HGSMI=
 VBOX_WITH_INIP=
 VBOX_WITH_INSTALLER=
 VBOX_WITH_INTERNAL_NETWORKING=
 VBOX_WITH_ISCSI=
 VBOX_WITH_KCHMVIEWER=
 VBOX_WITH_MAIN=
 VBOX_WITH_PDM_ASYNC_COMPLETION=
 VBOX_WITH_QTGUI=
 VBOX_WITH_RAW_MODE=
 VBOX_WITH_SECURELABEL=
 VBOX_WITH_VALIDATIONKIT=
 VBOX_WITH_USB=
 VBOX_WITH_VBOXDRV=
 VBOX_WITH_VBOXSDL=
 VBOX_WITH_WEBSERVICES=
 VBOX_WITH_XPCOM=
 VBOX_WITHOUT_HARDENING=1
 # remove later:
 VBOX_WITH_VRDP=
 VBOX_WITH_VRDP_AUTHMOD=
 VBOX_WITH_VRDP_RDESKTOP=
endif


#
# Include automatic and local config file to override the above settings
# and to provide defaults for the settings below this point.
#
ifndef AUTOCFG
 AUTOCFG := $(wildcard $(PATH_ROOT)/AutoConfig.kmk)
endif
ifneq ($(AUTOCFG),)
 include $(AUTOCFG)
endif

ifndef LOCALCFG
 LOCALCFG := $(wildcard $(PATH_ROOT)/LocalConfig.kmk)
 ifneq ($(LOCALCFG),)
  include $(LOCALCFG)
 endif
else
 # Ignore it if it doesn't exist.
 if exists "$(LOCALCFG)"
  include $(LOCALCFG)
 else
  $(warning LOCALCFG='$(LOCALCFG)' does not exist)
  override LOCALCFG :=
 endif
endif

#
# Allow to overwrite the branding information from an external file
#
ifdef VBOX_BRANDING_CFG
 include $(VBOX_BRANDING_CFG)
endif

#
# Bitch about old settings.
#
ifdef VBOX_WITHOUT_LINUX_COMPILER_H
 $(warning VBOX_WITHOUT_LINUX_COMPILER_H was renamed to VBOX_WITH_LINUX_COMPILER_H, the meaning is inverted.)
endif

#
# Indicate VBOX_ONLY build if any of the VBOX_ONLY_* variables are set.
#
VBOX_ONLY_BUILD := $(strip $(foreach x, ADDITIONS DOCS EXTPACKS SDK VALIDATIONKIT\
	, $(if-expr defined(VBOX_ONLY_$(x)),VBOX_ONLY_$(x))))
if $(words $(VBOX_ONLY_BUILD)) > 1
 $(error VBox: More than one VBOX_ONLY build enabled! $(VBOX_ONLY_BUILD))
endif

#
# For the docs build box.
#
ifdef VBOX_ONLY_DOCS
 VBOX_WITH_DOCS_CHM = 1
endif

#
# Disable components that are not open sourced.
#
ifdef VBOX_OSE
 VBOX_WITH_VRDP=
 VBOX_WITH_EHCI_IMPL=
 VBOX_WITH_XHCI_IMPL=
 VBOX_WITH_USB_VIDEO_IMPL=
 VBOX_WITH_NVME_IMPL=
 VBOX_WITH_EXTPACK_PUEL=
 VBOX_WITH_EXTPACK_PUEL_BUILD=
 VBOX_WITH_PCI_PASSTHROUGH_IMPL=
 VBOX_WITH_OS2_ADDITIONS_BIN=
 ifeq ($(KBUILD_TARGET),win)
  VBOX_WITH_NATIVE_NEM=
 endif
 # not yet
 VBOX_WITH_SECURELABEL=
 VBOX_WITH_KCHMVIEWER=
 VBOX_WITH_PLUGIN_CRYPT=
 VBOX_WITH_DRAG_AND_DROP_PROMISES=
 ifn1of ($(KBUILD_TARGET), linux)
  VBOX_WITH_DOCS=
  VBOX_WITH_DOCS_PACKING=
 endif
 if1of ($(KBUILD_TARGET), solaris)
  VBOX_WITH_32_ON_64_MAIN_API=
 endif
 if1of ($(KBUILD_TARGET), win)
  # tar/gzip uncommon on Windows
  VBOX_WITH_EXTPACK_VBOXDTRACE=
 endif
 # Enable any translations in OSE, even partial ones.
 ifndef ($(VBOX_NO_DOCS_TRANSLATIONS))
  VBOX_WITH_DOCS_TRANSLATIONS = 1
 endif
 VBOX_WITH_INTEL_PXE=
 # Disable for OSE, requires snv_159+.
 VBOX_WITH_NETFLT_CROSSBOW=
 ifn1of ($(KBUILD_TARGET), darwin linux solaris win)
  VBOX_WITH_INSTALLER=
 endif
 if1of ($(KBUILD_TARGET), win)
  # Undefine codec libraries which are not needed.
  VBOX_WITH_LIBVPX=
  VBOX_WITH_LIBOPUS=
  # Disable recording (with audio support).
  VBOX_WITH_RECORDING=
  VBOX_WITH_AUDIO_RECORDING=
 endif
 # branding
 VBOX_BRAND_LICENSE_HTML             := $(PATH_ROOT)/doc/License-gpl-2.0.html
 VBOX_BRAND_LICENSE_RTF              := $(PATH_ROOT)/doc/License-gpl-2.0.rtf
 VBOX_BRAND_LICENSE_TXT              := $(PATH_ROOT)/doc/License-gpl-2.0.txt
 VBOX_BRAND_BIOS_LOGO                := $(PATH_ROOT)/src/VBox/Devices/Graphics/BIOS/ose_logo.bmp
 VBOX_BRAND_GUI_ABOUT_PNG            := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/about.png
 VBOX_BRAND_GUI_ABOUT_X2_PNG         := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/about_x2.png
 VBOX_BRAND_GUI_ABOUT_X3_PNG         := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/about_x3.png
 VBOX_BRAND_GUI_ABOUT_X4_PNG         := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/about_x4.png
 VBOX_BRAND_GUI_ABOUT_16PX_PNG       := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/about_16px.png
 VBOX_BRAND_GUI_ABOUT_16PX_X2_PNG    := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/about_16px_x2.png
 VBOX_BRAND_GUI_ABOUT_16PX_X3_PNG    := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/about_16px_x3.png
 VBOX_BRAND_GUI_ABOUT_16PX_X4_PNG    := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/about_16px_x4.png
 VBOX_BRAND_GUI_VBOX_16PX_PNG        := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/VirtualBox_16px.png
 VBOX_BRAND_GUI_VBOX_20PX_PNG        := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/VirtualBox_20px.png
 VBOX_BRAND_GUI_VBOX_32PX_PNG        := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/VirtualBox_32px.png
 VBOX_BRAND_GUI_VBOX_40PX_PNG        := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/VirtualBox_40px.png
 VBOX_BRAND_GUI_VBOX_48PX_PNG        := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/VirtualBox_48px.png
 VBOX_BRAND_GUI_VBOX_64PX_PNG        := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/VirtualBox_64px.png
 VBOX_BRAND_GUI_CUBE_42PX_PNG        := $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/OSE/VirtualBox_cube_42px.png
 VBOX_BRAND_GUI_VBOX_SVG             := $(PATH_ROOT)/src/VBox/Artwork/OSE/virtualbox.svg
endif

#
# VBOX_WITHOUT_HARDENING is for developers (put in LocalConfig.kmk).
# Note that this is a bit rough since hardening governs more than one
# variable...  Also note that we allow VBOX_WITH_HARDENING=1 on the
# command line to overrule VBOX_WITHOUT_HARDENING (the check below).
#
ifdef VBOX_WITHOUT_HARDENING
 VBOX_WITH_HARDENING=
 ifeq ($(VBOX_WITH_HARDENING),)
  VBOX_PATH_APP_PRIVATE=
  VBOX_PATH_APP_PRIVATE_ARCH=
  VBOX_PATH_APP_PRIVATE_ARCH_TOP=
  VBOX_PATH_SHARED_LIBS=
  VBOX_PATH_APP_DOCS=
  VBOX_WITH_RUNPATH=
  if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd solaris) # duplicated up above
   VBOX_WITH_ORIGIN = 1
  endif
 endif
endif

#
# Sanitize the additions build config variables.
#
ifdef VBOX_WITH_ADDITIONS_FROM_BUILD_SERVER
 VBOX_WITHOUT_ADDITIONS := 1
 ifdef VBOX_ONLY_ADDITIONS
  $(error VBOX_ONLY_ADDITIONS + VBOX_WITH_ADDITIONS_FROM_BUILD_SERVER does not add up!)
 endif
endif

ifdef VBOX_ONLY_ADDITIONS
 ifdef VBOX_WITHOUT_ADDITIONS
  $(error VBOX_ONLY_ADDITIONS + VBOX_WITHOUT_ADDITIONS does not add up!)
 endif
 ifndef VBOX_WITH_ADDITIONS
  $(error VBOX_ONLY_ADDITIONS + unset VBOX_WITH_ADDITIONS does not add up!)
 endif
endif

ifdef VBOX_WITHOUT_ADDITIONS
 # Zap anything that could be contradicting this.
 VBOX_WITH_ADDITIONS :=
endif

#
# Sanitize the documentation build config variables.
#
ifdef VBOX_WITH_DOCS_FROM_BUILD_SERVER
 VBOX_WITHOUT_DOCS := 1
 ifdef VBOX_ONLY_DOCS
  $(error VBOX_ONLY_DOCS + VBOX_WITH_DOCS_FROM_BUILD_SERVER does not add up!)
 endif
endif

ifdef VBOX_ONLY_DOCS
 ifdef VBOX_WITHOUT_DOCS
  $(error VBOX_ONLY_DOCS + VBOX_WITHOUT_DOCS does not add up!)
 endif
endif

ifdef VBOX_WITHOUT_DOCS
 # Zap anything that could be contradicting this.
 VBOX_WITH_DOCS :=
 VBOX_WITH_DOCS_CHM :=
endif

#
# Disable components for headless
#
ifdef VBOX_HEADLESS
 VBOX_WITH_QTGUI=
 VBOX_WITH_VBOXSDL=
 VBOX_WITH_KCHMVIEWER=
 VBOX_WITH_VRDP_RDESKTOP=
endif

#
# Undefined VBOX_WITH_MAIN implies exclusion of a few more items.
#
ifndef VBOX_WITH_MAIN
 VBOX_WITH_VBOXSDL=
 VBOX_WITH_QTGUI=
 VBOX_WITH_DEBUGGER_GUI=
 VBOX_WITH_HEADLESS=
 ifdef VBOX_ONLY_DOCS
  $(error Oh, does VBOX_ONLY_DOCS actually end up here. sweet.)
 endif
 VBOX_WITH_DOCS=
endif

ifndef VBOX_WITH_QTGUI
 VBOX_WITH_KCHMVIEWER=
endif

ifdef VBOX_WITH_EXTPACK_PUEL_BUILD
 VBOX_WITH_EXTPACK_PUEL = 1
endif

ifdef VBOX_WITH_TESTSUITE
 $(warning VBOX_WITH_TESTSUITE was renamed to VBOX_WITH_VALIDATIONKIT)
 VBOX_WITH_VALIDATIONKIT = $(VBOX_WITH_TESTSUITE)
endif


#
# Derived indicators.
#

## Indicates that we need the extpack openssl libs.
if   defined(VBOX_WITH_EXTPACK_PUEL_BUILD) \
 && (   !defined(VRDP_WITH_IPRT_CRYPTO) \
     || !defined(VRDP_WITH_IPRT_SSL) \
     || !defined(VD_WITH_IPRT_CRYPTO) )
 VBOX_NEED_EXTPACK_OPENSSL = 1
else
 VBOX_NEED_EXTPACK_OPENSSL =
endif


#
# Mark OSE builds clearly, helps figuring out limitations more easily.
#
ifdef VBOX_OSE
# This can be overridden (e.g. in LocalConfig.kmk) by whoever publishes a set
# of VirtualBox binaries.  We request though that you always use something that
# clearly identifies your build and makes it clear that it is not one done by
# the VirtualBox team.
 VBOX_BUILD_PUBLISHER ?= _OSE
endif

# Keep in sync with G_virtualBoxPackage in glue-jaxws.xsl and glue-java.xsl
# Changed with every new version, so beware!
if $(VBOX_VERSION_BUILD) < 51
  VBOX_API_VERSION          = $(VBOX_VERSION_MAJOR)_$(VBOX_VERSION_MINOR)
else
  VBOX_API_VERSION          = $(VBOX_VERSION_MAJOR)_$(expr $(VBOX_VERSION_MINOR) + 1)
endif
VBOX_API_SUFFIX             = _$(VBOX_API_VERSION)
VBOX_JAVA_PACKAGE           = org.virtualbox$(VBOX_API_SUFFIX)

#
# Derived / helper config indicators.  Not configurable.
#

# Use the OpenGL module in qt when the video hardware acceleration feature
# is enabled.
if defined(VBOX_WITH_VIDEOHWACCEL) && defined(VBOX_WITH_QTGUI)
 VBOX_GUI_USE_QGL = 1
else
 VBOX_GUI_USE_QGL=
endif

# Collection macro mainly for deciding whether VBoxDTrace needs shipping.
VBOX_WITH_DTRACE := $(if-expr defined(VBOX_WITH_DTRACE_R0) || defined(VBOX_WITH_DTRACE_R0DRV) \
	       	            || defined(VBOX_WITH_DTRACE_R3) || defined(VBOX_WITH_DTRACE_RC),1,)

# kSubmit / kWorker is only available on windows.
ifdef VBOX_USE_KSUBMIT
 ifeq ($(KBUILD_HOST),win)
#  TOOL_VCC120AMD64_USE_KSUBMIT := 1
#  TOOL_VCC120X86_USE_KSUBMIT   := 1
  TOOL_VCC100AMD64_USE_KSUBMIT := 1
  TOOL_VCC100X86_USE_KSUBMIT   := 1
  TOOL_OPENWATCOM_USE_KSUBMIT  := 1
  TOOL_YASM_USE_KSUBMIT        := 1
  TOOL_NASM_USE_KSUBMIT        := 1
  TOOL_VBoxNasm_USE_KSUBMIT    := 1
 else
  VBOX_USE_KSUBMIT :=
 endif
endif

#
# Image and object format config.
#
if1of ($(KBUILD_TARGET), freebsd haiku linux netbsd openbsd solaris)
 VBOX_LDR_FMT = elf
endif
ifeq ($(KBUILD_TARGET),darwin)
 VBOX_LDR_FMT = macho
endif
ifeq ($(KBUILD_TARGET),os2)
 VBOX_LDR_FMT = lx
 VBOX_LDR_FMT32 = lx
 VBOX_LDR_FMT64 = elf
 DONT_USE_YASM = 1 # yasm doesn't implement omf yet.
endif
ifeq ($(KBUILD_TARGET),win)
 VBOX_LDR_FMT = pe
endif
VBOX_LDR_FMT32 ?= $(VBOX_LDR_FMT)
VBOX_LDR_FMT64 ?= $(VBOX_LDR_FMT)

#
# Assembler setup.
#
# This is a bit complicated since we have to support two different assmblers
# (yasm/nasm) and possibly two different formats (32-bit/64-bit).
#
ifeq ($(VBOX_LDR_FMT),elf)
 ifeq ($(KBUILD_TARGET_ARCH),x86)
VBOX_ASFLAGS_FMT = -f elf32 -DASM_FORMAT_ELF
 else
VBOX_ASFLAGS_FMT = -f elf64 -DASM_FORMAT_ELF
 endif
 VBOX_ASFLAGS_DBFINFO = -g dwarf2
endif
ifeq ($(VBOX_LDR_FMT),lx)
 VBOX_ASFLAGS_FMT = -f obj -DASM_FORMAT_OMF
 VBOX_ASFLAGS_DBFINFO = -g stabs
endif
ifeq ($(VBOX_LDR_FMT),macho)
 ifeq ($(KBUILD_TARGET_ARCH),x86)
  VBOX_ASFLAGS_FMT = -f macho32 -DASM_FORMAT_MACHO
 else
  VBOX_ASFLAGS_FMT = -f macho64 -DASM_FORMAT_MACHO
 endif
 VBOX_ASFLAGS_DBFINFO = -g dwarf2
endif
ifeq ($(VBOX_LDR_FMT),pe)
 ifeq ($(KBUILD_TARGET_ARCH),x86)
VBOX_ASFLAGS_FMT = -f win32 -DASM_FORMAT_PE
 else
VBOX_ASFLAGS_FMT = -f win64 -DASM_FORMAT_PE
 endif
VBOX_ASFLAGS_DBFINFO = -g cv8
endif
ifndef VBOX_ASFLAGS_FMT
 $(error VBOX_ASFLAGS_FMT is not defined. VBOX_LDR_FMT=$(VBOX_LDR_FMT))
endif

ifeq ($(VBOX_LDR_FMT32),elf)
 VBOX_ASFLAGS_FMT32 = -f elf32 -DASM_FORMAT_ELF
 VBOX_ASFLAGS_DBFINFO32 = -g dwarf2
endif
ifeq ($(VBOX_LDR_FMT32),lx)
 VBOX_ASFLAGS_FMT32 = -f obj -DASM_FORMAT_OMF
 VBOX_ASFLAGS_DBFINFO32 = -g stabs
endif
ifeq ($(VBOX_LDR_FMT32),macho)
 VBOX_ASFLAGS_FMT32 = -f macho32 -DASM_FORMAT_MACHO
 VBOX_ASFLAGS_DBFINFO32 = -g dwarf2
endif
ifeq ($(VBOX_LDR_FMT32),pe)
 VBOX_ASFLAGS_FMT32 = -f win32 -DASM_FORMAT_PE
 VBOX_ASFLAGS_DBFINFO32 = -g cv8
endif
ifndef VBOX_ASFLAGS_FMT32
 $(error VBOX_ASFLAGS_FMT32 is not defined. VBOX_LDR_FMT32=$(VBOX_LDR_FMT32))
endif

ifeq ($(VBOX_LDR_FMT64),elf)
 VBOX_ASFLAGS_FMT64 = -f elf64 -DASM_FORMAT_ELF
 VBOX_ASFLAGS_DBFINFO64 = -g dwarf2
endif
ifeq ($(VBOX_LDR_FMT64),macho)
 VBOX_ASFLAGS_FMT64 = -f macho64 -DASM_FORMAT_MACHO
 VBOX_ASFLAGS_DBFINFO64 = -g dwarf2
endif
ifeq ($(VBOX_LDR_FMT64),pe)
 VBOX_ASFLAGS_FMT64 = -f win64 -DASM_FORMAT_PE
 VBOX_ASFLAGS_DBFINFO64 = -g cv8
endif
ifndef VBOX_ASFLAGS_FMT64
 $(error VBOX_ASFLAGS_FMT64 is not defined. VBOX_LDR_FMT64=$(VBOX_LDR_FMT64))
endif

ifndef DONT_USE_YASM
 VBOX_ASTOOL    = YASM
 VBOX_LDR_FMT_2_YASM_DBGINFO.elf   = -g dwarf2
 VBOX_LDR_FMT_2_YASM_DBGINFO.lx    = -g stabs
 VBOX_LDR_FMT_2_YASM_DBGINFO.macho =
 VBOX_LDR_FMT_2_YASM_DBGINFO.pe    = -g cv8
 VBOX_ASFLAGS   = $(VBOX_ASFLAGS_FMT)   -D__YASM__ -Worphan-labels $(VBOX_YASM_Wno-segreg-in-64bit) $(VBOX_LDR_FMT_2_YASM_DBGINFO.$(VBOX_LDR_FMT))
 VBOX_ASFLAGS32 = $(VBOX_ASFLAGS_FMT32) -D__YASM__ -Worphan-labels $(VBOX_YASM_Wno-segreg-in-64bit) $(VBOX_LDR_FMT_2_YASM_DBGINFO.$(VBOX_LDR_FMT32))
 VBOX_ASFLAGS64 = $(VBOX_ASFLAGS_FMT64) -D__YASM__ -Worphan-labels $(VBOX_YASM_Wno-segreg-in-64bit) $(VBOX_LDR_FMT_2_YASM_DBGINFO.$(VBOX_LDR_FMT64))
else
 VBOX_ASTOOL    = NASM
 VBOX_ASFLAGS   = $(subst elf32,elf,$(VBOX_ASFLAGS_FMT))   -D__NASM__ -w+orphan-labels -g
 VBOX_ASFLAGS32 = $(subst elf32,elf,$(VBOX_ASFLAGS_FMT32)) -D__NASM__ -w+orphan-labels -g
 VBOX_ASFLAGS64 = $(VBOX_ASFLAGS_FMT64) -D__NASM__ -w+orphan-labels -g
endif

#
# Windows only has mingw handy. On *nix we have to deal with cross compiling
# 32-bit targets on 64-bit platforms, meaning we'll be using gcc32/g++32.
# In the latter case we'll also have to disable all the all the R0 driver related stuff.
#
ifndef VBOX_GCC_TOOL
 ifeq ($(KBUILD_TARGET),win)
  ifeq ($(KBUILD_TARGET_ARCH),x86)
   VBOX_GCC_TOOL := MINGW32
   TOOL_MINGW32_CFLAGS := $(UNDEFINED) # override -g
  else
   VBOX_GCC_TOOL := MINGWW64
  endif
 else ifeq ($(KBUILD_TARGET),os2)
  VBOX_GCC_TOOL := GXX3OMF
 else ifeq ($(KBUILD_TARGET),darwin)
  ifdef VBOX_WITH_NEW_XCODE
   VBOX_GCC_TOOL := VBoxXcode62
  else
   VBOX_GCC_TOOL := GXX4MACHO
  endif
 else ifeq ($(KBUILD_TARGET),haiku)
  # Haiku shouldn't pass '-r' to the linker by default
  VBOX_GCC_TOOL := GXX3PLAIN
 else ifeq ($(KBUILD_TARGET),solaris)
  VBOX_GCC_TOOL := GXX3PLAIN
  VBOX_GCC32_TOOL := GCC3PLAIN
  ifeq ($(KBUILD_HOST),solaris)
   TOOL_GXX3PLAIN_LD_SYSMOD ?= /usr/ccs/bin/ld
  endif
 else
  VBOX_GCC_TOOL := GXX3
  ifeq ($(KBUILD_TARGET_ARCH).$(KBUILD_HOST_ARCH),x86.amd64) ## @todo mixing target/host here!
   VBOX_GCC_TOOL := GXX32
   VBOX_WITH_VBOXDRV=
  else ifeq ($(KBUILD_TARGET_ARCH).$(KBUILD_HOST_ARCH),amd64.x86)
   VBOX_GCC_TOOL := GXX64
   VBOX_WITH_VBOXDRV=
  endif
 endif
endif
ifndef VBOX_GCC32_TOOL
 ifeq ($(KBUILD_TARGET_ARCH),x86)
  VBOX_GCC32_TOOL := $(VBOX_GCC_TOOL)
 else ifeq ($(KBUILD_TARGET),win)
  VBOX_GCC32_TOOL := MINGW32
 else
  VBOX_GCC32_TOOL := GCC32
 endif
endif

#
# Decide which Visual C++ compiler version we're using by default.
#
ifndef VBOX_VCC_TOOL_STEM
 VBOX_VCC_TOOL_STEM := VCC100
else ifn1of ($(VBOX_VCC_TOOL_STEM), VCC100 VCC110 VCC120)
 $(error VBox: VBOX_VCC_TOOL_STEM='$(VBOX_VCC_TOOL_STEM)' is not supported, only VCC100 and VCC110 is)
endif
ifndef VBOX_VCC_TOOL
 VBOX_VCC_TOOL := $(VBOX_VCC_TOOL_STEM)$(toupper $(KBUILD_TARGET_ARCH))
endif

#
# Decide which Visual C++ compiler version we're using for newer stuff.
#
ifndef VBOX_NEWER_VCC_TOOL_STEM
 VBOX_NEWER_VCC_TOOL_STEM := VCC120
else ifn1of ($(VBOX_NEWER_VCC_TOOL_STEM), VCC120)
 $(error VBox: VBOX_NEWER_VCC_TOOL_STEM='$(VBOX_NEWER_VCC_TOOL_STEM)' is not supported, only VCC120 is)
endif
ifndef VBOX_NEWER_VCC_TOOL
 VBOX_NEWER_VCC_TOOL := $(VBOX_NEWER_VCC_TOOL_STEM)$(toupper $(KBUILD_TARGET_ARCH))
endif

#
# Default too nonsense.
#
## @todo Remove the default tool crap here!
TOOL = $(VBOX_GCC_TOOL)
TOOL.win.x86 = $(VBOX_VCC_TOOL_STEM)X86
TOOL.win.amd64 = $(VBOX_VCC_TOOL_STEM)AMD64
ASTOOL = $(VBOX_ASTOOL)


#
# Setup the global defines and includes.
#
# Note! The __SOMETHING__ #defines are deprecated as they violate the C/C++ specs.
#
INCS += $(PATH_ROOT)/include $(PATH_OUT)
DEFS += VBOX
DEFS.debug      := DEBUG DEBUG_$(subst $(subst _, ,_),_,$(USERNAME)) DEBUG_USERNAME=$(subst $(subst _, ,_),_,$(USERNAME))
DEFS.dbgopt      = $(DEFS.debug)
DEFS.profile     = VBOX_WITH_STATISTICS
DEFS.strict      = RT_STRICT VBOX_STRICT
DEFS.x86         = RT_ARCH_X86 __X86__
DEFS.amd64       = RT_ARCH_AMD64 __AMD64__
DEFS.sparc32     = RT_ARCH_SPARC
DEFS.sparc64     = RT_ARCH_SPARC64
DEFS.darwin      = RT_OS_DARWIN __DARWIN__
DEFS.freebsd     = RT_OS_FREEBSD __FREEBSD__
DEFS.haiku       = RT_OS_HAIKU
DEFS.linux       = RT_OS_LINUX _FILE_OFFSET_BITS=64
DEFS.netbsd      = RT_OS_NETBSD
DEFS.openbsd     = RT_OS_OPENBSD
DEFS.os2         = RT_OS_OS2 __OS2__
DEFS.os-agnostic = RT_OS_AGNOSTIC
DEFS.solaris     = RT_OS_SOLARIS _FILE_OFFSET_BITS=64
DEFS.win         = RT_OS_WINDOWS __WIN__
DEFS.win.x86     = __WIN32__
DEFS.win.amd64   = __WIN64__
# optional defines (use environment or make commandline)
ifdef VBOX_WITH_STATISTICS
 DEFS += VBOX_WITH_STATISTICS
endif
ifdef VBOX_STRICT
 DEFS += VBOX_STRICT
endif
ifdef LOG_ENABLED
 DEFS += LOG_ENABLED
endif
ifdef VBOX_OSE
 DEFS += VBOX_OSE
endif
ifdef VBOX_WITH_64_BITS_GUESTS
 DEFS += VBOX_WITH_64_BITS_GUESTS
endif
ifdef VBOX_WITH_REM
 DEFS += VBOX_WITH_REM
endif
ifdef VBOX_WITH_RAW_MODE
 DEFS += VBOX_WITH_RAW_MODE
endif

# Don't flood CDEFS, old MASMs doesn't like too many defines.
ifdef VBOX_WITH_DEBUGGER
 CDEFS += VBOX_WITH_DEBUGGER
endif
ifdef VBOX_WITH_HARDENING
 CDEFS += VBOX_WITH_HARDENING
endif
if defined(VBOX_WITH_STRICT_LOCKS) && ($(KBUILD_TYPE) == "debug" || $(KBUILD_TYPE) == "strict")
 CDEFS += RT_LOCK_STRICT RT_LOCK_STRICT_ORDER
endif
ifdef VBOX_WITH_EF_WRAPS
 CDEFS += RTMEM_WRAP_TO_EF_APIS RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF
endif

# Quoted strings should not be passed to the assemblers since they might not
# subscribe to C preprocessing semantics.
ifdef VBOX_PATH_APP_PRIVATE
 CDEFS += RTPATH_APP_PRIVATE=\"$(VBOX_PATH_APP_PRIVATE)\"
endif
ifdef VBOX_PATH_APP_PRIVATE_ARCH
 CDEFS += RTPATH_APP_PRIVATE_ARCH=\"$(VBOX_PATH_APP_PRIVATE_ARCH)\"
endif
ifdef VBOX_PATH_APP_PRIVATE_ARCH_TOP
 CDEFS += RTPATH_APP_PRIVATE_ARCH_TOP=\"$(VBOX_PATH_APP_PRIVATE_ARCH_TOP)\"
endif
ifdef VBOX_PATH_SHARED_LIBS
 CDEFS += RTPATH_SHARED_LIBS=\"$(VBOX_PATH_SHARED_LIBS)\"
endif
ifdef VBOX_PATH_APP_DOCS
 CDEFS += RTPATH_APP_DOCS=\"$(VBOX_PATH_APP_DOCS)\"
endif
CXXDEFS  += $(CDEFS)
PCHDEFS  += $(CDEFS)
OBJCDEFS += $(CDEFS)

USES += dtrace
USES.win += vboximportchecker


#
# Decide which Windows DDK to use by default.
#
if1of ($(VBOX_VCC_TOOL_STEM), VCC110)
 VBOX_WINDDK         ?= WINDDK80
else
 VBOX_WINDDK         ?= WINDDK71
endif
VBOX_WINDDK_WLH      ?= $(VBOX_WINDDK)WLH

VBOX_WINDDK_GST      ?= $(VBOX_WINDDK)
VBOX_WINDDK_GST_W8   ?= WINDDK80W8
VBOX_WINDDK_GST_W7   ?= $(VBOX_WINDDK_GST)W7
VBOX_WINDDK_GST_WLH  ?= $(VBOX_WINDDK_GST)WLH
VBOX_WINDDK_GST_W2K3 ?= WINDDK71WNET
ifeq ($(KBUILD_TARGET_ARCH),x86)
 VBOX_WINDDK_GST_WXP ?= WINDDK71WXP
 VBOX_WINDDK_GST_W2K ?= $(VBOX_WINDDK_GST_WXP)
 VBOX_WINDDK_GST_NT4 ?= $(VBOX_WINDDK_GST_WXP)
else
 VBOX_WINDDK_GST_WXP ?= $(VBOX_WINDDK_GST_W2K3)
 VBOX_WINDDK_GST_W2K ?= $(VBOX_WINDDK_GST_W2K3)
 VBOX_WINDDK_GST_NT4 ?= $(VBOX_WINDDK_GST_W2K3)
endif


#
# Decide which Windows SDK to use by default.
#
if1of ($(VBOX_VCC_TOOL_STEM), VCC110)
 VBOX_WINPSDK ?= WINPSDK80
else
 VBOX_WINPSDK ?= WINPSDK71
endif
VBOX_WINPSDK_GST      ?= $(VBOX_WINPSDK)
VBOX_WINPSDK_GST_W8   ?= WINPSDK80
VBOX_WINPSDK_GST_W7   ?= $(VBOX_WINPSDK_GST)
VBOX_WINPSDK_GST_WLH  ?= $(VBOX_WINPSDK_GST)
VBOX_WINPSDK_GST_WXP  ?= $(VBOX_WINPSDK_GST)
ifeq ($(KBUILD_TARGET_ARCH),x86)
 VBOX_WINPSDK_GST_W2K ?= $(VBOX_WINPSDK_GST)
 VBOX_WINPSDK_GST_NT4 ?= $(VBOX_WINPSDK_GST)
else
 VBOX_WINPSDK_GST_W2K ?= $(VBOX_WINPSDK_GST_WXP)
 VBOX_WINPSDK_GST_NT4 ?= $(VBOX_WINPSDK_GST_WXP)
endif


#
# ARCH_BITS_DEFS.
#
if1of ($(KBUILD_TARGET_ARCH),amd64 sparc64)
 VBOX_HC_ARCH_BITS := 64
 ARCH_BITS_DEFS    := HC_ARCH_BITS=64
else if1of ($(KBUILD_TARGET_ARCH),x86 sparc32)
 VBOX_HC_ARCH_BITS := 32
 ARCH_BITS_DEFS    := HC_ARCH_BITS=32
else
 $(error VBox: KBUILD_TARGET_ARCH=$(KBUILD_TARGET_ARCH))
endif

ifdef VBOX_WITH_64_BITS_GUESTS
 VBOX_GC_ARCH_BITS_DEFS := GC_ARCH_BITS=64
else
 VBOX_GC_ARCH_BITS_DEFS := GC_ARCH_BITS=32
endif
ARCH_BITS_DEFS += $(VBOX_GC_ARCH_BITS_DEFS)

#
# Add the output dir(s) to the dynamic loader search path.
#
if1of ($(KBUILD_HOST), freebsd linux netbsd openbsd solaris)
 export LD_LIBRARY_PATH:=$(PATH_STAGE_BIN):$(PATH_STAGE_LIB):$(LD_LIBRARY_PATH)
endif
ifeq ($(KBUILD_HOST),haiku)
 export LIBRARY_PATH:=$(PATH_STAGE_BIN):$(PATH_STAGE_LIB):$(LIBRARY_PATH)
endif
ifeq ($(KBUILD_HOST),os2)
 #fixme! export BEGINLIBPATH:=$(PATH_STAGE_BIN);$(PATH_STAGE_LIB);$(BEGINLIBPATH)
endif
ifeq ($(KBUILD_HOST),win)
  # This check is a bit hacky, but avoids problems with PATH being changed
  # again when the makefiles are reread because some automatically generated
  # makefile has been modified.
  ifeq ($(findstring $(PATH_STAGE_BIN);$(PATH_STAGE_LIB);,$(PATH)),)
   export PATH:=$(PATH_STAGE_BIN);$(PATH_STAGE_LIB);$(PATH)
  endif
endif

#
# Common libraries and tools.
#
ifeq ($(KBUILD_TARGET),darwin)
 LIB_RUNTIME     = $(PATH_STAGE_BIN)/VBoxRT.dylib
 LIB_RUNTIME_EF  = #$(PATH_STAGE_LIB)/RuntimeEFCPP.a
 VBOX_LIB_RUNTIME_X86   = $(PATH_STAGE_BIN)/VBoxRT-x86.dylib
 LIB_KPROFILE    = $(PATH_STAGE_BIN)/kPrf2.dylib
 LIB_VMM         = $(PATH_STAGE_BIN)/VBoxVMM.dylib
 LIB_VMMRC       = $(PATH_STAGE_BIN)/VMMRC.rc
 LIB_REM         = $(PATH_STAGE_LIB)/VBoxREM.dylib
 LIB_XPCOM       = $(PATH_STAGE_BIN)/VBoxXPCOM.dylib
 LIB_XPCOM_IMP   = $(PATH_STAGE_LIB)/VBoxXPCOMImp.dylib
 VBOX_LIB_XPCOM_X86     = $(PATH_STAGE_BIN)/VBoxXPCOM-x86.dylib
 LIB_DDU         = $(PATH_STAGE_BIN)/VBoxDDU.dylib
endif
if1of ($(KBUILD_TARGET), freebsd haiku linux netbsd openbsd solaris)
 LIB_RUNTIME     = $(PATH_STAGE_BIN)/VBoxRT.so
 LIB_RUNTIME_EF  = $(PATH_STAGE_LIB)/RuntimeEFCPP.a
 VBOX_LIB_RUNTIME_X86   = $(PATH_STAGE_BIN)/VBoxRT-x86.so
 LIB_KPROFILE    = $(PATH_STAGE_BIN)/kPrf2.so
 LIB_VMM         = $(PATH_STAGE_BIN)/VBoxVMM.so
 LIB_VMMRC       = $(PATH_STAGE_BIN)/VMMRC.rc
 LIB_REM         = $(PATH_STAGE_LIB)/VBoxREM.so
 LIB_XPCOM       = $(PATH_STAGE_BIN)/VBoxXPCOM.so
 LIB_XPCOM_IMP   = $(PATH_STAGE_LIB)/VBoxXPCOMImp.so
 VBOX_LIB_XPCOM_X86   = $(PATH_STAGE_BIN)/VBoxXPCOM-x86.so
 LIB_DDU         = $(PATH_STAGE_BIN)/VBoxDDU.so
endif
ifeq ($(KBUILD_TARGET),os2)
 LIB_RUNTIME     = $(PATH_STAGE_BIN)/VBoxRT.dll
 LIB_RUNTIME_EF  = #$(PATH_STAGE_LIB)/RuntimeEFCPP.a
 VBOX_LIB_RUNTIME_X86   = $(PATH_STAGE_BIN)/VBoxRT-x86.dll
 LIB_KPROFILE    = $(PATH_STAGE_BIN)/kPrf2.dll
 LIB_VMM         = $(PATH_STAGE_BIN)/VBoxVMM.dll
 LIB_VMMRC       = $(PATH_STAGE_LIB)/VMMRCImp.lib
 LIB_REM         = $(PATH_STAGE_LIB)/VBoxREMImp.lib
 LIB_XPCOM       = $(PATH_STAGE_BIN)/VBoxXCOM.dll
 LIB_XPCOM_IMP   = $(PATH_STAGE_LIB)/VBoxXPCOMImp.lib
 VBOX_LIB_XPCOM_X86  = $(PATH_STAGE_BIN)/VBoxXPCOM-x86.dll
 LIB_DDU         = $(PATH_STAGE_BIN)/VBoxDDU.dll
 VBOX_OBJ_SYS0   = $(PATH_OBJ)/RuntimeR0/os2/sys0.obj
endif
ifeq ($(KBUILD_TARGET),win)
 LIB_RUNTIME     = $(PATH_STAGE_LIB)/VBoxRT.lib
 LIB_RUNTIME_EF  = #$(PATH_STAGE_LIB)/RuntimeEFCPP.lib
 VBOX_LIB_RUNTIME_X86   = $(PATH_STAGE_LIB)/VBoxRT-x86.lib
 LIB_KPROFILE    = $(PATH_STAGE_LIB)/kPrf2.lib
 LIB_VMM         = $(PATH_STAGE_LIB)/VBoxVMM.lib
 LIB_VMMRC       = $(PATH_OBJ)/VMMRC/VMMRC.lib
 LIB_REM         = $(PATH_STAGE_LIB)/VBoxREMImp.lib
 LIB_XPCOM       =
 LIB_XPCOM_IMP   =
 VBOX_LIB_XPCOM_X86 =
 LIB_DDU         = $(PATH_STAGE_LIB)/VBoxDDU.lib
endif
if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), win.amd64 linux.amd64)
 VBOX_LIB_VMM_LAZY      = $(PATH_STAGE_LIB)/VMMR3LazyImp$(VBOX_SUFF_LIB)
else
 VBOX_LIB_VMM_LAZY      = $(LIB_VMM)
endif
ifn1of ($(KBUILD_TARGET_ARCH), $(VBOX_SUPPORTED_HOST_ARCHS)) # Hack to build a couple of extpack things that thing they need the VMM lib.
 LIB_VMM           :=
 LIB_VMMRC         :=
 VBOX_LIB_VMM_LAZY :=
endif
VBOX_LIB_SUPHARDENED    = $(PATH_STAGE_LIB)/SUPR3HardenedStatic$(VBOX_SUFF_LIB)
VBOX_LIB_RUNTIME_STATIC = $(PATH_STAGE_LIB)/RuntimeR3$(VBOX_SUFF_LIB)

ifndef VBOX_WITH_REM
 LIB_REM :=
endif

# Python
ifndef VBOX_BLD_PYTHON
 if1of ($(KBUILD_HOST), win)
  VBOX_BLD_PYTHON := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS)/win.x86/python/v*/python$(HOSTSUFF_EXE))) \
  				   python-not-found.exe)
 else
  VBOX_BLD_PYTHON := $(firstword $(which python2.7$(HOSTSUFF_EXE)) $(which python2.6$(HOSTSUFF_EXE)) \
                                 $(which python$(HOSTSUFF_EXE)) $(which python3$(HOSTSUFF_EXE)) \
				   python-not-found)
 endif
endif
## For running python unittests in the validation kit.
VBOX_UNITTEST_PYTHON ?= $(VBOX_BLD_PYTHON)

#
# pylint setup, see https://www.pylint.org/.
#
# Disabled:
#   W0301 - Unnecessary semicolon.
#   W0511 - TODO/XXX/FIXME/+++.
#   W0603 - Using the global statement.
#   W0702 - No exception type(s) specified.
#   W0703 - Catch "Exception".
#   I0011 - Locally disabling XXXXX.
#   C0321 - More than one statement on a single line.
#   R0201 - Method could be a function.
#   C0326 - ????
#   W0123 - ????
#   C0330:bad-continuation - Wrong continued indentation (add X spaces).
#         * Triggering on perfectly legal comments in array initializers and stuff.
#   C0413:wrong-import-position - Import "YYYYY XXXXX" should be placed at the top of the module.
#         * False positives due to __copyright__, __version__, probably.
#   E0012:bad-option-value - Bad option value XXXXX.
#         * Newer pylint doesn't grok older warning disables in sources (e.g. W0142 in db.py). Wonderful!
#   I0012:locally-enabled - Locally enabling XXXXX.
#         * We temporarily disable stuff and then renabled it. Very tedious.
#
# Note! Yes, --max-branchs is a typo, but not by me.
#
# Note! Users of older pylint release (< 1.0) needs to define
#       VBOX_WITH_PYLINT_PRE_V1_0 in LocalConfig because they changed the
#       output arguments in an backwards incompatible way and added more
#       attribute regex options.
#
ifndef VBOX_PYLINT
 VBOX_PYLINT        := $(firstword $(which pylint-2.7) $(which pylint-2.6) $(which pylint2) $(which pylint))
 ifdef VBOX_PYLINT
  VBOX_PYLINT       := $(VBOX_BLD_PYTHON) $(VBOX_PYLINT)
 endif
endif
if !defined(VBOX_WITH_PYLINT) && defined(VBOX_PYLINT)
 VBOX_WITH_PYLINT := 1
 ifndef VBOX_PYLINT_VERSION
  ifdef VBOX_WITH_PYLINT_PRE_V1_0
   VBOX_PYLINT_VERSION =  9999
  else ifdef VBOX_WITH_PYLINT_V1_2_1_PLUS
   VBOX_PYLINT_VERSION = 10201
  else ifdef VBOX_WITH_PYLINT_V1_1_PLUS
   VBOX_PYLINT_VERSION = 10100
  else
   VBOX_PYLINT_VERSION = 10000
  endif
 endif
endif
VBOX_PYLINT_FLAGS = $(if-expr $(VBOX_PYLINT_VERSION) >= 10500,--reports=n,--report=n) \
	$(if-expr $(VBOX_PYLINT_VERSION) >= 10000\
	  ,--msg-template='{path}:{line}: <{msg_id}>({obj}:{symbol}): {msg}' \
	  ,--output-format=msvs --include-ids=y) \
	--persistent=n \
	--rcfile=$(PATH_ROOT)/tools/pylintrc \
	--max-line-length=130 \
	--max-attributes=32 \
	--max-branch$(if-expr $(VBOX_PYLINT_VERSION) >= 10000,e,)s=50 \
	--max-statements=100 \
	--max-returns=100 \
	--max-public-methods=139 \
	--max-args=9 \
	--max-module-lines=4096 \
       --max-locals=32 \
	$(if-expr $(VBOX_PYLINT_VERSION) >= 10500,--max-bool-expr=99,) \
       --min-public-methods=0 \
	--function-rgx='[a-z_][a-zA-Z0-9_]{2,40}$(DOLLAR)' \
	--method-rgx='[a-z_][a-zA-Z0-9_]{2,40}$(DOLLAR)' \
	--argument-rgx='([a-z_][a-zA-Z0-9_]{2,30}|rc|hr|s|c|ch|cx|cy|cb|fn)$(DOLLAR)' \
	--variable-rgx='([a-z_][a-zA-Z0-9_]{2,30}|rc|hr|s|c|ch|cx|cy|cb|fn)$(DOLLAR)' \
	--attr-rgx='([a-z_][a-zA-Z0-9_]{2,30}|rc|hr|o)$(DOLLAR)' \
	--module-rgx='(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(td[A-Z][a-zA-Z0-9]+)|(t(e|)st(-|)[a-zA-Z0-9]+))$(DOLLAR)' \
	--class-rgx='(td|)[A-Z_][a-zA-Z0-9_]+$(DOLLAR)' \
	--const-rgx='(g_(k|)[abcdefhmnpilorstu]+[A-Z][a-zA-Z0-9]+|[A-Z_][A-Z0-9_]+|__copyright__|__version__|__file__|__all__)$(DOLLAR)' \
	--good-names='i,j,k,t,o,c,e,ch,s,_' \
	$(if-expr $(VBOX_PYLINT_VERSION) >= 10000,--class-attribute-rgx='(k[abcdefhmnpilorstu]+[A-Z0-9][a-zA-Z0-9_]{0,32}|[A-Z_][A-Z0-9_]{2,32})',) \
	$(if-expr $(VBOX_PYLINT_VERSION) >= 10500,--max-nested-blocks=9,) \
       $(if-expr $(VBOX_PYLINT_VERSION) >= 10100,--disable=bad-whitespace,) \
       $(if-expr $(VBOX_PYLINT_VERSION) >= 10201,--disable=bad-continuation --disable=eval-used,) \
       $(if-expr $(VBOX_PYLINT_VERSION) >= 10201 && $(VBOX_PYLIN_VERSION) < 10500,--disable=bad-option-value,) \
       $(if-expr $(VBOX_PYLINT_VERSION) >= 10500,--disable=wrong-import-position --disable=E0012 --disable=locally-enabled,) \
       $(if-expr $(VBOX_PYLINT_VERSION) >= 10600,--disable=missing-docstring --disable=trailing-newlines --disable=ungrouped-imports,) \
       $(if-expr $(VBOX_PYLINT_VERSION) >= 10800,--disable=redundant-keyword-arg,) \
       $(if-expr $(VBOX_PYLINT_VERSION) >= 20000,--disable=useless-object-inheritance --disable=useless-return,) \
       $(if-expr $(VBOX_PYLINT_VERSION) >= 20400,--disable=import-outside-toplevel,) \
	--disable=unnecessary-semicolon,invalid-encoded-data,global-statement,bare-except,broad-except,multiple-statements,no-self-use,fixme \
	--disable=I0011 \
	--ignored-classes=testdriver.vboxcon \


# Define the macro for win path conversion.
ifndef VBOX_ONLY_SDK
  VBOX_FN_MAKE_WIN_PATH = $(subst /,\\,$(1))
else
  # on Wine Z: is always FS root
  VBOX_FN_MAKE_WIN_PATH = $(subst /,\\,$(patsubst /%,Z:/%,$(1)))
endif #!VBOX_ONLY_SDK

# The kprofile build automagically links with kProfile.
ifeq ($(KBUILD_TYPE),kprofile)
 LIB_RUNTIME += $(LIB_KPROFILE)
endif

# Enable C++ electric fence heap. (Warning: will easily run out of virtual memory / kernel stuff on Linux/Windows.)
ifdef VBOX_WITH_CPP_EF
 LIB_RUNTIME <= $(LIB_RUNTIME_EF)
endif

# Overridable libraries (unix).
LIB_PTHREAD      ?= pthread

# Xcursor (consider an SDK for this).
ifeq ($(VBOX_XCURSOR_LIBS),)
 ifeq ($(KBUILD_TARGET),solaris)
  VBOX_XCURSOR_LIBS := $(lastword $(wildcard $(KBUILD_DEVTOOLS_TRG)/libXcursor/*/lib/libXcursor.a))
  ifneq ($(VBOX_XCURSOR_LIBS),)
   VBOX_XCURSOR_INCS := $(patsubst %/lib/libXcursor.a,%/include, $(VBOX_XCURSOR_LIBS))
   VBOX_XCURSOR_LIBS += X11 Xrender Xfixes
  endif
 endif
 ifeq ($(VBOX_XCURSOR_LIBS),)
  VBOX_XCURSOR_LIBS := Xcursor
 endif
endif


# Intel ASL compiler for ACPI
VBOX_IASLCMD   ?= $(firstword $(wildcard $(KBUILD_DEVTOOLS_HST)/bin/iasl$(HOSTSUFF_EXE)) iasl$(HOSTSUFF_EXE))

# libxslt XSLT processor. (see PATH_TOOL_YASM for explanation why it's temporarily located in bin.)
ifeq ($(VBOX_XSLTPROC),)
 ifeq ($(KBUILD_HOST),win)
  VBOX_XSLTPROC := $(wildcard $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).$(KBUILD_HOST_ARCH)/libxslt/10128/bin/xsltproc.exe)
  ifeq ($(VBOX_XSLTPROC),)
   VBOX_XSLTPROC := $(KBUILD_DEVTOOLS)/win.x86/bin/xsltproc.exe
  endif
 else ifeq ($(KBUILD_HOST),os2)
  VBOX_XSLTPROC  := BEGINLIBPATH="$(KBUILD_DEVTOOLS_HST)/bin;$$BEGINLIBPATH" $(KBUILD_DEVTOOLS_HST)/bin/xsltproc.exe
 else ifeq ($(KBUILD_HOST),haiku)
  VBOX_XSLTPROC  := $(KBUILD_DEVTOOLS)/haiku.x86/bin/xsltproc
 else
  VBOX_XSLTPROC  := xsltproc$(HOSTSUFF_EXE)
 endif
endif

# bin2c (convert binary files into C arrays)
VBOX_BIN2C      ?= $(PATH_OBJ)/bin2c/bin2c$(HOSTSUFF_EXE)

# RTManifest (extension pack manifest utility)
VBOX_RTMANIFEST ?= $(PATH_OBJ)/bldRTManifest/bldRTManifest$(HOSTSUFF_EXE)

# RTSignTool (certificate extraction tool)
VBOX_RTSIGNTOOL ?= $(PATH_OBJ)/bldRTSignTool/bldRTSignTool$(HOSTSUFF_EXE)

# RTIsoMaker (our own ISO maker).
VBOX_RTISOMAKER  ?= $(PATH_OBJ)/bldRTIsoMaker/bldRTIsoMaker$(HOSTSUFF_EXE)

# RTLdrCheckImports (checks imports against oldest supported OS version (GAs typically))
VBOX_RTLDRCHECKIMPORTS ?= $(PATH_OBJ)/bldRTLdrCheckImports/bldRTLdrCheckImports$(HOSTSUFF_EXE)

# VBoxCmp (simple /bin/cmp with more sensible output)
VBOX_VBOXCMP    ?= $(PATH_OBJ)/VBoxCmp/VBoxCmp$(HOSTSUFF_EXE)

# VBoxCPP (special purpose C preprocessor)
VBOX_VBOXCPP    ?= $(PATH_OBJ)/VBoxCPP/VBoxCPP$(HOSTSUFF_EXE)

# VBoxTpG (tracepoint generator)
VBOX_VBOXTPG    ?= $(PATH_OBJ)/VBoxTpG/VBoxTpG$(HOSTSUFF_EXE)

# VBoxPeSetVersion (changes the minimum OS version of an image)
VBOX_PE_SET_VERSION ?= $(PATH_OBJ)/VBoxPeSetVersion/VBoxPeSetVersion$(HOSTSUFF_EXE)

# Visual C++ EditBin.exe.
VBOX_VCC_EDITBIN = $(if $(PATH_TOOL_$(VBOX_VCC_TOOL)_BIN),$(PATH_TOOL_$(VBOX_VCC_TOOL)_BIN)/,)editbin.exe /NoLogo

# filesplitter (splits java files)
VBOX_FILESPLIT  ?= $(PATH_OBJ)/filesplitter/filesplitter$(HOSTSUFF_EXE)

# biossums (set BIOS checksums)
VBOX_BIOSSUMS   ?= $(PATH_OBJ)/biossums/biossums$(HOSTSUFF_EXE)

# MakeAlternativeSource (for BIOSes)
VBOX_MAKE_ALTERNATIVE_SOURCE ?= $(PATH_OBJ)/MakeAlternativeSource/MakeAlternativeSource$(HOSTSUFF_EXE)

# VBoxDef2LazyLoad (lazy dynamic library loader assembly generator)
VBOX_DEF_2_LAZY_LOAD ?= $(PATH_OBJ)/VBoxDef2LazyLoad/VBoxDef2LazyLoad$(HOSTSUFF_EXE)

# VBoxCheckImports (checks what we imports from on windows)
VBOX_CHECK_IMPORTS ?= $(PATH_OBJ)/VBoxCheckImports/VBoxCheckImports$(HOSTSUFF_EXE)

# VBoxEditCoffLib (symbol name tweaking for VBoxSF on windows)
VBOX_EDIT_COFF_LIB ?= $(PATH_OBJ)/VBoxEditCoffLib/VBoxEditCoffLib$(HOSTSUFF_EXE)

# GNU tar if present.
if1of ($(KBUILD_TARGET), linux os2 win)
 VBOX_GTAR ?= tar
else if1of ($(KBUILD_TARGET), freebsd netbsd solaris)
 VBOX_GTAR ?= gtar
endif

# zip
VBOX_ZIP ?= zip$(HOSTSUFF_EXE)

ifeq ($(KBUILD_TARGET),win)
 ifeq ($(KBUILD_TARGET_ARCH),x86) # Normally we should test for KBUILD_HOST_ARCH but we only require MINGWW64 for 64-bit _targets_
  VBOX_NM ?= $(PATH_TOOL_MINGW32)/bin/nm.exe -p
 else
  VBOX_NM ?= $(PATH_TOOL_MINGWW64)/bin/nm.exe -p
 endif
else ifeq ($(KBUILD_HOST),darwin) # Xcode 7.3.1 nm doesn't like -t, and -x behaves very differently.  Throwing in -B (bsd) to make sure.
 VBOX_NM ?= $(subst $(REDIRECT_INT),$(REDIRECT_EXT),$(TOOL_$(VBOX_GCC_TOOL)_ENV_SETUP) $(PATH_TOOL_$(VBOX_GCC_TOOL)_TOOLCHAIN_BIN_SLASH)nm) -p \
        $(if-expr $(VBOX_XCODE_VERSION_MAJOR) > 7 || ($(VBOX_XCODE_VERSION_MAJOR) == 7 && $(VBOX_XCODE_VERSION_MINOR) >= 3),-B,)
else
 VBOX_NM ?= nm -p -t x
endif

# Makeself for the linux installers.
VBOX_MAKESELF  ?= $(KBUILD_DEVTOOLS)/common/makeself/v2.1.5/makeself.sh

# Microsoft HTML Help Workshop.
VBOX_PATH_HTML_HELP_WORKSHOP ?= $(KBUILD_DEVTOOLS)/win.x86/HTML_Help_Workshop/v1.3/

# Path to the null soft installer.
VBOX_PATH_NSIS ?= $(KBUILD_DEVTOOLS)/win.x86/nsis/v3.04-log

# Path to AutoIt3.
VBOX_PATH_AUTOIT3 ?= $(KBUILD_DEVTOOLS)/win.x86/autoit/v3.2.10.0

# Windows install tools...
# Note! The scripts has been moved to Bin in v8.0.
VBOX_PATH_WIX       ?= $(KBUILD_DEVTOOLS)/win.x86/wix/v3.8.1128.0
VBOX_PATH_MSITRAN   ?= $(KBUILD_DEVTOOLS)/win.x86/sdk/v7.1/Bin/MsiTran.Exe
VBOX_PATH_MSIDB     ?= $(KBUILD_DEVTOOLS)/win.x86/sdk/v7.1/Bin/MsiDb.Exe
VBOX_PATH_WISUBSTG  ?= $(KBUILD_DEVTOOLS)/win.x86/sdk/v7.1/Samples/sysmgmt/msi/scripts/WiSubStg.vbs
VBOX_PATH_WISUMINFO ?= $(KBUILD_DEVTOOLS)/win.x86/sdk/v7.1/Samples/sysmgmt/msi/scripts/WiSumInf.vbs
VBOX_PATH_DIFX      ?= $(KBUILD_DEVTOOLS)/win.$(KBUILD_TARGET_ARCH)/DIFx/v2.1-r3

ifdef VBOX_OSE ## @todo try get rid of this crap! People can use the latest and greatest Yasm release, no need to check in the binary for OSE.
 # We need to export YASM for OSE, but since it was converted to .zip we need to
 # allow for the location used by the zip to be properly cleaned up first.
 if1of ($(KBUILD_HOST).$(KBUILD_HOST_ARCH), linux.x86 solaris.x86 win.x86)
  PATH_TOOL_YASM ?= $(KBUILD_DEVTOOLS_HST)/bin
 endif
endif

# The Microsoft IDL compiler (the SDK build needs this on non-Windows).
VBOX_WIN_MIDL ?= $(EXEC_X86_WIN32) $(call VBOX_FN_MAKE_WIN_PATH,$(firstword $(wildcard $(addsuffix /[Mm][Ii][Dd][Ll].[Ee][Xx][Ee], \
	$(KBUILD_DEVTOOLS)/win.x86/sdk/v7.1/Bin$(if-expr "$(KBUILD_HOST).$(KBUILD_HOST_ARCH)" == "win.amd64",/x64,) \
	$(KBUILD_DEVTOOLS)/win.x86/ddk/7600.16385.1/bin/x86 \
	$(KBUILD_DEVTOOLS)/win.x86/bin \
	$(PATH_SDK_$(VBOX_WINPSDK)_BIN) \
	$(PATH_SDK_$(VBOX_WINPSDK)) \
	$(PATH_SDK_WINPSDK_BIN) \
	$(PATH_SDK_WINPSDK) \
	)) Sorry_Cannot_Find_The_Midl_Compiler_In_The_PSDK))

# XPCOM setup for all but win32.
ifneq ($(KBUILD_TARGET),win)
 VBOX_WITH_XPCOM      = 1
 # if updating, also update xpidl_INST var in src/libs/xpcom18a4/Makefile.kmk
 VBOX_XPIDL          ?= $(PATH_STAGE_BIN)/xpidl$(HOSTSUFF_EXE)
 ifeq ($(KBUILD_TARGET),os2)
  VBOX_XPIDL_ENV      = BEGINLIBPATH="$(dir $(VBOX_XPIDL));$$BEGINLIBPATH"$(SP)
 endif
 VBOX_PATH_XPCOM_IDL ?= $(VBOX_PATH_SDK)/bindings/xpcom/idl
 VBOX_XPCOM_INCS     ?=				\
 	$(VBOX_PATH_SDK)/bindings/xpcom/include	\
 	$(VBOX_PATH_SDK)/bindings/xpcom/include/xpcom	\
 	$(VBOX_PATH_SDK)/bindings/xpcom/include/string	\
 	$(VBOX_PATH_SDK)/bindings/xpcom/include/xpcom	\
 	$(VBOX_PATH_SDK)/bindings/xpcom/include/nsprpub \
 	$(VBOX_PATH_SDK)/bindings/xpcom/include/ipcd
 ifneq ($(KBUILD_TARGET),os2)
  # libIDL-config (for xpcom18a4)
  ifeq ($(origin VBOX_LIBIDL_CONFIG),undefined)
   ifeq ($(KBUILD_HOST),solaris)
    VBOX_LIBIDL_CONFIG_FALLBACK = $(lastword $(wildcard $(KBUILD_DEVTOOLS)/solaris.amd64/libIDL/*/bin/libIDL-config-2))
   endif
   export VBOX_LIBIDL_CONFIG := $(firstword $(which libIDL-config-2 libIDL-config $(VBOX_LIBIDL_CONFIG_FALLBACK)) libIDL-config-2-not-found)
  endif
 endif
endif

# The X11 LIBPATH. (The amd64 hack is for RHEL4.)
ifeq ($(KBUILD_TARGET_ARCH),amd64)
 VBOX_LIBPATH_X11 ?= /usr/X11R6/lib64 /usr/X11R6/lib
else
 VBOX_LIBPATH_X11 ?= /usr/X11R6/lib
endif

# 32bit X11 LIBPATH for building 32bit guest additions
VBOX_LIBPATH32_X11 ?= /usr/X11R6/lib32 /usr/X11R6/lib

# Good windows shell.
VBOX_GOOD_COMSPEC = $(subst \,/,$(SystemRoot))/System32/cmd.exe
VBOX_GOOD_COMSPEC_BS ?= $(subst /,\,$(VBOX_GOOD_COMSPEC))

#
# Macros dealing with the darwin version we're targeting.
# The DEF in VBOX_DEF_MACOSX_VERSION_MIN mean default.  The default min
# version is assumed to be the
#
ifeq ($(KBUILD_TARGET),darwin)
 ifdef VBOX_WITH_NEW_XCODE
  VBOX_DEF_MACOSX_VERSION_MIN ?= 10.9
 else
  VBOX_DEF_MACOSX_VERSION_MIN ?= 10.6
 endif

 ifdef VBOX_WITH_NEW_XCODE
  # Use the tool path of the compiler (it's clang, not gcc in this instance).
  include $(KBUILD_TOOL_PATHS)/$(VBOX_GCC_TOOL).kmk
  VBOX_PATH_MACOSX_DEVEL_ROOT := $(PATH_TOOL_$(VBOX_GCC_TOOL))
 else
  # Check for the Xcode 4.1 bits in tools/darwin.x86.
  if   !defined(VBOX_WITH_MACOSX_COMPILERS_FROM_DEVEL) \
    && !defined(VBOX_XCODE_VERSION) \
    && exists "$(KBUILD_DEVTOOLS)/darwin.x86/xcode/v4.1"
   VBOX_WITH_MACOSX_COMPILERS_FROM_DEVEL := 1
   VBOX_PATH_MACOSX_DEVEL_ROOT := $(KBUILD_DEVTOOLS)/darwin.x86/xcode/v4.1
   VBOX_XCODE_VERSION := 4.1
  endif
 endif

 # Fallback - system / LocalConfig.kmk.
 ifdef VBOX_WITH_NEW_XCODE
  ifndef VBOX_PATH_MACOSX_DEVEL_ROOT
   VBOX_PATH_MACOSX_DEVEL_ROOT := $(firstword $(wildcard /Applications/Xcode.app/Contents/Developer /Developer))
  endif
  ifndef VBOX_PATH_MACOSX_SDK_ROOT
   VBOX_PATH_MACOSX_SDK_ROOT := $(firstword $(wildcard \
   		$(PATH_TOOL_$(VBOX_GCC_TOOL)_SDKS) \
   		$(VBOX_PATH_MACOSX_DEVEL_ROOT)/SDKs/. \
   		/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/. \
   		/Developer/SDKs/. ))
  endif
  ifndef VBOX_PATH_MACOSX_TOOLCHAIN_ROOT
   VBOX_PATH_MACOSX_TOOLCHAIN_ROOT := $(firstword $(wildcard \
   		$(PATH_TOOL_$(VBOX_GCC_TOOL)_TOOLCHAIN) \
   		$(VBOX_PATH_MACOSX_DEVEL_ROOT)/Library/Developer/CommandLineTools/. \
   		$(VBOX_PATH_MACOSX_DEVEL_ROOT)/Toolchains/XcodeDefault.xctoolchain/. \
   		/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/. \
               /Library/Developer/CommandLineTools/. \
   		) /. )
  endif
 else
  VBOX_PATH_MACOSX_DEVEL_ROOT     ?= /Developer
  VBOX_PATH_MACOSX_SDK_ROOT       ?= $(VBOX_PATH_MACOSX_DEVEL_ROOT)/SDKs
  VBOX_PATH_MACOSX_TOOLCHAIN_ROOT ?= $(VBOX_PATH_MACOSX_DEVEL_ROOT)
 endif

# Where to search for SDKs.
VBOX_PATH_MACOSX_SDK_ROOT_DIRS ?= \
	$(VBOX_PATH_MACOSX_SDK_ROOT) \
	$(KBUILD_DEVTOOLS)/darwin.x86/SDKs/ \
	$(KBUILD_DEVTOOLS)/darwin.amd64/SDKs/ \
	$(KBUILD_DEVTOOLS)/darwin.x86/xcode/v4.1/SDKs \
	$(KBUILD_DEVTOOLS)/darwin.x86/xcode/v3.2.6/SDKs

 # Figure the default SDK location and obsolete linker tricks.
 ifeq ($(VBOX_DEF_MACOSX_VERSION_MIN),10.4)
  ifeq ($(origin VBOX_DARWIN_CLASSIC_LINKER),undefined)
   VBOX_DARWIN_CLASSIC_LINKER := $(shell ld -v 2>&1 )
   ifneq ($(filter ld64%, $(subst :, , $(VBOX_DARWIN_CLASSIC_LINKER))),)
    export VBOX_DARWIN_CLASSIC_LINKER := -Wl,-classic_linker
   else
    export VBOX_DARWIN_CLASSIC_LINKER :=
   endif
  endif
  ifndef VBOX_PATH_MACOSX_SDK
VBOX_PATH_MACOSX_SDK := $(firstword $(wildcard $(addsuffix /MacOSX$(VBOX_DEF_MACOSX_VERSION_MIN)u.sdk, $(VBOX_PATH_MACOSX_SDK_ROOT_DIRS))) \
	$(VBOX_PATH_MACOSX_SDK_ROOT)/MacOSX$(VBOX_DEF_MACOSX_VERSION_MIN)u.sdk )
  endif
 else
  ifndef VBOX_PATH_MACOSX_SDK
VBOX_PATH_MACOSX_SDK := $(firstword $(wildcard $(addsuffix /MacOSX$(VBOX_DEF_MACOSX_VERSION_MIN).sdk, $(VBOX_PATH_MACOSX_SDK_ROOT_DIRS))) \
	$(VBOX_PATH_MACOSX_SDK_ROOT)/MacOSX$(VBOX_DEF_MACOSX_VERSION_MIN).sdk )
  endif
 endif

 ## The Xcode version.
 ifeq ($(KBUILD_HOST),darwin)
  ifndef VBOX_XCODE_VERSION
   ifdef VBOX_WITH_NEW_XCODE
    VBOX_XCODE_VERSION := $(shell exec $(VBOX_PATH_MACOSX_DEVEL_ROOT)/usr/bin/xcodebuild -version 2>&1)
    ifneq ($(pos Symbol not found,$(VBOX_XCODE_VERSION)),0) # Try detect unresolved symbol running Xcode 6.2 on Catalina.
     VBOX_XCODE_VERSION = 6.2
    else
     VBOX_XCODE_VERSION := $(word 2, $(VBOX_XCODE_VERSION))
    endif
   else ifdef VBOX_WITH_MACOSX_COMPILERS_FROM_DEVEL
    VBOX_XCODE_VERSION := $(word 2, $(shell $(VBOX_PATH_MACOSX_DEVEL_ROOT)/usr/bin/xcodebuild -version))
   else
    VBOX_XCODE_VERSION := $(word 2, $(shell xcodebuild -version))
   endif
   ifeq ($(strip $(VBOX_XCODE_VERSION)),)
    ifdef VBOX_WITH_NEW_XCODE
     VBOX_XCODE_VERSION := 6.2
    else
     VBOX_XCODE_VERSION := 4.1
    endif
   endif
  endif
  ifdef VBOX_WITH_NEW_XCODE
   ifdef KBUILD_USE_KOBJCACHE
    $(warning KBUILD_USE_KOBJCACHE does _not_ currently work with this version of Xcode)
   endif
  else
   ifeq ($(VBOX_XCODE_VERSION),4.2)
    $(warning Xcode 4.2 is not able to correctly build the recompiler!)
    $(warning Please downgrade to Xcode 4.1 if you want a working VMM!)
   endif
  endif
 else
  VBOX_XCODE_VERSION ?= 4.1
 endif
 VBOX_XCODE_VERSION_MAJOR := $(word 1, $(subst ., ,$(VBOX_XCODE_VERSION)))
 VBOX_XCODE_VERSION_MINOR := $(word 2, $(subst ., ,$(VBOX_XCODE_VERSION)))
 VBOX_XCODE_VERSION       := $(VBOX_XCODE_VERSION_MAJOR).$(VBOX_XCODE_VERSION_MINOR)

 ifeq ($(KBUILD_TARGET_ARCH),x86)
  if1of ($(VBOX_DEF_MACOSX_VERSION_MIN), 10.4 10.5)
   VBOX_DARWIN_NO_COMPACT_LINKEDIT ?= $(VBOX_LD_no_compact_linkedit)
   TOOL_GXX4MACHO_SUFFIX ?= -4.0
  endif
 else
  if $(VBOX_XCODE_VERSION_MAJOR) < 4 && "$(VBOX_XCODE_VERSION)" != "3.2"
   ifeq ($(PATH_CURRENT),$(PATH_ROOT)/tools)
    $(warning VBox: 64-bit darwin builds require Xcode 3.2 or later, you have $(VBOX_XCODE_VERSION))
   else
    $(error VBox: 64-bit darwin builds require Xcode 3.2 or later, you have $(VBOX_XCODE_VERSION))
   endif
  endif
 endif
 ifdef VBOX_WITH_NEW_XCODE
  if $(KBUILD_HOST_VERSION_MAJOR) >= 18 # HACK ALERT! dtrace doesn't work on Mojave if we specify our Xcode 6.2 environment.
   override TOOL_StandardDTrace_DTRACE := dtrace "-xcpppath=$(VBOX_PATH_MACOSX_DEVEL_ROOT)/usr/bin/gcc"
  else
   override TOOL_StandardDTrace_DTRACE := $(TOOL_$(VBOX_GCC_TOOL)_ENV_SETUP) dtrace "-xcpppath=$(VBOX_PATH_MACOSX_DEVEL_ROOT)/usr/bin/gcc"
  endif
  export PATH:=$(VBOX_PATH_MACOSX_SDK)/usr/bin:$(PATH)
 else
  if  $(VBOX_XCODE_VERSION_MAJOR) > 4 || ($(VBOX_XCODE_VERSION_MAJOR) == 4 && $(VBOX_XCODE_VERSION_MINOR) >= 2)
   TOOL_GXX4MACHO_PREFIX ?= llvm-
  endif
  if  $(VBOX_XCODE_VERSION_MAJOR) < 5
   TOOL_GXX4MACHO_SUFFIX ?= -4.2
  endif
  VBOX_DARWIN_NO_COMPACT_LINKEDIT ?=

  TOOL_GCC4MACHO_SUFFIX ?= $(TOOL_GXX4MACHO_SUFFIX)$(HOSTSUFF_EXE)
  TOOL_GCC4MACHO_PREFIX ?= $(TOOL_GXX4MACHO_PREFIX)
  if defined(VBOX_WITH_MACOSX_COMPILERS_FROM_DEVEL)
   TOOL_GCC4MACHO_PREFIX := $(VBOX_PATH_MACOSX_TOOLCHAIN_ROOT)/usr/bin/$(TOOL_GCC4MACHO_PREFIX)
   TOOL_GXX4MACHO_PREFIX := $(VBOX_PATH_MACOSX_TOOLCHAIN_ROOT)/usr/bin/$(TOOL_GXX4MACHO_PREFIX)
   TOOL_GCC4MACHO_SUFFIX := $(TOOL_GCC4MACHO_SUFFIX) -isysroot $(VBOX_PATH_MACOSX_SDK)
   TOOL_GXX4MACHO_SUFFIX := $(TOOL_GXX4MACHO_SUFFIX) -isysroot $(VBOX_PATH_MACOSX_SDK)
   ifndef SVN  # must expand first so we won't be using old svn.
    SVN := $(firstword $(which svn) svn)
   endif
   if  $(VBOX_XCODE_VERSION_MAJOR) > 4 || ($(VBOX_XCODE_VERSION_MAJOR) == 4 && $(VBOX_XCODE_VERSION_MINOR) >= 2)
    export PATH:=$(VBOX_PATH_MACOSX_DEVEL_ROOT)/usr/bin/:$(VBOX_PATH_MACOSX_SDK)/usr/bin:$(VBOX_PATH_MACOSX_TOOLCHAIN_ROOT)/usr/bin:$(PATH)
    export DEVELOPER_DIR:=$(VBOX_PATH_MACOSX_DEVEL_ROOT)
   else
    export PATH:=$(VBOX_PATH_MACOSX_DEVEL_ROOT)/usr/bin/:$(PATH)
   endif
   TOOL_GXX32_CC  = $(TOOL_GCC4MACHO_PREFIX)gcc$(TOOL_GCC4MACHO_SUFFIX) -m32
   TOOL_GXX32_CXX = $(TOOL_GCC4MACHO_PREFIX)g++$(TOOL_GCC4MACHO_SUFFIX) -m32
   TOOL_GXX32_LD  = $(TOOL_GXX32_CXX)
   override TOOL_StandardDTrace_DTRACE := dtrace "-xcpppath=$(TOOL_GCC4MACHO_PREFIX)cpp-4.2"
  endif
  if  $(VBOX_XCODE_VERSION_MAJOR) < 5
   ## @todo WTF do we do the -m32/64 stuff here for these compilers? Also the visibility should be elsewhere...
   TOOL_GXX4MACHO_OBJC   = $(TOOL_GCC4MACHO_PREFIX)gcc$(TOOL_GCC4MACHO_SUFFIX) $(if-expr $(KBUILD_TARGET_ARCH) == "x86",-m32,-m64) -fvisibility=hidden
   TOOL_GXX4MACHO_OBJCXX = $(TOOL_GCC4MACHO_PREFIX)gcc$(TOOL_GCC4MACHO_SUFFIX) $(if-expr $(KBUILD_TARGET_ARCH) == "x86",-m32,-m64) -fvisibility=hidden -fvisibility-inlines-hidden
  endif
 endif

 VBOX_DARWIN_DEF_SDK_DEFS        := MAC_OS_X_VERSION_MIN_REQUIRED=$(subst .,,$(VBOX_DEF_MACOSX_VERSION_MIN))0 \
                                    MAC_OS_X_VERSION_MAX_ALLOWED=$(subst .,,$(VBOX_DEF_MACOSX_VERSION_MIN))0
 VBOX_DARWIN_DEF_SDK_CFLAGS      := -mmacosx-version-min=$(VBOX_DEF_MACOSX_VERSION_MIN) -isysroot $(VBOX_PATH_MACOSX_SDK)
 VBOX_DARWIN_DEF_SDK_CXXFLAGS    := -mmacosx-version-min=$(VBOX_DEF_MACOSX_VERSION_MIN) -isysroot $(VBOX_PATH_MACOSX_SDK)
 VBOX_DARWIN_DEF_SDK_OBJCFLAGS   := -mmacosx-version-min=$(VBOX_DEF_MACOSX_VERSION_MIN) -isysroot $(VBOX_PATH_MACOSX_SDK)
 VBOX_DARWIN_DEF_SDK_OBJCXXFLAGS := -mmacosx-version-min=$(VBOX_DEF_MACOSX_VERSION_MIN) -isysroot $(VBOX_PATH_MACOSX_SDK)
 VBOX_DARWIN_DEF_SDK_LDFLAGS      = -mmacosx-version-min=$(VBOX_DEF_MACOSX_VERSION_MIN) -Wl,-syslibroot,$(VBOX_PATH_MACOSX_SDK) \
	-Wl,-headerpad_max_install_names $(VBOX_DARWIN_CLASSIC_LINKER) $(VBOX_DARWIN_NO_COMPACT_LINKEDIT)

 # specific versions.
 ## @todo s/VBOX_DARWIN_DEF_SDK_10/VBOX_DARWIN_SDK_10/g

 if1of ($(VBOX_DEF_MACOSX_VERSION_MIN), 10.4) # classic linker detection is bust otherwise
  VBOX_PATH_MACOSX_SDK_10_4            ?= $(VBOX_PATH_MACOSX_SDK_ROOT)/MacOSX10.4u.sdk
  VBOX_DARWIN_DEF_SDK_10_4_DEFS        := MAC_OS_X_VERSION_MIN_REQUIRED=1040 MAC_OS_X_VERSION_MAX_ALLOWED=1040
  VBOX_DARWIN_DEF_SDK_10_4_CFLAGS      := -mmacosx-version-min=10.4 -isysroot $(VBOX_PATH_MACOSX_SDK_10_4)
  VBOX_DARWIN_DEF_SDK_10_4_CXXFLAGS    := -mmacosx-version-min=10.4 -isysroot $(VBOX_PATH_MACOSX_SDK_10_4)
  VBOX_DARWIN_DEF_SDK_10_4_OBJCFLAGS   := -mmacosx-version-min=10.4 -isysroot $(VBOX_PATH_MACOSX_SDK_10_4)
  VBOX_DARWIN_DEF_SDK_10_4_OBJCXXFLAGS := -mmacosx-version-min=10.4 -isysroot $(VBOX_PATH_MACOSX_SDK_10_4)
  VBOX_DARWIN_DEF_SDK_10_4_LDFLAGS     := -mmacosx-version-min=10.4 -Wl,-syslibroot,$(VBOX_PATH_MACOSX_SDK_10_4) \
	-Wl,-headerpad_max_install_names $(VBOX_DARWIN_CLASSIC_LINKER)
 else
  VBOX_PATH_MACOSX_SDK_10_4          = $(error VBox: $(if $(target),$(target): ,)Using 10.4 SDK)
  VBOX_DARWIN_DEF_SDK_10_4_CXXFLAGS  = $(error VBox: $(if $(target),$(target): ,)Using 10.4 SDK)
  VBOX_DARWIN_DEF_SDK_10_4_LDFLAGS   = $(error VBox: $(if $(target),$(target): ,)Using 10.4 SDK)
 endif

 if1of ($(VBOX_DEF_MACOSX_VERSION_MIN), 10.4 10.5)
  VBOX_PATH_MACOSX_SDK_10_5            ?= $(VBOX_PATH_MACOSX_SDK_ROOT)/MacOSX10.5.sdk
  VBOX_DARWIN_DEF_SDK_10_5_DEFS        := MAC_OS_X_VERSION_MIN_REQUIRED=1050 MAC_OS_X_VERSION_MAX_ALLOWED=1050
  VBOX_DARWIN_DEF_SDK_10_5_CFLAGS      := -mmacosx-version-min=10.5 -isysroot $(VBOX_PATH_MACOSX_SDK_10_5)
  VBOX_DARWIN_DEF_SDK_10_5_CXXFLAGS    := -mmacosx-version-min=10.5 -isysroot $(VBOX_PATH_MACOSX_SDK_10_5)
  VBOX_DARWIN_DEF_SDK_10_5_OBJCFLAGS   := -mmacosx-version-min=10.5 -isysroot $(VBOX_PATH_MACOSX_SDK_10_5)
  VBOX_DARWIN_DEF_SDK_10_5_OBJCXXFLAGS := -mmacosx-version-min=10.5 -isysroot $(VBOX_PATH_MACOSX_SDK_10_5)
  VBOX_DARWIN_DEF_SDK_10_5_LDFLAGS     := -mmacosx-version-min=10.5 -Wl,-syslibroot,$(VBOX_PATH_MACOSX_SDK_10_5) \
	-Wl,-headerpad_max_install_names $(VBOX_DARWIN_NO_COMPACT_LINKEDIT)
 else
  VBOX_PATH_MACOSX_SDK_10_5          = $(error VBox: $(if $(target),$(target): ,)Using 10.5 SDK)
  VBOX_DARWIN_DEF_SDK_10_5_CXXFLAGS  = $(error VBox: $(if $(target),$(target): ,)Using 10.5 SDK)
  VBOX_DARWIN_DEF_SDK_10_5_LDFLAGS   = $(error VBox: $(if $(target),$(target): ,)Using 10.5 SDK)
 endif

 if1of ($(VBOX_DEF_MACOSX_VERSION_MIN), 10.4 10.5 10.6)
  VBOX_PATH_MACOSX_SDK_10_6            ?= $(VBOX_PATH_MACOSX_SDK_ROOT)/MacOSX10.6.sdk
  VBOX_DARWIN_DEF_SDK_10_6_DEFS        := MAC_OS_X_VERSION_MIN_REQUIRED=1060 MAC_OS_X_VERSION_MAX_ALLOWED=1060
  VBOX_DARWIN_DEF_SDK_10_6_CFLAGS      := -mmacosx-version-min=10.6 -isysroot $(VBOX_PATH_MACOSX_SDK_10_6)
  VBOX_DARWIN_DEF_SDK_10_6_CXXFLAGS    := -mmacosx-version-min=10.6 -isysroot $(VBOX_PATH_MACOSX_SDK_10_6)
  VBOX_DARWIN_DEF_SDK_10_6_OBJCFLAGS   := -mmacosx-version-min=10.6 -isysroot $(VBOX_PATH_MACOSX_SDK_10_6)
  VBOX_DARWIN_DEF_SDK_10_6_OBJCXXFLAGS := -mmacosx-version-min=10.6 -isysroot $(VBOX_PATH_MACOSX_SDK_10_6)
  VBOX_DARWIN_DEF_SDK_10_6_LDFLAGS     := -mmacosx-version-min=10.6 -Wl,-syslibroot,$(VBOX_PATH_MACOSX_SDK_10_6) \
         -Wl,-headerpad_max_install_names
 else
  VBOX_PATH_MACOSX_SDK_10_6          = $(error VBox: $(if $(target),$(target): ,)Using 10.6 SDK)
  VBOX_DARWIN_DEF_SDK_10_6_CXXFLAGS  = $(error VBox: $(if $(target),$(target): ,)Using 10.6 SDK)
  VBOX_DARWIN_DEF_SDK_10_6_LDFLAGS   = $(error VBox: $(if $(target),$(target): ,)Using 10.6 SDK)
 endif

 if1of ($(VBOX_DEF_MACOSX_VERSION_MIN), 10.4 10.5 10.6 10.7)
  ifndef VBOX_PATH_MACOSX_SDK_10_7
   ifneq ($(wildcard $(VBOX_PATH_MACOSX_SDK_ROOT)/MacOSX10.7.sdk),)
    VBOX_PATH_MACOSX_SDK_10_7           = $(VBOX_PATH_MACOSX_SDK_ROOT)/MacOSX10.7.sdk
   else
    VBOX_PATH_MACOSX_SDK_10_7           = $(KBUILD_DEVTOOLS)/darwin.x86/SDKs/MacOSX10.7.sdk
   endif
  endif
  VBOX_DARWIN_DEF_SDK_10_7_DEFS        := MAC_OS_X_VERSION_MIN_REQUIRED=1070 MAC_OS_X_VERSION_MAX_ALLOWED=1070
  VBOX_DARWIN_DEF_SDK_10_7_CFLAGS      := -mmacosx-version-min=10.7 -isysroot $(VBOX_PATH_MACOSX_SDK_10_7)
  VBOX_DARWIN_DEF_SDK_10_7_CXXFLAGS    := -mmacosx-version-min=10.7 -isysroot $(VBOX_PATH_MACOSX_SDK_10_7)
  VBOX_DARWIN_DEF_SDK_10_7_OBJCFLAGS   := -mmacosx-version-min=10.7 -isysroot $(VBOX_PATH_MACOSX_SDK_10_7)
  VBOX_DARWIN_DEF_SDK_10_7_OBJCXXFLAGS := -mmacosx-version-min=10.7 -isysroot $(VBOX_PATH_MACOSX_SDK_10_7)
  VBOX_DARWIN_DEF_SDK_10_7_LDFLAGS     := -mmacosx-version-min=10.7 -Wl,-syslibroot,$(VBOX_PATH_MACOSX_SDK_10_7) \
         -Wl,-headerpad_max_install_names
 else
  VBOX_PATH_MACOSX_SDK_10_7          = $(error VBox: $(if $(target),$(target): ,)Using 10.7 SDK)
  VBOX_DARWIN_DEF_SDK_10_7_CXXFLAGS  = $(error VBox: $(if $(target),$(target): ,)Using 10.7 SDK)
  VBOX_DARWIN_DEF_SDK_10_7_LDFLAGS   = $(error VBox: $(if $(target),$(target): ,)Using 10.7 SDK)
 endif

 #
 # Use bison and flex from Xcode to avoid linking issues (bison).
 #
 TOOL_BISON_YACC ?= $(TOOL_$(VBOX_GCC_TOOL)_ENV_SETUP) $(PATH_TOOL_$(VBOX_GCC_TOOL)_TOOLCHAIN_BIN_SLASH)bison
 TOOL_FLEX_LEX   ?= $(TOOL_$(VBOX_GCC_TOOL)_ENV_SETUP) $(PATH_TOOL_$(VBOX_GCC_TOOL)_TOOLCHAIN_BIN_SLASH)flex

endif # target=darwin

#
# Macro switching between @executable_path, @rpath and /Applications/VirtualBox.app
# depending on whether the build is hardened or not (dylib install_name).
#
ifeq ($(KBUILD_TARGET),darwin)
 ifndef VBOX_DYLD_EXECUTABLE_PATH
  ifdef VBOX_WITH_HARDENING
   VBOX_DYLD_EXECUTABLE_PATH = $(VBOX_PATH_APP_PRIVATE_ARCH)
  else if 0
   VBOX_DYLD_EXECUTABLE_PATH = @executable_path
  else
   VBOX_DYLD_EXECUTABLE_PATH = @rpath
   VBOX_WITH_RELATIVE_RUNPATH = @loader_path/
  endif
 endif
endif

#
# Check for incompatible rpath combinations.
#
if defined(VBOX_WITH_RUNPATH) && defined(VBOX_WITH_ORIGIN)
 $(error VBox: VBOX_WITH_RUNPATH and VBOX_WITH_ORIGIN are mutually exclusive)
endif
if defined(VBOX_WITH_RELATIVE_RUNPATH) && defined(VBOX_WITH_ORIGIN)
 $(error VBox: VBOX_WITH_RELATIVE_RUNPATH and VBOX_WITH_ORIGIN are mutually exclusive)
endif
if defined(VBOX_WITH_RUNPATH) && defined(VBOX_WITH_RELATIVE_RUNPATH)
 $(error VBox: VBOX_WITH_RUNPATH and VBOX_WITH_RELATIVE_RUNPATH are mutually exclusive)
endif
if defined(VBOX_WITH_RELATIVE_RUNPATH) && defined(VBOX_WITH_HARDENING)
 $(error VBox: VBOX_WITH_RELATIVE_RUNPATH and VBOX_WITH_HARDENING are mutually exclusive)
endif

#
# VBOX_WITH_ORIGIN translates into VBOX_WITH_RELATIVE_RUNPATH.
#
# We use two helper variables for the VBOX_WITH_ORIGIN stuff:
#   VBOX_ORIGIN - Indirect expansion trick.
#   VBOX_GCC_RPATH_OPT - Different GCC/LD combinations needs different options.
#
VBOX_ORIGIN = $$ORIGIN
ifeq ($(KBUILD_TARGET),solaris)
 VBOX_GCC_RPATH_OPT  = -R
else
 VBOX_GCC_RPATH_OPT  = -Wl,-rpath,
 VBOX_GCC_ORIGIN_OPT = -Wl,-z,origin
endif
ifdef VBOX_WITH_ORIGIN
 VBOX_WITH_RELATIVE_RUNPATH = $$(VBOX_ORIGIN)
endif


#
# The X11 headers.
#
VBOX_PATH_X11_ROOT      = $(PATH_ROOT)/src/VBox/Additions/x11/x11include


#
# Miscellaneous includes
#
VBOX_GRAPHICS_INCS = $(PATH_ROOT)/include/VBox/Graphics
VBOX_JPEG_INCS     = $(PATH_ROOT)/src/libs/jpeg-9b


# The icons to use.
ifdef VBOX_OSE
 VBOX_WINDOWS_ICON_FILE           ?= $(PATH_ROOT)/src/VBox/Artwork/win/OSE/VirtualBox_win.ico
 VBOX_WINDOWS_ADDITIONS_ICON_FILE ?= $(PATH_ROOT)/src/VBox/Artwork/win/OSE/VirtualBox_win.ico
 VBOX_NSIS_ICON_FILE              ?= $(PATH_ROOT)/src/VBox/Artwork/win/OSE/VirtualBox_win.ico
 VBOX_MACOSX_ICON_FILE            ?= $(PATH_ROOT)/src/VBox/Artwork/darwin/OSE/VirtualBox.icns
else
 ifeq ($(KBUILD_HOST),win)
  VBOX_WINDOWS_ICON_FILE           ?= $(PATH_ROOT)/src/VBox/Artwork/win/NonOSE/VirtualBox-vista.ico
  VBOX_WINDOWS_ADDITIONS_ICON_FILE ?= $(PATH_ROOT)/src/VBox/Artwork/win/NonOSE/VirtualBoxGA-vista.ico
  VBOX_NSIS_ICON_FILE              ?= $(PATH_ROOT)/src/VBox/Artwork/win/NonOSE/VirtualBoxGA-nsis.ico
  TOOL_VCC80X86_RC                 := $(KBUILD_DEVTOOLS)/win.x86/ddk/6000/bin/x86/rc.exe
  TOOL_VCC80AMD64_RC               := $(KBUILD_DEVTOOLS)/win.x86/ddk/6000/bin/x86/rc.exe
  TOOL_VCC70_RC                    := $(KBUILD_DEVTOOLS)/win.x86/ddk/6000/bin/x86/rc.exe
 else
  VBOX_WINDOWS_ICON_FILE           ?= $(PATH_ROOT)/src/VBox/Artwork/win/NonOSE/VirtualBox-winxp.ico
  VBOX_WINDOWS_ADDITIONS_ICON_FILE ?= $(PATH_ROOT)/src/VBox/Artwork/win/NonOSE/VirtualBoxGA-winxp.ico
  VBOX_NSIS_ICON_FILE              ?= $(PATH_ROOT)/src/VBox/Artwork/win/NonOSE/VirtualBox-nsis.ico
 endif
 VBOX_MACOSX_ICON_FILE             ?= $(PATH_ROOT)/src/VBox/Artwork/darwin/NonOSE/VirtualBox.icns
endif


ifndef VBOX_NOINC_DYNAMIC_CONFIG_KMK
#
# GCC and YASM dynamic properties.
# Most of this is resolved on first kmk invocation and cached in PATH_OUT.
#
# Note! That a harmless warning is printed if the file doesn't exist.
# Note! Changes in GCC are not detected automatically (yet).
#
if $(pos VBox,$(VBOX_GCC_TOOL)) > 0
 include $(KBUILD_TOOL_PATHS)/$(VBOX_GCC_TOOL).kmk
else
 include $(KBUILD_PATH)/tools/$(VBOX_GCC_TOOL).kmk
endif
ifneq ($(VBOX_GCC_TOOL),$(VBOX_GCC32_TOOL))
 if $(pos VBox,$(VBOX_GCC32_TOOL)) > 0
  include $(KBUILD_TOOL_PATHS)/$(VBOX_GCC32_TOOL).kmk
 else
  include $(KBUILD_PATH)/tools/$(VBOX_GCC32_TOOL).kmk
 endif
endif

# These tests never worked on Windows because of /dev/null, so, there
# can be no harm in just dropping them until cygwin is mp safe.
ifeq ($(KBUILD_HOST),win)
 VBOX_GCC_CHECK_EX_CC  = $(3)
 VBOX_GCC_CHECK_EX_CXX = $(3)
 VBOX_GCC_CHECK_EX_LD  = $(3)
 VBOX_GCC_CHECK_CC = $(2)
 VBOX_GCC_CHECK_CXX = $(2)
 VBOX_GCC_CHECK_LD = $(2)
 VBOX_GCC32_CHECK_CXX = $(2)
else
 # Note! The chcking for 'error: unknown warning option' is for clang on darwin not giving us a
 #       non-zero exit code when using an invalid option here, but it does later on.
 ifndef CLOSEPAR
  CLOSEPAR := )
 endif
 VBOX_GCC_CHECK_EX_CC_CXX = $(shell \
    if $(1) $(subst -Wno-,-W,$(2)) -Werror -c -o /dev/null $(4) > /dev/null 2>&1; then \
        case "`LC_ALL=C $(1) $(subst -Wno-,-W,$(2)) -Werror -c -o /dev/null $(4) 2>&1`" in \
            "error: unknown warning option"*$(CLOSEPAR) echo "$(3)";; \
            *$(CLOSEPAR) echo "$(2)";; \
	 esac; \
    else echo "$(3)"; fi; )
 VBOX_GCC_CHECK_EX_CC  = $(call VBOX_GCC_CHECK_EX_CC_CXX,$(1),$(2),$(3),-xc   $(PATH_OUT)/DynamicConfig.c)
 VBOX_GCC_CHECK_EX_CXX = $(call VBOX_GCC_CHECK_EX_CC_CXX,$(1),$(2),$(3),-xc++ $(PATH_OUT)/DynamicConfig.cpp)
 VBOX_GCC_CHECK_EX_LD = $(shell \
    if $(1) -Wl,$(2) $(if $(eq $(KBUILD_HOST),darwin),-Wl$(COMMA)-u$(COMMA)start -Wl$(COMMA)-undefined$(COMMA)dynamic_lookup,) \
            -nostdlib -o /dev/null -xc /dev/null > /dev/null 2>&1; \
    then echo "-Wl,$(2)"; else echo "$(3)"; fi; )

 VBOX_GCC_CHECK_CC    = $(call VBOX_GCC_CHECK_EX_CC,  $(TOOL_$(VBOX_GCC_TOOL)_ENV_SETUP) $(TOOL_$(VBOX_GCC_TOOL)_CC),$1,$2)
 VBOX_GCC_CHECK_CXX   = $(call VBOX_GCC_CHECK_EX_CXX, $(TOOL_$(VBOX_GCC_TOOL)_ENV_SETUP) $(TOOL_$(VBOX_GCC_TOOL)_CXX),$1,$2)
 VBOX_GCC_CHECK_LD    = $(call VBOX_GCC_CHECK_EX_LD,  $(TOOL_$(VBOX_GCC_TOOL)_ENV_SETUP) $(TOOL_$(VBOX_GCC_TOOL)_LD),$1,$2)
 VBOX_GCC32_CHECK_CXX = $(call VBOX_GCC_CHECK_EX_CXX, $(TOOL_$(VBOX_GCC32_TOOL)_ENV_SETUP) $(TOOL_$(VBOX_GCC32_TOOL)_CXX),$1,$2)
endif

ifeq ($(KBUILD_HOST),win) ## @todo can drop this now, we're not using cygwin.
 # This isn't important (yet) on windows, so cook the result until
 # cygwin is feeling better.
 VBOX_GCC_VERSION := $(int-add $(int-mul 10000, 3), $(int-mul 100, 3), 3)
else
 # This is kind of bad, the returned string needs to be re-evaluated before use.
 # The reason for this hack is that the windows kmk_ash cannot deal with $((1+1)).
 # Some versions of gcc (e.g. openSUSE11) return only major.minor on `gcc -dumpversion`.
 # gcc-5 of openSUSE42.1 only returns the major version on `gcc -dumpversion`!
 VBOX_GCC_VERSION = $(shell ($(1) -dumpfullversion 2>/dev/null || $(1) -dumpversion) | \
    $(SED_EXT) 's|\([0-9][0-9]*\)\.\{0,1\}\([0-9]\{0,\}\)\.\{0,1\}\([0-9]\{0,\}\).*|$$(int-add $$(int-mul 10000, \1), $$(int-mul 100, $$(firstword \2 0)), $$(firstword \3 0))|' )
endif

# YASM macros
ifndef DONT_USE_YASM
 include $(KBUILD_PATH)/tools/YASM.kmk
 if1of ($(KBUILD_HOST), win os2)
  VBOX_YASM_CHECK = $(if-expr "$(shell $(TOOL_YASM_AS) -e -o nul $1 - < /dev/null 2>&1)" == "",$(1),)
 else
  VBOX_YASM_CHECK = $(if-expr "$(shell $(TOOL_YASM_AS) -e -o /dev/null $1 - < /dev/null 2>&1)" == "",$(1),)
 endif
else
 VBOX_YASM_CHECK =
endif

# NASM macros (input and output must differ with recent versions (strcmp)).
ifndef DONT_USE_NASM
 include $(KBUILD_PATH)/tools/NASM.kmk
 if1of ($(KBUILD_HOST), win os2)
  VBOX_NASM_CHECK = $(if-expr "$(shell $(TOOL_NASM_AS) -e -o nul $1 NUL 2>&1)" == "",$(1),$(2))
 else
  VBOX_NASM_CHECK = $(if-expr "$(shell $(TOOL_NASM_AS) -e -o /dev/./null $1 /dev/null 2>&1)" == "",$(1),$(2))
 endif
else
 VBOX_NASM_CHECK =
endif

# Figures the pylint version.
VBOX_PYLINT_FIGURE_VERSION = $(shell $(1) --version 2> /dev/null \
	| $(SED_EXT) -n -e 's/pylint-[^ \t]*/pylint/' \
	-e 's|^ *pylint *\([0-9][0-9]*\).\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$(DOLLAR)|$$(expr \1 * 10000 + \2 * 100 + \3)|p' )

# Java stuff.
ifeq ($(KBUILD_TARGET), darwin)
 VBOX_JAVA_COMMANDS = $(firstword $(wildcard \
        /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Commands \
        /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands \
        $(if-expr $(VBOX_XCODE_VERSION_MAJOR) >= 4,/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands,) \
        ) /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands)
 VBOX_JAVA      = $(VBOX_JAVA_COMMANDS)/java
 VBOX_JAVAC     = $(VBOX_JAVA_COMMANDS)/javac
 VBOX_JAVAH     = $(VBOX_JAVA_COMMANDS)/javah
 VBOX_JAR       = $(VBOX_JAVA_COMMANDS)/jar
 VBOX_JAVADOC   = $(VBOX_JAVA_COMMANDS)/javadoc
 VBOX_WSIMPORT  = $(VBOX_JAVA_COMMANDS)/wsimport
 if $(VBOX_XCODE_VERSION_MAJOR) >= 4 # Lion (4.1-preview 5) has a broken CurrentJDK link.  Blindly applying it to 4.0.
  VBOX_JAVA_INC  = $(VBOX_PATH_MACOSX_SDK)/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
 else
  VBOX_JAVA_INC  = $(VBOX_PATH_MACOSX_SDK)/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Headers
 endif

else # !darwin

 ifeq ($(KBUILD_TARGET),linux)
  ifeq ($(origin VBOX_JAVA_HOME),undefined)
   # Add correct detection for you distro after the /usr/../java-6-sun line.
   VBOX_JAVA_HOME := $(firstword $(wildcard \
	$(KBUILD_DEVTOOLS)/linux.x86/jdk1.6.0_27 \
	/usr/lib/jvm/java-6-sun  \
	/usr/lib/jvm/java-6-openjdk \
	/usr/lib/jvm/java-6-openjdk-i386 \
	/usr/lib/jvm/java-6-openjdk-amd64 \
	/usr/lib/jvm/java-7-openjdk-i386 \
	/usr/lib/jvm/java-7-openjdk-amd64 \
	/usr/lib/jvm/default-java \
	/usr/lib/jvm/java \
	\
	/usr/lib/jvm/sun-jdk-1.6 \
	) /usr/lib/jvm/java-6-sun)
  endif
 endif

 ifeq ($(KBUILD_TARGET),solaris)
  # VBOX_JAVA_HOME ?= /usr/jdk/jdk1.6.0
  VBOX_JAVA_HOME ?= $(firstword $(abspath $(wildcard \
	/usr/jdk/latest/include/.. \
	/usr/jdk/instances/jdk1.8*/include/.. \
	/usr/jdk/instances/jdk1.7*/include/.. \
	/usr/jdk/instances/jdk1.6*/include/.. \
	)) /usr/java)
 endif

 ifeq ($(KBUILD_TARGET),win)
  VBOX_JAVA_HOME ?= c:/jdk
 endif

 VBOX_JAVA     ?= "$(VBOX_JAVA_HOME)/bin/java$(HOSTSUFF_EXE)"
 VBOX_JAVAC     = "$(VBOX_JAVA_HOME)/bin/javac$(HOSTSUFF_EXE)"
 VBOX_JAVAH     = "$(VBOX_JAVA_HOME)/bin/javah$(HOSTSUFF_EXE)"
 VBOX_JAR       = "$(VBOX_JAVA_HOME)/bin/jar$(HOSTSUFF_EXE)"
 VBOX_JAVADOC   = "$(VBOX_JAVA_HOME)/bin/javadoc$(HOSTSUFF_EXE)"
 # With Java 11 wsimport was removed, usually part of a separate install now.
 VBOX_WSIMPORT  = $(firstword $(wildcard $(VBOX_JAVA_HOME)/bin/wsimport$(HOSTSUFF_EXE)) wsimport$(HOSTSUFF_EXE))
 # correct for targets we care about
 VBOX_MD_OS     = $(KBUILD_TARGET)
 VBOX_JAVA_INC  = \
 	$(VBOX_JAVA_HOME)/include \
 	$(VBOX_JAVA_HOME)/include/$(VBOX_MD_OS)
endif # !darwin
VBOX_JAVA_FIGURE_VERSION = $(shell $(1) -version 2>&1 \
	| $(SED_EXT) -n -e 's|^[^ ]* *\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$(DOLLAR)|$$(expr \1 * 10000 + \2 * 100 + \3)|p' )

# Test C and C++ files.
$(PATH_OUT)/DynamicConfig.c $(PATH_OUT)/DynamicConfig.cpp:
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(APPEND) -tn "$@" "int foobar(void)" "{" "    return 42;" "}" ""

# No $(QUIET) here as it's interesting to see what goes into the file.
$(PATH_OUT)/DynamicConfig.kmk: \
		$(PATH_ROOT)/Config.kmk \
		$(LOCALCFG) \
		$(AUTOCFG) \
		$(VBOX_GCC_PATH_CC) \
		$(VBOX_GCC_PATH_CXX) \
		$(VBOX_GCC_LIBGCC) \
		$(VBOX_GCC32_PATH_CC) \
		$(VBOX_GCC32_PATH_CXX) \
		$(VBOX_GCC32_LIBGCC) \
		$(if-expr "$(KBUILD_HOST).$(KBUILD_HOST_ARCH)" == "solaris.amd64" && $(KBUILD_HOST_VERSION_MINOR) >= 11 \
			, /platform/i86pc/kernel/$(KBUILD_HOST_ARCH)/unix,) \
        	| $(PATH_OUT)/DynamicConfig.c $(PATH_OUT)/DynamicConfig.cpp
	$(call MSG_GENERATE,,$@,)
	$(QUIET)$(RM) -f '$@'
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(APPEND) '$@' '# Host version: $(KBUILD_HOST_VERSION_MAJOR).$(KBUILD_HOST_VERSION_MINOR).$(KBUILD_HOST_VERSION_PATCH); full: $(KBUILD_HOST_VERSION)'
ifneq ($(KBUILD_TARGET),win)
	$(QUIET)$(APPEND) '$@' '# $(KBUILD_HOST_UNAME_SYSNAME) - $(KBUILD_HOST_UNAME_RELEASE) - $(KBUILD_HOST_UNAME_VERSION)'
endif
ifeq ($(KBUILD_TARGET),darwin)
	$(QUIET)$(APPEND) '$@' '#              VBOX_XCODE_VERSION: $(VBOX_XCODE_VERSION)'
	$(QUIET)$(APPEND) '$@' '# VBOX_PATH_MACOSX_TOOLCHAIN_ROOT: $(VBOX_PATH_MACOSX_TOOLCHAIN_ROOT)'
	$(QUIET)$(APPEND) '$@' '#       VBOX_PATH_MACOSX_SDK_ROOT: $(VBOX_PATH_MACOSX_SDK_ROOT)'
	$(QUIET)$(APPEND) '$@' '#     VBOX_PATH_MACOSX_DEVEL_ROOT: $(VBOX_PATH_MACOSX_DEVEL_ROOT)'
endif
# HC compiler switch detection.
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_PATH_CC               ?= $(which $(TOOL_$(VBOX_GCC_TOOL)_CC))'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_PATH_CXX              ?= $(which $(TOOL_$(VBOX_GCC_TOOL)_CXX))'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_VERSION_CC            ?= $(call VBOX_GCC_VERSION,$(TOOL_$(VBOX_GCC_TOOL)_CC))'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_VERSION_CXX           ?= $(call VBOX_GCC_VERSION,$(TOOL_$(VBOX_GCC_TOOL)_CXX))'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_LIBGCC                ?= $(shell $(TOOL_$(VBOX_GCC_TOOL)_CC) -print-libgcc-file-name)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-pointer-sign      ?= $(call VBOX_GCC_CHECK_CC,-Wno-pointer-sign,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-array_bounds      ?= $(call VBOX_GCC_CHECK_CC,-Wno-array-bounds,)'
# -Wextra produces additional useful warnings but includes -Wno-missing-field-initializers (too noisy)
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wextra                ?= $(call VBOX_GCC_CHECK_CC,-Wextra,)'
	$(QUIET)$(APPEND) '$@' 'ifneq ($$(VBOX_GCC_VERSION_CC),)'
	$(QUIET)$(APPEND) '$@' ' ifneq ($$(int-ge $$(VBOX_GCC_VERSION_CC),40500),)'
	$(QUIET)$(APPEND) '$@' '  VBOX_GCC_Wlogical-op         ?= $(call VBOX_GCC_CHECK_CC,-Wlogical-op,)'
	$(QUIET)$(APPEND) '$@' ' endif'
	$(QUIET)$(APPEND) '$@' 'endif'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-address           ?= $(call VBOX_GCC_CHECK_CXX,-Wno-address,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-delete-non-virtual-dtor    ?= $(call VBOX_GCC_CHECK_CXX,-Wno-delete-non-virtual-dtor,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-non-virtual-dtor           ?= $(call VBOX_GCC_CHECK_CXX,-Wno-non-virtual-dtor,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-int-in-bool-context        ?= $(call VBOX_GCC_CHECK_CC,-Wno-int-in-bool-context,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-int-to-pointer-cast        ?= $(call VBOX_GCC_CHECK_CC,-Wno-int-to-pointer-cast,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-invalid-offsetof           ?= $(call VBOX_GCC_CHECK_CXX,-Wno-invalid-offsetof,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-literal-suffix             ?= $(call VBOX_GCC_CHECK_CXX,-Wno-literal-suffix,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-misleading-indentation     ?= $(call VBOX_GCC_CHECK_CC,-Wno-misleading-indentation,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-missing-field-initializers ?= $(call VBOX_GCC_CHECK_CC,-Wno-missing-field-initializers,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-pointer-to-int-cast        ?= $(call VBOX_GCC_CHECK_CC,-Wno-pointer-to-int-cast,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-variadic-macros            ?= $(call VBOX_GCC_CHECK_CXX,-Wno-variadic-macros,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-vla                        ?= $(call VBOX_GCC_CHECK_CXX,-Wno-vla,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-overlength-strings         ?= $(call VBOX_GCC_CHECK_CC,-Wno-overlength-strings,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-overloaded-virtual         ?= $(call VBOX_GCC_CHECK_CXX,-Wno-overloaded-virtual,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-ignored-qualifiers         ?= $(call VBOX_GCC_CHECK_CXX,-Wno-ignored-qualifiers,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-multistatement-macros      ?= $(call VBOX_GCC_CHECK_CXX,-Wno-multistatement-macros,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-class-memaccess            ?= $(call VBOX_GCC_CHECK_CXX,-Wno-class-memaccess,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-stringop-overflow          ?= $(call VBOX_GCC_CHECK_CXX,-Wno-stringop-overflow,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-stringop-truncation        ?= $(call VBOX_GCC_CHECK_CXX,-Wno-stringop-truncation,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-cast-function-type         ?= $(call VBOX_GCC_CHECK_CC,-Wno-cast-function-type,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-deprecated-declarations    ?= $(call VBOX_GCC_CHECK_CC,-Wno-deprecated-declarations,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-implicit-fallthrough       ?= $(call VBOX_GCC_CHECK_CC,-Wno-implicit-fallthrough,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_fno-stack-protector   ?= $(call VBOX_GCC_CHECK_CC,-fno-stack-protector,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_fno-dwarf2-cfi-asm    ?= $(call VBOX_GCC_CHECK_CC,-fno-dwarf2-cfi-asm,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_m64                   ?= $(call VBOX_GCC_CHECK_CC,-m64,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_msse4.1               ?= $(call VBOX_GCC_CHECK_CC,-msse4.1,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_mavx                  ?= $(call VBOX_GCC_CHECK_CC,-mavx,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_mavx2                 ?= $(call VBOX_GCC_CHECK_CC,-mavx2,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_no-pie                ?= $(call VBOX_GCC_CHECK_CC,-no-pie,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_fdiagnostics-show-option ?= $(call VBOX_GCC_CHECK_CC,-fdiagnostics-show-option,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wa_cma_nocompress_debug_sections ?= $(call VBOX_GCC_CHECK_CC,-Wa$(COMMA)--nocompress-debug-sections,)'
# Produce code optimized for the most common IA32/AMD64/EM64T processors. Introduced with gcc version 4.2.
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_mtune-generic         ?= $(call VBOX_GCC_CHECK_CC,-mtune=generic,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_LD_as_needed              ?= $(call VBOX_GCC_CHECK_LD,--as-needed,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_LD_hash_style_sysv        ?= $(call VBOX_GCC_CHECK_LD,--hash-style=sysv,)'
# gcc version < 3.4 has a bug in handling __attribute__((regparm(3))).
# See http://osdir.com/ml/gcc.prs/2002-08/msg00223.html and probably http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20004
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_BUGGY_REGPARM         ?= $$(int-lt $$(VBOX_GCC_VERSION_CC),30400)'
# Set default attribute for ELF and MACH-O symbols to ``hidden'' to reduce the number
# of relocation entries and PLT indirections in shared libraries. Don't allow for gcc version < 4.
	$(QUIET)$(APPEND) '$@' 'ifneq ($$(VBOX_GCC_VERSION_CC),)'
	$(QUIET)$(APPEND) '$@' ' ifneq ($$(int-ge $$(VBOX_GCC_VERSION_CC),40000),)'
	$(QUIET)$(APPEND) '$@' '  VBOX_GCC_fvisibility-hidden  ?= $(call VBOX_GCC_CHECK_CC,-fvisibility=hidden -DVBOX_HAVE_VISIBILITY_HIDDEN -DRT_USE_VISIBILITY_DEFAULT,)'
	$(QUIET)$(APPEND) '$@' ' endif'
	$(QUIET)$(APPEND) '$@' 'endif'
ifn1of ($(KBUILD_TARGET),haiku)
# Set default attribute for inline functions to ``hidden'' to reduce the number
# of relocation entries and PLT indirections in shared libraries. Don't allow for gcc version < 4.
	$(QUIET)$(APPEND) '$@' 'ifneq ($$(VBOX_GCC_VERSION_CXX),)'
	$(QUIET)$(APPEND) '$@' ' ifneq ($$(int-ge $$(VBOX_GCC_VERSION_CXX),40000),)'
	$(QUIET)$(APPEND) '$@' '  VBOX_GCC_fvisibility-inlines-hidden ?= $(call VBOX_GCC_CHECK_CXX,-fvisibility-inlines-hidden,)'
	$(QUIET)$(APPEND) '$@' ' endif'
	$(QUIET)$(APPEND) '$@' 'endif'
endif
# Prevent warnings about unused parameters as of gcc-4.8 / clang 6 as this warning is now very verbose
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-unused-parameter ?= $(call VBOX_GCC_CHECK_CC,-Wno-unused-parameter,)'
# Clang 6.
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-language-extension-token ?= $(call VBOX_GCC_CHECK_CC,-Wno-language-extension-token,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-extended-offsetof ?= $(call VBOX_GCC_CHECK_CC,-Wno-extended-offsetof,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-gnu-folding-constant ?= $(call VBOX_GCC_CHECK_CC,-Wno-gnu-folding-constant,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-return-type-c-linkage ?= $(call VBOX_GCC_CHECK_CXX,-Wno-return-type-c-linkage,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-string-plus-int ?= $(call VBOX_GCC_CHECK_CC,-Wno-string-plus-int,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-nested-anon-types ?= $(call VBOX_GCC_CHECK_CC,-Wno-nested-anon-types,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_Wno-gnu-anonymous-struct ?= $(call VBOX_GCC_CHECK_CXX,-Wno-gnu-anonymous-struct,)'
# C++ Std settings
	$(QUIET)$(APPEND) '$@' 'ifneq ($$(VBOX_GCC_VERSION_CXX),)'
	$(QUIET)$(APPEND) '$@' ' ifneq ($$(int-ge $$(VBOX_GCC_VERSION_CXX),40800),)'
	$(QUIET)$(APPEND) '$@' '  VBOX_GCC_std ?= -std=c++11'
	$(QUIET)$(APPEND) '$@' ' else ifneq ($$(int-ge $$(VBOX_GCC_VERSION_CXX),40600),)'
	$(QUIET)$(APPEND) '$@' '  VBOX_GCC_std ?= -std=c++0x'
	$(QUIET)$(APPEND) '$@' ' endif'
	$(QUIET)$(APPEND) '$@' 'endif'
ifeq ($(KBUILD_TARGET),solaris)
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_msave-args            ?= $(call VBOX_GCC_CHECK_CXX,-msave-args,)'
# Detect the solaris assembler. It is used by the the 4.x gcc compilers,
# apparently. It will not be able to handle IEMAll via a -pipe, only when
# passed a file. The solaris assmbler rulez ... not!
	$(QUIET)$(APPEND) '$@' 'VBOX_AS_VERSION                ?= $(shell `gcc -print-prog-name=as` -V -o /dev/null < /dev/null 2>&1 | kmk_sed -e '1!d' -e 's/^as: *//' )'
	$(QUIET)$(APPEND) '$@' 'if $$(pos Sun Compiler Common,$$(VBOX_AS_VERSION)) > 0'
	$(QUIET)$(APPEND) '$@' ' VBOX_GCC_USING_SOLARIS_AS=1'
	$(QUIET)$(APPEND) '$@' 'endif'
	$(QUIET)$(APPEND) '$@' 'ifndef VBOX_GCC_USING_SOLARIS_AS'
	$(QUIET)$(APPEND) '$@' ' VBOX_GCC_pipe                 ?= -pipe'
	$(QUIET)$(APPEND) '$@' 'endif'
else
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC_pipe                  ?= -pipe'
endif
# Find the compiler includes for IPRT no-crt.
# Note that `$(dir $(gcc -print-libgcc-file-name))/include does not work for a 64-bit cross build on a 32-bit build host.
ifeq ($(KBUILD_HOST),win)
# With the cygwin issues and gcc on windows returning a useless path, just skip this on windows.
	$(QUIET)$(APPEND) '$@' 'VBOX_PATH_GCC_INCS             ?= '
else
	$(QUIET)$(APPEND) '$@' 'VBOX_PATH_GCC_INCS             ?= $(shell LC_ALL=C $(TOOL_$(VBOX_GCC_TOOL)_CC) -print-search-dirs|$(SED_EXT) -ne 's+^install: \(.*[^/][^/]*\)/+\1+p')/include'
endif
# 32-bit (GC) compiler switch detection.
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC32_PATH_CC             ?= $(which $(TOOL_$(VBOX_GCC32_TOOL)_CC))'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC32_PATH_CXX            ?= $(which $(TOOL_$(VBOX_GCC32_TOOL)_CXX))'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC32_VERSION_CC          ?= $(call VBOX_GCC_VERSION,$(TOOL_$(VBOX_GCC32_TOOL)_CC))'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC32_VERSION_CXX         ?= $(call VBOX_GCC_VERSION,$(TOOL_$(VBOX_GCC32_TOOL)_CXX))'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC32_LIBGCC              ?= $(shell $(TOOL_$(VBOX_GCC32_TOOL)_CC) -print-libgcc-file-name)'
	$(QUIET)$(APPEND) '$@' 'VBOX_GCC32_Wno-variadic-macros ?= $(call VBOX_GCC32_CHECK_CXX,-Wno-variadic-macros,)'
# darwin no_compact_linkedit starting at Xcode 3.2
ifeq ($(KBUILD_HOST),darwin)
	$(QUIET)$(APPEND) '$@' 'VBOX_LD_no_compact_linkedit    ?= $(call VBOX_GCC_CHECK_LD,-no_compact_linkedit,)'
endif
# YASM
	$(QUIET)$(APPEND) '$@' '# debug: TOOL_YASM_AS="$(TOOL_YASM_AS)"'
	$(QUIET)$(APPEND) '$@' 'VBOX_YASM_Wno-segreg-in-64bit  ?= $(call VBOX_YASM_CHECK,-Wno-segreg-in-64bit,)'
# NASM (--allow-64-bit: 2.12rc2)
	$(QUIET)$(APPEND) '$@' 'VBOX_NASM_allow_64_bit         ?= $(call VBOX_NASM_CHECK,--allow-64-bit,)'
ifeq ($(KBUILD_HOST),linux)
	$(QUIET)$(APPEND) '$@' 'VBOX_LD_HAS_LIBXCB             ?= $(shell /sbin/ldconfig -p|grep -q "\<libxcb\.so\.1\>" && echo "1")'
endif

ifdef VBOX_PATH_PREFIX_MINGW32
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW32_VERSION_CC                  ?= $(call VBOX_GCC_VERSION,$(VBOX_PATH_PREFIX_MINGW32)gcc -m32)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW32_VERSION_CXX                 ?= $(call VBOX_GCC_VERSION,$(VBOX_PATH_PREFIX_MINGW32)g++ -m32)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW32_Wno-array-bounds            ?= $(call VBOX_GCC_CHECK_EX_CXX,$(VBOX_PATH_PREFIX_MINGW32)g++ -m32,-Wno-array-bounds,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW32_Wno-unused-but-set-variable ?= $(call VBOX_GCC_CHECK_EX_CXX,$(VBOX_PATH_PREFIX_MINGW32)g++ -m32,-Wno-unused-but-set-variable,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW32_Wno-maybe-uninitialized     ?= $(call VBOX_GCC_CHECK_EX_CXX,$(VBOX_PATH_PREFIX_MINGW32)g++ -m32,-Wno-maybe-uninitialized,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW32_USER_LABEL_PREFIX           ?= $(shell echo "__USER_LABEL_PREFIX__" | $(VBOX_PATH_PREFIX_MINGW32)g++ -m32 -E -xc++ - | $(SED) -e "/^$(HASH)/d")'
endif
ifdef VBOX_PATH_PREFIX_MINGW64
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW64_VERSION_CC                  ?= $(call VBOX_GCC_VERSION,$(VBOX_PATH_PREFIX_MINGW64)gcc -m64)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW64_VERSION_CXX                 ?= $(call VBOX_GCC_VERSION,$(VBOX_PATH_PREFIX_MINGW64)g++ -m64)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW64_Wno-array-bounds            ?= $(call VBOX_GCC_CHECK_EX_CXX,$(VBOX_PATH_PREFIX_MINGW64)g++ -m64,-Wno-array-bounds,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW64_Wno-unused-but-set-variable ?= $(call VBOX_GCC_CHECK_EX_CXX,$(VBOX_PATH_PREFIX_MINGW64)g++ -m64,-Wno-unused-but-set-variable,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW64_Wno-maybe-uninitialized     ?= $(call VBOX_GCC_CHECK_EX_CXX,$(VBOX_PATH_PREFIX_MINGW64)g++ -m64,-Wno-maybe-uninitialized,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_MINGW64_USER_LABEL_PREFIX           ?= $(shell echo "__USER_LABEL_PREFIX__" | $(VBOX_PATH_PREFIX_MINGW64)g++ -m64 -E -xc++ - | $(SED) -e "/^$(HASH)/d")'
endif
ifeq ($(KBUILD_HOST),darwin)
	$(QUIET)$(APPEND) '$@' 'VBOX_HAVE_FLEX    ?= 1'
	$(QUIET)$(APPEND) '$@' 'VBOX_HAVE_BISON   ?= 1'
else
	$(QUIET)$(APPEND) '$@' 'VBOX_HAVE_FLEX    ?= $(if $(which flex),1,)'
	$(QUIET)$(APPEND) '$@' 'VBOX_HAVE_BISON   ?= $(if $(which bison),1,)'
endif
	$(QUIET)$(APPEND) '$@' 'VBOX_HAVE_XMLLINT ?= $(which xmllint)'
if "$(KBUILD_HOST)" == "solaris" && $(KBUILD_HOST_VERSION_MAJOR) == 5 && $(KBUILD_HOST_VERSION_MINOR) == 11
# BRANCH_VERSION format on S11 - S11.3:
#   <trunk_id>.<update>.<sru>.<reserved>.<buildid>.<nightly_id>
#   e.g.:  0.175.3.32.0.4.0:20180427T232405Z - N.B. trunk_id = 0.175
# BRANCH_VERSION format on S11.4:
#   <minor>.<update>.<sru>.<reserved>.<reserved>.<buildid>.<nightly_id>
#   e.g.: 11.4.0.0.1.10.0:20180702T173343Z
# We're interested in <update> and <buildid>.
	$(QUIET)$(APPEND) '$@' "VBOX_SOLARIS_11_BRANCH_VERSION := $(shell pkg contents -H -t set -o pkg.fmri system/kernel | $(SED_EXT) -e '1!d' -e 's/^.*\-//;s/\:.*//;s/.*,//')"
	$(QUIET)$(APPEND) '$@' 'ifeq ($$(word 2, $$(subst ., ,$$(VBOX_SOLARIS_11_BRANCH_VERSION))),175)'
	$(QUIET)$(APPEND) '$@' '   VBOX_SOLARIS_11_UPDATE_VERSION := $$(word 3, $$(subst ., ,$$(VBOX_SOLARIS_11_BRANCH_VERSION)))'
	$(QUIET)$(APPEND) '$@' 'else'
	$(QUIET)$(APPEND) '$@' '   VBOX_SOLARIS_11_UPDATE_VERSION := $$(word 2, $$(subst ., ,$$(VBOX_SOLARIS_11_BRANCH_VERSION)))'
	$(QUIET)$(APPEND) '$@' 'endif'
	$(QUIET)$(APPEND) '$@' 'VBOX_SOLARIS_11_BUILD_VERSION  := $$(word 6, $$(subst ., ,$$(VBOX_SOLARIS_11_BRANCH_VERSION)))'
endif
if1of ($(KBUILD_HOST), darwin freebsd solaris)
	$(QUIET)$(APPEND) '$@' 'VBOX_HOST_DTRACE_VERSION := $(shell dtrace -V)'
endif
if defined(VBOX_PYLINT) && !defined(VBOX_WITH_PYLINT_PRE_V1_0) && !defined(VBOX_WITH_PYLINT_V1_1_PLUS) && !defined(VBOX_WITH_PYLINT_V1_2_1_PLUS)
	$(QUIET)$(APPEND) '$@' "VBOX_PYLINT_VERSION  := $(call VBOX_PYLINT_FIGURE_VERSION, $(VBOX_PYLINT))"
endif
if defined(VBOX_JAVAC)
	$(QUIET)$(APPEND) '$@' 'VBOX_JAVA_VERSION    := $(call VBOX_JAVA_FIGURE_VERSION, $(VBOX_JAVAC))'
endif

	$(QUIET)$(ECHO) '========= START OF $@ ========='
	$(QUIET)$(CAT) $@
	$(QUIET)$(ECHO) '=========== END OF $@ ========='

include $(PATH_OUT)/DynamicConfig.kmk
endif # !VBOX_NOINC_DYNAMIC_CONFIG_KMK


#
# Compiler warning control.
#
VBOX_GCC_WARN     ?= -Wall $(VBOX_GCC_Wextra) $(VBOX_GCC_Wno-missing-field-initializers) -Wno-unused -Wno-trigraphs \
	$(VBOX_GCC_fdiagnostics-show-option) $(VBOX_GCC_Wno-unused-parameter) $(VBOX_GCC_Wno-language-extension-token) \
	$(VBOX_GCC_Wno-extended-offsetof) $(VBOX_GCC_Wno-gnu-folding-constant) $(VBOX_GCC_Wno-gnu-anonymous-struct) \
	$(VBOX_GCC_Wlogical-op) $(VBOX_GCC_Wno-string-plus-int) $(VBOX_GCC_Wno-nested-anon-types) $(VBOX_GCC_Wno-variadic-macros)
VBOX_GCC_WARN_PEDANTIC = -Wshadow $(VBOX_GCC_WARN) -Wno-long-long
if $(VBOX_GCC_VERSION_CXX) >= 40200 || defined(VBOX_WITH_MASOCHISTIC_WARNINGS) # gcc 4.2.x+ (4.1.2 is causing trouble with the extpack & add builds)
 VBOX_GCC_WARN_MASOCHISTIC ?= -Wunused-variable -Wunused-function -Wunused-label -Wunused-parameter
endif
if   $(KBUILD_TARGET) == "linux" \
  || ($(KBUILD_TARGET) == "darwin" && defined(VBOX_WITH_NEW_XCODE)) \
  || defined(VBOX_WITH_MASOCHISTIC_WARNINGS)
 VBOX_GCC_WARN_PEDANTIC += $(VBOX_GCC_WARN_MASOCHISTIC)
endif

VBOX_GCC_PEDANTIC_CXX ?= -pedantic $(VBOX_GCC_WARN_PEDANTIC) $(VBOX_GCC_Wno-return-type-c-linkage) $(VBOX_GCC_Wno-overloaded-virtual)
VBOX_GCC_PEDANTIC_C   ?= -pedantic $(VBOX_GCC_WARN_PEDANTIC) -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Werror-implicit-function-declaration

# Avoid freaking out when using flexible arrays in C++ code (ldrPE.cpp, ++).
if ($(VBOX_GCC_VERSION_CXX) < 60100 || $(VBOX_GCC_VERSION_CXX) >= 70000) && "$(VBOX_GCC_Wno-array_bounds)" != ""
 VBOX_GCC_PEDANTIC_CXX += $(VBOX_GCC_Wno-array_bounds)
endif
# Stupid problem with (__typeof__((*ppv)) casts in asm.h where volatile is involved and ignored.
if $(VBOX_GCC_VERSION_CXX) >= 80000 && "$(VBOX_GCC_Wno-ignored-qualifiers)"
 VBOX_GCC_PEDANTIC_CXX += $(VBOX_GCC_Wno-ignored-qualifiers)
endif


VBOX_GCC_NON_PEDANTIC_CXX ?= -Wno-sign-compare
VBOX_GCC_NON_PEDANTIC_C   ?= -Wno-sign-compare -Werror-implicit-function-declaration

ifdef VBOX_WITH_NEW_XCODE
 VBOX_GCC_PEDANTIC_CXX     += -Wno-c99-extensions
 VBOX_GCC_NON_PEDANTIC_CXX += -Wno-c99-extensions
endif

# The address sanitiser library intercepts dlopen() and breaks RPATH $ORIGIN,
# so we need to link it statically or set LD_LIBRARY_PATH.  To link statically,
# set VBOX_WITH_GCC_SANITIZER_STATIC in addition.
ifdef VBOX_WITH_GCC_SANITIZER
 VBOX_GCC_SANITIZER_FLAGS := \
 	-fsanitize=undefined \
 	-fsanitize=address \
 	-fsanitize=return \
 	-fsanitize=bounds \
 	-fsanitize=object-size \
 	-fno-sanitize=alignment \
 	-fno-sanitize=vptr \
 	-fno-common \
 	-DIPRT_WITH_GCC_SANITIZER \
 	-DVBOX_WITH_GCC_SANITIZER
else ifdef VBOX_WITH_CLANG_SANITIZER ## @todo make work...
 VBOX_GCC_SANITIZER_FLAGS := \
 	-DIPRT_WITH_GCC_SANITIZER \
 	-DVBOX_WITH_GCC_SANITIZER \
 	-fsanitize=object-size \
  	-fsanitize-undefined-trap-on-error
else
 VBOX_GCC_SANITIZER_FLAGS =
endif

# -libasan-static is currently not supported in combination with -no-undefined.
VBOX_GCC_NO_UNDEFINED    :=
VBOX_GCC_NO_UNDEFINED_R0 :=
ifdef VBOX_WITH_GCC_SANITIZER
 ifdef VBOX_WITH_GCC_SANITIZER_STATIC
  VBOX_GCC_NO_UNDEFINED    := -Wl,--no-undefined
  VBOX_GCC_NO_UNDEFINED_R0 := -no-undefined
  VBOX_GCC_SANITIZER_LDFLAGS += -static-libasan
 else
  VBOX_GCC_SANITIZER_LDFLAGS += -lasan
 endif
endif

# Disabled Visual C++ warnings, W4:
#      -wd4065: switch statement contains 'default' but no 'case' labels
#      -wd4996: deprecated / insecure.
#      -wd4127: conditional expression is constant [level 4]
#      -wd4706: assignment within conditional expression [level 4]
#      -wd4201: nonstandard extension used : nameless struct/union [level 4]
#      -wd4214: nonstandard extension used : bit field types other than int [level 4]
#      -wd4510: 'VM::<unnamed-tag>' : default constructor could not be generated
#      -wd4512: 'VM' : assignment operator could not be generated
#      -wd4610: union 'VM::<unnamed-tag>' can never be instantiated - user defined constructor required
# Disabled Visual C++ warnings, Wall:
#      -wd4514: unreferenced inline function has been removed
#      -wd4820: 'RTSTRSPACECORE' : '7' bytes padding added after data member 'RTSTRSPACECORE::uchHeight'
#      -wd4365: '=' : conversion from 'unsigned char' to 'char', signed/unsigned mismatch
#      -wd4987: nonstandard extension used: 'throw (...)' (setjmp.h + our stuff)
#      -wd4710: 'std::string std::_Narrow_str(std::wstring)' : function not inlined
#      -wd4061: enumerator 'RTASN1TYPE_END' in switch of enum 'RTASN1TYPE' is not explicitly handled by a case label
#               Note! C4062 checks for the same but includes the 'default' case, just like gcc.  So, no trouble disabling this.
#      -wd4986: 'operator new[]': exception specification does not match previous declaration (crtdbg.h vs new, exception specification only)
#      -wd4191: 'type cast' : unsafe conversion from 'int (__cdecl *)(gzFile)' to 'PFNRT'
#      -wd4574: 'INCL_WINSOCK_API_TYPEDEFS' is defined to be '0': did you mean to use '#if INCL_WINSOCK_API_TYPEDEFS'?
#      -wd4917: 'OLE_XPOS_HIMETRIC' : a GUID can only be associated with a class, interface or namespace
#      -wd4711: function 'void __cdecl rtMemCacheFreeOne(struct RTMEMCACHEINT * __ptr64,void * __ptr64)' selected for automatic inline expansion
#      -wd4571: Informational: catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught
#      -wd4611: interaction between '_setjmp' and C++ object destruction is non-portable
#      -wd4324: '_TDI_PNP_CONTEXT_XP' : structure was padded due to __declspec(align())
#      -wd4505: VBoxNetFltNobj.h(45) : warning C4505: 'VBoxNetFltNobj::Release' : unreferenced local function has been removed
#               Probably related to http://stackoverflow.com/questions/3051992/compiler-warning-at-c-template-base-class
#      -wd4263: 'int VRDPChannelClipboard::SendPacket(const void *,uint32_t)' : member function does not override any base class virtual member function
#               Probably useful, but impractical, just like the next one.
#      -wd4264: 'int VRDPOutputCtx::SendPacket(void)' : no override available for virtual member function from base 'VRDPOutputCtx'; function is hidden
#      -wd4738: storing 32-bit float result in memory, possible loss of performance
#      -wd4371: UIActionPool.h(393) : warning C4371: 'UIActionPool::PointerToFunction' : layout of class may have changed from a previous version of the compiler due to better packing of member 'UIActionPool::PointerToFunction::ptfr'
#      -wd4748: uiactionpoolmanager.cpp(2723) : warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function
# Want to enable these:
#      -wd4242: '=' : conversion from 'uint32_t' to 'uint8_t', possible loss of data
#      -wd4244: 'conversion' conversion from 'type1' to 'type2', possible loss of data
#      -wd4200: nonstandard extension used : zero-sized array in struct/union
#               Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
VBOX_VCC_WARN_ALL ?= -W4 -Wall -wd4065 -wd4996 -wd4127 -wd4706 -wd4201 -wd4214 -wd4510 -wd4512 -wd4610 \
	-wd4514 -wd4820 -wd4365 -wd4987 -wd4710 -wd4061 -wd4986 -wd4191 -wd4574 -wd4917 -wd4711 -wd4611 -wd4571 -wd4324 -wd4505 \
	-wd4263 -wd4264 -wd4738 -wd4200 -wd4371 -wd4748
if1of ($(VBOX_VCC_TOOL_STEM), VCC120)
 #    -wd4350: behavior change: 'std::_Wrap_alloc<std::allocator<char>>::_Wrap_alloc(const std::_Wrap_alloc<std::allocator<char>> &) throw()' called instead of 'std::_Wrap_alloc<std::allocator<char>>::_Wrap_alloc<std::_Wrap_alloc<std::allocator<char>>>(_Other &) throw()'
 #    -wd4435: iprt/cpp/xml.h(185) : warning C4435: 'xml::Input' : Object layout under /vd2 will change due to virtual base 'xml::Stream'
 VBOX_VCC_WARN_ALL += -wd4350 -wd4435
 VBOX_VCC120_WARN_ALL ?= $(VBOX_VCC_WARN_ALL)
endif
VBOX_VCC_WARN_ALL += -wd4242 -wd4244
ifndef VBOX_NEWER_VCC_WARN_ALL
 if "$(VBOX_VCC_TOOL_STEM)" < "VCC120"
  VBOX_NEWER_VCC_WARN_ALL := $(VBOX_VCC_WARN_ALL) -wd4350 -wd4435
 else
  VBOX_NEWER_VCC_WARN_ALL := $(VBOX_VCC_WARN_ALL)
 endif
endif


# Disable pedantic warnings for NP/NonPedantic templates.
#      -wd4131: 'bi_flush' : uses old-style declarator
#      -wd4255: 'tr_static_init' : no function prototype given: converting '()' to '(void)'
#      -wd4668: '_WIN32_WCE' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'/
#      -wd4100: 'cinfo' : unreferenced formal parameter
#      -wd4189: 'sz' : local variable is initialized but not referenced
#      -wd4132: 'xmlStringComment' : const object should be initialized
#      -wd4152: nonstandard extension, function/data pointer conversion in expression
#      -wd4702: unreachable code
#      -wd4057: '=' : 'xmlChar *' differs in indirection to slightly different base types from 'char *'
#      -wd4296: '>=' : expression is always true
#      -wd4389: '==' : signed/unsigned mismatch
#      -wd4018: '<=' : signed/unsigned mismatch
#      -wd4245: '=' : conversion from 'int' to 'unsigned int', signed/unsigned mismatch
#      -wd4267: '+=' : conversion from 'size_t' to 'long', possible loss of data
#      -wd4295: 'vendor_string' : array is too small to include a terminating null character
VBOX_VCC_NON_PEDANTIC = -wd4131 -wd4255 -wd4668 -wd4100 -wd4189 -wd4132 -wd4152 -wd4702 -wd4057 -wd4296 -wd4389 -wd4018 -wd4245 \
	-wd4267 -wd4295
VBOX_NEWER_VCC_NON_PEDANTIC = $(VBOX_VCC_NON_PEDANTIC)

ifeq ($(KBUILD_TARGET),win)
 VBOX_C_CXX_FLAGS_NO_UNUSED_PARAMETERS = -wd4100
else
 VBOX_C_CXX_FLAGS_NO_UNUSED_PARAMETERS = -Wno-unused-parameter
endif

#
# Compiler optimization flags.
#
ifeq ($(KBUILD_TYPE),debug)
 VBOX_GCC_FP     ?= -fno-omit-frame-pointer
 VBOX_GCC_OPT    ?= -O0
 VBOX_VCC_FP     ?= -Oy-
 VBOX_VCC_OPT    ?=
 VBOX_GCC_R0_FP  ?= -fno-omit-frame-pointer -fno-optimize-sibling-calls
 VBOX_GCC_R0_OPT ?= -O2
 VBOX_VCC_R0_FP  ?= -Oy-
 VBOX_VCC_R0_OPT ?=
 VBOX_GCC_GC_FP  ?= -fno-omit-frame-pointer -fno-optimize-sibling-calls
 VBOX_GCC_GC_OPT ?= -O2
 VBOX_VCC_GC_FP  ?= -Oy-
 VBOX_VCC_GC_OPT ?=
else
 # We should use -fomit-frame-pointer for GCC / -Oy for VCC.
 # -funwind-tables provides support for backtraces in gdb then.
 VBOX_GCC_FP     ?= -fno-omit-frame-pointer
 VBOX_GCC_OPT    ?= -O2 $(VBOX_GCC_mtune-generic)
 VBOX_VCC_FP     ?= -Oy-
 VBOX_VCC_OPT    ?= -O2
 VBOX_GCC_R0_FP  ?= -fno-omit-frame-pointer
 VBOX_GCC_R0_OPT ?= -O2 $(VBOX_GCC_mtune-generic)
 VBOX_VCC_R0_FP  ?= -Oy-
 VBOX_VCC_R0_OPT ?= -O2
 VBOX_GCC_GC_FP  ?= -fno-omit-frame-pointer
 VBOX_GCC_GC_OPT ?= -O2 $(VBOX_GCC_mtune-generic)
 VBOX_VCC_GC_FP  ?= -Oy-
 VBOX_VCC_GC_OPT ?= -O2
endif
ifeq ($(KBUILD_TARGET_ARCH),x86)
 ifneq ($(KBUILD_TARGET),darwin)
  # (The '<=' operator is for prepending (kmk specific).)
  VBOX_GCC_OPT <= -march=i586
 endif
endif


#
# Select the CRT type we're using with Microsoft Visual C++.
#
if1of ($(KBUILD_TYPE), debug dbgopt strict)
#not yet# VBOX_WITH_DEBUG_VCC_CRT = 1
endif
ifdef VBOX_WITH_DEBUG_VCC_CRT
 VBOX_VCC_CRT_TYPE   = d
 VBOX_VCC_CRT_TYPE_N =
else
 VBOX_VCC_CRT_TYPE   =
 VBOX_VCC_CRT_TYPE_N = d
endif


#
# Warnings as errors.
#
# GCC: We disable warnings on non-X86 systems because of the variadic
#      macro usage in the logger.
#
ifdef VBOX_WITH_WARNINGS_AS_ERRORS
 if $(VBOX_GCC_VERSION_CXX) >= 40000
  VBOX_GCC_WERR ?= -Werror
 endif
 VBOX_VCC_WERR ?= -WX
 VBOX_VCC_LD_WERR ?= ## @todo later also: -WX
endif

#
# The general GCC/Clang no warning policy.
#
# Note! This doesn't control everything.  Instead set VBOX_GCC_WERR=$(NO_SUCH_VARIABLE) to
#       completely disable -Werror.
#
if !defined(VBOX_WITHOUT_NO_GCC_WARNING_POLICY) && !defined(VBOX_WITH_NO_GCC_WARNING_POLICY)
 if defined(VBOX_WITH_MASOCHISTIC_WARNINGS) # gcc 4.6.x+
  VBOX_WITH_NO_GCC_WARNING_POLICY = 1
 else if $(KBUILD_TARGET) == "darwin" && defined(VBOX_WITH_NEW_XCODE)
   VBOX_WITH_NO_GCC_WARNING_POLICY = 1
 else if1of ($(KBUILD_TARGET), linux)
  if $(VBOX_GCC_VERSION_CXX) >= 40600 # gcc 4.6.x+
   VBOX_WITH_NO_GCC_WARNING_POLICY = 1
  endif
 endif
endif
ifdef VBOX_WITH_NO_GCC_WARNING_POLICY
 $(info build debug: VBOX_WITH_NO_GCC_WARNING_POLICY is enabled)
endif

#
# Misc stuff that should be after including DynamicConfig.kmk.
#

# libxml XML linter.
ifeq ($(VBOX_XMLLINT),)
 ifeq ($(KBUILD_HOST),win)
  VBOX_XMLLINT := $(wildcard $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).$(KBUILD_HOST_ARCH)/libxslt/10128/bin/xmllint.exe)
 endif
 ifeq ($(VBOX_XMLLINT),)
  VBOX_XMLLINT := $(VBOX_HAVE_XMLLINT)
 endif
 ifneq ($(VBOX_XMLLINT),)
  VBOX_HAVE_XMLLINT := 1
 else
  VBOX_XMLLINT := xmllint
  VBOX_HAVE_XMLLINT :=
 endif
else
 VBOX_HAVE_XMLLINT := 1
endif



#
# Misc macros.
#

##
# Edits VirtualBox version, vendor and package strings in a text file.
#
# The rule using this must list $(VBOX_SVN_REV_KMK) as a prerequisite.
#
# @param    1        The input filename.
# @param    2        The output filename.
#
VBOX_EDIT_VERSION_CMD_FN = $(SED) \
	-e 's/@VBOX_VERSION_MAJOR@/$(VBOX_VERSION_MAJOR)/g' \
	-e 's/@VBOX_VERSION_MINOR@/$(VBOX_VERSION_MINOR)/g' \
	-e 's/@VBOX_VERSION_BUILD@/$(VBOX_VERSION_BUILD)/g' \
	-e 's/@VBOX_VERSION_STRING@/$(VBOX_VERSION_STRING)/g' \
	-e 's/@VBOX_SVN_REV@/$(VBOX_SVN_REV)/g' \
	-e 's/@VBOX_VENDOR@/$(VBOX_VENDOR)/g' \
	-e 's/@VBOX_VENDOR_SHORT@/$(VBOX_VENDOR_SHORT)/g' \
	-e 's/@VBOX_PRODUCT@/$(VBOX_PRODUCT)/g' \
	-e 's/@VBOX_C_YEAR@/$(VBOX_C_YEAR)/g' \
	-e 's/@VBOX_PACKAGE_STRING@/$(VBOX_PACKAGE_STRING)/g' \
	--output $(2) $(1)

##
# Generates a rule for editing a file using VBOX_EDIT_VERSION_CMD_FN.
#
# @param    1        The target name.
# @param    2        The input filename relative to the current sub-makefile.
# @param    3        The output filename relative to the target output dir.
#                    Optional, defaults to 2.
#
VBOX_EDIT_VERSION_RULE_FN = $(eval $(value VBOX_EDIT_VERSION_RULE_DEF))
define VBOX_EDIT_VERSION_RULE_DEF
$$($(1)_0_OUTDIR)/$(if $(3),$(3),$(2)): $(PATH_SUB_CURRENT)/$(2) $(VBOX_SVN_REV_KMK) | $$(dir $$@)
	$(call MSG_GENERATE,$(1),$@,$<)
	$(QUIET)$(call VBOX_EDIT_VERSION_CMD_FN,$<,$@)
$(eval $(1)_CLEAN += $$($(1)_0_OUTDIR)/$(if $(3),$(3),$(2)))
endef


##
# Edits VirtualBox version, vendor, package, build target, build arch, and build type strings in a text file.
#
# Please use VBOX_EDIT_VERSION_AND_BUILD_RULE_FN to generate edit rule.
#
# @param    1        The input filename.
# @param    2        The output filename.
#
VBOX_EDIT_VERSION_AND_BUILD_CMD_FN = $(SED) \
	-e 's/@VBOX_VERSION_MAJOR@/$(VBOX_VERSION_MAJOR)/g' \
	-e 's/@VBOX_VERSION_MINOR@/$(VBOX_VERSION_MINOR)/g' \
	-e 's/@VBOX_VERSION_BUILD@/$(VBOX_VERSION_BUILD)/g' \
	-e 's/@VBOX_VERSION_STRING@/$(VBOX_VERSION_STRING)/g' \
	-e 's/@VBOX_SVN_REV@/$(VBOX_SVN_REV)/g' \
	-e 's/@VBOX_VENDOR@/$(VBOX_VENDOR)/g' \
	-e 's/@VBOX_VENDOR_SHORT@/$(VBOX_VENDOR_SHORT)/g' \
	-e 's/@VBOX_PRODUCT@/$(VBOX_PRODUCT)/g' \
	-e 's/@VBOX_C_YEAR@/$(VBOX_C_YEAR)/g' \
	-e 's/@VBOX_PACKAGE_STRING@/$(VBOX_PACKAGE_STRING)/g' \
	-e 's/@KBUILD_TYPE@/$(KBUILD_TYPE)/g' \
	-e 's/@KBUILD_TARGET@/$(KBUILD_TARGET)/g' \
	-e 's/@KBUILD_TARGET_ARCH@/$(KBUILD_TARGET_ARCH)/g' \
	--output $(2) $(1)

##
# Generates a rule for editing a file using VBOX_EDIT_VERSION_CMD_FN.
#
# @param    1        The target name.
# @param    2        The input filename relative to the current sub-makefile.
# @param    3        The output filename relative to the target output dir.
#                    Optional, defaults to 2.
#
VBOX_EDIT_VERSION_AND_BUILD_RULE_FN = $(eval $(VBOX_EDIT_VERSION_AND_BUILD_RULE_DEF))
define VBOX_EDIT_VERSION_AND_BUILD_RULE_DEF
$$$$($(1)_0_OUTDIR)/$(if $(3),$(3),$(2)): $$(PATH_SUB_CURRENT)/$(2) $$(VBOX_SVN_REV_KMK) | $$$$(dir $$$$@)
	$$(call MSG_GENERATE,$(1),$$@,$$<)
	$$(QUIET)$$(call VBOX_EDIT_VERSION_AND_BUILD_CMD_FN,$$<,$$@)
$(1)_CLEAN += $$($(1)_0_OUTDIR)/$(if $(3),$(3),$(2))
endef


##
# Fill in am import library target based on a somewhat special windows .def file.
#
# @param    1   The target name of the import library.
# @param    2   The name of the real library.
# @param    3   The .def-file paths relative to the current makefile.
#
VBOX_GENERATE_IMPORT_TARGET_FN = $(eval $(VBOX_GENERATE_IMPORT_TARGET_DEF))
define VBOX_GENERATE_IMPORT_TARGET_DEF
$(1)_TEMPLATE = VBoxR3Dll
$(1)_INST     = $(INST_LIB)
if $(KBUILD_TARGET) == "darwin"
 $(1)_LDFLAGS = -install_name $(VBOX_DYLD_EXECUTABLE_PATH)/$(2)$(SUFF_DLL)
else ifn1of ($(KBUILD_TARGET), os2 win)
 $(1)_SONAME  = $(2)$(SUFF_DLL)
endif
if1of ($(KBUILD_TARGET), os2 win)
 $(1)_SOURCES = $$($(1)_0_OUTDIR)/$(1)Imp.def
 $(1)_CLEAN   = $$($(1)_0_OUTDIR)/$(1)Imp.def
else
 $(1)_SOURCES = $$($(1)_0_OUTDIR)/$(1)Imp.c
 $(1)_CLEAN   = $$($(1)_0_OUTDIR)/$(1)Imp.c
endif

$$$$($(1)_SOURCES): $(addprefix $(PATH_SUB_CURRENT)/,$(3)) $(PATH_ROOT)/src/bldprogs/deftoimp.sed | $$$$(dir $$$$@)
	$$(call MSG_GENERATE,,$$@)
ifeq ($(KBUILD_TARGET),os2)
	$$(SED) \
		-e '/not-$(KBUILD_TARGET)/d' \
		-e '/not-$(KBUILD_TARGET_ARCH)/d' \
		-e 's/^LIBRARY[[:space:]][[:space:]]*\(.*\)\.dll/LIBRARY \1 INITINSTANCE TERMINSTANCE\nDATA MULTIPLE\n/' \
		-e 's/^[ \t][ \t]*\([_a-zA-Z]\)/    _\1/' \
		-e 's/[ \t]DATA[ \t]*/ /'  \
		--output $$@ $(addprefix $(PATH_SUB_CURRENT)/,$(3))
else ifeq ($(KBUILD_TARGET),win)
	$$(SED) \
		-e '/not-$(KBUILD_TARGET)/d' \
		-e '/not-$(KBUILD_TARGET_ARCH)/d' \
		--output $$@ $(addprefix $(PATH_SUB_CURRENT)/,$(3))
else
	$$(QUIET)$$(APPEND) -tn $$@ \
		'#ifdef VBOX_HAVE_VISIBILITY_HIDDEN' \
		'# define EXPORT __attribute__((visibility("default")))' \
		'# define EXPORT_DATA __attribute__((visibility("default")))' \
		'#else' \
		'# define EXPORT' \
		'# define EXPORT_DATA' \
		'#endif' \
		''
	$$(SED) \
		-e '/not-$(KBUILD_TARGET)/d' \
		-e '/not-$(KBUILD_TARGET_ARCH)/d' \
		-f $(PATH_ROOT)/src/bldprogs/deftoimp.sed \
		--append $$@ $(addprefix $(PATH_SUB_CURRENT)/,$(3))
endif
endef # VBOX_GENERATE_IMPORT_TARGET_DEF


#
# Code Signing.
#
# There are two signing modes; 'test' and 'release'.
#  - The 'test' mode is tailored local development, where typically test
#    certificates are involved. Only the bar minimum of files are signed and
#    nothing is timestamped (if we can control timestamping) in order to reduce
#    build time and to allow working offline.
#  - The 'release' mode is tailored for creating builds that are give to other
#    people, like the ones the build servers create.  As much as possible is
#    signed and timestamped.
#
ifdef VBOX_SIGNING_MODE
 VBOX_SIGNING_MODE := $(strip $(VBOX_SIGNING_MODE))
 ifn1of ($(VBOX_SIGNING_MODE), test release)
  $(error VBOX_SIGNING_MODE must be either 'test' or 'release'. The value '$(VBOX_SIGNING_MODE)' is not recognized.)
 endif
 VBOX_RETRY    ?= $(ASH) $(KBUILD_DEVTOOLS)/bin/retry.sh
 # temporary solution for a $(dir ...) equivalent which assumes that it gets a single path, possibly with spaces.
 VBOX_DIRX = $(subst ?,$(SP),$(dir $(subst $(SP),?,$1)))
 # Corp code signing client.
 VBOX_CCS_CLIENT_JAR := $(firstword $(rsort \
 	$(wildcard $(KBUILD_DEVTOOLS)/common/ccs/v*/Client.jar)) \
	$(KBUILD_DEVTOOLS)/common/ccs/notfound/Client.jar )
 VBOX_CCS_USER       ?= virtualbox_grp
 VBOX_CCS_GLOBAL_UID ?= non-of-your-business
 VBOX_CCS_SERVER     ?= UK
 ##
 # Corp Code Signing command line.
 # @param  $1  Signing method: solaris_elf, solaris_pkg, driver (microsoft), ...
 # @param  $2  The file to be submitted for signing.
 # @param  $3  The directory to put the signed file in. Defaults to $(dir $2).
 # @param  $4  Additional options.
 VBOX_CCS_SIGN_CMD    = $(VBOX_RETRY) $(VBOX_JAVA) -jar "$(VBOX_CCS_CLIENT_JAR)" \
 	sign -user "$(VBOX_CCS_USER)" -global_uid "$(VBOX_CCS_GLOBAL_UID)" \
		-job_timeout 90 -server_timeout 75 -server "$(VBOX_CCS_SERVER)" \
 		-sign_method "$1" -file_to_sign "$2" -signed_location "$(if $3,$3,$(call VBOX_DIRX,$2))" $4

 ifeq ($(KBUILD_HOST),win)
  #
  # Windows
  #

  # VBOX_PATH_SELFSIGN points to the Vista WDK bin/SelfSign directory.
  ifndef VBOX_PATH_SELFSIGN
   VBOX_PATH_SELFSIGN := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS)/win.x86/selfsign/*)))
   ifeq ($(VBOX_PATH_SELFSIGN),)
    VBOX_PATH_SELFSIGN := $(KBUILD_DEVTOOLS)/win.x86/selfsign/r1
   endif
  endif
  ifndef VBOX_PATH_SIGN_TOOLS
   VBOX_PATH_SIGN_TOOLS := $(firstword $(rsort $(wildcard \
   	$(addprefix $(KBUILD_DEVTOOLS)/win.x86/sdk/v8.1*/Bin/, x86 $(if-expr $(KBUILD_HOST_ARCH)=="amd64",x64,) ) )))
   ifeq ($(VBOX_PATH_SIGN_TOOLS),)
    VBOX_PATH_SIGN_TOOLS := $(firstword $(rsort $(wildcard \
    	$(addprefix $(KBUILD_DEVTOOLS)/win.x86/sdk/v10*/Bin/, x86 $(if-expr $(KBUILD_HOST_ARCH)=="amd64",x64,) ) )))
    ifeq ($(VBOX_PATH_SIGN_TOOLS),)
     VBOX_PATH_SIGN_TOOLS := $(VBOX_PATH_SELFSIGN)
    endif
   endif
  endif

  VBOX_SIGNTOOL ?= $(VBOX_RETRY) "$(VBOX_PATH_SIGN_TOOLS)/signtool.exe"
  VBOX_INF2CAT  ?= $(VBOX_PATH_SELFSIGN)/inf2cat.exe

  ifeq ($(VBOX_SIGNING_MODE),test)
   VBOX_CERTIFICATE_SUBJECT_NAME ?= MyTestCertificate
   VBOX_CERTIFICATE_SUBJECT_NAME_ARGS ?= /n "$(VBOX_CERTIFICATE_SUBJECT_NAME)"
  else # release
   VBOX_CERTIFICATE_SUBJECT_NAME ?= Oracle Corporation
   VBOX_CERTIFICATE_SUBJECT_NAME_ARGS ?= /n "$(VBOX_CERTIFICATE_SUBJECT_NAME)" /a
   #VBOX_CERTIFICATE_FINGERPRINT ?= 7e 92 b6 6b e5 1b 79 d8 ce 3f f2 5c 15 c2 df 6a b8 c7 f2 f2
   #VBOX_CERTIFICATE_FINGERPRINT ?= 5b de fe 58 0a 81 66 61 cd b5 7a 57 10 7b f4 18 74 86 ef cc
   VBOX_CERTIFICATE_FINGERPRINT ?= 6f 47 42 06 bc bb 39 1b b8 2b a9 e5 dc 03 02 de f3 7a eb be
   #VBOX_CROSS_CERTIFICATE_FILE ?= $(VBOX_PATH_SELFSIGN)/VeriSign Class 3 Public Primary Certification Authority - G5.cer
   VBOX_CROSS_CERTIFICATE_FILE ?= $(VBOX_PATH_SELFSIGN)/DigiCert Assured ID Root CA.crt
   #VBOX_TSA_URL ?= http://timestamp.verisign.com/scripts/timstamp.dll - Appears to be broken between 2020-12-25 and 2020-12-30 (bugref:9849).
   VBOX_TSA_URL ?= http://timestamp.digicert.com
  endif
  if !defined(VBOX_CROSS_CERTIFICATE_FILE_ARGS) && defined(VBOX_CROSS_CERTIFICATE_FILE)
   VBOX_CROSS_CERTIFICATE_FILE_ARGS = /ac "$(VBOX_CROSS_CERTIFICATE_FILE)"
  endif
  if !defined(VBOX_TSA_URL_ARGS) && defined(VBOX_TSA_URL)
   VBOX_TSA_URL_ARGS = /t "$(VBOX_TSA_URL)"
  endif
  VBOX_CERTIFICATE_STORE ?= my
  VBOX_CERTIFICATE_STORE_ARGS ?= /s "$(VBOX_CERTIFICATE_STORE)"
  VBOX_CERTIFICATE_FINGERPRINT_ARGS := $(if-expr "$(VBOX_CERTIFICATE_FINGERPRINT)" != "" \
  	,/sha1 "$(subst $(SP),,$(VBOX_CERTIFICATE_FINGERPRINT))",)

  ifeq ($(VBOX_SIGNING_MODE),test)
   #VBOX_CERTIFICATE_SHA2_SUBJECT_NAME ?= MyTestCertificateSha2
   VBOX_CERTIFICATE_SHA2_SUBJECT_NAME_ARGS ?= /n "$(VBOX_CERTIFICATE_SHA2_SUBJECT_NAME)"
  else # release
   VBOX_CERTIFICATE_SHA2_SUBJECT_NAME ?= Oracle Corporation
   VBOX_CERTIFICATE_SHA2_SUBJECT_NAME_ARGS ?= /n "$(VBOX_CERTIFICATE_SHA2_SUBJECT_NAME)" /a
   #VBOX_CERTIFICATE_SHA2_FINGERPRINT ?= 31 31 bb 58 8b 19 9e 6e 85 0f d3 35 82 b0 c5 82 55 e1 6c 49
   #VBOX_CERTIFICATE_SHA2_FINGERPRINT ?= 22 05 6a 4d 46 2e 3d 2b b2 c3 2f bf b0 5b 84 c4 65 9c f7 fe
   #VBOX_CERTIFICATE_SHA2_FINGERPRINT ?= 17 3a 19 bf 8e 62 72 be 25 04 d3 08 aa 68 b1 b0 0e 03 33 2c
   VBOX_CERTIFICATE_SHA2_FINGERPRINT ?= 30 65 6f ca 8c 48 b1 d9 86 23 a9 4b 40 a6 bc 98 bd 87 bf ad
   VBOX_CROSS_CERTIFICATE_SHA2_FILE ?= $(VBOX_PATH_SELFSIGN)/DigiCert Assured ID Root CA.crt
   #VBOX_TSA_SHA2_URL ?= http://sha256timestamp.ws.symantec.com/sha256/timestamp - phase out for consistency reasons
   VBOX_TSA_SHA2_URL ?= http://timestamp.digicert.com
  endif
  if !defined(VBOX_CROSS_CERTIFICATE_SHA2_FILE_ARGS) && defined(VBOX_CROSS_CERTIFICATE_SHA2_FILE)
   VBOX_CROSS_CERTIFICATE_SHA2_FILE_ARGS = /ac "$(VBOX_CROSS_CERTIFICATE_SHA2_FILE)"
  endif
  if !defined(VBOX_TSA_SHA2_URL_ARGS) && defined(VBOX_TSA_SHA2_URL)
   VBOX_TSA_SHA2_URL_ARGS = /tr "$(VBOX_TSA_SHA2_URL)"
  endif
  VBOX_CERTIFICATE_SHA2_STORE ?= my
  VBOX_CERTIFICATE_SHA2_STORE_ARGS ?= /s "$(VBOX_CERTIFICATE_SHA2_STORE)"
  VBOX_CERTIFICATE_SHA2_FINGERPRINT_ARGS := $(if-expr "$(VBOX_CERTIFICATE_SHA2_FINGERPRINT)" != "" \
  	,/sha1 "$(subst $(SP),,$(VBOX_CERTIFICATE_SHA2_FINGERPRINT))",) # Still using SHA-1 for fingerprinting, it's good enough for that!
  #VBOX_CERTIFICATE_EV_SUBJECT_NAME ?= MyEvCertificate
  VBOX_CERTIFICATE_EV_SUBJECT_NAME_ARGS ?= /n "$(VBOX_CERTIFICATE_EV_SUBJECT_NAME)"
  VBOX_CERTIFICATE_EV_STORE ?= my
  VBOX_CERTIFICATE_EV_STORE_ARGS ?= /s "$(VBOX_CERTIFICATE_EV_STORE)"
  #VBOX_CERTIFICATE_EV_FINGERPRINT ?= my ev cert fingerprint
  VBOX_CERTIFICATE_EV_FINGERPRINT_ARGS := $(if-expr "$(VBOX_CERTIFICATE_EV_FINGERPRINT)" != "" \
  	,/sha1 "$(subst $(SP),,$(VBOX_CERTIFICATE_EV_FINGERPRINT))",) # Still using SHA-1 for fingerprinting, it's good enough for that!

  ## Sign a file (generic).
  # @param 1  The file to sign.
  # @param 2  File description. Optional.
  # @param 3  Additional parameters. Optional.
  # @param 4  Set to 2 if the expression will be expanded twice before chopped into commands (for _CMDS).
  # @param 5  Disables dual signing if non-empty.
  # @param 6  non-zero for alternative command separator.  This is used for generating repacking scripts.
  ifndef VBOX_SIGN_FILE_FN
   if $(intersects win all 1,$(VBOX_WITH_CORP_CODE_SIGNING))
    VBOX_SIGN_FILE_FN     = $(call VBOX_CCS_SIGN_CMD,driver$(if-expr "$3" == "/ph",_pagehash,),$1,,-digest_algo SHA1) \
        $(if-expr "$5" == "",\
         $(if-expr "$6" == "",$(if-expr "$4" == "2",$$(NLTAB),$(NLTAB)),$6) \
         $(call VBOX_CCS_SIGN_CMD,driver$(if-expr "$3" == "/ph",_pagehash,),$1,,-dual_sign -digest_algo SHA2))
   else ifdef VBOX_CERTIFICATE_SHA2_SUBJECT_NAME
    VBOX_SIGN_FILE_FN     = $(VBOX_SIGNTOOL) \
    	sign /fd sha1\
	$(VBOX_CROSS_CERTIFICATE_FILE_ARGS) \
	$(VBOX_CERTIFICATE_STORE_ARGS) \
	$(VBOX_CERTIFICATE_SUBJECT_NAME_ARGS) \
       $(VBOX_CERTIFICATE_FINGERPRINT_ARGS) \
	$(VBOX_TSA_URL_ARGS) \
	$(if $(strip $(2)),/d "$(strip $(2))",) \
	$(3) \
	$(1) \
    	$(if-expr "$5" == "",\
	$(if-expr "$6" == "",$(if-expr "$4" == "2",$$(NLTAB),$(NLTAB)),$6)$(VBOX_SIGNTOOL) \
    	sign /as /fd sha256 \
	$(VBOX_CROSS_CERTIFICATE_SHA2_FILE_ARGS) \
	$(VBOX_CERTIFICATE_SHA2_STORE_ARGS) \
	$(VBOX_CERTIFICATE_SHA2_SUBJECT_NAME_ARGS) \
	$(VBOX_CERTIFICATE_SHA2_FINGERPRINT_ARGS) \
	$(VBOX_TSA_SHA2_URL_ARGS) \
	$(if $(strip $(2)),/d "$(strip $(2))",) \
	$(3) \
	$(1),)
   else
    VBOX_SIGN_FILE_FN     = $(VBOX_SIGNTOOL) sign \
	$(VBOX_CROSS_CERTIFICATE_FILE_ARGS) \
	$(VBOX_CERTIFICATE_STORE_ARGS) \
	$(VBOX_CERTIFICATE_SUBJECT_NAME_ARGS) \
	$(VBOX_CERTIFICATE_FINGERPRINT_ARGS) \
	$(VBOX_TSA_URL_ARGS) \
	$(if $(strip $(2)),/d "$(strip $(2))",) \
	$(3) \
	$(1)
   endif
  endif

  ## EV sign a file (generic).
  # @param 1  The file to sign.
  # @param 2  The directory to put the signed file in. Defaults to $(dir $1).
  ifndef VBOX_SIGN_EV_FILE_FN
   if $(intersects win_ev all 1,$(VBOX_WITH_CORP_CODE_SIGNING))
    VBOX_SIGN_EV_FILE_FN  = $(call VBOX_CCS_SIGN_CMD,microsoftev,$1,$(if $2,$2,))
   else ifdef VBOX_CERTIFICATE_EV_SUBJECT_NAME
    VBOX_SIGN_EV_FILE_FN  = $(VBOX_SIGNTOOL) \
    	sign /as /fd sha256 \
	$(VBOX_CERTIFICATE_EV_STORE_ARGS) \
	$(VBOX_CERTIFICATE_EV_SUBJECT_NAME_ARGS) \
	$(VBOX_CERTIFICATE_EV_FINGERPRINT_ARGS) \
	$(VBOX_TSA_SHA2_URL_ARGS) \
	$(1)
   endif
  endif

  ## Corp code signing for drivers and catalogs, plan B.
  #
  # Since the corp code signing cannot dual signing and doesn't even have a
  # SHA-1 cert, we have to get creative:
  #   1. Sign $1 using local SHA-1 certificate.
  #   2. Make temporary copy of $1 as $1.ccs
  #   3. Do SHA-256 corp code signing of $1.ccs
  #   4. Add the SHA-256 signature from $1.ccs to $1 using bldRTSignTool.
  #   5. Delete $1.ccs.
  #
  # @param 1  The file to sign.
  # @param 2  File description. Optional.
  # @param 3  Additional parameters. Optional.
  # @param 4  Set to 2 if the expression will be expanded twice before chopped into commands (for _CMDS).
  # @param 5  Disables dual signing if non-empty.
  #
  # @remarks The parameters are the same as VBOX_SIGN_FILE_FN.
  VBOX_SIGN_IMAGE_PLAN_B_FN = $(VBOX_SIGNTOOL) \
  	sign /fd sha1\
  	$(VBOX_CROSS_CERTIFICATE_FILE_ARGS) \
  	$(VBOX_CERTIFICATE_STORE_ARGS) \
  	$(VBOX_CERTIFICATE_SUBJECT_NAME_ARGS) \
  	$(VBOX_CERTIFICATE_FINGERPRINT_ARGS) \
  	$(VBOX_TSA_URL_ARGS) \
  	$(if $(strip $(2)),/d "$(strip $(2))",) \
  	$(3) \
  	$(1) \
  	$(if-expr "$5" == "",\
	$(if-expr "$4" == "2",$$(NLTAB),$(NLTAB))$(RM) -f -- "$1.ccs" \
  	$(if-expr "$4" == "2",$$(NLTAB),$(NLTAB))$(CP) -- "$1" "$1.ccs" \
  	$(if-expr "$4" == "2",$$(NLTAB),$(NLTAB))$(call VBOX_CCS_SIGN_CMD,driver$(if-expr "$3" == "/ph",_pagehash,),$1.ccs,,-digest_algo SHA2) \
  	$(if-expr "$4" == "2",$$(NLTAB),$(NLTAB))$(VBOX_RTSIGNTOOL) add-nested-$(if-expr "$(suffix $1)" == ".cat",cat,exe)-signature -v "$1" "$1.ccs" \
  	$(if-expr "$4" == "2",$$(NLTAB),$(NLTAB))$(RM) -f -- "$1.ccs" \
  	,)

  ## Sign an executable image.
  # @param 1  The file to sign.
  # @param 2  File description. Optional.
  # @param 3  Set to 2 if the expression will be expanded twice before chopped into commands (for _CMDS).
  VBOX_SIGN_IMAGE_FN     ?= $(call VBOX_SIGN_FILE_FN,$(1),$(2),/ph,$(3))

  ## Commands for signing a driver image after link.
  if $(intersects win_planb,$(VBOX_WITH_CORP_CODE_SIGNING))
   VBOX_SIGN_DRIVER_CMDS ?= $(if $(eq $(tool_do),LINK_LIBRARY),,$(call VBOX_SIGN_IMAGE_PLAN_B_FN,$(out),,/ph,2))
   VBOX_SIGN_DRIVER_ORDERDEPS ?= $(VBOX_RTSIGNTOOL)
  else
   VBOX_SIGN_DRIVER_CMDS ?= $(if $(eq $(tool_do),LINK_LIBRARY),,$(call VBOX_SIGN_IMAGE_FN,$(out),,2))
  endif

  ## Create a security catalog file.
  # @param 1  The directory containing the stuff to sign.
  # @param 2  The expected .cat name. (Inf2Cat lowercases it)
  # @param 3  The list of OSes, separated by ';'.
  ifndef VBOX_MAKE_CAT_HLP_FN
   VBOX_MAKE_CAT_HLP_FN = \
	$(RM) -f -- "$(2)"\
	$(NL)$(TAB)$(VBOX_INF2CAT) "/driver:$(strip $(1))" "/os:$(strip $(subst ;,$(COMMA),$(3)))" /verbose \
	$(NL)$(TAB)$(MV) -- "$(2)" "$(2)"
   if $(intersects win_planb,$(VBOX_WITH_CORP_CODE_SIGNING))
    VBOX_MAKE_CAT_HLP_FN += $(NL)$(TAB)$(call VBOX_SIGN_IMAGE_PLAN_B_FN,$(2),,,$(NL)$(TAB))
   else
    VBOX_MAKE_CAT_HLP_FN += $(NL)$(TAB)$(call         VBOX_SIGN_FILE_FN,$(2),,,$(NL)$(TAB))
   endif
  endif
  VBOX_MAKE_CAT64_FN   ?= $(call VBOX_MAKE_CAT_HLP_FN,$(1),$(2),XP_X64;Server2003_X64;Vista_X64)
  VBOX_MAKE_CAT32_FN   ?= $(call VBOX_MAKE_CAT_HLP_FN,$(1),$(2),2000;XP_X86;Server2003_X86;Vista_X86)
  ifeq ($(KBUILD_TARGET_ARCH),x86)
   VBOX_MAKE_CAT_FN    ?= $(call VBOX_MAKE_CAT32_FN,$(1),$(2))
  else
   VBOX_MAKE_CAT_FN    ?= $(call VBOX_MAKE_CAT64_FN,$(1),$(2))
  endif

  # Go nuts, sign everything.
  if "$(VBOX_SIGNING_MODE)" == "release" || defined(VBOX_WITH_HARDENING)
   ## Commands for signing an executable or a dll image after link.
   VBOX_SIGN_IMAGE_CMDS  ?= $(if $(eq $(tool_do),LINK_LIBRARY),,$(call VBOX_SIGN_IMAGE_FN,$(out),,2))
  endif
  ## Enable signing of the additions.
  VBOX_SIGN_ADDITIONS   ?= 1

 else ifeq ($(KBUILD_HOST),darwin)
  #
  # Darwin code signing.
  #
  # Currently release signing is done when packing.  This may change later.
  # (Installer package signing is done elsewhere (VBOX_MACOSX_INSTALLER_SIGN).)
  #
  if defined(VBOX_CERTIFICATE_FINGERPRINT) && !defined(VBOX_CERTIFICATE_SUBJECT_NAME)
    VBOX_CERTIFICATE_SUBJECT_NAME = $(subst $(SP),,$(VBOX_CERTIFICATE_FINGERPRINT))
  endif
  ifeq ($(VBOX_SIGNING_MODE),test)
   VBOX_CERTIFICATE_SUBJECT_NAME ?= $(error You need to set VBOX_CERTIFICATE_SUBJECT_NAME in LocalConfig.kmk.)
   VBOX_CERTIFICATE_SUBJECT_NAME_ARGS ?= --sign "$(VBOX_CERTIFICATE_SUBJECT_NAME)"
  else
   VBOX_CERTIFICATE_SUBJECT_NAME ?= Developer ID Application: Oracle America, Inc.
   VBOX_CERTIFICATE_SUBJECT_NAME_ARGS ?= --sign "$(VBOX_CERTIFICATE_SUBJECT_NAME)"
  endif

  VBOX_CODESIGN ?= codesign
  if 0
   VBOX_DARWIN_KEXT_SIGN_FILES = CodeDirectory CodeRequirement CodeResources CodeSignature
  else
   VBOX_DARWIN_KEXT_SIGN_FILES = CodeResources
  endif

  ##
  # Corp Code Notarization command line. Modifies the file because the tickets are stapled.
  # @param 1  The file to be submitted for signing.
  # @param 2  Identifier, mandatory.
  # @param 3  The directory to put the notarized file in. Defaults to $(dir $1).
 VBOX_CCS_NOTARIZE_CMD = $(VBOX_RETRY) $(VBOX_JAVA) -jar "$(VBOX_CCS_CLIENT_JAR)" \
 	mac_notarize -user "$(VBOX_CCS_USER)" -global_uid "$(VBOX_CCS_GLOBAL_UID)" \
		-job_timeout 90 -server_timeout 75 -server "$(VBOX_CCS_SERVER)" \
 		-file_to_notarize "$1" -bundle_id "$2" -download_location "$(if $3,$3,$(call VBOX_DIRX,$1))"

  ## Sign an application bundle, framework or kernel extension.
  # @param 1  The bundle to sign.
  # @param 2  Identifier, optional.
  # @param 3  Additional codesign command line parameters, optional.
  if $(intersects darwin all 1,$(VBOX_WITH_CORP_CODE_SIGNING))
   ## @todo cannot handle $(2), the identifier.
   ## @todo $(3) is hopefully either empty, --deep or --entitlements=...
   VBOX_SIGN_BUNDLE_FN = $(call MSG_TOOL,SIGNTOOL,,$(1),$(2))$(NLTAB) \
	ditto -c -k -V --keepParent "$(1)" "$(1).zip"$(NLTAB) \
	$(call VBOX_CCS_SIGN_CMD,apple,$(1).zip,,$(subst --entitlements=,-entitlement_file_path ,$(subst --deep,-deep,$(3))) \
		$(if $(VBOX_WITH_MACOS_HARDENED_RUNTIME),-hardened_runtime))$(NLTAB) \
	ditto -x -k -V "$(1).zip" "$(1)/../"$(NLTAB) \
	$(RM) -f -- "$(1).zip"
  else
   VBOX_SIGN_BUNDLE_FN = $(call MSG_TOOL,SIGNTOOL,,$(1),$(2))$(NLTAB)$(VBOX_CODESIGN) \
	--verbose=9 \
	--force \
	$(if-expr $(KBUILD_HOST_VERSION_MAJOR) <= 14,--digest-algorithm sha256,) \
	$(if $(VBOX_WITH_MACOS_HARDENED_RUNTIME),$(if-expr $(KBUILD_HOST_VERSION_MAJOR) <= 16,--options 0x10000,--options runtime)) \
	--file-list - \
	$(if-expr defined(VBOX_TSA_URL),--timestamp="$(VBOX_TSA_URL)") \
	$(3) \
	$(VBOX_CERTIFICATE_SUBJECT_NAME_ARGS) \
	$(1) $(if $(2),--identifier "$(2)",)
  endif

  ## Sign a Mach-O image.
  # @param 1  The file to sign.
  # @param 2  Identifier, optional.
  # @param 3  Additional codesign command line parameters, optional.
  if $(intersects darwin all 1,$(VBOX_WITH_CORP_CODE_SIGNING))
   ## @todo cannot handle $(2), the identifier.
   ## @todo $(3) is hopefully either empty or --entitlements=...
   VBOX_SIGN_MACHO_FN = $(call MSG_TOOL,SIGNTOOL,,$(1),$(2))$(NLTAB) \
	$(call VBOX_CCS_SIGN_CMD,binary,$(1),,$(subst --entitlements=,-entitlement_file_path ,$(3)) \
		$(if $(VBOX_WITH_MACOS_HARDENED_RUNTIME),-hardened_runtime))
  else
   VBOX_SIGN_MACHO_FN = $(call MSG_TOOL,SIGNTOOL,,$(1),$(2))$(NLTAB)$(VBOX_CODESIGN) \
	--verbose=9 \
	--force \
	$(if-expr $(KBUILD_HOST_VERSION_MAJOR) <= 14,--digest-algorithm sha256,) \
	$(if $(VBOX_WITH_MACOS_HARDENED_RUNTIME),$(if-expr $(KBUILD_HOST_VERSION_MAJOR) <= 16,--options 0x10000,--options runtime)) \
	--file-list - \
	$(if-expr defined(VBOX_TSA_URL),--timestamp="$(VBOX_TSA_URL)") \
	$(VBOX_CERTIFICATE_SUBJECT_NAME_ARGS) \
	$(3) \
	$(1) \
	$(if $(2),--identifier "$(2)",)
  endif

  ## Commands for signing an the extpack dylib files after link.
  if $(intersects darwin all 1,$(VBOX_WITH_CORP_CODE_SIGNING))
   VBOX_SIGN_EXTPACK_DYLIB_CMDS ?= $(if $(eq $(tool_do),LINK_LIBRARY),, \
	$(call VBOX_CCS_SIGN_CMD,binary,$(out),, \
		$(if $(VBOX_WITH_MACOS_HARDENED_RUNTIME),-hardened_runtime)) )
  else
   VBOX_SIGN_EXTPACK_DYLIB_CMDS ?= $(if $(eq $(tool_do),LINK_LIBRARY),, \
	$(VBOX_CODESIGN) \
	--verbose=9 \
	--force \
	$(if-expr $(KBUILD_HOST_VERSION_MAJOR) <= 14,--digest-algorithm sha256,) \
	$(if $(VBOX_WITH_MACOS_HARDENED_RUNTIME),$(if-expr $(KBUILD_HOST_VERSION_MAJOR) <= 16,--options 0x10000,--options runtime)) \
	--file-list - \
	$(if-expr defined(VBOX_TSA_URL),--timestamp="$(VBOX_TSA_URL)") \
	$(VBOX_CERTIFICATE_SUBJECT_NAME_ARGS) \
	$(out) )
  endif

  ## Sign a VMM Mach-O image.
  # @param 1  The file to sign.
  # @param 2  Identifier, optional.
  VBOX_SIGN_VMM_MOD_FN = $(VBOX_SIGN_MACHO_FN)

  ## Sign a non-executable file.
  # @param 1  The file to sign.
  # @param 2  Identifier, optional.
  if $(intersects darwin all 1,$(VBOX_WITH_CORP_CODE_SIGNING))
   ## @todo cannot handle $(2), the identifier.
   VBOX_SIGN_FILE_FN = $(call MSG_TOOL,SIGNTOOL,,$(1),$(2))$(NLTAB)$(call VBOX_CCS_SIGN_CMD,binary,$(1))
  else
   VBOX_SIGN_FILE_FN = $(call MSG_TOOL,SIGNTOOL,,$(1),$(2))$(NLTAB)$(VBOX_CODESIGN) \
	--verbose=9 \
	--force \
	$(if-expr $(KBUILD_HOST_VERSION_MAJOR) <= 14,--digest-algorithm sha256,) \
	--file-list=- \
	$(if-expr defined(VBOX_TSA_URL),--timestamp="$(VBOX_TSA_URL)") \
	$(if $(2),--identifier "$(2)",) \
	$(VBOX_CERTIFICATE_SUBJECT_NAME_ARGS) \
	$(1)
  endif

  ## Sign a DMG image.
  # @param 1  The file to sign.
  # @param 2  Identifier, optional.
  # @note Will segfault if --file-list is used on 10.15.2 (kSecCodeInfoChangedFiles -> NULL, outputter doesn't check for NULL).
  VBOX_SIGN_DMG_FN = $(filter-out --file-list=-,$(VBOX_SIGN_FILE_FN))

  ## Sign a PKG file. Used with corp code signing only.
  # @param 1  The file to sign.
  # @param 2  Identifier, optional.
  if $(intersects darwin all 1,$(VBOX_WITH_CORP_CODE_SIGNING))
   ## @todo cannot handle $(2), the identifier.
   VBOX_SIGN_PKG_FN = $(call MSG_TOOL,SIGNTOOL,,$(1),$(2))$(NLTAB)$(call VBOX_CCS_SIGN_CMD,mac_pkg,$(1))
  endif

  ## Notarize a file (usually DMG, can also be PKG). Used with corp code signing only.
  # @param 1  The file to notarize.
  # @param 2  Identifier, mandatory.
  if $(intersects darwin all 1,$(VBOX_WITH_CORP_CODE_SIGNING))
   VBOX_NOTARIZE_FILE_FN = $(call MSG_TOOL,SIGNTOOL,,$(1),$(2))$(NLTAB)$(call VBOX_CCS_NOTARIZE_CMD,$(1),$(2))
  endif

  ## @def VBOX_TEST_SIGN_KEXT
  # Adds test signing to a $1.kext target (the plist installer target).
  #
  # After both targets has been defined:
  #    $(evalcall2 VBOX_TEST_SIGN_KEXT,VBoxDrv)
  #
  # @param 1   The kext name.  Assumes there is a SYSMODS target of name $1
  #            as well as an .plist installer by the name of '$1.kext'.
  # @remarks   Currently assumes only binary + Info.plist in the bundle, no
  #            other files.  Should there be more, add them as a list in
  #            a 2nd parameter.
  # @note      This is only for the 'test' signing mode, we skip this in
  #            'release' signing mode as to not waste time on the build boxes.
  ifeq ($(VBOX_SIGNING_MODE),test) ## @todo when kBuild is updated to r2742+, this should be enabled for both modes.
   define VBOX_TEST_SIGN_KEXT
  $1_INSTTYPE.darwin = none

  $1.kext_SOURCES  += $$($1.kext_0_OUTDIR)/Contents/MacOS/$1=>MacOS/$1 \
  	$(foreach extfile, $(VBOX_DARWIN_KEXT_SIGN_FILES) \
	        , $$($1.kext_0_OUTDIR)/Contents/_CodeSignature/$(extfile)=>_CodeSignature/$(extfile))
  $1.kext_SYMLINKS += $(foreach symfile, $(VBOX_DARWIN_KEXT_SIGN_SYMLINKS), $(symfile)=>_CodeSignature/$(symfile))
  $1.kext_CLEAN    += \
  	$(foreach extfile, $(VBOX_DARWIN_KEXT_SIGN_FILES)   , $$($1.kext_0_OUTDIR)/Contents/_CodeSignature/$(extfile)) \
  	$(foreach symfile, $(VBOX_DARWIN_KEXT_SIGN_SYMLINKS), $$($1.kext_0_OUTDIR)/Contents/$(symfile)) \
	$$($1.kext_0_OUTDIR)/Contents/MacOS/$1 \
	$$($1.kext_0_OUTDIR)/$1.kext/Contents/_CodeSignature/
  $1.kext_BLDDIRS  += $$($1.kext_0_OUTDIR)/Contents/MacOS/

  $$$$($1.kext_0_OUTDIR)/Contents/MacOS/$1 \
  + $(foreach file,$(VBOX_DARWIN_KEXT_SIGN_FILES), $$$$($1.kext_0_OUTDIR)/Contents/_CodeSignature/$(file)): \
 		$$$$($1.kext_0_OUTDIR)/Contents/Info.plist $$$$($1_1_TARGET) | $$$$($1.kext_0_OUTDIR)/
	$(RM) -Rf -- "$$($1.kext_0_OUTDIR)/Contents/_CodeSignature/" "$$($1.kext_0_OUTDIR)/Contents/MacOS/"
	$(MKDIR) -p -- "$$($1.kext_0_OUTDIR)/Contents/MacOS/"
	$(INSTALL) -m 644 $$($1_1_TARGET) $$($1.kext_0_OUTDIR)/Contents/MacOS/$1
	$(call VBOX_SIGN_BUNDLE_FN,$$($1.kext_0_OUTDIR),org.virtualbox.app.kext.$1,)
   endef
  else
   VBOX_TEST_SIGN_KEXT =
  endif


 else ifeq ($(KBUILD_HOST),solaris)
  #
  # Solaris code signing.
  #
  ifeq ($(VBOX_SIGNING_MODE),test)
   VBOX_CERTIFICATE_FILE  ?= $(error You need to set VBOX_CERTIFICATE_FILE in LocalConfig.kmk.)
   VBOX_TOKEN_NAME        ?= $(error You need to set VBOX_TOKEN_NAME in LocalConfig.kmk.)
   VBOX_PIN_FILE          ?= $(error You need to set VBOX_PIN_FILE in LocalConfig.kmk.)
  else
   VBOX_CERTIFICATE_FILE  ?= $(PATH_ROOT)/oracle.pem
   VBOX_TOKEN_NAME        ?= "Sun Software PKCS\#11 softtoken"
   VBOX_PIN_FILE          ?= $(PATH_ROOT)/oracle.pin
  endif
  VBOX_CERTIFICATE_FILE_ARGS ?= -c $(VBOX_CERTIFICATE_FILE)
  VBOX_TOKEN_NAME_ARGS       ?= -T $(VBOX_TOKEN_NAME)
  VBOX_PIN_ARGS              ?= -P $(VBOX_PIN_FILE)

  VBOX_ELFSIGN ?= elfsign

  # Sign an ELF image.
  # @param 1   The elf object file to sign.
  VBOX_SIGN_ELF_FN ?= $(VBOX_ELFSIGN) \
	sign \
	$(VBOX_CERTIFICATE_FILE_ARGS) \
	$(VBOX_TOKEN_NAME_ARGS) \
	$(VBOX_PIN_ARGS) \
	-e $(1)

  ## Commands for signing a driver image after link.
  if $(intersects solaris all 1,$(VBOX_WITH_CORP_CODE_SIGNING))
   VBOX_SIGN_DRIVER_CMDS ?= $(if $(eq $(tool_do),LINK_LIBRARY),,$(call VBOX_CCS_SIGN_CMD,solaris_elf,$(out)))
  else
   VBOX_SIGN_DRIVER_CMDS ?= $(if $(eq $(tool_do),LINK_LIBRARY),,$(call VBOX_SIGN_ELF_FN,$(out)))
  endif

 else
  # Not Windows, Mac OS X or Solaris build host, ignore.
  VBOX_SIGNING_MODE :=
 endif

#
# Complain if windows hardening is enabled but not code signing.
#
else if "$(KBUILD_TARGET)" == "win" && defined(VBOX_WITH_HARDENING) && !defined(VBOX_ONLY_BUILD)
 $(error You need to enable code signing for a hardened windows build to work.)
endif

#
# Windows .inf editing.
#
ifeq ($(KBUILD_TARGET_ARCH),x86)
 VBOX_EDIT_INF_FN = $(call VBOX_EDIT_INF32_FN,$(1),$(2))
else
 VBOX_EDIT_INF_FN = $(call VBOX_EDIT_INF64_FN,$(1),$(2))
endif
## Edit an inf file an x86 target.
# @param    1   The inf file to edit.
# @param    2   The output file.
VBOX_EDIT_INF32_FN = $(SED) $(if $(VBOX_SIGNING_MODE),-e 's/^;cat  *//', -e '/^;cat /d') \
	-e 's/^;x86  *//' \
	-e '/^;amd64 /d' \
	-e 's/@DOT-NT-ARCH@//' \
	-e 's/@COMMA-NT-ARCH@//' \
	-e 's/^;edit-DriverVer.*/DriverVer = $(date-utc %m\/%d\/%Y),$(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD).$(expr $(VBOX_SVN_REV) % 50000) ; r$(VBOX_SVN_REV)/' \
	--output $(2) \
	$(1)
## Edit an inf file an x86 target.
# @param    1   The inf file to edit.
# @param    2   The output file.
VBOX_EDIT_INF64_FN = $(SED) \
	$(if $(VBOX_SIGNING_MODE),-e 's/^;cat  *//', -e '/^;cat /d')\
	-e 's/^;amd64  *//' \
	-e '/^;x86 /d' \
	-e 's/@DOT-NT-ARCH@/.ntamd64/' \
	-e 's/@COMMA-NT-ARCH@/,ntamd64/' \
	-e 's/^;edit-DriverVer.*/DriverVer = $(date-utc %m\/%d\/%Y),$(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD).$(expr $(VBOX_SVN_REV) % 50000) ; r$(VBOX_SVN_REV)/' \
	--output $(2) \
	$(1)

##
# Helper macro for re-signing DLL images from tools that we ship so they won't
# cause trouble for the hardened build requirements.
#
# Invoke via $(call VBOX_RE_SIGN_DLL_FN) inside the SOURCES list.  Necessary
# _CLEAN entry will be added to the target.  If hardening is not enabled or
# we're not on windows, the source will be returned.
#
# @returns  Name of the output file name.  May have leading space, but no trailing.
# @param    1   Target name.
# @param    2   The source name.
# @param    3   Optional prefix to avoid name collisions.
#
if defined(VBOX_SIGNING_MODE) && "$(KBUILD_TARGET)" == "win"
 VBOX_RE_SIGN_DLL_FN = $(if-expr !defined($(1)_VBOX_RE_SIGNED_$(3)$(notdir $(2))),\
	$(evalcall VBOX_RE_SIGN_DLL_INTERNAL_FN,$1,$2,$3)\
	,)$($(1)_0_OUTDIR)/$(3)$(notdir $2)

define VBOX_RE_SIGN_DLL_INTERNAL_FN
local n = $(3)$(notdir $2)
ifndef $(1)_VBOX_RE_SIGNED_$(n)
 $(1)_VBOX_RE_SIGNED_$(n) := 1
 $(eval $(1)_CLEAN += $$($(1)_0_OUTDIR)/$(n))

 $$($(1)_0_OUTDIR)/$(n): $(2) $(VBOX_VERSION_STAMP) | $$(dir $$@)
	$(call MSG_TOOL,SIGNTOOL,,$<,$@)
	$(RM) -f -- "$@"
	$(CP) -- "$<" "$@"
	$(VBOX_VCC_EDITBIN) /LargeAddressAware /DynamicBase /NxCompat /Release /IntegrityCheck \
		/Version:$(VBOX_VERSION_MAJOR)0$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
		"$@"
	$(call VBOX_SIGN_IMAGE_FN,$@)
endif
endef # VBOX_RESIGN_DLL_FN
else
 VBOX_RE_SIGN_DLL_FN = $(2)
endif


##
# @param
VBOX_RESIGN_DLL_FN =


#
# File version info and description macros (ignored on most OSes).
#

##
# Internal macro.
#
# @param 1     The target name.
# @param 2     The description
# @param 3     Optional icon file.
# @param 4     The template base name.
# @param 5     Additional RC options.
#
# @remarks     ASSUMES RCFLAGS isn't a simple variable (var := value).
define VBOX_SET_VER_INFO_INTERNAL
ifeq ($(KBUILD_TARGET),win)
$(1)_SOURCES.win += $(PATH_ROOT)/src/VBox/Artwork/win/$(4)
$(1)_RCFLAGS += /nologo /dIN_INTERNAL_NAME="\"$(1)\"" /dIN_FILE_DESCRIPTION="\"$(2)\"" \
	/dIN_ORIGINAL_NAME="\"$$(notdir $$($(1)_1_INST_TARGET))\"" \
	$(if $(3), /dIN_ICON_FILE="\"$(subst \\,/,$(strip $(3)))\"") $(5)
$$$$($(1)_0_OUTDIR)/src/VBox/Artwork/win/$(basename $(4)).res: \
	$(PATH_ROOT)/include/VBox/version.h $$$$(VBOX_VERSION_HEADER)
endif
endef

##
# Macro for setting DLL/SO/DYLIB version information and description.
#
# The macro must be invoked using evalcall2 after the whole target has
# been declared.
#
# @param 1     The target name.
# @param 2     The description
# @param 3     Optional icon file.
VBOX_SET_VER_INFO_DLL = $(evalcall2 VBOX_SET_VER_INFO_INTERNAL,$1,$2,$3,TemplateDll.rc,)

##
# Macro for setting EXE version information and description.
#
# The macro must be invoked using call after the whole target has been declared.
#
# @param 1     The target name.
# @param 2     The description
# @param 3     Optional icon file.
VBOX_SET_VER_INFO_EXE = $(evalcall2 VBOX_SET_VER_INFO_INTERNAL,$1,$2,$3,TemplateExe.rc,)

##
# Macro for setting driver version information and description.
#
# The macro must be invoked using call after the whole target has been declared.
#
# @param 1     The target name.
# @param 2     The description
# @param 3     Optional icon file.
# @param 4     Optional VFT2_DRV_xxx define for windows.  Uses VFT2_UNKNOWN by default.
VBOX_SET_VER_INFO_DRV = $(evalcall2 VBOX_SET_VER_INFO_INTERNAL,$1,$2,$3,TemplateDrv.rc,$(if $(4), /dIN_FILE_SUBTYPE=$(4)))

##
# Macro for setting the version information and description for a ring-0 module.
#
# The macro must be invoked using call after the whole target has been declared.
#
# @param 1     The target name.
# @param 2     The description
# @param 3     Optional icon file.
VBOX_SET_VER_INFO_R0 = $(evalcall2 VBOX_SET_VER_INFO_INTERNAL,$1,$2,$3,TemplateR0.rc,)

##
# Macro for setting the version information and description for a raw-mode context module.
#
# The macro must be invoked using call after the whole target has been declared.
#
# @param 1     The target name.
# @param 2     The description
# @param 3     Optional icon file.
VBOX_SET_VER_INFO_RC = $(evalcall2 VBOX_SET_VER_INFO_INTERNAL,$1,$2,$3,TemplateRc.rc,)



#
# Adjust kBuild defaults.
#
kBuildGlobalDefaults_DEBUG_NOSTAGE.win = true
kBuildGlobalDefaults_DEBUG_NOSTAGE.os2 = true
if1of ($(KBUILD_TARGET), darwin win)
 kBuildGlobalDefaults_LD_DEBUG = split
endif


#
# Haiku resource and version generation.
#
ifeq ($(KBUILD_HOST),haiku)
 VBOX_HAIKU_RCTOOL := rc
 VBOX_HAIKU_XRESTOOL := xres
 VBOX_HAIKU_SETVERSIONTOOL := setversion
 # XXX: install won't preserve attributes...
 VBOX_HAIKU_MIMESETTOOL := mimeset

  ## Add optional resources to the program, set its version info, and sniff its mime properties.
  # @param 1  The file to add resources to.
  # @param 2  The resource files.
  # @param 3  The target name.
define VBOX_HAIKU_XRES_SETVER_FN
	$(if $(2),$(call MSG_TOOL,HaikuAddResources,$(3),$(2))
	$(QUIET)$(VBOX_HAIKU_XRESTOOL) -o $(1) $(2),)
	$(call MSG_TOOL,HaikuSetVersion,$(3))
	$(QUIET)$(VBOX_HAIKU_SETVERSIONTOOL) $(1) \
		-app $(VBOX_VERSION_MAJOR) $(VBOX_VERSION_MINOR) $(VBOX_VERSION_BUILD) d $(VBOX_SVN_REV) \
		-short "$(VBOX_PRODUCT)" \
		-long "$(VBOX_PRODUCT) $(VBOX_VERSION_STRING) $(shell /bin/echo -e '\xC2\xA9')2009-$(VBOX_C_YEAR) $(VBOX_VENDOR)"
	$(call MSG_TOOL,HaikuMimeSet,$(3))
	$(QUIET)$(VBOX_HAIKU_MIMESETTOOL) -f $(1)
endef

 VBOX_HAIKU_XRES_SETVER_CMDS  ?= $(if $(eq $(tool_do),LINK_PROGRAM),$(call VBOX_HAIKU_XRES_SETVER_FN,$(out),$($(target)_RSRCS),$(target)),)
endif

#
# Default prefixes and suffixes.
#
VBOX_PREF_LIB =
if1of ($(KBUILD_TARGET), os2 win)
VBOX_SUFF_LIB = .lib
else
VBOX_SUFF_LIB = .a
endif
if1of ($(KBUILD_HOST), os2 win)
VBOX_HOSTSUFF_LIB = .lib
else
VBOX_HOSTSUFF_LIB = .a
endif
VBOX_SUFF_DLL = $(SUFF_DLL)
ifeq ($(KBUILD_TARGET),os2) # GXX3OMF produces out .o at the moment.
VBOX_SUFF_OBJ = .o
else
VBOX_SUFF_OBJ = $(SUFF_OBJ)
endif
VBOXW32GUEST_SUFF_LIB = .lib
VBOXLNX32GUEST_SUFF_LIB = .a

#
# SDKs for external libraries.
#
SDK_VBOX_LIBXML2           = .
SDK_VBOX_LIBXML2_INCS     ?= $(PATH_ROOT)/src/libs/libxml2-2.9.4/include
SDK_VBOX_LIBXML2_DEFS     ?= _REENTRANT LIBXML_STATIC LIBXML_STATIC_FOR_DLL
SDK_VBOX_LIBXML2_DEFS.win ?= WIN32 _WINDOWS _MBCS HAVE_WIN32_THREADS HAVE_COMPILER_TLS
# Note: no linking to LIB here, we do that explicitly in src/VBox/Runtime/Makefile.kmk to link
#       libxml against VBoxRT

SDK_VBOX_LIBPNG       = .
SDK_VBOX_LIBPNG_INCS ?= $(PATH_ROOT)/src/libs/libpng-1.6.36
SDK_VBOX_LIBPNG_LIBS ?= $(PATH_STAGE_LIB)/VBox-libpng$(VBOX_SUFF_LIB)

SDK_VBOX_ZLIB         = .
if1of ($(KBUILD_TARGET), os2 solaris win)
 SDK_VBOX_ZLIB_INCS  ?= $(PATH_ROOT)/src/libs/zlib-1.2.11
 SDK_VBOX_ZLIB_LIBS  ?= $(PATH_STAGE_LIB)/VBox-zlib$(VBOX_SUFF_LIB)
else
 SDK_VBOX_ZLIB_INCS  ?=
 SDK_VBOX_ZLIB_LIBS  ?= z
 SDK_VBOX_ZLIB_DEFS.linux ?= _LARGEFILE64_SOURCE
endif

SDK_VBOX_ZLIB-x86    = .
SDK_VBOX_ZLIB-x86_EXTENDS = VBOX_ZLIB
if1of ($(KBUILD_TARGET), os2 solaris win)
 SDK_VBOX_ZLIB_LIBS-x86  ?= $(PATH_STAGE_LIB)/VBox-zlib-x86$(VBOX_SUFF_LIB)
endif

SDK_VBOX_ZLIB_STATIC  = .
SDK_VBOX_ZLIB_STATIC_EXTENDS ?= VBOX_ZLIB
if1of ($(KBUILD_TARGET), os2 win) # Not required on solaris.
 SDK_VBOX_ZLIB_STATIC_LIBS ?= $(PATH_STAGE_LIB)/VBox-zlib-static$(VBOX_SUFF_LIB)
endif

SDK_VBOX_LZF		= .
SDK_VBOX_LZF_INCS  ?= $(PATH_ROOT)/src/libs/liblzf-3.4
SDK_VBOX_LZF_LIBS  ?= $(PATH_STAGE_LIB)/VBox-liblzf$(VBOX_SUFF_LIB)

SDK_VBOX_LZF-x86	= .
SDK_VBOX_LZF-x86_EXTENDS = VBOX_LZF
SDK_VBOX_LZF_LIBS-x86 ?= $(PATH_STAGE_LIB)/VBox-liblzf-x86$(VBOX_SUFF_LIB)

SDK_VBOX_LZF_STATIC  = .
SDK_VBOX_LZF_STATIC_EXTENDS ?= VBOX_LZF
if1of ($(KBUILD_TARGET), os2 win)
 SDK_VBOX_LZF_STATIC_LIBS ?= $(PATH_STAGE_LIB)/VBox-liblzf-static$(VBOX_SUFF_LIB)
endif

SDK_VBOX_OPENSSL      = Only for VBoxRT and/or statically linked programs.
SDK_VBOX_OPENSSL_VBOX_DEFAULT_INCS := $(PATH_OUT)/obj/crypto-1.1.1-headers/include
SDK_VBOX_OPENSSL_INCS ?= $(SDK_VBOX_OPENSSL_VBOX_DEFAULT_INCS)
SDK_VBOX_OPENSSL_ORDERDEPS ?= $(crypto-headers_1_TARGET)
if  !defined(VBOX_ONLY_SDK) \
 && (!defined(VBOX_ONLY_ADDITIONS) || !defined(VBOX_ONLY_ADDITIONS_WITHOUT_RTISOMAKER)) \
 && (!defined(VBOX_ONLY_EXTPACKS) || defined(VBOX_NEED_EXTPACK_OPENSSL) || !defined(VBOX_ONLY_EXTPACKS_USE_IMPLIBS)) \
 && ("$(SDK_VBOX_OPENSSL_INCS)" == "$(SDK_VBOX_OPENSSL_VBOX_DEFAULT_INCS)" || defined(VBOX_NEED_EXTPACK_OPENSSL))
 SDK_VBOX_OPENSSL_DEPS ?= $(SDK_VBOX_OPENSSL_INCS)/openssl/openssl-mangling.h
endif
SDK_VBOX_OPENSSL_LIBS ?= \
	$(PATH_STAGE_LIB)/VBox-libssl$(VBOX_SUFF_LIB) \
	$(PATH_STAGE_LIB)/VBox-libcrypto$(VBOX_SUFF_LIB)

SDK_VBOX_OPENSSL-x86      = Only for VBoxRT and/or statically linked programs.
SDK_VBOX_OPENSSL-x86_VBOX_DEFAULT_INCS := $(PATH_OUT)/obj/crypto-1.1.1-headers/include
SDK_VBOX_OPENSSL-x86_INCS ?= $(SDK_VBOX_OPENSSL_VBOX_DEFAULT_INCS)
SDK_VBOX_OPENSSL-x86_ORDERDEPS ?= $(crypto-headers_1_TARGET)
if ("$(SDK_VBOX_OPENSSL_INCS)" == "$(SDK_VBOX_OPENSSL_VBOX_DEFAULT_INCS)" || defined(VBOX_NEED_EXTPACK_OPENSSL))
 SDK_VBOX_OPENSSL-x86_DEPS ?= $(SDK_VBOX_OPENSSL_INCS)/openssl/openssl-mangling.h
endif
SDK_VBOX_OPENSSL-x86_LIBS ?= \
	$(PATH_STAGE_LIB)/VBox-libssl-x86$(VBOX_SUFF_LIB) \
	$(PATH_STAGE_LIB)/VBox-libcrypto-x86$(VBOX_SUFF_LIB)

SDK_VBOX_OPENSSL2      = What you should be using.
SDK_VBOX_OPENSSL2_EXTENDS = VBOX_OPENSSL
if "$(SDK_VBOX_OPENSSL_INCS)" == "$(SDK_VBOX_OPENSSL_VBOX_DEFAULT_INCS)"
 SDK_VBOX_OPENSSL2_LIBS = $(NO_SUCH_VARIABLE)
endif

ifdef VBOX_WITH_LIBCURL
SDK_VBOX_LIBCURL       = .
SDK_VBOX_LIBCURL_INCS ?= $(PATH_ROOT)/src/libs/curl-7.64.0/include
SDK_VBOX_LIBCURL_LIBS ?= $(PATH_STAGE_LIB)/VBox-libcurl$(VBOX_SUFF_LIB)
SDK_VBOX_LIBCURL_DEFS ?= BUILDING_LIBCURL

SDK_VBOX_LIBCURL-x86           = .
SDK_VBOX_LIBCURL-x86_INCS     ?= $(PATH_ROOT)/src/libs/curl-7.64.0/include
SDK_VBOX_LIBCURL-x86_LIBS.x86 ?= $(PATH_STAGE_LIB)/VBox-libcurl-x86$(VBOX_SUFF_LIB)
SDK_VBOX_LIBCURL-x86_DEFS     ?= BUILDING_LIBCURL
endif

ifdef VBOX_WITH_LIBVPX
 SDK_VBOX_VPX       = .
 SDK_VBOX_VPX_DEFAULT_INCS := $(PATH_ROOT)/src/libs/libvpx-1.6.1
 SDK_VBOX_VPX_INCS ?= $(SDK_VBOX_VPX_DEFAULT_INCS)
 SDK_VBOX_VPX_LIBS ?= $(PATH_STAGE_LIB)/VBox-libvpx$(VBOX_SUFF_LIB)
endif

ifdef VBOX_WITH_LIBOPUS
 SDK_VBOX_OPUS       = .
 SDK_VBOX_OPUS_DEFAULT_INCS := $(PATH_ROOT)/src/libs/libopus-1.2.1/include
 SDK_VBOX_OPUS_INCS ?= $(SDK_VBOX_OPUS_DEFAULT_INCS)
 SDK_VBOX_OPUS_LIBS ?= $(PATH_STAGE_LIB)/VBox-libopus$(VBOX_SUFF_LIB)
endif

ifdef VBOX_WITH_LIBFUSE
 SDK_VBOX_FUSE               = .
 SDK_VBOX_FUSE_DEFAULT_INCS := $(PATH_ROOT)/src/libs/libfuse-2.9.8/include
 SDK_VBOX_FUSE_INCS         ?= $(SDK_VBOX_FUSE_DEFAULT_INCS)
 SDK_VBOX_FUSE_LIBS         ?= $(PATH_STAGE_LIB)/VBox-libfuse$(VBOX_SUFF_LIB)
endif

#
# Special SDK for the problematic NTDLL.LIB.
#
SDK_VBOX_NTDLL = Mini NTDLL import library, required IPRT.
SDK_VBOX_NTDLL_LIBS.x86   ?= $(PATH_STAGE_LIB)/RuntimeR3NtDll-x86.lib
SDK_VBOX_NTDLL_LIBS.amd64 ?= $(PATH_STAGE_LIB)/RuntimeR3NtDll-amd64.lib

#
# Determine Solaris version.
#
ifeq ($(KBUILD_TARGET),solaris)
 VBOX_SOLARIS_VERSION := $(expr $(KBUILD_HOST_VERSION_MAJOR) * 100 + $(KBUILD_HOST_VERSION_MINOR))
 ifeq ($(VBOX_SOLARIS_VERSION),510)
  DEFS.solaris += RT_OS_SOLARIS_10
  # Solaris 10 does not include crossbow.
  VBOX_SOLARIS_10 = 1
  # We cannot compile additions on Solaris 10, due kernel interface deps
  VBOX_WITHOUT_ADDITIONS := 1
  VBOX_WITH_ADDITIONS =
 else ifeq ($(VBOX_SOLARIS_VERSION),511)
  # OSS audio support for Solaris
  VBOX_WITH_AUDIO_OSS := 1
 endif

 # XPCOM namespace cleanup issue with Solaris GCC 4.5.2 and newer, see @bugref{5838}.
 if $(VBOX_GCC_VERSION_CXX) >= 40502
  VBOX_WITH_XPCOM_NAMESPACE_CLEANUP =
 endif
endif

#
# VBoxTpG tool.
#
TOOL_VBoxTpG = The VirtualBox Tracepoint Generator
TOOL_VBoxTpG_DTRACE_DEPORD          = $(VBOX_VBOXTPG)
TOOL_VBoxTpG_DTRACE_HDR_FLAGS      := \
		-h --host-$(VBOX_HC_ARCH_BITS)-bit #-vvv
define TOOL_VBoxTpG_DTRACE_HDR_CMDS
	$(QUIET)$(VBOX_VBOXTPG) $(if-expr $(intersects $(bld_trg_arch),$(KBUILD_ARCHES_64)),-64,-32) \
		$(flags) -o "$(out)" -s "$(source)"
endef
TOOL_VBoxTpG_DTRACE_OBJ_NOT_NEEDED :=
TOOL_VBoxTpG_DTRACE_OBJ_FLAGS      := -G --host-$(VBOX_HC_ARCH_BITS)-bit #-vvv
define TOOL_VBoxTpG_DTRACE_OBJ_CMDS
	$(QUIET)$(VBOX_VBOXTPG) --assembler "$(TOOL_$(VBOX_ASTOOL)_AS)" \
		$(if-expr $(intersects $(bld_trg_arch),$(KBUILD_ARCHES_64)),-64,-32) \
		$(flags) \
		-o "$(out)" -s "$(source)"
endef


#
# VBoxTpG tool - Disabled, only generate the header.
#
TOOL_VBoxTpG-Disabled = The VirtualBox Tracepoint Generator, disabled.
TOOL_VBoxTpG-Disabled_DTRACE_DEPORD     = $(VBOX_VBOXTPG)
TOOL_VBoxTpG-Disabled_DTRACE_HDR_FLAGS := -h
define TOOL_VBoxTpG-Disabled_DTRACE_HDR_CMDS
	$(QUIET)$(VBOX_VBOXTPG) $(flags) -o "$(out)" -s "$(source)"
endef
TOOL_VBoxTpG-Disabled_DTRACE_OBJ_NOT_NEEDED := $(KBUILD_OSES)


#
# dtrace+VBoxTpG tool for ring-3 to ring-0 pointer conversion.
#
TOOL_DTraceAndVBoxTpG = DTrace and the VirtualBox Tracepoint Generator working together on static ring-3 probes.
TOOL_DTraceAndVBoxTpG_EXTENDS = StandardDTrace
TOOL_DTraceAndVBoxTpG_DTRACE_DEPORD   = $(VBOX_VBOXTPG)
TOOL_DTraceAndVBoxTpG_DTRACE_HDR_CMDS =
define TOOL_DTraceAndVBoxTpG_DTRACE_HDR_CMDS
	$(TOOL_StandardDTrace_DTRACE_HDR_CMDS)
	$(QUIET)$(VBOX_VBOXTPG) --generate-wrapper-header --host-$(VBOX_HC_ARCH_BITS)-bit --ring-3-context \
		$(filter-out -C, $(filter-out -h,$(flags))) \
		-o "$(out).tmp" -s "$(source)"
	$(APPEND) "$(out).tmp"
	$(SED) -e 's/\(#define.*\)(arg0/\1_ORIGINAL(arg0/' --append "$(out).tmp" "$(out)"
	$(MV) -f -- "$(out).tmp" "$(out)"
endef
TOOL_DTraceAndVBoxTpG_DTRACE_OBJ_NOT_NEEDED = $(TOOL_StandardDTrace_DTRACE_OBJ_NOT_NEEDED)
TOOL_DTraceAndVBoxTpG_DTRACE_OBJ_CMDS = $(TOOL_StandardDTrace_DTRACE_OBJ_CMDS)
define TOOL_DTraceAndVBoxTpG_DTRACE_OBJ_CMDS # remove when fixed upstream
	$(QUIET)$(TOOL_StandardDTrace_DTRACE) \
		$(if-expr $(intersects $(bld_trg_arch),$(KBUILD_ARCHES_64)),-64,-32) \
		$(flags) \
		-o "$(out)" -s "$(source)" \
		$$(filter-out %-dtrace-object-format.o %.gch, $$($(target)_2_OBJS))
endef


ifdef VBOX_WITH_RAW_MODE
 #
 # Template for building RC things.
 #
 # Disabled Visual C++ warnings:
 #     -wd4505: 'iemRaisePageFaultJmp' : unreferenced local function has been removed
 #
 TEMPLATE_VBoxRc = VBox Raw-Mode Context
 TEMPLATE_VBoxRc_ASTOOL              = $(VBOX_ASTOOL)
 TEMPLATE_VBoxRc_ASFLAGS             = $(VBOX_ASFLAGS32)
 TEMPLATE_VBoxRc_DEFS                = IN_RC IPRT_NO_CRT RT_WITH_NOCRT_ALIASES $(ARCH_BITS_DEFS)
 TEMPLATE_VBoxRc_INCS                = $(PATH_ROOT)/include/iprt/nocrt
 TEMPLATE_VBoxRc_SYSSUFF             = .rc
 TEMPLATE_VBoxRc_BLD_TRG_ARCH        = x86
 TEMPLATE_VBoxRc_MODE                = a+r,u+w

 TEMPLATE_VBoxRc_USES               += dtrace
 TEMPLATE_VBoxRc_DTRACE_HDR_FLAGS    = --raw-mode-context
 TEMPLATE_VBoxRc_DTRACE_OBJ_FLAGS    = --raw-mode-context --probe-fn-name "VMMRCProbeFire"
 ifdef VBOX_WITH_DTRACE_RC
  TEMPLATE_VBoxRc_DTRACETOOL         = VBoxTpG
  TEMPLATE_VBoxRc_DEFS              += VBOX_WITH_DTRACE VBOX_WITH_DTRACE_RC
 else
  TEMPLATE_VBoxRc_DTRACETOOL         = VBoxTpG-Disabled
 endif

 ifeq ($(VBOX_LDR_FMT32),pe)
  TEMPLATE_VBoxRc_TOOL               = $(VBOX_VCC_TOOL_STEM)X86
  TEMPLATE_VBoxRc_RCDEFS             = VBOX_SVN_REV=$(VBOX_SVN_REV) VBOX_SVN_REV_MOD_5K=$(expr $(VBOX_SVN_REV) % 50000)
  TEMPLATE_VBoxRc_CXXFLAGS          = -Zi -Zl -GR- -EHs- -GF -GS- -Zc:wchar_t- -Gs8192 $(VBOX_VCC_GC_OPT) $(VBOX_VCC_GC_FP) \
  	$(VBOX_VCC_WARN_ALL) -wd4505 $(VBOX_VCC_WERR)
  TEMPLATE_VBoxRc_CFLAGS             = $(TEMPLATE_VBoxRc_CXXFLAGS)
  TEMPLATE_VBoxRc_LDFLAGS            =  -Ignore:4197 \
  	-Driver -Subsystem:NATIVE -Incremental:NO -Align:64 -MapInfo:Exports -NoD $(VBOX_VCC_LD_WERR) -Release -Debug -Opt:Ref -Opt:Icf \
  	-Version:$(VBOX_VERSION_MAJOR)0$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
  	-Stub:$(PATH_ROOT)/src/VBox/HostDrivers/Support/win/winstub.com
  ifdef VBOX_SIGNING_MODE
   TEMPLATE_VBoxRc_LDFLAGS          += -IntegrityCheck
  endif
  TEMPLATE_VBoxRc_LIBS               = \
  	$(PATH_SDK_$(VBOX_WINDDK)_LIB.x86)/int64.lib
  TEMPLATE_VBoxRc_LIBS              += \
  	$(PATH_STAGE_LIB)/RuntimeRCStub$(VBOX_SUFF_LIB)
  TEMPLATE_VBoxRc_POST_CMDS          = $(VBOX_SIGN_IMAGE_CMDS)
 endif # pe

 ifeq ($(VBOX_LDR_FMT32),elf)
 TEMPLATE_VBoxRc_TOOL                = $(VBOX_GCC32_TOOL)
 TEMPLATE_VBoxRc_CXXFLAGS            = -fno-pie -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC32_Wno-variadic-macros) -fno-exceptions $(VBOX_GCC_GC_OPT) $(VBOX_GCC_GC_FP) -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -fno-strict-aliasing $(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_fvisibility-inlines-hidden) -fno-rtti $(VBOX_GCC_IPRT_FMT_CHECK)
 TEMPLATE_VBoxRc_CFLAGS              = -fno-pie -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_C)   $(VBOX_GCC32_Wno-variadic-macros) -fno-exceptions $(VBOX_GCC_GC_OPT) $(VBOX_GCC_GC_FP) -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -fno-strict-aliasing $(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_IPRT_FMT_CHECK)
  if $(VBOX_GCC32_VERSION_CC) < 30400
   TEMPLATE_VBoxRc_DEFS             += RT_WITHOUT_PRAGMA_ONCE
  endif
  ifeq ($(KBUILD_TARGET),solaris)
   TEMPLATE_VBoxRc_LDFLAGS           = -r
  else
   TEMPLATE_VBoxRc_LDFLAGS           = -nostdlib -Bsymbolic -g
   ## @todo WTF doesn't the globals work? Debug info is supposed to be split everywhere. GRR
   TEMPLATE_VBoxRc_LD_DEBUG          = split
  endif
  ifn1of ($(KBUILD_TARGET), solaris freebsd)
   TEMPLATE_VBoxRc_LIBS               = \
	$(VBOX_GCC32_LIBGCC) # intrinsics
  endif
  if1of ($(KBUILD_TARGET),linux)
   TEMPLATE_VBoxRc_POST_CMDS         = $(if $(eq $(tool_do),LINK_SYSMOD),if readelf -S $(out)|grep -q "[cd]tors"; then echo "Found ctors/dtors in $(out)!"; exit 1; fi)
  endif
 endif

 ifeq ($(VBOX_LDR_FMT32),macho)
 TEMPLATE_VBoxRc_TOOL                = $(VBOX_GCC_TOOL)
 TEMPLATE_VBoxRc_DEFS               += $(VBOX_DARWIN_DEF_SDK_DEFS)
 TEMPLATE_VBoxRc_CXXFLAGS            = $(VBOX_DARWIN_DEF_SDK_CXXFLAGS) -m32 -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC32_Wno-variadic-macros) -fno-common -msoft-float -static $(VBOX_GCC_fno-stack-protector) -fno-exceptions $(VBOX_GCC_GC_OPT) $(VBOX_GCC_GC_FP) -fno-strict-aliasing -fno-rtti
 TEMPLATE_VBoxRc_CFLAGS              = $(VBOX_DARWIN_DEF_SDK_CFLAGS)   -m32 -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_C)   $(VBOX_GCC32_Wno-variadic-macros) -fno-common -msoft-float -static $(VBOX_GCC_fno-stack-protector) -fno-exceptions $(VBOX_GCC_GC_OPT) $(VBOX_GCC_GC_FP) -fno-strict-aliasing
 TEMPLATE_VBoxRc_LDFLAGS             = $(VBOX_DARWIN_DEF_SDK_LDFLAGS)  -m32 -nostdlib
 #TEMPLATE_VBoxRc_LDFLAGS.release     = -Wl,-S ???
 endif

 ifeq ($(VBOX_LDR_FMT32),lx)
 TEMPLATE_VBoxRc_TOOL                = GXX3OMF
  if $(VBOX_GCC_VERSION_CC) < 30400
   TEMPLATE_VBoxRc_DEFS             += RT_WITHOUT_PRAGMA_ONCE
  endif
 TEMPLATE_VBoxRc_CXXFLAGS            = -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC32_Wno-variadic-macros) $(VBOX_GCC_GC_OPT) $(VBOX_GCC_GC_FP) -fno-strict-aliasing -fno-exceptions -fno-rtti
 TEMPLATE_VBoxRc_CFLAGS              = -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_C)   $(VBOX_GCC32_Wno-variadic-macros) $(VBOX_GCC_GC_OPT) $(VBOX_GCC_GC_FP) -fno-strict-aliasing -fno-exceptions
 TEMPLATE_VBoxRc_LDFLAGS             = -Zdll -nostdlib
 TEMPLATE_VBoxRc_LIBS                = \
	$(VBOX_GCC32_LIBGCC) \
	$(VBOX_OBJ_SYS0) \
	end
 endif


 #
 # Template for building a RC ring-3 testcase (tstVMStructGC, tstDevStructGC).
 #
 TEMPLATE_VBoxRcExe = VBox Raw-Mode as ring-3 testcase
 TEMPLATE_VBoxRcExe_EXTENDS = VBoxRc
 TEMPLATE_VBoxRcExe_DEFS = $(filter-out IPRT_NO_CRT RT_WITH_NOCRT_ALIASES,$(TEMPLATE_VBoxRc_DEFS))
 TEMPLATE_VBoxRcExe_INCS = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBoxRcExe_MODE = $(NO_SUCH_VARIABLE)

 ifeq ($(VBOX_LDR_FMT32),pe)
  TEMPLATE_VBoxRcExe_LDFLAGS = -Ignore:4197 \
  	-Incremental:NO -MapInfo:Exports -NoD -Debug -Opt:Ref -Opt:Icf \
  	-Version:$(VBOX_VERSION_MAJOR)0$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
  	-Stub:$(PATH_ROOT)/src/VBox/HostDrivers/Support/win/winstub.com
  TEMPLATE_VBoxRcExe_SDKS    = ReorderCompilerIncs $(VBOX_WINPSDK)
  TEMPLATE_VBoxRcExe_LIBS    = \
  	$(PATH_TOOL_$(VBOX_VCC_TOOL_STEM)X86_LIB)/libcmt.lib \
  	$(PATH_TOOL_$(VBOX_VCC_TOOL_STEM)X86_LIB)/oldnames.lib
 endif

 ifeq ($(VBOX_LDR_FMT32),elf)
  TEMPLATE_VBoxRcExe_CFLAGS   = $(filter-out -nostdinc,$(TEMPLATE_VBoxRc_CFLAGS)) -O0
  TEMPLATE_VBoxRcExe_CXXFLAGS = $(filter-out -nostdinc,$(TEMPLATE_VBoxRc_CXXFLAGS)) -O0
  TEMPLATE_VBoxRcExe_LDFLAGS  = -g
  TEMPLATE_VBoxRcExe_LDFLAGS.dbgopt = -g
  TEMPLATE_VBoxRcExe_LDFLAGS.strict = -g
  TEMPLATE_VBoxRcExe_LDFLAGS.release = -g
  if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), freebsd.amd64)
   # The FreeBSD port of gcc isn't picking up -m32 where it should.
   TEMPLATE_VBoxRcExe_DEFS.$(KBUILD_TARGET)    = $(TEMPLATE_VBoxRc_DEFS.$(KBUILD_TARGET))    IPRT_DONT_USE_SYSTEM_STDINT_H
   TEMPLATE_VBoxRcExe_LDFLAGS.$(KBUILD_TARGET) = /usr/lib32/crt1.o /usr/lib32/crti.o /usr/lib32/crtbegin.o $(TEMPLATE_VBoxRc_LDFLAGS.$(KBUILD_TARGET)) -nostdlib -v
   TEMPLATE_VBoxRcExe_LIBPATH.$(KBUILD_TARGET) = /usr/lib32
   TEMPLATE_VBoxRcExe_LIBS.$(KBUILD_TARGET)    = /usr/lib32/crtend.o /usr/lib32/crtn.o /usr/lib32/libc.so
  endif
 endif

 ifeq ($(VBOX_LDR_FMT32),macho)
  TEMPLATE_VBoxRcExe_CFLAGS   = $(filter-out -static -nostdinc,$(TEMPLATE_VBoxRc_CFLAGS))
  TEMPLATE_VBoxRcExe_CXXFLAGS = $(filter-out -static -nostdinc,$(TEMPLATE_VBoxRc_CXXFLAGS))
  TEMPLATE_VBoxRcExe_LDFLAGS  = -g -m32
 endif

 ifeq ($(VBOX_LDR_FMT32),lx)
  TEMPLATE_VBoxRcExe_CFLAGS   = $(filter-out -nostdinc,$(TEMPLATE_VBoxRc_CFLAGS))
  TEMPLATE_VBoxRcExe_CXXFLAGS = $(filter-out -nostdinc,$(TEMPLATE_VBoxRc_CXXFLAGS))
  TEMPLATE_VBoxRcExe_LDFLAGS  = -g
  TEMPLATE_VBoxRcExe_LIBS     = $(NO_SUCH_VARIABLE)
 endif
endif # VBOX_WITH_RAW_MODE


#
# Template for building R0 things.
#
# Disabled Visual C++ warnings:
#      -wd4505: 'iemRaisePageFaultJmp' : unreferenced local function has been removed
#
TEMPLATE_VBoxR0 = VBox Ring 0
TEMPLATE_VBoxR0_ASTOOL              = $(VBOX_ASTOOL)
TEMPLATE_VBoxR0_ASFLAGS             = $(VBOX_ASFLAGS)
TEMPLATE_VBoxR0_DEFS                = IN_RING0 IN_RING0_AGNOSTIC IPRT_NO_CRT RT_WITH_NOCRT_ALIASES $(ARCH_BITS_DEFS)
TEMPLATE_VBoxR0_INCS                = $(PATH_ROOT)/include/iprt/nocrt
TEMPLATE_VBoxR0_SYSSUFF             = .r0
TEMPLATE_VBoxR0_MODE                = a+r,u+w

TEMPLATE_VBoxR0_USES               += dtrace
TEMPLATE_VBoxR0_DTRACE_HDR_FLAGS    = --ring-0-context-agnostic
TEMPLATE_VBoxR0_DTRACE_OBJ_FLAGS    = --ring-0-context-agnostic
ifdef VBOX_WITH_DTRACE_R0
 TEMPLATE_VBoxR0_DTRACETOOL         = VBoxTpG
 TEMPLATE_VBoxR0_DEFS              += VBOX_WITH_DTRACE VBOX_WITH_DTRACE_R0
else
 TEMPLATE_VBoxR0_DTRACETOOL         = VBoxTpG-Disabled
endif

ifeq ($(VBOX_LDR_FMT),pe)
TEMPLATE_VBoxR0_TOOL                = $(VBOX_VCC_TOOL)
TEMPLATE_VBoxR0_RCDEFS              = VBOX_SVN_REV=$(VBOX_SVN_REV) VBOX_SVN_REV_MOD_5K=$(expr $(VBOX_SVN_REV) % 50000)
TEMPLATE_VBoxR0_CXXFLAGS            = -Zi -Zl -GR- -EHs- -GF -GS- -Zc:wchar_t- $(VBOX_VCC_OPT) $(VBOX_VCC_FP) \
  	$(VBOX_VCC_WARN_ALL) -wd4505 $(VBOX_VCC_WERR)
TEMPLATE_VBoxR0_CFLAGS              = $(TEMPLATE_VBoxR0_CXXFLAGS)
TEMPLATE_VBoxR0_LDFLAGS             = -Ignore:4197 \
	-Driver -Subsystem:NATIVE -Incremental:NO -Align:4096 -MapInfo:Exports -NoD $(VBOX_VCC_LD_WERR) -Release -Debug -Opt:Ref -Opt:Icf \
	-Version:$(VBOX_VERSION_MAJOR)0$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	-Stub:$(PATH_ROOT)/src/VBox/HostDrivers/Support/win/winstub.com
 ifdef VBOX_WITH_DTRACE_R0
TEMPLATE_VBoxR0_LDFLAGS            += -Merge:VTGPrLc.Data=VTGPrLc.Begin -Merge:VTGPrLc.End=VTGPrLc.Begin -Merge:VTGPrLc.Begin=VTGObj
 endif
 ifdef VBOX_SIGNING_MODE
  TEMPLATE_VBoxR0_LDFLAGS          += -IntegrityCheck
 endif
TEMPLATE_VBoxR0_LIBS                = \
	$(PATH_STAGE_LIB)/RuntimeR0Stub$(VBOX_SUFF_LIB)
 include $(KBUILD_PATH)/sdks/$(VBOX_WINDDK).kmk ## TODO: Add a kBuild feature for loading SDKs.
TEMPLATE_VBoxR0_LIBS.x86            = \
	$(PATH_SDK_$(VBOX_WINDDK)_LIB.x86)/int64.lib
TEMPLATE_VBoxR0_ORDERDEPS           = $(VBOX_SIGN_DRIVER_ORDERDEPS)
TEMPLATE_VBoxR0_POST_CMDS           = $(VBOX_SIGN_DRIVER_CMDS)
endif # pe

ifeq ($(VBOX_LDR_FMT),elf)
TEMPLATE_VBoxR0_TOOL                = $(VBOX_GCC_TOOL)
TEMPLATE_VBoxR0_CFLAGS              = -fno-pie -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_C) \
	$(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing -fno-exceptions \
	$(VBOX_GCC_fno-stack-protector) -fno-common $(VBOX_GCC_fvisibility-hidden) -std=gnu99 $(VBOX_GCC_IPRT_FMT_CHECK)
TEMPLATE_VBoxR0_CXXFLAGS            = -fno-pie -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_CXX) \
	$(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing -fno-exceptions \
	$(VBOX_GCC_fno-stack-protector) -fno-common $(VBOX_GCC_fvisibility-inlines-hidden) $(VBOX_GCC_fvisibility-hidden) \
	-fno-rtti $(VBOX_GCC_IPRT_FMT_CHECK)
TEMPLATE_VBoxR0_CFLAGS.amd64        = -m64 -mno-red-zone -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -fasynchronous-unwind-tables -ffreestanding
TEMPLATE_VBoxR0_CXXFLAGS.amd64      = -m64 -mno-red-zone -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -fasynchronous-unwind-tables
TEMPLATE_VBoxR0_CXXFLAGS.freebsd    = -ffreestanding
 if $(VBOX_GCC_VERSION_CC) < 30400
  TEMPLATE_VBoxR0_DEFS             += RT_WITHOUT_PRAGMA_ONCE
 endif
 ifeq ($(KBUILD_TARGET),solaris)
 TEMPLATE_VBoxR0_LDFLAGS            = -r
 TEMPLATE_VBoxR0_LDFLAGS.solaris    = -u _init -u _info
 TEMPLATE_VBoxR0_LIBS.solaris       = \
	$(PATH_STAGE_LIB)/RuntimeR0Stub$(VBOX_SUFF_LIB)
 ifdef VBOX_GCC_USING_SOLARIS_AS
  TEMPLATE_VBoxR0_CFLAGS.amd64 += -Wa,-xmodel=kernel
  TEMPLATE_VBoxR0_CXXFLAGS.amd64 += -Wa,-xmodel=kernel
 endif
 # Solaris driver signing.
 TEMPLATE_VBoxR0_POST_CMDS          = $(VBOX_SIGN_DRIVER_CMDS)
 else
 TEMPLATE_VBoxR0_LDFLAGS            = -nostdlib -Bsymbolic -g
 ## @todo WTF doesn't the globals work? Debug info is supposed to be split everywhere. GRR
 TEMPLATE_VBoxR0_LD_DEBUG           = split
 endif
 if1of ($(KBUILD_TARGET), linux)
VBOX_WITH_VBOXR0_AS_DLL = 1
TEMPLATE_VBoxR0_DLLSUFF             = .r0
TEMPLATE_VBoxR0_CFLAGS             += -fPIC
TEMPLATE_VBoxR0_CXXFLAGS           += -fPIC
TEMPLATE_VBoxR0_LDFLAGS            +=
TEMPLATE_VBoxR0_DTRACE_HDR_FLAGS   += --pic
TEMPLATE_VBoxR0_DTRACE_OBJ_FLAGS   += --pic
 else
TEMPLATE_VBoxR0_CFLAGS.amd64       += -mcmodel=kernel
TEMPLATE_VBoxR0_CXXFLAGS.amd64     += -mcmodel=kernel
 endif
 ifn1of ($(KBUILD_TARGET),solaris freebsd)
 TEMPLATE_VBoxR0_LIBS               = \
	$(VBOX_GCC_LIBGCC) # intrinsics
 endif
 if1of ($(KBUILD_TARGET),linux)
 TEMPLATE_VBoxR0_POST_CMDS         += $(NLTAB)\
 	$(if $(eq $(tool_do),LINK_SYSMOD),if readelf -S $(out)|grep -q "[cd]tors"; then echo "Found ctors/dtors in $(out)!"; exit 1; fi)
 endif
endif # elf

ifeq ($(VBOX_LDR_FMT),macho)
TEMPLATE_VBoxR0_TOOL                = $(VBOX_GCC_TOOL)
TEMPLATE_VBoxR0_DEFS               += $(VBOX_DARWIN_DEF_SDK_DEFS)
TEMPLATE_VBoxR0_CXXFLAGS            = $(VBOX_DARWIN_DEF_SDK_CXXFLAGS) -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC_Wno-variadic-macros) \
	-fno-common -msoft-float -static -fno-rtti -fno-exceptions $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing \
	-mno-sse -mno-mmx -mno-sse2 -mno-3dnow $(VBOX_GCC_fno-stack-protector)
TEMPLATE_VBoxR0_CXXFLAGS.amd64      = -m64 -mno-red-zone -mno-sse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2  -mno-sse4a -fno-unwind-tables
TEMPLATE_VBoxR0_CXXFLAGS.x86        = -m32
TEMPLATE_VBoxR0_CFLAGS              = $(VBOX_DARWIN_DEF_SDK_CFLAGS)   -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_C)   $(VBOX_GCC_Wno-variadic-macros) \
	-fno-common -msoft-float -static -fno-exceptions $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing \
	-mno-sse -mno-mmx -mno-sse2 -mno-3dnow $(VBOX_GCC_fno-stack-protector)
TEMPLATE_VBoxR0_CFLAGS.amd64        = -m64 -mno-red-zone -mno-sse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2  -mno-sse4a -fno-unwind-tables
TEMPLATE_VBoxR0_CFLAGS.x86          = -m32
TEMPLATE_VBoxR0_LDFLAGS             = $(VBOX_DARWIN_DEF_SDK_LDFLAGS) -nostdlib
TEMPLATE_VBoxR0_LDFLAGS.amd64       = -m64 -static
TEMPLATE_VBoxR0_LDFLAGS.x86         = -m32
TEMPLATE_VBoxR0_CXXFLAGS.amd64     += -mkernel
TEMPLATE_VBoxR0_CFLAGS.amd64       += -mkernel
TEMPLATE_VBoxR0_LDFLAGS            += -Wl,-kext -mkernel
TEMPLATE_VBoxR0_POST_CMDS           = $(if $(eq $(tool_do),LINK_LIBRARY),,$(call VBOX_SIGN_VMM_MOD_FN,$(out),org.virtualbox.app.r0.$(target)))
endif

ifeq ($(VBOX_LDR_FMT),lx)
TEMPLATE_VBoxR0_TOOL                = GXX3OMF
TEMPLATE_VBoxR0_CFLAGS              = -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_C)   $(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing -fno-exceptions -fno-common
TEMPLATE_VBoxR0_CXXFLAGS            = -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing -fno-exceptions -fno-common -fno-rtti
 if $(VBOX_GCC_VERSION_CC) < 30400
TEMPLATE_VBoxR0_DEFS               += RT_WITHOUT_PRAGMA_ONCE
 endif
TEMPLATE_VBoxR0_LDFLAGS             = -nostdlib -Zdll
TEMPLATE_VBoxR0_LIBS                = \
	$(VBOX_GCC_LIBGCC) \
	$(VBOX_OBJ_SYS0) \
	end
endif


#
# Template for building SUPDRV R0 things.
#
# Disabled Visual C++ warnings:
#     -wd4996: deprecated / insecure.
#     -wd4127: conditional expression is constant [level 4]
#     -wd4201: nonstandard extension used : nameless struct/union [level 4]
#     -wd4214: nonstandard extension used : bit field types other than int [level 4]
#     -wd4706: assignment within conditional expression [level 4]
#     -wd4324: '_TDI_PNP_CONTEXT_XP' : structure was padded due to __declspec(align())
#
#     -wd4100: 'identifier' : unreferenced formal parameter [level 4] --- TODO: Enable this one!
#
TEMPLATE_VBOXR0DRV                     = VBox SUPDRV Ring 0
TEMPLATE_VBOXR0DRV_ASTOOL              = $(VBOX_ASTOOL)
TEMPLATE_VBOXR0DRV_ASFLAGS             = $(VBOX_ASFLAGS)
TEMPLATE_VBOXR0DRV_DEFS                = IN_RING0 IN_RT_R0 $(ARCH_BITS_DEFS)
TEMPLATE_VBOXR0DRV_USES               += dtrace
ifdef VBOX_WITH_DTRACE_R0DRV
 TEMPLATE_VBOXR0DRV_DTRACETOOL         = VBoxTpG
 TEMPLATE_VBOXR0DRV_DEFS              += VBOX_WITH_DTRACE VBOX_WITH_DTRACE_R0DRV
 ifdef VBOX_WITH_NATIVE_DTRACE
  TEMPLATE_VBOXR0DRV_DEFS             += VBOX_WITH_NATIVE_DTRACE
 endif
else
 TEMPLATE_VBOXR0DRV_DTRACETOOL         = VBoxTpG-Disabled
endif

ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBOXR0DRV_TOOL               = $(VBOX_VCC_TOOL)
 TEMPLATE_VBOXR0DRV_RCDEFS             = VBOX_SVN_REV=$(VBOX_SVN_REV) VBOX_SVN_REV_MOD_5K=$(expr $(VBOX_SVN_REV) % 50000)
 TEMPLATE_VBOXR0DRV_DEFS.x86           = _X86_
 TEMPLATE_VBOXR0DRV_DEFS.x86          += NO_INTERLOCKED_INTRINSICS # Avoids intrisic VC/WDK trouble
 TEMPLATE_VBOXR0DRV_DEFS.x86          += WIN9X_COMPAT_SPINLOCK     # Avoid multiply defined _KeInitializeSpinLock@4
 TEMPLATE_VBOXR0DRV_DEFS.amd64         = _AMD64_
 TEMPLATE_VBOXR0DRV_DEFS.win           = IPRT_NT_MAP_TO_ZW
 TEMPLATE_VBOXR0DRV_CXXFLAGS           = -Zi -Zl -GR- -EHs- -GF -Gz -GS- -Zc:wchar_t- $(VBOX_VCC_FP) -Gs4096 $(VBOX_VCC_OPT) \
	$(VBOX_VCC_WARN_ALL) $(VBOX_VCC_WERR)
 TEMPLATE_VBOXR0DRV_CFLAGS             = $(TEMPLATE_VBOXR0DRV_CXXFLAGS)
 TEMPLATE_VBOXR0DRV_LDFLAGS            = -Ignore:4197 \
 	-Driver -Subsystem:NATIVE -Incremental:NO -Align:4096 -MapInfo:Exports -NoD -Release -Debug -Opt:Ref -Opt:Icf \
	-Version:$(VBOX_VERSION_MAJOR)0$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	-Stub:$(PATH_ROOT)/src/VBox/HostDrivers/Support/win/winstub.com
 ifdef VBOX_WITH_DTRACE_R0DRV
  TEMPLATE_VBOXR0DRV_LDFLAGS          += -Merge:VTGPrLc.Data=VTGPrLc.Begin -Merge:VTGPrLc.End=VTGPrLc.Begin -Merge:VTGPrLc.Begin=VTGObj
 endif
 ifdef VBOX_SIGNING_MODE
  TEMPLATE_VBOXR0DRV_LDFLAGS          += -IntegrityCheck
 endif
 TEMPLATE_VBOXR0DRV_ORDERDEPS          = $(VBOX_SIGN_DRIVER_ORDERDEPS)
 TEMPLATE_VBOXR0DRV_POST_CMDS          = $(VBOX_SIGN_DRIVER_CMDS)
endif

ifeq ($(KBUILD_TARGET),linux)
 TEMPLATE_VBOXR0DRV_TOOL                = $(NO_SUCH_VARIABLE)

 ifndef KERN_DIR
  ifndef KERN_VER
   KERN_VER := $(patsubst /lib/modules/%/build/.config,%,$(firstword $(shell LC_ALL=C ls -t /lib/modules/*/build/.config 2>/dev/null)))
  endif
  ifeq ($(KERN_VER),)
   KERN_VER := $(shell uname -r)
  endif
  KERN_DIR  := /lib/modules/$(KERN_VER)/build
 endif

 ##
 ## Generates a rule for test-building a linux kernel module (use evalcall2 to invoke).
 ##
 ## Since Linux KBuild will not abort due to undefined symbols when building
 ## external modules we need to grep the error output ourselves.  Since vboxdrv
 ## and vboxguest respectively provide symbols that other modules use, we use
 ## the rule target (tst*.run) to save those symbols so that KBuild can do its
 ## checking.
 ##
 ## @param 1    Module name.
 ## @param 2    The test build which symvers we need (empty if none)
 ## @param 3    Save symvers if non-empty.
 ##
 ## @note Using the extra expansion to replace $(1), $(2) and $(3) before eval,
 ##       thus everything else needs escaped dollars.
 ##
 if   defined(VBOX_WITH_TESTCASES) \
  && "$(KBUILD_HOST)" == "linux" \
  && "$(KBUILD_HOST_ARCH)" == "$(KBUILD_TARGET_ARCH)" \
  && !defined(VBOX_WITHOUT_LINUX_TEST_BUILDS) \
  && !defined(VBOX_ONLY_SDK) \
  && !defined(VBOX_ONLY_DOCS) \
  && !defined(VBOX_ONLY_VALIDATIONKIT)
  define VBOX_LINUX_KMOD_TEST_BUILD_RULE_FN
   ifneq ($(KERN_DIR),)
TESTING      += $$(PATH_TARGET)/tst$(1)$(subst /,_,$(KERN_DIR))_mod.run
OTHERS       += $$(PATH_TARGET)/tst$(1)$(subst /,_,$(KERN_DIR))_mod.run
OTHERS_CLEAN += $$(PATH_TARGET)/tst$(1)$(subst /,_,$(KERN_DIR))_mod.run
$$(PATH_TARGET)/tst$(1)$(subst /,_,$(KERN_DIR))_mod.run: \
		$$(if $(2),$$(PATH_TARGET)/tst$(2)$(subst /,_,$(KERN_DIR))_mod.run,) \
		$$$$($(1)_2_STAGE_TARGETS)
	$(QUIET)$$(call MSG_L1,Doing a test build of the $(1) kernel module)
	$(QUIET)$$(RM) -f    -- "$$@"
	$(QUIET)$$(TEST) -n "$$($(1)_INST)"
	$(QUIET)$$(RM) -Rf   -- "$$(PATH_TARGET)/tst$(1)_mod"
	$(QUIET)$$(MKDIR) -p -- "$$(PATH_TARGET)/tst$(1)_mod"
	$(QUIET)$$(CP) -R    -- "$$(PATH_STAGE_BIN)/../$$($(1)_INST)" "$$(PATH_TARGET)/tst$(1)_mod/"
	+ $(QUIET)make KBUILD_VERBOSE=$(KBUILD_VERBOSE) KERN_DIR=$(KERN_DIR) VBOX_KERN_QUIET=1 -C $$(PATH_TARGET)/tst$(1)_mod clean
   ifneq ($(2),)
	$(QUIET)$$(CP) -f    -- "$$<" "$$(PATH_TARGET)/tst$(1)_mod/Module.symvers"
   endif
	+ $(QUIET)$(REDIRECT_EXT) -d2=1 -w1 "$$(PATH_TARGET)/tst$(1)_mod/make.err" -- \
		make KBUILD_VERBOSE=$(KBUILD_VERBOSE) KERN_DIR=$(KERN_DIR) VBOX_KERN_QUIET=1 $(if $(2),KBUILD_EXTRA_SYMBOLS="$$(PATH_TARGET)/tst$(1)_mod/Module.symvers",) $(if-expr $(KMK_OPTS_JOBS) != 0,JOBS=$(KMK_OPTS_JOBS),) -C $$(PATH_TARGET)/tst$(1)_mod
	$(CAT) "$$(PATH_TARGET)/tst$(1)_mod/make.err"
	$(QUIET)! grep "^WARNING: .* undefined!$$$$" "$$(PATH_TARGET)/tst$(1)_mod/make.err"
   if1of ($(USERNAME), bird)
	- nm -u "$$(PATH_TARGET)/tst$(1)_mod/"*.ko | sort
   endif
   ifneq ($(3),)
	$(QUIET)$$(CP) -f    -- "$$(PATH_TARGET)/tst$(1)_mod/Module.symvers" "$$@"
   else
	$(QUIET)$$(APPEND) -t "$$@" "done"
   endif
	$(QUIET)$$(RM) -Rf   -- "$$(PATH_TARGET)/tst$(1)_mod"
vbox-linux-kmod-test-builds: $$(PATH_TARGET)/tst$(1)$(subst /,_,$(KERN_DIR))_mod.run
$$(foreach src,$$(notdir $$(filter %.c,$$(subst =>,/,$$($(1)_SOURCES)))),$$(patsubst %.c,%.o,$$(src))): $$(PATH_TARGET)/tst$(1)$(subst /,_,$(KERN_DIR))_mod.run
  endif
 endef # VBOX_LINUX_KMOD_TEST_BUILD_RULE_FN
 else
  VBOX_LINUX_KMOD_TEST_BUILD_RULE_FN =
 endif
else
  VBOX_LINUX_KMOD_TEST_BUILD_RULE_FN =
endif # linux target

ifeq ($(KBUILD_TARGET),os2)
 ifndef VBOX_USE_WATCOM_FOR_OS2
TEMPLATE_VBOXR0DRV_TOOL                = GXX3OMF
TEMPLATE_VBOXR0DRV_CXXFLAGS            = -g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing -fno-exceptions -fno-rtti
TEMPLATE_VBOXR0DRV_CFLAGS              = -g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_C)   $(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing -fno-exceptions
TEMPLATE_VBOXR0DRV_LIBS                = $(VBOX_GCC_LIBGCC)
# wlink thinks physdevice doesn't need fixups and should have a stack - stupid!
TEMPLATE_VBOXR0DRV_LDFLAGS             = -Zlinker Option -Zlinker internalrelocs, -Zlinker togglerelocs
  else
TEMPLATE_VBOXR0DRV_TOOL     = OPENWATCOM
TEMPLATE_VBOXR0DRV_CTOOL    = OPENWATCOM
TEMPLATE_VBOXR0DRV_CXXTOOL  = OPENWATCOM
TEMPLATE_VBOXR0DRV_LDTOOL   = OPENWATCOM-WL
TEMPLATE_VBOXR0DRV_ARTOOL   = OPENWATCOM
TEMPLATE_VBOXR0DRV_ASTOOL   = NASM
TEMPLATE_VBOXR0DRV_ASFLAGS  = -fobj -DASM_FORMAT_OMF -D__NASM__ -w+orphan-labels #-g -F borland
TEMPLATE_VBOXR0DRV_DEFS.os2 = #_OS2EMX_H
TEMPLATE_VBOXR0DRV_INCS     = \
	$(PATH_TOOL_OPENWATCOM)/h \
	$(PATH_TOOL_OPENWATCOM)/h/os2 \
	$(PATH_ROOT)/include \
	$(PATH_KLIBC_TRUNK)/libc/include # for os2ddk
TEMPLATE_VBOXR0DRV_CFLAGS   = -s -ze -w4 -hd -d1+ -nt=TEXT32 -nc=CODE -4 -of+
TEMPLATE_VBOXR0DRV_CXXFLAGS = -s -ze -w4 -hd -d2t -nt=TEXT32 -nc=CODE -4 -of+
TEMPLATE_VBOXR0DRV_LDFLAGS  = \
	form os2 lx physdevice \
	option NODefaultlibs, internalrelocs, togglerelocs \
	debug dwarf all #option symfile
#	debug codeview all option symfile - wlink generates bad info, overwritten mod dir header.
 endif
endif

ifeq ($(KBUILD_TARGET),darwin)
TEMPLATE_VBOXR0DRV_TOOL                = $(VBOX_GCC_TOOL)
TEMPLATE_VBOXR0DRV_DEFS               += $(VBOX_DARWIN_DEF_SDK_DEFS) KERNEL KERNEL_PRIVATE DRIVER_PRIVATE APPLE NeXT
 ifdef VBOX_WITH_NEW_XCODE # Note xcode uses -fstrict-aliasing, we currently don't dare... We also add -mno-red-zone.
TEMPLATE_VBOXR0DRV_INCS               += \
	$(VBOX_PATH_MACOSX_SDK)/System/Library/Frameworks/Kernel.framework/PrivateHeaders \
	$(VBOX_PATH_MACOSX_SDK)/System/Library/Frameworks/Kernel.framework/Headers
## @todo try use VBOX_GCC_PEDANTIC_CXX
# -Wno-c++11-extensions -Wno-c99-extensions -Wno-extra-semi -Wno-zero-length-array
TEMPLATE_VBOXR0DRV_CXXFLAGS            = $(VBOX_DARWIN_DEF_SDK_CXXFLAGS) -mkernel \
	-g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_CXX) -Wno-long-long $(VBOX_GCC_fdiagnostics-show-option) \
	-Wno-c++11-extensions -Wno-c99-extensions -Wno-extra-semi -Wno-zero-length-array \
	-Wno-gnu-zero-variadic-macro-arguments -Wno-four-char-constants \
	-fno-common -nostdinc -fno-builtin $(VBOX_GCC_fvisibility-inlines-hidden) $(VBOX_GCC_fvisibility-hidden) \
	-fno-exceptions -msoft-float -fapple-kext -fno-rtti -mkernel \
	-fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -Wnon-modular-include-in-framework-module \
	-Werror=non-modular-include-in-framework-module \
	$(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fasm-blocks -fno-strict-aliasing -stdlib=libc++
# also used by xcode 6.2: \
# -Werror=return-type \
# -Werror=deprecated-objc-isa-usage \
# -Werror=objc-root-class \
# -Wno-missing-field-initializers -Wno-missing-prototypes -Wunreachable-code \
# -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function \
# -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body \
# -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants \
# -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion \
# -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -Wdeprecated-declarations -Winvalid-offsetof -Wno-sign-conversion
TEMPLATE_VBOXR0DRV_CXXFLAGS.amd64      = -m64 -mno-red-zone
TEMPLATE_VBOXR0DRV_CXXFLAGS.x86        = -m32
TEMPLATE_VBOXR0DRV_CFLAGS              = $(VBOX_DARWIN_DEF_SDK_CFLAGS) -mkernel \
	-g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_C) -Wno-long-long $(VBOX_GCC_fdiagnostics-show-option) \
	-fno-common -nostdinc -fno-builtin $(VBOX_GCC_fvisibility-inlines-hidden) $(VBOX_GCC_fvisibility-hidden) \
	-fno-exceptions -msoft-float -fapple-kext -fno-rtti  \
	-fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -Wnon-modular-include-in-framework-module \
	-Werror=non-modular-include-in-framework-module \
	$(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fasm-blocks -fno-strict-aliasing
TEMPLATE_VBOXR0DRV_CFLAGS.amd64        = -m64 -mno-red-zone
TEMPLATE_VBOXR0DRV_CFLAGS.x86          = -m32
  if 1
   TEMPLATE_VBOXR0DRV_CFLAGS          += $(VBOX_GCC_WERR)
   TEMPLATE_VBOXR0DRV_CXXFLAGS        += $(VBOX_GCC_WERR)
  endif
TEMPLATE_VBOXR0DRV_LDFLAGS             =  $(filter-out $(VBOX_DARWIN_NO_COMPACT_LINKEDIT),$(VBOX_DARWIN_DEF_SDK_LDFLAGS)) \
	-nostdlib -stdlib=libc++ -Wl,-kext -Wl,-keep_private_externs
TEMPLATE_VBOXR0DRV_LDFLAGS.amd64       = -m64
TEMPLATE_VBOXR0DRV_LDFLAGS.x86         = -m32
TEMPLATE_VBOXR0DRV_LIBS                = kmodc++ kmod cc_kext
 else
TEMPLATE_VBOXR0DRV_INCS               += \
	$(VBOX_PATH_MACOSX_SDK)/System/Library/Frameworks/Kernel.framework/PrivateHeaders \
	$(VBOX_PATH_MACOSX_SDK)/System/Library/Frameworks/Kernel.framework/Headers
## @todo try use VBOX_GCC_PEDANTIC_CXX
TEMPLATE_VBOXR0DRV_CXXFLAGS            = $(VBOX_DARWIN_DEF_SDK_CXXFLAGS) \
	-g $(VBOX_GCC_pipe) $(VBOX_GCC_WARN) -Wno-long-long $(VBOX_GCC_fdiagnostics-show-option) \
	-fno-common -nostdinc -fno-builtin -finline $(VBOX_GCC_fvisibility-inlines-hidden) $(VBOX_GCC_fvisibility-hidden) \
	-fno-keep-inline-functions -fno-exceptions -msoft-float \
	-fapple-kext -fno-rtti -fcheck-new -force_cpusubtype_ALL \
	$(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing -fasm-blocks
TEMPLATE_VBOXR0DRV_CXXFLAGS.amd64      = -m64 -mkernel -mno-red-zone -gdwarf-2
TEMPLATE_VBOXR0DRV_CXXFLAGS.x86        = -m32 -static
TEMPLATE_VBOXR0DRV_CFLAGS              = $(VBOX_DARWIN_DEF_SDK_CFLAGS) \
	-g $(VBOX_GCC_pipe) $(VBOX_GCC_WARN) -Wno-long-long -fno-common -nostdinc -fno-builtin -finline \
	-fno-keep-inline-functions -fno-exceptions $(VBOX_GCC_fvisibility-hidden) -msoft-float \
	-Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations \
	-Werror-implicit-function-declaration -force_cpusubtype_ALL \
	$(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing -fasm-blocks
TEMPLATE_VBOXR0DRV_CFLAGS.amd64        = -m64 -mkernel -mno-red-zone -gdwarf-2
TEMPLATE_VBOXR0DRV_CFLAGS.x86          = -m32 -static
TEMPLATE_VBOXR0DRV_LDFLAGS             =  $(filter-out $(VBOX_DARWIN_NO_COMPACT_LINKEDIT),$(VBOX_DARWIN_DEF_SDK_LDFLAGS)) \
	-nostdlib -Wl,-kext,-new_linker -Wl,-Y,1455 -keep_private_extern
TEMPLATE_VBOXR0DRV_LDFLAGS.amd64       = -m64
TEMPLATE_VBOXR0DRV_LDFLAGS.x86         = -m32
TEMPLATE_VBOXR0DRV_LIBS                = kmodc++ kmod cc_kext cpp_kext $(VBOX_GCC_LIBGCC)
 endif
endif

ifeq ($(KBUILD_TARGET),solaris)
## The Solaris /usr/platform/i86pc/include and /usr/include directories.
VBOX_SOLARIS_SYS_INCS ?= /usr/platform/i86pc/include /usr/include

TEMPLATE_VBOXR0DRV_TOOL                = $(VBOX_GCC_TOOL)
TEMPLATE_VBOXR0DRV_DEFS               += _MACHDEP _KERNEL _STRICT_STDC
 if $(VBOX_GCC_VERSION_CC) < 30400
TEMPLATE_VBOXR0DRV_DEFS               += RT_WITHOUT_PRAGMA_ONCE
 endif
TEMPLATE_VBOXR0DRV_INCS                = $(VBOX_SOLARIS_SYS_INCS)
TEMPLATE_VBOXR0DRV_LDFLAGS             = -r -dy
TEMPLATE_VBOXR0DRV_LDFLAGS.amd64       = $(if $(eq $(KBUILD_HOST),solaris),-64,-m elf_x86_64)
# Exclude -Wall because of solaris headers' pragma ident warnings that gcc refuses to supress.
TEMPLATE_VBOXR0DRV_CFLAGS              = -Wpointer-arith -Winline $(VBOX_GCC_Wno-pointer-sign) \
	-Wmissing-prototypes -Wstrict-prototypes $(VBOX_GCC_fdiagnostics-show-option) \
	-Wshadow -Wuninitialized -Wunused-function -Wunused-label -Wunused-value -Wunused-variable \
	-Wformat  -Wimplicit-int -Wimplicit-function-declaration -Werror-implicit-function-declaration -Wparentheses \
	-O2 -fno-omit-frame-pointer -ffreestanding -nodefaultlibs -fno-strict-aliasing -fno-common -std=c99
TEMPLATE_VBOXR0DRV_CFLAGS.x86          = -m32 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
TEMPLATE_VBOXR0DRV_CFLAGS.amd64        = -m64 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow $(VBOX_GCC_msave-args) \
	-mno-red-zone -mcmodel=kernel $(if-expr defined(VBOX_GCC_USING_SOLARIS_AS),-Wa$(COMMA)-xmodel=kernel,) \
	-fno-reorder-blocks -fno-asynchronous-unwind-tables -funit-at-a-time
TEMPLATE_VBOXR0DRV_CXXFLAGS           = -Wpointer-arith -Winline \
	-Wshadow -Wuninitialized -Wunused-function -Wunused-label -Wunused-value -Wunused-variable \
	-Wformat \
	-O2 -nodefaultlibs -fno-omit-frame-pointer -fno-strict-aliasing -fno-common -fno-exceptions -fno-rtti
TEMPLATE_VBOXR0DRV_CXXFLAGS.x86       = $(TEMPLATE_VBOXR0DRV_CFLAGS.x86)
TEMPLATE_VBOXR0DRV_CXXFLAGS.amd64     = $(TEMPLATE_VBOXR0DRV_CFLAGS.amd64)
TEMPLATE_VBOXR0DRV_POST_CMDS          = $(VBOX_SIGN_DRIVER_CMDS)
endif # Solaris

ifeq ($(KBUILD_TARGET),freebsd)
# x86 FreeBSD (6.2 or something):
#  cc -O2 -fno-strict-aliasing -pipe -Werror -D_KERNEL -DKLD_MODULE \
#   -nostdinc -I- -I. -I@ -I@/contrib/altq -I@/../include -I/usr/include \
#   -finline-limit=8000 -fno-common -mno-align-long-strings -mpreferred-stack-boundary=2 \
#   -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -ffreestanding -Wall -Wredundant-decls -Wnested-externs \
#   -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -fformat-extensions \
#   -std=c99 -c ../my.c
#  ld -d -warn-common -r -d -o my.kld my.o
#  :> export_syms
#  awk -f /usr/src/sys/modules/my/../../conf/kmod_syms.awk my.kld export_syms | xargs -J% objcopy % my.kld
#  ld -Bsharable -d warn-commnon -o my.ko my.kld
#
# AMD64 FreeBSD (7.1):
#  cc -O2 -fno-strict-aliasing -pipe -D_KERNEL -DKLD_MODULE -std=c99 -nostdinc -I. -I@ -I@/contrib/altq \
#  -finline-limit=8000 --param inline-unit-growth=100 --param large-function-growth=1000 -fno-common  \
#  -fno-omit-frame-pointer -mcmodel=kernel -mno-red-zone -mfpmath=387 -mno-sse -mno-sse2 -mno-mmx \
#  -mno-3dnow -msoft-float -fno-asynchronous-unwind-tables -ffreestanding \
#  -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign \
#  -fformat-extensions -c /usr/src/sys/modules/my/../../dev/my/if_my.c
#  ld  -d -warn-common -r -d -o if_my.ko if_my.o
#  :> export_syms
#  awk -f /usr/src/sys/modules/my/../../conf/kmod_syms.awk if_my.ko  export_syms | xargs -J% objcopy % if_my.ko

# Note: @ -> /usr/src/sys  and  machine -> /usr/src/sys/i386/include

## The location of the FreeBSD kernel source.
VBOX_FREEBSD_SRC ?= /usr/src/sys
## The FreeBSD /usr/include.
VBOX_FREEBSD_SYS_INCS ?= /usr/include

TEMPLATE_VBOXR0DRV_TOOL                = $(VBOX_GCC_TOOL)
TEMPLATE_VBOXR0DRV_LDTOOL              = FREEBSDKMODLD
TEMPLATE_VBOXR0DRV_DEFS               += _KERNEL KLD_MODULE
 if $(VBOX_GCC_VERSION_CC) < 30400
TEMPLATE_VBOXR0DRV_DEFS               += RT_WITHOUT_PRAGMA_ONCE
 endif
TEMPLATE_VBOXR0DRV_INCS                = \
	$(VBOX_FREEBSD_SRC) \
	$(VBOX_FREEBSD_SRC)/contrib/altq \
	$(VBOX_FREEBSD_SRC)/contrib/ck/include \
	$(VBOX_FREEBSD_SRC)/../include \
	$(VBOX_FREEBSD_SYS_INCS)
# omitting: -Wcast-qual, -Wredundant-decls
TEMPLATE_VBOXR0DRV_CFLAGS              =  \
	$(VBOX_GCC_WARN) -Wpointer-arith -Winline $(VBOX_GCC_Wno-pointer-sign) $(VBOX_GCC_fdiagnostics-show-option) \
	-Wstrict-prototypes -Wmissing-prototypes -Wstrict-prototypes \
	-Wimplicit-function-declaration -Werror-implicit-function-declaration \
	-O2 -ffreestanding -fno-strict-aliasing -fno-common \
	$(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
	-nostdinc -std=c99
TEMPLATE_VBOXR0DRV_CFLAGS.x86          = -m32 -mno-align-long-strings -mno-mmx -mno-3dnow -mno-sse -mno-sse2
TEMPLATE_VBOXR0DRV_CFLAGS.amd64        = -m64 -fno-omit-frame-pointer -mcmodel=kernel -mno-red-zone -mfpmath=387 \
	-mno-sse -mno-sse2 -mno-mmx -mno-3dnow -msoft-float -fno-asynchronous-unwind-tables -Wundef
TEMPLATE_VBOXR0DRV_CXXFLAGS            = -fno-exceptions -fno-rtti \
	$(VBOX_GCC_WARN) -Wpointer-arith -Winline \
	-O2 -fno-strict-aliasing -fno-common \
	$(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
	-nostdinc
TEMPLATE_VBOXR0DRV_CXXFLAGS.x86        = $(TEMPLATE_VBOXR0DRV_CFLAGS.x86)
TEMPLATE_VBOXR0DRV_CXXFLAGS.amd64      = $(TEMPLATE_VBOXR0DRV_CFLAGS.amd64)
TEMPLATE_VBOXR0DRV_SYSSUFF             = .ko
TEMPLATE_VBOXR0DRV_LDFLAGS             = -d --warn-common
TEMPLATE_VBOXR0DRV_LDFLAGS.x86         = -m elf_i386_fbsd
TEMPLATE_VBOXR0DRV_LDFLAGS.amd64       = -m elf_x86_64_fbsd

TOOL_FREEBSDKMODLD = FreeBSD kernel module linker.
# See kBuild/tools/GCC3.kmk for docs.
TOOL_FREEBSDKMODLD_LINK_SYSMOD_OUTPUT_MAYBE = $(outbase).map
TOOL_FREEBSDKMODLD_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
TOOL_FREEBSDKMODLD_LINK_SYSMOD_DEPORD =
 ifeq ($(KBUILD_TARGET_ARCH),amd64)
TOOL_FREEBSDKMODLD_LINK_SYSMOD_OUTPUT =
define TOOL_FREEBSDKMODLD_LINK_SYSMOD_CMDS
# Link intermediate .kld (a relocatable object).
	ld $(flags) -r -o  $(out) $(objs) \
		$(foreach p,$(libpath), -L$(p))\
		$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
# Strip non-exported symbols private and localize the exported ones.
	awk -f $(VBOX_FREEBSD_SRC)/conf/kmod_syms.awk  $(out) $(if $(othersrc), $(othersrc),/dev/null) \
		| xargs -J% objcopy % $(out)

## Strip debug info (comment out if debugging or something).
	objcopy --strip-debug $(out)
endef
 else # x86
TOOL_FREEBSDKMODLD_LINK_SYSMOD_OUTPUT = $(outbase).kld
define TOOL_FREEBSDKMODLD_LINK_SYSMOD_CMDS
# Link intermediate .kld (a relocatable object).
	ld $(flags) -r -o $(outbase).kld $(objs) \
		$(foreach p,$(libpath), -L$(p))\
		$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
# Strip non-exported symbols private and localize the exported ones.
	awk -f $(VBOX_FREEBSD_SRC)/conf/kmod_syms.awk $(outbase).kld $(if $(othersrc), $(othersrc),/dev/null) \
		| xargs -J% objcopy % $(outbase).kld

# Link the final .ko (a shared object).
	ld $(flags) -Bshareable -o $(out) $(outbase).kld
endef
 endif # x86

endif # FreeBSD

ifeq ($(KBUILD_TARGET),netbsd)

# The location of the NetBSD sources.
VBOX_NETBSD_SRC ?= /usr/src

# NetBSD uses "i386" for 32-bit, "x86" for common 32- and 64-bit code.
ifeq ($(KBUILD_TARGET_ARCH),amd64)
VBOX_NETBSD_TARGET_ARCH=amd64
else
VBOX_NETBSD_TARGET_ARCH=i386
endif

VBOX_NETBSD_TARGET_SRC=$(VBOX_NETBSD_SRC)/sys/arch/$(VBOX_NETBSD_TARGET_ARCH)

TEMPLATE_VBOXR0DRV_TOOL                = $(VBOX_GCC_TOOL)
TEMPLATE_VBOXR0DRV_DEFS               += _KERNEL _MODULE
 if $(VBOX_GCC_VERSION_CC) < 30400
TEMPLATE_VBOXR0DRV_DEFS               += RT_WITHOUT_PRAGMA_ONCE
 endif
TEMPLATE_VBOXR0DRV_INCS                = \
	$(VBOX_NETBSD_SRC)/sys \
	$(VBOX_NETBSD_SRC)/common/include \
	$(PATH_OBJ)/netbsd/include

TEMPLATE_VBOXR0DRV_CFLAGS              =  \
	$(VBOX_GCC_WARN) -Wpointer-arith -Winline $(VBOX_GCC_Wno-pointer-sign) \
	$(VBOX_GCC_fdiagnostics-show-option) \
	-Wstrict-prototypes -Wmissing-prototypes -Wstrict-prototypes \
	-Wimplicit-function-declaration -Werror-implicit-function-declaration \
	-O2 -ffreestanding -fno-strict-aliasing -fno-common -finline-limit=8000 \
	$(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
	-nostdinc -std=c99 -msoft-float
TEMPLATE_VBOXR0DRV_CFLAGS.x86          = -m32 -mno-mmx -mno-sse -mno-avx \
    -mno-fp-ret-in-387
TEMPLATE_VBOXR0DRV_CFLAGS.amd64        = -m64 --param inline-unit-growth=100 \
    --param large-function-growth=1000 -fno-omit-frame-pointer \
    -mcmodel=kernel -mno-red-zone -mno-sse -mno-mmx -mno-avx \
	-fno-asynchronous-unwind-tables -mno-fp-ret-in-387
TEMPLATE_VBOXR0DRV_CXXFLAGS            = -fno-exceptions -fno-rtti \
	$(VBOX_GCC_WARN) -Wpointer-arith -Winline \
	-O2 -fno-strict-aliasing -fno-common -finline-limit=8000 \
	$(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
	-nostdinc -msoft-float
TEMPLATE_VBOXR0DRV_CXXFLAGS.x86        = $(TEMPLATE_VBOXR0DRV_CFLAGS.x86)
TEMPLATE_VBOXR0DRV_CXXFLAGS.amd64      = $(TEMPLATE_VBOXR0DRV_CFLAGS.amd64)
TEMPLATE_VBOXR0DRV_SYSSUFF             = .kmod
TEMPLATE_VBOXR0DRV_LDFLAGS             = -d --warn-common
TEMPLATE_VBOXR0DRV_LDFLAGS.x86         = -m elf_i386
TEMPLATE_VBOXR0DRV_LDFLAGS.amd64       = -m elf_x86_64

# symlink kernel includes
TEMPLATE_VBOXR0DRV_ORDERDEPS += \
	$(PATH_OBJ)/netbsd/include/$(VBOX_NETBSD_TARGET_ARCH) \
	$(PATH_OBJ)/netbsd/include/x86 \
	$(PATH_OBJ)/netbsd/include/machine

$$(PATH_OBJ)/netbsd/include/$(VBOX_NETBSD_TARGET_ARCH):
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(LN_SYMLINK) $(VBOX_NETBSD_TARGET_SRC)/include $@

$$(PATH_OBJ)/netbsd/include/x86:
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(LN_SYMLINK) $(VBOX_NETBSD_SRC)/sys/arch/x86/include $@

$$(PATH_OBJ)/netbsd/include/machine:
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(LN_SYMLINK) $(VBOX_NETBSD_TARGET_ARCH) $@

endif # NetBSD

ifeq ($(KBUILD_TARGET),haiku)
## The Haiku include directories
VBOX_HAIKU_SYS_INCS ?= /boot/develop/headers/os/kernel /boot/develop/headers/os/drivers

TEMPLATE_VBOXR0DRV_TOOL                = $(VBOX_GCC_TOOL)
TEMPLATE_VBOXR0DRV_LDTOOL              = $(VBOX_GCC_TOOL)
TEMPLATE_VBOXR0DRV_DEFS                = _KERNEL_MODE=1 _STRICT_STDC IN_RING0 IN_RT_R0
 if $(VBOX_GCC_VERSION_CC) < 30400
TEMPLATE_VBOXR0DRV_DEFS               += RT_WITHOUT_PRAGMA_ONCE
 endif
TEMPLATE_VBOXR0DRV_INCS                = $(VBOX_HAIKU_SYS_INCS)
#TODO: sort this out
TEMPLATE_VBOXR0DRV_LDFLAGS             = -shared $(VBOX_GCC_NO_UNDEFINED_R0) -dc -dy -lroot -rpath-link /boot/system/develop/lib/x86 --no-add-needed /boot/system/develop/lib/_KERNEL_ --no-add-needed /boot/system/develop/lib/haiku_version_glue.o
TEMPLATE_VBOXR0DRV_CFLAGS              = -fno-PIC \
	$(VBOX_GCC_WARN) -Wstrict-prototypes $(VBOX_GCC_Wno-pointer-sign) -Wno-sign-compare \
	$(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration
TEMPLATE_VBOXR0DRV_CFLAGS.x86          = -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
TEMPLATE_VBOXR0DRV_CFLAGS.x86          = -m32 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow
TEMPLATE_VBOXR0DRV_CFLAGS.amd64        = -m64 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow \
	-fno-reorder-blocks -ffreestanding -fno-asynchronous-unwind-tables -funit-at-a-time \
	-Wno-sign-compare
TEMPLATE_VBOXR0DRV_CXXFLAGS           = -fno-PIC -Wpointer-arith \
	-Wshadow -Wuninitialized -Wunused-function -Wunused-label -Wunused-value -Wunused-variable \
	-Wformat \
	-O2 -nodefaultlibs -fno-omit-frame-pointer -fno-strict-aliasing -fno-common -fno-exceptions -fno-rtti
TEMPLATE_VBOXR0DRV_CXXFLAGS.x86       = $(TEMPLATE_VBOXR0DRV_CFLAGS.x86) -fno-exceptions -fno-rtti
TEMPLATE_VBOXR0DRV_CXXFLAGS.amd64     = $(TEMPLATE_VBOXR0DRV_CFLAGS.amd64) -fno-exceptions -fno-rtti
endif # Haiku

ifdef VBOX_WITH_VBOXDRV
 ifndef TEMPLATE_VBOXR0DRV_TOOL
  $(warning Warning: VBox Build: Target $(KBUILD_HOST) is not officially supported!)
 endif
endif

ifn1of ($(KBUILD_TARGET), darwin os2 win solaris freebsd)
 # This doesn't work if supdrv is natively loading VMMR0.r0 et al, but
 # fortunately it isn't really necessary.
 TEMPLATE_VBOXR0DRV_CFLAGS    += -include $(PATH_ROOT)/include/VBox/SUPDrvMangling.h
 TEMPLATE_VBOXR0DRV_CXXFLAGS  += -include $(PATH_ROOT)/include/VBox/SUPDrvMangling.h
endif

#
# Template for building libraries used by ring-0 drivers.
#
TEMPLATE_VBoxR0DrvLib = VBox Ring 0 Driver Library
TEMPLATE_VBoxR0DrvLib_EXTENDS = VBOXR0DRV
TEMPLATE_VBoxR0DrvLib_INSTTYPE = stage
TEMPLATE_VBoxR0DrvLib_INSTTYPE.linux = stage

#
# Template for installing INF and CAT files.
#
TEMPLATE_VBoxR0DrvInfCat      = VBox SUPDRV Ring 0 - Install .sys, .cat, .inf
TEMPLATE_VBoxR0DrvInfCat_INST = $(INST_BIN)
TEMPLATE_VBoxR0DrvInfCat_MODE = a+r,u+w
TEMPLATE_VBoxR0DrvInfCat_IFFLAGS = --no-hard-link-files-when-possible


#
# Template for building R3 executables and static libraries which are linked into executables.
# Note! This is the base template for a whole lot of other ones, so be careful when changing it.
#
# Disabled Visual C++ warnings:
#      -wd4065: switch statement contains 'default' but no 'case' labels
#      -wd4244: 'conversion' conversion from 'type1' to 'type2', possible loss of data
#      -wd4996: deprecated / insecure.
#
TEMPLATE_VBOXR3EXE                     = VBox Ring 3 Exe
TEMPLATE_VBOXR3EXE_ASTOOL              = $(VBOX_ASTOOL)
TEMPLATE_VBOXR3EXE_ASFLAGS.x86         = $(VBOX_ASFLAGS32)
TEMPLATE_VBOXR3EXE_ASFLAGS.amd64       = $(VBOX_ASFLAGS64)
TEMPLATE_VBOXR3EXE_DEFS                = IN_RING3 $(VBOX_GC_ARCH_BITS_DEFS)
TEMPLATE_VBOXR3EXE_DEFS.x86            = HC_ARCH_BITS=32
TEMPLATE_VBOXR3EXE_DEFS.arm32          = HC_ARCH_BITS=32
TEMPLATE_VBOXR3EXE_DEFS.sparc32        = HC_ARCH_BITS=32
TEMPLATE_VBOXR3EXE_DEFS.amd64          = HC_ARCH_BITS=64
TEMPLATE_VBOXR3EXE_DEFS.arm64          = HC_ARCH_BITS=64
TEMPLATE_VBOXR3EXE_DEFS.sparc64        = HC_ARCH_BITS=64
TEMPLATE_VBOXR3EXE_DEFS.win            = _CRT_SECURE_NO_DEPRECATE
TEMPLATE_VBOXR3EXE_USES                = dtrace
if defined(VBOX_WITH_DTRACE_R3) && defined(VBOX_WITH_NATIVE_DTRACE)
 TEMPLATE_VBOXR3EXE_DTRACETOOL         = DTraceAndVBoxTpG
 TEMPLATE_VBOXR3EXE_DTRACE_OBJ_FLAGS   = -C
 TEMPLATE_VBOXR3EXE_DTRACE_HDR_FLAGS   = -C
 TEMPLATE_VBOXR3EXE_DEFS              += VBOX_WITH_DTRACE VBOX_WITH_DTRACE_R3 VBOX_WITH_NATIVE_DTRACE
else
  TEMPLATE_VBOXR3EXE_DTRACE_HDR_FLAGS  = --ring-3-context
  TEMPLATE_VBOXR3EXE_DTRACE_OBJ_FLAGS  = --ring-3-context --pic --probe-fn-imported --probe-fn-name "SUPTracerFireProbe"
 if defined(VBOX_WITH_DTRACE_R3)
  TEMPLATE_VBOXR3EXE_DTRACETOOL        = VBoxTpG
  TEMPLATE_VBOXR3EXE_DEFS             += VBOX_WITH_DTRACE VBOX_WITH_DTRACE_R3
 else
  TEMPLATE_VBOXR3EXE_DTRACETOOL        = VBoxTpG-Disabled
 endif
endif
TEMPLATE_VBOXR3EXE_LIBS.kprofile       = $(LIB_KPROFILE)
ifeq ($(KBUILD_TARGET),win)
# TEMPLATE_VBOXR3EXE_TOOL               = $(VBOX_VCC_TOOL)
 TEMPLATE_VBOXR3EXE_TOOL.win.x86       = $(VBOX_VCC_TOOL_STEM)X86
 TEMPLATE_VBOXR3EXE_TOOL.win.amd64     = $(VBOX_VCC_TOOL_STEM)AMD64
 TEMPLATE_VBOXR3EXE_RCDEFS             = VBOX_SVN_REV=$(VBOX_SVN_REV) VBOX_SVN_REV_MOD_5K=$(expr $(VBOX_SVN_REV) % 50000)
 TEMPLATE_VBOXR3EXE_SDKS               = ReorderCompilerIncs $(VBOX_WINPSDK)
 TEMPLATE_VBOXR3EXE_CXXFLAGS           = -Zi -Zl -GR- -EHsc -GF -MD$(VBOX_VCC_CRT_TYPE) -Zc:wchar_t- $(VBOX_VCC_OPT) $(VBOX_VCC_FP) \
 	$(VBOX_VCC_WARN_ALL) $(VBOX_VCC_WERR)
 TEMPLATE_VBOXR3EXE_CXXFLAGS.debug     = -RTCsu
 TEMPLATE_VBOXR3EXE_CXXFLAGS.dbgopt    = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBOXR3EXE_CXXFLAGS.kprofile  = -Gh -GH
 TEMPLATE_VBOXR3EXE_CFLAGS             = $(TEMPLATE_VBOXR3EXE_CXXFLAGS)
 TEMPLATE_VBOXR3EXE_CFLAGS.debug       = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.debug)
 TEMPLATE_VBOXR3EXE_CFLAGS.dbgopt      = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.dbgopt)
 TEMPLATE_VBOXR3EXE_CFLAGS.kprofile    = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.kprofile)
 TEMPLATE_VBOXR3EXE_PCHFLAGS           = $(TEMPLATE_VBOXR3EXE_CXXFLAGS)
 TEMPLATE_VBOXR3EXE_PCHFLAGS.debug     = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.debug)
 TEMPLATE_VBOXR3EXE_PCHFLAGS.dbgopt    = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.dbgopt)
 TEMPLATE_VBOXR3EXE_PCHFLAGS.kprofile  = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.kprofile)
 TEMPLATE_VBOXR3EXE_LDFLAGS            = -Ignore:4197 \
	/NOD /INCREMENTAL:NO /MAPINFO:EXPORTS /LargeAddressAware /DynamicBase /NxCompat /Release /Debug /Opt:Ref /Opt:Icf \
	/Version:$(VBOX_VERSION_MAJOR)0$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	/STUB:$(PATH_ROOT)/src/VBox/HostDrivers/Support/win/winstub.com \
	/DISALLOWLIB:libc.lib \
	/DISALLOWLIB:libcd.lib \
	/DISALLOWLIB:libcmt.lib \
	/DISALLOWLIB:libcmtd.lib \
	/DISALLOWLIB:msvcrt$(VBOX_VCC_CRT_TYPE_N).lib \
	/DISALLOWLIB:msvcprt$(VBOX_VCC_CRT_TYPE_N).lib
 ifdef VBOX_WITH_DTRACE_R3
  TEMPLATE_VBOXR3EXE_LDFLAGS          += -Merge:VTGPrLc.Data=VTGPrLc.Begin -Merge:VTGPrLc.End=VTGPrLc.Begin -Merge:VTGPrLc.Begin=VTGObj
 endif
 if defined(VBOX_SIGNING_MODE) && defined(VBOX_WITH_HARDENING)
   TEMPLATE_VBOXR3EXE_LDFLAGS         += -IntegrityCheck
 endif

 TEMPLATE_VBOXR3EXE_LIBS.x86           = \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.x86)_LIB)/msvcrt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.x86)_LIB)/msvcprt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.x86)_LIB)/oldnames.lib
 TEMPLATE_VBOXR3EXE_LIBS.amd64         = \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.amd64)_LIB)/msvcrt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.amd64)_LIB)/msvcprt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.amd64)_LIB)/oldnames.lib
 TEMPLATE_VBOXR3EXE_POST_CMDS          = $(VBOX_SIGN_IMAGE_CMDS)
 if defined(VBOX_WITH_MORE_NT4_COMPAT_BINARIES) && "$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)" == "win.x86"
  TEMPLATE_VBOXR3EXE_POST_CMDS.win.x86 = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION) $(out)$$(NLTAB)$(TEMPLATE_VBOXR3EXE_POST_CMDS))
  TEMPLATE_VBOXR3EXE_LNK_DEPS.win.x86  = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION))
  TEMPLATE_VBOXR3EXE_LDFLAGS.win.x86   = \
  	-Include:_vcc100_kernel32_fakes_cpp \
	-Include:_vcc100_kernel32_fakes_asm
  TEMPLATE_VBOXR3EXE_LIBS.win.x86      = \
  	$(PATH_STAGE_LIB)/RuntimeR3VccTricks2$(VBOX_SUFF_LIB)
  TEMPLATE_VBOXR3EXE_LIBS.x86          = \
  	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.x86)_LIB)/oldnames.lib \
  	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.x86)_LIB)/libcmt$(VBOX_VCC_CRT_TYPE).lib \
  	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.x86)_LIB)/libcpmt$(VBOX_VCC_CRT_TYPE).lib
 endif

else # the gcc guys
TEMPLATE_VBOXR3EXE_TOOL                = $(VBOX_GCC_TOOL)
 if $(VBOX_GCC_VERSION_CC) < 30400
TEMPLATE_VBOXR3EXE_DEFS               += RT_WITHOUT_PRAGMA_ONCE
 endif
TEMPLATE_VBOXR3EXE_CXXFLAGS            = -g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_OPT) \
 	$(VBOX_GCC_FP) -fno-strict-aliasing $(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_fvisibility-inlines-hidden) $(VBOX_GCC_IPRT_FMT_CHECK)
 ifdef VBOX_WITH_NO_GCC_WARNING_POLICY
  TEMPLATE_VBOXR3EXE_CXXFLAGS         += $(VBOX_GCC_WERR)
 endif
TEMPLATE_VBOXR3EXE_CXXFLAGS.x86        = -m32
TEMPLATE_VBOXR3EXE_CXXFLAGS.amd64      = -m64
TEMPLATE_VBOXR3EXE_CXXFLAGS.sparc32    = -m32
TEMPLATE_VBOXR3EXE_CXXFLAGS.sparc64    = -m64
TEMPLATE_VBOXR3EXE_CXXFLAGS.kprofile   = -finstrument-functions
TEMPLATE_VBOXR3EXE_CXXFLAGS.debug      = $(VBOX_GCC_SANITIZER_FLAGS)
TEMPLATE_VBOXR3EXE_CFLAGS              = -g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_C)   $(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_OPT) $(VBOX_GCC_FP) -fno-strict-aliasing $(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_IPRT_FMT_CHECK)
 ifdef VBOX_WITH_NO_GCC_WARNING_POLICY
  TEMPLATE_VBOXR3EXE_CFLAGS           += $(VBOX_GCC_WERR)
 endif
TEMPLATE_VBOXR3EXE_CFLAGS.x86          = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.x86)
TEMPLATE_VBOXR3EXE_CFLAGS.amd64        = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.amd64)
TEMPLATE_VBOXR3EXE_CFLAGS.sparc32      = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.sparc32)
TEMPLATE_VBOXR3EXE_CFLAGS.sparc64      = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.sparc64)
TEMPLATE_VBOXR3EXE_CFLAGS.debug        = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.debug)
TEMPLATE_VBOXR3EXE_CFLAGS.kprofile     = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.kprofile)
TEMPLATE_VBOXR3EXE_OBJCFLAGS           = $(TEMPLATE_VBOXR3EXE_CFLAGS)
TEMPLATE_VBOXR3EXE_OBJCFLAGS.x86       = $(TEMPLATE_VBOXR3EXE_CFLAGS.x86)
TEMPLATE_VBOXR3EXE_OBJCFLAGS.amd64     = $(TEMPLATE_VBOXR3EXE_CFLAGS.amd64)
TEMPLATE_VBOXR3EXE_OBJCFLAGS.debug     = $(TEMPLATE_VBOXR3EXE_CFLAGS.debug)
TEMPLATE_VBOXR3EXE_OBJCFLAGS.kprofile  = $(TEMPLATE_VBOXR3EXE_CFLAGS.kprofile)
TEMPLATE_VBOXR3EXE_OBJCXXFLAGS         = $(TEMPLATE_VBOXR3EXE_CXXFLAGS)
TEMPLATE_VBOXR3EXE_OBJCXXFLAGS.x86     = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.x86)
TEMPLATE_VBOXR3EXE_OBJCXXFLAGS.amd64   = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.amd64)
TEMPLATE_VBOXR3EXE_OBJCXXFLAGS.debug   = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.debug)
TEMPLATE_VBOXR3EXE_OBJCXXFLAGS.kprofile= $(TEMPLATE_VBOXR3EXE_CXXFLAGS.kprofile)
TEMPLATE_VBOXR3EXE_PCHFLAGS            = $(TEMPLATE_VBOXR3EXE_CXXFLAGS)
TEMPLATE_VBOXR3EXE_PCHFLAGS.x86        = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.x86)
TEMPLATE_VBOXR3EXE_PCHFLAGS.amd64      = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.amd64)
TEMPLATE_VBOXR3EXE_PCHFLAGS.debug      = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.debug)
TEMPLATE_VBOXR3EXE_PCHFLAGS.kprofile   = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.kprofile)
TEMPLATE_VBOXR3EXE_LDFLAGS.x86         = -m32
TEMPLATE_VBOXR3EXE_LDFLAGS.amd64       = -m64
TEMPLATE_VBOXR3EXE_LDFLAGS.sparc32     = -m32
TEMPLATE_VBOXR3EXE_LDFLAGS.sparc64     = -m64
TEMPLATE_VBOXR3EXE_LDFLAGS.linux       = -Wl,-z,noexecstack,-z,relro $(VBOX_LD_as_needed)
TEMPLATE_VBOXR3EXE_LDFLAGS.solaris     = -Wl,-z,ignore # same as VBOX_LD_as_needed
TEMPLATE_VBOXR3EXE_LDFLAGS.debug       = $(VBOX_GCC_SANITIZER_FLAGS) $(VBOX_GCC_SANITIZER_LDFLAGS)

 ifeq ($(KBUILD_TARGET),linux)
TEMPLATE_VBOXR3EXE_LIBS                = pthread m rt dl
 else ifeq ($(KBUILD_TARGET),os2)
TEMPLATE_VBOXR3EXE_TOOL                = GXX3OMF
TEMPLATE_VBOXR3EXE_LIBS                = socket iconv
 else ifeq ($(KBUILD_TARGET),darwin)
TEMPLATE_VBOXR3EXE_TOOL                = $(VBOX_GCC_TOOL)
TEMPLATE_VBOXR3EXE_LIBS                =
TEMPLATE_VBOXR3EXE_DEFS.darwin         = $(VBOX_DARWIN_DEF_SDK_DEFS)
TEMPLATE_VBOXR3EXE_CFLAGS.darwin       = $(VBOX_DARWIN_DEF_SDK_CFLAGS) -fno-common
TEMPLATE_VBOXR3EXE_CXXFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_CXXFLAGS)
TEMPLATE_VBOXR3EXE_PCHFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_CXXFLAGS)
TEMPLATE_VBOXR3EXE_OBJCFLAGS.darwin    = $(VBOX_DARWIN_DEF_SDK_OBJCFLAGS)
TEMPLATE_VBOXR3EXE_OBJCXXFLAGS.darwin  = $(VBOX_DARWIN_DEF_SDK_OBJCXXFLAGS)
TEMPLATE_VBOXR3EXE_LDFLAGS.darwin      = $(VBOX_DARWIN_DEF_SDK_LDFLAGS)
TEMPLATE_VBOXR3EXE_LDFLAGS.darwin.x86  = -read_only_relocs suppress
  ifdef VBOX_WITH_DTRACE_R3
   TEMPLATE_VBOXR3EXE_CXXFLAGS := $(filter-out -pedantic,$(TEMPLATE_VBOXR3EXE_CXXFLAGS)) -fdollars-in-identifiers # annoying gcc option precedence.
  endif
 else ifeq ($(KBUILD_TARGET),haiku)
TEMPLATE_VBOXR3EXE_TOOL                = GXX3
TEMPLATE_VBOXR3EXE_POST_CMDS          = $(VBOX_HAIKU_XRES_SETVER_CMDS)
TEMPLATE_VBOXR3EXE_LIBS                = network iconv stdc++ supc++
TEMPLATE_VBOXR3EXE_LIBPATH            += \
	/boot/common/lib
# Haiku uses PIC by default...
TEMPLATE_VBOXR3EXE_CFLAGS             += -fno-pic
TEMPLATE_VBOXR3EXE_CXXFLAGS           += -fno-pic
TEMPLATE_VBOXR3EXE_LDFLAGS            += -fno-pic
 else if1of ($(KBUILD_TARGET), freebsd openbsd)
TEMPLATE_VBOXR3EXE_TOOL                = GXX3
TEMPLATE_VBOXR3EXE_LIBS                = pthread
TEMPLATE_VBOXR3EXE_INCS               += \
	/usr/include \
	/usr/X11R6/include \
	/usr/local/include
TEMPLATE_VBOXR3EXE_LIBPATH            += \
	/usr/lib \
	/usr/X11R6/lib \
	/usr/local/lib
 else ifeq ($(KBUILD_TARGET),netbsd)
TEMPLATE_VBOXR3EXE_TOOL                = GXX3
TEMPLATE_VBOXR3EXE_LIBS                = pthread
TEMPLATE_VBOXR3EXE_INCS               += \
	/usr/include \
	/usr/X11R7/include
TEMPLATE_VBOXR3EXE_LIBPATH            += \
	/usr/lib \
	/usr/X11R7/lib
 else ifeq ($(KBUILD_TARGET),solaris)
TEMPLATE_VBOXR3EXE_TOOL                = GXX3PLAIN
TEMPLATE_VBOXR3EXE_DEFS               += LIBICONV_PLUG _REENTRANT # Avoid the GNU libiconv, for now at least.
TEMPLATE_VBOXR3EXE_LIBS                = rt socket
 else
$(warning Warning: VBOX Build: Target $(KBUILD_TARGET) is not officially supported!)
TEMPLATE_VBOXR3EXE_CXXFLAGS.profile    = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.release)
TEMPLATE_VBOXR3EXE_CXXFLAGS.kprofile   = $(TEMPLATE_VBOXR3EXE_CXXFLAGS.krelease)
 endif
 ifdef VBOX_WITH_RUNPATH
  TEMPLATE_VBOXR3EXE_LDFLAGS          += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)'
 else ifdef VBOX_WITH_RELATIVE_RUNPATH
  TEMPLATE_VBOXR3EXE_LDFLAGS          += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)'
 endif
 ifdef VBOX_WITH_ORIGIN
  TEMPLATE_VBOXR3EXE_LDFLAGS.linux    += $(VBOX_GCC_ORIGIN_OPT)
 endif
endif

#
# Template for building R3 shared objects / DLLs.
# This is mostly identical to the VBOXR3EXE template. (Avoid PIC if possible!)
#				       -
TEMPLATE_VBOXR3                        = VBox Ring 3 SO/DLLs
TEMPLATE_VBOXR3_EXTENDS                = VBOXR3EXE
TEMPLATE_VBOXR3_DEFS.darwin            = $(TEMPLATE_VBOXR3EXE_DEFS.darwin) PIC
TEMPLATE_VBOXR3_LDFLAGS.darwin         = $(TEMPLATE_VBOXR3EXE_LDFLAGS.darwin) \
	-current_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	-compatibility_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD)
ifn1of ($(KBUILD_TARGET), darwin win os2)
 TEMPLATE_VBOXR3_DEFS                  = $(TEMPLATE_VBOXR3EXE_DEFS) PIC
 TEMPLATE_VBOXR3_CFLAGS                = $(TEMPLATE_VBOXR3EXE_CFLAGS) -fPIC
 TEMPLATE_VBOXR3_CXXFLAGS              = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) -fPIC
 TEMPLATE_VBOXR3_PCHFLAGS              = $(TEMPLATE_VBOXR3EXE_PCHFLAGS) -fPIC
 TEMPLATE_VBOXR3_LDFLAGS               = $(TEMPLATE_VBOXR3EXE_LDFLAGS) -fPIC
endif
ifeq ($(KBUILD_TARGET),haiku)
 # Haiku uses PIC by default...
 TEMPLATE_VBOXR3_CFLAGS               = $(TEMPLATE_VBOXR3EXE_CFLAGS) -fno-pic
 TEMPLATE_VBOXR3_CXXFLAGS             = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) -fno-pic
 TEMPLATE_VBOXR3_PCHFLAGS             = $(TEMPLATE_VBOXR3EXE_PCHFLAGS) -fno-pic
 TEMPLATE_VBOXR3_LDFLAGS              = $(TEMPLATE_VBOXR3EXE_LDFLAGS) -fno-pic
endif

#
# Temporary: Renaming the template and warnings will be errors ("soon").
#
TEMPLATE_VBoxR3Dll                     += VBox ring-3 SO/DLLs, no warnings
TEMPLATE_VBoxR3Dll_EXTENDS             += VBOXR3
TEMPLATE_VBoxR3Dll_EXTENDS_BY          += appending
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxR3Dll_CFLAGS            += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3Dll_CXXFLAGS          += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3Dll_PCHFLAGS          += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3Dll_LDFLAGS           += $(VBOX_VCC_LD_WERR)
else
 TEMPLATE_VBoxR3Dll_CFLAGS            += $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3Dll_CXXFLAGS          += $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3Dll_PCHFLAGS          += $(VBOX_GCC_WERR)
endif

# x86 edition of the above template for use on AMD64 targets.
TEMPLATE_VBoxR3Dll-x86                = 32-bit VBox ring-3 SO/DLLs, no warnings
TEMPLATE_VBoxR3Dll-x86_EXTENDS        = VBoxR3Dll
TEMPLATE_VBoxR3Dll-x86_BLD_TRG_ARCH   = x86
TEMPLATE_VBoxR3Dll-x86_DEFS           = $(filter-out HC_ARCH_BITS%,$(TEMPLATE_VBoxR3Dll_DEFS)) \
	HC_ARCH_BITS=32 ARCH_BITS=32
ifeq ($(KBUILD_TARGET),solaris)
 ifdef VBOX_WITH_RUNPATH
  TEMPLATE_VBoxR3Dll-x86_LDFLAGS = \
	$(filter-out '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)',$(TEMPLATE_VBoxR3Dll_LDFLAGS)) \
	'$(VBOX_GCC_RPATH_OPT)$(VBOX_PATH_APP_PRIVATE)' \
	'$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)'
 endif
endif


#
# Template for building performance critical stuff with warnings-as-errors.
#
TEMPLATE_VBoxR3DllNoPic                    = VBox ring-3 SO/DLLs without PIC, without warnings.
TEMPLATE_VBoxR3DllNoPic_EXTENDS            = VBOXR3
if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), linux.x86 freebsd.x86)
 TEMPLATE_VBoxR3DllNoPic_DEFS              = $(TEMPLATE_VBOXR3EXE_DEFS)
 TEMPLATE_VBoxR3DllNoPic_CFLAGS            = $(TEMPLATE_VBOXR3EXE_CFLAGS)   $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3DllNoPic_CXXFLAGS          = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3DllNoPic_PCHFLAGS          = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3DllNoPic_LDFLAGS           = $(TEMPLATE_VBOXR3EXE_LDFLAGS)
else ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxR3DllNoPic_CFLAGS            = $(filter-out -W3 -wd%,$(TEMPLATE_VBOXR3_CFLAGS)) $(VBOX_VCC_WARN_ALL) $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3DllNoPic_CFLAGS.debug      = $(filter-out -RTC%,$(TEMPLATE_VBOXR3_CFLAGS.debug))
 TEMPLATE_VBoxR3DllNoPic_CFLAGS.release    = $(TEMPLATE_VBOXR3_CFLAGS.release) -GS-
 TEMPLATE_VBoxR3DllNoPic_CXXFLAGS          = $(filter-out -W3 -wd%,$(TEMPLATE_VBOXR3_CXXFLAGS)) $(VBOX_VCC_WARN_ALL) $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3DllNoPic_CXXFLAGS.debug    = $(filter-out -RTC%,$(TEMPLATE_VBOXR3_CXXFLAGS.debug)) # RTCsu Prevents IEM opt.
 TEMPLATE_VBoxR3DllNoPic_CXXFLAGS.release  = $(TEMPLATE_VBOXR3_CXXFLAGS.release) -GS-
 TEMPLATE_VBoxR3DllNoPic_PCHFLAGS          = $(filter-out -W3 -wd%,$(TEMPLATE_VBOXR3_PCHFLAGS)) $(VBOX_VCC_WARN_ALL) $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3DllNoPic_PCHFLAGS.debug    = $(filter-out -RTC%,$(TEMPLATE_VBOXR3_PCHFLAGS.debug)) # RTCsu Prevents IEM opt.
 TEMPLATE_VBoxR3DllNoPic_PCHFLAGS.release  = $(TEMPLATE_VBOXR3_PCHFLAGS.release) -GS-
 TEMPLATE_VBoxR3DllNoPic_LDFLAGS           = $(TEMPLATE_VBOXR3_LDFLAGS)  $(VBOX_VCC_LD_WERR)
else
 TEMPLATE_VBoxR3DllNoPic_CFLAGS            = $(TEMPLATE_VBOXR3_CFLAGS)   $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3DllNoPic_CXXFLAGS          = $(TEMPLATE_VBOXR3_CXXFLAGS) $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3DllNoPic_PCHFLAGS          = $(TEMPLATE_VBOXR3_PCHFLAGS) $(VBOX_GCC_WERR)
endif

# x86 edition of the above template for use on AMD64 targets.
TEMPLATE_VBoxR3DllNoPic-x86                = 32-bit VBox ring-3 SO/DLLs without PIC, without warnings.
TEMPLATE_VBoxR3DllNoPic-x86_EXTENDS        = VBoxR3DllNoPic
TEMPLATE_VBoxR3DllNoPic-x86_BLD_TRG_ARCH   = x86
TEMPLATE_VBoxR3DllNoPic-x86_DEFS           = $(filter-out HC_ARCH_BITS%,$(TEMPLATE_VBoxR3DllNoPic_DEFS)) \
	HC_ARCH_BITS=32 ARCH_BITS=32


#
# Template for building performance critical stuff without warnings-as-errors.
#
TEMPLATE_VBoxR3DllWarnNoPic                = VBox ring-3 SO/DLLs without PIC, with warnings.
TEMPLATE_VBoxR3DllWarnNoPic_EXTENDS        = VBOXR3
if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), linux.x86 freebsd.x86)
 TEMPLATE_VBoxR3DllWarnNoPic_DEFS          = $(TEMPLATE_VBOXR3EXE_DEFS)
 TEMPLATE_VBoxR3DllWarnNoPic_CFLAGS        = $(TEMPLATE_VBOXR3EXE_CFLAGS)
 TEMPLATE_VBoxR3DllWarnNoPic_CXXFLAGS      = $(TEMPLATE_VBOXR3EXE_CXXFLAGS)
 TEMPLATE_VBoxR3DllWarnNoPic_PCHFLAGS      = $(TEMPLATE_VBOXR3EXE_PCHFLAGS)
 TEMPLATE_VBoxR3DllWarnNoPic_LDFLAGS       = $(TEMPLATE_VBOXR3EXE_LDFLAGS)
else ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxR3DllWarnNoPic_CFLAGS.release   = $(TEMPLATE_VBOXR3_CFLAGS.release) -GS-
 TEMPLATE_VBoxR3DllWarnNoPic_CXXFLAGS.release = $(TEMPLATE_VBOXR3_CXXFLAGS.release) -GS-
 TEMPLATE_VBoxR3DllWarnNoPic_PCHFLAGS.release = $(TEMPLATE_VBOXR3_PCHFLAGS.release) -GS-
endif

#
# Template for building static R3 executables and any static
# libraries they link with.
#
TEMPLATE_VBOXR3STATIC                  = VBox Static Ring 3 EXE
TEMPLATE_VBOXR3STATIC_EXTENDS          = VBOXR3EXE
TEMPLATE_VBOXR3STATIC_DEFS             = IN_RT_STATIC IN_RT_R3 IN_SUP_STATIC $(TEMPLATE_VBOXR3EXE_DEFS)
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBOXR3STATIC_CFLAGS          = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBOXR3EXE_CFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBOXR3STATIC_CXXFLAGS        = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBOXR3EXE_CXXFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBOXR3STATIC_PCHFLAGS        = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBOXR3EXE_PCHFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBOXR3STATIC_LDFLAGS         = $(filter-out /DISALLOWLIB:libcmt$(VBOX_VCC_CRT_TYPE).lib /DISALLOWLIB:libcpmt$(VBOX_VCC_CRT_TYPE).lib, $(TEMPLATE_VBOXR3EXE_LDFLAGS)) \
	/DISALLOWLIB:msvcrt.lib \
	/DISALLOWLIB:msvcrtd.lib \
	/DISALLOWLIB:msvcprt.lib \
	/DISALLOWLIB:msvcprtd.lib
 TEMPLATE_VBOXR3STATIC_LIBS.x86           = \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3STATIC_TOOL.win.x86)_LIB)/oldnames.lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3STATIC_TOOL.win.x86)_LIB)/libcmt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3STATIC_TOOL.win.x86)_LIB)/libcpmt$(VBOX_VCC_CRT_TYPE).lib
 TEMPLATE_VBOXR3STATIC_LIBS.amd64         = \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3STATIC_TOOL.win.amd64)_LIB)/libcmt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3STATIC_TOOL.win.amd64)_LIB)/libcpmt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3STATIC_TOOL.win.amd64)_LIB)/oldnames.lib
else ifn1of ($(KBUILD_TARGET), darwin linux solaris)
 # The gcc guys sans darwin, linux and solaris (don't depend on statically compiled system libs there)
 TEMPLATE_VBOXR3STATIC_CFLAGS          = $(TEMPLATE_VBOXR3EXE_CFLAGS) -static
 TEMPLATE_VBOXR3STATIC_CXXFLAGS        = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) -static
 TEMPLATE_VBOXR3STATIC_PCHFLAGS        = $(TEMPLATE_VBOXR3EXE_PCHFLAGS) -static
 TEMPLATE_VBOXR3STATIC_OBJCFLAGS       = $(TEMPLATE_VBOXR3EXE_OBJCFLAGS) -static
 TEMPLATE_VBOXR3STATIC_OBJCXXFLAGS     = $(TEMPLATE_VBOXR3EXE_OBJCXXFLAGS) -static
 TEMPLATE_VBOXR3STATIC_LDFLAGS         = $(TEMPLATE_VBOXR3EXE_LDFLAGS) -static
else ifeq ($(KBUILD_TARGET),solaris)
 TEMPLATE_VBOXR3STATIC_LIBS            = $(TEMPLATE_VBOXR3EXE_LIBS) nsl
 TEMPLATE_VBOXR3STATIC_LDFLAGS         = $(filter-out '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)',$(TEMPLATE_VBOXR3EXE_LDFLAGS))
else
 TEMPLATE_VBOXR3STATIC_LDFLAGS         = $(filter-out '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)',$(TEMPLATE_VBOXR3EXE_LDFLAGS))
endif

#
# Temporary: Renaming the template and warnings will be errors (soon).
# Unlike VBOXR3STATIC, this is strict wrt warnings and includes IPRT.
#
TEMPLATE_VBoxR3Static               = New name for VBOXR3STATIC
TEMPLATE_VBoxR3Static_EXTENDS       = VBOXR3STATIC
TEMPLATE_VBoxR3Static_EXTENDS_BY    = appending
TEMPLATE_VBoxR3Static_SDKS         += VBOX_OPENSSL
TEMPLATE_VBoxR3Static_SDKS.win     += VBOX_NTDLL
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxR3Static_CFLAGS      += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3Static_CXXFLAGS    += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3Static_PCHFLAGS    += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3Static_LDFLAGS     += $(VBOX_VCC_LD_WERR)
else
 TEMPLATE_VBoxR3Static_CFLAGS      += $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3Static_CXXFLAGS    += $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3Static_PCHFLAGS    += $(VBOX_GCC_WERR)
endif
TEMPLATE_VBoxR3Static_LIBS         += \
 	$(VBOX_LIB_RUNTIME_STATIC)
ifndef SDK_VBOX_LIBXML2_LIBS
 TEMPLATE_VBoxR3Static_LIBS        += \
 	$(PATH_STAGE_LIB)/VBox-libxml2-static$(VBOX_SUFF_LIB)
endif
if1of ($(KBUILD_TARGET),os2 win)
 TEMPLATE_VBoxR3Static_LIBS        += \
 	$(SDK_VBOX_LZF_STATIC_LIBS) \
 	$(SDK_VBOX_ZLIB_STATIC_LIBS)
else
 TEMPLATE_VBoxR3Static_LIBS        += \
 	$(SDK_VBOX_LZF_LIBS) \
 	$(SDK_VBOX_ZLIB_LIBS)
 if1of ($(KBUILD_TARGET),darwin freebsd)
  TEMPLATE_VBoxR3Static_LIBS       += iconv
 else ifeq ($(KBUILD_TARGET),solaris)
  TEMPLATE_VBoxR3Static_LIBS       += kstat
 endif
endif

#
# Non-pedantic variation of VBoxR3Static
#
TEMPLATE_VBoxR3StaticNonPedantic            = VBox Static Ring-3 EXE, non-pedantic.
TEMPLATE_VBoxR3StaticNonPedantic_EXTENDS   = VBoxR3Static
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxR3StaticNonPedantic_CFLAGS   = $(TEMPLATE_VBoxR3Static_CFLAGS)   $(VBOX_VCC_NON_PEDANTIC)
 TEMPLATE_VBoxR3StaticNonPedantic_CXXFLAGS = $(TEMPLATE_VBoxR3Static_CXXFLAGS) $(VBOX_VCC_NON_PEDANTIC)
 TEMPLATE_VBoxR3StaticNonPedantic_PCHFLAGS = $(TEMPLATE_VBoxR3Static_PCHFLAGS) $(VBOX_VCC_NON_PEDANTIC)
else # gcc:
 TEMPLATE_VBoxR3StaticNonPedantic_TOOL     = $(VBOX_GCC_TOOL)
 TEMPLATE_VBoxR3StaticNonPedantic_CFLAGS   = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_C)  ,$(TEMPLATE_VBoxR3Static_CFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_CXX)
 TEMPLATE_VBoxR3StaticNonPedantic_CXXFLAGS = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBoxR3Static_CXXFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_CXX)
 TEMPLATE_VBoxR3StaticNonPedantic_PCHFLAGS = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBoxR3Static_PCHFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_CXX)
endif


#
# Same as VBOXR3EXE but without C++ exceptions.
#
# VBOXR3EXE does C++ exceptions and may assumes that extern "C" functions
# doesn't throw them. Use this template (and VBOXR3DLLNOXCPT) with care
# and only where the C++ overhead is really unwanted.
#
TEMPLATE_VBOXR3EXENOXCPT               = VBox Ring 3 Exe without C++ exception
TEMPLATE_VBOXR3EXENOXCPT_EXTENDS       = VBOXR3EXE
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBOXR3EXENOXCPT_CFLAGS       = $(filter-out -EH%,$(TEMPLATE_VBOXR3EXE_CFLAGS)  ) -EHs-
 TEMPLATE_VBOXR3EXENOXCPT_CXXFLAGS     = $(filter-out -EH%,$(TEMPLATE_VBOXR3EXE_CXXFLAGS)) -EHs-
 TEMPLATE_VBOXR3EXENOXCPT_PCHFLAGS     = $(filter-out -EH%,$(TEMPLATE_VBOXR3EXE_PCHFLAGS)) -EHs-
else
 TEMPLATE_VBOXR3EXENOXCPT_CXXFLAGS     = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) -fno-exceptions
 TEMPLATE_VBOXR3EXENOXCPT_PCHFLAGS     = $(TEMPLATE_VBOXR3EXE_PCHFLAGS) -fno-exceptions
endif

#
# Same as VBOXR3 but without C++ exceptions.
#
TEMPLATE_VBOXR3DLLNOXCPT               = VBox Ring 3 SO/DLLs without C++ exception
TEMPLATE_VBOXR3DLLNOXCPT_EXTENDS       = VBOXR3
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBOXR3DLLNOXCPT_CFLAGS       = $(filter-out -EH%,$(TEMPLATE_VBOXR3_CFLAGS)  ) -EHs-
 TEMPLATE_VBOXR3DLLNOXCPT_CXXFLAGS     = $(filter-out -EH%,$(TEMPLATE_VBOXR3_CXXFLAGS)) -EHs-
 TEMPLATE_VBOXR3DLLNOXCPT_PCHFLAGS     = $(filter-out -EH%,$(TEMPLATE_VBOXR3_PCHFLAGS)) -EHs-
else
 TEMPLATE_VBOXR3DLLNOXCPT_CXXFLAGS     = $(TEMPLATE_VBOXR3_CXXFLAGS) -fno-exceptions
 TEMPLATE_VBOXR3DLLNOXCPT_PCHFLAGS     = $(TEMPLATE_VBOXR3_PCHFLAGS) -fno-exceptions
endif

#
# Template for building hardened Ring-3 executables.
# These shall have no extra runpaths, esp. not origin ones.
#
TEMPLATE_VBOXR3HARDENEDEXE = Hardened VBox Ring-3 EXE
TEMPLATE_VBOXR3HARDENEDEXE_EXTENDS = VBOXR3EXE
TEMPLATE_VBOXR3HARDENEDEXE_DEBUG_INST.win = $(INST_DEBUG)hardened-exes/
ifdef VBOX_WITH_HARDENING
 TEMPLATE_VBOXR3HARDENEDEXE_LIBS = $(VBOX_LIB_SUPHARDENED) $(TEMPLATE_VBOXR3EXE_LIBS)
else
 TEMPLATE_VBOXR3HARDENEDEXE_LIBS = $(TEMPLATE_VBOXR3EXE_LIBS)
endif
TEMPLATE_VBOXR3HARDENEDEXE_LDFLAGS.darwin = $(TEMPLATE_VBOXR3EXE_LDFLAGS.darwin) -framework IOKit
ifeq ($(KBUILD_TARGET),linux)
# not necessary except USE_LIB_PCAP is defined in SUPR3HardenedMain.cpp
# TEMPLATE_VBOXR3HARDENEDEXE_LIBS += cap
endif
ifeq ($(KBUILD_TARGET),win) # No CRT!
 TEMPLATE_VBOXR3HARDENEDEXE_SDKS          = VBOX_NTDLL $(TEMPLATE_VBOXR3EXE_SDKS)
 TEMPLATE_VBOXR3HARDENEDEXE_LIBS.x86      = \
	$(PATH_SDK_$(VBOX_WINDDK)_LIB.x86)/int64.lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3HARDENEDEXE_TOOL.win.x86)_LIB)/chkstk.obj
 TEMPLATE_VBOXR3HARDENEDEXE_CXXFLAGS      = $(filter-out -RTC% -GZ -GS,$(TEMPLATE_VBOXR3EXE_CXXFLAGS)) -GS-
 TEMPLATE_VBOXR3HARDENEDEXE_CXXFLAGS.debug= $(filter-out -RTC% -GZ -GS,$(TEMPLATE_VBOXR3EXE_CXXFLAGS.debug)) -GS- #-O2 -Oy-
 TEMPLATE_VBOXR3HARDENEDEXE_PCHFLAGS      = $(filter-out -RTC% -GZ -GS,$(TEMPLATE_VBOXR3EXE_PCHFLAGS)) -GS-
 TEMPLATE_VBOXR3HARDENEDEXE_PCHFLAGS.debug= $(filter-out -RTC% -GZ -GS,$(TEMPLATE_VBOXR3EXE_PCHFLAGS.debug)) -GS- #-O2 -Oy-
 TEMPLATE_VBOXR3HARDENEDEXE_CFLAGS        = $(filter-out -RTC% -GZ -GS,$(TEMPLATE_VBOXR3EXE_CFLAGS)) -GS-
 TEMPLATE_VBOXR3HARDENEDEXE_CFLAGS.debug  = $(filter-out -RTC% -GZ -GS,$(TEMPLATE_VBOXR3EXE_CFLAGS.debug)) -GS- -O2 -Oy-
 TEMPLATE_VBOXR3HARDENEDEXE_LDFLAGS       = $(TEMPLATE_VBOXR3EXE_LDFLAGS) \
	/DISALLOWLIB:msvcrt$(VBOX_VCC_CRT_TYPE).lib \
	/DISALLOWLIB:msvcprt$(VBOX_VCC_CRT_TYPE).lib
 TEMPLATE_VBOXR3HARDENEDEXE_LDFLAGS.win.x86   = $(TEMPLATE_VBOXR3EXE_LDFLAGS.win.x86)   /entry:suplibHardenedWindowsMain
 TEMPLATE_VBOXR3HARDENEDEXE_LDFLAGS.win.amd64 = $(TEMPLATE_VBOXR3EXE_LDFLAGS.win.amd64) /entry:suplibHardenedWindowsMain
 TEMPLATE_VBOXR3HARDENEDEXE_LIBS.x86       = $(NOT_SUCH_VARIABLE)
 TEMPLATE_VBOXR3HARDENEDEXE_LIBS.amd64     = $(NOT_SUCH_VARIABLE)
else ifn1of ($(KBUILD_TARGET), os2 solaris)
 # We want to keep the RPATH on Solaris to be able to find libgcc_1/libstdc++ within $(VBOX_WITH_RUNPATH)
 TEMPLATE_VBOXR3HARDENEDEXE_LDFLAGS       = $(filter-out '$(VBOX_GCC_RPATH_OPT)%,$(TEMPLATE_VBOXR3EXE_LDFLAGS))
 TEMPLATE_VBOXR3HARDENEDEXE_LDFLAGS.linux = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBOXR3EXE_LDFLAGS.linux))
endif

#
# Template for building hardened Ring-3 libraries.
#
TEMPLATE_VBOXR3HARDENEDLIB = Hardened VBox Ring-3 LIB
TEMPLATE_VBOXR3HARDENEDLIB_EXTENDS = VBOXR3HARDENEDEXE
TEMPLATE_VBOXR3HARDENEDLIB_LIBS = $(NO_SUCH_VARIABLE)


#
# Template for building hardened Ring-3 testcase executables.
#
TEMPLATE_VBoxR3HardenedTstExe = VBox Ring-3 Hardened Testcase Exe (currently windows only!)
TEMPLATE_VBoxR3HardenedTstExe_EXTENDS = VBOXR3HARDENEDEXE
TEMPLATE_VBoxR3HardenedTstExe_INST = $(INST_TESTCASE)

#
# Template for building hardened Ring-3 testcase DLLs (pairs with VBoxR3HardenedTstExe).
#
TEMPLATE_VBoxR3HardenedTstDll = VBox Ring-3 Hardened Testcase Dll (currently windows only!)
TEMPLATE_VBoxR3HardenedTstDll_EXTENDS = VBoxR3TstDll
TEMPLATE_VBoxR3HardenedTstDll_INST = $(INST_TESTCASE)
 TEMPLATE_VBoxR3HardenedTstDll_LDFLAGS.win = $(TEMPLATE_VBoxR3TstDll_LDFLAGS.win) -IntegrityCheck
ifn1of ($(KBUILD_TARGET), win os2)
 TEMPLATE_VBoxR3HardenedTstDll_LDFLAGS       = $(filter-out '$(VBOX_GCC_RPATH_OPT)%,$(TEMPLATE_VBoxR3TstDll_LDFLAGS))
 TEMPLATE_VBoxR3HardenedTstDll_LDFLAGS.linux = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBoxR3TstDll_LDFLAGS.linux))
endif

#
# Template for building set-uid-to-root helper programs.
# In hardened builds, these may only contain absolute runpaths!
#
TEMPLATE_VBoxR3SetUidToRoot = Set-uid-to-root helper program.
if1of ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxR3SetUidToRoot_EXTENDS = VBOXR3EXE
else
 TEMPLATE_VBoxR3SetUidToRoot_EXTENDS = VBOXR3HARDENEDEXE
endif
TEMPLATE_VBoxR3SetUidToRoot_LIBS = $(NO_SUCH_VARIABLE)
ifdef VBOX_WITH_RUNPATH
 TEMPLATE_VBoxR3SetUidToRoot_LDFLAGS += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)'
endif
ifndef VBOX_WITH_HARDENING
 ifdef VBOX_WITH_RELATIVE_RUNPATH
  TEMPLATE_VBoxR3SetUidToRoot_LDFLAGS += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)'
 endif
 ifdef VBOX_WITH_ORIGIN
  TEMPLATE_VBoxR3SetUidToRoot_LDFLAGS.linux += $(VBOX_GCC_ORIGIN_OPT)
 endif
endif

#
# Template for building R3 tools.
#
TEMPLATE_VBoxR3Tool            = VBox Ring 3 Tools
TEMPLATE_VBoxR3Tool_EXTENDS    = VBOXR3EXE
TEMPLATE_VBoxR3Tool_INST       = $(VBOX_INST_TOOLS)
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxR3Tool_CFLAGS    = $(TEMPLATE_VBOXR3EXE_CFLAGS) $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3Tool_CXXFLAGS  = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3Tool_PCHFLAGS  = $(TEMPLATE_VBOXR3EXE_PCHFLAGS) $(VBOX_VCC_WERR)
 TEMPLATE_VBoxR3Tool_LDFLAGS   = $(TEMPLATE_VBOXR3EXE_LDFLAGS) $(VBOX_VCC_LD_WERR)
else
 TEMPLATE_VBoxR3Tool_CFLAGS    = $(TEMPLATE_VBOXR3EXE_CFLAGS) $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3Tool_CXXFLAGS  = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) $(VBOX_GCC_WERR)
 TEMPLATE_VBoxR3Tool_PCHFLAGS  = $(TEMPLATE_VBOXR3EXE_PCHFLAGS) $(VBOX_GCC_WERR)
 ifdef VBOX_WITH_RUNPATH
  TEMPLATE_VBoxR3Tool_LDFLAGS  = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' $(TEMPLATE_VBOXR3EXE_LDFLAGS)
 else ifdef VBOX_WITH_RELATIVE_RUNPATH
  TEMPLATE_VBoxR3Tool_LDFLAGS  = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/..' $(TEMPLATE_VBOXR3EXE_LDFLAGS)
 endif
endif
TEMPLATE_VBoxR3Tool_LIBS       = $(LIB_RUNTIME) $(TEMPLATE_VBOXR3EXE_LIBS)
if defined(VBOX_WITH_MORE_NT4_COMPAT_BINARIES) && "$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)" == "win.x86"
 TEMPLATE_VBoxR3Tool_LIBS.x86  = \
 	$(PATH_STAGE_LIB)/RuntimeR3VccTricks2$(VBOX_SUFF_LIB) \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.x86)_LIB)/oldnames.lib
endif

#
# Template for building R3 shared objects / DLLs with the 10.5 Mac OS X SDK.
# Identical to VBOXR3EXE, except for the DYLIB, the classic_linker and SDK bits.
#
TEMPLATE_VBOXR3OSX105  = VBox Ring 3 SO/DLLs for OS X 10.5
TEMPLATE_VBOXR3OSX105_EXTENDS = VBOXR3EXE
TEMPLATE_VBOXR3OSX105_DEFS.darwin        = $(VBOX_DARWIN_DEF_SDK_10_5_DEFS) PIC
TEMPLATE_VBOXR3OSX105_CFLAGS.darwin      = $(VBOX_DARWIN_DEF_SDK_10_5_CFLAGS) -fno-common
TEMPLATE_VBOXR3OSX105_CXXFLAGS.darwin    = $(VBOX_DARWIN_DEF_SDK_10_5_CXXFLAGS)
TEMPLATE_VBOXR3OSX105_PCHFLAGS.darwin    = $(VBOX_DARWIN_DEF_SDK_10_5_PCHFLAGS)
TEMPLATE_VBOXR3OSX105_OBJCFLAGS.darwin   = $(VBOX_DARWIN_DEF_SDK_10_5_OBJCFLAGS)
TEMPLATE_VBOXR3OSX105_OBJCXXFLAGS.darwin = $(VBOX_DARWIN_DEF_SDK_10_5_OBJCFLAGS)
TEMPLATE_VBOXR3OSX105_LDFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_10_5_LDFLAGS) \
	-read_only_relocs suppress \
	-current_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	-compatibility_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD)

#
# Template for building R3 shared objects / DLLs with the 10.7 Mac OS X SDK.
# Identical to VBoxR3Dll, except for the DYLIB, the classic_linker and SDK bits.
#
TEMPLATE_VBoxR3DllOsX107  = VBox Ring 3 SO/DLLs for OS X 10.7
TEMPLATE_VBoxR3DllOsX107_EXTENDS = VBoxR3Dll
TEMPLATE_VBoxR3DllOsX107_TOOL               = LLVMGXX42MACHO
TEMPLATE_VBoxR3DllOsX107_DEFS.darwin        = $(VBOX_DARWIN_DEF_SDK_10_7_DEFS) PIC
TEMPLATE_VBoxR3DllOsX107_CFLAGS.darwin      = $(VBOX_DARWIN_DEF_SDK_10_7_CFLAGS) -fno-common
TEMPLATE_VBoxR3DllOsX107_CXXFLAGS.darwin    = $(VBOX_DARWIN_DEF_SDK_10_7_CXXFLAGS)
TEMPLATE_VBoxR3DllOsX107_PCHFLAGS.darwin    = $(VBOX_DARWIN_DEF_SDK_10_7_PCHFLAGS)
TEMPLATE_VBoxR3DllOsX107_OBJCFLAGS.darwin   = $(VBOX_DARWIN_DEF_SDK_10_7_OBJCFLAGS)
TEMPLATE_VBoxR3DllOsX107_OBJCXXFLAGS.darwin = $(VBOX_DARWIN_DEF_SDK_10_7_OBJCFLAGS)
TEMPLATE_VBoxR3DllOsX107_LDFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_10_7_LDFLAGS) \
	-current_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	-compatibility_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD)


#
# Ring-3 testcase, running automatically during the build.
# This is the VBOXR3EXE template only with a different install dir.
#
TEMPLATE_VBOXR3AUTOTST  = VBox Ring 3 Testcase Exe
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBOXR3AUTOTST_EXTENDS = VBoxR3Static
 TEMPLATE_VBOXR3AUTOTST_LIBS    = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBOXR3AUTOTST_SDKS    = $(filter-out VBOX_OPENSSL,$(TEMPLATE_VBoxR3Static_SDKS))
else
 TEMPLATE_VBOXR3AUTOTST_EXTENDS = VBOXR3EXE
endif
TEMPLATE_VBOXR3AUTOTST_INST    = $(INST_TESTCASE)
if "$(KBUILD_TARGET)" == "win" && defined(VBOX_SIGNING_MODE)
 TEMPLATE_VBOXR3AUTOTST_POST_CMDS = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBOXR3AUTOTST_LDFLAGS = $(filter-out -IntegrityCheck, $(TEMPLATE_VBoxR3Static_LDFLAGS))
endif

#
# Ring-3 testcase.
# This is the VBOXR3EXE template only with a different install dir.
#
TEMPLATE_VBOXR3TSTEXE  = VBox Ring 3 Testcase Exe
TEMPLATE_VBOXR3TSTEXE_EXTENDS = VBOXR3EXE
TEMPLATE_VBOXR3TSTEXE_INST    = $(INST_TESTCASE)
TEMPLATE_VBOXR3TSTEXE_LIBS    = $(LIB_RUNTIME) $(TEMPLATE_VBOXR3EXE_LIBS)
ifdef VBOX_WITH_RUNPATH
 TEMPLATE_VBOXR3TSTEXE_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' $(TEMPLATE_VBOXR3EXE_LDFLAGS)
else ifdef VBOX_WITH_RELATIVE_RUNPATH
 TEMPLATE_VBOXR3TSTEXE_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/..' $(TEMPLATE_VBOXR3EXE_LDFLAGS)
endif
if "$(KBUILD_TARGET)" == "win" && defined(VBOX_SIGNING_MODE)
 TEMPLATE_VBOXR3TSTEXE_POST_CMDS =
 TEMPLATE_VBOXR3TSTEXE_LDFLAGS = $(filter-out -IntegrityCheck, $(TEMPLATE_VBOXR3EXE_LDFLAGS))
endif
if defined(VBOX_WITH_MORE_NT4_COMPAT_BINARIES) && "$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)" == "win.x86"
 TEMPLATE_VBOXR3TSTEXE_POST_CMDS.win.x86 = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION) $(out))
 TEMPLATE_VBOXR3TSTEXE_LIBS.x86 = \
 	$(PATH_STAGE_LIB)/RuntimeR3VccTricks2$(VBOX_SUFF_LIB) \
 	$(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.x86)_LIB)/oldnames.lib
endif

#
# Ring-3 testcase (no -pedantic)
#
TEMPLATE_VBOXR3TSTNPEXE  = VBox Ring 3 Testcase Exe Non-pedantic
TEMPLATE_VBOXR3TSTNPEXE_EXTENDS = VBOXR3TSTEXE
ifneq ($(KBUILD_TARGET),win) # (only gcc)
 TEMPLATE_VBOXR3TSTNPEXE_TOOL             = $(VBOX_GCC_TOOL)
 TEMPLATE_VBOXR3TSTNPEXE_CFLAGS           = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_C)  ,$(TEMPLATE_VBOXR3TSTEXE_CFLAGS)) \
 	-Wno-sign-compare
 TEMPLATE_VBOXR3TSTNPEXE_CXXFLAGS         = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBOXR3TSTEXE_CXXFLAGS)) \
 	-Wno-sign-compare
 TEMPLATE_VBOXR3TSTNPEXE_PCHFLAGS         = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBOXR3TSTEXE_PCHFLAGS)) \
 	-Wno-sign-compare
endif


#
# Ring-3 testcase DLL.
#
TEMPLATE_VBoxR3TstDll = VBox Ring-3 Testcase Dll
TEMPLATE_VBoxR3TstDll_EXTENDS = VBOXR3TSTEXE
ifn1of ($(KBUILD_TARGET), darwin win os2)
 TEMPLATE_VBoxR3TstDll_DEFS     = $(TEMPLATE_VBOXR3TSTEXE_DEFS) PIC
 TEMPLATE_VBoxR3TstDll_CFLAGS   = $(TEMPLATE_VBOXR3TSTEXE_CFLAGS) -fPIC
 TEMPLATE_VBoxR3TstDll_CXXFLAGS = $(TEMPLATE_VBOXR3TSTEXE_CXXFLAGS) -fPIC
 TEMPLATE_VBoxR3TstDll_PCHFLAGS = $(TEMPLATE_VBOXR3TSTEXE_PCHFLAGS) -fPIC
 TEMPLATE_VBoxR3TstDll_LDFLAGS  = $(TEMPLATE_VBOXR3TSTEXE_LDFLAGS) -fPIC
endif


#
# Template for the CppUnit kind of testcases.
#
TEMPLATE_VBOXCPPUNITEXE  = VBox CppUnit Testcase Exe
TEMPLATE_VBOXCPPUNITEXE_EXTENDS = VBOXR3TSTEXE
## @todo make a CPPUNIT SDK and add cppunit tools packages for windows, mac, solaris and OS/2.
#TEMPLATE_VBOXCPPUNITEXE_SDKS = CPPUNIT -
TEMPLATE_VBOXCPPUNITEXE_LIBS = \
	$(TEMPLATE_VBOXR3TSTEXE_LIBS) \
	cppunit

#
# Template for building bad C/C++ style R3 executables (no -pedantic).
#
TEMPLATE_VBOXR3NPEXE                     = VBox Ring 3 Non-pedantic
TEMPLATE_VBOXR3NPEXE_EXTENDS             = VBOXR3EXE
ifneq ($(KBUILD_TARGET),win) # (only gcc)
 TEMPLATE_VBOXR3NPEXE_TOOL               = $(VBOX_GCC_TOOL)
 TEMPLATE_VBOXR3NPEXE_CFLAGS             = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_C)  ,$(TEMPLATE_VBOXR3EXE_CFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_C)
 TEMPLATE_VBOXR3NPEXE_CXXFLAGS           = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBOXR3EXE_CXXFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_CXX)
 TEMPLATE_VBOXR3NPEXE_PCHFLAGS           = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBOXR3EXE_PCHFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_CXX)
endif


#
# Template for building bad C/C++ style R3 shared libraries / Dlls (no -pedantic).
# (Same transformation as for VBOXR3NPEXE.)
#
# @deprecated Use VBoxR3DllNonPedantic!
#
TEMPLATE_VBOXR3NP = VBox Ring 3 Non-pedantic
TEMPLATE_VBOXR3NP_EXTENDS = VBOXR3
ifneq ($(KBUILD_TARGET),win) # (only gcc)
 TEMPLATE_VBOXR3NP_TOOL                  = $(VBOX_GCC_TOOL)
 TEMPLATE_VBOXR3NP_CFLAGS                = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_C)  ,$(TEMPLATE_VBOXR3_CFLAGS)) \
	$(VBOX_GCC_NON_PEDANTIC_C)
 TEMPLATE_VBOXR3NP_CXXFLAGS              = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBOXR3_CXXFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_CXX)
 TEMPLATE_VBOXR3NP_PCHFLAGS              = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBOXR3_PCHFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_CXX)
 TEMPLATE_VBOXR3NP_OBJCFLAGS             = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) -pedantic -Wstrict-prototypes,$(TEMPLATE_VBOXR3_OBJCFLAGS))
 TEMPLATE_VBOXR3NP_OBJCXXFLAGS           = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) -pedantic,$(TEMPLATE_VBOXR3_OBJCXXFLAGS))
endif


#
# Template for building bad C/C++ style R3 shared libraries / Dlls (no -pedantic).
# (Same transformation as for VBoxR3ExeNonPedantic.)
#
TEMPLATE_VBoxR3DllNonPedantic               = VBox ring-3 Non-pedantic, with warnings.
TEMPLATE_VBoxR3DllNonPedantic_EXTENDS       = VBOXR3
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxR3DllNonPedantic_CFLAGS       = $(TEMPLATE_VBOXR3_CFLAGS)   $(VBOX_VCC_NON_PEDANTIC)
 TEMPLATE_VBoxR3DllNonPedantic_CXXFLAGS     = $(TEMPLATE_VBOXR3_CXXFLAGS) $(VBOX_VCC_NON_PEDANTIC)
 TEMPLATE_VBoxR3DllNonPedantic_PCHFLAGS     = $(TEMPLATE_VBOXR3_PCHFLAGS) $(VBOX_VCC_NON_PEDANTIC)
else # gcc:
 TEMPLATE_VBoxR3DllNonPedantic_TOOL         = $(VBOX_GCC_TOOL)
 TEMPLATE_VBoxR3DllNonPedantic_CFLAGS       = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_C)  ,$(TEMPLATE_VBOXR3_CFLAGS)) \
	$(VBOX_GCC_NON_PEDANTIC_C)
 TEMPLATE_VBoxR3DllNonPedantic_CXXFLAGS     = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBOXR3_CXXFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_CXX)
 TEMPLATE_VBoxR3DllNonPedantic_PCHFLAGS     = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBOXR3_PCHFLAGS)) \
 	$(VBOX_GCC_NON_PEDANTIC_CXX)
endif

# x86 edition of the above template for use on AMD64 targets.
TEMPLATE_VBoxR3DllNonPedantic-x86           = 32-bit VBox ring-3 SO/DLLs, no warnings
TEMPLATE_VBoxR3DllNonPedantic-x86_EXTENDS   = VBoxR3DllNonPedantic
TEMPLATE_VBoxR3DllNonPedantic-x86_BLD_TRG_ARCH = x86
TEMPLATE_VBoxR3DllNonPedantic-x86_DEFS      = $(filter-out HC_ARCH_BITS%,$(TEMPLATE_VBoxR3DllNonPedantic_DEFS)) \
	HC_ARCH_BITS=32 ARCH_BITS=32



#
# Same as VBoxR3DllNonPedantic, only it optimizes debug builds.
#
TEMPLATE_VBoxR3DllNonPedanticFast            = VBox ring-3 Non-pedantic, with warnings, optimized debug.
TEMPLATE_VBoxR3DllNonPedanticFast_EXTENDS    = VBoxR3DllNonPedantic
ifeq ($(KBUILD_TYPE),debug)
 ifeq ($(KBUILD_TARGET),win)
  TEMPLATE_VBoxR3DllNonPedanticFast_CFLAGS         = $(filter-out -O0,   $(TEMPLATE_VBoxR3DllNonPedantic_CFLAGS)) -O2 -Oy-
  TEMPLATE_VBoxR3DllNonPedanticFast_CFLAGS.debug   = $(filter-out -RTC%, $(TEMPLATE_VBoxR3DllNonPedantic_CFLAGS.debug))
  TEMPLATE_VBoxR3DllNonPedanticFast_CXXFLAGS       = $(filter-out -O0,   $(TEMPLATE_VBoxR3DllNonPedantic_CXXFLAGS)) -O2 -Oy-
  TEMPLATE_VBoxR3DllNonPedanticFast_CXXFLAGS.debug = $(filter-out -RTC%, $(TEMPLATE_VBoxR3DllNonPedantic_CXXFLAGS.debug))
  TEMPLATE_VBoxR3DllNonPedanticFast_PCHFLAGS       = $(filter-out -O0,   $(TEMPLATE_VBoxR3DllNonPedantic_PCHFLAGS)) -O2 -Oy-
  TEMPLATE_VBoxR3DllNonPedanticFast_PCHFLAGS.debug = $(filter-out -RTC%, $(TEMPLATE_VBoxR3DllNonPedantic_PCHFLAGS.debug))
 else
  TEMPLATE_VBoxR3DllNonPedanticFast_CFLAGS         = $(TEMPLATE_VBoxR3DllNonPedantic_CFLAGS) -O2 -fno-omit-frame-pointer
  TEMPLATE_VBoxR3DllNonPedanticFast_CXXFLAGS       = $(TEMPLATE_VBoxR3DllNonPedantic_CXXFLAGS) -O2 -fno-omit-frame-pointer
  TEMPLATE_VBoxR3DllNonPedanticFast_PCHFLAGS       = $(TEMPLATE_VBoxR3DllNonPedantic_PCHFLAGS) -O2 -fno-omit-frame-pointer
 endif
endif


#
# Template for building libraries that are linked into VBoxRT.dll
# and it's variations, pedantic variation.
#
TEMPLATE_VBoxR3RuntimeDll = For libraries that are linked into VBoxRT.
TEMPLATE_VBoxR3RuntimeDll_EXTENDS = VBoxR3Dll
if defined(VBOX_WITH_MORE_NT4_COMPAT_BINARIES) && "$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)" == "win.x86"
 TEMPLATE_VBoxR3RuntimeDll_CFLAGS   = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBoxR3Dll_CFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBoxR3RuntimeDll_CXXFLAGS = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBoxR3Dll_CXXFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBoxR3RuntimeDll_PCHFLAGS = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBoxR3Dll_PCHFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBoxR3RuntimeDll_LIBS.x86 = $(filter-out $(PATH_TOOL_$(TEMPLATE_VBOXR3EXE_TOOL.win.x86)_LIB)/%, $(TEMPLATE_VBoxR3Dll_LIBS.x86)) \
 	$(PATH_TOOL_$(TEMPLATE_VBoxR3RuntimeDll_TOOL.win.x86)_LIB)/oldnames.lib \
 	$(PATH_TOOL_$(TEMPLATE_VBoxR3RuntimeDll_TOOL.win.x86)_LIB)/libcmt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBoxR3RuntimeDll_TOOL.win.x86)_LIB)/libcpmt$(VBOX_VCC_CRT_TYPE).lib
endif

#
# Template for building libraries that are linked into VBoxRT.dll
# and it's variations, non-pedantic variation.
#
TEMPLATE_VBoxR3RuntimeDllNonPedantic = For libraries that are linked into VBoxRT, but must be excluded from -pedantic warnings.
TEMPLATE_VBoxR3RuntimeDllNonPedantic_EXTENDS = VBoxR3DllNonPedantic
if defined(VBOX_WITH_MORE_NT4_COMPAT_BINARIES) && $(KBUILD_TARGET_ARCH) == "x86"
 TEMPLATE_VBoxR3RuntimeDllNonPedantic_CFLAGS   = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBoxR3DllNonPedantic_CFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBoxR3RuntimeDllNonPedantic_CXXFLAGS = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBoxR3DllNonPedantic_CXXFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBoxR3RuntimeDllNonPedantic_PCHFLAGS = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBoxR3DllNonPedantic_PCHFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
endif

#
# Same as VBoxR3RuntimeDllNonPedantic, only it optimized debug builds too.
#
TEMPLATE_VBoxR3RuntimeDllNonPedanticFast = For libraries that are linked into VBoxRT, but must be excluded from -pedantic warnings, optmized debug.
TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_EXTENDS = VBoxR3RuntimeDllNonPedantic
ifeq ($(KBUILD_TYPE),debug)
 ifeq ($(KBUILD_TARGET),win)
  TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_CFLAGS         = $(filter-out -O0,   $(TEMPLATE_VBoxR3RuntimeDllNonPedantic_CFLAGS)) -O2 -Oy-
  TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_CFLAGS.debug   = $(filter-out -RTC%, $(TEMPLATE_VBoxR3RuntimeDllNonPedantic_CFLAGS.debug))
  TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_CXXFLAGS       = $(filter-out -O0,   $(TEMPLATE_VBoxR3RuntimeDllNonPedantic_CXXFLAGS)) -O2 -Oy-
  TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_CXXFLAGS.debug = $(filter-out -RTC%, $(TEMPLATE_VBoxR3RuntimeDllNonPedantic_CXXFLAGS.debug))
  TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_PCHFLAGS       = $(filter-out -O0,   $(TEMPLATE_VBoxR3RuntimeDllNonPedantic_PCHFLAGS)) -O2 -Oy-
  TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_PCHFLAGS.debug = $(filter-out -RTC%, $(TEMPLATE_VBoxR3RuntimeDllNonPedantic_PCHFLAGS.debug))
 else
  TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_CFLAGS         = $(TEMPLATE_VBoxR3RuntimeDllNonPedantic_CFLAGS) -O2 -fno-omit-frame-pointer
  TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_CXXFLAGS       = $(TEMPLATE_VBoxR3RuntimeDllNonPedantic_CXXFLAGS) -O2 -fno-omit-frame-pointer
  TEMPLATE_VBoxR3RuntimeDllNonPedanticFast_PCHFLAGS       = $(TEMPLATE_VBoxR3RuntimeDllNonPedantic_PCHFLAGS) -O2 -fno-omit-frame-pointer
 endif
endif


#
# Template for building libraries, shared libraries / modules
# which only depends on IPRT for crt.
#
TEMPLATE_VBoxNoCrtGccLib = VBox no-crt GCC libraries and modules, yasm/nasm.
TEMPLATE_VBoxNoCrtGccLib_DEFS              = IN_RING3 IPRT_NO_CRT $(ARCH_BITS_DEFS)
TEMPLATE_VBoxNoCrtGccLib_ASDEFS            = ASM_CALL64_GCC
TEMPLATE_VBoxNoCrtGccLib_CFLAGS            = -nostdinc -fno-strict-aliasing -fno-math-errno $(VBOX_GCC_WARN) -Werror-implicit-function-declaration
TEMPLATE_VBoxNoCrtGccLib_CFLAGS.x86        = -m32
TEMPLATE_VBoxNoCrtGccLib_CFLAGS.amd64      = -m64 -mcmodel=medium -fno-common
TEMPLATE_VBoxNoCrtGccLib_CFLAGS.sparc32    = -m32
TEMPLATE_VBoxNoCrtGccLib_CFLAGS.sparc64    = -m64
TEMPLATE_VBoxNoCrtGccLib_CFLAGS.release    = -O2 -fno-strict-aliasing
TEMPLATE_VBoxNoCrtGccLib_CFLAGS.profile    = $(TEMPLATE_VBoxNoCrtGccLib_CFLAGS.release)
TEMPLATE_VBoxNoCrtGccLib_CFLAGS.kprofile   = $(TEMPLATE_VBoxNoCrtGccLib_CFLAGS.release)
TEMPLATE_VBoxNoCrtGccLib_CFLAGS.darwin     = -static
TEMPLATE_VBoxNoCrtGccLib_CXXFLAGS          = $(filter-out -Werror-implicit-function-declaration,$(TEMPLATE_VBoxNoCrtGccLib_CFLAGS))
TEMPLATE_VBoxNoCrtGccLib_CXXFLAGS.$(KBUILD_TARGET) = $(TEMPLATE_VBoxNoCrtGccLib_CFLAGS.$(KBUILD_TARGET))
TEMPLATE_VBoxNoCrtGccLib_CXXFLAGS.$(KBUILD_TARGET_ARCH) = $(TEMPLATE_VBoxNoCrtGccLib_CFLAGS.$(KBUILD_TARGET_ARCH))
TEMPLATE_VBoxNoCrtGccLib_PCHFLAGS          = $(TEMPLATE_VBoxNoCrtGccLib_CXXFLAGS)
TEMPLATE_VBoxNoCrtGccLib_PCHFLAGS.$(KBUILD_TARGET) = $(TEMPLATE_VBoxNoCrtGccLib_CXXFLAGS.$(KBUILD_TARGET))
TEMPLATE_VBoxNoCrtGccLib_PCHFLAGS.$(KBUILD_TARGET_ARCH) =  $(TEMPLATE_VBoxNoCrtGccLib_CXXFLAGS.$(KBUILD_TARGET_ARCH))
TEMPLATE_VBoxNoCrtGccLib_INCS              = $(PATH_ROOT)/include/iprt/nocrt

ifeq (disabled-by-mingw-w64 $(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),win.amd64)
 # cross compile to 64-bit ELF (linux).
 TEMPLATE_VBoxNoCrtGccLib_TOOL             = XGCCAMD64LINUX
 TEMPLATE_VBoxNoCrtGccLib_ASTOOL           = YASM
 TEMPLATE_VBoxNoCrtGccLib_ASFLAGS          = -f elf64 -DASM_FORMAT_ELF -D__YASM__ -g dwarf2 -w+orphan-labels $(VBOX_YASM_Wno-segreg-in-64bit)
 TEMPLATE_VBoxNoCrtGccLib_LIBS             = $(KBUILD_DEVTOOLS)/win.x86/x86_64-unknown-linux-gnu/20060701-r2/lib/gcc/x86_64-unknown-linux-gnu/3.4.6/libgcc.a
 TEMPLATE_VBoxNoCrtGccLib_LDFLAGS          = -nostdlib

else if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), win.x86 win.amd64)
 # Use the default GCC (MinGW) with the Microsoft linker.
 # (Drop all '-g' options as we're unable to strip the debug info.)
 TEMPLATE_VBoxNoCrtGccLib_TOOL             = $(VBOX_GCC_TOOL)
 if $(VBOX_GCC_VERSION_CC) < 30400
  TEMPLATE_VBoxNoCrtGccLib_DEFS           += RT_WITHOUT_PRAGMA_ONCE
 endif
 TEMPLATE_VBoxNoCrtGccLib_ASTOOL           = $(VBOX_ASTOOL)
 TEMPLATE_VBoxNoCrtGccLib_ASFLAGS          = $(VBOX_ASFLAGS)
 TEMPLATE_VBoxNoCrtGccLib_LDTOOL           = $(VBOX_VCC_TOOL)
 TEMPLATE_VBoxNoCrtGccLib_LDFLAGS          = -Incremental:NO -MapInfo:Exports -NoD -Ignore:4197
 TEMPLATE_VBoxNoCrtGccLib_LIBS             = $(VBOX_GCC_LIBGCC)
 TEMPLATE_VBoxNoCrtGccLib_CFLAGS          := $(filter-out -g,$(TEMPLATE_VBoxNoCrtGccLib_CFLAGS)) -s
 TEMPLATE_VBoxNoCrtGccLib_CXXFLAGS        := $(filter-out -g,$(TEMPLATE_VBoxNoCrtGccLib_CXXFLAGS)) -s
 TEMPLATE_VBoxNoCrtGccLib_PCHFLAGS        := $(filter-out -g,$(TEMPLATE_VBoxNoCrtGccLib_PCHFLAGS)) -s

else
 # Use the default GCC.
 # The use of --exclude-libs ALL is to avoid confusing the linux ld.so.
 TEMPLATE_VBoxNoCrtGccLib_TOOL             = $(VBOX_GCC_TOOL)
 if $(VBOX_GCC_VERSION_CC) < 30400
  TEMPLATE_VBoxNoCrtGccLib_DEFS           += RT_WITHOUT_PRAGMA_ONCE
 endif
 TEMPLATE_VBoxNoCrtGccLib_ASTOOL           = $(VBOX_ASTOOL)
 TEMPLATE_VBoxNoCrtGccLib_ASFLAGS          = $(VBOX_ASFLAGS)
 TEMPLATE_VBoxNoCrtGccLib_CFLAGS          += $(VBOX_GCC_fno-stack-protector)
 TEMPLATE_VBoxNoCrtGccLib_CXXFLAGS        += $(VBOX_GCC_fno-stack-protector)
 TEMPLATE_VBoxNoCrtGccLib_PCHFLAGS        += $(VBOX_GCC_fno-stack-protector)
 ifeq ($(KBUILD_TARGET_ARCH),amd64)
  # in 64-bit mode we'll build a sys-module (VBoxREM2).
  if1of ($(KBUILD_TARGET), darwin solaris)
   TEMPLATE_VBoxNoCrtGccLib_LDFLAGS.solaris= -64 -r
  else
   TEMPLATE_VBoxNoCrtGccLib_LDFLAGS        = -nostdlib
  endif
 else # x86:
  TEMPLATE_VBoxNoCrtGccLib_LDFLAGS         = -nostdlib
  ifn1of ($(KBUILD_TARGET), os2 darwin solaris)
   TEMPLATE_VBoxNoCrtGccLib_LDFLAGS       += $(VBOX_GCC_NO_UNDEFINED)
  endif
 endif # x86
 TEMPLATE_VBoxNoCrtGccLib_LDFLAGS.darwin   = $(VBOX_DARWIN_DEF_SDK_LDFLAGS)
 TEMPLATE_VBoxNoCrtGccLib_LIBS             = # FIXME - has unwind mess.
endif


#
# Same as VBoxNoCrtGccLib only it uses GAS as the assembler instead of yasm/nasm.
#
TEMPLATE_VBOXNOCRTGAS = VBox no-crt GCC libraries and modules, gas.
TEMPLATE_VBOXNOCRTGAS_EXTENDS = VBoxNoCrtGccLib
TEMPLATE_VBOXNOCRTGAS_ASTOOL = $(TEMPLATE_VBoxNoCrtGccLib_TOOL)
ifeq ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),win.x86)
 TEMPLATE_VBOXNOCRTGAS_ASFLAGS = -s
else
 TEMPLATE_VBOXNOCRTGAS_ASFLAGS = -g
endif
TEMPLATE_VBOXNOCRTGAS_ASFLAGS.x86 = -m32
TEMPLATE_VBOXNOCRTGAS_ASFLAGS.amd64 = -m64


#
# Template for building executables that are part of the VBox Main component
# (COM/XPCOM interface to VirtualBox).
#
TEMPLATE_VBOXMAINEXE         = VBox Main Executable
TEMPLATE_VBOXMAINEXE_ASTOOL              = $(VBOX_ASTOOL)
TEMPLATE_VBOXMAINEXE_ASFLAGS             = $(VBOX_ASFLAGS)
TEMPLATE_VBOXMAINEXE_DEFS                = IN_RING3 UNICODE NDEBUG=1
TEMPLATE_VBOXMAINEXE_DEFS.win            = _UNICODE
TEMPLATE_VBOXMAINEXE_RCDEFS              = $(TEMPLATE_VBOXR3EXE_RCDEFS)
TEMPLATE_VBOXMAINEXE_LIBS.kprofile       = $(LIB_KPROFILE)
TEMPLATE_VBOXMAINEXE_USES                = dtrace
if defined(VBOX_WITH_DTRACE_R3_MAIN) && defined(VBOX_WITH_NATIVE_DTRACE)
 TEMPLATE_VBOXMAINEXE_DTRACETOOL         = DTraceAndVBoxTpG
 TEMPLATE_VBOXMAINEXE_DTRACE_OBJ_FLAGS   = -C
 TEMPLATE_VBOXMAINEXE_DTRACE_HDR_FLAGS   = -C
 TEMPLATE_VBOXMAINEXE_DEFS              += VBOX_WITH_DTRACE VBOX_WITH_DTRACE_R3 VBOX_WITH_DTRACE_R3_MAIN VBOX_WITH_NATIVE_DTRACE
else
  TEMPLATE_VBOXMAINEXE_DTRACE_HDR_FLAGS  = --ring-3-context
  TEMPLATE_VBOXMAINEXE_DTRACE_OBJ_FLAGS  = --ring-3-context --pic --probe-fn-imported --probe-fn-name "SUPTracerFireProbe"
 if defined(VBOX_WITH_DTRACE_R3_MAIN)
  TEMPLATE_VBOXMAINEXE_DTRACETOOL        = VBoxTpG
  TEMPLATE_VBOXMAINEXE_DEFS             += VBOX_WITH_DTRACE VBOX_WITH_DTRACE_R3 VBOX_WITH_DTRACE_R3_MAIN
 else
  TEMPLATE_VBOXMAINEXE_DTRACETOOL        = VBoxTpG-Disabled
 endif
endif

ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBOXMAINEXE_SDKS               = ReorderCompilerIncs $(VBOX_WINPSDK) $(VBOX_WINDDK)
 #TEMPLATE_VBOXMAINEXE_TOOL               = $(VBOX_VCC_TOOL)
 TEMPLATE_VBOXMAINEXE_TOOL.win.x86       = $(VBOX_VCC_TOOL_STEM)X86
 TEMPLATE_VBOXMAINEXE_TOOL.win.amd64     = $(VBOX_VCC_TOOL_STEM)AMD64
 TEMPLATE_VBOXMAINEXE_CXXFLAGS           = -Zi -Zl -GR -EHsc -GF -MD$(VBOX_VCC_CRT_TYPE) -Zc:wchar_t- $(VBOX_VCC_OPT) $(VBOX_VCC_FP)
 #    -wd4625: 'DisplaySourceBitmap' : copy constructor could not be generated because a base class copy constructor is inaccessible
 #    -wd4626: 'DisplaySourceBitmap' : assignment operator could not be generated because a base class assignment operator is inaccessible
 #             The two above can be cured by adding private: DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(xxxx); but too much work.
 #    -wd4355: 'this' : used in base member initializer list (e.g. VirtualBoxBase.cpp)
 TEMPLATE_VBOXMAINEXE_CXXFLAGS          += $(VBOX_VCC_WARN_ALL) -wd4625 -wd4626 -wd4355 $(VBOX_VCC_WERR)
 TEMPLATE_VBOXMAINEXE_CXXFLAGS.debug     = -RTCsu
 TEMPLATE_VBOXMAINEXE_CXXFLAGS.dbgopt    = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBOXMAINEXE_CXXFLAGS.kprofile  = -Gh -GH
 TEMPLATE_VBOXMAINEXE_CFLAGS             = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS)
 TEMPLATE_VBOXMAINEXE_CFLAGS.debug       = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.debug)
 TEMPLATE_VBOXMAINEXE_CFLAGS.dbgopt      = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.dbgopt)
 TEMPLATE_VBOXMAINEXE_CFLAGS.kprofile    = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.kprofile)
 TEMPLATE_VBOXMAINEXE_PCHFLAGS           = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS)
 TEMPLATE_VBOXMAINEXE_PCHFLAGS.debug     = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.debug)
 TEMPLATE_VBOXMAINEXE_PCHFLAGS.dbgopt    = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.dbgopt)
 TEMPLATE_VBOXMAINEXE_PCHFLAGS.kprofile  = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.kprofile)
 TEMPLATE_VBOXMAINEXE_LDFLAGS            = -Ignore:4197 \
	/NOD /INCREMENTAL:NO /MAPINFO:EXPORTS /LargeAddressAware /DynamicBase /NxCompat /Release /Debug /Opt:Ref /Opt:Icf \
	/Version:$(VBOX_VERSION_MAJOR)0$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	/STUB:$(PATH_ROOT)/src/VBox/HostDrivers/Support/win/winstub.com \
	/DISALLOWLIB:libc.lib \
	/DISALLOWLIB:libcd.lib \
	/DISALLOWLIB:libcmt.lib \
	/DISALLOWLIB:libcmtd.lib \
	/DISALLOWLIB:msvcrt$(VBOX_VCC_CRT_TYPE_N).lib \
	/DISALLOWLIB:msvcprt$(VBOX_VCC_CRT_TYPE_N).lib
 if defined(VBOX_SIGNING_MODE) && defined(VBOX_WITH_HARDENING)
  TEMPLATE_VBOXMAINEXE_LDFLAGS          += -IntegrityCheck
 endif
 ifdef VBOX_WITH_DTRACE_R3_MAIN
  TEMPLATE_VBOXMAINEXE_LDFLAGS          += -Merge:VTGPrLc.Data=VTGPrLc.Begin -Merge:VTGPrLc.End=VTGPrLc.Begin -Merge:VTGPrLc.Begin=VTGObj
 endif
 TEMPLATE_VBOXMAINEXE_LIBS               = \
	$(LIB_RUNTIME)
 TEMPLATE_VBOXMAINEXE_LIBS.x86           = \
	$(PATH_TOOL_$(TEMPLATE_VBOXMAINEXE_TOOL.win.x86)_LIB)/msvcrt$(VBOX_VCC_CRT_TYPE).lib \
	$(PATH_TOOL_$(TEMPLATE_VBOXMAINEXE_TOOL.win.x86)_LIB)/msvcprt$(VBOX_VCC_CRT_TYPE).lib \
	$(PATH_TOOL_$(TEMPLATE_VBOXMAINEXE_TOOL.win.x86)_LIB)/oldnames.lib
 TEMPLATE_VBOXMAINEXE_LIBS.amd64         = \
	$(PATH_TOOL_$(TEMPLATE_VBOXMAINEXE_TOOL.win.amd64)_LIB)/msvcrt$(VBOX_VCC_CRT_TYPE).lib \
	$(PATH_TOOL_$(TEMPLATE_VBOXMAINEXE_TOOL.win.amd64)_LIB)/msvcprt$(VBOX_VCC_CRT_TYPE).lib \
	$(PATH_TOOL_$(TEMPLATE_VBOXMAINEXE_TOOL.win.amd64)_LIB)/oldnames.lib
 TEMPLATE_VBOXMAINEXE_POST_CMDS          = $(VBOX_SIGN_IMAGE_CMDS)

else # the GCC guys:

TEMPLATE_VBOXMAINEXE_TOOL                = $(VBOX_GCC_TOOL)
 if $(VBOX_GCC_VERSION_CC) < 30400
  TEMPLATE_VBOXMAINEXE_DEFS             += RT_WITHOUT_PRAGMA_ONCE
 endif
TEMPLATE_VBOXMAINEXE_CXXFLAGS            = -g $(VBOX_GCC_pipe) \
	$(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_Wno-multistatement-macros) $(VBOX_GCC_Wno-class-memaccess) -Wshadow \
	-fshort-wchar -fpermissive -fexceptions -frtti $(VBOX_GCC_OPT) $(VBOX_GCC_FP) -fno-strict-aliasing \
	$(VBOX_GCC_fvisibility-inlines-hidden) $(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_std) $(VBOX_GCC_IPRT_FMT_CHECK)
 if !defined("VBOX_GCC_Wno-delete-non-virtual-dtor") && defined("VBOX_GCC_Wno-non-virtual-dtor")
  TEMPLATE_VBOXMAINEXE_CXXFLAGS         += $(VBOX_GCC_Wno-non-virtual-dtor)
 endif
 ifdef VBOX_WITH_NO_GCC_WARNING_POLICY
  TEMPLATE_VBOXMAINEXE_CXXFLAGS         += $(VBOX_GCC_WERR)
 endif
 ifdef VBOX_WITH_DTRACE_R3_MAIN
  TEMPLATE_VBOXMAINEXE_CXXFLAGS := $(filter-out -pedantic,$(TEMPLATE_VBOXMAINEXE_CXXFLAGS)) -fdollars-in-identifiers # annoying gcc option precedence.
 endif
TEMPLATE_VBOXMAINEXE_CXXFLAGS.x86        = -m32
TEMPLATE_VBOXMAINEXE_CXXFLAGS.amd64      = -m64
TEMPLATE_VBOXMAINEXE_CXXFLAGS.kprofile   = -finstrument-functions
TEMPLATE_VBOXMAINEXE_CXXFLAGS.debug      = $(VBOX_GCC_SANITIZER_FLAGS)
TEMPLATE_VBOXMAINEXE_CFLAGS              = -g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_C) $(VBOX_GCC_Wno-variadic-macros) \
	$(VBOX_GCC_OPT) $(VBOX_GCC_FP) -fno-strict-aliasing $(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_IPRT_FMT_CHECK)
 ifdef VBOX_WITH_NO_GCC_WARNING_POLICY
  TEMPLATE_VBOXMAINEXE_CFLAGS           += $(VBOX_GCC_WERR)
 endif
TEMPLATE_VBOXMAINEXE_CFLAGS.x86          = -m32
TEMPLATE_VBOXMAINEXE_CFLAGS.amd64        = -m64
TEMPLATE_VBOXMAINEXE_CFLAGS.kprofile     = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.kprofile)
TEMPLATE_VBOXMAINEXE_CFLAGS.debug        = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.debug)
TEMPLATE_VBOXMAINEXE_OBJCFLAGS           = $(TEMPLATE_VBOXMAINEXE_CFLAGS)
TEMPLATE_VBOXMAINEXE_OBJCFLAGS.x86       = $(TEMPLATE_VBOXMAINEXE_CFLAGS.x86)
TEMPLATE_VBOXMAINEXE_OBJCFLAGS.amd64     = $(TEMPLATE_VBOXMAINEXE_CFLAGS.amd64)
TEMPLATE_VBOXMAINEXE_OBJCFLAGS.debug     = $(TEMPLATE_VBOXMAINEXE_CFLAGS.debug)
TEMPLATE_VBOXMAINEXE_OBJCFLAGS.kprofile  = $(TEMPLATE_VBOXMAINEXE_CFLAGS.kprofile)
TEMPLATE_VBOXMAINEXE_OBJCXXFLAGS         = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS)
TEMPLATE_VBOXMAINEXE_OBJCXXFLAGS.x86     = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.x86)
TEMPLATE_VBOXMAINEXE_OBJCXXFLAGS.amd64   = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.amd64)
TEMPLATE_VBOXMAINEXE_OBJCXXFLAGS.debug   = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.debug)
TEMPLATE_VBOXMAINEXE_OBJCXXFLAGS.kprofile= $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.kprofile)
TEMPLATE_VBOXMAINEXE_PCHFLAGS            = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS)
TEMPLATE_VBOXMAINEXE_PCHFLAGS.x86        = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.x86)
TEMPLATE_VBOXMAINEXE_PCHFLAGS.amd64      = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.amd64)
TEMPLATE_VBOXMAINEXE_PCHFLAGS.debug      = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.debug)
TEMPLATE_VBOXMAINEXE_PCHFLAGS.kprofile   = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.kprofile)
TEMPLATE_VBOXMAINEXE_LDFLAGS.x86         = -m32
TEMPLATE_VBOXMAINEXE_LDFLAGS.amd64       = -m64
TEMPLATE_VBOXMAINEXE_LDFLAGS.debug       = $(VBOX_GCC_SANITIZER_FLAGS) $(VBOX_GCC_SANITIZER_LDFLAGS)
 ifeq ($(KBUILD_TARGET),linux)
TEMPLATE_VBOXMAINEXE_LIBS                = pthread m rt $(LIB_RUNTIME) dl
TEMPLATE_VBOXMAINEXE_LDFLAGS.linux       = -Wl,-z,noexecstack,-z,relro $(VBOX_LD_as_needed)
 else ifeq ($(KBUILD_TARGET),os2)
TEMPLATE_VBOXMAINEXE_TOOL                = GXX3OMF
TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME)
 else ifeq ($(KBUILD_TARGET),darwin)
TEMPLATE_VBOXMAINEXE_TOOL                = $(VBOX_GCC_TOOL)
TEMPLATE_VBOXMAINEXE_DEFS               += $(VBOX_DARWIN_DEF_SDK_DEFS)
TEMPLATE_VBOXMAINEXE_CFLAGS             += $(VBOX_DARWIN_DEF_SDK_CFLAGS)
TEMPLATE_VBOXMAINEXE_CXXFLAGS           += $(VBOX_DARWIN_DEF_SDK_CXXFLAGS)
TEMPLATE_VBOXMAINEXE_OBJCFLAGS          += $(VBOX_DARWIN_DEF_SDK_OBJCFLAGS)
TEMPLATE_VBOXMAINEXE_OBJCXXFLAGS        += $(VBOX_DARWIN_DEF_SDK_OBJCXXFLAGS)
TEMPLATE_VBOXMAINEXE_LDFLAGS.darwin     += -bind_at_load
TEMPLATE_VBOXMAINEXE_LDFLAGS            += $(VBOX_DARWIN_DEF_SDK_LDFLAGS) -framework Carbon
TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME)
 else ifeq ($(KBUILD_TARGET),haiku)
TEMPLATE_VBOXMAINEXE_TOOL                = GXX3
TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME) network stdc++ supc++
 else if1of ($(KBUILD_TARGET), freebsd openbsd)
TEMPLATE_VBOXMAINEXE_TOOL                = GXX3
TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME)
TEMPLATE_VBOXMAINEXE_INCS               += \
	/usr/include \
	/usr/X11R6/include \
	/usr/local/include
TEMPLATE_VBOXMAINEXE_LIBPATH            += \
	/usr/lib \
	/usr/X11R6/lib \
	/usr/local/lib
 else ifeq ($(KBUILD_TARGET),netbsd)
TEMPLATE_VBOXMAINEXE_TOOL                = GXX3
TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME)
TEMPLATE_VBOXMAINEXE_INCS               += \
	/usr/include \
	/usr/X11R7/include
TEMPLATE_VBOXMAINEXE_LIBPATH            += \
	/usr/lib \
	/usr/X11R7/lib
else ifeq ($(KBUILD_TARGET),solaris)
TEMPLATE_VBOXMAINEXE_TOOL                = GXX3PLAIN
TEMPLATE_VBOXMAINEXE_DEFS               += _REENTRANT
TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME) rt thread
 else
$(warning Warning: VBOX Build: Target $(KBUILD_TARGET) is not officially supported!)
TEMPLATE_VBOXMAINEXE_LIBS                =
 endif
TEMPLATE_VBOXMAINEXE_LDFLAGS.solaris     = -Wl,-z,ignore # Same as VBOX_LD_as_needed.
 ifdef VBOX_WITH_RUNPATH
TEMPLATE_VBOXMAINEXE_LDFLAGS            += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)'
 else ifdef VBOX_WITH_RELATIVE_RUNPATH
TEMPLATE_VBOXMAINEXE_LDFLAGS            += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)'
 endif
 ifdef VBOX_WITH_ORIGIN
TEMPLATE_VBOXMAINEXE_LDFLAGS.linux      += $(VBOX_GCC_ORIGIN_OPT)
 endif

endif # !win

# Add COM/XPCOM stuff
TEMPLATE_VBOXMAINEXE_LIBS               += \
	$(PATH_STAGE_LIB)/VBoxCOM$(VBOX_SUFF_LIB)
ifdef VBOX_WITH_XPCOM
 ## @todo may be worth creating the VBOX_XPCOM SDK def
 TEMPLATE_VBOXMAINEXE_DEFS              += VBOX_WITH_XPCOM
 ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
  TEMPLATE_VBOXMAINEXE_DEFS             += VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
 endif
 TEMPLATE_VBOXMAINEXE_INCS              += \
	$(VBOX_XPCOM_INCS)
 TEMPLATE_VBOXMAINEXE_LIBS              += \
	$(LIB_XPCOM)
 TEMPLATE_VBOXMAINEXE_INTERMEDIATES     += \
	$(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h

else  # COM
 TEMPLATE_VBOXMAINEXE_INCS              += \
	$(VBOX_PATH_SDK)/bindings/mscom/include
 TEMPLATE_VBOXMAINEXE_INTERMEDIATES     += \
	$(VBOX_PATH_SDK)/bindings/mscom/include/VirtualBox.h
endif # COM

#
# Template for building the Main DLL modules (such as in-process COM/XPCOM
# components for Main).
#
# This differs from VBOXMAINEXE only in PIC handling and similar DLL stuff.
#
TEMPLATE_VBOXMAINDLL  = VBox Main Component (shared library)
TEMPLATE_VBOXMAINDLL_EXTENDS = VBOXMAINEXE
ifn1of ($(KBUILD_TARGET), darwin haiku os2 win)
 TEMPLATE_VBOXMAINDLL_DEFS     = PIC $(TEMPLATE_VBOXMAINEXE_DEFS)
 TEMPLATE_VBOXMAINDLL_CFLAGS   = -fPIC $(TEMPLATE_VBOXMAINEXE_CFLAGS)
 TEMPLATE_VBOXMAINDLL_CXXFLAGS = -fPIC $(TEMPLATE_VBOXMAINEXE_CXXFLAGS)
 TEMPLATE_VBOXMAINDLL_PCHFLAGS = -fPIC $(TEMPLATE_VBOXMAINEXE_PCHFLAGS)
 TEMPLATE_VBOXMAINDLL_LDFLAGS  = -fPIC $(TEMPLATE_VBOXMAINEXE_LDFLAGS)
endif
TEMPLATE_VBOXMAINDLL_LDFLAGS.darwin = $(filter-out -bind_at_load,$(TEMPLATE_VBOXMAINEXE_LDFLAGS.darwin)) \
	-current_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	-compatibility_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD)

#
# Template identical to VBOXMAINDLL except for where the stuff is
# installed when using XPCOM (components/).
#
# Note! In the hardened build this gets a bit ugly since $ORIGIN/..
#       doesn't work. So, we keep the $ORIGIN from VBOXMAINEXE and let
#       the installers do the necessary .so symlinking.
#
# (No difference when building against COM on Windows.)
#
TEMPLATE_VBOXMAINCOMP            = VBox Main COM/XPCOM Component (shared library)
TEMPLATE_VBOXMAINCOMP_EXTENDS    = VBOXMAINEXE
ifn1of ($(KBUILD_TARGET), win)
 TEMPLATE_VBOXMAINCOMP_INST      = $(INST_BIN)components/
endif
ifneq ($(KBUILD_TARGET),win)
 ifeq ($(filter-out solaris.x86 %.amd64 %.sparc32 %.sparc64,$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)),) ## TODO: cleanup!
  TEMPLATE_VBOXMAINCOMP_DEFS     = PIC $(TEMPLATE_VBOXMAINEXE_DEFS)
  TEMPLATE_VBOXMAINCOMP_CFLAGS   = -fPIC $(TEMPLATE_VBOXMAINEXE_CFLAGS)
  TEMPLATE_VBOXMAINCOMP_CXXFLAGS = -fPIC $(TEMPLATE_VBOXMAINEXE_CXXFLAGS)
  TEMPLATE_VBOXMAINCOMP_PCHFLAGS = -fPIC $(TEMPLATE_VBOXMAINEXE_PCHFLAGS)
  if defined(VBOX_WITH_RELATIVE_RUNPATH) && !defined(VBOX_WITH_HARDENING)
   TEMPLATE_VBOXMAINCOMP_LDFLAGS = -fPIC $(filter-out '$(VBOX_GCC_RPATH_OPT)%',$(TEMPLATE_VBOXMAINEXE_LDFLAGS)) '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/..'
  else
   TEMPLATE_VBOXMAINCOMP_LDFLAGS = -fPIC $(TEMPLATE_VBOXMAINEXE_LDFLAGS)
  endif
 else ifndef VBOX_WITH_HARDENING
  ifdef VBOX_WITH_RELATIVE_RUNPATH
   TEMPLATE_VBOXMAINCOMP_LDFLAGS = $(filter-out '$(VBOX_GCC_RPATH_OPT)%',$(TEMPLATE_VBOXMAINEXE_LDFLAGS)) '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/..'
  endif
 endif
endif
TEMPLATE_VBOXMAINCOMP_LDFLAGS.darwin = $(filter-out -bind_at_load,$(TEMPLATE_VBOXMAINEXE_LDFLAGS.darwin)) \
	-current_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	-compatibility_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD)

TEMPLATE_VBoxMainComp-x86  = 32-bit VBox Main Component (shared library)
TEMPLATE_VBoxMainComp-x86_EXTENDS = VBOXMAINCOMP
TEMPLATE_VBoxMainComp-x86_BLD_TRG_ARCH = x86
TEMPLATE_VBoxMainComp-x86_INST.win = $(INST_DLL)x86/
TEMPLATE_VBoxMainComp-x86_DEFS = $(filter-out HC_ARCH_BITS%,$(TEMPLATE_VBOXMAINCOMP_DEFS)) HC_ARCH_BIT=32 ARCH_BITS=32 \
	VBOX_IN_32_ON_64_MAIN_API
TEMPLATE_VBoxMainComp-x86_LIBS = \
	$(subst $(PATH_STAGE_LIB)/VBoxCOM$(VBOX_SUFF_LIB),$(PATH_STAGE_LIB)/VBoxCOM-x86$(VBOX_SUFF_LIB),\
	$(subst $(LIB_RUNTIME),$(VBOX_LIB_RUNTIME_X86),\
	$(subst $(LIB_XPCOM),$(VBOX_LIB_XPCOM_X86),\
	$(TEMPLATE_VBOXMAINCOMP_LIBS))))
ifeq ($(KBUILD_TARGET),solaris)
 ifdef VBOX_WITH_RUNPATH
  TEMPLATE_VBoxMainComp-x86_LDFLAGS = \
	$(filter-out '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)',$(TEMPLATE_VBOXMAINCOMP_LDFLAGS)) \
	'$(VBOX_GCC_RPATH_OPT)$(VBOX_PATH_APP_PRIVATE)' \
	'$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)'
 endif
endif


#
# Template for building the Main static libraries.
#
# This differs from VBOXMAINDLL only that it zeroes out the _LIBS definition.
#
TEMPLATE_VBoxMainLib  = VBox Main Component (static library)
TEMPLATE_VBoxMainLib_EXTENDS = VBOXMAINDLL
TEMPLATE_VBoxMainLib_LIBS =

TEMPLATE_VBoxMainLib-x86  = 32-bit VBox Main Component (static library)
TEMPLATE_VBoxMainLib-x86_EXTENDS = VBoxMainLib
TEMPLATE_VBoxMainLib-x86_BLD_TRG_ARCH = x86
TEMPLATE_VBoxMainLib-x86_DEFS = $(filter-out HC_ARCH_BITS%,$(TEMPLATE_VBoxMainLib_DEFS)) HC_ARCH_BIT=32 ARCH_BITS=32 \
	VBOX_IN_32_ON_64_MAIN_API

#
# Main unit testing, for compiling API implementation files into a testcase.
# This is the VBOXMAINEXE template only with a different install dir.
#
TEMPLATE_VBOXMAINTSTEXE  = VBox Main Testcase Exe
TEMPLATE_VBOXMAINTSTEXE_EXTENDS = VBOXMAINEXE
TEMPLATE_VBOXMAINTSTEXE_INST    = $(INST_TESTCASE)
ifdef VBOX_WITH_RUNPATH
 TEMPLATE_VBOXMAINTSTEXE_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' $(TEMPLATE_VBOXMAINEXE_LDFLAGS)
else ifdef VBOX_WITH_RELATIVE_RUNPATH
 TEMPLATE_VBOXMAINTSTEXE_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/..' $(TEMPLATE_VBOXMAINEXE_LDFLAGS)
endif
if "$(KBUILD_TARGET)" == "win" && defined(VBOX_SIGNING_MODE)
 TEMPLATE_VBOXMAINTSTEXE_POST_CMDS =
endif

#
# Template for building executables that use the VBox Main component.
#
TEMPLATE_VBOXMAINCLIENTEXE              = VBox Main Client (executable)
TEMPLATE_VBOXMAINCLIENTEXE_EXTENDS      = VBOXMAINEXE
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBOXMAINCLIENTEXE_DEPS		= $(VBOX_PATH_SDK)/bindings/mscom/include/VirtualBox.h
 TEMPLATE_VBOXMAINCLIENTEXE_LIBS.win	= $(TEMPLATE_VBOXMAINEXE_LIBS.win) \
   $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/User32.Lib \
   $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/Shell32.Lib \
   $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/ShLwApi.Lib \
   $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/Ole32.Lib \
   $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/OleAut32.Lib \
   $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/Uuid.Lib
else
 TEMPLATE_VBOXMAINCLIENTEXE_DEPS		= $(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h
 TEMPLATE_VBOXMAINCLIENTEXE_DEFS		= $(TEMPLATE_VBOXMAINEXE_DEFS) \
	NDEBUG TRIMMED
 TEMPLATE_VBOXMAINCLIENTEXE_CXXFLAGS.linux = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.linux) -pthread
 TEMPLATE_VBOXMAINCLIENTEXE_PCHFLAGS.linux = $(TEMPLATE_VBOXMAINEXE_PCHFLAGS.linux) -pthread
endif

#
# Template for building shared libraries / DLLs that use the VBox Main component.
#
# This differs from VBOXMAINCLIENTEXE only in PIC handling and similar DLL stuff.
#
TEMPLATE_VBOXMAINCLIENTDLL              = VBox MAIN Client (shared library)
TEMPLATE_VBOXMAINCLIENTDLL_EXTENDS      = VBOXMAINCLIENTEXE
ifn1of ($(KBUILD_TARGET), darwin os2 win)
 TEMPLATE_VBOXMAINCLIENTDLL_DEFS        = PIC $(TEMPLATE_VBOXMAINCLIENTEXE_DEFS)
 TEMPLATE_VBOXMAINCLIENTDLL_CFLAGS      = -fPIC $(TEMPLATE_VBOXMAINCLIENTEXE_CFLAGS)
 TEMPLATE_VBOXMAINCLIENTDLL_CXXFLAGS    = -fPIC $(TEMPLATE_VBOXMAINCLIENTEXE_CXXFLAGS)
 TEMPLATE_VBOXMAINCLIENTDLL_PCHFLAGS    = -fPIC $(TEMPLATE_VBOXMAINCLIENTEXE_PCHFLAGS)
 TEMPLATE_VBOXMAINCLIENTDLL_LDFLAGS     = -fPIC $(TEMPLATE_VBOXMAINCLIENTEXE_LDFLAGS)
endif
TEMPLATE_VBOXMAINCLIENTDLL_LDFLAGS.darwin = $(filter-out -bind_at_load,$(TEMPLATE_VBOXMAINCLIENTEXE_LDFLAGS.darwin))

#
# Template for building testcases which are API clients.
#
TEMPLATE_VBOXMAINCLIENTTSTEXE           = VBox Main Client Testcase (executable)
TEMPLATE_VBOXMAINCLIENTTSTEXE_EXTENDS   = VBOXMAINCLIENTEXE
TEMPLATE_VBOXMAINCLIENTTSTEXE_INST      = $(INST_TESTCASE)
ifdef VBOX_WITH_RUNPATH
 TEMPLATE_VBOXMAINCLIENTTSTEXE_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' $(TEMPLATE_VBOXMAINCLIENTEXE_LDFLAGS)
else ifdef VBOX_WITH_RELATIVE_RUNPATH
 TEMPLATE_VBOXMAINCLIENTTSTEXE_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/..' $(TEMPLATE_VBOXMAINCLIENTEXE_LDFLAGS)
endif
if "$(KBUILD_TARGET)" == "win" && defined(VBOX_SIGNING_MODE)
 TEMPLATE_VBOXMAINCLIENTTSTEXE_POST_CMDS =
endif



#
# Templates used for building the extension packs.
#
ifdef VBOX_WITH_EXTPACK
 # Base templates (native or portable).
 TEMPLATE_VBoxR3ExtPack = For the ring-3 context extension pack modules.
 if 1 # Native for now.
  TEMPLATE_VBoxR3ExtPack_EXTENDS = VBOXR3DLLNOXCPT
  TEMPLATE_VBoxR3ExtPack_DEFS = $(TEMPLATE_VBOXR3DLLNOXCPT_DEFS) VBOX_IN_EXTPACK VBOX_IN_EXTPACK_R3
 else
  TEMPLATE_VBoxR3ExtPack_EXTENDS = VBoxNoCrtGccLib
  TEMPLATE_VBoxR3ExtPack_DEFS = $(TEMPLATE_VBoxNoCrtGccLib_DEFS) VBOX_IN_EXTPACK VBOX_IN_EXTPACK_R3 IPRT_NO_CRT IN_RING3
  TEMPLATE_VBoxR3ExtPack_INCS = $(PATH_ROOT)/include/iprt/nocrt $(TEMPLATE_VBOXR3DLLNOXCPT_INCS)
 endif
 ifneq ($(KBUILD_TARGET),win)
  TEMPLATE_VBoxR3ExtPack_CXXFLAGS = $(TEMPLATE_VBOXR3DLLNOXCPT_CXXFLAGS) -fno-rtti
  TEMPLATE_VBoxR3ExtPack_PCHFLAGS = $(TEMPLATE_VBOXR3DLLNOXCPT_PCHFLAGS) -fno-rtti
 endif
 TEMPLATE_VBoxR3ExtPack_INST = $(INST_EXTPACK)YouShallOverrideThis/
 ifeq ($(KBUILD_TARGET),linux)
  TEMPLATE_VBoxR3ExtPack_LDFLAGS = $(filter-out '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)', $(TEMPLATE_VBOXR3DLLNOXCPT_LDFLAGS))
 else if !defined(VBOX_WITH_RUNPATH) && defined(VBOX_WITH_RELATIVE_RUNPATH)
   TEMPLATE_VBoxR3ExtPack_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/../../..' $(filter-out '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)', $(TEMPLATE_VBOXR3DLLNOXCPT_LDFLAGS))
 endif
 ifdef VBOX_ONLY_EXTPACKS_USE_IMPLIBS
  if1of ($(KBUILD_TARGET), win os2)
   TEMPLATE_VBoxR3ExtPack_LIBS = \
   	$(TEMPLATE_LIBS_VBOXR3) \
   	$(if-expr "$(VBOX_LIB_VMM_LAZY)" == "$(LIB_VMM)", $(PATH_STAGE_LIB)/VMMR3Imp$(VBOX_SUFF_LIB), $(VBOX_LIB_VMM_LAZY)) \
   	$(PATH_STAGE_LIB)/VBoxRTImp$(VBOX_SUFF_LIB)
  else
   TEMPLATE_VBoxR3ExtPack_LIBS = \
   	$(TEMPLATE_LIBS_VBOXR3) \
   	$(if-expr "$(VBOX_LIB_VMM_LAZY)" == "$(LIB_VMM)", $(PATH_STAGE_LIB)/VMMR3Imp$(VBOX_SUFF_DLL), $(VBOX_LIB_VMM_LAZY)) \
   	$(PATH_STAGE_LIB)/VBoxRTImp$(VBOX_SUFF_DLL)
  endif
 else
  TEMPLATE_VBoxR3ExtPack_LIBS = \
  	$(TEMPLATE_LIBS_VBOXR3) \
  	$(LIB_RUNTIME) \
  	$(VBOX_LIB_VMM_LAZY)
 endif
 ifeq ($(KBUILD_TARGET),darwin)
  TEMPLATE_VBoxR3ExtPack_POST_CMDS = $(VBOX_SIGN_EXTPACK_DYLIB_CMDS)
 endif

 TEMPLATE_VBoxR3ExtPackApi = For the ring-3 context extension pack modules using the Main API.
 TEMPLATE_VBoxR3ExtPackApi_EXTENDS = VBOXMAINDLL
 TEMPLATE_VBoxR3ExtPackApi_DEFS = $(TEMPLATE_VBOXMAINDLL_DEFS) VBOX_IN_EXTPACK VBOX_IN_EXTPACK_R3
 TEMPLATE_VBoxR3ExtPackApi_INST = $(INST_EXTPACK)YouShallOverrideThis/
 ifeq ($(KBUILD_TARGET),linux)
  TEMPLATE_VBoxR3ExtPackApi_LDFLAGS = $(filter-out '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)', $(TEMPLATE_VBOXMAINDLL_LDFLAGS))
 else if !defined(VBOX_WITH_RUNPATH) && defined(VBOX_WITH_RELATIVE_RUNPATH)
   TEMPLATE_VBoxR3ExtPackApi_LDFLAGS = '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)/../../..' $(filter-out '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)', $(TEMPLATE_VBOXMAINDLL_LDFLAGS))
 endif
 ifdef VBOX_ONLY_EXTPACKS_USE_IMPLIBS
  if1of ($(KBUILD_TARGET), win os2)
   TEMPLATE_VBoxR3ExtPackApi_LIBS = \
   	$(TEMPLATE_LIBS_VBOXR3) \
   	$(if-expr "$(VBOX_LIB_VMM_LAZY)" == "$(LIB_VMM)", $(PATH_STAGE_LIB)/VMMR3Imp$(VBOX_SUFF_LIB), $(VBOX_LIB_VMM_LAZY)) \
   	$(PATH_STAGE_LIB)/VBoxRTImp$(VBOX_SUFF_LIB)
  else
   TEMPLATE_VBoxR3ExtPackApi_LIBS = \
   	$(TEMPLATE_LIBS_VBOXR3) \
   	$(if-expr "$(VBOX_LIB_VMM_LAZY)" == "$(LIB_VMM)", $(PATH_STAGE_LIB)/VMMR3Imp$(VBOX_SUFF_DLL), $(VBOX_LIB_VMM_LAZY)) \
   	$(PATH_STAGE_LIB)/VBoxRTImp$(VBOX_SUFF_DLL)
  endif
 else
  TEMPLATE_VBoxR3ExtPackApi_LIBS = \
  	$(TEMPLATE_LIBS_VBOXR3) \
  	$(LIB_RUNTIME) \
  	$(VBOX_LIB_VMM_LAZY)
 endif
 ifeq ($(KBUILD_TARGET),darwin)
  TEMPLATE_VBoxR3ExtPackApi_POST_CMDS = $(VBOX_SIGN_EXTPACK_DYLIB_CMDS)
 endif

 TEMPLATE_VBoxR0ExtPack = For the ring-0 context extension pack modules.
 TEMPLATE_VBoxR0ExtPack_EXTENDS = VBoxR0
 TEMPLATE_VBoxR0ExtPack_EXTENDS_BY = appending
 TEMPLATE_VBoxR0ExtPack_INST = $(INST_EXTPACK)YouShallOverrideThis/
 TEMPLATE_VBoxR0ExtPack_DEFS = VBOX_IN_EXTPACK VBOX_IN_EXTPACK_R0
 if1of ($(VBOX_LDR_FMT), pe lx)
  TEMPLATE_VBoxR0ExtPack_LIBS = \
	$(PATH_STAGE_LIB)/VMMR0Imp$(VBOX_SUFF_LIB) \
	$(PATH_STAGE_LIB)/SUPR0$(VBOX_SUFF_LIB)
 endif

 TEMPLATE_VBoxRcExtPack = For the raw-mode context extension pack modules.
 TEMPLATE_VBoxRcExtPack_EXTENDS = VBoxRc
 TEMPLATE_VBoxRcExtPack_EXTENDS_BY = appending
 TEMPLATE_VBoxRcExtPack_SYSSUFF = .rc
 TEMPLATE_VBoxRcExtPack_INST = $(INST_EXTPACK)YouShallOverrideThis/
 TEMPLATE_VBoxRcExtPack_DEFS = VBOX_IN_EXTPACK VBOX_IN_EXTPACK_RC
 if1of ($(VBOX_LDR_FMT32), pe lx)
  TEMPLATE_VBoxRcExtPack_LIBS = \
	$(PATH_STAGE_LIB)/VMMRCBuiltin$(VBOX_SUFF_LIB) \
	$(PATH_STAGE_LIB)/VMMRCImp$(VBOX_SUFF_LIB)
 endif

 TEMPLATE_VBoxInsExtPack = For the install targets of an extension pack.
 TEMPLATE_VBoxInsExtPack_MODE = 0644
 TEMPLATE_VBoxInsExtPack_INST = $(INST_EXTPACK)YouShallOverrideThis/

 # For each individual extension pack
 ifdef VBOX_WITH_EXTPACK_PUEL
  TEMPLATE_VBoxR3ExtPackPuel = For the ring-3 context modules in the PUEL extension pack.
  TEMPLATE_VBoxR3ExtPackPuel_EXTENDS = VBoxR3ExtPack
  TEMPLATE_VBoxR3ExtPackPuel_INST = $(INST_EXTPACK_PUEL)$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)/
  TEMPLATE_VBoxR3ExtPackPuel_DEFS = $(TEMPLATE_VBoxR3ExtPack_DEFS) VBOX_IN_PUEL_EXTPACK
  TEMPLATE_VBoxR3ExtPackPuel_LD_DEBUG = split

  TEMPLATE_VBoxR3ExtPackApiPuel = For the ring-3 context modules in the PUEL extension pack.
  TEMPLATE_VBoxR3ExtPackApiPuel_EXTENDS = VBoxR3ExtPackApi
  TEMPLATE_VBoxR3ExtPackApiPuel_INST = $(INST_EXTPACK_PUEL)$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)/
  TEMPLATE_VBoxR3ExtPackApiPuel_DEFS = $(TEMPLATE_VBoxR3ExtPackApi_DEFS) VBOX_IN_PUEL_EXTPACK
  TEMPLATE_VBoxR3ExtPackApiPuel_LD_DEBUG = split

  TEMPLATE_VBoxR3ExtPackPuelWithOpenSsl = For the ring-3 context modules in the PUEL extension pack using ExtPack OpenSSL.
  TEMPLATE_VBoxR3ExtPackPuelWithOpenSsl_EXTENDS = VBoxR3ExtPackPuel
  ifdef VBOX_NEED_EXTPACK_OPENSSL
   TEMPLATE_VBoxR3ExtPackPuelWithOpenSsl_INCS = \
   	$(TEMPLATE_VBoxR3ExtPack_INCS) \
   	$(SDK_VBOX_OPENSSL_VBOX_DEFAULT_INCS)
   TEMPLATE_VBoxR3ExtPackPuelWithOpenSsl_LIBS = \
   	$(PATH_STAGE_LIB)/VBoxExtPack-libssl$(VBOX_SUFF_LIB) \
   	$(PATH_STAGE_LIB)/VBoxExtPack-libcrypto$(VBOX_SUFF_LIB) \
   	$(TEMPLATE_VBoxR3ExtPack_LIBS) # Must come after the two libraries or we'll pick up SSL from VBoxRT!
  endif

  TEMPLATE_VBoxR0ExtPackPuel = For the ring-0 context modules in the PUEL extension pack.
  TEMPLATE_VBoxR0ExtPackPuel_EXTENDS = VBoxR0ExtPack
  TEMPLATE_VBoxR0ExtPackPuel_INST = $(INST_EXTPACK_PUEL)$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)/
  TEMPLATE_VBoxR0ExtPackPuel_DEFS = $(TEMPLATE_VBoxR0ExtPack_DEFS) VBOX_IN_PUEL_EXTPACK

  TEMPLATE_VBoxRcExtPackPuel = For the raw-mode context modules in the PUEL extension pack.
  TEMPLATE_VBoxRcExtPackPuel_EXTENDS = VBoxRcExtPack
  TEMPLATE_VBoxRcExtPackPuel_INST = $(INST_EXTPACK_PUEL)$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)/
  TEMPLATE_VBoxRcExtPackPuel_DEFS = $(TEMPLATE_VBoxRcExtPack_DEFS) VBOX_IN_PUEL_EXTPACK

  TEMPLATE_VBoxInsExtPackPuel = For the install targets of an extension pack.
  TEMPLATE_VBoxInsExtPackPuel_EXTENDS = VBoxR0ExtPack
  TEMPLATE_VBoxInsExtPackPuel_INST = $(INST_EXTPACK_PUEL)
 endif

endif # VBOX_WITH_EXTPACK


#
# Qt
# Qt
# Qt
#
ifdef VBOX_WITH_QTGUI

 # Guess VBOX_WITH_ORACLE_QT
 ifndef VBOX_WITH_ORACLE_QT
  ifndef VBOX_OSE
   if1of ($(KBUILD_TARGET), darwin solaris win)
    VBOX_WITH_ORACLE_QT := 1
   endif
  endif
 endif

 #
 # Handmade configuration of Qt - very annoying, this needs to
 # be cleaned up properly later some time (not important now).
 #
 ifeq ($(VBOX_PATH_QT),)
  ifeq ($(KBUILD_TARGET),darwin)
   VBOX_PATH_QT := $(lastword $(sort $(wildcard $(KBUILD_DEVTOOLS_TRG)/qt/v5*)))
   ifeq ($(VBOX_PATH_QT),)
    ifneq ($(wildcard /Library/Frameworks/QtCore.framework),)
     # Using the global installation (for OSE).
     VBOX_PATH_QT ?= /usr
     VBOX_PATH_QT_FRAMEWORKS ?= /Library/Frameworks
    endif
   endif
  else if1of ($(KBUILD_TARGET), win)
   VBOX_PATH_QT ?= $(lastword $(filter %-$(tolower $(VBOX_VCC_TOOL_STEM)),$(sort $(wildcard $(KBUILD_DEVTOOLS_TRG)/qt/v5*))))
  else if1of ($(KBUILD_TARGET), linux solaris)
   VBOX_PATH_QT ?= $(lastword $(sort $(wildcard $(KBUILD_DEVTOOLS_TRG)/qt/v5*)))
   ifneq ($(VBOX_PATH_QT),)
    VBOX_WITH_ORACLE_QT = 1
   endif
  endif
 endif
 ifeq ($(VBOX_PATH_QT),)
  if1of ($(USERNAME), bird)
   # gentoo (64-bit)
   VBOX_PATH_QT          ?= /usr
   VBOX_PATH_QT_LIB      ?= /usr/lib/qt5
  endif
 endif
 VBOX_PATH_QT            ?= /usr
 VBOX_PATH_QT_LIB        ?= $(VBOX_PATH_QT)/lib

 ifdef VBOX_WITH_ORACLE_QT
  VBOX_QT_INFIX=VBox
 endif

 ifeq ($(KBUILD_TARGET), darwin)
  VBOX_QT_MOD = \
   QtCore QtGui QtWidgets QtPrintSupport QtMacExtras \
   $(if $(VBOX_GUI_USE_QGL),QtOpenGL,)
 else if1of ($(KBUILD_TARGET), linux freebsd netbsd openbsd solaris win)
  VBOX_QT_MOD += \
   Qt5Core Qt5Gui Qt5Widgets Qt5PrintSupport \
   $(if $(VBOX_GUI_USE_QGL),Qt5OpenGL,)
   if1of ($(KBUILD_TARGET), linux freebsd netbsd openbsd solaris)
    VBOX_QT_MOD += \
     Qt5DBus Qt5XcbQpa Qt5X11Extras
    # legacy libraries required to be installed on EL5
    VBOX_QT_LEGACY_LIBS = \
     $(if $(VBOX_LD_HAS_LIBXCB),,libxcb.so.1 libX11.so.6 libX11-xcb.so.1)
    VBOX_QT_PLUGINS = \
      plugins/platforms/libqxcb.so \
      plugins/xcbglintegrations/libqxcb-glx-integration.so
   else ifeq ($(KBUILD_TARGET), win)
    VBOX_QT_MOD += \
     Qt5WinExtras
   endif # win
 endif # linux freebsd netbsd openbsd solaris win

 VBOX_QT_MOD_NAMES = $(foreach qtmod,$(VBOX_QT_MOD),$(qtmod)$(VBOX_QT_INFIX))

 # Hack LD_LIBRARY_PATH for stuff in tools.
 ifdef VBOX_WITH_ORACLE_QT
  if1of ($(KBUILD_TARGET), linux solaris)
   export LD_LIBRARY_PATH := $(VBOX_PATH_QT_LIB):$(LD_LIBRARY_PATH)
  endif
 endif


 #
 # Template for building Qt GUI executables.
 #
 TEMPLATE_VBOXQTGUIEXE = VBox Qt GUI Executable
 TEMPLATE_VBOXQTGUIEXE_USES = qt5
 TEMPLATE_VBOXQTGUIEXE_QTTOOL = QT5
 TEMPLATE_VBOXQTGUIEXE_MOCTOOL = QT5
 TEMPLATE_VBOXQTGUIEXE_UICTOOL = QT5
 TEMPLATE_VBOXQTGUIEXE_RCCTOOL = QT5
 TEMPLATE_VBOXQTGUIEXE_LRCTOOL = QT5
 TEMPLATE_VBOXQTGUIEXE_SDKS = QT5
 TEMPLATE_VBOXQTGUIEXE_MOCDEFS.darwin += QT_VERSION=0x050602
 TEMPLATE_VBOXQTGUIEXE_QT_INFIX = $(VBOX_QT_INFIX)
 TEMPLATE_VBOXQTGUIEXE_DEFS = IN_RING3 QT_NO_DEBUG QT_THREAD_SUPPORT QT_SHARED HAVE_CONFIG_H $(ARCH_BITS_DEFS)
 TEMPLATE_VBOXQTGUIEXE_RCDEFS = $(TEMPLATE_VBOXR3EXE_RCDEFS)

 ifeq ($(KBUILD_TARGET),win)
  # Note! No use of VBOX_VCC_CRT_TYPE here yet as it requires a /MDd build of Qt as well.
  TEMPLATE_VBOXQTGUIEXE_TOOL = $(VBOX_VCC_TOOL)
  TEMPLATE_VBOXQTGUIEXE_DEFS += \
     _WIN32_WINNT=0x0500 UNICODE _UNICODE \
     QT_DLL _CRT_SECURE_NO_DEPRECATE \
     $(QMAKE_PRL_DEFINES)
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS = -nologo -Zm200 -MD -Zi -EHsc -Zc:wchar_t-
  #    -wd4481: nonstandard extension used: override specifier 'override'
  #    -wd4625: 'QRubberBand' : copy constructor could not be generated because a base class copy constructor is inaccessible
  #    -wd4626: 'QRubberBand' : assignment operator could not be generated because a base class assignment operator is inaccessible
  #    -wd4640: qmetatype.h(2210): warning C4640: 'f' : construction of local static object is not thread-safe [too bad]
  #    -wd4350: behavior change: 'int QStringList::indexOf(const QRegExp &,int) const' called instead of 'int QStringList::indexOf(QRegExp &,int) const'
  #    -wd4121: UIActionPool.h(393) : warning C4121: 'UIActionPool::PointerToFunction' : alignment of a member was sensitive to packing
  #    -wd4718: qmap.h(222) : warning C4718: 'QMapNode<enum DetailsElementType,bool>::destroySubTree' : recursive call has no side effects, deleting
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS += $(VBOX_VCC_WARN_ALL) -wd4481 -wd4625 -wd4626 -wd4640 -wd4350 -wd4371 -wd4121 -wd4718 $(VBOX_VCC_WERR)
  if1of ($(VBOX_VCC_TOOL_STEM), VCC120)
   #   -wd4619: qvectro.h(305 : warning C4619: #pragma warning : there is no warning number '4345'
   TEMPLATE_VBOXQTGUIEXE_CXXFLAGS += -wd4619
  endif
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.debug = -RTCsu
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.debug = -RTCsu
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.dbgopt = $(NO_SUCH_VARIABLE)
  TEMPLATE_VBOXQTGUIEXE_PCHFLAGS        = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS)
  TEMPLATE_VBOXQTGUIEXE_PCHFLAGS.debug  = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.debug)
  TEMPLATE_VBOXQTGUIEXE_PCHFLAGS.dbgopt = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.dbgopt)
  TEMPLATE_VBOXQTGUIEXE_LDFLAGS = -Ignore:4197 \
	/NOD /INCREMENTAL:NO /MAPINFO:EXPORTS /LargeAddressAware /DynamicBase /NxCompat /Release /Debug /Opt:Ref /Opt:Icf \
	/Version:$(VBOX_VERSION_MAJOR)0$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	/STUB:$(PATH_ROOT)/src/VBox/HostDrivers/Support/win/winstub.com
  if defined(VBOX_SIGNING_MODE) && defined(VBOX_WITH_HARDENING)
   TEMPLATE_VBOXQTGUIEXE_LDFLAGS += -IntegrityCheck
  endif
  TEMPLATE_VBOXQTGUIEXE_SDKS += $(VBOX_WINPSDK)
  TEMPLATE_VBOXQTGUIEXE_LIBS = \
	$(VBOX_LIBS_QT) \
	$(LIB_RUNTIME) \
	$(VBOX_LIB_VMM_LAZY) \
	$(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/msvcprt.lib \
	$(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/msvcrt.lib \
	$(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/oldnames.lib \
	$(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/delayimp.lib
  TEMPLATE_VBOXQTGUIEXE_POST_CMDS = $(VBOX_SIGN_IMAGE_CMDS)

 else # the gcc guys:
  TEMPLATE_VBOXQTGUIEXE_TOOL = $(VBOX_GCC_TOOL)
  if $(VBOX_GCC_VERSION_CC) < 30400
   TEMPLATE_VBOXQTGUIEXE_DEFS += RT_WITHOUT_PRAGMA_ONCE
  endif
  TEMPLATE_VBOXQTGUIEXE_DEFS.linux = _REENTRANT
  TEMPLATE_VBOXQTGUIEXE_DEFS.solaris = _REENTRANT

  ## @todo Use VBOX_GCC_PEDANTIC_CXX?
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS = \
	-g $(VBOX_GCC_pipe) $(filter-out -Wno-unused $(VBOX_GCC_Wno-unused-parameter),$(VBOX_GCC_WARN)) -frtti -fno-exceptions \
	-Wno-long-long -fshort-wchar -fno-strict-aliasing \
	$(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_fvisibility-inlines-hidden) $(VBOX_GCC_Wno-multistatement-macros) $(VBOX_GCC_Wno-ignored-qualifiers) \
	$(VBOX_GCC_Wno-return-type-c-linkage) $(VBOX_GCC_std) $(VBOX_GCC_IPRT_FMT_CHECK)
  ifdef VBOX_WITH_NO_GCC_WARNING_POLICY
   TEMPLATE_VBOXQTGUIEXE_CXXFLAGS += $(VBOX_GCC_WERR)
  endif
  ifn1of ($(USERNAME),dsen serkan) # Bunch of stuff deprecated after 5.6.*. These guys knows how to deal with it. :)
   TEMPLATE_VBOXQTGUIEXE_CXXFLAGS += $(VBOX_GCC_Wno-deprecated-declarations)
  endif
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.x86 = -m32
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.amd64 = -m64
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.linux = -pthread
  TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.debug = $(VBOX_GCC_SANITIZER_FLAGS)
  TEMPLATE_VBOXQTGUIEXE_PCHFLAGS       = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS)
  TEMPLATE_VBOXQTGUIEXE_PCHFLAGS.x86   = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.x86)
  TEMPLATE_VBOXQTGUIEXE_PCHFLAGS.amd64 = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.amd64)
  TEMPLATE_VBOXQTGUIEXE_PCHFLAGS.linux = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.linux)
  TEMPLATE_VBOXQTGUIEXE_PCHFLAGS.debug = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.debug)
  TEMPLATE_VBOXQTGUIEXE_PCHFLAGS.dbgopt = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.dbgopt)
  TEMPLATE_VBOXQTGUIEXE_OBJCFLAGS = -g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_C) -fno-exceptions $(VBOX_GCC_IPRT_FMT_CHECK)
  TEMPLATE_VBOXQTGUIEXE_OBJCFLAGS.x86 = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.x86)
  TEMPLATE_VBOXQTGUIEXE_OBJCFLAGS.amd64 = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.amd64)
  TEMPLATE_VBOXQTGUIEXE_OBJCXXFLAGS = \
	-g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_CXX) \
	-frtti -fno-exceptions $(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_fvisibility-inlines-hidden) $(VBOX_GCC_IPRT_FMT_CHECK)
  ifdef VBOX_WITH_NO_GCC_WARNING_POLICY
   TEMPLATE_VBOXQTGUIEXE_OBJCXXFLAGS += $(VBOX_GCC_WERR)
  endif
  TEMPLATE_VBOXQTGUIEXE_OBJCXXFLAGS.x86 = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.x86)
  TEMPLATE_VBOXQTGUIEXE_OBJCXXFLAGS.amd64 = $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.amd64)
  TEMPLATE_VBOXQTGUIEXE_LDFLAGS.x86 = -m32
  TEMPLATE_VBOXQTGUIEXE_LDFLAGS.amd64 = -m64
  TEMPLATE_VBOXQTGUIEXE_LDFLAGS.debug = $(VBOX_GCC_SANITIZER_FLAGS) $(VBOX_GCC_SANITIZER_LDFLAGS)
  TEMPLATE_VBOXQTGUIEXE_LIBS = \
	$(VBOX_LIBS_QT) \
	$(LIB_RUNTIME) \
	$(if-expr "$(LIB_VMM)" == "$(VBOX_LIB_VMM_LAZY)",$(LIB_REM),) \
	$(VBOX_LIB_VMM_LAZY)

  ifeq ($(KBUILD_TARGET),linux)
   TEMPLATE_VBOXQTGUIEXE_LDFLAGS += -Wl,-z,noexecstack,-z,relro $(VBOX_LD_as_needed)
   TEMPLATE_VBOXQTGUIEXE_LIBS += \
     $(VBOX_XCURSOR_LIBS) \
	Xext \
	X11
    TEMPLATE_VBOXQTGUIEXE_LIBPATH += \
	$(VBOX_LIBPATH_X11)
   if defined(VBOX_WITH_ORACLE_QT) && !defined(VBOX_LD_HAS_LIBXCB)
    TEMPLATE_VBOXQTGUIEXE_LIBPATH += $(PATH_SDK_QT5_LIB)/legacy
    TEMPLATE_VBOXQTGUIEXE_INCS    += $(PATH_SDK_QT5_INC)/legacy
   endif
  else ifeq ($(KBUILD_TARGET),darwin)
   TEMPLATE_VBOXQTGUIEXE_DEFS.darwin        += $(VBOX_DARWIN_DEF_SDK_DEFS)
   TEMPLATE_VBOXQTGUIEXE_CFLAGS.darwin      += $(VBOX_DARWIN_DEF_SDK_CFLAGS)
   TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.darwin    += $(VBOX_DARWIN_DEF_SDK_CXXFLAGS)
   TEMPLATE_VBOXQTGUIEXE_PCHFLAGS.darwin    += $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.darwin)
   TEMPLATE_VBOXQTGUIEXE_OBJCFLAGS.darwin   += $(VBOX_DARWIN_DEF_SDK_OBJCFLAGS)
   TEMPLATE_VBOXQTGUIEXE_OBJCXXFLAGS.darwin += $(VBOX_DARWIN_DEF_SDK_OBJCXXFLAGS)
   TEMPLATE_VBOXQTGUIEXE_LDFLAGS.darwin     += $(VBOX_DARWIN_DEF_SDK_LDFLAGS) -bind_at_load
   TEMPLATE_VBOXQTGUIEXE_LIBS +=
   TEMPLATE_VBOXQTGUIEXE_LIBPATH +=
  else
   TEMPLATE_VBOXQTGUIEXE_INCS += \
	$(VBOX_XCURSOR_INCS)
   TEMPLATE_VBOXQTGUIEXE_LIBS += \
     $(VBOX_XCURSOR_LIBS) \
	Xext \
	X11 \
	m \
	$(LIB_PTHREAD)
   TEMPLATE_VBOXQTGUIEXE_LIBPATH += \
	$(VBOX_LIBPATH_X11)
   ifeq ($(KBUILD_TARGET),freebsd)
    TEMPLATE_VBOXQTGUIEXE_INCS += \
	/usr/include \
	/usr/X11R6/include \
	/usr/local/include
    TEMPLATE_VBOXQTGUIEXE_LIBPATH += \
	/usr/lib \
	/usr/X11R6/lib \
	/usr/local/lib
   endif
   ifeq ($(KBUILD_TARGET),solaris)
    TEMPLATE_VBOXQTGUIEXE_LDFLAGS.solaris = -Wl,-z,ignore # Same as VBOX_LD_as_needed.
    TEMPLATE_VBOXQTGUIEXE_LIBS += \
         rt socket nsl
   endif
  endif
  # Assume the Qt shared objects are in the same directory as the executable, on Solaris too.
  ifdef VBOX_WITH_RUNPATH
   TEMPLATE_VBOXQTGUIEXE_LDFLAGS += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)'
  else ifdef VBOX_WITH_RELATIVE_RUNPATH
   TEMPLATE_VBOXQTGUIEXE_LDFLAGS += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)'
  endif

 endif

 # Add COM/XPCOM stuff
 TEMPLATE_VBOXQTGUIEXE_LIBS += \
	$(PATH_STAGE_LIB)/VBoxCOM$(if-expr defined(VBOX_WITH_DEBUG_VCC_CRT) && $(KBUILD_TARGET) == win,-GUI,)$(VBOX_SUFF_LIB)
 ifdef VBOX_WITH_XPCOM
  ## @todo may be worth creating the VBOX_XPCOM SDK def, or just a SDK_VBOXXPCOM.
  TEMPLATE_VBOXQTGUIEXE_DEFS += VBOX_WITH_XPCOM
  ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
   TEMPLATE_VBOXQTGUIEXE_DEFS += VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
  endif
  TEMPLATE_VBOXQTGUIEXE_INCS += \
	$(VBOX_XPCOM_INCS)
  TEMPLATE_VBOXQTGUIEXE_LIBS += \
	$(LIB_XPCOM)
  TEMPLATE_VBOXQTGUIEXE_INTERMEDIATES += \
	$(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h
 else  # COM
  TEMPLATE_VBOXQTGUIEXE_INCS += \
	$(VBOX_PATH_SDK)/bindings/mscom/include
  TEMPLATE_VBOXQTGUIEXE_INTERMEDIATES += \
	$(VBOX_PATH_SDK)/bindings/mscom/include/VirtualBox.h
 endif # COM

 ifn1of ($(KBUILD_TARGET), darwin os2 win)
   TEMPLATE_VBOXQTGUIEXE_DEFS     += PIC
   TEMPLATE_VBOXQTGUIEXE_CFLAGS   += -fPIC
   TEMPLATE_VBOXQTGUIEXE_CXXFLAGS += -fPIC
   # Needed for GCC 9. Even system's Qt 5.12.4 (on Ubuntu 19.10) did not have this fixed yet.
   TEMPLATE_VBOXQTGUIEXE_CXXFLAGS.linux = -Wno-deprecated-copy $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS)
   TEMPLATE_VBOXQTGUIEXE_LDFLAGS  += -fPIC
 endif # not darwin, os2 or win

 ifeq ($(KBUILD_TARGET),darwin)
  TEMPLATE_VBOXQTGUIEXE_POST_CMDS = $(QUIET)install_name_tool $(foreach qtmod, $(VBOX_QT_MOD_NAMES), \
	$(foreach prefix, @executable_path/../Frameworks/ $(VBOX_PATH_QT)/Frameworks/ $(PATH_SDK_QT)/, \
		-change "$(prefix)$(qtmod).framework/Versions/5/$(qtmod)" \
			"$(if $(VBOX_WITH_HARDENING),/Applications/VirtualBox.app/Contents/Frameworks,@rpath)/$(qtmod).framework/Versions/5/$(qtmod)" ) ) "$(out)"
 endif

 #
 # Template for building Qt GUI components.
 #
 TEMPLATE_VBOXQTGUI = VBox Qt GUI Components
 TEMPLATE_VBOXQTGUI_EXTENDS = VBOXQTGUIEXE
 TEMPLATE_VBOXQTGUI_LIBS = $(filter-out $(QTMAIN),$(TEMPLATE_VBOXQTGUIEXE_LIBS))
 ifeq ($(KBUILD_TARGET),darwin)
  TEMPLATE_VBOXQTGUI_LDFLAGS.darwin += $(filter-out -bind_at_load,$(TEMPLATE_VBOXQTGUIEXE_LDFLAGS.darwin)) \
	-current_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	-compatibility_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD)
 endif
 ifn1of ($(KBUILD_TARGET), darwin os2 win)
   TEMPLATE_VBOXQTGUI_DEFS     = PIC $(TEMPLATE_VBOXQTGUIEXE_DEFS)
   TEMPLATE_VBOXQTGUI_CFLAGS   = -fPIC $(TEMPLATE_VBOXQTGUIEXE_CFLAGS)
   TEMPLATE_VBOXQTGUI_CXXFLAGS = -fPIC $(TEMPLATE_VBOXQTGUIEXE_CXXFLAGS)
   TEMPLATE_VBOXQTGUI_PCHFLAGS = $(TEMPLATE_VBOXQTGUI_CXXFLAGS)
   TEMPLATE_VBOXQTGUI_LDFLAGS  = -fPIC $(TEMPLATE_VBOXQTGUIEXE_LDFLAGS)
 endif

endif # VBOX_WITH_QTGUI


#
# Template for installing symbol files that we wish to ship.
#
TEMPLATE_VBoxDbgSyms = Symbol files for VBoxDbg and gurus.
TEMPLATE_VBoxDbgSyms_INST = $(INST_VBOXDBG_SYMS)


#
# Template for building build bldprogs.
# HACK ALERT! The BLD_TRG_* is a hack to allow building libraries as well.
#
TEMPLATE_VBoxBldProg  = VBox Build Program
TEMPLATE_VBoxBldProg_BLD_TRG            := $(KBUILD_HOST)
TEMPLATE_VBoxBldProg_BLD_TRG_ARCH       := $(KBUILD_HOST_ARCH)
TEMPLATE_VBoxBldProg_BLD_TRG_CPU        := $(KBUILD_HOST_CPU)
TEMPLATE_VBoxBldProg_DEFS               := IN_RING3 LOG_DISABLED IN_BLD_PROG
TEMPLATE_VBoxBldProg_DEFS.win           := _CRT_SECURE_NO_DEPRECATE
ifeq ($(KBUILD_TARGET),$(KBUILD_HOST))
 TEMPLATE_VBoxBldProg_ASTOOL            := $(VBOX_ASTOOL)
 TEMPLATE_VBoxBldProg_ASFLAGS.x86       := $(VBOX_ASFLAGS32)
 TEMPLATE_VBoxBldProg_ASFLAGS.amd64     := $(VBOX_ASFLAGS64)
else
 TEMPLATE_VBoxBldProg_ASTOOL            := YASM
 TEMPLATE_VBoxBldProg_ASFLAGS           := -D__YASM__ -Worphan-labels $(VBOX_YASM_Wno-segreg-in-64bit)
 if1of ($(KBUILD_HOST),win)
  TEMPLATE_VBoxBldProg_ASFLAGS          += -g cv8 -DASM_FORMAT_ELF
  TEMPLATE_VBoxBldProg_ASFLAGS.x86      := -f win32
  TEMPLATE_VBoxBldProg_ASFLAGS.amd64    := -f win64
 else if1of ($(KBUILD_HOST),darwin)
  TEMPLATE_VBoxBldProg_ASFLAGS          += -DASM_FORMAT_MACHO
  TEMPLATE_VBoxBldProg_ASFLAGS.x86      := -f macho32
  TEMPLATE_VBoxBldProg_ASFLAGS.amd64    := -f macho64
 else
  TEMPLATE_VBoxBldProg_ASFLAGS          += -g dwarf2 -DASM_FORMAT_ELF
  TEMPLATE_VBoxBldProg_ASFLAGS.x86      := -f elf32
  TEMPLATE_VBoxBldProg_ASFLAGS.amd64    := -f elf64
 endif
endif
ifeq ($(KBUILD_HOST),win)
 TEMPLATE_VBoxBldProg_TOOL              := $(VBOX_VCC_TOOL_STEM)$(toupper $(KBUILD_HOST_ARCH))
 TEMPLATE_VBoxBldProg_SDKS              := ReorderCompilerIncs $(VBOX_WINPSDK)
 TEMPLATE_VBoxBldProg_CXXFLAGS          := -Zi -Zl -GR- -EHsc -GF -Zc:wchar_t- $(VBOX_VCC_OPT) $(VBOX_VCC_FP) -MT$(VBOX_VCC_CRT_TYPE) \
	$(VBOX_VCC_WARN_ALL) $(VBOX_VCC_WERR)
 TEMPLATE_VBoxBldProg_CXXFLAGS.debug    := -RTCsu
 TEMPLATE_VBoxBldProg_CXXFLAGS.dbgopt    = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBoxBldProg_CXXFLAGS.profile   = $(TEMPLATE_VBoxBldProg_CXXFLAGS.release)
 TEMPLATE_VBoxBldProg_CXXFLAGS.kprofile  = $(TEMPLATE_VBoxBldProg_CXXFLAGS.release)
 TEMPLATE_VBoxBldProg_CFLAGS             = $(TEMPLATE_VBoxBldProg_CXXFLAGS)
 TEMPLATE_VBoxBldProg_CFLAGS.debug       = $(TEMPLATE_VBoxBldProg_CXXFLAGS.debug)
 TEMPLATE_VBoxBldProg_CFLAGS.dbgopt      = $(TEMPLATE_VBoxBldProg_CXXFLAGS.dbgopt)
 TEMPLATE_VBoxBldProg_CFLAGS.release     = $(TEMPLATE_VBoxBldProg_CXXFLAGS.release)
 TEMPLATE_VBoxBldProg_CFLAGS.profile     = $(TEMPLATE_VBoxBldProg_CXXFLAGS.profile)
 TEMPLATE_VBoxBldProg_CFLAGS.kprofile    = $(TEMPLATE_VBoxBldProg_CXXFLAGS.kprofile)
 TEMPLATE_VBoxBldProg_PCHFLAGS           = $(TEMPLATE_VBoxBldProg_CXXFLAGS)
 TEMPLATE_VBoxBldProg_PCHFLAGS.debug     = $(TEMPLATE_VBoxBldProg_CXXFLAGS.debug)
 TEMPLATE_VBoxBldProg_PCHFLAGS.dbgopt    = $(TEMPLATE_VBoxBldProg_CXXFLAGS.dbgopt)
 TEMPLATE_VBoxBldProg_PCHFLAGS.release   = $(TEMPLATE_VBoxBldProg_CXXFLAGS.release)
 TEMPLATE_VBoxBldProg_PCHFLAGS.profile   = $(TEMPLATE_VBoxBldProg_CXXFLAGS.profile)
 TEMPLATE_VBoxBldProg_PCHFLAGS.kprofile  = $(TEMPLATE_VBoxBldProg_CXXFLAGS.kprofile)
 TEMPLATE_VBoxBldProg_LDFLAGS            = -Ignore:4197 \
	/NOD /INCREMENTAL:NO /MAPINFO:EXPORTS /LargeAddressAware /DynamicBase /NxCompat /Release /Debug /Opt:Ref /Opt:Icf \
	/Version:$(VBOX_VERSION_MAJOR)0$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
	/DISALLOWLIB:libc$(VBOX_VCC_CRT_TYPE_N).lib \
	/DISALLOWLIB:libcmt$(VBOX_VCC_CRT_TYPE_N).lib \
	/DISALLOWLIB:msvcrt.lib \
	/DISALLOWLIB:msvcrtd.lib \
	/DISALLOWLIB:msvcprt.lib \
	/DISALLOWLIB:msvcprtd.lib
 TEMPLATE_VBoxBldProg_LIBS               = \
	$(PATH_TOOL_$(TEMPLATE_VBoxBldProg_TOOL)_LIB)/oldnames.lib \
	$(PATH_TOOL_$(TEMPLATE_VBoxBldProg_TOOL)_LIB)/libcmt$(VBOX_VCC_CRT_TYPE).lib \
	$(PATH_TOOL_$(TEMPLATE_VBoxBldProg_TOOL)_LIB)/libcpmt$(VBOX_VCC_CRT_TYPE).lib

else
# (gcc of some kind )
TEMPLATE_VBoxBldProg_TOOL                = GXX3
 if $(VBOX_GCC_VERSION_CC) < 30400
TEMPLATE_VBoxBldProg_DEFS               += RT_WITHOUT_PRAGMA_ONCE
 endif
TEMPLATE_VBoxBldProg_CFLAGS              = -g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_C) $(VBOX_GCC_Wno-variadic-macros)
 ifdef VBOX_WITH_NO_GCC_WARNING_POLICY
  TEMPLATE_VBoxBldProg_CFLAGS           += $(VBOX_GCC_WERR)
 endif
TEMPLATE_VBoxBldProg_CFLAGS.x86          = -m32
TEMPLATE_VBoxBldProg_CFLAGS.sparc32      = -m32
TEMPLATE_VBoxBldProg_CFLAGS.amd64        = -m64
TEMPLATE_VBoxBldProg_CFLAGS.sparc64      = -m64
TEMPLATE_VBoxBldProg_CFLAGS.release      = -O2 -fno-omit-frame-pointer -fno-strict-aliasing
TEMPLATE_VBoxBldProg_CFLAGS.profile      = $(TEMPLATE_VBoxBldProg_CXXFLAGS.profile)
TEMPLATE_VBoxBldProg_CFLAGS.kprofile     = $(TEMPLATE_VBoxBldProg_CXXFLAGS.kprofile)
TEMPLATE_VBoxBldProg_CXXFLAGS            = -g $(VBOX_GCC_pipe) $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC_Wno-variadic-macros)
 ifdef VBOX_WITH_NO_GCC_WARNING_POLICY
  TEMPLATE_VBoxBldProg_CXXFLAGS         += $(VBOX_GCC_WERR)
 endif
TEMPLATE_VBoxBldProg_CXXFLAGS.x86        = -m32
TEMPLATE_VBoxBldProg_CXXFLAGS.sparc32    = -m32
TEMPLATE_VBoxBldProg_CXXFLAGS.amd64      = -m64
TEMPLATE_VBoxBldProg_CXXFLAGS.sparc64    = -m64
TEMPLATE_VBoxBldProg_CXXFLAGS.release    = -O2 -fno-omit-frame-pointer -fno-strict-aliasing
TEMPLATE_VBoxBldProg_CXXFLAGS.profile    = $(TEMPLATE_VBoxBldProg_CXXFLAGS.release)
TEMPLATE_VBoxBldProg_CXXFLAGS.kprofile   = $(TEMPLATE_VBoxBldProg_CXXFLAGS.release)
TEMPLATE_VBoxBldProg_OBJCFLAGS           = $(TEMPLATE_VBoxBldProg_CFLAGS)
TEMPLATE_VBoxBldProg_OBJCFLAGS.x86       = $(TEMPLATE_VBoxBldProg_CFLAGS.x86)
TEMPLATE_VBoxBldProg_OBJCFLAGS.amd64     = $(TEMPLATE_VBoxBldProg_CFLAGS.amd64)
TEMPLATE_VBoxBldProg_OBJCFLAGS.release   = $(TEMPLATE_VBoxBldProg_CFLAGS.release)
TEMPLATE_VBoxBldProg_OBJCFLAGS.profile   = $(TEMPLATE_VBoxBldProg_CFLAGS.profile)
TEMPLATE_VBoxBldProg_OBJCFLAGS.kprofile  = $(TEMPLATE_VBoxBldProg_CFLAGS.kprofile)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS         = $(TEMPLATE_VBoxBldProg_CXXFLAGS)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS.x86     = $(TEMPLATE_VBoxBldProg_CXXFLAGS.x86)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS.amd64   = $(TEMPLATE_VBoxBldProg_CXXFLAGS.amd64)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS.release = $(TEMPLATE_VBoxBldProg_CXXFLAGS.release)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS.profile = $(TEMPLATE_VBoxBldProg_CXXFLAGS.profile)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS.kprofile= $(TEMPLATE_VBoxBldProg_CXXFLAGS.kprofile)
TEMPLATE_VBoxBldProg_PCHFLAGS         = $(TEMPLATE_VBoxBldProg_CXXFLAGS)
TEMPLATE_VBoxBldProg_PCHFLAGS.x86     = $(TEMPLATE_VBoxBldProg_CXXFLAGS.x86)
TEMPLATE_VBoxBldProg_PCHFLAGS.amd64   = $(TEMPLATE_VBoxBldProg_CXXFLAGS.amd64)
TEMPLATE_VBoxBldProg_PCHFLAGS.release = $(TEMPLATE_VBoxBldProg_CXXFLAGS.release)
TEMPLATE_VBoxBldProg_PCHFLAGS.profile = $(TEMPLATE_VBoxBldProg_CXXFLAGS.profile)
TEMPLATE_VBoxBldProg_PCHFLAGS.kprofile= $(TEMPLATE_VBoxBldProg_CXXFLAGS.kprofile)
TEMPLATE_VBoxBldProg_LDFLAGS.x86         = -m32
TEMPLATE_VBoxBldProg_LDFLAGS.sparc32     = -m32
TEMPLATE_VBoxBldProg_LDFLAGS.amd64       = -m64
TEMPLATE_VBoxBldProg_LDFLAGS.sparc64     = -m64
 ifeq ($(KBUILD_HOST),linux)
TEMPLATE_VBoxBldProg_LIBS                = pthread m rt dl
 else ifeq ($(KBUILD_HOST),os2)
TEMPLATE_VBoxBldProg_TOOL                = GXX3OMF
TEMPLATE_VBoxBldProg_LIBS                = socket iconv
 else ifeq ($(KBUILD_HOST),darwin)
TEMPLATE_VBoxBldProg_TOOL                = $(VBOX_GCC_TOOL)
  if "$(VBOX_DEF_MACOSX_VERSION_MIN)" == "10.7" || "$(VBOX_DARWIN_HOST_VERSION_MAJOR)" == "7"
TEMPLATE_VBoxBldProg_DEFS.darwin         = $(VBOX_DARWIN_DEF_SDK_10_7_DEFS)
TEMPLATE_VBoxBldProg_CFLAGS.darwin       = $(VBOX_DARWIN_DEF_SDK_10_7_CFLAGS) -fno-common
TEMPLATE_VBoxBldProg_CXXFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_10_7_CXXFLAGS)
TEMPLATE_VBoxBldProg_PCHFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_10_7_CXXFLAGS)
TEMPLATE_VBoxBldProg_OBJCFLAGS.darwin    = $(VBOX_DARWIN_DEF_SDK_10_7_OBJCFLAGS) $(VBOX_GCC_PEDANTIC_C)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS.darwin  = $(VBOX_DARWIN_DEF_SDK_10_7_OBJCXXFLAGS) $(VBOX_GCC_PEDANTIC_CXX)
TEMPLATE_VBoxBldProg_LDFLAGS.darwin      = $(VBOX_DARWIN_DEF_SDK_10_7_LDFLAGS)
  else if "$(VBOX_DEF_MACOSX_VERSION_MIN)" == "10.6" || "$(VBOX_DARWIN_HOST_VERSION_MAJOR)" == "6"
TEMPLATE_VBoxBldProg_DEFS.darwin         = $(VBOX_DARWIN_DEF_SDK_10_6_DEFS)
TEMPLATE_VBoxBldProg_CFLAGS.darwin       = $(VBOX_DARWIN_DEF_SDK_10_6_CFLAGS) -fno-common
TEMPLATE_VBoxBldProg_CXXFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_10_6_CXXFLAGS)
TEMPLATE_VBoxBldProg_PCHFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_10_6_CXXFLAGS)
TEMPLATE_VBoxBldProg_OBJCFLAGS.darwin    = $(VBOX_DARWIN_DEF_SDK_10_6_OBJCFLAGS) $(VBOX_GCC_PEDANTIC_C)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS.darwin  = $(VBOX_DARWIN_DEF_SDK_10_6_OBJCXXFLAGS) $(VBOX_GCC_PEDANTIC_CXX)
TEMPLATE_VBoxBldProg_LDFLAGS.darwin      = $(VBOX_DARWIN_DEF_SDK_10_6_LDFLAGS)
  else if "$(VBOX_DEF_MACOSX_VERSION_MIN)" == "10.5" || "$(VBOX_DARWIN_HOST_VERSION_MAJOR)" == "5" || defined(VBOX_MACOS_10_5_WORKAROUND)
TEMPLATE_VBoxBldProg_DEFS.darwin         = $(VBOX_DARWIN_DEF_SDK_10_5_DEFS)
TEMPLATE_VBoxBldProg_CFLAGS.darwin       = $(VBOX_DARWIN_DEF_SDK_10_5_CFLAGS) -fno-common
TEMPLATE_VBoxBldProg_CXXFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_10_5_CXXFLAGS)
TEMPLATE_VBoxBldProg_PCHFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_10_5_CXXFLAGS)
TEMPLATE_VBoxBldProg_OBJCFLAGS.darwin    = $(VBOX_DARWIN_DEF_SDK_10_5_OBJCFLAGS) $(VBOX_GCC_PEDANTIC_C)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS.darwin  = $(VBOX_DARWIN_DEF_SDK_10_5_OBJCXXFLAGS) $(VBOX_GCC_PEDANTIC_CXX)
TEMPLATE_VBoxBldProg_LDFLAGS.darwin      = $(VBOX_DARWIN_DEF_SDK_10_5_LDFLAGS)
  else
TEMPLATE_VBoxBldProg_DEFS.darwin         = $(VBOX_DARWIN_DEF_SDK_DEFS)
TEMPLATE_VBoxBldProg_CFLAGS.darwin       = $(VBOX_DARWIN_DEF_SDK_CFLAGS) -fno-common
TEMPLATE_VBoxBldProg_CXXFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_CXXFLAGS)
TEMPLATE_VBoxBldProg_PCHFLAGS.darwin     = $(VBOX_DARWIN_DEF_SDK_CXXFLAGS)
TEMPLATE_VBoxBldProg_OBJCFLAGS.darwin    = $(VBOX_DARWIN_DEF_SDK_OBJCFLAGS) $(VBOX_GCC_PEDANTIC_C)
TEMPLATE_VBoxBldProg_OBJCXXFLAGS.darwin  = $(VBOX_DARWIN_DEF_SDK_OBJCXXFLAGS) $(VBOX_GCC_PEDANTIC_CXX)
TEMPLATE_VBoxBldProg_LDFLAGS.darwin      = $(VBOX_DARWIN_DEF_SDK_LDFLAGS)
  endif
TEMPLATE_VBoxBldProg_LIBS                =
 else ifeq ($(KBUILD_HOST),haiku)
TEMPLATE_VBoxBldProg_TOOL                = GXX3
TEMPLATE_VBoxBldProg_LIBS                = network iconv
TEMPLATE_VBoxBldProg_LIBPATH            += \
	/boot/common/lib
 else if1of ($(KBUILD_HOST), freebsd openbsd)
TEMPLATE_VBoxBldProg_TOOL                = GXX3
TEMPLATE_VBoxBldProg_LIBS                = pthread
TEMPLATE_VBoxBldProg_INCS               += \
	/usr/include \
	/usr/X11R6/include \
	/usr/local/include
TEMPLATE_VBoxBldProg_LIBPATH            += \
	/usr/lib \
	/usr/X11R6/lib \
	/usr/local/lib
 else ifeq ($(KBUILD_HOST),netbsd)
TEMPLATE_VBoxBldProg_TOOL                = GXX3
TEMPLATE_VBoxBldProg_LIBS                = pthread
TEMPLATE_VBoxBldProg_INCS               += \
	/usr/include \
	/usr/X11R7/include
TEMPLATE_VBoxBldProg_LIBPATH            += \
	/usr/lib \
	/usr/X11R7/lib
 else ifeq ($(KBUILD_HOST),solaris)
TEMPLATE_VBoxBldProg_TOOL                = GXX3PLAIN
TEMPLATE_VBoxBldProg_LIBS                = rt
 else
$(warning Warning: VBOX Build: Target $(KBUILD_HOST) is not officially supported!)
 endif

endif # !win


#
# Advanced build programs using IPRT and stuff.
#
TEMPLATE_VBoxAdvBldProg = Advanced VBox Build Program
TEMPLATE_VBoxAdvBldProg_EXTENDS = VBoxBldProg
TEMPLATE_VBoxAdvBldProg_SDKS    = $(TEMPLATE_VBoxBldProg_SDKS)
TEMPLATE_VBoxAdvBldProg_SDKS.win= $(TEMPLATE_VBoxBldProg_SDKS.win) VBOX_NTDLL
TEMPLATE_VBoxAdvBldProg_DEFS    = $(TEMPLATE_VBoxBldProg_DEFS) IN_RT_R3 IN_ADV_BLD_PROG
ifeq ($(KBUILD_HOST),win)
 TEMPLATE_VBoxAdvBldProg_CFLAGS = $(TEMPLATE_VBoxBldProg_CFLAGS) $(VBOX_VCC_WERR)
 TEMPLATE_VBoxAdvBldProg_CXXFLAGS = $(TEMPLATE_VBoxBldProg_CXXFLAGS) $(VBOX_VCC_WERR)
 TEMPLATE_VBoxAdvBldProg_PCHFLAGS = $(TEMPLATE_VBoxAdvBldProg_CXXFLAGS)
endif
TEMPLATE_VBoxAdvBldProg_LIBS    = \
	$(PATH_STAGE_LIB)/RuntimeBldProg$(VBOX_HOSTSUFF_LIB) \
	$(TEMPLATE_VBoxBldProg_LIBS)
TEMPLATE_VBoxAdvBldProg_LIBS.darwin = \
	$(TEMPLATE_VBoxAdvBldProg_LIBS) \
	iconv \
	$(TEMPLATE_VBoxBldProg_LIBS.darwin)
TEMPLATE_VBoxAdvBldProg_LIBS.freebsd = \
	$(TEMPLATE_VBoxAdvBldProg_LIBS) \
	iconv \
	rt \
	$(TEMPLATE_VBoxBldProg_LIBS.freebsd)
TEMPLATE_VBoxAdvBldProg_LIBS.linux = \
	$(TEMPLATE_VBoxAdvBldProg_LIBS) \
	$(TEMPLATE_VBoxBldProg_LIBS.linux)
TEMPLATE_VBoxAdvBldProg_LIBS.solaris = \
	$(TEMPLATE_VBoxAdvBldProg_LIBS) \
	contract \
	kstat \
	rt \
	socket \
	nsl \
	$(TEMPLATE_VBoxBldProg_LIBS.solaris)


#
# Windows rc workaround for crosscompiling.
# (Some (old) Wine versions fails loading msvcrt.dll from the VCC bin directory.)
#
ifneq ($(KBUILD_HOST),win)
 TOOL_VCC80X86_RC    := $(EXEC_X86_WIN32) $(KBUILD_DEVTOOLS)/win.x86/bin/rc.exe
 TOOL_VCC80AMD64_RC  := $(EXEC_X86_WIN32) $(KBUILD_DEVTOOLS)/win.x86/bin/rc.exe
 TOOL_VCC70_RC       := $(EXEC_X86_WIN32) $(KBUILD_DEVTOOLS)/win.x86/bin/rc.exe
 WIN32_MC = $(EXEC_X86_WIN32) $(KBUILD_DEVTOOLS)/win.x86/bin/mc.exe
else
 WIN32_MC = $(EXEC_X86_WIN32) $(firstword $(wildcard \
	$(PATH_SDK_$(VBOX_WINPSDK)_BIN)/MC.Exe\
	$(PATH_SDK_WINPSDK_BIN)/MC.Exe\
	$(PATH_SDK_WINPSDK)/Bin/MC.Exe\
	$(PATH_SDK_WIN32SDK_BIN)/MC.Exe\
	$(PATH_SDK_WIN64SDK_BIN)/MC.Exe\
	$(KBUILD_DEVTOOLS)/win.x86/bin/mc.exe\
	) Sorry_Cannot_find_mc_in_the_PSDK)
endif


#
# Template for building R3 programs for the guest additions.
#
TEMPLATE_VBOXGUESTR3EXE           = VBox Guest Program
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBOXGUESTR3EXE_EXTENDS  = VBOXR3EXE
 TEMPLATE_VBOXGUESTR3EXE_SDKS     = ReorderCompilerIncs $(VBOX_WINPSDK_GST) VBOX_NTDLL
 TEMPLATE_VBOXGUESTR3EXE_CFLAGS   = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBOXR3EXE_CFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBOXGUESTR3EXE_CXXFLAGS = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBOXR3EXE_CFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
 TEMPLATE_VBOXGUESTR3EXE_LDFLAGS  = $(filter-out /DISALLOWLIB:libcmt$(VBOX_VCC_CRT_TYPE).lib /DISALLOWLIB:libcpmt$(VBOX_VCC_CRT_TYPE).lib, $(TEMPLATE_VBOXR3EXE_LDFLAGS)) \
	/DISALLOWLIB:msvcrt$(VBOX_VCC_CRT_TYPE).lib \
	/DISALLOWLIB:msvcprt$(VBOX_VCC_CRT_TYPE).lib
 TEMPLATE_VBOXGUESTR3EXE_LIBS.x86           = \
 	$(PATH_TOOL_$(TEMPLATE_VBOXGUESTR3EXE_TOOL.win.x86)_LIB)/oldnames.lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXGUESTR3EXE_TOOL.win.x86)_LIB)/libcmt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXGUESTR3EXE_TOOL.win.x86)_LIB)/libcpmt$(VBOX_VCC_CRT_TYPE).lib
 TEMPLATE_VBOXGUESTR3EXE_LIBS.amd64         = \
 	$(PATH_TOOL_$(TEMPLATE_VBOXGUESTR3EXE_TOOL.win.amd64)_LIB)/oldnames.lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXGUESTR3EXE_TOOL.win.amd64)_LIB)/libcmt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_VBOXGUESTR3EXE_TOOL.win.amd64)_LIB)/libcpmt$(VBOX_VCC_CRT_TYPE).lib
 # Hack for running on NT3x, NT4, W2K and XP w/o SP: Change OS and subsystem version in the image.
 # The .bss section trick is for NT 3.1 which doesn't support merging initialized and uninitialized
 # section because it doesn't recognize Misc.VirtualSize.  VBOX_PE_SET_VERSION will unset the !K flag.
 # HACK ALERT! Double expansion of $$(NLTAB).
 TEMPLATE_VBOXGUESTR3EXE_POST_CMDS.win.x86  = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION) $(out)$$(NLTAB)$(TEMPLATE_VBOXR3EXE_POST_CMDS))
 TEMPLATE_VBOXGUESTR3EXE_LNK_DEPS.win.x86   = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION))
 TEMPLATE_VBOXGUESTR3EXE_LDFLAGS.win.x86    = -Section:.bss,RW!K $(TEMPLATE_VBOXR3EXE_LDFLAGS.win.x86)

 if defined(VBOX_WITH_MORE_NT4_COMPAT_BINARIES) && "$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)" == "win.x86"
  TEMPLATE_VBOXGUESTR3EXE_LIBS.win.x86 = $(NO_SUCH_VARIABLE)# Ditch RuntimeR3VccTricks2
 endif
else # the gcc guys
 TEMPLATE_VBOXGUESTR3EXE_EXTENDS  = VBOXR3EXE
 TEMPLATE_VBOXGUESTR3EXE_TOOL    := $(subst GXX,GCC,$(TEMPLATE_VBOXR3EXE_TOOL))
 TEMPLATE_VBOXGUESTR3EXE_CXXFLAGS = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) -fno-exceptions -fno-rtti
 # Do not inherit sanitizer flags from VBOXR3EXE in guest executables.  Deal with them separately.
 TEMPLATE_VBOXGUESTR3EXE_CXXFLAGS.debug = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBOXGUESTR3EXE_CFLAGS.debug = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBOXGUESTR3EXE_LDFLAGS.linux = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBOXR3EXE_LDFLAGS.linux))
 TEMPLATE_VBOXGUESTR3EXE_LDFLAGS.debug = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBOXGUESTR3EXE_LDFLAGS  = $(filter-out '$(VBOX_GCC_RPATH_OPT)%,$(TEMPLATE_VBOXR3EXE_LDFLAGS))
endif
TEMPLATE_VBOXGUESTR3EXE_INST      = $(INST_ADDITIONS)
TEMPLATE_VBOXGUESTR3EXE_DEFS     := $(filter-out $(ARCH_BITS_DEFS), $(TEMPLATE_VBOXR3EXE_DEFS)) IN_GUEST IN_GUEST_R3 IN_RT_R3 $(VBOX_GC_ARCH_BITS_DEFS) RT_NEED_NEW_AND_DELETE
TEMPLATE_VBOXGUESTR3EXE_DEFS.linux := $(TEMPLATE_VBOXR3EXE_DEFS.linux) LOG_USE_C99 RT_WITHOUT_EXEC_ALLOC
ifeq ($(KBUILD_TARGET),linux) # As few libs as possible on linux.
 TEMPLATE_VBOXGUESTR3EXE_LIBS     = pthread rt m dl
else if1of ($(KBUILD_TARGET), darwin freebsd openbsd)
 TEMPLATE_VBOXGUESTR3EXE_LIBS     = $(TEMPLATE_VBOXR3EXE_LIBS) iconv
else ifeq ($(KBUILD_TARGET), solaris)
 TEMPLATE_VBOXGUESTR3EXE_LIBS     = $(TEMPLATE_VBOXR3EXE_LIBS) nsl
endif

# Use older versions of APIs which were improved in versions of glibc later
# than what we are targetting, and do not use the stack protector, which
# needs glibc 2.4 or later.
TEMPLATE_VBOXGUESTR3EXE_CXXFLAGS.linux    = \
	-include $(PATH_ROOT)/include/iprt/linux/symvers.h \
	$(VBOX_GCC_fno-stack-protector)
TEMPLATE_VBOXGUESTR3EXE_CFLAGS.linux      = $(TEMPLATE_VBOXGUESTR3EXE_CXXFLAGS.linux)
# The GNU_HASH ELF tag is not supported by older systems.
TEMPLATE_VBOXGUESTR3EXE_LDFLAGS.linux      += $(VBOX_LD_hash_style_sysv)

#
# Template for building normal R3 programs for the guest additions.
#
TEMPLATE_NewVBoxGuestR3Exe = VBox Guest Program w/ IPRT and VBGL.
TEMPLATE_NewVBoxGuestR3Exe_EXTENDS  = VBOXGUESTR3EXE
TEMPLATE_NewVBoxGuestR3Exe_LIBS     = \
	$(VBOX_LIB_IPRT_GUEST_R3) \
	$(VBOX_LIB_VBGL_R3) \
	$(VBOX_LIB_IPRT_GUEST_R3) \
	$(TEMPLATE_VBOXGUESTR3EXE_LIBS)
ifeq ($(KBUILD_TARGET),solaris)
TEMPLATE_NewVBoxGuestR3Exe_LIBS += contract
endif

#
# Template for building normal R3 programs for the guest additions, strict.
#
TEMPLATE_VBoxGuestR3Exe = VBox Guest Program w/ IPRT and VBGL.
TEMPLATE_VBoxGuestR3Exe_EXTENDS  = NewVBoxGuestR3Exe
TEMPLATE_VBoxGuestR3Exe_EXTENDS_BY = appending
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxGuestR3Exe_CFLAGS      += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxGuestR3Exe_CXXFLAGS    += $(VBOX_VCC_WERR)
 if1of ($(VBOX_VCC_TOOL_STEM), VCC120)
  # VBoxDrvInst.cpp(520) : warning C4313: 'wprintf'  : '%d' in format string conflicts with argument 1 of type 'const TCHAR *' [false positive - buggy compiler?]
  TEMPLATE_VBoxGuestR3Exe_CXXFLAGS   += -wd4313
 endif
 TEMPLATE_VBoxGuestR3Exe_LDFLAGS     += $(VBOX_VCC_LD_WERR)
else
 TEMPLATE_VBoxGuestR3Exe_CFLAGS      += $(VBOX_GCC_WERR)
 TEMPLATE_VBoxGuestR3Exe_CXXFLAGS    += $(VBOX_GCC_WERR)
endif

#
# Template for building R3 (dynamic) libraries for the guest additions.
#
TEMPLATE_VBOXGUESTR3DLL           = VBox Guest User Dynamic Libraries
TEMPLATE_VBOXGUESTR3DLL_EXTENDS   = VBOXGUESTR3EXE
## @todo add a INSTFUN that separates dlls and libs.
ifn1of ($(KBUILD_TARGET), darwin os2 win)
 TEMPLATE_VBOXGUESTR3DLL_DEFS     = $(TEMPLATE_VBOXGUESTR3EXE_DEFS) PIC
 TEMPLATE_VBOXGUESTR3DLL_CFLAGS   = $(TEMPLATE_VBOXGUESTR3EXE_CFLAGS) -fPIC
 TEMPLATE_VBOXGUESTR3DLL_CXXFLAGS = $(TEMPLATE_VBOXGUESTR3EXE_CXXFLAGS) -fPIC -fno-exceptions
 TEMPLATE_VBOXGUESTR3DLL_LDFLAGS  = $(TEMPLATE_VBOXGUESTR3EXE_LDFLAGS) -fPIC
endif

#
# Template for building normal R3 (dynamic) libraries for the guest additions, allows warnings.
#
## @todo rename to VBoxGuestR3DllWarn
TEMPLATE_NewVBoxGuestR3Dll = VBox Guest User Dynamic Libraries w/ IPRT and VBGL.
TEMPLATE_NewVBoxGuestR3Dll_EXTENDS  = VBOXGUESTR3DLL
TEMPLATE_NewVBoxGuestR3Dll_LIBS     = \
	$(VBOX_LIB_IPRT_GUEST_R3_SHARED) \
	$(VBOX_LIB_VBGL_R3_SHARED) \
	$(VBOX_LIB_IPRT_GUEST_R3_SHARED) \
	$(TEMPLATE_VBOXGUESTR3DLL_LIBS)

#
# Template for building normal R3 (dynamic) libraries for the guest additions, strict.
#
TEMPLATE_VBoxGuestR3Dll = VBox Guest User Dynamic Libraries w/ IPRT and VBGL.
TEMPLATE_VBoxGuestR3Dll_EXTENDS  = NewVBoxGuestR3Dll
TEMPLATE_VBoxGuestR3Dll_EXTENDS_BY = appending
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxGuestR3Dll_CFLAGS      += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxGuestR3Dll_CXXFLAGS    += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxGuestR3Dll_LDFLAGS     += $(VBOX_VCC_LD_WERR)
else
 TEMPLATE_VBoxGuestR3Dll_CFLAGS      += $(VBOX_GCC_WERR)
 TEMPLATE_VBoxGuestR3Dll_CXXFLAGS    += $(VBOX_GCC_WERR)
endif

#
# Variant of VBoxGuestR3Dll that requires Windows 2000 or later for x86, and W2K3 for AMD64.
#
TEMPLATE_VBoxGuestR3DllMinW2K = VBox Guest User Dynamic Libraries w/ IPRT and VBGL.
TEMPLATE_VBoxGuestR3DllMinW2K_EXTENDS  = VBoxGuestR3Dll
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxGuestR3DllMinW2K_LDFLAGS.win.x86 = $(filter-out -Section:.bss$(COMMA)RW!K,$(TEMPLATE_VBoxGuestR3Dll_LDFLAGS.win.x86))
 TEMPLATE_VBoxGuestR3DllMinW2K_POST_CMDS.win.x86 = $(subst $(VBOX_PE_SET_VERSION), $(VBOX_PE_SET_VERSION) --w2k,$(TEMPLATE_VBoxGuestR3Dll_POST_CMDS.win.x86))
 TEMPLATE_VBoxGuestR3DllMinW2K_POST_CMDS.win.amd64 = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION) --w2k3 $(out)$$(NLTAB)$(TEMPLATE_VBoxGuestR3Dll_POST_CMDS.win.amd64))
 TEMPLATE_VBoxGuestR3DllMinW2K_LNK_DEPS.win.amd64  = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION)) $(TEMPLATE_VBoxGuestR3Dll_LNK_DEPS.win.amd64)
endif

#
# Variant of VBoxGuestR3Dll that requires Windows Vista or later.
#
TEMPLATE_VBoxGuestR3DllMinVista = VBox Guest User Dynamic Libraries w/ IPRT and VBGL.
TEMPLATE_VBoxGuestR3DllMinVista_EXTENDS  = VBoxGuestR3Dll
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxGuestR3DllMinVista_LDFLAGS.win.x86 = $(filter-out -Section:.bss$(COMMA)RW!K,$(TEMPLATE_VBoxGuestR3Dll_LDFLAGS.win.x86))
 TEMPLATE_VBoxGuestR3DllMinVista_POST_CMDS.win.x86 = $(subst $(VBOX_PE_SET_VERSION), $(VBOX_PE_SET_VERSION) --vista,$(TEMPLATE_VBoxGuestR3Dll_POST_CMDS.win.x86))
 TEMPLATE_VBoxGuestR3DllMinVista_POST_CMDS.win.amd64 = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION) --vista $(out)$$(NLTAB)$(TEMPLATE_VBoxGuestR3Dll_POST_CMDS.win.amd64))
 TEMPLATE_VBoxGuestR3DllMinVista_LNK_DEPS.win.amd64  = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION)) $(TEMPLATE_VBoxGuestR3Dll_LNK_DEPS.win.amd64)
endif

#
# Template for building normal R3 (dynamic) libraries for the guest additions with Visual C++ 2013 or later, strict.
#
TEMPLATE_NewerVccVBoxGuestR3Dll          = VBOXGUESTR3DLL with the newer Visual C++ version (2013 or later).
TEMPLATE_NewerVccVBoxGuestR3Dll_EXTENDS  = VBOXGUESTR3DLL
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.x86    = $(VBOX_NEWER_VCC_TOOL_STEM)X86
 TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.amd64  = $(VBOX_NEWER_VCC_TOOL_STEM)AMD64
 TEMPLATE_NewerVccVBoxGuestR3Dll_CXXFLAGS        = \
 	$(filter-out $(VBOX_VCC_WARN_ALL) $(VBOX_VCC_WERR), $(TEMPLATE_VBOXGUESTR3DLL_CXXFLAGS)) \
	$(VBOX_NEWER_VCC_WARN_ALL) $(VBOX_VCC_WERR)
 TEMPLATE_NewerVccVBoxGuestR3Dll_CFLAGS          = $(TEMPLATE_NewerVccVBOXGUESTR3DLL_CXXFLAGS)
# Hack begin
# Does not work when building x86 for amd64 build (No rule to make target /oldnames.lib).
# TEMPLATE_NewerVccVBoxGuestR3Dll_LIBS.x86        = \
# 	$(subst $(PATH_TOOL_$(TEMPLATE_VBOXGUESTR3DLL_TOOL.win.x86)_LIB),$(PATH_TOOL_$(TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.x86)_LIB), $(TEMPLATE_VBOXGUESTR3DLL_LIBS.x86))
# TEMPLATE_NewerVccVBoxGuestR3Dll_LIBS.amd64      = \
# 	$(subst $(PATH_TOOL_$(TEMPLATE_VBOXGUESTR3DLL_TOOL.win.amd64)_LIB),$(PATH_TOOL_$(TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.amd64)_LIB), $(TEMPLATE_VBOXGUESTR3DLL_LIBS.amd64))
# Directly assign TEMPLATE_NewerVccVBoxGuestR3Dll_LIBS.
 TEMPLATE_NewerVccVBoxGuestR3Dll_LIBS.x86           = \
 	$(PATH_TOOL_$(TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.x86)_LIB)/oldnames.lib \
 	$(PATH_TOOL_$(TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.x86)_LIB)/libcmt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.x86)_LIB)/libcpmt$(VBOX_VCC_CRT_TYPE).lib
 TEMPLATE_NewerVccVBoxGuestR3Dll_LIBS.amd64         = \
 	$(PATH_TOOL_$(TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.amd64)_LIB)/oldnames.lib \
 	$(PATH_TOOL_$(TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.amd64)_LIB)/libcmt$(VBOX_VCC_CRT_TYPE).lib \
 	$(PATH_TOOL_$(TEMPLATE_NewerVccVBoxGuestR3Dll_TOOL.win.amd64)_LIB)/libcpmt$(VBOX_VCC_CRT_TYPE).lib
# Hack end
endif

#
# Variant of NewerVccVBoxGuestR3Dll that requires Windows Vista or later.
#
TEMPLATE_NewerVccVBoxGuestR3DllMinVista = NewerVccVBoxGuestR3Dll with the newer Visual C++ version (2013 or later).
TEMPLATE_NewerVccVBoxGuestR3DllMinVista_EXTENDS  = NewerVccVBoxGuestR3Dll
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_NewerVccVBoxGuestR3DllMinVista_LDFLAGS.win.x86 = $(filter-out -Section:.bss$(COMMA)RW!K,$(TEMPLATE_NewerVccVBoxGuestR3Dll_LDFLAGS.win.x86))
 TEMPLATE_NewerVccVBoxGuestR3DllMinVista_POST_CMDS.win.x86 = $(subst $(VBOX_PE_SET_VERSION), $(VBOX_PE_SET_VERSION) --vista,$(TEMPLATE_NewerVccVBoxGuestR3Dll_POST_CMDS.win.x86))
 TEMPLATE_NewerVccVBoxGuestR3DllMinVista_POST_CMDS.win.amd64 = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION) --vista $(out)$$(NLTAB)$(TEMPLATE_NewerVccVBoxGuestR3Dll_POST_CMDS.win.amd64))
 TEMPLATE_NewerVccVBoxGuestR3DllMinVista_LNK_DEPS.win.amd64  = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION)) $(TEMPLATE_NewerVccVBoxGuestR3Dll_LNK_DEPS.win.amd64)
endif

#
# Template for building R3 (static) libraries for the guest additions, allows warnings.
#
## @todo rename to VBoxGuestR3LibWarn.
TEMPLATE_VBOXGUESTR3LIB           = VBox Guest User Libraries
TEMPLATE_VBOXGUESTR3LIB_EXTENDS   = VBOXGUESTR3EXE
TEMPLATE_VBOXGUESTR3LIB_INST      = $(INST_ADDITIONS_LIB)

#
# Template for building R3 (static) libraries for the guest additions, strict.
#
TEMPLATE_VBoxGuestR3Lib = VBox Guest User Dynamic Libraries w/ IPRT and VBGL.
TEMPLATE_VBoxGuestR3Lib_EXTENDS  = VBOXGUESTR3LIB
TEMPLATE_VBoxGuestR3Lib_EXTENDS_BY = appending
ifeq ($(KBUILD_TARGET),win)
 TEMPLATE_VBoxGuestR3Lib_CFLAGS      += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxGuestR3Lib_CXXFLAGS    += $(VBOX_VCC_WERR)
 TEMPLATE_VBoxGuestR3Lib_LDFLAGS     += $(VBOX_VCC_LD_WERR)
else
 TEMPLATE_VBoxGuestR3Lib_CFLAGS      += $(VBOX_GCC_WERR)
 TEMPLATE_VBoxGuestR3Lib_CXXFLAGS    += $(VBOX_GCC_WERR)
endif

#
# Template for building R3 programs for the guest additions (no -pedantic)
#
TEMPLATE_VBOXGUESTR3NPEXE          = VBox Guest Program Non-pedantic
TEMPLATE_VBOXGUESTR3NPEXE_EXTENDS  = VBOXGUESTR3EXE
ifneq ($(KBUILD_TARGET),win) # gcc only
 TEMPLATE_VBOXGUESTR3NPEXE_CXXFLAGS = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_CXX),$(TEMPLATE_VBOXGUESTR3EXE_CXXFLAGS)) \
 	-Wno-sign-compare
 TEMPLATE_VBOXGUESTR3NPEXE_CFLAGS   = $(filter-out $(VBOX_GCC_WERR) $(VBOX_GCC_WARN_MASOCHISTIC) $(VBOX_GCC_PEDANTIC_C)  ,$(TEMPLATE_VBOXGUESTR3EXE_CFLAGS)) \
 	-Wno-sign-compare
endif

#
# Template for building R3 (dynamic) libraries for the guest additions (no -pedantic)
#
TEMPLATE_VBOXGUESTR3NPDLL           = VBox Guest User Dynamic Libraries Non-pedantic
TEMPLATE_VBOXGUESTR3NPDLL_EXTENDS   = VBOXGUESTR3NPEXE
## @todo add a INSTFUN that separates dlls and libs.
ifn1of ($(KBUILD_TARGET), darwin os2 win)
 TEMPLATE_VBOXGUESTR3NPDLL_DEFS     = $(TEMPLATE_VBOXGUESTR3NPEXE_DEFS) PIC
 TEMPLATE_VBOXGUESTR3NPDLL_CFLAGS   = $(TEMPLATE_VBOXGUESTR3NPEXE_CFLAGS) -fPIC
 TEMPLATE_VBOXGUESTR3NPDLL_CXXFLAGS = $(TEMPLATE_VBOXGUESTR3NPEXE_CXXFLAGS) -fPIC -fno-exceptions
 TEMPLATE_VBOXGUESTR3NPDLL_LDFLAGS  = $(TEMPLATE_VBOXGUESTR3NPEXE_LDFLAGS) -fPIC
endif

#
# Template for building R3 (static) libraries for the guest additions (no -pedantic)
#
TEMPLATE_VBOXGUESTR3NPLIB           = VBox Guest User Libraries Non-pedantic
TEMPLATE_VBOXGUESTR3NPLIB_EXTENDS   = VBOXGUESTR3NPEXE
TEMPLATE_VBOXGUESTR3NPLIB_INST      = $(INST_ADDITIONS_LIB)


#
# Template for XFree86 guest modules (relocatable module, i.e. sysmod).
# This mostly about zapping the VBOXR3EXE linker flags and libraries.
#
TEMPLATE_VBOXGUESTR3XF86MOD       = VBox XFree86 Guest Module
TEMPLATE_VBOXGUESTR3XF86MOD_EXTENDS = VBOXGUESTR3EXE
TEMPLATE_VBOXGUESTR3XF86MOD_LIBS.$(KBUILD_TYPE)      = $(NO_SUCH_VARIABLE)
TEMPLATE_VBOXGUESTR3XF86MOD_LIBS.$(KBUILD_TARGET)    = $(NO_SUCH_VARIABLE)
TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.$(KBUILD_TARGET) = $(NO_SUCH_VARIABLE)
# The GNU_HASH ELF tag is not supported by older glibc dynamic linkers.
TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.linux = $(subst -Wl$(COMMA),,$(VBOX_LD_hash_style_sysv))
TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.$(KBUILD_TYPE)   = $(NO_SUCH_VARIABLE)
TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS          = -r
if1of ($(KBUILD_TARGET), dragonfly freebsd linux netbsd openbsd) # the gnu ld guys.
 TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.release = -S
 TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.x86     = -m elf_i386
 TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.amd64   = -m elf_x86_64
endif
TEMPLATE_VBOXGUESTR3XF86MOD_CFLAGS  = $(TEMPLATE_VBOXGUESTR3EXE_CFLAGS) -fno-pie -fno-merge-constants -std=c99 -ffreestanding
TEMPLATE_VBOXGUESTR3XF86MOD_CXXFLAGS= $(TEMPLATE_VBOXGUESTR3EXE_CXXFLAGS) -fno-pie -fno-merge-constants -ffreestanding
TEMPLATE_VBOXGUESTR3XF86MOD_CFLAGS.linux  = $(VBOX_GCC_fno-stack-protector) # Remove symvers.h
TEMPLATE_VBOXGUESTR3XF86MOD_CXXFLAGS.linux = $(VBOX_GCC_fno-stack-protector) # Remove symvers.h
TEMPLATE_VBOXGUESTR3XF86MOD_SYSSUFF = .o
TEMPLATE_VBOXGUESTR3XF86MOD_LIBS  = \
	$(VBOX_LIB_VBGL_R3_XFREE86)
TEMPLATE_VBOXGUESTR3XF86MOD_DEFS  = $(TEMPLATE_VBOXGUESTR3DLL_DEFS) VBOX_GUESTR3XF86MOD RTMEM_NO_WRAP_TO_EF_APIS


#
# Template for XFree86 guest libraries.
#
TEMPLATE_VBOXGUESTR3XF86LIB         = VBox XFree86 Guest Library
TEMPLATE_VBOXGUESTR3XF86LIB_EXTENDS = VBOXGUESTR3XF86MOD
TEMPLATE_VBOXGUESTR3XF86LIB_INST    = $(INST_ADDITIONS_LIB)


#
# Template for X.org guest modules (shared libs).
# This mostly about zapping unnecessary LIBS from VBOXGUESTR3DLL and adding some flags.
#
TEMPLATE_VBOXGUESTR3XORGMOD       = VBox X.org Guest Module
TEMPLATE_VBOXGUESTR3XORGMOD_EXTENDS = VBOXGUESTR3DLL
TEMPLATE_VBOXGUESTR3XORGMOD_LIBS.$(KBUILD_TYPE)     = $(NO_SUCH_VARIABLE)
TEMPLATE_VBOXGUESTR3XORGMOD_LIBS.$(KBUILD_TARGET)   = $(NO_SUCH_VARIABLE)
TEMPLATE_VBOXGUESTR3XORGMOD_CFLAGS                  = $(TEMPLATE_VBOXGUESTR3DLL_CFLAGS) -std=c99
if1of ($(KBUILD_TARGET), linux)
 TEMPLATE_VBOXGUESTR3XORGMOD_CFLAGS                += -Wno-conversion -Wno-unused-parameter
endif
TEMPLATE_VBOXGUESTR3XORGMOD_DEFS = $(TEMPLATE_VBOXGUESTR3DLL_DEFS) VBOX_GUESTR3XORGMOD RTMEM_NO_WRAP_TO_EF_APIS
ifeq ($(KBUILD_TARGET_ARCH),amd64)
 TEMPLATE_VBOXGUESTR3XORGMOD_DEFS += _XSERVER64
endif
TEMPLATE_VBOXGUESTR3XORGMOD_LIBS = \
	$(VBOX_LIB_VBGL_R3_XORG)
TEMPLATE_VBOXGUESTR3XORGMOD_LIBS.freebsd += \
	iconv


#
# Template for X.Org guest libraries.
#
TEMPLATE_VBOXGUESTR3XORGLIB         = VBox X.Org Guest Library
TEMPLATE_VBOXGUESTR3XORGLIB_EXTENDS = VBOXGUESTR3XORGMOD
TEMPLATE_VBOXGUESTR3XORGLIB_INST    = $(INST_ADDITIONS_LIB)


#
# Template for building R0 drivers for the guest additions.
#
TEMPLATE_VBOXGUESTR0             = VBox Guest Driver
TEMPLATE_VBOXGUESTR0_EXTENDS     = VBOXR0DRV
TEMPLATE_VBOXGUESTR0_INST        = $(INST_ADDITIONS)
TEMPLATE_VBOXGUESTR0_SDKS.win.x86   = ReorderCompilerIncs $(VBOX_WINDDK_GST) $(VBOX_WINPSDK_GST)INCS
TEMPLATE_VBOXGUESTR0_SDKS.win.amd64 = ReorderCompilerIncs $(VBOX_WINDDK_GST) $(VBOX_WINPSDK_GST)INCS
TEMPLATE_VBOXGUESTR0_LIBS.win.x86   = \
	$(PATH_SDK_$(VBOX_WINDDK)_LIB)/int64.lib
TEMPLATE_VBOXGUESTR0_DEFS        = $(TEMPLATE_VBOXR0DRV_DEFS) IN_GUEST IN_GUEST_R0
TEMPLATE_VBOXGUESTR0_DEFS.linux  = RT_NO_EXPORT_SYMBOL
ifeq ($(KBUILD_TARGET),solaris)
 TEMPLATE_VBOXGUESTR0_LDFLAGS    = -r -dy
endif
ifn1of (darwin os2 win, $(KBUILD_TARGET))
 TEMPLATE_VBOXGUESTR0_CFLAGS     = $(patsubst %/VBox/SUPDrvMangling.h,%/VBox/VBoxGuestMangling.h,$(TEMPLATE_VBOXR0DRV_CFLAGS))
 TEMPLATE_VBOXGUESTR0_CXXFLAGS   = $(patsubst %/VBox/SUPDrvMangling.h,%/VBox/VBoxGuestMangling.h,$(TEMPLATE_VBOXR0DRV_CXXFLAGS))
endif


#
# Template for building R0 libraries for the guest additions.
#
TEMPLATE_VBOXGUESTR0LIB          = VBox Guest Driver Libraries
TEMPLATE_VBOXGUESTR0LIB_EXTENDS  = VBOXGUESTR0
TEMPLATE_VBOXGUESTR0LIB_INSTTYPE = stage
TEMPLATE_VBOXGUESTR0LIB_INSTTYPE.linux = stage
TEMPLATE_VBOXGUESTR0LIB_INST     = $(INST_ADDITIONS_LIB)
ifeq ($(KBUILD_TARGET),haiku)
 TEMPLATE_VBOXGUESTR0LIB_LDFLAGS = -r -dy
endif


#
# Guest additions libraries (all static).
#   The _MINI and _SHARED are both compiled as PIC and intended for linking into a .so/.dll/.dylib.
#
VBOX_LIB_IPRT_GUEST_R3           = $(VBOX_PATH_ADDITIONS_LIB)/RuntimeGuestR3$(VBOX_SUFF_LIB)
VBOX_LIB_IPRT_GUEST_R3_SHARED    = $(VBOX_PATH_ADDITIONS_LIB)/RuntimeGuestR3Shared$(VBOX_SUFF_LIB)
VBOX_LIB_IPRT_GUEST_R0           = $(VBOX_PATH_ADDITIONS_LIB)/RuntimeGuestR0$(VBOX_SUFF_LIB)
#ifeq ($(KBUILD_TARGET_ARCH),x86)
# VBOX_LIB_IPRT_GUEST_R0_NT4      = $(VBOX_PATH_ADDITIONS_LIB)/RuntimeGuestR0NT4$(VBOX_SUFF_LIB)
#else
 VBOX_LIB_IPRT_GUEST_R0_NT4      = $(VBOX_LIB_IPRT_GUEST_R0)
#endif
VBOX_LIB_VBGL_R3                 = $(VBOX_PATH_ADDITIONS_LIB)/VBoxGuestR3Lib$(VBOX_SUFF_LIB)
VBOX_LIB_VBGL_R3_XFREE86         = $(VBOX_PATH_ADDITIONS_LIB)/VBoxGuestR3LibXFree86$(VBOX_SUFF_LIB)
VBOX_LIB_VBGL_R3_XORG            = $(VBOX_PATH_ADDITIONS_LIB)/VBoxGuestR3LibXOrg$(VBOX_SUFF_LIB)
VBOX_LIB_VBGL_R3_SHARED          = $(VBOX_PATH_ADDITIONS_LIB)/VBoxGuestR3LibShared$(VBOX_SUFF_LIB)
VBOX_LIB_VBGL_R0BASE             = $(VBOX_PATH_ADDITIONS_LIB)/VBoxGuestR0LibBase$(VBOX_SUFF_LIB)
VBOX_LIB_VBGL_R0                 = $(VBOX_PATH_ADDITIONS_LIB)/VBoxGuestR0Lib$(VBOX_SUFF_LIB)
ifeq ($(KBUILD_TARGET),x86)
 VBOX_LIB_IPRT_GUEST_R3_X86      = $(VBOX_LIB_IPRT_GUEST_R3)
 VBOX_LIB_IPRT_GUEST_R3_SHARED_X86 = $(VBOX_LIB_IPRT_GUEST_R3_SHARED)
 VBOX_LIB_VBGL_R3_X86            = $(VBOX_LIB_VBGL_R3)
 VBOX_LIB_VBGL_R3_SHARED_X86     = $(VBOX_LIB_VBGL_R3_SHARED)
else
 VBOX_LIB_IPRT_GUEST_R3_X86      = $(VBOX_PATH_ADDITIONS_LIB)/RuntimeGuestR3-x86$(VBOX_SUFF_LIB)
 VBOX_LIB_IPRT_GUEST_R3_SHARED_X86 = $(VBOX_PATH_ADDITIONS_LIB)/RuntimeGuestR3Shared-x86$(VBOX_SUFF_LIB)
 VBOX_LIB_VBGL_R3_X86            = $(VBOX_PATH_ADDITIONS_LIB)/VBoxGuestR3Lib-x86$(VBOX_SUFF_LIB)
 VBOX_LIB_VBGL_R3_SHARED_X86     = $(VBOX_PATH_ADDITIONS_LIB)/VBoxGuestR3LibShared-x86$(VBOX_SUFF_LIB)
endif


#
# Check the publisher and version string.
#
# We are being very strict because the version string is visible in various
# APIs and logs and must be machine readable.
#
VBOX_VERSION_COMP_VALID_CHAR_SET = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz()[]{}+-.,
ifneq ($(VBOX_BUILD_PUBLISHER),)
 if !defined(VBOX_BUILD_TAG) && $(length $(VBOX_BUILD_PUBLISHER)) > 10
  $(error VBox: VBOX_BUILD_PUBLISHER must not be longer than 10 characters!)
 else if defined(VBOX_BUILD_TAG) && $(length $(VBOX_BUILD_PUBLISHER)) > 48
  $(error VBox: VBOX_BUILD_PUBLISHER must not be longer than 48 characters!)
 endif
 if "$(substr $(VBOX_BUILD_PUBLISHER), 1, 1)" != "_"
  $(error VBox: VBOX_BUILD_PUBLISHER must start with an underscore!)
 endif
 if "$(translate $(substr $(VBOX_BUILD_PUBLISHER),2),$(VBOX_VERSION_COMP_VALID_CHAR_SET),)" != ""
  $(error VBox: VBOX_BUILD_PUBLISHER='$(VBOX_BUILD_PUBLISHER)' contains bad characters! Valid set is:$(NLTAB)$(VBOX_VERSION_COMP_VALID_CHAR_SET))
 endif
endif

if $(words $(VBOX_VERSION_STRING)) != 1
 $(error VBox: VBOX_VERSION_STRING='$(VBOX_VERSION_STRING)' contains spaces or is empty.)
endif
if "$(subst __,-,$(VBOX_VERSION_STRING))" != "$(VBOX_VERSION_STRING)"
 $(error VBox: VBOX_VERSION_STRING='$(VBOX_VERSION_STRING)' contains double underscores.)
endif

VBOX_VER_TMP1 := $(subst _,$(SP),$(VBOX_VERSION_STRING))

if $(words $(VBOX_VER_TMP1)) > 3
 $(error VBox: VBOX_VERSION_STRING='$(VBOX_VERSION_STRING)' contains too many parts (underscores), max 3!)
endif
if "$(translate $(word 1,$(VBOX_VER_TMP1)),0123456789,)" != ".."
 $(error VBox: The x.y.z part of VBOX_VERSION_STRING='$(VBOX_VERSION_STRING)' is malformed: '$(word 1,$(VBOX_VER_TMP1))')
endif
if "$(word 1,$(VBOX_VER_TMP1))" != "$(VBOX_VERSION_STRING_RAW)"
 $(error VBox: VBOX_VERSION_STRING='$(VBOX_VERSION_STRING)' does not start with VBOX_VERSION_STRING_RAW='$(VBOX_VERSION_STRING_RAW)')
endif

if $(words $(VBOX_VER_TMP1)) == 3 || ($(words $(VBOX_VER_TMP1)) == 2 && "$(VBOX_BUILD_PUBLISHER)" == "")
 if      "$(substr $(word 2,$(VBOX_VER_TMP1)),1,4)" == "BETA"
  VBOX_VER_TMP2 = 5
 else if "$(substr $(word 2,$(VBOX_VER_TMP1)),1,5)" == "ALPHA"
  VBOX_VER_TMP2 = 6
 else if "$(substr $(word 2,$(VBOX_VER_TMP1)),1,2)" == "RC"
  VBOX_VER_TMP2 = 3
 else
  $(error VBox: VBOX_VERSION_STRING='$(VBOX_VERSION_STRING)' uses an unknown build type: '$(word 2,$(VBOX_VER_TMP1))')
 endif
 if "$(translate $(substr $(word 2,$(VBOX_VER_TMP1)),$(VBOX_VER_TMP2)),0123456789)" != ""
  $(error VBox: VBOX_VERSION_STRING='$(VBOX_VERSION_STRING)' uses an unknown build type: '$(word 2,$(VBOX_VER_TMP1))')
 endif
endif

VBOX_VER_TMP1 :=
VBOX_VER_TMP2 :=


#
# Two targets to coordinate version number changes properly. Note that the
# only way to get a really consistent build is to run 'kmk' in the top-level
# directory. If you don't run it there, you get a consistent sub-tree only.
#
VBOX_BAD_CHAR_SET   = ,;:/\$(SP)$(TAB)$(HASH)=![]@%&''()*""<>?^{}|~
VBOX_VERSION_STAMP  = $(PATH_OUT)/version-stamp-raw-api-$(translate $(VBOX_VERSION_STRING)-$(VBOX_C_YEAR)-$(VBOX_VENDOR)-$(VBOX_PRODUCT)-$(VBOX_API_VERSION)-$(VBOX_BUILD_PUBLISHER)-$(USERNAME),$(VBOX_BAD_CHAR_SET),,_)
VBOX_VERSION_HEADER = $(PATH_OUT)/version-generated.h
VBOX_VERSION_MK     = $(PATH_OUT)/version-generated.mk

$(VBOX_VERSION_STAMP): | $(PATH_ROOT)/Config.kmk
	$(call MSG_GENERATE,,$@)
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(RM) -f $(wildcard $(PATH_OUT)/version-stamp-*)
	$(QUIET)$(APPEND) $@ $(VBOX_VERSION_STRING)

$(VBOX_VERSION_HEADER): $(VBOX_VERSION_STAMP)
	$(call MSG_GENERATE,,$@)
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(RM) -f $@ $@.tmp
	$(QUIET)$(APPEND) $@.tmp '#ifndef ___version_generated_h___'
	$(QUIET)$(APPEND) $@.tmp '#define ___version_generated_h___'
	$(QUIET)$(APPEND) $@.tmp ''
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_VERSION_MAJOR $(VBOX_VERSION_MAJOR)'
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_VERSION_MINOR $(VBOX_VERSION_MINOR)'
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_VERSION_BUILD $(VBOX_VERSION_BUILD)'
ifneq ($(VBOX_VERSION_PRERELEASE),)
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_VERSION_PRERELEASE "$(strip $(VBOX_VERSION_PRERELEASE))"'
endif
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_VERSION_STRING_RAW "$(VBOX_VERSION_STRING_RAW)"'
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_VERSION_STRING "$(VBOX_VERSION_STRING)"'
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_API_VERSION_STRING "$(VBOX_API_VERSION)"'
	$(QUIET)$(APPEND) $@.tmp ''
ifdef VBOX_BUILD_SERVER_BUILD
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_BUILD_SERVER_BUILD 1'
else
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_PRIVATE_BUILD_DESC "Private build by $(USERNAME)"'
endif
	$(QUIET)$(APPEND) $@.tmp ''
	$(QUIET)$(APPEND) $@.tmp '#endif'
	$(QUIET)$(MV) -f $@.tmp $@


VBOX_PACKAGE_HEADER = $(PATH_OUT)/package-generated.h

$(VBOX_PACKAGE_HEADER):
	$(call MSG_GENERATE,,$@)
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(RM) -f $@ $@.tmp
	$(QUIET)$(APPEND) $@.tmp '#ifndef ___package_generated_h___'
	$(QUIET)$(APPEND) $@.tmp '#define ___package_generated_h___'
	$(QUIET)$(APPEND) $@.tmp ''
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_PACKAGE_STRING "$(VBOX_PACKAGE_STRING)"'
	$(QUIET)$(APPEND) $@.tmp ''
	$(QUIET)$(APPEND) $@.tmp '#endif'
	$(QUIET)$(MV) -f $@.tmp $@

VBOX_PRODUCT_HEADER = $(PATH_OUT)/product-generated.h

$(VBOX_PRODUCT_HEADER): $(VBOX_VERSION_STAMP)
	$(call MSG_GENERATE,,$@)
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(RM) -f $@ $@.tmp
	$(QUIET)$(APPEND) $@.tmp '#ifndef ___product_generated_h___'
	$(QUIET)$(APPEND) $@.tmp '#define ___product_generated_h___'
	$(QUIET)$(APPEND) $@.tmp ''
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_VENDOR "$(VBOX_VENDOR)"'
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_VENDOR_SHORT "$(VBOX_VENDOR_SHORT)"'
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_PRODUCT "$(VBOX_PRODUCT)"'
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_BUILD_PUBLISHER "$(VBOX_BUILD_PUBLISHER)"'
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_C_YEAR "$(VBOX_C_YEAR)"'
	$(QUIET)$(APPEND) $@.tmp ''
	$(QUIET)$(APPEND) $@.tmp '#endif'
	$(QUIET)$(MV) -f $@.tmp $@

#
# Used for external makefiles which cannot include Config.kmk
#
$(VBOX_VERSION_MK): $(VBOX_VERSION_STAMP)
	$(call MSG_GENERATE,,$@)
	$(QUIET)$(RM) -f $@ $@.tmp
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(APPEND) $@.tmp 'VBOX_VERSION_MAJOR = $(VBOX_VERSION_MAJOR)'
	$(QUIET)$(APPEND) $@.tmp 'VBOX_VERSION_MINOR = $(VBOX_VERSION_MINOR)'
	$(QUIET)$(APPEND) $@.tmp 'VBOX_VERSION_BUILD = $(VBOX_VERSION_BUILD)'
	$(QUIET)$(APPEND) $@.tmp 'VBOX_VERSION_STRING = $(VBOX_VERSION_STRING)'
ifneq ($(VBOX_VERSION_PRERELEASE),)
	$(QUIET)$(APPEND) $@.tmp 'VBOX_VERSION_PRERELEASE = $(strip $(VBOX_VERSION_PRERELEASE))'
endif
	$(QUIET)$(APPEND) $@.tmp 'VBOX_VENDOR = $(VBOX_VENDOR)'
	$(QUIET)$(APPEND) $@.tmp 'VBOX_VENDOR_SHORT = $(VBOX_VENDOR_SHORT)'
	$(QUIET)$(APPEND) $@.tmp 'VBOX_PRODUCT = $(VBOX_PRODUCT)'
	$(QUIET)$(APPEND) $@.tmp 'VBOX_C_YEAR = $(VBOX_C_YEAR)'
ifdef VBOX_BUILD_SERVER_BUILD
	$(QUIET)$(APPEND) $@.tmp 'VBOX_BUILD_SERVER_BUILD = 1'
else
	$(QUIET)$(APPEND) $@.tmp 'VBOX_PRIVATE_BUILD_DESC = Private build by $(USERNAME)'
endif
	$(QUIET)$(MV) -f $@.tmp $@

if !defined(VBOX_OSE) && !defined(VBOX_NOINC_LICENSE_VER_KMK)
 if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd solaris)
  # VBOX_LICENSE_VER is used in several Makefiles
  VBOX_LICENSE_VER_KMK = $(PATH_OUT)/license-version.kmk
$(VBOX_LICENSE_VER_KMK): $(VBOX_BRAND_LICENSE_HTML)
	$(call MSG_GENERATE,,$(VBOX_LICENSE_VER_KMK))
	$(QUIET)$(MKDIR) -p $(@D)
  ifdef VBOX_BRAND_LICENSE_VER
	$(QUIET)$(RM) -f '$@'
	$(APPEND) '$@' 'VBOX_LICENSE_VER=$(VBOX_BRAND_LICENSE_VER)'
  else
	$(QUIET)$(SED) -e "s/.*License version \([0-9.]*\) *[,&].*/VBOX_LICENSE_VER=\1/;t;d" --output $@ $(VBOX_BRAND_LICENSE_HTML)
  endif
  -include $(VBOX_LICENSE_VER_KMK)
  ifdef VBOX_LICENSE_VER
   VBOX_LICENSE_FILES = \
	 License-$(VBOX_LICENSE_VER).html \
	 $(foreach f,$(VBOX_INSTALLER_ADD_LANGUAGES),License-$(VBOX_LICENSE_VER)-$(f).html)
   VBOX_LICENSE_BINS = $(addprefix $(PATH_STAGE_BIN)/,$(VBOX_LICENSE_FILES))
  endif
 endif
endif


ifndef VBOX_NOINC_MISC
# Force building of the version header file as the first thing anywhere in
# the tree. This eliminates the need for manual dependencies on it.
## @todo there gotta be a better way of doing this.
Makefile.kmk: | $(VBOX_VERSION_HEADER) $(VBOX_VERSION_MK) $(VBOX_PRODUCT_HEADER) $(VBOX_PACKAGE_HEADER)
endif


#
# Subversion tree revision.
#
# The VBOX_SVN_REV contains our best guess.  Use svn info on the root of the
# tree to determine this it if .svn/wc.db or .svn/entries is found (the former
# also up to two directory levels higher to allow for checkouts of the entire
# repository), otherwise fall back on maximum value of Config.kmk and
# Version.kmk revision.
#
# Makefile rules using this information shall list $(VBOX_SVN_REV_KMK) as a
# prerequisite.
#
SVN                    ?= svn$(HOSTSUFF_EXE)
VBOX_SVN_REV_KMK        = $(PATH_OUT)/revision.kmk
ifndef VBOX_SVN_REV
 VBOX_SVN_REV_CONFIG_FALLBACK := $(patsubst %:,,  $Rev: 143633 $  )
 VBOX_SVN_REV_FALLBACK := $(if-expr $(VBOX_SVN_REV_CONFIG_FALLBACK) > $(VBOX_SVN_REV_VERSION_FALLBACK),$(VBOX_SVN_REV_CONFIG_FALLBACK),$(VBOX_SVN_REV_VERSION_FALLBACK))
 VBOX_SVN_DEP          := $(firstword $(wildcard $(PATH_ROOT)/.svn/wc.db $(abspath $(PATH_ROOT)/../.svn/wc.db) $(abspath $(PATH_ROOT)/../../.svn/wc.db) $(PATH_ROOT)/.svn/entries))
 ifeq ($(which $(SVN)),)
  VBOX_SVN_DEP         :=
 endif

# Rule for generating a timestamp and updating the real thing on change.
$(VBOX_SVN_REV_KMK).ts +| $(VBOX_SVN_REV_KMK): $(if $(VBOX_SVN_DEP), $(VBOX_SVN_DEP), $(PATH_ROOT)/Config.kmk)
	$(call MSG_GENERATE,,$(VBOX_SVN_REV_KMK))
	$(QUIET)$(RM) -f $@ $@.tmp
	$(QUIET)$(MKDIR) -p $(@D)
 ifneq ($(VBOX_SVN_DEP),)
	-$(REDIRECT) -E 'LC_ALL=C' -wo $@.tmp -- $(SVN) info $(PATH_ROOT)
	# Append fallback. Will be ignored if "svn info" provides meaningful data.
	$(QUIET)$(APPEND) $@.tmp 'Last Changed Rev: $(VBOX_SVN_REV_FALLBACK)'
	$(SED) -e '/^Last Changed Rev/!d'  -e 's/Last Changed Rev\: */export VBOX_SVN_REV=/; t a; :a q' --output $@ $@.tmp
	$(QUIET)$(RM) -f $@.tmp
 else
	$(QUIET)$(APPEND) $@ 'export VBOX_SVN_REV=$(VBOX_SVN_REV_FALLBACK)'
 endif
	$(QUIET)$(CP) --changed -fv $@ $(VBOX_SVN_REV_KMK)

 ifndef VBOX_NOINC_SVN_REV_KMK
  include $(VBOX_SVN_REV_KMK)
 endif
else
# allow to overwrite VBOX_SVN_REV externally (mainly for building .debs/.rpms)
$(VBOX_SVN_REV_KMK):
	$(call MSG_GENERATE,,$(VBOX_SVN_REV_KMK))
	$(QUIET)$(RM) -f $@
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(APPEND) $@ 'export VBOX_SVN_REV=$(VBOX_SVN_REV)'
	$(QUIET)echo '* $(VBOX_SVN_REV_KMK) was externally overwritten:'
	$(QUIET)$(CAT) $(VBOX_SVN_REV_KMK)
endif

# only needed for VBoxGuest for Linux/FreeBSD guests
VBOX_SVN_REV_HEADER = $(PATH_OUT)/revision-generated.h
$(VBOX_SVN_REV_HEADER): $(VBOX_SVN_REV_KMK)
	$(call MSG_GENERATE,,$@)
	$(QUIET)$(RM) -f $@ $@.tmp
	$(QUIET)$(MKDIR) -p $(@D)
	$(QUIET)$(APPEND) $@.tmp '#define VBOX_SVN_REV $(VBOX_SVN_REV)'
	$(QUIET)$(MV) -f $@.tmp $@

#
# Shared definitions of the XIDL file to use as a source for
# generating various other files (VBoxSVC, webservice, docs, front-ends, ...)
#

# Real XIDL source file; from this we strip the <desc> elements to generate
# a second XIDL file, from which the COM/XPCOM IDL files are then generated:
VBOX_XIDL_FILE_SRC     = $(PATH_ROOT)/src/VBox/Main/idl/VirtualBox.xidl
# second XIDL file to use as source for COM/XPCOM IDL (with stripped docs):
VBOX_XIDL_FILE         = $(PATH_OUT)/obj/VirtualBox_stripped.xidl


#
# VBOX_SEP needs to be quoted when used on the shell command line.
#
if1of ($(KBUILD_TARGET), os2 win)
 VBOX_SEP = $(SEMICOLON)
else
 VBOX_SEP = $(COLON)
endif

# Java compiler options, needs some version checking.
if defined(VBOX_JAVA_VERSION) && $(VBOX_JAVA_VERSION) >= 110000
 VBOX_JAVA_WS_PATH ?= /usr/share/java
 VBOX_JAVA_WS_EXTRA_JARS ?= $(VBOX_JAVA_WS_PATH)/jws-api.jar$(VBOX_SEP)$(VBOX_JAVA_WS_PATH)/jaxb-api.jar$(VBOX_SEP)$(VBOX_JAVA_WS_PATH)/jaxws-api.jar
else if defined(VBOX_JAVA_VERSION) && $(VBOX_JAVA_VERSION) >= 10900
 VBOX_JAVA_WS_OPTS ?= --add-modules java.xml.ws
endif
if defined(VBOX_JAVA_VERSION) && $(VBOX_JAVA_VERSION) >= 110000
 VBOX_JAVAC_OPTS   = -encoding UTF-8 -source 9 -target 9 -Xlint:unchecked
else if defined(VBOX_JAVA_VERSION) && $(VBOX_JAVA_VERSION) >= 100000
 VBOX_JAVAC_OPTS   = -encoding UTF-8 -source 6 -target 6 -Xlint:unchecked
else
 VBOX_JAVAC_OPTS   = -encoding UTF-8 -source 1.5 -target 1.5 -Xlint:unchecked
endif
VBOX_JAVADOC_OPTS = -encoding UTF-8


#
# Legacy.
#
## @todo try remove this.
ifneq ($(LOCALCFG),)
 include $(LOCALCFG)
endif


#
# For efficiently build serveral build types / archs.
#
both-debug-release both-release-debug: \
		build-release-$(KBUILD_TARGET_ARCH) \
		build-debug-$(KBUILD_TARGET_ARCH)
both-x86-amd64     both-amd64-x86: \
		build-$(KBUILD_TYPE)-x86 \
		build-$(KBUILD_TYPE)-x86
both-types-archs both-archs-types: \
		build-debug-x86 \
		build-release-x86 \
		build-debug-amd64 \
		build-release-amd64

build-release-x86:
	+$(MAKE) KBUILD_TYPE=release KBUILD_TARGET_ARCH=x86

build-debug-x86:
	+$(MAKE) KBUILD_TYPE=debug KBUILD_TARGET_ARCH=x86

build-release-amd64:
	+$(MAKE) KBUILD_TYPE=release KBUILD_TARGET_ARCH=amd64

build-debug-amd64:
	+$(MAKE) KBUILD_TYPE=debug KBUILD_TARGET_ARCH=amd64


#
# Some extra goals.
#
.PHONY: up update st stat status
up update::
	$(SVN) up

up2 update2::
	$(SVN) up --ignore-externals

st stat status:
	$(SVN) status