This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
57 lines (41 loc) · 1.44 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
GO := go
GOFMT := gofmt
GO111MODULE := on
GOHOSTOS := $(shell $(GO) env GOHOSTOS)
GOHOSTARCH := $(shell $(GO) env GOHOSTARCH)
BINARY := litespeed_exporter
PLATFORMS := darwin/amd64 dragonfly/amd64 freebsd/amd64 linux/amd64 netbsd/amd64 openbsd/amd64 windows/amd64 linux/386 freebsd/386 netbsd/386 openbsd/386 windows/386
BUILD_VERSION := $(shell cat VERSION)
BUILD_DATE := $(shell date '+%FT%T')
BUILD_REVISION := $(shell git rev-parse HEAD)
LDFLAGS=-ldflags "-X main.Version=$(BUILD_VERSION) -X main.Date=$(BUILD_DATE) -X main.Revision=$(BUILD_REVISION)"
all: check test clean build
.PHONY: test
test:
$(GO) test -v -cover -race -coverprofile=coverage.txt ./...
.PHONY: check
check:
$(GO) vet ./...
$(GOFMT) -s -d $(shell find . -path ./vendor -prune -o -name '*.go' -print)
.PHONY: clean
clean:
rm -rf bin/*
rm -rf dist
.PHONY: build
build:
GO111MODULE=$(GO111MODULE) GOOS=$(GOHOSTOS) GOARCH=$(GOHOSTARCH) $(GO) build $(LDFLAGS) -v -o bin/$(BINARY)-$(BUILD_VERSION)
temp = $(subst /, ,$@)
OS = $(word 1, $(temp))
ARCH = $(word 2, $(temp))
.PHONY: build-all $(PLATFORMS)
build-all: $(PLATFORMS)
$(PLATFORMS):
GO111MODULE=$(GO111MODULE) GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(LDFLAGS) -v -o bin/$(BINARY)-v$(BUILD_VERSION).$(OS)-$(ARCH)
BINARIES := $(shell cd bin && find *)
.PHONY: tarballs $(BINARIES)
tarballs: dist-folder $(BINARIES)
dist-folder:
rm -rf dist
mkdir dist
$(BINARIES):
tar -C bin -czf "dist/$@.tar.gz" "$@"