golang.mk 1.65 KB
Newer Older
1
# golang utilities
Steven Allen's avatar
Steven Allen committed
2
GO_MIN_VERSION = 1.11
3
export GO111MODULE=on
4

5

6
# pre-definitions
7
GOCC ?= go
8
GOTAGS ?=
Steven Allen's avatar
Steven Allen committed
9
unexport GOFLAGS
10 11 12
GOFLAGS ?=
GOTFLAGS ?=

Jakub Sztandera's avatar
Jakub Sztandera committed
13 14 15
# match Go's default GOPATH behaviour
export GOPATH ?= $(shell $(GOCC) env GOPATH)

16 17
DEPS_GO :=
TEST_GO :=
18
TEST_GO_BUILD :=
19 20
CHECK_GO :=

21
go-pkg-name=$(shell $(GOCC) list $(go-tags) github.com/ipfs/go-ipfs/$(1))
22 23
go-main-name=$(notdir $(call go-pkg-name,$(1)))$(?exe)
go-curr-pkg-tgt=$(d)/$(call go-main-name,$(d))
Steven Allen's avatar
Steven Allen committed
24
go-pkgs=$(shell $(GOCC) list github.com/ipfs/go-ipfs/...)
25

Jakub Sztandera's avatar
Jakub Sztandera committed
26
go-tags=$(if $(GOTAGS), -tags="$(call join-with,$(space),$(GOTAGS))")
27 28
go-flags-with-tags=$(GOFLAGS)$(go-tags)

29
define go-build-relative
Łukasz Magiera's avatar
Łukasz Magiera committed
30
$(GOCC) build $(go-flags-with-tags) -o "$@" "$(call go-pkg-name,$<)"
31 32
endef

33 34 35 36
define go-build
$(GOCC) build $(go-flags-with-tags) -o "$@" "$(1)"
endef

37 38 39 40
define go-try-build
$(GOCC) build $(go-flags-with-tags) -o /dev/null "$(call go-pkg-name,$<)"
endef

41 42 43 44
test_go_test: $$(DEPS_GO)
	$(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) ./...
.PHONY: test_go_test

45
test_go_short: GOTFLAGS += -test.short
46
test_go_short: test_go_test
47 48 49
.PHONY: test_go_short

test_go_race: GOTFLAGS += -race
50
test_go_race: test_go_test
51 52
.PHONY: test_go_race

53
test_go_expensive: test_go_test $$(TEST_GO_BUILD)
54 55 56 57 58 59 60 61
.PHONY: test_go_expensive
TEST_GO += test_go_expensive

test_go_fmt:
	bin/test-go-fmt
.PHONY: test_go_fmt
TEST_GO += test_go_fmt

62
test_go_megacheck:
63
	@$(GOCC) get honnef.co/go/tools/cmd/megacheck
Steven Allen's avatar
Steven Allen committed
64
	@for pkg in $(go-pkgs); do megacheck "$$pkg"; done
65 66
.PHONY: megacheck

67 68 69 70 71
test_go: $(TEST_GO)

check_go_version:
	bin/check_go_version $(GO_MIN_VERSION)
.PHONY: check_go_version
Jakub Sztandera's avatar
Jakub Sztandera committed
72
DEPS_GO += check_go_version
73 74 75

TEST += $(TEST_GO)
TEST_SHORT += test_go_fmt test_go_short