Makefile 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # Shaarli, the personal, minimalist, super-fast, no-database delicious clone.
  2. # Makefile for PHP code analysis & testing
  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 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. # PHPUnit
  83. # Runs unitary and functional tests
  84. # Generates an HTML coverage report if Xdebug is enabled
  85. #
  86. # See phpunit.xml for configuration
  87. # https://phpunit.de/manual/current/en/appendixes.configuration.html
  88. ##
  89. test:
  90. @echo "-------"
  91. @echo "PHPUNIT"
  92. @echo "-------"
  93. @mkdir -p sandbox
  94. @$(BIN)/phpunit tests
  95. ##
  96. # Targets for repository and documentation maintenance
  97. ##
  98. ### remove all unversioned files
  99. clean:
  100. @git clean -df
  101. @rm -rf sandbox
  102. ### generate Doxygen documentation
  103. doxygen: clean
  104. @rm -rf doxygen
  105. @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
  106. ### update the local copy of the documentation
  107. doc: clean
  108. @rm -rf doc
  109. @git clone https://github.com/shaarli/Shaarli.wiki.git doc
  110. @rm -rf doc/.git
  111. ### Generate a custom sidebar
  112. #
  113. # Sidebar content:
  114. # - convert GitHub-flavoured relative links to standard Markdown
  115. # - trim HTML, only keep the list (<ul>[...]</ul>) part
  116. htmlsidebar:
  117. @echo '<div id="local-sidebar">' > doc/sidebar.html
  118. @awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
  119. 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
  120. '!m { print $$0 }' doc/_Sidebar.md > doc/tmp.md
  121. @pandoc -f markdown -t html5 -s doc/tmp.md | awk '/(ul>|li>)/' >> doc/sidebar.html
  122. @echo '</div>' >> doc/sidebar.html
  123. @rm doc/tmp.md
  124. ### Convert local markdown documentation to HTML
  125. #
  126. # For all pages:
  127. # - infer title from the file name
  128. # - convert GitHub-flavoured relative links to standard Markdown
  129. # - insert the sidebar menu
  130. htmlpages:
  131. @for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
  132. base=`basename $$file .md`; \
  133. sed -i "1i #$${base//-/ }" $$file; \
  134. awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
  135. 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
  136. '!m { print $$0 }' $$file > doc/tmp.md; \
  137. mv doc/tmp.md $$file; \
  138. pandoc -f markdown_github -t html5 -s \
  139. -c "github-markdown.css" \
  140. -T Shaarli -M pagetitle:"$${base//-/ }" -B doc/sidebar.html \
  141. -o doc/$$base.html $$file; \
  142. done;
  143. htmldoc: doc htmlsidebar htmlpages