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 := go.fd.io/govpp
15 VPP_API_DIR ?= ${VPP_DIR}/build-root/install-vpp-native/vpp/share/vpp/api
17 VERSION_PKG := $(GOVPP_PKG)/version
19 -X $(VERSION_PKG).version=$(VERSION) \
20 -X $(VERSION_PKG).commitHash=$(COMMIT) \
21 -X $(VERSION_PKG).buildStamp=$(BUILD_STAMP) \
22 -X $(VERSION_PKG).buildBranch=$(BUILD_BRANCH) \
23 -X $(VERSION_PKG).buildUser=$(BUILD_USER) \
24 -X $(VERSION_PKG).buildHost=$(BUILD_HOST)
30 GO_BUILD_TAGS ?= novpp
32 GO_BUILD_ARGS = -ldflags "$(LDFLAGS)"
33 ifneq ($(GO_BUILD_TAGS),)
34 GO_BUILD_ARGS += -tags="${GO_BUILD_TAGS}"
36 ifneq ($(GO_NOTRIM),0)
37 GO_BUILD_ARGS += -trimpath
43 # VPP Docker image to use for api generation (gen-binapi-docker)
44 VPP_IMG ?= ligato/vpp-base:latest
45 # Local VPP directory used for binary api generation (gen-binapi-from-code)
47 # Target directory for generated go api bindings
48 BINAPI_DIR ?= ./binapi
49 # Binapi generator path
50 BINAPI_GENERATOR = ./bin/binapi-generator
55 @: $(if $(value $*),,$(error $* is undefined))
61 build: cmd examples ## Build all
64 cmd: bin ## Build commands
65 @go build ${GO_BUILD_ARGS} -o bin ./cmd/...
67 .PHONY: binapi-generator
68 binapi-generator: bin ## Build only the binapi generator
69 @go build ${GO_BUILD_ARGS} -o bin ./cmd/binapi-generator/
72 examples: bin ## Build examples
73 @go build ${GO_BUILD_ARGS} -o bin ./examples/...
76 test: ## Run unit tests
77 @echo "# running tests"
78 go test -tags="${GO_BUILD_TAGS}" ./...
80 .PHONY: test-integration
81 test-integration: ## Run integration tests
82 @echo "# running integration tests"
83 go test -tags="integration ${GO_BUILD_TAGS}" ./test/integration
86 lint: ## Run code linter
87 @echo "# running linter"
91 install: install-generator install-proxy ## Install all
93 .PHONY: install-generator
94 install-generator: ## Install binapi-generator
95 @echo "# installing binapi-generator ${VERSION}"
96 @go install ${GO_BUILD_ARGS} ./cmd/binapi-generator
99 install-proxy: ## Install vpp-proxy
100 @echo "# installing vpp-proxy ${VERSION}"
101 @go install ${GO_BUILD_ARGS} ./cmd/vpp-proxy
104 generate: generate-binapi ## Generate all
106 .PHONY: generate-binapi
107 generate-binapi: install-generator ## Generate binapi code
108 @echo "# generating binapi"
109 @go generate -x "$(BINAPI_DIR)"
111 .PHONY: gen-binapi-local
112 gen-binapi-local: binapi-generator check-VPP_DIR ## Generate binapi code (using locally cloned VPP)
113 @make -C ${VPP_DIR} json-api-files
114 @find $(BINAPI_DIR)/*/*.ba.go -delete
115 @find $(BINAPI_DIR)/* -type d -delete
116 @./bin/binapi-generator -input-dir=$(VPP_API_DIR) -output-dir=$(BINAPI_DIR) -gen=rpc
117 @./bin/binapi-generator -input-dir=$(VPP_API_DIR) -input-file=$(VPP_API_DIR)/core/vpe.api.json -output-dir=$(BINAPI_DIR) -gen=http
118 @sed -i 's@$(VPP_API_DIR)@/usr/share/vpp/api@g' $(BINAPI_DIR)/*/*.ba.go
120 .PHONY: gen-binapi-docker
121 gen-binapi-docker: install-generator ## Generate binapi code (using Docker)
122 @echo "# generating binapi in docker image ${VPP_IMG}"
123 $(eval cmds := $(shell go generate -n $(BINAPI_DIR) 2>&1 | tr "\n" ";"))
126 -v "$(shell which binapi-generator):/usr/local/bin/binapi-generator:ro" \
127 -v "$(shell pwd):/govpp" \
129 -u "$(shell id -u):$(shell id -g)" \
131 sh -ec "cd $(BINAPI_DIR) && $(cmds)"
135 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'