Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (92 loc) · 4.42 KB
/
Copy pathMakefile
File metadata and controls
111 lines (92 loc) · 4.42 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
BINARY := flockdeck
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X main.version=$(VERSION)
DIST := dist
# On Windows the GUI subsystem is used so that launching the application from a
# shortcut or file manager does not flash a console window behind it. A program
# linked that way is given no console, even by a terminal, so the program
# borrows the terminal's itself (useConsole in console_windows.go).
WINFLAGS := $(LDFLAGS) -H=windowsgui
# Beside it on Windows goes $(CHAT).exe, the same program linked as a console
# program. An API agent's pane runs Flockdeck's own chat client as its process,
# and a pane is a pseudo-console, which Windows attaches only to console
# programs; run from the GUI build the pane stays blank.
CHAT := $(BINARY)-chat
# Where go install puts programs, for the twin it cannot install itself.
GOBIN_DIR := $(or $(shell go env GOBIN),$(shell go env GOPATH)/bin)
# Every target here builds with cgo disabled, so all platforms compile from any
# one machine with nothing but the Go toolchain installed. A Linux or macOS
# binary built this way has no native window (that needs cgo: GTK4/WebKitGTK,
# Cocoa) and opens the page in the default browser instead; the release
# builds of those two use cgo, natively (see cmd/release).
export CGO_ENABLED = 0
PLATFORMS := \
windows/amd64 \
windows/arm64 \
linux/amd64 \
linux/arm64 \
darwin/amd64 \
darwin/arm64
.PHONY: all build install test race vet fmt check clean dist package installer $(PLATFORMS)
all: check build
build:
ifeq ($(shell go env GOOS),windows)
go build -ldflags "$(WINFLAGS)" -o $(BINARY).exe .
go build -ldflags "$(LDFLAGS)" -o $(CHAT).exe .
else
go build -ldflags "$(LDFLAGS)" -o $(BINARY) .
endif
install:
ifeq ($(shell go env GOOS),windows)
go install -ldflags "$(WINFLAGS)" .
go build -ldflags "$(LDFLAGS)" -o "$(GOBIN_DIR)/$(CHAT).exe" .
else
go install -ldflags "$(LDFLAGS)" .
endif
test:
go test ./...
# The race detector needs a C toolchain; skipped by default because the app
# itself never requires one.
race:
CGO_ENABLED=1 go test -race ./...
vet:
go vet ./...
fmt:
gofmt -l -w .
check: vet test
dist: $(PLATFORMS)
# The Windows builds take the GUI subsystem here too, as build and package do;
# without it a binary from dist opens a console window behind the interface.
$(PLATFORMS):
@mkdir -p $(DIST)
GOOS=$(word 1,$(subst /, ,$@)) GOARCH=$(word 2,$(subst /, ,$@)) \
go build -ldflags "$(if $(filter windows,$(word 1,$(subst /, ,$@))),$(WINFLAGS),$(LDFLAGS))" \
-o $(DIST)/$(BINARY)-$(word 1,$(subst /, ,$@))-$(word 2,$(subst /, ,$@))$(if $(filter windows,$(word 1,$(subst /, ,$@))),.exe,) .
$(if $(filter windows,$(word 1,$(subst /, ,$@))),GOOS=windows GOARCH=$(word 2,$(subst /, ,$@)) \
go build -ldflags "$(LDFLAGS)" -o $(DIST)/$(CHAT)-windows-$(word 2,$(subst /, ,$@)).exe .,)
@echo "built $(DIST)/$(BINARY)-$(subst /,-,$@)"
# package cross-builds every platform and writes the archives and checksums a
# release is made of, which is exactly what CI publishes. Run it before tagging
# to see what a release would contain, or to hand someone a build.
package:
go run ./cmd/release -version $(VERSION) -out $(DIST)
clean:
rm -rf $(DIST) bin $(BINARY) $(BINARY).exe $(CHAT).exe
# installer packages flockdeck.exe as a Windows installer using Wails' own
# NSIS tooling (build/windows/nsis), rather than a build system of its own:
# Wails is only ever a library dependency here (see internal/appwindow), so
# `build` above -- a plain `go build` -- is still what produces the binary
# this packages. build/windows/nsis/project.nsi is wails3's own template
# (from `wails3 generate build-assets`), customised only to match the
# binary's real name; build/windows/icon.ico is generated from the same
# source PNG as the .syso icon resource winres.go's go:generate makes
# (see build/appicon.png and `wails3 generate icons`).
#
# Requires NSIS's makensis on PATH (https://nsis.sourceforge.io/) and, the
# first time, a network connection to fetch the WebView2 bootstrapper the
# installer runs (see .gitignore: it is not carried in the repository).
# Windows only, like the installer it makes.
installer: build
mkdir -p bin
test -f build/windows/nsis/MicrosoftEdgeWebview2Setup.exe || wails3 generate webview2bootstrapper -dir build/windows/nsis
makensis -DARG_WAILS_AMD64_BINARY="$(CURDIR)/$(BINARY).exe" -DINFO_PRODUCTVERSION=$(patsubst v%,%,$(firstword $(subst -, ,$(VERSION)))) build/windows/nsis/project.nsi