2020-10-13 10:20:40 +02:00
|
|
|
#!/bin/sh
|
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
|
|
|
|
;;
|
2022-05-03 07:44:40 +02:00
|
|
|
-b|--bits)
|
|
|
|
bits="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2021-07-17 06:04:08 +02:00
|
|
|
--disable-pty)
|
|
|
|
disable_pty="yes"
|
|
|
|
shift
|
|
|
|
;;
|
2022-05-03 07:44:40 +02:00
|
|
|
--docker)
|
|
|
|
docker="yes"
|
|
|
|
shift
|
|
|
|
;;
|
2021-07-17 06:04:08 +02:00
|
|
|
*)
|
2022-05-03 07:44:40 +02:00
|
|
|
echo "Usage: ./build.sh [-t|--target <release|debug>] [-b|--bits <32|64>] [--disable_pty] [--docker]";
|
2021-07-17 06:04:08 +02:00
|
|
|
exit 128
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2022-05-03 07:44:40 +02:00
|
|
|
|
2021-07-17 06:04:08 +02:00
|
|
|
# Set defaults.
|
|
|
|
target=${target:-debug}
|
2022-05-03 07:44:40 +02:00
|
|
|
bits=${bits:-64}
|
2021-07-17 06:04:08 +02:00
|
|
|
disable_pty=${disable_pty:-no}
|
|
|
|
nproc=$(nproc || sysctl -n hw.ncpu)
|
|
|
|
|
2022-05-03 07:44:40 +02: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
|
|
|
|
2022-05-03 07:44:40 +02:00
|
|
|
if [ -n "$docker" ]; then
|
|
|
|
# Run build script inside docker container.
|
|
|
|
cd ${NATIVE_DIR}
|
|
|
|
UID_GID="0:0" TARGET=$target BITS=$bits docker-compose build linux
|
|
|
|
UID_GID="$(id -u):$(id -g)" TARGET=$target BITS=$bits docker-compose run linux
|
|
|
|
exit 0
|
|
|
|
fi
|
2020-11-05 09:42:00 +01: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}
|
2021-07-17 06:04:08 +02:00
|
|
|
nix-shell --pure --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
|
|
|
|
updateSubmodules LIBTSM_DIR ${NATIVE_DIR}/thirdparty/libtsm
|
|
|
|
updateSubmodules GODOT_CPP_DIR ${NATIVE_DIR}/thirdparty/godot-cpp
|
|
|
|
|
2020-11-20 15:34:49 +01:00
|
|
|
# Build godot-cpp bindings.
|
|
|
|
cd ${GODOT_CPP_DIR}
|
2021-07-17 06:04:08 +02:00
|
|
|
echo "scons generate_bindings=yes target=$target -j$nproc"
|
2022-05-03 07:44:40 +02:00
|
|
|
scons generate_bindings=yes target=$target bits=$bits -j$nproc
|
2020-11-05 09:42:00 +01:00
|
|
|
|
2021-07-02 19:27:34 +02:00
|
|
|
# Build libuv as a static library.
|
|
|
|
cd ${LIBUV_DIR}
|
2022-05-03 07:44:40 +02:00
|
|
|
mkdir -p build
|
2021-07-02 19:27:34 +02:00
|
|
|
cd build
|
2021-07-18 11:06:38 +02:00
|
|
|
args="-DCMAKE_BUILD_TYPE=$target -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE"
|
|
|
|
if [ "$target" == "release" ]; then
|
|
|
|
args="$args -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL"
|
|
|
|
else
|
|
|
|
args="$args -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL"
|
|
|
|
fi
|
2022-05-03 07:44:40 +02:00
|
|
|
if [[ "$bits" -eq 32 ]]; then args="$args -DCMAKE_SYSTEM_PROCESSOR=i686 -DCMAKE_C_FLAGS=-m32"; fi
|
2021-07-18 11:06:38 +02:00
|
|
|
cmake .. $args
|
2021-07-02 19:27:34 +02:00
|
|
|
cd ..
|
2022-05-03 07:44:40 +02:00
|
|
|
cmake --build build --config $target
|
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}
|
2022-05-03 07:44:40 +02:00
|
|
|
scons target=$target bits=$bits disable_pty=$disable_pty -j$nproc
|
2021-06-07 08:53:43 +02:00
|
|
|
|
2021-06-15 08:54:35 +02:00
|
|
|
# Use Docker to build libgodot-xterm javascript.
|
2021-07-17 06:04:08 +02: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 javascript
|
|
|
|
fi
|