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

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

use_logf="#undef ROCKBOX_HAS_LOGF"
use_simsound="#undef ROCKBOX_HAS_SIMSOUND"

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
}

checksoundcard () {
    if test -n "$codecs"; then
        if test -f "/usr/include/sys/soundcard.h"; then
         # We have a header file so we can build the sound code
            use_simsound="#define ROCKBOX_HAS_SIMSOUND 1"
            echo "Enabled PCM sound playback in simulator"
        fi # header file present
    fi # has codecs
}

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


simcc () {

 # default tool setup for native building
 prefixtools ""

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

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

 if [ "$simver" = "sdl" ]; then
     # 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
 fi

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

   if [ "$simver" = "win32" ]; then
       # win32 version
       GCCOPTS="$GCCOPTS -mno-cygwin -DNOCYGWIN"
       LDOPTS="-lgdi32 -luser32 -mno-cygwin"
   elif [ "$simver" = "sdl" ]; then
       # sdl version
       GCCOPTS="$GCCOPTS `sdl-config --cflags`"
       LDOPTS="`sdl-config --libs`"
       checksoundcard
   else
       # x11 version
       GCCOPTS="$GCCOPTS"
       LDOPTS='-L/usr/X11R6/lib -lSM -lICE -lXt -lX11 -lXmu -lSM -lICE -lX11 -lpthread'
       checksoundcard
   fi
   output="rockboxui.exe" # use this as output binary name
   ;;

   Linux)
   echo "Linux host detected"
   GCCOPTS="$GCCOPTS"
   if [ "$simver" = "win32" ]; then
       LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -lnsl -ldl -lpthread'
       crosswincc # setup cross-compiler
   elif [ "$simver" = "sdl" ]; then
       GCCOPTS="$GCCOPTS `sdl-config --cflags`"
       LDOPTS="`sdl-config --libs`"
       checksoundcard
   else
       LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -lnsl -ldl -lpthread'
       checksoundcard
   fi # not a cross-compiler
   ;;

   FreeBSD)
   echo "FreeBSD host detected"
   LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -dl -lpthread'
   if [ "$simver" = "win32" ]; then
     crosswincc # setup cross-compiler
   fi
   ;;

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


 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
}

shcc () {
 prefixtools sh-elf-
 GCCOPTS="$CCOPTS -m1"
 GCCOPTIMIZE="-fomit-frame-pointer -fschedule-insns"
 endian="big"
}

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

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

arm7tdmicc () {
 prefixtools arm-elf-
 GCCOPTS="$CCOPTS -mcpu=arm7tdmi -ffunction-sections -mlong-calls"
 GCCOPTIMIZE="-fomit-frame-pointer"
 endian="little"
}

whichaddr () {
    case $archos in
    gmini120|gminisp)
	echo ""
	echo "Where do you want the firmware to be flashed?"
	echo "WARNING: Do not answer this question lightly,"
	echo "unless you don't plan to flash your gmini."
	echo "In this case, reply '0x10000' (no quotes) and "
	echo "re-configure when you know better."
	loadaddress=`input`

        if [ "0$loadaddress" = "0" ]; then
            #default
            loadaddress="0x10000";
        fi
        echo "You selected $loadaddress"
	;;
    *)
	;;
    esac
}

whichdevel () {
  ##################################################################
  # Prompt for specific developer options
  #
  echo ""
  echo "Enter your developer options (press enter when done)"
  echo "(D)EBUG, (L)ogf, (S)imulator, (P)rofiling"
  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
        ;;
      *)
        echo "done"
        cont=0
        ;;
    esac 
  done

  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"
    whichsim
  fi
  if [ "yes" = "$profile" ]; then
    extradefines="$extradefines -DRB_PROFILE"
    PROFILE_OPTS="-finstrument-functions"
    GCCOPTS="$GCCOPTS $GCCOPTIMIZE"
  fi
}

