|
| 1 | +# |
| 2 | +# APKBUILD.cmake |
| 3 | +# Copyright 2022 ItJustWorksTM |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +cmake_minimum_required (VERSION 3.16) |
| 19 | +message (DEBUG "CPack APKBUILD Packager v0.1") |
| 20 | + |
| 21 | +if (NOT DEFINED APKBUILD_PACKAGE_NAME) |
| 22 | + set (APKBUILD_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") |
| 23 | +endif () |
| 24 | +if (NOT DEFINED APKBUILD_PACKAGE_VERSION) |
| 25 | + set (APKBUILD_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}") |
| 26 | +endif () |
| 27 | +if (NOT DEFINED APKBUILD_PACKAGE_RELEASE) |
| 28 | + set (APKBUILD_PACKAGE_RELEASE 0) |
| 29 | +endif () |
| 30 | +if (NOT DEFINED APKBUILD_PACKAGE_DESCRIPTION) |
| 31 | + set (APKBUILD_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}") |
| 32 | +endif () |
| 33 | +string (REPLACE "\n" "\\n" APKBUILD_PACKAGE_DESCRIPTION "${APKBUILD_PACKAGE_DESCRIPTION}") |
| 34 | +if (NOT DEFINED APKBUILD_PACKAGE_HOMEPAGE) |
| 35 | + set (APKBUILD_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}") |
| 36 | +endif () |
| 37 | +if (NOT DEFINED APKBUILD_PACKAGE_ARCHITECTURE) |
| 38 | + set (APKBUILD_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}") |
| 39 | +endif () |
| 40 | +if (NOT DEFINED APKBUILD_PACKAGE_LICENSE) |
| 41 | + set (APKBUILD_PACKAGE_LICENSE "unknown") |
| 42 | +endif() |
| 43 | +if (NOT DEFINED APKBUILD_PACKAGE_DEPENDS) |
| 44 | + set (APKBUILD_PACKAGE_DEPENDS "") |
| 45 | +endif() |
| 46 | + |
| 47 | +set (SRCDIR ".") |
| 48 | +set (BUILDDIR "$srcdir/build") |
| 49 | +configure_file ("${CMAKE_CURRENT_LIST_DIR}/APKBUILD.in" "${CPACK_PACKAGE_DIRECTORY}/APKBUILD" @ONLY) |
| 50 | + |
| 51 | +if (NOT DEFINED APKBUILD_GENERATE_PACKAGE) |
| 52 | + set (APKBUILD_GENERATE_PACKAGE Yes) |
| 53 | +endif () |
| 54 | +if (NOT APKBUILD_GENERATE_PACKAGE) |
| 55 | + return () |
| 56 | +endif () |
| 57 | + |
| 58 | + |
| 59 | +list (GET CPACK_BUILD_SOURCE_DIRS 0 CPACK_SOURCE_DIR) |
| 60 | +list (GET CPACK_BUILD_SOURCE_DIRS 1 CPACK_BUILD_DIR) |
| 61 | +file (MAKE_DIRECTORY "${CPACK_BUILD_DIR}/cpack-abuild") |
| 62 | +set (SRCDIR "${CPACK_SOURCE_DIR}") |
| 63 | +set (BUILDDIR "${CPACK_BUILD_DIR}") |
| 64 | +configure_file ("${CMAKE_CURRENT_LIST_DIR}/APKBUILD.in" "${CPACK_BUILD_DIR}/cpack-abuild/APKBUILD" @ONLY) |
| 65 | + |
| 66 | +find_program (ID_EXECUTABLE id) |
| 67 | +if (NOT ID_EXECUTABLE) |
| 68 | + message (FATAL_ERROR "Unable to detect current user id (root check)") |
| 69 | +endif () |
| 70 | + |
| 71 | +execute_process (COMMAND "${ID_EXECUTABLE}" -u OUTPUT_VARIABLE uid) |
| 72 | + |
| 73 | +if (uid EQUAL 0) |
| 74 | + set (abuild_maybe_root -F) |
| 75 | +else () |
| 76 | + set (abuild_maybe_root) |
| 77 | +endif () |
| 78 | + |
| 79 | +find_program (ABUILD_EXECUTABLE abuild REQUIRED) |
| 80 | +execute_process ( |
| 81 | + COMMAND "${ABUILD_EXECUTABLE}" -P "${CPACK_TEMPORARY_DIRECTORY}" ${abuild_maybe_root} rootpkg |
| 82 | + WORKING_DIRECTORY "${CPACK_BUILD_DIR}/cpack-abuild" |
| 83 | +) |
| 84 | + |
| 85 | +set (CPACK_EXTERNAL_BUILT_PACKAGES) |
| 86 | +file (GLOB_RECURSE package_files "${CPACK_TEMPORARY_DIRECTORY}/*.apk") |
| 87 | +foreach (package_file IN LISTS package_files) |
| 88 | + file (COPY "${package_file}" DESTINATION "${CPACK_PACKAGE_DIRECTORY}") |
| 89 | + get_filename_component (package_filename "${package_file}" NAME) |
| 90 | + list (APPEND CPACK_EXTERNAL_BUILT_PACKAGES "${CPACK_PACKAGE_DIRECTORY}/${package_filename}") |
| 91 | +endforeach () |
0 commit comments