]> git.immae.eu Git - github/shaarli/Shaarli.git/blame_incremental - Makefile
documentation: set edit_uri
[github/shaarli/Shaarli.git] / Makefile
... / ...
CommitLineData
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
15BIN = vendor/bin
16PHP_SOURCE = index.php application tests plugins
17PHP_COMMA_SOURCE = index.php,application,tests,plugins
18
19all: static_analysis_summary check_permissions test
20
21##
22# Concise status of the project
23# These targets are non-blocking: || exit 0
24##
25
26static_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
37code_sniffer: code_sniffer_full
38
39### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
40PHPCS_%:
41 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
42
43### - errors by Git author
44code_sniffer_blame:
45 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
46
47### - all errors/warnings
48code_sniffer_full:
49 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
50
51### - errors grouped by kind
52code_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
61copy_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##
73MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
74
75mess_title:
76 @echo "-----------------"
77 @echo "PHP MESS DETECTOR"
78 @echo "-----------------"
79
80### - all warnings
81mess_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
85mess_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
90mess_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
95mess_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# Checks source file & script permissions
103##
104check_permissions:
105 @echo "----------------------"
106 @echo "Check file permissions"
107 @echo "----------------------"
108 @for file in `git ls-files`; do \
109 if [ -x $$file ]; then \
110 errors=true; \
111 echo "$${file} is executable"; \
112 fi \
113 done; [ -z $$errors ] || false
114
115##
116# PHPUnit
117# Runs unitary and functional tests
118# Generates an HTML coverage report if Xdebug is enabled
119#
120# See phpunit.xml for configuration
121# https://phpunit.de/manual/current/en/appendixes.configuration.html
122##
123test:
124 @echo "-------"
125 @echo "PHPUNIT"
126 @echo "-------"
127 @mkdir -p sandbox coverage
128 @$(BIN)/phpunit --coverage-php coverage/main.cov --testsuite unit-tests
129
130locale_test_%:
131 @UT_LOCALE=$*.utf8 \
132 $(BIN)/phpunit \
133 --coverage-php coverage/$(firstword $(subst _, ,$*)).cov \
134 --bootstrap tests/languages/bootstrap.php \
135 --testsuite language-$(firstword $(subst _, ,$*))
136
137all_tests: test locale_test_de_DE locale_test_en_US locale_test_fr_FR
138 @$(BIN)/phpcov merge --html coverage coverage
139 @# --text doesn't work with phpunit 4.* (v5 requires PHP 5.6)
140 @#$(BIN)/phpcov merge --text coverage/txt coverage
141
142##
143# Custom release archive generation
144#
145# For each tagged revision, GitHub provides tar and zip archives that correspond
146# to the output of git-archive
147#
148# These targets produce similar archives, featuring 3rd-party dependencies
149# to ease deployment on shared hosting.
150##
151ARCHIVE_VERSION := shaarli-$$(git describe)-full
152ARCHIVE_PREFIX=Shaarli/
153
154release_archive: release_tar release_zip
155
156### download 3rd-party PHP libraries
157composer_dependencies: clean
158 composer install --no-dev --prefer-dist
159 find vendor/ -name ".git" -type d -exec rm -rf {} +
160
161### generate a release tarball and include 3rd-party dependencies
162release_tar: composer_dependencies
163 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD
164 tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/
165 gzip $(ARCHIVE_VERSION).tar
166
167### generate a release zip and include 3rd-party dependencies
168release_zip: composer_dependencies
169 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD
170 mkdir $(ARCHIVE_PREFIX)
171 rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/
172 zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/
173 rm -rf $(ARCHIVE_PREFIX)
174
175##
176# Targets for repository and documentation maintenance
177##
178
179### remove all unversioned files
180clean:
181 @git clean -df
182 @rm -rf sandbox
183
184### generate the AUTHORS file from Git commit information
185authors:
186 @cp .github/mailmap .mailmap
187 @git shortlog -sne > AUTHORS
188 @rm .mailmap
189
190### generate Doxygen documentation
191doxygen: clean
192 @rm -rf doxygen
193 @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
194
195### Convert local markdown documentation to HTML
196#
197# For all pages:
198# - convert GitHub-flavoured relative links to standard Markdown
199# - generate html documentation with mkdocs
200htmlpages:
201 python3 -m venv venv/
202 bash -c 'source venv/bin/activate; \
203 pip install mkdocs; \
204 mkdocs build'
205 find doc/html/ -type f -exec chmod a-x '{}' \;
206 rm -r venv
207
208doc_html: authors htmlpages
209