rules.mk 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Only use the recipes defined in these makefiles
  2. MAKEFLAGS += --no-builtin-rules
  3. .SUFFIXES:
  4. # Delete target files if there's an error
  5. # This avoids a failure to then skip building on next run if the output is created by shell redirection for example
  6. # Not really necessary for now, but just good to have already if it becomes necessary later.
  7. .DELETE_ON_ERROR:
  8. # Treat the whole recipe as a one shell script/invocation instead of one-per-line
  9. .ONESHELL:
  10. # Use bash instead of plain sh
  11. SHELL := bash
  12. .SHELLFLAGS := -o pipefail -euc
  13. version := $(shell git rev-parse --short HEAD)
  14. tag := $(shell git tag --points-at HEAD)
  15. ifneq (,$(tag))
  16. version := $(tag)-$(version)
  17. endif
  18. LDFLAGS := -ldflags "-X main.version=$(version)"
  19. export CGO_ENABLED := 0
  20. ifeq ($(origin GOBIN), undefined)
  21. GOBIN := ${PWD}/bin
  22. export GOBIN
  23. PATH := ${GOBIN}:${PATH}
  24. export PATH
  25. endif
  26. toolsBins := $(addprefix bin/,$(notdir $(shell grep '^\s*_' tooling/tools.go | awk -F'"' '{print $$2}')))
  27. # installs cli tools defined in tools.go
  28. $(toolsBins): tooling/go.mod tooling/go.sum tooling/tools.go
  29. $(toolsBins): CMD=$(shell awk -F'"' '/$(@F)"/ {print $$2}' tooling/tools.go)
  30. $(toolsBins):
  31. cd tooling && go install $(CMD)
  32. .PHONY: gofumpt
  33. gofumpt: bin/gofumpt
  34. gofumpt -s -d .
  35. gofumpt-fix: bin/gofumpt
  36. gofumpt -s -w .
  37. .PHONY: prettier prettier-fix
  38. prettier:
  39. prettier --list-different --ignore-path .gitignore .
  40. prettier-fix:
  41. prettier --write --ignore-path .gitignore .