Skip to content

Instantly share code, notes, and snippets.

@siddhesh
Last active July 2, 2025 15:06
Show Gist options
  • Save siddhesh/8a900d4abc0218eed18ba01fbd3b2c25 to your computer and use it in GitHub Desktop.
Save siddhesh/8a900d4abc0218eed18ba01fbd3b2c25 to your computer and use it in GitHub Desktop.
Helper script to build a branch+target combination for gcc.
#!/bin/bash
worktree_root=$path_to/gcc-worktrees
gcc_root=$HOME/gcc
if [ -z $1 ]; then
echo "Usage: $0 <git commit ref> [target]"
exit 1
fi
ref=$1
if [ -z $2 ]; then
target="x86_64"
else
target="$2"
fi
case "$target" in
i686)
config="--enable-sanitizers --enable-clocale=gnu --with-system-zlib --enable-shared --enable-cet --with-demangler-in-ld --enable-libmpx i686-linux --with-fpmath=sse --disable-bootstrap"
runtest=true
;;
ubsan)
config="--with-build-config=bootstrap-ubsan --enable-languages=c,c++,fortran,lto --disable-multilib --enable-shared"
runtest=false
;;
*)
config="--enable-bootstrap --enable-languages=c,c++,fortran,lto --enable-sanitizers"
runtest=true
;;
esac
pushd $gcc_root
# First unlock and reset everything.
echo "Unlocking and resetting the old build."
worktree_path=$worktree_root/$ref-$target
git worktree remove -f $worktree_path
git worktree prune
rm -rf $worktree_path
echo "Deleting the old branch $ref-$target"
git branch -D $ref-$target
# Force update the remote branch
echo "Updating $ref"
git remote update -p
git branch -f $ref origin/$ref
# Now we start over.
echo "Set up worktree $worktree_path ($ref, $ref-$target)"
git worktree add -b $ref-$target $worktree_path $ref
pushd $worktree_path
echo "Off to the races! Start the build"
mkdir build && cd build
../configure $config && \
make -j$(nproc) > /dev/null && $runtest && \
make -j$(nproc) check > $worktree_root/check-$ref-$target.out 2>&1
popd # $worktree_path
popd # $gcc_root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment