]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - Makefile
Merge pull request #393 from ArthurHoaro/tools-js-indent
[github/shaarli/Shaarli.git] / Makefile
1 # Shaarli, the personal, minimalist, super-fast, no-database delicious clone.
2 # Makefile for PHP code analysis & testing
3
4 # Prerequisites:
5 # - install Composer, either:
6 # - from your distro's package manager;
7 # - from the official website (https://getcomposer.org/download/);
8 # - install/update test dependencies:
9 # $ composer install # 1st setup
10 # $ composer update
11 # - install Xdebug for PHPUnit code coverage reports:
12 # - see http://xdebug.org/docs/install
13 # - enable in php.ini
14
15 BIN = vendor/bin
16 PHP_SOURCE = index.php application tests plugins
17 PHP_COMMA_SOURCE = index.php,application,tests,plugins
18
19 all: static_analysis_summary test
20
21 ##
22 # Concise status of the project
23 # These targets are non-blocking: || exit 0
24 ##
25
26 static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
27 @echo
28
29 ##
30 # PHP_CodeSniffer
31 # Detects PHP syntax errors
32 # Documentation (usage, output formatting):
33 # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
34 # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
35 ##
36
37 code_sniffer: code_sniffer_full
38
39 ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
40 PHPCS_%:
41 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
42
43 ### - errors by Git author
44 code_sniffer_blame:
45 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
46
47 ### - all errors/warnings
48 code_sniffer_full:
49 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
50
51 ### - errors grouped by kind
52 code_sniffer_source:
53 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
54
55 ##
56 # PHP Copy/Paste Detector
57 # Detects code redundancy
58 # Documentation: https://github.com/sebastianbergmann/phpcpd
59 ##
60
61 copy_paste:
62 @echo "-----------------------"
63 @echo "PHP COPY/PASTE DETECTOR"
64 @echo "-----------------------"
65 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
66 @echo
67
68 ##
69 # PHP Mess Detector
70 # Detects PHP syntax errors, sorted by category
71 # Rules documentation: http://phpmd.org/rules/index.html
72 ##
73 MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
74
75 mess_title:
76 @echo "-----------------"
77 @echo "PHP MESS DETECTOR"
78 @echo "-----------------"
79
80 ### - all warnings
81 mess_detector: mess_title
82 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
83
84 ### - all warnings + HTML output contains links to PHPMD's documentation
85 mess_detector_html:
86 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
87 --reportfile phpmd.html || exit 0
88
89 ### - warnings grouped by message, sorted by descending frequency order
90 mess_detector_grouped: mess_title
91 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
92 | cut -f 2 | sort | uniq -c | sort -nr
93
94 ### - summary: number of warnings by rule set
95 mess_detector_summary: mess_title
96 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
97 warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
98 printf "$$warnings\t$$rule\n"; \
99 done;
100
101 ##
102 # PHPUnit
103 # Runs unitary and functional tests
104 # Generates an HTML coverage report if Xdebug is enabled
105 #
106 # See phpunit.xml for configuration
107 # https://phpunit.de/manual/current/en/appendixes.configuration.html
108 ##
109 test:
110 @echo "-------"
111 @echo "PHPUNIT"
112 @echo "-------"
113 @mkdir -p sandbox
114 @$(BIN)/phpunit tests
115
116 ##
117 # Targets for repository and documentation maintenance
118 ##
119
120 ### remove all unversioned files
121 clean:
122 @git clean -df
123 @rm -rf sandbox
124
125 ### generate Doxygen documentation
126 doxygen: clean
127 @rm -rf doxygen
128 @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
129
130 ### update the local copy of the documentation
131 doc: clean
132 @rm -rf doc
133 @git clone https://github.com/shaarli/Shaarli.wiki.git doc
134 @rm -rf doc/.git
135
136 ### Generate a custom sidebar
137 #
138 # Sidebar content:
139 # - convert GitHub-flavoured relative links to standard Markdown
140 # - trim HTML, only keep the list (<ul>[...]</ul>) part
141 htmlsidebar:
142 @echo '<div id="local-sidebar">' > doc/sidebar.html
143 @awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
144 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
145 '!m { print $$0 }' doc/_Sidebar.md > doc/tmp.md
146 @pandoc -f markdown -t html5 -s doc/tmp.md | awk '/(ul>|li>)/' >> doc/sidebar.html
147 @echo '</div>' >> doc/sidebar.html
148 @rm doc/tmp.md
149
150 ### Convert local markdown documentation to HTML
151 #
152 # For all pages:
153 # - infer title from the file name
154 # - convert GitHub-flavoured relative links to standard Markdown
155 # - insert the sidebar menu
156 htmlpages:
157 @for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
158 base=`basename $$file .md`; \
159 sed -i "1i #$${base//-/ }" $$file; \
160 awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
161 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
162 '!m { print $$0 }' $$file > doc/tmp.md; \
163 mv doc/tmp.md $$file; \
164 pandoc -f markdown_github -t html5 -s \
165 -c "github-markdown.css" \
166 -T Shaarli -M pagetitle:"$${base//-/ }" -B doc/sidebar.html \
167 -o doc/$$base.html $$file; \
168 done;
169
170 htmldoc: doc htmlsidebar htmlpages