-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (73 loc) · 2.46 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
GIT_COMMIT?=$(shell git rev-parse --short HEAD)
GIT_VERSION?=$(shell git describe --tags 2>/dev/null || echo "v0.0.0-"$(GIT_COMMIT))
IMG_REG?=ghcr.io
IMG_REPO?=fgiudici/ddflare
IMG_TAG?=$(GIT_VERSION:v%=%)
export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BUILD_DIR := bin
RELEASE_DIR := release
LDFLAGS := -w -s
LDFLAGS += -X "github.com/fgiudici/ddflare/pkg/version.Version=${GIT_VERSION}"
COVERFILE?=coverage.out
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
.PHONY: build
build: build-cli
.PHONY: build-cli
build-cli:
CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(BUILD_DIR)/ddflare $(ROOT_DIR)/cli
.PHONY: clean
clean:
@rm -vrf $(BUILD_DIR) $(COVERFILE) ${RELEASE_DIR}
.PHONY: release
release:
$(call cross_compile,${GOOS},${GOARCH})
.PHONY: release-all
release-all: release-linux-amd64 release-linux-arm64 \
release-linux-armv6 release-linux-armv7 \
release-darwin-amd64 release-darwin-arm64 \
release-windows-amd64 release-windows-arm64
.PHONY: release-linux-amd64
release-linux-amd64:
$(call cross_compile,"linux","amd64","","")
.PHONY: release-linux-arm64
release-linux-arm64:
$(call cross_compile,"linux","arm64","","")
.PHONY: release-linux-armv6
release-linux-armv6:
$(call cross_compile,"linux","arm","6","-v6")
.PHONY: release-linux-armv7
release-linux-armv7:
$(call cross_compile,"linux","arm","7","-v7")
.PHONY: release-darwin-amd64
release-darwin-amd64:
$(call cross_compile,"darwin","amd64","","")
.PHONY: release-darwin-arm64
release-darwin-arm64:
$(call cross_compile,"darwin","arm64","","")
.PHONY: release-windows-amd64
release-windows-amd64:
$(call cross_compile,"windows","amd64","","")
.PHONY: release-windows-arm64
release-windows-arm64:
$(call cross_compile,"windows","arm64","","")
.PHONY: docker
docker:
DOCKER_BUILDKIT=1 docker build \
-f Dockerfile \
--build-arg "VERSION=${GIT_VERSION}" \
-t ${IMG_REG}/${IMG_REPO}:${IMG_TAG}
.PHONY: unit-tests
unit-tests:
@go test -coverprofile $(COVERFILE) ./pkg/...
define cross_compile
mkdir -p ${RELEASE_DIR}
$(eval $@_GOOS = $(1))
$(eval $@_GOARCH = $(2))
$(eval $@_GOARM = $(3))
$(eval $@_SUFFIX = $(4))
env GOOS=${$@_GOOS} GOARCH=${$@_GOARCH} GOARM=${$@_GOARM} CGO_ENABLED=0 go build \
-ldflags '$(LDFLAGS)' -o ${RELEASE_DIR}/ddflare-${$@_GOOS}-${$@_GOARCH}${$@_SUFFIX} ${ROOT_DIR}/cli
shasum -a 256 ${RELEASE_DIR}/ddflare-${$@_GOOS}-${$@_GOARCH}${$@_SUFFIX} \
> ${RELEASE_DIR}/ddflare-${$@_GOOS}-${$@_GOARCH}${$@_SUFFIX}.sha256
endef