Makefile 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #! /usr/bin/make -f
  2. #
  3. # Copyright © 2015 Ben Finney <ben+python@benfinney.id.au>
  4. #
  5. # This is free software: you may copy, modify, and/or distribute this work
  6. # under the terms of the GNU General Public License as published by the
  7. # Free Software Foundation; version 3 of that license or any later version.
  8. # No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details.
  9. # Makefile for ‘dput’ code base.
  10. PYTHON ?= /usr/bin/python2
  11. UNITTEST2 = /usr/bin/unit2
  12. PY_MODULE_SUFFIX = .py
  13. PY_MODULE_BYTECODE_SUFFIX = .pyc
  14. package_modules = $(shell find ${CURDIR}/dput/ -name '*${PY_MODULE_SUFFIX}')
  15. python_modules = $(shell find ${CURDIR}/ -name '*${PY_MODULE_SUFFIX}')
  16. GENERATED_FILES :=
  17. GENERATED_FILES += $(patsubst \
  18. %${PY_MODULE_SUFFIX},%${PY_MODULE_BYTECODE_SUFFIX}, \
  19. ${python_modules})
  20. GENERATED_FILES += ${CURDIR}/*.egg-info
  21. GENERATED_FILES += ${CURDIR}/build ${CURDIR}/dist
  22. UNITTEST_OPTS ?= --buffer
  23. PYTHON_COVERAGE = $(PYTHON) -m coverage
  24. COVERAGE_RUN_OPTS ?= --branch
  25. COVERAGE_REPORT_OPTS ?=
  26. COVERAGE_TEXT_REPORT_OPTS ?=
  27. COVERAGE_HTML_REPORT_OPTS ?=
  28. .PHONY: all
  29. all:
  30. .PHONY: clean
  31. clean:
  32. $(RM) -r ${GENERATED_FILES}
  33. .PHONY: tags
  34. tags: TAGS
  35. GENERATED_FILES += TAGS
  36. TAGS: ${python_modules}
  37. etags --output "$@" --lang=python ${python_modules}
  38. .PHONY: test
  39. test: test-unittest
  40. .PHONY: test-unittest
  41. test-unittest:
  42. $(PYTHON) -m unittest discover ${UNITTEST_OPTS}
  43. .PHONY: test-coverage
  44. test-coverage: test-coverage-run test-coverage-html test-coverage-report
  45. GENERATED_FILES += .coverage
  46. .PHONY: test-coverage-run
  47. test-coverage-run: coverage_opts = ${COVERAGE_RUN_OPTS}
  48. test-coverage-run:
  49. $(PYTHON) -m coverage run ${coverage_opts} \
  50. $(UNITTEST2) discover ${UNITTEST_OPTS}
  51. GENERATED_FILES += htmlcov/
  52. .PHONY: test-coverage-html
  53. test-coverage-html: coverage_opts = ${COVERAGE_REPORT_OPTS} ${COVERAGE_HTML_REPORT_OPTS}
  54. test-coverage-html:
  55. $(PYTHON_COVERAGE) html ${coverage_opts} ${package_modules}
  56. .PHONY: test-coverage-report
  57. test-coverage-report: coverage_opts = ${COVERAGE_REPORT_OPTS} ${COVERAGE_TEXT_REPORT_OPTS}
  58. test-coverage-report:
  59. $(PYTHON_COVERAGE) report ${coverage_opts} ${package_modules}
  60. # Local variables:
  61. # coding: utf-8
  62. # mode: make
  63. # End:
  64. # vim: fileencoding=utf-8 filetype=make :