From 6c2b3b74d3be4903ef9b9cd77fde9b2199edcadc Mon Sep 17 00:00:00 2001 From: Jeremy Bennett Date: Tue, 13 Aug 2024 16:25:20 +0100 Subject: [PATCH] Add scripts to build tools. * EXPECTED_BRANCHES: Created. * README.md: Add instructions for cloning repos and building tools. * build-all.sh: Created. * checkout-all.sh: Created. * clone-all.sh: Created. Signed-off-by: Jeremy Bennett --- EXPECTED_BRANCHES | 19 ++ README.md | 100 ++++++++- build-all.sh | 529 ++++++++++++++++++++++++++++++++++++++++++++++ checkout-all.sh | 111 ++++++++++ clone-all.sh | 116 ++++++++++ 5 files changed, 873 insertions(+), 2 deletions(-) create mode 100644 EXPECTED_BRANCHES create mode 100755 build-all.sh create mode 100755 checkout-all.sh create mode 100755 clone-all.sh diff --git a/EXPECTED_BRANCHES b/EXPECTED_BRANCHES new file mode 100644 index 0000000..fc972fe --- /dev/null +++ b/EXPECTED_BRANCHES @@ -0,0 +1,19 @@ +#!/bin/bash +# +# This file defines the branches that the build script should +# check for and which the checkout and clone scripts use. It is +# sourced by other scripts. +# +# Copyright (C) 2022 Embecosm Limited + +# Contributor: Edward Jones + +# SPDX-License-Identifier: GPL-3.0-or-later + +BINUTILS_BRANCH=binutils-2_42 +GDB_BRANCH=gdb-14.2-release +GCC_BRANCH=releases/gcc-14.1.0 +LLVM_BRANCH=llvmorg-18.1.5 +GLIBC_BRANCH=glibc-2.39 +TOOLCHAIN_BRANCH=master +QEMU_BRANCH=master diff --git a/README.md b/README.md index 7f3da4a..64db27e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,98 @@ -# rise-rvv-tcg-qemu-tooling -A set of convenience scripts for building and benchmarking QEMU for RISC-V with RVV +# Tooling for the RISE RVV QEMU project + +A set of convenience scripts for building and benchmarking QEMU for RISC-V +with RVV + +## Assumptions + +The scripts work on a top level directory structure of +``` +- build where out-of-tree build artifacts are placed +- install where tools etc are installed +- qemu the QEMU source tree +- riscv-gnu-toolchain The RISC-V infrastructure for building tool chains +- rise-rvv-tcg-qemu-tooling this repository +- speccpu2017 SPEC CPU 2017 source +``` + +Alongside are the following directories if the compiler tools are being built +``` +- binutils The binutils-gdb repository +- gcc The gcc repository +- gdb The binutils-gdb repository +- glibc The glibc repository +- linux The Linux kernel repository +- llvm-project The LLVM project repository +``` +However it should be noted that most users will not use this, but will instead +use pre-built tool chains. **Note.** There are separate checkouts for the +binutils-gdb repository, to allow different versions for GDB and binutils to +be built. + +## Cloning the repos + +Initially clone this repository and change into it. From this directory the +following command will check out the core repositories using the hierarchy +above. +``` +./clone-all.sh +``` + +If you wish to clone all the repositories to use for building tool chains, you +can use: +``` +./clone-all.sh --all +``` + +Don't worry if you already have some repos cloned, they'll just be skipped +with a warning. + +Once cloned, the repositories will be checked out to their default branches +for the project. + +## Checking out the correct branches/tags + +The following convenience script will check out the default tag/branches for +any of the above repositories which have been cloned. +``` +./checkout-all.sh +``` +An optional argument, `--pull` will pull the repositories after they have been +checked out, but beware of using this if any of the defaults are tags rather +than branches. + +For this project, a convenience options `--qemu-checkout ` can be used to +override the default branch used for QEMU. + +If you plan to build the tool chains, the default checkouts are for release +tool chains as follows: +- GCC 14.1 +- LLVM 18.1.5 +- binutils 2.42 +- GDB 14.2 +- Glibc 2.39 + +## Building QEMU + +QEMU can be built using the `--build-all.sh` script. +``` +./build-all.sh --qemu-only +``` +**Note.** If you omit the `--qemu-only` argument, the entire tool GCC compiler +tool chain will attempt to be built. + +## Building the entire compiler tool chain (optional) + +If you wish to build the entire tool chain, this can be achieved with the +`build-all.sh` script: +``` +./build-all.sh --qemu-only +``` + +This will build a GCC tool chain. + +The `--build-clang` option will also build a Clang/LLVM tool chain. The +`--build-gdbserver` option will also build the Linux GDB server program. + +Various other options can be used to fine-tune the build. You can use the +`--help` option to see all these. diff --git a/build-all.sh b/build-all.sh new file mode 100755 index 0000000..a4fba6a --- /dev/null +++ b/build-all.sh @@ -0,0 +1,529 @@ +#!/bin/bash + +# Script to build the RISC-V GNU tool chain + +# Copyright (C) 2009, 2013, 2014, 2015, 2016, 2017, 2022, 2023, 2024 Embecosm Limited +# Contributor Jeremy Bennett + +# This file is part of the Embecosm GNU toolchain build system for RISC-V. + +# SPDX-License-Identifier: GPL-3.0-or-later + +set -u + +usage () { + cat <] : Target architecture. Default + architecture is rv64gc + [--abi ] : Target ABI. Default ABI is lp64d + [--tune ] : Target tuning. Default tuning is + unset + [--multilib-linux [scalar | vector] Type of multilib to build. + [--disable-multilib] : Disable multilibs + [--hashes] : Print to hashes.txt the hashes of + the HEAD commits of each tool in + the tool chain + [--autoconf-version] : Version of autoconf to generate. + [--autoconf-temp-dir] : Build/install directory for autoconf. + [--clean] : Delete build directories in + riscv-gnu-toolchain and the install + directory before building + [--help] : Print this message and exit +EOF +} + +TOPDIR="$(dirname $(cd $(dirname $0) && echo $PWD))" +actmpdir=$(mktemp -d -p /tmp build-all-ac-XXXXXX) + +INSTALLDIR=${TOPDIR}/install +BUILDDIR=${TOPDIR}/build +LOGDIR=${TOPDIR}/logs + +DEFAULTARCH=rv64gc +DEFAULTTUNE= +DEFAULTABI=lp64d +DEFAULTTRIPLE=riscv64-unknown-elf + +build_linux=true +qemu_only=false +build_gdbserver=false +build_clang=false +clean_build=false +enable_multilib=true +print_help=false +print_hashes=false +autoconf_version="" +autoconf_temp_dir="" + +TARGETARCH="${DEFAULTARCH}" +TARGETTUNE="${DEFAULTTUNE}" +TARGETABI="${DEFAULTABI}" +TARGETTRIPLE="${DEFAULTTRIPLE}" + +# Fixed set of permitted multilibs +SCALAR_MULTILIB_LINUX="rv32gc-ilp32d rv64gc-lp64d" +VECTOR_MULTILIB_LINUX="rv32gcv-ilp32d rv64gcv-lp64d" +SCALAR_MULTILIB_OPTIONS="march=rv32gc/march=rv64gc/ mabi=ilp32d/mabi=lp64d" +VECTOR_MULTILIB_OPTIONS="march=rv32gcv/march=rv64gcv/ mabi=ilp32d/mabi=lp64d" +SCALAR_MULTILIB_DIRNAMES="rv32gc rv64gc ilp32d lp64d" +VECTOR_MULTILIB_DIRNAMES="rv32gcv rv64gcv ilp32d lp64d" +SCALAR_MULTILIB_REQUIRED="march=rv32gc/mabi=ilp32d march=rv64gc/mabi=lp64d" +VECTOR_MULTILIB_REQUIRED="march=rv32gcv/mabi=ilp32d march=rv64gcv/mabi=lp64d" + +EXTRA_OPTS="" +EXTRA_LLVM_OPTS="" +EXTRA_CFLAGS="" +MULTILIB_LINUX="${SCALAR_MULTILIB_LINUX}" +MULTILIB_OPTIONS="${SCALAR_MULTILIB_OPTIONS}" +MULTILIB_DIRNAMES="${SCALAR_MULTILIB_DIRNAMES}" +MULTILIB_REQUIRED="${SCALAR_MULTILIB_REQUIRED}" + +# Parse command line options +set +u +until + opt="$1" + case "${opt}" in + --prefix) + shift + INSTALLDIR="$1" + ;; + --arch) + shift + TARGETARCH="$1" + ;; + --tune) + shift + TARGETTUNE="$1" + ;; + --abi) + shift + TARGETABI="$1" + ;; + --build-elf) + build_linux=false + ;; + --qemu-only) + qemu_only=true + ;; + --build-gdbserver) + build_gdbserver=true + ;; + --build-clang) + build_clang=true + ;; + --disable-multilib) + enable_multilib=false + ;; + --multilib-generator) + shift + MULTILIB_ELF="$1" + ;; + --multilib-linux) + shift + case "x$1" in + scalar|Scalar|SCALAR) + MULTILIB_LINUX="${SCALAR_MULTILIB_LINUX}" + MULTILIB_OPTIONS="${SCALAR_MULTILIB_OPTIONS}" + MULTILIB_DIRNAMES="${SCALAR_MULTILIB_DIRNAMES}" + MULTILIB_REQUIRED="${SCALAR_MULTILIB_REQUIRED}" + ;; + vector|Vector|VECTOR) + MULTILIB_LINUX="${VECTOR_MULTILIB_LINUX}" + MULTILIB_OPTIONS="${VECTOR_MULTILIB_OPTIONS}" + MULTILIB_DIRNAMES="${VECTOR_MULTILIB_DIRNAMES}" + MULTILIB_REQUIRED="${VECTOR_MULTILIB_REQUIRED}" + ;; + *) + echo "Unknown Linux multilib type: $1" + ;; + esac + ;; + --hashes) + print_hashes=true + ;; + --autoconf-version) + shift + autoconf_version="$1" + ;; + --autoconf-temp-dir) + shift + autoconf_temp_dir="$1" + ;; + --clean) + clean_build=true + ;; + --help) + print_help=true + ;; + ?*) + echo "Unknown argument '$1'" + exit 1 + ;; + *) + ;; + esac +[ "x${opt}" = "x" ] +do + shift +done +set -u + +if ${print_help} +then + usage + exit 1 +fi + +echo "Logging in: ${LOGDIR}" +mkdir -p ${LOGDIR} + +# Function to build a version of autoconf +# - $1: The version to build +# - $2: A directory in which to build and install +getautoconf () { + if [[ "x$1" == "x" || "x$2" == "x" ]] + then + echo "Usage: $0 " >&2 + return 1 + fi + v="$1" + d="$2" + pushd ${d} + wget http://ftp.gnu.org/gnu/autoconf/autoconf-${v}.tar.gz + tar xf autoconf-${v}.tar.gz + mkdir build + pushd build + ../autoconf-${v}/configure --prefix="${d}/install" + make -j + make install + popd + popd +} + +# Sanity check the autoconf version + +if ! ${qemu_only} +then + if ! autoconf --version | grep -q '2.69' + then + log_file="${LOGDIR}/build-autoconf.log" + echo "Building autoconf 2.69... logging to ${log_file}" + getautoconf "2.69" ${actmpdir} > ${log_file} 2>&1 + PATH=${actmpdir}/install/bin:$PATH + fi +fi + +# Print the GCC and G++ used in this build +which gcc +which g++ + +if ${qemu_only} +then + build_linux=false + build_gdbserver=false + build_clang=false + enable_multilib=false +fi + +echo +echo "Build plan:" +echo " arch: ${TARGETARCH}" +echo " tune: ${TARGETTUNE}" +echo " abi: ${TARGETABI}" +if ${build_linux} +then + echo " build linux: yes" + EXTRA_OPTS="${EXTRA_OPTS} --enable-linux" + TARGETTRIPLE="riscv64-unknown-linux-gnu" + if ${enable_multilib} + then + sed -i -r -e "s/\[AC_SUBST\(glibc_multilib_names,\"rv.*\"\)\]/\[AC_SUBST\(glibc_multilib_names,\"$MULTILIB_LINUX\"\)\]/g" $TOPDIR/riscv-gnu-toolchain/configure.ac + cd $TOPDIR/riscv-gnu-toolchain + autoconf + cd - > /dev/null 2>&1 + # Hack to fix up broken multilibs + cd ${TOPDIR}/gcc/gcc/config/riscv > /dev/null 2>&1 + mv t-linux-multilib t-linux-multilib.orig + touch t-linux-multilib + echo "MULTILIB_OPTIONS = ${MULTILIB_OPTIONS}" >> t-linux-multilib + echo "MULTILIB_DIRNAMES = ${MULTILIB_DIRNAMES}" >> t-linux-multilib + echo "MULTILIB_REQUIRED = ${MULTILIB_REQUIRED}" >> t-linux-multilib + cd - > /dev/null 2>&1 + fi +else + echo " build linux: no" +fi +if ${enable_multilib} +then + echo " multilib: yes" + EXTRA_OPTS="${EXTRA_OPTS} --enable-multilib" +else + echo " multilib: no" + EXTRA_OPTS="${EXTRA_OPTS} --disable-multilib" +fi +echo " build qemu: yes" +if ${build_gdbserver} +then + echo " build gdbserver: yes" +else + echo " build gdbserver: no" +fi +if ${build_clang} +then + echo " build Clang: yes" +else + echo " build Clang: no" +fi + +cd $TOPDIR/riscv-gnu-toolchain + +log_file="${LOGDIR}/clean-toolchain.log" +if ${clean_build} +then + echo + echo "Cleaning... logging to ${log_file}" + # We need to configure in case we have a broken existing configuration + ( + set -ex + rm -f config.status + ./configure + ) > ${log_file} 2>&1 + if [ $? -ne 0 ]; then + echo "Error configuring for cleaning, check log file!" >&2 + exit 1 + fi + + ( + make -j $(nproc) clean + ) > ${log_file} 2>&1 + if [ $? -ne 0 ]; then + echo "Error cleaning, check log file!" >&2 + exit 1 + fi + + rm -rf ${BUILDDIR}/* + # Don't blow away SPEC installations + rm -rf ${INSTALLDIR}/{bin,include,lib*,risc*,share,sysroot} +fi + +echo +echo "Building in: $TOPDIR/riscv-gnu-toolchain/" +echo "Installing in: ${INSTALLDIR}" + +if ! ${qemu_only} +then + log_file="${LOGDIR}/configure-toolchain.log" + echo "Configuring Tool Chain... logging to ${log_file}" + ( + # export EXTRA_CFLAGS="${EXTRA_CFLAGS} -mavx" + set -ex + ./configure \ + --with-arch=$TARGETARCH --with-tune=$TARGETTUNE --with-abi=$TARGETABI \ + --prefix=$INSTALLDIR \ + --with-gcc-src=$TOPDIR/gcc \ + --with-binutils-src=$TOPDIR/binutils \ + --with-newlib-src=$TOPDIR/newlib \ + --with-glibc-src=$TOPDIR/glibc \ + --with-gdb-src=$TOPDIR/gdb \ + --with-cmodel=medany \ + ${EXTRA_OPTS} + ) > ${log_file} 2>&1 + if [ $? -ne 0 ]; then + echo "Error configuring, check log file!" >&2 + exit 1 + fi +fi +# --with-qemu-src=$TOPDIR/qemu \ + +if ! ${qemu_only} +then + log_file="${LOGDIR}/build-toolchain.log" + echo "Building Tool Chain... logging to ${log_file}" + ( + make -j $(nproc) + ) > ${log_file} 2>&1 + if [ $? -ne 0 ]; then + echo "Error building, check log file!" >&2 + exit 1 + fi +fi + +# No need to configure the QEMU targets as the default ones are already +# riscv32-linux-user and riscv64-linux-user. +log_file="${LOGDIR}/build-qemu.log" +echo "Building QEMU... logging to ${log_file}" +( + mkdir -p ${BUILDDIR}/qemu + cd ${BUILDDIR}/qemu + $TOPDIR/qemu/configure --prefix=$INSTALLDIR \ + --target-list=riscv64-linux-user,riscv32-linux-user \ + --interp-prefix=$INSTALLDIR/sysroot \ + --python=python3 \ + --extra-cflags="-Wno-error" + make -j $(nproc) + make install +) > ${log_file} 2>&1 +if [ $? -ne 0 ]; then + echo "Error building, check log file!" >&2 + exit 1 +fi + +# Clang +if ${build_clang} +then + mkdir -p ${LOGDIR} + log_file="${LOGDIR}/configure-clang.log" + echo "Configuring Clang... logging to ${log_file}" + ( + # Attempt to identify the host architecture, and include this in the + # build + if [ "$(arch)" == "arm64" ]; then + LLVM_NATIVE_ARCH="AArch64" + else + LLVM_NATIVE_ARCH="X86" + fi + + # Location of the binutils repository in order to pass the linker + # plugin header to LLVM's build system + BINUTILS_DIR="${TOPDIR}/binutils" + + # Build and install it + set -e + mkdir -p ${BUILDDIR}/llvm + set -x + cd ${BUILDDIR}/llvm + cmake -G"Unix Makefiles" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${INSTALLDIR} \ + -DLLVM_ENABLE_PROJECTS=clang\;lld \ + -DLLVM_ENABLE_PLUGINS=ON \ + -DLLVM_BINUTILS_INCDIR=${BINUTILS_DIR}/include \ + -DLLVM_DISTRIBUTION_COMPONENTS=clang\;clang-resource-headers\;lld\;llvm-ar\;llvm-cov\;llvm-cxxfilt\;llvm-dwp\;llvm-ranlib\;llvm-nm\;llvm-objcopy\;llvm-objdump\;llvm-readobj\;llvm-size\;llvm-strings\;llvm-strip\;llvm-profdata\;llvm-symbolizer\;LLVMgold \ + -DLLVM_PARALLEL_LINK_JOBS=5 \ + -DLLVM_TARGETS_TO_BUILD=${LLVM_NATIVE_ARCH}\;RISCV \ + -DDEFAULT_SYSROOT=${INSTALLDIR}/sysroot \ + ${EXTRA_LLVM_OPTS} \ + ${TOPDIR}/llvm-project/llvm + ) > ${log_file} 2>&1 + if [ $? -ne 0 ]; then + echo "Error configuring Clang, check log file!" >&2 + exit 1 + fi + + log_file="${LOGDIR}/build-clang.log" + echo "Building Clang... logging to ${log_file}" + ( + cd ${BUILDDIR}/llvm + make -j$(nproc) + make install-distribution + + # Add symlinks to LLVM tools + cd ${INSTALLDIR}/bin + for TOOL in clang clang++; do + ln -sv clang riscv64-unknown-linux-gnu-${TOOL} + done + ) > ${log_file} 2>&1 + if [ $? -ne 0 ]; then + echo "Error building Clang, check log file!" >&2 + exit 1 + fi +fi + +PATH=${INSTALLDIR}/bin:$PATH + +if ${build_gdbserver} +then + log_file="${LOGDIR}/configure-gdbserver.log" + echo "Configuring gdbserver... logging to ${log_file}" + ( + set -e + mkdir -p ${BUILDDIR}/gdbserver + set -x + cd ${BUILDDIR}/gdbserver + ../../gdb/configure \ + CC="${TARGETTRIPLE}-gcc -static" \ + CXX="${TARGETTRIPLE}-g++ -static" \ + --prefix=${INSTALLDIR} \ + --cache-file=/dev/null \ + --disable-bfd \ + --disable-binutils \ + --disable-gas \ + --disable-gdb \ + --disable-gold \ + --disable-gprof \ + --disable-ld \ + --disable-libctf \ + --disable-libdecnumber \ + --disable-opcodes \ + --disable-readline \ + --disable-sim \ + --host=${TARGETTRIPLE} \ + ${EXTRA_OPTS} + ) > ${log_file} 2>&1 + if [ $? -ne 0 ]; then + echo "Error configuring gdbserver, check log file!" >&2 + exit 1 + fi + + log_file="${LOGDIR}/build-gdbserver.log" + echo "Building gdbserver... logging to ${log_file}" + ( + cd ${BUILDDIR}/gdbserver + make -j $(nproc) + make install + ) > ${log_file} 2>&1 + if [ $? -ne 0 ]; then + echo "Error building gdbserver, check log file!" >&2 + exit 1 + fi +fi + +if $print_hashes +then + hashes_file="$TOPDIR/hashes.txt" + echo "Printing hashes to $hashes_file" + cd $TOPDIR/binutils + BINUTILS_HASH=$(git rev-parse HEAD) + cd $TOPDIR/gdb + GDB_HASH=$(git rev-parse HEAD) + cd $TOPDIR/gcc + GCC_HASH=$(git rev-parse HEAD) + cd $TOPDIR/newlib + NEWLIB_HASH=$(git rev-parse HEAD) + cd $TOPDIR/glibc + GLIBC_HASH=$(git rev-parse HEAD) + + cd $TOPDIR + echo "binutils: $BINUTILS_HASH" >> ${hashes_file} + echo "gdb: $GDB_HASH" >> ${hashes_file} + echo "gcc: $GCC_HASH" >> ${hashes_file} + echo "newlib: $NEWLIB_HASH" >> ${hashes_file} + echo "glibc: $GLIBC_HASH" >> ${hashes_file} +fi + +echo "Cleaning up" + +pushd $TOPDIR/riscv-gnu-toolchain > /dev/null 2>&1 +if ! git checkout configure configure.ac > /dev/null 2>&1 +then + echo "Unable to restore configure and configure.ac in riscv-gnu-toolchain" + echo "- manual restoration recommended." +fi +popd > /dev/null 2>&1 + +cd ${TOPDIR}/gcc/gcc/config/riscv > /dev/null 2>&1 +if [[ -e t-linux-multilib.orig ]] +then + rm -f t-linux-multilib + mv t-linux-multilib.orig t-linux-multilib +fi +cd - > /dev/null 2>&1 + +rm -rf ${actmpdir} + +echo "Build completed successfully." diff --git a/checkout-all.sh b/checkout-all.sh new file mode 100755 index 0000000..34193a0 --- /dev/null +++ b/checkout-all.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +# Checkout script for the RISC-V tool chain + +# Copyright (C) 2009, 2013-2017, 2022-2024 Embecosm Limited +# Contributor Jeremy Bennett + +# This file is part of the Embecosm GNU toolchain build system for RISC-V. + +# SPDX-License-Identifier: GPL-3.0-or-later + +# Invocation Syntax + +# checkout-all.sh [--pull] + +# Argument meanings: + +# --pull Pull the respositories as well as checking them out. + +# Parse arg + +do_pull=false +qemu_checkout="" + +usage () { + cat <] : Checkout a specific version of QEMU. + [--help] : Print this message and exit. +EOF +} + +set +u +until + opt="$1" + case "${opt}" in + --pull) + do_pull=true + ;; + --qemu-checkout) + shift + qemu_checkout="$1" + ;; + --help) + usage + ;; + ?*) + echo "Unknown argument '$1'" + exit 1 + ;; + *) + ;; + esac +[ "x${opt}" = "x" ] +do + shift +done +set -u + +# Import the default branches +source EXPECTED_BRANCHES + +if [ -z "${qemu_checkout}" ] +then + qemu_checkout="${QEMU_BRANCH}" +fi + +# Set the top level directory. +topdir=$(cd $(dirname $0)/..;pwd) + +repos="binutils:${BINUTILS_BRANCH} \ + gdb:${GDB_BRANCH} \ + gcc:${GCC_BRANCH} \ + llvm-project:${LLVM_BRANCH} \ + glibc:${GLIBC_BRANCH} \ + qemu:${qemu_checkout} \ + riscv-gnu-toolchain:${TOOLCHAIN_BRANCH} " + +# Some repos may be missing in a minimal checkout. Silently ignore missing +# repos. +for r in ${repos} +do + tool=$(echo ${r} | cut -d ':' -f 1) + branch=$(echo ${r} | cut -d ':' -f 2) + + if [[ -d ${topdir}/${tool} ]] + then + cd ${topdir}/${tool} + # Ignore failed fetches (may be offline) + + printf "%-14s fetching... " "${tool}:" + git fetch --all > /dev/null 2>&1 || true + + # Checkout the branch. Not sure what happens if the branch is in + # mutliple remotes. + + echo -n "checking out ${branch} ... " + git checkout ${branch} > /dev/null 2>&1 || true + + # Pull to the latest if requested. + if ${do_pull} + then + echo -n "pulling..." + git pull > /dev/null 2>&1 || true + fi + + # Repo done + echo + fi +done diff --git a/clone-all.sh b/clone-all.sh new file mode 100755 index 0000000..8d20dff --- /dev/null +++ b/clone-all.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +# Clone script for the RISC-V tool chain +# +# Copyright (C) 2009, 2013, 2014, 2015, 2016, 2017, 2022, 2023, 2024 Embecosm Limited +# Contributor Jeremy Bennett +# +# This file is part of the Embecosm GNU toolchain build system for RISC-V. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# Invoke with: +# +# ./clone-all.sh + +# Function to print a help message +usage () { + cat <] : QEMU URL to clone from. + [--help] : Print this message and exit. + +--qemu-url is particularly useful to specify a SSH repo link to faciliate +writing to the repository. +EOF +} + +# Function to only clone if not already there. +# $1 URL +# $2 directory +cloneit () { + if [[ -e "$2" ]] + then + echo "$2 already cloned?" + else + git clone $1 $2 + fi +} + +# Set flags +minimal=true + +# Set the top level directory. +tooldir=$(cd $(dirname $0);pwd) +topdir=$(cd $(dirname $0)/..;pwd) + +# Set the URLs which hold the repos +KERNEL_URL=git://git.kernel.org/pub/scm +GCC_URL=git://gcc.gnu.org/git +LLVM_URL=https://github.com/llvm +SOURCEWARE_URL=git://sourceware.org/git +TOOLCHAIN_URL=https://github.com/riscv +QEMU_URL=https://github.com/embecosm + +# Set the specific repos +binutils_repo=${SOURCEWARE_URL}/binutils-gdb.git +gdb_repo=${SOURCEWARE_URL}/binutils-gdb.git +gcc_repo=${GCC_URL}/gcc.git +llvm_repo=${LLVM_URL}/llvm-project.git +glibc_repo=${SOURCEWARE_URL}/glibc.git +linux_repo=${KERNEL_URL}/linux/kernel/git/torvalds/linux.git +qemu_repo=${QEMU_URL}/rise-rvv-tcg-qemu.git +rv_toolchain_repo=${TOOLCHAIN_URL}/riscv-gnu-toolchain.git + +set +u +until + opt="$1" + case "${opt}" in + --all) + minimal=false + ;; + --minimal) + minimal=true + ;; + --qemu-url) + shift + qemu_repo="$1" + ;; + --help) + usage + exit 0 + ;; + ?*) + echo "Unknown argument '$1'" + usage + exit 1 + ;; + *) + ;; + esac +[ "x${opt}" = "x" ] +do + shift +done +set -u + +cd ${topdir} + +# Toolchain repos +cloneit ${qemu_repo} qemu +cloneit ${rv_toolchain_repo} riscv-gnu-toolchain + +if ! ${minimal} +then + cloneit ${binutils_repo} binutils + cloneit ${gdb_repo} gdb + cloneit ${gcc_repo} gcc + cloneit ${llvm_repo} llvm-project + cloneit ${glibc_repo} glibc + cloneit ${linux_repo} linux +fi + +# Get the right branches +cd ${tooldir} +./checkout-all.sh