mirror of
https://github.com/cheat/cheat.git
synced 2024-11-17 01:18:29 +01:00
3786ac96a5
* makefile wip * feat: adds Makefile Adds a `Makefile` for managing build-related tasks. * chore: updates dependencies * chore: updates dependencies * chore: updates bin scripts - Removes `build_release.sh` - Places deprecation notice in `build_devel.sh`, as its purpose has been superceded by the `Makefile`. * chore: updates bin scripts - Removes `build_release.sh` - Places deprecation notice in `build_devel.sh`, as its purpose has been superceded by the `Makefile`. * fix: Makefile Makes several corrections and improvements to the `Makefile`: - Previously, the `ifeq` rules were not behaving as intended, due to false assumptions regarding how `make` fundamentally behaves. Malfunctioning imperative-style programming has been replaced with declarative rules to repair this issue. - Previously, all release executables were zipped after compilation. In order to spare non-Windows users from (possibly) needing to install a package to unzip the executables, all non-Windows binaries are now compressed with `gzip`. (Windows executables are still compressed with `zip`.) - Removes a bit of needlessly verbosity in several rules and paths. * chore: updates dependencies * chore: bumps version to 3.3.1
150 lines
3.2 KiB
Makefile
150 lines
3.2 KiB
Makefile
# paths
|
|
makefile := $(realpath $(lastword $(MAKEFILE_LIST)))
|
|
cmd_dir := ./cmd/cheat
|
|
dist_dir := ./dist
|
|
|
|
# executables
|
|
CAT := cat
|
|
COLUMN := column
|
|
CTAGS := ctags
|
|
GO := go
|
|
GREP := grep
|
|
GZIP := gzip --best
|
|
LINT := revive
|
|
MKDIR := mkdir -p
|
|
RM := rm
|
|
SCC := scc
|
|
SED := sed
|
|
SORT := sort
|
|
ZIP := zip -m
|
|
|
|
# build flags
|
|
BUILD_FLAGS := -ldflags="-s -w" -mod vendor
|
|
GOBIN :=
|
|
|
|
# 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
|
|
|
|
## build: builds an executable for your architecture
|
|
.PHONY: build
|
|
build: $(dist_dir)
|
|
$(GO) build $(BUILD_FLAGS) -o $(dist_dir)/cheat $(cmd_dir)
|
|
|
|
## build-release: builds release executables
|
|
.PHONY: build-release
|
|
build-release: $(releases)
|
|
|
|
# cheat-darwin-amd64
|
|
$(dist_dir)/cheat-darwin-amd64: prepare
|
|
GOARCH=amd64 GOOS=darwin \
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@
|
|
|
|
# cheat-linux-amd64
|
|
$(dist_dir)/cheat-linux-amd64: prepare
|
|
GOARCH=amd64 GOOS=linux \
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@
|
|
|
|
# cheat-linux-arm5
|
|
$(dist_dir)/cheat-linux-arm5: prepare
|
|
GOARCH=arm GOOS=linux GOARM=5 \
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@
|
|
|
|
# cheat-linux-arm6
|
|
$(dist_dir)/cheat-linux-arm6: prepare
|
|
GOARCH=arm GOOS=linux GOARM=6 \
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@
|
|
|
|
# cheat-linux-arm7
|
|
$(dist_dir)/cheat-linux-arm7: prepare
|
|
GOARCH=arm GOOS=linux GOARM=7 \
|
|
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@
|
|
|
|
# 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)
|
|
|
|
.PHONY: generate
|
|
generate:
|
|
$(GO) generate $(cmd_dir)
|
|
|
|
## install: builds and installs cheat on your PATH
|
|
.PHONY: install
|
|
install:
|
|
$(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:
|
|
$(RM) ./tags
|
|
|
|
## 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:
|
|
$(CTAGS) -R . --exclude=./vendor
|
|
|
|
## vendor: downloads, tidies, and verifies dependencies
|
|
.PHONY: vendor
|
|
vendor:
|
|
$(GO) mod vendor && $(GO) mod tidy && $(GO) mod verify
|
|
|
|
## fmt: runs go fmt
|
|
.PHONY: fmt
|
|
fmt:
|
|
$(GO) fmt ./...
|
|
|
|
## lint: lints go source files
|
|
.PHONY: lint
|
|
lint: vendor
|
|
$(LINT) -exclude vendor/... ./...
|
|
|
|
## vet: vets go source files
|
|
.PHONY: vet
|
|
vet:
|
|
$(GO) vet ./...
|
|
|
|
## test: runs unit-tests
|
|
.PHONY: test
|
|
test:
|
|
$(GO) test ./...
|
|
|
|
## check: formats, lints, vets, vendors, and run unit-tests
|
|
.PHONY: check
|
|
check: | vendor fmt lint vet test
|
|
|
|
.PHONY: prepare
|
|
prepare: | $(dist_dir) clean generate vendor fmt lint vet test
|
|
|
|
## help: displays this help text
|
|
.PHONY: help
|
|
help:
|
|
@$(CAT) $(makefile) | \
|
|
$(SORT) | \
|
|
$(GREP) "^##" | \
|
|
$(SED) 's/## //g' | \
|
|
$(COLUMN) -t -s ':'
|