From 419750b8d03ab8d325c97eb28add80126e03e05f Mon Sep 17 00:00:00 2001 From: AndrewQuijano Date: Sat, 21 Dec 2024 22:24:59 -0500 Subject: [PATCH] Can create debian and rpm, just want to get the formatting looking nice --- BUILDING.md | 10 +++++ CMakeLists.txt | 3 ++ CPackConfig.txt | 59 ++++++++++++++++++++++++++++++ packages/rpm/remove_blank_lines.sh | 3 ++ packages/rpm/uninstall.sh | 25 +++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 CPackConfig.txt create mode 100644 packages/rpm/remove_blank_lines.sh create mode 100644 packages/rpm/uninstall.sh diff --git a/BUILDING.md b/BUILDING.md index a6c51c7cfb..67858ee2cd 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -12,6 +12,16 @@ cmake --build build cmake --install build --prefix "" ``` +To create rpm, debian and OSX packages, run the following +```bash +cmake -B build -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX=/usr +cmake --build build +cd build +cpack -G DEB +cpack -G RPM +cpack -G DragNDrop +``` + **Windows** ```bash diff --git a/CMakeLists.txt b/CMakeLists.txt index b4c77a7996..8cd3054285 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -959,3 +959,6 @@ if(CAPSTONE_BUILD_CSTEST) set(TESTS_UNIT_DIR ${PROJECT_SOURCE_DIR}/tests/unit) add_subdirectory(${TESTS_UNIT_DIR}) endif() + +# Include CPack +include(CPackConfig.txt) \ No newline at end of file diff --git a/CPackConfig.txt b/CPackConfig.txt new file mode 100644 index 0000000000..f1aaaa0157 --- /dev/null +++ b/CPackConfig.txt @@ -0,0 +1,59 @@ +set(CPACK_PACKAGE_NAME "libcapstone-dev") +set(CPACK_PACKAGE_VENDOR "Rot127") +set(CPACK_PACKAGE_CONTACT "Rot127 ") +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.") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "lightweight multi-architecture disassembly framework - devel files") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.capstone-engine.org/") +set(CPACK_STRIP_FILES false) +set(CPACK_PACKAGE_ARCHITECTURE "amd64") +if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") + set(CPACK_PACKAGE_ARCHITECTURE "arm64") +endif() + +set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}") + +# Copy over documentation for Debian Packages +# Check if the generator includes DEB +if("DEB" IN_LIST CPACK_GENERATOR) + install(FILES "${CMAKE_SOURCE_DIR}/ChangeLog" DESTINATION "/usr/share/doc/libcapstone-dev") + install(FILES "${CMAKE_SOURCE_DIR}/CREDITS.TXT" DESTINATION "/usr/share/doc/libcapstone-dev") + install(FILES "${CMAKE_SOURCE_DIR}/README.md" DESTINATION "/usr/share/doc/libcapstone-dev") + install(FILES "${CMAKE_SOURCE_DIR}/SPONSORS.TXT" DESTINATION "/usr/share/doc/libcapstone-dev") +endif() +install(DIRECTORY "${CMAKE_SOURCE_DIR}/LICENSES" DESTINATION "/usr/share/doc/libcapstone-dev") + +# Set Debian-specific package variables +set(CPACK_DEBIAN_PACKAGE_SOURCE "capstone") +set(CPACK_DEBIAN_PACKAGE_ORIGINAL_MAINTAINER "Debian Security Tools ") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.2.5)") +set(CPACK_DEBIAN_PACKAGE_SECTION "libdevel") +set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") +set(CPACK_DEBIAN_PACKAGE_MULTIARCH "same") + +# Include additional file to run 'ldconfig' after install +set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/packages/deb/triggers") + +# RPM package settings +set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") +set(CPACK_RPM_PACKAGE_REQUIRES "libc6 >= 2.2.5") +set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packages/deb/triggers") +set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packages/rpm/uninstall.sh") +set(CPACK_RPM_CHANGELOG_FILE "${CMAKE_SOURCE_DIR}/ChangeLog") +set(CPACK_RPM_PACKAGE_LICENSE "/usr/share/doc/libcapstone-dev/LICENSES") +set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}") +set(CPACK_RPM_SPEC_MORE_DEFINE "%define credits %{_topdir}/CREDITS.TXT\n%include %{credits}") + +# Custom script to remove blank lines from spec file +set(CPACK_RPM_SPEC_MORE_DEFINE "%define __spec_post %{_rpmconfigdir}/remove_blank_lines.sh") + +# TODO: Do you have a script to run tests after installing the RPM/Debian package? +# Add %check section to RPM spec file +set(CPACK_RPM_SPEC_MORE_DEFINE "${CPACK_RPM_SPEC_MORE_DEFINE}\n%check\necho \"test\"") + +# OSX package settings +set(CPACK_BUNDLE_NAME "Capstone") +set(CPACK_BUNDLE_PLIST "xcode/CapstoneFramework/Info.plist") + +# Include CPack +include(CPack) diff --git a/packages/rpm/remove_blank_lines.sh b/packages/rpm/remove_blank_lines.sh new file mode 100644 index 0000000000..80078007e1 --- /dev/null +++ b/packages/rpm/remove_blank_lines.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# remove_blank_lines.sh +sed -i '/^$/d' "$1" \ No newline at end of file diff --git a/packages/rpm/uninstall.sh b/packages/rpm/uninstall.sh new file mode 100644 index 0000000000..542cd27162 --- /dev/null +++ b/packages/rpm/uninstall.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Remove cstool +rm -f /usr/bin/cstool + +# Remove include files +rm -rf /usr/include/capstone + +# Remove cmake files +rm -rf /usr/lib/x86_64-linux-gnu/cmake/capstone + +# Remove libraries +rm -f /usr/lib/x86_64-linux-gnu/libcapstone.a +rm -f /usr/lib/x86_64-linux-gnu/libcapstone.so +rm -f /usr.lib/x86_64-linux-gnu/libcapstone.so.6 +rm -f /usr/lib/x86_64-linux-gnu/libcapstone.so.6.0.0 + +# Remove pkgconfig files +rm -f /usr/lib/x86_64-linux-gnu/pkgconfig/capstone.pc + +# Remove documentation +rm -rf /usr/share/doc/libcapstone-dev + +# Run ldconfig to update the shared library cache +ldconfig \ No newline at end of file