-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild
executable file
·270 lines (227 loc) · 7.35 KB
/
build
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/make -f
DOCKER_REPO:=tanosi/
SCRIPTDIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BUILDROOT:=$(abspath $(SCRIPTDIR)/root)
# Sanity checks
ifeq ("$(SCRIPTDIR)","$(CURDIR)")
$(error Please run ./packaging/build inside of the project source directory)
endif
#
# List of supported OS
#
DEBIAN:=
UBUNTU:=ubuntu-xenial-amd64 ubuntu-xenial-i386
DEBS:=$(DEBIAN) $(UBUNTU)
# CI values
CI_COMMIT:=
CI_TAG:=
CI_BUILD:=
## Defaults
PROJECT=$(notdir $(basename ${CURDIR}))
PROJECT_PREFIX:=
VERSION=$(shell cat VERSION)
ifneq ($(CI_TAG), )
NIGHTLY=0
else
NIGHTLY=1
endif
-include $(SCRIPTDIR)/projects/$(PROJECT).mk
# Debian overrides
DEB_VERSION=$(VERSION)
ifneq ($(CI_TAG), )
DEB_RELEASE=1
else ifneq ($(CI_BUILD), )
DEB_RELEASE=0~build$(CI_BUILD)
else
DEB_RELEASE=0
endif
# Apple overrides
APPLE_VERSION=$(VERSION)
ifneq ($(CI_BUILD), )
APPLE_RELEASE=_build$(CI_BUILD)
else
APPLE_RELEASE=
endif
NAME=$(PROJECT_PREFIX)$(PROJECT)-$(VERSION)
DATE=$(shell date +%Y-%m-%d)
TARBALL=$(NAME).tar.gz
TARBALL_EXTRA_ARGS:=
# get os-dist from target name
define osdist
$(shell echo $1| sed -n 's/.*\/\([a-z]*\)-\([_a-z0-9\-]*\).*/\2/p')
endef
define ostarget
$(shell echo $1| sed -n 's/\([_a-z0-9\-]*\)-\([_a-z0-9\-]*\)-\([_a-z0-9\-]*\)/\2/p')
endef
define osarch
$(shell echo $1| sed -n 's/\([_a-z0-9\-]*\)-\([_a-z0-9\-]*\)-\([_a-z0-9\-]*\)/\3/p')
endef
define builderu
$(shell echo $1| sed -n 's/.*\/\([a-z]*\)-\([_a-z0-9\-]*\).*/\1/p' | tr a-z A-Z)
endef
define builder
$(shell echo $1| sed -n 's/.*\/\([a-z]*\)-\([_a-z0-9\-]*\).*/\1/p')
endef
$(info -------------------------------------------------------------------)
$(info Building $(PROJECT) $(VERSION))
$(info -------------------------------------------------------------------)
##
## Common rules
##
# Build all
all: $(DEBS)
TAR:=tar
ifneq ($(strip $(shell which gtar)), )
TAR=gtar
endif
$(BUILDROOT)/files:
@mkdir -p $(dir $@)
git ls-files >> $@
# Create tarball in buildroot
$(BUILDROOT)/$(TARBALL): $(BUILDROOT)/files
@echo "-------------------------------------------------------------------"
@echo "Creating source tarball"
@echo "-------------------------------------------------------------------"
$(TAR) \
--exclude=.git --exclude='.gitignore' --exclude='.gitmodules' \
--exclude=packaging \
--exclude=debian --exclude=rpm \
$(TARBALL_EXTRA_ARGS) \
--transform="s,,$(NAME)/,S" \
--owner=root --group=root \
-T $< --show-transformed \
-czvf $@
# Copy tarball to buildroot/$OS-$DIST chroot
$(BUILDROOT)/%/$(TARBALL): $(BUILDROOT)/$(TARBALL)
cp -pf $< $@
# Copy builder.mk to buildroot/$OS-$DIST
$(BUILDROOT)/%/Makefile:
@mkdir -p $(dir $@)
cp -pf $(SCRIPTDIR)/types/$(call builder,$@).mk $@
# Build packages using Docker in buildroot/$OS-$DIST/
$(BUILDROOT)/%/.build: $(BUILDROOT)/%/$(TARBALL) \
$(BUILDROOT)/%/Makefile
@echo "-------------------------------------------------------------------"
@echo "Building packages"
@echo "-------------------------------------------------------------------"
rm -rf $@
cd $(dir $@) && \
ls -l && \
docker run \
-ti \
--volume $$(pwd):$$(pwd) \
--volume $(HOME)/.ccache:/ccache \
-e CCACHE_DIR=/ccache \
--workdir $$(pwd) \
--rm=true $(DOCKER_REPO)$(call osdist,$@) \
make PROJECT=$(PROJECT_PREFIX)$(PROJECT) NAME=$(NAME) \
TARBALL=$(TARBALL) TARGET=$(call ostarget,$(call osdist,$@)) \
VERSION=$($(call builderu,$@)_VERSION) \
RELEASE=$($(call builderu,$@)_RELEASE) \
NIGHTLY=$(NIGHTLY) COMMIT=$(CI_COMMIT)
@echo "Successfully build $(PROJECT) for $@"
ls -1sh $(dir $@)/results/
test -f $(dir $@)/results/.done
# Build packages directly in current shell
$(BUILDROOT)/%/.build-shell: $(BUILDROOT)/%/$(TARBALL) \
$(BUILDROOT)/%/Makefile
@echo "-------------------------------------------------------------------"
@echo "Building packages"
@echo "-------------------------------------------------------------------"
rm -rf $@
cd $(dir $@) && \
ls -l && \
make PROJECT=$(PROJECT_PREFIX)$(PROJECT) NAME=$(NAME) \
TARBALL=$(TARBALL) TARGET=$(call ostarget,$(call osdist,$@)) \
VERSION=$($(call builderu,$@)_VERSION) \
RELEASE=$($(call builderu,$@)_RELEASE) \
NIGHTLY=$(NIGHTLY) COMMIT=$(CI_COMMIT)
@echo "Successfully build $(PROJECT) for $@"
ls -1sh $(dir $@)/results/
test -f $(dir $@)/results/.done
# Generate Bintray descriptor.json
$(BUILDROOT)/%/descriptor.json: $(BUILDROOT)/%/descriptorfiles.json
@mkdir -p $(dir $@)
@echo "-------------------------------------------------------------------"
@echo "Generating descriptor.json"
@echo "-------------------------------------------------------------------"
@echo '{' > [email protected]
@echo ' "package": {' >> [email protected]
@echo ' "name": "$(PROJECT)",' >> [email protected]
ifneq ($(CI_TAG), )
@echo ' "repo": "$(call builder,$@)",' >> [email protected]
else
@echo ' "repo": "$(call builder,$@)-nightly",' >> [email protected]
endif
@echo ' "subject": "tano-si"' >> [email protected]
@echo ' },' >> [email protected]
@echo '' >> [email protected]
@echo ' "version": {' >> [email protected]
@echo ' "name": "$(VERSION)",' >> [email protected]
@echo ' "released": "$(DATE)",' >> [email protected]
ifneq ($(CI_TAG), )
@echo ' "vcs_tag": "$(CI_TAG)",' >> [email protected]
endif
@echo ' "gpgSign": true' >> [email protected]
@echo ' },' >> [email protected]
@echo '' >> [email protected]
cat $(dir $@)/descriptorfiles.json >> [email protected]
@echo '' >> [email protected]
@echo ' "publish": true' >> [email protected]
@echo '}' >> [email protected]
@mv [email protected] $@
# Generate Bintray descriptor.json files for deb
$(BUILDROOT)/deb-%/descriptorfiles.json:
@mkdir -p $(dir $@)
@echo ' "files": [{' >> [email protected]
@echo ' "includePattern": "packaging/root/deb-$(call osdist,$@)/results/(.*\.deb)",' >> [email protected]
@echo ' "uploadPattern": "$$1",' >> [email protected]
@echo ' "matrixParams": {' >> [email protected]
@echo ' "deb_distribution": "$(call ostarget,$(call osdist,$@))",' >> [email protected]
@echo ' "deb_component": "main",' >> [email protected]
@echo ' "deb_architecture": "$(call osarch,$(call osdist,$@))"' >> [email protected]
@echo ' }' >> [email protected]
@echo ' }],' >> [email protected]
@mv [email protected] $@
# Generate Bintray descriptor.json files for apple
$(BUILDROOT)/apple-%/descriptorfiles.json:
@mkdir -p $(dir $@)
@echo ' "files": [{' >> [email protected]
@echo ' "includePattern": "packaging/root/apple-$(call osdist,$@)/results/(.*\.zip)",' >> [email protected]
@echo ' "uploadPattern": "/$$1"' >> [email protected]
@echo ' }],' >> [email protected]
@mv [email protected] $@
##
## DEB
##
# Copy debian/ to buildroot/$OS-$DIST
$(BUILDROOT)/deb-%/debian/changelog: debian/changelog
@mkdir -p $(abspath $(dir $@)/../)
cp -fpR debian $(abspath $(dir $@)/../)
# A rule to build DEB packages
$(BUILDROOT)/deb-%/results/.done: $(BUILDROOT)/deb-%/debian/changelog \
$(BUILDROOT)/deb-%/descriptor.json \
$(BUILDROOT)/deb-%/.build
@true
##
## Apple
##
# A rule to build Apple packages
$(BUILDROOT)/apple-%/results/.done: $(BUILDROOT)/apple-%/descriptor.json \
$(BUILDROOT)/apple-%/.build-shell
@true
##
## Targets
##
tarball: $(BUILDROOT)/$(TARBALL)
# Don't remove all rules, otherwise pattern matching will stop work
debian-%: $(BUILDROOT)/deb-debian-%/results/.done
@true
ubuntu-%: $(BUILDROOT)/deb-ubuntu-%/results/.done
@true
macos-%: $(BUILDROOT)/apple-macos-%/results/.done
@true
clean:
#rm -rf $(BUILDROOT)
.SECONDARY: # no target is removed because it is considered intermediate
.PHONY: clean