1$(eval HGROOT := $(shell cd ../..; pwd))
2
3DEBIAN_CODENAMES := \
4  stretch \
5  buster \
6  bullseye
7
8UBUNTU_CODENAMES := \
9  xenial \
10  bionic \
11  cosmic \
12  focal
13
14FEDORA_RELEASE := 31
15
16CENTOS_RELEASES := \
17  7 \
18  8
19
20# Build a Python for these CentOS releases.
21CENTOS_WITH_PYTHON_RELEASES :=
22CENTOS_WITH_NONVERSIONED_PYTHON :=
23CENTOS_WITH_36_DOCUTILS := 7
24
25help:
26	@echo 'Packaging Make Targets'
27	@echo ''
28	@echo 'docker-centos{$(strip $(CENTOS_RELEASES))}'
29	@echo '   Build an RPM for a specific CentOS version using Docker.'
30	@echo ''
31	@echo 'docker-debian-{$(strip $(DEBIAN_CODENAMES))}'
32	@echo '   Build Debian packages specific to a Debian distro using Docker.'
33	@echo ''
34	@echo 'docker-fedora'
35	@echo '   Build an RPM for a Fedora $(FEDORA_RELEASE) using Docker.'
36	@echo ''
37	@echo 'docker-ubuntu-{$(strip $(UBUNTU_CODENAMES))}'
38	@echo '   Build Debian package specific to an Ubuntu distro using Docker.'
39	@echo ''
40	@echo 'docker-ubuntu-{$(strip $(UBUNTU_CODENAMES))}-ppa'
41	@echo '   Build a source-only Debian package specific to an Ubuntu distro'
42	@echo '   using Docker.'
43	@echo ''
44	@echo 'linux-wheels'
45	@echo '   Build Linux manylinux wheels using Docker.'
46	@echo ''
47	@echo 'linux-wheels-{x86_64, i686}'
48	@echo '   Build Linux manylinux wheels for a specific architecture using Docker'
49	@echo ''
50	@echo 'deb'
51	@echo '   Build a Debian package locally targeting the current system'
52	@echo ''
53	@echo 'ppa'
54	@echo '   Build a Debian source package locally targeting the current system'
55	@echo ''
56	@echo 'centos{$(strip $(CENTOS_RELEASES))}'
57	@echo '   Build an RPM for a specific CentOS version locally'
58	@echo ''
59	@echo 'fedora'
60	@echo '   Build an RPM for Fedora $(FEDORA_RELEASE) locally'
61
62.PHONY: help
63
64.PHONY: deb
65deb:
66	./builddeb
67
68.PHONY: ppa
69ppa:
70	./builddeb --source-only
71
72# Debian targets.
73define debian_targets =
74.PHONY: docker-debian-$(1)
75docker-debian-$(1):
76	./dockerdeb debian $(1)
77
78endef
79
80$(foreach codename,$(DEBIAN_CODENAMES),$(eval $(call debian_targets,$(codename))))
81
82# Ubuntu targets.
83define ubuntu_targets =
84.PHONY: docker-ubuntu-$(1)
85docker-ubuntu-$(1):
86	./dockerdeb ubuntu $(1)
87
88.PHONY: docker-ubuntu-$(1)-ppa
89docker-ubuntu-$(1)-ppa:
90	./dockerdeb ubuntu $(1) --source-only
91
92endef
93
94$(foreach codename,$(UBUNTU_CODENAMES),$(eval $(call ubuntu_targets,$(codename))))
95
96# Fedora targets.
97.PHONY: fedora
98fedora:
99	mkdir -p $(HGROOT)/packages/fedora$(FEDORA_RELEASE)
100	./buildrpm
101	cp $(HGROOT)/contrib/packaging/rpmbuild/RPMS/*/* $(HGROOT)/packages/fedora$(FEDORA_RELEASE)
102	cp $(HGROOT)/contrib/packaging/rpmbuild/SRPMS/* $(HGROOT)/packages/fedora$(FEDORA_RELEASE)
103	rm -rf $(HGROOT)/rpmbuild
104
105.PHONY: docker-fedora
106docker-fedora:
107	./dockerrpm fedora$(FEDORA_RELEASE)
108
109# CentOS targets.
110define centos_targets
111.PHONY: centos$(1)
112centos$(1):
113	mkdir -p $$(HGROOT)/packages/centos$(1)
114	./buildrpm $$(if $$(filter $(1),$$(CENTOS_WITH_PYTHON_RELEASES)),--withpython,$$(if $$(filter $(1),$$(CENTOS_WITH_NONVERSIONED_PYTHON)),--python python,))$$(if $$(filter $(1),$$(CENTOS_WITH_36_DOCUTILS)), --docutilspackage python36-docutils,)
115	cp $$(HGROOT)/contrib/packaging/rpmbuild/RPMS/*/* $$(HGROOT)/packages/centos$(1)
116	cp $$(HGROOT)/contrib/packaging/rpmbuild/SRPMS/* $$(HGROOT)/packages/centos$(1)
117
118.PHONY: docker-centos$(1)
119docker-centos$(1):
120	./dockerrpm centos$(1) $$(if $$(filter $(1),$$(CENTOS_WITH_PYTHON_RELEASES)),--withpython,$$(if $$(filter $(1),$$(CENTOS_WITH_NONVERSIONED_PYTHON)),--python python,))$$(if $$(filter $(1),$$(CENTOS_WITH_36_DOCUTILS)), --docutilspackage python36-docutils,)
121
122endef
123
124$(foreach release,$(CENTOS_RELEASES),$(eval $(call centos_targets,$(release))))
125
126.PHONY: linux-wheels
127linux-wheels: linux-wheels-x86_64 linux-wheels-i686
128
129.PHONY: linux-wheels-x86_64
130linux-wheels-x86_64:
131	docker run -e "HGTEST_JOBS=$(shell nproc)" --rm -ti -v `pwd`/../..:/src quay.io/pypa/manylinux1_x86_64 /src/contrib/packaging/build-linux-wheels.sh
132
133.PHONY: linux-wheels-i686
134linux-wheels-i686:
135	docker run -e "HGTEST_JOBS=$(shell nproc)" --rm -ti -v `pwd`/../..:/src quay.io/pypa/manylinux1_i686 linux32 /src/contrib/packaging/build-linux-wheels.sh
136