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