X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=Makefile;h=5354609fb92a1cea489a14fbb73b6afcc078f41a;hb=73733b0a8ab8612233c98f9828f5f563c69fc2b7;hp=ec013130e1a4811ffcf634d1cdaa22512e6d6d6c;hpb=62d19032621c7db801b313a1e19e787cfb1fbc3e;p=govpp.git diff --git a/Makefile b/Makefile index ec01313..5354609 100644 --- a/Makefile +++ b/Makefile @@ -1,52 +1,96 @@ +SHELL = /bin/bash + +GO ?= GO111MODULE=on go +GOVPP_PKG := $(shell go list) + 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 + +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) + +GO_BUILD_ARGS = -ldflags "${LDFLAGS}" +ifeq ($(V),1) +GO_BUILD_ARGS += -v +endif +ifneq ($(GO_BUILD_TAGS),) +GO_BUILD_ARGS += -tags="${GO_BUILD_TAGS}" +endif all: test build examples install: - @echo "=> installing ${VERSION}" - go install ./cmd/binapi-generator + @echo "=> installing binapi-generator ${VERSION}" + $(GO) install ${GO_BUILD_ARGS} ./cmd/binapi-generator build: - @echo "=> building ${VERSION}" - cd cmd/binapi-generator && go build -v + @echo "=> building binapi-generator ${VERSION}" + cd cmd/binapi-generator && $(GO) build ${GO_BUILD_ARGS} examples: @echo "=> building examples" - cd examples/cmd/simple-client && go build -v - cd examples/cmd/stats-client && go build -v - cd examples/cmd/perf-bench && go build -v - -test: - @echo "=> testing" - go test -cover ./cmd/... - go test -cover ./core ./api ./codec - -extras: - @echo "=> building extras" - cd extras/libmemif/examples/gopacket && go build -v - cd extras/libmemif/examples/icmp-responder && go build -v - cd extras/libmemif/examples/jumbo-frames && go build -v - cd extras/libmemif/examples/raw-data && go build -v + 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" - rm -f cmd/binapi-generator/binapi-generator - rm -f examples/cmd/perf-bench/perf-bench - rm -f examples/cmd/simple-client/simple-client - rm -f examples/cmd/stats-client/stats-client - rm -f extras/libmemif/examples/gopacket/gopacket - rm -f extras/libmemif/examples/icmp-responder/icmp-responder - rm -f extras/libmemif/examples/jumbo-frames/jumbo-frames - rm -f extras/libmemif/examples/raw-data/raw-data - -generate: install - @echo "=> generating code" - cd examples && go generate ./... + 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 bin_api || true + @golint ./... | grep -v vendor | grep -v /binapi/ || true + +gen-binapi-docker: install + @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" \ + -v "$(shell which binapi-generator):/usr/local/bin/binapi-generator:ro" \ + -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 ./... + +extras: + @make -C extras + .PHONY: all \ - install build examples test \ - extras clean generate lint + install build examples clean test test-integration lint \ + generate generate-binapi gen-binapi-docker \ + extras