GitHub

@@ -1,5 +1,6 @@

11

.PHONY: generate build test vet cover release docs docs-clean clean format lint platformtest

2-

.DEFAULT_GOAL := build

2+

.PHONY: release bins-all release-noarch

3+

.DEFAULT_GOAL := zrepl-bin

3445

ARTIFACTDIR := artifacts

56

@@ -12,68 +13,141 @@ ifndef _ZREPL_VERSION

1213

$(error cannot infer variable ZREPL_VERSION using git and variable is not overriden by make invocation)

1314

endif

1415

endif

16+1517

GO := go

18+

GOOS ?= $(shell bash -c 'source <($(GO) env) && echo "$$GOOS"')

19+

GOARCH ?= $(shell bash -c 'source <($(GO) env) && echo "$$GOARCH"')

20+

GOHOSTOS ?= $(shell bash -c 'source <($(GO) env) && echo "$$GOHOSTOS"')

21+

GOHOSTARCH ?= $(shell bash -c 'source <($(GO) env) && echo "$$GOHOSTARCH"')

1622

GO_ENV_VARS := GO111MODULE=on

1723

GO_LDFLAGS := "-X github.com/zrepl/zrepl/version.zreplVersion=$(_ZREPL_VERSION)"

1824

GO_MOD_READONLY := -mod=readonly

1925

GO_BUILDFLAGS := $(GO_MOD_READONLY)

20-

GO_BUILD := $(GO_ENV_VARS) $(GO) build $(GO_BUILDFLAGS) -v -ldflags $(GO_LDFLAGS)

26+

GO_BUILD := $(GO_ENV_VARS) $(GO) build $(GO_BUILDFLAGS) -ldflags $(GO_LDFLAGS)

27+

GOLANGCI_LINT := golangci-lint

28+29+

.PHONY: printvars

30+

printvars:

31+

@echo GOOS=$(GOOS)

32+

@echo GOARCH=$(GOARCH)

33+34+35+

##################### PRODUCING A RELEASE #############

36+

.PHONY: release wrapup-and-checksum check-git-clean sign clean

37+38+

release: clean

39+

# no cross-platform support for target test

40+

$(MAKE) test

41+

$(MAKE) bins-all

42+

$(MAKE) noarch

43+

$(MAKE) wrapup-and-checksum

44+

$(MAKE) check-git-clean

45+

ifeq (SIGN, 1)

46+

$(make) sign

47+

endif

48+

@echo "ZREPL RELEASE ARTIFACTS AVAILABLE IN artifacts/release"

214922-

# keep in sync with vet target

23-

RELEASE_BINS := $(ARTIFACTDIR)/zrepl-freebsd-amd64

24-

RELEASE_BINS += $(ARTIFACTDIR)/zrepl-linux-amd64

25-

RELEASE_BINS += $(ARTIFACTDIR)/zrepl-linux-arm64

26-

RELEASE_BINS += $(ARTIFACTDIR)/zrepl-darwin-amd64

50+

# expects `release` target to have run before

51+

NOARCH_TARBALL := $(ARTIFACTDIR)/zrepl-noarch.tar

52+

wrapup-and-checksum:

53+

rm -f $(NOARCH_TARBALL)

54+

tar --mtime='1970-01-01' --sort=name \

55+

--transform 's/$(ARTIFACTDIR)/zrepl-$(_ZREPL_VERSION)-noarch/' \

56+

--transform 's#dist#zrepl-$(_ZREPL_VERSION)-noarch/dist#' \

57+

--transform 's#config/samples#zrepl-$(_ZREPL_VERSION)-noarch/config#' \

58+

-acf $(NOARCH_TARBALL) \

59+

$(ARTIFACTDIR)/docs/html \

60+

$(ARTIFACTDIR)/bash_completion \

61+

$(ARTIFACTDIR)/go_env.txt \

62+

dist \

63+

config/samples

64+

rm -rf "$(ARTIFACTDIR)/release"

65+

mkdir -p "$(ARTIFACTDIR)/release"

66+

cp -l $(ARTIFACTDIR)/zrepl-* \

67+

$(ARTIFACTDIR)/platformtest-* \

68+

"$(ARTIFACTDIR)/release"

69+

cd "$(ARTIFACTDIR)/release" && sha512sum $$(ls | sort) > sha512sum.txt

277028-

RELEASE_NOARCH := $(ARTIFACTDIR)/zrepl-noarch.tar

29-

THIS_PLATFORM_RELEASE_BIN := $(shell bash -c 'source <($(GO) env) && echo "zrepl-$${GOOS}-$${GOARCH}"' )

71+

check-git-clean:

