Skip to content

Instantly share code, notes, and snippets.

@jwakely
Last active June 13, 2022 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwakely/95b3a790157f55d75e18f577e12b50d7 to your computer and use it in GitHub Desktop.
Save jwakely/95b3a790157f55d75e18f577e12b50d7 to your computer and use it in GitHub Desktop.
Script to build any version of GCC (since 3.4.x)
#!/bin/bash -ex
set -e
# baseurl=ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/
baseurl=ftp://sourceware.org/pub/
fetch() {
local ver=$1
local path=$( [[ $ver == ?.?.? ]] && echo releases/gcc-$ver || echo snapshots/$ver )
local file=gcc-${2:+$2-}$ver.tar.gz
[ -f $file ] || wget $baseurl/gcc/$path/$file
tar xf $file
#for p in $patches
#do
# ( cd gcc-$ver && curl "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=$p" | filterdiff -x '*/ChangeLog' | patch -p1 )
#done
}
fetch_src() {
local ver=$1
shift
[ -d gcc-$ver ] && return
for src in """$@"
do
fetch $ver $src
done
}
buildgcc() {
local ver=$1
shift
rm -rf build.$ver
mkdir build.$ver
cd build.$ver
STAGE1_CFLAGS="-O2 -g" ../gcc-$ver/configure --prefix=$HOME/gcc/$ver --with-system-zlib --with-gnu-ld --with-gnu-as --enable-libstdcxx-debug --disable-libitm --disable-libquadmath --disable-libmudflap --disable-libvtv --disable-libcilkrts --enable-languages=c,c++ "$@"
make -j ${MAKEJOBS:-2} # STAGE1_CFLAGS="-O2 -g -std=gnu89" STAGE1_CXXFLAGS="-O2 -g -std=gnu++98"
make install
cd ..
[[ $CLEAN ]] && rm -r build.$ver gcc-$ver
# Create link from x.y to x.y.0
if [[ $ver == *.[1-9].0 ]] && (( ${ver%.[1-9].0} >= 5 ))
then
test -e ~/gcc/${ver%.0} || ln -s $ver ~/gcc/${ver%.0}
fi
}
# 6.{2,1}.0 5.{4,3,2,1}.0 4.9.{4,3,2,1,0} 4.8.{5,4,3,2,1,0} 4.7.{4,3,2,1,0} 4.6.4 4.5.4 4.4.7
for ver
do
config=
case $ver in
[12].*|3.3.*) echo "$0: ancient versions not supported" >&2 ; exit 1 ;;
4.[0123456].*|3.*) fetch_src $ver core g++ ;;&
4.[01234].*) sed -i 's/struct siginfo/siginfo_t/' gcc-$ver/gcc/config/i386/linux-unwind.h ;;&
4.[2345678].*) config="MAKEINFO=missing" ;;&
4.9.[0123]) patches='8c3fa311caa86f61b4e28d1563d1110b44340fb2' ;;&
5.[123].*) patches='1e5f1089dec3af328fd03125d6778f666d0bd4e4' ;;&
4.[789].*|[56789].*) fetch_src $ver ;;&
4.8.*)
sed -i 's/struct ucontext/ucontext_t/' gcc-$ver/libgcc/config/i386/linux-unwind.h
sed -i '/<unistd.h>/a #include <signal.h>' gcc-$ver/libsanitizer/asan/asan_linux.cc
sed -i 's/__res_state/struct &/' gcc-$ver/libsanitizer/tsan/tsan_platform_linux.cc
;;&
# for ISL failures see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86724
esac
buildgcc $ver $config
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment