-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
239 lines (182 loc) · 9.28 KB
/
Makefile
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
238
239
DIST_DIR ?= dist
GOOS ?= $(shell uname -s | tr "[:upper:]" "[:lower:]")
ARCH ?= $(shell uname -m)
ifeq ($(ARCH),x86_64)
GOARCH := amd64
else
# no idea if this works for other platforms....
GOARCH := $(ARCH)
endif
BUILDINFOSDET ?=
PROGRAM_ARGS ?=
PROJECT_VERSION := 2.4.2
BUILD_ID := 1
DOCKER_REPO := synfinatic
PROJECT_NAME := alpacascope
PROJECT_TAG := $(shell git describe --tags 2>/dev/null $(git rev-list --tags --max-count=1))
ifeq ($(PROJECT_TAG),)
PROJECT_TAG := NO-TAG
endif
PROJECT_COMMIT := $(shell git rev-parse HEAD)
ifeq ($(PROJECT_COMMIT),)
PROJECT_COMMIT := NO-CommitID
endif
PROJECT_DELTA := $(shell DELTA_LINES=$$(git diff | wc -l); if [ $${DELTA_LINES} -ne 0 ]; then echo $${DELTA_LINES} ; else echo "''" ; fi)
VERSION_PKG := $(shell echo $(PROJECT_VERSION) | sed 's/^v//g')
LICENSE := GPLv3
URL := https://github.com/$(DOCKER_REPO)/$(PROJECT_NAME)
DESCRIPTION := AlpacaScope: Alpaca to Telescope Protocol Proxy
BUILDINFOS := $(shell date +%FT%T%z)$(BUILDINFOSDET)
HOSTNAME := $(shell hostname)
LDFLAGS := -X "main.Version=$(PROJECT_VERSION)" -X "main.Delta=$(PROJECT_DELTA)" -X "main.Buildinfos=$(BUILDINFOS)" -X "main.Tag=$(PROJECT_TAG)" -X "main.CommitID=$(PROJECT_COMMIT)"
OUTPUT_NAME := $(DIST_DIR)/$(PROJECT_NAME)-$(PROJECT_VERSION)-$(GOOS)-$(GOARCH) # default for current platform
# supported platforms for `make release`
LINUX_BIN := $(DIST_DIR)/$(PROJECT_NAME)-$(PROJECT_VERSION)-linux-amd64
LINUXARM64_BIN := $(DIST_DIR)/$(PROJECT_NAME)-$(PROJECT_VERSION)-linux-arm64
LINUXARM32_BIN := $(DIST_DIR)/$(PROJECT_NAME)-$(PROJECT_VERSION)-linux-arm32
LINUX_GUI := $(DIST_DIR)/$(PROJECT_NAME)-gui-$(PROJECT_VERSION)-linux-amd64
DARWIN_BIN := $(DIST_DIR)/$(PROJECT_NAME)-$(PROJECT_VERSION)-darwin-amd64
DARWIN_RELEASE_GUI := $(DIST_DIR)/AlpacaScope.app
DARWIN_RELEASE_ZIP := $(DIST_DIR)/AlpacaScope-$(PROJECT_VERSION).app.zip
DARWIN_GUI := $(DIST_DIR)/$(PROJECT_NAME)-gui-$(PROJECT_VERSION)-darwin-amd64
WINDOWS_RELEASE := $(DIST_DIR)/AlpacaScope.exe
WINDOWS_CLI := $(DIST_DIR)/AlpacaScope-CLI-$(PROJECT_VERSION).exe
WINDOWS := $(DIST_DIR)/AlpacaScope-Debug-$(PROJECT_VERSION).exe
FYNE_VERSION := v2.5.1
FYNE_CROSS_VERSION := v1.5.0
GUI_FILES = $(shell find . -type f -name '*.go' | grep -v _test.go | grep -v ./cmd/alpacascope/ ) Makefile
CLI_FILES = $(shell find . -type f -name '*.go' | grep -v _test.go | grep -v ./cmd/alpacascope-gui/) Makefile
ALL: $(GOOS) ## Build binary. Needs to be a supported plaform as defined above
include help.mk # place after ALL target and before all other targets
release: clean .build-release ## Build CLI release files
@echo "You still need to build 'make windows-release' and 'make sign-relase'"
.PHONY: sign-release
sign-release: $(DIST_DIR)/release.sig.asc ## Sign release
.PHONY:
.verify_windows:
@if test ! -f $(WINDOWS_RELEASE); then echo "Missing Windows release binary"; exit 1; fi
$(DIST_DIR)/release.sig.asc: .build-release $(DARWIN_RELEASE_ZIP) .verify_windows
cd dist && shasum -a 256 * | gpg --clear-sign >release.sig.asc
# This target builds anywhere
.build-release: $(LINUX_BIN) $(LINUXARM64_BIN) $(LINUXARM32_BIN) $(DARWIN_BIN) $(DARWIN_GUI) $(DARWIN_RELEASE_GUI) $(WINDOWS_CLI)
# this targets only build on MacOS
build-gui: darwin-gui darwin-release-gui windows linux-gui ## Build GUI binaries
.build-gui-check:
@if test $(GOOS) != "darwin" ; then echo "$(MAKECMDGOALS) requires building on MacOS" ; exit 1 ; fi
.build-windows-check:
@if test -z "`echo $(GOOS) | grep 'mingw64'`" ; then echo "$(MAKECMDGOALS) requires building on Windows/MINGW64" ; exit 1 ; fi
install-fyne: ## Download and install Fyne
go install fyne.io/fyne/v2/cmd/fyne@$(FYNE_VERSION)
install-fyne-cross: ## Download and install Fyne-Cross
go install github.com/fyne-io/fyne-cross@$(FYNE_CROSS_VERSION)
# Install fyne binary in $GOPATh/bin
.PHONY: .fyne .fyne-cross
.fyne:
@if test -z "`which fyne`"; then echo "Please install fyne: make install-fyne" ; exit 1 ; fi
.fyne-cross:
@if test -z "`which fyne-cross`"; then echo "Please install fyne-cross: make install-fyne-cross" ; exit 1 ; fi
# used by our github action to test building the release binaries + GUI on Linux
.build-test-binaries: $(LINUX_BIN) $(DARWIN_BIN) $(WINDOWS)
.PHONY: run
run: $(CLI_FILES) ## build and run cria using $PROGRAM_ARGS
go run ./cmd/alpacascope/... $(PROGRAM_ARGS)
clean-all: clean ## clean _everything_
clean: ## Remove all binaries in dist
rm -rf dist/*
clean-go: ## Clean Go cache
go clean -i -r -cache -modcache
go-get: ## Get our go modules
go install -v all
.PHONY: build-race
build-race: .prepare ## Build race detection binary
go build -race -ldflags='$(LDFLAGS)' -o $(OUTPUT_NAME) ./cmd/alpacascope/...
go build -race -ldflags='$(LDFLAGS)' -o $(OUTPUT_NAME) ./cmd/alpacascope-gui/...
debug: .prepare ## Run debug in dlv
dlv debug ./cmd/alpacascope/...
.PHONY: unittest
unittest: ## Run go unit tests
go test -ldflags='$(LDFLAGS)' -covermode=atomic -coverprofile=coverage.out ./...
.PHONY: test-race
test-race: ## Run `go test -race` on the code
@echo checking code for races...
go test -race ./...
.PHONY: vet
vet: ## Run `go vet` on the code
@echo checking code is vetted...
go vet $(shell go list ./...)
test: vet unittest ## Run all tests
.prepare: $(DIST_DIR)
$(DIST_DIR):
@if test ! -d $(DIST_DIR); then mkdir -p $(DIST_DIR) ; fi
.PHONY: fmt
fmt: ## Format Go code
@go fmt cmd/...
.PHONY: test-fmt
test-fmt: fmt ## Test to make sure code if formatted correctly
@if test `git diff cmd | wc -l` -gt 0; then \
echo "Code changes detected when running 'go fmt':" ; \
git diff -Xfiles ; \
exit -1 ; \
fi
.PHONY: test-tidy
test-tidy: ## Test to make sure go.mod is tidy
@go mod tidy
@if test `git diff go.mod | wc -l` -gt 0; then \
echo "Need to run 'go mod tidy' to clean up go.mod" ; \
exit -1 ; \
fi
precheck: test test-fmt test-tidy ## Run all tests that happen in a PR
# Build targets for our supported plaforms
linux: $(LINUX_BIN) ## Build Linux/x86_64 CLI
$(LINUX_BIN): $(CLI_FILES) | .prepare
GOARCH=amd64 GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUX_BIN) ./cmd/alpacascope/...
@echo "Created: $(LINUX_BIN)"
linux-arm64: $(LINUXARM64_BIN) ## Build Linux/arm64 CLI
$(LINUXARM64_BIN): $(CLI_FILES) | .prepare
GOARCH=arm64 GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUXARM64_BIN) ./cmd/alpacascope/...
@echo "Created: $(LINUXARM64_BIN)"
linux-arm32: $(LINUXARM32_BIN) ## Build Linux/arm64 CLI
$(LINUXARM32_BIN): $(CLI_FILES) | .prepare
GOARCH=arm GOOS=linux go build -ldflags='$(LDFLAGS)' -o $(LINUXARM32_BIN) ./cmd/alpacascope/...
@echo "Created: $(LINUXARM32_BIN)"
darwin: $(DARWIN_BIN) ## Build MacOS/x86_64 CLI
$(DARWIN_BIN): $(CLI_FILES) | .prepare
GOARCH=amd64 GOOS=darwin go build -ldflags='$(LDFLAGS)' -o $(DARWIN_BIN) ./cmd/alpacascope/...
@echo "Created: $(DARWIN_BIN)"
darwin-gui: $(DARWIN_GUI) ## Build MacOS/x86_64 GUI
darwin-release-gui: $(DARWIN_RELEASE_GUI) ## Build MacOS/x86_64 Release GUI
$(DARWIN_RELEASE_GUI): $(GUI_FILES) | .build-gui-check .prepare .fyne
@fyne package --appID net.synfin.alpacascope --name AlpacaScope \
--appVersion $(PROJECT_VERSION) --appBuild $(BUILD_ID) \
--target darwin -sourceDir cmd/alpacascope-gui && \
rm -rf $(DARWIN_RELEASE_GUI) && mv AlpacaScope.app $(DARWIN_RELEASE_GUI)
$(DARWIN_RELEASE_ZIP): $(DARWIN_RELEASE_GUI)
@zip -mr $(DARWIN_RELEASE_ZIP) $(DARWIN_RELEASE_GUI)
$(DARWIN_GUI): $(GUI_FILES) | .build-gui-check .prepare
go build -ldflags='$(LDFLAGS)' -o $(DARWIN_GUI) ./cmd/alpacascope-gui/...
windows: $(WINDOWS) ## Build Windows/x86_64 GUI
$(WINDOWS): $(GUI_FILES) | .fyne-cross .prepare
fyne-cross windows -app-id net.synfin.alpacascope -developer "Aaron Turner" \
-app-version $(PROJECT_VERSION) \
-env FYNE_VERSION=$(FYNE_VERSION) \
-icon ./cmd/alpacascope-gui/Icon.png \
-name AlpacaScope-Debug-$(PROJECT_VERSION) ./cmd/alpacascope-gui && \
mv ./fyne-cross/bin/windows-$(GOARCH)/AlpacaScope-Debug-$(PROJECT_VERSION).exe $(DIST_DIR)
windows-release: $(WINDOWS_RELEASE) ## Build Windows/x86_64 release GUI
$(WINDOWS_RELEASE): $(GUI_FILES) | .build-windows-check .prepare .fyne
@rm -f dist/AlpacaScope-$(PROJECT_VERSION).exe && \
fyne package --appID net.synfin.AlpacaScope --name net.synfin.AlpacaScope \
--appVersion $(PROJECT_VERSION) --appBuild $(BUILD_ID) --target windows --release \
--sourceDir cmd/alpacascope-gui && \
mv cmd/alpacascope-gui/alpacascope-gui.exe $(WINDOWS_RELEASE)
windows-cli: $(WINDOWS_CLI) ## Build Windows/amd64 CLI
$(WINDOWS_CLI): $(GUI_FILES) | .prepare
GOARCH=amd64 GOOS=windows go build -ldflags='$(LDFLAGS)' -o $(WINDOWS_CLI) ./cmd/alpacascope/...
@echo "Created: $(WINDOWS_CLI)"
linux-gui: $(LINUX_GUI) ## Build Linux/x86_64 GUI
$(LINUX_GUI): $(GUI_FILES) | .prepare .fyne-cross
@fyne-cross linux -app-id net.synfin.alpacascope \
-app-version $(PROJECT_VERSION) -ldflags '$(LDFLAGS)' \
-icon $(shell pwd)/cmd/alpacascope-gui/Icon.png \
-name alpacascope $(shell pwd)/cmd/alpacascope-gui && \
mv fyne-cross/bin/linux-amd64/alpacascope $(LINUX_GUI)