aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: d3be667d6080184deb7768a350188f7649b080f5 (plain)
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
profile := dev
target = $(shell rustc -vV | grep host | awk '{print $$2}')
channel := unstable

# Config: Directories & Locations ##############################################
# Cargo outputs dev profile to 'debug' directory, not 'dev'
prefix := /usr/local
ifeq ($(profile),dev)
output_dir := debug
else
output_dir := $(profile)
endif
flatpak_cargo_generator := $(HOME)/projects/vendor/flatpak-builder-tools/cargo

# Config: Packaging Config #####################################################
linuxdeploy_url := https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-$(shell uname -m).AppImage
linuxdeploy := .cache/linuxdeploy.AppImage
pkgver := $(shell grep '^pkgver=' build-aux/arch/PKGBUILD | cut -d= -f2)
pkgrel := $(shell grep '^pkgrel=' build-aux/arch/PKGBUILD | cut -d= -f2)

# Filename format: map-aarch64-unstable.flatpak or map-aarch64-unstable-fedora43.rpm
filename = $(app_name)-$(arch)-$(channel)

# Config: Naming ###############################################################
arch = $(firstword $(subst -, ,$(target)))
app_name := map

# Config: Container Images #####################################################
fedora_versions := fedora43 fedora44 fedora-rawhide
debian_versions := trixie forky
all_containers := arch $(fedora_versions) $(debian_versions)
container_image_prefix := map-build
clean_images := 0

# Config: Release Location #####################################################
deploy_host := deploy@build.r.bdr.sh
deploy_path := /srv/http/build.r.bdr.sh/$(app_name)-linux

define sign_and_deploy
	@./scripts/sign.sh "$(1)" "$(channel)" "$(arch)"
	rsync -avz $(1) $(deploy_host):$(deploy_path)
	rsync -avz $(1).minisig $(deploy_host):$(deploy_path)
endef

# Container Images #############################################################

build-container-%:
ifeq ($(clean_images),1)
	podman system prune -af
endif
	@echo "=== Building container image: $(container_image_prefix):$* ==="
	podman build -t $(container_image_prefix):$* build-containers/$*

build-containers: $(addprefix build-container-,$(all_containers))

# Packaging ####################################################################


# Generic packages
# These run directly on the host machine, since the assumption is that it
# shouldn't affect the outcome.

update_flatpak_dependencies:
	cd $(flatpak_cargo_generator) && `poetry env activate` && python3 flatpak-cargo-generator.py $(CURDIR)/Cargo.lock -o $(CURDIR)/build-aux/flatpak/cargo-sources.json && deactivate

package-flatpak: update_flatpak_dependencies
	flatpak-builder --force-clean --user --install-deps-from=flathub --repo=repo --install builddir ./build-aux/flatpak/systems.tranquil.Map.yml
	flatpak build-bundle repo dist/$(filename).flatpak systems.tranquil.Map

$(linuxdeploy):
	@mkdir -p .cache
	curl -L -o $(linuxdeploy) $(linuxdeploy_url)
	chmod +x $(linuxdeploy)

package-appimage: $(linuxdeploy)
ifeq ($(findstring linux,$(target)),linux)
	$(MAKE) build-container-trixie
	@echo "=== Building AppImage ==="
	./scripts/build_appimage.sh $(container_image_prefix) trixie $(app_name) $(arch) $(channel) $(linuxdeploy)
ifeq ($(clean_images),1)
	podman rmi $(container_image_prefix):trixie
endif
endif

# Distro-specific packages
# These run inside containers, as we want to make sure they're built with the
# libraries available in that particular distribution.

package-arch: build-container-arch
	@echo "=== Building Arch package for $(arch) ==="
	./scripts/build_arch.sh $(container_image_prefix) arch $(app_name) $(arch) $(channel)
ifeq ($(clean_images),1)
	podman rmi $(container_image_prefix):arch
endif

package-rpm:
ifndef distro
	$(error distro is required, e.g., make package-rpm distro=fedora43)
endif
	$(MAKE) build-container-$(distro)
	@echo "=== Building RPM for $(distro) ($(arch)) ==="
	./scripts/build_rpm.sh $(container_image_prefix) $(distro) $(app_name) $(arch) $(channel)
ifeq ($(clean_images),1)
	podman rmi $(container_image_prefix):$(distro)
endif

package-deb:
ifndef distro
	$(error distro is required, e.g., make package-deb distro=trixie)
