2020-01-02 05:06:14 +03:00
|
|
|
#!/usr/bin/env bash
|
2019-05-15 21:05:18 +03:00
|
|
|
set -e
|
2020-05-06 18:40:06 +03:00
|
|
|
shopt -s globstar
|
2019-11-02 19:34:54 +03:00
|
|
|
# This file will need to be run in bash, for now.
|
|
|
|
|
2020-03-07 19:38:16 +03:00
|
|
|
|
|
|
|
# === CONFIGURATION AND SETUP ===
|
|
|
|
|
2019-04-15 16:16:47 +03:00
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
2019-11-02 19:34:54 +03:00
|
|
|
echo "$DIR"
|
2019-04-15 17:34:41 +03:00
|
|
|
|
2019-12-18 00:42:42 +03:00
|
|
|
ARCH=${ARCH:-"i686"}
|
|
|
|
TARGET="$ARCH-pc-serenity"
|
2019-04-15 16:16:47 +03:00
|
|
|
PREFIX="$DIR/Local"
|
2020-05-06 18:40:06 +03:00
|
|
|
BUILD=$(realpath "$DIR/../Build")
|
|
|
|
SYSROOT="$BUILD/Root"
|
2019-04-15 16:16:47 +03:00
|
|
|
|
2020-03-22 07:25:17 +03:00
|
|
|
MAKE="make"
|
|
|
|
MD5SUM="md5sum"
|
|
|
|
NPROC="nproc"
|
2020-01-02 05:06:14 +03:00
|
|
|
|
2020-05-11 07:11:26 +03:00
|
|
|
# Each cache entry is 260 MB. 8 entries are 4 GiB.
|
|
|
|
# It seems that Travis starts having trouble at 35 entries, so I think this is a good amount.
|
|
|
|
KEEP_CACHE_COUNT=8
|
|
|
|
|
2020-03-22 07:25:17 +03:00
|
|
|
if [ "$(uname -s)" = "OpenBSD" ]; then
|
2020-01-02 05:06:14 +03:00
|
|
|
MAKE=gmake
|
|
|
|
MD5SUM="md5 -q"
|
|
|
|
NPROC="sysctl -n hw.ncpuonline"
|
|
|
|
export CC=egcc
|
|
|
|
export CXX=eg++
|
|
|
|
export with_gmp=/usr/local
|
|
|
|
export LDFLAGS=-Wl,-z,notext
|
2020-03-22 07:25:17 +03:00
|
|
|
elif [ "$(uname -s)" = "FreeBSD" ]; then
|
2020-03-21 11:46:30 +03:00
|
|
|
MAKE=gmake
|
|
|
|
MD5SUM="md5 -q"
|
|
|
|
NPROC="sysctl -n hw.ncpu"
|
2020-01-02 05:06:14 +03:00
|
|
|
fi
|
|
|
|
|
2020-04-27 11:03:27 +03:00
|
|
|
git_patch=
|
|
|
|
while [ "$1" != "" ]; do
|
|
|
|
case $1 in
|
|
|
|
--dev ) git_patch=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2019-11-02 19:34:54 +03:00
|
|
|
echo PREFIX is "$PREFIX"
|
|
|
|
echo SYSROOT is "$SYSROOT"
|
2019-05-08 16:50:24 +03:00
|
|
|
|
2019-04-15 16:16:47 +03:00
|
|
|
mkdir -p "$DIR/Tarballs"
|
2019-04-25 20:28:10 +03:00
|
|
|
|
2019-12-18 00:42:42 +03:00
|
|
|
BINUTILS_VERSION="2.33.1"
|
2019-12-19 20:43:31 +03:00
|
|
|
BINUTILS_MD5SUM="1a6b16bcc926e312633fcc3fae14ba0a"
|
2019-12-18 00:42:42 +03:00
|
|
|
BINUTILS_NAME="binutils-$BINUTILS_VERSION"
|
|
|
|
BINUTILS_PKG="${BINUTILS_NAME}.tar.gz"
|
|
|
|
BINUTILS_BASE_URL="http://ftp.gnu.org/gnu/binutils"
|
|
|
|
|
2020-05-16 07:52:49 +03:00
|
|
|
GCC_VERSION="10.1.0"
|
|
|
|
GCC_MD5SUM="8a9fbd7e24d04c5d36e96bc894d3cd6b"
|
2019-12-18 00:42:42 +03:00
|
|
|
GCC_NAME="gcc-$GCC_VERSION"
|
|
|
|
GCC_PKG="${GCC_NAME}.tar.gz"
|
|
|
|
GCC_BASE_URL="http://ftp.gnu.org/gnu/gcc"
|
|
|
|
|
2020-03-07 19:38:16 +03:00
|
|
|
|
|
|
|
# === CHECK CACHE AND REUSE ===
|
|
|
|
|
|
|
|
pushd "$DIR"
|
|
|
|
if [ "${TRY_USE_LOCAL_TOOLCHAIN}" = "y" ] ; then
|
|
|
|
echo "Checking cached toolchain:"
|
|
|
|
|
|
|
|
DEPS_CONFIG="
|
|
|
|
uname=$(uname),TARGET=${TARGET},
|
|
|
|
BuildItHash=$($MD5SUM $(basename $0)),
|
|
|
|
MAKE=${MAKE},MD5SUM=${MD5SUM},NPROC=${NPROC},
|
|
|
|
CC=${CC},CXX=${CXX},with_gmp=${with_gmp},LDFLAGS=${LDFLAGS},
|
|
|
|
BINUTILS_VERSION=${BINUTILS_VERSION},BINUTILS_MD5SUM=${BINUTILS_MD5SUM},
|
|
|
|
GCC_VERSION=${GCC_VERSION},GCC_MD5SUM=${GCC_MD5SUM}"
|
|
|
|
echo "Config is:${DEPS_CONFIG}"
|
2020-03-22 07:25:17 +03:00
|
|
|
if ! DEPS_HASH=$("$DIR/ComputeDependenciesHash.sh" "$MD5SUM" <<<"${DEPS_CONFIG}"); then
|
2020-03-07 19:38:16 +03:00
|
|
|
echo "Dependency hashing failed"
|
|
|
|
echo "Will rebuild toolchain from scratch, and NOT SAVE THE RESULT."
|
|
|
|
echo "Someone should look into this, but for now it'll work, albeit inefficient."
|
|
|
|
# Should be empty anyway, but just to make sure:
|
|
|
|
DEPS_HASH=""
|
|
|
|
elif [ -r "Cache/ToolchainLocal_${DEPS_HASH}.tar.gz" ] ; then
|
|
|
|
echo "Cache at Cache/ToolchainLocal_${DEPS_HASH}.tar.gz exists!"
|
|
|
|
echo "Extracting toolchain from cache:"
|
|
|
|
tar xzf "Cache/ToolchainLocal_${DEPS_HASH}.tar.gz"
|
|
|
|
echo "Done 'building' the toolchain."
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "Cache at Cache/ToolchainLocal_${DEPS_HASH}.tar.gz does not exist."
|
|
|
|
echo "Will rebuild toolchain from scratch, and save the result."
|
2020-05-11 07:11:26 +03:00
|
|
|
echo "But first, getting rid of old, outdated caches. Current caches:"
|
|
|
|
pushd "Cache/"
|
|
|
|
ls -l
|
|
|
|
# Travis preserves timestamps. Don't ask me why, but it does.
|
|
|
|
# We can exploit this to get an easy approximation of recent-ness.
|
|
|
|
# Our purging algorithm is simple: keep only the newest X entries.
|
|
|
|
ls -t | tail "-n+${KEEP_CACHE_COUNT}" | xargs -r rm -v
|
|
|
|
echo "After deletion:"
|
|
|
|
ls -l
|
|
|
|
popd
|
2020-03-07 19:38:16 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
popd
|
|
|
|
|
|
|
|
|
|
|
|
# === DOWNLOAD AND PATCH ===
|
|
|
|
|
2019-04-15 16:16:47 +03:00
|
|
|
pushd "$DIR/Tarballs"
|
2020-01-02 05:06:14 +03:00
|
|
|
md5="$($MD5SUM $BINUTILS_PKG | cut -f1 -d' ')"
|
2019-05-08 16:50:24 +03:00
|
|
|
echo "bu md5='$md5'"
|
2019-12-18 00:42:42 +03:00
|
|
|
if [ ! -e $BINUTILS_PKG ] || [ "$md5" != ${BINUTILS_MD5SUM} ] ; then
|
|
|
|
rm -f $BINUTILS_PKG
|
|
|
|
wget "$BINUTILS_BASE_URL/$BINUTILS_PKG"
|
2019-04-15 17:34:41 +03:00
|
|
|
else
|
|
|
|
echo "Skipped downloading binutils"
|
2019-04-15 16:16:47 +03:00
|
|
|
fi
|
|
|
|
|
2020-01-02 05:06:14 +03:00
|
|
|
md5="$($MD5SUM ${GCC_PKG} | cut -f1 -d' ')"
|
2019-05-08 16:50:24 +03:00
|
|
|
echo "gc md5='$md5'"
|
2019-12-18 00:42:42 +03:00
|
|
|
if [ ! -e $GCC_PKG ] || [ "$md5" != ${GCC_MD5SUM} ] ; then
|
|
|
|
rm -f $GCC_PKG
|
|
|
|
wget "$GCC_BASE_URL/$GCC_NAME/$GCC_PKG"
|
2019-04-15 17:34:41 +03:00
|
|
|
else
|
|
|
|
echo "Skipped downloading gcc"
|
2019-04-15 16:16:47 +03:00
|
|
|
fi
|
|
|
|
|
2019-12-18 00:42:42 +03:00
|
|
|
if [ ! -d ${BINUTILS_NAME} ]; then
|
2019-04-15 17:34:41 +03:00
|
|
|
echo "Extracting binutils..."
|
2020-01-02 05:06:14 +03:00
|
|
|
tar -xzf ${BINUTILS_PKG}
|
2019-04-15 16:16:47 +03:00
|
|
|
|
2019-12-18 00:42:42 +03:00
|
|
|
pushd ${BINUTILS_NAME}
|
2020-04-27 11:03:27 +03:00
|
|
|
if [ "$git_patch" = "1" ]; then
|
|
|
|
git init > /dev/null
|
|
|
|
git add . > /dev/null
|
|
|
|
git commit -am "BASE" > /dev/null
|
|
|
|
git apply "$DIR"/Patches/binutils.patch > /dev/null
|
|
|
|
else
|
|
|
|
patch -p1 < "$DIR"/Patches/binutils.patch > /dev/null
|
|
|
|
fi
|
2019-04-15 16:16:47 +03:00
|
|
|
popd
|
2019-04-15 17:34:41 +03:00
|
|
|
else
|
|
|
|
echo "Skipped extracting binutils"
|
2019-04-15 16:16:47 +03:00
|
|
|
fi
|
|
|
|
|
2019-12-18 00:42:42 +03:00
|
|
|
if [ ! -d $GCC_NAME ]; then
|
2019-04-15 17:34:41 +03:00
|
|
|
echo "Extracting gcc..."
|
2020-01-02 05:06:14 +03:00
|
|
|
tar -xzf $GCC_PKG
|
2019-12-18 00:42:42 +03:00
|
|
|
pushd $GCC_NAME
|
2020-04-27 11:03:27 +03:00
|
|
|
if [ "$git_patch" = "1" ]; then
|
|
|
|
git init > /dev/null
|
|
|
|
git add . > /dev/null
|
|
|
|
git commit -am "BASE" > /dev/null
|
|
|
|
git apply "$DIR"/Patches/gcc.patch > /dev/null
|
|
|
|
else
|
2020-05-16 07:52:49 +03:00
|
|
|
patch -p1 < "$DIR/Patches/gcc.patch" > /dev/null
|
2020-04-27 11:03:27 +03:00
|
|
|
fi
|
2019-04-15 16:16:47 +03:00
|
|
|
popd
|
2019-04-15 17:34:41 +03:00
|
|
|
else
|
|
|
|
echo "Skipped extracting gcc"
|
2019-04-15 16:16:47 +03:00
|
|
|
fi
|
2019-12-25 17:21:23 +03:00
|
|
|
|
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
|
|
pushd "gcc-${GCC_VERSION}"
|
|
|
|
./contrib/download_prerequisites
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2019-04-15 16:16:47 +03:00
|
|
|
popd
|
|
|
|
|
|
|
|
|
2020-03-07 19:38:16 +03:00
|
|
|
# === COMPILE AND INSTALL ===
|
|
|
|
|
|
|
|
mkdir -p "$PREFIX"
|
2019-04-15 16:16:47 +03:00
|
|
|
mkdir -p "$DIR/Build/binutils"
|
|
|
|
mkdir -p "$DIR/Build/gcc"
|
|
|
|
|
2019-05-15 21:08:23 +03:00
|
|
|
if [ -z "$MAKEJOBS" ]; then
|
2020-01-02 05:06:14 +03:00
|
|
|
MAKEJOBS=$($NPROC)
|
2019-05-15 21:08:23 +03:00
|
|
|
fi
|
|
|
|
|
2019-04-15 16:16:47 +03:00
|
|
|
pushd "$DIR/Build/"
|
|
|
|
unset PKG_CONFIG_LIBDIR # Just in case
|
|
|
|
|
|
|
|
pushd binutils
|
2019-12-18 00:42:42 +03:00
|
|
|
"$DIR"/Tarballs/binutils-2.33.1/configure --prefix="$PREFIX" \
|
2019-11-11 22:07:44 +03:00
|
|
|
--target="$TARGET" \
|
|
|
|
--with-sysroot="$SYSROOT" \
|
2019-12-27 16:26:25 +03:00
|
|
|
--enable-shared \
|
2019-11-11 22:07:44 +03:00
|
|
|
--disable-nls || exit 1
|
2019-12-28 19:53:14 +03:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
|
|
# under macOS generated makefiles are not resolving the "intl"
|
|
|
|
# dependency properly to allow linking its own copy of
|
|
|
|
# libintl when building with --enable-shared.
|
2020-01-02 05:06:14 +03:00
|
|
|
"$MAKE" -j "$MAKEJOBS" || true
|
2019-12-28 19:53:14 +03:00
|
|
|
pushd intl
|
2020-01-02 05:06:14 +03:00
|
|
|
"$MAKE" all-yes
|
2019-12-28 19:53:14 +03:00
|
|
|
popd
|
|
|
|
fi
|
2020-01-02 05:06:14 +03:00
|
|
|
"$MAKE" -j "$MAKEJOBS" || exit 1
|
|
|
|
"$MAKE" install || exit 1
|
2019-04-15 16:16:47 +03:00
|
|
|
popd
|
|
|
|
|
|
|
|
pushd gcc
|
2020-03-22 07:25:17 +03:00
|
|
|
if [ "$(uname -s)" = "OpenBSD" ]; then
|
|
|
|
perl -pi -e 's/-no-pie/-nopie/g' "$DIR/Tarballs/gcc-$GCC_VERSION/gcc/configure"
|
2020-01-02 05:06:14 +03:00
|
|
|
fi
|
|
|
|
|
2020-03-22 07:25:17 +03:00
|
|
|
"$DIR/Tarballs/gcc-$GCC_VERSION/configure" --prefix="$PREFIX" \
|
2019-11-11 22:07:44 +03:00
|
|
|
--target="$TARGET" \
|
|
|
|
--with-sysroot="$SYSROOT" \
|
|
|
|
--disable-nls \
|
|
|
|
--with-newlib \
|
2019-12-27 16:26:25 +03:00
|
|
|
--enable-shared \
|
2019-11-11 22:07:44 +03:00
|
|
|
--enable-languages=c,c++ || exit 1
|
2019-04-15 17:34:41 +03:00
|
|
|
|
2019-05-08 16:50:24 +03:00
|
|
|
echo "XXX build gcc and libgcc"
|
2020-01-02 05:06:14 +03:00
|
|
|
"$MAKE" -j "$MAKEJOBS" all-gcc all-target-libgcc || exit 1
|
2019-05-08 16:50:24 +03:00
|
|
|
echo "XXX install gcc and libgcc"
|
2020-01-02 05:06:14 +03:00
|
|
|
"$MAKE" install-gcc install-target-libgcc || exit 1
|
2019-04-17 18:29:45 +03:00
|
|
|
|
2020-05-20 15:23:30 +03:00
|
|
|
echo "XXX serenity libc and libm"
|
|
|
|
mkdir -p "$BUILD"
|
|
|
|
pushd "$BUILD"
|
|
|
|
cmake ..
|
|
|
|
"$MAKE" LibC
|
|
|
|
install -D Libraries/LibC/libc.a Libraries/LibM/libm.a Libraries/LibCxx/libstdc++.a Root/usr/lib/
|
|
|
|
SRC_ROOT=$(realpath "$DIR"/..)
|
|
|
|
for header in "$SRC_ROOT"/Libraries/Lib{C,M}/**/*.h; do
|
|
|
|
target=$(echo "$header" | sed -e "s@$SRC_ROOT/Libraries/LibC@@" -e "s@$SRC_ROOT/Libraries/LibM@@")
|
|
|
|
install -D "$header" "Root/usr/include/$target"
|
|
|
|
done
|
|
|
|
unset SRC_ROOT
|
|
|
|
popd
|
|
|
|
|
2020-03-22 07:25:17 +03:00
|
|
|
if [ "$(uname -s)" = "OpenBSD" ]; then
|
|
|
|
cd "$DIR/Local/libexec/gcc/i686-pc-serenity/$GCC_VERSION" && ln -sf liblto_plugin.so.0.0 liblto_plugin.so
|
2020-01-02 05:06:14 +03:00
|
|
|
fi
|
2020-05-06 18:40:06 +03:00
|
|
|
|
2019-04-15 16:16:47 +03:00
|
|
|
popd
|
2019-04-29 16:09:57 +03:00
|
|
|
popd
|
|
|
|
|
2020-03-07 19:38:16 +03:00
|
|
|
|
|
|
|
# == SAVE TO CACHE ==
|
|
|
|
|
|
|
|
pushd "$DIR"
|
|
|
|
if [ "${TRY_USE_LOCAL_TOOLCHAIN}" = "y" ] ; then
|
|
|
|
# TODO: Compress with -z. It's factor 3, and costs no time.
|
|
|
|
echo "Caching toolchain:"
|
|
|
|
|
|
|
|
if [ -z "${DEPS_HASH}" ] ; then
|
|
|
|
echo "NOT SAVED, because hashing failed."
|
|
|
|
echo "It's computed in the beginning; see there for the error message."
|
|
|
|
elif [ -e "Cache/ToolchainLocal_${DEPS_HASH}.tar.gz" ] ; then
|
|
|
|
# Note: This checks for *existence*. Initially we checked for
|
|
|
|
# *readability*. If Travis borks permissions, there's not much we can do.
|
|
|
|
echo "Cache exists but was not used?!"
|
|
|
|
echo "Not touching cache then."
|
|
|
|
else
|
|
|
|
mkdir -p Cache/
|
|
|
|
tar czf "Cache/ToolchainLocal_${DEPS_HASH}.tar.gz" Local/
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
popd
|