forked from tomcz/openldap_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
50 lines (39 loc) · 1.35 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
GITCOMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)
GIT_TAG := $(shell git describe --tags 2>/dev/null)
LDFLAGS := -s -w -X github.com/tomcz/openldap_exporter.commit=${GITCOMMIT}
LDFLAGS := ${LDFLAGS} -X github.com/tomcz/openldap_exporter.tag=${GIT_TAG}
OUTFILE ?= openldap_exporter
.PHONY: precommit
precommit: clean format lint compile
.PHONY: build
build: clean compile
.PHONY: commit
commit: clean cross-compile
ls -lha target/
.PHONY: clean
clean:
rm -rf target
target:
mkdir target
.PHONY: format
format:
@echo 'goimports ./...'
@goimports -w -local github.com/tomcz/openldap_exporter $(shell find . -type f -name '*.go' | grep -v '/vendor/')
.PHONY: lint
lint:
golangci-lint run
.PHONY: compile
compile: target
go build -ldflags "${LDFLAGS}" -o target/${OUTFILE} ./cmd/openldap_exporter/...
gzip -c < target/${OUTFILE} > target/${OUTFILE}.gz
.PHONY: cross-compile
cross-compile:
OUTFILE=openldap_exporter-linux-amd64 GOOS=linux GOARCH=amd64 $(MAKE) compile
OUTFILE=openldap_exporter-linux-nocgo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(MAKE) compile
OUTFILE=openldap_exporter-osx-amd64 GOOS=darwin GOARCH=amd64 $(MAKE) compile
OUTFILE=openldap_exporter-osx-arm64 GOOS=darwin GOARCH=arm64 $(MAKE) compile
(cd target && find . -name '*.gz' -exec sha256sum {} \;) > target/verify.sha256
.PHONY: vendor
vendor:
go mod tidy -compat=1.20
go mod vendor