whichsim () {

if [ -z "$simver" ]; then

  ##################################################################
  # Figure out what simulator version
  #
  # x11 is deprecated so hide it from the question
  # win32 is also deprecated
  #
  echo ""
  echo "Build (S)DL version? (S)"

  option=`input`;

  case $option in
   [Ww])
     simver="win32"

     WINDRES=windres
     DLLTOOL=dlltool
     DLLWRAP=dllwrap

     # make sure the code knows this is for win32
     extradefines="$extradefines -DWIN32"
     ;;
   [Xx])
     simver="x11"
     extradefines="$extradefines -DX11"
     ;;
   [Ss]|*)
     simver="sdl"
     extradefines="$extradefines -DSDL"
     ;;
   esac
   echo "Selected $simver simulator"
fi
}

if test "$1" = "--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 ""
  echo "Usage: configure [--ccache]"
  exit
fi

if test "$1" = "--ccache"; then
  echo "Enable ccache for building"
  ccache="yes"
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

if [ "$target" = "--help" -o \
     "$target" = "-h" ]; then
  echo "Just invoke the script and answer the questions."
  echo "This script will write a Makefile for you"
  exit
fi

# get our current directory
pwd=`pwd`;

if [ "$target" = "update" ]; then
  echo "configure update is unfortunately no longer supported"
  exit
else

echo "This script will setup your Rockbox build environment."
echo "Further docs here: http://www.rockbox.org/"
echo ""

fi

if [ -z "$rootdir" ]; then
  ##################################################################
  # Figure out where the source code root is!
  #

  firmfile="crt0.S" # a file to check for in the firmware root dir

  for dir in  . .. ../.. ../rockbox*; do
    if [ -f $dir/firmware/$firmfile ]; then
     rootdir=$dir
     break
    fi
  done

  if [ -z "$rootdir" ]; then
    echo "This script couldn't find your source code root directory. Please enter the"
    echo "full path to the source code directory here:"

    firmdir=`input`
  fi

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

  echo "Using this source code root directory:"
  echo $rootdir
  echo ""

  # cd back to the build dir
  cd $now
fi

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


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

  echo "Enter target platform:"

  echo "1 - Archos Player/Studio"
  echo "2 - Archos Recorder"
  echo "3 - Archos FM Recorder"
  echo "4 - Archos Recorder v2"
  echo "5 - Archos Gmini 120"
  echo "6 - Archos Gmini SP"
  echo "7 - Archos Ondio SP"
  echo "8 - Archos Ondio FM"
  echo "9 - iriver H120/H140"
  echo "10 - iriver H320/H340"
  echo "11 - iriver iHP-100/iHP-110/iHP-115"
  echo "12 - iAudio X5"
  echo "13 - iPod Color/Photo"
  echo "14 - iPod Nano"
  echo "15 - iPod Video"
  echo "16 - iPod 3G"
  echo "17 - iPod 4G (Grayscale)"
  echo "18 - iriver iFP-790"

  target_id=`input`;

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

  # Toolsets for some target families:
  archosbitmaptools="$toolset scramble descramble sh2d uclpack bmp2rb codepages"
  iriverbitmaptools="$toolset scramble descramble mkboot bmp2rb codepages"
  iaudiobitmaptools="$toolset scramble descramble mkboot bmp2rb codepages"
  ipodbitmaptools="$toolset scramble ipod_fw bmp2rb codepages"
  ifpbitmaptools="$toolset bmp2rb codepages"

  case $target_id in

   1)
    archos="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"
    codecs=""

    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$toolset scramble descramble sh2d generate_rocklatin 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

    ;;

   2)
    archos="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"
    codecs=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$archosbitmaptools
    ;;

   3)
    archos="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"
    codecs=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$archosbitmaptools
    ;;

   4)
    archos="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"
    codecs=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$archosbitmaptools
    ;;

   5)
    archos="gmini120"
    target="-DARCHOS_GMINI120"
    memory=16 # fixed size (16 is a guess, remove comment when checked)
    calmrisccc
    tool="cp" # might work for now!
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.gmini"
    appextra="recorder:gui"
    archosrom=""
    flash=""
    plugins="" # disabled for now, enable later on
    codecs="libmad"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$toolset bmp2rb codepages"
    ;;

   6)
    archos="gminisp"
    target="-DARCHOS_GMINISP"
    memory=16 # fixed size (16 is a guess, remove comment when checked)
    calmrisccc
    tool="cp" # might work for now!
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.gmini"
    appextra="recorder:gui"
    archosrom=""
    flash=""
    plugins="" # disabled for now, enable later on
    codecs="libmad"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$toolset bmp2rb codepages"
    ;;

   7)
    archos="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"
    codecs=""
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$archosbitmaptools
    ;;

   8)
    archos="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"
    codecs=""
    toolset=$archosbitmaptools
    ;;

   9)
    archos="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"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$iriverbitmaptools
    ;;

   10)
    archos="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"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$iriverbitmaptools
    ;;

   11)
    archos="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"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$iriverbitmaptools
    ;;

   12)
    archos="x5"
    target="-DIAUDIO_X5"
    memory=16 # always
    coldfirecc
    tool="$rootdir/tools/scramble -add=h120" # wrong, must be fixed
    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"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset="$iaudiobitmaptools"
    ;;

   13)
    archos="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"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    ;;

   14)
    archos="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"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    ;;

   15)
    archos="ipodvideo"
    target="-DIPOD_VIDEO"
    memory=32 # 30GB models have 32MB, 60GB have 64MB
    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"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    ;;

   16)
    archos="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"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    ;;
    
   17)
    archos="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"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ipodbitmaptools
    ;;
    
   18)
    archos="ifp7xx"
    target="-DIRIVER_IFP7XX"
    memory=1
    arm7tdmicc
    tool="cp"
    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
    bmp2rb_native="$rootdir/tools/bmp2rb -f 0"
    output="rockbox.wma"
    appextra="recorder:gui"
    archosrom=""
    flash=""
    plugins="yes"
    codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libfaad libm4a"
    # toolset is the tools within the tools directory that we build for
    # this particular target.
    toolset=$ifpbitmaptools
    ;;

   *)
    echo "Please select an actual target platform!"
    exit
    ;;

  esac

  echo "Platform set to $archos"


############################################################################
# Amount of memory, for those that can differ.
#

if [ -z "$memory" ]; then
  size="2"
  if [ -z "$update" ]; then
    echo "Enter size of your RAM (in MB): (defaults to 2)"
    size=`input`;
  fi

  case $size in
   8)
    memory="8"
    ;;
   *)
    memory="2"
    ;;

  esac
  echo "Memory size selected: $memory MB"
fi

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

  # the ifp7x0 is the only platform that supports building a gdb stub like
  # this
  case $archos in
    ifp7xx)
       gdbstub="(G)DB stub, "
       ;;
    *)
       ;;
  esac

  echo ""
  echo "Build (N)ormal, (D)evel, (S)imulator, (B)ootloader, $gdbstub(M)anual? (N)"

  option=`input`;

  case $option in
    [Bb])
      case $archos in
          h100|h120|h300|x5|ipodcolor|ipodnano|ipodvideo|ipod3g|ipod4g)
              extradefines="-DBOOTLOADER" # for target makefile symbol EXTRA_DEFINES
              appsdir='\$(ROOTDIR)/bootloader'
              apps="bootloader"
              ;;
          *)
              extradefines="-DBOOTLOADER -ffunction-sections -fdata-sections"
              appsdir='\$(ROOTDIR)/flash/bootbox'
              apps="bootbox"
              ;;
      esac
      bootloader="1"
      echo "Bootloader build selected"
      ;;
    [Ss])
      debug="-DDEBUG"
      simulator="yes"
      extradefines="-DSIMULATOR"
      echo "Simulator build selected"
      whichsim
      ;;
    [Dd])
      echo "Devel build selected"
      whichdevel
      ;;
    [Gg])
      extradefines="-DSTUB" # for target makefile symbol EXTRA_DEFINES
      appsdir='\$(ROOTDIR)/gdb'
      apps="stub"
      case $archos in
          ifp7xx)
              output="stub.wma"
              ;;
          *)
              ;;
      esac
      echo "GDB stub build selected"
      ;;
    [Mm])
      appsdir='\$(ROOTDIR)/manual'
      firmdir='\$(ROOTDIR)/manual/platform' # No Makefile here.  Effectively ignores target
      toolsdir=$firmdir;
      toolset='';
      apps="manual"
      case $archos in
          fmrecorder)
              archos="recorderv2fm"
              ;;
          recorderv2)
              archos="recorderv2fm"
              ;;
          ondio??)
              archos="ondio"
              ;;
          h1??)
              archos="h1xx"
              ;;        
          *)
              ;;
      esac
      echo "Manual build selected"
      ;; 
    *)
      debug=""
      echo "Normal build selected"
      GCCOPTS="$GCCOPTS $GCCOPTIMIZE"
      ;;

  esac


