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 := git.fd.io/govpp.git
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 Docker image to use for api generation (gen-binapi-docker)
41 VPP_IMG ?= ligato/vpp-base:latest
42 # Local VPP directory used for binary api generation (gen-binapi-from-code)
44 # Target directory for generated go api bindings
45 BINAPI_DIR ?= ./binapi
46 # Binapi generator path
47 BINAPI_GENERATOR = ./bin/binapi-generator
53 @echo "# building ${VERSION}"
54 $(GO) build ${GO_BUILD_ARGS} ./...
56 cmd-binapi-generator: bin ## Build commands
57 $(GO) build ${GO_BUILD_ARGS} -o bin ./cmd/binapi-generator
59 cmd: bin ## Build commands
60 $(GO) build ${GO_BUILD_ARGS} -o bin ./cmd/...
62 examples: bin ## Build examples
63 $(GO) build ${GO_BUILD_ARGS} -o bin ./examples/...
69 test: ## Run unit tests
71 @echo "# running tests"
72 $(GO) test -tags="${GO_BUILD_TAGS}" ./...
74 integration: ## Run integration tests
75 @echo "# running integration tests"
76 $(GO) test -tags="integration ${GO_BUILD_TAGS}" ./test/integration
78 lint: ## Run code linter
79 @echo "# running linter"
82 install: install-generator install-proxy ## Install all
84 install-generator: ## Install binapi-generator
85 @echo "# installing binapi-generator ${VERSION}"
86 @$(GO) install ${GO_BUILD_ARGS} ./cmd/binapi-generator
88 install-proxy: ## Install vpp-proxy
89 @echo "# installing vpp-proxy ${VERSION}"
90 $(GO) install ${GO_BUILD_ARGS} ./cmd/vpp-proxy
92 generate: ## Generate all
93 @echo "# generating code"
94 $(GO) generate -x ./...
96 generate-binapi: install-generator ## Generate binapi code
97 @echo "# generating binapi VPP $(VPP_VERSION)"
98 $(GO) generate -x "$(BINAPI_DIR)"
100 gen-binapi-from-code: cmd-binapi-generator
101 $(eval VPP_API_DIR := ${VPP_DIR}/build-root/install-vpp-native/vpp/share/vpp/api/)
102 @echo "Generating vpp API.json and go bindings"
103 @echo "Vpp Directory ${VPP_DIR}"
104 @echo "Vpp API files ${VPP_API_DIR}"
105 @echo "Go bindings ${BINAPI_DIR}"
106 @cd ${VPP_DIR} && make json-api-files
107 @${BINAPI_GENERATOR} \
108 --input-dir=${VPP_API_DIR} \
109 --output-dir=${BINAPI_DIR} \
111 --no-source-path-info
113 gen-binapi-docker: install-generator ## Generate binapi code (using Docker)
114 @echo "# generating binapi in docker image ${VPP_IMG}"
115 $(eval cmds := $(shell go generate -n $(BINAPI_DIR) 2>&1 | tr "\n" ";"))
118 -v "$(shell which binapi-generator):/usr/local/bin/binapi-generator:ro" \
119 -v "$(shell pwd):/govpp" \
121 -u "$(shell id -u):$(shell id -g)" \
123 sh -ec "cd $(BINAPI_DIR) && $(cmds)"
129 @echo "List of make targets:"
130 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
135 build cmd examples clean \
136 lint test integration \
137 install install-generator install-proxy \
138 generate generate-binapi gen-binapi-docker \