Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
# Put followings into /etc/crontab
# LANG=C.UTF-8
# LC_TIME=C
# 10 8 * * 1 root dt=`date +\%F.\%H-\%M` && tmux -L download-and-build-gcc-10-snapshot new-session -d "exec script -t -c 'exec sh /home/src/download-and-build-gcc-10-snapshot.sh' /home/src/download-and-build-gcc-10-snapshot.log.$dt 2> /home/src/download-and-build-gcc-10-snapshot.log.$dt.time"
set -x
set -e
GCC_SNAPSHOT_URL=http://ftp.tsukuba.wide.ad.jp/software/gcc/snapshots/LATEST-10/
WGET_FLAGS="--timeout 30 --waitretry 1 --tries 1024"
latest_source_package_file_name="`wget $WGET_FLAGS \"$GCC_SNAPSHOT_URL\" -O - | grep -Eo '^ *<tr><td><a href=\"gcc\\-10\\-[0-9]{8}\\.tar\\.xz\">gcc\\-10\\-[0-9]{8}\\.tar\\.xz</a></td>'`"
latest_source_package_file_name="${latest_source_package_file_name#*<a href=\"}"
latest_source_package_file_name="${latest_source_package_file_name%%\">*}"
source_directory_name="${latest_source_package_file_name%.tar.xz}"
if [ -f "/home/src/$latest_source_package_file_name" ]; then
printf "Source package %s is already downloaded\\n" "$latest_source_package_file_name" 1>&2
exit 0
fi
if [ -d "/home/src/$source_directory_name" ]; then
printf "Source directory %s already exists\\n" "$source_directory_name" 1>&2
exit 0
fi
cd /home/src/
wget $WGET_FLAGS "$GCC_SNAPSHOT_URL$latest_source_package_file_name"
tar -x -f "$latest_source_package_file_name"
if [ ! -d "$source_directory_name" ]; then
printf "Expected directory %s doesn't exist after extracting source package\\n" "$source_directory_name" 1>&2
exit 1
fi
sed -i -r -e "s/^([[:space:]]+)(hardcode_libdir_flag_spec[_a-zA-Z0-9]*=[\"'](\\\$\\{wl\\}){0,1}(\\-(rpath|blibpath|R)|\\+b ).+)/\\1#\\2/" -e "s/^([[:space:]]+)(runpath_var=[\"']{0,1}LD_RUN_PATH[\"']{0,1})/\\1#\\2/" -e 's/^([[:space:]]+)(hardcode_into_libs=yes)/\1#\2/' -e 's#( \-install_name )\\\$rpath/#\1#g' "$source_directory_name"/configure "$source_directory_name"/*/configure "$source_directory_name"/*/*/configure || true
sed -i s/need_relink=yes/need_relink=no/ "$source_directory_name"/ltmain.sh
mkdir "$source_directory_name-build"
cd "$source_directory_name-build"
# Use GCC 9.2 as bootstrap compiler
export PATH=/opt/gcc-9.2/bin:$PATH
export CC=gcc-9.2
export CXX=g++-9.2
"../$source_directory_name/configure" --prefix=/usr/local --sysconfdir=/etc --localstatedir=/var --libexecdir='${prefix}/lib' --enable-version-specific-runtime-libs --disable-rpath --with-system-zlib --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,fortran,lto --enable-plugin --enable-initfini-array --enable-gnu-indirect-function --program-suffix=${source_directory_name#gcc}
time make -j 31
make install prefix=/opt/$source_directory_name gxx_include_dir=/opt/$source_directory_name/include/c++/${source_directory_name#gcc-} libexecdir=/opt/$source_directory_name/lib
cd /opt/$source_directory_name/lib/gcc/x86_64-pc-linux-gnu/
mv lib64/libgcc_s.so.1 lib64/libgcc_s.so 10.0.0/
ln -s ../10.0.0/libgcc_s.so.1 ../10.0.0/libgcc_s.so lib64/
/opt/$source_directory_name/bin/$source_directory_name --version
/opt/$source_directory_name/bin/$source_directory_name -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment