* fix some cursor bugs (patch 1222287)
[maemo-rb.git] / tools / configure
blob464ea4c220f191b7660b54d748241ee908119227
1 #!/bin/sh
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
11 # global CC options for all platforms
12 CCOPTS="-W -Wall -O -nostdlib -ffreestanding -Wstrict-prototypes"
14 use_logf="#undef ROCKBOX_HAS_LOGF"
17 # Begin Function Definitions
19 input() {
20 read response
21 echo $response
24 prefixtools () {
25 prefix="$1"
26 CC=${prefix}gcc
27 WINDRES=${prefix}windres
28 DLLTOOL=${prefix}dlltool
29 DLLWRAP=${prefix}dllwrap
30 RANLIB=${prefix}ranlib
31 LD=${prefix}ld
32 AR=${prefix}ar
33 AS=${prefix}as
34 OC=${prefix}objcopy
37 crosswincc () {
38 # naive approach to selecting a mingw cross-compiler on linux/*nix
39 echo "Enabling win32 crosscompiling"
41 prefixtools i586-mingw32msvc-
43 LDOPTS="-lgdi32 -luser32 -mwindows"
44 # add cross-compiler option(s)
45 GCCOPTS="$GCCOPTS -mno-cygwin"
47 output="rockboxui.exe" # use this as output binary name
48 crosscompile="yes"
49 endian="little" # windows is little endian
52 simcc () {
54 # default tool setup for native building
55 prefixtools ""
57 GCCOPTS='-W -Wall -g -fno-builtin'
59 output="rockboxui" # use this as default output binary name
61 case $uname in
62 CYGWIN*)
63 echo "Cygwin host detected"
65 if [ "$simver" = "win32" ]; then
66 # win32 version
67 GCCOPTS="$GCCOPTS -mno-cygwin -DNOCYGWIN"
68 LDOPTS="-lgdi32 -luser32 -mno-cygwin"
69 else
70 # x11 version
71 GCCOPTS="$GCCOPTS"
72 LDOPTS='-L/usr/X11R6/lib -lSM -lICE -lXt -lX11 -lXmu -lSM -lICE -lX11 -lpthread'
74 output="rockboxui.exe" # use this as output binary name
77 Linux)
78 echo "Linux host detected"
79 GCCOPTS="$GCCOPTS"
80 LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -lnsl -ldl -lpthread'
81 if [ "$simver" = "win32" ]; then
82 crosswincc # setup cross-compiler
86 FreeBSD)
87 echo "FreeBSD host detected"
88 LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -dl -lpthread'
89 if [ "$simver" = "win32" ]; then
90 crosswincc # setup cross-compiler
95 echo "Unsupported system: $uname, fix configure and retry"
96 exit
98 esac
101 if test "X$crosscompile" != "Xyes"; then
102 id=$$
103 cat >/tmp/conftest-$id.c <<EOF
104 #include <stdio.h>
105 int main(int argc, char **argv)
107 int var=0;
108 char *varp = (char *)&var;
109 *varp=1;
111 printf("%d\n", var);
112 return 0;
116 $CC -o /tmp/conftest-$id /tmp/conftest-$id.c 2>/dev/null
118 if test `/tmp/conftest-$id 2>/dev/null` -gt "1"; then
119 # big endian
120 endian="big"
121 else
122 # little endian
123 endian="little"
125 echo "Simulator environment deemed $endian endian"
127 # use wildcard here to make it work even if it was named *.exe like
128 # on cygwin
129 rm -f /tmp/conftest-$id*
133 shcc () {
134 prefixtools sh-elf-
135 GCCOPTS="$CCOPTS -m1"
136 GCCOPTIMIZE="-fomit-frame-pointer -fschedule-insns"
137 endian="big"
140 calmrisccc () {
141 prefixtools calmrisc16-unknown-elf-
142 GCCOPTS="-Wl\,--no-check-sections $CCOPTS"
143 GCCOPTIMIZE="-fomit-frame-pointer"
144 endian="big"
147 coldfirecc () {
148 prefixtools m68k-elf-
149 GCCOPTS="$CCOPTS -g -m5200 -Wa\,-m5249 -malign-int -mstrict-align"
150 GCCOPTIMIZE="-fomit-frame-pointer"
151 endian="big"
154 whichaddr () {
155 case $archos in
156 gmini120|gminisp)
157 echo ""
158 echo "Where do you want the firmware to be flashed?"
159 echo "WARNING: Do not answer this question lightly,"
160 echo "unless you don't plan to flash your gmini."
161 echo "In this case, reply '0x10000' (no quotes) and "
162 echo "re-configure when you know better."
163 loadaddress=`input`
165 if [ "0$loadaddress" = "0" ]; then
166 #default
167 loadaddress="0x10000";
169 echo "You selected $loadaddress"
173 esac
176 whichdevel () {
177 ##################################################################
178 # Prompt for specific developer options
180 echo ""
181 echo "Enter your developer options (press enter when done)"
182 echo "(D)EBUG, (L)ogf, (S)imulator"
183 cont=1
185 while [ $cont = "1" ]; do
187 option=`input`;
189 case $option in
190 [Dd])
191 echo "define DEBUG"
192 debug="1"
193 GCCOPTS="$GCCOPTS -g -DDEBUG"
195 [Ll])
196 logf="yes"
197 echo "logf() support enabled"
198 use_logf="#define ROCKBOX_HAS_LOGF 1"
200 [Ss])
201 echo "Simulator build enabled"
202 simulator="yes"
205 echo "done"
206 cont=0
208 esac
209 done
211 if [ "yes" = "$simulator" ]; then
212 debug="1"
213 extradefines="-DSIMULATOR"
214 whichsim
218 whichsim () {
220 if [ -z "$simver" ]; then
222 ##################################################################
223 # Figure out win32/x11 GUI
225 echo ""
226 echo "Build (W)in32 or (X)11 GUI version? (X)"
228 option=`input`;
230 case $option in
231 [Ww])
232 simver="win32"
234 WINDRES=windres
235 DLLTOOL=dlltool
236 DLLWRAP=dllwrap
238 # make sure the code knows this is for win32
239 extradefines="$extradefines -DWIN32"
242 simver="x11"
244 esac
245 echo "Selected $simver simulator"
249 picklang() {
250 # figure out which languages that are around
251 for file in $rootdir/apps/lang/*.lang; do
252 clean=`echo $file | sed -e 's:.*/::g' | cut "-d." -f1`
253 langs="$langs $clean"
254 done
256 num=1
257 for one in $langs; do
258 echo "$num. $one"
259 num=`expr $num + 1`
260 done
262 read pick
263 return $pick;
266 whichlang() {
267 num=1
268 for one in $langs; do
269 if [ "$num" = "$pick" ]; then
270 echo $one
271 return
273 num=`expr $num + 1`
274 done
277 if test "$1" = "--help"; then
278 echo "Rockbox configure script."
279 echo "Invoke this in a directory to generate a Makefile to build Rockbox"
280 echo "Do *NOT* run this within the tools directory!"
281 echo ""
282 echo "Usage: configure [--ccache]"
283 exit
286 if test "$1" = "--ccache"; then
287 echo "Enable ccache for building"
288 ccache="yes"
291 if test -r "configure"; then
292 # this is a check for a configure script in the current directory, it there
293 # is one, try to figure out if it is this one!
295 if { grep "^# Jukebox" configure >/dev/null 2>&1 ; } then
296 echo "WEEEEEEEEP. Don't run this configure script within the tools directory."
297 echo "It will only cause you pain and grief. Instead do this:"
298 echo ""
299 echo " cd .."
300 echo " mkdir build-dir"
301 echo " cd build-dir"
302 echo " ../tools/configure"
303 echo ""
304 echo "Much happiness will arise from this. Enjoy"
305 exit
309 if [ "$target" = "--help" -o \
310 "$target" = "-h" ]; then
311 echo "Just invoke the script and answer the questions."
312 echo "This script will write a Makefile for you"
313 exit
316 # get our current directory
317 pwd=`pwd`;
319 if [ "$target" = "update" ]; then
320 echo "configure update is unfortunately no longer supported"
321 exit
322 else
324 echo "This script will setup your Rockbox build environment."
325 echo "Further docs here: http://www.rockbox.org/"
326 echo ""
330 if [ -z "$rootdir" ]; then
331 ##################################################################
332 # Figure out where the source code root is!
335 firmfile="crt0.S" # a file to check for in the firmware root dir
337 for dir in . .. ../.. ../rockbox*; do
338 if [ -f $dir/firmware/$firmfile ]; then
339 rootdir=$dir
340 break
342 done
344 if [ -z "$rootdir" ]; then
345 echo "This script couldn't find your source code root directory. Please enter the"
346 echo "full path to the source code directory here:"
348 firmdir=`input`
351 #####################################################################
352 # Convert the possibly relative directory name to an absolute version
354 now=`pwd`
355 cd $rootdir
356 rootdir=`pwd`
358 echo "Using this source code root directory:"
359 echo $rootdir
360 echo ""
362 # cd back to the build dir
363 cd $now
366 apps="apps"
367 appsdir='\$(ROOTDIR)/apps'
369 ##################################################################
370 # Figure out target platform
373 echo "Enter target platform:"
375 echo "1 - Archos Player/Studio"
376 echo "2 - Archos Recorder"
377 echo "3 - Archos FM Recorder"
378 echo "4 - Archos Recorder v2"
379 echo "5 - Archos Gmini 120"
380 echo "6 - Archos Gmini SP"
381 echo "7 - Archos Ondio SP"
382 echo "8 - Archos Ondio FM"
383 echo "9 - iRiver H120/H140"
384 echo "10 - iRiver H320/H340"
386 getit=`input`;
388 case $getit in
391 archos="player"
392 target="-DARCHOS_PLAYER"
393 shcc
394 tool="$rootdir/tools/scramble"
395 output="archos.mod"
396 appextra="player"
397 archosrom="$pwd/rombox.ucl"
398 flash="$pwd/rockbox.ucl"
399 plugins="yes"
400 codecs=""
404 archos="recorder"
405 target="-DARCHOS_RECORDER"
406 shcc
407 tool="$rootdir/tools/scramble"
408 output="ajbrec.ajz"
409 appextra="recorder"
410 archosrom="$pwd/rombox.ucl"
411 flash="$pwd/rockbox.ucl"
412 plugins="yes"
413 codecs=""
417 archos="fmrecorder"
418 target="-DARCHOS_FMRECORDER"
419 shcc
420 tool="$rootdir/tools/scramble -fm"
421 output="ajbrec.ajz"
422 appextra="recorder"
423 archosrom=""
424 flash="$pwd/rockbox.ucl"
425 plugins="yes"
426 codecs=""
430 archos="recorderv2"
431 target="-DARCHOS_RECORDERV2"
432 shcc
433 tool="$rootdir/tools/scramble -v2"
434 output="ajbrec.ajz"
435 appextra="recorder"
436 archosrom="$pwd/rombox.ucl"
437 flash="$pwd/rockbox.ucl"
438 plugins="yes"
439 codecs=""
443 archos="gmini120"
444 target="-DARCHOS_GMINI120"
445 memory=16 # fixed size (16 is a guess, remove comment when checked)
446 calmrisccc
447 tool="cp" # might work for now!
448 output="rockbox.gmini"
449 appextra="recorder"
450 archosrom=""
451 flash=""
452 plugins="" # disabled for now, enable later on
453 codecs="libmad"
457 archos="gminisp"
458 target="-DARCHOS_GMINISP"
459 memory=16 # fixed size (16 is a guess, remove comment when checked)
460 calmrisccc
461 tool="cp" # might work for now!
462 output="rockbox.gmini"
463 appextra="recorder"
464 archosrom=""
465 flash=""
466 plugins="" # disabled for now, enable later on
467 codecs="libmad"
471 archos="ondiosp"
472 target="-DARCHOS_ONDIOSP"
473 shcc
474 tool="$rootdir/tools/scramble -osp"
475 output="ajbrec.ajz"
476 appextra="recorder"
477 archosrom="$pwd/rombox.ucl"
478 flash="$pwd/rockbox.ucl"
479 plugins="yes"
480 codecs=""
484 archos="ondiofm"
485 target="-DARCHOS_ONDIOFM"
486 shcc
487 tool="$rootdir/tools/scramble -ofm"
488 output="ajbrec.ajz"
489 appextra="recorder"
490 archosrom="$pwd/rombox.ucl"
491 flash="$pwd/rockbox.ucl"
492 plugins="yes"
493 codecs=""
497 archos="h100"
498 target="-DIRIVER_H100"
499 memory=32 # always
500 coldfirecc
501 tool="$rootdir/tools/scramble -add=h120"
502 output="rockbox.iriver"
503 appextra="recorder"
504 archosrom=""
505 flash=""
506 plugins="yes"
507 codecs="libmad liba52 libFLAC libTremor libwavpack dumb libmusepack"
511 archos="h300"
512 target="-DIRIVER_H300"
513 memory=32 # always
514 coldfirecc
515 tool="$rootdir/tools/scramble -add=h120"
516 output="rockbox.iriver"
517 appextra="recorder"
518 archosrom=""
519 flash=""
520 plugins="yes"
521 codecs="libmad liba52 libFLAC libTremor libwavpack dumb libmusepack"
525 echo "Please select an actual target platform!"
526 exit
529 esac
531 echo "Platform set to $archos"
534 ############################################################################
535 # Amount of memory, for those that can differ.
538 if [ -z "$memory" ]; then
539 size="2"
540 if [ -z "$update" ]; then
541 echo "Enter size of your RAM (in MB): (defaults to 2)"
542 size=`input`;
545 case $size in
547 memory="8"
550 memory="2"
553 esac
554 echo "Memory size selected: $memory MB"
557 ##################################################################
558 # Figure out build "type"
560 echo ""
561 echo "Build (N)ormal, (D)evel, (S)imulator, (B)ootloader? (N)"
563 option=`input`;
565 case $option in
566 [Bb])
567 if [ "$archos" = "h100" ]; then
568 extradefines="-DBOOTLOADER" # for target makefile symbol EXTRA_DEFINES
569 appsdir='\$(ROOTDIR)/bootloader'
570 apps="bootloader"
571 else
572 extradefines="-DBOOTLOADER -ffunction-sections -fdata-sections"
573 appsdir='\$(ROOTDIR)/flash/bootbox'
574 apps="bootbox"
576 bootloader="1"
577 echo "Bootloader build selected"
579 [Ss])
580 debug="1"
581 simulator="yes"
582 extradefines="-DSIMULATOR"
583 echo "Simulator build selected"
584 whichsim
586 [Dd])
587 echo "Devel build selected"
588 whichdevel
591 debug=""
592 echo "Normal build selected"
593 GCCOPTS="$GCCOPTS $GCCOPTIMIZE"
596 esac
599 whichaddr
601 ############################################################################
602 # language
604 echo "Select a number for the language to use (default is english)"
606 picklang
607 language=`whichlang`
609 if [ -z "$language" ]; then
610 # pick a default
611 language="english"
613 echo "Language set to $language"
615 uname=`uname`
617 if [ "yes" = "$simulator" ]; then
618 # setup compiler and things for simulator
619 simcc
621 if [ -d "archos" ]; then
622 echo "sub directory archos already present"
623 else
624 mkdir archos
625 echo "created an archos subdirectory for simulating the hard disk"
629 # Now, figure out version number of the (gcc) compiler we are about to use
630 gccver=`$CC -dumpversion`;
632 if [ -z "$gccver" ]; then
633 echo "WARNING: The compiler you must use ($CC) is not in your path!"
634 echo "WARNING: this may cause your build to fail since we cannot do the"
635 echo "WARNING: checks we want now."
636 else
638 # gccver should now be "3.3.5", "3.4.3", "2.95.3-6" and similar, but don't
639 # DEPEND on it
641 num1=`echo $gccver | cut -d . -f1`
642 num2=`echo $gccver | cut -d . -f2`
643 gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
645 # This makes:
646 # 3.3.X => 303
647 # 3.4.X => 304
648 # 2.95.3 => 295
650 echo "Using $CC $gccver ($gccnum)"
654 if test "X$ccache" = "Xyes"; then
655 CC="ccache $CC"
658 if test "X$endian" = "Xbig"; then
659 defendian="ROCKBOX_BIG_ENDIAN"
660 else
661 defendian="ROCKBOX_LITTLE_ENDIAN"
664 sed > autoconf.h \
665 -e "s,@ENDIAN@,${defendian},g" \
666 -e "s,^#undef ROCKBOX_HAS_LOGF,$use_logf,g" \
667 <<EOF
668 /* This header was made by configure */
669 #ifndef __BUILD_AUTOCONF_H
670 #define __BUILD_AUTOCONF_H
672 /* Define endianess for the target or simulator platform */
673 #define @ENDIAN@ 1
675 /* Define this if you build rockbox to support the logf logging and display */
676 #undef ROCKBOX_HAS_LOGF
678 #endif /* __BUILD_AUTOCONF_H */
681 if test "$simulator" = "yes"; then
682 # add simul make stuff on the #SIMUL# line
683 simmagic='/#SIMUL#/c\ @$(MAKE) -C $(SIMDIR) OBJDIR=$(BUILDDIR)/sim\n @$(MAKE) -C $(ROOTDIR)/uisimulator/common OBJDIR=$(BUILDDIR)/comsim'
684 else
685 # delete the line that matches
686 simmagic='/#SIMUL#/D'
689 sed > Makefile \
690 -e "s,@ROOTDIR@,${rootdir},g" \
691 -e "s,@DEBUG@,${debug},g" \
692 -e "s,@MEMORY@,${memory},g" \
693 -e "s,@TARGET@,${target},g" \
694 -e "s,@ARCHOS@,${archos},g" \
695 -e "s,@LANGUAGE@,${language},g" \
696 -e "s,@PWD@,${pwd},g" \
697 -e "s,@CC@,${CC},g" \
698 -e "s,@LD@,${LD},g" \
699 -e "s,@AR@,${AR},g" \
700 -e "s,@AS@,${AS},g" \
701 -e "s,@OC@,${OC},g" \
702 -e "s,@WINDRES@,${WINDRES},g" \
703 -e "s,@DLLTOOL@,${DLLTOOL},g" \
704 -e "s,@DLLWRAP@,${DLLWRAP},g" \
705 -e "s,@RANLIB@,${RANLIB},g" \
706 -e "s,@TOOL@,${tool},g" \
707 -e "s,@OUTPUT@,${output},g" \
708 -e "s,@APPEXTRA@,${appextra},g" \
709 -e "s,@ARCHOSROM@,${archosrom},g" \
710 -e "s,@FLASHFILE@,${flash},g" \
711 -e "s,@PLUGINS@,${plugins},g" \
712 -e "s,@CODECS@,${codecs},g" \
713 -e "s,@GCCOPTS@,${GCCOPTS},g" \
714 -e "s,@LDOPTS@,${LDOPTS},g" \
715 -e "s,@LOADADDRESS@,${loadaddress},g" \
716 -e "s,@EXTRADEF@,${extradefines},g" \
717 -e "s,@APPSDIR@,${appsdir},g" \
718 -e "s,@APPS@,${apps},g" \
719 -e "s,@SIMVER@,${simver},g" \
720 -e "s,@GCCVER@,${gccver},g" \
721 -e "s,@GCCNUM@,${gccnum},g" \
722 -e "s,@UNAME@,${uname},g" \
723 -e "s,@ENDIAN@,${defendian},g" \
724 -e "${simmagic}" \
725 <<EOF
726 ## Automaticly generated. http://www.rockbox.org/
728 export ROOTDIR=@ROOTDIR@
729 export FIRMDIR=\$(ROOTDIR)/firmware
730 export APPSDIR=@APPSDIR@
731 export TOOLSDIR=\$(ROOTDIR)/tools
732 export DOCSDIR=\$(ROOTDIR)/docs
733 export DEBUG=@DEBUG@
734 export ARCHOS=@ARCHOS@
735 export ARCHOSROM=@ARCHOSROM@
736 export FLASHFILE=@FLASHFILE@
737 export TARGET=@TARGET@
738 export OBJDIR=@PWD@
739 export BUILDDIR=@PWD@
740 export LANGUAGE=@LANGUAGE@
741 export MEMORYSIZE=@MEMORY@
742 export VERSION=\$(shell date +%y%m%d-%H%M)
743 export MKFIRMWARE=@TOOL@
744 export BINARY=@OUTPUT@
745 export APPEXTRA=@APPEXTRA@
746 export ENABLEDPLUGINS=@PLUGINS@
747 export SOFTWARECODECS=@CODECS@
748 export EXTRA_DEFINES=@EXTRADEF@
749 export CC=@CC@
750 export LD=@LD@
751 export AR=@AR@
752 export AS=@AS@
753 export OC=@OC@
754 export WINDRES=@WINDRES@
755 export DLLTOOL=@DLLTOOL@
756 export DLLWRAP=@DLLWRAP@
757 export RANLIB=@RANLIB@
758 export GCCOPTS=@GCCOPTS@
759 export LOADADDRESS=@LOADADDRESS@
760 export SIMVER=@SIMVER@
761 export SIMDIR=\$(ROOTDIR)/uisimulator/\$(SIMVER)
762 export LDOPTS=@LDOPTS@
763 export GCCVER=@GCCVER@
764 export GCCNUM=@GCCNUM@
765 export UNAME=@UNAME@
767 # Do not print "Entering directory ..."
768 MAKEFLAGS += --no-print-directory
770 .PHONY: all clean tags zip
772 all:
773 #SIMUL#
774 @\$(MAKE) -C \$(FIRMDIR) OBJDIR=\$(BUILDDIR)/firmware
775 @\$(MAKE) -C \$(APPSDIR) OBJDIR=\$(BUILDDIR)/@APPS@
777 clean:
778 @\$(MAKE) -C \$(FIRMDIR) clean OBJDIR=\$(BUILDDIR)/firmware
779 @\$(MAKE) -C \$(APPSDIR) clean OBJDIR=\$(BUILDDIR)/@APPS@
780 @rm -rf rockbox.zip TAGS @APPS@ firmware comsim sim lang.h
782 tags:
783 @rm -f TAGS
784 \$(MAKE) -C \$(FIRMDIR) tags
785 \$(MAKE) -C \$(APPSDIR) tags
786 \$(MAKE) -C \$(APPSDIR)/plugins tags
787 \$(MAKE) -C \$(APPSDIR)/plugins/lib tags
789 zip:
790 \$(TOOLSDIR)/buildzip.pl -r "\$(ROOTDIR)" \$(TARGET) \$(BINARY)
793 if [ "yes" = "$simulator" ]; then
795 cat >> Makefile <<EOF
797 install:
798 @echo "installing a full setup in your archos dir"
799 @(make zip && cd archos && unzip -oq ../rockbox.zip)
804 echo "Created Makefile"