Makefile 6.3 KB

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