summaryrefslogtreecommitdiffstats
path: root/tools/configure
blob: 35f4b6d107fe7f20b78047051617407c399f0c90 (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
#!/bin/sh
#             __________               __   ___.
#   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
#   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
#   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
#   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
#                     \/            \/     \/    \/            \/
#

# global CC options for all platforms
CCOPTS="-W -Wall -Wextra -Wundef -Os -nostdlib -ffreestanding -Wstrict-prototypes -pipe -std=gnu99 -funit-at-a-time -fno-delete-null-pointer-checks -fno-strict-overflow"

# LD options for the core
LDOPTS=""
# LD options for the core + plugins
GLOBAL_LDOPTS=""

extradefines=""
use_logf="#undef ROCKBOX_HAS_LOGF"
use_bootchart="#undef DO_BOOTCHART"
use_logf_serial="#undef LOGF_SERIAL"

scriptver=`echo '$Revision$' | sed -e 's:\\$::g' -e 's/Revision: //'`

rbdir="/.rockbox"
bindir=
libdir=
sharedir=

arm_thumb_boot=
thread_support="ASSEMBLER_THREADS"
sysfont="08-Schumacher-Clean"
app_lcd_width=
app_lcd_height=
app_lcd_orientation=

# Properly retain command line arguments containing spaces
cmdline=
for arg in "$@"; do
  case "$arg" in
    *\ *) cmdline="$cmdline \"$arg\"";;
    *)    cmdline="$cmdline $arg";;
  esac
done

#
# Begin Function Definitions
#
input() {
    read response
    echo $response
}

prefixtools () {
 prefix="$1"
 if [ -n "$ARG_COMPILER_PREFIX" ]; then
  echo "WARNING: asked to override target toolchain $1 with $ARG_COMPILER_PREFIX"
  echo "WARNING: overriding the toolchain means you are running an untested configuration"
  echo "WARNING: you build might be broken because of that"
  prefix="$ARG_COMPILER_PREFIX"
 fi
 CC=${prefix}gcc
 CPP=${prefix}cpp
 WINDRES=${prefix}windres
 DLLTOOL=${prefix}dlltool
 DLLWRAP=${prefix}dllwrap
 RANLIB=${prefix}gcc-ranlib
 LD=${prefix}ld
 AR=${prefix}gcc-ar
 AS=${prefix}as
 OC=${prefix}objcopy
}

app_set_paths () {
    # setup files and paths depending on the platform
    if [ -z "$ARG_PREFIX" ]; then
        sharedir="/usr/local/share/rockbox"
        bindir="/usr/local/bin"
        libdir="/usr/local/lib"
    else
        if [ -d "$ARG_PREFIX" ]; then
            if [ -z `echo $ARG_PREFIX | grep "^/"` ]; then
                ARG_PREFIX=`realpath $ARG_PREFIX`
                if [ "0" != "$?" ]; then
                    echo "ERROR: Could not get prefix path (is realpath installed?)."
                    exit
                fi
            fi
            sharedir="$ARG_PREFIX/share/rockbox"
            bindir="$ARG_PREFIX/bin"
            libdir="$ARG_PREFIX/lib"
        else
            echo "ERROR: PREFIX directory $ARG_PREFIX does not exist"
            exit
        fi
    fi
}

# Set the application LCD size according to the following priorities:
# 1) If --lcdwidth and --lcdheight are set, use them
# 2) If a size is passed to the app_set_lcd_size() function, use that
# 3) Otherwise ask the user
app_set_lcd_size () {
    if [ -z "$ARG_LCDWIDTH" ]; then
        ARG_LCDWIDTH=$1
    fi
    if [ -z "$ARG_LCDHEIGHT" ]; then
        ARG_LCDHEIGHT=$2
    fi

    echo "Enter the LCD width (default: 320)"
    if [ -z "$ARG_LCDWIDTH" ]; then
        app_lcd_width=`input`
    else
        app_lcd_width="$ARG_LCDWIDTH"
    fi
    if [ -z "$app_lcd_width" ]; then app_lcd_width="320"; fi
    echo "Enter the LCD height (default: 480)"
    if [ -z "$ARG_LCDHEIGHT" ]; then
        app_lcd_height=`input`
    else
        app_lcd_height="$ARG_LCDHEIGHT"
    fi
    if [ -z "$app_lcd_height" ]; then app_lcd_height="480"; fi
    if [ $app_lcd_width -gt $app_lcd_height ]; then
        lcd_orientation="landscape"
    else
        lcd_orientation="portrait"
    fi
    echo "Selected $app_lcd_width x $app_lcd_height resolution ($lcd_orientation)"
    ARG_LCDWIDTH=$app_lcd_width
    ARG_LCDHEIGHT=$app_lcd_height

    app_lcd_width="#define LCD_WIDTH $app_lcd_width"
    app_lcd_height="#define LCD_HEIGHT $app_lcd_height"
}

findarmgcc() {
  prefixtools arm-elf-eabi-
  gccchoice="4.9.4"
}

# scan the $PATH for the given command
findtool(){
  file="$1"

  IFS=":"
  for path in $PATH
  do
    # echo "checks for $file in $path" >&2
    if test -f "$path/$file"; then
      echo "$path/$file"
      return
    fi
  done
  # check whether caller wants literal return value if not found
  if [ "$2" = "--lit" ]; then
    echo "$file"
  fi
}

# scan the $PATH for sdl-config - check whether for a (cross-)win32
# sdl as requested
findsdl(){
  files=sdl-config
  if [ -n "$CROSS_COMPILE" ]; then
    # sdl-config might (not) be prefixed for cross compiles so try both.
    files="${CROSS_COMPILE}sdl-config:${files}"
  fi
  winbuild="$1"

  paths2check="$PATH"

  if [ -n "$CROSS_COMPILE" ]; then
    # add cross compile sys-root-directories to search in:
    sysroot=$($CPP --print-sysroot 2>&1)
    if [ $? -eq 0 ];
    then
      subdirs="bin:mingw/bin:sbin:mingw/sbin"
      IFS=":"
      for subdir in $subdirs
      do
        if [ -e "${sysroot}/${subdir}" ]; then
          paths2check="${sysroot}/${subdir}:${paths2check}"
        fi
      done
    else
      echo "WARNING: unable to get sys-root directory from your cross-compiler" >&2
      echo "WARNING: $CPP --print-sysroot returns" >&2
      echo "WARNING: ${sysroot}" >&2
    fi
  fi

  # search for the correct sdl-config
  IFS=":"
  for path in $paths2check
  do
    for file in $files
    do
      if test -f "$path/$file"; then
        if [ "0" != `$path/$file --libs |grep -c mwindows` ]; then
          if [ "yes" = "${winbuild}" ]; then
            echo "$path/$file"
            return
          fi
        else
          if [ "yes" != "${winbuild}" ]; then
            echo "$path/$file"
            return
          fi
        fi
      fi
    done
  done
}

# check for availability of sigaltstack to support our thread engine
check_sigaltstack() {
   cat >$tmpdir/check_threads.c <<EOF
#include <signal.h>
int main(int argc, char **argv)
{
#ifndef NULL
  #define NULL (void*)0
#endif
  sigaltstack(NULL, NULL);
  return 0;
}
EOF
   $CC -o $tmpdir/check_threads $tmpdir/check_threads.c 1> /dev/null
   result=$?
   rm -rf $tmpdir/check_threads*
   echo $result
}

# check for availability of Fiber on Win32 to support our thread engine
check_fiber() {
   cat >$tmpdir/check_threads.c <<EOF
#include <windows.h>
int main(int argc, char **argv)
{
  ConvertThreadToFiber(NULL);
  return 0;
}
EOF
   $CC -o $tmpdir/check_threads $tmpdir/check_threads.c 2>/dev/null
   result=$?
   rm -rf $tmpdir/check_threads*
   echo $result
}

simcc () {
 # default tool setup for native building
 prefixtools "$CROSS_COMPILE"
 ARG_ARM_THUMB=0 # can't use thumb in native builds

 # unset arch if already set shcc() and friends
 arch=
 arch_version=

 app_type=$1
 winbuild=""
 GCCOPTS=`echo $CCOPTS | sed -e s/\ -ffreestanding// -e s/\ -nostdlib// -e s/\ -Wundef//`

 if [ "yes" = "$use_debug" ]; then
    GCCOPTS=`echo $GCCOPTS | sed -e s/\ -Os/\ -Og/`
 fi

 GCCOPTS="$GCCOPTS -fno-builtin -g"

 if [ "$ARG_ADDR_SAN" = "1" ] ; then
   # Use AddressSanitizer!
   echo "Using AddressSanitizer"
   GCCOPTS="$GCCOPTS -fsanitize=address -fPIC"
   LDOPTS="$LDOPTS -fsanitize=address -lasan"
 fi

 if [ "$ARG_UBSAN" = "1" ] ; then
   echo "Using UBSan"
   GCCOPTS="$GCCOPTS -fsanitize=undefined -fPIC"
   LDOPTS="$LDOPTS -fsanitize=undefined"
 fi

 # Some linux setups like to warn about unused results. They are correct,
 # but cleaning this up is a lot of work.
 GCCOPTS="$GCCOPTS -Wno-unused-result"
 GCCOPTIMIZE=''
 LDOPTS="$LDOPTS -lm" # button-sdl.c uses sqrt()
 sigaltstack=""
 fibers=""
 endian="" # endianess of the dap doesnt matter here

 # build a 32-bit simulator
 if [ "$ARG_32BIT" = "1" ]; then
     echo "Building 32-bit simulator"
     GCCOPTS="$GCCOPTS -m32"
     LDOPTS="$LDOPTS -m32"
 fi

 # default output binary name, don't override app_get_platform()
 if [ "$app_type" != "sdl-app" ]; then
    output="rockboxui"
 fi

 # default share option, override below if needed
 SHARED_LDFLAGS="-shared"
 SHARED_CFLAGS="-fPIC -fvisibility=hidden"

 if [ "$win32crosscompile" = "yes" ]; then
   # We are crosscompiling
   # add cross-compiler option(s)
   GCCOPTS="$GCCOPTS -Wno-format"
   LDOPTS="$LDOPTS -mconsole -static"
   GLOBAL_LDOPTS=`echo $GLOBAL_LDOPTS | sed -e s/\-Wl,-z,defs//`
   LDOPTS=`echo $LDOPTS | sed -e s/-ldl// -e s/-lrt// -e s/-lasound//`
   output="$output.exe"
   winbuild="yes"

   if [ -z "$CROSS_COMPILE" ]; then
     if [ "$win64" = "yes" ]; then
       CROSS_COMPILE=${CROSS_COMPILE:-"x86_64-w64-mingw32-"}
     else
       # different possible names; try to find the correct one:
       names="i686-w64-mingw32 i686-pc-mingw32 i586-mingw32msvc"

       for name in $names
       do
         if which "${name}-gcc" >/dev/null 2>&1 ; then
           CROSS_COMPILE="${name}-"
           break
         fi
       done

       if [ -z "$CROSS_COMPILE" ]; then
         echo "WARNING: unable to find cross-compiler for 32-bit Windows environment!"
         echo "WARNING: it's none of \"$names\"."
         echo "WARNING: set your compiler prefix with CROSS_COMPILE=\"your-prefix-\" and"
         echo "WARNING: re-run configure again!"
         exit 2
       fi
     fi
   fi
   SHARED_CFLAGS=''
   prefixtools "$CROSS_COMPILE"
   fibers=`check_fiber`
   endian="little" # windows is little endian
   echo "Enabling MMX support"
   # -mno-ms-bitfields is a workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991
   # mingw-gcc >= 4.7 defaults to -mms-bitfields which breaks __attribute__((packed))
   # disable it explicitly for the time being (it doesn't appear to be required for us)
   GCCOPTS="$GCCOPTS -mmmx -mno-ms-bitfields"
 else
 case $uname in
   CYGWIN*)
   echo "Cygwin host detected"

   fibers=`check_fiber`
   LDOPTS="$LDOPTS -mconsole"
   output="$output.exe"
   winbuild="yes"
   SHARED_CFLAGS=''
   ;;

   MINGW*)
   echo "MinGW host detected"

   fibers=`check_fiber`
   LDOPTS="$LDOPTS -mconsole"
   output="$output.exe"
   winbuild="yes"
   ;;

   Linux)
   sigaltstack=`check_sigaltstack`
   echo "Linux host detected"
   LDOPTS="$LDOPTS -ldl"
   # newer glibc implementations use byteswap.h
   if echo "#include <byteswap.h>" | gcc -E - > /dev/null 2>&1; then
       echo "Using byteswap.h"
       extradefines="$extradefines -DOS_USE_BYTESWAP_H"
   fi
   ;;

   FreeBSD)
   sigaltstack=`check_sigaltstack`
   echo "FreeBSD host detected"
   LDOPTS="$LDOPTS"
   ;;

   Darwin)
   sigaltstack=`check_sigaltstack`
   echo "Darwin host detected"
   LDOPTS="$LDOPTS -ldl"
   SHARED_LDFLAGS="-dynamiclib -Wl\,-single_module"
   ;;

   SunOS)
   sigaltstack=`check_sigaltstack`
   echo "*Solaris host detected"

   GCCOPTS="$GCCOPTS -fPIC"
   LDOPTS="$LDOPTS -ldl"
   ;;

   *)
   echo "[ERROR] Unsupported system: $uname, fix configure and retry"
   exit 1
   ;;
 esac
 fi

 if [ "$winbuild" != "yes" ]; then
   GLOBAL_LDOPTS="$GLOBAL_LDOPTS -Wl,-z,defs"
   if [ "`uname -m`" = "i686" ]; then
     echo "Enabling MMX support"
     GCCOPTS="$GCCOPTS -mmmx"
   fi
 fi

 sdl=`findsdl $winbuild`

 if [ -n `echo $app_type | grep "sdl"` ]; then
    if [ -z "$sdl" ]; then
        echo "configure didn't find sdl-config, which indicates that you"
        echo "don't have SDL (properly) installed. Please correct and"
        echo "re-run configure!"
        exit 2
    else
        echo Using $sdl

        # generic sdl-config checker
        sdlccopts=$($sdl --cflags)
        if $sdl --static-libs > /dev/null 2>&1 ; then
          sdlldopts=$($sdl --static-libs)
        else
          echo "Your sdl-config does not know about static libs, falling back to shared library"
          sdlldopts=$($sdl --libs)
        fi
        GCCOPTS="$GCCOPTS ${sdlccopts}"
        LDOPTS="$LDOPTS ${sdlldopts}"
    fi
 fi


 GCCOPTS="$GCCOPTS -I\$(SIMDIR)"
 # x86_64 supports MMX by default

  if [ "$endian" = "" ]; then
    id=$$
    cat >$tmpdir/conftest-$id.c <<EOF
