58 lines
1.6 KiB
Makefile
58 lines
1.6 KiB
Makefile
BINNAME = go-monitoring
|
|
BINDIR = $(CURDIR)/bin
|
|
TARGETS = linux/amd64 linux/386 linux/arm linux/arm64
|
|
|
|
SRC := $(shell find . -type f -name '*.go' -print) go.mod go.sum
|
|
GOHOSTOS = $(shell go env GOHOSTOS)
|
|
GOHOSTARCH ?= $(shell go env GOHOSTARCH)
|
|
|
|
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
|
|
GIT_COMMIT = $(shell git rev-parse --short HEAD 2>/dev/null)
|
|
GIT_STATUS = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
|
|
|
|
ifneq ($(VERSION),)
|
|
BINARY_VERSION = $(VERSION)
|
|
endif
|
|
BINARY_VERSION ?= $(GIT_TAG)
|
|
|
|
LDFLAGS += -w -s
|
|
ifneq ($(BINARY_VERSION),)
|
|
LDFLAGS += -X nocternity.net/go-monitoring/pkg/version.version=${BINARY_VERSION}
|
|
endif
|
|
LDFLAGS += -X nocternity.net/go-monitoring/pkg/version.commit=${GIT_COMMIT}
|
|
LDFLAGS += -X nocternity.net/go-monitoring/pkg/version.status=${GIT_STATUS}
|
|
|
|
|
|
.PHONY: all
|
|
all: build
|
|
|
|
.PHONY: build
|
|
build: GOOS=$(GOHOSTOS)
|
|
build: GOARCH=$(GOHOSTARCH)
|
|
build: build-target symlink
|
|
|
|
.PHONY: symlink
|
|
symlink:
|
|
@ln -sf $(BINDIR)/$(GOOS)/$(GOARCH)/$(BINNAME) $(BINDIR)/$(BINNAME)
|
|
|
|
.PHONY: build-target
|
|
build-target: LDFLAGS += -X nocternity.net/go-monitoring/pkg/version.target=${GOOS}/${GOARCH}
|
|
build-target: $(BINDIR)/$(GOOS)/$(GOARCH)/$(BINNAME)
|
|
|
|
$(BINDIR)/$(GOOS)/$(GOARCH)/$(BINNAME): $(SRC)
|
|
@mkdir -p $(BINDIR)/$(GOOS)/$(GOARCH)
|
|
@CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BINDIR)/$(GOOS)/$(GOARCH)/$(BINNAME) .
|
|
|
|
.PHONY: test
|
|
test: build
|
|
@go test -v ./...
|
|
|
|
.PHONY: build-cross
|
|
build-cross:
|
|
@for target in $(TARGETS); do \
|
|
$(MAKE) build-target GOOS=`echo $$target | cut -d / -f 1` GOARCH=`echo $$target | cut -d / -f 2`; \
|
|
done
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
@rm -rf $(BINDIR)
|