Guest User

Rockboxdev.sh

a guest
Oct 13th, 2019
183
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" "https://gcc.gnu.org/pub/gcc/infrastructure/"
  408.  
  409.             tar xzf $dlwhere/mpc-0.8.1.tar.gz
  410.             ln -s mpc-0.8.1 mpc
  411.         fi
  412.         cd $builddir
  413.     fi
  414.  
  415.     echo "ROCKBOXDEV: mkdir build-$toolname"
  416.     mkdir build-$toolname
  417.  
  418.     echo "ROCKBOXDEV: cd build-$toolname"
  419.     cd build-$toolname
  420.  
  421.     echo "ROCKBOXDEV: logging to $logfile"
  422.     rm -f "$logfile"
  423.  
  424.     echo "ROCKBOXDEV: $toolname/configure"
  425.     case $toolname in
  426.         crosstool-ng) # ct-ng doesnt support out-of-tree build and the src folder is named differently
  427.             toolname="crosstool-ng"
  428.             cp -r ../$toolname-$version/* ../$toolname-$version/.version .
  429.             ./configure --prefix=$prefix $configure_params
  430.         ;;
  431.         *)
  432.             CFLAGS='-U_FORTIFY_SOURCE -fgnu89-inline'
  433.             run_cmd "$logfile" ../$toolname-$version/configure --target=$target --prefix=$prefix --enable-languages=c --disable-libssp --disable-docs $configure_params
  434.         ;;
  435.     esac
  436.  
  437.     echo "ROCKBOXDEV: $toolname/make"
  438.     run_cmd "$logfile" $make -i
  439.  
  440.     echo "ROCKBOXDEV: $toolname/make install"
  441.     run_cmd "$logfile" $make install -i
  442.  
  443.     echo "ROCKBOXDEV: rm -rf build-$toolname $toolname-$version"
  444.     cd ..
  445.     rm -rf build-$toolname $toolname-$version
  446. }
  447.  
  448. make_ctng() {
  449.     if test -f "`which ct-ng 2>/dev/null`"; then
  450.         ctng="ct-ng"
  451.     else
  452.         ctng=""
  453.     fi
  454.  
  455.     if test ! -n "$ctng"; then
  456.         if test ! -f "$prefix/bin/ct-ng"; then # look if we build it already
  457.             build "crosstool-ng" "" "1.13.2" "crosstool-ng-1.13.2.diff"
  458.         fi
  459.     fi
  460.     ctng=`PATH=$prefix/bin:$PATH which ct-ng`
  461. }
  462.  
  463. build_ctng() {
  464.     ctng_target="$1"
  465.     extra="$2"
  466.     tc_arch="$3"
  467.     tc_host="$4"
  468.  
  469.     make_ctng
  470.  
  471.     dlurl="http://www.rockbox.org/gcc/$ctng_target"
  472.  
  473.     # download
  474.     getfile "ct-ng-config" "$dlurl"
  475.  
  476.     test -n "$extra" && getfile "$extra" "$dlurl"
  477.    
  478.     # create build directory
  479.     if test -d $builddir; then
  480.         if test ! -w $builddir; then
  481.             echo "ROCKBOXDEV: No write permission for $builddir"
  482.             exit
  483.         fi
  484.     else
  485.         mkdir -p $builddir
  486.     fi
  487.  
  488.     # copy config and cd to $builddir
  489.     mkdir $builddir/build-$ctng_target
  490.     ctng_config="$builddir/build-$ctng_target/.config"
  491.     cat "$dlwhere/ct-ng-config" | sed -e "s,\(CT_PREFIX_DIR=\).*,\1$prefix," > $ctng_config
  492.     cd $builddir/build-$ctng_target
  493.  
  494.     $ctng "build"
  495.  
  496.     # install extras
  497.     if test -e "$dlwhere/$extra"; then
  498.         # verify the toolchain has sysroot support
  499.         if test -n `cat $ctng_config | grep CT_USE_SYSROOT\=y`; then
  500.             sysroot=`cat $ctng_config | grep CT_SYSROOT_NAME | sed -e 's,CT_SYSROOT_NAME\=\"\([a-zA-Z0-9]*\)\",\1,'`
  501.             tar xf "$dlwhere/$extra" -C "$prefix/$tc_arch-$ctng_target-$tc_host/$sysroot"
  502.         fi
  503.     fi
  504.    
  505.     # cleanup
  506.     cd $builddir
  507.     rm -rf $builddir/build-$ctng_target
  508. }
  509.  
  510. # build a cross compiler toolchain for linux
  511. # $1=target
  512. # $2=binutils version
  513. # $3=binutils configure extra options
  514. # $4=gcc version
  515. # $5=gcc configure extra options
  516. # $6=linux version
  517. # $7=glibc version
  518. # $8=glibc configure extra options
  519. build_linux_toolchain () {
  520.     target="$1"
  521.     binutils_ver="$2"
  522.     binutils_opts="$3"
  523.     gcc_ver="$4"
  524.     gcc_opts="$5"
  525.     linux_ver="$6"
  526.     glibc_ver="$7"
  527.     glibc_opts="$8"
  528.     # where to put the sysroot
  529.     sysroot="$prefix/$target/sysroot"
  530.     # extract arch from target
  531.     arch=${target%%-*}
  532.  
  533.     # check libraries:
  534.     # contrary to other toolchains that rely on a hack to avoid installing
  535.     # gmp, mpc and mpfr, we simply require that they are installed on the system
  536.     # this is not a huge requirement since virtually all systems these days
  537.     # provide dev packages for them
  538.     # FIXME: maybe add an option to download and install them automatically
  539.     checklib "mpc" "gmp" "mpfr"
  540.  
  541.     # create build directory
  542.     if test -d $builddir; then
  543.         if test ! -w $builddir; then
  544.             echo "ROCKBOXDEV: No write permission for $builddir"
  545.             exit
  546.         fi
  547.     else
  548.         mkdir -p $builddir
  549.     fi
  550.  
  551.     # download all tools
  552.     gettool "binutils" "$binutils_ver"
  553.     gettool "gcc" "$gcc_ver"
  554.     gettool "linux" "$linux_ver"
  555.     gettool "glibc" "$glibc_ver"
  556.  
  557.     # extract them
  558.     cd $builddir
  559.     extract "binutils-$binutils_ver"
  560.     extract "gcc-$gcc_ver"
  561.     extract "linux-$linux_ver"
  562.     extract "glibc-$glibc_ver"
  563.  
  564.     # we make it possible to restart a build on error by using the RESTART
  565.     # variable, the format is RESTART="tool" where tool is the toolname at which
  566.     # to restart (binutils, gcc)
  567.  
  568.     # install binutils, with support for sysroot
  569.     buildtool "binutils" "$binutils_ver" "--target=$target --disable-werror \
  570.        --with-sysroot=$sysroot --disable-nls" "" ""
  571.     # build stage 1 compiler: disable headers, disable threading so that
  572.     # pthread headers are not included, pretend we use newlib so that libgcc
  573.     # doesn't get linked at the end
  574.     # NOTE there is some magic involved here
  575.     RESTART_STEP="gcc-stage1" \
  576.     buildtool "gcc" "$gcc_ver" "$gcc_opts --enable-languages=c --target=$target \
  577.        --without-headers --disable-threads --disable-libgomp --disable-libmudflap \
  578.        --disable-libssp --disable-libquadmath --disable-libquadmath-support \
  579.        --disable-shared --with-newlib --disable-libitm \
  580.        --disable-libsanitizer --disable-libatomic" "" ""
  581.     # install linux headers
  582.     # NOTE: we need to tell make where to put the build files, since buildtool
  583.     # switches to the builddir, "." will be the correct builddir when ran
  584.     if [ "$arch" == "mipsel" ]; then
  585.         arch="mips"
  586.     fi
  587.     linux_opts="O=. ARCH=$arch INSTALL_HDR_PATH=$sysroot/usr/"
  588.     RESTART_STEP="linux-headers" \
  589.     buildtool "linux" "$linux_ver" "NO_CONFIGURE" \
  590.         "$linux_opts headers_install" "$linux_opts headers_check"
  591.     # build glibc using the first stage cross compiler
  592.     # we need to set the prefix to /usr because the glibc runs on the actual
  593.     # target and is indeed installed in /usr
  594.     prefix="/usr" \
  595.     buildtool "glibc" "$glibc_ver" "--target=$target --host=$target --build=$MACHTYPE \
  596.        --with-__thread --with-headers=$sysroot/usr/include $glibc_opts" \
  597.         "" "install install_root=$sysroot"
  598.     # build stage 2 compiler
  599.     buildtool "gcc" "$gcc_ver" "$gcc_opts --enable-languages=c,c++ --target=$target \
  600.        --with-sysroot=$sysroot" "" ""
  601. }
  602.  
  603. usage () {
  604.     echo "usage: rockboxdev.sh [options]"
  605.     echo "options:"
  606.     echo "  --help              Display this help"
  607.     echo "  --target=LIST       List of targets to build"
  608.     echo "  --restart=STEP      Restart build at given STEP (same as RESTART env var)"
  609.     echo "  --prefix=PREFIX     Set install prefix (same as RBDEV_PREFIX env var)"
  610.     echo "  --dlwhere=DIR       Set download directory (same as RBDEV_DOWNLOAD env var)"
  611.     echo "  --builddir=DIR      Set build directory (same as RBDEV_BUILD env var)"
  612.     echo "  --makeflags=FLAGS   Set make flags (same as MAKEFLAGS env var)"
  613.     exit 1
  614. }
  615.  
  616. ##############################################################################
  617. # Code:
  618.  
  619. # Parse arguments
  620. for i in "$@"
  621. do
  622. case $i in
  623.     --help)
  624.         usage
  625.         ;;
  626.     --prefix=*)
  627.         prefix="${i#*=}"
  628.         shift
  629.         ;;
  630.     --target=*)
  631.         RBDEV_TARGET="${i#*=}"
  632.         shift
  633.         ;;
  634.     --restart=*)
  635.         RBDEV_RESTART="${i#*=}"
  636.         shift
  637.         ;;
  638.     --dlwhere=*)
  639.         dlwhere="${i#*=}"
  640.         shift
  641.         ;;
  642.     --builddir=*)
  643.         builddir="${i#*=}"
  644.         shift
  645.         ;;
  646.     --makeflags=*)
  647.         export MAKEFLAGS="${i#*=}" # export so it's available in make
  648.         shift
  649.         ;;
  650.     *)
  651.         echo "Unknown option '$i'"
  652.         exit 1
  653.         ;;
  654. esac
  655. done
  656.  
  657. # Verify required tools and libraries
  658. for t in $reqtools; do
  659.     tool=`findtool $t`
  660.     if test -z "$tool"; then
  661.         echo "ROCKBOXDEV: \"$t\" is required for this script to work."
  662.         missingtools="yes"
  663.     fi
  664. done
  665. if [ -n "$missingtools" ]; then
  666.     echo "ROCKBOXDEV: Please install the missing tools and re-run the script."
  667.     exit 1
  668. fi
  669.  
  670. echo "Download directory : $dlwhere (set RBDEV_DOWNLOAD or use --download= to change)"
  671. echo "Install prefix     : $prefix  (set RBDEV_PREFIX or use --prefix= to change)"
  672. echo "Build dir          : $builddir (set RBDEV_BUILD or use --builddir= to change)"
  673. echo "Make options       : $MAKEFLAGS (set MAKEFLAGS or use --makeflags= to change)"
  674. echo "Restart step       : $RBDEV_RESTART (set RBDEV_RESTART or use --restart= to change)"
  675. echo "Target arch        : $RBDEV_TARGET (set RBDEV_TARGET or use --target to change)"
  676.  
  677. # Verify download directory
  678. if test -d "$dlwhere"; then
  679.   if ! test -w "$dlwhere"; then
  680.     echo "ROCKBOXDEV: No write permission for $dlwhere"
  681.     exit
  682.   fi
  683. else
  684.   mkdir $dlwhere
  685.   if test $? -ne 0; then
  686.     echo "ROCKBOXDEV: Failed creating directory $dlwhere"
  687.     exit
  688.   fi
  689. fi
  690.  
  691.  
  692. # Verify the prefix dir
  693. if test ! -d $prefix; then
  694.   mkdir -p $prefix
  695.   if test $? -ne 0; then
  696.       echo "ROCKBOXDEV: Failed creating directory $prefix"
  697.       exit
  698.   fi
  699. fi
  700. if test ! -w $prefix; then
  701.   echo "ROCKBOXDEV: No write permission for $prefix"
  702.   exit
  703. fi
  704.  
  705. if [ -z "$RBDEV_TARGET" ]; then
  706.     echo "Select target arch:"
  707.     echo "s   - sh       (Archos models)"
  708.     echo "m   - m68k     (iriver h1x0/h3x0, iaudio m3/m5/x5 and mpio hd200)"
  709.     echo "a   - arm      (ipods, iriver H10, Sansa, D2, Gigabeat, etc)"
  710.     echo "i   - mips     (Jz47xx and ATJ-based players)"
  711.     echo "r   - arm-app  (Samsung ypr0)"
  712.     echo "x   - arm-linux  (Generic Linux ARM: Samsung ypr0, Linux-based Sony NWZ)"
  713.     echo "y   - mips-linux  (Generic Linux MIPS: AGPTek Rocker)"
  714.     echo "separate multiple targets with spaces"
  715.     echo "(Example: \"s m a\" will build sh, m68k and arm)"
  716.     echo ""
  717.     selarch=`input`
  718. else
  719.     selarch=$RBDEV_TARGET
  720. fi
  721. system=`uname -s`
  722.  
  723. # add target dir to path to ensure the new binutils are used in gcc build
  724. PATH="$prefix/bin:${PATH}"
  725.  
  726. for arch in $selarch
  727. do
  728.     echo ""
  729.     case $arch in
  730.         [Ss])
  731.             # For binutils 2.16.1 builtin rules conflict on some systems with a
  732.             # default rule for Objective C. Disable the builtin make rules. See
  733.             # http://sourceware.org/ml/binutils/2005-12/msg00259.html
  734.             export MAKEFLAGS="-r $MAKEFLAGS"
  735.             build "binutils" "sh-elf" "2.16.1" "binutils-2.16.1-texinfo-fix.diff" "--disable-werror"
  736.             build "gcc" "sh-elf" "4.0.3" "gcc-4.0.3-rockbox-1.diff"
  737.             ;;
  738.  
  739.         [Ii])
  740.             build "binutils" "mipsel-elf" "2.26.1" "" "--disable-werror"
  741.             build "gcc" "mipsel-elf" "4.9.4" "" "" "gmp mpfr mpc"
  742.             ;;
  743.  
  744.         [Mm])
  745.             build "binutils" "m68k-elf" "2.20.1" "binutils-2.20.1-texinfo-fix.diff" "--disable-werror"
  746.             build "gcc" "m68k-elf" "4.5.2" "" "--with-arch=cf MAKEINFO=missing" "gmp mpfr mpc"
  747.             ;;
  748.  
  749.         [Aa])
  750.             binopts=""
  751.             gccopts=""
  752.             case $system in
  753.                 Darwin)
  754.                     binopts="--disable-nls"
  755.                     gccopts="--disable-nls"
  756.                     ;;
  757.             esac
  758.             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"
  759.             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"
  760.             ;;
  761.         [Rr])
  762.             build_ctng "ypr0" "alsalib.tar.gz" "arm" "linux-gnueabi"
  763.             ;;
  764.         [Xx])
  765.             # IMPORTANT NOTE
  766.             # This toolchain must support several targets and thus must support
  767.             # the oldest possible configuration.
  768.             #
  769.             # Samsung YP-R0/R1:
  770.             #  ARM1176JZF-S, softfp EABI
  771.             #   gcc: 4.9.4 is the latest 4.9.x stable branch, also the only one that
  772.             #        compiles with GCC >6
  773.             #   kernel: 2.6.27.59 is the same 2.6.x stable kernel as used by the
  774.             #           original ct-ng toolchain, the device runs kernel 2.6.24
  775.             #   glibc: 2.19 is the latest version that supports kernel 2.6.24 which
  776.             #          is used on the device, but we need to support ABI 2.4 because
  777.             #          the device uses glibc 2.4.2
  778.             #
  779.             # Sony NWZ:
  780.             #   gcc: 4.9.4 is the latest 4.9.x stable branch, also the only one that
  781.             #        compiles with GCC >6
  782.             #   kernel: 2.6.32.68 is the latest 2.6.x stable kernel, the device
  783.             #           runs kernel 2.6.23 or 2.6.35 or 3.x for the most recent
  784.             #   glibc: 2.19 is the latest version that supports kernel 2.6.23 which
  785.             #          is used on many Sony players, but we need to support ABI 2.7
  786.             #          because the device uses glibc 2.7
  787.             #
  788.             # Thus the lowest common denominator is to use the latest 2.6.x stable
  789.             # kernel but compile glibc to support kernel 2.6.23 and glibc 2.4.
  790.             # We use a recent 2.26.1 binutils to avoid any build problems and
  791.             # avoid patches/bugs.
  792.             glibcopts="--enable-kernel=2.6.23 --enable-oldest-abi=2.4"
  793.             build_linux_toolchain "arm-rockbox-linux-gnueabi" "2.26.1" "" "4.9.4" \
  794.                 "$gccopts" "2.6.32.68" "2.19" "$glibcopts"
  795.             # build alsa-lib
  796.             # we need to set the prefix to how it is on device (/usr) and then
  797.             # tweak install dir at make install step
  798.             alsalib_ver="1.0.19"
  799.             gettool "alsa-lib" "$alsalib_ver"
  800.             extract "alsa-lib-$alsalib_ver"
  801.             prefix="/usr" buildtool "alsa-lib" "$alsalib_ver" \
  802.                 "--host=$target --disable-python" "" "install DESTDIR=$prefix/$target/sysroot"
  803.             ;;
  804.         [yy])
  805.             # IMPORTANT NOTE
  806.             # This toolchain must support several targets and thus must support
  807.             # the oldest possible configuration.
  808.             #
  809.             # AGPTek Rocker:
  810.             #   XBurst release 1 (something inbetween mips32r1 and mips32r2)
  811.             #   gcc: 4.9.4 is the latest 4.9.x stable branch, also the only one that
  812.             #        compiles with GCC >6
  813.             #   kernel: 3.10.14
  814.             #   glibc: 2.16
  815.             #
  816.             # To maximize compatibility, we use kernel 3.2.85 which is the lastest
  817.             # longterm 3.2 kernel and is supported by the latest glibc, and we
  818.             # require support for up to glibc 2.4
  819.             # We use a recent 2.26.1 binutils to avoid any build problems and
  820.             # avoid patches/bugs.
  821.             glibcopts="--enable-kernel=3.2 --enable-oldest-abi=2.4"
  822.             # FIXME: maybe add -mhard-float
  823.             build_linux_toolchain "mipsel-rockbox-linux-gnu" "2.26.1" "" "4.9.4" \
  824.                 "$gccopts" "3.2.85" "2.25" "$glibcopts"
  825.             # build alsa-lib
  826.             # we need to set the prefix to how it is on device (/usr) and then
  827.             # tweak install dir at make install step
  828.             alsalib_ver="1.0.19"
  829.             gettool "alsa-lib" "$alsalib_ver"
  830.             extract "alsa-lib-$alsalib_ver"
  831.             prefix="/usr" buildtool "alsa-lib" "$alsalib_ver" \
  832.                 "--host=$target --disable-python" "" "install DESTDIR=$prefix/$target/sysroot"
  833.             ;;
  834.         *)
  835.             echo "ROCKBOXDEV: Unsupported architecture option: $arch"
  836.             exit
  837.             ;;
  838.     esac
  839. done
  840.  
  841. echo ""
  842. echo "ROCKBOXDEV: Done!"
  843. echo ""
  844. echo "ROCKBOXDEV: Make sure your PATH includes $prefix/bin"
  845. echo ""
RAW Paste Data