Begin development of next release 0.3.0
[govpp.git] / Makefile
1 SHELL := /usr/bin/env bash -o pipefail
2
3 VERSION ?= $(shell git describe --always --tags --dirty)
4 COMMIT ?= $(shell git rev-parse HEAD)
5 BUILD_STAMP ?= $(shell git log -1 --format="%ct")
6 BUILD_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
7
8 BUILD_HOST ?= $(shell hostname)
9 BUILD_USER ?= $(shell id -un)
10
11 GO ?= go
12
13 GOVPP_PKG := $(shell go list)
14 LDFLAGS = \
15         -X ${GOVPP_PKG}/version.version=$(VERSION) \
16         -X ${GOVPP_PKG}/version.commitHash=$(COMMIT) \
17         -X ${GOVPP_PKG}/version.buildStamp=$(BUILD_STAMP) \
18         -X ${GOVPP_PKG}/version.buildBranch=$(BUILD_BRANCH) \
19         -X ${GOVPP_PKG}/version.buildUser=$(BUILD_USER) \
20         -X ${GOVPP_PKG}/version.buildHost=$(BUILD_HOST)
21 ifeq ($(NOSTRIP),)
22 LDFLAGS += -w -s
23 endif
24
25 GO_BUILD_TAGS ?= novpp
26
27 GO_BUILD_ARGS = -ldflags "${LDFLAGS}"
28 ifneq ($(GO_BUILD_TAGS),)
29 GO_BUILD_ARGS += -tags="${GO_BUILD_TAGS}"
30 endif
31 ifneq ($(GO_NOTRIM),0)
32 GO_BUILD_ARGS += -trimpath
33 endif
34 ifeq ($(V),1)
35 GO_BUILD_ARGS += -v
36 endif
37
38 VPP_VERSION     = $(shell dpkg-query -f '\${Version}' -W vpp)
39
40 VPP_IMG         ?= ligato/vpp-base:latest
41 BINAPI_DIR      ?= ./examples/binapi
42
43 help:
44         @echo "List of make targets:"
45         grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
46
47 .DEFAULT = help
48
49 bin:
50         mkdir -p bin
51
52 build: ## Build all
53         @echo "# building ${VERSION}"
54         $(GO) build ${GO_BUILD_ARGS} ./...
55
56 cmd: bin ## Build commands
57         $(GO) build ${GO_BUILD_ARGS} -o bin ./cmd/...
58
59 examples: bin ## Build examples
60         $(GO) build ${GO_BUILD_ARGS} -o bin ./examples/...
61
62 clean: ## Clean all
63         @echo "# cleaning"
64         $(GO) clean -v ./...
65
66 test: ## Run unit tests
67         @echo "# running tests"
68         $(GO) test -tags="${GO_BUILD_TAGS}" ./...
69
70 integration: ## Run integration tests
71         @echo "# running integration tests"
72         $(GO) test -tags="integration ${GO_BUILD_TAGS}" ./test/integration
73
74 lint: ## Run code linter
75         @echo "# running linter"
76         @golint ./...
77
78 install-generator: ## Install binapi-generator
79         @echo "# installing binapi-generator ${VERSION}"
80         $(GO) install ${GO_BUILD_ARGS} ./cmd/binapi-generator
81
82 generate: ## Generate code
83         @echo "# generating code"
84         $(GO) generate -x ./...
85
86 generate-binapi: install-generator
87         @echo "# generating binapi VPP $(VPP_VERSION)"
88         $(GO) generate -x "$(BINAPI_DIR)"
89
90 gen-binapi-docker: install-generator
91         @echo "# generating binapi in docker image ${VPP_IMG}"
92         $(eval cmds := $(shell go generate -n $(BINAPI_DIR) 2>&1 | tr "\n" ";"))
93         docker run -t --rm \
94                 -v "$(shell which gofmt):/usr/local/bin/gofmt:ro" \
95                 -v "$(shell which binapi-generator):/usr/local/bin/binapi-generator:ro" \
96                 -v "$(shell pwd):/govpp" -w /govpp \
97                 -u "$(shell id -u):$(shell id -g)" \
98                 "${VPP_IMG}" \
99           sh -xc "cd $(BINAPI_DIR) && $(cmds)"
100
101 extras:
102         @make -C extras
103
104
105 .PHONY: help \
106     build cmd examples clean \
107         lint test integration \
108         install-generator generate generate-binapi gen-binapi-docker \
109         extras
110