[#3] Simplify Makefile

Signed-off-by: Stanislav Bogatyrev <s.bogatyrev@yadro.com>
This commit is contained in:
Stanislav Bogatyrev 2023-02-10 15:47:06 +03:00 committed by fyrchik
parent 9f80f99aed
commit a5347ee68e
3 changed files with 85 additions and 57 deletions

38
.gitignore vendored
View file

@ -1,15 +1,27 @@
# Binaries for programs and plugins # IDE
*.exe .idea
*.exe~ .vscode
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Vendoring
vendor vendor
tzsum
# tempfiles
.DS_Store
*~
.cache
temp
tmp
# binary
bin/
release/
# coverage
coverage.txt
coverage.html
# testing
cmd/test
/plugins/
testfile

View file

@ -1,56 +1,61 @@
B=\033[0;1m #!/usr/bin/make -f
G=\033[0;92m SHELL = bash
R=\033[0m
NAME ?= homo REPO ?= $(shell go list -m)
VERSION ?= $(shell git describe --tags --dirty --match "v*" --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")
.PHONY: help attach auto up down deps BIN = bin
DIRS = $(BIN)
# Show this help prompt # List of binaries to build.
help: CMDS = $(notdir $(basename $(wildcard cmd/*)))
@echo ' Usage:' BINS = $(addprefix $(BIN)/, $(CMDS))
@echo ''
@echo ' make <target>'
@echo ''
@echo ' Targets:'
@echo ''
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort | uniq
# Install dependencies .PHONY: all help clean
deps:
@go mod tidy -v
@go mod vendor
# Auto Tillich-Zémor hasher demo # To build a specific binary, use it's name prefix with bin/ as a target
auto: down deps # For example `make bin/tzsum` will build only storage node binary
@echo "\n${B}${G}build container${R}\n" # Just `make` will build all possible binaries
@time docker build -t poc-demo . all: $(DIRS) $(BINS)
@echo "\n${B}${G}Bootup container:${R}\n"
@time docker run -d --rm -it --name hash-demo poc-demo:latest sh
@bash ./auto.sh
@make down
# Stop demo container # help target
down: include help.mk
@echo "\n${B}${G}Stop container${R}\n"
@docker kill hash-demo || true
@docker rm -f hash-demo || true
# Run Tillich-Zémor hasher demo $(BINS): $(DIRS) dep
up: down deps @echo "⇒ Build $@"
@echo "\n${B}${G}build container${R}\n" CGO_ENABLED=0 \
@time docker build -t poc-demo . go build -v -trimpath \
@echo "\n${B}${G}enter inside container:${R}\n" -ldflags "-X $(REPO)/misc.Version=$(VERSION)" \
@time docker run --rm -it --name hash-demo poc-demo:latest sh -o $@ ./cmd/$(notdir $@)
# Attach to existing container $(DIRS):
attach: @echo "⇒ Ensure dir: $@"
@echo "\n${B}${G} attach to hash-container ${R}\n" @mkdir -p $@
@time docker exec -it --name hash-demo /bin/sh
# Test code with all backends # Pull go dependencies
dep:
@printf "⇒ Download requirements: "
CGO_ENABLED=0 \
go mod download && echo OK
@printf "⇒ Tidy requirements : "
CGO_ENABLED=0 \
go mod tidy -v && echo OK
# Run Unit Test with go test
test: test:
go test ./... @echo "⇒ Running go test"
@go test ./...
# Run Unit Test with go test
test.generic: test.generic:
go test ./... --tags=generic @echo "⇒ Running go test with generic tag"
@go test ./... --tags=generic
# Print version
version:
@echo $(VERSION)
clean:
rm -rf vendor
rm -rf .cache
rm -rf $(BIN)

11
help.mk Normal file
View file

@ -0,0 +1,11 @@
.PHONY: help
# Show this help prompt
help:
@echo ' Usage:'
@echo ''
@echo ' make <target>'
@echo ''
@echo ' Targets:'
@echo ''
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort | uniq