golang.mk 1.74 KB
Newer Older
1
# golang utilities
Jeromy's avatar
Jeromy committed
2
GO_MIN_VERSION = 1.9
3

4 5 6
# match Go's default GOPATH behaviour
GOPATH ?= $(HOME)/go

7
# pre-definitions
8
GOCC ?= go
9 10 11 12 13 14
GOTAGS ?=
GOFLAGS ?=
GOTFLAGS ?=

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

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

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

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

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

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

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

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

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

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

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

67 68 69 70 71
check_go_path:
	bin/check_go_path $(realpath $(shell pwd)) $(realpath $(addsuffix /src/github.com/ipfs/go-ipfs,$(subst $(PATH_SEP),$(space),$(GOPATH))))
.PHONY: check_go_path
DEPS_GO += check_go_path

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