-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
44 lines (32 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
# ########################################################## #
# Makefile for Golang Project
# Includes cross-compiling, installation, cleanup
# ########################################################## #
# Check for required command tools to build or stop immediately
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BINARY := sm2
VERSION := 1.2.0
BUILD := `git rev-parse HEAD`
# Setup linker flags option for build that interoperate with variable names in src code
# -s / -w omit debug symbols (for intel/arm) same as running strip cli tool
# -X writes the version/build into the binary so its available in `sm2 --version`
LDFLAGS=-ldflags "-s -w -X sm2/version.Version=$(VERSION) -X sm2/version.Build=$(BUILD)"
default: build
all: clean build_all package
build:
go build ${LDFLAGS} -o ${BINARY}
build_all:
@echo building all versions...
$(shell export CGO_ENABLED=0; export GOOS=linux; export GOARCH=amd64; go build $(LDFLAGS) -o build/$(BINARY)-$(VERSION)-linux-intel/$(BINARY))
$(shell export CGO_ENABLED=0; export GOOS=linux; export GOARCH=arm64; go build $(LDFLAGS) -o build/$(BINARY)-$(VERSION)-linux-arm64/$(BINARY))
$(shell export CGO_ENABLED=0; export GOOS=darwin; export GOARCH=amd64; go build $(LDFLAGS) -o build/$(BINARY)-$(VERSION)-apple-intel/$(BINARY))
$(shell export CGO_ENABLED=0; export GOOS=darwin; export GOARCH=arm64; go build $(LDFLAGS) -o build/$(BINARY)-$(VERSION)-apple-arm64/$(BINARY))
package:
@echo compressing releases
@find ${ROOT_DIR}/build -name '${BINARY}[-?][a-zA-Z0-9]*[-?][a-zA-Z0-9]*' -exec zip -j {}.zip {}/$(BINARY) \;
# Remove only what we've created
clean:
rm -rf ./build
test:
go test ./...
.PHONY: check clean install build_all all