-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
185 lines (149 loc) · 7.04 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
179
180
181
182
183
184
185
################################################################################
# Build Variables
################################################################################
BUILDFLAGS = -v
DEVFLAGS = -v -race
TESTFLAGS = -race -cover
VETFLAGS = -v
POTFLAGS = --package-name="$(APP)" --from-code=utf-8 --sort-output
FPBFLAGS = --user --force-clean
ASVFLAGS = --explain --pedantic --override=cid-contains-hyphen=pedantic
################################################################################
# Install Variables
################################################################################
# The `DESTDIR` variable is supported by the `install`/`uninstall` targets and
# should be overridden instead of `prefix` when building packages unless a
# custom install location, e.g. `/app` for flatpaks, is required.
prefix = /usr
bindir = $(prefix)/bin
datadir = $(prefix)/share
################################################################################
# Application Variables
################################################################################
APP = com.github.rkoesters.xkcd-gtk
MODULE = github.com/rkoesters/xkcd-gtk
EXEC = $(APP)
ICON = data/$(APP).svg
DESKTOP = data/$(APP).desktop
SERVICE = data/$(APP).service
APPDATA = data/$(APP).appdata.xml
MODULE_PACKAGES = $(MODULE)/cmd/... $(MODULE)/internal/...
BUILD_PACKAGE = $(MODULE)/internal/build
BUILD_DATA = app-id=$(APP),version=$(shell tools/app-version.sh)
TAGS = $(shell tools/pkg-config-tags.sh)
GO_SOURCES = $(shell find cmd internal -name '*.go' -type f)
CSS_SOURCES = $(shell find cmd internal -name '*.css' -type f)
UI_SOURCES = $(shell find cmd internal -name '*.ui' -type f)
SH_SOURCES = $(shell find tools -name '*.sh' -type f)
POT = po/$(APP).pot
LINGUAS = $(shell cat po/LINGUAS)
PO = $(shell find po -name '*.po' -type f)
MO = $(patsubst %.po,%.mo,$(PO))
FLATPAK_YML_IN = $(shell find flatpak -name '*.yml.in')
FLATPAK_YML = $(APP).yml $(patsubst %.in,%,$(FLATPAK_YML_IN))
################################################################################
# Targets
################################################################################
all: $(EXEC) $(DESKTOP) $(APPDATA) $(POT) $(MO)
$(EXEC): Makefile $(GO_SOURCES) $(CSS_SOURCES) $(UI_SOURCES) $(APPDATA)
go build -o $@ -ldflags="-X '$(BUILD_PACKAGE).data=$(BUILD_DATA)'" -tags "$(TAGS)" $(BUILDFLAGS) $(MODULE)/cmd/xkcd-gtk
dev: $(APPDATA)
go build -o $(EXEC)-dev -ldflags="-X $(BUILD_PACKAGE).data=$(BUILD_DATA)" -tags "$(TAGS) xkcd_gtk_debug" $(DEVFLAGS) $(MODULE)/cmd/xkcd-gtk
$(POT): tools/fill-pot-header.sh $(GO_SOURCES) $(UI_SOURCES) $(DESKTOP).in $(APPDATA).in
xgettext -o $@ --language=C -kl $(POTFLAGS) $(GO_SOURCES)
xgettext -o $@ -j $(POTFLAGS) $(UI_SOURCES)
xgettext -o $@ -j --language=Desktop $(POTFLAGS) $(DESKTOP).in
xgettext -o $@ -j --its=po/appdata.its $(POTFLAGS) $(APPDATA).in
tools/fill-pot-header.sh <$@ >$@.out
mv $@.out $@
%.desktop: %.desktop.in $(PO)
msgfmt --desktop -d po -c -o $@ --template $<
%.xml: %.xml.in $(PO)
msgfmt --xml -d po -c -o $@ --template $<
%.mo: %.po
msgfmt -c -o $@ $<
flatpak/%.yml: flatpak/%.yml.in go.mod go.sum tools/gen-flatpak-deps.sh $(GO_SOURCES)
cp $< $@.tmp
tools/gen-flatpak-deps.sh >>$@.tmp
mv $@.tmp $@
flatpak/modules.txt: go.mod go.sum $(GO_SOURCES)
go mod vendor -o flatpak-build/vendor
cp flatpak-build/vendor/modules.txt $@
flathub: flatpak/flathub.yml flatpak/modules.txt
flatpak-builder $(FPBFLAGS) --state-dir=flatpak-build/.flatpak-builder-$@/ --install-deps-from=flathub flatpak-build/$@/ $<
flathub-install: flatpak/flathub.yml flatpak/modules.txt
flatpak-builder $(FPBFLAGS) --state-dir=flatpak-build/.flatpak-builder-$@/ --install-deps-from=flathub --install flatpak-build/$@/ $<
appcenter: flatpak/appcenter.yml flatpak/modules.txt
flatpak-builder $(FPBFLAGS) --state-dir=flatpak-build/.flatpak-builder-$@/ --install-deps-from=appcenter flatpak-build/$@/ $<
appcenter-install: flatpak/appcenter.yml flatpak/modules.txt
flatpak-builder $(FPBFLAGS) --state-dir=flatpak-build/.flatpak-builder-$@/ --install-deps-from=appcenter --install flatpak-build/$@/ $<
appcenter-reviews: # No dependencies, manifest will be read as-is from repo.
flatpak-builder $(FPBFLAGS) --state-dir=flatpak-build/.flatpak-builder-$@/ --install-deps-from=appcenter flatpak-build/$@/ $(APP).yml
$(APP).yml: flatpak/appcenter.yml flatpak/modules.txt
sed -e "s/path: '..'/path: '.'/" -e 's/path: modules.txt/path: flatpak\/modules.txt/' $< >$@
fix: $(POT) $(PO) $(APP).yml
go fix $(MODULE_PACKAGES)
go fmt $(MODULE_PACKAGES)
go mod tidy
([ -d vendor ] && go mod vendor) || true
echo $(UI_SOURCES) | xargs -n1 gtk-builder-tool simplify --replace
(find data -name '*.in' && \
printf '%s\n' $(UI_SOURCES) && \
grep -E -l '[^A-Za-z0-9]l\(' $(GO_SOURCES)\
) | sort >po/POTFILES
dos2unix -q po/LINGUAS po/appdata.its $(POT) $(PO)
for lang in $(LINGUAS); do \
msgmerge -U --backup=none "po/$$lang.po" $(POT); \
done
check: $(APPDATA) $(FLATPAK_YML)
go vet -tags "$(TAGS)" $(VETFLAGS) $(MODULE_PACKAGES)
staticcheck -tags "$(TAGS)" $(MODULE_PACKAGES)
shellcheck $(SH_SOURCES)
xmllint --noout $(APPDATA) $(ICON) $(UI_SOURCES)
yamllint .github/workflows/*.yml $(FLATPAK_YML)
-appstreamcli validate $(ASVFLAGS) --no-net $(APPDATA)
-appstreamcli validate $(ASVFLAGS) --strict $(APPDATA)
test: $(FLATPAK_YML) $(APPDATA)
go test -ldflags="-X $(BUILD_PACKAGE).data=$(BUILD_DATA)" -tags "$(TAGS)" $(TESTFLAGS) $(MODULE_PACKAGES)
tools/test-banned-imports.sh
tools/test-flatpak-config.sh $(FLATPAK_YML)
tools/test-install.sh
# Shorthand for all the targets that CI covers.
ci: all check test
ci-full: ci appcenter appcenter-reviews flathub
clean:
rm -f $(EXEC)
rm -f $(EXEC)-dev
rm -f $(DESKTOP)
rm -f $(APPDATA)
rm -f $(MO)
rm -f flatpak/*.yml
rm -rf flatpak-build/
rm -rf .flatpak-builder/
strip: $(EXEC)
strip $(EXEC)
install: $(EXEC) $(DESKTOP) $(APPDATA) $(MO)
mkdir -p $(DESTDIR)$(bindir)
install $(EXEC) $(DESTDIR)$(bindir)
mkdir -p $(DESTDIR)$(datadir)/icons/hicolor/scalable/apps
cp $(ICON) $(DESTDIR)$(datadir)/icons/hicolor/scalable/apps
mkdir -p $(DESTDIR)$(datadir)/applications
cp $(DESKTOP) $(DESTDIR)$(datadir)/applications
mkdir -p $(DESTDIR)$(datadir)/dbus-1/services
cp $(SERVICE) $(DESTDIR)$(datadir)/dbus-1/services
mkdir -p $(DESTDIR)$(datadir)/metainfo
cp $(APPDATA) $(DESTDIR)$(datadir)/metainfo
for lang in $(LINGUAS); do \
mkdir -p "$(DESTDIR)$(datadir)/locale/$$lang/LC_MESSAGES"; \
cp "po/$$lang.mo" "$(DESTDIR)$(datadir)/locale/$$lang/LC_MESSAGES/$(APP).mo"; \
done
uninstall:
rm $(DESTDIR)$(bindir)/$(notdir $(EXEC))
rm $(DESTDIR)$(datadir)/icons/hicolor/scalable/apps/$(notdir $(ICON))
rm $(DESTDIR)$(datadir)/applications/$(notdir $(DESKTOP))
rm $(DESTDIR)$(datadir)/dbus-1/services/$(notdir $(SERVICE))
rm $(DESTDIR)$(datadir)/metainfo/$(notdir $(APPDATA))
for lang in $(LINGUAS); do \
rm "$(DESTDIR)$(datadir)/locale/$$lang/LC_MESSAGES/$(APP).mo"; \
done
.PHONY: all appcenter appcenter-install appcenter-reviews check ci ci-full clean dev fix flathub flathub-install install strip test uninstall