-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
52 lines (40 loc) · 1.37 KB
/
Makefile
File metadata and controls
52 lines (40 loc) · 1.37 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
BINARY_NAME := zapstore
CMD_PATH := .
DIST := dist
GOFLAGS := -trimpath
LDFLAGS := -s -w
HOST_OS := $(shell go env GOOS)
HOST_ARCH := $(shell go env GOARCH)
ifeq ($(HOST_OS),darwin)
linux-arm64_CC := $(or $(CC_LINUX_ARM64),zig cc -target aarch64-linux-musl)
linux-amd64_CC := $(or $(CC_LINUX_AMD64),zig cc -target x86_64-linux-musl)
else
linux-arm64_CC := $(or $(CC_LINUX_ARM64),aarch64-linux-gnu-gcc)
linux-amd64_CC := $(or $(CC_LINUX_AMD64),x86_64-linux-gnu-gcc)
endif
.PHONY: all build build-darwin-arm64 build-linux-amd64 build-linux-arm64 clean fmt vet
build:
CGO_ENABLED=1 go build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o $(BINARY_NAME) $(CMD_PATH)
all: build-darwin-arm64 build-linux-amd64 build-linux-arm64
build-darwin-arm64:
@mkdir -p $(DIST)
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 \
go build $(GOFLAGS) -ldflags '$(LDFLAGS)' \
-o $(DIST)/$(BINARY_NAME)-darwin-arm64 $(CMD_PATH)
build-linux-amd64:
@mkdir -p $(DIST)
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC="$(linux-amd64_CC)" \
go build $(GOFLAGS) -ldflags '$(LDFLAGS)' \
-o $(DIST)/$(BINARY_NAME)-linux-amd64 $(CMD_PATH)
build-linux-arm64:
@mkdir -p $(DIST)
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC="$(linux-arm64_CC)" \
go build $(GOFLAGS) -ldflags '$(LDFLAGS)' \
-o $(DIST)/$(BINARY_NAME)-linux-arm64 $(CMD_PATH)
clean:
rm -f $(BINARY_NAME)
rm -rf $(DIST)
fmt:
go fmt ./...
vet:
go vet ./...