#!/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" SHARED_FLAG="-shared" 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" SHARED_FLAG="-shared" if [ "$simver" = "win32" ]; then LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -lnsl -ldl -lpthread' crosswincc # setup cross-compiler elif [ "$simver" = "sdl" ]; then if [ "0" != `sdl-config --libs |grep -c mwindows` ]; then # Enable crosscompiling if sdl-config is from Windows SDL crosswincc fi GCCOPTS="$GCCOPTS `sdl-config --cflags`" LDOPTS="`sdl-config --libs`" 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' SHARED_FLAG="-shared" if [ "$simver" = "win32" ]; then crosswincc # setup cross-compiler fi ;; Darwin) echo "Darwin host detected" # sdl version GCCOPTS="$GCCOPTS `sdl-config --cflags`" LDOPTS="`sdl-config --libs`" SHARED_FLAG="-dynamiclib -Wl\,-single_module" use_simsound="#define ROCKBOX_HAS_SIMSOUND 1" echo "Enabled PCM sound playback in simulator" ;; *) echo "Unsupported system: $uname, fix configure and retry" exit ;; esac if [ "`uname -m`" = "x86_64" ]; then GCCOPTS="$GCCOPTS -fPIC" # needed to make shared objects link fi if test "X$crosscompile" != "Xyes"; then id=$$ cat >/tmp/conftest-$id.c < 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 -m5206e -Wa\,-m5249 -malign-int -mstrict-align" GCCOPTIMIZE="-fomit-frame-pointer" endian="big" } arm7tdmicc () { prefixtools arm-elf- GCCOPTS="$CCOPTS -mcpu=arm7tdmi" if test "X$1" != "Xshort"; then GCCOPTS="$GCCOPTS -ffunction-sections -mlong-calls" fi GCCOPTIMIZE="-fomit-frame-pointer" endian="little" } arm9tdmicc () { prefixtools arm-elf- GCCOPTS="$CCOPTS -mcpu=arm9tdmi -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" 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 } target=$1 if test "$target" = "--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][--no-ccache]" exit fi if test -r "configure"; then # this is a check for a configure script in the current directory, it there # is one, try to figure out if it is this one! if { grep "^# Jukebox" configure >/dev/null 2>&1 ; } then echo "WEEEEEEEEP. Don't run this configure script within the tools directory." echo "It will only cause you pain and grief. Instead do this:" echo "" echo " cd .." echo " mkdir build-dir" echo " cd build-dir" echo " ../tools/configure" echo "" echo "Much happiness will arise from this. Enjoy" exit fi fi # get our current directory pwd=`pwd`; if [ -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` # 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:" cat </dev/null` # This makes: # 3.3.X => 303 # 3.4.X => 304 # 2.95.3 => 295 echo "Using $CC $gccver ($gccnum)" if test "$gccnum" -ge "400"; then # gcc 4.0 is just *so* much pickier on arguments that differ in signedness # so we ignore that warnings for now # -Wno-pointer-sign GCCOPTS="$GCCOPTS -Wno-pointer-sign" fi if test "$gccnum" -ge "401"; then # this is a lame hack to avoid "warning: dereferencing type-punned pointer # will break strict-aliasing rules" GCCOPTS="$GCCOPTS -fno-strict-aliasing" fi fi # check the compiler for SH platforms if test "$CC" = "sh-elf-gcc"; then if test "$gccnum" -lt "400"; then echo "WARNING: Consider upgrading your compiler to the 4.0.X series!" echo "WARNING: http://www.rockbox.org/twiki/bin/view/Main/CrossCompiler" else # figure out patch status gccpatch=`$CC --version`; if { echo $gccpatch | grep "rockbox" >/dev/null 2>&1; } then echo "gcc $gccver is rockbox patched" # then convert -O to -Os to get smaller binaries! GCCOPTS=`echo $GCCOPTS | sed 's/ -O / -Os /'` else echo "WARNING: You use an unpatched gcc compiler: $gccver" echo "WARNING: http://www.rockbox.org/twiki/bin/view/Main/CrossCompiler" fi fi fi if test "$1" = "--ccache"; then echo "Enable ccache for building" ccache="ccache" else if test "$1" != "--no-ccache"; then ccache=`findtool ccache` if test -n "$ccache"; then echo "Found and uses ccache ($ccache)" fi fi fi if test -n "$ccache"; then CC="$ccache $CC" fi if test "X$endian" = "Xbig"; then defendian="ROCKBOX_BIG_ENDIAN" else defendian="ROCKBOX_LITTLE_ENDIAN" fi sed > autoconf.h \ -e "s,@ENDIAN@,${defendian},g" \ -e "s,^#undef ROCKBOX_HAS_LOGF,$use_logf,g" \ -e "s,@SIMSOUND@,$use_simsound,g" \ < 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,@SHARED_FLAG@,${SHARED_FLAG},g" \ -e "s,@GCCOPTS@,${GCCOPTS},g" \ -e "s,@TARGET_INC@,${TARGET_INC},g" \ -e "s!@LDOPTS@!${LDOPTS}!g" \ -e "s,@LOADADDRESS@,${loadaddress},g" \ -e "s,@EXTRADEF@,${extradefines},g" \ -e "s,@APPSDIR@,${appsdir},g" \ -e "s,@FIRMDIR@,${firmdir},g" \ -e "s,@TOOLSDIR@,${toolsdir},g" \ -e "s,@APPS@,${apps},g" \ -e "s,@SIMVER@,${simver},g" \ -e "s,@GCCVER@,${gccver},g" \ -e "s,@GCCNUM@,${gccnum},g" \ -e "s,@UNAME@,${uname},g" \ -e "s,@ENDIAN@,${defendian},g" \ -e "s,@TOOLSET@,${toolset},g" \ -e "${simmagic1}" \ -e "${simmagic2}" \ <> Makefile <