2020-10-13 10:20:40 +02:00
|
|
|
#!/bin/sh
|
2023-01-25 19:12:07 +01:00
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2020-2023 Leroy Hopson <godot-xterm@leroy.geek.nz>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2020-09-17 11:23:01 +02:00
|
|
|
set -e
|
2020-07-13 06:14:30 +02:00
|
|
|
|
2021-07-17 06:04:08 +02:00
|
|
|
# Parse args.
|
|
|
|
args=$@
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
key="$1"
|
|
|
|
case $key in
|
|
|
|
-t|--target)
|
|
|
|
target="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
2024-02-24 07:47:12 +01:00
|
|
|
echo "Usage: ./build.sh [-t|--target <template_release|template_debug>]";
|
2021-07-17 06:04:08 +02:00
|
|
|
exit 128
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2023-01-25 19:12:07 +01:00
|
|
|
|
2021-07-17 06:04:08 +02:00
|
|
|
# Set defaults.
|
2024-02-24 07:47:12 +01:00
|
|
|
target=${target:-template_debug}
|
|
|
|
if [ "$target" == "template_debug" ]; then
|
2024-01-06 23:06:26 +01:00
|
|
|
debug_symbols="yes"
|
|
|
|
else
|
|
|
|
debug_symbols="no"
|
|
|
|
fi
|
2021-07-17 06:04:08 +02:00
|
|
|
nproc=$(nproc || sysctl -n hw.ncpu)
|
|
|
|
|
2023-01-25 19:12:07 +01:00
|
|
|
# Get the absolute path to the directory this script is in.
|
2020-10-13 10:20:40 +02:00
|
|
|
NATIVE_DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
2020-07-13 06:14:30 +02:00
|
|
|
|
2020-10-13 10:20:40 +02:00
|
|
|
# Run script inside a nix shell if it is available.
|
|
|
|
if command -v nix-shell && [ $NIX_PATH ] && [ -z $IN_NIX_SHELL ]; then
|
|
|
|
cd ${NATIVE_DIR}
|
2023-02-11 22:51:45 +01:00
|
|
|
nix-shell --pure --keep SCONS_CACHE --run "NIX_PATH=${NIX_PATH} ./build.sh $args"
|
2020-10-13 10:20:40 +02:00
|
|
|
exit
|
2020-07-13 06:14:30 +02:00
|
|
|
fi
|
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
# Update git submodules.
|
2021-07-02 19:27:34 +02:00
|
|
|
updateSubmodules() {
|
|
|
|
eval $1=$2 # E.g LIBUV_DIR=${NATIVE_DIR}/thirdparty/libuv
|
|
|
|
|
|
|
|
if [ -z "$(ls -A -- "$2")" ]; then
|
|
|
|
cd ${NATIVE_DIR}
|
|
|
|
git submodule update --init --recursive -- $2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSubmodules LIBUV_DIR ${NATIVE_DIR}/thirdparty/libuv
|
2024-02-06 12:01:14 +01:00
|
|
|
updateSubmodules LIBTSM_DIR ${NATIVE_DIR}/thirdparty/libtsm
|
2021-07-02 19:27:34 +02:00
|
|
|
updateSubmodules GODOT_CPP_DIR ${NATIVE_DIR}/thirdparty/godot-cpp
|
|
|
|
|
|
|
|
# Build libuv as a static library.
|
|
|
|
cd ${LIBUV_DIR}
|
|
|
|
mkdir build || true
|
|
|
|
cd build
|
2022-05-31 15:14:41 +02:00
|
|
|
args="-DCMAKE_BUILD_TYPE=$target -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
|
|
|
|
-DCMAKE_OSX_ARCHITECTURES=$(uname -m)"
|
2024-02-24 07:47:12 +01:00
|
|
|
if [ "$target" == "template_release" ]; then
|
2021-07-18 11:06:38 +02:00
|
|
|
args="$args -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL"
|
|
|
|
else
|
|
|
|
args="$args -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL"
|
|
|
|
fi
|
|
|
|
cmake .. $args
|
2021-07-02 19:27:34 +02:00
|
|
|
cd ..
|
2021-07-17 06:04:08 +02:00
|
|
|
cmake --build build --config $target -j$nproc
|
2021-07-02 19:27:34 +02:00
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
# Build libgodot-xterm.
|
2020-10-13 10:20:40 +02:00
|
|
|
cd ${NATIVE_DIR}
|
2024-02-24 07:47:12 +01:00
|
|
|
scons target=$target arch=$(uname -m) debug_symbols=$debug_symbols
|
2021-06-07 08:53:43 +02:00
|
|
|
|
2021-06-15 08:54:35 +02:00
|
|
|
# Use Docker to build libgodot-xterm javascript.
|
2022-12-29 10:52:13 +01:00
|
|
|
#if [ -x "$(command -v docker-compose)" ]; then
|
|
|
|
# UID_GID="0:0" TARGET=$target docker-compose build javascript
|
|
|
|
# UID_GID="$(id -u):$(id -g)" TARGET=$target docker-compose run --rm javascript
|
|
|
|
#fi
|