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

# global CC options for all platforms
CCOPTS="-W -Wall -Wundef -O -nostdlib -ffreestanding -Wstrict-prototypes"

use_logf="#undef ROCKBOX_HAS_LOGF"

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

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

prefixtools () {
 prefix="$1"
 CC=${prefix}gcc
 WINDRES=${prefix}windres
 DLLTOOL=${prefix}dlltool
 DLLWRAP=${prefix}dllwrap
 RANLIB=${prefix}ranlib
 LD=${prefix}ld
 AR=${prefix}ar
 AS=${prefix}as
 OC=${prefix}objcopy
}

crosswincc () {
 # naive approach to selecting a mingw cross-compiler on linux/*nix
 echo "Enabling win32 crosscompiling"

 prefixtools i586-mingw32msvc-

 LDOPTS="-lgdi32 -luser32 -mwindows"
 # add cross-compiler option(s)
 GCCOPTS="$GCCOPTS -mno-cygwin"

 output="rockboxui.exe" # use this as output binary name
 crosscompile="yes"
 endian="little" # windows is little endian
}

# 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
}

# parse the argument list, returns the value after the = in case of a
# option=value type option, returns 0 in case of --ccache or --no-ccache,
# returns 1 if the searched argument type wasn't fount in the argument list
# Usage [var = ]`parse_args <argumenttype>`, i.e. `parse_args target`

# var definitons below are needed so that parse_args can see the arguments
arg1=$1 arg2=$2 arg3=$3 arg4=$4 arg5=$5 arg6=$6 arg7=$7 arg8=$8 arg9=$9

parse_args() {
  ret="1"
  for i in $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9
  do
    if [ "$1" = "--ccache" ]; then
      if [ "$i" = "--ccache" ]; then
        ret="0"
      fi
    elif [ "$1" = "--no-ccache" ]; then
      if [ "$i" = "--no-ccache" ]; then
        ret="0"
      fi
    elif [ "$1" = `echo $i|cut -d'=' -f1` ]; then
      ret=`echo $i|cut -d'=' -f2`
    fi
  done
  echo "$ret"
}

simcc () {

 # default tool setup for native building
 prefixtools ""

 simver=sdl
 GCCOPTS='-W -Wall -g -fno-builtin'

 output="rockboxui" # use this as default output binary name

 # generic sdl-config checker
 sdl=`findtool sdl-config`

 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
 fi

 # default share option, override below if needed
 SHARED_FLAG="-shared"

 case $uname in
   CYGWIN*)
   echo "Cygwin host detected"

   # sdl version
   GCCOPTS="$GCCOPTS `sdl-config --cflags`"
   LDOPTS="`sdl-config --libs` -mconsole"

   output="rockboxui.exe" # use this as output binary name
   ;;

   Linux)
   echo "Linux host detected"
   GCCOPTS="$GCCOPTS"
   if [ "0" != `sdl-config --libs |grep -c mwindows` ]; then
       # Enable crosscompiling if sdl-config is from Windows SDL
       crosswincc
   fi
   GCCOPTS="$GCCOPTS `sdl-config --cflags`"
   LDOPTS="`sdl-config --libs`"
   ;;

   FreeBSD)
   echo "FreeBSD host detected"
   # sdl version
   GCCOPTS="$GCCOPTS `sdl-config --cflags`"
   LDOPTS="`sdl-config --libs`"
   ;;

   Darwin)
   echo "Darwin host detected"
   # sdl version
   GCCOPTS="$GCCOPTS `sdl-config --cflags`"
   LDOPTS="`sdl-config --libs`"
   SHARED_FLAG="-dynamiclib -Wl\,-single_module"
   ;;

   *)
   echo "Unsupported system: $uname, fix configure and retry"
   exit
   ;;
 esac

 if [ "`uname -m`" = "x86_64" ] || [ "`uname -m`" = "amd64" ]; then
   # fPIC is needed to make shared objects link
   # setting visibility to hidden is necessary to avoid strange crashes
   # due to symbol clashing
   GCCOPTS="$GCCOPTS -fPIC -fvisibility=hidden"
 fi

 GCCOPTS="$GCCOPTS -I\$(SIMDIR)"

 if test "X$crosscompile" != "Xyes"; then
   id=$$
   cat >/tmp/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 /tmp/conftest-$id /tmp/conftest-$id.c 2>/dev/null

   if test `/tmp/conftest-$id 2>/dev/null` -gt "1"; then
     # big endian
     endian="big"
   else
     # little endian
     endian="little"
   fi
   echo "Simulator environment deemed $endian endian"

   # use wildcard here to make it work even if it was named *.exe like
   # on cygwin
   rm -f /tmp/conftest-$id*
 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
#
shcc () {
 prefixtools sh-elf-
 GCCOPTS="$CCOPTS -m1"
 GCCOPTIMIZE="-fomit-frame-pointer -fschedule-insns"
 endian="big"
 gccchoice="4.0.3"
}

calmrisccc () {
 prefixtools calmrisc16-unknown-elf-
 GCCOPTS="-Wl\,--no-check-sections $CCOPTS"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="big"
}

coldfirecc () {
 prefixtools m68k-elf-
 GCCOPTS="$CCOPTS -m5206e -Wa\,-m5249 -malign-int -mstrict-align"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="big"
 gccchoice="3.4.6"
}

arm7tdmicc () {
 prefixtools arm-elf-
 GCCOPTS="$CCOPTS -mcpu=arm7tdmi"
 if test "X$1" != "Xshort"; then
   GCCOPTS="$GCCOPTS -mlong-calls"
 fi
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
 gccchoice="4.0.3"
}

arm9tdmicc () {
 prefixtools arm-elf-
 GCCOPTS="$CCOPTS -mcpu=arm9tdmi -mlong-calls"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
 gccchoice="4.0.3"
}

arm946cc () {
 prefixtools arm-elf-
 GCCOPTS="$CCOPTS -mcpu=arm9e -mlong-calls"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
 gccchoice="4.0.3"
}

arm926ejscc () {
 prefixtools arm-elf-
 GCCOPTS="$CCOPTS -mcpu=arm926ej-s -mlong-calls"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
 gccchoice="4.0.3"
}

arm1136jfscc () {
 prefixtools arm-elf-
 GCCOPTS="$CCOPTS -mcpu=arm1136jf-s -mlong-calls"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
 gccchoice="4.0.3"
}

whichadvanced () {
  ##################################################################
  # Prompt for specific developer options
  #
  echo ""
  echo "Enter your developer options (press enter when done)"
  echo -n "(D)EBUG, (L)ogf, (S)imulator, (P)rofiling, (V)oice"
  if [ "$memory" = "2" ]; then
    echo -n ", (8)MB MOD"
  fi
  if [ "$modelname" = "h120" ]; then
    echo -n ", (R)TC MOD"
  fi
  echo ""

  cont=1

  while [ $cont = "1" ]; do

    option=`input`;

    case $option in
      [Dd])
        if [ "yes" = "$profile" ]; then
          echo "Debug is incompatible with profiling"
        else
          echo "define DEBUG"
          use_debug="yes"
        fi
        ;;
      [Ll])
        echo "logf() support enabled"
        logf="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"
        ;;
      8)
        if [ "$memory" = "2" ]; then
          memory="8"
          echo "Memory size selected: 8MB"
        else
          cont=0
        fi
        ;;
      [Rr])
        if [ "$modelname" = "h120" ]; then
          config_rtc="#define CONFIG_RTC RTC_DS1339_DS3231"
          have_rtc_alarm="#define HAVE_RTC_ALARM"
          echo "RTC functions enabled (DS1339/DS3231)"
        else
          cont=0
        fi
        ;;
      *)
        cont=0
        ;;
    esac
  done
  echo "done"

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

    picklang
    voicelanguage=`whichlang`

    if [ -z "$voicelanguage" ]; then
      # pick a default
      voicelanguage="english"
    fi
    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
  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" = "$simulator" ]; then
    debug="-DDEBUG"
    extradefines="$extradefines -DSIMULATOR"
  fi
  if [ "yes" = "$profile" ]; then
    extradefines="$extradefines -DRB_PROFILE"
    PROFILE_OPTS="-finstrument-functions"
  fi
}

# Configure voice settings
voiceconfig () {
    thislang=$1
    echo "Building $thislang voice for $modelname. Select options"
    echo ""

    if [ -f "`which flite`" ]; then
        FLITE="F(l)ite "
        FLITE_OPTS=""
        DEFAULT_TTS="flite"
        DEFAULT_TTS_OPTS=$FLITE_OPTS
        DEFAULT_NOISEFLOOR="500"
        DEFAULT_CHOICE="L"
    fi
    if [ -f "`which espeak`" ]; then
        ESPEAK="(e)Speak "
        ESPEAK_OPTS=""
        DEFAULT_TTS="espeak"
        DEFAULT_TTS_OPTS=$ESPEAK_OPTS
        DEFAULT_NOISEFLOOR="500"
        DEFAULT_CHOICE="e"
    fi
    if [ -f "`which festival`" ]; then
        FESTIVAL="(F)estival "
        case "$thislang" in
            "italiano")
            FESTIVAL_OPTS="--language italian"
            ;;
            "espanol")
            FESTIVAL_OPTS="--language spanish"
            ;;
            "finnish")
            FESTIVAL_OPTS="--language finnish"
            ;;
            "czech")
            FESTIVAL_OPTS="--language czech"
            ;;
            *)
            FESTIVAL_OPTS=""
            ;;
        esac
        DEFAULT_TTS="festival"
        DEFAULT_TTS_OPTS=$FESTIVAL_OPTS
        DEFAULT_NOISEFLOOR="500"
        DEFAULT_CHOICE="F"
    fi
    if [ -f "`which swift`" ]; then
        SWIFT="S(w)ift "
        SWIFT_OPTS=""
        DEFAULT_TTS="swift"
        DEFAULT_TTS_OPTS=$SWIFT_OPTS
        DEFAULT_NOISEFLOOR="500"
        DEFAULT_CHOICE="w"
    fi
    # Allow SAPI if Windows is in use
    if [ -f "`which winver`" ]; then
        SAPI="(S)API "
        SAPI_OPTS=""
        DEFAULT_TTS="sapi"
        DEFAULT_TTS_OPTS=$SAPI_OPTS
        DEFAULT_NOISEFLOOR="500"
        DEFAULT_CHOICE="S"
    fi

    if [ "$FESTIVAL" = "$FLITE" ] && [ "$FLITE" = "$ESPEAK" ] && [ "$ESPEAK" = "$SAPI" ] && [ "$SAPI" = "$SWIFT" ]; then
        echo "You need Festival, eSpeak or Flite in your path, or SAPI available to build voice files"
        exit
    fi

    echo "TTS engine to use: ${FLITE}${FESTIVAL}${ESPEAK}${SAPI}${SWIFT}(${DEFAULT_CHOICE})?"
    option=`input`
    case "$option" in
        [Ll])
        TTS_ENGINE="flite"
        NOISEFLOOR="500" # TODO: check this value
        TTS_OPTS=$FLITE_OPTS
        ;;
        [Ee])
        TTS_ENGINE="espeak"
        NOISEFLOOR="500"
        TTS_OPTS=$ESPEAK_OPTS
        ;;
        [Ff])
        TTS_ENGINE="festival"
        NOISEFLOOR="500"
        TTS_OPTS=$FESTIVAL_OPTS
        ;;
        [Ss])
        TTS_ENGINE="sapi"
        NOISEFLOOR="500"
        TTS_OPTS=$SAPI_OPTS
        ;;
	[Ww])
        TTS_ENGINE="swift"
        NOISEFLOOR="500"
        TTS_OPTS=$SWIFT_OPTS
	;;
        *)
        TTS_ENGINE=$DEFAULT_TTS
        TTS_OPTS=$DEFAULT_TTS_OPTS
        NOISEFLOOR=$DEFAULT_NOISEFLOOR
    esac
    echo "Using $TTS_ENGINE for TTS"

    # Allow the user to input manual commandline options
    printf "Enter $TTS_ENGINE options (enter for defaults \"$TTS_OPTS\"): "
    USER_TTS_OPTS=`input`
    if [ -n "$USER_TTS_OPTS" ]; then
        TTS_OPTS="$USER_TTS_OPTS"
    fi

    echo ""

    if [ "$swcodec" = "yes" ]; then
        ENCODER="rbspeexenc"
        ENC_CMD="rbspeexenc"
        ENC_OPTS="-q 4 -c 10"
    else
        if [ -f "`which lame`" ]; then
            ENCODER="lame"
            ENC_CMD="lame"
            ENC_OPTS="--resample 12 -t -m m -h -V 9 -S -B 64 --vbr-new"
         else
            echo "You need LAME in the system path to build voice files for"
            echo "HWCODEC targets."
            exit
         fi
    fi
 
    echo "Using $ENCODER for encoding voice clips"

    # Allow the user to input manual commandline options
    printf "Enter $ENCODER options (enter for defaults \"$ENC_OPTS\"): "
    USER_ENC_OPTS=`input`
    if [ -n "$USER_ENC_OPTS" ]; then
        ENC_OPTS=$USER_ENC_OPTS
    fi

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

picklang() {
    # figure out which languages that are around
    for file in $rootdir/apps/lang/*.lang; do
        clean=`echo $file | sed -e 's:.*/::g' | cut "-d." -f1`
        langs="$langs $clean"
    done

    num=1
    for one in $langs; do
        echo "$num. $one"
        num=`expr $num + 1`
    done

    read pick
}

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
    echo $output
}

opt=$1

if test "$opt" = "--help"; then
  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 the
                      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. The shortcut is valied.
                      Run without this option to see available types.
    --ccache          Enable ccache use (done by default these days)
    --no-ccache       Disable ccache use
    --help            Shows this message (must not be used with other options)

EOF

  exit
fi

if test -r "configure"; then
 # this is a check for a configure script in the current directory, it 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
 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
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'
firmdir='\$(ROOTDIR)/firmware'
toolsdir='\$(ROOTDIR)/tools'


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

if [ "1" != `parse_args --target` ]; then
  buildfor=`parse_args --target`;
else
  echo "Enter target platform:"
cat <<EOF
 ==Archos==            ==iriver==             ==Apple iPod==
  0) Player/Studio     10) H120/H140          20) Color/Photo
  1) Recorder          11) H320/H340          21) Nano
  2) FM Recorder       12) iHP-100/110/115    22) Video
  3) Recorder v2       13) iFP-790            23) 3G
  4) Ondio SP          14) H10 20Gb           24) 4G Grayscale
  5) Ondio FM          15) H10 5/6Gb          25) Mini 1G
  6) AV300                                    26) Mini 2G
                                              27) 1G, 2G

 ==iAudio==            ==Toshiba==            ==SanDisk==
 30) X5/X5V/X5L        40) Gigabeat F         50) Sansa e200
 31) M5/M5L            41) Gigabeat S         51) Sansa e200R
 32) 7                                        52) Sansa c200
 33) Cowon D2                                 53) Sansa m200
 34) M3/M3L

 ==Tatung==            ==Olympus==            ==Logik==
 60) Elio TPJ-1022     70) M:Robe 500         80) DAX 1GB MP3/DAB
                       71) M:Robe 100
 ==Creative==
 90) Zen Vision:M 30GB
 91) Zen Vision:M 60GB
 92) Zen Vision

EOF

  buildfor=`input`;

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

  # Toolsets for some target families:
  archosbitmaptools="$toolset scramble descramble sh2d uclpack bmp2rb"
  iriverbitmaptools="$toolset scramble descramble mkboot bmp2rb"
  iaudiobitmaptools="$toolset scramble descramble mkboot bmp2rb"
  ipodbitmaptools="$toolset scramble bmp2rb"
  gigabeatbitmaptools="$toolset scramble descramble bmp2rb"
  tccbitmaptools="$toolset scramble mktccboot bmp2rb"
  # generic is used by IFP, H10, Sansa-e200
  genericbitmaptools="$toolset bmp2rb"


  #  ---- 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
  # archosrom: used only for Archos targets that build a special flashable .ucl
  #            image.
  # 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
  # swcodec:   set 'yes' on swcodec targets
  # 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

   0|player)
    target_id=1
    modelname="player"
    target="-DARCHOS_PLAYER"
    shcc
    tool="$rootdir/tools/scramble"
    output="archos.mod"
    appextra="player:gui"
    archosrom="$pwd/rombox.ucl"
    flash="$pwd/rockbox.ucl"
    plugins="yes"
    swcodec=""

    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$toolset scramble descramble sh2d player_unifont uclpack"

    # Note: the convbdf is present in the toolset just because: 1) the
    # firmware/Makefile assumes it is present always, and 2) we will need it when we
    # build the player simulator

    t_cpu="sh"
    t_manufacturer="archos"
    t_model="player"
    ;;

   1|recorder)
    target_id=2
    modelname="recorder"
    target="-DARCHOS_RECORDER"
    shcc
    tool="$rootdir/tools/scramble"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="ajbrec.ajz"
    appextra="recorder:gui"
    #archosrom="$pwd/rombox.ucl"
    flash="$pwd/rockbox.ucl"
    plugins="yes"
    swcodec=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$archosbitmaptools
    t_cpu="sh"
    t_manufacturer="archos"
    t_model="recorder"
    ;;

   2|fmrecorder)
    target_id=3
    modelname="fmrecorder"
    target="-DARCHOS_FMRECORDER"
    shcc
    tool="$rootdir/tools/scramble -fm"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="ajbrec.ajz"
    appextra="recorder:gui"
    #archosrom="$pwd/rombox.ucl"
    flash="$pwd/rockbox.ucl"
    plugins="yes"
    swcodec=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$archosbitmaptools
    t_cpu="sh"
    t_manufacturer="archos"
    t_model="fm_v2"
    ;;

   3|recorderv2)
    target_id=4
    modelname="recorderv2"
    target="-DARCHOS_RECORDERV2"
    shcc
    tool="$rootdir/tools/scramble -v2"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="ajbrec.ajz"
    appextra="recorder:gui"
    #archosrom="$pwd/rombox.ucl"
    flash="$pwd/rockbox.ucl"
    plugins="yes"
    swcodec=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$archosbitmaptools
    t_cpu="sh"
    t_manufacturer="archos"
    t_model="fm_v2"
    ;;

   4|ondiosp)
    target_id=7
    modelname="ondiosp"
    target="-DARCHOS_ONDIOSP"
    shcc
    tool="$rootdir/tools/scramble -osp"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="ajbrec.ajz"
    appextra="recorder:gui"
    archosrom="$pwd/rombox.ucl"
    flash="$pwd/rockbox.ucl"
    plugins="yes"
    swcodec=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$archosbitmaptools
    t_cpu="sh"
    t_manufacturer="archos"
    t_model="ondio"
    ;;

   5|ondiofm)
    target_id=8
    modelname="ondiofm"
    target="-DARCHOS_ONDIOFM"
    shcc
    tool="$rootdir/tools/scramble -ofm"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="ajbrec.ajz"
    appextra="recorder:gui"
    #archosrom="$pwd/rombox.ucl"
    flash="$pwd/rockbox.ucl"
    plugins="yes"
    swcodec=""
    toolset=$archosbitmaptools
    t_cpu="sh"
    t_manufacturer="archos"
    t_model="ondio"
    ;;

   6|av300)
    target_id=38
    modelname="av300"
    target="-DARCHOS_AV300"
    memory=16 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -mm=C"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 6"
    output="cjbm.ajz"
    appextra="recorder:gui"
    plugins="yes"
    swcodec=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$toolset scramble descramble bmp2rb"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="archos"
    t_model="av300"
    ;;

  10|h120)
    target_id=9
    modelname="h120"
    target="-DIRIVER_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"
    appextra="recorder:gui"
    flash="$pwd/rombox.iriver"
    plugins="yes"
    swcodec="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|h300)
    target_id=10
    modelname="h300"
    target="-DIRIVER_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"
    appextra="recorder:gui"
    plugins="yes"
    swcodec="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|h100)
    target_id=11
    modelname="h100"
    target="-DIRIVER_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"
    appextra="recorder:gui"
    flash="$pwd/rombox.iriver"
    plugins="yes"
    swcodec="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"
    ;;

   13|ifp7xx)
    target_id=19
    modelname="ifp7xx"
    target="-DIRIVER_IFP7XX"
    memory=1
    arm7tdmicc short
    tool="cp"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.wma"
    appextra="recorder:gui"
    plugins="yes"
    swcodec="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$genericbitmaptools
    t_cpu="arm"
    t_manufacturer="pnx0101"
    t_model="iriver-ifp7xx"
    ;;

   14|h10)
    target_id=22
    modelname="h10"
    target="-DIRIVER_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"
    plugins="yes"
    swcodec="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="$genericbitmaptools scramble"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="iriver"
    t_model="h10"
    ;;

   15|h10_5gb)
    target_id=24
    modelname="h10_5gb"
    target="-DIRIVER_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"
    plugins="yes"
    swcodec="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="$genericbitmaptools scramble"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="iriver"
    t_model="h10"
    ;;

   20|ipodcolor)
    target_id=13
    modelname="ipodcolor"
    target="-DIPOD_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"
    plugins="yes"
    swcodec="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="ipod"
    t_model="color"
    ;;

   21|ipodnano)
    target_id=14
    modelname="ipodnano"
    target="-DIPOD_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"
    plugins="yes"
    swcodec="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="ipod"
    t_model="nano"
    ;;

   22|ipodvideo)
    target_id=15
    modelname="ipodvideo"
    target="-DIPOD_VIDEO"
    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"
    plugins="yes"
    swcodec="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="ipod"
    t_model="video"
    ;;

   23|ipod3g)
    target_id=16
    modelname="ipod3g"
    target="-DIPOD_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"
    plugins="yes"
    swcodec="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="ipod"
    t_model="3g"
    ;;

   24|ipod4g)
    target_id=17
    modelname="ipod4g"
    target="-DIPOD_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"
    plugins="yes"
    swcodec="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="ipod"
    t_model="4g"
    ;;

   25|ipodmini)
    target_id=18
    modelname="ipodmini"
    target="-DIPOD_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"
    plugins="yes"
    swcodec="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="ipod"
    t_model="mini"
    ;;

   26|ipodmini2g)
    target_id=21
    modelname="ipodmini2g"
    target="-DIPOD_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"
    plugins="yes"
    swcodec="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="ipod"
    t_model="mini2g"
    ;;

   27|ipod1g2g)
    target_id=29
    modelname="ipod1g2g"
    target="-DIPOD_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"
    plugins="yes"
    swcodec="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="ipod"
    t_model="1g2g"
    ;;

   30|x5)
    target_id=12
    modelname="x5"
    target="-DIAUDIO_X5"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=iax5"
    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"
    appextra="recorder:gui"
    plugins="yes"
    swcodec="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|m5)
    target_id=28
    modelname="m5"
    target="-DIAUDIO_M5"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=iam5"
    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"
    appextra="recorder:gui"
    plugins="yes"
    swcodec="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"
    ;;

   32|iaudio7)
    target_id=32
    modelname="iaudio7"
    target="-DIAUDIO_7"
    memory=16 # always
    arm946cc
    tool="$rootdir/tools/scramble -add i7"
    boottool="$rootdir/tools/scramble -tcc=crc"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
    output="rockbox.iaudio"
    appextra="recorder:gui"
    plugins="yes"
    swcodec="yes"
    bootoutput="I7_FW.BIN"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$tccbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tcc77x"
    t_model="iaudio7"
    ;;

    33|cowond2)
    target_id=34
    modelname="cowond2"
    target="-DCOWON_D2"
    memory=32
    arm926ejscc
    tool="$rootdir/tools/scramble -add=d2"
    boottool="$rootdir/tools/scramble -tcc=crc"
    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.iaudio"
    appextra="recorder:gui"
    plugins="yes"
    swcodec="yes"
    toolset="$tccbitmaptools"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tcc780x"
    t_model="cowond2"
    ;;
    
   34|m3)
    target_id=37
    modelname="m3"
    target="-DIAUDIO_M3"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=iam3"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 7"
    output="rockbox.iaudio"
    appextra="recorder:gui"
    plugins="yes"
    swcodec="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|gigabeatf)
    target_id=20
    modelname="gigabeatf"
    target="-DGIGABEAT_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"
    plugins="yes"
    swcodec="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="-DGIGABEAT_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"
    plugins="yes"
    swcodec="yes"
    toolset="$gigabeatbitmaptools mknkboot"
    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="-DMROBE_500"
    memory=64 # always
    arm926ejscc
    # tool="$rootdir/tools/scramble -add=m500"
    tool="cp "
    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.mrobe500"
    appextra="recorder:gui"
    plugins="yes"
    swcodec="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="-DMROBE_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"
    plugins="yes"
    swcodec="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="$genericbitmaptools scramble"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="olympus"
    t_model="mrobe-100"
    ;;

   80|logikdax)
    target_id=31
    modelname="logikdax"
    target="-DLOGIK_DAX"
    memory=2 # always
    arm946cc
    tool="$rootdir/tools/scramble -add=ldax"
    boottool="$rootdir/tools/scramble -tcc=crc"
    bootoutput="player.rom"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.logik"
    appextra="recorder:gui"
    plugins=""
    swcodec="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$tccbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tcc77x"
    t_model="logikdax"
    ;;
	
    90|creativezvm30gb)
    target_id=35
    modelname="creativezvm30"
    target="-DCREATIVE_ZVM"
    memory=64
    arm926ejscc
    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"
    tool="$rootdir/tools/scramble -creative=zvm"
    USE_ELF="yes"
    output="rockbox.zvm"
    appextra="recorder:gui"
    plugins=""
    swcodec="yes"
    toolset=$ipodbitmaptools
    boottool="$rootdir/tools/scramble -creative=zvm"
    bootoutput="rockbox.zvmboot"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tms320dm320"
    t_model="creative-zvm"
    ;;
    
    91|creativezvm60gb)
    target_id=40
    modelname="creativezvm60"
    target="-DCREATIVE_ZVM60GB"
    memory=64
    arm926ejscc
    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"
    tool="$rootdir/tools/scramble -creative=zvm60"
    USE_ELF="yes"
    output="rockbox.zvm60"
    appextra="recorder:gui"
    plugins=""
    swcodec="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|creativezenvision)
    target_id=39
    modelname="creativezv"
    target="-DCREATIVE_ZV"
    memory=64
    arm926ejscc
    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"
    tool="$rootdir/tools/scramble -creative=zenvision"
    USE_ELF="yes"
    output="rockbox.zv"
    appextra="recorder:gui"
    plugins=""
    swcodec="yes"
    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"
    ;;

   50|e200)
    target_id=23
    modelname="e200"
    target="-DSANSA_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"
    plugins="yes"
    swcodec="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="$genericbitmaptools scramble"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="sandisk"
    t_model="sansa-e200"
    ;;

   51|e200r)
    # 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="e200r"
    target="-DSANSA_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"
    plugins="yes"
    swcodec="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="$genericbitmaptools scramble"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="sandisk"
    t_model="sansa-e200"
    ;;

   52|c200)
    target_id=30
    modelname="c200"
    target="-DSANSA_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"
    plugins="yes"
    swcodec="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="$genericbitmaptools scramble"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="sandisk"
    t_model="sansa-c200"
    ;;

   53|m200)
    target_id=31
    modelname="m200"
    target="-DSANSA_M200"
    memory=2 # always
    arm946cc
    tool="$rootdir/tools/scramble -add=m200"
    boottool="$rootdir/tools/scramble -tcc=crc"
    bootoutput="player.rom"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.m200"
    appextra="recorder:gui"
    plugins=""
    swcodec="yes"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$tccbitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tcc77x"
    t_model="m200"
    ;;
	
   60|tpj1022)
    target_id=25
    modelname="tpj1022"
    target="-DELIO_TPJ1022"
    memory=32 # always
    arm7tdmicc
    tool="$rootdir/tools/scramble -add tpj2"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 5"
    output="rockbox.elio"
    appextra="recorder:gui"
    plugins="yes"
    swcodec="yes"
    boottool="$rootdir/tools/scramble -mi4v2"
    bootoutput="pp5020.mi4"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$genericbitmaptools scramble"
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tatung"
    t_model="tpj1022"
    ;;

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

  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)
    echo "Enter size of your RAM (in MB): (Defaults to 32)"
    if [ "1" != `parse_args --ram` ]; then
      size=`parse_args --ram`;
    else
      size=`input`;
    fi
    case $size in
    60|64)
      memory="64"
      ;;
    *)
      memory="32"
      ;;
    esac
    ;;
  *)
    echo "Enter size of your RAM (in MB): (Defaults to 2)"
      if [ "1" != `parse_args --ram` ]; then
        size=`parse_args --ram`;
      else
        size=`input`;
      fi
      case $size in
      8)
        memory="8"
        ;;
      *)
        memory="2"
        ;;
      esac
    ;;
  esac
  echo "Memory size selected: $memory MB"
  echo ""
fi
#remove end

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

  # the ifp7x0 is the only platform that supports building a gdb stub like
  # this
case $modelname in
  ifp7xx)
     gdbstub="(G)DB stub, "
     ;;
  e200r|e200)
     gdbstub="(I)installer, "
     ;;
  *)
     ;;
esac
if [ "1" != `parse_args --type` ]; then
  option=`parse_args --type`;
else
  echo "Build (N)ormal, (A)dvanced, (S)imulator, (B)ootloader, $gdbstub(M)anual: (Defaults to N)"
  option=`input`;
fi

  case $option in
    [Ii])
      appsdir='\$(ROOTDIR)/bootloader'
      apps="bootloader"
      extradefines="-DBOOTLOADER -DE200R_INSTALLER -ffunction-sections -fdata-sections"
      bootloader="1"
      echo "e200R-installer build selected"
      ;;
    [Bb])
      if test $t_manufacturer = "archos"; then
          # Archos SH-based players do this somewhat differently for
          # some reason
          appsdir='\$(ROOTDIR)/flash/bootbox'
          apps="bootbox"
      else
          appsdir='\$(ROOTDIR)/bootloader'
          apps="bootloader"
          flash=""
          if test -n "$boottool"; then
              tool="$boottool"
          fi
          if test -n "$bootoutput"; then
              output=$bootoutput
          fi
      fi
      extradefines="-DBOOTLOADER -ffunction-sections -fdata-sections"
      bootloader="1"
      echo "Bootloader build selected"
      ;;
    [Ss])
      debug="-DDEBUG"
      simulator="yes"
      extradefines="-DSIMULATOR"
      echo "Simulator build selected"
      ;;
    [Aa])
      echo "Advanced build selected"
      whichadvanced
      ;;
    [Gg])
      extradefines="-DSTUB" # for target makefile symbol EXTRA_DEFINES
      appsdir='\$(ROOTDIR)/gdb'
      apps="stub"
      case $modelname in
          ifp7xx)
              output="stub.wma"
              ;;
          *)
              ;;
      esac
      echo "GDB stub build selected"
      ;;
    [Mm])
      toolset='';
      apps="manual"
      echo "Manual build selected"
      ;;
    *)
      if [ "$modelname" = "e200r" ]; then
          echo "Do not use the e200R target for regular builds.  Use e200 instead."
          exit
      fi
      debug=""
      echo "Normal build selected"
      ;;

  esac
  # to be able running "make manual" from non-manual configuration
  case $modelname in
      fmrecorder)
          manualdev="recorderv2fm"
          ;;
      recorderv2)
          manualdev="recorderv2fm"
          ;;
      h1??)
          manualdev="h1xx"
          ;;
      ipodmini2g)
          manualdev="ipodmini"
          ;;
      *)
          manualdev=$modelname
          ;;
  esac

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

echo "Using source code root directory: $rootdir"

# this was once possible to change at build-time, but no more:
language="english"

uname=`uname`

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

  if [ -d "archos" ]; then
    echo "sub directory archos already present"
  else
    mkdir archos
    echo "created an archos 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
ldver=`$LD --version | head -n 1 | sed -e 's/[^0-9.]//g'`

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

  # gccver should now be "3.3.5", "3.4.3", "2.95.3-6" and similar, but don't
  # DEPEND on it

 num1=`echo $gccver | cut -d . -f1`
 num2=`echo $gccver | 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

 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 "401"; then
   # this is a lame hack to avoid "warning: dereferencing type-punned pointer
   # will break strict-aliasing rules"

   GCCOPTS="$GCCOPTS -fno-strict-aliasing"
 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

 case $prefix in
   "")
     # simulator
   ;;
   i586-mingw32msvc-)
     # cross-compile for win32
   ;;
   *)
   # 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"

# check the compiler for SH platforms
if test "$CC" = "sh-elf-gcc"; then
  if test "$gccnum" -lt "400"; then
    echo "WARNING: Consider upgrading your compiler to the 4.0.X series!"
    echo "WARNING: http://www.rockbox.org/twiki/bin/view/Main/CrossCompiler"
  else
    # figure out patch status
    gccpatch=`$CC --version`;

    if { echo $gccpatch | grep "rockbox" >/dev/null 2>&1; } then
      echo "gcc $gccver is rockbox patched"
      # then convert -O to -Os to get smaller binaries!
      GCCOPTS=`echo $GCCOPTS | sed 's/ -O / -Os /'`
    else
      echo "WARNING: You use an unpatched gcc compiler: $gccver"
      echo "WARNING: http://www.rockbox.org/twiki/bin/view/Main/CrossCompiler"
    fi
  fi
fi

if test "$CC" = "m68k-elf-gcc"; then
  # convert -O to -Os to get smaller binaries!
  GCCOPTS=`echo $GCCOPTS | sed 's/ -O / -Os /'`
fi
  for path in $PATH
  do
    # echo "checks for $file in $path" >&2
    if test -f "$path/$file"; then
      echo "$path/$file"
      return
    fi
  done

if [ "1" != `parse_args --ccache` ]; then
  echo "Enable ccache for building"
  ccache="ccache"
else
  if [ "1" = `parse_args --no-ccache` ]; then
    ccache=`findtool ccache`
    if test -n "$ccache"; then
      echo "Found and uses ccache ($ccache)"
    fi
  fi
fi

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

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

sed > autoconf.h \
 -e "s,@ENDIAN@,${defendian},g" \
 -e "s,^#undef ROCKBOX_HAS_LOGF,$use_logf,g" \
 -e "s,@config_rtc@,$config_rtc,g" \
 -e "s,@have_rtc_alarm@,$have_rtc_alarm,g" \
<<EOF
/* This header was made by configure */
#ifndef __BUILD_AUTOCONF_H
#define __BUILD_AUTOCONF_H

/* Define endianess for the target or simulator platform */
#define @ENDIAN@ 1

/* Define this if you build rockbox to support the logf logging and display */
#undef ROCKBOX_HAS_LOGF

/* optional defines for RTC mod for h1x0 */
@config_rtc@
@have_rtc_alarm@

#endif /* __BUILD_AUTOCONF_H */
EOF

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

if test "$simulator" = "yes"; then
  # add simul make stuff on the #SIMUL# line
  simmagic1="s,@SIMUL1@,\$(SILENT)\$(MAKE) -C \$(SIMDIR) OBJDIR=\$(BUILDDIR)/sim,"
  simmagic2="s,@SIMUL2@,\$(SILENT)\$(MAKE) -C \$(ROOTDIR)/uisimulator/common OBJDIR=\$(BUILDDIR)/comsim,"
else
  # delete the lines that match
  simmagic1='/@SIMUL1@/D'
  simmagic2='/@SIMUL2@/D'
fi

if test "$swcodec" = "yes"; then
  voicetoolset="rbspeexenc voicefont wavtrim"
else
  voicetoolset="voicefont wavtrim"
fi

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

sed > Makefile \
 -e "s,@ROOTDIR@,${rootdir},g" \
 -e "s,@DEBUG@,${debug},g" \
 -e "s,@MEMORY@,${memory},g" \
 -e "s,@TARGET_ID@,${target_id},g" \
 -e "s,@TARGET@,${target},g" \
 -e "s,@CPU@,${t_cpu},g" \
 -e "s,@MANUFACTURER@,${t_manufacturer},g" \
 -e "s,@MODELNAME@,${modelname},g" \
 -e "s,@LANGUAGE@,${language},g" \
 -e "s:@VOICELANGUAGE@:${voicelanguage}:g" \
 -e "s,@PWD@,${pwd},g" \
 -e "s,@CC@,${CC},g" \
 -e "s,@LD@,${LD},g" \
 -e "s,@AR@,${AR},g" \
 -e "s,@AS@,${AS},g" \
 -e "s,@OC@,${OC},g" \
 -e "s,@WINDRES@,${WINDRES},g" \
 -e "s,@DLLTOOL@,${DLLTOOL},g" \
 -e "s,@DLLWRAP@,${DLLWRAP},g" \
 -e "s,@RANLIB@,${RANLIB},g" \
 -e "s,@TOOL@,${tool},g" \
 -e "s,@BMP2RB_NATIVE@,${bmp2rb_native},g" \
 -e "s,@BMP2RB_MONO@,${bmp2rb_mono},g" \
 -e "s,@BMP2RB_REMOTENATIVE@,${bmp2rb_remotenative},g" \
 -e "s,@BMP2RB_REMOTEMONO@,${bmp2rb_remotemono},g" \
 -e "s,@OUTPUT@,${output},g" \
 -e "s,@APPEXTRA@,${appextra},g" \
 -e "s,@ARCHOSROM@,${archosrom},g" \
 -e "s,@FLASHFILE@,${flash},g" \
 -e "s,@PLUGINS@,${plugins},g" \
 -e "s,@CODECS@,${swcodec},g" \
 -e "s,@PROFILE_OPTS@,${PROFILE_OPTS},g" \
 -e "s,@SHARED_FLAG@,${SHARED_FLAG},g" \
 -e "s,@GCCOPTS@,${GCCOPTS},g" \
 -e "s,@TARGET_INC@,${TARGET_INC},g" \
 -e "s!@LDOPTS@!${LDOPTS}!g" \
 -e "s,@LOADADDRESS@,${loadaddress},g" \
 -e "s,@EXTRADEF@,${extradefines},g" \
 -e "s,@APPSDIR@,${appsdir},g" \
 -e "s,@FIRMDIR@,${firmdir},g" \
 -e "s,@TOOLSDIR@,${toolsdir},g" \
 -e "s,@APPS@,${apps},g" \
 -e "s,@SIMVER@,${simver},g" \
 -e "s,@GCCVER@,${gccver},g" \
 -e "s,@GCCNUM@,${gccnum},g" \
 -e "s,@UNAME@,${uname},g" \
 -e "s,@ENDIAN@,${defendian},g" \
 -e "s,@TOOLSET@,${toolset},g" \
 -e "${simmagic1}" \
 -e "${simmagic2}" \
 -e "s,@MANUALDEV@,${manualdev},g" \
 -e "s,@ENCODER@,${ENC_CMD},g" \
 -e "s,@ENC_OPTS@,${ENC_OPTS},g" \
 -e "s,@TTS_ENGINE@,${TTS_ENGINE},g" \
 -e "s,@TTS_OPTS@,${TTS_OPTS},g" \
 -e "s,@VOICETOOLSET@,${voicetoolset},g" \
 -e "s,@LANGS@,${buildlangs},g" \
 -e "s,@USE_ELF@,${USE_ELF},g" \
<<EOF
## Automatically generated. http://www.rockbox.org/

ifndef V
SILENT=@
else
VERBOSEOPT=-v
endif

# old 'make' versions don't have the built-in 'info' function
info=old\$(shell echo >&2 "Consider upgrading to GNU make 3.81+ for optimum build performance.")
ifeq (\$(call info),old)
export info=echo "\$\$(1)";
endif

export ROOTDIR=@ROOTDIR@
export FIRMDIR=@FIRMDIR@
export APPSDIR=@APPSDIR@
export TOOLSDIR=@TOOLSDIR@
export DOCSDIR=\$(ROOTDIR)/docs
export MANUALDIR=\${ROOTDIR}/manual
export DEBUG=@DEBUG@
export MODELNAME=@MODELNAME@
export ARCHOSROM=@ARCHOSROM@
export FLASHFILE=@FLASHFILE@
export TARGET_ID=@TARGET_ID@
export TARGET=@TARGET@
export CPU=@CPU@
export MANUFACTURER=@MANUFACTURER@
export OBJDIR=@PWD@
export BUILDDIR=@PWD@
export LANGUAGE=@LANGUAGE@
export VOICELANGUAGE=@VOICELANGUAGE@
export MEMORYSIZE=@MEMORY@
export VERSION=\$(shell \$(ROOTDIR)/tools/svnversion.sh \$(ROOTDIR))
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 SOFTWARECODECS=@CODECS@
export EXTRA_DEFINES=@EXTRADEF@
export HOSTCC=gcc
export HOSTAR=ar
export CC=@CC@
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 PROFILE_OPTS=@PROFILE_OPTS@
export SIMVER=@SIMVER@
export SIMDIR=\$(ROOTDIR)/uisimulator/sdl
export GCCOPTS=@GCCOPTS@
export TARGET_INC=@TARGET_INC@
export LOADADDRESS=@LOADADDRESS@
export SHARED_FLAG=@SHARED_FLAG@
export LDOPTS=@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@

# Do not print "Entering directory ..."
MAKEFLAGS += --no-print-directory

.PHONY: all clean tags zip tools manual bin build info langs

all: info

info: build
	\$(SILENT)\$(TOOLSDIR)/mkinfo.pl \$(BUILDDIR)/rockbox-info.txt

build: tools @LANGS@
	@SIMUL1@
	@SIMUL2@
	\$(SILENT)\$(MAKE) -C \$(FIRMDIR) OBJDIR=\$(BUILDDIR)/firmware
	\$(SILENT)\$(MAKE) -C \$(APPSDIR) OBJDIR=\$(BUILDDIR)/@APPS@

bin: tools @LANGS@
	@SIMUL1@
	@SIMUL2@
	\$(SILENT)\$(MAKE) -C \$(FIRMDIR) OBJDIR=\$(BUILDDIR)/firmware
	\$(SILENT)\$(MAKE) -C \$(APPSDIR) OBJDIR=\$(BUILDDIR)/@APPS@ \$(BUILDDIR)/\$(BINARY)

rocks: tools
	\$(SILENT)\$(MAKE) -C \$(APPSDIR) OBJDIR=\$(BUILDDIR)/@APPS@ rocks

veryclean: clean toolsclean

toolsclean:
	\$(SILENT)\$(MAKE) -C \$(TOOLSDIR) clean

clean:
	\$(SILENT)echo Cleaning build directory
	\$(SILENT)rm -rf rockbox.zip TAGS @APPS@ firmware comsim sim lang.[ch]\
                  manual *.pdf *.a credits.raw @OUTPUT@ bitmaps pluginbitmaps \
                  @ARCHOSROM@ @FLASHFILE@ UI256.bmp rockbox-full.zip \
	          html txt rockbox-manual*.zip sysfont.h rockbox-info.txt \
	          voicefontids *.wav *.mp3 *.voice max_language_size.h

tools:
	\$(SILENT)\$(MAKE) -C \$(TOOLSDIR) CC=\$(HOSTCC) AR=\$(HOSTAR) @TOOLSET@

voicetools:
	\$(SILENT)\$(MAKE) -C \$(TOOLSDIR) CC=\$(HOSTCC) AR=\$(HOSTAR) @VOICETOOLSET@

tags:
	\$(SILENT)rm -f TAGS
	\$(SILENT)\$(MAKE) -C \$(FIRMDIR) tags
	\$(SILENT)\$(MAKE) -C \$(APPSDIR) tags
	\$(SILENT)\$(MAKE) -C \$(APPSDIR)/plugins tags
	\$(SILENT)\$(MAKE) -C \$(APPSDIR)/plugins/lib tags

fontzip:
	\$(SILENT)\$(TOOLSDIR)/buildzip.pl \$(VERBOSEOPT) -t \"\$(MODELNAME)\" -r "\$(ROOTDIR)" -f 1 -o rockbox-fonts.zip \$(TARGET) \$(BINARY)

zip:
	\$(SILENT)for f in \`cat \$(BUILDDIR)/@APPS@/features\`; do feat="\$\$feat:\$\$f" ; done ; \\
	\$(TOOLSDIR)/buildzip.pl \$(VERBOSEOPT) -t \"\$(MODELNAME)\$\$feat\" -i \"\$(TARGET_ID)\"  -r "\$(ROOTDIR)" \$(TARGET) \$(BINARY)

mapzip:
	\$(SILENT)find . -name "*.map" | xargs zip rockbox-maps.zip

fullzip:
	\$(SILENT)for f in \`cat \$(BUILDDIR)/@APPS@/features\`; do feat="\$\$feat:\$\$f" ; done; \\
	\$(TOOLSDIR)/buildzip.pl \$(VERBOSEOPT) -t \"\$(MODELNAME)\$\$feat\" -i \"\$(TARGET_ID)\"  -r "\$(ROOTDIR)" -f 2 -o rockbox-full.zip \$(TARGET) \$(BINARY)

7zip:
	\$(SILENT)for f in \`cat \$(BUILDDIR)/@APPS@/features\`; do feat="\$\$feat:\$\$f" ; done; \\
	\$(TOOLSDIR)/buildzip.pl \$(VERBOSEOPT) -t \"\$(MODELNAME)\$\$feat\" -i \"\$(TARGET_ID)\"  -o "rockbox.7z" -z "7za a" -r "\$(ROOTDIR)" \$(TARGET) \$(BINARY)

tar:
	\$(SILENT)rm -f rockbox.tar
	\$(SILENT)for f in \`cat \$(BUILDDIR)/@APPS@/features\`; do feat="\$\$feat:\$\$f" ; done; \\
	\$(TOOLSDIR)/buildzip.pl \$(VERBOSEOPT) -t \"\$(MODELNAME)\$\$feat\" -i \"\$(TARGET_ID)\"  -o "rockbox.tar" -z "tar --no-recursion -uf" -r "\$(ROOTDIR)" \$(TARGET) \$(BINARY)

bzip2: tar
	\$(SILENT)bzip2 -f9 rockbox.tar

gzip: tar
	\$(SILENT)gzip -f9 rockbox.tar

langs: features
	\$(SILENT)mkdir -p \$(BUILDDIR)/apps/lang
	\$(SILENT)\$(MAKE) -C \$(APPSDIR)/lang OBJDIR=\$(BUILDDIR)/apps/lang

manual: manual-pdf
manual-pdf:
	\$(SILENT)\$(MAKE) -C \$(MANUALDIR) OBJDIR=\$(BUILDDIR)/manual manual-pdf
manual-html:
	\$(SILENT)\$(MAKE) -C \$(MANUALDIR) OBJDIR=\$(BUILDDIR)/manual manual-html
manual-zhtml: manual-zip
manual-txt:
	\$(SILENT)\$(MAKE) -C \$(MANUALDIR) OBJDIR=\$(BUILDDIR)/manual manual-txt
manual-ztxt:
	\$(SILENT)\$(MAKE) -C \$(MANUALDIR) OBJDIR=\$(BUILDDIR)/manual manual-txt-zip
manual-zip:
	\$(SILENT)\$(MAKE) -C \$(MANUALDIR) OBJDIR=\$(BUILDDIR)/manual manual-zip

features: tools
	\$(SILENT)\$(MAKE) -C \$(APPSDIR) OBJDIR=\$(BUILDDIR)/@APPS@ features

help:
	@echo "A few helpful make targets"
	@echo ""
	@echo "all         - builds a full Rockbox (default), including tools"
	@echo "bin         - builds only the Rockbox.<target name> file"
	@echo "rocks       - builds only plugins and codecs"
	@echo "clean       - cleans a build directory (not tools)"
	@echo "veryclean   - cleans the build and tools directories"
	@echo "manual      - builds a manual"
	@echo "manual-html - HTML manual"
	@echo "manual-zip  - HTML manual (zipped)"
	@echo "manual-txt  - txt manual"
	@echo "fullzip     - creates a rockbox.zip of your build with fonts"
	@echo "zip         - creates a rockbox.zip of your build (no fonts)"
	@echo "gzip        - creates a rockbox.tar.gz of your build (no fonts)"
	@echo "bzip2       - creates a rockbox.tar.bz2 of your build (no fonts)"
	@echo "7zip        - creates a rockbox.7z of your build (no fonts)"
	@echo "fontzip     - creates rockbox-fonts.zip"
	@echo "mapzip      - creates rockbox-maps.zip with all .map files"
	@echo "tools       - builds the tools only"
	@echo "voicetools  - builds the voice tools only"
	@echo "install     - installs your build (for simulator builds only)"

EOF

if [ "yes" = "$simulator" ]; then

 cat >> Makefile <<EOF

install:
	@echo "installing a full setup in your archos dir"
	@(\$(MAKE) fullzip && cd archos && unzip -oq ../rockbox-full.zip)
EOF

fi

if [ "yes" = "$voice" ]; then

 cat >> Makefile <<EOF

voice: voicetools features
	\$(SILENT)for f in \`cat \$(BUILDDIR)/${apps}/features\`; do feat="\$\$feat:\$\$f" ; done ; \\
	for lang in \`echo \$(VOICELANGUAGE) |sed "s/,/ /g"\`; do \$(TOOLSDIR)/voice.pl -V -l=\$\$lang -t=\$(MODELNAME)\$\$feat -i=\$(TARGET_ID) -e="\$(ENCODER)" -E="\$(ENC_OPTS)" -s=\$(TTS_ENGINE) -S="\$(TTS_OPTS)"; done \\
EOF

fi

echo "Created Makefile"