2021-04-18 12:01:52 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-03-07 19:37:29 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
ARG0=$0
|
|
|
|
print_help() {
|
2021-04-15 15:09:36 +00:00
|
|
|
NAME=$(basename "$ARG0")
|
2021-03-07 19:37:29 +00:00
|
|
|
cat <<EOF
|
2021-09-03 20:12:07 +00:00
|
|
|
Usage: $NAME COMMAND [TARGET] [TOOLCHAIN] [ARGS...]
|
2023-08-17 09:32:32 +00:00
|
|
|
Supported TARGETs: aarch64, x86_64, riscv64, lagom. Defaults to SERENITY_ARCH, or x86_64 if not set.
|
2022-05-16 08:15:43 +00:00
|
|
|
Supported TOOLCHAINs: GNU, Clang. Defaults to SERENITY_TOOLCHAIN, or GNU if not set.
|
2021-03-07 19:37:29 +00:00
|
|
|
Supported COMMANDs:
|
|
|
|
build: Compiles the target binaries, [ARGS...] are passed through to ninja
|
|
|
|
install: Installs the target binary
|
|
|
|
image: Creates a disk image with the installed binaries
|
2021-04-15 15:09:36 +00:00
|
|
|
run: TARGET lagom: $NAME run lagom LAGOM_EXECUTABLE [ARGS...]
|
2021-03-23 21:41:14 +00:00
|
|
|
Runs the Lagom-built LAGOM_EXECUTABLE on the build host, e.g.
|
|
|
|
'shell' or 'js', [ARGS...] are passed through to the executable
|
2021-04-15 15:09:36 +00:00
|
|
|
All other TARGETs: $NAME run [TARGET] [KERNEL_CMD_LINE]
|
2021-03-07 19:37:29 +00:00
|
|
|
Runs the built image in QEMU, and optionally passes the
|
2021-03-12 18:03:49 +00:00
|
|
|
KERNEL_CMD_LINE to the Kernel
|
2021-03-11 04:26:26 +00:00
|
|
|
gdb: Same as run, but also starts a gdb remote session.
|
2021-04-15 15:09:36 +00:00
|
|
|
TARGET lagom: $NAME gdb lagom LAGOM_EXECUTABLE [-ex 'any gdb command']...
|
2021-03-12 18:07:17 +00:00
|
|
|
Passes through '-ex' commands to gdb
|
2021-04-15 15:09:36 +00:00
|
|
|
All other TARGETs: $NAME gdb [TARGET] [KERNEL_CMD_LINE] [-ex 'any gdb command']...
|
2021-03-12 18:07:17 +00:00
|
|
|
If specified, passes the KERNEL_CMD_LINE to the Kernel
|
2021-03-11 04:26:26 +00:00
|
|
|
Passes through '-ex' commands to gdb
|
2021-04-15 15:09:36 +00:00
|
|
|
test: TARGET lagom: $NAME test lagom [TEST_NAME_PATTERN]
|
2021-03-12 18:06:20 +00:00
|
|
|
Runs the unit tests on the build host, or if TEST_NAME_PATTERN
|
|
|
|
is specified tests matching it.
|
2021-04-15 15:09:36 +00:00
|
|
|
All other TARGETs: $NAME test [TARGET]
|
2021-03-12 18:06:20 +00:00
|
|
|
Runs the built image in QEMU in self-test mode, by passing
|
2021-10-23 16:26:50 +00:00
|
|
|
system_mode=self-test to the Kernel
|
2021-03-12 18:03:49 +00:00
|
|
|
delete: Removes the build environment for TARGET
|
2021-03-07 19:37:29 +00:00
|
|
|
recreate: Deletes and re-creates the build environment for TARGET
|
|
|
|
rebuild: Deletes and re-creates the build environment, and compiles for TARGET
|
2021-04-15 15:09:36 +00:00
|
|
|
kaddr2line: $NAME kaddr2line TARGET ADDRESS
|
2021-03-07 19:37:29 +00:00
|
|
|
Resolves the ADDRESS in the Kernel/Kernel binary to a file:line
|
2021-04-15 15:09:36 +00:00
|
|
|
addr2line: $NAME addr2line TARGET BINARY_FILE ADDRESS
|
2021-03-07 19:37:29 +00:00
|
|
|
Resolves the ADDRESS in BINARY_FILE to a file:line. It will
|
|
|
|
attempt to find the BINARY_FILE in the appropriate build directory
|
|
|
|
rebuild-toolchain: Deletes and re-builds the TARGET's toolchain
|
2021-04-20 04:29:10 +00:00
|
|
|
rebuild-world: Deletes and re-builds the toolchain and build environment for TARGET.
|
2021-08-22 07:11:17 +00:00
|
|
|
copy-src: Same as image, but also copies the project's source tree to ~/Source/serenity
|
|
|
|
in the built disk image.
|
|
|
|
|
2021-03-07 19:37:29 +00:00
|
|
|
|
|
|
|
Examples:
|
2022-10-03 23:48:37 +00:00
|
|
|
$NAME run x86_64 GNU smp=on
|
2021-03-07 19:37:29 +00:00
|
|
|
Runs the image in QEMU passing "smp=on" to the kernel command line
|
2021-04-15 15:09:36 +00:00
|
|
|
$NAME run
|
2022-10-03 23:48:37 +00:00
|
|
|
Runs the image for the default TARGET x86_64 in QEMU
|
2021-04-15 15:09:36 +00:00
|
|
|
$NAME run lagom js -A
|
2021-03-12 18:03:49 +00:00
|
|
|
Runs the Lagom-built js(1) REPL
|
2021-04-15 15:09:36 +00:00
|
|
|
$NAME test lagom
|
2021-03-12 18:06:20 +00:00
|
|
|
Runs the unit tests on the build host
|
2022-10-03 23:48:37 +00:00
|
|
|
$NAME kaddr2line x86_64 0x12345678
|
2021-03-07 19:37:29 +00:00
|
|
|
Resolves the address 0x12345678 in the Kernel binary
|
2022-10-03 23:48:37 +00:00
|
|
|
$NAME addr2line x86_64 WindowServer 0x12345678
|
2021-03-07 19:37:29 +00:00
|
|
|
Resolves the address 0x12345678 in the WindowServer binary
|
2022-10-03 23:48:37 +00:00
|
|
|
$NAME gdb x86_64 smp=on -ex 'hb *init'
|
|
|
|
Runs the image for the TARGET x86_64 in qemu and attaches a gdb session
|
2021-03-11 04:26:26 +00:00
|
|
|
setting a breakpoint at the init() function in the Kernel.
|
2021-03-07 19:37:29 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
>&2 print_help
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
CMD=$1
|
|
|
|
[ -n "$CMD" ] || usage
|
|
|
|
shift
|
|
|
|
if [ "$CMD" = "help" ]; then
|
|
|
|
print_help
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-04-24 19:12:31 +00:00
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "${DIR}/shell_include.sh"
|
|
|
|
|
|
|
|
exit_if_running_as_root "Do not run serenity.sh as root, your Build directory will become root-owned"
|
2022-05-31 05:35:59 +00:00
|
|
|
|
2023-09-07 14:44:33 +00:00
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "${DIR}/find_compiler.sh"
|
|
|
|
|
2021-03-07 19:37:29 +00:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
TARGET="$1"; shift
|
|
|
|
else
|
2022-10-02 17:55:22 +00:00
|
|
|
TARGET="${SERENITY_ARCH:-"x86_64"}"
|
2021-03-07 19:37:29 +00:00
|
|
|
fi
|
2021-09-03 20:12:07 +00:00
|
|
|
|
2021-11-01 13:22:20 +00:00
|
|
|
CMAKE_ARGS=()
|
|
|
|
|
|
|
|
# Toolchain selection only applies to non-lagom targets.
|
2022-05-16 08:15:43 +00:00
|
|
|
if [ "$TARGET" != "lagom" ] && [ -n "$1" ]; then
|
|
|
|
TOOLCHAIN_TYPE="$1"; shift
|
|
|
|
else
|
|
|
|
TOOLCHAIN_TYPE="${SERENITY_TOOLCHAIN:-"GNU"}"
|
|
|
|
fi
|
|
|
|
if ! [[ "${TOOLCHAIN_TYPE}" =~ ^(GNU|Clang)$ ]]; then
|
|
|
|
>&2 echo "ERROR: unknown toolchain '${TOOLCHAIN_TYPE}'."
|
|
|
|
exit 1
|
2021-11-01 13:22:20 +00:00
|
|
|
fi
|
2022-05-16 08:15:43 +00:00
|
|
|
CMAKE_ARGS+=( "-DSERENITY_TOOLCHAIN=$TOOLCHAIN_TYPE" )
|
2021-09-03 20:12:07 +00:00
|
|
|
|
2021-03-07 19:37:29 +00:00
|
|
|
CMD_ARGS=( "$@" )
|
2021-09-03 20:12:07 +00:00
|
|
|
|
2021-03-07 19:37:29 +00:00
|
|
|
get_top_dir() {
|
|
|
|
git rev-parse --show-toplevel
|
|
|
|
}
|
|
|
|
|
|
|
|
is_valid_target() {
|
2021-08-28 02:36:38 +00:00
|
|
|
if [ "$TARGET" = "aarch64" ]; then
|
|
|
|
CMAKE_ARGS+=("-DSERENITY_ARCH=aarch64")
|
|
|
|
return 0
|
|
|
|
fi
|
2021-07-01 12:18:26 +00:00
|
|
|
if [ "$TARGET" = "x86_64" ]; then
|
|
|
|
CMAKE_ARGS+=("-DSERENITY_ARCH=x86_64")
|
|
|
|
return 0
|
|
|
|
fi
|
2023-08-17 09:32:32 +00:00
|
|
|
if [ "$TARGET" = "riscv64" ]; then
|
|
|
|
CMAKE_ARGS+=("-DSERENITY_ARCH=riscv64")
|
|
|
|
return 0
|
|
|
|
fi
|
2021-08-29 12:50:07 +00:00
|
|
|
if [ "$TARGET" = "lagom" ]; then
|
|
|
|
CMAKE_ARGS+=("-DBUILD_LAGOM=ON")
|
2022-12-23 19:42:12 +00:00
|
|
|
if [ "${CMD_ARGS[0]}" = "ladybird" ]; then
|
2023-10-24 14:35:33 +00:00
|
|
|
CMAKE_ARGS+=("-DENABLE_LAGOM_LADYBIRD=ON")
|
2022-12-23 19:42:12 +00:00
|
|
|
fi
|
2021-08-29 12:50:07 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
2021-03-07 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
create_build_dir() {
|
2021-09-07 08:32:41 +00:00
|
|
|
if [ "$TARGET" != "lagom" ]; then
|
|
|
|
cmake -GNinja "${CMAKE_ARGS[@]}" -S "$SERENITY_SOURCE_DIR/Meta/CMake/Superbuild" -B "$SUPER_BUILD_DIR"
|
|
|
|
else
|
|
|
|
cmake -GNinja "${CMAKE_ARGS[@]}" -S "$SERENITY_SOURCE_DIR/Meta/Lagom" -B "$SUPER_BUILD_DIR"
|
|
|
|
fi
|
2021-03-07 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd_with_target() {
|
|
|
|
is_valid_target || ( >&2 echo "Unknown target: $TARGET"; usage )
|
2022-10-23 22:06:41 +00:00
|
|
|
|
2022-04-14 14:32:32 +00:00
|
|
|
pick_host_compiler
|
2022-10-23 22:06:41 +00:00
|
|
|
CMAKE_ARGS+=("-DCMAKE_C_COMPILER=${CC}")
|
|
|
|
CMAKE_ARGS+=("-DCMAKE_CXX_COMPILER=${CXX}")
|
2021-04-17 01:08:48 +00:00
|
|
|
|
2021-04-20 00:51:04 +00:00
|
|
|
if [ ! -d "$SERENITY_SOURCE_DIR" ]; then
|
|
|
|
SERENITY_SOURCE_DIR="$(get_top_dir)"
|
|
|
|
export SERENITY_SOURCE_DIR
|
2021-04-17 01:08:48 +00:00
|
|
|
fi
|
2021-09-03 20:12:07 +00:00
|
|
|
local TARGET_TOOLCHAIN=""
|
2021-09-07 08:32:41 +00:00
|
|
|
if [[ "$TOOLCHAIN_TYPE" != "GNU" && "$TARGET" != "lagom" ]]; then
|
|
|
|
# Only append the toolchain if it's not GNU
|
|
|
|
TARGET_TOOLCHAIN=$(echo "$TOOLCHAIN_TYPE" | tr "[:upper:]" "[:lower:]")
|
2021-09-03 20:12:07 +00:00
|
|
|
fi
|
|
|
|
BUILD_DIR="$SERENITY_SOURCE_DIR/Build/$TARGET$TARGET_TOOLCHAIN"
|
2021-03-12 17:58:49 +00:00
|
|
|
if [ "$TARGET" != "lagom" ]; then
|
|
|
|
export SERENITY_ARCH="$TARGET"
|
2022-02-18 23:39:02 +00:00
|
|
|
export SERENITY_TOOLCHAIN="$TOOLCHAIN_TYPE"
|
Toolchain+Meta: Update LLVM version to 13.0.0
This commit updates the Clang toolchain's version to 13.0.0, which comes
with better C++20 support and improved handling of new features by
clang-format. Due to the newly enabled `-Bsymbolic-functions` flag, our
Clang binaries will only be 2-4% slower than if we dynamically linked
them, but we save hundreds of megabytes of disk space.
The `BuildClang.sh` script has been reworked to build the entire
toolchain in just three steps: one for the compiler, one for GNU
binutils, and one for the runtime libraries. This reduces the complexity
of the build script, and will allow us to modify the CI configuration to
only rebuild the libraries when our libc headers change.
Most of the compile flags have been moved out to a separate CMake cache
file, similarly to how the Android and Fuchsia toolchains are
implemented within the LLVM repo. This provides a nicer interface than
the heaps of command-line arguments.
We no longer build separate toolchains for each architecture, as the
same Clang binary can compile code for multiple targets.
The horrible mess that `SERENITY_CLANG_ARCH` was, has been removed in
this commit. Clang happily accepts an `i686-pc-serenity` target triple,
which matches what our GCC toolchain accepts.
2021-08-13 10:11:12 +00:00
|
|
|
if [ "$TOOLCHAIN_TYPE" = "Clang" ]; then
|
|
|
|
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR/Toolchain/Local/clang"
|
|
|
|
else
|
|
|
|
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR/Toolchain/Local/$TARGET_TOOLCHAIN/$TARGET"
|
|
|
|
fi
|
2021-09-07 08:32:41 +00:00
|
|
|
SUPER_BUILD_DIR="$SERENITY_SOURCE_DIR/Build/superbuild-$TARGET$TARGET_TOOLCHAIN"
|
|
|
|
else
|
|
|
|
SUPER_BUILD_DIR="$BUILD_DIR"
|
|
|
|
CMAKE_ARGS+=("-DCMAKE_INSTALL_PREFIX=$SERENITY_SOURCE_DIR/Build/lagom-install")
|
2022-11-26 02:03:42 +00:00
|
|
|
CMAKE_ARGS+=("-DSERENITY_CACHE_DIR=${SERENITY_SOURCE_DIR}/Build/caches")
|
2021-03-07 19:37:29 +00:00
|
|
|
fi
|
2022-12-10 20:33:16 +00:00
|
|
|
export PATH="$SERENITY_SOURCE_DIR/Toolchain/Local/cmake/bin":$PATH
|
2021-03-07 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ensure_target() {
|
2021-09-07 08:32:41 +00:00
|
|
|
[ -f "$SUPER_BUILD_DIR/build.ninja" ] || create_build_dir
|
2021-03-07 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run_tests() {
|
|
|
|
local TEST_NAME="$1"
|
2023-08-19 19:46:26 +00:00
|
|
|
local CTEST_ARGS=("--output-on-failure" "--test-dir" "$BUILD_DIR")
|
2021-03-07 19:37:29 +00:00
|
|
|
if [ -n "$TEST_NAME" ]; then
|
2023-08-19 19:46:26 +00:00
|
|
|
if [ "$TEST_NAME" = "WPT" ]; then
|
|
|
|
CTEST_ARGS+=("-C" "Integration")
|
|
|
|
fi
|
|
|
|
CTEST_ARGS+=("-R" "$TEST_NAME")
|
2021-03-07 19:37:29 +00:00
|
|
|
fi
|
2023-08-19 19:46:26 +00:00
|
|
|
ctest "${CTEST_ARGS[@]}"
|
2021-03-07 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
build_target() {
|
2021-09-16 09:02:44 +00:00
|
|
|
if [ "$TARGET" = "lagom" ]; then
|
|
|
|
# Ensure that all lagom binaries get built, in case user first
|
|
|
|
# invoked superbuild for serenity target that doesn't set -DBUILD_LAGOM=ON
|
2023-08-25 11:05:57 +00:00
|
|
|
local EXTRA_CMAKE_ARGS=()
|
2022-12-23 19:42:12 +00:00
|
|
|
if [ "${CMD_ARGS[0]}" = "ladybird" ]; then
|
2023-10-24 14:35:33 +00:00
|
|
|
EXTRA_CMAKE_ARGS=("-DENABLE_LAGOM_LADYBIRD=ON")
|
2022-12-23 19:42:12 +00:00
|
|
|
fi
|
2023-08-25 11:05:57 +00:00
|
|
|
cmake -S "$SERENITY_SOURCE_DIR/Meta/Lagom" -B "$BUILD_DIR" -DBUILD_LAGOM=ON "${EXTRA_CMAKE_ARGS[@]}"
|
2021-09-16 09:02:44 +00:00
|
|
|
fi
|
2022-02-28 22:56:38 +00:00
|
|
|
|
2022-09-09 21:53:53 +00:00
|
|
|
# Get either the environment MAKEJOBS or all processors via CMake
|
2022-09-02 08:52:15 +00:00
|
|
|
[ -z "$MAKEJOBS" ] && MAKEJOBS=$(cmake -P "$SERENITY_SOURCE_DIR/Meta/CMake/processor-count.cmake")
|
2022-02-28 22:56:38 +00:00
|
|
|
|
2021-09-07 08:32:41 +00:00
|
|
|
# With zero args, we are doing a standard "build"
|
|
|
|
# With multiple args, we are doing an install/image/run
|
|
|
|
if [ $# -eq 0 ]; then
|
2022-02-28 22:56:38 +00:00
|
|
|
CMAKE_BUILD_PARALLEL_LEVEL="$MAKEJOBS" cmake --build "$SUPER_BUILD_DIR"
|
2021-09-07 08:32:41 +00:00
|
|
|
else
|
2022-02-28 22:56:38 +00:00
|
|
|
ninja -j "$MAKEJOBS" -C "$BUILD_DIR" -- "$@"
|
2021-09-07 08:32:41 +00:00
|
|
|
fi
|
2021-03-07 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 07:15:20 +00:00
|
|
|
build_image() {
|
|
|
|
if [ "$SERENITY_RUN" = "limine" ]; then
|
|
|
|
build_target limine-image
|
|
|
|
else
|
2023-03-12 01:12:37 +00:00
|
|
|
build_target qemu-image
|
2022-01-16 07:15:20 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-03-07 19:37:29 +00:00
|
|
|
delete_target() {
|
|
|
|
[ ! -d "$BUILD_DIR" ] || rm -rf "$BUILD_DIR"
|
2021-09-07 08:32:41 +00:00
|
|
|
[ ! -d "$SUPER_BUILD_DIR" ] || rm -rf "$SUPER_BUILD_DIR"
|
2021-03-07 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
2022-12-10 20:33:16 +00:00
|
|
|
build_cmake() {
|
|
|
|
echo "CMake version too old: build_cmake"
|
|
|
|
( cd "$SERENITY_SOURCE_DIR/Toolchain" && ./BuildCMake.sh )
|
|
|
|
}
|
|
|
|
|
2021-03-07 19:37:29 +00:00
|
|
|
build_toolchain() {
|
2021-09-03 20:12:07 +00:00
|
|
|
echo "build_toolchain: $TOOLCHAIN_DIR"
|
2023-06-03 14:46:05 +00:00
|
|
|
|
2021-09-07 08:32:41 +00:00
|
|
|
if [ "$TOOLCHAIN_TYPE" = "Clang" ]; then
|
Toolchain+Meta: Update LLVM version to 13.0.0
This commit updates the Clang toolchain's version to 13.0.0, which comes
with better C++20 support and improved handling of new features by
clang-format. Due to the newly enabled `-Bsymbolic-functions` flag, our
Clang binaries will only be 2-4% slower than if we dynamically linked
them, but we save hundreds of megabytes of disk space.
The `BuildClang.sh` script has been reworked to build the entire
toolchain in just three steps: one for the compiler, one for GNU
binutils, and one for the runtime libraries. This reduces the complexity
of the build script, and will allow us to modify the CI configuration to
only rebuild the libraries when our libc headers change.
Most of the compile flags have been moved out to a separate CMake cache
file, similarly to how the Android and Fuchsia toolchains are
implemented within the LLVM repo. This provides a nicer interface than
the heaps of command-line arguments.
We no longer build separate toolchains for each architecture, as the
same Clang binary can compile code for multiple targets.
The horrible mess that `SERENITY_CLANG_ARCH` was, has been removed in
this commit. Clang happily accepts an `i686-pc-serenity` target triple,
which matches what our GCC toolchain accepts.
2021-08-13 10:11:12 +00:00
|
|
|
( cd "$SERENITY_SOURCE_DIR/Toolchain" && ./BuildClang.sh )
|
2021-09-03 20:12:07 +00:00
|
|
|
else
|
2023-06-03 14:46:05 +00:00
|
|
|
(
|
|
|
|
# HACK: ISL's configure fails with "Link Time Optimisation is not supported" if CC is
|
|
|
|
# Homebrew Clang due to incompatibility with Xcode's ranlib.
|
|
|
|
[ "$(uname -s)" = "Darwin" ] && unset CC CXX
|
|
|
|
cd "$SERENITY_SOURCE_DIR/Toolchain" && ARCH="$TARGET" ./BuildGNU.sh
|
|
|
|
)
|
2021-09-03 20:12:07 +00:00
|
|
|
fi
|
2021-03-07 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ensure_toolchain() {
|
2022-12-10 20:33:16 +00:00
|
|
|
if [ "$(cmake -P "$SERENITY_SOURCE_DIR"/Meta/CMake/cmake-version.cmake)" -ne 1 ]; then
|
|
|
|
build_cmake
|
|
|
|
fi
|
2021-03-07 19:37:29 +00:00
|
|
|
[ -d "$TOOLCHAIN_DIR" ] || build_toolchain
|
2022-02-05 14:48:32 +00:00
|
|
|
|
|
|
|
if [ "$TOOLCHAIN_TYPE" = "GNU" ]; then
|
|
|
|
local ld_version
|
|
|
|
ld_version="$("$TOOLCHAIN_DIR"/bin/"$TARGET"-pc-serenity-ld -v)"
|
2023-09-04 05:48:49 +00:00
|
|
|
local expected_version="GNU ld (GNU Binutils) 2.41"
|
2022-02-05 14:48:32 +00:00
|
|
|
if [ "$ld_version" != "$expected_version" ]; then
|
|
|
|
echo "Your toolchain has an old version of binutils installed."
|
|
|
|
echo " installed version: \"$ld_version\""
|
|
|
|
echo " expected version: \"$expected_version\""
|
|
|
|
echo "Please run $ARG0 rebuild-toolchain $TARGET to update it."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-03-07 19:37:29 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 17:42:28 +00:00
|
|
|
confirm_rebuild_if_toolchain_exists() {
|
|
|
|
[ ! -d "$TOOLCHAIN_DIR" ] && return
|
|
|
|
|
|
|
|
read -rp "You already have a toolchain, are you sure you want to delete and rebuild one [y/N]? " input
|
|
|
|
|
|
|
|
if [[ "$input" != "y" && "$input" != "Y" ]]; then
|
|
|
|
die "Aborted rebuild"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-03-07 19:37:29 +00:00
|
|
|
delete_toolchain() {
|
|
|
|
[ ! -d "$TOOLCHAIN_DIR" ] || rm -rf "$TOOLCHAIN_DIR"
|
|
|
|
}
|
|
|
|
|
2021-03-11 04:26:26 +00:00
|
|
|
kill_tmux_session() {
|
|
|
|
local TMUX_SESSION
|
|
|
|
TMUX_SESSION="$(tmux display-message -p '#S')"
|
|
|
|
[ -z "$TMUX_SESSION" ] || tmux kill-session -t "$TMUX_SESSION"
|
|
|
|
}
|
|
|
|
|
|
|
|
set_tmux_title() {
|
|
|
|
printf "\033]2;%s\033\\" "$1"
|
|
|
|
}
|
|
|
|
|
2021-03-12 17:53:06 +00:00
|
|
|
lagom_unsupported() {
|
|
|
|
[ "$TARGET" != "lagom" ] || die "${1:-"Command '$CMD' not supported for the lagom target"}"
|
|
|
|
}
|
|
|
|
|
2021-03-11 04:26:26 +00:00
|
|
|
run_gdb() {
|
|
|
|
local GDB_ARGS=()
|
|
|
|
local PASS_ARG_TO_GDB=""
|
|
|
|
local KERNEL_CMD_LINE=""
|
2021-03-12 18:07:17 +00:00
|
|
|
local LAGOM_EXECUTABLE=""
|
2021-03-11 04:26:26 +00:00
|
|
|
for arg in "${CMD_ARGS[@]}"; do
|
|
|
|
if [ "$PASS_ARG_TO_GDB" != "" ]; then
|
|
|
|
GDB_ARGS+=( "$PASS_ARG_TO_GDB" "$arg" )
|
|
|
|
PASS_ARG_TO_GDB=""
|
|
|
|
elif [ "$arg" = "-ex" ]; then
|
|
|
|
PASS_ARG_TO_GDB="$arg"
|
|
|
|
elif [[ "$arg" =~ ^-.*$ ]]; then
|
|
|
|
die "Don't know how to handle argument: $arg"
|
|
|
|
else
|
2021-03-12 18:07:17 +00:00
|
|
|
if [ "$TARGET" = "lagom" ]; then
|
|
|
|
if [ "$LAGOM_EXECUTABLE" != "" ]; then
|
|
|
|
die "Lagom executable can't be specified more than once"
|
|
|
|
fi
|
|
|
|
LAGOM_EXECUTABLE="$arg"
|
2022-12-23 19:42:12 +00:00
|
|
|
if [ "$LAGOM_EXECUTABLE" = "ladybird" ]; then
|
|
|
|
# FIXME: Make ladybird less cwd-dependent while in the build directory
|
|
|
|
cd "$BUILD_DIR/Ladybird"
|
|
|
|
fi
|
2021-03-12 18:07:17 +00:00
|
|
|
else
|
|
|
|
if [ "$KERNEL_CMD_LINE" != "" ]; then
|
|
|
|
die "Kernel command line can't be specified more than once"
|
|
|
|
fi
|
|
|
|
KERNEL_CMD_LINE="$arg"
|
2021-03-11 04:26:26 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$PASS_ARG_TO_GDB" != "" ]; then
|
|
|
|
GDB_ARGS+=( "$PASS_ARG_TO_GDB" )
|
|
|
|
fi
|
2021-03-12 18:07:17 +00:00
|
|
|
if [ "$TARGET" = "lagom" ]; then
|
2023-03-18 15:23:35 +00:00
|
|
|
gdb "$BUILD_DIR/bin/$LAGOM_EXECUTABLE" "${GDB_ARGS[@]}"
|
2021-03-12 18:07:17 +00:00
|
|
|
else
|
|
|
|
if [ -n "$KERNEL_CMD_LINE" ]; then
|
|
|
|
export SERENITY_KERNEL_CMDLINE="$KERNEL_CMD_LINE"
|
|
|
|
fi
|
2021-04-20 16:37:33 +00:00
|
|
|
sleep 1
|
2021-09-06 23:17:36 +00:00
|
|
|
"$(get_top_dir)/Meta/debug-kernel.sh" "${GDB_ARGS[@]}"
|
2021-03-11 04:26:26 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-01-25 19:46:44 +00:00
|
|
|
build_and_run_lagom_target() {
|
2023-01-26 11:51:48 +00:00
|
|
|
local run_target="${1}"
|
2023-01-25 19:46:44 +00:00
|
|
|
local lagom_target="${CMD_ARGS[0]}"
|
|
|
|
local lagom_args
|
|
|
|
|
|
|
|
# All command arguments must have any existing semicolon escaped, to prevent CMake from
|
|
|
|
# interpreting them as list separators.
|
|
|
|
local cmd_args=()
|
|
|
|
for arg in "${CMD_ARGS[@]:1}"; do
|
|
|
|
cmd_args+=( "${arg//;/\\;}" )
|
|
|
|
done
|
|
|
|
|
|
|
|
# Then existing list separators must be replaced with a semicolon for CMake.
|
|
|
|
lagom_args=$(IFS=';' ; echo -e "${cmd_args[*]}")
|
|
|
|
|
2023-01-26 11:51:48 +00:00
|
|
|
LAGOM_TARGET="${lagom_target}" LAGOM_ARGS="${lagom_args[*]}" build_target "${run_target}"
|
2023-01-25 19:46:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 07:11:17 +00:00
|
|
|
if [[ "$CMD" =~ ^(build|install|image|copy-src|run|gdb|test|rebuild|recreate|kaddr2line|addr2line|setup-and-run)$ ]]; then
|
2021-03-07 19:37:29 +00:00
|
|
|
cmd_with_target
|
|
|
|
[[ "$CMD" != "recreate" && "$CMD" != "rebuild" ]] || delete_target
|
2021-03-12 17:58:49 +00:00
|
|
|
[ "$TARGET" = "lagom" ] || ensure_toolchain
|
2021-06-01 23:33:48 +00:00
|
|
|
ensure_target
|
2021-03-07 19:37:29 +00:00
|
|
|
case "$CMD" in
|
|
|
|
build)
|
2023-08-25 11:05:57 +00:00
|
|
|
build_target "${CMD_ARGS[@]}"
|
2021-03-07 19:37:29 +00:00
|
|
|
;;
|
|
|
|
install)
|
|
|
|
build_target
|
|
|
|
build_target install
|
|
|
|
;;
|
|
|
|
image)
|
2021-03-12 17:53:06 +00:00
|
|
|
lagom_unsupported
|
2021-03-07 19:37:29 +00:00
|
|
|
build_target
|
|
|
|
build_target install
|
2022-01-16 07:15:20 +00:00
|
|
|
build_image
|
2021-03-07 19:37:29 +00:00
|
|
|
;;
|
2021-08-22 07:11:17 +00:00
|
|
|
copy-src)
|
|
|
|
lagom_unsupported
|
|
|
|
build_target
|
|
|
|
build_target install
|
|
|
|
export SERENITY_COPY_SOURCE=1
|
2022-01-16 07:15:20 +00:00
|
|
|
build_image
|
2021-08-22 07:11:17 +00:00
|
|
|
;;
|
2021-03-07 19:37:29 +00:00
|
|
|
run)
|
|
|
|
if [ "$TARGET" = "lagom" ]; then
|
2022-12-23 19:42:12 +00:00
|
|
|
if [ "${CMD_ARGS[0]}" = "ladybird" ]; then
|
2023-01-26 11:51:48 +00:00
|
|
|
build_and_run_lagom_target "run-ladybird"
|
2022-12-23 19:42:12 +00:00
|
|
|
else
|
2023-01-26 11:51:48 +00:00
|
|
|
build_and_run_lagom_target "run-lagom-target"
|
2022-12-23 19:42:12 +00:00
|
|
|
fi
|
2021-03-07 19:37:29 +00:00
|
|
|
else
|
2021-03-12 18:03:49 +00:00
|
|
|
build_target
|
2021-03-07 19:37:29 +00:00
|
|
|
build_target install
|
2022-01-16 07:15:20 +00:00
|
|
|
build_image
|
2021-03-07 19:37:29 +00:00
|
|
|
if [ -n "${CMD_ARGS[0]}" ]; then
|
|
|
|
export SERENITY_KERNEL_CMDLINE="${CMD_ARGS[0]}"
|
|
|
|
fi
|
|
|
|
build_target run
|
|
|
|
fi
|
|
|
|
;;
|
2021-03-11 04:26:26 +00:00
|
|
|
gdb)
|
|
|
|
if [ "$TARGET" = "lagom" ]; then
|
2021-03-12 18:07:17 +00:00
|
|
|
[ $# -ge 1 ] || usage
|
2023-08-25 11:05:57 +00:00
|
|
|
build_target "${CMD_ARGS[@]}"
|
2021-03-12 18:07:17 +00:00
|
|
|
run_gdb "${CMD_ARGS[@]}"
|
2021-03-11 04:26:26 +00:00
|
|
|
else
|
2023-04-03 02:35:37 +00:00
|
|
|
command -v tmux >/dev/null 2>&1 || die "Please install tmux!"
|
2021-03-12 18:07:17 +00:00
|
|
|
build_target
|
2021-03-11 04:26:26 +00:00
|
|
|
build_target install
|
2022-01-16 07:15:20 +00:00
|
|
|
build_image
|
2022-02-18 23:39:02 +00:00
|
|
|
tmux new-session "$ARG0" __tmux_cmd "$TARGET" "$TOOLCHAIN_TYPE" run "${CMD_ARGS[@]}" \; set-option -t 0 mouse on \; split-window "$ARG0" __tmux_cmd "$TARGET" "$TOOLCHAIN_TYPE" gdb "${CMD_ARGS[@]}" \;
|
2021-03-11 04:26:26 +00:00
|
|
|
fi
|
|
|
|
;;
|
2021-03-12 18:06:20 +00:00
|
|
|
test)
|
|
|
|
build_target
|
|
|
|
if [ "$TARGET" = "lagom" ]; then
|
|
|
|
run_tests "${CMD_ARGS[0]}"
|
|
|
|
else
|
|
|
|
build_target install
|
2022-01-16 07:15:20 +00:00
|
|
|
build_image
|
2021-10-23 15:31:00 +00:00
|
|
|
# In contrast to CI, we don't set 'panic=shutdown' here,
|
|
|
|
# in case the user wants to inspect qemu some more.
|
2022-08-12 05:37:23 +00:00
|
|
|
export SERENITY_KERNEL_CMDLINE="graphics_subsystem_mode=off system_mode=self-test"
|
2021-03-12 18:06:20 +00:00
|
|
|
export SERENITY_RUN="ci"
|
|
|
|
build_target run
|
|
|
|
fi
|
|
|
|
;;
|
2021-03-07 19:37:29 +00:00
|
|
|
rebuild)
|
2023-08-25 11:05:57 +00:00
|
|
|
build_target "${CMD_ARGS[@]}"
|
2021-03-07 19:37:29 +00:00
|
|
|
;;
|
|
|
|
recreate)
|
|
|
|
;;
|
|
|
|
kaddr2line)
|
2021-03-12 17:53:06 +00:00
|
|
|
lagom_unsupported
|
2021-03-07 19:37:29 +00:00
|
|
|
build_target
|
|
|
|
[ $# -ge 1 ] || usage
|
2021-09-23 14:29:07 +00:00
|
|
|
if [ "$TOOLCHAIN_TYPE" = "Clang" ]; then
|
|
|
|
ADDR2LINE="$TOOLCHAIN_DIR/bin/llvm-addr2line"
|
|
|
|
else
|
2022-03-27 11:47:35 +00:00
|
|
|
ADDR2LINE="$TOOLCHAIN_DIR/bin/$TARGET-pc-serenity-addr2line"
|
2021-09-23 14:29:07 +00:00
|
|
|
fi
|
|
|
|
"$ADDR2LINE" -e "$BUILD_DIR/Kernel/Kernel" "$@"
|
2021-03-07 19:37:29 +00:00
|
|
|
;;
|
|
|
|
addr2line)
|
|
|
|
build_target
|
|
|
|
[ $# -ge 2 ] || usage
|
|
|
|
BINARY_FILE="$1"; shift
|
|
|
|
BINARY_FILE_PATH="$BUILD_DIR/$BINARY_FILE"
|
2021-03-12 17:58:49 +00:00
|
|
|
if [ "$TARGET" = "lagom" ]; then
|
|
|
|
command -v addr2line >/dev/null 2>&1 || die "Please install addr2line!"
|
|
|
|
ADDR2LINE=addr2line
|
2021-09-23 14:29:07 +00:00
|
|
|
elif [ "$TOOLCHAIN_TYPE" = "Clang" ]; then
|
|
|
|
ADDR2LINE="$TOOLCHAIN_DIR/bin/llvm-addr2line"
|
2021-03-12 17:58:49 +00:00
|
|
|
else
|
2022-03-27 11:47:35 +00:00
|
|
|
ADDR2LINE="$TOOLCHAIN_DIR/bin/$TARGET-pc-serenity-addr2line"
|
2021-03-12 17:58:49 +00:00
|
|
|
fi
|
2021-03-07 19:37:29 +00:00
|
|
|
if [ -x "$BINARY_FILE_PATH" ]; then
|
2021-03-12 17:58:49 +00:00
|
|
|
"$ADDR2LINE" -e "$BINARY_FILE_PATH" "$@"
|
2021-03-07 19:37:29 +00:00
|
|
|
else
|
2021-03-12 17:58:49 +00:00
|
|
|
find "$BUILD_DIR" -name "$BINARY_FILE" -executable -type f -exec "$ADDR2LINE" -e {} "$@" \;
|
2021-03-07 19:37:29 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
2023-08-25 11:05:57 +00:00
|
|
|
build_target "$CMD" "${CMD_ARGS[@]}"
|
2021-03-07 19:37:29 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
elif [ "$CMD" = "delete" ]; then
|
|
|
|
cmd_with_target
|
|
|
|
delete_target
|
|
|
|
elif [ "$CMD" = "rebuild-toolchain" ]; then
|
|
|
|
cmd_with_target
|
2021-03-12 17:53:06 +00:00
|
|
|
lagom_unsupported "The lagom target uses the host toolchain"
|
2022-09-12 17:42:28 +00:00
|
|
|
confirm_rebuild_if_toolchain_exists
|
2021-03-07 19:37:29 +00:00
|
|
|
delete_toolchain
|
|
|
|
ensure_toolchain
|
2021-04-20 04:29:10 +00:00
|
|
|
elif [ "$CMD" = "rebuild-world" ]; then
|
|
|
|
cmd_with_target
|
|
|
|
lagom_unsupported "The lagom target uses the host toolchain"
|
|
|
|
delete_toolchain
|
|
|
|
delete_target
|
|
|
|
ensure_toolchain
|
|
|
|
ensure_target
|
|
|
|
build_target
|
2021-03-11 04:26:26 +00:00
|
|
|
elif [ "$CMD" = "__tmux_cmd" ]; then
|
|
|
|
trap kill_tmux_session EXIT
|
|
|
|
cmd_with_target
|
|
|
|
CMD="$1"; shift
|
|
|
|
CMD_ARGS=("${CMD_ARGS[@]:1}")
|
|
|
|
if [ "$CMD" = "run" ]; then
|
|
|
|
if [ -n "${CMD_ARGS[0]}" ]; then
|
|
|
|
export SERENITY_KERNEL_CMDLINE="${CMD_ARGS[0]}"
|
|
|
|
fi
|
|
|
|
# We need to make sure qemu doesn't start until we continue in gdb
|
|
|
|
export SERENITY_EXTRA_QEMU_ARGS="${SERENITY_EXTRA_QEMU_ARGS} -d int -no-reboot -no-shutdown -S"
|
2022-03-24 22:03:32 +00:00
|
|
|
# We need to disable kaslr to let gdb map the kernel symbols correctly
|
|
|
|
export SERENITY_KERNEL_CMDLINE="${SERENITY_KERNEL_CMDLINE} disable_kaslr"
|
2021-03-11 04:26:26 +00:00
|
|
|
set_tmux_title 'qemu'
|
|
|
|
build_target run
|
|
|
|
elif [ "$CMD" = "gdb" ]; then
|
|
|
|
set_tmux_title 'gdb'
|
|
|
|
run_gdb "${CMD_ARGS[@]}"
|
|
|
|
fi
|
2021-03-07 19:37:29 +00:00
|
|
|
else
|
|
|
|
>&2 echo "Unknown command: $CMD"
|
|
|
|
usage
|
|
|
|
fi
|