forked from cloudera/bigtop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.mk
200 lines (172 loc) · 7.96 KB
/
package.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# Implicit targets
SHELL := /bin/bash
# Download
$(BUILD_DIR)/%/.download:
mkdir -p $(@D)
mkdir -p $(DL_DIR)
[ -f $($(PKG)_DOWNLOAD_DST) ] || (cd $(DL_DIR) && curl --retry 5 -# -L -k -o $($(PKG)_TARBALL_DST) $($(PKG)_DOWNLOAD_URL))
touch $@
# Make source RPMs
$(BUILD_DIR)/%/.srpm:
-rm -rf $(PKG_BUILD_DIR)/rpm/
mkdir -p $(PKG_BUILD_DIR)/rpm/
cp -r $(BASE_DIR)/src/pkg/rpm/$($(PKG)_NAME)/* $(PKG_BUILD_DIR)/rpm/
mkdir -p $(PKG_BUILD_DIR)/rpm/{INSTALL,SOURCES,BUILD,SRPMS}
cp $($(PKG)_DOWNLOAD_DST) $(PKG_BUILD_DIR)/rpm/SOURCES
[ -d $(BASE_DIR)/src/pkg/common/$($(PKG)_NAME) ] && cp -r $(BASE_DIR)/src/pkg/common/$($(PKG)_NAME)/* $(PKG_BUILD_DIR)/rpm/SOURCES
rpmbuild --define "_topdir $(PKG_BUILD_DIR)/rpm/" \
--define "$($(PKG)_NAME)_base_version $($(PKG)_BASE_VERSION)" \
--define "$($(PKG)_NAME)_version $($(PKG)_PKG_VERSION)$(BIGTOP_BUILD_STAMP)" \
--define "$($(PKG)_NAME)_release $($(PKG)_RELEASE_VERSION)" \
-bs \
--nodeps \
--buildroot="$(PKG_BUILD_DIR)/rpm/INSTALL" \
$(PKG_BUILD_DIR)/rpm/SPECS/$($(PKG)_NAME).spec
mkdir -p $($(PKG)_OUTPUT_DIR)/
cp $(PKG_BUILD_DIR)/rpm/SRPMS/$($(PKG)_PKG_NAME)-$($(PKG)_PKG_VERSION)$(BIGTOP_BUILD_STAMP)-$($(PKG)_RELEASE_VERSION).src.rpm \
$($(PKG)_OUTPUT_DIR)/
touch $@
# Make binary RPMs
$(BUILD_DIR)/%/.rpm: SRCRPM=$($(PKG)_OUTPUT_DIR)/$($(PKG)_PKG_NAME)-$($(PKG)_PKG_VERSION)$(BIGTOP_BUILD_STAMP)-$($(PKG)_RELEASE_VERSION).src.rpm
$(BUILD_DIR)/%/.rpm:
rpmbuild --define "_topdir $(PKG_BUILD_DIR)/rpm/" \
--define "$($(PKG)_NAME)_base_version $($(PKG)_BASE_VERSION)" \
--define "$($(PKG)_NAME)_version $($(PKG)_PKG_VERSION)$(BIGTOP_BUILD_STAMP)" \
--define "$($(PKG)_NAME)_release $($(PKG)_RELEASE_VERSION)" \
--rebuild $(SRCRPM)
cp -r $(PKG_BUILD_DIR)/rpm/RPMS/*/* $($(PKG)_OUTPUT_DIR)/
touch $@
# Make yum repo
$(BUILD_DIR)/%/.yum: $(BUILD_DIR)/%/.rpm
createrepo -o $(OUTPUT_DIR) $(OUTPUT_DIR)
touch $@
# Make source DEBs
$(BUILD_DIR)/%/.sdeb:
-rm -rf $(PKG_BUILD_DIR)/deb/
mkdir -p $(PKG_BUILD_DIR)/deb/$($(PKG)_NAME)-$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP)
cp $($(PKG)_DOWNLOAD_DST) $(PKG_BUILD_DIR)/deb/$($(PKG)_PKG_NAME)_$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP).orig.tar.gz
cd $(PKG_BUILD_DIR)/deb/$($(PKG)_NAME)-$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP) && \
tar --strip-components 1 -xvf ../$($(PKG)_PKG_NAME)_$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP).orig.tar.gz
cd $(PKG_BUILD_DIR)/deb/$($(PKG)_NAME)-$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP) && \
cp -r $(BASE_DIR)/src/pkg/deb/$($(PKG)_NAME) debian && \
cp -r $(BASE_DIR)/src/pkg/common/$($(PKG)_NAME)/* debian && \
echo -e "version=$(PKG_PKG_VERSION)\ngit.hash=deadbeaf" >> debian/build.properties && \
(echo -e "$($(PKG)_PKG_NAME) ($(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP)-$($(PKG)_RELEASE)) stable; urgency=low\n" && \
echo " Clean build" && \
echo " -- Jenkins <[email protected]> "`date +'%a, %d %b %Y %T %z'`) > debian/changelog && \
find debian -name "*.[ex,EX,~]" | xargs rm -f && \
dpkg-buildpackage -uc -us -sa -S
mkdir -p $($(PKG)_OUTPUT_DIR)/
for file in $($(PKG)_PKG_NAME)_$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP)-$($(PKG)_RELEASE).dsc \
$($(PKG)_PKG_NAME)_$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP)-$($(PKG)_RELEASE).diff.gz \
$($(PKG)_PKG_NAME)_$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP)-$($(PKG)_RELEASE)_source.changes \
$($(PKG)_PKG_NAME)_$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP).orig.tar.gz ; \
do cp $(PKG_BUILD_DIR)/deb/$$file $($(PKG)_OUTPUT_DIR); \
done
touch $@
$(BUILD_DIR)/%/.deb: SRCDEB=$($(PKG)_PKG_NAME)_$($(PKG)_PKG_VERSION)$(BIGTOP_BUILD_STAMP)-$($(PKG)_RELEASE).dsc
$(BUILD_DIR)/%/.deb:
cd $($(PKG)_OUTPUT_DIR) && \
dpkg-source -x $(SRCDEB) && \
cd $($(PKG)_PKG_NAME)-$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP) && \
debuild \
--preserve-envvar PATH \
--preserve-envvar JAVA32_HOME \
--preserve-envvar JAVA64_HOME \
--preserve-envvar JAVA5_HOME \
--preserve-envvar FORREST_HOME \
--preserve-envvar MAVEN3_HOME \
--preserve-envvar JAVA_HOME \
--set-envvar=$(PKG)_VERSION=$($(PKG)_PKG_VERSION)$(BIGTOP_BUILD_STAMP) \
--set-envvar=$(PKG)_RELEASE=$($(PKG)_RELEASE_VERSION) \
-uc -us -b
rm -rf $($(PKG)_OUTPUT_DIR)/$($(PKG)_PKG_NAME)-$(PKG_PKG_VERSION)$(BIGTOP_BUILD_STAMP)
touch $@
# Make apt repo
$(BUILD_DIR)/%/.apt: $(BUILD_DIR)/%/.deb
-mkdir -p $(OUTPUT_DIR)/apt/conf
cp $(REPO_DIR)/repos/distributions $(OUTPUT_DIR)/apt/conf
for i in $($(PKG)_OUTPUT_DIR)/$($(PKG)_PKG_NAME)_$(PKG_PKG_VERSION)*.changes ; do reprepro -Vb $(OUTPUT_DIR)/apt include bigtop $$i ; done
touch $@
# Package make function
# $1 is the target prefix, $2 is the variable prefix
define PACKAGE
# The default PKG_NAME will be the target prefix
$(2)_NAME ?= $(1)
# For deb packages, the name of the package itself
$(2)_PKG_NAME ?= $$($(2)_NAME)
# The default PKG_RELEASE will be 1 unless specified
$(2)_RELEASE ?= 1
$(2)_BUILD_DIR = $(BUILD_DIR)/$(1)/
$(2)_OUTPUT_DIR = $(OUTPUT_DIR)/$(1)
$(2)_SOURCE_DIR = $$($(2)_BUILD_DIR)/source
# Download source URL and destination path
$(2)_DOWNLOAD_URL = $($(2)_SITE)/$($(2)_TARBALL_SRC)
$(2)_DOWNLOAD_DST = $(DL_DIR)/$($(2)_TARBALL_DST)
# Define the file stamps
$(2)_TARGET_DL = $$($(2)_BUILD_DIR)/.download
$(2)_TARGET_SRPM = $$($(2)_BUILD_DIR)/.srpm
$(2)_TARGET_RPM = $$($(2)_BUILD_DIR)/.rpm
$(2)_TARGET_YUM = $$($(2)_BUILD_DIR)/.yum
$(2)_TARGET_SDEB = $$($(2)_BUILD_DIR)/.sdeb
$(2)_TARGET_DEB = $$($(2)_BUILD_DIR)/.deb
$(2)_TARGET_APT = $$($(2)_BUILD_DIR)/.apt
$(2)_TARGET_RELNOTES = $$($(2)_BUILD_DIR)/.relnotes
# We download target when the source is not in the download directory
$(1)-download: $$($(2)_TARGET_DL)
# To make srpms, we need to build the package
$(1)-srpm: $(1)-download $$($(2)_TARGET_SRPM)
# To make binary rpms, we need to build source RPMs
$(1)-rpm: $(1)-srpm $$($(2)_TARGET_RPM)
# To make a yum/zypper repo, we need to build binary RPMs
$(1)-yum: $(1)-rpm $$($(2)_TARGET_YUM)
# To make sdebs, we need to build the package
$(1)-sdeb: $(1)-download $$($(2)_TARGET_SDEB)
# To make debs, we need to make source packages
$(1)-deb: $(1)-sdeb $$($(2)_TARGET_DEB)
# To make an apt repo, we need to build binary DEBs
$(1)-apt: $(1)-deb $$($(2)_TARGET_APT)
####
# Helper targets -version -help etc
$(1)-version:
@echo "Base: $$($(2)_BASE_VERSION)"
$(1)-help:
@echo " $(1) [$(1)-version, $(1)-info, $(1)-relnotes,"
@echo " $(1)-srpm, $(1)-rpm]"
@echo " $(1)-sdeb, $(1)-deb]"
$(1)-clean:
rm -rf $(BUILD_DIR)/$(1)
$(1)-info:
@echo "Info for package $(1)"
@echo " Will download from URL: $$($(2)_DOWNLOAD_URL)"
@echo " To destination file: $$($(2)_DOWNLOAD_DST)"
@echo " Then unpack into $$($(2)_SOURCE_DIR)"
@echo
@echo "Patches:"
@echo " BASE_REF: $$($(2)_BASE_REF)"
@echo " BUILD_REF: $$($(2)_BUILD_REF)"
@echo
@echo "Version: $$($(2)_BASE_VERSION)"
@echo
@echo "Stamp status:"
@for mystamp in DL PREP PATCH BUILD SRPM RPM SDEB DEB RELNOTES;\
do echo -n " $$$$mystamp: " ; \
([ -f $($(1)_$$$$mystamp) ] && echo present || echo not present) ; \
done
# Implicit rules with PKG variable
$$($(2)_TARGET_DL): PKG=$(2)
$$($(2)_TARGET_APT) $$($(2)_TARGET_RPM) $$($(2)_TARGET_SRPM) $$($(2)_TARGET_SDEB) $$($(2)_TARGET_DEB): PKG=$(2)
$$($(2)_TARGET_RPM) $$($(2)_TARGET_SRPM) $$($(2)_TARGET_SDEB) $$($(2)_TARGET_DEB): PKG_BASE_VERSION=$$($(2)_BASE_VERSION)
$$($(2)_TARGET_APT) $$($(2)_TARGET_RPM) $$($(2)_TARGET_SRPM) $$($(2)_TARGET_SDEB) $$($(2)_TARGET_DEB): PKG_PKG_VERSION=$$($(2)_PKG_VERSION)
$$($(2)_TARGET_RPM) $$($(2)_TARGET_SRPM) $$($(2)_TARGET_SDEB) $$($(2)_TARGET_DEB): PKG_SOURCE_DIR=$$($(2)_SOURCE_DIR)
$$($(2)_TARGET_RPM) $$($(2)_TARGET_SRPM) $$($(2)_TARGET_SDEB) $$($(2)_TARGET_DEB): PKG_BUILD_DIR=$$($(2)_BUILD_DIR)
TARGETS += $(1)
TARGETS_HELP += $(1)-help
TARGETS_CLEAN += $(1)-clean
TARGETS_SRPM += $(1)-srpm
TARGETS_RPM += $(1)-rpm
TARGETS_SDEB += $(1)-sdeb
TARGETS_DEB += $(1)-deb
TARGETS_YUM += $(1)-yum
TARGETS_APT += $(1)-apt
endef