Makefile 5.46 KB
Newer Older
1
# Minimum version numbers for software required to build IPFS
Jeromy's avatar
Jeromy committed
2
IPFS_MIN_GO_VERSION = 1.7
3 4
IPFS_MIN_GX_VERSION = 0.6
IPFS_MIN_GX_GO_VERSION = 1.1
5

6 7 8 9 10
GOTAGS =
GOTAGS += "" # we have to have always at least one tag, empty tag works well

GOFLAGS =
GOTFLAGS =
11 12

export IPFS_REUSEPORT=false
13 14 15 16
export GOFLAGS
export GOTFLAGS

GOFLAGS += -tags $(call join-with,$(comma),$(GOTAGS))
17 18

ifeq ($(TEST_NO_FUSE),1)
Jakub Sztandera's avatar
Jakub Sztandera committed
19
	GOTAGS += nofuse
20 21
endif

Dominic Della Valle's avatar
Dominic Della Valle committed
22
ifeq ($(OS),Windows_NT)
Jakub Sztandera's avatar
Jakub Sztandera committed
23
	GOPATH_DELIMITER = ;
Dominic Della Valle's avatar
Dominic Della Valle committed
24
else
Jakub Sztandera's avatar
Jakub Sztandera committed
25
	GOPATH_DELIMITER = :
Dominic Della Valle's avatar
Dominic Della Valle committed
26
endif
27

Jeromy's avatar
Jeromy committed
28 29 30
dist_root=/ipfs/QmNZL8wNsvAGdVYr8uGeUE9aGfHjFpHegAWywQFEdSaJbp
gx_bin=bin/gx-v0.9.0
gx-go_bin=bin/gx-go-v1.3.0
31

32 33 34 35 36 37 38

# util functions

space =
space +=
comma =,
join-with = $(subst $(space),$1,$(strip $2))
39 40
# use things in our bin before any other system binaries
export PATH := bin:$(PATH)
41
export IPFS_API ?= v04x.ipfs.io
42

43
all: help
44 45 46 47

godep:
	go get github.com/tools/godep

48
go_check:
49
	@bin/check_go_version $(IPFS_MIN_GO_VERSION)
50

Jeromy's avatar
Jeromy committed
51
bin/gx-v%:
52
	@echo "installing gx $(@:bin/gx-%=%)"
53
	@bin/dist_get ${dist_root} gx $@ $(@:bin/gx-%=%)
Jeromy's avatar
Jeromy committed
54 55
	rm -f bin/gx
	ln -s $(@:bin/%=%) bin/gx
56

Jeromy's avatar
Jeromy committed
57
bin/gx-go-v%:
58
	@echo "installing gx-go $(@:bin/gx-go-%=%)"
59
	@bin/dist_get ${dist_root} gx-go $@ $(@:bin/gx-go-%=%)
60 61 62 63
	rm -f bin/gx-go
	ln -s $(@:bin/%=%) bin/gx-go

gx_check: ${gx_bin} ${gx-go_bin}
64

65
path_check:
Dominic Della Valle's avatar
Dominic Della Valle committed
66
	@bin/check_go_path $(realpath $(shell pwd)) $(realpath $(addsuffix /src/github.com/ipfs/go-ipfs,$(subst $(GOPATH_DELIMITER), ,$(GOPATH))))
67

68
deps: go_check gx_check path_check $(covertools_rule)
Jakub Sztandera's avatar
Jakub Sztandera committed
69
	${gx_bin} --verbose install --global
70

Jakub Sztandera's avatar
Jakub Sztandera committed
71 72
deps_covertools:
	go get -u github.com/wadey/gocovmerge
73 74
	go get -u golang.org/x/tools/cmd/cover

75 76 77 78 79
# saves/vendors third-party dependencies to Godeps/_workspace
# -r flag rewrites import paths to use the vendored path
# ./... performs operation on all packages in tree
vendor: godep
	godep save -r ./...
80

81 82 83 84 85
nofuse: GOTAGS += nofuse
nofuse: deps
	$(MAKE) -C cmd/ipfs install

install build: deps
86
	$(MAKE) -C cmd/ipfs $@
Henry's avatar
Henry committed
87

88
clean:
89
	$(MAKE) -C cmd/ipfs clean
90
	$(MAKE) -C test clean
91 92

uninstall:
93
	$(MAKE) -C cmd/ipfs uninstall
94

Jakub Sztandera's avatar
Jakub Sztandera committed
95
PHONY += all help godep gx_check covertools
96
PHONY += go_check deps vendor install build nofuse clean uninstall
97

98 99 100
##############################################################
# tests targets

101
test: test_expensive
102

Jakub Sztandera's avatar
Jakub Sztandera committed
103
test_short: test_go_fmt build test_go_short test_sharness_short
104

