diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml index e6a7de1381..3177dfa338 100644 --- a/.github/workflows/build_release.yml +++ b/.github/workflows/build_release.yml @@ -15,20 +15,14 @@ jobs: with: submodules: true - - name: Make setup.sh and check_capstone.sh are executable + - name: Create Debian and RPM packages run: | - chmod +x ./packages/deb/setup.sh - chmod +x ./packages/deb/check_capstone.sh - - - name: Build Debian Package - working-directory: ./packages/deb - run: ./setup.sh ${{ github.event.release.tag_name }} - - - name: Run sanity checks on the Debian package - working-directory: ./packages/deb - run: | - ./check_capstone.sh ./libcapstone-dev_${{ github.event.release.tag_name }}_amd64.deb - + cmake -B build -DPROJECT_VERSION=${{ github.event.release.tag_name }} -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX=/usr + cmake --build build + cd build + cpack -G DEB + cpack -G RPM + - name: Upload debian package to release uses: softprops/action-gh-release@v2 env: @@ -36,8 +30,9 @@ jobs: with: tag_name: ${{ github.event.release.tag_name }} files: | - ./packages/deb/*.deb - + ./build/*.deb + ./build/*.rpm + - name: Create archive id: archive run: | 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..a7e5e7c1e1 --- /dev/null +++ b/CPackConfig.txt @@ -0,0 +1,75 @@ +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_VERSION "${PROJECT_VERSION}") + +# Determine architecture +if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") + set(CPACK_PACKAGE_ARCHITECTURE "aarch64") +elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") + if(CMAKE_SIZE_OF_VOID_P EQUAL 4) + set(CPACK_PACKAGE_ARCHITECTURE "i386") + else() + set(CPACK_PACKAGE_ARCHITECTURE "x86_64") + endif() +elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm") + if(CMAKE_SIZE_OF_VOID_P EQUAL 4) + set(CPACK_PACKAGE_ARCHITECTURE "armhf") + else() + set(CPACK_PACKAGE_ARCHITECTURE "arm64") + endif() +else() + set(CPACK_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) +endif() + +# 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") + install(DIRECTORY "${CMAKE_SOURCE_DIR}/LICENSES" DESTINATION "/usr/share/doc/libcapstone-dev") +endif() + +# Set Debian-specific package variables +set(CPACK_DEBIAN_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}") +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_NAME "capstone-devel") +set(CPACK_RPM_PACKAGE_VERSION "${PROJECT_VERSION}") +# set(CPACK_RPM_PACKAGE_RELEASE "6.fc42") +set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) +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/rpm/postinstall.sh") +set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packages/rpm/postinstall.sh") +set(CPACK_RPM_CHANGELOG_FILE "${CMAKE_SOURCE_DIR}/ChangeLog") +set(CPACK_RPM_PACKAGE_LICENSE "BSD3, LLVM") +set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}") + +# 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\ntrue") + +# TODO: Please help get CPack working for Mac OSX packages too +# 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/capstone.spec b/packages/rpm/capstone.spec deleted file mode 100644 index 738187445c..0000000000 --- a/packages/rpm/capstone.spec +++ /dev/null @@ -1,167 +0,0 @@ -Name: capstone -Version: 3.0.4 -Release: 2 -Summary: A lightweight multi-platform, multi-architecture disassembly framework - -License: BSD -URL: http://www.capstone-engine.org/ -Source0: http://www.capstone-engine.org/download/%{version}/%{name}-%{version}.tar.gz - -%if 0%{?fedora} > 12 -%global with_python3 1 -%else -%{!?__python2: %global __python2 /usr/bin/python2} -%{!?python2_sitelib: %global python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print (get_python_lib())")} -%endif - -%global srcname distribute - -BuildRequires: python2-devel -BuildRequires: jna -BuildRequires: java-devel -%if 0%{?with_python3} -BuildRequires: python3-devel -%endif # if with_python3 -%global _hardened_build 1 - - -%description -Capstone is a disassembly framework with the target of becoming the ultimate -disasm engine for binary analysis and reversing in the security community. - -%package devel -Summary: Development files for %{name} -Requires: %{name}%{?_isa} = %{version}-%{release} - -%description devel -The %{name}-devel package contains libraries and header files for -developing applications that use %{name}. - -%package python -Summary: Python bindings for %{name} -Requires: %{name}%{?_isa} = %{version}-%{release} - -%description python -The %{name}-python package contains python bindings for %{name}. - -%if 0%{?with_python3} -%package python3 -Summary: Python3 bindings for %{name} -Requires: %{name}%{?_isa} = %{version}-%{release} - -%description python3 -The %{name}-python3 package contains python3 bindings for %{name}. -%endif # with_python3 - -%package java -Summary: Java bindings for %{name} -Requires: %{name} = %{version}-%{release} -BuildArch: noarch - -%description java -The %{name}-java package contains java bindings for %{name}. - -%prep -%setup -q - -%build -DESTDIR="%{buildroot}" V=1 CFLAGS="%{optflags}" \ -LIBDIRARCH="%{_lib}" INCDIR="%{_includedir}" make %{?_smp_mflags} - -# Fix pkgconfig file -sed -i 's;%{buildroot};;' capstone.pc -grep -v archive capstone.pc > capstone.pc.tmp -mv capstone.pc.tmp capstone.pc - -# build python bindings -pushd bindings/python -CFLAGS="%{optflags}" %{__python2} setup.py build -%if 0%{?with_python3} -CFLAGS="%{optflags}" %{__python3} setup.py build -%endif # with_python3 -popd - -# build java bindings -pushd bindings/java -make CFLAGS="%{optflags}" # %{?_smp_mflags} parallel seems broken -popd - -%install -DESTDIR=%{buildroot} LIBDIRARCH=%{_lib} \ -INCDIR="%{_includedir}" make install -find %{buildroot} -name '*.la' -exec rm -f {} ';' -find %{buildroot} -name '*.a' -exec rm -f {} ';' - -# install python bindings -pushd bindings/python -%{__python2} setup.py install --skip-build --root %{buildroot} -%if 0%{?with_python3} -%{__python3} setup.py install --skip-build --root %{buildroot} -%endif # with_python3 -popd - -# install java bindings -install -D -p -m 0644 bindings/java/%{name}.jar %{buildroot}/%{_javadir}/%{name}.jar - -%check -ln -s libcapstone.so libcapstone.so.3 -make check LD_LIBRARY_PATH="`pwd`" - -%post -p /sbin/ldconfig - -%postun -p /sbin/ldconfig - - -%files -# %license does not work for RHEL<7 -%if 0%{?rhel} || 0%{?fedora} < 21 -%doc LICENSE.TXT LICENSE_LLVM.TXT -%else -%license LICENSE.TXT LICENSE_LLVM.TXT -%endif # %license workaround for RHEL<7 -%doc README ChangeLog -%{_libdir}/*.so.* - -%files devel -%{_includedir}/* -%{_libdir}/*.so -%{_libdir}/pkgconfig/* - -%files python -%{python2_sitelib}/*egg-info -%{python2_sitelib}/%{name} - -%if 0%{?with_python3} -%files python3 -%{python3_sitelib}/*egg-info -%{python3_sitelib}/%{name} -%endif # _with_python3 - -%files java -%{_javadir}/ - -%changelog -* Thu Jul 16 2015 Stefan Cornelius - 3.0.4-2 -- Fix EPEL6 build problems - -* Wed Jul 15 2015 Stefan Cornelius - 3.0.4-1 -- new version 3.0.4. Includes security fixes. - -* Tue May 12 2015 Stefan Cornelius - 3.0.3-2 -- Addressed issues found during package review. - -* Fri May 08 2015 Stefan Cornelius - 3.0.3-1 -- Update to version 3.0.3 - -* Fri May 08 2015 Stefan Cornelius - 3.0.2-3 -- Added python3 and hardened build support. Update java building. -- Various cleanups. - -* Wed May 06 2015 Stefan Cornelius - 3.0.2-2 -- Update to 3.0.2. Fix 64bit issues. add %check. - -* Sat Sep 27 2014 Adel Gadllah - 2.1.2-2 -- Addressed issues found during package review. - -* Mon May 19 2014 Adel Gadllah - 2.1.2-1 -- Initial package diff --git a/packages/rpm/postinstall.sh b/packages/rpm/postinstall.sh new file mode 100644 index 0000000000..0a8c3154dd --- /dev/null +++ b/packages/rpm/postinstall.sh @@ -0,0 +1,2 @@ +#!/bin/sh +/sbin/ldconfig \ No newline at end of file