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

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 29
go-flags-with-tags=$(GOFLAGS)$(go-tags)

define go-build
Ł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-try-build
$(GOCC) build $(go-flags-with-tags) -o /dev/null "$(call go-pkg-name,$<)"
endef

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

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

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

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

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

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

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

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