go-onerng/Makefile
Dave Henderson d9e2265891
Adding makefile and CI
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
2020-11-01 14:18:36 -05:00

56 lines
1.4 KiB
Makefile

.DEFAULT_GOAL = build
extension = $(patsubst windows,.exe,$(filter windows,$(1)))
GO := go
BIN_NAME := onerng
PREFIX := .
COMMIT ?= `git rev-parse --short HEAD 2>/dev/null`
VERSION ?= `git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1) 2>/dev/null | sed 's/v\(.*\)/\1/'`
COMMIT_FLAG := -X `go list ./version`.GitCommit=$(COMMIT)
VERSION_FLAG := -X `go list ./version`.Version=$(VERSION)
GOOS ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\1/')
GOARCH ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\2/')
ifeq ("$(TARGETVARIANT)","")
ifneq ("$(GOARM)","")
TARGETVARIANT := v$(GOARM)
endif
else
ifeq ("$(GOARM)","")
GOARM ?= $(subst v,,$(TARGETVARIANT))
endif
endif
clean:
rm -Rf $(PREFIX)/bin/*
$(PREFIX)/bin/$(BIN_NAME)_%: $(shell find $(PREFIX) -type f -name '*.go')
GOOS=$(shell echo $* | cut -f1 -d-) GOARCH=$(shell echo $* | cut -f2 -d- | cut -f1 -d.) CGO_ENABLED=0 \
$(GO) build \
-ldflags "-w -s $(COMMIT_FLAG) $(VERSION_FLAG)" \
-o $@ \
./cmd/$(BIN_NAME)
$(PREFIX)/bin/$(BIN_NAME)$(call extension,$(GOOS)): $(PREFIX)/bin/$(BIN_NAME)_$(GOOS)-$(GOARCH)$(call extension,$(GOOS))
cp $< $@
build: $(PREFIX)/bin/$(BIN_NAME)$(call extension,$(GOOS))
ifeq ($(OS),Windows_NT)
test:
$(GO) test -coverprofile=c.out ./...
else
test:
$(GO) test -race -coverprofile=c.out ./...
endif
lint:
@golangci-lint run --max-same-issues=0 --sort-results
.PHONY: clean test build lint
.DELETE_ON_ERROR:
.SECONDARY: