-
Notifications
You must be signed in to change notification settings - Fork 11
/
makefile
70 lines (59 loc) · 1.71 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
DT := $(shell date +%Y%U)
REV := $(shell git rev-parse --short HEAD)
APP := $(shell basename $(CURDIR))
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
EXT :=
ifeq ($(GOOS),windows)
EXT := .exe
endif
ARTIFACT := bin/$(APP)-$(GOOS)-$(GOARCH)$(EXT)
AMD64CC :=
ARM64CC :=
TAGS ?= dev
GOFLAGS ?= -race -v
GOLDFLAGS ?= -X main.buildRevision=$(DT).$(REV)
ifeq ($(shell go env GOHOSTOS), windows)
AMD64CC = x86_64-w64-mingw32-gcc
ARM64CC = aarch64-w64-mingw32-gcc
GOLDFLAGS = -H=windowsgui -X main.buildRevision=$(DT).$(REV)
else ifeq ($(shell go env GOHOSTOS), linux)
ifeq ($(shell go env GOHOSTARCH), amd64)
ARM64CC = aarch64-linux-gnu-gcc
else
AMD64CC = x86_64-linux-gnu-gcc
endif
endif
.PHONY: all amd64 arm64 build macapp release tidy updep
build:
CGO_ENABLED=1 go build $(GOFLAGS) -ldflags "$(GOLDFLAGS)" -tags="$(TAGS)" -o $(ARTIFACT) cmd/*.go
release:
GOFLAGS="-trimpath" GOLDFLAGS="$(GOLDFLAGS) -s -w" TAGS="release" $(MAKE) build
amd64:
ifeq ($(shell go env GOHOSTOS), windows)
goversioninfo -64
endif
GOARCH=amd64 CC=$(AMD64CC) $(MAKE) release
ifeq ($(shell go env GOHOSTOS), windows)
rm -f resource.syso
endif
arm64:
ifeq ($(shell go env GOHOSTOS), windows)
goversioninfo -64 -arm
endif
GOARCH=arm64 CC=$(ARM64CC) $(MAKE) release
ifeq ($(shell go env GOHOSTOS), windows)
rm -f resource.syso
endif
tidy: go.mod
go mod tidy
updep: go.mod
rm -f go.sum
head -1 go.mod > /tmp/go.mod
mv /tmp/go.mod go.mod
go mod tidy
macapp: kmactor.app bin/kmactor-darwin-amd64 bin/kmactor-darwin-arm64
lipo -create -output kmactor.app/Contents/MacOS/kmactor bin/kmactor-darwin-amd64 bin/kmactor-darwin-arm64
zip bin/kmactor.app.zip -r kmactor.app
rm bin/kmactor-darwin-amd64 bin/kmactor-darwin-arm64
all: amd64 arm64