|
| 1 | +# REPO |
| 2 | +REPO?=github.com/codedellemc/infrakit.rackhd |
| 3 | + |
| 4 | +# Set an output prefix, which is the local directory if not specified |
| 5 | +PREFIX?=$(shell pwd -L) |
| 6 | + |
| 7 | +# Used to populate version variable in main package. |
| 8 | +VERSION?=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always) |
| 9 | +REVISION?=$(shell git rev-list -1 HEAD) |
| 10 | + |
| 11 | +# Allow turning off function inlining and variable registerization |
| 12 | +ifeq (${DISABLE_OPTIMIZATION},true) |
| 13 | + GO_GCFLAGS=-gcflags "-N -l" |
| 14 | + VERSION:="$(VERSION)-noopt" |
| 15 | +endif |
| 16 | + |
| 17 | +.PHONY: clean all fmt vet lint build test containers get-tools |
| 18 | +.DEFAULT: all |
| 19 | +all: clean fmt vet lint build test |
| 20 | + |
| 21 | +ci: fmt vet lint coverage |
| 22 | + |
| 23 | +AUTHORS: .mailmap .git/HEAD |
| 24 | + git log --format='%aN <%aE>' | sort -fu > $@ |
| 25 | + |
| 26 | +# Package list |
| 27 | +PKGS_AND_MOCKS := $(shell go list ./... | grep -v ^${REPO}/vendor/) |
| 28 | +PKGS := $(shell echo $(PKGS_AND_MOCKS) | tr ' ' '\n' | grep -v /mock$) |
| 29 | + |
| 30 | +vet: |
| 31 | + @echo "+ $@" |
| 32 | + @go vet $(PKGS) |
| 33 | + |
| 34 | +fmt: |
| 35 | + @echo "+ $@" |
| 36 | + @test -z "$$(gofmt -s -l . 2>&1 | grep -v ^vendor/ | tee /dev/stderr)" || \ |
| 37 | + (echo >&2 "+ please format Go code with 'gofmt -s', or use 'make fmt-save'" && false) |
| 38 | + |
| 39 | +fmt-save: |
| 40 | + @echo "+ $@" |
| 41 | + @gofmt -s -l . 2>&1 | grep -v ^vendor/ | xargs gofmt -s -l -w |
| 42 | + |
| 43 | +lint: |
| 44 | + @echo "+ $@" |
| 45 | + $(if $(shell which golint || echo ''), , \ |
| 46 | + $(error Please install golint: `go get -u github.com/golang/lint/golint`)) |
| 47 | + @test -z "$$(golint ./... 2>&1 | grep -v ^vendor/ | grep -v mock/ | tee /dev/stderr)" |
| 48 | + |
| 49 | +build: |
| 50 | + @echo "+ $@" |
| 51 | + @go build ${GO_LDFLAGS} $(PKGS) |
| 52 | + |
| 53 | +clean: |
| 54 | + @echo "+ $@" |
| 55 | + rm -rf build |
| 56 | + mkdir -p build |
| 57 | + |
| 58 | +define build_binary |
| 59 | + go build -o build/$(1) \ |
| 60 | + -ldflags "-X github.com/codedellemc/infrakit.rackhd/plugin.Version=$(VERSION) -X github.com/codedellemc/infrakit.rackhd/plugin.Revision=$(REVISION)" $(2) |
| 61 | +endef |
| 62 | +binaries: clean build-binaries |
| 63 | +build-binaries: |
| 64 | + @echo "+ $@" |
| 65 | +ifneq (,$(findstring .m,$(VERSION))) |
| 66 | + @echo "\nWARNING - repository contains uncommitted changes, tagging binaries as dirty\n" |
| 67 | +endif |
| 68 | + |
| 69 | + $(call build_binary,infrakit-instance-rackhd,github.com/codedellemc/infrakit.rackhd/plugin/instance/cmd) |
| 70 | + |
| 71 | + |
| 72 | +install: |
| 73 | + @echo "+ $@" |
| 74 | + @go install ${GO_LDFLAGS} $(PKGS) |
| 75 | + |
| 76 | +generate: |
| 77 | + @echo "+ $@" |
| 78 | + @go generate -x $(PKGS_AND_MOCKS) |
| 79 | + |
| 80 | +test: |
| 81 | + @echo "+ $@" |
| 82 | + @go test -test.short -race -v $(PKGS) |
| 83 | + |
| 84 | +coverage: |
| 85 | + @echo "+ $@" |
| 86 | + @for pkg in $(PKGS); do \ |
| 87 | + go test -test.short -coverprofile="../../../$$pkg/coverage.txt" $${pkg} || exit 1; \ |
| 88 | + done |
| 89 | + |
| 90 | +test-full: |
| 91 | + @echo "+ $@" |
| 92 | + @go test -race $(PKGS) |
| 93 | + |
| 94 | +get-tools: |
| 95 | + @echo "+ $@" |
| 96 | + @go get -u \ |
| 97 | + github.com/golang/lint/golint \ |
| 98 | + github.com/wfarner/blockcheck \ |
| 99 | + github.com/rancher/trash |
| 100 | + |
| 101 | +# Current working environment. Set these explicitly if you want to cross-compile |
| 102 | +# in the build container (see the build-in-container target): |
| 103 | +GOOS?=$(shell go env GOOS) |
| 104 | +GOARCH?=$(shell go env GOARCH) |
| 105 | +DOCKER_BUILD_FLAGS?=--no-cache --pull |
| 106 | +build-in-container: |
| 107 | + @echo "+ $@" |
| 108 | + @docker build ${DOCKER_BUILD_FLAGS} -t infrakit-build -f ${CURDIR}/dockerfiles/Dockerfile.build . |
| 109 | + @docker run --rm \ |
| 110 | + -e GOOS=${GOOS} -e GOARCCH=${GOARCH} -e DOCKER_CLIENT_VERSION=${DOCKER_CLIENT_VERSION} \ |
| 111 | + -v ${CURDIR}/build:/go/src/${REPO}/build \ |
| 112 | + infrakit-build |
| 113 | + |
| 114 | +# For packaging as Docker container images. Set the environment variables DOCKER_PUSH, DOCKER_TAG_LATEST |
| 115 | +# if also push to remote repo. You must have access to the remote repo. |
| 116 | +DOCKER_IMAGE?=infrakit/rackhd |
| 117 | +DOCKER_TAG?=dev |
| 118 | +build-docker: |
| 119 | + @echo "+ $@" |
| 120 | + GOOS=linux GOARCH=amd64 make build-in-container |
| 121 | + @docker build ${DOCKER_BUILD_FLAGS} \ |
| 122 | + -t ${DOCKER_IMAGE}:${DOCKER_TAG} \ |
| 123 | + -f ${CURDIR}/dockerfiles/Dockerfile.bundle . |
| 124 | +ifeq (${DOCKER_PUSH},true) |
| 125 | + @docker push ${DOCKER_IMAGE}:${DOCKER_TAG} |
| 126 | +ifeq (${DOCKER_TAG_LATEST},true) |
| 127 | + @docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest |
| 128 | + @docker push ${DOCKER_IMAGE}:latest |
| 129 | +endif |
| 130 | +endif |
0 commit comments