Makefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. # The personal, minimalist, super-fast, database free, bookmarking service.
  2. # Makefile for PHP code analysis & testing, documentation and release generation
  3. # Prerequisites:
  4. # - install Composer, either:
  5. # - from your distro's package manager;
  6. # - from the official website (https://getcomposer.org/download/);
  7. # - install/update test dependencies:
  8. # $ composer install # 1st setup
  9. # $ composer update
  10. # - install Xdebug for PHPUnit code coverage reports:
  11. # - see http://xdebug.org/docs/install
  12. # - enable in php.ini
  13. BIN = vendor/bin
  14. PHP_SOURCE = index.php application tests plugins
  15. PHP_COMMA_SOURCE = index.php,application,tests,plugins
  16. all: static_analysis_summary check_permissions test
  17. ##
  18. # Concise status of the project
  19. # These targets are non-blocking: || exit 0
  20. ##
  21. static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
  22. @echo
  23. ##
  24. # PHP_CodeSniffer
  25. # Detects PHP syntax errors
  26. # Documentation (usage, output formatting):
  27. # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
  28. # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
  29. ##
  30. code_sniffer: code_sniffer_full
  31. ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
  32. PHPCS_%:
  33. @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
  34. ### - errors by Git author
  35. code_sniffer_blame:
  36. @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
  37. ### - all errors/warnings
  38. code_sniffer_full:
  39. @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
  40. ### - errors grouped by kind
  41. code_sniffer_source:
  42. @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
  43. ##
  44. # PHP Copy/Paste Detector
  45. # Detects code redundancy
  46. # Documentation: https://github.com/sebastianbergmann/phpcpd
  47. ##
  48. copy_paste:
  49. @echo "-----------------------"
  50. @echo "PHP COPY/PASTE DETECTOR"
  51. @echo "-----------------------"
  52. @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
  53. @echo
  54. ##
  55. # PHP Mess Detector
  56. # Detects PHP syntax errors, sorted by category
  57. # Rules documentation: http://phpmd.org/rules/index.html
  58. ##
  59. MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
  60. mess_title:
  61. @echo "-----------------"
  62. @echo "PHP MESS DETECTOR"
  63. @echo "-----------------"
  64. ### - all warnings
  65. mess_detector: mess_title
  66. @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
  67. ### - all warnings + HTML output contains links to PHPMD's documentation
  68. mess_detector_html:
  69. @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
  70. --reportfile phpmd.html || exit 0
  71. ### - warnings grouped by message, sorted by descending frequency order
  72. mess_detector_grouped: mess_title
  73. @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
  74. | cut -f 2 | sort | uniq -c | sort -nr
  75. ### - summary: number of warnings by rule set
  76. mess_detector_summary: mess_title
  77. @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
  78. warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
  79. printf "$$warnings\t$$rule\n"; \
  80. done;
  81. ##
  82. # Checks source file & script permissions
  83. ##
  84. check_permissions:
  85. @echo "----------------------"
  86. @echo "Check file permissions"
  87. @echo "----------------------"
  88. @for file in `git ls-files`; do \
  89. if [ -x $$file ]; then \
  90. errors=true; \
  91. echo "$${file} is executable"; \
  92. fi \
  93. done; [ -z $$errors ] || false
  94. ##
  95. # PHPUnit
  96. # Runs unitary and functional tests
  97. # Generates an HTML coverage report if Xdebug is enabled
  98. #
  99. # See phpunit.xml for configuration
  100. # https://phpunit.de/manual/current/en/appendixes.configuration.html
  101. ##
  102. test:
  103. @echo "-------"
  104. @echo "PHPUNIT"
  105. @echo "-------"
  106. @mkdir -p sandbox coverage
  107. @$(BIN)/phpunit --coverage-php coverage/main.cov --testsuite unit-tests
  108. locale_test_%:
  109. @UT_LOCALE=$*.utf8 \
  110. $(BIN)/phpunit \
  111. --coverage-php coverage/$(firstword $(subst _, ,$*)).cov \
  112. --bootstrap tests/languages/bootstrap.php \
  113. --testsuite language-$(firstword $(subst _, ,$*))
  114. all_tests: test locale_test_de_DE locale_test_en_US locale_test_fr_FR
  115. @$(BIN)/phpcov merge --html coverage coverage
  116. @# --text doesn't work with phpunit 4.* (v5 requires PHP 5.6)
  117. @#$(BIN)/phpcov merge --text coverage/txt coverage
  118. ##
  119. # Custom release archive generation
  120. #
  121. # For each tagged revision, GitHub provides tar and zip archives that correspond
  122. # to the output of git-archive
  123. #
  124. # These targets produce similar archives, featuring 3rd-party dependencies
  125. # to ease deployment on shared hosting.
  126. ##
  127. ARCHIVE_VERSION := shaarli-$$(git describe)-full
  128. ARCHIVE_PREFIX=Shaarli/
  129. release_archive: release_tar release_zip
  130. ### download 3rd-party PHP libraries
  131. composer_dependencies: clean
  132. composer update --no-dev
  133. find vendor/ -name ".git" -type d -exec rm -rf {} +
  134. ### generate a release tarball and include 3rd-party dependencies
  135. release_tar: composer_dependencies
  136. git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD
  137. tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/
  138. gzip $(ARCHIVE_VERSION).tar
  139. ### generate a release zip and include 3rd-party dependencies
  140. release_zip: composer_dependencies
  141. git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD
  142. mkdir $(ARCHIVE_PREFIX)
  143. rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/
  144. zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/
  145. rm -rf $(ARCHIVE_PREFIX)
  146. ##
  147. # Targets for repository and documentation maintenance
  148. ##
  149. ### remove all unversioned files
  150. clean:
  151. @git clean -df
  152. @rm -rf sandbox
  153. ### generate the AUTHORS file from Git commit information
  154. authors:
  155. @cp .github/mailmap .mailmap
  156. @git shortlog -sne > AUTHORS
  157. @rm .mailmap
  158. ### generate Doxygen documentation
  159. doxygen: clean
  160. @rm -rf doxygen
  161. @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
  162. ### update the local copy of the documentation
  163. doc: clean
  164. @rm -rf doc
  165. @git clone https://github.com/shaarli/Shaarli.wiki.git doc
  166. @rm -rf doc/.git
  167. ### Generate a custom sidebar
  168. #
  169. # Sidebar content:
  170. # - convert GitHub-flavoured relative links to standard Markdown
  171. # - trim HTML, only keep the list (<ul>[...]</ul>) part
  172. htmlsidebar:
  173. @echo '<div id="local-sidebar">' > doc/sidebar.html
  174. @awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
  175. 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
  176. '!m { print $$0 }' doc/_Sidebar.md > doc/tmp.md
  177. @pandoc -f markdown -t html5 -s doc/tmp.md | awk '/(ul>|li>)/' >> doc/sidebar.html
  178. @echo '</div>' >> doc/sidebar.html
  179. @rm doc/tmp.md
  180. ### Convert local markdown documentation to HTML
  181. #
  182. # For all pages:
  183. # - infer title from the file name
  184. # - convert GitHub-flavoured relative links to standard Markdown
  185. # - insert the sidebar menu
  186. htmlpages:
  187. @for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
  188. base=`basename $$file .md`; \
  189. sed -i "1i #$${base//-/ }" $$file; \
  190. awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
  191. 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
  192. '!m { print $$0 }' $$file > doc/tmp.md; \
  193. mv doc/tmp.md $$file; \
  194. pandoc -f markdown_github -t html5 -s \
  195. -c "github-markdown.css" \
  196. -T Shaarli -M pagetitle:"$${base//-/ }" -B doc/sidebar.html \
  197. -o doc/$$base.html $$file; \
  198. done;
  199. htmldoc: authors doc htmlsidebar htmlpages