-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (55 loc) · 1.16 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
# settings
IS_RELEASE ?= false
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
# tools
GO = go
WINRES = $(GO) run github.com/tc-hib/go-winres@latest
UPX = upx
# output
BINARY = ./bin/$(GOOS)-$(GOARCH)
EXE_EXT = $(shell go env GOEXE)
ifeq ($(GOARCH),wasm)
EXE_EXT = .wasm
endif
EXE = $(BINARY)/gophengine$(EXE_EXT)
# flags
UPX_FLAGS = --best --lzma
GO_GCFLAGS =
GO_LDFLAGS =
GO_FLAGS = -v
ifeq ($(IS_RELEASE),true)
GO_GCFLAGS += -dwarf=false
GO_LDFLAGS += -s -w
GO_FLAGS += -trimpath
ifeq ($(GOOS),windows)
GO_LDFLAGS += -H windowsgui
endif
endif
GO_FLAGS += -gcflags="$(GO_GCFLAGS)" -ldflags="$(GO_LDFLAGS)" -buildvcs=true
ifneq ($(GOARCH),wasm)
GO_FLAGS += -buildmode=pie
endif
.PHONY: all
all: build upx
.PHONY: build
build: clean
mkdir -p $(BINARY)
$(GO) get
ifeq ($(GOOS),windows)
$(WINRES) make --out ./cmd/gophengine/rsrc
endif
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build $(GO_FLAGS) -o $(EXE) ./cmd/gophengine
.PHONY: upx
upx: build
ifeq ($(IS_RELEASE),true)
ifneq ($(GOARCH),wasm)
$(UPX) $(UPX_FLAGS) $(EXE)
endif
endif
.PHONY: clean
clean:
rm -rf $(BINARY)
ifeq ($(GOOS),windows)
rm -f ./cmd/gophengine/rsrc_windows_*.syso
endif