2018-03-20 01:52:49 +00:00
|
|
|
# Set an output prefix, which is the local directory if not specified
|
2016-04-15 06:42:40 +00:00
|
|
|
PREFIX?=$(shell pwd)
|
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
# Setup name variables for the package/tool
|
|
|
|
NAME := binctr
|
|
|
|
PKG := github.com/genuinetools/$(NAME)
|
2016-04-15 06:42:40 +00:00
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
# Set any default go build tags
|
2018-03-20 02:21:14 +00:00
|
|
|
BUILDTAGS := seccomp apparmor
|
2016-04-15 06:42:40 +00:00
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
# Set the build dir, where built cross-compiled binaries will be output
|
|
|
|
BUILDDIR := ${PREFIX}/cross
|
|
|
|
|
2018-03-20 02:21:14 +00:00
|
|
|
IMAGE := alpine
|
2018-03-20 02:31:34 +00:00
|
|
|
IMAGE_DATA_FILE := image/data.go
|
2018-03-20 02:21:14 +00:00
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
# Populate version variables
|
|
|
|
# Add to compile time flags
|
|
|
|
VERSION := $(shell cat VERSION.txt)
|
2016-04-15 06:42:40 +00:00
|
|
|
GITCOMMIT := $(shell git rev-parse --short HEAD)
|
|
|
|
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
|
|
|
|
ifneq ($(GITUNTRACKEDCHANGES),)
|
2018-03-20 01:52:49 +00:00
|
|
|
GITCOMMIT := $(GITCOMMIT)-dirty
|
2016-04-15 06:42:40 +00:00
|
|
|
endif
|
2018-03-20 02:21:14 +00:00
|
|
|
CTIMEVAR=-X $(PKG)/version.GITCOMMIT=$(GITCOMMIT) -X $(PKG)/version.VERSION=$(VERSION) \
|
2018-03-20 02:31:34 +00:00
|
|
|
-X $(PKG)/image.NAME=$(notdir $(IMAGE)) \
|
|
|
|
-X $(PKG)/image.SHA=$(shell docker inspect --format "{{.Id}}" $(IMAGE))
|
2018-03-20 01:52:49 +00:00
|
|
|
GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)"
|
|
|
|
GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static"
|
2016-04-15 06:42:40 +00:00
|
|
|
|
2018-03-20 02:21:14 +00:00
|
|
|
all: clean build fmt lint test staticcheck vet ## Runs a clean, build, fmt, lint, test, staticcheck, and vet
|
2016-04-15 06:42:40 +00:00
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
.PHONY: build
|
2018-03-20 02:21:14 +00:00
|
|
|
build: $(BUILDDIR)/$(notdir $(IMAGE)) ## Builds a static executable or package
|
2016-04-15 06:42:40 +00:00
|
|
|
|
2018-03-20 02:21:14 +00:00
|
|
|
$(BUILDDIR):
|
|
|
|
@mkdir -p $@
|
2016-04-15 08:54:02 +00:00
|
|
|
|
2018-03-20 02:31:34 +00:00
|
|
|
$(BUILDDIR)/$(notdir $(IMAGE)): $(BUILDDIR) $(IMAGE_DATA_FILE) *.go VERSION.txt
|
2016-04-15 06:42:40 +00:00
|
|
|
@echo "+ $@"
|
2018-03-20 02:21:14 +00:00
|
|
|
CGO_ENABLED=1 go build \
|
2018-03-20 01:52:49 +00:00
|
|
|
-tags "$(BUILDTAGS) static_build" \
|
2018-03-20 02:21:14 +00:00
|
|
|
${GO_LDFLAGS_STATIC} -o $@ .
|
|
|
|
@echo "Static container for $(IMAGE) created at: $@"
|
2016-04-15 08:54:02 +00:00
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
.PHONY: fmt
|
|
|
|
fmt: ## Verifies all files have men `gofmt`ed
|
2016-04-15 06:42:40 +00:00
|
|
|
@echo "+ $@"
|
2018-03-20 01:52:49 +00:00
|
|
|
@gofmt -s -l . | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr
|
2016-04-15 06:42:40 +00:00
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
.PHONY: lint
|
|
|
|
lint: ## Verifies `golint` passes
|
2016-04-15 06:42:40 +00:00
|
|
|
@echo "+ $@"
|
2018-03-20 01:52:49 +00:00
|
|
|
@golint ./... | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr
|
2016-04-15 06:42:40 +00:00
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
.PHONY: test
|
|
|
|
test: ## Runs the go tests
|
2016-04-15 06:42:40 +00:00
|
|
|
@echo "+ $@"
|
2018-03-20 01:52:49 +00:00
|
|
|
@go test -v -tags "$(BUILDTAGS) cgo" $(shell go list ./... | grep -v vendor)
|
2016-04-15 06:42:40 +00:00
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
.PHONY: vet
|
|
|
|
vet: ## Verifies `go vet` passes
|
2016-04-15 06:42:40 +00:00
|
|
|
@echo "+ $@"
|
2018-03-20 01:52:49 +00:00
|
|
|
@go vet $(shell go list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr
|
2016-04-15 08:54:02 +00:00
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
.PHONY: staticcheck
|
|
|
|
staticcheck: ## Verifies `staticcheck` passes
|
2016-04-15 06:42:40 +00:00
|
|
|
@echo "+ $@"
|
2018-03-20 01:52:49 +00:00
|
|
|
@staticcheck $(shell go list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr
|
|
|
|
|
|
|
|
.PHONY: cover
|
|
|
|
cover: ## Runs go test with coverage
|
|
|
|
@echo "" > coverage.txt
|
|
|
|
@for d in $(shell go list ./... | grep -v vendor); do \
|
|
|
|
go test -race -coverprofile=profile.out -covermode=atomic "$$d"; \
|
|
|
|
if [ -f profile.out ]; then \
|
|
|
|
cat profile.out >> coverage.txt; \
|
|
|
|
rm profile.out; \
|
|
|
|
fi; \
|
|
|
|
done;
|
|
|
|
|
|
|
|
.PHONY: bump-version
|
|
|
|
BUMP := patch
|
|
|
|
bump-version: ## Bump the version in the version file. Set BUMP to [ patch | major | minor ]
|
|
|
|
@go get -u github.com/jessfraz/junk/sembump # update sembump tool
|
|
|
|
$(eval NEW_VERSION = $(shell sembump --kind $(BUMP) $(VERSION)))
|
|
|
|
@echo "Bumping VERSION.txt from $(VERSION) to $(NEW_VERSION)"
|
|
|
|
echo $(NEW_VERSION) > VERSION.txt
|
|
|
|
@echo "Updating links to download binaries in README.md"
|
|
|
|
sed -i s/$(VERSION)/$(NEW_VERSION)/g README.md
|
|
|
|
git add VERSION.txt README.md
|
|
|
|
git commit -vsam "Bump version to $(NEW_VERSION)"
|
|
|
|
@echo "Run make tag to create and push the tag for new version $(NEW_VERSION)"
|
|
|
|
|
|
|
|
.PHONY: tag
|
|
|
|
tag: ## Create a new git tag to prepare to build a release
|
|
|
|
git tag -sa $(VERSION) -m "$(VERSION)"
|
|
|
|
@echo "Run git push origin $(VERSION) to push your new tag to GitHub and trigger a travis build."
|
|
|
|
|
2018-03-20 02:21:14 +00:00
|
|
|
.PHONY: image.tar
|
|
|
|
image.tar:
|
|
|
|
docker pull --disable-content-trust=false $(IMAGE)
|
|
|
|
docker export $(shell docker create $(IMAGE) sh) > $@
|
|
|
|
|
2018-03-20 02:31:34 +00:00
|
|
|
.PHONY: $(IMAGE_DATA_FILE)
|
|
|
|
$(IMAGE_DATA_FILE): image.tar
|
2018-03-20 02:21:14 +00:00
|
|
|
GOMAXPROCS=1 go generate
|
|
|
|
|
2018-03-20 01:52:49 +00:00
|
|
|
.PHONY: clean
|
|
|
|
clean: ## Cleanup any build binaries or packages
|
|
|
|
@echo "+ $@"
|
|
|
|
$(RM) $(NAME)
|
|
|
|
$(RM) -r $(BUILDDIR)
|
2018-03-20 02:21:14 +00:00
|
|
|
@sudo $(RM) -r rootfs
|
|
|
|
$(RM) *.tar
|
2018-03-20 02:31:34 +00:00
|
|
|
$(RM) $(IMAGE_DATA_FILE)
|
2018-03-20 02:21:14 +00:00
|
|
|
-@docker rm $(shell docker ps -aq) /dev/null 2>&1
|
2018-03-20 01:52:49 +00:00
|
|
|
|
|
|
|
.PHONY: help
|
|
|
|
help:
|
|
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|