Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
121 lines (100 loc) · 5.41 KB
/
Copy pathMakefile
File metadata and controls
121 lines (100 loc) · 5.41 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
BINARY = lerd
# Tags carry a leading v, the version string does not: the release workflow
# injects ${GITHUB_REF_NAME#v}, so stripping it here keeps a local build's
# `lerd --version` and its upgrade banner identical to a released one.
VERSION ?= $(patsubst v%,%,$(shell git describe --tags --always --dirty 2>/dev/null || echo "0.1.0"))
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
BUILD_DIR = ./build
INSTALL_DIR = $(HOME)/.local/bin
# Mirrors config.RunDir(): $XDG_DATA_HOME (default ~/.local/share) + /lerd/run.
LERD_RUN_DIR = $(if $(XDG_DATA_HOME),$(XDG_DATA_HOME),$(HOME)/.local/share)/lerd/run
UI_DIR = internal/ui/web
# JS runtime for the web UI build. Prefer npm (when lerd manages Node), fall
# back to bun so lerd can be built on a host where Node is unmanaged. Checks
# ~/.bun/bin too since the bun installer may leave it off a non-login PATH.
# Both run the same package.json scripts; only the install verb differs
# (npm ci vs bun install).
JS_PM := $(shell command -v npm 2>/dev/null || command -v bun 2>/dev/null || echo $(HOME)/.bun/bin/bun)
ifeq ($(notdir $(JS_PM)),bun)
JS_INSTALL = install
else
JS_INSTALL = ci
endif
PKG = github.com/geodro/lerd/internal/version
LDFLAGS = -s -w \
-X $(PKG).Version=$(VERSION) \
-X $(PKG).Commit=$(COMMIT) \
-X $(PKG).Date=$(DATE)
.PHONY: build build-windows build-tray build-ui install-ui-deps test-ui install install-installer licenses test dupes clean release release-snapshot
UI_INSTALL_STAMP = $(UI_DIR)/node_modules/.package-lock.json
install-ui-deps: $(UI_INSTALL_STAMP)
$(UI_INSTALL_STAMP): $(UI_DIR)/package-lock.json $(UI_DIR)/package.json
cd $(UI_DIR) && $(JS_PM) $(JS_INSTALL)
@touch $@
build-ui: $(UI_INSTALL_STAMP)
cd $(UI_DIR) && $(JS_PM) run build
test-ui: $(UI_INSTALL_STAMP)
cd $(UI_DIR) && $(JS_PM) run test
build: build-ui build-windows
CGO_ENABLED=0 go build -tags nogui -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY) ./cmd/lerd
# lerd.exe, the Windows side of a WSL install, built for this machine's arch.
build-windows:
GOOS=windows CGO_ENABLED=0 go build -ldflags="-s -w" -o $(BUILD_DIR)/lerd.exe ./cmd/lerd-windows
build-tray:
CGO_ENABLED=1 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/lerd-tray ./cmd/lerd-tray
install: build build-tray
install -Dm755 $(BUILD_DIR)/$(BINARY) $(INSTALL_DIR)/$(BINARY)
install -Dm755 $(BUILD_DIR)/lerd-tray $(INSTALL_DIR)/lerd-tray
@# On WSL, wsl:setup copies lerd.exe out from beside lerd, as install.sh places it.
@if grep -qi microsoft /proc/sys/kernel/osrelease 2>/dev/null; then install -Dm755 $(BUILD_DIR)/lerd.exe $(INSTALL_DIR)/lerd.exe && echo "Installed $(INSTALL_DIR)/lerd.exe"; fi
@echo "Installed $(INSTALL_DIR)/$(BINARY) and $(INSTALL_DIR)/lerd-tray"
@# The watcher tears the whole environment down when it reads a SIGTERM as a
@# logout. Restarting it here is not one, so mark it the way lerd's own
@# restart paths do, or `make install` stops every container and the VM.
@mkdir -p $(LERD_RUN_DIR) && touch $(LERD_RUN_DIR)/watcher-managed-stop
@if [ "$$(uname)" = "Darwin" ]; then \
launchctl kickstart -k gui/$$(id -u)/com.lerd.lerd-ui 2>/dev/null && echo "Restarted lerd-ui" || true; \
launchctl kickstart -k gui/$$(id -u)/com.lerd.lerd-watcher 2>/dev/null && echo "Restarted lerd-watcher" || true; \
launchctl kickstart -k gui/$$(id -u)/com.lerd.lerd-dns 2>/dev/null && echo "Restarted lerd-dns" || true; \
launchctl kickstart -k gui/$$(id -u)/com.lerd.lerd-tray 2>/dev/null || true; \
else \
systemctl --user daemon-reload 2>/dev/null || true; \
systemctl --user is-active --quiet lerd-ui 2>/dev/null && systemctl --user restart lerd-ui && echo "Restarted lerd-ui" || true; \
systemctl --user is-active --quiet lerd-watcher 2>/dev/null && systemctl --user restart lerd-watcher && echo "Restarted lerd-watcher" || true; \
systemctl --user is-active --quiet lerd-dns 2>/dev/null && systemctl --user restart lerd-dns && echo "Restarted lerd-dns" || true; \
systemctl --user is-active --quiet lerd-tray 2>/dev/null && systemctl --user restart lerd-tray || true; \
fi
# Install the installer script as 'lerd-installer' so users can run
# lerd-installer --update or lerd-installer --uninstall
install-installer:
install -Dm755 install.sh $(INSTALL_DIR)/lerd-installer
@echo "Installed $(INSTALL_DIR)/lerd-installer"
# Regenerates the third-party notices embedded in the binary. Needs the UI
# dependencies installed, since the npm tree is half of what gets disclosed.
licenses: $(UI_INSTALL_STAMP)
go run ./tools/licensegen
test:
go test ./...
test-installer:
bats tests/installer/installer.bats
test-all: test test-ui test-installer
# Copy-paste report like PhpStorm's Duplicated Code, opened in the browser.
# Pinned so the scan is reproducible; tests are left out because table-driven
# setup repeats on purpose.
dupes:
npx --yes jscpd@5.3.3 internal cmd \
--format go,typescript,javascript,markup \
--formats-exts markup:svelte \
--ignore '**/*_test.go,**/*.test.ts,**/node_modules/**,**/dist/**,**/demo/**,**/paraglide/**' \
--min-tokens 70 --reporters html,json,console --silent \
--output $(BUILD_DIR)/dupes
xdg-open $(BUILD_DIR)/dupes/jscpd-report.html >/dev/null 2>&1 || true
clean:
rm -rf $(BUILD_DIR)
rm -rf $(UI_DIR)/dist
# Requires goreleaser: https://goreleaser.com/install/
release:
goreleaser release --clean
release-snapshot:
goreleaser release --snapshot --clean