aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-08-02 15:07:53 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-08-02 15:07:53 +0200
commitca6003af1a7e1adb7d45879c2d5038bc05c2bb1a (patch)
tree97a3620b0fc5c7a0ee032fe7d12d37b6303cfb01 /Makefile
parent639870b5083a1e66f4584ec7a5f30492fcdb7168 (diff)
Migrate to modules, refactor Makefile and use Travis for CI
- migrate to Go modules and remove vendor - refactor Makefile - add version package and store version - split extras from the rest - use travis for CI Change-Id: I81b35220653b0f7c9a0fcdd4c527d691ec1e96c1 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile116
1 files changed, 71 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index abc200b..ed6bfd5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,66 +1,92 @@
+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)
-BINAPI_DIR ?= $(shell cd examples/bin_api && pwd)
-VPP_VERSION := $(shell apt-cache show vpp | grep Version: | cut -d' ' -f2-)
+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 binapi generator ${VERSION}"
- go install ./cmd/binapi-generator
+ @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 -v
+ @echo "=> building binapi-generator ${VERSION}"
+ cd cmd/binapi-generator && $(GO) build ${GO_BUILD_ARGS}
examples:
@echo "=> building examples"
- cd examples/simple-client && go build -v
- cd examples/stats-api && go build -v
- cd examples/perf-bench && go build -v
- cd examples/union-example && go build -v
+ cd examples/simple-client && $(GO) build ${GO_BUILD_ARGS} -v
+ cd examples/stats-api && $(GO) build ${GO_BUILD_ARGS} -v
+ cd examples/perf-bench && $(GO) build ${GO_BUILD_ARGS} -v
+ cd examples/union-example && $(GO) build ${GO_BUILD_ARGS} -v
+ cd examples/rpc-service && $(GO) build ${GO_BUILD_ARGS} -v
+
+clean:
+ @echo "=> cleaning"
+ go clean -v ./cmd/...
+ go clean -v ./examples/...
test:
@echo "=> running tests"
- go test -cover ./cmd/...
- go test -cover ./ ./adapter ./core ./api ./codec
+ $(GO) test -v ./cmd/...
+ $(GO) test -v ./ ./api ./adapter ./codec ./core
-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
+lint:
+ @echo "=> running linter"
+ @golint ./... | grep -v vendor | grep -v /binapi/ || true
-clean:
- @echo "=> cleaning"
- rm -f cmd/binapi-generator/binapi-generator
- rm -f examples/perf-bench/perf-bench
- rm -f examples/simple-client/simple-client
- rm -f examples/stats-api/stats-api
- rm -f examples/union-example/union-example
- 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-binapi:
- @echo "=> generating binapi"
- @go generate "${BINAPI_DIR}"
-
-generate: install
+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"
- cd examples && go generate -x ./...
+ $(GO) generate -x ./...
-update-vppapi:
- @echo "=> updating API JSON files using installed VPP ${VPP_VERSION}"
- @cd ${BINAPI_DIR} && find . -type f -name '*.api.json' -exec cp /usr/share/vpp/api/'{}' '{}' \;
- @echo ${VPP_VERSION} > ${BINAPI_DIR}/VPP_VERSION
+extras:
+ @make -C extras
-lint:
- @echo "=> running linter"
- @golint ./... | grep -v vendor | grep -v bin_api || true
.PHONY: all \
- install build examples test \
- extras clean generate lint
+ install build examples clean test lint \
+ generate generate-binapi gen-binapi-docker \
+ extras