-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (51 loc) · 2.47 KB
/
Copy pathMakefile
File metadata and controls
69 lines (51 loc) · 2.47 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
# Where's That MUNI? — build / test / lint / deploy
#
# Local dev runs under X11/Wayland (Fyne uses OpenGL via GLFW). The deploy target
# is a Raspberry Pi 3 + 5" touchscreen running labwc (Wayland) with XWayland.
BINARY := muni-display
PKG := ./cmd/muni-display
# Deploy target. Override on the command line (make deploy PI_HOST=...), or set
# PI_HOST / PI_DIR in .env (gitignored) alongside the API key so `make deploy`
# needs no arguments. The ?= defaults below apply only when .env omits them.
-include .env
PI_HOST ?= pi@raspberrypi.local
PI_DIR ?= /home/pi/wheres-that-muni
SHOT ?= pi-screenshot.png
# Prefer golangci-lint on PATH, otherwise fall back to the one in GOPATH/bin.
GOLANGCI ?= $(shell command -v golangci-lint 2>/dev/null || echo "$(shell go env GOPATH)/bin/golangci-lint")
.DEFAULT_GOAL := help
.PHONY: help all build run test lint lint-install tidy fmt vet clean deploy build-pi screenshot
help: ## Show this help
@echo "Where's That MUNI? — make targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'
all: test lint build ## Test, lint, then build
build: ## Compile the binary for the local machine
go build -o $(BINARY) $(PKG)
run: ## Run the app locally (needs an X11/Wayland session)
go run $(PKG)
test: ## Run all unit tests
go test ./...
lint: ## Run golangci-lint (see lint-install)
$(GOLANGCI) run ./...
lint-install: ## Install golangci-lint into GOPATH/bin
GOTOOLCHAIN=auto go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
tidy: ## Sync go.mod/go.sum
go mod tidy
fmt: ## Format all Go sources
go fmt ./...
vet: ## Run go vet
go vet ./...
clean: ## Remove build artifacts
rm -f $(BINARY)
rm -rf dist/
deploy: ## Sync source to the Pi and build it natively there
rsync -av --exclude '.git' --exclude '.env' --exclude '$(BINARY)' \
./ $(PI_HOST):$(PI_DIR)/
ssh $(PI_HOST) 'cd $(PI_DIR) && GOTOOLCHAIN=auto go build -o $(BINARY) $(PKG)'
build-pi: ## Build ON the Pi (after a git pull / rsync)
GOTOOLCHAIN=auto go build -o $(BINARY) $(PKG)
screenshot: ## Grab the Pi's screen to SHOT (default pi-screenshot.png)
@ssh $(PI_HOST) 'rt=/run/user/$$(id -u); XDG_RUNTIME_DIR=$$rt WAYLAND_DISPLAY=$$(basename $$(ls "$$rt"/wayland-[0-9] 2>/dev/null | head -1)) grim -' > $(SHOT) \
&& test -s $(SHOT) && echo "saved $(SHOT)" \
|| { echo "screenshot failed (is the graphical session up and grim installed?)"; rm -f $(SHOT); exit 1; }