Skip to content

Instantly share code, notes, and snippets.

@siddhesh
Last active July 9, 2025 20:43
Show Gist options
  • Select an option

  • Save siddhesh/df3d26938cbd08d4877c91872e3d0eec to your computer and use it in GitHub Desktop.

Select an option

Save siddhesh/df3d26938cbd08d4877c91872e3d0eec to your computer and use it in GitHub Desktop.
My build and bootstrap test script. this does a ubsan bootstrap (to test __bdos with itself), x86_64 bootstrap and test, i686 build and test and a few cross build targets to generate a cc1 for quick testing.
#!/bin/bash
worktree_root=$HOME/src/upstream/gcc/
if [ -z $1 ]; then
echo "Usage: $0 <git commit ref> [targets]"
exit 1
fi
ref=$1
shift
if [ -z $1 ]; then
targets="i686 x86_64 ubsan"
else
targets="$@"
fi
LANGUAGES="--enable-languages=c,c++,fortran,lto"
COMMON_CONFIG_FLAGS="$LANGUAGES --enable-sanitizers --enable-shared --with-system-zlib"
cross_config() {
target=$1
if [ "x$1" = "xppc64le" ]; then
build_target="powerpc64le-linux-gnu"
else
build_target="$target-linux-gnu"
fi
sysroot="/usr/$target-redhat-linux/sys-root/fc42"
echo "--enable-languages=c,c++ --includedir=$sysroot/usr/include --libdir=$sysroot/usr/lib64 --with-build-sysroot=$sysroot/ --target=$build_target --disable-bootstrap --disable-libsanitizer --disable-multilib"
}
get_configure_flags() {
case "$target" in
i686)
echo "$COMMON_CONFIG_FLAGS i686-linux --with-fpmath=sse --disable-bootstrap"
;;
cross-*)
cross_config $(echo $target | sed 's/cross-//')
;;
ubsan)
echo "$COMMON_CONFIG_FLAGS --with-build-config=bootstrap-ubsan --disable-multilib"
;;
*)
echo "$COMMON_CONFIG_FLAGS --enable-bootstrap"
;;
esac
}
make_args() {
target=$1
case "$target" in
cross-*)
echo "SUBDIRS=gcc"
;;
*)
echo ""
;;
esac
}
skip_test() {
target=$1
case "$target" in
ubsan)
echo true
;;
cross-*)
echo true
;;
*)
echo false
;;
esac
}
if [ ! -d gcc-$ref ]; then
echo "Worktree gcc-$ref not set up yet. Do that first."
exit 1
fi
build_one() {
target=$1
../configure $(get_configure_flags $target) > build.log 2>&1 && \
make -j$(nproc) $(make_args) >> build.log 2>&1
if [ $? -ne 0 ]; then
echo "Build for $target failed, see $PWD/build.log for details"
return
fi
if $(skip_test $target); then
echo "skipping tests for $target"
else
echo "running tests for $target"
make -j$(nproc) check > /dev/null 2>&1
echo "Copying over test results for $target"
mkdir -p $worktree_root/testresults/$ref
find gcc/testsuite -name "*.log" | while read f; do
cp -f $f $worktree_root/testresults/$ref/
done
fi
echo "$target done"
}
build_target() {
target=$1
builddir=build-$target
rm -rf $builddir
mkdir $builddir
pushd $builddir
echo "Building for $target"
time build_one $target
popd # $builddir
}
pushd gcc-$ref
# Get the actual branch name. For 15 for example, it'll be releases/gcc-15.
ref=$(git branch --show-current)
git remote update -p
if git branch -a | grep remotes/origin/$ref; then
base=$ref
else
# Jiska koi baap nahi hota, uska baap bhagvaan hota hai...
base="master"
fi
git rebase origin/$base
# Sync with my github. It's my github and not a canonical source of truth for
# anybody, so force rewriting is OK.
git push github +$ref
for t in $targets; do
build_target $t
done
wait # wait for all builds to finish
popd # gcc-$ref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment