-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
99 lines (81 loc) · 3.16 KB
/
Copy pathmakefile
File metadata and controls
99 lines (81 loc) · 3.16 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
GO_INSTALLED := $(shell command -v go version)
GO_VERSION := 1.26
GORELEASER_EXISTS := $(shell command -v goreleaser version)
INSTALL_GORELEASER := go install github.com/goreleaser/goreleaser/v2@latest
# Linux setup
GO_TARBALL := https://golang.org/dl/go$(GO_VERSION).linux-amd64.tar.gz
LINUX_INSTALL_DIR := /usr/local
install: APP_NAME := koshime
install: VERSION := $(shell git describe --tags --exact-match 2>/dev/null)
install: COMMIT := $(shell git rev-parse --short HEAD)
install: LDFLAGS := -s -w -X 'main.version=$(VERSION)' -X 'main.commitSha=$(COMMIT)'
install: DISPLAY_VERSION := $(if $(VERSION),$(VERSION),No Tag)
install:
@echo "📦 Installing $(APP_NAME)"
@echo " Version: $(DISPLAY_VERSION)"
@echo " Commit: $(COMMIT)"
@go install -trimpath -ldflags="$(LDFLAGS)" ./...
# Try to install Go on windows if it doesn't exist
install-go-windows:
@if [ -z "$(GO_INSTALLED)" ]; then \
echo "Go is not installed. Installing now..."; \
choco install golang --version $(GO_VERSION) -y; \
if [ $$? -ne 0 ]; then \
echo "Failed to install Golang. Please install it manually."; \
exit 1; \
fi \
fi
# Try to install Go on linux if it doesn't exist (partially tested)
install-go-linux:
@if [ -z "$(GO_INSTALLED)" ]; then \
echo "Go not found. Installing Go $(GO_VERSION)..."; \
curl -L $(GO_TARBALL) | sudo tar -C $(LINUX_INSTALL_DIR) -xzf; \
if [ $$? -ne 0 ]; then \
echo "Failed to install Golang. Please install it manually."; \
exit 1; \
fi \
fi
# Try to install go on macos if it doesn't exist (not tested)
install-go-macos:
@if [ -z "$(GO_INSTALLED)" ]; then \
echo "Go not found. Installing Go $(GO_VERSION)..."; \
brew install golang@$(GO_VERSION); \
if [ $$? -ne 0 ]; then \
echo "Failed to install Golang. Please install it manually."; \
exit 1; \
fi \
fi
# Check if GoReleaser is installed
install-goreleaser:
@if [ -z "$(GORELEASER_EXISTS)" ]; then \
echo "GoReleaser is not installed. Installing..."; \
$(INSTALL_GORELEASER); \
if [ $$? -ne 0 ]; then \
echo "Failed to install GoReleaser. Please install it manually."; \
exit 1; \
fi \
fi
setup-windows: install-go-windows install-goreleaser
@echo "You're all set!"
setup-linux: install-go-linux install-goreleaser
@echo "You're all set!"
setup-macos: install-go-macos install-goreleaser
@echo "You're all set!"
dev:
@goreleaser build --snapshot --clean --config .goreleaser.dev.yml
release:
@goreleaser release --snapshot --clean
test:
@gotestsum -f testdox --watch
testall:
@gotestsum -- ./...
# Define variables and dummy target evaluations at top level
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(RUN_ARGS):;@:)
rundev: VERSION := $(shell git describe --tags --exact-match 2>/dev/null)
rundev: COMMIT := $(shell git rev-parse --short HEAD)
rundev: DISPLAY_COMMIT := $(if $(COMMIT),$(COMMIT),"d3adb33f")
rundev: DISPLAY_VERSION := $(if $(VERSION),$(VERSION),$(COMMIT))
rundev: LDFLAGS := -ldflags="-X 'main.version=$(DISPLAY_VERSION)-dev' -X 'main.commitSha=$(DISPLAY_COMMIT)' -X 'main.buildDate='"
rundev:
@CGO_ENABLED=0 go run -gcflags="all=-N -l" $(LDFLAGS) . $(RUN_ARGS)