optimize build target
This commit is contained in:
parent
5aeb0808da
commit
c784c8f7c7
1 changed files with 29 additions and 15 deletions
44
Makefile
44
Makefile
|
@ -1,7 +1,7 @@
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
.DEFAULT_GOAL := help
|
.DEFAULT_GOAL := help
|
||||||
.PHONY: generate
|
.PHONY: generate go-tools
|
||||||
|
|
||||||
version := $(shell git describe --tags --always)
|
version := $(shell git describe --tags --always)
|
||||||
revision := $(shell git rev-parse HEAD)
|
revision := $(shell git rev-parse HEAD)
|
||||||
|
@ -11,6 +11,9 @@ builddate := $(shell date '+%FT%T_%Z')
|
||||||
|
|
||||||
versionPkgPrefix := mystrom-exporter/pkg/version
|
versionPkgPrefix := mystrom-exporter/pkg/version
|
||||||
|
|
||||||
|
BINDIR := $(CURDIR)/output
|
||||||
|
GO ?= go
|
||||||
|
GOPATH ?= $(shell $(GO) env GOPATH)
|
||||||
LDFLAGS := -w -s \
|
LDFLAGS := -w -s \
|
||||||
-X $(versionPkgPrefix).Version=${version} \
|
-X $(versionPkgPrefix).Version=${version} \
|
||||||
-X $(versionPkgPrefix).Revision=${revision} \
|
-X $(versionPkgPrefix).Revision=${revision} \
|
||||||
|
@ -18,25 +21,36 @@ LDFLAGS := -w -s \
|
||||||
-X $(versionPkgPrefix).BuildUser=${builduser} \
|
-X $(versionPkgPrefix).BuildUser=${builduser} \
|
||||||
-X $(versionPkgPrefix).BuildDate=${builddate}
|
-X $(versionPkgPrefix).BuildDate=${builddate}
|
||||||
GOFLAGS := -v
|
GOFLAGS := -v
|
||||||
|
GOX_FLAGS := -mod=vendor
|
||||||
|
GO_BUILD_FLAGS := -v
|
||||||
|
export GO111MODULE := on
|
||||||
|
|
||||||
linux: generate ## builds the linux version of the exporter
|
build: go-tools generate ## builds the all platform binaries of the exporter
|
||||||
GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -ldflags '$(LDFLAGS)'
|
$(GOPATH)/bin/gox \
|
||||||
mac: generate ## builds the macos version of the exporter
|
-os="darwin linux" \
|
||||||
GOOS=darwin GOARCH=amd64 go build $(GOFLAGS) -ldflags '$(LDFLAGS)'
|
-arch="amd64 arm arm64" \
|
||||||
mac-arm: generate ## builds the macos (m1) version of the exporter
|
-osarch="!darwin/arm" \
|
||||||
GOOS=darwin GOARCH=arm64 go build $(GOFLAGS) -ldflags '$(LDFLAGS)'
|
-output "${BINDIR}/{{.Dir}}-{{.OS}}-{{.Arch}}" \
|
||||||
arm64: generate
|
-gcflags "$(GO_BUILD_FLAGS)" \
|
||||||
GOOS=linux GOARCH=arm64 go build $(GOFLAGS) -ldflags '$(LDFLAGS)'
|
-ldflags '$(LDFLAGS)' \
|
||||||
arm: generate
|
-tags '$(TAGS)' \
|
||||||
GOOS=linux GOARCH=arm go build $(GOFLAGS) -ldflags '$(LDFLAGS)'
|
./...
|
||||||
|
|
||||||
|
run:
|
||||||
|
${BINDIR}/mystrom-exporter-$(shell $(GO) env GOOS)-$(shell $(GO) env GOARCH)
|
||||||
|
|
||||||
|
|
||||||
|
generate: go-tools
|
||||||
|
$(GO) generate ./...
|
||||||
|
|
||||||
|
go-tools: $(GOPATH)/bin/stringer $(GOPATH)/bin/gox
|
||||||
|
|
||||||
# -- see more info on https://pkg.go.dev/golang.org/x/tools/cmd/stringer
|
# -- see more info on https://pkg.go.dev/golang.org/x/tools/cmd/stringer
|
||||||
generate: $(GOPATH)/bin/stringer
|
|
||||||
go generate ./...
|
|
||||||
|
|
||||||
$(GOPATH)/bin/stringer:
|
$(GOPATH)/bin/stringer:
|
||||||
go install golang.org/x/tools/cmd/stringer@latest
|
$(GO) install golang.org/x/tools/cmd/stringer@latest
|
||||||
|
|
||||||
|
$(GOPATH)/bin/gox:
|
||||||
|
$(GO) install github.com/mitchellh/gox@latest
|
||||||
# --
|
# --
|
||||||
help:
|
help:
|
||||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
Loading…
Reference in a new issue