1 SHELL := /usr/bin/env bash -o pipefail
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)
8 BUILD_HOST ?= $(shell hostname)
9 BUILD_USER ?= $(shell id -un)
13 GOVPP_PKG := $(shell go list)
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)
25 GO_BUILD_TAGS ?= novpp
27 GO_BUILD_ARGS = -ldflags "${LDFLAGS}"
28 ifneq ($(GO_BUILD_TAGS),)
29 GO_BUILD_ARGS += -tags="${GO_BUILD_TAGS}"
31 ifneq ($(GO_NOTRIM),0)
32 GO_BUILD_ARGS += -trimpath
38 VPP_VERSION = $(shell dpkg-query -f '\${Version}' -W vpp)
40 VPP_IMG ?= ligato/vpp-base:latest
41 BINAPI_DIR ?= ./examples/binapi
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}'
53 @echo "# building ${VERSION}"
54 $(GO) build ${GO_BUILD_ARGS} ./...
56 cmd: bin ## Build commands
57 $(GO) build ${GO_BUILD_ARGS} -o bin ./cmd/...
59 examples: bin ## Build examples
60 $(GO) build ${GO_BUILD_ARGS} -o bin ./examples/...
66 test: ## Run unit tests
67 @echo "# running tests"
68 $(GO) test -tags="${GO_BUILD_TAGS}" ./...
70 integration: ## Run integration tests
71 @echo "# running integration tests"
72 $(GO) test -tags="integration ${GO_BUILD_TAGS}" ./test/integration
74 lint: ## Run code linter
75 @echo "# running linter"
78 install-generator: ## Install binapi-generator
79 @echo "# installing binapi-generator ${VERSION}"
80 $(GO) install ${GO_BUILD_ARGS} ./cmd/binapi-generator
82 generate: ## Generate code
83 @echo "# generating code"
84 $(GO) generate -x ./...
86 generate-binapi: install-generator
87 @echo "# generating binapi VPP $(VPP_VERSION)"
88 $(GO) generate -x "$(BINAPI_DIR)"
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" ";"))
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)" \
99 sh -xc "cd $(BINAPI_DIR) && $(cmds)"
106 build cmd examples clean \
107 lint test integration \
108 install-generator generate generate-binapi gen-binapi-docker \