#include <stdio.h>
int main(int argc, char **argv)
{
int var=0;
char *varp = (char *)&var;
*varp=1;

printf("%d\n", var);
return 0;
}
EOF
    $CC -o $tmpdir/conftest-$id $tmpdir/conftest-$id.c 2>/dev/null
    # when cross compiling, the endianess cannot be detected because the above program doesn't run
    # on the local machine. assume little endian but print a warning
    endian=`$tmpdir/conftest-$id 2> /dev/null`
    if [ "$endian" != "" ] && [ $endian -gt "1" ]; then
      # big endian
      endian="big"
    else
      # little endian
      endian="little"
    fi
  fi

 if [ "$CROSS_COMPILE" != "" ]; then
   echo "WARNING: Cross Compiling, cannot detect endianess. Assuming $endian endian!"
 fi

 if [ "$app_type" = "sdl-sim" ]; then
   echo "Simulator environment deemed $endian endian"
 elif [ "$app_type" = "sdl-app" ]; then
   echo "Application environment deemed $endian endian"
 elif [ "$app_type" = "checkwps" ]; then
   echo "CheckWPS environment deemed $endian endian"
 fi

 # use wildcard here to make it work even if it was named *.exe like
 # on cygwin
 rm -f $tmpdir/conftest-$id*

 # AddressSanitizer requires SDL threads
 if [ "$ARG_ADDR_SAN" = "1" ] ; then
     ARG_THREAD_SUPPORT=1
 fi
 if [ "$ARG_UBSAN" = "1" ] ; then
     ARG_THREAD_SUPPORT=1
 fi

 thread_support=
 if [ -z "$ARG_THREAD_SUPPORT" ] || [ "$ARG_THREAD_SUPPORT" = "0" ]; then
   if [ "$sigaltstack" = "0" ]; then
     thread_support="HAVE_SIGALTSTACK_THREADS"
     LDOPTS="$LDOPTS -lpthread" # pthread needed
     echo "Selected sigaltstack threads"
   elif [ "$fibers" = "0" ]; then
     thread_support="HAVE_WIN32_FIBER_THREADS"
     echo "Selected Win32 Fiber threads"
   fi
 fi

 if [ -n `echo $app_type | grep "sdl"` ] && [ -z "$thread_support" ] \
    && [ "$ARG_THREAD_SUPPORT" != "0" ]; then
   thread_support="HAVE_SDL_THREADS"
   if [ "$ARG_THREAD_SUPPORT" = "1" ]; then
     echo "Selected SDL threads"
   else
     echo "WARNING: Falling back to SDL threads"
   fi
 fi
}

#
# functions for setting up cross-compiler names and options
# also set endianess and what the exact recommended gcc version is
# the gcc version should most likely match what versions we build with
# rockboxdev.sh
#

coldfirecc () {
 prefixtools m68k-elf-
 GCCOPTS="$CCOPTS -mcpu=5249 -malign-int -mstrict-align"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="big"
 gccchoice="4.9.4"
}

arm7tdmicc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm7tdmi"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm9tdmicc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm9tdmi"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm940tbecc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mbig-endian -mcpu=arm940t"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="big"
}

arm940tcc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm940t"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm946cc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm9e"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm926ejscc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm926ej-s"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm1136jfscc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm1136jf-s -mfloat-abi=softfp"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm1176jzscc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm1176jz-s"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm7ejscc () {
 findarmgcc
 GCCOPTS="$CCOPTS -march=armv5te"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

mipselcc () {
 prefixtools mipsel-elf-
 # mips is predefined, but we want it for paths. use __mips instead
 GCCOPTS="$CCOPTS -march=mips32 -mtune=r4600 -mno-mips16 -mno-long-calls -Umips"
 GCCOPTS="$GCCOPTS -ffunction-sections -msoft-float -G 0 -Wno-parentheses"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
 gccchoice="4.9.4"
}

mipsr2elcc () {
 prefixtools mipsel-elf-
 # mips is predefined, but we want it for paths. use __mips instead
 GCCOPTS="$CCOPTS -march=mips32r2 -mno-mips16 -mno-long-calls -Umips"
 GCCOPTS="$GCCOPTS -ffunction-sections -msoft-float -G 0 -Wno-parentheses"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
 gccchoice="4.9.4"
}

maemocc () {
 # Scratchbox sets up "gcc" based on the active target
 prefixtools ""

 GCCOPTS=`echo $CCOPTS | sed -e s/-ffreestanding// -e s/-nostdlib// -e s/-Wundef//`
 GCCOPTS="$GCCOPTS -fno-builtin -g -I\$(SIMDIR)"
 GCCOPTIMIZE=''
 LDOPTS="-lm -ldl $LDOPTS"
 GLOBAL_LDOPTS="$GLOBAL_LDOPTS -Wl,-z,defs"
 SHARED_LDFLAGS="-shared"
 SHARED_CFLAGS=''
 endian="little"
 thread_support="HAVE_SIGALTSTACK_THREADS"

 is_n900=0
 # Determine maemo version
 if pkg-config --atleast-version=5 maemo-version; then
    if [ "$1" == "4" ]; then
        echo "ERROR: Maemo 4 SDK required."
        exit 1
    fi
    extradefines="$extradefines -DMAEMO5"
    echo "Found N900 maemo version"
    is_n900=1
 elif pkg-config --atleast-version=4 maemo-version; then
    if [ "$1" == "5" ]; then
        echo "ERROR: Maemo 5 SDK required."
        exit 1
    fi
    extradefines="$extradefines -DMAEMO4"
    echo "Found N8xx maemo version"
 else
    echo "Unable to determine maemo version. Is the maemo-version-dev package installed?"
    exit 1
 fi

 # SDL
 if [ $is_n900 -eq 1 ]; then
    GCCOPTS="$GCCOPTS `pkg-config --cflags sdl`"
    LDOPTS="$LDOPTS `pkg-config --libs sdl`"
 else
    GCCOPTS="$GCCOPTS `sdl-config --cflags`"
    LDOPTS="$LDOPTS `sdl-config --libs`"
 fi

 # glib and libosso support
 GCCOPTS="$GCCOPTS `pkg-config --cflags libosso glib-2.0 gthread-2.0`"
 LDOPTS="$LDOPTS `pkg-config --libs libosso glib-2.0 gthread-2.0`"

 # libhal support: Battery monitoring
 GCCOPTS="$GCCOPTS `pkg-config --cflags hal`"
 LDOPTS="$LDOPTS `pkg-config --libs hal`"

 GCCOPTS="$GCCOPTS -O2 -fno-strict-aliasing"
 if [ $is_n900 -eq 1 ]; then
    # gstreamer support: Audio output.
    GCCOPTS="$GCCOPTS `pkg-config --cflags gstreamer-base-0.10 gstreamer-plugins-base-0.10 gstreamer-app-0.10`"
    LDOPTS="$LDOPTS `pkg-config --libs gstreamer-base-0.10 gstreamer-plugins-base-0.10 gstreamer-app-0.10`"

    # N900 specific: libplayback support
    GCCOPTS="$GCCOPTS `pkg-config --cflags libplayback-1`"
    LDOPTS="$LDOPTS `pkg-config --libs libplayback-1`"

    # N900 specific: Enable ARMv7 NEON support
    if sb-conf show -A |grep -q -i arm; then
        echo "Detected ARM target"
        GCCOPTS="$GCCOPTS -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
        extradefines="$extradefines -DMAEMO_ARM_BUILD"
    else
        echo "Detected x86 target"
    fi
 else
    # N8xx specific: Enable armv5te instructions
    if sb-conf show -A |grep -q -i arm; then
        echo "Detected ARM target"
        GCCOPTS="$GCCOPTS -mcpu=arm1136jf-s -mfloat-abi=softfp -mfpu=vfp"
        extradefines="$extradefines -DMAEMO_ARM_BUILD"
    else
        echo "Detected x86 target"
    fi
 fi
}

pandoracc () {
 # Note: The new "Ivanovic" pandora toolchain is not able to compile rockbox.
 #       You have to use the sebt3 toolchain:
 #       http://www.gp32x.com/board/index.php?/topic/58490-yactfeau/

 PNDSDK="/usr/local/angstrom/arm"
 if [ ! -x $PNDSDK/bin/arm-angstrom-linux-gnueabi-gcc ]; then
     echo "Pandora SDK gcc not found in $PNDSDK/bin/arm-angstrom-linux-gnueabi-gcc"
     exit
 fi

 PATH=$PNDSDK/bin:$PATH:$PNDSDK/arm-angstrom-linux-gnueabi/usr/bin
 PKG_CONFIG_PATH=$PNDSDK/arm-angstrom-linux-gnueabi/usr/lib/pkgconfig
 LDOPTS="-L$PNDSDK/arm-angstrom-linux-gnueabi/usr/lib -Wl,-rpath,$PNDSDK/arm-angstrom-linux-gnueabi/usr/lib $LDOPTS"
 PKG_CONFIG="pkg-config"

 GCCOPTS=`echo $CCOPTS | sed -e s/-ffreestanding// -e s/-nostdlib// -e s/-Wundef//`
 GCCOPTS="$GCCOPTS -fno-builtin -g -I\$(SIMDIR)"
 GCCOPTIMIZE=''
 LDOPTS="-lm -ldl $LDOPTS"
 GLOBAL_LDOPTS="$GLOBAL_LDOPTS -Wl,-z,defs"
 SHARED_LDFLAGS="-shared"
 SHARED_CFLAGS=''
 endian="little"
 thread_support="HAVE_SIGALTSTACK_THREADS"

 # Include path
 GCCOPTS="$GCCOPTS -I$PNDSDK/arm-angstrom-linux-gnueabi/usr/include"

 # Set up compiler
 gccchoice="4.3.3"
 prefixtools "$PNDSDK/bin/arm-angstrom-linux-gnueabi-"

 # Detect SDL
 GCCOPTS="$GCCOPTS `$PNDSDK/bin/sdl-config --cflags`"
 LDOPTS="$LDOPTS `$PNDSDK/bin/sdl-config --libs`"

 # Compiler options
 GCCOPTS="$GCCOPTS -O2 -fno-strict-aliasing"
 GCCOPTS="$GCCOPTS -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
 GCCOPTS="$GCCOPTS -ffast-math -fsingle-precision-constant"
}

arm1176jzlinuxcc () {
 GCCOPTS=`echo $CCOPTS | sed -e s/-ffreestanding// -e s/-nostdlib//`
 # Although the ARM1176JZ-S supports unaligned accesses, those seems to disabled
 # by the kernel. Since GCC emits unaligned accesses by default on ARMv6, we
 # need to disable that
 GCCOPTS="$GCCOPTS -mcpu=arm1176jz-s -mno-unaligned-access -mfloat-abi=softfp"
 GCCOPTIMIZE=''
 LDOPTS="-lasound -lpthread -lm -ldl -lrt $LDOPTS"
 GLOBAL_LDOPTS="$GLOBAL_LDOPTS -Wl,-z,defs" # warn about undefined symbols in shared libraries
 SHARED_LDFLAGS="-shared"
 SHARED_CFLAGS=''
 endian="little"
 app_type="ypr0"

 # Include path
 GCCOPTS="$GCCOPTS  -D_GNU_SOURCE=1 -U_FORTIFY_SOURCE -D_REENTRANT"

 # Set up compiler
 gccchoice="4.9.4"
 prefixtools "arm-rockbox-linux-gnueabi-"
}

ypr0cc () {
 arm1176jzlinuxcc
 app_type="ypr0"
}

sonynwzcc () {
 arm1176jzlinuxcc
 app_type="sonynwz"
}

androidcc () {
    if [ -z "$ANDROID_SDK_PATH" ]; then
        echo "ERROR: You need the Android SDK installed and have the ANDROID_SDK_PATH"
        echo "environment variable point to the root directory of the Android SDK."
        exit
    fi
    if [ -z "$ANDROID_NDK_PATH" ]; then
        echo "ERROR: You need the Android NDK installed (r10e or higher) and have the ANDROID_NDK_PATH"
        echo "environment variable point to the root directory of the Android NDK."
        exit
    fi
    make_toolchain="${ANDROID_NDK_PATH}/build/tools/make-standalone-toolchain.sh"

    # the prebuilt android NDK only supports x86_64 architecture anyway, so we can take shortcuts
    buildhost=$(uname | tr "[:upper:]" "[:lower:]")-x86_64
    GCCOPTS=`echo $CCOPTS | sed -e s/-ffreestanding// -e s/-nostdlib// -e s/-Wundef//`
    LDOPTS="$LDOPTS -ldl -llog"
    if [ "$modelname" != "ibassodx50" ] && [ "$modelname" != "ibassodx90" ]; then
        LDOPTS="$LDOPTS -Wl,-soname,librockbox.so -shared"
    fi
    SHARED_LDFLAGS="-shared"
    SHARED_CFLAGS=''
    GLOBAL_LDOPTS="-Wl,-z,defs -Wl,-z,noexecstack"
    thread_support="HAVE_SIGALTSTACK_THREADS"
    ANDROID_ARCH=$2 # for android.make too
    ANDROID_PLATFORM_VERSION=$1
    GCCOPTS="$GCCOPTS $3"
    gccchoice="4.9"
    # arch dependant stuff
    case $ANDROID_ARCH in
        armeabi)
            endian="little"
            gcctarget="arm-linux-androideabi-"
            echo "${make_toolchain} --toolchain=arm-linux-androideabi-${gccchoice} --platform=android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain"
            ${make_toolchain} --toolchain=arm-linux-androideabi-${gccchoice} --platform=android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain
            if [ ${?} != 0 ]; then
                exit
            fi
	    # Android 4.4 (API 19) doesn't support anything older than armv7.
            GCCOPTS="$GCCOPTS -fomit-frame-pointer -fuse-ld=bfd"
            ;;
        aarch64)
            endian="little"
            gcctarget="arm-linux-androideabi-"
            echo "${make_toolchain} --toolchain=aarch64-linux-android-${gccchoice} --platform=android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain"
            ${make_toolchain} --toolchain=aarch64-linux-android-${gccchoice} --platform=android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain
            if [ ${?} != 0 ]; then
                exit
            fi
            GCCOPTS="$GCCOPTS -fomit-frame-pointer -fuse-ld=bfd"  # what default cpu arch/tune to use?
            ;;
        mips)
            endian="little"
            gcctarget="mipsel-linux-android-"
            echo "${make_toolchain} --toolchain=mipsel-linux-android-${gccchoice} --platform=android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain"
            ${make_toolchain} --toolchain=mipsel-linux-android-${gccchoice} --platform=android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain
            if [ ${?} != 0 ]; then
                exit
            fi
            GCCOPTS="$GCCOPTS -march=mips32 -mtune=r4600 -mno-mips16 -mno-long-calls -fomit-frame-pointer -fPIC"
            ;;
        x86)
            endian="little"
            gcctarget="i686-linux-android-"
            echo "${make_toolchain} --toolchain=x86-${gccchoice} --platform=android-android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain"
            ${make_toolchain} --toolchain=x86-${gccchoice} --platform=android-android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain
            if [ ${?} != 0 ]; then
                exit
            fi
            GCCOPTS="$GCCOPTS -Wa,--noexecstack -ffunction-sections -fomit-frame-pointer"
            ;;
        *)
            echo "ERROR: androidcc(): Unknown target architecture"
            exit
            ;;
    esac

    LDOPTS="$LDOPTS -fuse-ld=bfd --sysroot=${pwd}/android-toolchain/sysroot"
    GCCOPTS="$GCCOPTS --sysroot=${pwd}/android-toolchain/sysroot"
    echo "Using endian ${endian}"
    echo "Using gccchoice ${gccchoice}"
    echo "Using gcctarget ${gcctarget}"
    PATH=$PATH:${pwd}/android-toolchain/bin
    prefixtools $gcctarget
}

