Makefile 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. MAKEFLAGS := --jobs=1
  2. VERSION := $(shell git describe --tag)
  3. .PHONY:
  4. help:
  5. @echo "Typical commands (more see below):"
  6. @echo " make build - Build web app, documentation and server/client (sloowwww)"
  7. @echo " make cli-linux-amd64 - Build server/client binary (amd64, no web app or docs)"
  8. @echo " make install-linux-amd64 - Install ntfy binary to /usr/bin/ntfy (amd64)"
  9. @echo " make web - Build the web app"
  10. @echo " make docs - Build the documentation"
  11. @echo " make check - Run all tests, vetting/formatting checks and linters"
  12. @echo
  13. @echo "Build everything:"
  14. @echo " make build - Build web app, documentation and server/client"
  15. @echo " make clean - Clean build/dist folders"
  16. @echo
  17. @echo "Build server & client (not release version):"
  18. @echo " make cli - Build server & client (all architectures)"
  19. @echo " make cli-linux-amd64 - Build server & client (Linux, amd64 only)"
  20. @echo " make cli-linux-armv6 - Build server & client (Linux, armv6 only)"
  21. @echo " make cli-linux-armv7 - Build server & client (Linux, armv7 only)"
  22. @echo " make cli-linux-arm64 - Build server & client (Linux, arm64 only)"
  23. @echo " make cli-windows-amd64 - Build client (Windows, amd64 only)"
  24. @echo " make cli-darwin-amd64 - Build client (macOS, amd64 only)"
  25. @echo
  26. @echo "Build web app:"
  27. @echo " make web - Build the web app"
  28. @echo " make web-deps - Install web app dependencies (npm install the universe)"
  29. @echo " make web-build - Actually build the web app"
  30. @echo
  31. @echo "Build documentation:"
  32. @echo " make docs - Build the documentation"
  33. @echo " make docs-deps - Install Python dependencies (pip3 install)"
  34. @echo " make docs-build - Actually build the documentation"
  35. @echo
  36. @echo "Test/check:"
  37. @echo " make test - Run tests"
  38. @echo " make race - Run tests with -race flag"
  39. @echo " make coverage - Run tests and show coverage"
  40. @echo " make coverage-html - Run tests and show coverage (as HTML)"
  41. @echo " make coverage-upload - Upload coverage results to codecov.io"
  42. @echo
  43. @echo "Lint/format:"
  44. @echo " make fmt - Run 'go fmt'"
  45. @echo " make fmt-check - Run 'go fmt', but don't change anything"
  46. @echo " make vet - Run 'go vet'"
  47. @echo " make lint - Run 'golint'"
  48. @echo " make staticcheck - Run 'staticcheck'"
  49. @echo
  50. @echo "Releasing:"
  51. @echo " make release - Create a release"
  52. @echo " make release-snapshot - Create a test release"
  53. @echo
  54. @echo "Install locally (requires sudo):"
  55. @echo " make install-linux-amd64 - Copy amd64 binary from dist/ to /usr/bin/ntfy"
  56. @echo " make install-linux-armv6 - Copy armv6 binary from dist/ to /usr/bin/ntfy"
  57. @echo " make install-linux-armv7 - Copy armv7 binary from dist/ to /usr/bin/ntfy"
  58. @echo " make install-linux-arm64 - Copy arm64 binary from dist/ to /usr/bin/ntfy"
  59. @echo " make install-linux-deb-amd64 - Install .deb from dist/ (amd64 only)"
  60. @echo " make install-linux-deb-armv6 - Install .deb from dist/ (armv6 only)"
  61. @echo " make install-linux-deb-armv7 - Install .deb from dist/ (armv7 only)"
  62. @echo " make install-linux-deb-arm64 - Install .deb from dist/ (arm64 only)"
  63. # Building everything
  64. clean: .PHONY
  65. rm -rf dist build server/docs server/site
  66. build: web docs cli
  67. update: web-deps-update cli-deps-update docs-deps-update
  68. # Documentation
  69. docs: docs-deps docs-build
  70. docs-build: .PHONY
  71. mkdocs build
  72. docs-deps: .PHONY
  73. pip3 install -r requirements.txt
  74. docs-deps-update: .PHONY
  75. pip3 install -r requirements.txt --upgrade
  76. # Web app
  77. web: web-deps web-build
  78. web-build:
  79. cd web \
  80. && npm run build \
  81. && mv build/index.html build/app.html \
  82. && rm -rf ../server/site \
  83. && mv build ../server/site \
  84. && rm \
  85. ../server/site/config.js \
  86. ../server/site/asset-manifest.json
  87. web-deps:
  88. cd web && npm install
  89. # If this fails for .svg files, optimize them with svgo
  90. web-deps-update:
  91. cd web && npm update
  92. # Main server/client build
  93. cli: cli-deps
  94. goreleaser build --snapshot --rm-dist --debug
  95. cli-linux-amd64: cli-deps-static-sites
  96. goreleaser build --snapshot --rm-dist --debug --id ntfy_linux_amd64
  97. cli-linux-armv6: cli-deps-static-sites cli-deps-gcc-armv6-armv7
  98. goreleaser build --snapshot --rm-dist --debug --id ntfy_linux_armv6
  99. cli-linux-armv7: cli-deps-static-sites cli-deps-gcc-armv6-armv7
  100. goreleaser build --snapshot --rm-dist --debug --id ntfy_linux_armv7
  101. cli-linux-arm64: cli-deps-static-sites cli-deps-gcc-arm64
  102. goreleaser build --snapshot --rm-dist --debug --id ntfy_linux_arm64
  103. cli-windows-amd64: cli-deps-static-sites
  104. goreleaser build --snapshot --rm-dist --debug --id ntfy_windows_amd64
  105. cli-darwin-all: cli-deps-static-sites
  106. goreleaser build --snapshot --rm-dist --debug --id ntfy_darwin_all
  107. cli-deps: cli-deps-static-sites cli-deps-all cli-deps-gcc
  108. cli-deps-gcc: cli-deps-gcc-armv6-armv7 cli-deps-gcc-arm64
  109. cli-deps-static-sites:
  110. mkdir -p server/docs server/site
  111. touch server/docs/index.html server/site/app.html
  112. cli-deps-all:
  113. which upx || { echo "ERROR: upx not installed. On Ubuntu, run: apt install upx"; exit 1; }
  114. cli-deps-gcc-armv6-armv7:
  115. which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/ARMv7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
  116. cli-deps-gcc-arm64:
  117. which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
  118. cli-deps-update:
  119. go get -u
  120. go install honnef.co/go/tools/cmd/staticcheck@latest
  121. # Test/check targets
  122. check: test fmt-check vet lint staticcheck
  123. test: .PHONY
  124. go test -v $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  125. race: .PHONY
  126. go test -race $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  127. coverage:
  128. mkdir -p build/coverage
  129. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  130. go tool cover -func build/coverage/coverage.txt
  131. coverage-html:
  132. mkdir -p build/coverage
  133. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  134. go tool cover -html build/coverage/coverage.txt
  135. coverage-upload:
  136. cd build/coverage && (curl -s https://codecov.io/bash | bash)
  137. # Lint/formatting targets
  138. fmt:
  139. gofmt -s -w .
  140. fmt-check:
  141. test -z $(shell gofmt -l .)
  142. vet:
  143. go vet ./...
  144. lint:
  145. which golint || go install golang.org/x/lint/golint@latest
  146. go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
  147. staticcheck: .PHONY
  148. rm -rf build/staticcheck
  149. which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
  150. mkdir -p build/staticcheck
  151. ln -s "go" build/staticcheck/go
  152. PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
  153. rm -rf build/staticcheck
  154. # Releasing targets
  155. release: clean update cli-deps release-check-tags docs web check
  156. goreleaser release --rm-dist --debug
  157. release-snapshot: clean update cli-deps docs web check
  158. goreleaser release --snapshot --skip-publish --rm-dist --debug
  159. release-check-tags:
  160. $(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-))
  161. if ! grep -q $(LATEST_TAG) docs/install.md; then\
  162. echo "ERROR: Must update docs/install.md with latest tag first.";\
  163. exit 1;\
  164. fi
  165. if ! grep -q $(LATEST_TAG) docs/releases.md; then\
  166. echo "ERROR: Must update docs/releases.md with latest tag first.";\
  167. exit 1;\
  168. fi
  169. # Installing targets
  170. install-linux-amd64: remove-binary
  171. sudo cp -a dist/ntfy_amd64_linux_amd64_v1/ntfy /usr/bin/ntfy
  172. install-linux-armv6: remove-binary
  173. sudo cp -a dist/ntfy_armv6_linux_arm_6/ntfy /usr/bin/ntfy
  174. install-linux-armv7: remove-binary
  175. sudo cp -a dist/ntfy_armv7_linux_arm_7/ntfy /usr/bin/ntfy
  176. install-linux-arm64: remove-binary
  177. sudo cp -a dist/ntfy_arm64_linux_arm64/ntfy /usr/bin/ntfy
  178. remove-binary:
  179. sudo rm -f /usr/bin/ntfy
  180. install-linux-amd64-deb: purge-package
  181. sudo dpkg -i dist/ntfy_*_linux_amd64.deb
  182. install-linux-armv6-deb: purge-package
  183. sudo dpkg -i dist/ntfy_*_linux_armv6.deb
  184. install-linux-armv7-deb: purge-package
  185. sudo dpkg -i dist/ntfy_*_linux_armv7.deb
  186. install-linux-arm64-deb: purge-package
  187. sudo dpkg -i dist/ntfy_*_linux_arm64.deb
  188. purge-package:
  189. sudo systemctl stop ntfy || true
  190. sudo apt-get purge ntfy || true