2021-08-24 10:18:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
CURDIR="$PWD"
|
2024-05-23 00:03:03 +00:00
|
|
|
if [ -z ${1+x} ]; then
|
2021-08-24 10:18:20 +00:00
|
|
|
echo "Give a destination path where to run this script, please choose a path other than in the source directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-05-23 00:03:03 +00:00
|
|
|
if [ -z ${2+x} ]; then
|
2024-05-11 16:05:54 +00:00
|
|
|
echo "Specify the target system: android, linux, window, webasm"
|
2022-03-25 08:26:37 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
OS_NAME=$2
|
2024-05-23 00:03:03 +00:00
|
|
|
|
2022-03-25 08:26:37 +00:00
|
|
|
COMPILEFLAGS="-fPIC"
|
|
|
|
LINKFLAGS="-fPIC"
|
|
|
|
if [[ "${OS_NAME}" == "webasm" ]]; then
|
|
|
|
COMPILEFLAGS="-pthread -O3 -g -s USE_PTHREADS=1"
|
|
|
|
LINKFLAGS="-pthread -O3 -g -s USE_PTHREADS=1 -s ASYNCIFY=1 -s WASM=1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
COMP_HAS_ARM32=0
|
|
|
|
COMP_HAS_ARM64=0
|
|
|
|
COMP_HAS_x86=0
|
|
|
|
COMP_HAS_x64=0
|
|
|
|
COMP_HAS_WEBASM=0
|
|
|
|
|
|
|
|
if [[ "${OS_NAME}" == "android" ]]; then
|
|
|
|
COMP_HAS_ARM32=1
|
|
|
|
COMP_HAS_ARM64=1
|
|
|
|
COMP_HAS_x86=1
|
|
|
|
COMP_HAS_x64=1
|
|
|
|
elif [[ "${OS_NAME}" == "linux" ]]; then
|
|
|
|
COMP_HAS_x64=1
|
|
|
|
elif [[ "${OS_NAME}" == "windows" ]]; then
|
|
|
|
COMP_HAS_x86=1
|
|
|
|
COMP_HAS_x64=1
|
|
|
|
elif [[ "${OS_NAME}" == "webasm" ]]; then
|
|
|
|
COMP_HAS_WEBASM=1
|
2024-05-11 16:05:54 +00:00
|
|
|
else
|
|
|
|
echo "Specify the target system: android, linux, window, webasm"
|
|
|
|
exit 1
|
2022-03-25 08:26:37 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-24 10:18:20 +00:00
|
|
|
mkdir -p "$1"
|
|
|
|
cd "$1" || exit 1
|
|
|
|
|
2024-05-07 14:34:49 +00:00
|
|
|
_ANDROID_ABI_LEVEL=34
|
|
|
|
|
2021-08-24 10:18:20 +00:00
|
|
|
function build_cmake_lib() {
|
|
|
|
if [ ! -d "${1}" ]; then
|
2024-05-07 11:12:48 +00:00
|
|
|
if [ -z ${3+x} ]; then
|
|
|
|
git clone "${2}" "${1}"
|
|
|
|
else
|
|
|
|
git clone --single-branch --branch "${3}" "${2}" "${1}"
|
|
|
|
fi
|
2021-08-24 10:18:20 +00:00
|
|
|
fi
|
|
|
|
(
|
|
|
|
cd "${1}" || exit 1
|
2022-03-25 08:26:37 +00:00
|
|
|
cp "${CURDIR}"/scripts/compile_libs/cmake_lib_compile.sh cmake_lib_compile.sh
|
|
|
|
./cmake_lib_compile.sh "$_ANDROID_ABI_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS"
|
2021-08-24 10:18:20 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-25 08:26:37 +00:00
|
|
|
mkdir -p compile_libs
|
|
|
|
cd compile_libs || exit 1
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
# start with openssl
|
|
|
|
(
|
|
|
|
if [ ! -d "openssl" ]; then
|
|
|
|
git clone https://github.com/openssl/openssl openssl
|
|
|
|
fi
|
|
|
|
(
|
|
|
|
cd openssl || exit 1
|
2022-03-25 08:26:37 +00:00
|
|
|
cp "${CURDIR}"/scripts/compile_libs/make_lib_openssl.sh make_lib_openssl.sh
|
|
|
|
./make_lib_openssl.sh "$_ANDROID_ABI_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS"
|
2021-08-24 10:18:20 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-03-25 08:26:37 +00:00
|
|
|
build_cmake_lib zlib https://github.com/madler/zlib
|
|
|
|
build_cmake_lib png https://github.com/glennrp/libpng
|
2021-08-24 10:18:20 +00:00
|
|
|
build_cmake_lib curl https://github.com/curl/curl
|
|
|
|
build_cmake_lib freetype2 https://gitlab.freedesktop.org/freetype/freetype
|
2024-05-07 11:12:48 +00:00
|
|
|
build_cmake_lib sdl https://github.com/libsdl-org/SDL SDL2
|
2021-08-24 10:18:20 +00:00
|
|
|
build_cmake_lib ogg https://github.com/xiph/ogg
|
|
|
|
build_cmake_lib opus https://github.com/xiph/opus
|
2022-03-25 08:26:37 +00:00
|
|
|
|
2021-08-24 10:18:20 +00:00
|
|
|
(
|
|
|
|
_WAS_THERE_OPUSFILE=1
|
|
|
|
if [ ! -d "opusfile" ]; then
|
|
|
|
git clone https://github.com/xiph/opusfile opusfile
|
|
|
|
_WAS_THERE_OPUSFILE=0
|
|
|
|
fi
|
|
|
|
cd opusfile || exit 1
|
|
|
|
if [[ "$_WAS_THERE_OPUSFILE" == 0 ]]; then
|
|
|
|
./autogen.sh
|
|
|
|
fi
|
2022-03-25 08:26:37 +00:00
|
|
|
cp "${CURDIR}"/scripts/compile_libs/make_lib_opusfile.sh make_lib_opusfile.sh
|
|
|
|
./make_lib_opusfile.sh "$_ANDROID_ABI_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS"
|
2021-08-24 10:18:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# SQLite, just download and built by hand
|
|
|
|
if [ ! -d "sqlite3" ]; then
|
|
|
|
wget https://www.sqlite.org/2021/sqlite-amalgamation-3360000.zip
|
|
|
|
7z e sqlite-amalgamation-3360000.zip -osqlite3
|
|
|
|
fi
|
|
|
|
|
|
|
|
(
|
|
|
|
cd sqlite3 || exit 1
|
2022-03-25 08:26:37 +00:00
|
|
|
cp "${CURDIR}"/scripts/compile_libs/make_lib_sqlite3.sh make_lib_sqlite3.sh
|
|
|
|
./make_lib_sqlite3.sh "$_ANDROID_ABI_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS"
|
2021-08-24 10:18:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
cd ..
|
2024-05-11 16:11:39 +00:00
|
|
|
mkdir -p ddnet-libs
|
2021-08-24 10:18:20 +00:00
|
|
|
|
2022-03-25 08:26:37 +00:00
|
|
|
function copy_arches_for_lib() {
|
|
|
|
if [[ "$COMP_HAS_ARM32" == "1" ]]; then
|
|
|
|
${1} arm arm
|
|
|
|
fi
|
|
|
|
if [[ "$COMP_HAS_ARM64" == "1" ]]; then
|
|
|
|
${1} arm64 arm64
|
|
|
|
fi
|
|
|
|
if [[ "$COMP_HAS_x86" == "1" ]]; then
|
|
|
|
${1} x86 32
|
|
|
|
fi
|
|
|
|
if [[ "$COMP_HAS_x64" == "1" ]]; then
|
|
|
|
${1} x86_64 64
|
|
|
|
fi
|
|
|
|
if [[ "$COMP_HAS_WEBASM" == "1" ]]; then
|
|
|
|
${1} wasm wasm
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-08-24 10:18:20 +00:00
|
|
|
function _copy_curl() {
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/curl/"$OS_NAME"/lib"$2"
|
|
|
|
cp compile_libs/curl/build_"$OS_NAME"_"$1"/lib/libcurl.a ddnet-libs/curl/"$OS_NAME"/lib"$2"/libcurl.a
|
2021-08-24 10:18:20 +00:00
|
|
|
}
|
2022-03-25 08:26:37 +00:00
|
|
|
copy_arches_for_lib _copy_curl
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
function _copy_freetype2() {
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/freetype/"$OS_NAME"/lib"$2"
|
|
|
|
cp compile_libs/freetype2/build_"$OS_NAME"_"$1"/libfreetype.a ddnet-libs/freetype/"$OS_NAME"/lib"$2"/libfreetype.a
|
2021-08-24 10:18:20 +00:00
|
|
|
}
|
2022-03-25 08:26:37 +00:00
|
|
|
copy_arches_for_lib _copy_freetype2
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
function _copy_sdl() {
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/sdl/"$OS_NAME"/lib"$2"
|
|
|
|
cp compile_libs/sdl/build_"$OS_NAME"_"$1"/libSDL2.a ddnet-libs/sdl/"$OS_NAME"/lib"$2"/libSDL2.a
|
|
|
|
cp compile_libs/sdl/build_"$OS_NAME"_"$1"/libSDL2main.a ddnet-libs/sdl/"$OS_NAME"/lib"$2"/libSDL2main.a
|
2024-05-11 16:06:12 +00:00
|
|
|
mkdir -p ddnet-libs/sdl/include/"$OS_NAME"
|
2024-05-11 15:57:13 +00:00
|
|
|
cp -R compile_libs/sdl/include/* ddnet-libs/sdl/include/"$OS_NAME"
|
2021-08-24 10:18:20 +00:00
|
|
|
}
|
2022-03-25 08:26:37 +00:00
|
|
|
copy_arches_for_lib _copy_sdl
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
# copy java code from SDL2
|
2022-03-25 08:26:37 +00:00
|
|
|
if [[ "$OS_NAME" == "android" ]]; then
|
|
|
|
rm -R ddnet-libs/sdl/java
|
|
|
|
mkdir -p ddnet-libs/sdl/java
|
|
|
|
cp -R compile_libs/sdl/android-project/app/src/main/java/org ddnet-libs/sdl/java/
|
|
|
|
fi
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
function _copy_ogg() {
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/opus/"$OS_NAME"/lib"$2"
|
|
|
|
cp compile_libs/ogg/build_"$OS_NAME"_"$1"/libogg.a ddnet-libs/opus/"$OS_NAME"/lib"$2"/libogg.a
|
2021-08-24 10:18:20 +00:00
|
|
|
}
|
2022-03-25 08:26:37 +00:00
|
|
|
copy_arches_for_lib _copy_ogg
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
function _copy_opus() {
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/opus/"$OS_NAME"/lib"$2"
|
|
|
|
cp compile_libs/opus/build_"$OS_NAME"_"$1"/libopus.a ddnet-libs/opus/"$OS_NAME"/lib"$2"/libopus.a
|
2021-08-24 10:18:20 +00:00
|
|
|
}
|
2022-03-25 08:26:37 +00:00
|
|
|
copy_arches_for_lib _copy_opus
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
function _copy_opusfile() {
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/opus/"$OS_NAME"/lib"$2"
|
|
|
|
cp compile_libs/opusfile/build_"$OS_NAME"_"$1"/libopusfile.a ddnet-libs/opus/"$OS_NAME"/lib"$2"/libopusfile.a
|
2021-08-24 10:18:20 +00:00
|
|
|
}
|
2022-03-25 08:26:37 +00:00
|
|
|
copy_arches_for_lib _copy_opusfile
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
function _copy_sqlite3() {
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/sqlite3/"$OS_NAME"/lib"$2"
|
|
|
|
cp compile_libs/sqlite3/build_"$OS_NAME"_"$1"/sqlite3.a ddnet-libs/sqlite3/"$OS_NAME"/lib"$2"/libsqlite3.a
|
2021-08-24 10:18:20 +00:00
|
|
|
}
|
2022-03-25 08:26:37 +00:00
|
|
|
copy_arches_for_lib _copy_sqlite3
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
function _copy_openssl() {
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/openssl/"$OS_NAME"/lib"$2"
|
2021-08-24 10:18:20 +00:00
|
|
|
mkdir -p ddnet-libs/openssl/include
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/openssl/include/"$OS_NAME"
|
|
|
|
cp compile_libs/openssl/build_"$OS_NAME"_"$1"/libcrypto.a ddnet-libs/openssl/"$OS_NAME"/lib"$2"/libcrypto.a
|
|
|
|
cp compile_libs/openssl/build_"$OS_NAME"_"$1"/libssl.a ddnet-libs/openssl/"$OS_NAME"/lib"$2"/libssl.a
|
|
|
|
cp -R compile_libs/openssl/build_"$OS_NAME"_"$1"/include/* ddnet-libs/openssl/include/"$OS_NAME"
|
2022-03-25 08:26:37 +00:00
|
|
|
cp -R compile_libs/openssl/include/* ddnet-libs/openssl/include
|
|
|
|
}
|
|
|
|
copy_arches_for_lib _copy_openssl
|
|
|
|
|
|
|
|
function _copy_zlib() {
|
|
|
|
# copy headers
|
|
|
|
(
|
|
|
|
cd compile_libs/zlib || exit 1
|
|
|
|
find . -maxdepth 1 -iname '*.h' -print0 | while IFS= read -r -d $'\0' file; do
|
|
|
|
mkdir -p ../../ddnet-libs/zlib/include/"$(dirname "$file")"
|
|
|
|
cp "$file" ../../ddnet-libs/zlib/include/"$(dirname "$file")"
|
|
|
|
done
|
|
|
|
|
|
|
|
cd build_"$OS_NAME"_"$1" || exit 1
|
|
|
|
find . -maxdepth 1 -iname '*.h' -print0 | while IFS= read -r -d $'\0' file; do
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ../../../ddnet-libs/zlib/include/"$OS_NAME"/"$(dirname "$file")"
|
|
|
|
cp "$file" ../../../ddnet-libs/zlib/include/"$OS_NAME"/"$(dirname "$file")"
|
2022-03-25 08:26:37 +00:00
|
|
|
done
|
|
|
|
)
|
|
|
|
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/zlib/"$OS_NAME"/lib"$2"
|
|
|
|
cp compile_libs/zlib/build_"$OS_NAME"_"$1"/libz.a ddnet-libs/zlib/"$OS_NAME"/lib"$2"/libz.a
|
2022-03-25 08:26:37 +00:00
|
|
|
}
|
|
|
|
copy_arches_for_lib _copy_zlib
|
|
|
|
|
|
|
|
function _copy_png() {
|
2024-05-11 15:57:13 +00:00
|
|
|
mkdir -p ddnet-libs/png/"$OS_NAME"/lib"$2"
|
|
|
|
cp compile_libs/png/build_"$OS_NAME"_"$1"/libpng16.a ddnet-libs/png/"$OS_NAME"/lib"$2"/libpng16.a
|
2021-08-24 10:18:20 +00:00
|
|
|
}
|
2022-03-25 08:26:37 +00:00
|
|
|
copy_arches_for_lib _copy_png
|