Skip to content

Commit 44b0589

Browse files
Create CPack for RPM and DEB packaging (#2596)
1 parent ea42c28 commit 44b0589

11 files changed

+101
-386
lines changed

.github/workflows/build_release.yml

+15-13
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,30 @@ jobs:
1515
with:
1616
submodules: true
1717

18-
- name: Make setup.sh and check_capstone.sh are executable
18+
- name: Configure CMake and build the project
1919
run: |
20-
chmod +x ./packages/deb/setup.sh
21-
chmod +x ./packages/deb/check_capstone.sh
22-
23-
- name: Build Debian Package
24-
working-directory: ./packages/deb
25-
run: ./setup.sh ${{ github.event.release.tag_name }}
26-
27-
- name: Run sanity checks on the Debian package
28-
working-directory: ./packages/deb
20+
cmake -B build \
21+
-DPROJECT_VERSION=${{ github.event.release.tag_name }} \
22+
-DCMAKE_BUILD_TYPE=Release \
23+
-DBUILD_SHARED_LIBS=1 \
24+
-DCMAKE_INSTALL_PREFIX=/usr
25+
cmake --build build
26+
27+
- name: Package DEB and RPM package
2928
run: |
30-
./check_capstone.sh ./libcapstone-dev_${{ github.event.release.tag_name }}_amd64.deb
31-
29+
cd build
30+
cpack -G DEB
31+
cpack -G RPM
32+
3233
- name: Upload debian package to release
3334
uses: softprops/action-gh-release@v2
3435
env:
3536
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3637
with:
3738
tag_name: ${{ github.event.release.tag_name }}
3839
files: |
39-
./packages/deb/*.deb
40+
./build/*.deb
41+
./build/*.rpm
4042
4143
- name: archive
4244
id: archive

CMakeLists.txt

+13-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ cmake_policy(SET CMP0091 NEW)
2323

2424
# Check if VERSION is provided externally, otherwise default to 5.0.3
2525
if(NOT DEFINED PROJECT_VERSION)
26-
set(PROJECT_VERSION "5.0.3")
26+
set(PROJECT_VERSION "5.0.4")
2727
endif()
2828

29-
# Extract the major, minor, and patch versions
30-
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" PROJECT_VERSION_BASE ${PROJECT_VERSION})
29+
# Use PROJECT_VERSION directly for CPack
30+
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
31+
32+
# Remove the 'v' prefix if it exists and extract the major, minor, and patch versions
33+
string(REGEX MATCH "^[vV]?([0-9]+\\.[0-9]+\\.[0-9]+)" _ ${PROJECT_VERSION})
34+
set(PROJECT_VERSION_BASE ${CMAKE_MATCH_1})
35+
36+
# Print the values of PROJECT_VERSION and PROJECT_VERSION_BASE
37+
message(STATUS "PROJECT_VERSION: ${CPACK_PACKAGE_VERSION} CAPSTONE_VERSION: ${PROJECT_VERSION_BASE}")
3138

3239
# Set the project version without the pre-release identifier
3340
project(capstone VERSION ${PROJECT_VERSION_BASE})
@@ -841,3 +848,6 @@ if(CAPSTONE_BUILD_CSTEST)
841848
install(TARGETS cstest EXPORT capstone-targets DESTINATION ${CMAKE_INSTALL_BINDIR})
842849
endif()
843850
endif()
851+
852+
set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackConfig.cmake")
853+
include(CPackConfig.txt)

CPackConfig.cmake

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Used to dynamically set the package file name based on the generator
2+
foreach(generator ${CPACK_GENERATOR})
3+
if("${generator}" STREQUAL "DEB")
4+
set(CPACK_PACKAGE_FILE_NAME ${CPACK_DEBIAN_PACKAGE_FILE_NAME})
5+
elseif("${generator}" STREQUAL "RPM")
6+
set(CPACK_PACKAGE_FILE_NAME ${CPACK_RPM_PACKAGE_FILE_NAME})
7+
elseif("${generator}" STREQUAL "DragNDrop")
8+
set(CPACK_PACKAGE_FILE_NAME ${CPACK_DMG_PACKAGE_FILE_NAME})
9+
else()
10+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-unknown")
11+
endif()
12+
message(STATUS "Generating package for ${generator} with file name ${CPACK_PACKAGE_FILE_NAME}")
13+
endforeach()

CPackConfig.txt

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright © 2024 Andrew Quijano <[email protected]>
2+
# SPDX-License-Identifier: MIT
3+
4+
# Set general CPack values
5+
set(CPACK_PACKAGE_NAME "capstone")
6+
set(CPACK_PACKAGE_VENDOR "Rot127")
7+
set(CPACK_PACKAGE_CONTACT "Rot127 <[email protected]>")
8+
set(CPACK_PACKAGE_DESCRIPTION "Capstone is a lightweight multi-platform, multi-architecture disassembly framework. These are the development headers and libraries.\n Features:\n - Support hardware architectures: AArch64, ARM, Alpha, BPF, EVM, HPPA, LongArch, M680X, M68K, MOS65XX, Mips, PowerPC, RISCV, SH, Sparc, SystemZ, TMS320C64x, TriCore, WASM, x86, XCore, Xtensa.\n - Clean/simple/lightweight/intuitive architecture-neutral API.\n - Provide details on disassembled instructions (called \\\"decomposer\\\" by some others).\n - Provide some semantics of the disassembled instruction, such as list of implicit registers read & written.\n - Thread-safe by design.\n - Special support for embedding into firmware or OS kernel.\n - Distributed under the open source BSD license.")
9+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Lightweight multi-architecture disassembly framework - devel files")
10+
set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.capstone-engine.org/")
11+
set(CPACK_STRIP_FILES false)
12+
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.TXT")
13+
14+
# Set Debian-specific package variables
15+
set(CPACK_DEBIAN_PACKAGE_NAME "libcapstone-dev")
16+
set(CPACK_DEBIAN_PACKAGE_SOURCE "capstone")
17+
set(CPACK_DEBIAN_PACKAGE_VERSION "${PROJECT_VERSION}")
18+
set(CPACK_DEBIAN_PACKAGE_ORIGINAL_MAINTAINER "Debian Security Tools <[email protected]>")
19+
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.2.5)")
20+
set(CPACK_DEBIAN_PACKAGE_SECTION "libdevel")
21+
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
22+
set(CPACK_DEBIAN_PACKAGE_MULTIARCH "same")
23+
24+
# Determine architecture for Debian package
25+
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
26+
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
27+
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
28+
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
29+
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
30+
if(CMAKE_SIZE_OF_VOID_P EQUAL 4)
31+
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "armhf")
32+
else()
33+
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "arm64")
34+
endif()
35+
else()
36+
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
37+
endif()
38+
39+
# Include additional file to run 'ldconfig' after install
40+
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/packages/deb/triggers")
41+
42+
# RPM package settings
43+
set(CPACK_RPM_PACKAGE_NAME "capstone-devel")
44+
set(CPACK_RPM_PACKAGE_VERSION "${PROJECT_VERSION}")
45+
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
46+
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
47+
set(CPACK_RPM_PACKAGE_REQUIRES "glibc >= 2.2.5")
48+
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packages/rpm/postinstall.sh")
49+
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packages/rpm/postinstall.sh")
50+
set(CPACK_RPM_CHANGELOG_FILE "${CMAKE_SOURCE_DIR}/ChangeLog")
51+
set(CPACK_RPM_PACKAGE_LICENSE "BSD3, LLVM")
52+
set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")
53+
54+
# Set package file name based on the generator
55+
set(CPACK_DEBIAN_PACKAGE_FILE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
56+
set(CPACK_RPM_PACKAGE_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}")
57+
set(CPACK_DMG_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
58+
59+
include(CPack)

packages/deb/.gitignore

-2
This file was deleted.

packages/deb/Dockerfile

-69
This file was deleted.

packages/deb/check_capstone.sh

-50
This file was deleted.

packages/deb/control

-25
This file was deleted.

packages/deb/setup.sh

-57
This file was deleted.

0 commit comments

Comments
 (0)