2020-01-20 18:34:48 +01:00
|
|
|
# paths
|
|
|
|
makefile := $(realpath $(lastword $(MAKEFILE_LIST)))
|
2020-01-25 20:44:51 +01:00
|
|
|
cmd_dir := ./cmd/cheat
|
|
|
|
dist_dir := ./dist
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
# executables
|
|
|
|
CAT := cat
|
|
|
|
COLUMN := column
|
|
|
|
CTAGS := ctags
|
|
|
|
GO := go
|
|
|
|
GREP := grep
|
2020-01-25 20:44:51 +01:00
|
|
|
GZIP := gzip --best
|
2020-01-20 18:34:48 +01:00
|
|
|
LINT := revive
|
|
|
|
MKDIR := mkdir -p
|
|
|
|
RM := rm
|
|
|
|
SCC := scc
|
|
|
|
SED := sed
|
|
|
|
SORT := sort
|
2020-01-20 19:54:53 +01:00
|
|
|
ZIP := zip -m
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
# build flags
|
2020-01-29 14:50:47 +01:00
|
|
|
BUILD_FLAGS := -ldflags="-s -w" -mod vendor -trimpath
|
2020-01-20 18:34:48 +01:00
|
|
|
GOBIN :=
|
2020-01-31 20:01:57 +01:00
|
|
|
TMPDIR := /tmp
|
2020-01-20 18:34:48 +01:00
|
|
|
|
2020-01-25 20:44:51 +01:00
|
|
|
# release binaries
|
|
|
|
releases := \
|
|
|
|
$(dist_dir)/cheat-darwin-amd64 \
|
|
|
|
$(dist_dir)/cheat-linux-amd64 \
|
|
|
|
$(dist_dir)/cheat-linux-arm5 \
|
|
|
|
$(dist_dir)/cheat-linux-arm6 \
|
|
|
|
$(dist_dir)/cheat-linux-arm7 \
|
|
|
|
$(dist_dir)/cheat-windows-amd64.exe
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
## build: builds an executable for your architecture
|
|
|
|
.PHONY: build
|
2020-02-27 01:21:07 +01:00
|
|
|
build: $(dist_dir) clean vendor generate
|
2020-01-20 18:34:48 +01:00
|
|
|
$(GO) build $(BUILD_FLAGS) -o $(dist_dir)/cheat $(cmd_dir)
|
|
|
|
|
|
|
|
## build-release: builds release executables
|
|
|
|
.PHONY: build-release
|
2020-01-25 20:44:51 +01:00
|
|
|
build-release: $(releases)
|
|
|
|
|
2020-01-29 14:50:47 +01:00
|
|
|
## ci: builds a "release" executable for the current architecture (used in ci)
|
|
|
|
.PHONY: ci
|
|
|
|
ci: | setup prepare build
|
|
|
|
|
2020-01-25 20:44:51 +01:00
|
|
|
# cheat-darwin-amd64
|
|
|
|
$(dist_dir)/cheat-darwin-amd64: prepare
|
|
|
|
GOARCH=amd64 GOOS=darwin \
|
2020-01-29 15:11:06 +01:00
|
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
|
2020-01-25 20:44:51 +01:00
|
|
|
|
|
|
|
# cheat-linux-amd64
|
|
|
|
$(dist_dir)/cheat-linux-amd64: prepare
|
|
|
|
GOARCH=amd64 GOOS=linux \
|
2020-01-29 15:11:06 +01:00
|
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
|
2020-01-25 20:44:51 +01:00
|
|
|
|
|
|
|
# cheat-linux-arm5
|
|
|
|
$(dist_dir)/cheat-linux-arm5: prepare
|
|
|
|
GOARCH=arm GOOS=linux GOARM=5 \
|
2020-01-29 15:11:06 +01:00
|
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
|
2020-01-25 20:44:51 +01:00
|
|
|
|
|
|
|
# cheat-linux-arm6
|
|
|
|
$(dist_dir)/cheat-linux-arm6: prepare
|
|
|
|
GOARCH=arm GOOS=linux GOARM=6 \
|
2020-01-29 15:11:06 +01:00
|
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
|
2020-01-25 20:44:51 +01:00
|
|
|
|
|
|
|
# cheat-linux-arm7
|
|
|
|
$(dist_dir)/cheat-linux-arm7: prepare
|
|
|
|
GOARCH=arm GOOS=linux GOARM=7 \
|
2020-01-29 15:11:06 +01:00
|
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
|
2020-01-25 20:44:51 +01:00
|
|
|
|
|
|
|
# cheat-windows-amd64
|
|
|
|
$(dist_dir)/cheat-windows-amd64.exe: prepare
|
|
|
|
GOARCH=amd64 GOOS=windows \
|
|
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(ZIP) $@.zip $@
|
|
|
|
|
|
|
|
# ./dist
|
|
|
|
$(dist_dir):
|
|
|
|
$(MKDIR) $(dist_dir)
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
.PHONY: generate
|
|
|
|
generate:
|
|
|
|
$(GO) generate $(cmd_dir)
|
|
|
|
|
|
|
|
## install: builds and installs cheat on your PATH
|
|
|
|
.PHONY: install
|
2020-02-27 01:21:07 +01:00
|
|
|
install: build
|
2020-01-20 18:34:48 +01:00
|
|
|
$(GO) install $(BUILD_FLAGS) $(GOBIN) $(cmd_dir)
|
|
|
|
|
|
|
|
## clean: removes compiled executables
|
|
|
|
.PHONY: clean
|
|
|
|
clean: $(dist_dir)
|
|
|
|
$(RM) -f $(dist_dir)/*
|
|
|
|
|
|
|
|
## distclean: removes the tags file
|
|
|
|
.PHONY: distclean
|
|
|
|
distclean:
|
2020-01-29 15:36:59 +01:00
|
|
|
$(RM) -f tags
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
## setup: installs revive (linter) and scc (sloc tool)
|
|
|
|
.PHONY: setup
|
|
|
|
setup:
|
|
|
|
GO111MODULE=off $(GO) get -u github.com/boyter/scc github.com/mgechev/revive
|
|
|
|
|
|
|
|
## sloc: counts "semantic lines of code"
|
|
|
|
.PHONY: sloc
|
|
|
|
sloc:
|
|
|
|
$(SCC) --exclude-dir=vendor
|
|
|
|
|
|
|
|
## tags: builds a tags file
|
|
|
|
.PHONY: tags
|
|
|
|
tags:
|
2020-01-29 15:36:59 +01:00
|
|
|
$(CTAGS) -R --exclude=vendor --languages=go
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
## vendor: downloads, tidies, and verifies dependencies
|
|
|
|
.PHONY: vendor
|
2020-01-25 20:44:51 +01:00
|
|
|
vendor:
|
2020-01-20 18:34:48 +01:00
|
|
|
$(GO) mod vendor && $(GO) mod tidy && $(GO) mod verify
|
|
|
|
|
|
|
|
## fmt: runs go fmt
|
|
|
|
.PHONY: fmt
|
|
|
|
fmt:
|
2020-01-25 20:44:51 +01:00
|
|
|
$(GO) fmt ./...
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
## lint: lints go source files
|
|
|
|
.PHONY: lint
|
2020-01-25 20:44:51 +01:00
|
|
|
lint: vendor
|
|
|
|
$(LINT) -exclude vendor/... ./...
|
|
|
|
|
|
|
|
## vet: vets go source files
|
|
|
|
.PHONY: vet
|
|
|
|
vet:
|
|
|
|
$(GO) vet ./...
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
## test: runs unit-tests
|
|
|
|
.PHONY: test
|
|
|
|
test:
|
2020-01-25 20:44:51 +01:00
|
|
|
$(GO) test ./...
|
2020-01-20 18:34:48 +01:00
|
|
|
|
2020-01-31 20:01:57 +01:00
|
|
|
## coverage: generates a test coverage report
|
|
|
|
.PHONY: coverage
|
|
|
|
coverage:
|
|
|
|
$(GO) test ./... -coverprofile=$(TMPDIR)/cheat-coverage.out && \
|
|
|
|
$(GO) tool cover -html=$(TMPDIR)/cheat-coverage.out
|
|
|
|
|
2020-01-25 20:44:51 +01:00
|
|
|
## check: formats, lints, vets, vendors, and run unit-tests
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: check
|
2020-01-25 20:44:51 +01:00
|
|
|
check: | vendor fmt lint vet test
|
|
|
|
|
|
|
|
.PHONY: prepare
|
|
|
|
prepare: | $(dist_dir) clean generate vendor fmt lint vet test
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
## help: displays this help text
|
|
|
|
.PHONY: help
|
|
|
|
help:
|
|
|
|
@$(CAT) $(makefile) | \
|
|
|
|
$(SORT) | \
|
|
|
|
$(GREP) "^##" | \
|
|
|
|
$(SED) 's/## //g' | \
|
|
|
|
$(COLUMN) -t -s ':'
|