-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
257 lines (226 loc) · 8.88 KB
/
Makefile
File metadata and controls
257 lines (226 loc) · 8.88 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Makefile for whereami
#
# Provides convenience targets for:
# - Local Go build / run / lint
# - Flatpak build, install, run, clean
# - Local desktop install (binary + .desktop + icon)
#
# Requirements (host, outside Flatpak):
# - Go toolchain (matching go.mod version)
# - qmllint-qt6 (for QML lint target) optional
#
# Common usage:
# make build
# make run
# make install (local desktop integration)
#
# Override variables if needed:
# make INSTALL_PREFIX=/custom/path install
#
APP_NAME := whereami
APP_ID := io.github.rubiojr.whereami
BIN_DIR := bin
GO := go
QML_LINT := qmllint-qt6
# Optional: pass ldflags to reduce binary size
LDFLAGS := -s -w
# Desktop integration install prefixes (override INSTALL_PREFIX to relocate)
INSTALL_PREFIX ?= $(HOME)/.local
BIN_INSTALL_DIR := $(INSTALL_PREFIX)/bin
DESKTOP_DIR := $(INSTALL_PREFIX)/share/applications
ICON_DIR_SCALABLE := $(INSTALL_PREFIX)/share/icons/hicolor/scalable/apps
ICON_SIZES := 16 24 32 48 64 128 256
DESKTOP_FILE_SRC := desktop/$(APP_ID).desktop
ICON_FILE_SRC := ui/icons/$(APP_ID).svg
DESKTOP_FILE_DEST := $(DESKTOP_DIR)/$(APP_ID).desktop
ICON_FILE_DEST := $(ICON_DIR_SCALABLE)/$(APP_ID).svg
# Detect OS/Arch (optional for logging)
HOST_OS := $(shell uname -s)
HOST_ARCH := $(shell uname -m)
.PHONY: all build run clean lint fmt vet tidy qml-test \
install uninstall print-vars help \
release release-snapshot release-rpm release-rpm-fedora check-release-deps
all: build
print-vars:
@echo "HOST_OS=$(HOST_OS)"
@echo "HOST_ARCH=$(HOST_ARCH)"
@echo "APP_ID=$(APP_ID)"
@echo "FLATPAK_MANIFEST=$(FLATPAK_MANIFEST)"
@echo "FLATPAK_BUILDDIR=$(FLATPAK_BUILDDIR)"
@echo "FLATPAK_EXPORTDIR=$(FLATPAK_EXPORTDIR)"
@echo "INSTALL_PREFIX=$(INSTALL_PREFIX)"
@echo "BIN_INSTALL_DIR=$(BIN_INSTALL_DIR)"
@echo "DESKTOP_FILE_DEST=$(DESKTOP_FILE_DEST)"
@echo "ICON_FILE_DEST=$(ICON_FILE_DEST)"
########################################
# Go (local) targets
########################################
build:
@echo "==> Building $(APP_NAME)"
@mkdir -p $(BIN_DIR)
PATH=$(PATH):/usr/lib64/qt6/libexec $(GO) generate
$(GO) build -ldflags '$(LDFLAGS)' -o $(BIN_DIR)/$(APP_NAME) .
run: build
@echo "==> Running $(APP_NAME)"
./$(BIN_DIR)/$(APP_NAME)
clean:
@echo "==> Cleaning local build artifacts"
rm -rf $(BIN_DIR)
fmt:
@echo "==> go fmt"
$(GO) fmt ./...
vet:
@echo "==> go vet"
$(GO) vet ./...
tidy:
@echo "==> go mod tidy"
$(GO) mod tidy
lint-qml:
@echo "==> QML lint (non-fatal if tool not present)"
@if command -v $(QML_LINT) >/dev/null 2>&1; then \
$(QML_LINT) ui/*.qml ui/components/*.qml ui/services/*.qml || true; \
else \
echo "Skipping QML lint: $(QML_LINT) not found"; \
fi
lint: fmt vet lint-qml
qml-test:
@echo "==> Running QML tests"
@if command -v qmltestrunner-qt6 >/dev/null 2>&1; then \
qmltestrunner-qt6 -import ui -input ui/tests ; \
elif command -v qmltestrunner >/dev/null 2>&1; then \
qmltestrunner -import ui -input ui/tests ; \
else \
echo "qmltestrunner not found (install Qt Quick Test)"; \
exit 1; \
fi
########################################
# Desktop install targets (local user)
########################################
install: build
@echo "==> Installing binary to $(BIN_INSTALL_DIR)"
@mkdir -p "$(BIN_INSTALL_DIR)"
@mv "$(BIN_DIR)/$(APP_NAME)" "$(BIN_INSTALL_DIR)/$(APP_NAME)"
@chmod 755 "$(BIN_INSTALL_DIR)/$(APP_NAME)"
@echo "==> Installing desktop file to $(DESKTOP_DIR)"
@mkdir -p "$(DESKTOP_DIR)"
@cp "$(DESKTOP_FILE_SRC)" "$(DESKTOP_FILE_DEST)"
@chmod 644 "$(DESKTOP_FILE_DEST)"
@echo "==> Installing scalable icon to $(ICON_DIR_SCALABLE)"
@mkdir -p "$(ICON_DIR_SCALABLE)"
@cp "$(ICON_FILE_SRC)" "$(ICON_FILE_DEST)"
@chmod 644 "$(ICON_FILE_DEST)"
@echo "==> Generating PNG icons ($(ICON_SIZES)) if rsvg-convert or inkscape is available"
@for sz in $(ICON_SIZES); do \
outdir="$(INSTALL_PREFIX)/share/icons/hicolor/$${sz}x$${sz}/apps"; \
mkdir -p "$$outdir"; \
if command -v rsvg-convert >/dev/null 2>&1; then \
rsvg-convert -w $$sz -h $$sz "$(ICON_FILE_SRC)" -o "$$outdir/$(APP_ID).png"; \
elif command -v inkscape >/dev/null 2>&1; then \
inkscape "$(ICON_FILE_SRC)" --export-type=png -w $$sz -h $$sz -o "$$outdir/$(APP_ID).png" >/dev/null 2>&1; \
else \
echo " (no converter found: rsvg-convert or inkscape)"; \
break; \
fi; \
chmod 644 "$$outdir/$(APP_ID).png"; \
done
@echo "==> Updating desktop database / icon cache if available"
@command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$(INSTALL_PREFIX)/share/applications" || echo "Skipping update-desktop-database"
@command -v gtk-update-icon-cache >/dev/null 2>&1 && gtk-update-icon-cache -q "$(INSTALL_PREFIX)/share/icons/hicolor" || echo "Skipping gtk-update-icon-cache"
@echo "==> Install complete. You may need to restart your desktop shell or run 'xdg-desktop-menu forceupdate'"
uninstall:
@echo "==> Removing installed assets"
@rm -f "$(BIN_INSTALL_DIR)/$(APP_NAME)"
@rm -f "$(DESKTOP_FILE_DEST)"
@rm -f "$(ICON_FILE_DEST)"
@echo "==> Running desktop/icon cache updates (if tools available)"
@command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$(INSTALL_PREFIX)/share/applications" || true
@command -v gtk-update-icon-cache >/dev/null 2>&1 && gtk-update-icon-cache -q "$(INSTALL_PREFIX)/share/icons/hicolor" || true
@echo "==> Uninstall complete"
########################################
# GoReleaser targets for releases and RPMs
########################################
# Check if goreleaser is installed
check-release-deps:
@echo "==> Checking release dependencies"
@if ! command -v goreleaser >/dev/null 2>&1; then \
echo "Error: goreleaser not found!"; \
echo "Install with one of:"; \
echo " go install github.com/goreleaser/goreleaser/v2@latest"; \
echo " brew install goreleaser"; \
echo " snap install goreleaser"; \
exit 1; \
fi
@echo " ✓ goreleaser found: $$(goreleaser --version)"
@if [ -x scripts/build.sh ]; then \
./scripts/build.sh --check-deps; \
fi
# Build a snapshot release (without publishing)
release-snapshot: check-release-deps
@echo "==> Building snapshot release with GoReleaser"
goreleaser release --snapshot --clean
# Build RPMs using the generic configuration
release-rpm:
@echo "==> Building RPMs with build-podman"
@if [ ! -x scripts/build-podman ]; then \
echo "Error: scripts/build-podman not found or not executable"; \
exit 1; \
fi
./scripts/build-podman
# Create a full release (requires git tag)
release: check-release-deps
@echo "==> Creating release with GoReleaser"
@if ! git describe --exact-match --tags HEAD 2>/dev/null; then \
echo "Error: Current commit is not tagged!"; \
echo "Create a tag first: git tag -a v1.0.0 -m 'Release v1.0.0'"; \
exit 1; \
fi
goreleaser release --clean
########################################
# Utility / Help
########################################
help:
@echo ""
@echo "Available targets:"
@echo " build Build local Go binary"
@echo " run Build and run locally"
@echo " clean Remove local build artifacts"
@echo " fmt Run go fmt"
@echo " vet Run go vet"
@echo " tidy Run go mod tidy"
@echo " lint-qml Run QML linter (if available)"
@echo " lint fmt + vet + QML lint"
@echo " qml-test Run QML JS test suite"
@echo " install Install binary, desktop file & icon to ~/.local"
@echo " uninstall Remove installed binary/desktop/icon"
@echo " flatpak-build Flatpak build (no install)"
@echo " flatpak-install Flatpak build + install (user)"
@echo " flatpak-run Run installed Flatpak"
@echo " flatpak-clean Remove Flatpak build dirs"
@echo " flatpak-rebuild Clean + build + install"
@echo " flatpak-bundle Create distributable .flatpak file"
@echo " flatpak-release Upload .flatpak to latest GitHub release"
@echo " release-snapshot Build snapshot release with GoReleaser"
@echo " release-rpm Build RPMs using build-podman"
@echo " release Create full release (requires git tag)"
@echo " print-vars Show variable values"
@echo " help This message"
@echo ""
@echo "Examples:"
@echo " make build"
@echo " make install"
@echo " make flatpak-install"
@echo " make flatpak-run"
@echo ""
@echo "Adjust FLATPAK_BUILDDIR or other vars:"
@echo " make FLATPAK_BUILDDIR=out/fp flatpak-build"
@echo "Override install prefix:"
@echo " make INSTALL_PREFIX=/opt/local install"
@echo ""
@echo "Release examples:"
@echo " make release-snapshot # Test build without publishing"
@echo " make release-rpm # Build RPMs in Fedora container"
@echo " make flatpak-bundle # Create .flatpak file"
@echo " make flatpak-release # Upload .flatpak to GitHub"
@echo " git tag -a v1.0.0 -m 'Release v1.0.0'"
@echo " make release # Create GitHub release"
@echo ""