2020-01-02 02:06:14 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-05-27 06:02:57 +00:00
|
|
|
set -eo pipefail
|
2019-11-02 16:34:54 +00:00
|
|
|
# This file will need to be run in bash, for now.
|
|
|
|
|
2020-03-07 16:38:16 +00:00
|
|
|
# === CONFIGURATION AND SETUP ===
|
|
|
|
|
2019-04-15 13:16:47 +00:00
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
2023-04-24 18:24:22 +00:00
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "${DIR}/../Meta/shell_include.sh"
|
|
|
|
|
2023-06-12 08:23:56 +00:00
|
|
|
exit_if_running_as_root "Do not run BuildGNU.sh as root, your Build directory will become root-owned"
|
2023-04-24 18:24:22 +00:00
|
|
|
|
2019-11-02 16:34:54 +00:00
|
|
|
echo "$DIR"
|
2019-04-15 14:34:41 +00:00
|
|
|
|
2022-10-02 17:55:22 +00:00
|
|
|
ARCH=${ARCH:-"x86_64"}
|
2019-12-17 21:42:42 +00:00
|
|
|
TARGET="$ARCH-pc-serenity"
|
2020-12-29 03:38:52 +00:00
|
|
|
PREFIX="$DIR/Local/$ARCH"
|
2021-03-07 19:37:29 +00:00
|
|
|
BUILD="$DIR/../Build/$ARCH"
|
2020-05-06 15:40:06 +00:00
|
|
|
SYSROOT="$BUILD/Root"
|
2019-04-15 13:16:47 +00:00
|
|
|
|
2020-03-22 04:25:17 +00:00
|
|
|
MAKE="make"
|
|
|
|
MD5SUM="md5sum"
|
2020-12-28 23:36:15 +00:00
|
|
|
REALPATH="realpath"
|
2020-01-02 02:06:14 +00:00
|
|
|
|
2020-07-08 21:57:51 +00:00
|
|
|
if command -v ginstall &>/dev/null; then
|
|
|
|
INSTALL=ginstall
|
|
|
|
else
|
|
|
|
INSTALL=install
|
|
|
|
fi
|
|
|
|
|
2021-04-18 12:45:26 +00:00
|
|
|
SYSTEM_NAME="$(uname -s)"
|
|
|
|
|
2021-04-17 19:28:02 +00: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 11:22:39 +00:00
|
|
|
export CFLAGS="-g0 -O2 -mtune=native"
|
|
|
|
export CXXFLAGS="-g0 -O2 -mtune=native"
|
2021-04-17 19:28:02 +00:00
|
|
|
|
2021-04-18 12:45:26 +00:00
|
|
|
if [ "$SYSTEM_NAME" = "OpenBSD" ]; then
|
2020-01-02 02:06:14 +00:00
|
|
|
MAKE=gmake
|
|
|
|
MD5SUM="md5 -q"
|
2020-12-28 23:36:15 +00:00
|
|
|
REALPATH="readlink -f"
|
2020-01-02 02:06:14 +00:00
|
|
|
export CC=egcc
|
|
|
|
export CXX=eg++
|
|
|
|
export with_gmp=/usr/local
|
|
|
|
export LDFLAGS=-Wl,-z,notext
|
2021-04-18 12:45:26 +00:00
|
|
|
elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then
|
2020-03-21 08:46:30 +00:00
|
|
|
MAKE=gmake
|
|
|
|
MD5SUM="md5 -q"
|
2020-10-17 20:25:13 +00:00
|
|
|
export with_gmp=/usr/local
|
|
|
|
export with_mpfr=/usr/local
|
2023-01-09 00:08:28 +00:00
|
|
|
elif [ "$SYSTEM_NAME" = "Darwin" ]; then
|
|
|
|
MD5SUM="md5 -q"
|
2020-01-02 02:06:14 +00:00
|
|
|
fi
|
|
|
|
|
2020-12-28 23:36:15 +00: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 08:03:27 +00:00
|
|
|
git_patch=
|
|
|
|
while [ "$1" != "" ]; do
|
|
|
|
case $1 in
|
|
|
|
--dev ) git_patch=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2019-11-02 16:34:54 +00:00
|
|
|
echo PREFIX is "$PREFIX"
|
|
|
|
echo SYSROOT is "$SYSROOT"
|
2019-05-08 13:50:24 +00:00
|
|
|
|
2019-04-15 13:16:47 +00:00
|
|
|
mkdir -p "$DIR/Tarballs"
|
2019-04-25 17:28:10 +00:00
|
|
|
|
2023-09-04 05:48:49 +00:00
|
|
|
BINUTILS_VERSION="2.41"
|
|
|
|
BINUTILS_MD5SUM="256d7e0ad998e423030c84483a7c1e30"
|
2019-12-17 21:42:42 +00:00
|
|
|
BINUTILS_NAME="binutils-$BINUTILS_VERSION"
|
2023-05-03 18:04:54 +00:00
|
|
|
BINUTILS_PKG="${BINUTILS_NAME}.tar.xz"
|
2023-05-28 08:28:03 +00:00
|
|
|
BINUTILS_BASE_URL="https://ftpmirror.gnu.org/gnu/binutils"
|
2019-12-17 21:42:42 +00:00
|
|
|
|
2021-04-27 07:25:02 +00: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 15:14:43 +00:00
|
|
|
GCC_VERSION="13.2.0"
|
|
|
|
GCC_MD5SUM="e0e48554cc6e4f261d55ddee9ab69075"
|
2019-12-17 21:42:42 +00:00
|
|
|
GCC_NAME="gcc-$GCC_VERSION"
|
2023-05-03 18:04:54 +00:00
|
|
|
GCC_PKG="${GCC_NAME}.tar.xz"
|
2023-05-28 08:28:03 +00:00
|
|
|
GCC_BASE_URL="https://ftpmirror.gnu.org/gnu/gcc"
|
2019-12-17 21:42:42 +00:00
|
|
|
|
2021-04-18 00:35:16 +00:00
|
|
|
buildstep() {
|
|
|
|
NAME=$1
|
|
|
|
shift
|
2021-04-18 15:25:46 +00:00
|
|
|
"$@" 2>&1 | sed $'s|^|\x1b[34m['"${NAME}"$']\x1b[39m |'
|
2021-04-18 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 08:48:47 +00: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 16:38:16 +00:00
|
|
|
# === DOWNLOAD AND PATCH ===
|
2019-04-15 13:16:47 +00:00
|
|
|
pushd "$DIR/Tarballs"
|
2021-05-27 06:02:57 +00:00
|
|
|
md5=""
|
|
|
|
if [ -e "$BINUTILS_PKG" ]; then
|
|
|
|
md5="$($MD5SUM $BINUTILS_PKG | cut -f1 -d' ')"
|
2022-08-23 06:52:23 +00:00
|
|
|
echo "binutils md5='$md5'"
|
2021-05-27 06:02:57 +00:00
|
|
|
fi
|
|
|
|
if [ "$md5" != ${BINUTILS_MD5SUM} ] ; then
|
2019-12-17 21:42:42 +00:00
|
|
|
rm -f $BINUTILS_PKG
|
2020-06-18 14:31:12 +00:00
|
|
|
curl -LO "$BINUTILS_BASE_URL/$BINUTILS_PKG"
|
2019-04-15 14:34:41 +00:00
|
|
|
else
|
|
|
|
echo "Skipped downloading binutils"
|
2019-04-15 13:16:47 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-27 06:02:57 +00:00
|
|
|
md5=""
|
|
|
|
if [ -e "$GCC_PKG" ]; then
|
|
|
|
md5="$($MD5SUM ${GCC_PKG} | cut -f1 -d' ')"
|
2022-08-23 06:51:40 +00:00
|
|
|
echo "gcc md5='$md5'"
|
2021-05-27 06:02:57 +00:00
|
|
|
fi
|
|
|
|
if [ "$md5" != ${GCC_MD5SUM} ] ; then
|
2019-12-17 21:42:42 +00:00
|
|
|
rm -f $GCC_PKG
|
2020-06-18 14:31:12 +00:00
|
|
|
curl -LO "$GCC_BASE_URL/$GCC_NAME/$GCC_PKG"
|
2019-04-15 14:34:41 +00:00
|
|
|
else
|
|
|
|
echo "Skipped downloading gcc"
|
2019-04-15 13:16:47 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-26 21:28:31 +00: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 18:20:29 +00:00
|
|
|
fi
|
2022-09-26 21:28:31 +00:00
|
|
|
echo "Extracting binutils..."
|
2023-05-03 18:04:54 +00:00
|
|
|
tar -xJf ${BINUTILS_PKG}
|
2022-09-26 21:28:31 +00: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 13:16:47 +00:00
|
|
|
fi
|
2022-09-26 21:28:31 +00: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 18:20:29 +00:00
|
|
|
fi
|
2022-09-26 21:28:31 +00:00
|
|
|
echo "Extracting gcc..."
|
2023-05-03 18:04:54 +00:00
|
|
|
tar -xJf ${GCC_PKG}
|
2019-12-25 14:21:23 +00:00
|
|
|
|
2022-09-26 21:28:31 +00: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 14:21:23 +00:00
|
|
|
popd
|
2022-09-26 21:28:31 +00:00
|
|
|
else
|
|
|
|
echo "Using existing GCC source directory"
|
2019-12-25 14:21:23 +00:00
|
|
|
fi
|
2019-04-15 13:16:47 +00:00
|
|
|
popd
|
|
|
|
|
|
|
|
|
2020-03-07 16:38:16 +00:00
|
|
|
# === COMPILE AND INSTALL ===
|
|
|
|
|
2021-04-16 18:42:18 +00:00
|
|
|
rm -rf "$PREFIX"
|
2020-03-07 16:38:16 +00:00
|
|
|
mkdir -p "$PREFIX"
|
2019-04-15 13:16:47 +00:00
|
|
|
|
2023-05-02 19:05:04 +00:00
|
|
|
NPROC=$(get_number_of_processing_units)
|
|
|
|
[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC}
|
2019-05-15 18:08:23 +00:00
|
|
|
|
2021-04-16 18:42:18 +00:00
|
|
|
mkdir -p "$DIR/Build/$ARCH"
|
|
|
|
|
2020-12-29 03:38:52 +00:00
|
|
|
pushd "$DIR/Build/$ARCH"
|
2019-04-15 13:16:47 +00:00
|
|
|
unset PKG_CONFIG_LIBDIR # Just in case
|
|
|
|
|
2021-04-16 18:42:18 +00:00
|
|
|
rm -rf binutils
|
|
|
|
mkdir -p binutils
|
|
|
|
|
2019-04-15 13:16:47 +00:00
|
|
|
pushd binutils
|
2020-08-01 13:32:04 +00:00
|
|
|
echo "XXX configure binutils"
|
2022-03-12 10:19:18 +00: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 00:35:16 +00:00
|
|
|
buildstep "binutils/configure" "$DIR"/Tarballs/$BINUTILS_NAME/configure --prefix="$PREFIX" \
|
2020-10-12 09:52:58 +00:00
|
|
|
--target="$TARGET" \
|
|
|
|
--with-sysroot="$SYSROOT" \
|
|
|
|
--enable-shared \
|
|
|
|
--disable-nls \
|
2023-05-27 15:54:17 +00:00
|
|
|
${CI:+"--quiet"} || exit 1
|
2021-04-18 12:45:26 +00:00
|
|
|
if [ "$SYSTEM_NAME" = "Darwin" ]; then
|
2019-12-28 16:53:14 +00: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 12:46:52 +00:00
|
|
|
buildstep "binutils/build" "$MAKE" -j "$MAKEJOBS" || true
|
2019-12-28 16:53:14 +00:00
|
|
|
pushd intl
|
2021-04-18 12:46:52 +00:00
|
|
|
buildstep "binutils/build" "$MAKE" all-yes
|
2019-12-28 16:53:14 +00:00
|
|
|
popd
|
|
|
|
fi
|
2020-08-01 13:32:04 +00:00
|
|
|
echo "XXX build binutils"
|
2022-11-04 23:25:26 +00:00
|
|
|
buildstep "binutils/build" "$MAKE" MAKEINFO=true -j "$MAKEJOBS" || exit 1
|
|
|
|
buildstep "binutils/install" "$MAKE" MAKEINFO=true install || exit 1
|
2019-04-15 13:16:47 +00:00
|
|
|
popd
|
|
|
|
|
2022-09-05 23:01:21 +00:00
|
|
|
echo "XXX serenity libc headers"
|
2021-04-16 18:42:18 +00:00
|
|
|
mkdir -p "$BUILD"
|
|
|
|
pushd "$BUILD"
|
|
|
|
mkdir -p Root/usr/include/
|
|
|
|
SRC_ROOT=$($REALPATH "$DIR"/..)
|
2022-02-25 21:28:06 +00:00
|
|
|
FILES=$(find \
|
|
|
|
"$SRC_ROOT"/Kernel/API \
|
|
|
|
"$SRC_ROOT"/Kernel/Arch \
|
|
|
|
"$SRC_ROOT"/Userland/Libraries/LibC \
|
2023-04-30 15:07:21 +00:00
|
|
|
"$SRC_ROOT"/Userland/Libraries/LibELF/ELFABI.h \
|
2023-04-29 20:50:54 +00:00
|
|
|
"$SRC_ROOT"/Userland/Libraries/LibRegex/RegexDefs.h \
|
2022-02-25 21:28:06 +00:00
|
|
|
-name '*.h' -print)
|
2021-04-16 18:42:18 +00:00
|
|
|
for header in $FILES; do
|
2022-02-25 21:28:06 +00:00
|
|
|
target=$(echo "$header" | sed \
|
2023-03-13 18:55:15 +00:00
|
|
|
-e "s|$SRC_ROOT/Userland/Libraries/LibC||" \
|
2023-04-29 20:50:54 +00:00
|
|
|
-e "s|$SRC_ROOT/Kernel/|Kernel/|" \
|
2023-04-30 15:07:21 +00:00
|
|
|
-e "s|$SRC_ROOT/Userland/Libraries/LibELF/|LibELF/|" \
|
2023-04-29 20:50:54 +00:00
|
|
|
-e "s|$SRC_ROOT/Userland/Libraries/LibRegex/|LibRegex/|")
|
2023-01-09 00:08:51 +00:00
|
|
|
buildstep "system_headers" mkdir -p "$(dirname "Root/usr/include/$target")"
|
|
|
|
buildstep "system_headers" $INSTALL "$header" "Root/usr/include/$target"
|
2021-04-16 18:42:18 +00:00
|
|
|
done
|
|
|
|
unset SRC_ROOT
|
|
|
|
popd
|
2020-01-02 02:06:14 +00:00
|
|
|
|
2021-04-18 12:45:26 +00:00
|
|
|
if [ "$SYSTEM_NAME" = "OpenBSD" ]; then
|
2021-04-16 18:42:18 +00:00
|
|
|
perl -pi -e 's/-no-pie/-nopie/g' "$DIR/Tarballs/gcc-$GCC_VERSION/gcc/configure"
|
|
|
|
fi
|
2020-05-20 12:23:30 +00:00
|
|
|
|
2021-07-06 10:36:18 +00: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 18:24:02 +00:00
|
|
|
--disable-libstdcxx-pch \
|
2021-07-06 10:36:18 +00:00
|
|
|
--enable-shared \
|
2023-07-23 13:20:18 +00:00
|
|
|
--enable-languages=c,c++,objc,obj-c++ \
|
2021-07-06 10:36:18 +00:00
|
|
|
--enable-default-pie \
|
|
|
|
--enable-lto \
|
|
|
|
--enable-threads=posix \
|
2022-01-19 18:12:50 +00:00
|
|
|
--enable-initfini-array \
|
2022-01-19 18:18:10 +00:00
|
|
|
--with-linker-hash-style=gnu \
|
2023-05-27 15:54:17 +00:00
|
|
|
${CI:+"--quiet"} || exit 1
|
2021-07-06 10:36:18 +00: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 13:09:57 +00:00
|
|
|
popd
|
|
|
|
|
2022-01-19 19:54:34 +00:00
|
|
|
pushd "$DIR/Local/$ARCH/$ARCH-pc-serenity/bin"
|
|
|
|
buildstep "mold_symlink" ln -s ../../../mold/bin/mold ld.mold
|
|
|
|
popd
|