Last active
January 18, 2024 05:51
-
-
Save xiangchu0/5555a3a1ec389cef6eaad2a836d217e8 to your computer and use it in GitHub Desktop.
gcc cross compile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh -ex | |
| # http://git.z3bra.org/cross/file/cross-gcc.html | |
| # Couple of useful links: | |
| # + http://wiki.osdev.org/GCC_Cross-Compiler | |
| # + http://wiki.osdev.org/Cross-Compiler_Successful_Builds | |
| # + https://git.framasoft.org/Ypnose/solyste/blob/master/scripts/create-crossenv | |
| # + http://kegel.com/crosstool/ | |
| # + https://github.com/GregorR/musl-cross/tree/master/patches | |
| # | |
| # 0. download gcc, binutils, gmp, mpc, mpfr | |
| # 1. extract them | |
| # 2. patch everything that require patching | |
| # 3. prepare gcc (move gmp, mpc, mpfr in) | |
| # 4. install linux headers | |
| # 5. build binutils | |
| # 6. build musl | |
| # 7. build gcc | |
| # 8. add pkg-config wrapper | |
| # cross compiler environment | |
| MARCH=$(uname -m) | |
| TARGET=${TARGET:-${MARCH}-linux-musl} | |
| PREFIX=${PREFIX:-/opt/cross} | |
| BLDDIR=${BLDDIR:-${PWD}/tmp/build} | |
| SRCDIR=${SRCDIR:-${PWD}/tmp/source} | |
| PATCHD=${PATCHD:-${PWD}/patches} | |
| # compilation variables | |
| CFLAGS="-Os -fomit-frame-pointer -pipe" | |
| CXXFLAGS="${CFLAGS}" | |
| CPPFLAGS="${CFLAGS}" | |
| LDFLAGS="-Wl,--as-needed" | |
| MAKEFLAGS="-j4" | |
| # versions | |
| GCCV=${GCCV:-5.3.0} | |
| BINV=${BINV:-2.25} | |
| GMPV=${GMPV:-5.1.3} | |
| MPCV=${MPCV:-1.0.3} | |
| MPFRV=${MPFRV:-3.1.3} | |
| MUSLV=${MUSLV:-1.1.12} | |
| KERNV=${KERNV:-4.1.13} | |
| # random but useful vars | |
| PATH="${PREFIX}/bin:${PATH}" | |
| GNUMIRROR=ftp://ftp.gnu.org/gnu | |
| MUSLMIRROR=http://www.musl-libc.org/releases | |
| LINUXMIRROR=https://www.kernel.org/pub/linux/kernel/v4.x | |
| # Preparing sources | |
| mkdir -p "${SRCDIR}" "${BLDDIR}" "${PREFIX}" | |
| cd "${SRCDIR}" | |
| # | |
| # ┏━┓ | |
| # ┃┃┃ | |
| # ┗━┛╹ | |
| # Get all GNU tarballs | |
| grab_sources() { | |
| curl -O -# "${GNUMIRROR}/gcc/gcc-${GCCV}/gcc-${GCCV}.tar.gz" | |
| curl -O -# "${GNUMIRROR}/binutils/binutils-${BINV}.tar.gz" | |
| curl -O -# "${GNUMIRROR}/mpc/mpc-${MPCV}.tar.gz" | |
| curl -O -# "${GNUMIRROR}/gmp/gmp-${GMPV}.tar.gz" | |
| curl -O -# "${GNUMIRROR}/mpfr/mpfr-${MPFRV}.tar.gz" | |
| curl -O -# "${MUSLMIRROR}/musl-${MUSLV}.tar.gz" | |
| curl -O -# "${LINUXMIRROR}/linux-${KERNV}.tar.xz" | |
| } | |
| # | |
| # ╺┓ | |
| # ┃ | |
| # ╺┻╸╹ | |
| # Extract everything | |
| extract_source() { | |
| tar xz < gcc-${GCCV}.tar.gz | |
| tar xz < binutils-${BINV}.tar.gz | |
| tar xz < mpc-${MPCV}.tar.gz | |
| tar xz < gmp-${GMPV}.tar.gz | |
| tar xz < mpfr-${MPFRV}.tar.gz | |
| tar xz < musl-${MUSLV}.tar.gz | |
| tar xJ < linux-${KERNV}.tar.xz | |
| } | |
| # | |
| # ┏━┓ | |
| # ┏━┛ | |
| # ┗━╸╹ | |
| # Patch all source trees. | |
| # This will take all patches in $PATCHD matching the programs | |
| # (eg: gcc-4.8.4-*.diff to patch gcc in version 4.8.4) | |
| patch_sources() { | |
| for DIR in $(find "${SRCDIR}" -maxdepth 1 -type d); do | |
| cd "${DIR}" | |
| cat "${PATCHD}/$(basename ${DIR})"-*.diff | patch -Np1 | |
| done | |
| } | |
| # | |
| # ┏━┓ | |
| # ╺━┫ | |
| # ┗━┛╹ | |
| # Prepare the gcc dir | |
| prepare_gcc() { | |
| mv "${SRCDIR}/gmp-${GMPV}" "${SRCDIR}/gcc-${GCCV}/gmp" | |
| mv "${SRCDIR}/mpc-${MPCV}" "${SRCDIR}/gcc-${GCCV}/mpc" | |
| mv "${SRCDIR}/mpfr-${MPFRV}" "${SRCDIR}/gcc-${GCCV}/mpfr" | |
| } | |
| # | |
| # ╻ ╻ | |
| # ┗━┫ | |
| # ╹╹ | |
| # Get linux headers | |
| install_headers() { | |
| cd "${SRCDIR}/linux-${KERNV}" | |
| make ARCH=$(uname -m) headers_check | |
| make ARCH=$(uname -m) INSTALL_HDR_PATH=${PREFIX}/${TARGET} headers_install | |
| rm -r "${SRCDIR}/linux-${KERNV}" | |
| } | |
| # | |
| # ┏━╸ | |
| # ┗━┓ | |
| # ┗━┛╹ | |
| # Build binutils and install them to ${PREFIX} | |
| install_binutils() { | |
| mkdir -p "${BLDDIR}/binutils" | |
| cd "${BLDDIR}/binutils" | |
| ${SRCDIR}/binutils-${BINV}/configure --target=${TARGET} \ | |
| --prefix=${PREFIX} \ | |
| --with-sysroot=${PREFIX}/${TARGET} \ | |
| --disable-nls \ | |
| --disable-shared \ | |
| --disable-multilib | |
| make configure-host | |
| make LDFLAGS="${LDFLAGS} -all-static -static" | |
| make install | |
| rm -rf "${BLDDIR}/binutils" | |
| rm -rf "${SRCDIR}/binutils-${BINV}" | |
| } | |
| # | |
| # ┏━┓ | |
| # ┣━┓ | |
| # ┗━┛╹ | |
| # Build the musl libc | |
| install_musl() { | |
| cd "${SRCDIR}/musl-${MUSLV}" | |
| ./configure --prefix=${PREFIX}/${TARGET} \ | |
| --target=${TARGET} \ | |
| --disable-gcc-wrapper \ | |
| --disable-debug \ | |
| --disable-shared \ | |
| --disable-warning | |
| make LDFLAGS="${LDFLAGS}" | |
| make install | |
| rm -rf "${SRCDIR}/musl-${MUSLV}" | |
| } | |
| # | |
| # ┏━┓ | |
| # ┃ | |
| # ╹╹ | |
| # Build gcc linked against musl | |
| install_gcc() { | |
| mkdir -p "${BLDDIR}/gcc" | |
| cd "${BLDDIR}/gcc" | |
| ${SRCDIR}/gcc-${GCCV}/configure --target=${TARGET} \ | |
| --prefix=${PREFIX} \ | |
| --with-sysroot=${PREFIX}/${TARGET} \ | |
| --with-native-system-header-dir=/include \ | |
| --disable-nls \ | |
| --disable-shared \ | |
| --disable-multilib \ | |
| --disable-libmudflap \ | |
| --enable-threads=posix \ | |
| --enable-languages=c | |
| make LDFLAGS="${LDFLAGS} -static" all-gcc all-target-libgcc | |
| make install-gcc install-target-libgcc | |
| rm -rf "${BLDDIR}/gcc" | |
| rm -rf "${SRCDIR}/gcc-${GCCV}" | |
| } | |
| # | |
| # ┏━┓ | |
| # ┣━┫ | |
| # ┗━┛╹ | |
| # Add pkg-config wrapper | |
| install_pkgconfig() { | |
| cat << EOF > "${PREFIX}/bin/${TARGET}-pkg-config" | |
| #!/bin/sh | |
| export PKG_CONFIG_SYSROOT_DIR=${PREFIX}/${TARGET} | |
| export PKG_CONFIG_LIBDIR=${PREFIX}/${TARGET}/usr/lib/pkgconfig | |
| export PKG_CONFIG_PATH=\$PKG_CONFIG_LIBDIR | |
| exec pkg-config --static "\$@" | |
| EOF | |
| chmod 755 "${PREFIX}/bin/${TARGET}-pkg-config" | |
| } | |
| grab_sources | |
| extract_source | |
| patch_sources | |
| prepare_gcc | |
| install_headers | |
| install_binutils | |
| install_musl | |
| install_gcc | |
| install_pkgconfig | |
| rm -rf "${SRCDIR}" | |
| rm -rf "${BLDDIR}" | |
| rm -rf "${PREFIX}/share" | |
| rm -f "${PREFIX}/lib/libiberty.a" | |
| cat << EOF | tee ${PREFIX}/README | |
| TRIPLET : $TARGET | |
| PREFIX : $PREFIX | |
| GCC : $GCCV | |
| BINUTILS: $BINV | |
| MUSL : $MUSLV | |
| KERNEL : $KERNV | |
| EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ./Configure no-ssl2 no-ssl3 no-idea no-shared no-asm no-async linux-armv4 --prefix=/ | |
| ./configure --prefix=/ --host=arm-arago-linux-gnueabi; make DESTDIR=/app/cross/opensource/ PREFIX=/ install | |
| autoreconf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export BASE_DIR=/app/cross/ | |
| export LOG_DIR=$BASE_DIR/log | |
| export SRC_DIR=$BASE_DIR/src | |
| export BUILD_DIR=$BASE_DIR/build | |
| export INSTALL_DIR=$BASE_DIR/aarch64 | |
| export SYSROOT_DIR=$INSTALL_DIR/sysroot | |
| export TARGET_MACH=aarch64-fsf-linux | |
| export LINUX_ARCH=arm64 | |
| export BUILD_MACH=$(gcc -dumpmachine) | |
| export binutils_version=binutils-2.27 | |
| export kernel_version=linux-4.14.59 | |
| export gcc_version=gcc-6.4.0 | |
| export musl_version=musl-1.1.19 | |
| export glibc_version=glibc-2.25 | |
| # https://gmplib.org gmp-6.1.2 | |
| # http://www.mpfr.org mpfr-4.0.1.tar.gz | |
| # http://www.multiprecision.org mpc-1.1.0 | |
| # http://isl.gforge.inria.fr isl-0.18 | |
| export BINUTILS_SRC=$SRC_DIR/$binutils_version | |
| export KERNEL_SRC=$SRC_DIR/$kernel_version | |
| export GCC_SRC=$SRC_DIR/$gcc_version | |
| export GLIBC_SRC=$SRC_DIR/$glibc_version | |
| export MUSL_SRC=$SRC_DIR/$musl_version | |
| wrap_cmd() { | |
| stage=$1; shift | |
| LOGFILE="$LOG_DIR/$stage.log" | |
| rm -rf "$LOGFILE" | |
| echo "begin $stage" | |
| for cmd in "$@" | |
| do | |
| echo "begin $cmd" | |
| eval "$cmd >> $LOGFILE 2>&1" | |
| [ $? -ne 0 ] && echo "error" && exit 1 | |
| echo "end $cmd" | |
| done | |
| echo "end $stage" | |
| } | |
| rm -rf $BUILD_DIR | |
| mkdir -p $BUILD_DIR | |
| mkdir -p $SRC_DIR | |
| rm -rf $LOG_DIR | |
| mkdir -p $LOG_DIR | |
| #wrap_cmd \ | |
| # "00.download_packages" \ | |
| # "cd $SRC_DIR" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/binutils/$binutils_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/gcc/$gcc_version/$gcc_version.tar.gz" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/glibc/$glibc_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/kernel/v4.x/$kernel_version.tar.gz" | |
| function build_01_binutils () { | |
| wrap_cmd \ | |
| "01-01.binutils_extract" \ | |
| "rm -rf $BINUTILS_SRC" \ | |
| "tar jxf $BINUTILS_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -p $BUILD_DIR/binutils" | |
| wrap_cmd \ | |
| "01-02.binutils_configure" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "$BINUTILS_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --disable-werror" | |
| wrap_cmd \ | |
| "01-03.binutils_build" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "make -j$(nproc)" "make install" | |
| } | |
| function build_02_linux_header () { | |
| wrap_cmd \ | |
| "02-01.linux_extract" \ | |
| "rm -rf $KERNEL_SRC" \ | |
| "tar zxf $KERNEL_SRC.tar.gz -C $SRC_DIR/" | |
| wrap_cmd \ | |
| "02-02.linux_header_install" \ | |
| "cd $KERNEL_SRC" \ | |
| "make mrproper" \ | |
| "make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$SYSROOT_DIR/usr headers_install" | |
| } | |
| function build_03_gcc_bootstrap() { | |
| wrap_cmd \ | |
| "03-01.gcc_extract" \ | |
| "rm -rf $GCC_SRC" \ | |
| "rm -rf $BUILD_DIR/bootstrap-gcc" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "sed -i -e '/k prot/agcc_cv_libc_provides_ssp=yes' $GCC_SRC/gcc/configure" \ | |
| "cd $GCC_SRC" \ | |
| "ln -sf $SRC_DIR/gmp gmp" \ | |
| "ln -sf $SRC_DIR/mpfr mpfr" \ | |
| "ln -sf $SRC_DIR/mpc mpc" \ | |
| "ln -sf $SRC_DIR/isl isl" \ | |
| "ln -sf $SRC_DIR/cloog cloog" \ | |
| "mkdir $BUILD_DIR/bootstrap-gcc" | |
| wrap_cmd \ | |
| "03-02.gcc_configure" \ | |
| "cd $BUILD_DIR/bootstrap-gcc" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --without-headers \ | |
| --enable-languages='c' \ | |
| --enable-__cxa_atexit \ | |
| --with-gnu-ld \ | |
| --with-gnu-as \ | |
| --disable-libmudflap \ | |
| --disable-threads \ | |
| --disable-libssp \ | |
| --disable-libgomp \ | |
| --disable-nls \ | |
| --disable-multilib \ | |
| --disable-decimal-float \ | |
| --disable-libatomic \ | |
| --disable-shared" | |
| wrap_cmd \ | |
| "03-03.gcc_build" \ | |
| "mkdir -p $SYSROOT_DIR/lib" \ | |
| "mkdir -p $SYSROOT_DIR/usr/lib" \ | |
| "ln -sf lib $SYSROOT_DIR/lib64" \ | |
| "ln -sf lib $SYSROOT_DIR/usr/lib64" \ | |
| "cd $BUILD_DIR/bootstrap-gcc" \ | |
| "make -j$(nproc) all-gcc" \ | |
| "make -j$(nproc) all-target-libgcc" \ | |
| "make install-gcc" \ | |
| "make install-target-libgcc" | |
| } | |
| function build_04_libc_header() { | |
| wrap_cmd \ | |
| "04-01.glibc_extract" \ | |
| "rm -rf $GLIBC_SRC" \ | |
| "rm -rf $BUILD_DIR/libc" \ | |
| "tar jxf $GLIBC_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -pv $BUILD_DIR/libc" | |
| wrap_cmd \ | |
| "04-02.glibc_configure" \ | |
| "cd $BUILD_DIR/libc" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "export PATH=$INSTALL_DIR/bin:$PATH" \ | |
| "export CC=${TARGET_MACH}-gcc" \ | |
| "export LD=${TARGET_MACH}-ld" \ | |
| "export AS=${TARGET_MACH}-as" \ | |
| "$GLIBC_SRC/configure \ | |
| --prefix=/usr \ | |
| --build=$BUILD_MACH \ | |
| --host=$TARGET_MACH \ | |
| --with-headers=$SYSROOT_DIR/usr/include \ | |
| --config-cache \ | |
| --enable-kernel=4.0" | |
| wrap_cmd \ | |
| "04-03.glibc_build" \ | |
| "make -k install-headers cross_compiling=yes install_root=$SYSROOT_DIR" | |
| } | |
| function build_04_libc() { | |
| wrap_cmd \ | |
| "04-01.glibc_extract" \ | |
| "rm -rf $GLIBC_SRC" \ | |
| "rm -rf $BUILD_DIR/libc" \ | |
| "tar zxf $GLIBC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "mkdir -pv $BUILD_DIR/libc" | |
| wrap_cmd \ | |
| "04-02.glibc_configure" \ | |
| "cd $BUILD_DIR/libc" \ | |
| "export PATH=$INSTALL_DIR/bin:$PATH" \ | |
| "export CC=${TARGET_MACH}-gcc" \ | |
| "export LD=${TARGET_MACH}-ld" \ | |
| "export AS=${TARGET_MACH}-as" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GLIBC_SRC/configure \ | |
| --prefix=/usr \ | |
| --build=$BUILD_MACH \ | |
| --host=$TARGET_MACH \ | |
| --with-headers=$SYSROOT_DIR/usr/include \ | |
| --config-cache \ | |
| --enable-kernel=4.0" | |
| wrap_cmd \ | |
| "04-03.glibc_build" \ | |
| "make -j$(nproc)" \ | |
| "make DESTDIR=$SYSROOT_DIR install" \ | |
| "unset CC" "unset LD" "unset AS" | |
| } | |
| function build_05_gcc_01() { | |
| wrap_cmd \ | |
| "06-01.gcc-final-01_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-01" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-01" \ | |
| "rm -rf $GCC_SRC" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "cd $GCC_SRC" \ | |
| "ln -sf $SRC_DIR/gmp gmp" \ | |
| "ln -sf $SRC_DIR/mpfr mpfr" \ | |
| "ln -sf $SRC_DIR/mpc mpc" \ | |
| "ln -sf $SRC_DIR/isl isl" \ | |
| "ln -sf $SRC_DIR/cloog cloog" | |
| wrap_cmd \ | |
| "06-02.gcc-final-01_configure" \ | |
| "cd $BUILD_DIR/final-gcc-01" \ | |
| "echo $PATH" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --enable-c99 \ | |
| --enable-long-long \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-bootstrap\ | |
| --disable-nls \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "06-03.gcc-final-01_build" \ | |
| "make -j$(nproc) all-gcc all-target-libgcc" \ | |
| "make install-gcc install-target-libgcc" | |
| } | |
| function build_06_gcc_final_02() { | |
| wrap_cmd \ | |
| "07-01.gcc-final-02_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-02" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-02" | |
| wrap_cmd \ | |
| "07-02.gcc-final-02_configure" \ | |
| "cd $BUILD_DIR/final-gcc-02" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --enable-c99 \ | |
| --enable-long-long \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-libsanitizer \ | |
| --disable-nls \ | |
| --disable-libssp \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "07-03.gcc-final-02_build" \ | |
| "make -j$(nproc)" \ | |
| "make install" | |
| } | |
| build_01_binutils | |
| build_02_linux_header | |
| build_03_gcc_bootstrap | |
| build_04_libc | |
| build_05_gcc_01 | |
| build_06_gcc_final_02 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -x | |
| export BASE_DIR=/app/cross/ | |
| export LOG_DIR=$BASE_DIR/log | |
| export SRC_DIR=$BASE_DIR/src | |
| export BUILD_DIR=$BASE_DIR/build | |
| export INSTALL_DIR=$BASE_DIR/x64 | |
| export SYSROOT_DIR=$INSTALL_DIR/sysroot | |
| export TARGET_MACH=x86_64-fsf-linux | |
| export LINUX_ARCH=x86_64 | |
| export BUILD_MACH=$(gcc -dumpmachine) | |
| export binutils_version=binutils-2.27 | |
| export kernel_version=linux-4.14.59 | |
| export gcc_version=gcc-6.4.0 | |
| export musl_version=musl-1.1.19 | |
| export glibc_version=glibc-2.25 | |
| # binutils-2.27.tar.bz2 | |
| # gcc-6.4.0.tar.gz | |
| # glibc-2.25.tar.gz | |
| # linux-4.14.59.tar.gz | |
| # cloog-0.18.4.tar.gz | |
| # https://gmplib.org gmp-6.1.0.tar.bz2 | |
| # http://www.mpfr.org mpfr-3.1.5.tar.gz | |
| # http://www.multiprecision.org mpc-1.1.0.tar.gz | |
| # http://isl.gforge.inria.fr isl-0.18.tar.bz2 | |
| export BINUTILS_SRC=$SRC_DIR/$binutils_version | |
| export KERNEL_SRC=$SRC_DIR/$kernel_version | |
| export GCC_SRC=$SRC_DIR/$gcc_version | |
| export GLIBC_SRC=$SRC_DIR/$glibc_version | |
| export MUSL_SRC=$SRC_DIR/$musl_version | |
| wrap_cmd() { | |
| stage=$1; shift | |
| LOGFILE="$LOG_DIR/$stage.log" | |
| rm -rf "$LOGFILE" | |
| echo "begin $stage" | |
| for cmd in "$@" | |
| do | |
| echo "begin $cmd" | |
| eval "$cmd >> $LOGFILE 2>&1" | |
| [ $? -ne 0 ] && echo "error" && exit 1 | |
| echo "end $cmd" | |
| done | |
| echo "end $stage" | |
| } | |
| rm -rf $BUILD_DIR | |
| mkdir -p $BUILD_DIR | |
| mkdir -p $SRC_DIR | |
| rm -rf $LOG_DIR | |
| mkdir -p $LOG_DIR | |
| #wrap_cmd \ | |
| # "00.download_packages" \ | |
| # "cd $SRC_DIR" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/binutils/$binutils_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/gcc/$gcc_version/$gcc_version.tar.gz" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/glibc/$glibc_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/kernel/v4.x/$kernel_version.tar.gz" | |
| function build_01_binutils () { | |
| wrap_cmd \ | |
| "01-01.binutils_extract" \ | |
| "rm -rf $BINUTILS_SRC" \ | |
| "tar jxf $BINUTILS_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -p $BUILD_DIR/binutils" | |
| wrap_cmd \ | |
| "01-02.binutils_configure" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "$BINUTILS_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --disable-werror" | |
| wrap_cmd \ | |
| "01-03.binutils_build" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "make -j$(nproc)" "make install" | |
| } | |
| function build_02_linux_header () { | |
| wrap_cmd \ | |
| "02-01.linux_extract" \ | |
| "rm -rf $KERNEL_SRC" \ | |
| "tar zxf $KERNEL_SRC.tar.gz -C $SRC_DIR/" | |
| wrap_cmd \ | |
| "02-02.linux_header_install" \ | |
| "cd $KERNEL_SRC" \ | |
| "make mrproper" \ | |
| "make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$SYSROOT_DIR/usr headers_install" | |
| } | |
| function build_03_gcc_bootstrap() { | |
| wrap_cmd \ | |
| "03-01.gcc_extract" \ | |
| "rm -rf $GCC_SRC" \ | |
| "rm -rf $BUILD_DIR/bootstrap-gcc" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "sed -i -e '/k prot/agcc_cv_libc_provides_ssp=yes' $GCC_SRC/gcc/configure" \ | |
| "cd $GCC_SRC" \ | |
| "ln -sf $SRC_DIR/gmp gmp" \ | |
| "ln -sf $SRC_DIR/mpfr mpfr" \ | |
| "ln -sf $SRC_DIR/mpc mpc" \ | |
| "ln -sf $SRC_DIR/isl isl" \ | |
| "ln -sf $SRC_DIR/cloog cloog" \ | |
| "mkdir $BUILD_DIR/bootstrap-gcc" | |
| wrap_cmd \ | |
| "03-02.gcc_configure" \ | |
| "cd $BUILD_DIR/bootstrap-gcc" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --without-headers \ | |
| --enable-languages='c' \ | |
| --enable-__cxa_atexit \ | |
| --with-gnu-ld \ | |
| --with-gnu-as \ | |
| --disable-libmudflap \ | |
| --disable-threads \ | |
| --disable-libssp \ | |
| --disable-libgomp \ | |
| --disable-nls \ | |
| --disable-multilib \ | |
| --disable-decimal-float \ | |
| --disable-libatomic \ | |
| --disable-shared" | |
| wrap_cmd \ | |
| "03-03.gcc_build" \ | |
| "mkdir -p $SYSROOT_DIR/lib" \ | |
| "mkdir -p $SYSROOT_DIR/usr/lib" \ | |
| "ln -sf lib $SYSROOT_DIR/lib64" \ | |
| "ln -sf lib $SYSROOT_DIR/usr/lib64" \ | |
| "cd $BUILD_DIR/bootstrap-gcc" \ | |
| "make -j$(nproc) all-gcc" \ | |
| "make -j$(nproc) all-target-libgcc" \ | |
| "make install-gcc" \ | |
| "make install-target-libgcc" | |
| } | |
| function build_04_libc_header() { | |
| wrap_cmd \ | |
| "04-01.glibc_extract" \ | |
| "rm -rf $GLIBC_SRC" \ | |
| "rm -rf $BUILD_DIR/libc" \ | |
| "tar jxf $GLIBC_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -pv $BUILD_DIR/libc" | |
| wrap_cmd \ | |
| "04-02.glibc_configure" \ | |
| "cd $BUILD_DIR/libc" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "export PATH=$INSTALL_DIR/bin:$PATH" \ | |
| "export CC=${TARGET_MACH}-gcc" \ | |
| "export LD=${TARGET_MACH}-ld" \ | |
| "export AS=${TARGET_MACH}-as" \ | |
| "$GLIBC_SRC/configure \ | |
| --prefix=/usr \ | |
| --build=$BUILD_MACH \ | |
| --host=$TARGET_MACH \ | |
| --with-headers=$SYSROOT_DIR/usr/include \ | |
| --config-cache \ | |
| --enable-kernel=4.0" | |
| wrap_cmd \ | |
| "04-03.glibc_build" \ | |
| "make -k install-headers cross_compiling=yes install_root=$SYSROOT_DIR" | |
| } | |
| function build_04_libc() { | |
| wrap_cmd \ | |
| "04-01.glibc_extract" \ | |
| "rm -rf $GLIBC_SRC" \ | |
| "rm -rf $BUILD_DIR/libc" \ | |
| "tar zxf $GLIBC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "mkdir -pv $BUILD_DIR/libc" | |
| wrap_cmd \ | |
| "04-02.glibc_configure" \ | |
| "cd $BUILD_DIR/libc" \ | |
| "export PATH=$INSTALL_DIR/bin:$PATH" \ | |
| "export CC=${TARGET_MACH}-gcc" \ | |
| "export LD=${TARGET_MACH}-ld" \ | |
| "export AS=${TARGET_MACH}-as" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GLIBC_SRC/configure \ | |
| --prefix=/usr \ | |
| --build=$BUILD_MACH \ | |
| --host=$TARGET_MACH \ | |
| --with-headers=$SYSROOT_DIR/usr/include \ | |
| --config-cache \ | |
| --enable-kernel=4.0" | |
| wrap_cmd \ | |
| "04-03.glibc_build" \ | |
| "make -j$(nproc)" \ | |
| "make DESTDIR=$SYSROOT_DIR install" \ | |
| "unset CC" "unset LD" "unset AS" | |
| } | |
| function build_05_gcc_01() { | |
| wrap_cmd \ | |
| "06-01.gcc-final-01_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-01" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-01" \ | |
| "rm -rf $GCC_SRC" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "cd $GCC_SRC" \ | |
| "ln -sf $SRC_DIR/gmp gmp" \ | |
| "ln -sf $SRC_DIR/mpfr mpfr" \ | |
| "ln -sf $SRC_DIR/mpc mpc" \ | |
| "ln -sf $SRC_DIR/isl isl" \ | |
| "ln -sf $SRC_DIR/cloog cloog" | |
| wrap_cmd \ | |
| "06-02.gcc-final-01_configure" \ | |
| "cd $BUILD_DIR/final-gcc-01" \ | |
| "echo $PATH" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --enable-c99 \ | |
| --enable-long-long \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-bootstrap\ | |
| --disable-nls \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "06-03.gcc-final-01_build" \ | |
| "make -j$(nproc) all-gcc all-target-libgcc" \ | |
| "make install-gcc install-target-libgcc" | |
| } | |
| function build_06_gcc_final_02() { | |
| wrap_cmd \ | |
| "07-01.gcc-final-02_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-02" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-02" | |
| wrap_cmd \ | |
| "07-02.gcc-final-02_configure" \ | |
| "cd $BUILD_DIR/final-gcc-02" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --enable-c99 \ | |
| --enable-long-long \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-libsanitizer \ | |
| --disable-nls \ | |
| --disable-libssp \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "07-03.gcc-final-02_build" \ | |
| "make -j$(nproc)" \ | |
| "make install" | |
| } | |
| build_01_binutils | |
| build_02_linux_header | |
| build_03_gcc_bootstrap | |
| build_04_libc | |
| build_05_gcc_01 | |
| build_06_gcc_final_02 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -x | |
| export BASE_DIR=/app/cross/ | |
| export LOG_DIR=$BASE_DIR/log | |
| export SRC_DIR=$BASE_DIR/src | |
| export BUILD_DIR=$BASE_DIR/build | |
| export INSTALL_DIR=$BASE_DIR/x64_7 | |
| export SYSROOT_DIR=$INSTALL_DIR/sysroot | |
| export TARGET_MACH=x86_64-fsf-linux | |
| export LINUX_ARCH=x86_64 | |
| export BUILD_MACH=$(gcc -dumpmachine) | |
| export binutils_version=binutils-2.27 | |
| export kernel_version=linux-4.14.59 | |
| export gcc_version=gcc-7.3.0 | |
| export musl_version=musl-1.1.19 | |
| export glibc_version=glibc-2.25 | |
| # https://gmplib.org gmp-6.1.2 | |
| # http://www.mpfr.org mpfr-3.1.5.tar.gz | |
| # http://www.multiprecision.org mpc-1.1.0 | |
| # http://isl.gforge.inria.fr isl-0.18 | |
| export BINUTILS_SRC=$SRC_DIR/$binutils_version | |
| export KERNEL_SRC=$SRC_DIR/$kernel_version | |
| export GCC_SRC=$SRC_DIR/$gcc_version | |
| export GLIBC_SRC=$SRC_DIR/$glibc_version | |
| export MUSL_SRC=$SRC_DIR/$musl_version | |
| wrap_cmd() { | |
| stage=$1; shift | |
| LOGFILE="$LOG_DIR/$stage.log" | |
| rm -rf "$LOGFILE" | |
| echo "begin $stage" | |
| for cmd in "$@" | |
| do | |
| echo "begin $cmd" | |
| eval "$cmd >> $LOGFILE 2>&1" | |
| [ $? -ne 0 ] && echo "error" && exit 1 | |
| echo "end $cmd" | |
| done | |
| echo "end $stage" | |
| } | |
| rm -rf $BUILD_DIR | |
| mkdir -p $BUILD_DIR | |
| mkdir -p $SRC_DIR | |
| rm -rf $LOG_DIR | |
| mkdir -p $LOG_DIR | |
| #wrap_cmd \ | |
| # "00.download_packages" \ | |
| # "cd $SRC_DIR" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/binutils/$binutils_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/gcc/$gcc_version/$gcc_version.tar.gz" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/glibc/$glibc_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/kernel/v4.x/$kernel_version.tar.gz" | |
| function build_01_binutils () { | |
| wrap_cmd \ | |
| "01-01.binutils_extract" \ | |
| "rm -rf $BINUTILS_SRC" \ | |
| "tar jxf $BINUTILS_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -p $BUILD_DIR/binutils" | |
| wrap_cmd \ | |
| "01-02.binutils_configure" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "$BINUTILS_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --disable-werror" | |
| wrap_cmd \ | |
| "01-03.binutils_build" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "make -j$(nproc)" "make install" | |
| } | |
| function build_02_linux_header () { | |
| wrap_cmd \ | |
| "02-01.linux_extract" \ | |
| "rm -rf $KERNEL_SRC" \ | |
| "tar zxf $KERNEL_SRC.tar.gz -C $SRC_DIR/" | |
| wrap_cmd \ | |
| "02-02.linux_header_install" \ | |
| "cd $KERNEL_SRC" \ | |
| "make mrproper" \ | |
| "make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$SYSROOT_DIR/usr headers_install" | |
| } | |
| function build_03_gcc_bootstrap() { | |
| wrap_cmd \ | |
| "03-01.gcc_extract" \ | |
| "rm -rf $GCC_SRC" \ | |
| "rm -rf $BUILD_DIR/bootstrap-gcc" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "sed -i -e '/k prot/agcc_cv_libc_provides_ssp=yes' $GCC_SRC/gcc/configure" \ | |
| "cd $GCC_SRC" \ | |
| "ln -sf $SRC_DIR/gmp gmp" \ | |
| "ln -sf $SRC_DIR/mpfr mpfr" \ | |
| "ln -sf $SRC_DIR/mpc mpc" \ | |
| "ln -sf $SRC_DIR/isl isl" \ | |
| "ln -sf $SRC_DIR/cloog cloog" \ | |
| "mkdir $BUILD_DIR/bootstrap-gcc" | |
| wrap_cmd \ | |
| "03-02.gcc_configure" \ | |
| "cd $BUILD_DIR/bootstrap-gcc" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --without-headers \ | |
| --enable-languages='c' \ | |
| --enable-__cxa_atexit \ | |
| --with-gnu-ld \ | |
| --with-gnu-as \ | |
| --disable-libmudflap \ | |
| --disable-threads \ | |
| --disable-libssp \ | |
| --disable-libgomp \ | |
| --disable-nls \ | |
| --disable-multilib \ | |
| --disable-decimal-float \ | |
| --disable-libatomic \ | |
| --disable-shared" | |
| wrap_cmd \ | |
| "03-03.gcc_build" \ | |
| "mkdir -p $SYSROOT_DIR/lib" \ | |
| "mkdir -p $SYSROOT_DIR/usr/lib" \ | |
| "ln -sf lib $SYSROOT_DIR/lib64" \ | |
| "ln -sf lib $SYSROOT_DIR/usr/lib64" \ | |
| "cd $BUILD_DIR/bootstrap-gcc" \ | |
| "make -j$(nproc) all-gcc" \ | |
| "make -j$(nproc) all-target-libgcc" \ | |
| "make install-gcc" \ | |
| "make install-target-libgcc" | |
| } | |
| function build_04_libc_header() { | |
| wrap_cmd \ | |
| "04-01.glibc_extract" \ | |
| "rm -rf $GLIBC_SRC" \ | |
| "rm -rf $BUILD_DIR/libc" \ | |
| "tar jxf $GLIBC_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -pv $BUILD_DIR/libc" | |
| wrap_cmd \ | |
| "04-02.glibc_configure" \ | |
| "cd $BUILD_DIR/libc" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "export PATH=$INSTALL_DIR/bin:$PATH" \ | |
| "export CC=${TARGET_MACH}-gcc" \ | |
| "export LD=${TARGET_MACH}-ld" \ | |
| "export AS=${TARGET_MACH}-as" \ | |
| "$GLIBC_SRC/configure \ | |
| --prefix=/usr \ | |
| --build=$BUILD_MACH \ | |
| --host=$TARGET_MACH \ | |
| --with-headers=$SYSROOT_DIR/usr/include \ | |
| --config-cache \ | |
| --enable-kernel=4.0" | |
| wrap_cmd \ | |
| "04-03.glibc_build" \ | |
| "make -k install-headers cross_compiling=yes install_root=$SYSROOT_DIR" | |
| } | |
| function build_04_libc() { | |
| wrap_cmd \ | |
| "04-01.glibc_extract" \ | |
| "rm -rf $GLIBC_SRC" \ | |
| "rm -rf $BUILD_DIR/libc" \ | |
| "tar zxf $GLIBC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "mkdir -pv $BUILD_DIR/libc" | |
| wrap_cmd \ | |
| "04-02.glibc_configure" \ | |
| "cd $BUILD_DIR/libc" \ | |
| "export PATH=$INSTALL_DIR/bin:$PATH" \ | |
| "export CC=${TARGET_MACH}-gcc" \ | |
| "export LD=${TARGET_MACH}-ld" \ | |
| "export AS=${TARGET_MACH}-as" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GLIBC_SRC/configure \ | |
| --prefix=/usr \ | |
| --build=$BUILD_MACH \ | |
| --host=$TARGET_MACH \ | |
| --with-headers=$SYSROOT_DIR/usr/include \ | |
| --config-cache \ | |
| --enable-kernel=4.0" | |
| wrap_cmd \ | |
| "04-03.glibc_build" \ | |
| "make -j$(nproc)" \ | |
| "make DESTDIR=$SYSROOT_DIR install" \ | |
| "unset CC" "unset LD" "unset AS" | |
| } | |
| function build_05_gcc_01() { | |
| wrap_cmd \ | |
| "06-01.gcc-final-01_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-01" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-01" \ | |
| "rm -rf $GCC_SRC" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "cd $GCC_SRC" \ | |
| "ln -sf $SRC_DIR/gmp gmp" \ | |
| "ln -sf $SRC_DIR/mpfr mpfr" \ | |
| "ln -sf $SRC_DIR/mpc mpc" \ | |
| "ln -sf $SRC_DIR/isl isl" \ | |
| "ln -sf $SRC_DIR/cloog cloog" | |
| wrap_cmd \ | |
| "06-02.gcc-final-01_configure" \ | |
| "cd $BUILD_DIR/final-gcc-01" \ | |
| "echo $PATH" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --enable-c99 \ | |
| --enable-long-long \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-bootstrap\ | |
| --disable-nls \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "06-03.gcc-final-01_build" \ | |
| "make -j$(nproc) all-gcc all-target-libgcc" \ | |
| "make install-gcc install-target-libgcc" | |
| } | |
| function build_06_gcc_final_02() { | |
| wrap_cmd \ | |
| "07-01.gcc-final-02_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-02" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-02" | |
| wrap_cmd \ | |
| "07-02.gcc-final-02_configure" \ | |
| "cd $BUILD_DIR/final-gcc-02" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --enable-c99 \ | |
| --enable-long-long \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-libsanitizer \ | |
| --disable-nls \ | |
| --disable-libssp \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "07-03.gcc-final-02_build" \ | |
| "make -j$(nproc)" \ | |
| "make install" | |
| } | |
| build_01_binutils | |
| build_02_linux_header | |
| build_03_gcc_bootstrap | |
| build_04_libc | |
| build_05_gcc_01 | |
| build_06_gcc_final_02 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export BASE_DIR=/app/cross/ | |
| export LOG_DIR=$BASE_DIR/log | |
| export SRC_DIR=$BASE_DIR/src | |
| export BUILD_DIR=$BASE_DIR/build | |
| export INSTALL_DIR=$BASE_DIR/x86_64 | |
| export SYSROOT_DIR=$INSTALL_DIR/sysroot | |
| export TARGET_MACH=x86_64-fsf-linux | |
| export LINUX_ARCH=x86_64 | |
| export BUILD_MACH=$(gcc -dumpmachine) | |
| export binutils_version=binutils-2.27 | |
| export kernel_version=linux-4.9.35 | |
| export gcc_version=gcc-6.4.0 | |
| export glibc_version=glibc-2.25 | |
| export BINUTILS_SRC=$SRC_DIR/$binutils_version | |
| export KERNEL_SRC=$SRC_DIR/$kernel_version | |
| export GCC_SRC=$SRC_DIR/$gcc_version | |
| export GLIBC_SRC=$SRC_DIR/$glibc_version | |
| wrap_cmd() { | |
| stage=$1; shift | |
| LOGFILE="$LOG_DIR/$stage.log" | |
| rm -rf "$LOGFILE" | |
| echo "begin $stage" | |
| for cmd in "$@" | |
| do | |
| echo "begin $cmd" | |
| eval "$cmd >> $LOGFILE 2>&1" | |
| [ $? -ne 0 ] && echo "error" && exit 1 | |
| echo "end $cmd" | |
| done | |
| echo "end $stage" | |
| } | |
| rm -rf $BUILD_DIR | |
| mkdir -p $BUILD_DIR | |
| mkdir -p $SRC_DIR | |
| rm -rf $LOG_DIR | |
| mkdir -p $LOG_DIR | |
| #wrap_cmd \ | |
| # "00.download_packages" \ | |
| # "cd $SRC_DIR" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/binutils/$binutils_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/gcc/$gcc_version/$gcc_version.tar.gz" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/glibc/$glibc_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/kernel/v4.x/$kernel_version.tar.gz" | |
| wrap_cmd \ | |
| "01-01.binutils_extract" \ | |
| "rm -rf $BINUTILS_SRC" \ | |
| "tar jxf $BINUTILS_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -p $BUILD_DIR/binutils" | |
| wrap_cmd \ | |
| "01-02.binutils_configure" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "$BINUTILS_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --disable-werror" | |
| wrap_cmd \ | |
| "01-03.binutils_build" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "make -j$(nproc)" "make install" | |
| wrap_cmd \ | |
| "02-01.linux_extract" \ | |
| "rm -rf $KERNEL_SRC" \ | |
| "tar zxf $KERNEL_SRC.tar.gz -C $SRC_DIR/" | |
| wrap_cmd \ | |
| "02-02.linux_header_install" \ | |
| "cd $KERNEL_SRC" \ | |
| "make mrproper" \ | |
| "make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$SYSROOT_DIR/usr headers_install" | |
| wrap_cmd \ | |
| "03-01.gcc_extract" \ | |
| "rm -rf $GCC_SRC" \ | |
| "rm -rf $BUILD_DIR/bootstrap-gcc" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "sed -i -e '/k prot/agcc_cv_libc_provides_ssp=yes' $GCC_SRC/gcc/configure" \ | |
| "mkdir $BUILD_DIR/bootstrap-gcc" | |
| wrap_cmd \ | |
| "03-02.gcc_configure" \ | |
| "cd $BUILD_DIR/bootstrap-gcc" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --without-headers \ | |
| --enable-boostrap \ | |
| --enable-languages='c' \ | |
| --disable-threads \ | |
| --enable-__cxa_atexit \ | |
| --disable-libmudflap \ | |
| --with-gnu-ld \ | |
| --with-gnu-as \ | |
| --disable-libssp \ | |
| --disable-libgomp \ | |
| --disable-nls \ | |
| --disable-multilib \ | |
| --disable-shared" | |
| wrap_cmd \ | |
| "03-03.gcc_build" \ | |
| "make -j$(nproc) all-gcc" \ | |
| "make -j$(nproc) all-target-libgcc" \ | |
| "make install-gcc" \ | |
| "make install-target-libgcc" | |
| wrap_cmd \ | |
| "04-01.glibc_extract" \ | |
| "rm -rf $GLIBC_SRC" \ | |
| "rm -rf $BUILD_DIR/libc" \ | |
| "tar jxf $GLIBC_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -pv $BUILD_DIR/libc" | |
| wrap_cmd \ | |
| "04-02.glibc_configure" \ | |
| "cd $BUILD_DIR/libc" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "export PATH=$INSTALL_DIR/bin:$PATH" \ | |
| "export CC=${TARGET_MACH}-gcc" \ | |
| "export LD=${TARGET_MACH}-ld" \ | |
| "export AS=${TARGET_MACH}-as" \ | |
| "$GLIBC_SRC/configure \ | |
| --prefix=/usr \ | |
| --build=$BUILD_MACH \ | |
| --host=$TARGET_MACH \ | |
| --with-headers=$SYSROOT_DIR/usr/include \ | |
| --config-cache \ | |
| --enable-kernel=4.0" | |
| wrap_cmd \ | |
| "04-03.glibc_build" \ | |
| "make -k install-headers cross_compiling=yes install_root=$SYSROOT_DIR" | |
| wrap_cmd \ | |
| "05-01.glibc_extract" \ | |
| "rm -rf $GLIBC_SRC" \ | |
| "rm -rf $BUILD_DIR/libc" \ | |
| "tar jxf $GLIBC_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -pv $BUILD_DIR/libc" | |
| wrap_cmd \ | |
| "05-02.glibc_configure" \ | |
| "cd $BUILD_DIR/libc" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GLIBC_SRC/configure \ | |
| --prefix=/usr \ | |
| --build=$BUILD_MACH \ | |
| --host=$TARGET_MACH \ | |
| --with-headers=$SYSROOT_DIR/usr/include \ | |
| --config-cache \ | |
| --enable-kernel=4.0" | |
| wrap_cmd \ | |
| "05-03.glibc_build" \ | |
| "make -k install-headers cross_compiling=yes install_root=$SYSROOT_DIR" \ | |
| "make" \ | |
| "make install_root=${SYSROOT_DIR} install " \ | |
| "ln -sf $SYSROOT_DIR/lib64 $SYSROOT_DIR/lib" \ | |
| "ln -sf $SYSROOT_DIR/usr/lib64 $SYSROOT_DIR/usr/lib" \ | |
| "unset CC" "unset LD" "unset AS" | |
| wrap_cmd \ | |
| "06-01.gcc-final-01_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-01" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-01" \ | |
| "rm -rf $GCC_SRC" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" | |
| # "cd $GCC_SRC/" \ | |
| # "./contrib/download_prerequisites" \ | |
| wrap_cmd \ | |
| "06-02.gcc-final-01_configure" \ | |
| "echo $PATH" \ | |
| "export BUILD_CC=gcc" \ | |
| "export BUILD_CXX=g++" \ | |
| "cd $BUILD_DIR/final-gcc-01" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-bootstrap \ | |
| --disable-nls \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "06-03.gcc-final-01_build" \ | |
| "make -j$(nproc) all-gcc" \ | |
| "make install-gcc" \ | |
| "make -j$(nproc) all-target-libgcc" \ | |
| "make install-target-libgcc" \ | |
| wrap_cmd \ | |
| "07-01.gcc-final-02_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-02" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-02" | |
| wrap_cmd \ | |
| "07-02.gcc-final-02_configure" \ | |
| "export BUILD_CC=gcc" \ | |
| "export BUILD_CXX=g++" \ | |
| "cd $BUILD_DIR/final-gcc-02" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-nls \ | |
| --disable-libssp \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "07-03.gcc-final-02_build" \ | |
| "make -j$(nproc)" \ | |
| "make install" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export BASE_DIR=/app/cross/ | |
| export LOG_DIR=$BASE_DIR/log | |
| export SRC_DIR=$BASE_DIR/src | |
| export BUILD_DIR=$BASE_DIR/build | |
| export INSTALL_DIR=$BASE_DIR/x86_64 | |
| export SYSROOT_DIR=$INSTALL_DIR/sysroot | |
| export TARGET_MACH=x86_64-linux-musl | |
| export LINUX_ARCH=x86_64 | |
| export BUILD_MACH=$(gcc -dumpmachine) | |
| export binutils_version=binutils-2.27 | |
| export kernel_version=linux-4.9.35 | |
| export gcc_version=gcc-6.4.0 | |
| export musl_version=musl-1.1.19 | |
| export glibc_version=glibc-2.25 | |
| export BINUTILS_SRC=$SRC_DIR/$binutils_version | |
| export KERNEL_SRC=$SRC_DIR/$kernel_version | |
| export GCC_SRC=$SRC_DIR/$gcc_version | |
| export GLIBC_SRC=$SRC_DIR/$glibc_version | |
| export MUSL_SRC=$SRC_DIR/$musl_version | |
| wrap_cmd() { | |
| stage=$1; shift | |
| LOGFILE="$LOG_DIR/$stage.log" | |
| rm -rf "$LOGFILE" | |
| echo "begin $stage" | |
| for cmd in "$@" | |
| do | |
| echo "begin $cmd" | |
| eval "$cmd >> $LOGFILE 2>&1" | |
| [ $? -ne 0 ] && echo "error" && exit 1 | |
| echo "end $cmd" | |
| done | |
| echo "end $stage" | |
| } | |
| rm -rf $BUILD_DIR | |
| mkdir -p $BUILD_DIR | |
| mkdir -p $SRC_DIR | |
| rm -rf $LOG_DIR | |
| mkdir -p $LOG_DIR | |
| #wrap_cmd \ | |
| # "00.download_packages" \ | |
| # "cd $SRC_DIR" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/binutils/$binutils_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/gcc/$gcc_version/$gcc_version.tar.gz" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/gnu/glibc/$glibc_version.tar.bz2" \ | |
| # "wget https://mirrors4.tuna.tsinghua.edu.cn/kernel/v4.x/$kernel_version.tar.gz" | |
| function build_01_binutils () { | |
| wrap_cmd \ | |
| "01-01.binutils_extract" \ | |
| "rm -rf $BINUTILS_SRC" \ | |
| "tar jxf $BINUTILS_SRC.tar.bz2 -C $SRC_DIR/" \ | |
| "mkdir -p $BUILD_DIR/binutils" | |
| wrap_cmd \ | |
| "01-02.binutils_configure" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "$BINUTILS_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --disable-werror" | |
| wrap_cmd \ | |
| "01-03.binutils_build" \ | |
| "cd $BUILD_DIR/binutils" \ | |
| "make -j$(nproc)" "make install" | |
| } | |
| function build_02_linux_header () { | |
| wrap_cmd \ | |
| "02-01.linux_extract" \ | |
| "rm -rf $KERNEL_SRC" \ | |
| "tar zxf $KERNEL_SRC.tar.gz -C $SRC_DIR/" | |
| wrap_cmd \ | |
| "02-02.linux_header_install" \ | |
| "cd $KERNEL_SRC" \ | |
| "make mrproper" \ | |
| "make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$SYSROOT_DIR/usr headers_install" | |
| } | |
| function build_03_gcc_bootstrap() { | |
| wrap_cmd \ | |
| "03-01.gcc_extract" \ | |
| "rm -rf $GCC_SRC" \ | |
| "rm -rf $BUILD_DIR/bootstrap-gcc" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "sed -i -e '/k prot/agcc_cv_libc_provides_ssp=yes' $GCC_SRC/gcc/configure" \ | |
| "cd $GCC_SRC" \ | |
| "ln -sf $SRC_DIR/gmp gmp" \ | |
| "ln -sf $SRC_DIR/mpfr mpfr" \ | |
| "ln -sf $SRC_DIR/mpc mpc" \ | |
| "ln -sf $SRC_DIR/isl isl" \ | |
| "ln -sf $SRC_DIR/cloog cloog" \ | |
| "mkdir $BUILD_DIR/bootstrap-gcc" | |
| wrap_cmd \ | |
| "03-02.gcc_configure" \ | |
| "cd $BUILD_DIR/bootstrap-gcc" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --without-headers \ | |
| --enable-languages='c' \ | |
| --enable-__cxa_atexit \ | |
| --with-gnu-ld \ | |
| --with-gnu-as \ | |
| --disable-libmudflap \ | |
| --disable-threads \ | |
| --disable-libssp \ | |
| --disable-libgomp \ | |
| --disable-nls \ | |
| --disable-multilib \ | |
| --disable-decimal-float \ | |
| --disable-libatomic \ | |
| --disable-shared" | |
| wrap_cmd \ | |
| "03-03.gcc_build" \ | |
| "cd $BUILD_DIR/bootstrap-gcc" \ | |
| "make -j$(nproc) all-gcc" \ | |
| "make -j$(nproc) all-target-libgcc" \ | |
| "make install-gcc" \ | |
| "make install-target-libgcc" \ | |
| "mkdir $SYSROOT_DIR/lib" \ | |
| "mkdir $SYSROOT_DIR/usr/lib" \ | |
| "ln -sf lib64 $SYSROOT_DIR/lib" \ | |
| "ln -sf lib64 $SYSROOT_DIR/usr/lib" | |
| } | |
| function build_04_libc() { | |
| wrap_cmd \ | |
| "04-01.glibc_extract" \ | |
| "rm -rf $MUSL_SRC" \ | |
| "rm -rf $BUILD_DIR/libc" \ | |
| "tar zxf $MUSL_SRC.tar.gz -C $SRC_DIR/" \ | |
| "mkdir -pv $BUILD_DIR/libc" | |
| wrap_cmd \ | |
| "04-02.glibc_configure" \ | |
| "cd $BUILD_DIR/libc" \ | |
| "export PATH=$INSTALL_DIR/bin:$PATH" \ | |
| "export CC=${TARGET_MACH}-gcc" \ | |
| "export LD=${TARGET_MACH}-ld" \ | |
| "export AS=${TARGET_MACH}-as" \ | |
| "$MUSL_SRC/configure \ | |
| --prefix=/usr \ | |
| --build=$BUILD_MACH \ | |
| --host=$TARGET_MACH" | |
| wrap_cmd \ | |
| "04-03.glibc_build" \ | |
| "make -j$(nproc)" \ | |
| "make DESTDIR=$SYSROOT_DIR install" \ | |
| "unset CC" "unset LD" "unset AS" | |
| } | |
| function build_05_gcc_01() { | |
| wrap_cmd \ | |
| "06-01.gcc-final-01_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-01" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-01" \ | |
| "rm -rf $GCC_SRC" \ | |
| "tar zxf $GCC_SRC.tar.gz -C $SRC_DIR/" \ | |
| "cd $GCC_SRC" \ | |
| "ln -sf $SRC_DIR/gmp gmp" \ | |
| "ln -sf $SRC_DIR/mpfr mpfr" \ | |
| "ln -sf $SRC_DIR/mpc mpc" \ | |
| "ln -sf $SRC_DIR/isl isl" \ | |
| "ln -sf $SRC_DIR/cloog cloog" | |
| wrap_cmd \ | |
| "06-02.gcc-final-01_configure" \ | |
| "cd $BUILD_DIR/final-gcc-01" \ | |
| "echo $PATH" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --enable-c99 \ | |
| --enable-long-long \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-bootstrap\ | |
| --disable-nls \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "06-03.gcc-final-01_build" \ | |
| "make -j$(nproc) all-gcc all-target-libgcc" \ | |
| "make install-gcc install-target-libgcc" | |
| } | |
| function build_06_gcc_final_02() { | |
| wrap_cmd \ | |
| "07-01.gcc-final-02_extract" \ | |
| "rm -rf $BUILD_DIR/final-gcc-02" \ | |
| "mkdir -pv $BUILD_DIR/final-gcc-02" | |
| wrap_cmd \ | |
| "07-02.gcc-final-02_configure" \ | |
| "cd $BUILD_DIR/final-gcc-02" \ | |
| "echo 'libc_cv_forced_unwind=yes' > config.cache" \ | |
| "echo 'libc_cv_c_cleanup=yes' >> config.cache" \ | |
| "$GCC_SRC/configure \ | |
| --prefix=$INSTALL_DIR \ | |
| --build=$BUILD_MACH \ | |
| --host=$BUILD_MACH \ | |
| --target=$TARGET_MACH \ | |
| --with-sysroot=$SYSROOT_DIR \ | |
| --enable-languages='c,c++' \ | |
| --enable-c99 \ | |
| --enable-long-long \ | |
| --with-gnu-as \ | |
| --with-gnu-ld \ | |
| --disable-multilib \ | |
| --disable-libsanitizer \ | |
| --disable-nls \ | |
| --disable-libssp \ | |
| --enable-threads=posix \ | |
| --with-shared" | |
| wrap_cmd \ | |
| "07-03.gcc-final-02_build" \ | |
| "make -j$(nproc)" \ | |
| "make install" | |
| } | |
| build_01_binutils | |
| build_02_linux_header | |
| build_03_gcc_bootstrap | |
| build_04_libc | |
| build_05_gcc_01 | |
| build_06_gcc_final_02 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment