-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
66 lines (49 loc) · 1.68 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
ifeq ($(OS),Windows_NT)
COMPILE_TIME := $(shell echo %date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%)
else
COMPILE_TIME := $(shell date +"%Y-%m-%d %H:%M:%S")
endif
VERSION=1.0.3
BUILD=$(shell git rev-parse HEAD)
RELEASE=$(COMPILE_TIME)
PLATFORMS=darwin linux windows
ARCHITECTURES=386 amd64
# Setup linker flags option for build that interoperate with variable names in src code
LDFLAGS=-ldflags '-s -w -X "main.Version=$(VERSION)" -X "main.Build=$(BUILD)" -X "main.Release=$(RELEASE)"'
# Sperate "linux-amd64" as GOOS and GOARCH
OSARCH_SPERATOR = $(word $2,$(subst -, ,$1))
.PHONY: default all
# Local build options
gsx2json: fmt tidy
go build $(LDFLAGS) -o ./build/ ./cmd/gsx2json/...
gencert: fmt tidy
go build $(LDFLAGS) -o ./build/ ./cmd/gencert/...
build: gsx2json gencert
# Architecture build options
gsx2json-arch-%: export GOARCH=$(call OSARCH_SPERATOR,$*,1)
gsx2json-arch-%: fmt tidy
go build $(LDFLAGS) -o ./build/$(GOARCH)/ ./cmd/gsx2json/...
gencert-arch-%: export GOARCH=$(call OSARCH_SPERATOR,$*,1)
gencert-arch-%: fmt tidy
go build $(LDFLAGS) -o ./build/$(GOARCH)/ ./cmd/gencert/...
arch-%: export GOARCH=$(call OSARCH_SPERATOR,$*,1)
arch-%: fmt tidy
go build $(LDFLAGS) -o ./build/$(GOARCH)/ ./cmd/...
# Platform build options
cross-compile-%: export GOOS=$(call OSARCH_SPERATOR,$*,1)
cross-compile-%: export GOARCH=$(call OSARCH_SPERATOR,$*,2)
cross-compile-%:
go build $(LDFLAGS) -o ./build/$(GOOS)-$(GOARCH)/ ./cmd/...
linux: cross-compile-linux-amd64
darwin: cross-compile-darwin-amd64
windows: cross-compile-windows-amd64
all: darwin linux windows
# Docker options
image:
docker build -t gsx2json .
# Misc
fmt:
go fmt ./...
tidy:
go mod tidy
default: all