aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-13 04:09:56 +0000
committer_ov4 <ov4@ov4.org>2026-10-13 04:09:56 +0000
commit2cd7f7c890803a8dff2a2e9c5e5e24332979d04b (patch)
tree777acd2e7599ce3b8feb2d53c08dd679b3ce5c35
parent74c67f47c24c2aba8773ecc99272fd0f502e8df2 (diff)
build: add script-based installation and tar.xz releases
Generate the manual on installation and delegate copying to install.sh. Package the compiler, manual, installer and license using the HEAD commit's UTC timestamp and short ID, plus the target system and architecture. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
-rw-r--r--CMakeLists.txt15
-rw-r--r--cmake/Install.cmake.in18
-rw-r--r--cmake/Release.cmake33
3 files changed, 66 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c311928..b3986eb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,3 +79,18 @@ add_custom_command(
VERBATIM
)
add_custom_target(doc DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/doc/cpsc.1")
+
+configure_file(cmake/Install.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/Install.cmake" @ONLY)
+install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/Install.cmake")
+
+add_custom_target(release
+ COMMAND "${CMAKE_COMMAND}"
+ "-DCPSC_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
+ "-DCPSC_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
+ "-DCPSC_EXECUTABLE=$<TARGET_FILE:cpsc>"
+ "-DCPSC_PLATFORM=${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}"
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Release.cmake"
+ DEPENDS cpsc doc
+ COMMENT "Packaging cpsc and its manual"
+ VERBATIM
+)
diff --git a/cmake/Install.cmake.in b/cmake/Install.cmake.in
new file mode 100644
index 0000000..68ecb46
--- /dev/null
+++ b/cmake/Install.cmake.in
@@ -0,0 +1,18 @@
+# The ordinary build does not require Pandoc; generate the manual on installation.
+execute_process(
+ COMMAND "@CMAKE_COMMAND@" --build "@CMAKE_CURRENT_BINARY_DIR@" --target doc
+ RESULT_VARIABLE cpsc_doc_result
+)
+if(NOT cpsc_doc_result STREQUAL "0")
+ message(FATAL_ERROR "Cannot build the manual; make sure Pandoc is installed")
+endif()
+
+execute_process(
+ COMMAND sh "@CMAKE_CURRENT_SOURCE_DIR@/install.sh"
+ --source-dir "@CMAKE_CURRENT_BINARY_DIR@"
+ --prefix "${CMAKE_INSTALL_PREFIX}"
+ RESULT_VARIABLE cpsc_install_result
+)
+if(NOT cpsc_install_result STREQUAL "0")
+ message(FATAL_ERROR "cpsc installation failed (${cpsc_install_result})")
+endif()
diff --git a/cmake/Release.cmake b/cmake/Release.cmake
new file mode 100644
index 0000000..be78088
--- /dev/null
+++ b/cmake/Release.cmake
@@ -0,0 +1,33 @@
+# Read HEAD at packaging time so subsequent commits do not require reconfiguration.
+find_package(Git REQUIRED)
+execute_process(
+ COMMAND "${GIT_EXECUTABLE}" -C "${CPSC_SOURCE_DIR}" log -1 "--format=%ct:%h"
+ OUTPUT_VARIABLE cpsc_revision
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE cpsc_git_result
+)
+if(NOT cpsc_git_result STREQUAL "0" OR NOT cpsc_revision MATCHES "^([0-9]+):([0-9a-f]+)$")
+ message(FATAL_ERROR "Cannot read the HEAD commit for the release version")
+endif()
+set(ENV{SOURCE_DATE_EPOCH} "${CMAKE_MATCH_1}")
+set(cpsc_short_id "${CMAKE_MATCH_2}")
+string(TIMESTAMP cpsc_commit_time "%Y-%m-%d-%H-%M-%S" UTC)
+set(cpsc_package_name "cpsc-${cpsc_commit_time}-${cpsc_short_id}-${CPSC_PLATFORM}")
+set(cpsc_package_dir "${CPSC_BINARY_DIR}/release/${cpsc_package_name}")
+set(cpsc_archive "${CPSC_BINARY_DIR}/${cpsc_package_name}.tar.xz")
+
+file(REMOVE_RECURSE "${cpsc_package_dir}")
+file(MAKE_DIRECTORY "${cpsc_package_dir}/doc")
+file(COPY "${CPSC_EXECUTABLE}" "${CPSC_SOURCE_DIR}/install.sh" "${CPSC_SOURCE_DIR}/LICENSE"
+ DESTINATION "${cpsc_package_dir}")
+file(COPY "${CPSC_BINARY_DIR}/doc/cpsc.1" DESTINATION "${cpsc_package_dir}/doc")
+execute_process(
+ COMMAND "${CMAKE_COMMAND}" -E tar cJf "${cpsc_archive}" --format=gnutar "${cpsc_package_name}"
+ WORKING_DIRECTORY "${CPSC_BINARY_DIR}/release"
+ RESULT_VARIABLE cpsc_tar_result
+)
+if(NOT cpsc_tar_result STREQUAL "0")
+ file(REMOVE "${cpsc_archive}")
+ message(FATAL_ERROR "Cannot create the release archive (${cpsc_tar_result})")
+endif()
+message(STATUS "Release archive: ${cpsc_archive}")