jmenashe

cross toolchain

Dec 29th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.45 KB | None | 0 0
  1. #! /bin/bash
  2. set -e
  3. trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
  4. trap 'echo FAILED COMMAND: $previous_command' EXIT
  5.  
  6. #-------------------------------------------------------------------------------------------
  7. # This script will download packages for, configure, build and install a GCC cross-compiler.
  8. # Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running.
  9. # If you get an error and need to resume the script from some point in the middle,
  10. # just delete/comment the preceding lines before running it again.
  11. #
  12. # See: http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler
  13. #-------------------------------------------------------------------------------------------
  14.  
  15. INSTALL_PATH=$HOME/build_cross_gcc/install
  16. TARGET=i686-linux-gnu
  17. USE_NEWLIB=0
  18. LINUX_ARCH=x86
  19. CONFIGURATION_OPTIONS="--disable-multilib" # --disable-threads --disable-shared
  20. PARALLEL_MAKE=-j8
  21. BINUTILS_VERSION=binutils-2.25.1
  22. GCC_VERSION=gcc-5.3.0
  23. LINUX_KERNEL_VERSION=linux-2.6.33
  24. GLIBC_VERSION=glibc-2.22
  25. MPFR_VERSION=mpfr-3.1.3
  26. GMP_VERSION=gmp-6.1.0
  27. MPC_VERSION=mpc-1.0.2
  28. ISL_VERSION=isl-0.12.2
  29. CLOOG_VERSION=cloog-0.18.1
  30. export PATH=$INSTALL_PATH/bin:$PATH
  31.  
  32. mkdir -p $INSTALL_PATH
  33.  
  34. # Download packages
  35. export http_proxy=$HTTP_PROXY https_proxy=$HTTP_PROXY ftp_proxy=$HTTP_PROXY
  36. wget -nc https://ftp.gnu.org/gnu/binutils/$BINUTILS_VERSION.tar.gz
  37. wget -nc https://ftp.gnu.org/gnu/gcc/$GCC_VERSION/$GCC_VERSION.tar.gz
  38. if [ $USE_NEWLIB -ne 0 ]; then
  39.     wget -nc -O newlib-master.zip https://github.com/bminor/newlib/archive/master.zip || true
  40.     unzip -qo newlib-master.zip
  41. else
  42.     #wget -nc https://www.kernel.org/pub/linux/kernel/v2.6/$LINUX_KERNEL_VERSION.tar.xz
  43.     wget -nc https://www.kernel.org/pub/linux/kernel/v3.x/$LINUX_KERNEL_VERSION.tar.xz
  44.     wget -nc https://ftp.gnu.org/gnu/glibc/$GLIBC_VERSION.tar.xz
  45. fi
  46. wget -nc https://ftp.gnu.org/gnu/mpfr/$MPFR_VERSION.tar.xz
  47. wget -nc https://ftp.gnu.org/gnu/gmp/$GMP_VERSION.tar.xz
  48. wget -nc https://ftp.gnu.org/gnu/mpc/$MPC_VERSION.tar.gz
  49. wget -nc ftp://gcc.gnu.org/pub/gcc/infrastructure/$ISL_VERSION.tar.bz2
  50. wget -nc ftp://gcc.gnu.org/pub/gcc/infrastructure/$CLOOG_VERSION.tar.gz
  51.  
  52. # Extract everything
  53. for f in *.tar*; do tar --skip-old-files -xf $f; done
  54.  
  55. # Make symbolic links
  56. cd $GCC_VERSION
  57. ln -sf `ls -1d ../mpfr-*/` mpfr
  58. ln -sf `ls -1d ../gmp-*/` gmp
  59. ln -sf `ls -1d ../mpc-*/` mpc
  60. ln -sf `ls -1d ../isl-*/` isl
  61. ln -sf `ls -1d ../cloog-*/` cloog
  62. cd ..
  63.  
  64. # Step 1. Binutils
  65. mkdir -p build-binutils
  66. cd build-binutils
  67. ../$BINUTILS_VERSION/configure --prefix=$INSTALL_PATH --target=$TARGET $CONFIGURATION_OPTIONS
  68. make $PARALLEL_MAKE
  69. make install
  70. cd ..
  71.  
  72. # Step 2. Linux Kernel Headers
  73. if [ $USE_NEWLIB -eq 0 ]; then
  74.     cd $LINUX_KERNEL_VERSION
  75.     make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$INSTALL_PATH/$TARGET headers_install
  76.     cd ..
  77. fi
  78.  
  79. # Step 3. C/C++ Compilers
  80. mkdir -p build-gcc
  81. cd build-gcc
  82. if [ $USE_NEWLIB -ne 0 ]; then
  83.     NEWLIB_OPTION=--with-newlib
  84. fi
  85. ../$GCC_VERSION/configure --prefix=$INSTALL_PATH --target=$TARGET --enable-languages=c,c++ $CONFIGURATION_OPTIONS $NEWLIB_OPTION
  86. make $PARALLEL_MAKE all-gcc
  87. make install-gcc
  88. cd ..
  89.  
  90. if [ $USE_NEWLIB -ne 0 ]; then
  91.     # Steps 4-6: Newlib
  92.     mkdir -p build-newlib
  93.     cd build-newlib
  94.     ../newlib-master/configure --prefix=$INSTALL_PATH --target=$TARGET $CONFIGURATION_OPTIONS
  95.     make $PARALLEL_MAKE
  96.     make install
  97.     cd ..
  98. else
  99.     # Step 4. Standard C Library Headers and Startup Files
  100.     mkdir -p build-glibc
  101.     cd build-glibc
  102.     ../$GLIBC_VERSION/configure --prefix=$INSTALL_PATH/$TARGET --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-headers=$INSTALL_PATH/$TARGET/include $CONFIGURATION_OPTIONS libc_cv_forced_unwind=yes
  103.     make install-bootstrap-headers=yes install-headers
  104.     make $PARALLEL_MAKE csu/subdir_lib
  105.     install csu/crt1.o csu/crti.o csu/crtn.o $INSTALL_PATH/$TARGET/lib
  106.     $TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $INSTALL_PATH/$TARGET/lib/libc.so
  107.     touch $INSTALL_PATH/$TARGET/include/gnu/stubs.h
  108.     cd ..
  109.  
  110.     # Step 5. Compiler Support Library
  111.     cd build-gcc
  112.     make $PARALLEL_MAKE all-target-libgcc
  113.     make install-target-libgcc
  114.     cd ..
  115.  
  116.     # Step 6. Standard C Library & the rest of Glibc
  117.     cd build-glibc
  118.     make $PARALLEL_MAKE
  119.     make install
  120.     cd ..
  121. fi
  122.  
  123. # Step 7. Standard C++ Library & the rest of GCC
  124. cd build-gcc
  125. make $PARALLEL_MAKE all
  126. make install
  127. cd ..
  128.  
  129. trap - EXIT
  130. echo 'Success!'
Advertisement
Add Comment
Please, Sign In to add comment