Guest User

rockboxdev.sh

a guest
Jun 17th, 2019
33
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Abort execution as soon as an error is encountered
  4. # That way the script do not let the user think the process completed correctly
  5. # and leave the opportunity to fix the problem and restart compilation where
  6. # it stopped
  7. set -e
  8.  
  9. # this is where this script will store downloaded files and check for already
  10. # downloaded files
  11. dlwhere="${RBDEV_DOWNLOAD:-/tmp/rbdev-dl}"
  12.  
  13. # will append the target string to the prefix dir mentioned here
  14. # Note that the user running this script must be able to do make install in
  15. # this given prefix directory. Also make sure that this given root dir
  16. # exists.
  17. prefix="${RBDEV_PREFIX:-/usr/local}"
  18.  
  19. # This directory is used to extract all files and to build everything in. It
  20. # must not exist before this script is invoked (as a security measure).
  21. builddir="${RBDEV_BUILD:-/tmp/rbdev-build}"
  22.  
  23. # This script needs to use GNU Make. On Linux systems, GNU Make is invoked
  24. # by running the "make" command, on most BSD systems, GNU Make is invoked
  25. # by running the "gmake" command. Set the "make" variable accordingly.
  26. if [ -f "`which gmake 2>/dev/null`" ]; then
  27.     make="gmake"
  28. else
  29.     make="make"
  30. fi
  31.  
  32. if [ -z $GNU_MIRROR ] ; then
  33.     GNU_MIRROR=http://mirrors.kernel.org/gnu
  34. fi
  35.  
  36. if [ -z $LINUX_MIRROR ] ; then
  37.     LINUX_MIRROR=http://www.kernel.org/pub/linux
  38. fi
  39.  
  40. # These are the tools this script requires and depends upon.
  41. reqtools="gcc bzip2 gzip make patch makeinfo automake libtool autoconf flex bison"
  42.  
  43. ##############################################################################
  44. # Functions:
  45.  
  46. findtool(){
  47.   file="$1"
  48.  
  49.   IFS=":"
  50.   for path in $PATH
  51.   do
  52.     # echo "Checks for $file in $path" >&2
  53.     if test -f "$path/$file"; then
  54.       echo "$path/$file"
  55.       return
  56.     fi
  57.   done
  58. }
  59.  
  60. findlib (){
  61.     lib="$1"
  62.     # on error, gcc will spit out "cannot find -lxxxx", but it may not be in
  63.     # english so grep for -lxxxx
  64.     if ! gcc -l$lib 2>&1 | grep -q -- "-l$lib"; then
  65.         echo "ok"
  66.         return
  67.     fi
  68. }
  69.  
  70. # check if all the libraries in argument are installed, exit with error if not
  71. checklib() {
  72.     for t in "$@"; do
  73.         lib=`findlib $t`
  74.         if test -z "$lib"; then
  75.             echo "ROCKBOXDEV: library \"$t\" is required for this script to work."
  76.             missingtools="yes"
  77.         fi
  78.     done
  79.     if [ -n "$missingtools" ]; then
  80.         echo "ROCKBOXDEV: Please install the missing libraries and re-run the script."
  81.         exit 1
  82.     fi
  83. }
  84.  
  85. input() {
  86.     read response
  87.     echo $response
  88. }
  89.  
  90. # compare two versions, return 1 if first version is strictly before the second
  91. # version_lt ver1 ver2
  92. version_lt() {
  93.     # use sort with natural version sorting
  94.     ltver=`printf "$1\n$2" | sort -V | head -n 1`
  95.     [ "$1" = "$ltver" ] && true || false
  96. }
  97.  
  98. # Download a file from a server (unless it already exists locally in $dlwhere).
  99. # The output file name is always $dlwhere/$1, and the function will try URLs
  100. # one after the other
  101. # $1 file
  102. # $2 server file name
  103. # $2,$3,... URL root list
  104. getfile_ex() {
  105.     out_file="$dlwhere/$1"
  106.     srv_file="$2"
  107.     if test -f $out_file; then
  108.         echo "ROCKBOXDEV: Skipping download of $1: File already exists"
  109.         return
  110.     fi
  111.     # find tool (curl or wget) and build download command
  112.     tool=`findtool curl`
  113.     if test -z "$tool"; then
  114.         tool=`findtool wget`
  115.         if test -n "$tool"; then
  116.             # wget download
  117.             echo "ROCKBOXDEV: Downloading $1 using wget"
  118.             tool="$tool -T 60 -O "
  119.         else
  120.             echo "ROCKBOXDEV: No downloader tool found!"
  121.             echo "ROCKBOXDEV: Please install curl or wget and re-run the script"
  122.             exit
  123.         fi
  124.     else
  125.         # curl download
  126.         echo "ROCKBOXDEV: Downloading $1 using curl"
  127.         tool="$tool -fLo "
  128.     fi
  129.  
  130.     # shift arguments so that $@ is the list of URLs
  131.     shift
  132.     shift
  133.     for url in "$@"; do
  134.         echo "ROCKBOXDEV: try $url/$srv_file"
  135.         if $tool "$out_file" "$url/$srv_file"; then
  136.             return
  137.         fi
  138.     done
  139.  
  140.     echo "ROCKBOXDEV: couldn't download the file!"
  141.     echo "ROCKBOXDEV: check your internet connection"
  142.     exit
  143. }
  144.  
  145. #$1 file
  146. #$2 URL"root
  147. # Output file name is the same as the server file name ($1)
  148. # Does not download the file if it already exists locally in $dlwhere/
  149. getfile() {
  150.     getfile_ex "$1" "$1" "$2"
  151. }
  152.  
  153. # wrapper around getfile to abstract url
  154. # getttool tool version
  155. # the file is always downloaded to "$dlwhere/$toolname-$version.tar.bz2"
  156. gettool() {
  157.     toolname="$1"
  158.     version="$2"
  159.     ext="tar.bz2"
  160.     file="$toolname-$version"
  161.     srv_file="$toolname-$version"
  162.     case $toolname in
  163.         gcc)
  164.             # before 4.7, the tarball was named gcc-core
  165.             if version_lt "$version" "4.7"; then
  166.                 srv_file="gcc-core-$version"
  167.             fi
  168.             url="$GNU_MIRROR/gcc/gcc-$version"
  169.             ;;
  170.  
  171.         binutils)
  172.             url="$GNU_MIRROR/binutils"
  173.             ;;
  174.  
  175.         glibc)
  176.             url="$GNU_MIRROR/glibc"
  177.             ;;
  178.  
  179.         crosstool-ng)
  180.             url="http://crosstool-ng.org/download/crosstool-ng"
  181.             ;;
  182.  
  183.         alsa-lib)
  184.             url="ftp://ftp.alsa-project.org/pub/lib/"
  185.             ;;
  186.  
  187.         linux)
  188.             # FIXME linux kernel server uses an overcomplicated architecture,
  189.             # especially for longterm kernels, so we need to lookup several
  190.             # places. This will need fixing for non-4-part 2.6 versions but it
  191.             # is written in a way that should make it easy
  192.             case "$version" in
  193.                 2.6.*.*)
  194.                     # 4-part versions -> remove last digit for longterm
  195.                     longterm_ver="${version%.*}"
  196.                     top_dir="v2.6"
  197.                     ;;
  198.                 3.*)
  199.                     longterm_ver=""
  200.                     top_dir="v3.x"
  201.                     ;;
  202.                 *)
  203.                     echo "ROCKBOXDEV: I don't know how to handle this kernel version: $version"
  204.                     exit
  205.                 ;;
  206.             esac
  207.             base_url="http://www.kernel.org/pub/linux/kernel/$top_dir"
  208.             # we try several URLs, the 2.6 versions are a mess and need that
  209.             url="$base_url $base_url/longterm/v$longterm_ver $base_url/longterm"
  210.             ext="tar.gz"
  211.             ;;
  212.  
  213.         *)
  214.             echo "ROCKBOXDEV: Bad toolname $toolname"
  215.             exit
  216.             ;;
  217.     esac
  218.     getfile_ex "$file.$ext" "$srv_file.$ext" $url
  219. }
  220.  
  221. # extract file to the current directory
  222. # extract file
  223. extract() {
  224.     if [ -d "$1" ]; then
  225.         echo "ROCKBOXDEV: Skipping extraction of $1: already done"
  226.         return
  227.     fi
  228.     echo "ROCKBOXDEV: extracting $1"
  229.     if [ -f "$dlwhere/$1.tar.bz2" ]; then
  230.         tar xjf "$dlwhere/$1.tar.bz2"
  231.     elif [ -f "$dlwhere/$1.tar.gz" ]; then
  232.         tar xzf "$dlwhere/$1.tar.gz"
  233.     else
  234.         echo "ROCKBOXDEV: I don't know how to extract $1 (no bzip2 or gzip)"
  235.         exit
  236.     fi
  237. }
  238.  
  239. # run a command, and a log command and output to a file (append)
  240. # exit on error
  241. # run_cmd logfile cmd...
  242. run_cmd() {
  243.     logfile="$1"
  244.     shift
  245.     echo "Running '$@'" >>$logfile
  246.     if ! $@ >> "$logfile" 2>&1; then
  247.         echo "ROCKBOXDEV: an error occured, please see $logfile"
  248.         exit
  249.     fi
  250. }
  251.  
  252. # check if the following should be executed or not, depending on RESTART variable:
  253. # $1=tool
  254. # If RESTART is empty, always perform step, otherwise only perform is there is
  255. # an exact match. On the first match, RESTART is reset to "" so that next step
  256. # are executed
  257. check_restart() {
  258.     if [ "$1" = "$RESTART" ]; then
  259.         RESTART=""
  260.         true
  261.     fi
  262.     [ "$RESTART" = "" ] && true || false
  263. }
  264.  
  265. # advanced tool building: create a build directory, run configure, run make
  266. # and run make install. It is possible to customize all steps or disable them
  267. # $1=tool
  268. # $2=version
  269. # $3=configure options, or "NO_CONFIGURE" to disable step
  270. # $4=make options, or "NO_MAKE" to disable step
  271. # $5=make install options (will be replaced by "install" if left empty)
  272. # By default, the restary step is the toolname, but it can be changed by setting
  273. # RESTART_STEP
  274. buildtool() {
  275.     tool="$1"
  276.     version="$2"
  277.     toolname="$tool-$version"
  278.     config_opt="$3"
  279.     make_opts="$4"
  280.     install_opts="$5"
  281.     logfile="$builddir/build-$toolname.log"
  282.  
  283.     stepname=${RESTART_STEP-$tool}
  284.     if ! check_restart "$stepname"; then
  285.         echo "ROCKBOXDEV: Skipping step '$stepname' as requested per RESTART"
  286.         return
  287.     fi
  288.     echo "ROCKBOXDEV: Starting step '$stepname'"
  289.  
  290.     echo "ROCKBOXDEV: logging to $logfile"
  291.     rm -f "$logfile"
  292.  
  293.     echo "ROCKBOXDEV: mkdir build-$toolname"
  294.     mkdir "build-$toolname"
  295.  
  296.     echo "ROCKBOXDEV: cd build-$toolname"
  297.     cd "build-$toolname"
  298.  
  299.     # in-tree/out-of-tree build
  300.     case "$tool" in
  301.         linux|alsa-lib)
  302.             # in-intree
  303.             echo "ROCKBOXDEV: copy $toolname for in-tree build"
  304.             # copy the source directory to the build directory
  305.             cp -r ../$toolname/* .
  306.             cfg_dir="."
  307.             ;;
  308.  
  309.         *)
  310.             # out-of-tree
  311.             cfg_dir="../$toolname";
  312.             ;;
  313.     esac
  314.  
  315.     if [ "$config_opt" != "NO_CONFIGURE" ]; then
  316.         echo "ROCKBOXDEV: $toolname/configure"
  317.         # NOTE glibc requires to be compiled with optimization
  318.         CFLAGS='-U_FORTIFY_SOURCE -fgnu89-inline -O2' run_cmd "$logfile" \
  319.             "$cfg_dir/configure" "--prefix=$prefix" \
  320.             --disable-docs $config_opt
  321.     fi
  322.  
  323.     if [ "$make_opts" != "NO_MAKE" ]; then
  324.         echo "ROCKBOXDEV: $toolname/make"
  325.         run_cmd "$logfile" $make $make_opts
  326.     fi
  327.  
  328.     if [ "$install_opts" = "" ]; then
  329.         install_opts="install"
  330.     fi
  331.     echo "ROCKBOXDEV: $toolname/make (install)"
  332.     run_cmd "$logfile" $make $install_opts
  333.  
  334.     echo "ROCKBOXDEV: rm -rf build-$toolname $toolname"
  335.     cd ..
  336.     rm -rf build-$toolname
  337. }
  338.  
  339. build() {
  340.     toolname="$1"
  341.     target="$2"
  342.     version="$3"
  343.     patch="$4"
  344.     configure_params="$5"
  345.     needs_libs="$6"
  346.  
  347.     logfile="$builddir/build-$toolname.log"
  348.  
  349.     patch_url="http://www.rockbox.org/gcc"
  350.  
  351.     # create build directory
  352.     if test -d $builddir; then
  353.         if test ! -w $builddir; then
  354.             echo "ROCKBOXDEV: No write permission for $builddir"
  355.             exit
  356.         fi
  357.     else
  358.         mkdir -p $builddir
  359.     fi
  360.  
  361.     # download source tarball
  362.     gettool "$toolname" "$version"
  363.     file="$toolname-$version"
  364.  
  365.     # download patch
  366.     for p in $patch; do
  367.         getfile "$p" "$patch_url"
  368.     done
  369.  
  370.     cd $builddir
  371.  
  372.     extract "$toolname-$version"
  373.  
  374.     # do we have a patch?
  375.     for p in $patch; do
  376.         echo "ROCKBOXDEV: applying patch $p"
  377.  
  378.         # apply the patch
  379.         (cd $builddir/$toolname-$version && patch -p1 < "$dlwhere/$p")
  380.  
  381.         # check if the patch applied cleanly
  382.         if [ $? -gt 0 ]; then
  383.             echo "ROCKBOXDEV: failed to apply patch $p"
  384.             exit
  385.         fi
  386.     done
  387.  
  388.     # kludge to avoid having to install GMP, MPFR and MPC, for new gcc
  389.     if test -n "$needs_libs"; then
  390.         cd "gcc-$version"
  391.         if (echo $needs_libs | grep -q gmp && test ! -d gmp); then
  392.             echo "ROCKBOXDEV: Getting GMP"
  393.             getfile "gmp-4.3.2.tar.bz2" "$GNU_MIRROR/gmp"
  394.             tar xjf $dlwhere/gmp-4.3.2.tar.bz2
  395.             ln -s gmp-4.3.2 gmp
  396.         fi
  397.  
  398.         if (echo $needs_libs | grep -q mpfr && test ! -d mpfr); then
  399.             echo "ROCKBOXDEV: Getting MPFR"
  400.             getfile "mpfr-2.4.2.tar.bz2" "$GNU_MIRROR/mpfr"
  401.             tar xjf $dlwhere/mpfr-2.4.2.tar.bz2
  402.             ln -s mpfr-2.4.2 mpfr
  403.         fi
  404.  
  405.         if (echo $needs_libs | grep -q mpc && test ! -d mpc); then
  406.             echo "ROCKBOXDEV: Getting MPC"
  407.             getfile "mpc-0.8.1.tar.gz" "http://www.multiprecision.org/downloads"
  408.             tar xzf $dlwhere/mpc-0.8.1.tar.gz
  409.             ln -s mpc-0.8.1 mpc
  410.         fi
  411.         cd $builddir
  412.     fi
  413.  
  414.     echo "ROCKBOXDEV: mkdir build-$toolname"
  415.     mkdir build-$toolname
  416.  
  417.     echo "ROCKBOXDEV: cd build-$toolname"
  418.     cd build-$toolname
  419.  
  420.     echo "ROCKBOXDEV: logging to $logfile"
  421.     rm -f "$logfile"
  422.  
  423.     echo "ROCKBOXDEV: $toolname/configure"
  424.     case $toolname in
  425.         crosstool-ng) # ct-ng doesnt support out-of-tree build and the src folder is named differently
  426.             toolname="crosstool-ng"
  427.             cp -r ../$toolname-$version/* ../$toolname-$version/.version .
  428.             ./configure --prefix=$prefix $configure_params
  429.         ;;
  430.         *)
  431.             CFLAGS='-U_FORTIFY_SOURCE -fgnu89-inline'
  432.             run_cmd "$logfile" ../$toolname-$version/configure --target=$target --prefix=$prefix --enable-languages=c --disable-libssp --disable-docs $configure_params
  433.         ;;
  434.     esac
  435.  
  436.     echo "ROCKBOXDEV: $toolname/make"
  437.     run_cmd "$logfile" $make -i
  438.  
  439.     echo "ROCKBOXDEV: $toolname/make install"
  440.     run_cmd "$logfile" $make install -i
  441.  
  442.     echo "ROCKBOXDEV: rm -rf build-$toolname $toolname-$version"
  443.     cd ..
  444.     rm -rf build-$toolname $toolname-$version
  445. }
  446.  
  447. make_ctng() {
  448.     if test -f "`which ct-ng 2>/dev/null`"; then
  449.         ctng="ct-ng"
  450.     else
  451.         ctng=""
  452.     fi
  453.  
  454.     if test ! -n "$ctng"; then
  455.         if test ! -f "$prefix/bin/ct-ng"; then # look if we build it already
  456.             build "crosstool-ng" "" "1.13.2" "crosstool-ng-1.13.2.diff"
  457.         fi
  458.     fi
  459.     ctng=`PATH=$prefix/bin:$PATH which ct-ng`
  460. }
  461.  
  462. build_ctng() {
  463.     ctng_target="$1"
  464.     extra="$2"
  465.     tc_arch="$3"
  466.     tc_host="$4"
  467.  
  468.     make_ctng
  469.  
  470.     dlurl="http://www.rockbox.org/gcc/$ctng_target"
  471.  
  472.     # download
  473.     getfile "ct-ng-config" "$dlurl"
  474.  
  475.     test -n "$extra" && getfile "$extra" "$dlurl"
  476.    
  477.     # create build directory
  478.     if test -d $builddir; then
  479.         if test ! -w $builddir; then
  480.             echo "ROCKBOXDEV: No write permission for $builddir"
  481.             exit
  482.         fi
  483.     else
  484.         mkdir -p $builddir
  485.     fi
  486.  
  487.     # copy config and cd to $builddir
  488.     mkdir $builddir/build-$ctng_target
  489.     ctng_config="$builddir/build-$ctng_target/.config"
  490.     cat "$dlwhere/ct-ng-config" | sed -e "s,\(CT_PREFIX_DIR=\).*,\1$prefix," > $ctng_config
  491.     cd $builddir/build-$ctng_target
  492.  
  493.     $ctng "build"
  494.  
  495.     # install extras
  496.     if test -e "$dlwhere/$extra"; then
  497.         # verify the toolchain has sysroot support
  498.         if test -n `cat $ctng_config | grep CT_USE_SYSROOT\=y`; then
  499.             sysroot=`cat $ctng_config | grep CT_SYSROOT_NAME | sed -e 's,CT_SYSROOT_NAME\=\"\([a-zA-Z0-9]*\)\",\1,'`
  500.             tar xf "$dlwhere/$extra" -C "$prefix/$tc_arch-$ctng_target-$tc_host/$sysroot"
  501.         fi
  502.     fi
  503.    
  504.     # cleanup
  505.     cd $builddir
  506.     rm -rf $builddir/build-$ctng_target
  507. }
  508.  
  509. # build a cross compiler toolchain for linux
  510. # $1=target
  511. # $2=binutils version
  512. # $3=binutils configure extra options
  513. # $4=gcc version
  514. # $5=gcc configure extra options
  515. # $6=linux version
  516. # $7=glibc version
  517. # $8=glibc configure extra options
  518. build_linux_toolchain () {
  519.     target="$1"
  520.     binutils_ver="$2"
  521.     binutils_opts="$3"
  522.     gcc_ver="$4"
  523.     gcc_opts="$5"
  524.     linux_ver="$6"
  525.     glibc_ver="$7"
  526.     glibc_opts="$8"
  527.     # where to put the sysroot
  528.     sysroot="$prefix/$target/sysroot"
  529.     # extract arch from target
  530.     arch=${target%%-*}
  531.  
  532.     # check libraries:
  533.     # contrary to other toolchains that rely on a hack to avoid installing
  534.     # gmp, mpc and mpfr, we simply require that they are installed on the system
  535.     # this is not a huge requirement since virtually all systems these days
  536.     # provide dev packages for them
  537.     # FIXME: maybe add an option to download and install them automatically
  538.     checklib "mpc" "gmp" "mpfr"
  539.  
  540.     # create build directory
  541.     if test -d $builddir; then
  542.         if test ! -w $builddir; then
  543.             echo "ROCKBOXDEV: No write permission for $builddir"
  544.             exit
  545.         fi
  546.     else
  547.         mkdir -p $builddir
  548.     fi
  549.  
  550.     # download all tools
  551.     gettool "binutils" "$binutils_ver"
  552.     gettool "gcc" "$gcc_ver"
  553.     gettool "linux" "$linux_ver"
  554.     gettool "glibc" "$glibc_ver"
  555.  
  556.     # extract them
  557.     cd $builddir
  558.     extract "binutils-$binutils_ver"
  559.     extract "gcc-$gcc_ver"
  560.     extract "linux-$linux_ver"
  561.     extract "glibc-$glibc_ver"
  562.  
  563.     # we make it possible to restart a build on error by using the RESTART
  564.     # variable, the format is RESTART="tool" where tool is the toolname at which
  565.     # to restart (binutils, gcc)
  566.  
  567.     # install binutils, with support for sysroot
  568.     buildtool "binutils" "$binutils_ver" "--target=$target --disable-werror \
  569.        --with-sysroot=$sysroot --disable-nls" "" ""
  570.     # build stage 1 compiler: disable headers, disable threading so that
  571.     # pthread headers are not included, pretend we use newlib so that libgcc
  572.     # doesn't get linked at the end
  573.     # NOTE there is some magic involved here
  574.     RESTART_STEP="gcc-stage1" \
  575.     buildtool "gcc" "$gcc_ver" "$gcc_opts --enable-languages=c --target=$target \
  576.        --without-headers --disable-threads --disable-libgomp --disable-libmudflap \
  577.        --disable-libssp --disable-libquadmath --disable-libquadmath-support \
  578.        --disable-shared --with-newlib --disable-libitm \
  579.        --disable-libsanitizer --disable-libatomic" "" ""
  580.     # install linux headers
  581.     # NOTE: we need to tell make where to put the build files, since buildtool
  582.     # switches to the builddir, "." will be the correct builddir when ran
  583.     if [ "$arch" == "mipsel" ]; then
  584.         arch="mips"
  585.     fi
  586.     linux_opts="O=. ARCH=$arch INSTALL_HDR_PATH=$sysroot/usr/"
  587.     RESTART_STEP="linux-headers" \
  588.     buildtool "linux" "$linux_ver" "NO_CONFIGURE" \
  589.         "$linux_opts headers_install" "$linux_opts headers_check"
  590.     # build glibc using the first stage cross compiler
  591.     # we need to set the prefix to /usr because the glibc runs on the actual
  592.     # target and is indeed installed in /usr
  593.     prefix="/usr" \
  594.     buildtool "glibc" "$glibc_ver" "--target=$target --host=$target --build=$MACHTYPE \
  595.        --with-__thread --with-headers=$sysroot/usr/include $glibc_opts" \
  596.         "" "install install_root=$sysroot"
  597.     # build stage 2 compiler
  598.     buildtool "gcc" "$gcc_ver" "$gcc_opts --enable-languages=c,c++ --target=$target \
  599.        --with-sysroot=$sysroot" "" ""
  600. }
  601.  
  602. usage () {
  603.     echo "usage: rockboxdev.sh [options]"
  604.     echo "options:"
  605.     echo "  --help              Display this help"
  606.     echo "  --target=LIST       List of targets to build"
  607.     echo "  --restart=STEP      Restart build at given STEP (same as RESTART env var)"
  608.     echo "  --prefix=PREFIX     Set install prefix (same as RBDEV_PREFIX env var)"
  609.     echo "  --dlwhere=DIR       Set download directory (same as RBDEV_DOWNLOAD env var)"
  610.     echo "  --builddir=DIR      Set build directory (same as RBDEV_BUILD env var)"
  611.     echo "  --makeflags=FLAGS   Set make flags (same as MAKEFLAGS env var)"
  612.     exit 1
  613. }
  614.  
  615. ##############################################################################
  616. # Code:
  617.  
  618. # Parse arguments
  619. for i in "$@"
  620. do
  621. case $i in
  622.     --help)
  623.         usage
  624.         ;;
  625.     --prefix=*)
  626.         prefix="${i#*=}"
  627.         shift
  628.         ;;
  629.     --target=*)
  630.         RBDEV_TARGET="${i#*=}"
  631.         shift
  632.         ;;
  633.     --restart=*)
  634.         RBDEV_RESTART="${i#*=}"
  635.         shift
  636.         ;;
  637.     --dlwhere=*)
  638.         dlwhere="${i#*=}"
  639.         shift
  640.         ;;
  641.     --builddir=*)
  642.         builddir="${i#*=}"
  643.         shift
  644.         ;;
  645.     --makeflags=*)
  646.         export MAKEFLAGS="${i#*=}" # export so it's available in make
  647.         shift
  648.         ;;
  649.     *)
  650.         echo "Unknown option '$i'"
  651.         exit 1
  652.         ;;
  653. esac
  654. done
  655.  
  656. # Verify required tools and libraries
  657. for t in $reqtools; do
  658.     tool=`findtool $t`
  659.     if test -z "$tool"; then
  660.         echo "ROCKBOXDEV: \"$t\" is required for this script to work."
  661.         missingtools="yes"
  662.     fi
  663. done
  664. if [ -n "$missingtools" ]; then
  665.     echo "ROCKBOXDEV: Please install the missing tools and re-run the script."
  666.     exit 1
  667. fi
  668.  
  669. echo "Download directory : $dlwhere (set RBDEV_DOWNLOAD or use --download= to change)"
  670. echo "Install prefix     : $prefix  (set RBDEV_PREFIX or use --prefix= to change)"
  671. echo "Build dir          : $builddir (set RBDEV_BUILD or use --builddir= to change)"
  672. echo "Make options       : $MAKEFLAGS (set MAKEFLAGS or use --makeflags= to change)"
  673. echo "Restart step       : $RBDEV_RESTART (set RBDEV_RESTART or use --restart= to change)"
  674. echo "Target arch        : $RBDEV_TARGET (set RBDEV_TARGET or use --target to change)"
  675.  
  676. # Verify download directory
  677. if test -d "$dlwhere"; then
  678.   if ! test -w "$dlwhere"; then
  679.     echo "ROCKBOXDEV: No write permission for $dlwhere"
  680.     exit
  681.   fi
  682. else
  683.   mkdir $dlwhere
  684.   if test $? -ne 0; then
  685.     echo "ROCKBOXDEV: Failed creating directory $dlwhere"
  686.     exit
  687.   fi
  688. fi
  689.  
  690.  
  691. # Verify the prefix dir
  692. if test ! -d $prefix; then
  693.   mkdir -p $prefix
  694.   if test $? -ne 0; then
  695.       echo "ROCKBOXDEV: Failed creating directory $prefix"
  696.       exit
  697.   fi
  698. fi
  699. if test ! -w $prefix; then
  700.   echo "ROCKBOXDEV: No write permission for $prefix"
  701.   exit
  702. fi
  703.  
  704. if [ -z "$RBDEV_TARGET" ]; then
  705.     echo "Select target arch:"
  706.     echo "s   - sh       (Archos models)"
  707.     echo "m   - m68k     (iriver h1x0/h3x0, iaudio m3/m5/x5 and mpio hd200)"
  708.     echo "a   - arm      (ipods, iriver H10, Sansa, D2, Gigabeat, etc)"
  709.     echo "i   - mips     (Jz47xx and ATJ-based players)"
  710.     echo "r   - arm-app  (Samsung ypr0)"
  711.     echo "x   - arm-linux  (Generic Linux ARM: Samsung ypr0, Linux-based Sony NWZ)"
  712.     echo "y   - mips-linux  (Generic Linux MIPS: AGPTek Rocker)"
  713.     echo "separate multiple targets with spaces"
  714.     echo "(Example: \"s m a\" will build sh, m68k and arm)"
  715.     echo ""
  716.     selarch=`input`
  717. else
  718.     selarch=$RBDEV_TARGET
  719. fi
  720. system=`uname -s`
  721.  
  722. # add target dir to path to ensure the new binutils are used in gcc build
  723. PATH="$prefix/bin:${PATH}"
  724.  
  725. for arch in $selarch
  726. do
  727.     echo ""
  728.     case $arch in
  729.         [Ss])
  730.             # For binutils 2.16.1 builtin rules conflict on some systems with a
  731.             # default rule for Objective C. Disable the builtin make rules. See
  732.             # http://sourceware.org/ml/binutils/2005-12/msg00259.html
  733.             export MAKEFLAGS="-r $MAKEFLAGS"
  734.             build "binutils" "sh-elf" "2.16.1" "binutils-2.16.1-texinfo-fix.diff" "--disable-werror"
  735.             build "gcc" "sh-elf" "4.0.3" "gcc-4.0.3-rockbox-1.diff"
  736.             ;;
  737.  
  738.         [Ii])
  739.             build "binutils" "mipsel-elf" "2.26.1" "" "--disable-werror"
  740.             build "gcc" "mipsel-elf" "4.9.4" "" "" "gmp mpfr mpc"
  741.             ;;
  742.  
  743.         [Mm])
  744.             build "binutils" "m68k-elf" "2.20.1" "binutils-2.20.1-texinfo-fix.diff" "--disable-werror"
  745.             build "gcc" "m68k-elf" "4.5.2" "" "--with-arch=cf MAKEINFO=missing" "gmp mpfr mpc"
  746.             ;;
  747.  
  748.         [Aa])
  749.             binopts=""
  750.             gccopts=""
  751.             case $system in
  752.                 Darwin)
  753.                     binopts="--disable-nls"
  754.                     gccopts="--disable-nls"
  755.                     ;;
  756.             esac
  757.             build "binutils" "arm-elf-eabi" "2.20.1" "binutils-2.20.1-ld-thumb-interwork-long-call.diff binutils-2.20.1-texinfo-fix.diff" "$binopts --disable-werror"
  758.             build "gcc" "arm-elf-eabi" "4.4.4" "rockbox-multilibs-noexceptions-arm-elf-eabi-gcc-4.4.2_1.diff" "$gccopts MAKEINFO=missing" "gmp mpfr"
  759.             ;;
  760.         [Rr])
  761.             build_ctng "ypr0" "alsalib.tar.gz" "arm" "linux-gnueabi"
  762.             ;;
  763.         [Xx])
  764.             # IMPORTANT NOTE
  765.             # This toolchain must support several targets and thus must support
  766.             # the oldest possible configuration.
  767.             #
  768.             # Samsung YP-R0/R1:
  769.             #  ARM1176JZF-S, softfp EABI
  770.             #   gcc: 4.9.4 is the latest 4.9.x stable branch, also the only one that
  771.             #        compiles with GCC >6
  772.             #   kernel: 2.6.27.59 is the same 2.6.x stable kernel as used by the
  773.             #           original ct-ng toolchain, the device runs kernel 2.6.24
  774.             #   glibc: 2.19 is the latest version that supports kernel 2.6.24 which
  775.             #          is used on the device, but we need to support ABI 2.4 because
  776.             #          the device uses glibc 2.4.2
  777.             #
  778.             # Sony NWZ:
  779.             #   gcc: 4.9.4 is the latest 4.9.x stable branch, also the only one that
  780.             #        compiles with GCC >6
  781.             #   kernel: 2.6.32.68 is the latest 2.6.x stable kernel, the device
  782.             #           runs kernel 2.6.23 or 2.6.35 or 3.x for the most recent
  783.             #   glibc: 2.19 is the latest version that supports kernel 2.6.23 which
  784.             #          is used on many Sony players, but we need to support ABI 2.7
  785.             #          because the device uses glibc 2.7
  786.             #
  787.             # Thus the lowest common denominator is to use the latest 2.6.x stable
  788.             # kernel but compile glibc to support kernel 2.6.23 and glibc 2.4.
  789.             # We use a recent 2.26.1 binutils to avoid any build problems and
  790.             # avoid patches/bugs.
  791.             glibcopts="--enable-kernel=2.6.23 --enable-oldest-abi=2.4"
  792.             build_linux_toolchain "arm-rockbox-linux-gnueabi" "2.26.1" "" "4.9.4" \
  793.                 "$gccopts" "2.6.32.68" "2.19" "$glibcopts"
  794.             # build alsa-lib
  795.             # we need to set the prefix to how it is on device (/usr) and then
  796.             # tweak install dir at make install step
  797.             alsalib_ver="1.0.19"
  798.             gettool "alsa-lib" "$alsalib_ver"
  799.             extract "alsa-lib-$alsalib_ver"
  800.             prefix="/usr" buildtool "alsa-lib" "$alsalib_ver" \
  801.                 "--host=$target --disable-python" "" "install DESTDIR=$prefix/$target/sysroot"
  802.             ;;
  803.         [yy])
  804.             # IMPORTANT NOTE
  805.             # This toolchain must support several targets and thus must support
  806.             # the oldest possible configuration.
  807.             #
  808.             # AGPTek Rocker:
  809.             #   XBurst release 1 (something inbetween mips32r1 and mips32r2)
  810.             #   gcc: 4.9.4 is the latest 4.9.x stable branch, also the only one that
  811.             #        compiles with GCC >6
  812.             #   kernel: 3.10.14
  813.             #   glibc: 2.16
  814.             #
  815.             # To maximize compatibility, we use kernel 3.2.85 which is the lastest
  816.             # longterm 3.2 kernel and is supported by the latest glibc, and we
  817.             # require support for up to glibc 2.4
  818.             # We use a recent 2.26.1 binutils to avoid any build problems and
  819.             # avoid patches/bugs.
  820.             glibcopts="--enable-kernel=3.2 --enable-oldest-abi=2.4"
  821.             # FIXME: maybe add -mhard-float
  822.             build_linux_toolchain "mipsel-rockbox-linux-gnu" "2.26.1" "" "4.9.4" \
  823.                 "$gccopts" "3.2.85" "2.25" "$glibcopts"
  824.             # build alsa-lib
  825.             # we need to set the prefix to how it is on device (/usr) and then
  826.             # tweak install dir at make install step
  827.             alsalib_ver="1.0.19"
  828.             gettool "alsa-lib" "$alsalib_ver"
  829.             extract "alsa-lib-$alsalib_ver"
  830.             prefix="/usr" buildtool "alsa-lib" "$alsalib_ver" \
  831.                 "--host=$target --disable-python" "" "install DESTDIR=$prefix/$target/sysroot"
  832.             ;;
  833.         *)
  834.             echo "ROCKBOXDEV: Unsupported architecture option: $arch"
  835.             exit
  836.             ;;
  837.     esac
  838. done
  839.  
  840. echo ""
  841. echo "ROCKBOXDEV: Done!"
  842. echo ""
  843. echo "ROCKBOXDEV: Make sure your PATH includes $prefix/bin"
  844. echo ""
RAW Paste Data