aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 619a431e52931511c2ab6f1c298beab7a42cf0e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Makefile for building CoreDNS
GITCOMMIT:=$(shell git describe --dirty --always)
BINARY:=coredns
SYSTEM:=
CHECKS:=check
BUILDOPTS:=-v
GOPATH?=$(HOME)/go
PRESUBMIT:=core coremain plugin test request
MAKEPWD:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
CGO_ENABLED:=0

.PHONY: all
all: coredns

.PHONY: coredns
coredns: $(CHECKS)
	GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) $(SYSTEM) go build $(BUILDOPTS) -ldflags="-s -w -X github.com/coredns/coredns/coremain.GitCommit=$(GITCOMMIT)" -o $(BINARY)

.PHONY: check
check: presubmit core/plugin/zplugin.go core/dnsserver/zdirectives.go

.PHONY: travis
travis:
ifeq ($(TEST_TYPE),core)
	( cd request ; GO111MODULE=on go test -v -race ./... )
	( cd core ; GO111MODULE=on go test -v -race  ./... )
	( cd coremain ; GO111MODULE=on go test -v -race ./... )
endif
ifeq ($(TEST_TYPE),integration)
	( cd test ; GO111MODULE=on go test -v -race ./... )
endif
ifeq ($(TEST_TYPE),plugin)
	( cd plugin ; GO111MODULE=on go test -v -race ./... )
endif
ifeq ($(TEST_TYPE),coverage)
	for d in `go list ./... | grep -v vendor`; do \
		t=$$(date +%s); \
		GO111MODULE=on go test -i -coverprofile=cover.out -covermode=atomic $$d || exit 1; \
		GO111MODULE=on go test -v -coverprofile=cover.out -covermode=atomic $$d || exit 1; \
		echo "Coverage test $$d took $$(($$(date +%s)-t)) seconds"; \
		if [ -f cover.out ]; then \
			cat cover.out >> coverage.txt; \
			rm cover.out; \
		fi; \
	done
endif
ifeq ($(TEST_TYPE),fuzzit)
	# skip fuzzing for PR
	if [ "$(TRAVIS_PULL_REQUEST)" = "false" ] || [ "$(FUZZIT_TYPE)" = "local-regression" ] ; then \
        export GO111MODULE=off; \
        go get -u github.com/dvyukov/go-fuzz/go-fuzz-build; \
        go get -u -v .; \
        cd ../../go-acme/lego; \
        git checkout v2.5.0; \
        cd ../../coredns/coredns; \
        LIBFUZZER=YES make -f Makefile.fuzz cache chaos file rewrite whoami corefile; \
        wget -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/download/v2.4.27/fuzzit_Linux_x86_64; \
        chmod a+x fuzzit; \
        ./fuzzit create job --type $(FUZZIT_TYPE) coredns/cache ./cache; \
        ./fuzzit create job --type $(FUZZIT_TYPE) coredns/chaos ./chaos; \
        ./fuzzit create job --type $(FUZZIT_TYPE) coredns/file ./file; \
        ./fuzzit create job --type $(FUZZIT_TYPE) coredns/rewrite ./rewrite; \
        ./fuzzit create job --type $(FUZZIT_TYPE) coredns/whoami ./whoami; \
        ./fuzzit create job --type $(FUZZIT_TYPE) coredns/corefile ./corefile; \
    fi;
endif

core/plugin/zplugin.go core/dnsserver/zdirectives.go: plugin.cfg
	GO111MODULE=on go generate coredns.go

.PHONY: gen
gen:
	GO111MODULE=on go generate coredns.go

.PHONY: pb
pb:
	$(MAKE) -C pb

# Presubmit runs all scripts in .presubmit; any non 0 exit code will fail the build.
.PHONY: presubmit
presubmit:
	@for pre in $(MAKEPWD)/.presubmit/* ; do "$$pre" $(PRESUBMIT) || exit 1 ; done

.PHONY: clean
clean:
	GO111MODULE=on go clean
	rm -f coredns