├── README.md ├── build-sfml.sh ├── check-requirements.sh ├── download-ndk-and-build-sfml.sh ├── rebuild-all.sh └── rebuild.sh /README.md: -------------------------------------------------------------------------------- 1 | # Build SFML For Android On Linux 2 | Bash scripts to build SFML for Android, using the latest Android NDK 3 | 4 | # Requirements 5 | 6 | Successfully building SFML requires that you have 7 | * `cmake` (minimum version is **3.7.2**) 8 | * `make` 9 | * `git` 10 | * `unzip` 11 | * `wget` 12 | 13 | Additional requirements to enable parallel builds (compile SFML for every ABI at the same time): 14 | 15 | * `gnome-terminal` 16 | 17 | # How to use it 18 | 19 | ### ● If you have NDK installed: 20 | 21 | Run `build-sfml.sh` followed by the absolute path to your NDK. For example, if your NDK is located at /home/test/android-ndk-r19, then you have to run `./build-sfml.sh /home/test/android-ndk-r19`. 22 | 23 | ### ● If you don't have NDK installed: 24 | 25 | You can install the newest version before building SFML, by executing `download-ndk-and-build-sfml.sh`. You can also specify where to install ndk, by providing an absolute path to the script. For example, if you want to install it in /etc/Android, then you should run `download-ndk-and-build-sfml.sh /etc/Android`. After downloading the NDK, this script will also run `build-sfml.sh` and thus build SFML. 26 | 27 | ## Path to the downloaded SFML repository 28 | 29 | The script will download SFML to ~/SFML. For example, if your username is foo, you will be able to find the downloaded SFML repository at /home/foo/SFML. 30 | 31 | ## Created scripts 32 | 33 | The following scripts are created in ~/SFML/build and its subdirectories. They are also run by `build-sfml.sh` when it builds SFML for the first time. You can use them to rebuild SFML in case you modify something in it. 34 | 35 | #### ● `rebuild-all.sh`: 36 | Rebuilds SFML for all ABIs. 37 | 38 | #### ● `rebuild.sh` (in each ABI's directory): 39 | Rebuilds SFML for the ABI corrisponding to script's directory. 40 | -------------------------------------------------------------------------------- /build-sfml.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $# < 1 ]]; then 4 | echo "Please provide the path to your ndk" 5 | exit 1 6 | fi 7 | 8 | ./check-requirements.sh 9 | if [[ $? != 0 ]]; then 10 | exit 1 11 | fi 12 | 13 | ndk_input_path=$1 14 | if [[ ${1: -1} != / ]]; then 15 | ndk_input_path=${ndk_input_path}/ 16 | fi 17 | 18 | readonly CURRENT_PATH=$(dirname "$(readlink -f "$0")") 19 | 20 | if [[ ${ndk_input_path:0:1} != / ]]; then 21 | readonly NDK_PATH=${CURRENT_PATH}/${ndk_input_path} 22 | else 23 | readonly NDK_PATH=${ndk_input_path} 24 | fi 25 | 26 | if [[ $# < 2 ]]; then 27 | readonly INSTALL_PATH=~/SFML/ 28 | else 29 | readonly INSTALL_PATH=$2 30 | fi 31 | 32 | echo "Downloading SFML to ${INSTALL_PATH}" 33 | mkdir -p ${INSTALL_PATH} 34 | pushd ${INSTALL_PATH} 35 | git clone https://github.com/SFML/SFML 36 | 37 | cd SFML 38 | mkdir build 39 | cd build 40 | 41 | abis=(x86 armeabi-v7a arm64-v8a x86_64) 42 | for abi in ${abis[@]} ; do 43 | mkdir ${abi} 44 | echo "#!/usr/bin/env bash" > ${abi}/rebuild-temp 45 | echo "readonly CURRENT_ABI=${abi}" >> ${abi}/rebuild-temp 46 | echo "readonly NDK_PATH=${NDK_PATH}" >> ${abi}/rebuild-temp 47 | done 48 | 49 | popd 50 | for abi in ${abis[@]} ; do 51 | temp_file_path=${INSTALL_PATH}/SFML/build/${abi}/rebuild-temp 52 | 53 | cat ${CURRENT_PATH}/rebuild.sh >> ${temp_file_path} 54 | cat ${temp_file_path} > ${INSTALL_PATH}/SFML/build/${abi}/rebuild.sh 55 | chmod +x ${INSTALL_PATH}/SFML/build/${abi}/rebuild.sh 56 | 57 | rm -rf ${temp_file_path} 58 | done 59 | 60 | cp ${CURRENT_PATH}/rebuild-all.sh ${INSTALL_PATH}/SFML/build/ 61 | 62 | ${INSTALL_PATH}/SFML/build/rebuild-all.sh 63 | -------------------------------------------------------------------------------- /check-requirements.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | requirements=(wget unzip cmake git make) 4 | 5 | for requirement in ${requirements[@]} ; do 6 | if ! type "${requirement}" > /dev/null 2>&1; then 7 | echo "Requirement '${requirement}' not found!" 8 | exit 1 9 | fi 10 | done 11 | 12 | bad_cmake_version(){ 13 | echo "Minimum required CMake version is ${REQUIRED_CMAKE_MAJOR}.${REQUIRED_CMAKE_MINOR}.${REQUIRED_CMAKE_PATCH}" 14 | echo "You only have ${CMAKE_VERSION}" 15 | echo "Please upgrade your CMake" 16 | exit 1 17 | } 18 | 19 | readonly REQUIRED_CMAKE_MAJOR=3 20 | readonly REQUIRED_CMAKE_MINOR=7 21 | readonly REQUIRED_CMAKE_PATCH=2 22 | 23 | readonly CMAKE_VERSION=$(cmake --version | head -n 1 | sed 's/cmake version //g') 24 | readonly CMAKE_MAJOR=$(echo ${CMAKE_VERSION} | sed -r 's/^([0-9]+).*$/\1/') 25 | readonly CMAKE_MINOR=$(echo ${CMAKE_VERSION} | sed -r 's/^[0-9]+\.([0-9]+).*$/\1/') 26 | readonly CMAKE_PATCH=$(echo ${CMAKE_VERSION} | sed -r 's/^[0-9]+\.[0-9]+\.([0-9]+).*$/\1/') 27 | 28 | if (( ${CMAKE_MAJOR} < ${REQUIRED_CMAKE_MAJOR} )) ; then 29 | bad_cmake_version 30 | elif (( ${CMAKE_MAJOR} > ${REQUIRED_CMAKE_MAJOR} )) ; then 31 | exit 0 32 | fi 33 | 34 | if (( ${CMAKE_MINOR} < ${REQUIRED_CMAKE_MINOR} )) ; then 35 | bad_cmake_version 36 | elif (( ${CMAKE_MINOR} > ${REQUIRED_CMAKE_MINOR} )) ; then 37 | exit 0 38 | fi 39 | 40 | if (( ${CMAKE_PATCH} < ${REQUIRED_CMAKE_PATCH} )) ; then 41 | bad_cmake_version 42 | else 43 | exit 0 44 | fi -------------------------------------------------------------------------------- /download-ndk-and-build-sfml.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ./check-requirements.sh 4 | if [[ $? != 0 ]]; then 5 | exit 1 6 | fi 7 | 8 | readonly LATEST_NDK_VERSION=20 9 | readonly ANDROID_ZIP_NAME=android-ndk-r${LATEST_NDK_VERSION}-linux-x86_64.zip 10 | 11 | if [[ $# > 0 ]]; then 12 | readonly NDK_DOWNLOAD_PATH=$1 13 | else 14 | readonly CURRENT_PATH=$(dirname "$(readlink -f "$0")") 15 | readonly NDK_DOWNLOAD_PATH=${CURRENT_PATH} 16 | fi 17 | 18 | echo "Downloading Android NDK..." 19 | wget --no-verbose --directory-prefix ${NDK_DOWNLOAD_PATH} https://dl.google.com/android/repository/${ANDROID_ZIP_NAME} 20 | echo "Unzipping Android NDK..." 21 | unzip -q -d ${NDK_DOWNLOAD_PATH} ${NDK_DOWNLOAD_PATH}/${ANDROID_ZIP_NAME} 22 | rm -rf ${NDK_DOWNLOAD_PATH}/${ANDROID_ZIP_NAME} 23 | 24 | ./build-sfml.sh ${NDK_DOWNLOAD_PATH}/android-ndk-r${LATEST_NDK_VERSION} 25 | -------------------------------------------------------------------------------- /rebuild-all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | readonly CURRENT_PATH=$(dirname "$(readlink -f "$0")") 4 | 5 | abis=(x86 armeabi-v7a arm64-v8a x86_64) 6 | for abi in ${abis[@]} ; do 7 | pushd ${CURRENT_PATH}/${abi} 8 | if type gnome-terminal > /dev/null 2>&1; then 9 | gnome-terminal --tab -e "/bin/bash -c '${CURRENT_PATH}/${abi}/rebuild.sh; exec /bin/bash -i'" # The terminal should not be closed after the script finished running. 10 | else 11 | ${CURRENT_PATH}/${abi}/rebuild.sh 12 | fi 13 | popd 14 | done 15 | -------------------------------------------------------------------------------- /rebuild.sh: -------------------------------------------------------------------------------- 1 | #@IgnoreInspection BashAddShebang 2 | 3 | patterns_to_remove=(src CMakeFiles lib SFML* CMake* Makefile install* cmake*) 4 | 5 | for ptr in ${patterns_to_remove[@]} ; do 6 | rm -rf ${ptr} 7 | done 8 | 9 | cmake -DANDROID_ABI=${CURRENT_ABI} -DANDROID_PLATFORM=android-21 -stdlib=libc++ -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}build/cmake/android.toolchain.cmake -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK=${NDK_PATH} -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles" ../.. 10 | make 11 | make install 12 | --------------------------------------------------------------------------------