Makefile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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
  107. @$(BIN)/phpunit tests
  108. ##
  109. # Custom release archive generation
  110. #
  111. # For each tagged revision, GitHub provides tar and zip archives that correspond
  112. # to the output of git-archive
  113. #
  114. # These targets produce similar archives, featuring 3rd-party dependencies
  115. # to ease deployment on shared hosting.
  116. ##
  117. ARCHIVE_VERSION := shaarli-$$(git describe)-full
  118. release_archive: release_tar release_zip
  119. ### download 3rd-party PHP libraries
  120. composer_dependencies: clean
  121. composer update --no-dev
  122. find vendor/ -name ".git" -type d -exec rm -rf {} +
  123. ### generate a release tarball and include 3rd-party dependencies
  124. release_tar: composer_dependencies
  125. git archive -o $(ARCHIVE_VERSION).tar HEAD
  126. tar rvf $(ARCHIVE_VERSION).tar vendor/
  127. ### generate a release zip and include 3rd-party dependencies
  128. release_zip: composer_dependencies
  129. git archive -o $(ARCHIVE_VERSION).zip -9 HEAD
  130. zip -r $(ARCHIVE_VERSION).zip vendor/
  131. ##
  132. # Targets for repository and documentation maintenance
  133. ##
  134. ### remove all unversioned files
  135. clean:
  136. @git clean -df
  137. @rm -rf sandbox
  138. ### generate Doxygen documentation
  139. doxygen: clean
  140. @rm -rf doxygen
  141. @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
  142. ### update the local copy of the documentation
  143. doc: clean
  144. @rm -rf doc
  145. @git clone https://github.com/shaarli/Shaarli.wiki.git doc
  146. @rm -rf doc/.git
  147. ### Generate a custom sidebar
  148. #
  149. # Sidebar content:
  150. # - convert GitHub-flavoured relative links to standard Markdown
  151. # - trim HTML, only keep the list (<ul>[...]</ul>) part
  152. htmlsidebar:
  153. @echo '<div id="local-sidebar">' > doc/sidebar.html
  154. @awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
  155. 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
  156. '!m { print $$0 }' doc/_Sidebar.md > doc/tmp.md
  157. @pandoc -f markdown -t html5 -s doc/tmp.md | awk '/(ul>|li>)/' >> doc/sidebar.html
  158. @echo '</div>' >> doc/sidebar.html
  159. @rm doc/tmp.md
  160. ### Convert local markdown documentation to HTML
  161. #
  162. # For all pages:
  163. # - infer title from the file name
  164. # - convert GitHub-flavoured relative links to standard Markdown
  165. # - insert the sidebar menu
  166. htmlpages:
  167. @for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
  168. base=`basename $$file .md`; \
  169. sed -i "1i #$${base//-/ }" $$file; \
  170. awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
  171. 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
  172. '!m { print $$0 }' $$file > doc/tmp.md; \
  173. mv doc/tmp.md $$file; \
  174. pandoc -f markdown_github -t html5 -s \
  175. -c "github-markdown.css" \
  176. -T Shaarli -M pagetitle:"$${base//-/ }" -B doc/sidebar.html \
  177. -o doc/$$base.html $$file; \
  178. done;
  179. htmldoc: doc htmlsidebar htmlpages