72+

@# note that we use ZREPL_VERSION and not _ZREPL_VERSION because we want to detect the override

73+

@if git describe --always --dirty 2>/dev/null | grep dirty >/dev/null; then \

74+

echo '[INFO] either git reports checkout is dirty or git is not installed or this is not a git checkout'; \

75+

if [ "$(ZREPL_VERSION)" = "" ]; then \

76+

echo '[WARN] git checkout is dirty and make variable ZREPL_VERSION was not used to override'; \

77+

git status; \

78+

echo "git diff:"; \

79+

git diff | cat; \

80+

exit 1; \

81+

fi; \

82+

fi;

308331-

generate: #not part of the build, must do that manually

32-

protoc -I=replication/logic/pdu --go_out=plugins=grpc:replication/logic/pdu replication/logic/pdu/pdu.proto

33-

$(GO_ENV_VARS) $(GO) generate $(GO_BUILDFLAGS) -x ./...

84+

sign:

85+

gpg -u "89BC 5D89 C845 568B F578 B306 CDBD 8EC8 E27C A5FC" \

86+

--armor \

87+

--detach-sign $(ARTIFACTDIR)/release/sha512sum.txt

348835-

format:

36-

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')

89+

clean: docs-clean

90+

rm -rf "$(ARTIFACTDIR)"

379138-

lint:

39-

golangci-lint run ./...

92+

##################### BINARIES #####################

93+

.PHONY: bins-all lint test vet zrepl-bin platformtest-bin

409441-

build:

42-

