2020-10-10 03:26:24 +02:00
|
|
|
#!/bin/bash -e
|
2020-12-28 19:52:17 +01:00
|
|
|
# MAIN REQUIRED ENVIRONMENT VARIABLES:
|
|
|
|
# OPERATING_SYSTEM_NAME = <windows | linux | osx>
|
2021-01-03 14:44:17 +01:00
|
|
|
# OPERATING_SYSTEM_NAME_SHORT = <win | linux | osx>
|
2021-09-14 13:32:20 +02:00
|
|
|
# CPU_ARCHITECTURE_NAME = <amd64 | aarch64 | 386 | s390x | armhf | ppc64le>
|
2020-12-28 19:52:17 +01:00
|
|
|
# IMPLEMENTATION_NAME = <tdlib | tdlight>
|
2021-01-05 12:34:21 +01:00
|
|
|
# BUILD_TYPE = <Debug | Release | RelWithDebInfo | MinSizeRel>
|
2020-12-28 19:52:17 +01:00
|
|
|
# CPU_CORES = "-- -j<cores>" or "-m" on Windows
|
|
|
|
# OTHER REQUIRED ENVIRONMENT VARIABLES:
|
|
|
|
# CMAKE_EXTRA_ARGUMENTS = <args>
|
2022-02-19 01:10:17 +01:00
|
|
|
# OPTIONAL ENVIRONMENT VARIABLES:
|
|
|
|
# CROSS_BUILD_DEPS_DIR = <args>
|
2020-10-10 03:26:24 +02:00
|
|
|
|
|
|
|
# Check variables correctness
|
|
|
|
if [ -z "${OPERATING_SYSTEM_NAME}" ]; then
|
|
|
|
echo "Missing parameter: OPERATING_SYSTEM_NAME"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-03 14:44:17 +01:00
|
|
|
if [ -z "${OPERATING_SYSTEM_NAME_SHORT}" ]; then
|
|
|
|
echo "Missing parameter: OPERATING_SYSTEM_NAME_SHORT"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-10-10 03:26:24 +02:00
|
|
|
if [ -z "${CPU_ARCHITECTURE_NAME}" ]; then
|
|
|
|
echo "Missing parameter: CPU_ARCHITECTURE_NAME"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "${IMPLEMENTATION_NAME}" ]; then
|
|
|
|
echo "Missing parameter: IMPLEMENTATION_NAME"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-05 12:34:21 +01:00
|
|
|
if [ -z "${BUILD_TYPE}" ]; then
|
|
|
|
echo "Missing parameter: BUILD_TYPE"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-10-10 03:26:24 +02:00
|
|
|
if [ -z "${CPU_CORES}" ]; then
|
|
|
|
echo "Missing parameter: CPU_CORES"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-09-11 12:27:22 +02:00
|
|
|
source ./setup-variables.sh
|
|
|
|
|
2020-12-28 19:52:17 +01:00
|
|
|
cd ../../
|
2021-04-07 21:51:32 +02:00
|
|
|
JAVA_API_PACKAGE_PATH="it/tdlight/jni"
|
|
|
|
JAVA_LIB_PACKAGE_PATH="it/tdlight/tdnative"
|
2020-10-10 03:26:24 +02:00
|
|
|
|
|
|
|
# Print details
|
|
|
|
echo "Compiling tdjni..."
|
|
|
|
echo "Current directory: $(pwd)"
|
|
|
|
echo "Operating system: ${OPERATING_SYSTEM_NAME}"
|
|
|
|
echo "Architecture: ${CPU_ARCHITECTURE_NAME}"
|
|
|
|
echo "Td implementation: ${IMPLEMENTATION_NAME}"
|
2021-01-05 12:34:21 +01:00
|
|
|
echo "Build type: ${BUILD_TYPE}"
|
2020-10-10 15:08:26 +02:00
|
|
|
echo "CPU cores count: ${CPU_CORES}"
|
|
|
|
echo "CMake extra arguments: '${CMAKE_EXTRA_ARGUMENTS}'"
|
2021-04-07 21:51:32 +02:00
|
|
|
echo "JAVA_API_PACKAGE_PATH: '${JAVA_API_PACKAGE_PATH}'"
|
|
|
|
echo "JAVA_LIB_PACKAGE_PATH: '${JAVA_LIB_PACKAGE_PATH}'"
|
2020-10-10 03:26:24 +02:00
|
|
|
|
|
|
|
# Delete old data
|
|
|
|
echo "Deleting old data..."
|
|
|
|
[ -d ./generated/tdjni_build/ ] && rm -r ./generated/tdjni_build/
|
|
|
|
[ -d ./generated/tdjni_bin/ ] && rm -r ./generated/tdjni_bin/
|
|
|
|
[ -d ./generated/tdjni_docs/ ] && rm -r ./generated/tdjni_docs/
|
|
|
|
[ -d ./generated/src/main/jni-cpp-src/ ] && rm -r ./generated/src/main/jni-cpp-src/
|
|
|
|
[ -d ./generated/src/main/jni-java-src/ ] && rm -r ./generated/src/main/jni-java-src/
|
|
|
|
|
|
|
|
# Create missing folders
|
|
|
|
echo "Creating missing folders..."
|
|
|
|
[ -d ./generated/tdjni_build/ ] || mkdir ./generated/tdjni_build/
|
|
|
|
[ -d ./generated/tdjni_bin/ ] || mkdir ./generated/tdjni_bin/
|
|
|
|
[ -d ./generated/tdjni_docs/ ] || mkdir ./generated/tdjni_docs/
|
|
|
|
|
|
|
|
# Copy source files
|
|
|
|
echo "Copying source files..."
|
2020-10-10 03:36:01 +02:00
|
|
|
cp -r ./src/main/jni-cpp-src/common/. ./generated/src/main/jni-cpp-src
|
|
|
|
cp -r ./src/main/jni-cpp-src/${IMPLEMENTATION_NAME}/. ./generated/src/main/jni-cpp-src
|
2020-10-10 03:26:24 +02:00
|
|
|
cp -r ./src/main/jni-java-src ./generated/src/main/jni-java-src
|
|
|
|
|
2021-04-07 21:51:32 +02:00
|
|
|
# Create missing jni-src folders
|
|
|
|
echo "Creating missing jni-src folders..."
|
|
|
|
[ -d ./generated/src/main/jni-java-src/${JAVA_API_PACKAGE_PATH} ] || mkdir -p ./generated/src/main/jni-java-src/${JAVA_API_PACKAGE_PATH}
|
|
|
|
|
2020-10-11 04:12:41 +02:00
|
|
|
# Copy executables
|
|
|
|
echo "Copying executables..."
|
2020-12-27 14:05:47 +01:00
|
|
|
if [[ "$OPERATING_SYSTEM_NAME" == "windows" ]]; then
|
2021-09-14 02:58:39 +02:00
|
|
|
TD_GENERATED_BINARIES_DIR=$(realpath -m ./generated/td_tools/td/generate/Release)
|
2020-10-11 04:12:41 +02:00
|
|
|
else
|
2021-09-14 02:58:39 +02:00
|
|
|
TD_GENERATED_BINARIES_DIR=$(realpath -m ./generated/td_tools/td/generate)
|
2020-10-11 04:12:41 +02:00
|
|
|
fi
|
2021-09-14 02:58:39 +02:00
|
|
|
export TD_GENERATED_BINARIES_DIR
|
2020-10-11 04:12:41 +02:00
|
|
|
|
2020-10-10 03:26:24 +02:00
|
|
|
# Configure cmake
|
|
|
|
echo "Configuring CMake..."
|
|
|
|
cd ./generated/tdjni_build/
|
2021-09-14 02:13:12 +02:00
|
|
|
|
|
|
|
CMAKE_EXTRA_ARGUMENTS_TDJNI=""
|
2022-02-18 19:28:35 +01:00
|
|
|
if [[ -n "$CROSS_BUILD_DEPS_DIR" ]]; then
|
2021-09-14 02:13:12 +02:00
|
|
|
# shellcheck disable=SC2089
|
|
|
|
CMAKE_EXTRA_ARGUMENTS_TDJNI="${CMAKE_EXTRA_ARGUMENTS_TDJNI} -DCMAKE_TOOLCHAIN_FILE=${CROSS_BUILD_DEPS_DIR}/toolchain.cmake"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
2020-10-10 03:26:24 +02:00
|
|
|
cmake \
|
2021-01-05 12:34:21 +01:00
|
|
|
"-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" \
|
2020-10-11 04:12:41 +02:00
|
|
|
-DTD_GENERATED_BINARIES_DIR=${TD_GENERATED_BINARIES_DIR} \
|
2021-09-14 02:58:39 +02:00
|
|
|
"-DTD_SRC_DIR=$(realpath -m ../implementation/)" \
|
|
|
|
"-DTDNATIVES_BIN_DIR=$(realpath -m ../tdjni_bin/)" \
|
|
|
|
"-DTDNATIVES_DOCS_BIN_DIR=$(realpath -m ../tdjni_docs/)" \
|
|
|
|
"-DTd_DIR=$(realpath -m ../td_bin/lib/cmake/Td/)" \
|
|
|
|
"-DJAVA_SRC_DIR=$(realpath -m ../src/main/jni-java-src/)" \
|
|
|
|
"-DTDNATIVES_CPP_SRC_DIR:PATH=$(realpath -m ../src/main/jni-cpp-src/)" \
|
2021-09-14 02:13:12 +02:00
|
|
|
${CMAKE_EXTRA_ARGUMENTS_TDJNI} \
|
2020-10-10 15:32:45 +02:00
|
|
|
${CMAKE_EXTRA_ARGUMENTS} \
|
2021-09-14 02:58:39 +02:00
|
|
|
"$(realpath -m ../src/main/jni-cpp-src/)"
|
2020-10-10 03:26:24 +02:00
|
|
|
|
|
|
|
# Build
|
|
|
|
echo "Compiling ${IMPLEMENTATION_NAME} jni..."
|
2021-01-05 12:34:21 +01:00
|
|
|
cmake --build . --target install --config "${BUILD_TYPE}" ${CPU_CORES}
|
2020-10-10 04:03:20 +02:00
|
|
|
cd ..
|
2020-10-10 03:26:24 +02:00
|
|
|
|
2020-10-10 04:03:20 +02:00
|
|
|
# Copy to resources
|
|
|
|
echo "Copying to resources..."
|
|
|
|
[ -d ./src/main/resources/libs/${OPERATING_SYSTEM_NAME_SHORT}/${CPU_ARCHITECTURE_NAME}/ ] || mkdir -p ./src/main/resources/libs/${OPERATING_SYSTEM_NAME_SHORT}/${CPU_ARCHITECTURE_NAME}/
|
2020-12-27 14:05:47 +01:00
|
|
|
if [[ "$OPERATING_SYSTEM_NAME" == "windows" ]]; then
|
2020-10-10 04:03:20 +02:00
|
|
|
cp ./tdjni_bin/tdjni.dll ./src/main/resources/libs/${OPERATING_SYSTEM_NAME_SHORT}/${CPU_ARCHITECTURE_NAME}/tdjni.dll
|
2020-12-27 14:05:47 +01:00
|
|
|
elif [[ "$OPERATING_SYSTEM_NAME" == "osx" ]]; then
|
2020-10-10 04:03:20 +02:00
|
|
|
cp ./tdjni_bin/libtdjni.dylib ./src/main/resources/libs/${OPERATING_SYSTEM_NAME_SHORT}/${CPU_ARCHITECTURE_NAME}/tdjni.dylib
|
2020-12-27 14:05:47 +01:00
|
|
|
elif [[ "$OPERATING_SYSTEM_NAME" == "linux" ]]; then
|
2020-10-10 04:03:20 +02:00
|
|
|
cp ./tdjni_bin/libtdjni.so ./src/main/resources/libs/${OPERATING_SYSTEM_NAME_SHORT}/${CPU_ARCHITECTURE_NAME}/tdjni.so
|
|
|
|
fi
|
2020-10-10 03:26:24 +02:00
|
|
|
|
|
|
|
echo "Done."
|
|
|
|
exit 0
|