aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 0f6087dfb473f37fdfb177564f82616738adf04c (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
profile := dev
target = $(shell rustc -vV | grep host | awk '{print $$2}')
architectures := x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu
app_name := map
deploy_host := deploy@build.r.bdr.sh
deploy_path := /srv/http/build.r.bdr.sh/$(app_name)
install_path := /usr/local/bin/$(app_name)

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

default: build

set_rust:
	rustup default stable

prepare:
ifneq ($(skip_prepare),1)
	rustup target add $(target)
endif

# Build ########################################################################

build: prepare
	@$(eval target_dir := ./target/$(target)/$(profile)/map)
	cargo build --profile $(profile) --target $(target)

# Code Quality #################################################################

test:
	cargo test

coverage:
	cargo tarpaulin

format:
	cargo fmt && cargo clippy --fix

lint:
	cargo fmt -- --check && cargo clippy

# Internationalization / Localization ##########################################

find_translatable_files:
	@find ./ -not -path '*/.*' -type f -name "*.rs" -exec grep -l "tr!(\"\|gettext" {} \; | sort > po/POTFILES

extract_strings: find_translatable_files
	@xgettext --files-from=po/POTFILES --output=po/systems.tranquil.Map.pot --from-code=UTF-8 --add-comments --keyword='tr!'

po_files := $(wildcard po/*.po)
mo_files := $(patsubst po/%.po,po/%/LC_MESSAGES/systems.tranquil.Map.mo,$(po_files))

compile_translations: $(mo_files)

po/%/LC_MESSAGES/systems.tranquil.Map.mo: po/%.po
	@mkdir -p $(dir $@)
	msgfmt $< -o $@

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

package: $(architectures)

release: rpm tar deb
	@$(eval filename := $(app_name)-$(target)-$(channel))

flatpak:
	@flatpak-builder --force-clean --user --install-deps-from=flathub --repo=repo --install builddir ./build-aux/systems.tranquil.Map.yml

deb: build
ifeq ($(findstring linux,$(target)),linux)
	@$(eval filename := $(app_name)-$(target)-$(channel))
	cargo deb --profile $(profile) --target $(target)
	mv target/$(target)/debian/*.deb $(filename).deb
	@$(call sign_and_deploy,$(filename).deb)
endif

rpm: build
ifeq ($(findstring linux,$(target)),linux)
	@$(eval filename := $(app_name)-$(target)-$(channel))
	cargo generate-rpm --profile $(profile) --target $(target)
	mv target/$(target)/generate-rpm/*.rpm $(filename).rpm
	@$(call sign_and_deploy,$(filename).rpm)
endif

tar: build
	@$(eval filename := $(app_name)-$(target)-$(channel))
	tar -czvf $(filename).tar.gz -C target/$(target)/$(profile)/ $(app_name)
	@$(call sign_and_deploy,$(filename).tar.gz)

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

install: build
	@cp target/$(target)/$(profile)/ $(install_path)

# CI ###########################################################################

ci: lint coverage
ifeq ($(GIT_REF),refs/heads/main)
	$(MAKE) -e profile=release -e channel=unstable package
else ifneq (,$(findstring refs/tags/,$(GIT_REF)))
	$(MAKE) -e profile=release -e channel=$(subst refs/tags/,,$(GIT_REF)) package
endif

$(architectures):
ifneq ($(channel),)
	$(MAKE) -e channel=$(channel) -e target=$@ release
else
	$(MAKE) -e target=$@ build
endif


.PHONY: default build $(architectures) rpm package prepare set_rust ci release test coverage format flatpak extract_strings find_translatable_files compile_translations