androidndkcc()
{
    if ! [ -d "$ANDROID_NDK_PATH" ]; then
        echo "ERROR: You need the Android NDK installed (r10e or higher) and have the ANDROID_NDK_PATH"
        echo "environment variable point to the root directory of the Android NDK."
        exit
    fi

    make_toolchain="${ANDROID_NDK_PATH}/build/tools/make-standalone-toolchain.sh"

    if ! [ -e "${make_toolchain}" ]; then
        echo "ERROR: ${make_toolchain} could not be found."
        exit
    fi

    # the prebuilt android NDK only supports x86_64 architecture anyway, so we can take shortcuts
    buildhost=$(uname -s | tr "[:upper:]" "[:lower:]")-x86_64

    GCCOPTS=`echo $CCOPTS | sed -e s/-ffreestanding// -e s/-nostdlib// -e s/-Wundef//`
    LDOPTS="$LDOPTS -ldl -llog"
    SHARED_LDFLAGS="-shared"
    SHARED_CFLAGS=''
    GLOBAL_LDOPTS="-Wl,-z,defs -Wl,-z,noexecstack"

    ANDROID_PLATFORM_VERSION=$1
    GCCOPTS="$GCCOPTS $3"

    # arch dependant stuff
    case $2 in
        armeabi)
            endian="little"
            gccchoice="4.9"
            gcctarget="arm-linux-androideabi-"
            echo "${make_toolchain} --toolchain=arm-linux-androideabi-4.9 --platform=android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain"
            ${make_toolchain} --toolchain=arm-linux-androideabi-4.9 --platform=android-$ANDROID_PLATFORM_VERSION --install-dir=${pwd}/android-toolchain
            if [ ${?} != 0 ]; then
                exit
            fi
            GCCOPTS="$GCCOPTS -fomit-frame-pointer"
            ;;
        *)
            echo "ERROR: androidndkcc(): Unknown target architecture"
            exit
            ;;
    esac

    # -fuse-ld=bfd is needed because toolchain defaults to 'gold'
    # which often crashes when linking.
    LDOPTS="$LDOPTS -fuse-ld=bfd --sysroot=${pwd}/android-toolchain/sysroot"
    GCCOPTS="$GCCOPTS -fuse-ld=bfd --sysroot=${pwd}/android-toolchain/sysroot"

    echo "Using endian ${endian}"
    echo "Using gccchoice ${gccchoice}"
    echo "Using gcctarget ${gcctarget}"

    PATH=$PATH:${pwd}/android-toolchain/bin
    prefixtools $gcctarget
}

mipsellinuxcc () {
 GCCOPTS=`echo $CCOPTS | sed -e s/-ffreestanding// -e s/-nostdlib//`
 GCCOPTS="$GCCOPTS -march=mips32r2 -mhard-float -mno-mips16 -mno-long-calls -Umips -fPIC"
 GCCOPTIMIZE=''
 LDOPTS="-lasound -lpthread -lm -ldl -lrt $LDOPTS"
 GLOBAL_LDOPTS="$GLOBAL_LDOPTS -Wl,-z,defs"
 SHARED_LDFLAGS="-shared"
 SHARED_CFLAGS='-fPIC -fvisibility=hidden'
 endian="little"
 thread_support="HAVE_SIGALTSTACK_THREADS"

 # Include path
 GCCOPTS="$GCCOPTS  -D_GNU_SOURCE=1 -U_FORTIFY_SOURCE -D_REENTRANT"

 # Set up compiler
 gccchoice="4.9.4"
 prefixtools "mipsel-rockbox-linux-gnu-"
}

whichadvanced () {
  atype=`echo "$1" | cut -c 2-`
  ##################################################################
  # Prompt for specific developer options
  #
  if [ "$atype" ]; then
    interact=
  else
    interact=1
    echo ""
    printf "Enter your developer options (press only enter when done)\n\
(D)EBUG, (L)ogf, Boot(c)hart, (S)imulator, (P)rofiling, (V)oice, (U)SB Serial, (W)in32 crosscompile,\n\
Win(6)4 crosscompile, (T)est plugins, (O)mit plugins, S(m)all C lib, Logf to Ser(i)al port, LTO (B)uild "
    if [ "$modelname" = "iaudiom5" ]; then
      printf ", (F)M radio MOD"
    fi
    if [ "$modelname" = "iriverh120" ]; then
      printf ", (R)TC MOD"
    fi
    printf ":"
    echo ""
  fi

  cont=1
  while [ $cont = "1" ]; do

    if [ "$interact" ]; then
      option=`input`
    else
      option=`echo "$atype" | cut -c 1`
    fi

    case $option in
      [Dd])
        if [ "yes" = "$profile" ]; then
          echo "Debug is incompatible with profiling"
        else
          echo "DEBUG build enabled"
          use_debug="yes"
        fi
        ;;
      [Ll])
        echo "logf() support enabled"
        logf="yes"
        ;;
      [Mm])
        echo "Using Rockbox' small C library"
        extradefines="$extradefines -DHAVE_ROCKBOX_C_LIBRARY"
        ;;
      [Tt])
        echo "Including test plugins"
        extradefines="$extradefines -DHAVE_TEST_PLUGINS"
        ;;
      [Oo])
        echo "Disabling building of plugins"
        plugins="no"
        ;;
      [Cc])
        echo "bootchart enabled (logf also enabled)"
        bootchart="yes"
        logf="yes"
        ;;
      [Ii])
        echo "Logf to serial port enabled (logf also enabled)"
        logf="yes"
        logf_serial="yes"
        ;;
      [Ss])
        echo "Simulator build enabled"
        simulator="yes"
        ;;
      [Pp])
        if [ "yes" = "$use_debug" ]; then
          echo "Profiling is incompatible with debug"
        else
          echo "Profiling support is enabled"
          profile="yes"
        fi
        ;;
      [Vv])
        echo "Voice build selected"
        voice="yes"
        ;;
      [Ff])
        if [ "$modelname" = "iaudiom5" ]; then
          have_fmradio_in="#define HAVE_FMRADIO_IN"
          echo "FM radio functions enabled"
        fi
        ;;
      [Rr])
        if [ "$modelname" = "iriverh120" ]; then
          config_rtc="#define CONFIG_RTC RTC_DS1339_DS3231"
          have_rtc_alarm="#define HAVE_RTC_ALARM"
          echo "RTC functions enabled (DS1339/DS3231)"
        fi
        ;;
      [Uu])
        echo "USB Serial support enabled"
        use_usb_serial="#define USB_ENABLE_SERIAL"
        logf="yes"
        ;;
      [Ww])
        echo "Enabling Windows cross-compiling (32-bit)"
        win32crosscompile="yes"
        win64=""
        ;;
      [6])
        echo "Enabling Windows cross-compiling (64-bit)"
        win32crosscompile="yes"
        win64="yes"
        ;;
       [Bb])
        echo "LTO build enabled"
        LTO_ARG="export USE_LTO=y"
        ;;
      "") # Match enter press when finished with advanced options
        cont=0
        ;;
      *)
        echo "[ERROR] Option $option unsupported"
        ;;
    esac
    if [ "$interact" ]; then
      btype="$btype$option"
    else
      atype=`echo "$atype" | cut -c 2-`
      [ "$atype" ] || cont=0
    fi
  done
  echo "done"

  if [ "yes" = "$voice" ]; then
    # Ask about languages to build
    picklang
    voicelanguage=`whichlang`
    echo "Voice language set to $voicelanguage"

    # Configure encoder and TTS engine for each language
    for thislang in `echo $voicelanguage | sed 's/,/ /g'`; do
      voiceconfig "$thislang"
    done
    if [ -z "$POOL" ] ; then
	echo " \$POOL is not set, will use <builddir>/voice-pool by default"
    fi
  fi
  if [ "yes" = "$use_debug" ]; then
    debug="-DDEBUG"
    GCCOPTS="$GCCOPTS -g -DDEBUG"
  fi
  if [ "yes" = "$logf" ]; then
    use_logf="#define ROCKBOX_HAS_LOGF 1"
  fi
  if [ "yes" = "$logf_serial" ]; then
    use_logf_serial="#define LOGF_SERIAL 1"
  fi
  if [ "yes" = "$bootchart" ]; then
    use_bootchart="#define DO_BOOTCHART 1"
  fi
  if [ "yes" = "$simulator" ]; then
    debug="-DDEBUG"
    extradefines="$extradefines -DSIMULATOR -DHAVE_TEST_PLUGINS"
    flash=""
  fi
  if [ "yes" = "$profile" ]; then
    extradefines="$extradefines -DRB_PROFILE"
    PROFILE_OPTS="-finstrument-functions"
  fi
}

# Configure voice settings
voiceconfig () {
    thislang=$1
    if [ ! "$ARG_TTS" ]; then
        echo "Building $thislang voice for $modelname. Select options"
        echo ""
    fi

    if [ -n "`findtool flite`" ]; then
        FLITE="F(l)ite "
        FLITE_OPTS=""
        DEFAULT_TTS="flite"
        DEFAULT_TTS_OPTS=$FLITE_OPTS
        DEFAULT_CHOICE="l"
    fi
    if [ -n "`findtool espeak`" ]; then
        ESPEAK="(e)Speak "
        ESPEAK_OPTS=""
        DEFAULT_TTS="espeak"
        DEFAULT_TTS_OPTS=$ESPEAK_OPTS
        DEFAULT_CHOICE="e"
    fi
    if [ -n "`findtool espeak-ng`" ]; then
        ESPEAK="(e)Speak-ng "
        ESPEAK_OPTS=""
        DEFAULT_TTS="espeak-ng"
        DEFAULT_TTS_OPTS=$ESPEAK_OPTS
        DEFAULT_CHOICE="e"
    fi
    if [ -n "`findtool festival`" ]; then
        FESTIVAL="(F)estival "
        FESTIVAL_OPTS=""
        DEFAULT_TTS="festival"
        DEFAULT_TTS_OPTS=$FESTIVAL_OPTS
        DEFAULT_CHOICE="f"
    fi
    if [ -n "`findtool mimic`" ]; then
        MIMIC="(M)imic "
        MIMIC_OPTS=""
        DEFAULT_TTS="mimic"
        DEFAULT_TTS_OPTS=$MIMIC_OPTS
        DEFAULT_CHOICE="M"
    fi
    if [ -n "`findtool swift`" ]; then
        SWIFT="S(w)ift "
        SWIFT_OPTS=""
        DEFAULT_TTS="swift"
        DEFAULT_TTS_OPTS=$SWIFT_OPTS
        DEFAULT_CHOICE="w"
    fi
    # Allow SAPI if Windows is in use
    if [ -n "`findtool winver`" ]; then
        SAPI="(S)API "
        SAPI_OPTS=""
        DEFAULT_TTS="sapi"
        DEFAULT_TTS_OPTS=$SAPI_OPTS
        DEFAULT_CHOICE="S"
    fi
    if [ -n "`findtool gtts-cli`" ]; then
        GTTS="(g)tts "
        GTTS_OPTS=""
        DEFAULT_TTS="gtts"
        DEFAULT_TTS_OPTS=$GTTS_OPTS
        DEFAULT_CHOICE="g"
    fi
    if [ -n "`findtool piper`" ]; then
        PIPER="(p)iper "
        PIPER_OPTS=""
        DEFAULT_TTS="piper"
        DEFAULT_TTS_OPTS=$PIPER_OPTS
        DEFAULT_CHOICE="p"
    fi
    if [ -n "`findtool rbspeak`" ]; then
        RBSPEAK="(O)ther "
        RBSPEAK_OPTS=""
        DEFAULT_TTS="rbspeak"
        DEFAULT_TTS_OPTS=$RBSPEAK_OPTS
        DEFAULT_CHOICE="O"
    fi

    if [ "$FESTIVAL" = "$FLITE" ] && [ "$FLITE" = "$ESPEAK" ] && [ "$ESPEAK" = "$SAPI" ] && [ "$SAPI" = "$MIMIC" ] && [ "$MIMIC" = "$SWIFT" ] && [ "$SWIFT" = "$GTTS" ] && [ "$GTTS" = "$PIPER" ] && [ "$PIPER" = "$RBSPEAK" ] ; then
        echo "You need Festival, eSpeak, Mimic, Flite, piper, gtts, or rbspeak in your path, or SAPI available to build voice files"
        exit 3
    fi

    if [ "$ARG_TTS" ]; then
        option=$ARG_TTS
    else
        echo "TTS engine to use: ${FLITE}${FESTIVAL}${ESPEAK}${MIMIC}${SAPI}${SWIFT}${GTTS}${RBSPEAK}${PIPER}(${DEFAULT_CHOICE})?"
        option=`input`
        if [ -z "$option" ]; then option=${DEFAULT_CHOICE}; fi
        advopts="$advopts --tts=$option"
    fi
    case "$option" in
        [Ll]|flite)
        TTS_ENGINE="flite"
        TTS_OPTS=$FLITE_OPTS
        ;;
        [Ee]|espeak)
        TTS_ENGINE="espeak"
        TTS_OPTS=$ESPEAK_OPTS
        ;;
        [Ff]|festival)
        TTS_ENGINE="festival"
        TTS_OPTS=$FESTIVAL_OPTS
        ;;
        [Mm]|mimic)
        TTS_ENGINE="mimic"
        TTS_OPTS=$MIMIC_OPTS
        ;;
        [Ss]|sapi)
        TTS_ENGINE="sapi"
        TTS_OPTS=$SAPI_OPTS
        ;;
	[Ww]|swift)
        TTS_ENGINE="swift"
        TTS_OPTS=$SWIFT_OPTS
	;;
	[Gg]|gtts)
        TTS_ENGINE="gtts"
        TTS_OPTS=$GTTS_OPTS
	;;
	[Pp]|piper)
        TTS_ENGINE="piper"
        TTS_OPTS=$PIPER_OPTS
	;;
	[Oo]|rbspeak)
        TTS_ENGINE="rbspeak"
        TTS_OPTS=$RBSPEAK_OPTS
	;;
        *)
        TTS_ENGINE=$DEFAULT_TTS
        TTS_OPTS=$DEFAULT_TTS_OPTS
    esac
    echo "Using $TTS_ENGINE for TTS"

    # Select which voice to use for Festival
    if [ "$TTS_ENGINE" = "festival" ]; then
        voicelist=`echo "(voice.list)"|festival -i 2>/dev/null |tr "\n" " "|sed -e 's/.*festival> (\(.*\)) festival>/\1/'|sort`
        for voice in $voicelist; do
            TTS_FESTIVAL_VOICE="$voice" # Default choice
            break
        done
        if [ "$ARG_VOICE" ]; then
            CHOICE=$ARG_VOICE
        else
            i=1
            for voice in $voicelist; do
                printf "%3d. %s\n" "$i" "$voice"
                i=`expr $i + 1`
            done
            printf "Please select which Festival voice to use (default is $TTS_FESTIVAL_VOICE): "
            CHOICE=`input`
        fi
        i=1
        for voice in $voicelist; do
            if [ "$i" = "$CHOICE" -o "$voice" = "$CHOICE" ]; then
                TTS_FESTIVAL_VOICE="$voice"
            fi
            i=`expr $i + 1`
        done
        advopts="$advopts --voice=$CHOICE"
        echo "Festival voice set to $TTS_FESTIVAL_VOICE"
        echo "(voice_$TTS_FESTIVAL_VOICE)" > festival-prolog.scm
    elif [ "$TTS_ENGINE" = "piper" ]; then
	if [ -z "$PIPER_MODEL_DIR" ]; then
	    echo "Please set PIPER_MODEL_DIR!";
	    exit 1
	fi
	models=`(cd $PIPER_MODEL_DIR ; ls -1 *onnx)`
	for model in $models; do
	    PIPER_MODEL="$model"  # Default
	    break;
        done
        if [ "$ARG_VOICE" ]; then
            CHOICE=$ARG_VOICE
        else
	    i=1
	    for model in $models; do
		printf "%3d. %s\n" "$i" "$model"
                i=`expr $i + 1`
            done
            printf "Please select which piper model to use (default is $PIPER_MODEL): "
            CHOICE=`input`
	fi
        i=1
        for model in $models; do
            if [ "$i" = "$CHOICE" -o "$model" = "$CHOICE" ]; then
                PIPER_MODEL="$model"
		break;
            fi
            i=`expr $i + 1`
        done

	TTS_OPTS="$TTS_OPTS --model $PIPER_MODEL_DIR/$PIPER_MODEL"
        advopts="$advopts --voice=$PIPER_MODEL"
        echo "Piper model set to $PIPER_MODEL"
    elif [ "$TTS_ENGINE" = "mimic" ]; then
	voicelist=`mimic -lv | cut -d':' -f2`
        for voice in $voicelist; do
            TTS_MIMIC_VOICE="$voice" # Default choice
            break
        done
        if [ "$ARG_VOICE" ]; then
            CHOICE=$ARG_VOICE
        else
            i=1
            for voice in $voicelist; do
                printf "%3d. %s\n" "$i" "$voice"
                i=`expr $i + 1`
            done
            printf "Please select which Mimic voice to use (default is $TTS_MIMIC_VOICE): "
            CHOICE=`input`
        fi
        i=1
        for voice in $voicelist; do
            if [ "$i" = "$CHOICE" -o "$voice" = "$CHOICE" ]; then
                TTS_MIMIC_VOICE="$voice"
		break
            fi
            i=`expr $i + 1`
        done
        advopts="$advopts --voice=$CHOICE"
        echo "Mimic voice set to $TTS_MIMIC_VOICE"
	TTS_OPTS="$TTS_OPTS -voice $TTS_MIMIC_VOICE"
    elif [ "$TTS_ENGINE" = "espeak" ] ; then
	if [ -n "`findtool espeak-ng`" ] ; then
	    TTS_ENGINE="espeak-ng"
	fi
    fi

    # Read custom tts options from command line
    if [ "$ARG_TTSOPTS" ]; then
        TTS_OPTS="$ARG_TTSOPTS"
        echo "$TTS_ENGINE options set to $TTS_OPTS"
    fi

    ENCODER="rbspeexenc"
    ENC_OPTS="-q 7 -c 10"

    echo "Using $ENCODER for encoding voice clips"

    # Read custom encoder options from command line
    if [ "$ARG_ENCOPTS" ]; then
        ENC_OPTS="$ARG_ENCOPTS"
        echo "$ENCODER options set to $ENC_OPTS"
    fi

    TEMPDIR="${pwd}"
    if [ -n "`findtool cygpath`" ]; then
        TEMPDIR=`cygpath . -a -w`
    fi
}

