Tools written in Go for interfacing with Xiaomi Flora sensors for IoT use cases.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

80 lines
2.7 KiB

  1. # https://tech.davis-hansson.com/p/make/
  2. SHELL := bash
  3. .ONESHELL:
  4. .SHELLFLAGS := -eux -o pipefail -c
  5. .DELETE_ON_ERROR:
  6. .SILENT:
  7. .DEFAULT_GOAL := all
  8. MAKEFLAGS += --warn-undefined-variables
  9. MAKEFLAGS += --no-builtin-rules
  10. MIFLORA_ADDR?=00:00:00:00:00:00
  11. MIFLORAD_VERSION?=master
  12. RUN_COMMAND=miflorad
  13. RUN_OPTIONS=$(MIFLORA_ADDR)
  14. .PHONY: all
  15. all: clean build test ## Run clean, build and test (default goal)
  16. .PHONY: run
  17. run: clean build test ## Run clean, build, test and finally launch the $RUN_COMMAND as root
  18. sudo cmd/$(RUN_COMMAND)/$(RUN_COMMAND) $(RUN_OPTIONS)
  19. .PHONY: clean
  20. clean: ## Remove all produced executables
  21. rm -f cmd/miflorad/miflorad
  22. rm -f cmd/munin-miflora/munin-miflora
  23. rm -f cmd/munin-miflora-gatt/munin-miflora-gatt
  24. .PHONY: build
  25. build: cmd/miflorad/miflorad cmd/munin-miflora/munin-miflora cmd/munin-miflora-gatt/munin-miflora-gatt ## Build all produced executables
  26. .PHONY: test
  27. test: build ## Run all tests
  28. pushd cmd/miflorad
  29. go test -v -race
  30. popd
  31. pushd common
  32. go test -v -race
  33. popd
  34. .PHONY: remote-run
  35. remote-run: clean ## Run clean, build $RUN_COMMAND for Linux on ARM and launch it via SSH on extzero
  36. pushd cmd/$(RUN_COMMAND)
  37. CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w"
  38. popd
  39. file cmd/$(RUN_COMMAND)/$(RUN_COMMAND)
  40. scp cmd/$(RUN_COMMAND)/$(RUN_COMMAND) extzero:$(RUN_COMMAND)
  41. ssh extzero "./$(RUN_COMMAND) $(RUN_OPTIONS)"
  42. .PHONY: release
  43. release: ## Build and upload release version of miflorad to Github
  44. mkdir -p pkg
  45. pushd cmd/miflorad
  46. CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-amd64" -ldflags="-s -w -X main.version=$(MIFLORAD_VERSION)"
  47. CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-arm" -ldflags="-s -w -X main.version=$(MIFLORAD_VERSION)"
  48. popd
  49. # github-release "v$(MIFLORAD_VERSION)" pkg/miflorad-$(MIFLORAD_VERSION)-* --commit "master" --tag "v$(MIFLORAD_VERSION)" --prerelease --github-repository "cmur2/miflorad"
  50. github-release "v$(MIFLORAD_VERSION)" pkg/miflorad-$(MIFLORAD_VERSION)-* --commit "master" --tag "v$(MIFLORAD_VERSION)" --github-repository "cmur2/miflorad"
  51. .PHONY: cmd/miflorad/miflorad
  52. cmd/miflorad/miflorad:
  53. pushd cmd/miflorad
  54. CGO_ENABLED=0 go build -buildmode=pie -ldflags "-X main.version=$(MIFLORAD_VERSION)"
  55. .PHONY: cmd/munin-miflora/munin-miflora
  56. cmd/munin-miflora/munin-miflora:
  57. pushd cmd/munin-miflora
  58. CGO_ENABLED=0 go build -buildmode=pie
  59. .PHONY: cmd/munin-miflora-gatt/munin-miflora-gatt
  60. cmd/munin-miflora-gatt/munin-miflora-gatt:
  61. pushd cmd/munin-miflora-gatt
  62. CGO_ENABLED=0 go build -buildmode=pie
  63. .PHONY: help
  64. help: ## Print this help text
  65. @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'