$(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl"

95+

BINS_ALL_TARGETS := zrepl-bin platformtest-bin vet lint

96+

bins-all:

97+

$(MAKE) $(BINS_ALL_TARGETS) GOOS=freebsd GOARCH=amd64

98+

$(MAKE) $(BINS_ALL_TARGETS) GOOS=freebsd GOARCH=386

99+

$(MAKE) $(BINS_ALL_TARGETS) GOOS=linux GOARCH=amd64

100+

$(MAKE) $(BINS_ALL_TARGETS) GOOS=linux GOARCH=arm64

101+

$(MAKE) $(BINS_ALL_TARGETS) GOOS=linux GOARCH=386

102+

$(MAKE) $(BINS_ALL_TARGETS) GOOS=darwin GOARCH=amd64

43103104+

lint:

105+

$(GO_ENV_VARS) $(GOLANGCI_LINT) run ./...

44106

test:

45107

$(GO_ENV_VARS) $(GO) test $(GO_BUILDFLAGS) ./...

46-

# TODO compile the tests for each supported platform

47-

# but `go test -c ./...` is not supported

48-49108

vet:

50109

$(GO_ENV_VARS) $(GO) vet $(GO_BUILDFLAGS) ./...

51-

# for each supported platform to cover conditional compilation

52-

# (keep in sync with RELEASE_BINS)

53-

GOOS=freebsd GOARCH=amd64 $(GO_ENV_VARS) $(GO) vet $(GO_BUILDFLAGS) ./...

54-

GOOS=linux GOARCH=amd64 $(GO_ENV_VARS) $(GO) vet $(GO_BUILDFLAGS) ./...

55-

GOOS=linux GOARCH=arm64 $(GO_ENV_VARS) $(GO) vet $(GO_BUILDFLAGS) ./...

56-

GOOS=darwin GOARCH=amd64 $(GO_ENV_VARS) $(GO) vet $(GO_BUILDFLAGS) ./...

110+111+

zrepl-bin:

112+

$(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl-$(GOOS)-$(GOARCH)"

113+114+

platformtest-bin:

115+

$(GO_BUILD) -o "$(ARTIFACTDIR)/platformtest-$(GOOS)-$(GOARCH)" ./platformtest/harness

116+117+

##################### DEV TARGETS #####################

118+

# not part of the build, must do that manually

119+

.PHONY: generate format platformtest

120+121+

generate:

122+

protoc -I=replication/logic/pdu --go_out=plugins=grpc:replication/logic/pdu replication/logic/pdu/pdu.proto

123+

$(GO_ENV_VARS) $(GO) generate $(GO_BUILDFLAGS) -x ./...

124+125+

format:

126+

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')

5712758128

ZREPL_PLATFORMTEST_POOLNAME := zreplplatformtest

59129

ZREPL_PLATFORMTEST_IMAGEPATH := /tmp/zreplplatformtest.pool.img

60-

$(ARTIFACTDIR)/zrepl_platformtest:

61-

$(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl_platformtest" ./platformtest/harness

62-

platformtest: $(ARTIFACTDIR)/zrepl_platformtest

63-

"$(ARTIFACTDIR)/zrepl_platformtest" -poolname "$(ZREPL_PLATFORMTEST_POOLNAME)" -imagepath "$(ZREPL_PLATFORMTEST_IMAGEPATH)"

130+

platformtest: # do not track dependency on platformtest-bin to allow build of platformtest outside of test VM

131+

"$(ARTIFACTDIR)/platformtest-$(GOOS)-$(GOARCH)" -poolname "$(ZREPL_PLATFORMTEST_POOLNAME)" -imagepath "$(ZREPL_PLATFORMTEST_IMAGEPATH)"

132+133+

##################### NOARCH #####################

134+

.PHONY: noarch $(ARTIFACTDIR)/bash_completion $(ARTIFACTDIR)/go_env.txt docs docs-clean

135+6413665137

$(ARTIFACTDIR):

66138

mkdir -p "$@"

67-68139

$(ARTIFACTDIR)/docs: $(ARTIFACTDIR)

69140

mkdir -p "$@"

7014171-

$(ARTIFACTDIR)/bash_completion: $(RELEASE_BINS)

72-

artifacts/$(THIS_PLATFORM_RELEASE_BIN) bashcomp "$@"

142+

noarch: $(ARTIFACTDIR)/bash_completion $(ARTIFACTDIR)/go_env.txt docs

143+

# pass

7314474-

.PHONY: $(ARTIFACTDIR)/go_version.txt

75-

$(ARTIFACTDIR)/go_version.txt:

76-

$(GO_ENV_VARS) $(GO) version > $@

145+

$(ARTIFACTDIR)/bash_completion:

146+

$(MAKE) zrepl-bin GOOS=$(GOHOSTOS) GOARCH=$(GOHOSTARCH)

147+

artifacts/zrepl-$(GOHOSTOS)-$(GOHOSTARCH) bashcomp "$@"

148+149+

$(ARTIFACTDIR)/go_env.txt:

150+

$(GO_ENV_VARS) $(GO) env > $@

7715178152

docs: $(ARTIFACTDIR)/docs

79153

make -C docs \

@@ -84,41 +158,3 @@ docs-clean:

84158

make -C docs \

85159

clean \

86160

BUILDDIR=../artifacts/docs

87-88-

.PHONY: $(RELEASE_BINS)

89-

# TODO: two wildcards possible

90-

$(RELEASE_BINS): $(ARTIFACTDIR)/zrepl-%: generate $(ARTIFACTDIR) vet test lint

91-

STEM=$*; GOOS="$${STEM%%-*}"; GOARCH="$${STEM##*-}"; export GOOS GOARCH; \

92-

$(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl-$$GOOS-$$GOARCH"

93-94-

$(RELEASE_NOARCH): docs $(ARTIFACTDIR)/bash_completion $(ARTIFACTDIR)/go_version.txt

95-

tar --mtime='1970-01-01' --sort=name \

96-

--transform 's/$(ARTIFACTDIR)/zrepl-$(_ZREPL_VERSION)-noarch/' \

97-

--transform 's#dist#zrepl-$(_ZREPL_VERSION)-noarch/dist#' \

98-

--transform 's#config/samples#zrepl-$(_ZREPL_VERSION)-noarch/config#' \

99-

-acf $@ \

100-

$(ARTIFACTDIR)/docs/html \

101-

$(ARTIFACTDIR)/bash_completion \

102-

$(ARTIFACTDIR)/go_version.txt \

103-

dist \

104-

config/samples

105-106-

release: $(RELEASE_BINS) $(RELEASE_NOARCH)

107-

rm -rf "$(ARTIFACTDIR)/release"

108-

mkdir -p "$(ARTIFACTDIR)/release"

109-

cp $^ "$(ARTIFACTDIR)/release"

110-

cd "$(ARTIFACTDIR)/release" && sha512sum $$(ls | sort) > sha512sum.txt

111-

@# note that we use ZREPL_VERSION and not _ZREPL_VERSION because we want to detect the override

112-

@if git describe --always --dirty 2>/dev/null | grep dirty >/dev/null; then \

113-

echo '[INFO] either git reports checkout is dirty or git is not installed or this is not a git checkout'; \

114-

if [ "$(ZREPL_VERSION)" = "" ]; then \

115-

echo '[WARN] git checkout is dirty and make variable ZREPL_VERSION was not used to override'; \

116-

git status; \

117-

echo "git diff:"; \

118-

git diff | cat; \

119-

exit 1; \

120-

fi; \

121-

fi;

122-123-

clean: docs-clean

124-

rm -rf "$(ARTIFACTDIR)"

Read the original on github.com ↗