X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=Makefile;h=46e04ec4c11ebb20ed1f7b3a6066814e6cb4f30e;hb=d0b973030fe07dc7875da72f5ebe42d8bd9544b1;hp=5354609fb92a1cea489a14fbb73b6afcc078f41a;hpb=809b69ea4a90455445c34bbad7d8e5fea5cf3462;p=govpp.git diff --git a/Makefile b/Makefile index 5354609..46e04ec 100644 --- a/Makefile +++ b/Makefile @@ -1,96 +1,127 @@ -SHELL = /bin/bash +SHELL := /usr/bin/env bash -o pipefail -GO ?= GO111MODULE=on go -GOVPP_PKG := $(shell go list) +PROJECT := govpp -VERSION ?= $(shell git describe --always --tags --dirty) -COMMIT ?= $(shell git rev-parse HEAD) -BUILD_STAMP ?= $(shell git log -1 --format="%ct") +VERSION ?= $(shell git describe --always --tags --dirty) +COMMIT ?= $(shell git rev-parse HEAD) +BUILD_STAMP ?= $(shell git log -1 --format='%ct') BUILD_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) + BUILD_HOST ?= $(shell hostname) BUILD_USER ?= $(shell id -un) -VPP_VERSION = $(shell dpkg-query -f '\${Version}' -W vpp) - -VPP_IMG ?= ligato/vpp-base:latest -BINAPI_DIR ?= ./examples/binapi +GOVPP_PKG := git.fd.io/govpp.git -LDFLAGS = -w -s \ - -X ${GOVPP_PKG}/version.version=$(VERSION) \ - -X ${GOVPP_PKG}/version.commitHash=$(COMMIT) \ - -X ${GOVPP_PKG}/version.buildStamp=$(BUILD_STAMP) \ - -X ${GOVPP_PKG}/version.buildBranch=$(BUILD_BRANCH) \ - -X ${GOVPP_PKG}/version.buildUser=$(BUILD_USER) \ - -X ${GOVPP_PKG}/version.buildHost=$(BUILD_HOST) +VERSION_PKG := $(GOVPP_PKG)/internal/version +LDFLAGS = \ + -X $(VERSION_PKG).version=$(VERSION) \ + -X $(VERSION_PKG).commitHash=$(COMMIT) \ + -X $(VERSION_PKG).buildStamp=$(BUILD_STAMP) \ + -X $(VERSION_PKG).buildBranch=$(BUILD_BRANCH) \ + -X $(VERSION_PKG).buildUser=$(BUILD_USER) \ + -X $(VERSION_PKG).buildHost=$(BUILD_HOST) -GO_BUILD_ARGS = -ldflags "${LDFLAGS}" -ifeq ($(V),1) -GO_BUILD_ARGS += -v +ifeq ($(NOSTRIP),) +LDFLAGS += -w -s endif + +GO_BUILD_TAGS ?= novpp + +GO_BUILD_ARGS = -ldflags "$(LDFLAGS)" ifneq ($(GO_BUILD_TAGS),) GO_BUILD_ARGS += -tags="${GO_BUILD_TAGS}" endif +ifneq ($(GO_NOTRIM),0) +GO_BUILD_ARGS += -trimpath +endif +ifeq ($(V),1) +GO_BUILD_ARGS += -v +endif -all: test build examples - -install: - @echo "=> installing binapi-generator ${VERSION}" - $(GO) install ${GO_BUILD_ARGS} ./cmd/binapi-generator - -build: - @echo "=> building binapi-generator ${VERSION}" - cd cmd/binapi-generator && $(GO) build ${GO_BUILD_ARGS} - -examples: - @echo "=> building examples" - cd examples/perf-bench && $(GO) build ${GO_BUILD_ARGS} -v - cd examples/rpc-service && $(GO) build ${GO_BUILD_ARGS} -v - cd examples/simple-client && $(GO) build ${GO_BUILD_ARGS} -v - cd examples/stats-client && $(GO) build ${GO_BUILD_ARGS} -v - cd examples/union-example && $(GO) build ${GO_BUILD_ARGS} -v - -clean: - @echo "=> cleaning" - go clean -v ./cmd/... - go clean -v ./examples/... - -test: - @echo "=> running tests" - $(GO) test ${GO_BUILD_ARGS} ./cmd/... - $(GO) test ${GO_BUILD_ARGS} ./ ./api ./adapter ./codec ./core - -test-integration: - @echo "=> running integration tests" - $(GO) test ${GO_BUILD_ARGS} ./test/integration - -lint: - @echo "=> running linter" - @golint ./... | grep -v vendor | grep -v /binapi/ || true - -gen-binapi-docker: install - @echo "=> generating binapi in docker image ${VPP_IMG}" +# VPP Docker image to use for api generation (gen-binapi-docker) +VPP_IMG ?= ligato/vpp-base:latest +# Local VPP directory used for binary api generation (gen-binapi-from-code) +VPP_DIR ?= +# Target directory for generated go api bindings +BINAPI_DIR ?= ./binapi +# Binapi generator path +BINAPI_GENERATOR = ./bin/binapi-generator + +.DEFAULT_GOAL = help + +bin: + mkdir -p bin + +build: ## Build all + @echo "# building ${VERSION}" + go build ${GO_BUILD_ARGS} ./... + +cmd: bin ## Build commands + go build ${GO_BUILD_ARGS} -o bin ./cmd/... + +examples: bin ## Build examples + go build ${GO_BUILD_ARGS} -o bin ./examples/... + +test: ## Run unit tests + @echo "# running tests" + go test -tags="${GO_BUILD_TAGS}" ./... + +test-integration: ## Run integration tests + @echo "# running integration tests" + go test -tags="integration ${GO_BUILD_TAGS}" ./test/integration + +lint: ## Run code linter + @echo "# running linter" + @golint ./... + +install: install-generator install-proxy ## Install all + +install-generator: ## Install binapi-generator + @echo "# installing binapi-generator ${VERSION}" + @go install ${GO_BUILD_ARGS} ./cmd/binapi-generator + +install-proxy: ## Install vpp-proxy + @echo "# installing vpp-proxy ${VERSION}" + go install ${GO_BUILD_ARGS} ./cmd/vpp-proxy + +generate: generate-binapi ## Generate all + +generate-binapi: install-generator ## Generate binapi code + @echo "# generating binapi" + go generate -x "$(BINAPI_DIR)" + +gen-binapi-from-code: cmd-binapi-generator + $(eval VPP_API_DIR := ${VPP_DIR}/build-root/install-vpp-native/vpp/share/vpp/api/) + @echo "Generating vpp API.json and go bindings" + @echo "Vpp Directory ${VPP_DIR}" + @echo "Vpp API files ${VPP_API_DIR}" + @echo "Go bindings ${BINAPI_DIR}" + @cd ${VPP_DIR} && make json-api-files + @${BINAPI_GENERATOR} \ + --input-dir=${VPP_API_DIR} \ + --output-dir=${BINAPI_DIR} \ + --gen rpc,rest \ + --no-source-path-info + +gen-binapi-docker: install-generator ## Generate binapi code (using Docker) + @echo "# generating binapi in docker image ${VPP_IMG}" $(eval cmds := $(shell go generate -n $(BINAPI_DIR) 2>&1 | tr "\n" ";")) docker run -t --rm \ - -v "$(shell which gofmt):/usr/local/bin/gofmt:ro" \ + -e DEBUG_GOVPP \ -v "$(shell which binapi-generator):/usr/local/bin/binapi-generator:ro" \ - -v "$(shell pwd):/govpp" -w /govpp \ + -v "$(shell pwd):/govpp" \ + -w /govpp \ -u "$(shell id -u):$(shell id -g)" \ "${VPP_IMG}" \ - sh -xc "cd $(BINAPI_DIR) && $(cmds)" - -generate-binapi: install - @echo "=> generating binapi VPP $(VPP_VERSION)" - $(GO) generate -x "$(BINAPI_DIR)" - -generate: - @echo "=> generating code" - $(GO) generate -x ./... + sh -ec "cd $(BINAPI_DIR) && $(cmds)" -extras: - @make -C extras +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' - -.PHONY: all \ - install build examples clean test test-integration lint \ +.PHONY: help \ + build cmd examples clean \ + lint test integration \ + install install-generator install-proxy \ generate generate-binapi gen-binapi-docker \ extras +