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
|
2020-11-08 00:47:24 +01:00
|
|
|
DOCKER := docker
|
2020-01-20 18:34:48 +01:00
|
|
|
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
|
2020-03-25 01:19:33 +01:00
|
|
|
MAN := man
|
2020-01-20 18:34:48 +01:00
|
|
|
MKDIR := mkdir -p
|
2020-03-25 01:19:33 +01:00
|
|
|
PANDOC := pandoc
|
2020-01-20 18:34:48 +01:00
|
|
|
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
|
|
|
|
2020-11-08 00:47:24 +01:00
|
|
|
docker_image := cheat-devel:latest
|
|
|
|
|
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 \
|
2020-05-15 02:02:35 +02:00
|
|
|
$(dist_dir)/cheat-linux-386 \
|
2020-01-25 20:44:51 +01:00
|
|
|
$(dist_dir)/cheat-linux-amd64 \
|
|
|
|
$(dist_dir)/cheat-linux-arm5 \
|
|
|
|
$(dist_dir)/cheat-linux-arm6 \
|
|
|
|
$(dist_dir)/cheat-linux-arm7 \
|
2021-06-09 02:55:15 +02:00
|
|
|
$(dist_dir)/cheat-linux-arm64 \
|
2020-01-25 20:44:51 +01:00
|
|
|
$(dist_dir)/cheat-windows-amd64.exe
|
2020-01-20 18:34:48 +01:00
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## build: build an executable for your architecture
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: build
|
2022-08-26 19:09:40 +02:00
|
|
|
build: $(dist_dir) | clean generate fmt lint vet vendor man
|
2020-01-20 18:34:48 +01:00
|
|
|
$(GO) build $(BUILD_FLAGS) -o $(dist_dir)/cheat $(cmd_dir)
|
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## build-release: build release executables
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: build-release
|
2020-01-25 20:44:51 +01:00
|
|
|
build-release: $(releases)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
2020-05-15 02:02:35 +02:00
|
|
|
# cheat-linux-386
|
|
|
|
$(dist_dir)/cheat-linux-386: prepare
|
|
|
|
GOARCH=386 GOOS=linux \
|
|
|
|
$(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
|
2021-06-06 22:40:43 +02:00
|
|
|
|
|
|
|
# cheat-linux-arm64
|
|
|
|
$(dist_dir)/cheat-linux-arm64: prepare
|
|
|
|
GOARCH=arm64 GOOS=linux \
|
|
|
|
$(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 \
|
2022-07-04 18:34:06 +02:00
|
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(ZIP) $@.zip $@ -j
|
2020-01-25 20:44:51 +01:00
|
|
|
|
|
|
|
# ./dist
|
|
|
|
$(dist_dir):
|
|
|
|
$(MKDIR) $(dist_dir)
|
2020-01-20 18:34:48 +01:00
|
|
|
|
|
|
|
.PHONY: generate
|
|
|
|
generate:
|
|
|
|
$(GO) generate $(cmd_dir)
|
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## install: build and install cheat on your PATH
|
2020-01-20 18:34:48 +01:00
|
|
|
.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)
|
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## clean: remove compiled executables
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: clean
|
|
|
|
clean: $(dist_dir)
|
2022-08-26 19:09:40 +02:00
|
|
|
$(RM) -f $(dist_dir)/* $(cmd_dir)/str_config.go $(cmd_dir)/str_usage.go
|
2020-01-20 18:34:48 +01:00
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## distclean: remove the tags file
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: distclean
|
|
|
|
distclean:
|
2020-01-29 15:36:59 +01:00
|
|
|
$(RM) -f tags
|
2020-11-08 00:47:24 +01:00
|
|
|
@$(DOCKER) image rm -f $(docker_image)
|
2020-01-20 18:34:48 +01:00
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## setup: install revive (linter) and scc (sloc tool)
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: setup
|
|
|
|
setup:
|
|
|
|
GO111MODULE=off $(GO) get -u github.com/boyter/scc github.com/mgechev/revive
|
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## sloc: count "semantic lines of code"
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: sloc
|
|
|
|
sloc:
|
|
|
|
$(SCC) --exclude-dir=vendor
|
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## tags: build a tags file
|
2020-01-20 18:34:48 +01:00
|
|
|
.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
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## man: build a man page
|
|
|
|
# NB: pandoc may not be installed, so we're ignoring this error on failure
|
|
|
|
.PHONY: man
|
|
|
|
man:
|
|
|
|
-$(PANDOC) -s -t man doc/cheat.1.md -o doc/cheat.1
|
|
|
|
|
|
|
|
## vendor: download, tidy, and verify dependencies
|
2020-01-20 18:34:48 +01:00
|
|
|
.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
|
|
|
|
|
2020-11-27 15:50:11 +01:00
|
|
|
## vendor-update: update vendored dependencies
|
|
|
|
vendor-update:
|
2021-04-28 18:35:32 +02:00
|
|
|
$(GO) get -t -u ./... && $(GO) mod vendor
|
2020-11-27 15:50:11 +01:00
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## fmt: run go fmt
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: fmt
|
|
|
|
fmt:
|
2020-01-25 20:44:51 +01:00
|
|
|
$(GO) fmt ./...
|
2020-01-20 18:34:48 +01:00
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## lint: lint go source files
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: lint
|
2020-01-25 20:44:51 +01:00
|
|
|
lint: vendor
|
|
|
|
$(LINT) -exclude vendor/... ./...
|
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## vet: vet go source files
|
2020-01-25 20:44:51 +01:00
|
|
|
.PHONY: vet
|
|
|
|
vet:
|
|
|
|
$(GO) vet ./...
|
2020-01-20 18:34:48 +01:00
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## test: run unit-tests
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: test
|
|
|
|
test:
|
2020-01-25 20:44:51 +01:00
|
|
|
$(GO) test ./...
|
2020-01-20 18:34:48 +01:00
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## coverage: generate a test coverage report
|
2020-01-31 20:01:57 +01:00
|
|
|
.PHONY: coverage
|
|
|
|
coverage:
|
|
|
|
$(GO) test ./... -coverprofile=$(TMPDIR)/cheat-coverage.out && \
|
|
|
|
$(GO) tool cover -html=$(TMPDIR)/cheat-coverage.out
|
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## check: format, lint, vet, vendor, 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
|
|
|
|
2020-11-08 00:47:24 +01:00
|
|
|
## docker-setup: create a docker image for use during development
|
|
|
|
.PHONY: docker-setup
|
|
|
|
docker-setup:
|
|
|
|
$(DOCKER) build -t $(docker_image) -f Dockerfile .
|
|
|
|
|
|
|
|
## docker-sh: shell into the docker development container
|
|
|
|
.PHONY: docker-sh
|
|
|
|
docker-sh:
|
|
|
|
$(DOCKER) run -v $(shell pwd):/app -ti $(docker_image) /bin/ash
|
|
|
|
|
2020-03-25 01:19:33 +01:00
|
|
|
## help: display this help text
|
2020-01-20 18:34:48 +01:00
|
|
|
.PHONY: help
|
|
|
|
help:
|
|
|
|
@$(CAT) $(makefile) | \
|
|
|
|
$(SORT) | \
|
|
|
|
$(GREP) "^##" | \
|
|
|
|
$(SED) 's/## //g' | \
|
|
|
|
$(COLUMN) -t -s ':'
|