my-log/Makefile

50 lines
1.1 KiB
Makefile

SOURCES = $(wildcard *.go) $(wildcard **/*.go)
OUT=my-log
GOBIN=$(shell go env GOBIN)
COVEROUT=cover.out
COVERHTML=cover.html
OPEN=xdg-open
OS=$(shell uname -s)
ifeq ($(OS),Darwin)
OPEN=open
endif
.PHONY: help
help: ## Show help for documented recipes
@echo "Make recipes:"
@echo
@grep -E '^[a-zA-Z0-9_#-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: clean
clean: ## Removes temporary and build files
rm -v $(COVEROUT) $(COVERHTML) $(OUT) || true
.PHONY: fmt ## Runs go fmt
fmt: $(SOURCES) ## Runs go fmt
go fmt ./...
.PHONY: test
test: ## Test application and generate coverage report
$(MAKE) clean
$(MAKE) $(COVEROUT)
$(COVEROUT): $(SOURCES)
$(MAKE) fmt
go test ./... -race -cover -coverprofile $@
$(COVERHTML): $(COVEROUT)
go tool cover -html=$< -o $@
.PHONY: report
report: $(COVERHTML) ## Generate a coverage report
.PHONY: open-report
open-report: $(COVERHTML) ## Open the coverage report in the default browser
$(OPEN) $<
.PHONY: build
build: $(OUT) ## Builds the application
$(OUT): $(SOURCES) fmt
go build -o $@