picklang() {
    # figure out which languages that are around
    for file in $rootdir/apps/lang/*.lang; do
        clean=`basename $file .lang`
        langs="$langs $clean"
    done

    if [ "$ARG_LANG" ]; then
        pick=$ARG_LANG
    else
        echo "Select a number for the language to use (default is english)"
        # FIXME The multiple-language feature is currently broken
        # echo "You may enter a comma-separated list of languages to build"

        num=1
        for one in $langs; do
            echo "$num. $one"
            num=`expr $num + 1`
        done
        pick=`input`
        advopts="$advopts --language=$pick"
    fi
}

whichlang() {
    output=""
    # Allow the user to pass a comma-separated list of langauges
    for thispick in `echo $pick | sed 's/,/ /g'`; do
        num=1
        for one in $langs; do
            # Accept both the language number and name
            if [ "$num" = "$thispick" ] || [ "$thispick" = "$one" ]; then
                if [ "$output" = "" ]; then
                    output=$one
                else
                    output=$output,$one
                fi
            fi
            num=`expr $num + 1`
        done
    done
    if [ -z "$output" ]; then
      # pick a default
      output="english"
    fi
    echo $output
}

help() {
  echo "Rockbox configure script."
  echo "Invoke this in a directory to generate a Makefile to build Rockbox"
  echo "Do *NOT* run this within the tools directory!"
  echo ""
  cat <<EOF
  Usage: configure [OPTION]...
  Options:
    --target=TARGET   Sets the target, TARGET can be either the target ID or
                      corresponding string. Run without this option to see all
                      available targets.

    --ram=RAM         Sets the RAM for certain targets. Even though any number
                      is accepted, not every number is correct. The default
                      value will be applied, if you entered a wrong number
                      (which depends on the target). Watch the output.  Run
                      without this option if you are not sure which the right
                      number is.

    --type=TYPE       Sets the build type. Shortcuts are also valid.
                      Run without this option to see all available types.
                      Multiple values are allowed and managed in the input
                      order. So --type=b stands for Bootloader build, while
                      --type=ab stands for "Backlight MOD" build.

    --lcdwidth=X      Sets the width of the LCD. Used only for application
                      targets.

    --lcdheight=Y     Sets the height of the LCD. Used only for application
                      targets.

    --language=LANG   Set the language used for voice generation (used only if
                      TYPE is AV).

    --tts=ENGINE      Set the TTS engine used for voice generation (used only
                      if TYPE is AV).

    --voice=VOICE     Set voice to use with selected TTS (used only if TYPE is
                      AV).

    --ttsopts=OPTS    Set TTS engine manual options (used only if TYPE is AV).

    --encopts=OPTS    Set encoder manual options (used only if ATYPE is AV).

    --rbdir=dir       Use alternative rockbox directory (default: ${rbdir}).
                      This is useful for having multiple alternate builds on
                      your device that you can load with ROLO. However as the
                      bootloader looks for .rockbox you won't be able to boot
                      into this build.

    --ccache          Enable ccache use (done by default these days)
    --no-ccache       Disable ccache use

    --thumb           Build with -mthumb (for ARM builds)
    --no-thumb        The opposite of --thumb (don't use thumb even for targets
                      where this is the default
    --sdl-threads     Force use of SDL threads. They have inferior performance,
                      but are better debuggable with GDB and valgrind
    --no-sdl-threads  Disallow use of SDL threads. This prevents the default
                      behavior of falling back to them if no native thread
                      support was found.
    --with-address-sanitizer
                      Enasbles the AddressSanitizer feature. Forces SDL threads.
    --32-bit          Force a 32-bit simulator (use with --sdl-threads for duke3d)
    --prefix          Target installation directory
    --compiler-prefix Override compiler prefix (inherently dangerous)
    --help            Shows this message (must not be used with other options)

EOF

  exit
}

ARG_CCACHE=
ARG_ENCOPTS=
ARG_LANG=
ARG_RAM=
ARG_RBDIR=
ARG_TARGET=
ARG_TTS=
ARG_TTSOPTS=
ARG_TYPE=
ARG_VOICE=
ARG_ARM_THUMB=
ARG_PREFIX="$PREFIX"
ARG_THREAD_SUPPORT=
ARG_32BIT=
ARG_ADDR_SAN=
ARG_UBSAN=
err=
for arg in "$@"; do
	case "$arg" in
		--ccache)     ARG_CCACHE=1;;
		--no-ccache)  ARG_CCACHE=0;;
		--encopts=*)  ARG_ENCOPTS=`echo "$arg" | cut -d = -f 2`;;
		--language=*) ARG_LANG=`echo "$arg" | cut -d = -f 2`;;
		--lcdwidth=*) ARG_LCDWIDTH=`echo "$arg" | cut -d = -f 2`;;
		--lcdheight=*) ARG_LCDHEIGHT=`echo "$arg" | cut -d = -f 2`;;
		--ram=*)      ARG_RAM=`echo "$arg" | cut -d = -f 2`;;
		--rbdir=*)    ARG_RBDIR=`echo "$arg" | cut -d = -f 2`;;
		--target=*)   ARG_TARGET=`echo "$arg" | cut -d = -f 2`;;
		--tts=*)      ARG_TTS=`echo "$arg" | cut -d = -f 2`;;
		--ttsopts=*)  ARG_TTSOPTS=`echo "$arg" | cut -d = -f 2`;;
		--type=*)     ARG_TYPE=`echo "$arg" | cut -d = -f 2`;;
		--voice=*)    ARG_VOICE=`echo "$arg" | cut -d = -f 2`;;
		--thumb)      ARG_ARM_THUMB=1;;
		--no-thumb)   ARG_ARM_THUMB=0;;
		--32-bit)     ARG_32BIT=1;;
        --sdl-threads)ARG_THREAD_SUPPORT=1;;
        --no-sdl-threads)
                      ARG_THREAD_SUPPORT=0;;
        --with-address-sanitizer) ARG_ADDR_SAN=1;;
        --with-ubsan) ARG_UBSAN=1;;
        --prefix=*)   ARG_PREFIX=`echo "$arg" | cut -d = -f 2`;;
        --compiler-prefix=*)   ARG_COMPILER_PREFIX=`echo "$arg" | cut -d = -f 2`;;
		--help)       help;;
		*)            err=1; echo "[ERROR] Option '$arg' unsupported";;
	esac
done
[ "$err" ] && exit 1

advopts=

if [ "$TMPDIR" != "" ]; then
  tmpdir=$TMPDIR
else
  tmpdir=/tmp
fi
echo Using temporary directory $tmpdir

if test -r "configure"; then
 # this is a check for a configure script in the current directory, if there
 # is one, try to figure out if it is this one!

 if { grep "^#   Jukebox" configure >/dev/null 2>&1 ; } then
   echo "WEEEEEEEEP. Don't run this configure script within the tools directory."
   echo "It will only cause you pain and grief. Instead do this:"
   echo ""
   echo " cd .."
   echo " mkdir build-dir"
   echo " cd build-dir"
   echo " ../tools/configure"
   echo ""
   echo "Much happiness will arise from this. Enjoy"
   exit 5
 fi
fi

if test -r "tools/configure"; then
 # this is a check for a configure script in the tools/ directory, if there
 # is one, try to figure out if it is this one!

 if { grep "^#   Jukebox" tools/configure >/dev/null 2>&1 ; } then
   echo "WEEEEEEEEP. Don't run this configure script in the root of the tree."
   echo "It will only cause you pain and grief. Instead do this:"
   echo ""
   echo " mkdir build-dir"
   echo " cd build-dir"
   echo " ../tools/configure"
   echo ""
   echo "Much happiness will arise from this. Enjoy"
   exit 5
 fi
fi

# get our current directory
pwd=`pwd`;

if { echo $pwd | grep " "; } then
  echo "You're running this script in a path that contains space. The build"
  echo "system is unfortunately not clever enough to deal with this. Please"
  echo "run the script from a different path, rename the path or fix the build"
  echo "system!"
  exit 6
fi

if [ -z "$rootdir" ]; then
  ##################################################################
  # Figure out where the source code root is!
  #
  rootdir=`dirname $0`/../

  #####################################################################
  # Convert the possibly relative directory name to an absolute version
  #
  now=`pwd`
  cd $rootdir
  rootdir=`pwd`

  # cd back to the build dir
  cd $now
fi

apps="apps"
appsdir='$(ROOTDIR)/apps'
toolsdir='$(ROOTDIR)/tools'


##################################################################
# Figure out target platform
#

if [ "$ARG_TARGET" ]; then
  buildfor=$ARG_TARGET
else
  echo "Enter target platform:"
cat <<EOF
 ==Cowon/iAudio==         ==iriver==             ==Apple iPod==
 30) X5/X5V/X5L           10) H120/H140          20) Color/Photo
 31) M5/M5L               11) H320/H340          21) Nano 1G
                          12) iHP-100/110/115    22) Video
 33) D2                                          23) 3G
 34) M3/M3L               14) H10 20Gb           24) 4G Grayscale
                          15) H10 5/6Gb          25) Mini 1G
 ==Creative==                                    26) Mini 2G
 89) Zen X-Fi Style       ==Toshiba==            27) 1G, 2G
 90) Zen Vision:M 30GB    40) Gigabeat F/X       28) Nano 2G
 91) Zen Vision:M 60GB    41) Gigabeat S         29) Classic/6G
 92) Zen Vision
 93) Zen X-Fi2            ==Olympus=             ==SanDisk==
 94) Zen X-Fi3            70) M:Robe 500         50) Sansa e200
 96) Zen X-Fi             71) M:Robe 100         51) Sansa e200R
 97) Zen Mozaic                                  52) Sansa c200
 98) Zen                  ==Philips==
                          100) GoGear SA9200
 ==Onda==                 101) GoGear HDD1630/   55) Sansa Clip
 120) VX747                    HDD1830           56) Sansa e200v2
 121) VX767               102) GoGear HDD6330    57) Sansa m200v4
 122) VX747+                                     58) Sansa Fuze
 123) VX777               ==Meizu==              59) Sansa c200v2
                          110) M6SL              60) Sansa Clipv2
 ==Samsung==              111) M6SP              61) Sansa View
 140) YH-820              112) M3                62) Sansa Clip+
 141) YH-920                                     63) Sansa Fuze v2
 142) YH-925                                     64) Sansa Fuze+
 143) YP-S3                                      65) Sansa Clip Zip
                          ==Packard Bell==       66) Sansa Connect
 ==Application==          160) Vibe 500
 200) SDL
 201) Android             ==MPIO==
 202) Nokia N8xx          170) HD200             ==Lyre project==
 203) Nokia N900          171) HD300             130) Lyre proto 1
 204) Pandora                                    131) Mini2440
 205) Samsung YP-R0       ==ROCKCHIP==
 206) Android MIPS        180) rk27xx generic    ==HiFiMAN==
 207) Android x86                                190) HM-60x
 208) Samsung YP-R1       ==HiFi E.T.==          191) HM-801
                          210) MA9
 ==iBasso==               211) MA9C              ==Sony==
 232) DX50                212) MA8               219) NWZ-E350 series
 233) DX90                213) MA8C              220) NWZ-E370/E380 series
                                                 221) NWZ-E360 series
 ==xDuoo==                ==IHIFI==              222) NWZ-E450 series
 241) X3                  230) 760               223) NWZ-E460 series
 242) X3II                231) 960               224) NWZ-E470 series
 243) X20                 250) 770C              225) NWZ-E580 series
                          251) 770               226) NWZ-A10 series
 ==AgpTek==               252) 800               227) NW-A20 series
 240) Rocker                                     228) NWZ-A860 series
                          ==FiiO==               229) NWZ-S750 series
 ==AIGO==                 244) M3K Linux
 245) Eros Q / K          246) M3K baremetal     ==Shanling==
 247) Eros Q / K native                          260) Q1
EOF

  buildfor=`input`;

fi
  # Set of tools built for all target platforms:
  toolset="rdf2binary convbdf codepages"

  # Toolsets for some target families:
  iriverbitmaptools="$toolset scramble descramble mkboot bmp2rb"
  iaudiobitmaptools="$toolset scramble descramble mkboot bmp2rb"
  ipodbitmaptools="$toolset scramble bmp2rb"
  gigabeatbitmaptools="$toolset scramble descramble bmp2rb"
  tccbitmaptools="$toolset scramble bmp2rb"
  # generic is used by IFP, Meizu and Onda
  genericbitmaptools="$toolset bmp2rb"
  # scramble is used by all other targets
  scramblebitmaptools="$genericbitmaptools scramble"
  # used by X1000 targets
  x1000tools="$genericbitmaptools scramble mkspl-x1000 uclpack"

  #  ---- For each target ----
  #
  #   *Variables*
  # target_id: a unique number identifying this target, IS NOT the menu number.
  #            Just use the currently highest number+1 when you add a new
  #            target.
  # modelname: short model name used all over to identify this target
  # memory:    number of megabytes of RAM this target has. If the amount can
  #            be selected by the size prompt, let memory be unset here
  # target:    -Ddefine passed to the build commands to make the correct
  #            config-*.h file get included etc
  # tool:      the tool that takes a plain binary and converts that into a
  #            working "firmware" file for your target
  # output:    the final output file name
  # boottool:  the tool that takes a plain binary and generates a bootloader
  #            file for your target (or blank to use $tool)
  # bootoutput:the final output file name for the bootloader (or blank to use
  #            $output)
  # appextra:  passed to the APPEXTRA variable in the Makefiles.
  #            TODO: add proper explanation
  # flash:     name of output for flashing, for targets where there's a special
  #            file output for this.
  # plugins:   set to 'yes' to build the plugins. Early development builds can
  #            set this to no in the early stages to have an easier life for a
  #            while
  # toolset:   lists what particular tools in the tools/ directory that this
  #            target needs to have built prior to building Rockbox
  #
  #   *Functions*
  # *cc:       sets up gcc and compiler options for your target builds. Note
  #            that if you select a simulator build, the compiler selection is
  #            overridden later in the script.

  case $buildfor in

  10|iriverh120)
    target_id=9
    modelname="iriverh120"
    target="IRIVER_H120"
    memory=32 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=h120"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 2"
    bmp2rb_remotemono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_remotenative="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.iriver"
    bootoutput="bootloader.iriver"
    appextra="recorder:gui:radio"
    flash="$pwd/rombox.iriver"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$iriverbitmaptools
    t_cpu="coldfire"
    t_manufacturer="iriver"
    t_model="h100"
    ;;

   11|iriverh300)
    target_id=10
    modelname="iriverh300"
    target="IRIVER_H300"
    memory=32 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=h300"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    bmp2rb_remotemono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_remotenative="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.iriver"
    bootoutput="bootloader.iriver"
    appextra="recorder:gui:radio"
    flash="$pwd/rombox.iriver"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$iriverbitmaptools
    t_cpu="coldfire"
    t_manufacturer="iriver"
    t_model="h300"
    ;;

   12|iriverh100)
    target_id=11
    modelname="iriverh100"
    target="IRIVER_H100"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=h100"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 2"
    bmp2rb_remotemono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_remotenative="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.iriver"
    bootoutput="bootloader.iriver"
    appextra="recorder:gui:radio"
    flash="$pwd/rombox.iriver"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$iriverbitmaptools
    t_cpu="coldfire"
    t_manufacturer="iriver"
    t_model="h100"
    ;;

   14|iriverh10)
    target_id=22
    modelname="iriverh10"
    target="IRIVER_H10"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v3 -model=h10 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v3 -model=h10 -type=RBBL"
    bootoutput="H10_20GC.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="iriver"
    t_model="h10"
    ;;

   15|iriverh10_5gb)
    target_id=24
    modelname="iriverh10_5gb"
    target="IRIVER_H10_5GB"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v2 -model=h105 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v2 -model=h105 -type=RBBL"
    bootoutput="H10.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="iriver"
    t_model="h10"
    ;;

   20|ipodcolor)
    target_id=13
    modelname="ipodcolor"
    target="IPOD_COLOR"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -add=ipco"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="ipod"
    t_model="color"
    ;;

   21|ipodnano1g)
    target_id=14
    modelname="ipodnano1g"
    target="IPOD_NANO"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -add=nano"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="ipod"
    t_model="nano"
    ;;

   22|ipodvideo)
    target_id=15
    modelname="ipodvideo"
    target="IPOD_VIDEO"
    memory=64 # always. This is reduced at runtime if needed
    arm7tdmicc
    tool="$rootdir/tools/scramble -add=ipvd"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="ipod"
    t_model="video"
    ;;

   23|ipod3g)
    target_id=16
    modelname="ipod3g"
    target="IPOD_3G"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -add=ip3g"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 6"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="ipod"
    t_model="3g"
    ;;

   24|ipod4g)
    target_id=17
    modelname="ipod4g"
    target="IPOD_4G"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -add=ip4g"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 6"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="ipod"
    t_model="4g"
    ;;

   25|ipodmini1g)
    target_id=18
    modelname="ipodmini1g"
    target="IPOD_MINI"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -add=mini"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 6"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="ipod"
    t_model="mini"
    ;;

   26|ipodmini2g)
    target_id=21
    modelname="ipodmini2g"
    target="IPOD_MINI2G"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -add=mn2g"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 6"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="ipod"
    t_model="mini2g"
    ;;

   27|ipod1g2g)
    target_id=29
    modelname="ipod1g2g"
    target="IPOD_1G2G"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -add=1g2g"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 6"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="ipod"
    t_model="1g2g"
    ;;

   28|ipodnano2g)
    target_id=62
    modelname="ipodnano2g"
    target="IPOD_NANO2G"
    memory=32 # always
    arm940tcc
    tool="$rootdir/tools/scramble -add=nn2g"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="s5l8700"
    t_model="ipodnano2g"
    ;;

   29|ipod6g)
    target_id=71
    modelname="ipod6g"
    target="IPOD_6G"
    memory=64 # always
    arm926ejscc
    tool="$rootdir/tools/scramble -add=ip6g"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.ipod"
    appextra="recorder:gui:radio"
    plugins="yes"
    bootoutput="bootloader-$modelname.ipod"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="s5l8702"
    t_model="ipod6g"
    ;;

   30|iaudiox5)
    target_id=12
    modelname="iaudiox5"
    target="IAUDIO_X5"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=iax5"
    boottool="$rootdir/tools/scramble -iaudiox5"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    bmp2rb_remotemono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_remotenative="$rootdir/tools/bmp2rb -f 7"
    output="rockbox.iaudio"
    bootoutput="x5_fw.bin"
    appextra="recorder:gui:radio"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$iaudiobitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="coldfire"
    t_manufacturer="iaudio"
    t_model="x5"
    ;;

   31|iaudiom5)
    target_id=28
    modelname="iaudiom5"
    target="IAUDIO_M5"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=iam5"
    boottool="$rootdir/tools/scramble -iaudiom5"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 2"
    bmp2rb_remotemono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_remotenative="$rootdir/tools/bmp2rb -f 7"
    output="rockbox.iaudio"
    bootoutput="m5_fw.bin"
    appextra="recorder:gui:radio"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$iaudiobitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="coldfire"
    t_manufacturer="iaudio"
    t_model="m5"
    ;;

    33|cowond2)
    target_id=34
    modelname="cowond2"
    target="COWON_D2"
    memory=32
    arm926ejscc
    tool="$rootdir/tools/scramble -add=d2"
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.d2"
    bootoutput="bootloader-cowond2.bin"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset="$tccbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tcc780x"
    t_model="cowond2"
    ;;

   34|iaudiom3)
    target_id=37
    modelname="iaudiom3"
    target="IAUDIO_M3"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=iam3"
    boottool="$rootdir/tools/scramble -iaudiom3"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 7"
    output="rockbox.iaudio"
    bootoutput="cowon_m3.bin"
    appextra="recorder:gui:radio"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$iaudiobitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="coldfire"
    t_manufacturer="iaudio"
    t_model="m3"
    ;;

   40|gigabeatfx)
    target_id=20
    modelname="gigabeatfx"
    target="GIGABEAT_F"
    memory=32 # always
    arm9tdmicc
    tool="$rootdir/tools/scramble -add=giga"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.gigabeat"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$gigabeatbitmaptools
    boottool="$rootdir/tools/scramble -gigabeat"
    bootoutput="FWIMG01.DAT"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="s3c2440"
    t_model="gigabeat-fx"
    ;;

    41|gigabeats)
    target_id=26
    modelname="gigabeats"
    target="GIGABEAT_S"
    memory=64
    arm1136jfscc
    tool="$rootdir/tools/scramble -add=gigs"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.gigabeat"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset="$gigabeatbitmaptools"
    boottool="$rootdir/tools/scramble -gigabeats"
    bootoutput="nk.bin"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="imx31"
    t_model="gigabeat-s"
    ;;

    70|mrobe500)
    target_id=36
    modelname="mrobe500"
    target="MROBE_500"
    memory=64 # always
    arm926ejscc
    tool="$rootdir/tools/scramble -add=m500"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 8"
    bmp2rb_remotemono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_remotenative="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.mrobe500"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$gigabeatbitmaptools
    boottool="cp "
    bootoutput="rockbox.mrboot"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tms320dm320"
    t_model="mrobe-500"
    ;;

   71|mrobe100)
    target_id=33
    modelname="mrobe100"
    target="MROBE_100"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v2 -model=m100 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_remotemono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_remotenative="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v2 -model=m100 -type=RBBL"
    bootoutput="pp5020.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="olympus"
    t_model="mrobe-100"
    ;;

    89|creativezenxfistyle)
    target_id=94
    modelname="creativezenxfistyle"
    target="CREATIVE_ZENXFISTYLE"
    memory=64
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=zxfs"
    output="rockbox.creative"
    bootoutput="bootloader-zenxfistyle.creative"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="creative-zen"
    arm926ejscc
    ;;

    90|zenvisionm30gb)
    target_id=35
    modelname="zenvisionm30gb"
    target="CREATIVE_ZVM"
    memory=64
    arm926ejscc
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -creative=zvm"
    USE_ELF="yes"
    output="rockbox.zvm"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$ipodbitmaptools
    boottool="$rootdir/tools/scramble -creative=zvm -no-ciff"
    bootoutput="rockbox.zvmboot"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tms320dm320"
    t_model="creative-zvm"
    ;;

    91|zenvisionm60gb)
    target_id=40
    modelname="zenvisionm60gb"
    target="CREATIVE_ZVM60GB"
    memory=64
    arm926ejscc
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -creative=zvm60 -no-ciff"
    USE_ELF="yes"
    output="rockbox.zvm60"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$ipodbitmaptools
    boottool="$rootdir/tools/scramble -creative=zvm60"
    bootoutput="rockbox.zvm60boot"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tms320dm320"
    t_model="creative-zvm"
    ;;

    92|zenvision)
    target_id=39
    modelname="zenvision"
    target="CREATIVE_ZV"
    memory=64
    arm926ejscc
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -creative=zenvision -no-ciff"
    USE_ELF="yes"
    output="rockbox.zv"
    appextra="recorder:gui:radio"
    plugins=""
    toolset=$ipodbitmaptools
    boottool="$rootdir/tools/scramble -creative=zenvision"
    bootoutput="rockbox.zvboot"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tms320dm320"
    t_model="creative-zvm"
    ;;

   93|creativezenxfi2)
    target_id=80
    modelname="creativezenxfi2"
    target="CREATIVE_ZENXFI2"
    memory=64
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=zxf2"
    output="rockbox.creative"
    bootoutput="bootloader-zenxfi2.creative"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="creative-zenxfi2"
    arm926ejscc
    ;;

   94|creativezenxfi3)
    target_id=81
    modelname="creativezenxfi3"
    target="CREATIVE_ZENXFI3"
    memory=64
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=zxf3"
    output="rockbox.creative"
    bootoutput="bootloader-zenxfi3.creative"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="creative-zenxfi3"
    arm926ejscc
    ;;

    95|creativezenv)
    target_id=92
    modelname="creativezenv"
    target="CREATIVE_ZENV"
    memory=32
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=zenv"
    output="rockbox.creative"
    bootoutput="bootloader-zenv.creative"
    appextra="radio:gui:recorder"
    plugins=""
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="creative-zen"
    arm926ejscc
    ;;

   96|creativezenxfi)
    target_id=86
    modelname="creativezenxfi"
    target="CREATIVE_ZENXFI"
    memory=64
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 9"
    tool="$rootdir/tools/scramble -add=zxfi"
    output="rockbox.creative"
    bootoutput="bootloader-zenxfi.creative"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="creative-zen"
    arm926ejscc
    ;;

   97|creativezenmozaic)
    target_id=87
    modelname="creativezenmozaic"
    target="CREATIVE_ZENMOZAIC"
    memory=32
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=zmoz"
    output="rockbox.creative"
    bootoutput="bootloader-zenmozaic.creative"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="creative-zen"
    arm926ejscc
    ;;

  98|creativezen)
    target_id=90
    modelname="creativezen"
    target="CREATIVE_ZEN"
    memory=32
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 9"
    tool="$rootdir/tools/scramble -add=zen"
    output="rockbox.creative"
    bootoutput="bootloader-zen.creative"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="creative-zen"
    arm926ejscc
    ;;


   50|sansae200)
    target_id=23
    modelname="sansae200"
    target="SANSA_E200"
    memory=32 # supposedly
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v3 -model=e200 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v3 -model=e200 -type=RBBL"
    bootoutput="PP5022.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="sandisk"
    t_model="sansa-e200"
    ;;

   51|sansae200r)
    # the e200R model is pretty much identical to the e200, it only has a
    # different option to the scramble tool when building a bootloader and
    # makes the bootloader output file name in all lower case.
    target_id=27
    modelname="sansae200r"
    target="SANSA_E200"
    memory=32 # supposedly
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v3 -model=e20r -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4r -model=e20r -type=RBBL"
    bootoutput="pp5022.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="sandisk"
    t_model="sansa-e200"
    ;;

   52|sansac200)
    target_id=30
    modelname="sansac200"
    target="SANSA_C200"
    memory=32 # supposedly
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v3 -model=c200 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v3 -model=c200 -type=RBBL"
    bootoutput="firmware.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="sandisk"
    t_model="sansa-c200"
    ;;

   55|sansaclip)
    target_id=50
    modelname="sansaclip"
    target="SANSA_CLIP"
    memory=2
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$bmp2rb_mono"
    tool="$rootdir/tools/scramble -add=clip"
    output="rockbox.sansa"
    bootoutput="bootloader-clip.sansa"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-clip"
    sysfont="08-Rockfont"
    if [ "$ARG_ARM_THUMB" != 0 ]; then ARG_ARM_THUMB=1; fi
    arm9tdmicc
    ;;

   56|sansae200v2)
    target_id=51
    modelname="sansae200v2"
    target="SANSA_E200V2"
    memory=8
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=e2v2"
    output="rockbox.sansa"
    bootoutput="bootloader-e200v2.sansa"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    arm_thumb_boot=1
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-e200v2"
    arm9tdmicc
    ;;


   57|sansam200v4)
    target_id=52
    modelname="sansam200v4"
    target="SANSA_M200V4"
    memory=2
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$bmp2rb_mono"
    tool="$rootdir/tools/scramble -add=m2v4"
    output="rockbox.sansa"
    bootoutput="bootloader-m200v4.sansa"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-m200v4"
    sysfont="08-Rockfont"
    if [ "$ARG_ARM_THUMB" != 0 ]; then ARG_ARM_THUMB=1; fi
    arm9tdmicc
    ;;


   58|sansafuze)
    target_id=53
    modelname="sansafuze"
    target="SANSA_FUZE"
    memory=8
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=fuze"
    output="rockbox.sansa"
    bootoutput="bootloader-fuze.sansa"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-fuze"
    arm9tdmicc
    ;;


   59|sansac200v2)
    target_id=55
    modelname="sansac200v2"
    target="SANSA_C200V2"
    memory=2 # as per OF diagnosis mode
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=c2v2"
    output="rockbox.sansa"
    bootoutput="bootloader-c200v2.sansa"
    appextra="recorder:gui:radio"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-c200v2"
    if [ "$ARG_ARM_THUMB" != 0 ]; then ARG_ARM_THUMB=1; fi
    arm9tdmicc
    ;;

   60|sansaclipv2)
    target_id=60
    modelname="sansaclipv2"
    target="SANSA_CLIPV2"
    memory=8
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$bmp2rb_mono"
    tool="$rootdir/tools/scramble -add=clv2"
    output="rockbox.sansa"
    bootoutput="bootloader-clipv2.sansa"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-clipv2"
    sysfont="08-Rockfont"
    arm926ejscc
    ;;

   61|sansaview)
    target_id=63
    modelname="sansaview"
    target="SANSA_VIEW"
    memory=32
    arm1176jzscc
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="gui"
    plugins=""
    boottool="$rootdir/tools/scramble -mi4v3 -model=view -type=RBBL"
    bootoutput="firmware.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="sandisk"
    t_model="sansa-view"
    ;;

   62|sansaclipplus)
    target_id=66
    modelname="sansaclipplus"
    target="SANSA_CLIPPLUS"
    memory=8
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$bmp2rb_mono"
    tool="$rootdir/tools/scramble -add=cli+"
    output="rockbox.sansa"
    bootoutput="bootloader-clipplus.sansa"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-clipplus"
    sysfont="08-Rockfont"
    arm926ejscc
    ;;

   63|sansafuzev2)
    target_id=68
    modelname="sansafuzev2"
    target="SANSA_FUZEV2"
    memory=8 # not sure
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
    tool="$rootdir/tools/scramble -add=fuz2"
    output="rockbox.sansa"
    bootoutput="bootloader-fuzev2.sansa"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-fuzev2"
    arm926ejscc
    ;;

   64|sansafuzeplus)
    target_id=80
    modelname="sansafuzeplus"
    target="SANSA_FUZEPLUS"
    memory=64
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=fuz+"
    output="rockbox.sansa"
    bootoutput="bootloader-fuzeplus.sansa"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="sansa-fuzeplus"
    arm926ejscc
    ;;

   65|sansaclipzip)
    target_id=68
    modelname="sansaclipzip"
    target="SANSA_CLIPZIP"
    memory=8 # not sure
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=clzp"
    output="rockbox.sansa"
    bootoutput="bootloader-clipzip.sansa"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-clipzip"
    arm926ejscc
    ;;

   66|sansaconnect)
    target_id=81
    modelname="sansaconnect"
    target="SANSA_CONNECT"
    memory=64
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=conn"
    output="rockbox.sansa"
    bootoutput="bootloader-connect.sansa"
    appextra="recorder:gui"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="tms320dm320"
    t_model="sansa-connect"
    arm926ejscc
    ;;

   100|gogearsa9200)
    target_id=41
    modelname="gogearsa9200"
    target="PHILIPS_SA9200"
    memory=32 # supposedly
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v3 -model=9200 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v3 -model=9200 -type=RBBL"
    bootoutput="FWImage.ebn"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="philips"
    t_model="sa9200"
    ;;

   101|gogearhdd1630)
    target_id=43
    modelname="gogearhdd1630"
    target="PHILIPS_HDD1630"
    memory=32 # supposedly
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v3 -model=1630 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v3 -model=1630 -type=RBBL"
    bootoutput="FWImage.ebn"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="philips"
    t_model="hdd1630"
    ;;

   102|gogearhdd6330)
    target_id=65
    modelname="gogearhdd6330"
    target="PHILIPS_HDD6330"
    memory=64 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v3 -model=6330 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v3 -model=6330 -type=RBBL"
    bootoutput="FWImage.ebn"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="philips"
    t_model="hdd6330"
    ;;

   110|meizum6sl)
    target_id=49
    modelname="meizum6sl"
    target="MEIZU_M6SL"
    memory=16 # always
    arm940tbecc
    tool="cp"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.meizu"
    appextra="recorder:gui:radio"
    plugins="no" #FIXME
    toolset=$genericbitmaptools
    boottool="cp"
    bootoutput="rockboot.ebn"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="s5l8700"
    t_model="meizu-m6sl"
    ;;

   111|meizum6sp)
    target_id=46
    modelname="meizum6sp"
    target="MEIZU_M6SP"
    memory=16 # always
    arm940tbecc
    tool="cp"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.meizu"
    appextra="recorder:gui:radio"
    plugins="no" #FIXME
    toolset=$genericbitmaptools
    boottool="cp"
    bootoutput="rockboot.ebn"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="s5l8700"
    t_model="meizu-m6sp"
    ;;

   112|meizum3)
    target_id=47
    modelname="meizum3"
    target="MEIZU_M3"
    memory=16 # always
    arm940tbecc
    tool="cp"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.meizu"
    appextra="recorder:gui:radio"
    plugins="no" #FIXME
    toolset=$genericbitmaptools
    boottool="cp"
    bootoutput="rockboot.ebn"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="s5l8700"
    t_model="meizu-m3"
    ;;

    120|ondavx747)
    target_id=45
    modelname="ondavx747"
    target="ONDA_VX747"
    memory=16
    mipselcc
    tool="$rootdir/tools/scramble -add=x747"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.vx747"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    boottool="$rootdir/tools/scramble -ccpmp"
    bootoutput="ccpmp.bin"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="mips"
    t_manufacturer="ingenic_jz47xx"
    t_model="onda_vx747"
    ;;

    121|ondavx767)
    target_id=64
    modelname="ondavx767"
    target="ONDA_VX767"
    memory=16 #FIXME
    mipselcc
    tool="cp"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.vx767"
    appextra="recorder:gui:radio"
    plugins="" #FIXME
    toolset=$genericbitmaptools
    boottool="$rootdir/tools/scramble -ccpmp"
    bootoutput="ccpmp.bin"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="mips"
    t_manufacturer="ingenic_jz47xx"
    t_model="onda_vx767"
    ;;

    122|ondavx747p)
    target_id=54
    modelname="ondavx747p"
    target="ONDA_VX747P"
    memory=16
    mipselcc
    tool="$rootdir/tools/scramble -add=747p"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.vx747p"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    boottool="$rootdir/tools/scramble -ccpmp"
    bootoutput="ccpmp.bin"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="mips"
    t_manufacturer="ingenic_jz47xx"
    t_model="onda_vx747"
    ;;

    123|ondavx777)
    target_id=61
    modelname="ondavx777"
    target="ONDA_VX777"
    memory=16
    mipselcc
    tool="$rootdir/tools/scramble -add=x777"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.vx777"
    appextra="recorder:gui:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    boottool="$rootdir/tools/scramble -ccpmp"
    bootoutput="ccpmp.bin"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="mips"
    t_manufacturer="ingenic_jz47xx"
    t_model="onda_vx747"
    ;;

    130|lyreproto1)
    target_id=56
    modelname="lyreproto1"
    target="LYRE_PROTO1"
    memory=64
    arm926ejscc
    tool="cp"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.lyre"
    appextra="recorder:gui:radio"
    plugins=""
    toolset=$scramblebitmaptools
    boottool="cp"
    bootoutput="bootloader-proto1.lyre"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="at91sam"
    t_model="lyre_proto1"
    ;;

   131|mini2440)
    target_id=99
    modelname="mini2440"
    target="MINI2440"
    memory=64
    arm9tdmicc
    tool="$rootdir/tools/scramble -add=m244"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mini2440"
    appextra="recorder:gui:radio"
    plugins=""
    toolset=$scramblebitmaptools
    boottool="cp"
    bootoutput="bootloader-mini2440.lyre"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="s3c2440"
    t_model="mini2440"
    ;;

   140|samsungyh820)
    target_id=57
    modelname="samsungyh820"
    target="SAMSUNG_YH820"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v2 -model=y820 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v2 -model=y820 -type=RBBL"
    bootoutput="FW_YH820.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="samsung"
    t_model="yh820"
    ;;

   141|samsungyh920)
    target_id=58
    modelname="samsungyh920"
    target="SAMSUNG_YH920"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v2 -model=y920 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 2"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v2 -model=y920 -type=RBBL"
    bootoutput="PP5020.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="samsung"
    t_model="yh920"
    ;;

   142|samsungyh925)
    target_id=59
    modelname="samsungyh925"
    target="SAMSUNG_YH925"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v2 -model=y925 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v2 -model=y925 -type=RBBL"
    bootoutput="FW_YH925.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="samsung"
    t_model="yh925"
    ;;

   143|samsungyps3)
    target_id=72
    modelname="samsungyps3"
    target="SAMSUNG_YPS3"
    memory=16 # always
    arm940tbecc
    tool="cp"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.yps3"
    appextra="recorder:gui:radio"
    plugins="no" #FIXME
    toolset=$genericbitmaptools
    boottool="cp"
    bootoutput="rockboot.ebn"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="s5l8700"
    t_model="yps3"
    ;;

   160|vibe500)
    target_id=67
    modelname="vibe500"
    target="PBELL_VIBE500"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v3 -model=v500 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
    output="rockbox.mi4"
    appextra="recorder:gui:radio"
    plugins="yes"
    boottool="$rootdir/tools/scramble -mi4v3 -model=v500 -type=RBBL"
    bootoutput="jukebox.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_soc="pp"
    t_manufacturer="pbell"
    t_model="vibe500"
    ;;

   170|mpiohd200)
    target_id=69
    modelname="mpiohd200"
    target="MPIO_HD200"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=hd20"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 7"
    output="rockbox.mpio"
    bootoutput="bootloader.mpio"
    appextra="recorder:gui:radio"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="coldfire"
    t_manufacturer="mpio"
    t_model="hd200"
    ;;

   171|mpiohd300)
    target_id=70
    modelname="mpiohd300"
    target="MPIO_HD300"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=hd30"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 2"
    output="rockbox.mpio"
    bootoutput="bootloader.mpio"
    appextra="recorder:gui:radio"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="coldfire"
    t_manufacturer="mpio"
    t_model="hd300"
    ;;

   180|rk27generic)
    target_id=78
    modelname="rk27generic"
    target="RK27_GENERIC"
    memory=16 # always
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=73"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui:radio"
    plugins=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="rk27generic"
    ;;

   190|hifimanhm60x)
    target_id=79
    modelname="hifimanhm60x"
    target="HM60X"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=79"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="hm60x"
    ;;

   191|hifimanhm801)
    target_id=82
    modelname="hifimanhm801"
    target="HM801"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=82"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="hm801"
    ;;

   200|sdlapp)
    application="yes"
    target_id=73
    modelname="sdlapp"
    target="SDLAPP"
    app_set_paths
    app_set_lcd_size
    memory=8
    uname=`uname`
    simcc "sdl-app"
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 9"
    output="rockbox"
    bootoutput="rockbox"
    appextra="recorder:gui:radio"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="sdl"
    t_model="app"
    ;;

   201|android)
    application="yes"
    target_id=74
    modelname="android"
    target="ANDROID"
    app_type="android"
    app_set_lcd_size
    sharedir="/data/data/org.rockbox/app_rockbox/rockbox"
    bindir="/data/data/org.rockbox/lib"
    libdir="/data/data/org.rockbox/app_rockbox"
    memory=8
    uname=`uname`
    androidcc 19 armeabi "-march=armv7-a -mtune=cortex-a9 -mfloat-abi=softfp"
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="librockbox.so"
    bootoutput="librockbox.so"
    appextra="recorder:gui:radio:hosted/android"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="android"
    t_model="app"
    ;;

   202|nokian8xx)
    application="yes"
    target_id=75
    modelname="nokian8xx"
    app_type="sdl-app"
    target="NOKIAN8XX"
    sharedir="/opt/rockbox/share/rockbox"
    bindir="/opt/rockbox/bin"
    libdir="/opt/rockbox/lib"
    memory=8
    uname=`uname`
    maemocc 4
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox"
    bootoutput="rockbox"
    appextra="recorder:gui:radio"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="maemo"
    t_model="app"
    ;;

   203|nokian900)
    application="yes"
    target_id=76
    modelname="nokian900"
    app_type="sdl-app"
    target="NOKIAN900"
    sharedir="/opt/rockbox/share/rockbox"
    bindir="/opt/rockbox/bin"
    libdir="/opt/rockbox/lib"
    memory=8
    uname=`uname`
    maemocc 5
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox"
    bootoutput="rockbox"
    appextra="recorder:gui:radio"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="maemo"
    t_model="app"
    ;;

   204|pandora)
    application="yes"
    target_id=77
    modelname="pandora"
    app_type="sdl-app"
    target="PANDORA"
    sharedir="rockbox/share/rockbox"
    bindir="rockbox/bin"
    libdir="rockbox/lib"
    memory=8
    uname=`uname`
    pandoracc
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox"
    bootoutput="rockbox"
    appextra="recorder:gui:radio"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="pandora"
    t_model="app"
    ;;

   205|samsungypr0)
    application="yes"
    target_id=78
    modelname="samsungypr0"
    target="SAMSUNG_YPR0"
    memory=32
    uname=`uname`
    ypr0cc
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 9"
    output="rockbox"
    bootoutput="rockbox"
    appextra="recorder:gui:radio"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="samsungypr"
    t_model="ypr0"
    ;;

   206|androidmips)
    application="yes"
    target_id=74
    modelname="androidmips"
    target="ANDROID"
    app_type="android"
    app_set_lcd_size
    sharedir="/data/data/org.rockbox/app_rockbox/rockbox"
    bindir="/data/data/org.rockbox/lib"
    libdir="/data/data/org.rockbox/app_rockbox"
    memory=8
    uname=`uname`
    androidcc 19 mips
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="librockbox.so"
    bootoutput="librockbox.so"
    appextra="recorder:gui:radio:hosted/android"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="android"
    t_model="app"
    ;;

   207|androidx86)
    application="yes"
    target_id=74
    modelname="androidx86"
    target="ANDROID"
    app_type="android"
    app_set_lcd_size
    sharedir="/data/data/org.rockbox/app_rockbox/rockbox"
    bindir="/data/data/org.rockbox/lib"
    libdir="/data/data/org.rockbox/app_rockbox"
    memory=8
    uname=`uname`
    androidcc 19 x86
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="librockbox.so"
    bootoutput="librockbox.so"
    appextra="recorder:gui:radio:hosted/android"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="android"
    t_model="app"
    ;;

   208|samsungypr1)
    application="yes"
    target_id=93
    modelname="samsungypr1"
    target="SAMSUNG_YPR1"
    memory=32
    uname=`uname`
    # Linux environment and CPU are the same as for R0, use the same gcc options
    ypr0cc
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 9"
    output="rockbox"
    bootoutput="rockbox"
    appextra="recorder:gui:radio"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="samsungypr"
    t_model="ypr1"
    ;;

   210|hifietma9)
    target_id=83
    modelname="hifietma9"
    target="MA9"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=83"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="ma"
    ;;

   211|hifietma9c)
    target_id=84
    modelname="hifietma9c"
    target="MA9C"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=84"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="ma"
    ;;

   212|hifietma8)
    target_id=85
    modelname="hifietma8"
    target="MA8"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=85"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="ma"
    ;;

   213|hifietma8c)
    target_id=91
    modelname="hifietma8c"
    target="MA8C"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=91"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="ma"
    ;;

   219|sonynwze350)
    application="yes"
    target_id=105
    modelname="sonynwze350"
    target="SONY_NWZE350"
    memory=16
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="cp"
    output="rockbox.sony"
    boottool="$rootdir/tools/scramble -add=e350"
    bootoutput="bootloader-nwze350.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    t_cpu="hosted"
    t_manufacturer="sonynwz"
    t_model="nwze350"
    uname=`uname`
    sonynwzcc
    ;;

   220|sonynwze370)
    target_id=88
    modelname="sonynwze370"
    target="SONY_NWZE370"
    memory=32
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=e370"
    output="rockbox.sony"
    bootoutput="bootloader-nwze370.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="sony-nwz"
    arm926ejscc
    ;;

   221|sonynwze360)
    target_id=89
    modelname="sonynwze360"
    target="SONY_NWZE360"
    memory=32
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="$rootdir/tools/scramble -add=e360"
    output="rockbox.sony"
    bootoutput="bootloader-nwze360.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="imx233"
    t_model="sony-nwz"
    arm926ejscc
    ;;

   222|sonynwze450)
    application="yes"
    target_id=96
    modelname="sonynwze450"
    target="SONY_NWZE450"
    memory=16
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="cp"
    output="rockbox.sony"
    boottool="$rootdir/tools/scramble -add=e450"
    bootoutput="bootloader-nwze450.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    t_cpu="hosted"
    t_manufacturer="sonynwz"
    t_model="nwze450"
    uname=`uname`
    sonynwzcc
    ;;

   223|sonynwze460)
    application="yes"
    target_id=97
    modelname="sonynwze460"
    target="SONY_NWZE460"
    memory=16
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="cp"
    output="rockbox.sony"
    boottool="$rootdir/tools/scramble -add=e460"
    bootoutput="bootloader-nwze460.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    t_cpu="hosted"
    t_manufacturer="sonynwz"
    t_model="nwze460"
    uname=`uname`
    sonynwzcc
    ;;

   224|sonynwze470)
    application="yes"
    target_id=100
    modelname="sonynwze470"
    target="SONY_NWZE470"
    memory=16
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="cp"
    output="rockbox.sony"
    boottool="$rootdir/tools/scramble -add=e470"
    bootoutput="bootloader-nwze470.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    t_cpu="hosted"
    t_manufacturer="sonynwz"
    t_model="nwze470"
    uname=`uname`
    sonynwzcc
    ;;

   225|sonynwze580)
    application="yes"
    target_id=98
    modelname="sonynwze580"
    target="SONY_NWZE580"
    memory=16
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="cp"
    output="rockbox.sony"
    boottool="$rootdir/tools/scramble -add=e580"
    bootoutput="bootloader-nwze580.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    t_cpu="hosted"
    t_manufacturer="sonynwz"
    t_model="nwze580"
    uname=`uname`
    sonynwzcc
    ;;

   226|sonynwza10)
    application="yes"
    target_id=101
    modelname="sonynwza10"
    target="SONY_NWZA10"
    memory=16
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="cp"
    output="rockbox.sony"
    boottool="$rootdir/tools/scramble -add=a10"
    bootoutput="bootloader-nwza10.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    t_cpu="hosted"
    t_manufacturer="sonynwz"
    t_model="nwza10"
    uname=`uname`
    sonynwzcc
    ;;

   227|sonynwa20)
    application="yes"
    target_id=102
    modelname="sonynwa20"
    target="SONY_NWA20"
    memory=16
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="cp"
    output="rockbox.sony"
    boottool="$rootdir/tools/scramble -add=a20"
    bootoutput="bootloader-nwa20.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    t_cpu="hosted"
    t_manufacturer="sonynwz"
    t_model="nwa20"
    uname=`uname`
    sonynwzcc
    ;;

   228|sonynwza860)
    application="yes"
    target_id=103
    modelname="sonynwza860"
    target="SONY_NWZA860"
    memory=16
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="cp"
    output="rockbox.sony"
    boottool="$rootdir/tools/scramble -add=a860"
    bootoutput="bootloader-nwza860.sony"
    appextra="gui:recorder:radio"
    plugins=""
    toolset=$genericbitmaptools
    t_cpu="hosted"
    t_manufacturer="sonynwz"
    t_model="nwza860"
    uname=`uname`
    sonynwzcc
    ;;

   229|sonynwzs750)
    application="yes"
    target_id=104
    modelname="sonynwzs750"
    target="SONY_NWZS750"
    memory=16
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    tool="cp"
    output="rockbox.sony"
    boottool="$rootdir/tools/scramble -add=s750"
    bootoutput="bootloader-nwzs750.sony"
    appextra="gui:recorder:radio"
    plugins="yes"
    toolset=$genericbitmaptools
    t_cpu="hosted"
    t_manufacturer="sonynwz"
    t_model="nwzs750"
    uname=`uname`
    sonynwzcc
    ;;

   230|ihifi760)
    target_id=92
    modelname="ihifi760"
    target="IHIFI760"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=92"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="ihifi"
    ;;

   231|ihifi960)
    target_id=93
    modelname="ihifi960"
    target="IHIFI960"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=93"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="ihifi"
    ;;

   232|ibassodx50)
    application="yes"
    target_id=94
    modelname="ibassodx50"
    target="DX50"
    app_type="android_ndk"
    lcd_orientation="landscape"
    # Actually 408260kB
    memory=256
    uname=`uname`
    androidndkcc 16 armeabi "-mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=softfp"
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox"
    bootoutput="rockbox"
    appextra="recorder:gui:hosted"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="ibasso"
    t_model="dx50"
    ;;

    233|ibassodx90)
    application="yes"
    target_id=95
    modelname="ibassodx90"
    target="DX90"
    app_type="android_ndk"
    lcd_orientation="landscape"
    memory=256
    uname=`uname`
    androidndkcc 16 armeabi "-mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=softfp"
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox"
    bootoutput="rockbox"
    appextra="recorder:gui:hosted"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="ibasso"
    t_model="dx90"
    ;;

    240|agptekrocker)
    application="yes"
    app_type="rocker"
    target_id=97
    modelname="agptekrocker"
    target="AGPTEK_ROCKER"
    memory=8
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 10"
    output="rockbox.rocker"
    bootoutput="bootloader.rocker"
    appextra="recorder:gui:hosted"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="agptek"
    t_model="rocker"
    mipsellinuxcc
    ;;

    241|xduoox3)
    target_id=106
    modelname="xduoox3"
    target="XDUOO_X3"
    memory=64
    mipselcc
    tool="$rootdir/tools/scramble -add=xdx3"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$bmp2rb_mono"
    output="rockbox.x3"
    appextra="recorder:gui"
    plugins="yes"
    toolset=$genericbitmaptools
    boottool="cp"
    bootoutput="bootloader-x3.bin"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="mips"
    t_manufacturer="ingenic_jz47xx"
    t_model="xduoo_x3"
    sysfont="08-Rockfont"
    ;;

    242|xduoox3ii)
    target_id=110
    application=yes
    app_type="xduoo"
    modelname="xduoox3ii"
    target="XDUOO_X3II"
    memory=8
    mipsellinuxcc
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 10"
    output="rockbox.x3ii"
    bootoutput="bootloader.x3ii"
    appextra="recorder:gui:hosted"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="xduoo"
    t_model="xduoo_x3ii"
    sysfontbl="16-Terminus"
    ;;

    243|xduoox20)
    target_id=111
    application=yes
    app_type="xduoo"
    modelname="xduoox20"
    target="XDUOO_X20"
    memory=8
    mipsellinuxcc
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 10"
    output="rockbox.x20"
    bootoutput="bootloader.x20"
    appextra="recorder:gui:hosted"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="xduoo"
    t_model="xduoo_x20"
    sysfontbl="16-Terminus"
    ;;

    244|fiiom3klinux)
    application="yes"
    app_type="fiio"
    target_id=112
    modelname="fiiom3klinux"
    target="FIIO_M3K_LINUX"
    memory=16 # XXX Can probably go over 32?
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.m3k"
    bootoutput="bootloader.m3k"
    appextra="recorder:gui:hosted"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="fiio"
    t_model="m3k"
    mipsellinuxcc
    sysfontbl="16-Terminus"
    ;;

    245|aigoerosq|erosq)
    target_id=113
    application=yes
    app_type="erosq"
    modelname="aigoerosq"
    target="EROS_Q"
    memory=8
    mipsellinuxcc
    tool="cp "
    boottool="cp "
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 10"
    output="rockbox.erosq"
    bootoutput="bootloader.erosq"
    appextra="recorder:gui:hosted"
    plugins="yes"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="hosted"
    t_manufacturer="aigo"
    t_model="erosq"
    sysfontbl="16-Terminus"
    ;;

   250|ihifi770c)
    target_id=107
    modelname="ihifi770c"
    target="IHIFI770C"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=97"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="ihifi2"
    ;;

   251|ihifi770)
    target_id=108
    modelname="ihifi770"
    target="IHIFI770"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=98"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="ihifi2"
    ;;

   252|ihifi800)
    target_id=109
    modelname="ihifi800"
    target="IHIFI800"
    memory=16
    arm7ejscc
    tool="$rootdir/tools/scramble -rkw -modelnum=99"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.rkw"
    bootoutput="bootloader.rkw"
    appextra="recorder:gui"
    plugins="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="rk27xx"
    t_model="ihifi2"
    ;;

  246|fiiom3k)
    target_id=114
    modelname="fiiom3k"
    target="FIIO_M3K"
    memory=64
    mipsr2elcc
    appextra="recorder:gui"
    plugins="yes"
    tool="$rootdir/tools/scramble -add=fiiom3k "
    boottool="$rootdir/tools/mkspl-x1000 -type=nand -ppb=2 -bpp=2 "
    output="rockbox.m3k"
    bootoutput="bootloader.m3k"
    sysfontbl="16-Terminus"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$x1000tools"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="mips"
    t_manufacturer="ingenic_x1000"
    t_model="fiiom3k"
    ;;

  260|shanlingq1)
    target_id=115
    modelname="shanlingq1"
    target="SHANLING_Q1"
    memory=64
    mipsr2elcc
    appextra="recorder:gui"
    plugins="yes"
    tool="$rootdir/tools/scramble -add=shq1 "
    boottool="$rootdir/tools/mkspl-x1000 -type=nand -ppb=2 -bpp=2 "
    output="rockbox.q1"
    bootoutput="bootloader.q1"
    sysfontbl="16-Terminus"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$x1000tools"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="mips"
    t_manufacturer="ingenic_x1000"
    t_model="shanlingq1"
    ;;

    247|erosqnative)
    target_id=116
    modelname="erosqnative"
    target="EROS_QN"
    memory=32
    mipsr2elcc
    appextra="recorder:gui"
    plugins="yes"
    tool="$rootdir/tools/scramble -add=erosqnative "
    boottool="$rootdir/tools/mkspl-x1000 -type=nand -ppb=2 -bpp=2 "
    output="rockbox.erosq"
    bootoutput="bootloader.erosq"
    sysfontbl="16-Terminus"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$x1000tools"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="mips"
    t_manufacturer="ingenic_x1000"
    t_model="erosqnative"
    ;;

   *)
    echo "Please select a supported target platform!"
    exit 7
    ;;

  esac

  echo "Platform set to $modelname"


#remove start
############################################################################
# Amount of memory, for those that can differ. They have $memory unset at
# this point.
#

if [ -z "$memory" ]; then
  case $target_id in
  15)
    if [ "$ARG_RAM" ]; then
      size=$ARG_RAM
    else
      echo "Enter size of your RAM (in MB): (Defaults to 32)"
      size=`input`;
    fi
    case $size in
    60|64)
      memory="64"
      ;;
    *)
      memory="32"
      ;;
    esac
    ;;
  *)
    if [ "$ARG_RAM" ]; then
      size=$ARG_RAM
    else
      echo "Enter size of your RAM (in MB): (Defaults to 2)"
      size=`input`;
    fi
    case $size in
    8)
      memory="8"
      ;;
    *)
      memory="2"
      ;;
    esac
    ;;
  esac
  echo "Memory size selected: $memory MB"
  [ "$ARG_TYPE" ] || echo ""
fi
#remove end

##################################################################
# Figure out build "type"
#

case $modelname in
  sansae200r|sansae200)
     gdbstub=", (I)nstaller"
     ;;
  sansac200)
     gdbstub=", (E)raser"
     ;;
  sansae200)
     gdbstub=", (E)raser"
     ;;
  *)
     ;;
esac
if [ "$ARG_TYPE" ]; then
  btype=$ARG_TYPE
else
  echo "Build (N)ormal, (A)dvanced, (S)imulator, (B)ootloader, (C)heckWPS, (D)atabase tool, (W)arble codec tool$gdbstub: (Defaults to N)"
  btype=`input`;
fi

  case $btype in
    [Ii])
      appsdir='$(ROOTDIR)/bootloader'
      apps="bootloader"
      extradefines="$extradefines -DBOOTLOADER -DE200R_INSTALLER -ffunction-sections -fdata-sections"
      bootloader="1"
      echo "e200R-installer build selected"
      ;;
    [Ee])
      appsdir='$(ROOTDIR)/bootloader'
      apps="bootloader"
      extradefines="$extradefines -DBOOTLOADER -DSANSA_PP_ERASE -ffunction-sections -fdata-sections"
      bootloader="1"
      echo "sansa eraser build selected"
      ;;
    [Bb])
      appsdir='$(ROOTDIR)/bootloader'
      apps="bootloader"
      flash=""
      if test -n "$boottool"; then
          tool="$boottool"
      fi
      if test -n "$bootoutput"; then
          output=$bootoutput
      fi
      if test -n "$arm_thumb_boot" && test -z "$ARG_ARM_THUMB"; then
          ARG_ARM_THUMB=1
      fi
      extradefines="$extradefines -DBOOTLOADER -ffunction-sections -fdata-sections"
      bootloader="1"
      if [ -n "${sysfontbl}" ] ; then sysfont=$sysfontbl ; fi
      echo "Bootloader build selected"
      ;;
    [Ss])
      if [ "$modelname" = "sansae200r" ]; then
          echo "Do not use the e200R target for simulator builds.  Use e200 instead."
          exit 8
      fi
      debug="-DDEBUG"
      simulator="yes"
      extradefines="$extradefines -DSIMULATOR -DHAVE_TEST_PLUGINS"
      flash=""
      echo "Simulator build selected"
      ;;
    [Aa]*)
      echo "Advanced build selected"
      whichadvanced $btype
      ;;
    [Cc])
      uname=`uname`
      simcc "checkwps"
      toolset='';
      GCCOPTS='';
      rbdir='.'
      extradefines="$extradefines  -DDEBUG"
      appsdir='$(ROOTDIR)/tools/checkwps';
      output='checkwps.'${modelname};
      echo "CheckWPS build selected"
      ;;
    [Dd])
      uname=`uname`
      simcc "database-sdl"
      toolset='';
      appsdir='$(ROOTDIR)/tools/database';

      case $uname in
          CYGWIN*|MINGW*)
              output="database_${modelname}.exe"
              ;;
          *)
              output='database.'${modelname};
              ;;
      esac
      # architecture, manufacturer and model for the target-tree build
      t_cpu="hosted"
      t_manufacturer="sdl"
      t_model="database"
      echo "Database tool build selected"
      ;;
    [Ww])
      uname=`uname`
      simcc "warble"
      toolset='';
      t_cpu='';
      GCCOPTS='';
      extradefines="$extradefines  -DDEBUG -DWARBLE"
      output='warble.'${modelname};
      echo "Warble build selected"
      ;;
    *)
      if [ "$modelname" = "sansae200r" ]; then
          echo "Do not use the e200R target for regular builds.  Use e200 instead."
          exit 8
      fi
      debug=""
      btype="N" # set it explicitly since RET only gets here as well
      echo "Normal build selected"
      ;;

  esac
  # to be able running "make manual" from non-manual configuration
  case $modelname in
      iriverh1??)
          manualdev="iriverh100"
          ;;
      ipodmini2g)
          manualdev="ipodmini1g"
          ;;
      *)
          manualdev=$modelname
          ;;
  esac

if [ -z "$debug" ]; then
  GCCOPTS="$GCCOPTS $GCCOPTIMIZE"
fi

# if building a simulator for an hosted port, APPLICATION
# define clashes with SIMULATOR define

if [ "yes" = "$simulator" ]; then
    echo Unsetting APPLICATION define for SIMULATOR build
    unset application
fi

if [ "yes" = "$application" ]; then
  echo Building Rockbox as an Application
  extradefines="$extradefines -DAPPLICATION"
fi

echo "Using source code root directory: $rootdir"

uname=`uname`

if [ "yes" = "$simulator" ]; then
  # setup compiler and things for simulator
  simcc "sdl-sim"

  if [ -d "simdisk" ]; then
    echo "Subdirectory 'simdisk' already present"
  else
    mkdir simdisk
    echo "Created a 'simdisk' subdirectory for simulating the hard disk"
  fi
fi

# Now, figure out version number of the (gcc) compiler we are about to use
gccver=`$CC -dumpversion`;

# figure out the binutil version too and display it, mostly for the build
# system etc to be able to see it easier
if [ $uname = "Darwin" ]; then
 ldver=`$LD -v 2>&1 | sed -e 's/[^0-9.-]//g'`
 # Convert LD version to a number major*100 + minor
 ldnum1=`echo $ldver | cut -d . -f1`
 ldnum2=`echo $ldver | cut -d . -f2`
 ldnum=`(expr $ldnum1 "*" 100 + $ldnum2) 2>/dev/null`
else
 ldnum=`$LD --version | sed -n '1p' | sed -e 's/.* \([0-9]*\)\.\([0-9]*\).*/\1\2/'`
fi

if test "$ldnum" -ge "227"; then
  have_nocrossrefs_to="#define HAVE_NOCROSSREFS_TO"
else
  have_nocrossrefs_to="#undef HAVE_NOCROSSREFS_TO"
fi

if [ -z "$gccver" ]; then
  echo "[WARNING] The compiler you must use ($CC) is not in your path!"
  echo "[WARNING] this may cause your build to fail since we cannot do the"
  echo "[WARNING] checks we want now."
else

  # convert gcc version to a number (major*100 + minor).
  # Newer compilers may only return the major number, so we neen to fetch the
  # version using -dumpfullversion. MinGW compilers may return names like
  # "7.3-win32", so me must strip off the last part.
 gccver2=`$CC -dumpfullversion -dumpversion | cut -d "-" -f1`;
 num1=`echo $gccver2 | cut -d . -f1`
 num2=`echo $gccver2 | cut -d . -f2`
 gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`

 # This makes:
 # 3.3.X  => 303
 # 3.4.X  => 304
 # 2.95.3 => 295
 # 7.3-win32 => 703

 echo "Using $CC $gccver ($gccnum)"

 if test "$gccnum" -ge "400"; then
   # gcc 4.0 is just *so* much pickier on arguments that differ in signedness
   # so we ignore that warnings for now
   # -Wno-pointer-sign
   GCCOPTS="$GCCOPTS -Wno-pointer-sign"
 fi

 if test "$gccnum" -ge "402"; then
   # disable warning about "warning: initialized field overwritten" as gcc 4.2
   # and later would throw it for several valid cases
   GCCOPTS="$GCCOPTS -Wno-override-init"
 fi

 if test "$gccnum" -ge "601"; then
   # gcc 6 adds a lot of warnings that while useful are too time-consuming
   # to clean up right away
   GCCOPTS="$GCCOPTS -Wno-shift-negative-value -Wno-unused-const-variable -Wno-nonnull-compare -Wno-tautological-compare"
 fi

 if test "$gccnum" -ge "700"; then
   # gcc 7 spews a bunch of warnings by default
   GCCOPTS="$GCCOPTS -Wno-expansion-to-defined -Wimplicit-fallthrough=0"
 fi

 case $prefix in
   ""|"$CROSS_COMPILE")
     # simulator
   ;;
   *)
   # Verify that the cross-compiler is of a recommended version!
   if test "$gccver" != "$gccchoice"; then
     echo "WARNING: Your cross-compiler $CC $gccver is not of the recommended"
     echo "WARNING: version $gccchoice!"
     echo "WARNING: This may cause your build to fail since it may be a version"
     echo "WARNING: that isn't functional or known to not be the best choice."
     echo "WARNING: If you suffer from build problems, you know that this is"
     echo "WARNING: a likely source for them..."
   fi
   ;;
 esac

fi


echo "Using $LD $ldver"

makever=`make --version | head -1`
echo "Detected make $makever"

if [ "$ARG_CCACHE" = "1" ]; then
  echo "Enable ccache for building"
  ccache="ccache"
elif [ "$ARG_CCACHE" != "0" ]; then
  ccache=`findtool ccache`
  if test -n "$ccache"; then
    echo "Found and uses ccache ($ccache)"
  fi
else
  CCACHE_ARG="export CCACHE_DISABLE=true"
fi

# figure out the full path to the various commands if possible
HOSTCC=`findtool gcc --lit`
HOSTAR=`findtool ar --lit`
CC=`findtool ${CC} --lit`
CPP=`findtool ${CPP} --lit`
LD=`findtool ${LD} --lit`
AR=`findtool ${AR} --lit`
AS=`findtool ${AS} --lit`
OC=`findtool ${OC} --lit`
WINDRES=`findtool ${WINDRES} --lit`
DLLTOOL=`findtool ${DLLTOOL} --lit`
DLLWRAP=`findtool ${DLLWRAP} --lit`
RANLIB=`findtool ${RANLIB} --lit`

# in pure cross-compiler environments without own native compiler this helps:
HOSTCC=${HOSTCC:-${CC}}
HOSTAR=${HOSTAR:-${AR}}

if [ -z "$arch" ]; then
    cpp_defines=$(echo "" | $CPP $GCCOPTS -dD)
    if [ -n "$(echo $cpp_defines | grep -w __m68k__)" ]; then
        arch="m68k"
    elif [ -n "$(echo $cpp_defines | grep -w __arm__)" ]; then
        arch="arm"
        # cpp defines like "#define __ARM_ARCH_4TE__ 1" (where we want to extract the 4)
        arch_version="$(echo $cpp_defines | tr ' ' '\012' | grep __ARM_ARCH | sed -e 's,.*\([0-9]\).*,\1,' | grep -v __ARM_ARCH | head -1)"
	if test "$gccnum" -ge "800"; then
	    # GCC8+ can natively emit unified asm syntax
	    GCCOPTS="$GCCOPTS -masm-syntax-unified"
	fi
    elif [ -n "$(echo $cpp_defines | grep -w __mips__)" ]; then
        arch="mips"
        arch_version="$(echo $cpp_defines | tr ' ' '\012' | grep _MIPS_ARCH_MIPS | sed -e 's,.*\([0-9][0-9]\).*,\1,' | grep -v _MIPS_ARCH_MIPS)"
    elif [ -n "$(echo $cpp_defines | grep -w __i386__)" ]; then
        arch="x86"
    elif [ -n "$(echo $cpp_defines | grep -w __x86_64__)" ]; then
        arch="amd64"
    else
        arch="none"
        echo "Warning: Could not determine target arch"
    fi
    if [ "$arch" != "none" ]; then
        if [ -n "$arch_version" ]; then
            echo "Automatically selected arch: $arch (ver $arch_version)"
        else
            echo "Automatically selected arch: $arch"
        fi
    fi;
else
    if [ -n "$arch_version" ]; then
        echo "Manually selected arch: $arch (ver $arch_version)"
    else
        echo "Manually selected arch: $arch"
    fi
fi

arch="arch_$arch"
if [ -n "$arch_version" ]; then
    Darch_version="#define ARCH_VERSION $arch_version"
fi

if test -n "$ccache"; then
  CC="$ccache $CC"
fi

if test "$ARG_ARM_THUMB" = "1"; then
  extradefines="$extradefines -DUSE_THUMB"
  CC="$toolsdir/thumb-cc.py $CC"
fi

if test "X$endian" = "Xbig"; then
  defendian="ROCKBOX_BIG_ENDIAN"
else
  defendian="ROCKBOX_LITTLE_ENDIAN"
fi

if [ "$ARG_RBDIR" != "" ]; then
    if [ -z `echo $ARG_RBDIR | grep '^/'` ]; then
        rbdir="/"$ARG_RBDIR
    else
        rbdir=$ARG_RBDIR
    fi
  echo "Using alternate rockbox dir: ${rbdir}"
fi

cat > autoconf.h.new <<EOF
/* This header was made by configure */
#ifndef __BUILD_AUTOCONF_H
#define __BUILD_AUTOCONF_H

/* lower case names match the what's exported in the Makefile
 * upper case name looks nicer in the code */

#define arch_none 0
#define ARCH_NONE 0

#define arch_sh 1
#define ARCH_SH 1

#define arch_m68k 2
#define ARCH_M68K 2

#define arch_arm 3
#define ARCH_ARM 3

#define arch_mips 4
#define ARCH_MIPS 4

#define arch_x86 5
#define ARCH_X86 5

#define arch_amd64 6
#define ARCH_AMD64 6

/* Define target machine architecture */
#define ARCH ${arch}
/* Optionally define architecture version */
${Darch_version}

/* Define endianess for the target or simulator platform */
#define ${defendian} 1

/* Define the GCC version used for the build */
#define GCCNUM ${gccnum}

/* Define this if you build rockbox to support the logf logging and display */
${use_logf}

/* Define this if you want logf to output to the serial port */
${use_logf_serial}

/* Define this to record a chart with timings for the stages of boot */
${use_bootchart}

/* optional define for FM radio mod for iAudio M5 */
${have_fmradio_in}

/* optional define for USB Serial */
${use_usb_serial}

/* optional defines for RTC mod for h1x0 */
${config_rtc}
${have_rtc_alarm}

/* the threading backend we use */
#define ${thread_support}

/* lcd dimensions for application builds from configure */
${app_lcd_width}
${app_lcd_height}

/* root of Rockbox */
#define ROCKBOX_DIR "${rbdir}"
#define ROCKBOX_SHARE_PATH "${sharedir}"
#define ROCKBOX_BINARY_PATH "${bindir}"
#define ROCKBOX_LIBRARY_PATH "${libdir}"

/* linker feature test macro for validating cross-section references */
${have_nocrossrefs_to}

#endif /* __BUILD_AUTOCONF_H */
EOF

# Make sure the file is different.
if ! diff -q autoconf.h.new autoconf.h > /dev/null 2>&1 ; then
    mv autoconf.h.new autoconf.h
    echo "Created autoconf.h"
else
    rm -f autoconf.h.new
fi

if test -n "$t_cpu"; then
  TARGET_INC="-I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer/$t_model"

  if [ "$application" = "yes" ] && [ "$t_manufacturer" = "maemo" ]; then
    # Maemo needs the SDL port, too
    TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/sdl/app"
    TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/sdl"
  elif [ "$application" = "yes" ] && [ "$t_manufacturer" = "pandora" ]; then
    # Pandora needs the SDL port, too
    TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/sdl/app"
    TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/sdl"
  elif [ "$simulator" = "yes" ]; then # a few more includes for the sim target tree
    TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/sdl"
    TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted"
  elif [ "$t_manufacturer" = "ibasso" ]; then
    TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/ibasso/tinyalsa/include"
  fi

  TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer"
  test -n "$t_soc" && TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu/$t_soc"
  TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu"
  GCCOPTS="$GCCOPTS"
fi

voicetoolset="rbspeexenc voicefont wavtrim"

if test "$apps" = "apps"; then
  # only when we build "real" apps we build the .lng files
  buildlangs="langs"
fi

#### Fix the cmdline ###
if [ -n "$ARG_PREFIX" ]; then
  cmdline="$cmdline --prefix=\$(PREFIX)"
fi
if [ -n "$ARG_LCDWIDTH" ]; then
  cmdline="$cmdline --lcdwidth=$ARG_LCDWIDTH --lcdheight=$ARG_LCDHEIGHT "
fi

# remove parts from the cmdline we're going to set unconditionally
cmdline=`echo $cmdline | sed -e s,--target=[a-zA-Z_0-9]\*,,g \
                            -e s,--ram=[0-9]\*,,g \
                            -e s,--rbdir=[./a-zA-Z0-9]\*,,g \
                            -e s,--voice=[-_./a-zA-Z0-9]\*,,g \
                            -e s,--type=[a-zA-Z]\*,,g`
cmdline="$cmdline --target=\$(MODELNAME) --ram=\$(MEMORYSIZE) --rbdir=\$(RBDIR) --type=$btype$advopts"

### end of cmdline

cat > Makefile <<EOF
## Automatically generated. http://www.rockbox.org/

export ROOTDIR=${rootdir}
export FIRMDIR=\$(ROOTDIR)/firmware
export APPSDIR=${appsdir}
export TOOLSDIR=${toolsdir}
export DOCSDIR=${rootdir}/docs
export MANUALDIR=${rootdir}/manual
export DEBUG=${debug}
export MODELNAME=${modelname}
export FLASHFILE=${flash}
export TARGET_ID=${target_id}
export TARGET=-D${target}
export SYSFONT=${sysfont}
export ARCH=${arch}
export ARCH_VERSION=${arch_version}
export CPU=${t_cpu}
export MANUFACTURER=${t_manufacturer}
export OBJDIR=${pwd}
export BUILDDIR=${pwd}
export RBCODEC_BLD=${pwd}/lib/rbcodec
export VOICELANGUAGE=${voicelanguage}
export MEMORYSIZE=${memory}
export BUILDDATE:=\$(shell date -u +'-DYEAR=%Y -DMONTH=%m -DDAY=%d')
export MKFIRMWARE=${tool}
export BMP2RB_MONO=${bmp2rb_mono}
export BMP2RB_NATIVE=${bmp2rb_native}
export BMP2RB_REMOTEMONO=${bmp2rb_remotemono}
export BMP2RB_REMOTENATIVE=${bmp2rb_remotenative}
export BINARY=${output}
export APPEXTRA=${appextra}
export ENABLEDPLUGINS=${plugins}
export EXTRA_DEFINES=${extradefines}
export HOSTCC=${HOSTCC}
export HOSTAR=${HOSTAR}
export CC=${CC}
export CPP=${CPP}
export LD=${LD}
export AR=${AR}
export AS=${AS}
export OC=${OC}
export WINDRES=${WINDRES}
export DLLTOOL=${DLLTOOL}
export DLLWRAP=${DLLWRAP}
export RANLIB=${RANLIB}
export PREFIX=${ARG_PREFIX}
export PROFILE_OPTS=${PROFILE_OPTS}
export APP_TYPE=${app_type}
export APPLICATION=${application}
export SIMDIR=\$(ROOTDIR)/uisimulator/sdl
export GCCOPTS=${GCCOPTS}
export TARGET_INC=${TARGET_INC}
export LOADADDRESS=${loadaddress}
export SHARED_LDFLAGS=${SHARED_LDFLAGS}
export SHARED_CFLAGS=${SHARED_CFLAGS}
export LDOPTS=${LDOPTS}
export GLOBAL_LDOPTS=${GLOBAL_LDOPTS}
export GCCVER=${gccver}
export GCCNUM=${gccnum}
export UNAME=${uname}
export MANUALDEV=${manualdev}
export TTS_OPTS=${TTS_OPTS}
export TTS_ENGINE=${TTS_ENGINE}
export ENC_OPTS=${ENC_OPTS}
export ENCODER=${ENCODER}
export USE_ELF=${USE_ELF}
export RBDIR=${rbdir}
export ROCKBOX_SHARE_PATH=${sharedir}
export ROCKBOX_BINARY_PATH=${bindir}
export ROCKBOX_LIBRARY_PATH=${libdir}
export SDLCONFIG=${sdl}
export LCDORIENTATION=${lcd_orientation}
export ANDROID_ARCH=${ANDROID_ARCH}
export ANDROID_NDK_PATH=${ANDROID_NDK_PATH}
export ANDROID_SDK_PATH=${ANDROID_SDK_PATH}
export ANDROID_PLATFORM_VERSION=${ANDROID_PLATFORM_VERSION}
export TOOLSET=${toolset}
export PIPER_MODEL_DIR=${PIPER_MODEL_DIR}
$CCACHE_ARG
$LTO_ARG

CONFIGURE_OPTIONS=${cmdline}

include \$(TOOLSDIR)/root.make
EOF

echo "Created Makefile"