2020-01-02 05:06:14 +03:00
|
|
|
#!/usr/bin/env bash
|
2021-05-27 09:02:57 +03:00
|
|
|
set -eo pipefail
|
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 )"
|
|
|
|
|
2023-04-24 21:24:22 +03:00
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "${DIR}/../Meta/shell_include.sh"
|
|
|
|
|
2023-06-12 11:23:56 +03:00
|
|
|
exit_if_running_as_root "Do not run BuildGNU.sh as root, your Build directory will become root-owned"
|
2023-04-24 21:24:22 +03:00
|
|
|
|
2019-11-02 19:34:54 +03:00
|
|
|
echo "$DIR"
|
2019-04-15 17:34:41 +03:00
|
|
|
|
2022-10-02 20:55:22 +03:00
|
|
|
ARCH=${ARCH:-"x86_64"}
|
2019-12-18 00:42:42 +03:00
|
|
|
TARGET="$ARCH-pc-serenity"
|
2020-12-29 06:38:52 +03:00
|
|
|
PREFIX="$DIR/Local/$ARCH"
|
2021-03-07 22:37:29 +03:00
|
|
|
BUILD="$DIR/../Build/$ARCH"
|
2020-05-06 18:40:06 +03:00
|
|
|
SYSROOT="$BUILD/Root"
|
2019-04-15 16:16:47 +03:00
|
|
|
|
2020-03-22 07:25:17 +03:00
|
|
|
MAKE="make"
|
|
|
|
MD5SUM="md5sum"
|
2020-12-29 02:36:15 +03:00
|
|
|
REALPATH="realpath"
|
2020-01-02 05:06:14 +03:00
|
|
|
|
2020-07-09 00:57:51 +03:00
|
|
|
if command -v ginstall &>/dev/null; then
|
|
|
|
INSTALL=ginstall
|
|
|
|
else
|
|
|
|
INSTALL=install
|
|
|
|
fi
|
|
|
|
|
2021-04-18 15:45:26 +03:00
|
|
|
SYSTEM_NAME="$(uname -s)"
|
|
|
|
|
2021-04-17 22:28:02 +03:00
|
|
|
# We *most definitely* don't need debug symbols in the linker/compiler.
|
|
|
|
# This cuts the uncompressed size from 1.2 GiB per Toolchain down to about 120 MiB.
|
|
|
|
# Hence, this might actually cause marginal speedups, although the point is to not waste space as blatantly.
|
2021-05-21 14:22:39 +03:00
|
|
|
export CFLAGS="-g0 -O2 -mtune=native"
|
|
|
|
export CXXFLAGS="-g0 -O2 -mtune=native"
|
2021-04-17 22:28:02 +03:00
|
|
|
|
2021-04-18 15:45:26 +03:00
|
|
|
if [ "$SYSTEM_NAME" = "OpenBSD" ]; then
|
2020-01-02 05:06:14 +03:00
|
|
|
MAKE=gmake
|
|
|
|
MD5SUM="md5 -q"
|
2020-12-29 02:36:15 +03:00
|
|
|
REALPATH="readlink -f"
|
2020-01-02 05:06:14 +03:00
|
|
|
export CC=egcc
|
|
|
|
export CXX=eg++
|
|
|
|
export with_gmp=/usr/local
|
|
|
|
export LDFLAGS=-Wl,-z,notext
|
2021-04-18 15:45:26 +03:00
|
|
|
elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then
|
2020-03-21 11:46:30 +03:00
|
|
|
MAKE=gmake
|
|
|
|
MD5SUM="md5 -q"
|
2020-10-17 23:25:13 +03:00
|
|
|
export with_gmp=/usr/local
|
|
|
|
export with_mpfr=/usr/local
|
2023-01-09 03:08:28 +03:00
|
|
|
elif [ "$SYSTEM_NAME" = "Darwin" ]; then
|
|
|
|
MD5SUM="md5 -q"
|
2020-01-02 05:06:14 +03:00
|
|
|
fi
|
|
|
|
|
2020-12-29 02:36:15 +03:00
|
|
|
# On at least OpenBSD, the path must exist to call realpath(3) on it
|
|
|
|
if [ ! -d "$BUILD" ]; then
|
|
|
|
mkdir -p "$BUILD"
|
|
|
|
fi
|
|
|
|
BUILD=$($REALPATH "$BUILD")
|
|
|
|
|
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
|
|
|
|
2023-09-04 08:48:49 +03:00
|
|
|
BINUTILS_VERSION="2.41"
|
|
|
|
BINUTILS_MD5SUM="256d7e0ad998e423030c84483a7c1e30"
|
2019-12-18 00:42:42 +03:00
|
|
|
BINUTILS_NAME="binutils-$BINUTILS_VERSION"
|
2023-05-03 21:04:54 +03:00
|
|
|
BINUTILS_PKG="${BINUTILS_NAME}.tar.xz"
|
2023-05-28 11:28:03 +03:00
|
|
|
BINUTILS_BASE_URL="https://ftpmirror.gnu.org/gnu/binutils"
|
2019-12-18 00:42:42 +03:00
|
|
|
|
2021-04-27 10:25:02 +03:00
|
|
|
# Note: If you bump the gcc version, you also have to update the matching
|
|
|
|
# GCC_VERSION variable in the project's root CMakeLists.txt
|
2023-08-01 18:14:43 +03:00
|
|
|
GCC_VERSION="13.2.0"
|
|
|
|
GCC_MD5SUM="e0e48554cc6e4f261d55ddee9ab69075"
|
2019-12-18 00:42:42 +03:00
|
|
|
GCC_NAME="gcc-$GCC_VERSION"
|
2023-05-03 21:04:54 +03:00
|
|
|
GCC_PKG="${GCC_NAME}.tar.xz"
|
2023-05-28 11:28:03 +03:00
|
|
|
GCC_BASE_URL="https://ftpmirror.gnu.org/gnu/gcc"
|
2019-12-18 00:42:42 +03:00
|
|
|
|
2021-04-18 03:35:16 +03:00
|
|
|
buildstep() {
|
|
|
|
NAME=$1
|
|
|
|
shift
|
2021-04-18 18:25:46 +03:00
|
|
|
"$@" 2>&1 | sed $'s|^|\x1b[34m['"${NAME}"$']\x1b[39m |'
|
2021-04-18 03:35:16 +03:00
|
|
|
}
|
|
|
|
|
2021-05-30 11:48:47 +03:00
|
|
|
# === DEPENDENCIES ===
|
|
|
|
buildstep dependencies echo "Checking whether 'make' is available..."
|
|
|
|
if ! command -v ${MAKE:-make} >/dev/null; then
|
|
|
|
buildstep dependencies echo "Please make sure to install GNU Make (for the '${MAKE:-make}' tool)."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
buildstep dependencies echo "Checking whether 'patch' is available..."
|
|
|
|
if ! command -v patch >/dev/null; then
|
|
|
|
buildstep dependencies echo "Please make sure to install GNU patch (for the 'patch' tool)."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
buildstep dependencies echo "Checking whether your C compiler works..."
|
|
|
|
if ! ${CC:-cc} -o /dev/null -xc - >/dev/null <<'PROGRAM'
|
|
|
|
int main() {}
|
|
|
|
PROGRAM
|
|
|
|
then
|
|
|
|
buildstep dependencies echo "Please make sure to install a working C compiler."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$SYSTEM_NAME" != "Darwin" ]; then
|
|
|
|
for lib in gmp mpc mpfr; do
|
|
|
|
buildstep dependencies echo "Checking whether the $lib library and headers are available..."
|
|
|
|
if ! ${CC:-cc} -I /usr/local/include -L /usr/local/lib -l$lib -o /dev/null -xc - >/dev/null <<PROGRAM
|
|
|
|
#include <$lib.h>
|
|
|
|
int main() {}
|
|
|
|
PROGRAM
|
|
|
|
then
|
|
|
|
echo "Please make sure to install the $lib library and headers."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2020-03-07 19:38:16 +03:00
|
|
|
# === DOWNLOAD AND PATCH ===
|
2019-04-15 16:16:47 +03:00
|
|
|
pushd "$DIR/Tarballs"
|
2021-05-27 09:02:57 +03:00
|
|
|
md5=""
|
|
|
|
if [ -e "$BINUTILS_PKG" ]; then
|
|
|
|
md5="$($MD5SUM $BINUTILS_PKG | cut -f1 -d' ')"
|
2022-08-23 09:52:23 +03:00
|
|
|
echo "binutils md5='$md5'"
|
2021-05-27 09:02:57 +03:00
|
|
|
fi
|
|
|
|
if [ "$md5" != ${BINUTILS_MD5SUM} ] ; then
|
2019-12-18 00:42:42 +03:00
|
|
|
rm -f $BINUTILS_PKG
|
2020-06-18 17:31:12 +03:00
|
|
|
curl -LO "$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
|
|
|
|
|
2021-05-27 09:02:57 +03:00
|
|
|
md5=""
|
|
|
|
if [ -e "$GCC_PKG" ]; then
|
|
|
|
md5="$($MD5SUM ${GCC_PKG} | cut -f1 -d' ')"
|
2022-08-23 09:51:40 +03:00
|
|
|
echo "gcc md5='$md5'"
|
2021-05-27 09:02:57 +03:00
|
|
|
fi
|
|
|
|
if [ "$md5" != ${GCC_MD5SUM} ] ; then
|
2019-12-18 00:42:42 +03:00
|
|
|
rm -f $GCC_PKG
|
2020-06-18 17:31:12 +03:00
|
|
|
curl -LO "$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
|
|
|
|
|
2022-09-27 00:28:31 +03:00
|
|
|
patch_md5="$(${MD5SUM} "${DIR}"/Patches/binutils/*.patch)"
|
|
|
|
|
|
|
|
if [ ! -d "${BINUTILS_NAME}" ] || [ "$(cat ${BINUTILS_NAME}/.patch.applied)" != "${patch_md5}" ]; then
|
|
|
|
if [ -d ${BINUTILS_NAME} ]; then
|
|
|
|
rm -rf "${BINUTILS_NAME}"
|
|
|
|
rm -rf "${DIR}/Build/${ARCH}/${BINUTILS_NAME}"
|
2021-02-21 21:20:29 +03:00
|
|
|
fi
|
2022-09-27 00:28:31 +03:00
|
|
|
echo "Extracting binutils..."
|
2023-05-03 21:04:54 +03:00
|
|
|
tar -xJf ${BINUTILS_PKG}
|
2022-09-27 00:28:31 +03:00
|
|
|
|
|
|
|
pushd ${BINUTILS_NAME}
|
|
|
|
if [ "${git_patch}" = "1" ]; then
|
|
|
|
git init > /dev/null
|
|
|
|
git add . > /dev/null
|
|
|
|
git commit -am "BASE" > /dev/null
|
|
|
|
git am "${DIR}"/Patches/binutils/*.patch > /dev/null
|
|
|
|
else
|
|
|
|
for patch in "${DIR}"/Patches/binutils/*.patch; do
|
|
|
|
patch -p1 < "${patch}" > /dev/null
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
${MD5SUM} "${DIR}"/Patches/binutils/*.patch > .patch.applied
|
|
|
|
popd
|
|
|
|
else
|
|
|
|
echo "Using existing binutils source directory"
|
2019-04-15 16:16:47 +03:00
|
|
|
fi
|
2022-09-27 00:28:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
patch_md5="$(${MD5SUM} "${DIR}"/Patches/gcc/*.patch)"
|
|
|
|
|
|
|
|
if [ ! -d "${GCC_NAME}" ] || [ "$(cat ${GCC_NAME}/.patch.applied)" != "${patch_md5}" ]; then
|
|
|
|
if [ -d ${GCC_NAME} ]; then
|
|
|
|
rm -rf "${GCC_NAME}"
|
|
|
|
rm -rf "${DIR}/Build/${ARCH}/${GCC_NAME}"
|
2021-02-21 21:20:29 +03:00
|
|
|
fi
|
2022-09-27 00:28:31 +03:00
|
|
|
echo "Extracting gcc..."
|
2023-05-03 21:04:54 +03:00
|
|
|
tar -xJf ${GCC_PKG}
|
2019-12-25 17:21:23 +03:00
|
|
|
|
2022-09-27 00:28:31 +03:00
|
|
|
pushd ${GCC_NAME}
|
|
|
|
if [ "${git_patch}" = "1" ]; then
|
|
|
|
git init > /dev/null
|
|
|
|
git add . > /dev/null
|
|
|
|
git commit -am "BASE" > /dev/null
|
|
|
|
git am --keep-non-patch "${DIR}"/Patches/gcc/*.patch > /dev/null
|
|
|
|
else
|
|
|
|
for patch in "${DIR}"/Patches/gcc/*.patch; do
|
|
|
|
patch -p1 < "${patch}" > /dev/null
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
${MD5SUM} "${DIR}"/Patches/gcc/*.patch > .patch.applied
|
|
|
|
|
|
|
|
if [ "${SYSTEM_NAME}" = "Darwin" ]; then
|
|
|
|
./contrib/download_prerequisites
|
|
|
|
fi
|
2019-12-25 17:21:23 +03:00
|
|
|
popd
|
2022-09-27 00:28:31 +03:00
|
|
|
else
|
|
|
|
echo "Using existing GCC source directory"
|
2019-12-25 17:21:23 +03:00
|
|
|
fi
|
2019-04-15 16:16:47 +03:00
|
|
|
popd
|
|
|
|
|
|
|
|
|
2020-03-07 19:38:16 +03:00
|
|
|
# === COMPILE AND INSTALL ===
|
|
|
|
|
2021-04-16 21:42:18 +03:00
|
|
|
rm -rf "$PREFIX"
|
2020-03-07 19:38:16 +03:00
|
|
|
mkdir -p "$PREFIX"
|
2019-04-15 16:16:47 +03:00
|
|
|
|
2023-05-02 22:05:04 +03:00
|
|
|
NPROC=$(get_number_of_processing_units)
|
|
|
|
[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC}
|
2019-05-15 21:08:23 +03:00
|
|
|
|
2021-04-16 21:42:18 +03:00
|
|
|
mkdir -p "$DIR/Build/$ARCH"
|
|
|
|
|
2020-12-29 06:38:52 +03:00
|
|
|
pushd "$DIR/Build/$ARCH"
|
2019-04-15 16:16:47 +03:00
|
|
|
unset PKG_CONFIG_LIBDIR # Just in case
|
|
|
|
|
2021-04-16 21:42:18 +03:00
|
|
|
rm -rf binutils
|
|
|
|
mkdir -p binutils
|
|
|
|
|
2019-04-15 16:16:47 +03:00
|
|
|
pushd binutils
|
2020-08-01 16:32:04 +03:00
|
|
|
echo "XXX configure binutils"
|
2022-03-12 13:19:18 +03:00
|
|
|
|
|
|
|
# We don't need the documentation that is being built, so
|
|
|
|
# don't force people to install makeinfo just for that.
|
|
|
|
export ac_cv_prog_MAKEINFO=true
|
|
|
|
|
2021-04-18 03:35:16 +03:00
|
|
|
buildstep "binutils/configure" "$DIR"/Tarballs/$BINUTILS_NAME/configure --prefix="$PREFIX" \
|
2020-10-12 12:52:58 +03:00
|
|
|
--target="$TARGET" \
|
|
|
|
--with-sysroot="$SYSROOT" \
|
|
|
|
--enable-shared \
|
|
|
|
--disable-nls \
|
2023-05-27 18:54:17 +03:00
|
|
|
${CI:+"--quiet"} || exit 1
|
2021-04-18 15:45:26 +03:00
|
|
|
if [ "$SYSTEM_NAME" = "Darwin" ]; then
|
2019-12-28 19:53:14 +03:00
|
|
|
# under macOS generated makefiles are not resolving the "intl"
|
|
|
|
# dependency properly to allow linking its own copy of
|
|
|
|
# libintl when building with --enable-shared.
|
2021-04-18 15:46:52 +03:00
|
|
|
buildstep "binutils/build" "$MAKE" -j "$MAKEJOBS" || true
|
2019-12-28 19:53:14 +03:00
|
|
|
pushd intl
|
2021-04-18 15:46:52 +03:00
|
|
|
buildstep "binutils/build" "$MAKE" all-yes
|
2019-12-28 19:53:14 +03:00
|
|
|
popd
|
|
|
|
fi
|
2020-08-01 16:32:04 +03:00
|
|
|
echo "XXX build binutils"
|
2022-11-05 02:25:26 +03:00
|
|
|
buildstep "binutils/build" "$MAKE" MAKEINFO=true -j "$MAKEJOBS" || exit 1
|
|
|
|
buildstep "binutils/install" "$MAKE" MAKEINFO=true install || exit 1
|
2019-04-15 16:16:47 +03:00
|
|
|
popd
|
|
|
|
|
2022-09-06 02:01:21 +03:00
|
|
|
echo "XXX serenity libc headers"
|
2021-04-16 21:42:18 +03:00
|
|
|
mkdir -p "$BUILD"
|
|
|
|
pushd "$BUILD"
|
|
|
|
mkdir -p Root/usr/include/
|
|
|
|
SRC_ROOT=$($REALPATH "$DIR"/..)
|
2022-02-26 00:28:06 +03:00
|
|
|
FILES=$(find \
|
|
|
|
"$SRC_ROOT"/Kernel/API \
|
|
|
|
"$SRC_ROOT"/Kernel/Arch \
|
|
|
|
"$SRC_ROOT"/Userland/Libraries/LibC \
|
2023-04-30 18:07:21 +03:00
|
|
|
"$SRC_ROOT"/Userland/Libraries/LibELF/ELFABI.h \
|
2023-04-29 23:50:54 +03:00
|
|
|
"$SRC_ROOT"/Userland/Libraries/LibRegex/RegexDefs.h \
|
2022-02-26 00:28:06 +03:00
|
|
|
-name '*.h' -print)
|
2021-04-16 21:42:18 +03:00
|
|
|
for header in $FILES; do
|
2022-02-26 00:28:06 +03:00
|
|
|
target=$(echo "$header" | sed \
|
2023-03-13 21:55:15 +03:00
|
|
|
-e "s|$SRC_ROOT/Userland/Libraries/LibC||" \
|
2023-04-29 23:50:54 +03:00
|
|
|
-e "s|$SRC_ROOT/Kernel/|Kernel/|" \
|
2023-04-30 18:07:21 +03:00
|
|
|
-e "s|$SRC_ROOT/Userland/Libraries/LibELF/|LibELF/|" \
|
2023-04-29 23:50:54 +03:00
|
|
|
-e "s|$SRC_ROOT/Userland/Libraries/LibRegex/|LibRegex/|")
|
2023-01-09 03:08:51 +03:00
|
|
|
buildstep "system_headers" mkdir -p "$(dirname "Root/usr/include/$target")"
|
|
|
|
buildstep "system_headers" $INSTALL "$header" "Root/usr/include/$target"
|
2021-04-16 21:42:18 +03:00
|
|
|
done
|
|
|
|
unset SRC_ROOT
|
|
|
|
popd
|
2020-01-02 05:06:14 +03:00
|
|
|
|
2021-04-18 15:45:26 +03:00
|
|
|
if [ "$SYSTEM_NAME" = "OpenBSD" ]; then
|
2021-04-16 21:42:18 +03:00
|
|
|
perl -pi -e 's/-no-pie/-nopie/g' "$DIR/Tarballs/gcc-$GCC_VERSION/gcc/configure"
|
|
|
|
fi
|
2020-05-20 15:23:30 +03:00
|
|
|
|
2021-07-06 13:36:18 +03:00
|
|
|
rm -rf gcc
|
|
|
|
mkdir -p gcc
|
|
|
|
|
|
|
|
pushd gcc
|
|
|
|
echo "XXX configure gcc and libgcc"
|
|
|
|
buildstep "gcc/configure" "$DIR/Tarballs/gcc-$GCC_VERSION/configure" --prefix="$PREFIX" \
|
|
|
|
--target="$TARGET" \
|
|
|
|
--with-sysroot="$SYSROOT" \
|
|
|
|
--disable-nls \
|
2023-05-26 21:24:02 +03:00
|
|
|
--disable-libstdcxx-pch \
|
2021-07-06 13:36:18 +03:00
|
|
|
--enable-shared \
|
2023-07-23 16:20:18 +03:00
|
|
|
--enable-languages=c,c++,objc,obj-c++ \
|
2021-07-06 13:36:18 +03:00
|
|
|
--enable-default-pie \
|
|
|
|
--enable-lto \
|
|
|
|
--enable-threads=posix \
|
2022-01-19 21:12:50 +03:00
|
|
|
--enable-initfini-array \
|
2022-01-19 21:18:10 +03:00
|
|
|
--with-linker-hash-style=gnu \
|
2023-05-27 18:54:17 +03:00
|
|
|
${CI:+"--quiet"} || exit 1
|
2021-07-06 13:36:18 +03:00
|
|
|
|
|
|
|
echo "XXX build gcc and libgcc"
|
|
|
|
buildstep "gcc/build" "$MAKE" -j "$MAKEJOBS" all-gcc || exit 1
|
|
|
|
buildstep "libgcc/build" "$MAKE" -j "$MAKEJOBS" all-target-libgcc || exit 1
|
|
|
|
echo "XXX install gcc and libgcc"
|
|
|
|
buildstep "gcc+libgcc/install" "$MAKE" install-gcc install-target-libgcc || exit 1
|
|
|
|
|
|
|
|
echo "XXX build libstdc++"
|
|
|
|
buildstep "libstdc++/build" "$MAKE" -j "$MAKEJOBS" all-target-libstdc++-v3 || exit 1
|
|
|
|
echo "XXX install libstdc++"
|
|
|
|
buildstep "libstdc++/install" "$MAKE" install-target-libstdc++-v3 || exit 1
|
|
|
|
popd
|
|
|
|
|
2019-04-29 16:09:57 +03:00
|
|
|
popd
|
|
|
|
|
2022-01-19 22:54:34 +03:00
|
|
|
pushd "$DIR/Local/$ARCH/$ARCH-pc-serenity/bin"
|
|
|
|
buildstep "mold_symlink" ln -s ../../../mold/bin/mold ld.mold
|
|
|
|
popd
|