diff --git a/tools/build_cros_gcc b/tools/build_cros_gcc index c04634a81..03711ccd8 100755 --- a/tools/build_cros_gcc +++ b/tools/build_cros_gcc @@ -1,178 +1,204 @@ #!/bin/bash + set -e + + # '\033[1;31m' outputs red text. '\033[0m' reverts it to normal. + command -v crew &>/dev/null || { echo -e "\033[1;31mcrew command not found.\033[0m"; exit 1; } + GLIBC=glibc-$(crew search glibc -v | tail -1 | cut -d' ' -f2 | cut -d'-' -f1) - BINUTILS=binutils-2.31.1 - GCC=gcc-8.2.0 - MPFR=mpfr-4.0.1 - GMP=gmp-6.1.2 - MPC=mpc-1.1.0 - ISL=isl-0.20 - CLOOG=cloog-0.18.4 + BINUTILS=binutils-$(crew search binutils -v | tail -1 | cut -d' ' -f2 | cut -d'-' -f1) + GCC=gcc-$(crew search gcc -v | tail -1 | cut -d' ' -f2 | cut -d'-' -f1) + MPFR=mpfr-$(crew search mpfr -v | tail -1 | cut -d' ' -f2 | cut -d'-' -f1) + GMP=gmp-$(crew search gmp -v | tail -1 | cut -d' ' -f2 | cut -d'-' -f1) + MPC=mpc-$(crew search mpc -v | tail -1 | cut -d' ' -f2 | cut -d'-' -f1) + ISL=isl-$(crew search isl -v | tail -1 | cut -d' ' -f2 | cut -d'-' -f1) - KERNEL_VERSION=$(crew search linuxheaders -v | tail -1 | cut -d' ' -f2 | cut -d'-' -f1).1 + KERNEL_VERSION=$(crew search linuxheaders -v | tail -1 | cut -d' ' -f2 | cut -d'-' -f1) - MAJOR_VERSION="$(echo $KERNEL_VERSION | cut -c1)" + MAJOR_VERSION="$(echo ${KERNEL_VERSION} | cut -c1)" - case $1 in - -h|--help) echo USAGE: - echo \ $0 target arch_type prefix - echo \ \-h, --help: Display this help - echo \ \-v, --version: Display version - echo \ \-t, --const: Display constants - echo \ \-c, --clean: Clean current directory - echo \ Valid targets: 'aarch64-cros-linux-gnu', 'x86_64-cros-linux-gnu', 'i686-cros-linux-gnu', 'armv7l-cros-linux-gnueabihf' - shift - exit 0;; - -v|--version) echo build_cros_gcc version 1.26 - shift - exit 0;; - -c|--clean) rm -rf build-binutils build-gcc build-glibc - rm -rf \ - ./$GCC \ - ./$CLOOG \ - ./$GMP \ - ./$GLIBC \ - ./$BINUTILS \ - ./$MPFR \ - ./$MPC \ - ./linux-$KERNEL_VERSION \ - ./$ISL \ - ./$GLIBC.tar.xz \ - ./$GMP.tar.xz \ - ./$GCC.tar.xz \ - ./$BINUTILS.tar.xz \ - ./linux-$KERNEL_VERSION.tar.xz \ - ./$MPFR.tar.xz \ - ./$CLOOG.tar.gz \ - ./$ISL.tar.bz2 \ - ./$MPC.tar.gz || true - shift - exit 0;; - -t|--const) - echo KERNEL_VERSION=$KERNEL_VERSION - echo MAJOR_VERSION=$MAJOR_VERSION - echo CLOOG=$CLOOG - echo ISL=$ISL - echo MPC=$MPC - echo GMP=$GMP - echo MPFR=$MPFR - echo GCC=$GCC - echo BINUTILS=$BINUTILS - echo GLIBC=$GLIBC - shift - exit 0;; - armv7l-cros-linux-gnueabihf) - true;; - aarch64-cros-linux-gnu) - true;; - i686-cros-linux-gnu) - true;; - x86_64-cros-linux-gnu) - true;; - *) - echo Invalid target or option \'$1\' - $0 -h - exit 1;; + case x${1}x in + x-hx|x--helpx) echo Usage: + echo \ $0 target [jobs] [prefix] + echo \ \-h, --help: Display this help + echo \ \-v, --version: Display version + echo \ \-t, --const: Display constants + echo \ \-c, --clean: Clean current directory + echo \ Valid targets: 'aarch64-cros-linux-gnu', 'x86_64-cros-linux-gnu', 'i686-cros-linux-gnu', 'armv7l-cros-linux-gnueabihf' + exit 0;; + x-vx|x--versionx) echo build_cros_gcc version 1.27.1 + exit 0;; + x-cx|x--cleanx) rm -rf build-binutils build-gcc build-glibc + rm -rf \ + ./${GCC} \ + ./${GMP} \ + ./${GLIBC} \ + ./${BINUTILS} \ + ./${MPFR} \ + ./${MPC} \ + ./linux-${KERNEL_VERSION} \ + ./${ISL} \ + ./${GLIBC}.tar.xz \ + ./${GMP}.tar.xz \ + ./${GCC}.tar.xz \ + ./${BINUTILS}.tar.xz \ + ./linux-${KERNEL_VERSION}.tar.xz \ + ./${MPFR}.tar.xz \ + ./${ISL}.tar.bz2 \ + ./${MPC}.tar.gz \ + ./sha256sum || true + exit 0;; + x-tx|x--constx) + echo KERNEL_VERSION=${KERNEL_VERSION} + echo MAJOR_VERSION=${MAJOR_VERSION} + echo ISL=${ISL} + echo MPC=${MPC} + echo GMP=${GMP} + echo MPFR=${MPFR} + echo GCC=${GCC} + echo BINUTILS=${BINUTILS} + echo GLIBC=${GLIBC} + exit 0;; + xarmv7l-cros-linux-gnueabihfx) + true;; + xaarch64-cros-linux-gnux) + true;; + xi686-cros-linux-gnux) + true;; + xx86_64-cros-linux-gnux) + true;; + xx) + $0 -h + exit 1;; + x*x) + echo -e "\033[1;31mInvalid target or option '$1'\033[0m" + $0 -h + exit 1;; esac - # '\033[1;31' outputs red text. '\033[0m' reverts it to normal. - command -v crew > /dev/null || { echo "\033[1;31mcrew command not found.\033[0m"; exit 1; } + TARGET="$1" && shift - if test ! $2; then - echo "$1" | grep x86_64 1>/dev/null - if [ $? == 0 ]; then - $0 $1 x86 $3; - exit 0; - fi - echo "$1" | grep i686 1>/dev/null - if [ $? == 0 ]; then - $0 $1 x86 $3; - exit 0; - fi - echo "$1" | grep armv7l 1>/dev/null - if [ $? == 0 ]; then - $0 $1 arm $3; - exit 0; - fi - echo "$1" | grep aarch64 1>/dev/null - if [ $? == 0 ]; then - $0 $1 arm64 $3; - exit 0; + if ! [[ "$1" =~ "^[0-9]+$" ]] &>/dev/null; then + JOBS="$1" + shift + else + shift + fi + if [[ -d $1 ]] &>/dev/null; then + PREFIX="$1" + shift + else + if ! [[ "$1" =~ "^[0-9]+$" ]] &>/dev/null; then + JOBS="$1" + shift + else + PREFIX="$1" + shift fi fi - if test ! $3; then - $0 $1 $2 $(crew const CREW_PREFIX | cut -d'=' -f2) - exit 0 + if [[ -z "${ARCH}" ]]; then + if { echo "${TARGET}" | grep x86_64 1>/dev/null; }; then + ARCH="x86_64"; + fi + if { echo "${TARGET}" | grep i686 1>/dev/null; }; then + ARCH="x86"; + fi + if { echo "${TARGET}" | grep armv7l 1>/dev/null; }; then + ARCH="arm"; + fi + if { echo "${TARGET}" | grep aarch64 1>/dev/null; }; then + ARCH="arm64"; + fi + fi + if [[ -z "${PREFIX}" ]]; then + PREFIX="$(crew const CREW_PREFIX | cut -d'=' -f2)" + fi + if [[ -z "${JOBS}" ]]; then + JOBS="$(nproc --all)" fi - $0 -c + rm -rf \ + ./${GLIBC} \ + ./${GMP} \ + ./${GCC} \ + ./${BINUTILS} \ + ./linux-${KERNEL_VERSION} \ + ./${MPFR} \ + ./${ISL} \ + ./${MPC} \ + ./sha256sum - echo $1 $2 $3 + wget -c https://ftpmirror.gnu.org/gnu/binutils/${BINUTILS}.tar.xz + wget -c https://ftpmirror.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.xz + wget -c https://www.kernel.org/pub/linux/kernel/v"${MAJOR_VERSION}".x/linux-${KERNEL_VERSION}.tar.xz + wget -c https://ftpmirror.gnu.org/gnu/libc/${GLIBC}.tar.xz + wget -c https://ftpmirror.gnu.org/gnu/mpfr/${MPFR}.tar.xz + wget -c https://ftpmirror.gnu.org/gnu/gmp/${GMP}.tar.xz + wget -c https://ftpmirror.gnu.org/gnu/mpc/${MPC}.tar.gz + wget -c http://isl.gforge.inria.fr/${ISL}.tar.bz2 - wget https://ftpmirror.gnu.org/gnu/binutils/$BINUTILS.tar.xz - wget https://ftpmirror.gnu.org/gnu/gcc/$GCC/$GCC.tar.xz - wget https://www.kernel.org/pub/linux/kernel/v"$MAJOR_VERSION".x/linux-$KERNEL_VERSION.tar.xz - wget https://ftpmirror.gnu.org/gnu/libc/$GLIBC.tar.xz - wget https://ftpmirror.gnu.org/gnu/mpfr/$MPFR.tar.xz - wget https://ftpmirror.gnu.org/gnu/gmp/$GMP.tar.xz - wget https://ftpmirror.gnu.org/gnu/mpc/$MPC.tar.gz - wget http://isl.gforge.inria.fr/$ISL.tar.bz2 - wget https://www.bastoul.net/cloog/pages/download/$CLOOG.tar.gz + SUMS="5d20086ecf5752cc7d9134246e9588fa201740d540f7eb84d795b1f7a93bca86 $BINUTILS.tar.xz\n" + SUMS+="832ca6ae04636adbb430e865a1451adf6979ab44ca1c8374f61fba65645ce15c $GCC.tar.xz\n" + SUMS+="94efeb00e4603c8546209cefb3e1a50a5315c86fa9b078b6fad758e187ce13e9 $GLIBC.tar.xz\n" + SUMS+="87b565e89a9a684fe4ebeeddb8399dce2599f9c9049854ca8c0dfbdea0e21912 $GMP.tar.xz\n" + SUMS+="b587e083eb65a8b394e833dea1744f21af3f0e413a448c17536b5549ae42a4c2 $ISL.tar.bz2\n" + SUMS+="becc413cc9e6d7f5cc52a3ce66d65c3725bc1d1cc1001f4ce6c32b69eb188cbd linux-$KERNEL_VERSION.tar.xz\n" + SUMS+="6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e $MPC.tar.gz\n" + SUMS+="67874a60826303ee2fb6affc6dc0ddd3e749e9bfcb4c8655e3953d0458a6e16e $MPFR.tar.xz" + echo -e "${SUMS}" > sha256sum - for tar in *.tar*; do tar xpf $tar; done + if ! { shasum -a 256 -c sha256sum; }; then + echo -e "\033[1;31mChecksum mismatch. Please try again. :/ \033[0m"; + exit 1; + fi - rm -f \ - ./$GLIBC.tar.xz \ - ./$GMP.tar.xz \ - ./$GCC.tar.xz \ - ./$BINUTILS.tar.xz \ - ./linux-$KERNEL_VERSION.tar.xz \ - ./$MPFR.tar.xz \ - ./$CLOOG.tar.gz \ - ./$ISL.tar.bz2 \ - ./$MPC.tar.gz + for tar in *.tar.*; do echo "Extracting ${tar}..." && tar xpf ${tar}; done - cd $GCC - ln -s ../$CLOOG cloog - ln -s ../$ISL isl - ln -s ../$MPC mpc - ln -s ../$GMP gmp - ln -s ../$MPFR mpfr + cd ${GCC} + GCC_PATCHES="gcc-8.2.0-isl-0.20.patch" + for PATCH in ${GCC_PATCHES}; do + wget https://github.com/JL2210/patches/raw/master/${PATCH} + patch -Np1 -i ${PATCH} + done + ln -s ../${ISL} isl + ln -s ../${MPC} mpc + ln -s ../${GMP} gmp + ln -s ../${MPFR} mpfr cd .. mkdir build-binutils || true cd build-binutils - ../$BINUTILS/configure --prefix=$3 --target=$1 --disable-multilib - make -j$(nproc) + ../${BINUTILS}/configure --prefix=${PREFIX} --target=${TARGET} --disable-multilib + make -j${JOBS} make install cd .. - cd linux-$KERNEL_VERSION - make ARCH=$2 INSTALL_HDR_PATH=$3/$1 headers_install + cd linux-${KERNEL_VERSION} + make ARCH=${ARCH} INSTALL_HDR_PATH=${PREFIX}/${TARGET} headers_install cd .. mkdir build-gcc || true cd build-gcc - ../$GCC/configure --disable-libmpx --prefix=$3 --target=$1 --enable-shared --enable-host-shared --enable-languages=c,c++,fortran,go --disable-multilib - make -j$(nproc) all-gcc + ../${GCC}/configure --prefix=${PREFIX} --target=${TARGET} --enable-shared --enable-host-shared --enable-languages=c,c++,fortran,go --disable-multilib --disable-libmpx + make -j${JOBS} all-gcc make install-gcc cd .. mkdir build-glibc || true cd build-glibc - ../$GLIBC/configure --disable-libmpx --prefix=$3/$1 --enable-shared --enable-host-shared --build=$MACHTYPE --host=$1 --target=$1 --with-headers=$3/$1/include --disable-multilib libc_cv_forced_unwind=yes + ../${GLIBC}/configure --prefix=${PREFIX}/${TARGET} --enable-shared --enable-host-shared --build=${MACHTYPE} --host=${TARGET} --target=${TARGET} --with-headers=${PREFIX}/${TARGET}/include --disable-multilib --disable-werror libc_cv_forced_unwind=yes make install-bootstrap-headers=yes install-headers - make -j$(nproc) csu/subdir_lib - install csu/crt1.o csu/crti.o csu/crtn.o $3/$1/lib - $1-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $3/$1/lib/libc.so - touch $3/$1/include/gnu/stubs.h + make -j${JOBS} csu/subdir_lib + install csu/crt1.o csu/crti.o csu/crtn.o ${PREFIX}/${TARGET}/lib/ + ${TARGET}-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o ${PREFIX}/${TARGET}/lib/libc.so + touch ${PREFIX}/${TARGET}/include/gnu/stubs.h cd .. cd build-gcc - make -j$(nproc) all-target-libgcc + make -j${JOBS} all-target-libgcc make install-target-libgcc cd .. cd build-glibc - make -j$(nproc) + make -j${JOBS} make install cd .. cd build-gcc - make -j$(nproc) + make -j${JOBS} make install cd .. - $1-gcc -v + ${TARGET}-gcc -v