golang.mk 1.67 KB
Newer Older
1
# golang utilities
Steven Allen's avatar
Steven Allen committed
2
GO_MIN_VERSION = 1.11
3

4

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

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

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

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

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

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

32 33 34 35
define go-try-build
$(GOCC) build $(go-flags-with-tags) -o /dev/null "$(call go-pkg-name,$<)"
endef

36 37 38 39
test_go_test: $$(DEPS_GO)
	$(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) ./...
.PHONY: test_go_test

40
test_go_short: GOTFLAGS += -test.short
41
test_go_short: test_go_test
42 43 44
.PHONY: test_go_short

test_go_race: GOTFLAGS += -race
45
test_go_race: test_go_test
46 47
.PHONY: test_go_race

48
test_go_expensive: test_go_test $$(TEST_GO_BUILD)
49 50 51 52 53 54 55 56
.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

57
test_go_megacheck:
58
	@$(GOCC) get honnef.co/go/tools/cmd/megacheck
Steven Allen's avatar
Steven Allen committed
59
	@for pkg in $(go-pkgs); do megacheck "$$pkg"; done
60 61
.PHONY: megacheck

62 63 64 65 66
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
67
DEPS_GO += check_go_version
68

69
check_go_path:
70
	GOPATH="$(GOPATH)" bin/check_go_path github.com/ipfs/go-ipfs
71 72 73
.PHONY: check_go_path
DEPS_GO += check_go_path

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