-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
237 lines (207 loc) · 8.39 KB
/
Copy pathMakefile
File metadata and controls
237 lines (207 loc) · 8.39 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
# Makefile for whereami
#
# Provides convenience targets for:
# - Local Go build / run / lint
# - Local desktop install (binary + .desktop + icon)
#
# Requirements (host):
# - 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
GEODATA_BASE_URL ?= https://files.rbel.co/whereami/geodata
GEODATA_VERSION ?= 2026-04-15.0
GEODATA_SOURCE_VERSION ?= overturemaps-2026-04-15
GEODATA_ID ?= xiangshan-$(GEODATA_VERSION)
GEODATA_INPUT_DIR ?= build/geodata/$(GEODATA_VERSION)
GEODATA_DIST_ROOT ?= dist/geodata
GEODATA_DIST_DIR := $(GEODATA_DIST_ROOT)/$(GEODATA_VERSION)
GEODATA_LOCAL_DATA_DIR ?= build/geodata-local
XIANGSHAN_DIR ?=
# 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 lint-qml \
geodata-build geodata-dist geodata-install-local geodata-run-local
all: build
print-vars:
@echo "HOST_OS=$(HOST_OS)"
@echo "HOST_ARCH=$(HOST_ARCH)"
@echo "APP_ID=$(APP_ID)"
@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/components/*.qml ui/services/*.qml ui/themes/*.qml ui/tests/*.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
########################################
# Administrative geodata
########################################
geodata-build:
@if [ -z "$(XIANGSHAN_DIR)" ]; then \
echo "Set XIANGSHAN_DIR to a Xiangshan v0.2.0 checkout containing data/divisions"; \
exit 1; \
fi
$(MAKE) -C "$(XIANGSHAN_DIR)" remote-split VERSION="$(GEODATA_VERSION)" SOURCE="$(GEODATA_SOURCE_VERSION)"
mkdir -p "$(GEODATA_INPUT_DIR)"
cp --reflink=auto "$(XIANGSHAN_DIR)/build/divisions.xs-index.gz" "$(GEODATA_INPUT_DIR)/divisions.xs-index.gz"
cp --reflink=auto "$(XIANGSHAN_DIR)/build/divisions.xs-poly" "$(GEODATA_INPUT_DIR)/divisions.xs-poly"
geodata-dist:
@echo "==> Packaging geodata for $(GEODATA_BASE_URL)/$(GEODATA_VERSION)"
rm -rf "$(GEODATA_DIST_DIR)"
$(GO) run ./cmd/geodata-package \
-input "$(GEODATA_INPUT_DIR)" \
-output "$(GEODATA_DIST_DIR)" \
-base-url "$(GEODATA_BASE_URL)" \
-id "$(GEODATA_ID)" \
-dataset-version "$(GEODATA_VERSION)" \
-source-version "$(GEODATA_SOURCE_VERSION)"
@echo "Upload-ready directory: $(GEODATA_DIST_DIR)"
geodata-install-local: geodata-dist
./scripts/install-local-geodata.sh "$(GEODATA_DIST_DIR)" "$(GEODATA_LOCAL_DATA_DIR)"
geodata-run-local: build geodata-install-local
./$(BIN_DIR)/$(APP_NAME) \
--data-dir "$(GEODATA_LOCAL_DATA_DIR)" \
--cache-dir "$(GEODATA_LOCAL_DATA_DIR)/cache" \
--config-dir "$(GEODATA_LOCAL_DATA_DIR)/config" \
--geodata-manifest "$(GEODATA_LOCAL_DATA_DIR)/geodata/admin/local-manifest.json"
########################################
# 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"
########################################
# 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 " geodata-build Build Xiangshan split files from a checkout"
@echo " geodata-dist Create the versioned directory to upload"
@echo " geodata-install-local Install the packaged generation for local testing"
@echo " geodata-run-local Build and run against the local generation"
@echo " install Install binary, desktop file & icon to ~/.local"
@echo " uninstall Remove installed binary/desktop/icon"
@echo " print-vars Show variable values"
@echo " help This message"
@echo ""
@echo "Examples:"
@echo " make build"
@echo " make install"
@echo ""
@echo "Override install prefix:"
@echo " make INSTALL_PREFIX=/opt/local install"
@echo ""
@echo "Releases are built from the whereami-flatpak repository."
@echo ""