From e5fc2a61aaf66e25e9718651ee822633473ab5e3 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 10 Nov 2021 22:17:04 -0500 Subject: [PATCH] Revamp Packaging --- .gitignore | 10 +- CMakeLists.txt | 5 +- ...-toolchain.cmake => amd64-toolchain.cmake} | 7 +- cmake/arm-toolchain.cmake | 11 -- cmake/arm64-toolchain.cmake | 7 +- cmake/armhf-toolchain.cmake | 7 + cmake/base-toolchain.cmake | 121 +++++++++++++++--- cmake/i386-toolchain.cmake | 7 + debian/.gitignore | 6 + debian/client-arm | 7 - debian/client-arm64 | 7 - debian/client-x86_64 | 7 - debian/control | 21 +++ debian/copyright | 21 +++ debian/server-arm | 7 - debian/server-arm64 | 7 - debian/server-x86_64 | 7 - scripts/build-all.sh | 14 -- scripts/build.sh | 6 +- scripts/ci/run.sh | 11 +- scripts/install-dependencies.sh | 5 + scripts/package.sh | 41 ++---- scripts/test.sh | 2 +- 23 files changed, 204 insertions(+), 140 deletions(-) rename cmake/{x86_64-toolchain.cmake => amd64-toolchain.cmake} (54%) delete mode 100644 cmake/arm-toolchain.cmake create mode 100644 cmake/armhf-toolchain.cmake create mode 100644 cmake/i386-toolchain.cmake create mode 100644 debian/.gitignore delete mode 100644 debian/client-arm delete mode 100644 debian/client-arm64 delete mode 100644 debian/client-x86_64 create mode 100644 debian/control create mode 100644 debian/copyright delete mode 100644 debian/server-arm delete mode 100644 debian/server-arm64 delete mode 100644 debian/server-x86_64 delete mode 100755 scripts/build-all.sh diff --git a/.gitignore b/.gitignore index 95c2f47..58bbd33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -/out -/debian/tmp -/.vscode -/build -/CMakeLists.txt.user +out +debian/tmp +.vscode +build +CMakeLists.txt.user *.autosave diff --git a/CMakeLists.txt b/CMakeLists.txt index 05f1a3f..1092318 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ endif() # Setup ARM Cross Compilation if(USE_ARM32_TOOLCHAIN) - include(cmake/arm-toolchain.cmake) + include(cmake/armhf-toolchain.cmake) endif() # Utility Functions @@ -77,6 +77,9 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Clang") add_link_options("-fuse-ld=lld") endif() +# PIC +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + # Buld LibPNG + ZLib + Download Minecraft: Pi Edition if(BUILD_ARM_COMPONENTS) add_subdirectory(dependencies) diff --git a/cmake/x86_64-toolchain.cmake b/cmake/amd64-toolchain.cmake similarity index 54% rename from cmake/x86_64-toolchain.cmake rename to cmake/amd64-toolchain.cmake index 36ac896..145f491 100644 --- a/cmake/x86_64-toolchain.cmake +++ b/cmake/amd64-toolchain.cmake @@ -1,8 +1,7 @@ # Compile For x86_64 include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake") -if(NOT HOST_ARCHITECTURE STREQUAL "x86_64") - # Use x86_64 Cross-Compiler - setup_toolchain("x86_64-linux-gnu") -endif() +# Use x86_64 Cross-Compiler +setup_toolchain("x86_64-linux-gnu") +# Details set(CMAKE_SYSTEM_NAME "Linux") set(CMAKE_SYSTEM_PROCESSOR "x86_64") diff --git a/cmake/arm-toolchain.cmake b/cmake/arm-toolchain.cmake deleted file mode 100644 index 42a495f..0000000 --- a/cmake/arm-toolchain.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# Compile For ARM -include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake") -if(HOST_ARCHITECTURE STREQUAL "aarch64_be" OR HOST_ARCHITECTURE STREQUAL "aarch64" OR HOST_ARCHITECTURE STREQUAL "armv8b" OR HOST_ARCHITECTURE STREQUAL "armv8l") - # Force 32-Bit Compile - add_compile_options("-m32") -elseif((NOT HOST_ARCHITECTURE STREQUAL "arm") AND (NOT HOST_ARCHITECTURE STREQUAL "armv7l")) - # Use ARM Cross-Compiler - setup_toolchain("arm-linux-gnueabihf") -endif() -set(CMAKE_SYSTEM_NAME "Linux") -set(CMAKE_SYSTEM_PROCESSOR "arm") diff --git a/cmake/arm64-toolchain.cmake b/cmake/arm64-toolchain.cmake index c6d5fd2..9671e40 100644 --- a/cmake/arm64-toolchain.cmake +++ b/cmake/arm64-toolchain.cmake @@ -1,8 +1,7 @@ # Compile For ARM64 include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake") -if(NOT (HOST_ARCHITECTURE STREQUAL "aarch64_be" OR HOST_ARCHITECTURE STREQUAL "aarch64" OR HOST_ARCHITECTURE STREQUAL "armv8b" OR HOST_ARCHITECTURE STREQUAL "armv8l")) - # Use ARM64 Cross-Compiler - setup_toolchain("aarch64-linux-gnu") -endif() +# Use ARM64 Cross-Compiler +setup_toolchain("aarch64-linux-gnu") +# Details set(CMAKE_SYSTEM_NAME "Linux") set(CMAKE_SYSTEM_PROCESSOR "aarch64") diff --git a/cmake/armhf-toolchain.cmake b/cmake/armhf-toolchain.cmake new file mode 100644 index 0000000..efcd9dd --- /dev/null +++ b/cmake/armhf-toolchain.cmake @@ -0,0 +1,7 @@ +# Compile For ARM +include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake") +# Use ARM Cross-Compiler +setup_toolchain("arm-linux-gnueabihf") +# Details +set(CMAKE_SYSTEM_NAME "Linux") +set(CMAKE_SYSTEM_PROCESSOR "arm") diff --git a/cmake/base-toolchain.cmake b/cmake/base-toolchain.cmake index 94fdbc8..fd5825b 100644 --- a/cmake/base-toolchain.cmake +++ b/cmake/base-toolchain.cmake @@ -2,19 +2,103 @@ find_program(UNAME uname /bin /usr/bin /usr/local/bin REQUIRED) execute_process(COMMAND "${UNAME}" "-m" OUTPUT_VARIABLE HOST_ARCHITECTURE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) -# Pick GCC Version -macro(pick_gcc_version gcc_root gcc_version) - file(GLOB children RELATIVE "${gcc_root}" "${gcc_root}/*") - set("${gcc_version}" "") - foreach(child IN LISTS children) - if(IS_DIRECTORY "${gcc_root}/${child}" AND ("${${gcc_version}}" STREQUAL "" OR "${child}" GREATER_EQUAL "${${gcc_version}}")) - set("${gcc_version}" "${child}") +# Get Include Directories +function(get_include_dirs target compiler result) + # Get Tool Name + set(tool "cc1") + if(compiler MATCHES "^.*g\\+\\+$") + set(tool "cc1plus") + endif() + + # Get Tool Path + execute_process( + COMMAND "${compiler}" "-print-prog-name=${tool}" + ERROR_QUIET + OUTPUT_VARIABLE tool + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Run Tool To Get Include Path + set(tool_output "") + execute_process( + COMMAND "${tool}" "-quiet" "-v" "-imultiarch" "${target}" + OUTPUT_QUIET + ERROR_VARIABLE tool_output + ERROR_STRIP_TRAILING_WHITESPACE + INPUT_FILE "/dev/null" + ) + string(REPLACE "\n" ";" tool_output "${tool_output}") + + # Loop + set(parsing_include_section FALSE) + foreach(line IN LISTS tool_output) + # Check Include Section Status + if(parsing_include_section) + # Check If Include Section Is Over + if(line MATCHES "^End of search list.$") + # Starting Include Section + set(parsing_include_section FALSE) + break() + else() + # Parsing Include Section + if(line MATCHES "^ .*$") + # Strip Line + string(STRIP "${line}" line) + # Add To List + list(APPEND "${result}" "${line}") + endif() + endif() + else() + # Check If Include Section Is Starting + if(line MATCHES "^#include <\\.\\.\\.> search starts here:$") + # Starting Include Section + set(parsing_include_section TRUE) + endif() endif() endforeach() - if("${${gcc_version}}" STREQUAL "") - message(FATAL_ERROR "Unable To Pick GCC Version") + + # Return + set("${result}" "${${result}}" PARENT_SCOPE) +endfunction() + +# Get GCC Prefix +function(get_gcc_prefix target result) + # Get Default Target + set("${result}" "" PARENT_SCOPE) + set(output "") + execute_process( + COMMAND "gcc" "-dumpmachine" + ERROR_QUIET + OUTPUT_VARIABLE output + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Check + if(NOT output STREQUAL target) + set("${result}" "${target}-" PARENT_SCOPE) endif() -endmacro() +endfunction() + +# Setup Include Directories +function(setup_include_dirs compiler target result) + # Get Full Compiler + set(prefix "") + get_gcc_prefix("${target}" prefix) + set(full_compiler "${prefix}${compiler}") + + # Get Include Directories + set(include_dirs "") + get_include_dirs("${target}" "${full_compiler}" include_dirs) + + # Loop + set(flags "") + foreach(include_dir IN LISTS include_dirs) + set(flags "${flags} -isystem ${include_dir}") + endforeach() + + # Return + set("${result}" "${${result}} ${flags}" PARENT_SCOPE) +endfunction() # Setup Toolchain macro(setup_toolchain target) @@ -24,20 +108,17 @@ macro(setup_toolchain target) set(CMAKE_CXX_COMPILER "clang++") set(CMAKE_CXX_COMPILER_TARGET "${target}") set(CMAKE_FIND_ROOT_PATH "/usr/${target}" "/usr/lib/${target}") - # Include Directories - pick_gcc_version("/usr/lib/gcc-cross/${target}" GCC_VERSION) + # Flags string(CONCAT NEW_FLAGS - "-nostdinc -nostdinc++ -Wno-unused-command-line-argument " - "-isystem /usr/${target}/include/c++/${GCC_VERSION} " - "-isystem /usr/${target}/include/c++/${GCC_VERSION}/${target} " - "-isystem /usr/${target}/include/c++/${GCC_VERSION}/backward " - "-isystem /usr/lib/gcc-cross/${target}/${GCC_VERSION}/include " - "-isystem /usr/lib/gcc-cross/${target}/${GCC_VERSION}/include-fixed " - "-isystem /usr/${target}/include " - "-isystem /usr/include" + "-nostdinc " + "-nostdinc++ " + "-Wno-unused-command-line-argument" ) set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} ${NEW_FLAGS}") set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} ${NEW_FLAGS}") + # Include Directories + setup_include_dirs("gcc" "${target}" CMAKE_C_FLAGS_INIT) + setup_include_dirs("g++" "${target}" CMAKE_CXX_FLAGS_INIT) # Extra set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) endmacro() diff --git a/cmake/i386-toolchain.cmake b/cmake/i386-toolchain.cmake new file mode 100644 index 0000000..5ae2054 --- /dev/null +++ b/cmake/i386-toolchain.cmake @@ -0,0 +1,7 @@ +# Compile For i386 +include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake") +# Use i386 Cross-Compiler +setup_toolchain("i386-linux-gnu") +# Details +set(CMAKE_SYSTEM_NAME "Linux") +set(CMAKE_SYSTEM_PROCESSOR "i386") diff --git a/debian/.gitignore b/debian/.gitignore new file mode 100644 index 0000000..07a6ac7 --- /dev/null +++ b/debian/.gitignore @@ -0,0 +1,6 @@ +* +!control +!copyright +!rukes +!source +!.gitignore diff --git a/debian/client-arm b/debian/client-arm deleted file mode 100644 index 7d98f96..0000000 --- a/debian/client-arm +++ /dev/null @@ -1,7 +0,0 @@ -Package: minecraft-pi-reborn-client -Version: ${VERSION} -Maintainer: TheBrokenRail -Description: Fun with Blocks -Homepage: https://www.minecraft.net/en-us/edition/pi -Architecture: armhf -Depends: libc6, libstdc++6, zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3, libopenal1 diff --git a/debian/client-arm64 b/debian/client-arm64 deleted file mode 100644 index d89a362..0000000 --- a/debian/client-arm64 +++ /dev/null @@ -1,7 +0,0 @@ -Package: minecraft-pi-reborn-client -Version: ${VERSION} -Maintainer: TheBrokenRail -Description: Fun with Blocks -Homepage: https://www.minecraft.net/en-us/edition/pi -Architecture: arm64 -Depends: libc6, libstdc++6, libc6:armhf, libstdc++6:armhf, zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3, libopenal1 diff --git a/debian/client-x86_64 b/debian/client-x86_64 deleted file mode 100644 index 59d8eaf..0000000 --- a/debian/client-x86_64 +++ /dev/null @@ -1,7 +0,0 @@ -Package: minecraft-pi-reborn-client -Version: ${VERSION} -Maintainer: TheBrokenRail -Description: Fun with Blocks -Homepage: https://www.minecraft.net/en-us/edition/pi -Architecture: amd64 -Depends: libc6, libstdc++6, libc6-armhf-cross, libstdc++6-armhf-cross, zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3, libopenal1, qemu-user-static diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..bbee032 --- /dev/null +++ b/debian/control @@ -0,0 +1,21 @@ +Source: minecraft-pi-reborn +Section: games +Priority: optional +Maintainer: TheBrokenRail +Build-Depends: debhelper-compat (= 12), clang:native, lld:native, cmake, make:native, libglfw3, libglfw3-dev, libfreeimage3, libfreeimage-dev:native, libopenal1, libopenal-dev, crossbuild-essential-armhf +Standards-Version: 4.4.1 +Homepage: https://www.minecraft.net/en-us/edition/pi +Vcs-Browser: https://gitea.thebrokenrail.com/TheBrokenRail/minecraft-pi-reborn +Vcs-Git: https://gitea.thebrokenrail.com/TheBrokenRail/minecraft-pi-reborn.git + +Package: minecraft-pi-reborn-client +Architecture: amd64 i386 arm64 armhf +Multi-Arch: foreign +Depends: libc6, libstdc++6, libc6-armhf-cross [!arm64 !armhf], libstdc++6-armhf-cross [!arm64 !armhf], zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3, libopenal1, qemu-user-static [!arm64 !armhf] +Description: Fun with Blocks + +Package: minecraft-pi-reborn-server +Architecture: amd64 i386 arm64 armhf +Multi-Arch: foreign +Depends: libc6, libstdc++6, libc6-armhf-cross [!arm64 !armhf], libstdc++6-armhf-cross [!arm64 !armhf], qemu-user-static [!arm64 !armhf] +Description: Fun with Blocks (Dedicated Server) diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..2bad0ca --- /dev/null +++ b/debian/copyright @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 TheBrokenRail + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/debian/server-arm b/debian/server-arm deleted file mode 100644 index 697b4ec..0000000 --- a/debian/server-arm +++ /dev/null @@ -1,7 +0,0 @@ -Package: minecraft-pi-reborn-server -Version: ${VERSION} -Maintainer: TheBrokenRail -Description: Fun with Blocks -Homepage: https://www.minecraft.net/en-us/edition/pi -Architecture: armhf -Depends: libc6, libstdc++6 diff --git a/debian/server-arm64 b/debian/server-arm64 deleted file mode 100644 index 5bd4d13..0000000 --- a/debian/server-arm64 +++ /dev/null @@ -1,7 +0,0 @@ -Package: minecraft-pi-reborn-server -Version: ${VERSION} -Maintainer: TheBrokenRail -Description: Fun with Blocks -Homepage: https://www.minecraft.net/en-us/edition/pi -Architecture: arm64 -Depends: libc6, libstdc++6, libc6:armhf, libstdc++6:armhf diff --git a/debian/server-x86_64 b/debian/server-x86_64 deleted file mode 100644 index 5c9e71b..0000000 --- a/debian/server-x86_64 +++ /dev/null @@ -1,7 +0,0 @@ -Package: minecraft-pi-reborn-server -Version: ${VERSION} -Maintainer: TheBrokenRail -Description: Fun with Blocks -Homepage: https://www.minecraft.net/en-us/edition/pi -Architecture: amd64 -Depends: libc6, libstdc++6, libc6-armhf-cross, libstdc++6-armhf-cross, qemu-user-static diff --git a/scripts/build-all.sh b/scripts/build-all.sh deleted file mode 100755 index aa60a37..0000000 --- a/scripts/build-all.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -set -e - -# Clean Prefix -rm -rf out - -# Build -./scripts/build.sh client x86_64 -./scripts/build.sh server x86_64 -./scripts/build.sh client arm64 -./scripts/build.sh server arm64 -./scripts/build.sh client arm -./scripts/build.sh server arm diff --git a/scripts/build.sh b/scripts/build.sh index 031baca..a682567 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -48,7 +48,7 @@ build() { } # Build For ARM -arm_build() { +armhf_build() { # Create Build Dir rm -rf "build/$1-arm" mkdir -p "build/$1-arm" @@ -81,8 +81,8 @@ if [ "$1" != "client" ] && [ "$1" != "server" ]; then fi # Build -if [ "$2" = "arm" ]; then - arm_build "$1" +if [ "$2" = "armhf" ]; then + armhf_build "$1" else build "$1" "$2" fi diff --git a/scripts/ci/run.sh b/scripts/ci/run.sh index 937904f..61017d4 100755 --- a/scripts/ci/run.sh +++ b/scripts/ci/run.sh @@ -14,13 +14,12 @@ echo '==== Installing Dependencies ====' ./scripts/install-dependencies.sh # Build -echo '==== Building ====' -./scripts/build-all.sh +echo '==== Building & Packaging ====' +rm -rf out build +./scripts/package.sh amd64 +./scripts/package.sh arm64 +./scripts/package.sh armhf # Test echo '==== Testing ====' ./scripts/test.sh - -# Package -echo '==== Packaging ====' -./scripts/package.sh diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh index 003b86f..4577bb1 100755 --- a/scripts/install-dependencies.sh +++ b/scripts/install-dependencies.sh @@ -20,6 +20,7 @@ sudo apt-get dist-upgrade -y # Install sudo apt-get install --no-install-recommends -y \ + build-essential \ ca-certificates \ lsb-release \ git \ @@ -27,6 +28,10 @@ sudo apt-get install --no-install-recommends -y \ lld \ cmake \ make \ + dpkg-dev \ + debhelper \ + devscripts \ + libdistro-info-perl \ libglfw3 libglfw3-dev \ libfreeimage3 libfreeimage-dev \ crossbuild-essential-armhf \ diff --git a/scripts/package.sh b/scripts/package.sh index a99cf14..fd3fe1e 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -3,35 +3,18 @@ set -e # Prepare +rm -f debian/changelog +PACKAGE='minecraft-pi-reborn' VERSION="$(cat VERSION)" +DISTRO="$(lsb_release -cs)" +EDITOR='true' NAME='TheBrokenRail' EMAIL='connor24nolan@live.com' dch -u low -v "${VERSION}" --create --distribution "${DISTRO}" --package "${PACKAGE}" "Release ${VERSION}" -# Common -package() { - local dir="out/$1" - - # Create DEBIAN Dir - rm -rf "${dir}/DEBIAN" - mkdir -p "${dir}/DEBIAN" - cp "debian/$1" "${dir}/DEBIAN/control" - - # Format DEBIAN/control - sed -i "s/\${VERSION}/${VERSION}/g" "${dir}/DEBIAN/control" - - # Fix Permissions On Jenkins - chmod -R g-s "${dir}" - - # Package - dpkg-deb --root-owner-group --build "${dir}" out -} +# Custom Architecture +ARCH="$(dpkg-architecture -qDEB_BUILD_ARCH)" +if [ -z "$1" ]; then + ARCH="$1" +fi -# Find And Package -for dir in out/*; do - # Check If Directory Exists - if [ -d "${dir}" ]; then - # Check If Debian Package Exists - pkg="$(basename ${dir})" - if [ -f "debian/${pkg}" ]; then - package "${pkg}" - fi - fi -done +# Build +export DEB_CUSTOM_OUTPUT_DIR='out' +debuild --no-lintian -a"${ARCH}" -us -uc --buildinfo-option=-u"${DEB_CUSTOM_OUTPUT_DIR}" --changes-option=-u"${DEB_CUSTOM_OUTPUT_DIR}" -b diff --git a/scripts/test.sh b/scripts/test.sh index d5c7cbe..c57235f 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -3,7 +3,7 @@ set -e # Add minecraft-pi-reborn-server To PATH -export PATH="$(pwd)/out/server-x86_64/usr/bin:${PATH}" +export PATH="$(pwd)/out/server-$(dpkg-architecture -qDEB_HOST_ARCH)/usr/bin:${PATH}" # Create Test Directory rm -rf build/test