Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. .POSIX:
  2. #
  3. # DO NOT EDIT THIS FILE. YOUR CHANGES MAY GET OVERWRITTEN.
  4. # Edit Makefile.in instead and then re-generate the Makefile
  5. # with python3 -mmacrop Makefile.in Makefile.
  6. #
  7. #
  8. # Special targets
  9. #
  10. .PHONY: \
  11. check \
  12. clean \
  13. coverage \
  14. dependcheck \
  15. dist \
  16. distcheck \
  17. distclean \
  18. deb \
  19. debupload \
  20. docs \
  21. install \
  22. install-comp \
  23. install-man \
  24. install-strip \
  25. install-module \
  26. installdirs \
  27. lint \
  28. maintainer-clean \
  29. mostlyclean \
  30. virtinstall \
  31. wheelupload \
  32. pre-install \
  33. post-uninstall \
  34. quickcheck \
  35. quicklint \
  36. uninstall \
  37. uninstall-module \
  38. uninstallfiles \
  39. userinstall
  40. .SUFFIXES:
  41. all:
  42. :
  43. #
  44. # Macros
  45. #
  46. BANDIT = bandit
  47. BANDITFLAGS = -qc pyproject.toml
  48. COVERAGE = coverage
  49. CTAGS = ctags
  50. CURL = curl
  51. DESTDIR =
  52. DPKG_DEB = dpkg-deb
  53. FLAKE8 = flake8
  54. GPG = gpg -ab
  55. GPGFLAGS = -q --batch --yes
  56. SHELL = /bin/sh
  57. INSTALL = install
  58. JQ = jq
  59. LINTIAN = lintian
  60. # TODO: Add pedantic and warning, once changelos are to spec.
  61. LINTIANFLAGS = --cfg deb/lintian.cfg --fail-on error
  62. MYPY = mypy
  63. PATHCHK = pathchk
  64. PYLINT = pylint
  65. PYRIGHT = pyright
  66. PYTHON = python3
  67. PIP = pip
  68. PIPFLAGS = --root=$(DESTDIR) --prefix=$(prefix)
  69. PREFIX = /usr/local
  70. PYPI_UPLOAD = $(TWINE) upload $(TWINEFLAGS)
  71. RUFF = ruff
  72. RUFFFLAGS = --quiet
  73. SPHINX = sphinx-build
  74. VENV = $(PYTHON) -m venv
  75. VERMIN = vermin
  76. VULTURE = vulture
  77. VPATH = .
  78. SAFETY = safety
  79. SAFETYFLAGS = --disable-optional-telemetry --policy-file=$(safetypolicy)
  80. TAR = pax -ws '/^/$(distname)\//' -x ustar
  81. TWINE = twine
  82. TWINEFLAGS = -s -rtestpypi
  83. UNTAR = tar -x
  84. UNZIP = gunzip -c
  85. ZIP = gzip
  86. bashcompdir = $(datarootdir)/bash-completion/completions
  87. bindir = $(exec_prefix)/bin
  88. checks = discover
  89. copyright = COPYRIGHT
  90. datarootdir = $(prefix)/share
  91. debdir = deb/$(package)_$(version)-0_all
  92. deburl = $(forgejo_url)/debian/pool/bullseye/main/upload
  93. deb = $(debdir).deb
  94. distar = $(distname).tgz
  95. distfiles = \
  96. INSTALL.rst \
  97. LICENSE.rst \
  98. NEWS.rst \
  99. README.rst \
  100. comp/sievemgr.bash \
  101. comp/sievemgr.zsh \
  102. deb/control.in \
  103. deb/copyright.in \
  104. deb/lintian.cfg \
  105. docs/Makefile \
  106. docs/_static/custom.css \
  107. docs/changelog.rst \
  108. docs/command.rst \
  109. docs/conf.py \
  110. docs/config.rst \
  111. docs/contrib.rst \
  112. docs/feedback.rst \
  113. docs/index.rst \
  114. docs/install.rst \
  115. docs/license.rst \
  116. docs/module.rst \
  117. docs/security.rst \
  118. docs/sphinx.txt \
  119. examples/sievepatch \
  120. linters.txt \
  121. Makefile \
  122. Makefile.in \
  123. macrop.py \
  124. man/sieve.cf.5 \
  125. man/sievemgr.1 \
  126. pyproject.toml \
  127. setup.cfg \
  128. sievemgr.py \
  129. tests/__init__.py \
  130. tests/test_acap.py \
  131. tests/test_backup.py \
  132. tests/test_log.py \
  133. tests/test_sasl.py \
  134. tests/test_sieve.py \
  135. tests/test_term.py
  136. distname = $(module)-$(version)
  137. exec_prefix = $(prefix)
  138. forgejo_url = https://codeberg.org/api/packages/$(forgejo_user)
  139. forgejo_user = odkr
  140. installdirs = \
  141. $(DESTDIR)$(man1dir) \
  142. $(DESTDIR)$(man5dir) \
  143. $(DESTDIR)$(bashcompdir) \
  144. $(DESTDIR)$(zshcompdir)
  145. instlog = install.log
  146. mandir = $(datarootdir)/man
  147. man1dir = $(mandir)/man1
  148. man5dir = $(mandir)/man5
  149. man1ext = .1
  150. man5ext = .5
  151. module = $(package)
  152. package = sievemgr
  153. prefix = $(PREFIX)
  154. safetypolicy = safety.yml
  155. srcs = \
  156. sievemgr.py \
  157. $(tests)
  158. tests = \
  159. tests/__init__.py \
  160. tests/test_acap.py \
  161. tests/test_backup.py \
  162. tests/test_log.py \
  163. tests/test_sasl.py \
  164. tests/test_sieve.py \
  165. tests/test_term.py
  166. venvdir = /opt/odkr/$(module)
  167. version = 0.7.4.7
  168. zshcompdir = $(datarootdir)/zsh-completions
  169. badgeurl = https://img.shields.io/badge/coverage-{}%25-lightgrey
  170. coverage = docs/_static/coverage.svg docs/_static/coverage/index.html
  171. #
  172. # Build system
  173. #
  174. .SUFFIXES: .in
  175. Makefile: sievemgr.py Makefile.in
  176. .in:
  177. $(PYTHON) -mmacrop $@.in $@
  178. #
  179. # Installation
  180. #
  181. install: pre-install install-module install-man install-comp
  182. install-man: \
  183. installdirs \
  184. $(DESTDIR)$(man1dir)/sievemgr$(man1ext) \
  185. $(DESTDIR)$(man5dir)/sieve.cf$(man5ext)
  186. uninstall: uninstall-module uninstallfiles uninstalldirs post-uninstall
  187. install-comp: \
  188. installdirs \
  189. $(DESTDIR)$(bashcompdir)/sievemgr.bash \
  190. $(DESTDIR)$(zshcompdir)/_sievemgr
  191. install-strip: install
  192. virtinstall: $(venvdir)/bin/pip
  193. install-module:
  194. $(NORMAL_INSTALL)
  195. $(PIP) install $(PIPFLAGS) .
  196. printf 'pip: %s\n' '$(PIP)' >>$(instlog)
  197. pre-install:
  198. $(PRE_INSTALL)
  199. set -C && : >$(instlog)
  200. installdirs: $(installdirs)
  201. userinstall:
  202. $(MAKE) -e PIPFLAGS=--user prefix="$$HOME/.local" install
  203. virtinstall:
  204. @echo 'Installing SieveManager to $(venvdir) ...'
  205. $(MAKE) -e PIP=$(venvdir)/bin/pip PIPFLAGS= \
  206. PREFIX='$(venvdir)' install
  207. uninstall-module:
  208. $(NORMAL_UNINSTALL)
  209. -"$$(sed -n 's/pip: //p' $(instlog))" uninstall -y $(module)
  210. uninstalldirs:
  211. $(POST_UNINSTALL)
  212. - sed -n 's/^dir: //p' $(instlog) | xargs -E '' rmdir -pv
  213. uninstallfiles:
  214. $(POST_UNINSTALL)
  215. sed -n 's/^file: //p' $(instlog) | xargs -E '' rm -f
  216. post-uninstall:
  217. $(POST_UNINSTALL)
  218. rm $(instlog)
  219. $(DESTDIR)$(man1dir)/sievemgr$(man1ext): man/sievemgr.1
  220. $(POST_INSTALL)
  221. $(INSTALL) -m u=rw,go=r man/sievemgr.1 '$@'
  222. printf 'file: %s\n' '$@' >>$(instlog)
  223. $(DESTDIR)$(man5dir)/sieve.cf$(man5ext): man/sieve.cf.5
  224. $(POST_INSTALL)
  225. $(INSTALL) -m u=rw,go=r man/sieve.cf.5 '$@'
  226. printf 'file: %s\n' '$@' >>$(instlog)
  227. $(DESTDIR)$(bashcompdir)/sievemgr.bash: comp/sievemgr.bash
  228. $(POST_INSTALL)
  229. $(INSTALL) -m u=rw,go=r comp/sievemgr.bash '$@'
  230. printf 'file: %s\n' '$@' >>$(instlog)
  231. $(DESTDIR)$(zshcompdir)/_sievemgr: comp/sievemgr.zsh
  232. $(POST_INSTALL)
  233. $(INSTALL) -m u=rw,go=r comp/sievemgr.zsh '$@'
  234. printf 'file: %s\n' '$@' >>$(instlog)
  235. $(installdirs):
  236. $(PRE_INSTALL)
  237. mkdir -pm0755 $@
  238. printf 'dir: %s\n' '$@' >>$(instlog)
  239. $(venvdir)/bin/pip:
  240. @echo 'Creating a Python virtual environment in $(venvdir) ...'
  241. $(PYTHON) -mvenv $(venvdir)
  242. #
  243. # Documentation
  244. #
  245. .coverage: sievemgr.py $(tests)
  246. $(COVERAGE) run -m --include sievemgr.py unittest discover
  247. coverage: $(coverage)
  248. docs: man/sievemgr.1 man/sieve.cf.5
  249. . ./bin/activate && cd docs && $(MAKE) -e html
  250. docs/_static/coverage/index.html: .coverage
  251. $(GCOVR) $(GCOVRFLAGS) --html-self-contained --html-details $@
  252. $(COVERAGE) html --include sievemgr.py -d docs/_static/coverage
  253. docs/_static/coverage.svg: .coverage
  254. $(COVERAGE) json -o - | $(JQ) .totals.percent_covered_display -r | \
  255. xargs -I '{}' $(CURL) -o $@ $(badgeurl)
  256. man/sievemgr.1: docs/command.rst
  257. man/sieve.cf.5: docs/config.rst
  258. man/sievemgr.1.gz: man/sievemgr.1
  259. man/sieve.cf.5.gz: man/sieve.cf.5
  260. man/sievemgr.1 man/sieve.cf.5:
  261. . ./bin/activate && $(SPHINX) $(SPHINXFLAGS) -bman docs man
  262. #
  263. # Distribution
  264. #
  265. dist: dependcheck $(distar) $(distar).asc
  266. distcheck: dist
  267. $(distar): lint check $(distfiles)
  268. $(distar).asc: $(distar)
  269. dependcheck:
  270. $(SAFETY) scan $(SAFETYFLAGS) || [ $$? -eq 127 ]
  271. distcheck:
  272. $(UNZIP) $(distar) | $(UNTAR)
  273. cd $(distname) && $(MAKE) -e check
  274. rm -rf $(distname)
  275. $(distar):
  276. $(PATHCHK) $(PATHCHKFLAGS) -Pp $(distfiles)
  277. $(TAR) $(TARFLAGS) $(distfiles) | $(ZIP) $(ZIPFLAGS) >$(distar)
  278. $(distar).asc:
  279. $(GPG) $(GPGFLAGS) $(distar)
  280. #
  281. # PyPI
  282. #
  283. build: lint check
  284. $(PYTHON) -m build
  285. wheelupload: build
  286. $(PYPI_UPLOAD) dist/$(distname).tar.gz dist/$(distname)-py3-none-any.whl
  287. #
  288. # Debian package
  289. #
  290. deb: $(deb)
  291. debupload: $(deb)
  292. $(deb): \
  293. lint \
  294. check \
  295. $(debdir)/usr/lib/python3/dist-packages/sievemgr.py \
  296. $(debdir)/usr/share/man/man1/sievemgr.1.gz \
  297. $(debdir)/usr/share/man/man5/sieve.cf.5.gz \
  298. $(debdir)/usr/share/bash-completion/completions/sievemgr.bash \
  299. $(debdir)/usr/share/zsh-completions/_sievemgr \
  300. $(debdir)/DEBIAN/control \
  301. $(debdir)/usr/share/doc/$(package)/copyright \
  302. $(debdir)/usr/share/doc/$(package)/changelog.gz
  303. $(DPKG_DEB) $(DPKG_DEBFLAGS) --root-owner-group --build $(debdir)
  304. $(LINTIAN) $(LINTIANFLAGS) $@ || [ $$? -eq 127 ]
  305. GPG_TTY=$$(tty) debsigs --sign=maint $@
  306. $(debdir)/usr/lib/python3/dist-packages/sievemgr.py:
  307. /usr/bin/pip3 install --root=$(debdir) --prefix=/usr --no-deps .
  308. if [ -e $(debdir)/usr/local ]; \
  309. then \
  310. mv $(debdir)/usr/local/* $(debdir)/usr; \
  311. rmdir $(debdir)/usr/local; \
  312. fi
  313. pydir="$$(ls -d $(debdir)/usr/lib/python*)"; \
  314. debpydir="$${pydir%.*}"; \
  315. if [ -e "$$pydir" ]; \
  316. then mv "$$pydir" "$$debpydir"; \
  317. fi
  318. if [ -e "$$debpydir/site-packages" ]; \
  319. then mv "$$debpydir/site-packages" "$$debpydir/dist-packages"; \
  320. fi
  321. find $(debdir) -type d -name __pycache__ -exec rm -rf '{}' ';' -prune
  322. $(debdir)/usr/share/man/man1/sievemgr.1.gz: man/sievemgr.1
  323. mkdir -pm0755 $$(dirname $@)
  324. gzip -9n <man/sievemgr.1 >$@
  325. $(debdir)/usr/share/man/man5/sieve.cf.5.gz: man/sieve.cf.5
  326. mkdir -pm0755 $$(dirname $@)
  327. gzip -9n <man/sieve.cf.5 >$@
  328. $(debdir)/DEBIAN/control: deb/control
  329. mkdir -pm0755 $$(dirname $@)
  330. $(INSTALL) -m u=rw,go=r deb/control $@
  331. $(debdir)/usr/share/doc/$(package)/copyright: deb/copyright
  332. mkdir -pm0755 $$(dirname $@)
  333. $(INSTALL) -m u=rw,go=r deb/copyright $@
  334. $(debdir)/usr/share/doc/$(package)/changelog.gz: NEWS.rst
  335. mkdir -pm0755 $$(dirname $@)
  336. gzip -9n <NEWS.rst >$@
  337. $(debdir)/usr/share/bash-completion/completions/sievemgr.bash:
  338. mkdir -pm0755 $$(dirname $@)
  339. $(INSTALL) -m u=rw,go=r comp/sievemgr.bash $@
  340. $(debdir)/usr/share/zsh-completions/_sievemgr:
  341. mkdir -pm0755 $$(dirname $@)
  342. $(INSTALL) -m u=rw,go=r comp/sievemgr.zsh $@
  343. deb/control: sievemgr.py deb/control.in
  344. deb/copyright: sievemgr.py deb/copyright.in
  345. debupload:
  346. GPG_TTY=$$(tty) debsigs --sign=origin $(deb)
  347. curl -n --netrc-file .netrc -T$(deb) $(deburl)
  348. #
  349. # Cleanup
  350. #
  351. maintainer-clean: distclean
  352. @echo '$@ is for maintainers only!'
  353. @echo 'It deletes files that cannot be built with standard tools.'
  354. rm -f deb/control deb/copyright Makefile man/sievemgr.1 man/sieve.cf.5
  355. distclean: clean
  356. rm -f $(instlog) tags
  357. clean: mostlyclean
  358. find . '(' -name '*.deb' -o -name '*.asc' -o -name '*.tgz' ')' \
  359. -exec rm -f '{}' +
  360. rm -rf $(package).egg-info .*_cache build deb/$(package)_*
  361. mostlyclean:
  362. find . -type d -name __pycache__ | xargs -E '' rm -rf
  363. find . -type f -name '*.bak' -exec rm '{}' +
  364. rm -f $(package)-*.tgz $(package)-*.tgz.asc deb/$(package)_*.deb dist/*
  365. #
  366. # Tags
  367. #
  368. TAGS: tags
  369. tags: $(srcs)
  370. $(CTAGS) $(CTAGSFLAGS) $(srcs)
  371. #
  372. # Tests
  373. #
  374. check:
  375. $(PYTHON) -m unittest $(checks)
  376. quickcheck:
  377. QUICKTEST=y $(PYTHON) -m unittest $(checks)
  378. #
  379. # Linters
  380. #
  381. lint: quicklint
  382. lint:
  383. $(PYRIGHT) $(PYRIGHTFLAGS) $(srcs) || [ $$? -eq 127 ]
  384. $(FLAKE8) $(FLAKE8FLAGS) $(srcs) || [ $$? -eq 127 ]
  385. $(VERMIN) $(VERMINFLAGS) $(srcs) || [ $$? -eq 127 ]
  386. $(RUFF) check $(RUFFFLAGS) $(srcs) || [ $$? -eq 127 ]
  387. $(PYLINT) $(PYLINTFLAGS) $(srcs) || [ $$? -eq 127 ]
  388. $(VULTURE) $(VULTUREFLAGS) $(srcs) || [ $$? -eq 127 ]
  389. quicklint:
  390. $(MYPY) $(MYPYFLAGS) $(srcs) || [ $$? -eq 127 ]
  391. $(BANDIT) $(BANDITFLAGS) $(srcs) || [ $$? -eq 127 ]