diff --git a/Makefile b/Makefile index 68d44e6..cc7a23a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,13 @@ -.POSIX: + +# https://tech.davis-hansson.com/p/make/ +SHELL := bash +.ONESHELL: +.SHELLFLAGS := -eux -o pipefail -c +.DELETE_ON_ERROR: +.SILENT: +.DEFAULT_GOAL := all +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules MIFLORA_ADDR?=00:00:00:00:00:00 MIFLORAD_VERSION?=master @@ -7,49 +16,64 @@ RUN_COMMAND=miflorad RUN_OPTIONS=$(MIFLORA_ADDR) .PHONY: all -all: clean build test +all: clean build test ## Run clean, build and test (default goal) .PHONY: run -run: clean build test +run: clean build test ## Run clean, build, test and finally launch the $RUN_COMMAND as root sudo cmd/$(RUN_COMMAND)/$(RUN_COMMAND) $(RUN_OPTIONS) .PHONY: clean -clean: +clean: ## Remove all produced executables rm -f cmd/miflorad/miflorad rm -f cmd/munin-miflora/munin-miflora rm -f cmd/munin-miflora-gatt/munin-miflora-gatt .PHONY: build -build: cmd/miflorad/miflorad cmd/munin-miflora/munin-miflora cmd/munin-miflora-gatt/munin-miflora-gatt +build: cmd/miflorad/miflorad cmd/munin-miflora/munin-miflora cmd/munin-miflora-gatt/munin-miflora-gatt ## Build all produced executables .PHONY: test -test: build - cd cmd/miflorad && go test -v -race && cd ../.. - cd common && go test -v -race && cd .. +test: build ## Run all tests + pushd cmd/miflorad + go test -v -race + popd + pushd common + go test -v -race + popd .PHONY: remote-run -remote-run: clean - cd cmd/$(RUN_COMMAND) && CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w" && cd ../.. +remote-run: clean ## Run clean, build $RUN_COMMAND for Linux on ARM and launch it via SSH on extzero + pushd cmd/$(RUN_COMMAND) + CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w" + popd file cmd/$(RUN_COMMAND)/$(RUN_COMMAND) scp cmd/$(RUN_COMMAND)/$(RUN_COMMAND) extzero:$(RUN_COMMAND) ssh extzero "./$(RUN_COMMAND) $(RUN_OPTIONS)" .PHONY: release -release: +release: ## Build and upload release version of miflorad to Github mkdir -p pkg - cd cmd/miflorad && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-amd64" -ldflags="-s -w -X main.version=$(MIFLORAD_VERSION)" && cd ../.. - cd cmd/miflorad && CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-arm" -ldflags="-s -w -X main.version=$(MIFLORAD_VERSION)" && cd ../.. + pushd cmd/miflorad + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-amd64" -ldflags="-s -w -X main.version=$(MIFLORAD_VERSION)" + CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-arm" -ldflags="-s -w -X main.version=$(MIFLORAD_VERSION)" + popd # github-release "v$(MIFLORAD_VERSION)" pkg/miflorad-$(MIFLORAD_VERSION)-* --commit "master" --tag "v$(MIFLORAD_VERSION)" --prerelease --github-repository "cmur2/miflorad" github-release "v$(MIFLORAD_VERSION)" pkg/miflorad-$(MIFLORAD_VERSION)-* --commit "master" --tag "v$(MIFLORAD_VERSION)" --github-repository "cmur2/miflorad" .PHONY: cmd/miflorad/miflorad cmd/miflorad/miflorad: - cd cmd/miflorad && CGO_ENABLED=0 go build -buildmode=pie -ldflags "-X main.version=$(MIFLORAD_VERSION)" && cd ../.. + pushd cmd/miflorad + CGO_ENABLED=0 go build -buildmode=pie -ldflags "-X main.version=$(MIFLORAD_VERSION)" .PHONY: cmd/munin-miflora/munin-miflora cmd/munin-miflora/munin-miflora: - cd cmd/munin-miflora && CGO_ENABLED=0 go build -buildmode=pie && cd ../.. + pushd cmd/munin-miflora + CGO_ENABLED=0 go build -buildmode=pie .PHONY: cmd/munin-miflora-gatt/munin-miflora-gatt cmd/munin-miflora-gatt/munin-miflora-gatt: - cd cmd/munin-miflora-gatt && CGO_ENABLED=0 go build -buildmode=pie && cd ../.. + pushd cmd/munin-miflora-gatt + CGO_ENABLED=0 go build -buildmode=pie + +.PHONY: help +help: ## Print this help text + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'