golang.mk 1.69 KB
Newer Older
1
# golang utilities
2
GO_MIN_VERSION = 1.10
3

4

5
# pre-definitions
6
GOCC ?= go
7 8 9 10
GOTAGS ?=
GOFLAGS ?=
GOTFLAGS ?=

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

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

19
go-pkg-name=$(shell $(GOCC) list $(go-tags) github.com/ipfs/go-ipfs/$(1))
20 21
go-main-name=$(notdir $(call go-pkg-name,$(1)))$(?exe)
go-curr-pkg-tgt=$(d)/$(call go-main-name,$(d))
22
go-pkgs-novendor=$(shell $(GOCC) list github.com/ipfs/go-ipfs/... | grep -v /Godeps/)
23

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

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

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

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

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

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

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

56
test_go_megacheck:
57
	@$(GOCC) get honnef.co/go/tools/cmd/megacheck
58 59 60
	@for pkg in $(go-pkgs-novendor); do megacheck "$$pkg"; done
.PHONY: megacheck

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

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

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