whichaddr

# 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`;

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

fi

if test "X$ccache" = "Xyes"; 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,@SIMSOUND@,$use_simsound,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

/* Define this if you have the linux/soundcard.h header and thus can compile
   the sound-playing code in the X11 sim */
@SIMSOUND@

#endif /* __BUILD_AUTOCONF_H */
EOF

if test "$simulator" = "yes"; then
  # add simul make stuff on the #SIMUL# line
  simmagic1="s,@SIMUL1@,@\$(MAKE) -C \$(SIMDIR) OBJDIR=\$(BUILDDIR)/sim,"
  simmagic2="s,@SIMUL2@,@\$(MAKE) -C \$(ROOTDIR)/uisimulator/common OBJDIR=\$(BUILDDIR)/comsim,"
else
  # delete the lines that match
  simmagic1='/@SIMUL1@/D'
  simmagic2='/@SIMUL2@/D'
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,@ARCHOS@,${archos},g" \
 -e "s,@LANGUAGE@,${language},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@,${codecs},g" \
 -e "s,@PROFILE_OPTS@,${PROFILE_OPTS},g" \
 -e "s,@GCCOPTS@,${GCCOPTS},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}" \
<<EOF
## Automaticly generated. http://www.rockbox.org/

ifndef V
SILENT=@
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 ARCHOS=@ARCHOS@
export ARCHOSROM=@ARCHOSROM@
export FLASHFILE=@FLASHFILE@
export TARGET_ID=@TARGET_ID@
export TARGET=@TARGET@
export OBJDIR=@PWD@
export BUILDDIR=@PWD@
export LANGUAGE=@LANGUAGE@
export MEMORYSIZE=@MEMORY@
export VERSION=\$(shell date +%y%m%d-%H%M)
export BUILDDATE=\$(shell date +'-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 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 GCCOPTS=@GCCOPTS@
export LOADADDRESS=@LOADADDRESS@
export SIMVER=@SIMVER@
export SIMDIR=\$(ROOTDIR)/uisimulator/\$(SIMVER)
export LDOPTS=@LDOPTS@
export GCCVER=@GCCVER@
export GCCNUM=@GCCNUM@
export UNAME=@UNAME@

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

.PHONY: all clean tags zip tools manual

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

clean:
	\$(SILENT)\$(MAKE) -C \$(FIRMDIR) clean OBJDIR=\$(BUILDDIR)/firmware
	\$(SILENT)\$(MAKE) -C \$(APPSDIR) clean OBJDIR=\$(BUILDDIR)/@APPS@
	\$(SILENT)\$(MAKE) -C \$(TOOLSDIR) clean
	\$(SILENT)rm -rf rockbox.zip TAGS @APPS@ firmware comsim sim lang.h manual *.pdf

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

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

zip:
	\$(SILENT)\$(TOOLSDIR)/buildzip.pl -r "\$(ROOTDIR)" \$(TARGET) \$(BINARY)

7zip:
	\$(SILENT)\$(TOOLSDIR)/buildzip.pl -o "rockbox.7z" -z "7za a" -r "\$(ROOTDIR)" \$(TARGET) \$(BINARY)

manual:
	\$(SILENT)\$(MAKE) -C \$(MANUALDIR) OBJDIR=\$(BUILDDIR)/manual buildmanual

EOF

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

 cat >> Makefile <<EOF

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

fi

echo "Created Makefile"