Debian Codegraph @

Makefile

raw
1 export GOPROXY=https://proxy.golang.org
2
3 GO ?= go
4 EPOCH_TEST_COMMIT ?= 394c06f491fe9f1c28a410e3b0b91916a5119406
5 DESTDIR ?=
6 LIBEXECDIR ?= ${PREFIX}/libexec/cni
7 PREFIX ?= /usr/local
8
9 PROJECT := github.com/containers/dnsname
10 FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
11 GOPKGDIR := $(FIRST_GOPATH)/src/$(PROJECT)
12 GOPKGBASEDIR ?= $(shell dirname "$(GOPKGDIR)")
13
14 SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
15
16 COMMIT_NO ?= $(shell git rev-parse HEAD 2> /dev/null || true)
17 GIT_COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})
18
19 LDFLAGS_DNSNAME ?= -X main.gitCommit=$(GIT_COMMIT)
20
21 GO_BUILD=$(GO) build
22 # Go module support: set `-mod=vendor` to use the vendored sources
23 ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true)
24 GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor
25 endif
26
27 GOBIN := $(shell $(GO) env GOBIN)
28 ifeq ($(GOBIN),)
29 GOBIN := $(FIRST_GOPATH)/bin
30 endif
31
32 all: binaries
33
34 validate: install.tools gofmt .gitvalidation lint
35
36 gofmt:
37 find . -name '*.go' ! -path './vendor/*' -exec gofmt -s -w {} \+
38 git diff --exit-code
39
40
41 binaries:
42 $(GO_BUILD) -ldflags '$(LDFLAGS_DNSNAME)' -o bin/dnsname github.com/containers/dnsname/plugins/meta/dnsname
43
44 .PHONY: .gitvalidation
45 .gitvalidation:
46 GIT_CHECK_EXCLUDE="./vendor" $(GOBIN)/git-validation -v -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..$(HEAD)
47
48 .PHONY: install.tools
49 install.tools: .install.gitvalidation .install.ginkgo .install.golangci-lint
50
51 lint: .install.golangci-lint
52 $(GOBIN)/golangci-lint run
53
54 define go-get
55 env GO111MODULE=off \
56 $(GO) get -u ${1}
57 endef
58
59 .install.ginkgo:
60 if [ ! -x "$(GOBIN)/ginkgo" ]; then \
61 $(call go-get,github.com/onsi/ginkgo/ginkgo); \
62 fi
63
64 .install.gitvalidation:
65 if [ ! -x "$(GOBIN)/git-validation" ]; then \
66 $(call go-get,github.com/vbatts/git-validation); \
67 fi
68
69 .install.golangci-lint:
70 if [ ! -x "$(GOBIN)/golangci-lint" ]; then \
71 curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOBIN)/ v1.23.6; \
72 fi
73
74 install:
75 install ${SELINUXOPT} -d -m 755 $(DESTDIR)$(LIBEXECDIR)
76 install ${SELINUXOPT} -m 755 bin/dnsname $(DESTDIR)$(LIBEXECDIR)/dnsname
77
78 clean:
79 rm -fr bin/
80
81 test: .install.ginkgo
82 $(GO) test -v ./...
83
84 vendor:
85 export GO111MODULE=on \
86 $(GO) mod tidy && \
87 $(GO) mod vendor && \
88 $(GO) mod verify
89
90 .PHONY: vendor-in-container
91 vendor-in-container:
92 podman run --privileged --rm --env HOME=/root -v `pwd`:/src -w /src docker.io/library/golang:1.13 make vendor
93
94 .PHONY: \
95 binaries \
96 test \
97 gofmt \
98 lint \
99 validate \
100 vendor