#!/bin/sh # __________ __ ___. # Open \______ \ ____ ____ | | _\_ |__ _______ ___ # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ # \/ \/ \/ \/ \/ # $Id$ # # global CC options for all platforms CCOPTS="-W -Wall -Wundef -O -nostdlib -ffreestanding -Wstrict-prototypes" use_logf="#undef ROCKBOX_HAS_LOGF" scriptver=`echo '$Revision$' | sed -e 's:\\$::g' -e 's/Revision: //'` # # Begin Function Definitions # input() { read response echo $response } prefixtools () { prefix="$1" CC=${prefix}gcc WINDRES=${prefix}windres DLLTOOL=${prefix}dlltool DLLWRAP=${prefix}dllwrap RANLIB=${prefix}ranlib LD=${prefix}ld AR=${prefix}ar AS=${prefix}as OC=${prefix}objcopy } crosswincc () { # naive approach to selecting a mingw cross-compiler on linux/*nix echo "Enabling win32 crosscompiling" prefixtools i586-mingw32msvc- # add cross-compiler option(s) GCCOPTS="$GCCOPTS `sdl-config --cflags`" LDOPTS="`sdl-config --libs` -mconsole" output="rockboxui.exe" # use this as output binary name crosscompile="yes" endian="little" # windows is little endian } # scan the $PATH for the given command findtool(){ file="$1" IFS=":" for path in $PATH do # echo "checks for $file in $path" >&2 if test -f "$path/$file"; then echo "$path/$file" return fi done # check whether caller wants literal return value if not found if [ "$2" = "--lit" ]; then echo "$file" fi } # parse the argument list, returns the value after the = in case of a # option=value type option, returns 0 in case of --ccache or --no-ccache, # returns 1 if the searched argument type wasn't fount in the argument list # Usage [var = ]`parse_args `, e.g. `parse_args --target` # var definitons below are needed so that parse_args can see the arguments arg1=$1 arg2=$2 arg3=$3 arg4=$4 arg5=$5 arg6=$6 arg7=$7 arg8=$8 arg9=$9 parse_args() { ret="1" for i in $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 do if [ "$1" = "--ccache" ]; then if [ "$i" = "--ccache" ]; then ret="0" fi elif [ "$1" = "--no-ccache" ]; then if [ "$i" = "--no-ccache" ]; then ret="0" fi elif [ "$1" = `echo $i|cut -d'=' -f1` ]; then ret=`echo $i|cut -d'=' -f2` fi done echo "$ret" } simcc () { # default tool setup for native building prefixtools "" simver=sdl GCCOPTS='-W -Wall -g -fno-builtin' output="rockboxui" # use this as default output binary name # generic sdl-config checker sdl=`findtool sdl-config` if [ -z "$sdl" ]; then echo "configure didn't find sdl-config, which indicates that you" echo "don't have SDL (properly) installed. Please correct and" echo "re-run configure!" exit fi # default share option, override below if needed SHARED_FLAG="-shared" case $uname in CYGWIN*) echo "Cygwin host detected" # sdl version GCCOPTS="$GCCOPTS `sdl-config --cflags`" LDOPTS="`sdl-config --libs` -mconsole" output="rockboxui.exe" # use this as output binary name ;; Linux) echo "Linux host detected" if [ "0" != `sdl-config --libs |grep -c mwindows` ]; then # Enable crosscompiling if sdl-config is from Windows SDL crosswincc else GCCOPTS="$GCCOPTS `sdl-config --cflags`" LDOPTS="`sdl-config --libs`" fi ;; FreeBSD) echo "FreeBSD host detected" # sdl version GCCOPTS="$GCCOPTS `sdl-config --cflags`" LDOPTS="`sdl-config --libs`" ;; Darwin) echo "Darwin host detected" # sdl version GCCOPTS="$GCCOPTS `sdl-config --cflags`" LDOPTS="`sdl-config --libs`" SHARED_FLAG="-dynamiclib -Wl\,-single_module" ;; *) echo "Unsupported system: $uname, fix configure and retry" exit ;; esac 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 >/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 } # # functions for setting up cross-compiler names and options # also set endianess and what the exact recommended gcc version is # the gcc version should most likely match what versions we build with # rockboxdev.sh # shcc () { prefixtools sh-elf- GCCOPTS="$CCOPTS -m1" GCCOPTIMIZE="-fomit-frame-pointer -fschedule-insns" endian="big" gccchoice="4.0.3" } calmrisccc () { prefixtools calmrisc16-unknown-elf- GCCOPTS="-Wl\,--no-check-sections $CCOPTS" GCCOPTIMIZE="-fomit-frame-pointer" endian="big" } coldfirecc () { prefixtools m68k-elf- GCCOPTS="$CCOPTS -m5206e -Wa\,-m5249 -malign-int -mstrict-align" GCCOPTIMIZE="-fomit-frame-pointer" endian="big" gccchoice="3.4.6" } arm7tdmicc () { prefixtools arm-elf- GCCOPTS="$CCOPTS -mcpu=arm7tdmi" if test "X$1" != "Xshort"; then GCCOPTS="$GCCOPTS -mlong-calls" fi GCCOPTIMIZE="-fomit-frame-pointer" endian="little" gccchoice="4.0.3" } arm9tdmicc () { prefixtools arm-elf- GCCOPTS="$CCOPTS -mcpu=arm9tdmi -mlong-calls" GCCOPTIMIZE="-fomit-frame-pointer" endian="little" gccchoice="4.0.3" } arm940tbecc () { prefixtools arm-elf- GCCOPTS="$CCOPTS -mbig-endian -mcpu=arm940t -mlong-calls" GCCOPTIMIZE="-fomit-frame-pointer" endian="big" gccchoice="4.0.3" } arm946cc () { prefixtools arm-elf- GCCOPTS="$CCOPTS -mcpu=arm9e -mlong-calls" GCCOPTIMIZE="-fomit-frame-pointer" endian="little" gccchoice="4.0.3" } arm926ejscc () { prefixtools arm-elf- GCCOPTS="$CCOPTS -mcpu=arm926ej-s -mlong-calls" GCCOPTIMIZE="-fomit-frame-pointer" endian="little" gccchoice="4.0.3" } arm1136jfscc () { prefixtools arm-elf- GCCOPTS="$CCOPTS -mcpu=arm1136jf-s -mlong-calls" GCCOPTIMIZE="-fomit-frame-pointer" endian="little" gccchoice="4.0.3" } mipselcc () { prefixtools mipsel-elf- GCCOPTS="$CCOPTS -march=mips32 -mno-mips16 -mno-abicalls -mlong-calls" GCCOPTIMIZE="-fomit-frame-pointer" GCCOPTS="$GCCOPTS -fno-pic -fno-builtin -fno-exceptions -ffunction-sections -msoft-float -G 0" endian="little" gccchoice="4.1.2" } whichadvanced () { ################################################################## # Prompt for specific developer options # echo "" echo "Enter your developer options (press enter when done)" echo -n "(D)EBUG, (L)ogf, (S)imulator, (P)rofiling, (V)oice" if [ "$memory" = "2" ]; then echo -n ", (8)MB MOD" fi if [ "$modelname" = "h120" ]; then echo -n ", (R)TC MOD" fi echo "" cont=1 while [ $cont = "1" ]; do option=`input`; case $option in [Dd]) if [ "yes" = "$profile" ]; then echo "Debug is incompatible with profiling" else echo "define DEBUG" use_debug="yes" fi ;; [Ll]) echo "logf() support enabled" logf="yes" ;; [Ss]) echo "Simulator build enabled" simulator="yes" ;; [Pp]) if [ "yes" = "$use_debug" ]; then echo "Profiling is incompatible with debug" else echo "Profiling support is enabled" profile="yes" fi ;; [Vv]) echo "Voice build selected" voice="yes" ;; 8) if [ "$memory" = "2" ]; then memory="8" echo "Memory size selected: 8MB" else cont=0 fi ;; [Rr]) if [ "$modelname" = "h120" ]; then config_rtc="#define CONFIG_RTC RTC_DS1339_DS3231" have_rtc_alarm="#define HAVE_RTC_ALARM" echo "RTC functions enabled (DS1339/DS3231)" else cont=0 fi ;; *) cont=0 ;; esac done echo "done" if [ "yes" = "$voice" ]; then # Ask about languages to build echo "Select a number for the language to use (default is english)" # The multiple-language feature is currently broken # echo "You may enter a comma-separated list of languages to build" picklang voicelanguage=`whichlang` if [ -z "$voicelanguage" ]; then # pick a default voicelanguage="english" fi echo "Voice language set to $voicelanguage" # Configure encoder and TTS engine for each language for thislang in `echo $voicelanguage | sed 's/,/ /g'`; do voiceconfig "$thislang" done fi if [ "yes" = "$use_debug" ]; then debug="-DDEBUG" GCCOPTS="$GCCOPTS -g -DDEBUG" fi if [ "yes" = "$logf" ]; then use_logf="#define ROCKBOX_HAS_LOGF 1" fi if [ "yes" = "$simulator" ]; then debug="-DDEBUG" extradefines="$extradefines -DSIMULATOR" fi if [ "yes" = "$profile" ]; then extradefines="$extradefines -DRB_PROFILE" PROFILE_OPTS="-finstrument-functions" fi } # Configure voice settings voiceconfig () { thislang=$1 echo "Building $thislang voice for $modelname. Select options" echo "" if [ -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 fi echo "TTS engine to use: ${FLITE}${FESTIVAL}${ESPEAK}${SAPI}${SWIFT}(${DEFAULT_CHOICE})?" option=`input` case "$option" in [Ll]) TTS_ENGINE="flite" NOISEFLOOR="500" # TODO: check this value TTS_OPTS=$FLITE_OPTS ;; [Ee]) TTS_ENGINE="espeak" NOISEFLOOR="500" TTS_OPTS=$ESPEAK_OPTS ;; [Ff]) TTS_ENGINE="festival" NOISEFLOOR="500" TTS_OPTS=$FESTIVAL_OPTS ;; [Ss]) TTS_ENGINE="sapi" NOISEFLOOR="500" TTS_OPTS=$SAPI_OPTS ;; [Ww]) TTS_ENGINE="swift" NOISEFLOOR="500" TTS_OPTS=$SWIFT_OPTS ;; *) TTS_ENGINE=$DEFAULT_TTS TTS_OPTS=$DEFAULT_TTS_OPTS NOISEFLOOR=$DEFAULT_NOISEFLOOR esac echo "Using $TTS_ENGINE for TTS" # Allow the user to input manual commandline options printf "Enter $TTS_ENGINE options (enter for defaults \"$TTS_OPTS\"): " USER_TTS_OPTS=`input` if [ -n "$USER_TTS_OPTS" ]; then TTS_OPTS="$USER_TTS_OPTS" fi echo "" if [ "$swcodec" = "yes" ]; then ENCODER="rbspeexenc" ENC_CMD="rbspeexenc" ENC_OPTS="-q 4 -c 10" else if [ -n "`findtool lame`" ]; then ENCODER="lame" ENC_CMD="lame" ENC_OPTS="--resample 12 -t -m m -h -V 9 -S -B 64 --vbr-new" else echo "You need LAME in the system path to build voice files for" echo "HWCODEC targets." exit fi fi echo "Using $ENCODER for encoding voice clips" # Allow the user to input manual commandline options printf "Enter $ENCODER options (enter for defaults \"$ENC_OPTS\"): " USER_ENC_OPTS=`input` if [ -n "$USER_ENC_OPTS" ]; then ENC_OPTS=$USER_ENC_OPTS fi TEMPDIR="${pwd}" if [ -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=`echo $file | sed -e 's:.*/::g' | cut "-d." -f1` langs="$langs $clean" done num=1 for one in $langs; do echo "$num. $one" num=`expr $num + 1` done read pick } whichlang() { output="" # Allow the user to pass a comma-separated list of langauges for thispick in `echo $pick | sed 's/,/ /g'`; do num=1 for one in $langs; do # Accept both the language number and name if [ "$num" = "$thispick" ] || [ "$thispick" = "$one" ]; then if [ "$output" = "" ]; then output=$one else output=$output,$one fi fi num=`expr $num + 1` done done echo $output } opt=$1 if test "$opt" = "--help"; then echo "Rockbox configure script." echo "Invoke this in a directory to generate a Makefile to build Rockbox" echo "Do *NOT* run this within the tools directory!" echo "" cat </dev/null 2>&1 ; } then echo "WEEEEEEEEP. Don't run this configure script within the tools directory." echo "It will only cause you pain and grief. Instead do this:" echo "" echo " cd .." echo " mkdir build-dir" echo " cd build-dir" echo " ../tools/configure" echo "" echo "Much happiness will arise from this. Enjoy" exit fi fi # get our current directory pwd=`pwd`; if { echo $pwd | grep " "; } then echo "You're running this script in a path that contains space. The build" echo "system is unfortunately not clever enough to deal with this. Please" echo "run the script from a different path, rename the path or fix the build" echo "system!" exit fi if [ -z "$rootdir" ]; then ################################################################## # Figure out where the source code root is! # rootdir=`dirname $0`/../ ##################################################################### # Convert the possibly relative directory name to an absolute version # now=`pwd` cd $rootdir rootdir=`pwd` # cd back to the build dir cd $now fi apps="apps" appsdir='\$(ROOTDIR)/apps' firmdir='\$(ROOTDIR)/firmware' toolsdir='\$(ROOTDIR)/tools' ################################################################## # Figure out target platform # if [ "1" != `parse_args --target` ]; then buildfor=`parse_args --target`; else echo "Enter target platform:" cat </dev/null` # This makes: # 3.3.X => 303 # 3.4.X => 304 # 2.95.3 => 295 echo "Using $CC $gccver ($gccnum)" if test "$gccnum" -ge "400"; then # gcc 4.0 is just *so* much pickier on arguments that differ in signedness # so we ignore that warnings for now # -Wno-pointer-sign GCCOPTS="$GCCOPTS -Wno-pointer-sign" fi if test "$gccnum" -ge "401"; then # this is a lame hack to avoid "warning: dereferencing type-punned pointer # will break strict-aliasing rules" GCCOPTS="$GCCOPTS -fno-strict-aliasing" fi if test "$gccnum" -ge "402"; then # disable warning about "warning: initialized field overwritten" as gcc 4.2 # and later would throw it for several valid cases GCCOPTS="$GCCOPTS -Wno-override-init" fi case $prefix in "") # simulator ;; i586-mingw32msvc-) # cross-compile for win32 ;; *) # Verify that the cross-compiler is of a recommended version! if test "$gccver" != "$gccchoice"; then echo "WARNING: Your cross-compiler $CC $gccver is not of the recommended" echo "WARNING: version $gccchoice!" echo "WARNING: This may cause your build to fail since it may be a version" echo "WARNING: that isn't functional or known to not be the best choice." echo "WARNING: If you suffer from build problems, you know that this is" echo "WARNING: a likely source for them..." fi ;; esac fi echo "Using $LD $ldver" # check the compiler for SH platforms if test "$CC" = "sh-elf-gcc"; then if test "$gccnum" -lt "400"; then echo "WARNING: Consider upgrading your compiler to the 4.0.X series!" echo "WARNING: http://www.rockbox.org/twiki/bin/view/Main/CrossCompiler" else # figure out patch status gccpatch=`$CC --version`; if { echo $gccpatch | grep "rockbox" >/dev/null 2>&1; } then echo "gcc $gccver is rockbox patched" # then convert -O to -Os to get smaller binaries! GCCOPTS=`echo $GCCOPTS | sed 's/ -O / -Os /'` else echo "WARNING: You use an unpatched gcc compiler: $gccver" echo "WARNING: http://www.rockbox.org/twiki/bin/view/Main/CrossCompiler" fi fi fi if test "$CC" = "m68k-elf-gcc"; then # convert -O to -Os to get smaller binaries! GCCOPTS=`echo $GCCOPTS | sed 's/ -O / -Os /'` fi if [ "1" != `parse_args --ccache` ]; then echo "Enable ccache for building" ccache="ccache" else if [ "1" = `parse_args --no-ccache` ]; then ccache=`findtool ccache` if test -n "$ccache"; then echo "Found and uses ccache ($ccache)" fi fi fi # figure out the full path to the various commands if possible HOSTCC=`findtool gcc --lit` HOSTAR=`findtool ar --lit` CC=`findtool ${CC} --lit` LD=`findtool ${AR} --lit` AR=`findtool ${AR} --lit` AS=`findtool ${AS} --lit` OC=`findtool ${OC} --lit` WINDRES=`findtool ${WINDRES} --lit` DLLTOOL=`findtool ${DLLTOOL} --lit` DLLWRAP=`findtool ${DLLWRAP} --lit` RANLIB=`findtool ${RANLIB} --lit` if test -n "$ccache"; then CC="$ccache $CC" fi if test "X$endian" = "Xbig"; then defendian="ROCKBOX_BIG_ENDIAN" else defendian="ROCKBOX_LITTLE_ENDIAN" fi sed > autoconf.h \ -e "s,@ENDIAN@,${defendian},g" \ -e "s,^#undef ROCKBOX_HAS_LOGF,$use_logf,g" \ -e "s,@config_rtc@,$config_rtc,g" \ -e "s,@have_rtc_alarm@,$have_rtc_alarm,g" \ < Makefile \ -e "s,@ROOTDIR@,${rootdir},g" \ -e "s,@DEBUG@,${debug},g" \ -e "s,@MEMORY@,${memory},g" \ -e "s,@TARGET_ID@,${target_id},g" \ -e "s,@TARGET@,${target},g" \ -e "s,@CPU@,${t_cpu},g" \ -e "s,@MANUFACTURER@,${t_manufacturer},g" \ -e "s,@MODELNAME@,${modelname},g" \ -e "s,@LANGUAGE@,${language},g" \ -e "s:@VOICELANGUAGE@:${voicelanguage}:g" \ -e "s,@PWD@,${pwd},g" \ -e "s,@HOSTCC@,${HOSTCC},g" \ -e "s,@HOSTAR@,${HOSTAR},g" \ -e "s,@CC@,${CC},g" \ -e "s,@LD@,${LD},g" \ -e "s,@AR@,${AR},g" \ -e "s,@AS@,${AS},g" \ -e "s,@OC@,${OC},g" \ -e "s,@WINDRES@,${WINDRES},g" \ -e "s,@DLLTOOL@,${DLLTOOL},g" \ -e "s,@DLLWRAP@,${DLLWRAP},g" \ -e "s,@RANLIB@,${RANLIB},g" \ -e "s,@TOOL@,${tool},g" \ -e "s,@BMP2RB_NATIVE@,${bmp2rb_native},g" \ -e "s,@BMP2RB_MONO@,${bmp2rb_mono},g" \ -e "s,@BMP2RB_REMOTENATIVE@,${bmp2rb_remotenative},g" \ -e "s,@BMP2RB_REMOTEMONO@,${bmp2rb_remotemono},g" \ -e "s,@OUTPUT@,${output},g" \ -e "s,@APPEXTRA@,${appextra},g" \ -e "s,@ARCHOSROM@,${archosrom},g" \ -e "s,@FLASHFILE@,${flash},g" \ -e "s,@PLUGINS@,${plugins},g" \ -e "s,@CODECS@,${swcodec},g" \ -e "s,@PROFILE_OPTS@,${PROFILE_OPTS},g" \ -e "s,@SHARED_FLAG@,${SHARED_FLAG},g" \ -e "s,@GCCOPTS@,${GCCOPTS},g" \ -e "s,@TARGET_INC@,${TARGET_INC},g" \ -e "s!@LDOPTS@!${LDOPTS}!g" \ -e "s,@LOADADDRESS@,${loadaddress},g" \ -e "s,@EXTRADEF@,${extradefines},g" \ -e "s,@APPSDIR@,${appsdir},g" \ -e "s,@FIRMDIR@,${firmdir},g" \ -e "s,@TOOLSDIR@,${toolsdir},g" \ -e "s,@APPS@,${apps},g" \ -e "s,@SIMVER@,${simver},g" \ -e "s,@GCCVER@,${gccver},g" \ -e "s,@GCCNUM@,${gccnum},g" \ -e "s,@UNAME@,${uname},g" \ -e "s,@ENDIAN@,${defendian},g" \ -e "s,@TOOLSET@,${toolset},g" \ -e "${simmagic1}" \ -e "${simmagic2}" \ -e "s,@MANUALDEV@,${manualdev},g" \ -e "s,@ENCODER@,${ENC_CMD},g" \ -e "s,@ENC_OPTS@,${ENC_OPTS},g" \ -e "s,@TTS_ENGINE@,${TTS_ENGINE},g" \ -e "s,@TTS_OPTS@,${TTS_OPTS},g" \ -e "s,@VOICETOOLSET@,${voicetoolset},g" \ -e "s,@LANGS@,${buildlangs},g" \ -e "s,@USE_ELF@,${USE_ELF},g" \ <