Create Toolchain with Crosstool-NG
Preparation
sudo apt install -y flex help2man libtool-bin bison libncurses5-dev
wget -c http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.26.0.tar.xz
Build and Install crosstool-NG
./configure
make
sudo make install
Dotconfig generation
ct-ng list-samples
ct-ng show-aarch64-unknown-linux-gnu
ct-ng aarch64-unknown-linux-gnu
# Save current config to defconfig
ct-ng savedefconfig
cat defconfig
CT_CONFIG_VERSION="4"
CT_LOCAL_TARBALLS_DIR="${HOME}/cross/src"
CT_USE_MIRROR=y
CT_MIRROR_BASE_URL="https://mirrors.ustc.edu.cn/gnu"
CT_ARCH_ARM=y
CT_ARCH_64=y
CT_TARGET_VENDOR=""
CT_TARGET_ALIAS="aarch64-linux-gnu"
CT_KERNEL_LINUX=y
CT_BINUTILS_LINKER_LD_GOLD=y
CT_BINUTILS_GOLD_THREADS=y
CT_BINUTILS_LD_WRAPPER=y
CT_BINUTILS_PLUGINS=y
CT_CC_GCC_LIBSANITIZER=y
CT_CC_LANG_CXX=y
CT_DEBUG_GDB=y
Generate toolchain
ct-ng build
# See build log
tail -f build.log
export PATH=$PATH:$HOME/x-tools/aarch64-unknown-linux-gnu/bin
aarch64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/fdbai/x-tools/aarch64-unknown-linux-gnu/libexec/gcc/aarch64-unknown-linux-gnu/13.2.0/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: /home/fdbai/projects/toolchain/crosstool-ng-1.26.0/.build/aarch64-unknown-linux-gnu/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=aarch64-unknown-linux-gnu --prefix=/home/fdbai/x-tools/aarch64-unknown-linux-gnu --exec_prefix=/home/fdbai/x-tools/aarch64-unknown-linux-gnu --with-sysroot=/home/fdbai/x-tools/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot --enable-languages=c,c++ --with-pkgversion='crosstool-NG 1.26.0' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --enable-libsanitizer --disable-libmpx --with-gmp=/home/fdbai/projects/toolchain/crosstool-ng-1.26.0/.build/aarch64-unknown-linux-gnu/buildtools --with-mpfr=/home/fdbai/projects/toolchain/crosstool-ng-1.26.0/.build/aarch64-unknown-linux-gnu/buildtools --with-mpc=/home/fdbai/projects/toolchain/crosstool-ng-1.26.0/.build/aarch64-unknown-linux-gnu/buildtools --with-isl=/home/fdbai/projects/toolchain/crosstool-ng-1.26.0/.build/aarch64-unknown-linux-gnu/buildtools --enable-lto --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/fdbai/x-tools/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot --enable-long-long
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (crosstool-NG 1.26.0)
The following two command can be used to extract config from existing toolchain:
ct-ng extractconfig <build.log > .config
bzcat build.log.bz2 | ct-ng extractconfig > .config