From 249b44a81a75ff81dfe18cffd0d438438c01becd Mon Sep 17 00:00:00 2001 From: YZBruh Date: Sun, 24 Aug 2025 16:16:30 +0300 Subject: [PATCH] Improve build system, etc... --- .gitignore | 3 +- CMakeLists.txt | 2 +- build.sh | 63 ++++++++----------- {cmake => build/cmake}/generate_headers.cmake | 0 src/CMakeLists.txt | 3 +- src/functions/ShellFunction.cpp | 16 +++++ src/functions/functions.hpp | 11 ++++ 7 files changed, 56 insertions(+), 42 deletions(-) rename {cmake => build/cmake}/generate_headers.cmake (100%) create mode 100644 src/functions/ShellFunction.cpp diff --git a/.gitignore b/.gitignore index fa9ecd7..dedee73 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,7 @@ cmake-build-* include/generated # Dont't add build directories -build_arm64-v8a -build_armeabi-v7a +build_* # Don't add generated objects and libs *.o diff --git a/CMakeLists.txt b/CMakeLists.txt index b272648..c114c45 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ else() endif() # Add pmt's CMake module(s) -include(cmake/generate_headers.cmake) +include(build/cmake/generate_headers.cmake) # Generate header(s) get_property(FLAGS DIRECTORY PROPERTY COMPILE_OPTIONS) diff --git a/build.sh b/build.sh index eeea693..8204771 100755 --- a/build.sh +++ b/build.sh @@ -15,74 +15,61 @@ # limitations under the License. # -set -e - -BUILD_64="build_arm64-v8a" -BUILD_32="build_armeabi-v7a" THIS="$(basename $0)" +TARGET_ABI_LIST=("arm64-v8a" "armeabi-v7a") echo() { command echo "[$THIS]: $@"; } -checks() -{ +checks() { if [ -z "$ANDROID_NDK" ]; then echo "Please set ANDROID_NDK variable as your NDK path." exit 1 fi - if [ ! -f /usr/bin/cmake ] && [ ! -f /bin/cmake ]; then + if ! which cmake &>/dev/null; then echo "Please verify your CMake installation." exit 1 fi } -clean() -{ +clean() { echo "Cleaning workspace." - rm -rf $BUILD_32 $BUILD_64 \ - include/generated \ + for a in ${TARGET_ABI_LIST[@]}; do rm -rf build_$a; done + rm -rf include/generated \ srclib/libhelper/tests/dir \ srclib/libhelper/tests/linkdir \ srclib/libhelper/tests/file.txt } -build() -{ - mkdir -p $BUILD_64 $BUILD_32 +build() { + set -e command echo -e "BUILD INFO: - ARCHS: arm64-v8a armeabi-v7a + ARCHS: ${TARGET_ABI_LIST[@]} ANDROID_PLATFORM: $ANDROID_PLATFORM ANDROID_TOOLCHAIN_FILE: $ANDROID_NDK/build/cmake/android.toolchain.cmake\n" - echo "Configuring for arm64-v8a..." - cmake -B $BUILD_64 -S . $1 \ - -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ - -DANDROID_ABI=arm64-v8a \ - -DANDROID_PLATFORM=$ANDROID_PLATFORM \ - -DANDROID_STL=c++_static + for a in ${TARGET_ABI_LIST[@]}; do + echo "Configuring for $a..." + mkdir -p build_$a + cmake -B build_$a -S . $1 \ + -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ + -DANDROID_ABI=$a \ + -DANDROID_PLATFORM=$ANDROID_PLATFORM \ + -DANDROID_STL=c++_static + done - echo "Configuring for armeabi-v7a..." - cmake -B $BUILD_32 -S . $1 \ - -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ - -DANDROID_ABI=armeabi-v7a \ - -DANDROID_PLATFORM=$ANDROID_PLATFORM \ - -DANDROID_STL=c++_static - - echo "Building arm64-v8a artifacts..." - cmake --build $BUILD_64 - echo "arm64-v8a build complete, artifacts: $PWD/$BUILD_64" - - echo "Building armeabi-v7a artifacts..." - cmake --build $BUILD_32 - echo "armeabi-v7a build complete, artifacts: $PWD/$BUILD_32" + for a in ${TARGET_ABI_LIST[@]}; do + echo "Building $a artifacts..." + cmake --build build_$a + echo "$a build complete, artifacts: $PWD/build_$a" + done } if [ $# -eq 0 ]; then - command echo "Usage: $0 build|rebuild|clean [EXTRA_CMAKE_FLAGS] [ANDROID_PLATFORM=SELECTED_ANDROID_PLATFORM]" + command echo -e "Usage: $0 build|rebuild|clean [EXTRA_CMAKE_FLAGS]\n HINT: Export ANDROID_PLATFORM if you set min Android target.\n HINT: Change TARGET_ABI_LIST array in build.sh if you build other archs." exit 1 fi -if [ -z $ANDROID_PLATFORM ]; then ANDROID_PLATFORM="android-21"; fi - +[ -z $ANDROID_PLATFORM ] && ANDROID_PLATFORM="android-21" checks case $1 in diff --git a/cmake/generate_headers.cmake b/build/cmake/generate_headers.cmake similarity index 100% rename from cmake/generate_headers.cmake rename to build/cmake/generate_headers.cmake diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e747b0b..ac53f0b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,7 +30,8 @@ set(PMT_SOURCES ) # Add pmt -add_executable(pmt ${PMT_SOURCES}) +add_executable(pmt ${PMT_SOURCES} + functions/ShellFunction.cpp) add_executable(pmt_static ${PMT_SOURCES}) # Set linker options diff --git a/src/functions/ShellFunction.cpp b/src/functions/ShellFunction.cpp new file mode 100644 index 0000000..f6ffbdc --- /dev/null +++ b/src/functions/ShellFunction.cpp @@ -0,0 +1,16 @@ +/* +Copyright 2025 Yağız Zengin + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + diff --git a/src/functions/functions.hpp b/src/functions/functions.hpp index 990be99..cdd745b 100644 --- a/src/functions/functions.hpp +++ b/src/functions/functions.hpp @@ -175,6 +175,17 @@ public: [[nodiscard]] const char *name() const override; }; +class shellFunction final : public FunctionBase { +public: + CLI::App *cmd = nullptr; + + bool init(CLI::App &_app) override; + bool run() override; + + [[nodiscard]] bool isUsed() const override; + [[nodiscard]] const char *name() const override; +}; + } // namespace PartitionManager #endif // #ifndef FUNCTIONS_HPP