golang.mk 1.67 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
# match Go's default GOPATH behaviour
export GOPATH ?= $(shell $(GOCC) env GOPATH)
15
export GOBIN = $(abspath bin)
Jakub Sztandera's avatar
Jakub Sztandera committed
16

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

22
go-pkg-name=$(shell $(GOCC) list $(go-tags) github.com/ipfs/go-ipfs/$(1))
23 24
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
25
go-pkgs=$(shell $(GOCC) list github.com/ipfs/go-ipfs/...)
26

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

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

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

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

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

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

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

54
test_go_expensive: test_go_test $$(TEST_GO_BUILD)
55 56 57 58 59 60 61 62
.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

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

68 69 70 71 72
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
73
DEPS_GO += check_go_version
74 75 76

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