Skip to content

Instantly share code, notes, and snippets.

@hansemro
Created October 19, 2022 10:07
Show Gist options
  • Save hansemro/279be7a2ec02f1a81830f526a1773514 to your computer and use it in GitHub Desktop.
Save hansemro/279be7a2ec02f1a81830f526a1773514 to your computer and use it in GitHub Desktop.
Build script for nds32 v3 toolchain
# git clone -b ast-v3_2_5-release-v3 https://github.com/andestech/nds-gnu-toolchain
# cd nds-gnu-toolchain
# git submodule update --init --recursive
# patch binutils and gcc...
TARGET=nds32le-linux
PREFIX=`pwd`/nds32le-linux-glibc-v3
ARCH=v3
CPU=n9
BUILD=`pwd`/build-nds32le-linux-glibc-v3
SYSROOT=${PREFIX}/sysroot
TARGET_CC=${PREFIX}/bin/${TARGET}-gcc
TARGET_CXX=${PREFIX}/bin/${TARGET}-g++
BINUTILS_SRC=`pwd`/binutils
GDB_SRC=`pwd`/gdb
GCC_SRC=`pwd`/gcc
GLIBC_SRC=`pwd`/glibc
KERNEL_HDR_SRC=`pwd`/linux-headers
MAKE_PARALLEL=-j1
#MAKE_PARALLEL=-j12
mkdir ${BUILD}
# 00. Prepare
export PATH=${PREFIX}/bin:$PATH
cd ${GCC_SRC}
./contrib/download_prerequisites
cd -
cd ${BUILD}
# 01. Binutils
# patch gprof/prof_io.c and gprof/timeline.c so that NIBBLE is static in both
mkdir -p binutils
cd binutils
${BINUTILS_SRC}/configure \
--target=${TARGET} --prefix=${PREFIX} --with-arch=${ARCH} \
--with-curses --disable-nls --disable-tui --with-python=no --with-lzma=no \
--with-expat=yes --with-guile=no --enable-plugins --disable-werror \
--enable-deterministic-archives --disable-gdb --disable-sim \
--with-sysroot=${SYSROOT}
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL} all
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make install
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ..
# 02. Install kernel header files.
mkdir -p ${SYSROOT}/usr/
cp -a ${KERNEL_HDR_SRC}/include ${SYSROOT}/usr/
# 03. Bootstrap GCC
# patch gcc/reload so that spill_indirect_levels++ becomes spill_indirect_levels ^= 1
mkdir -p bootstrap-gcc
cd bootstrap-gcc
${GCC_SRC}/configure \
--target=${TARGET} --prefix=${PREFIX} --with-cpu=${CPU} --target=${TARGET} \
--disable-nls --enable-languages=c,c++ --enable-lto \
--with-arch=${ARCH} --disable-werror \
--disable-multilib --enable-shared --enable-tls \
--disable-libsanitizer --enable-checking=release \
CFLAGS_FOR_TARGET="-O2 -g" \
CXXFLAGS_FOR_TARGET="-O2 -g" \
--without-headers --disable-shared --disable-threads \
--disable-libatomic --disable-libmudflap --disable-libssp \
--disable-libquadmath --disable-libgomp
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL} inhibit-libc=true all-gcc
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make inhibit-libc=true install-gcc
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL} inhibit-libc=true all-target-libgcc
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make inhibit-libc=true install-gcc install-target-libgcc
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ..
# 04. glibc
mkdir -p glibc
cd glibc
${GLIBC_SRC}/configure --prefix=/usr --host=${TARGET} \
--prefix=/usr --disable-werror --enable-shared --enable-obsolete-rpc \
--enable-kernel=3.0.0 --with-headers=${SYSROOT}/usr/include \
--with-arch=${ARCH} \
CC=${TARGET_CC} CXX=${TARGET_CXX} CFLAGS="-O2 -g"
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL}
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make install install_root=${SYSROOT}
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ..
# 05. Final GCC
mkdir -p final-gcc
cd final-gcc
${GCC_SRC}/configure \
--target=${TARGET} --prefix=${PREFIX} --with-cpu=${CPU} --target=${TARGET} \
--disable-nls --enable-languages=c,c++ --enable-lto \
--with-arch=${ARCH} --disable-werror \
--disable-multilib --enable-shared --enable-tls \
--with-sysroot=${SYSROOT} \
--enable-checking=release \
CFLAGS_FOR_TARGET="-O2 -g" \
CXXFLAGS_FOR_TARGET="-O2 -g"
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make ${MAKE_PARALLEL} all
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
make install
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
cd ..
# 6. GDB
# Does not compile with GCC 12.2.0
#mkdir -p gdb
#cd gdb
#${GDB_SRC}/configure \
# --target=${TARGET} --prefix=${PREFIX} --with-arch=${ARCH} \
# --with-curses --disable-nls --enable-tui --with-python=no \
# --with-lzma=no --with-expat=yes --with-guile=no \
# --disable-werror --disable-sim \
# --disable-binutils --disable-ld --disable-gas --disable-gprof \
# CFLAGS="-std=gnu99"
#rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
#
#make ${MAKE_PARALLEL} all
#rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
#
#make install
#rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
#
#cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment