forked from open-horizon/horizon-deb-packager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
178 lines (142 loc) · 8.47 KB
/
Makefile
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
SHELL := /bin/bash
arch-tag := $(shell tools/arch-tag)
# N.B. This number has to match the latest addition to the changelog in pkgsrc/deb/debian/changelog
subproject_names = anax anax-ui
subprojects = $(addprefix bld/,$(subproject_names))
version := $(shell cat VERSION)
version_tail = $(addprefix ~ppa~,$(1))
aug_version = $(addsuffix $(call version_tail,$(2)),$(1)$(version))
pkg_version = $(call aug_version,horizon-,$(1))
file_version = $(call aug_version,horizon_,$(1))
git_repo_prefix = ssh://[email protected]/open-horizon
# only returns names of distributions that are valid for this architecture
distribution_names = $(shell find pkgsrc/deb/meta/dist/* -maxdepth 0 -exec bash -c 'for d; do if grep -q "$(arch-tag)" "$${d}/arch"; then echo $$(basename $$d); fi; done ' _ {} +)
release_only = $(lastword $(subst ., ,$1))
pkgstub = $(foreach dname,$(distribution_names),dist/$(1)$(call pkg_version,$(dname))_$(arch-tag).deb)
meta = $(addprefix meta-,$(distribution_names))
bluehorizon_deb_packages = $(call pkgstub,blue)
horizon_deb_packages = $(call pkgstub,)
packages = $(horizon_deb_packages) $(bluehorizon_deb_packages)
debian_shared = $(shell find ./pkgsrc/deb/shared/debian -type f | sed 's,^./pkgsrc/deb/shared/debian/,,g' | xargs)
docker_tag_prefix := horizon
all: meta
ifndef verbose
.SILENT:
endif
bld:
mkdir -p bld
# TODO: consider making deps at this stage: that'd put all deps in the orig.tar.gz. This could be good for repeatable builds (we fetch from the internet all deps and wrap them in a source package), but it could be legally tenuous and there is still a chance of differences b/n .orig.tar.gzs between different arch's builds (b/c different machines run the builds and each fetches its own copy of those deps)
#-@[ ! -e "bld/$*" ] && git clone ssh://[email protected]/open-horizon/$*.git "$(CURDIR)/bld/$*" && cd $(CURDIR)/bld/$* && $(MAKE) deps
# TODO: could add capability to build from specified branch instead of master (right now this is only supported by doing some of the build steps, monkeying with the local copy and then running the rest of the steps.
bld/%/.git/logs/HEAD: | bld
git clone $(git_repo_prefix)/$*.git "$(CURDIR)/bld/$*"
cd $(CURDIR)/bld/$* && \
if [ "$($(*)-branch)" != "" ]; then git checkout $($(*)-branch); else \
if [[ "$$(git tag -l $(docker_tag_prefix)/$(version))" != "" ]]; then \
git checkout -b "$(docker_tag_prefix)/$(version)-b" $(docker_tag_prefix)/$(version); \
fi; \
fi
bld/%/.git-gen-changelog: bld/%/.git/logs/HEAD | bld
bash -x tools/git-gen-changelog "$(CURDIR)/bld/$*" "$(CURDIR)/pkgsrc/deb/meta/changelog.tmpl" "$(docker_tag_prefix)/$(version)"
bld/changelog.tmpl: pkgsrc/deb/meta/changelog.tmpl $(addsuffix /.git-gen-changelog,$(subprojects))
mkdir -p bld
if [[ "$$(cat pkgsrc/deb/meta/changelog.tmpl | head -n1 | grep $(version))" != "" ]]; then \
cp pkgsrc/deb/meta/changelog.tmpl bld/changelog.tmpl; \
else \
tools/render-debian-changelog "++DISTRIBUTIONS++" "$(version)" "++VERSIONSUFFIX++" bld/changelog.tmpl pkgsrc/deb/meta/changelog.tmpl $(shell find bld -iname ".git-gen-changelog"); \
fi
dist/$(call pkg_version,%)/debian:
mkdir -p dist/$(call pkg_version,$*)/debian
clean: clean-src mostlyclean
@echo "Use distclean target to revert all configuration, in addition to build artifacts, and clean up horizon_$(version) branch"
-rm -f bld/changelog.tmpl
-rm -Rf horizon* bluehorizon*
-rm -Rf bld
clean-src:
for src in $(subprojects); do \
if [ -e $$src ]; then \
cd $$src && \
git checkout . && \
git reset --hard HEAD && \
git clean -fdx; \
fi; \
done
mostlyclean:
-rm -Rf dist
for src in $(subprojects); do \
if [ -e $$src ]; then \
cd $$src && $(MAKE) clean; \
fi; \
done
distclean: clean
@echo "distclean"
# TODO: add other files to reset that might have changed?
-@git reset VERSION
-@git checkout master && git branch -D horizon_$(version)
# both creates directory and fills it: this is not the best use of make but it is trivial work that can stay flexible
dist/$(call pkg_version,%)/debian/fs-horizon: $(shell find pkgsrc/seed) | dist/$(call pkg_version,%)/debian
dir=dist/$(call pkg_version,$*)/debian/fs-horizon && \
mkdir -p $$dir && \
./pkgsrc/mk-dir-trees $$dir && \
cp -Ra ./pkgsrc/seed/horizon/fs/. $$dir && \
echo "SNAP_COMMON=/var/horizon" > $$dir/etc/default/horizon && \
envsubst < ./pkgsrc/seed/dynamic/horizon.tmpl >> $$dir/etc/default/horizon && \
./pkgsrc/render-json-config ./pkgsrc/seed/dynamic/anax.json.tmpl $$dir/etc/horizon/anax.json.example && \
cp pkgsrc/mk-dir-trees $$dir/usr/horizon/sbin/
dist/$(call pkg_version,%)/debian/fs-bluehorizon: dist/$(call pkg_version,%)/debian/fs-horizon $(shell find pkgsrc/seed) | dist/$(call pkg_version,%)/debian
dir=dist/$(call pkg_version,$*)/debian/fs-bluehorizon && \
mkdir -p $$dir && \
cp -Ra ./pkgsrc/seed/bluehorizon/fs/. $$dir && \
cp dist/$(call pkg_version,$*)/debian/fs-horizon/etc/horizon/anax.json.example $$dir/etc/horizon/anax.json
# meta for every distribution, the target of horizon_$(version)-meta/$(distribution_names)
dist/$(call pkg_version,%)/debian/changelog: bld/changelog.tmpl | dist/$(call pkg_version,%)/debian
sed "s,++DISTRIBUTIONS++,$(call release_only,$*) $(addprefix $(call release_only,$*)-,updates testing unstable),g" bld/changelog.tmpl > dist/$(call pkg_version,$*)/debian/changelog
sed -i.bak "s,++VERSIONSUFFIX++,$(call version_tail,$*),g" dist/$(call pkg_version,$*)/debian/changelog && rm dist/$(call pkg_version,$*)/debian/changelog.bak
# N.B. This target will copy all files from the source to the dest. as one target
$(addprefix dist/$(call pkg_version,%)/debian/,$(debian_shared)): $(addprefix pkgsrc/deb/shared/debian/,$(debian_shared)) | dist/$(call pkg_version,%)/debian
cp -Ra pkgsrc/deb/shared/debian/. dist/$(call pkg_version,$*)/debian/
# next, copy specific package overwrites
-[[ "$(ls pkgsrc/deb/meta/dist/$*/debian/*)" != "" ]] && cp -Rva pkgsrc/deb/meta/dist/$*/debian/* dist/$(call pkg_version,$*)/debian/
dist/$(call file_version,%).orig.tar.gz: dist/$(call pkg_version,%)/debian/fs-horizon dist/$(call pkg_version,%)/debian/fs-bluehorizon dist/$(call pkg_version,%)/debian/changelog $(addprefix dist/$(call pkg_version,%)/debian/,$(debian_shared))
for src in $(subprojects); do \
rsync -a --exclude=".git*" $(PWD)/$$src dist/$(call pkg_version,$*)/; \
if [ -e $${src}-rules.env ]; then \
cp $${src}-rules.env dist/$(call pkg_version,$*)/$$(basename $$src)/rules.env; \
fi; \
done
tar --mtime $(CURDIR)/VERSION --sort=name -c -C dist/$(call pkg_version,$*) . | gzip -n > dist/$(call file_version,$*).orig.tar.gz
# also builds the bluehorizon package
$(bluehorizon_deb_packages):
dist/blue$(call pkg_version,%)_$(arch-tag).deb:
$(horizon_deb_packages):
dist/$(call pkg_version,%)_$(arch-tag).deb: dist/$(call file_version,%).orig.tar.gz
@echo "Running Debian build in $*"
cd dist/$(call pkg_version,$*) && \
debuild -a$(arch-tag) -us -uc --lintian-opts --allow-root
find dist/* -exec touch -r $(CURDIR)/VERSION {} +
$(meta): meta-%: bld/changelog.tmpl dist/$(call file_version,%).orig.tar.gz
tools/meta-precheck $(CURDIR) "$(docker_tag_prefix)/$(version)" $(subprojects)
@echo "================="
@echo "Metadata created"
@echo "================="
@echo "Please inspect dist/$(call pkg_version,$*), the shared template file bld/changelog.tmpl, and VERSION. If accurate and if no other changes exist in the local copy, execute 'make publish-meta'. This will commit your local changes to the canonical upstream and tag dependent projects. The operation requires manual effort to undo so be sure you're ready before executing."
meta: $(meta)
packages: $(packages)
publish-meta-bld/%:
@echo "+ Visiting publish-meta subproject $*"
tools/git-tag 0 "$(CURDIR)/bld/$*" "$(docker_tag_prefix)/$(version)"
publish-meta: $(addprefix publish-meta-bld/,$(subproject_names))
git checkout -b horizon_$(version)
cp bld/changelog.tmpl pkgsrc/deb/meta/changelog.tmpl
git add ./VERSION pkgsrc/deb/meta/changelog.tmpl
git commit -m "updated package metadata to $(version)"
git push --set-upstream origin horizon_$(version)
show-distribution-names:
@echo $(distribution_names)
show-subprojects:
@echo $(subprojects)
show-packages:
@echo $(packages)
# make these "precious" so Make won't remove them
.PRECIOUS: dist/$(call file_version,%).orig.tar.gz bld/%/.git/logs/HEAD dist/$(call pkg_version,%)/debian $(addprefix dist/$(call pkg_version,%)/debian/,$(debian_shared) changelog fs-horizon fs-bluehorizon)
.PHONY: clean clean-src $(meta) mostlyclean publish-meta publish-meta-bld/% show-distribution-names show-packages show-subprojects