Jakub Sztandera's avatar
Jakub Sztandera committed
105
test_expensive: test_go_fmt build test_go_expensive test_sharness_expensive windows_build_check
106

107
test_3node:
108
	$(MAKE) -C test/3nodetest
Brian Tiger Chow's avatar
Brian Tiger Chow committed
109

Jakub Sztandera's avatar
Jakub Sztandera committed
110 111 112
test_go_fmt:
	bin/test-go-fmt

113 114 115
test_go_short: GOTFLAGS += -test.short
test_go_race: GOTFLAGS += -race
test_go_expensive test_go_short test_go_race:
Jakub Sztandera's avatar
Jakub Sztandera committed
116 117 118 119 120 121 122 123 124 125
	go test $(GOFLAGS) $(GOTFLAGS) ./...

coverage: deps_covertools
	@echo Running coverage
	$(eval PKGS := $(shell go list -f '{{if (len .GoFiles)}}{{.ImportPath}}{{end}}' ./... | grep -v /vendor/ | grep -v /Godeps/))
#$(eval PKGS_DELIM := $(call join-with,$(comma),$(PKGS)))
	@go list -f '{{if or (len .TestGoFiles) (len .XTestGoFiles)}}go test $(GOFLAGS) $(GOTFLAGS) -covermode=atomic -coverprofile={{.Name}}_{{len .Imports}}_{{len .Deps}}.coverprofile {{.ImportPath}}{{end}}' $(GOFLAGS) $(PKGS) | xargs -I {} bash -c {} 2>&1 | grep -v 'warning: no packages being tested depend on'
	gocovmerge `ls *.coverprofile` > coverage.txt
	rm *.coverprofile
	bash -c 'bash <(curl -s https://codecov.io/bash)'
Brian Tiger Chow's avatar
Brian Tiger Chow committed
126

127
test_sharness_short:
128
	$(MAKE) -j1 -C test/sharness/
129 130

test_sharness_expensive:
131
	TEST_EXPENSIVE=1 $(MAKE) -j1 -C test/sharness/
132 133 134 135 136

test_all_commits:
	@echo "testing all commits between origin/master..HEAD"
	@echo "WARNING: this will 'git rebase --exec'."
	@test/bin/continueyn
137
	GIT_EDITOR=true git rebase -i --exec "$(MAKE) test" origin/master
138 139 140 141 142 143 144

test_all_commits_travis:
	# these are needed because travis.
	# we don't use this yet because it takes way too long.
	git config --global user.email "nemo@ipfs.io"
	git config --global user.name "IPFS BOT"
	git fetch origin master:master
145
	GIT_EDITOR=true git rebase -i --exec "$(MAKE) test" master
146 147 148

# since we have CI for osx and linux but not windows, this should help
windows_build_check:
149
	GOOS=windows GOARCH=amd64 go build -o .test.ipfs.exe ./cmd/ipfs
Jakub Sztandera's avatar
Jakub Sztandera committed
150
	rm -f .test.ipfs.exe
151 152 153 154 155 156 157 158 159

PHONY += test test_short test_expensive

##############################################################
# A semi-helpful help message

help:
	@echo 'DEPENDENCY TARGETS:'
	@echo ''
160
	@echo '  gx_check        - Installs or upgrades gx and gx-go'
161 162
	@echo '  deps            - Download dependencies using gx'
	@echo '  vendor          - Create a Godep workspace of 3rd party dependencies'
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
	@echo ''
	@echo 'BUILD TARGETS:'
	@echo ''
	@echo '  all          - print this help message'
	@echo '  build        - Build binary at ./cmd/ipfs/ipfs'
	@echo '  nofuse       - Build binary with no fuse support'
	@echo '  install      - Build binary and install into $$GOPATH/bin'
#	@echo '  dist_install - TODO: c.f. ./cmd/ipfs/dist/README.md'
	@echo ''
	@echo 'CLEANING TARGETS:'
	@echo ''
	@echo '  clean        - Remove binary from build directory'
	@echo '  uninstall    - Remove binary from $$GOPATH/bin'
	@echo ''
	@echo 'TESTING TARGETS:'
	@echo ''
	@echo '  test                    - Run expensive tests and Window$$ check'
	@echo '  test_short              - Run short tests and sharness tests'
	@echo '  test_expensive          - Run a few extras'
	@echo '  test_3node'
	@echo '  test_go_short'
	@echo '  test_go_expensive'
	@echo '  test_go_race'
	@echo '  test_sharness_short'
	@echo '  test_sharness_expensive'
	@echo '  test_all_commits'
	@echo "  test_all_commits_travis - DON'T USE: takes way too long"
	@echo '  windows_build_check'
	@echo ''

PHONY += help

.PHONY: $(PHONY)