-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (59 loc) · 2.22 KB
/
Copy pathMakefile
File metadata and controls
69 lines (59 loc) · 2.22 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
.DEFAULT_GOAL := service-install
.PHONY: build release-build install service-install uninstall release
CONFIG_DIR = $$HOME/.config/perch
BIN_DIR = $$HOME/.local/bin
VERSION := $(shell git describe --tags --abbrev=0)
UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
SERVICE_DIR = $$HOME/Library/LaunchAgents
SERVICE_FILE = perchd.plist
INSTALL_SVC = sed "s|@HOME@|$$HOME|g" installation/perchd.plist > $(SERVICE_DIR)/perchd.plist
RELOAD = true
ENABLE = launchctl bootstrap gui/$$(id -u) $(SERVICE_DIR)/perchd.plist
DISABLE = launchctl bootout gui/$$(id -u)/com.perch.perchd
SHA = shasum -a 256
else
SERVICE_DIR = $$HOME/.local/share/systemd/user
SERVICE_FILE = perchd.service
INSTALL_SVC = cp installation/perchd.service $(SERVICE_DIR)
RELOAD = systemctl --user daemon-reload
ENABLE = systemctl --user enable --now perchd.service
DISABLE = systemctl --user disable --now perchd.service
SHA = sha256sum
endif
PLATFORMS = linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
build:
go build -ldflags "-X main.version=$(VERSION)" -o ./bin/perch ./cmd/perch
release-build:
rm -rf ./bin
@for p in $(PLATFORMS); do \
os=$${p%/*}; arch=$${p#*/}; \
echo "building perch-$$os-$$arch"; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 go build -ldflags "-X main.version=$(VERSION)" -o ./bin/perch-$$os-$$arch ./cmd/perch || exit 1; \
done
cp ./installation/perchd.service ./installation/perchd.plist ./bin
cd ./bin && $(SHA) perch-* perchd.service perchd.plist > checksums.txt
service-install: install
mkdir -p $(SERVICE_DIR) && \
$(INSTALL_SVC) && \
$(RELOAD) && \
$(ENABLE)
install: build
mkdir -p $(BIN_DIR) && cp ./bin/perch $(BIN_DIR)
@if ! [ -e $(CONFIG_DIR)/perchconf.toml ]; then \
mkdir -p $(CONFIG_DIR) && \
cd $(CONFIG_DIR) && \
printf "# perch config\n# add [[watches]] entries below" > perchconf.toml; \
fi
@if ! [ -e $(CONFIG_DIR)/markers.json ]; then \
cd $(CONFIG_DIR) && \
printf "{}" > markers.json; \
fi
uninstall:
$(DISABLE) && \
rm -f $(SERVICE_DIR)/$(SERVICE_FILE) && \
$(RELOAD) && \
rm -f $(BIN_DIR)/perch && \
rm -rf $(CONFIG_DIR)
release: release-build
gh release create $(VERSION) ./bin/* --title "$(VERSION)" --generate-notes