From 846c38a5276270bec10dcdd1d9285b7586aa0a44 Mon Sep 17 00:00:00 2001 From: Adam Fowles Date: Mon, 24 Feb 2020 14:40:17 +0000 Subject: [PATCH] Add RPM packaging --- packaging/get_version.py | 24 ++++++++++++++ packaging/rpm/Makefile | 48 ++++++++++++++++++++++++++++ packaging/rpm/cppkafka.spec | 62 +++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100755 packaging/get_version.py create mode 100644 packaging/rpm/Makefile create mode 100644 packaging/rpm/cppkafka.spec diff --git a/packaging/get_version.py b/packaging/get_version.py new file mode 100755 index 00000000..a43db41f --- /dev/null +++ b/packaging/get_version.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +import sys + +if len(sys.argv) != 2: + raise Exception('Usage: %s path/to/CMakeLists.txt' % sys.argv[0]) + +cmake_lists_file = sys.argv[1] +major = "0" +minor = "0" +patch = "0" +with open(cmake_lists_file) as f: + for line in f: + if 'CPPKAFKA_VERSION_MAJOR ' in line: + major = line.split()[-1].replace(')', '') + elif 'CPPKAFKA_VERSION_MINOR ' in line: + minor = line.split()[-1].replace(')', '') + elif 'CPPKAFKA_VERSION_REVISION ' in line: + patch = line.split()[-1].replace(')', '') + break + +version = '.'.join(str(item) for item in (major, minor, patch)) + +print version diff --git a/packaging/rpm/Makefile b/packaging/rpm/Makefile new file mode 100644 index 00000000..d60d76a2 --- /dev/null +++ b/packaging/rpm/Makefile @@ -0,0 +1,48 @@ +PACKAGE_NAME?= cppkafka +VERSION?= $(shell ../get_version.py ../../CMakeLists.txt) +BUILD_NUMBER?= 1 +MOCK_CONFIG?= default +RESULT_DIR?= pkgs-$(VERSION)-$(BUILD_NUMBER)-$(MOCK_CONFIG) + +all: rpm + +SOURCES: + mkdir -p SOURCES + +archive: SOURCES + cd ../../ && \ + git archive --prefix=$(PACKAGE_NAME)-$(VERSION)/ \ + -o packaging/rpm/SOURCES/$(PACKAGE_NAME)-$(VERSION).tar.gz HEAD + + +build_prepare: archive + mkdir -p $(RESULT_DIR) + rm -f $(RESULT_DIR)/$(PACKAGE_NAME)*.rpm + + +srpm: build_prepare + /usr/bin/mock \ + -r $(MOCK_CONFIG) \ + --define "__version $(VERSION)" \ + --define "__release $(BUILD_NUMBER)" \ + --resultdir=$(RESULT_DIR) \ + --no-clean --no-cleanup-after \ + --buildsrpm \ + --spec=cppkafka.spec \ + --sources=SOURCES + +rpm: srpm + /usr/bin/mock \ + -r $(MOCK_CONFIG) \ + --define "__version $(VERSION)"\ + --define "__release $(BUILD_NUMBER)"\ + --resultdir=$(RESULT_DIR) \ + --no-clean --no-cleanup-after \ + --rebuild $(RESULT_DIR)/$(PACKAGE_NAME)*.src.rpm + +copy-artifacts: + cp $(RESULT_DIR)/*rpm ../../artifacts/ + +clean: + rm -rf SOURCES + /usr/bin/mock -r $(MOCK_CONFIG) --clean diff --git a/packaging/rpm/cppkafka.spec b/packaging/rpm/cppkafka.spec new file mode 100644 index 00000000..c135e476 --- /dev/null +++ b/packaging/rpm/cppkafka.spec @@ -0,0 +1,62 @@ +Name: cppkafka +Version: %{__version} +Release: %{__release}%{?dist} + +Summary: Modern C++ Apache Kafka client library (wrapper for librdkafka) +Group: Development/Libraries/C and C++ +License: BSD-2-Clause +URL: https://github.com/mfontanini/cppkafka +Source: %{name}-%{version}.tar.gz + +BuildRequires: librdkafka-devel cmake g++ boost-devel openssl-devel zlib-devel + +%description +Modern C++ Apache Kafka client library (wrapper for librdkafka) + +%package devel +Summary: Development files for %{name} +Group: Development/Libraries/C and C++ +Requires: %{name} = %{version} + +%description devel +This package contains headers and libraries required to build applications +using cppkafka. + +%global debug_package %%{nil} + +%prep +%setup + +%build +cd $RPM_BUILD_DIR +mkdir build +cd build +cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + $RPM_BUILD_DIR/%{name}-%{version} +make -j$(nproc) + +%install +cd $RPM_BUILD_DIR/build +DESTDIR=%{buildroot} make install + +%clean +rm -rf %{buildroot} + +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + +%pre +%preun + +%files +%{_libdir}/lib%{name}*.so.* + +%files devel +%{_libdir}/lib%{name}*.so* +%{_libdir}/../lib/cmake/CppKafka/* +%{_includedir}/%{name} +%{_datadir}/pkgconfig + +%changelog +* Fri Feb 21 2020 Adam Fowles 0.3.1-0 +- Initial RPM package