-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
executable file
·33 lines (23 loc) · 1.06 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
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BINARY=mxcheck
VERSION=v1.6.2
BUILD=$(shell git rev-parse --short HEAD)
PLATFORMS=darwin linux windows
ARCHITECTURES=amd64 arm64
LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w -s"
BLDFLAGS=-buildmode=pie
all: clean build_all
build:
go build ${BLDFLAGS} ${LDFLAGS} -o ${BINARY}
build_all: $(foreach GOOS,$(PLATFORMS),$(foreach GOARCH,$(ARCHITECTURES),build_$(GOOS)_$(GOARCH)))
define build_template
build_$(1)_$(2):
GOOS=$(1) GOARCH=$(2) go build $(BLDFLAGS) $(LDFLAGS) -o $(BINARY)-$(1)-$(2)
tar cvfz $(BINARY)_$(1)_$(2)_$(VERSION).tar.gz $(if $(findstring windows,$(1)),$(BINARY)-$(1)-$(2).exe,$(BINARY)-$(1)-$(2))
rm $(if $(findstring windows,$(1)),$(BINARY)-$(1)-$(2).exe,$(BINARY)-$(1)-$(2))
endef
$(foreach GOOS,$(PLATFORMS),$(foreach GOARCH,$(ARCHITECTURES),$(eval $(call build_template,$(GOOS),$(GOARCH)))))
clean:
rm -f ${BINARY}-*
rm -f *.tar.gz
.PHONY: clean build build_all $(foreach GOOS,$(PLATFORMS),$(foreach GOARCH,$(ARCHITECTURES),build_$(GOOS)_$(GOARCH)))