Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 (using GoReleaser, 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-all - Build client (macOS, arm64+amd64 universal binary)"
  25. @echo
  26. @echo "Build server & client (without GoReleaser):"
  27. @echo " make cli-linux-server - Build client & server (no GoReleaser, current arch, Linux)"
  28. @echo " make cli-darwin-server - Build client & server (no GoReleaser, current arch, macOS)"
  29. @echo " make cli-client - Build client only (no GoReleaser, current arch, Linux/macOS/Windows)"
  30. @echo
  31. @echo "Build web app:"
  32. @echo " make web - Build the web app"
  33. @echo " make web-deps - Install web app dependencies (npm install the universe)"
  34. @echo " make web-build - Actually build the web app"
  35. @echo
  36. @echo "Build documentation:"
  37. @echo " make docs - Build the documentation"
  38. @echo " make docs-deps - Install Python dependencies (pip3 install)"
  39. @echo " make docs-build - Actually build the documentation"
  40. @echo
  41. @echo "Test/check:"
  42. @echo " make test - Run tests"
  43. @echo " make race - Run tests with -race flag"
  44. @echo " make coverage - Run tests and show coverage"
  45. @echo " make coverage-html - Run tests and show coverage (as HTML)"
  46. @echo " make coverage-upload - Upload coverage results to codecov.io"
  47. @echo
  48. @echo "Lint/format:"
  49. @echo " make fmt - Run 'go fmt'"
  50. @echo " make fmt-check - Run 'go fmt', but don't change anything"
  51. @echo " make vet - Run 'go vet'"
  52. @echo " make lint - Run 'golint'"
  53. @echo " make staticcheck - Run 'staticcheck'"
  54. @echo
  55. @echo "Releasing:"
  56. @echo " make release - Create a release"
  57. @echo " make release-snapshot - Create a test release"
  58. @echo
  59. @echo "Install locally (requires sudo):"
  60. @echo " make install-linux-amd64 - Copy amd64 binary from dist/ to /usr/bin/ntfy"
  61. @echo " make install-linux-armv6 - Copy armv6 binary from dist/ to /usr/bin/ntfy"
  62. @echo " make install-linux-armv7 - Copy armv7 binary from dist/ to /usr/bin/ntfy"
  63. @echo " make install-linux-arm64 - Copy arm64 binary from dist/ to /usr/bin/ntfy"
  64. @echo " make install-linux-deb-amd64 - Install .deb from dist/ (amd64 only)"
  65. @echo " make install-linux-deb-armv6 - Install .deb from dist/ (armv6 only)"
  66. @echo " make install-linux-deb-armv7 - Install .deb from dist/ (armv7 only)"
  67. @echo " make install-linux-deb-arm64 - Install .deb from dist/ (arm64 only)"
  68. # Building everything
  69. clean: .PHONY
  70. rm -rf dist build server/docs server/site
  71. build: web docs cli
  72. update: web-deps-update cli-deps-update docs-deps-update
  73. docker pull alpine
  74. # Documentation
  75. docs: docs-deps docs-build
  76. docs-build: .PHONY
  77. mkdocs build
  78. docs-deps: .PHONY
  79. pip3 install -r requirements.txt
  80. docs-deps-update: .PHONY
  81. pip3 install -r requirements.txt --upgrade
  82. # Web app
  83. web: web-deps web-build
  84. web-build:
  85. cd web \
  86. && npm run build \
  87. && mv build/index.html build/app.html \
  88. && rm -rf ../server/site \
  89. && mv build ../server/site \
  90. && rm \
  91. ../server/site/config.js \
  92. ../server/site/asset-manifest.json
  93. web-deps:
  94. cd web && npm install
  95. # If this fails for .svg files, optimize them with svgo
  96. web-deps-update:
  97. cd web && npm update
  98. # Main server/client build
  99. cli: cli-deps
  100. goreleaser build --snapshot --rm-dist --debug
  101. cli-linux-amd64: cli-deps-static-sites
  102. goreleaser build --snapshot --rm-dist --debug --id ntfy_linux_amd64
  103. cli-linux-armv6: cli-deps-static-sites cli-deps-gcc-armv6-armv7
  104. goreleaser build --snapshot --rm-dist --debug --id ntfy_linux_armv6
  105. cli-linux-armv7: cli-deps-static-sites cli-deps-gcc-armv6-armv7
  106. goreleaser build --snapshot --rm-dist --debug --id ntfy_linux_armv7
  107. cli-linux-arm64: cli-deps-static-sites cli-deps-gcc-arm64
  108. goreleaser build --snapshot --rm-dist --debug --id ntfy_linux_arm64
  109. cli-windows-amd64: cli-deps-static-sites
  110. goreleaser build --snapshot --rm-dist --debug --id ntfy_windows_amd64
  111. cli-darwin-all: cli-deps-static-sites
  112. goreleaser build --snapshot --rm-dist --debug --id ntfy_darwin_all
  113. cli-linux-server: cli-deps-static-sites
  114. # This is a target to build the CLI (including the server) manually.
  115. # Use this for development, if you really don't want to install GoReleaser ...
  116. mkdir -p dist/ntfy_linux_server server/docs
  117. CGO_ENABLED=1 go build \
  118. -o dist/ntfy_linux_server/ntfy \
  119. -tags sqlite_omit_load_extension,osusergo,netgo \
  120. -ldflags \
  121. "-linkmode=external -extldflags=-static -s -w -X main.version=$(VERSION) -X main.commit=$(shell git rev-parse --short HEAD) -X main.date=$(shell date +%s)"
  122. cli-darwin-server: cli-deps-static-sites
  123. # This is a target to build the CLI (including the server) manually.
  124. # Use this for macOS/iOS development, so you have a local server to test with.
  125. mkdir -p dist/ntfy_darwin_server server/docs
  126. CGO_ENABLED=1 go build \
  127. -o dist/ntfy_darwin_server/ntfy \
  128. -tags sqlite_omit_load_extension,osusergo,netgo \
  129. -ldflags \
  130. "-linkmode=external -s -w -X main.version=$(VERSION) -X main.commit=$(shell git rev-parse --short HEAD) -X main.date=$(shell date +%s)"
  131. cli-client: cli-deps-static-sites
  132. # This is a target to build the CLI (excluding the server) manually. This should work on Linux/macOS/Windows.
  133. # Use this for development, if you really don't want to install GoReleaser ...
  134. mkdir -p dist/ntfy_client server/docs
  135. CGO_ENABLED=0 go build \
  136. -o dist/ntfy_client/ntfy \
  137. -tags noserver \
  138. -ldflags \
  139. "-X main.version=$(VERSION) -X main.commit=$(shell git rev-parse --short HEAD) -X main.date=$(shell date +%s)"
  140. cli-deps: cli-deps-static-sites cli-deps-all cli-deps-gcc
  141. cli-deps-gcc: cli-deps-gcc-armv6-armv7 cli-deps-gcc-arm64
  142. cli-deps-static-sites:
  143. mkdir -p server/docs server/site
  144. touch server/docs/index.html server/site/app.html
  145. cli-deps-all:
  146. which upx || { echo "ERROR: upx not installed. On Ubuntu, run: apt install upx"; exit 1; }
  147. cli-deps-gcc-armv6-armv7:
  148. which arm-linux-gnueabi-gcc || { echo "ERROR: ARMv6/ARMv7 cross compiler not installed. On Ubuntu, run: apt install gcc-arm-linux-gnueabi"; exit 1; }
  149. cli-deps-gcc-arm64:
  150. which aarch64-linux-gnu-gcc || { echo "ERROR: ARM64 cross compiler not installed. On Ubuntu, run: apt install gcc-aarch64-linux-gnu"; exit 1; }
  151. cli-deps-update:
  152. go get -u
  153. go install honnef.co/go/tools/cmd/staticcheck@latest
  154. # Test/check targets
  155. check: test fmt-check vet lint staticcheck
  156. test: .PHONY
  157. go test -v $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  158. race: .PHONY
  159. go test -race $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  160. coverage:
  161. mkdir -p build/coverage
  162. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  163. go tool cover -func build/coverage/coverage.txt
  164. coverage-html:
  165. mkdir -p build/coverage
  166. go test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic $(shell go list ./... | grep -vE 'ntfy/(test|examples|tools)')
  167. go tool cover -html build/coverage/coverage.txt
  168. coverage-upload:
  169. cd build/coverage && (curl -s https://codecov.io/bash | bash)
  170. # Lint/formatting targets
  171. fmt:
  172. gofmt -s -w .
  173. fmt-check:
  174. test -z $(shell gofmt -l .)
  175. vet:
  176. go vet ./...
  177. lint:
  178. which golint || go install golang.org/x/lint/golint@latest
  179. go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
  180. staticcheck: .PHONY
  181. rm -rf build/staticcheck
  182. which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
  183. mkdir -p build/staticcheck
  184. ln -s "go" build/staticcheck/go
  185. PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
  186. rm -rf build/staticcheck
  187. # Releasing targets
  188. release: clean update cli-deps release-check-tags docs web check
  189. goreleaser release --rm-dist --debug
  190. release-snapshot: clean update cli-deps docs web check
  191. goreleaser release --snapshot --skip-publish --rm-dist --debug
  192. release-check-tags:
  193. $(eval LATEST_TAG := $(shell git describe --abbrev=0 --tags | cut -c2-))
  194. if ! grep -q $(LATEST_TAG) docs/install.md; then\
  195. echo "ERROR: Must update docs/install.md with latest tag first.";\
  196. exit 1;\
  197. fi
  198. if ! grep -q $(LATEST_TAG) docs/releases.md; then\
  199. echo "ERROR: Must update docs/releases.md with latest tag first.";\
  200. exit 1;\
  201. fi
  202. # Installing targets
  203. install-linux-amd64: remove-binary
  204. sudo cp -a dist/ntfy_amd64_linux_amd64_v1/ntfy /usr/bin/ntfy
  205. install-linux-armv6: remove-binary
  206. sudo cp -a dist/ntfy_armv6_linux_arm_6/ntfy /usr/bin/ntfy
  207. install-linux-armv7: remove-binary
  208. sudo cp -a dist/ntfy_armv7_linux_arm_7/ntfy /usr/bin/ntfy
  209. install-linux-arm64: remove-binary
  210. sudo cp -a dist/ntfy_arm64_linux_arm64/ntfy /usr/bin/ntfy
  211. remove-binary:
  212. sudo rm -f /usr/bin/ntfy
  213. install-linux-amd64-deb: purge-package
  214. sudo dpkg -i dist/ntfy_*_linux_amd64.deb
  215. install-linux-armv6-deb: purge-package
  216. sudo dpkg -i dist/ntfy_*_linux_armv6.deb
  217. install-linux-armv7-deb: purge-package
  218. sudo dpkg -i dist/ntfy_*_linux_armv7.deb
  219. install-linux-arm64-deb: purge-package
  220. sudo dpkg -i dist/ntfy_*_linux_arm64.deb
  221. purge-package:
  222. sudo systemctl stop ntfy || true
  223. sudo apt-get purge ntfy || true