endif
	$(MAKE) build-container-$(distro)
	@echo "=== Building DEB for $(distro) ($(arch)) ==="
	./scripts/build_deb.sh $(container_image_prefix) $(distro) $(app_name) $(arch) $(channel)
ifeq ($(clean_images),1)
	podman rmi $(container_image_prefix):$(distro)
endif

package-rpm-all:
	@for v in $(fedora_versions); do \
		$(MAKE) distro=$$v package-rpm; \
	done

package-deb-all:
	@for v in $(debian_versions); do \
		$(MAKE) distro=$$v package-deb; \
	done

package: package-tar package-flatpak package-appimage package-arch package-rpm-all package-deb-all

# Distribution #################################################################

distribute-flatpak:
	@$(call sign_and_deploy,$(filename).flatpak)

distribute-appimage:
	@$(call sign_and_deploy,$(filename).AppImage)

distribute-pacman:
	@$(call sign_and_deploy,$(app_name)-$(arch)-$(channel)-arch.pkg.tar.gz)

distribute-rpm:
	@for v in $(fedora_versions); do \
		./scripts/sign.sh "$(filename)-$$v.rpm" "$(channel)" "$(arch)" && \
		rsync -avz $(filename)-$$v.rpm $(deploy_host):$(deploy_path) && \
		rsync -avz $(filename)-$$v.rpm.minisig $(deploy_host):$(deploy_path); \
	done

distribute-deb:
	@for v in $(debian_versions); do \
		./scripts/sign.sh "$(filename)-$$v.deb" "$(channel)" "$(arch)" && \
		rsync -avz $(filename)-$$v.deb $(deploy_host):$(deploy_path) && \
		rsync -avz $(filename)-$$v.deb.minisig $(deploy_host):$(deploy_path); \
	done

distribute: distribute-tar distribute-flatpak distribute-appimage distribute-arch distribute-rpm distribute-deb

# Release ######################################################################

release:
	$(MAKE) profile=release package distribute

# Installation #################################################################

install: build
	install -Dm0755 target/$(target)/$(output_dir)/$(app_name) $(prefix)/bin/$(app_name)
	install -Dm0644 resources/logo.svg $(prefix)/share/icons/hicolor/scalable/apps/systems.tranquil.Map.svg
	install -Dm0644 resources/systems.tranquil.Map.desktop $(prefix)/share/applications/systems.tranquil.Map.desktop
	install -Dm0644 resources/systems.tranquil.Map.metainfo.xml $(prefix)/share/metainfo/systems.tranquil.Map.metainfo.xml
	install -Dm0644 resources/systems.tranquil.Map.service $(prefix)/share/dbus-1/services/systems.tranquil.Map.service
	install -Dm0644 resources/wmap.lang $(prefix)/share/gtksourceview-5/language-specs/wmap.lang
	@for po_file in po/*.po; do \
		locale=$$(basename "$$po_file" .po); \
		install -Dm0644 po/$$locale/LC_MESSAGES/systems.tranquil.Map.mo $(prefix)/share/locale/$$locale/LC_MESSAGES/systems.tranquil.Map.mo; \
	done

uninstall:
	rm -f $(prefix)/bin/$(app_name)
	rm -f $(prefix)/share/icons/hicolor/scalable/apps/systems.tranquil.Map.svg
	rm -f $(prefix)/share/applications/systems.tranquil.Map.desktop
	rm -f $(prefix)/share/metainfo/systems.tranquil.Map.metainfo.xml
	rm -f $(prefix)/share/dbus-1/services/systems.tranquil.Map.service
	rm -f $(prefix)/share/gtksourceview-5/language-specs/wmap.lang
	@for po_file in po/*.po; do \
		locale=$$(basename "$$po_file" .po); \
		rm -f $(prefix)/share/locale/$$locale/LC_MESSAGES/systems.tranquil.Map.mo; \
	done

ci: lint
ifeq ($(GIT_REF),refs/heads/main)
	$(MAKE) -e channel=unstable release
else ifneq (,$(findstring refs/tags/,$(GIT_REF)))
	$(MAKE) -e channel=$(subst refs/tags/,,$(GIT_REF)) release
else
	@echo "Not in CI environment."
endif

.PHONY: default \
	update_flatpak_dependencies \
	package-flatpak package-appimage \
	package-arch package-rpm package-deb \
	package-rpm-all package-deb-all package \
	distribute-flatpak distribute-appimage distribute-arch distribute-rpm distribute-deb distribute \
	release install uninstall \
	build-containers