From 5a6424839dba2cee534acfb9a9c90df6da2624be Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 13 Dec 2019 16:09:11 -0800 Subject: [PATCH] Improve the Makefile Signed-off-by: Chris Cummer --- Makefile | 64 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index cc11d98b..5f7e1843 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,20 @@ -.PHONY: build contrib_check coverage install isntall binary_msg lint run size test uninstall +.PHONY: build clean contrib_check coverage help install isntall binary_msg lint run size test uninstall # detect GOPATH if not set ifndef $(GOPATH) - $(info GOPATH is not set, autodetecting..) - TESTPATH := $(dir $(abspath ../../..)) - DIRS := bin pkg src - # create a ; separated line of tests and pass it to shell - MISSING_DIRS := $(shell $(foreach entry,$(DIRS),test -d "$(TESTPATH)$(entry)" || echo "$(entry)";)) - ifeq ($(MISSING_DIRS),) - $(info Found GOPATH: $(TESTPATH)) - export GOPATH := $(TESTPATH) - else - $(info ..missing dirs "$(MISSING_DIRS)" in "$(TESTDIR)") - $(info GOPATH autodetection failed) - endif + $(info GOPATH is not set, autodetecting..) + TESTPATH := $(dir $(abspath ../../..)) + DIRS := bin pkg src + + # create a ; separated line of tests and pass it to shell + MISSING_DIRS := $(shell $(foreach entry,$(DIRS),test -d "$(TESTPATH)$(entry)" || echo "$(entry)";)) + ifeq ($(MISSING_DIRS),) + $(info Found GOPATH: $(TESTPATH)) + export GOPATH := $(TESTPATH) + else + $(info ..missing dirs "$(MISSING_DIRS)" in "$(TESTDIR)") + $(info GOPATH autodetection failed) + endif endif # Set go modules to on and use GoCenter for immutable modules @@ -23,43 +24,68 @@ export GOPROXY = https://proxy.golang.org,direct # Determines the path to this Makefile THIS_FILE := $(lastword $(MAKEFILE_LIST)) +APP=wtfutil + binary_msg: @echo "Install path: " +# -------------------- Actions -------------------- # + +## build: builds a local version build: - go build -o bin/wtfutil + go build -o bin/${APP} @$(MAKE) -f $(THIS_FILE) binary_msg +## clean: removes old build cruft +clean: + rm -rf ./dist + rm -rf ./bin/${APP} + +## contrib-check: checks for any contributors who have not been given due credit contrib_check: npx all-contributors-cli check +## coverage: figures out and displays test code coverage coverage: go test -coverprofile=coverage.out ./... go tool cover -html=coverage.out +## help: prints this help message +help: + @echo "Usage: \n" + @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' + +## isntall: an alias for 'install' isntall: @$(MAKE) -f $(THIS_FILE) install +## install: installs a local version of the app install: - @echo "Installing wtfutil..." + @echo "Installing ${APP}..." @go clean @go install -ldflags="-s -w -X main.version=$(shell git describe --always --abbrev=6) -X main.date=$(shell date +%FT%T%z)" - @mv ~/go/bin/wtf ~/go/bin/wtfutil + @mv ~/go/bin/wtf ~/go/bin/${APP} @$(MAKE) -f $(THIS_FILE) binary_msg - @which wtfutil || echo "Could not find wtfutil in PATH" && exit 0 + @which ${APP} || echo "Could not find ${APP} in PATH" && exit 0 +## lint: runs a number of code quality checks against the source code lint: + go vet ./... structcheck ./... varcheck ./... +## run: executes the locally-installed version run: build - bin/wtfutil + bin/${APP} +## size: displays the lines of code (LoC) count size: loc --exclude _sample_configs/ _site/ docs/ Makefile *.md +## test: runs the test suite test: build go test ./... +## uninstall: uninstals a locally-installed version uninstall: - @rm ~/go/bin/wtfutil + @rm ~/go/bin/${APP}