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