minecraft-pi-docker/scripts/build.sh

92 lines
1.9 KiB
Bash
Raw Normal View History

2020-09-25 16:43:53 +00:00
#!/bin/sh
set -e
2021-12-17 23:19:23 +00:00
# ARM Toolchain File
ARM_TOOLCHAIN_FILE="$(pwd)/cmake/armhf-toolchain.cmake"
2021-09-17 02:00:40 +00:00
# Build
build() {
# Find Toolchain
local toolchain_file="$(pwd)/cmake/$2-toolchain.cmake"
if [ ! -f "${toolchain_file}" ]; then
2021-09-21 02:47:33 +00:00
echo "Invalid Architecture: $2" > /dev/stderr
2021-09-17 02:00:40 +00:00
exit 1
2021-06-17 21:32:24 +00:00
fi
2021-06-24 16:40:34 +00:00
# Create Build Dir
2021-09-17 02:00:40 +00:00
rm -rf "build/$1-$2"
mkdir -p "build/$1-$2"
cd "build/$1-$2"
2021-06-24 16:40:34 +00:00
# Create Prefix
2021-09-17 02:00:40 +00:00
local prefix="$(cd ../../; pwd)/out/$1-$2"
2021-06-24 16:40:34 +00:00
rm -rf "${prefix}"
mkdir -p "${prefix}"
# Prepare
local extra_arg='-DMCPI_USE_MEDIA_LAYER_PROXY=ON'
if [ "$1" = "server" ]; then
extra_arg='-DMCPI_SERVER_MODE=ON'
fi
# Build ARM Components
mkdir arm
cd arm
2021-12-17 23:19:23 +00:00
cmake -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=arm "${extra_arg}" ../../..
2021-06-24 16:40:34 +00:00
make -j$(nproc)
make install DESTDIR="${prefix}"
cd ../
# Build Native Components
mkdir native
cd native
2021-09-17 02:00:40 +00:00
cmake -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" -DMCPI_BUILD_MODE=native "${extra_arg}" ../../..
2021-06-24 16:40:34 +00:00
make -j$(nproc)
make install DESTDIR="${prefix}"
cd ../
# Exit
cd ../../
}
2021-06-17 21:32:24 +00:00
# Build For ARM
2021-11-11 03:17:04 +00:00
armhf_build() {
2021-06-17 21:32:24 +00:00
# Create Build Dir
2021-11-12 05:04:11 +00:00
rm -rf "build/$1-armhf"
mkdir -p "build/$1-armhf"
cd "build/$1-armhf"
2021-06-17 21:32:24 +00:00
# Create Prefix
2021-11-12 05:04:11 +00:00
local prefix="$(cd ../../; pwd)/out/$1-armhf"
2021-06-17 21:32:24 +00:00
rm -rf "${prefix}"
mkdir -p "${prefix}"
# Prepare
local server_mode='OFF'
if [ "$1" = "server" ]; then
server_mode='ON'
fi
# Build All Components
2021-12-17 23:19:23 +00:00
cmake -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=both -DMCPI_SERVER_MODE="${server_mode}" ../..
2021-06-17 21:32:24 +00:00
make -j$(nproc)
make install DESTDIR="${prefix}"
# Exit
cd ../../
}
# Verify Mode
2021-09-17 02:00:40 +00:00
if [ "$1" != "client" ] && [ "$1" != "server" ]; then
2021-09-21 02:47:33 +00:00
echo "Invalid Mode: $1" > /dev/stderr
exit 1
fi
2021-06-17 21:32:24 +00:00
# Build
2021-11-11 03:17:04 +00:00
if [ "$2" = "armhf" ]; then
armhf_build "$1"
else
2021-09-17 02:00:40 +00:00
build "$1" "$2"
2021-06-17 21:32:24 +00:00
fi