.POSIX: DESTDIR=$(HOME) PREFIX=/.local INSTALL_PATH=$(DESTDIR)$(PREFIX)/bin BIN=prognosis DIST=dist .PHONY: help build install uninstall test vet fmt ci cross clean help: ## show this help @grep -E '^[a-z-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[1m%-16s\033[0m %s\n", $$1, $$2}' build: ## build the Go binary into ./$(BIN) go build -trimpath -ldflags "-s -w" -o $(BIN) ./cmd/prognosis install: build ## build and install the Go binary mkdir -p $(INSTALL_PATH) # rm first: the target may be a symlink into this repo (see `link`), and cp # follows symlinks -- it would write the binary over bin/prognosis itself. rm -f $(INSTALL_PATH)/$(BIN) cp $(BIN) $(INSTALL_PATH)/$(BIN) chmod 755 $(INSTALL_PATH)/$(BIN) @echo "Installed. Config: $$($(INSTALL_PATH)/$(BIN) -config)" uninstall: ## remove the installed binary rm -f $(INSTALL_PATH)/$(BIN) test: ## run the tests go test ./... vet: ## go vet go vet ./... fmt: ## gofmt the tree gofmt -w . ci: ## pre-push gate: gofmt clean, vet, tests, no third-party deps @test -z "$$(gofmt -l .)" || { echo "gofmt needed:"; gofmt -l .; exit 1; } go vet ./... go test ./... @deps=$$(go list -deps ./... | grep -E '^[a-z0-9-]+\.[a-z]+/' | grep -v '^github.com/lukaszkasprzak/prognosis' || true); \ test -z "$$deps" || { echo "third-party dependencies crept in:"; echo "$$deps"; exit 1; } @echo "ci ok" cross: ## cross-compile into $(DIST)/ -- android/arm64 is the phone mkdir -p $(DIST) CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o $(DIST)/$(BIN)-linux-amd64 ./cmd/prognosis CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o $(DIST)/$(BIN)-linux-arm64 ./cmd/prognosis CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o $(DIST)/$(BIN)-android-arm64 ./cmd/prognosis @ls -la $(DIST) clean: ## remove build artifacts rm -rf $(BIN) $(DIST)