1PACKAGE_NAME?=	librdkafka
2VERSION?=	$(shell ../get_version.py ../../src/rdkafka.h)
3
4# Jenkins CI integration
5BUILD_NUMBER?= 1
6
7MOCK_CONFIG?=default
8
9RESULT_DIR?=pkgs-$(VERSION)-$(BUILD_NUMBER)-$(MOCK_CONFIG)
10
11# Where built packages are copied with `make copy-artifacts`
12ARTIFACTS_DIR?=../../artifacts
13
14all: rpm
15
16
17SOURCES:
18	mkdir -p SOURCES
19
20archive: SOURCES
21	cd ../../ && \
22	git archive --prefix=$(PACKAGE_NAME)-$(VERSION)/ \
23		-o packaging/rpm/SOURCES/$(PACKAGE_NAME)-$(VERSION).tar.gz HEAD
24
25
26build_prepare: archive
27	mkdir -p $(RESULT_DIR)
28	rm -f $(RESULT_DIR)/$(PACKAGE_NAME)*.rpm
29
30
31srpm: build_prepare
32	/usr/bin/mock \
33		-r $(MOCK_CONFIG) \
34		$(MOCK_OPTIONS) \
35		--define "__version $(VERSION)" \
36		--define "__release $(BUILD_NUMBER)" \
37		--enable-network \
38		--resultdir=$(RESULT_DIR) \
39		--no-clean --no-cleanup-after \
40		--install epel-release \
41		--buildsrpm \
42		--spec=librdkafka.spec \
43		--sources=SOURCES || \
44	(tail -n 100 pkgs-$(VERSION)*/*log ; false)
45	@echo "======= Source RPM now available in $(RESULT_DIR) ======="
46
47rpm: srpm
48	/usr/bin/mock \
49		-r $(MOCK_CONFIG) \
50		$(MOCK_OPTIONS) \
51		--define "__version $(VERSION)"\
52		--define "__release $(BUILD_NUMBER)"\
53		--enable-network \
54		--resultdir=$(RESULT_DIR) \
55		--no-clean --no-cleanup-after \
56		--rebuild $(RESULT_DIR)/$(PACKAGE_NAME)*.src.rpm || \
57	(tail -n 100 pkgs-$(VERSION)*/*log ; false)
58	@echo "======= Binary RPMs now available in $(RESULT_DIR) ======="
59
60copy-artifacts:
61	cp $(RESULT_DIR)/*rpm $(ARTIFACTS_DIR)
62
63clean:
64	rm -rf SOURCES
65	/usr/bin/mock -r $(MOCK_CONFIG) --clean
66
67distclean: clean
68	rm -f build.log root.log state.log available_pkgs installed_pkgs \
69		*.rpm *.tar.gz
70
71# Prepare ubuntu 14.04 for building RPMs with mock.
72#  - older versions of mock needs the config file to reside in /etc/mock,
73#    so we copy it there.
74#  - add a mock system group (if not already exists)
75#  - add the current user to the mock group.
76#  - prepare mock environment with some needed packages.
77# NOTE: This target should be run with sudo.
78prepare_ubuntu:
79	apt-get -qq update
80	apt-get install -y -qq mock make git python-lzma
81	cp *.cfg /etc/mock/
82	addgroup --system mock || true
83	adduser $$(whoami) mock
84	/usr/bin/mock -r $(MOCK_CONFIG) --init
85	/usr/bin/mock -r $(MOCK_CONFIG) \
86		--enable-network \
87		--no-cleanup-after \
88		--install epel-release shadow-utils
89
90prepare_centos:
91	yum install -y -q mock make git
92	cp *.cfg /etc/mock/
93