1 SHELL := /usr/bin/env bash -o pipefail
5 VERSION ?= $(shell git describe --always --tags --dirty)
6 COMMIT ?= $(shell git rev-parse HEAD)
7 BUILD_STAMP ?= $(shell git log -1 --format='%ct')
8 BUILD_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
10 BUILD_HOST ?= $(shell hostname)
11 BUILD_USER ?= $(shell id -un)
13 GOVPP_PKG := git.fd.io/govpp.git
15 VERSION_PKG := $(GOVPP_PKG)/internal/version
17 -X $(VERSION_PKG).version=$(VERSION) \
18 -X $(VERSION_PKG).commitHash=$(COMMIT) \
19 -X $(VERSION_PKG).buildStamp=$(BUILD_STAMP) \
20 -X $(VERSION_PKG).buildBranch=$(BUILD_BRANCH) \
21 -X $(VERSION_PKG).buildUser=$(BUILD_USER) \
22 -X $(VERSION_PKG).buildHost=$(BUILD_HOST)
28 GO_BUILD_TAGS ?= novpp
30 GO_BUILD_ARGS = -ldflags "$(LDFLAGS)"
31 ifneq ($(GO_BUILD_TAGS),)
32 GO_BUILD_ARGS += -tags="${GO_BUILD_TAGS}"
34 ifneq ($(GO_NOTRIM),0)
35 GO_BUILD_ARGS += -trimpath
41 # VPP Docker image to use for api generation (gen-binapi-docker)
42 VPP_IMG ?= ligato/vpp-base:latest
43 # Local VPP directory used for binary api generation (gen-binapi-from-code)
45 # Target directory for generated go api bindings
46 BINAPI_DIR ?= ./binapi
47 # Binapi generator path
48 BINAPI_GENERATOR = ./bin/binapi-generator
56 @echo "# building ${VERSION}"
57 go build ${GO_BUILD_ARGS} ./...
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/...
65 test: ## Run unit tests
66 @echo "# running tests"
67 go test -tags="${GO_BUILD_TAGS}" ./...
69 test-integration: ## Run integration tests
70 @echo "# running integration tests"
71 go test -tags="integration ${GO_BUILD_TAGS}" ./test/integration
73 lint: ## Run code linter
74 @echo "# running linter"
77 install: install-generator install-proxy ## Install all
79 install-generator: ## Install binapi-generator
80 @echo "# installing binapi-generator ${VERSION}"
81 @go install ${GO_BUILD_ARGS} ./cmd/binapi-generator
83 install-proxy: ## Install vpp-proxy
84 @echo "# installing vpp-proxy ${VERSION}"
85 go install ${GO_BUILD_ARGS} ./cmd/vpp-proxy
87 generate: generate-binapi ## Generate all
89 generate-binapi: install-generator ## Generate binapi code
90 @echo "# generating binapi"
91 go generate -x "$(BINAPI_DIR)"
93 gen-binapi-from-code: cmd-binapi-generator
94 $(eval VPP_API_DIR := ${VPP_DIR}/build-root/install-vpp-native/vpp/share/vpp/api/)
95 @echo "Generating vpp API.json and go bindings"
96 @echo "Vpp Directory ${VPP_DIR}"
97 @echo "Vpp API files ${VPP_API_DIR}"
98 @echo "Go bindings ${BINAPI_DIR}"
99 @cd ${VPP_DIR} && make json-api-files
100 @${BINAPI_GENERATOR} \
101 --input-dir=${VPP_API_DIR} \
102 --output-dir=${BINAPI_DIR} \
104 --no-source-path-info
106 gen-binapi-docker: install-generator ## Generate binapi code (using Docker)
107 @echo "# generating binapi in docker image ${VPP_IMG}"
108 $(eval cmds := $(shell go generate -n $(BINAPI_DIR) 2>&1 | tr "\n" ";"))
111 -v "$(shell which binapi-generator):/usr/local/bin/binapi-generator:ro" \
112 -v "$(shell pwd):/govpp" \
114 -u "$(shell id -u):$(shell id -g)" \
116 sh -ec "cd $(BINAPI_DIR) && $(cmds)"
119 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
122 build cmd examples clean \
123 lint test integration \
124 install install-generator install-proxy \
125 generate generate-binapi gen-binapi-docker \