2019-11-24 11:32:59 +00:00
|
|
|
PKG := github.com/guggero/chantools
|
2022-07-18 07:24:17 +00:00
|
|
|
TOOLS_DIR := tools
|
2019-11-09 14:41:31 +00:00
|
|
|
|
|
|
|
GOTEST := GO111MODULE=on go test -v
|
|
|
|
|
|
|
|
GO_BIN := ${GOPATH}/bin
|
|
|
|
|
|
|
|
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
|
|
|
|
GOLIST := go list $(PKG)/... | grep -v '/vendor/'
|
|
|
|
|
2022-07-18 07:24:17 +00:00
|
|
|
GOIMPORTS_BIN := $(GO_BIN)/gosimports
|
|
|
|
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
|
2019-11-09 14:41:31 +00:00
|
|
|
|
2022-07-18 07:24:17 +00:00
|
|
|
GOBUILD := go build -v
|
|
|
|
GOINSTALL := go install -v
|
|
|
|
GOTEST := go test -v
|
2019-11-09 14:41:31 +00:00
|
|
|
XARGS := xargs -L 1
|
|
|
|
|
2020-06-11 07:59:42 +00:00
|
|
|
VERSION_TAG = $(shell git describe --tags)
|
|
|
|
VERSION_CHECK = @$(call print, "Building master with date version tag")
|
|
|
|
|
2020-10-29 19:35:17 +00:00
|
|
|
BUILD_SYSTEM = darwin-amd64 \
|
2020-06-11 07:59:42 +00:00
|
|
|
linux-386 \
|
|
|
|
linux-amd64 \
|
|
|
|
linux-armv6 \
|
|
|
|
linux-armv7 \
|
|
|
|
linux-arm64 \
|
|
|
|
windows-386 \
|
|
|
|
windows-amd64 \
|
|
|
|
windows-arm
|
|
|
|
|
|
|
|
# By default we will build all systems. But with the 'sys' tag, a specific
|
|
|
|
# system can be specified. This is useful to release for a subset of
|
|
|
|
# systems/architectures.
|
|
|
|
ifneq ($(sys),)
|
|
|
|
BUILD_SYSTEM = $(sys)
|
|
|
|
endif
|
|
|
|
|
2022-07-18 07:24:17 +00:00
|
|
|
DOCKER_TOOLS = docker run -v $$(pwd):/build chantools-tools
|
|
|
|
|
2019-11-09 14:41:31 +00:00
|
|
|
TEST_FLAGS = -test.timeout=20m
|
|
|
|
|
|
|
|
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS)
|
2020-06-11 07:59:42 +00:00
|
|
|
LDFLAGS := -X main.Commit=$(shell git describe --tags)
|
|
|
|
RELEASE_LDFLAGS := -s -w -buildid= $(LDFLAGS)
|
|
|
|
|
|
|
|
GREEN := "\\033[0;32m"
|
|
|
|
NC := "\\033[0m"
|
|
|
|
define print
|
|
|
|
echo $(GREEN)$1$(NC)
|
|
|
|
endef
|
2019-11-09 14:41:31 +00:00
|
|
|
|
|
|
|
default: build
|
|
|
|
|
2022-07-18 07:24:17 +00:00
|
|
|
$(GOIMPORTS_BIN):
|
|
|
|
@$(call print, "Installing goimports.")
|
|
|
|
cd $(TOOLS_DIR); go install -trimpath $(GOIMPORTS_PKG)
|
2019-11-09 14:41:31 +00:00
|
|
|
|
|
|
|
unit:
|
|
|
|
@$(call print, "Running unit tests.")
|
|
|
|
$(UNIT)
|
|
|
|
|
|
|
|
build:
|
2019-11-24 11:32:59 +00:00
|
|
|
@$(call print, "Building chantools.")
|
2020-06-11 07:59:42 +00:00
|
|
|
$(GOBUILD) -ldflags "$(LDFLAGS)" ./...
|
2019-11-09 14:41:31 +00:00
|
|
|
|
|
|
|
install:
|
2019-11-24 11:32:59 +00:00
|
|
|
@$(call print, "Installing chantools.")
|
2020-06-11 07:59:42 +00:00
|
|
|
$(GOINSTALL) -ldflags "$(LDFLAGS)" ./...
|
|
|
|
|
|
|
|
release:
|
|
|
|
@$(call print, "Creating release of chantools.")
|
|
|
|
rm -rf chantools-v*
|
|
|
|
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_LDFLAGS)"
|
2019-11-09 14:41:31 +00:00
|
|
|
|
2022-07-18 07:24:17 +00:00
|
|
|
docker-tools:
|
|
|
|
@$(call print, "Building tools docker image.")
|
|
|
|
docker build -q -t chantools-tools $(TOOLS_DIR)
|
|
|
|
|
|
|
|
fmt: $(GOIMPORTS_BIN)
|
|
|
|
@$(call print, "Fixing imports.")
|
|
|
|
gosimports -w $(GOFILES_NOVENDOR)
|
2019-11-09 14:41:31 +00:00
|
|
|
@$(call print, "Formatting source.")
|
|
|
|
gofmt -l -w -s $(GOFILES_NOVENDOR)
|
|
|
|
|
2022-07-18 07:24:17 +00:00
|
|
|
lint: docker-tools
|
2019-11-09 14:41:31 +00:00
|
|
|
@$(call print, "Linting source.")
|
2022-07-18 07:24:17 +00:00
|
|
|
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
|
2020-12-27 00:10:02 +00:00
|
|
|
|
|
|
|
docs: install
|
|
|
|
@$(call print, "Rendering docs.")
|
|
|
|
chantools doc
|