|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -o errexit |
| 4 | +set -o pipefail |
| 5 | +set -o xtrace |
| 6 | + |
| 7 | +JOBS="$(getconf _NPROCESSORS_ONLN)" |
| 8 | + |
| 9 | +case "$1" in |
| 10 | +x86_64) |
| 11 | + SYSROOT_MACH='i386' |
| 12 | + ;; |
| 13 | +*) |
| 14 | + printf 'ERROR: unknown architecture: %s\n' "$1" |
| 15 | + exit 1 |
| 16 | +esac |
| 17 | + |
| 18 | +BUILD_TARGET="$1-sun-solaris2.10" |
| 19 | + |
| 20 | +# |
| 21 | +# NOTE: The compiler version selected here is more specific than might appear. |
| 22 | +# GCC 7.X releases do not appear to cross-compile correctly for Solaris |
| 23 | +# targets, at least insofar as they refuse to enable TLS in libstdc++. When |
| 24 | +# changing the GCC version in future, one must carefully verify that TLS is |
| 25 | +# enabled in all of the static libraries we intend to include in output |
| 26 | +# binaries. |
| 27 | +# |
| 28 | +GCC_VERSION='8.4.0' |
| 29 | +GCC_MD5='bb815a8e3b7be43c4a26fa89dbbd9795' |
| 30 | +GCC_BASE="gcc-$GCC_VERSION" |
| 31 | +GCC_TAR="gcc-$GCC_VERSION.tar.xz" |
| 32 | +GCC_URL="https://ftp.gnu.org/gnu/gcc/$GCC_BASE/$GCC_TAR" |
| 33 | + |
| 34 | +SYSROOT_VER='20181213-de6af22ae73b-v1' |
| 35 | +SYSROOT_MD5='23462f7f5297f390803d27c424c32ad6' |
| 36 | +SYSROOT_TAR="illumos-sysroot-$SYSROOT_MACH-$SYSROOT_VER.tar.gz" |
| 37 | +SYSROOT_URL='https://github.com/illumos/sysroot/releases/download/' |
| 38 | +SYSROOT_URL+="$SYSROOT_VER/$SYSROOT_TAR" |
| 39 | +SYSROOT_DIR='/ws/sysroot' |
| 40 | + |
| 41 | +BINUTILS_VERSION='2.25.1' |
| 42 | +BINUTILS_MD5='ac493a78de4fee895961d025b7905be4' |
| 43 | +BINUTILS_BASE="binutils-$BINUTILS_VERSION" |
| 44 | +BINUTILS_TAR="$BINUTILS_BASE.tar.bz2" |
| 45 | +BINUTILS_URL="https://ftp.gnu.org/gnu/binutils/$BINUTILS_TAR" |
| 46 | + |
| 47 | + |
| 48 | +download_file() { |
| 49 | + local file="$1" |
| 50 | + local url="$2" |
| 51 | + local md5="$3" |
| 52 | + |
| 53 | + while :; do |
| 54 | + if [[ -f "$file" ]]; then |
| 55 | + if ! h="$(md5sum "$file" | awk '{ print $1 }')"; then |
| 56 | + printf 'ERROR: reading hash\n' >&2 |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + |
| 60 | + if [[ "$h" == "$md5" ]]; then |
| 61 | + return 0 |
| 62 | + fi |
| 63 | + |
| 64 | + printf 'WARNING: hash mismatch: %s != expected %s\n' \ |
| 65 | + "$h" "$md5" >&2 |
| 66 | + rm -f "$file" |
| 67 | + fi |
| 68 | + |
| 69 | + printf 'Downloading: %s\n' "$url" |
| 70 | + if ! curl -f -L -o "$file" "$url"; then |
| 71 | + rm -f "$file" |
| 72 | + sleep 1 |
| 73 | + fi |
| 74 | + done |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | +case "$2" in |
| 79 | +sysroot) |
| 80 | + download_file "/tmp/$SYSROOT_TAR" "$SYSROOT_URL" "$SYSROOT_MD5" |
| 81 | + mkdir -p "$SYSROOT_DIR" |
| 82 | + cd "$SYSROOT_DIR" |
| 83 | + tar -xzf "/tmp/$SYSROOT_TAR" |
| 84 | + rm -f "/tmp/$SYSROOT_TAR" |
| 85 | + ;; |
| 86 | + |
| 87 | +binutils) |
| 88 | + download_file "/tmp/$BINUTILS_TAR" "$BINUTILS_URL" "$BINUTILS_MD5" |
| 89 | + mkdir -p /ws/src/binutils |
| 90 | + cd /ws/src/binutils |
| 91 | + tar -xjf "/tmp/$BINUTILS_TAR" |
| 92 | + rm -f "/tmp/$BINUTILS_TAR" |
| 93 | + |
| 94 | + mkdir -p /ws/build/binutils |
| 95 | + cd /ws/build/binutils |
| 96 | + "/ws/src/binutils/$BINUTILS_BASE/configure" \ |
| 97 | + --target="$BUILD_TARGET" \ |
| 98 | + --with-sysroot="$SYSROOT_DIR" |
| 99 | + |
| 100 | + make -j "$JOBS" |
| 101 | + make install |
| 102 | + |
| 103 | + cd / |
| 104 | + rm -rf /ws/src/binutils /ws/build/binutils |
| 105 | + ;; |
| 106 | + |
| 107 | +gcc) |
| 108 | + download_file "/tmp/$GCC_TAR" "$GCC_URL" "$GCC_MD5" |
| 109 | + mkdir -p /ws/src/gcc |
| 110 | + cd /ws/src/gcc |
| 111 | + tar -xJf "/tmp/$GCC_TAR" |
| 112 | + rm -f "/tmp/$GCC_TAR" |
| 113 | + |
| 114 | + mkdir -p /ws/build/gcc |
| 115 | + cd /ws/build/gcc |
| 116 | + export CFLAGS='-fPIC' |
| 117 | + export CXXFLAGS='-fPIC' |
| 118 | + export CXXFLAGS_FOR_TARGET='-fPIC' |
| 119 | + export CFLAGS_FOR_TARGET='-fPIC' |
| 120 | + "/ws/src/gcc/$GCC_BASE/configure" \ |
| 121 | + --target="$BUILD_TARGET" \ |
| 122 | + --with-sysroot="$SYSROOT_DIR" \ |
| 123 | + --with-gnu-as \ |
| 124 | + --with-gnu-ld \ |
| 125 | + --disable-nls \ |
| 126 | + --disable-libgomp \ |
| 127 | + --disable-libquadmath \ |
| 128 | + --disable-libssp \ |
| 129 | + --disable-libvtv \ |
| 130 | + --disable-libcilkrts \ |
| 131 | + --disable-libada \ |
| 132 | + --disable-libsanitizer \ |
| 133 | + --disable-libquadmath-support \ |
| 134 | + --disable-shared \ |
| 135 | + --enable-tls |
| 136 | + |
| 137 | + make -j "$JOBS" |
| 138 | + make install |
| 139 | + |
| 140 | + cd / |
| 141 | + rm -rf /ws/src/gcc /ws/build/gcc |
| 142 | + ;; |
| 143 | + |
| 144 | +*) |
| 145 | + printf 'ERROR: unknown phase "%s"\n' "$1" >&2 |
| 146 | + exit 100 |
| 147 | + ;; |
| 148 | +esac |
0 commit comments