summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/ltablib.c
blob: b6d9cb4ac74d7ada27bfa1d429114a16758d257a (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
/*
** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/


#include <stddef.h>

#define ltablib_c
#define LUA_LIB

#include "lua.h"

#include "lauxlib.h"
#include "lualib.h"


#define aux_getn(L,n)	(luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))


static int foreachi (lua_State *L) {
  int i;
  int n = aux_getn(L, 1);
  luaL_checktype(L, 2, LUA_TFUNCTION);
  for (i=1; i <= n; i++) {
    lua_pushvalue(L, 2);  /* function */
    lua_pushinteger(L, i);  /* 1st argument */
    lua_rawgeti(L, 1, i);  /* 2nd argument */
    lua_call(L, 2, 1);
    if (!lua_isnil(L, -1))
      return 1;
    lua_pop(L, 1);  /* remove nil result */
  }
  return 0;
}


static int foreach (lua_State *L) {
  luaL_checktype(L, 1, LUA_TTABLE);
  luaL_checktype(L, 2, LUA_TFUNCTION);
  lua_pushnil(L);  /* first key */
  while (lua_next(L, 1)) {
    lua_pushvalue(L, 2);  /* function */
    lua_pushvalue(L, -3);  /* key */
    lua_pushvalue(L, -3);  /* value */
    lua_call(L, 2, 1);
    if (!lua_isnil(L, -1))
      return 1;
    lua_pop(L, 2);  /* remove value and result */
  }
  return 0;
}


static int maxn (lua_State *L) {
  lua_Number max = 0;
  luaL_checktype(L, 1, LUA_TTABLE);
  lua_pushnil(L);  /* first key */
  while (lua_next(L, 1)) {
    lua_pop(L, 1);  /* remove value */
    if (lua_type(L, -1) == LUA_TNUMBER) {
      lua_Number v = lua_tonumber(L, -1);
      if (v > max) max = v;
    }
  }
  lua_pushnumber(L, max);
  return 1;
}


static int getn (lua_State *L) {
  lua_pushinteger(L, aux_getn(L, 1));
  return 1;
}


static int setn (lua_State *L) {
  luaL_checktype(L, 1, LUA_TTABLE);
#ifndef luaL_setn
  luaL_setn(L, 1, luaL_checkint(L, 2));
#else
  luaL_error(L, LUA_QL("setn") " is obsolete");
#endif
  lua_pushvalue(L, 1);
  return 1;
}


static int tinsert (lua_State *L) {
  int e = aux_getn(L, 1) + 1;  /* first empty element */
  int pos;  /* where to insert new element */
  switch (lua_gettop(L)) {
    case 2: {  /* called with only 2 arguments */
      pos = e;  /* insert new element at the end */
      break;
    }
    case 3: {
      int i;
      pos = luaL_checkint(L, 2);  /* 2nd argument is the position */
      if (pos > e) e = pos;  /* `grow' array if necessary */
      for (i = e; i > pos; i--) {  /* move up elements */
        lua_rawgeti(L, 1, i-1);
        lua_rawseti(L, 1, i);  /* t[i] = t[i-1] */
      }
      break;
    }
    default: {
      return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
    }
  }
  luaL_setn(L, 1, e);  /* new size */
  lua_rawseti(L, 1, pos);  /* t[pos] = v */
  return 0;
}


static int tremove (lua_State *L) {
  int e = aux_getn(L, 1);
  int pos = luaL_optint(L, 2, e);
  if (!(1 <= pos && pos <= e))  /* position is outside bounds? */
   return 0;  /* nothing to remove */
  luaL_setn(L, 1, e - 1);  /* t.n = n-1 */
  lua_rawgeti(L, 1, pos);  /* result = t[pos] */
  for ( ;pos<e; pos++) {
    lua_rawgeti(L, 1, pos+1);
    lua_rawseti(L, 1, pos);  /* t[pos] = t[pos+1] */
  }
  lua_pushnil(L);
  lua_rawseti(L, 1, e);  /* t[e] = nil */
  return 1;
}


static void addfield (lua_State *L, luaL_Buffer *b, int i) {
  lua_rawgeti(L, 1, i);
  if (!lua_isstring(L, -1))
    luaL_error(L, "invalid value (%s) at index %d in table for "
                  LUA_QL("concat"), luaL_typename(L, -1), i);
    luaL_addvalue(b);
}


static int tconcat (lua_State *L) {
  luaL_Buffer b;
  size_t lsep;
  int i, last;
  const char *sep = luaL_optlstring(L, 2, "", &lsep);
  luaL_checktype(L, 1, LUA_TTABLE);
  i = luaL_optint(L, 3, 1);
  last = luaL_opt(L, luaL_checkint, 4, luaL_getn(L, 1));
  luaL_buffinit(L, &b);
  for (; i < last; i++) {
    addfield(L, &b, i);
    luaL_addlstring(&b, sep, lsep);
  }
  if (i == last)  /* add last value (if interval was not empty) */
    addfield(L, &b, i);
  luaL_pushresult(&b);
  return 1;
}



/*
** {======================================================
** Quicksort
** (based on `Algorithms in MODULA-3', Robert Sedgewick;
**  Addison-Wesley, 1993.)
*/


static void set2 (lua_State *L, int i, int j) {
  lua_rawseti(L, 1, i);
  lua_rawseti(L, 1, j);
}

static int sort_comp (lua_State *L, int a, int b) {
  if (!lua_isnil(L, 2)) {  /* function? */
    int res;
    lua_pushvalue(L, 2);
    lua_pushvalue(L, a-1);  /* -1 to compensate function */
    lua_pushvalue(L, b-2);  /* -2 to compensate function and `a' */
    lua_call(L, 2, 1);
    res = lua_toboolean(L, -1);
    lua_pop(L, 1);
    return res;
  }
  else  /* a < b? */
    return lua_lessthan(L, a, b);
}

static void auxsort (lua_State *L, int l, int u) {
  while (l < u) {  /* for tail recursion */
    int i, j;
    /* sort elements a[l], a[(l+u)/2] and a[u] */
    lua_rawgeti(L, 1, l);
    lua_rawgeti(L, 1, u);
    if (sort_comp(L, -1, -2))  /* a[u] < a[l]? */
      set2(L, l, u);  /* swap a[l] - a[u] */
    else
      lua_pop(L, 2);
    if (u-l == 1) break;  /* only 2 elements */
    i = (l+u)/2;
    lua_rawgeti(L, 1, i);
    lua_rawgeti(L, 1, l);
    if (sort_comp(L, -2, -1))  /* a[i]<a[l]? */
      set2(L, i, l);
    else {
      lua_pop(L, 1);  /* remove a[l] */
      lua_rawgeti(L, 1, u);
      if (sort_comp(L, -1, -2))  /* a[u]<a[i]? */
        set2(L, i, u);
      else
        lua_pop(L, 2);
    }
    if (u-l == 2) break;  /* only 3 elements */
    lua_rawgeti(L, 1, i);  /* Pivot */
    lua_pushvalue(L, -1);
    lua_rawgeti(L, 1, u-1);
    set2(L, i, u-1);
    /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
    i = l; j = u-1;
    for (;;) {  /* invariant: a[l..i] <= P <= a[j..u] */
      /* repeat ++i until a[i] >= P */
      while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
        if (i>u) luaL_error(L, "invalid order function for sorting");
        lua_pop(L, 1);  /* remove a[i] */
      }
      /* repeat --j until a[j] <= P */
      while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
        if (j<l) luaL_error(L, "invalid order function for sorting");
        lua_pop(L, 1);  /* remove a[j] */
      }
      if (j<i) {
        lua_pop(L, 3);  /* pop pivot, a[i], a[j] */
        break;
      }
      set2(L, i, j);
    }
    lua_rawgeti(L, 1, u-1);
    lua_rawgeti(L, 1, i);
    set2(L, u-1, i);  /* swap pivot (a[u-1]) with a[i] */
    /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
    /* adjust so that smaller half is in [j..i] and larger one in [l..u] */
    if (i-l < u-i) {
      j=l; i=i-1; l=i+2;
    }
    else {
      j=i+1; i=u; u=j-2;
    }
    auxsort(L, j, i);  /* call recursively the smaller one */
  }  /* repeat the routine for the larger one */
}

static int sort (lua_State *L) {
  int n = aux_getn(L, 1);
  luaL_checkstack(L, 40, "");  /* assume array is smaller than 2^40 */
  if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */
    luaL_checktype(L, 2, LUA_TFUNCTION);
  lua_settop(L, 2);  /* make sure there is two arguments */
  auxsort(L, 1, n);
  return 0;
}

/* }====================================================== */


static const luaL_Reg tab_funcs[] = {
  {"concat", tconcat},
  {"foreach", foreach},
  {"foreachi", foreachi},
  {"getn", getn},
  {"maxn", maxn},
  {"insert", tinsert},
  {"remove", tremove},
  {"setn", setn},
  {"sort", sort},
  {NULL, NULL}
};


LUALIB_API int luaopen_table (lua_State *L) {
  luaL_register(L, LUA_TABLIBNAME, tab_funcs);
  return 1;
}

2' href='#n1422'>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
#!/bin/sh
#             __________               __   ___.
#   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
#   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
#   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
#   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
#                     \/            \/     \/    \/            \/
# $Id$
#

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

use_logf="#undef ROCKBOX_HAS_LOGF"

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

rbdir=".rockbox"
  
#
# 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
}

findarmgcc() {
  if [ "$ARG_ARM_EABI" = "1" ]; then
    prefixtools arm-elf-eabi-
    gccchoice="4.4.2"
  else
    prefixtools arm-elf-
    gccchoice="4.0.3"
  fi
}

# 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 - if crosscompiling, require that it is
# a mingw32 sdl-config
findsdl(){
  file="sdl-config"

  IFS=":"
  for path in $PATH
  do
    #echo "checks for $file in $path" >&2
    if test -f "$path/$file"; then
      if [ "yes" = "${crosscompile}" ]; then
        if [ "0" != `$path/$file --libs |grep -c mwindows` ]; then
          echo "$path/$file"
          return
        fi
      else
        echo "$path/$file"
        return
      fi
    fi
  done
}

simcc () {

 # default tool setup for native building
 prefixtools ""

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

 output="rockboxui" # use this as default output binary name
 sdl=`findsdl`
 sdl_cflags=""
 sdl_libs=""

 if [ $1 = "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 1
    else 
        # generic sdl-config checker
        sdl_cflags=`$sdl --cflags`
        sdl_libs=`$sdl --libs`
    fi
 fi

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

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

   # sdl version
   GCCOPTS="$GCCOPTS $sdl_cflags"
   LDOPTS="-mconsole $sdl_libs"

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

   MINGW*)
   echo "MinGW host detected"

   # sdl version
   GCCOPTS="$GCCOPTS $sdl_cflags"
   LDOPTS="-mconsole $sdl_libs"

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

   Linux)
   echo "Linux host detected"
   GCCOPTS="$GCCOPTS $sdl_cflags"
   LDOPTS="$sdl_libs"
   ;;

   FreeBSD)
   echo "FreeBSD host detected"
   # sdl version
   GCCOPTS="$GCCOPTS $sdl_cflags"
   LDOPTS="$sdl_libs"
   ;;

   Darwin)
   echo "Darwin host detected"
   # sdl version
   GCCOPTS="$GCCOPTS $sdl_cflags"
   LDOPTS="$sdl_libs"
   SHARED_FLAG="-dynamiclib -Wl\,-single_module"
   ;;

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

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

 if test "X$crosscompile" != "Xyes"; then
   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

   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

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

   if [ $1 = "sdl" ]; then
     echo "Simulator environment deemed $endian endian"
   elif [ $1 = "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*
 else
   # We are crosscompiling
   # add cross-compiler option(s)
   prefixtools i586-mingw32msvc-
   LDOPTS="-mconsole $sdl_libs"
   output="rockboxui.exe" # use this as output binary name
   endian="little" # windows is little endian
 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 () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm7tdmi"
 if test "X$1" != "Xshort" -a "$ARG_ARM_EABI" != "1"; then
   GCCOPTS="$GCCOPTS -mlong-calls"
 fi
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm9tdmicc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm9tdmi"
 if test "$modelname" != "gigabeatfx" -a "$t_manufacturer" != "as3525" -a "$ARG_ARM_EABI" != "1"; then
  GCCOPTS="$GCCOPTS -mlong-calls"
 fi
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm940tbecc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mbig-endian -mcpu=arm940t"
 if test "ARG_ARM_EABI" != "1"; then
  GCCOPTS="$GCCOPTS -mlong-calls"
 fi
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="big"
}

arm940tcc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm940t"
 if test "ARG_ARM_EABI" != "1"; then
  GCCOPTS="$GCCOPTS -mlong-calls"
 fi
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm946cc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm9e"
 if test "ARG_ARM_EABI" != "1"; then
  GCCOPTS="$GCCOPTS -mlong-calls"
 fi
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm926ejscc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm926ej-s"
 if test "ARG_ARM_EABI" != "1"; then
  GCCOPTS="$GCCOPTS -mlong-calls"
 fi
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm1136jfscc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm1136jf-s"
 if test "$modelname" != "gigabeats" -a "ARG_ARM_EABI" != "1"; then
  GCCOPTS="$GCCOPTS -mlong-calls"
 fi
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

arm1176jzscc () {
 findarmgcc
 GCCOPTS="$CCOPTS -mcpu=arm1176jz-s"
 if test "ARG_ARM_EABI" != "1"; then
  GCCOPTS="$GCCOPTS -mlong-calls"
 fi
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

mipselcc () {
 prefixtools mipsel-elf-
 GCCOPTS="$CCOPTS -march=mips32 -mtune=r4600 -mno-mips16 -mno-long-calls"
 GCCOPTS="$GCCOPTS -ffunction-sections -msoft-float -G 0 -Wno-parentheses"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
 gccchoice="4.1.2"
}

whichadvanced () {
  atype=`echo "$1" | cut -c 2-`
  ##################################################################
  # Prompt for specific developer options
  #
  if [ "$atype" ]; then
    interact=
  else
    interact=1
    echo ""
    echo "Enter your developer options (press enter when done)"
    printf "(D)EBUG, (L)ogf, (S)imulator, (P)rofiling, (V)oice, (W)in32 crosscompile"
    if [ "$memory" = "2" ]; then
      printf ", (8)MB MOD"
    fi
    if [ "$modelname" = "archosplayer" ]; then
      printf ", Use (A)TA poweroff"
    fi
    if [ "$t_model" = "ondio" ]; then
      printf ", (B)acklight MOD"
    fi
    if [ "$modelname" = "iaudiom5" ]; then
      printf ", (F)M radio MOD"
    fi
    if [ "$modelname" = "iriverh120" ]; then
      printf ", (R)TC MOD"
    fi
    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"
        ;;
      [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"
        fi
        ;;
      [Aa])
        if [ "$modelname" = "archosplayer" ]; then
          have_ata_poweroff="#define HAVE_ATA_POWEROFF"
          echo "ATA poweroff enabled"
        fi
        ;;
      [Bb])
        if [ "$t_model" = "ondio" ]; then
          have_backlight="#define HAVE_BACKLIGHT"
          echo "Backlight functions enabled"
        fi
        ;;
      [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
        ;;
      [Ww])
        echo "Enabling Windows 32 cross-compiling"
        crosscompile="yes"
        ;;
      *)
        if [ "$interact" ]; then
          cont=0
        else
          echo "[ERROR] Option $option unsupported"
        fi
        ;;
    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
  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"
    archosrom=""
    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_NOISEFLOOR="500"
        DEFAULT_CHOICE="L"
    fi
    if [ -n "`findtool espeak`" ]; then
        ESPEAK="(e)Speak "
        ESPEAK_OPTS=""
        DEFAULT_TTS="espeak"
        DEFAULT_TTS_OPTS=$ESPEAK_OPTS
        DEFAULT_NOISEFLOOR="500"
        DEFAULT_CHOICE="e"
    fi
    if [ -n "`findtool 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 [ -n "`findtool 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 [ -n "`findtool 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 3
    fi

    if [ "$ARG_TTS" ]; then
        option=$ARG_TTS
    else
        echo "TTS engine to use: ${FLITE}${FESTIVAL}${ESPEAK}${SAPI}${SWIFT}(${DEFAULT_CHOICE})?"
        option=`input`
    fi
    advopts="$advopts --tts=$option"
    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"

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

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

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

    # Read custom encoder options from command line
    if [ "$ARG_ENCOPTS" ]; then
        ENC_OPTS="$ARG_ENCOPTS"
        advopts="$advopts --encopts='$ENC_OPTS'"
        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`
    fi
    advopts="$advopts --language=$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
    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.

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

    --eabi            Make configure prefer toolchains that are able to compile
                      for the new ARM standard abi EABI
    --no-eabi         The opposite of --eabi (prefer old non-eabi toolchains)
    --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_EABI=
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`;;
		--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`;;
		--eabi)       ARG_ARM_EABI=1;;
		--no-eabi)    ARG_ARM_EABI=0;;
		--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, 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 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'
firmdir='\$(ROOTDIR)/firmware'
toolsdir='\$(ROOTDIR)/tools'


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

if [ "$ARG_TARGET" ]; then
  buildfor=$ARG_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 1G
  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
                          ==Toshiba==            27) 1G, 2G
 ==Cowon/iAudio==         40) Gigabeat F/X       28) Nano 2G
 30) X5/X5V/X5L           41) Gigabeat S
 31) M5/M5L                                      ==SanDisk==
 32) 7                    ==Olympus=             50) Sansa e200
 33) D2                   70) M:Robe 500         51) Sansa e200R
 34) M3/M3L               71) M:Robe 100         52) Sansa c200
                                                 53) Sansa m200
 ==Creative==             ==Philips==            54) Sansa c100
 90) Zen Vision:M 30GB    100) GoGear SA9200     55) Sansa Clip
 91) Zen Vision:M 60GB    101) GoGear HDD1630/   56) Sansa e200v2
 92) Zen Vision                HDD1830           57) Sansa m200v4
                          102) GoGear HDD6330    58) Sansa Fuze
 ==Onda==                                        59) Sansa c200v2
 120) VX747               ==Meizu==              60) Sansa Clipv2
 121) VX767               110) M6SL              61) Sansa View
 122) VX747+              111) M6SP
 123) VX777               112) M3                ==Logik==
                                                 80) DAX 1GB MP3/DAB
 ==Samsung==              ==Tatung==
 140) YH-820              150) Elio TPJ-1022     ==Lyre project==
 141) YH-920                                     130) Lyre proto 1
 142) YH-925                                     131) Mini2440
 143) YP-S3
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 bmp2rb"
  # generic is used by IFP, Meizu and Onda
  genericbitmaptools="$toolset bmp2rb"
  # scramble is used by all other targets
  scramblebitmaptools="$genericbitmaptools scramble"


  #  ---- 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|archosplayer)
    target_id=1
    modelname="archosplayer"
    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|archosrecorder)
    target_id=2
    modelname="archosrecorder"
    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|archosfmrecorder)
    target_id=3
    modelname="archosfmrecorder"
    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|archosrecorderv2)
    target_id=4
    modelname="archosrecorderv2"
    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|archosondiosp)
    target_id=7
    modelname="archosondiosp"
    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|archosondiofm)
    target_id=8
    modelname="archosondiofm"
    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|archosav300)
    target_id=38
    modelname="archosav300"
    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|iriverh120)
    target_id=9
    modelname="iriverh120"
    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"
    bootoutput="bootloader.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|iriverh300)
    target_id=10
    modelname="iriverh300"
    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|iriverh100)
    target_id=11
    modelname="iriverh100"
    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"
    bootoutput="bootloader.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|iriverifp7xx)
    target_id=19
    modelname="iriverifp7xx"
    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|iriverh10)
    target_id=22
    modelname="iriverh10"
    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=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="iriver"
    t_model="h10"
    ;;

   15|iriverh10_5gb)
    target_id=24
    modelname="iriverh10_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=$scramblebitmaptools
    # 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|ipodnano1g)
    target_id=14
    modelname="ipodnano1g"
    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|ipodmini1g)
    target_id=18
    modelname="ipodmini1g"
    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"
    ;;

   28|ipodnano2g)
    target_id=62
    modelname="ipodnano2g"
    target="-DIPOD_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"
    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="s5l8700"
    t_model="ipodnano2g"
    ;;

   30|iaudiox5)
    target_id=12
    modelname="iaudiox5"
    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|iaudiom5)
    target_id=28
    modelname="iaudiom5"
    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 4"
    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="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"
    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|iaudiom3)
    target_id=37
    modelname="iaudiom3"
    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|gigabeatfx)
    target_id=20
    modelname="gigabeatfx"
    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"
    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"
    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"
    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=$scramblebitmaptools
    # 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|zenvisionm30gb)
    target_id=35
    modelname="zenvisionm30gb"
    target="-DCREATIVE_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"
    plugins="yes"
    swcodec="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="-DCREATIVE_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"
    plugins="yes"
    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|zenvision)
    target_id=39
    modelname="zenvision"
    target="-DCREATIVE_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"
    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|sansae200)
    target_id=23
    modelname="sansae200"
    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=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    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="-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=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="sandisk"
    t_model="sansa-e200"
    ;;

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

   53|sansam200)
    target_id=48
    modelname="sansam200"
    target="-DSANSA_M200"
    memory=1 # 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"
    ;;

   54|sansac100)
    target_id=42 
    modelname="sansac100" 
    target="-DSANSA_C100"     
    memory=2
    arm946cc
    tool="$rootdir/tools/scramble -add=c100"
    boottool="$rootdir/tools/scramble -tcc=crc"
    bootoutput="player.rom"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.c100"
    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="c100"
    ;;

   55|sansaclip)
    target_id=50
    modelname="sansaclip"
    target="-DSANSA_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"
    plugins="yes"
    swcodec="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-clip"
    arm9tdmicc
    ;;


   56|sansae200v2)
    target_id=51
    modelname="sansae200v2"
    target="-DSANSA_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"
    plugins="yes"
    swcodec="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-e200v2"
    arm9tdmicc
    ;;


   57|sansam200v4)
    target_id=52
    modelname="sansam200v4"
    target="-DSANSA_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"
    plugins="yes"
    swcodec="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-m200v4"
    arm9tdmicc
    ;;


   58|sansafuze)
    target_id=53
    modelname="sansafuze"
    target="-DSANSA_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"
    plugins="yes"
    swcodec="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-fuze"
    arm9tdmicc
    ;;


   59|sansac200v2)
    target_id=55
    modelname="sansac200v2"
    target="-DSANSA_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"
    plugins="yes"
    swcodec="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"
    arm9tdmicc
    ;;

   60|sansaclipv2)
    echo "Sansa Clipv2 is not yet supported !"
    exit 1
    target_id=60
    modelname="sansaclipv2"
    target="-DSANSA_CLIPV2"
    memory=8
    arm926ejscc
    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"
    plugins="yes"
    swcodec="yes"
    toolset=$scramblebitmaptools
    t_cpu="arm"
    t_manufacturer="as3525"
    t_model="sansa-clipv2"
    ;;

   61|sansaview)
    echo "Sansa View is not yet supported!"
    exit 1
    target_id=63
    modelname="sansaview"
    target="-DSANSA_VIEW"
    memory=32
    arm1176jzscc
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="gui"
    plugins=""
    swcodec="yes"
    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_manufacturer="sandisk"
    t_model="sansa-view"
    ;;

   150|tatungtpj1022)
    target_id=25
    modelname="tatungtpj1022"
    target="-DTATUNG_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=$scramblebitmaptools
    # architecture, manufacturer and model for the target-tree build
    t_cpu="arm"
    t_manufacturer="tatung"
    t_model="tpj1022"
    ;;

   100|gogearsa9200)
    target_id=41
    modelname="gogearsa9200"
    target="-DPHILIPS_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"
    plugins=""
    swcodec="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_manufacturer="philips"
    t_model="sa9200"
    ;;

   101|gogearhdd1630)
    target_id=43
    modelname="gogearhdd1630"
    target="-DPHILIPS_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"
    plugins="yes"
    swcodec="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_manufacturer="philips"
    t_model="hdd1630"
    ;;

   102|gogearhdd6330)
    target_id=65
    modelname="gogearhdd6330"
    target="-DPHILIPS_HDD6330"
    memory=32 # supposedly
    arm7tdmicc
    tool="$rootdir/tools/scramble -mi4v3 -model=6330 -type=RBOS"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
    output="rockbox.mi4"
    appextra="recorder:gui"
    plugins=""
    swcodec="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_manufacturer="philips"
    t_model="hdd6330"
    ;;

   110|meizum6sl)
    target_id=49
    modelname="meizum6sl"
    target="-DMEIZU_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"
    plugins="no" #FIXME
    swcodec="yes"
    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="-DMEIZU_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"
    plugins="no" #FIXME
    swcodec="yes"
    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="-DMEIZU_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"
    plugins="no" #FIXME
    swcodec="yes"
    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="-DONDA_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"
    plugins="yes"
    swcodec="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="-DONDA_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"
    plugins="" #FIXME
    swcodec="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_vx767"
    ;;
    
    122|ondavx747p)
    target_id=54
    modelname="ondavx747p"
    target="-DONDA_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"
    plugins="yes"
    swcodec="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="-DONDA_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"
    plugins="yes"
    swcodec="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="-DLYRE_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"
    plugins=""
    swcodec="yes"
    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="-DMINI2440"
    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"
    plugins=""
    swcodec="yes"
    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="-DSAMSUNG_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"
    plugins="yes"
    swcodec="yes"
    boottool="$rootdir/tools/scramble -mi4v2 -model=y820 -type=RBBL"
    bootoutput="FW_YH820.mi4"