2019-09-03 14:45:18 +02:00
|
|
|
.PHONY: generate build test vet cover release docs docs-clean clean format lint
|
2017-11-12 21:41:34 +01:00
|
|
|
.DEFAULT_GOAL := build
|
2017-09-30 16:40:39 +02:00
|
|
|
|
|
|
|
ARTIFACTDIR := artifacts
|
|
|
|
|
2018-10-19 17:46:30 +02:00
|
|
|
ifdef ZREPL_VERSION
|
|
|
|
_ZREPL_VERSION := $(ZREPL_VERSION)
|
|
|
|
endif
|
|
|
|
ifndef _ZREPL_VERSION
|
2019-01-05 21:53:59 +01:00
|
|
|
_ZREPL_VERSION := $(shell git describe --always --dirty 2>/dev/null || echo "ZREPL_BUILD_INVALID_VERSION" )
|
2018-10-19 17:46:30 +02:00
|
|
|
ifeq ($(_ZREPL_VERSION),ZREPL_BUILD_INVALID_VERSION) # can't use .SHELLSTATUS because Debian Stretch is still on gmake 4.1
|
2017-11-18 20:34:28 +01:00
|
|
|
$(error cannot infer variable ZREPL_VERSION using git and variable is not overriden by make invocation)
|
|
|
|
endif
|
|
|
|
endif
|
2019-09-03 14:45:18 +02:00
|
|
|
GO := go
|
2018-10-19 17:46:30 +02:00
|
|
|
GO_LDFLAGS := "-X github.com/zrepl/zrepl/version.zreplVersion=$(_ZREPL_VERSION)"
|
2019-09-03 14:45:18 +02:00
|
|
|
GO_MOD_READONLY := -mod=readonly
|
|
|
|
GO_BUILDFLAGS := $(GO_MOD_READONLY)
|
|
|
|
GO_BUILD := GO111MODULE=on $(GO) build $(GO_BUILDFLAGS) -v -ldflags $(GO_LDFLAGS)
|
2017-11-18 20:34:28 +01:00
|
|
|
|
2019-06-23 12:10:52 +02:00
|
|
|
# keep in sync with vet target
|
2018-10-13 16:57:25 +02:00
|
|
|
RELEASE_BINS := $(ARTIFACTDIR)/zrepl-freebsd-amd64
|
|
|
|
RELEASE_BINS += $(ARTIFACTDIR)/zrepl-linux-amd64
|
2019-06-23 12:10:52 +02:00
|
|
|
RELEASE_BINS += $(ARTIFACTDIR)/zrepl-linux-arm64
|
2018-10-13 16:57:25 +02:00
|
|
|
RELEASE_BINS += $(ARTIFACTDIR)/zrepl-darwin-amd64
|
|
|
|
|
2018-02-18 16:46:54 +01:00
|
|
|
RELEASE_NOARCH := $(ARTIFACTDIR)/zrepl-noarch.tar
|
2019-09-03 14:45:18 +02:00
|
|
|
THIS_PLATFORM_RELEASE_BIN := $(shell bash -c 'source <($(GO) env) && echo "zrepl-$${GOOS}-$${GOARCH}"' )
|
2017-11-19 12:32:25 +01:00
|
|
|
|
2017-11-12 16:15:12 +01:00
|
|
|
generate: #not part of the build, must do that manually
|
2019-02-22 11:40:27 +01:00
|
|
|
protoc -I=replication/logic/pdu --go_out=plugins=grpc:replication/logic/pdu replication/logic/pdu/pdu.proto
|
2019-09-03 14:45:18 +02:00
|
|
|
$(GO) generate $(GO_BUILDFLAGS) -x ./...
|
2017-09-30 16:40:39 +02:00
|
|
|
|
2019-03-22 19:41:12 +01:00
|
|
|
format:
|
2019-03-22 20:45:27 +01:00
|
|
|
goimports -srcdir . -local 'github.com/zrepl/zrepl' -w $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -name '*.pb.go' -not -name '*_enumer.go')
|
|
|
|
|
|
|
|
lint:
|
|
|
|
golangci-lint run ./...
|
2019-03-22 19:41:12 +01:00
|
|
|
|
2017-11-12 16:15:12 +01:00
|
|
|
build:
|
2017-11-19 12:32:25 +01:00
|
|
|
$(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl"
|
2017-11-12 16:15:12 +01:00
|
|
|
|
2017-09-30 16:40:39 +02:00
|
|
|
test:
|
2019-09-03 14:45:18 +02:00
|
|
|
$(GO) test $(GO_BUILDFLAGS) ./...
|
2019-06-23 12:10:52 +02:00
|
|
|
# TODO compile the tests for each supported platform
|
|
|
|
# but `go test -c ./...` is not supported
|
2017-09-30 16:40:39 +02:00
|
|
|
|
|
|
|
vet:
|
2019-09-03 14:45:18 +02:00
|
|
|
$(GO) vet $(GO_BUILDFLAGS) ./...
|
2018-12-11 22:01:50 +01:00
|
|
|
# for each supported platform to cover conditional compilation
|
2019-06-23 12:10:52 +02:00
|
|
|
# (keep in sync with RELEASE_BINS)
|
2019-09-03 14:45:18 +02:00
|
|
|
GOOS=freebsd GOARCH=amd64 $(GO) vet $(GO_BUILDFLAGS) ./...
|
|
|
|
GOOS=linux GOARCH=amd64 $(GO) vet $(GO_BUILDFLAGS) ./...
|
|
|
|
GOOS=linux GOARCH=arm64 $(GO) vet $(GO_BUILDFLAGS) ./...
|
|
|
|
GOOS=darwin GOARCH=amd64 $(GO) vet $(GO_BUILDFLAGS) ./...
|
2017-09-30 16:40:39 +02:00
|
|
|
|
2017-11-18 16:20:14 +01:00
|
|
|
$(ARTIFACTDIR):
|
|
|
|
mkdir -p "$@"
|
2017-09-30 16:40:39 +02:00
|
|
|
|
2017-11-18 16:21:53 +01:00
|
|
|
$(ARTIFACTDIR)/docs: $(ARTIFACTDIR)
|
|
|
|
mkdir -p "$@"
|
|
|
|
|
2018-02-18 16:46:54 +01:00
|
|
|
$(ARTIFACTDIR)/bash_completion: $(RELEASE_BINS)
|
2017-12-27 13:48:28 +01:00
|
|
|
artifacts/$(THIS_PLATFORM_RELEASE_BIN) bashcomp "$@"
|
|
|
|
|
2019-09-03 14:45:18 +02:00
|
|
|
.PHONY: $(ARTIFACTDIR)/go_version.txt
|
2018-02-18 16:46:54 +01:00
|
|
|
$(ARTIFACTDIR)/go_version.txt:
|
2019-09-03 14:45:18 +02:00
|
|
|
$(GO) version > $@
|
2018-02-18 16:46:54 +01:00
|
|
|
|
2017-11-18 16:21:53 +01:00
|
|
|
docs: $(ARTIFACTDIR)/docs
|
|
|
|
make -C docs \
|
|
|
|
html \
|
|
|
|
BUILDDIR=../artifacts/docs \
|
|
|
|
|
|
|
|
docs-clean:
|
|
|
|
make -C docs \
|
|
|
|
clean \
|
|
|
|
BUILDDIR=../artifacts/docs
|
|
|
|
|
2018-02-18 16:46:54 +01:00
|
|
|
.PHONY: $(RELEASE_BINS)
|
|
|
|
# TODO: two wildcards possible
|
2019-06-23 12:10:52 +02:00
|
|
|
$(RELEASE_BINS): $(ARTIFACTDIR)/zrepl-%: generate $(ARTIFACTDIR) vet test lint
|
|
|
|
STEM=$*; GOOS="$${STEM%%-*}"; GOARCH="$${STEM##*-}"; export GOOS GOARCH; \
|
|
|
|
$(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl-$$GOOS-$$GOARCH"
|
2018-02-18 16:46:54 +01:00
|
|
|
|
|
|
|
$(RELEASE_NOARCH): docs $(ARTIFACTDIR)/bash_completion $(ARTIFACTDIR)/go_version.txt
|
|
|
|
tar --mtime='1970-01-01' --sort=name \
|
2018-10-19 17:46:30 +02:00
|
|
|
--transform 's/$(ARTIFACTDIR)/zrepl-$(_ZREPL_VERSION)-noarch/' \
|
2018-02-18 16:46:54 +01:00
|
|
|
-acf $@ \
|
|
|
|
$(ARTIFACTDIR)/docs/html \
|
|
|
|
$(ARTIFACTDIR)/bash_completion \
|
|
|
|
$(ARTIFACTDIR)/go_version.txt
|
|
|
|
|
|
|
|
release: $(RELEASE_BINS) $(RELEASE_NOARCH)
|
|
|
|
rm -rf "$(ARTIFACTDIR)/release"
|
|
|
|
mkdir -p "$(ARTIFACTDIR)/release"
|
|
|
|
cp $^ "$(ARTIFACTDIR)/release"
|
|
|
|
cd "$(ARTIFACTDIR)/release" && sha512sum $$(ls | sort) > sha512sum.txt
|
2018-10-19 17:46:30 +02:00
|
|
|
@# note that we use ZREPL_VERSION and not _ZREPL_VERSION because we want to detect the override
|
2019-01-05 21:53:59 +01:00
|
|
|
@if git describe --always --dirty 2>/dev/null | grep dirty >/dev/null; then \
|
2018-12-01 12:52:41 +01:00
|
|
|
echo '[INFO] either git reports checkout is dirty or git is not installed or this is not a git checkout'; \
|
|
|
|
if [ "$(ZREPL_VERSION)" = "" ]; then \
|
|
|
|
echo '[WARN] git checkout is dirty and make variable ZREPL_VERSION was not used to override'; \
|
2019-09-03 14:45:18 +02:00
|
|
|
git status; \
|
|
|
|
echo "git diff:"; \
|
|
|
|
git diff | cat; \
|
2018-10-19 17:46:30 +02:00
|
|
|
exit 1; \
|
|
|
|
fi; \
|
|
|
|
fi;
|
2017-11-18 20:34:28 +01:00
|
|
|
|
2017-11-18 16:21:53 +01:00
|
|
|
clean: docs-clean
|
2017-09-30 16:40:39 +02:00
|
|
|
rm -rf "$(ARTIFACTDIR)"
|