1 # The personal, minimalist, super-fast, database free, bookmarking service.
2 # Makefile for PHP code analysis & testing, documentation and release generation
5 PHP_SOURCE = index.php application tests plugins
6 PHP_COMMA_SOURCE = index.php,application,tests,plugins
8 all: static_analysis_summary check_permissions test
13 # Shaarli sources and vendored libraries are copied from a shared volume
14 # to a user-owned directory to enable running tests as a non-root user.
17 rsync -az /shaarli/ ~/shaarli/
18 cd ~/shaarli && make $*
21 # Concise status of the project
22 # These targets are non-blocking: || exit 0
25 static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
30 # Detects PHP syntax errors
31 # Documentation (usage, output formatting):
32 # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
33 # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
36 code_sniffer: code_sniffer_full
38 ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
40 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
42 ### - errors by Git author
44 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
46 ### - all errors/warnings
48 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
50 ### - errors grouped by kind
52 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
55 # PHP Copy/Paste Detector
56 # Detects code redundancy
57 # Documentation: https://github.com/sebastianbergmann/phpcpd
61 @echo "-----------------------"
62 @echo "PHP COPY/PASTE DETECTOR"
63 @echo "-----------------------"
64 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
69 # Detects PHP syntax errors, sorted by category
70 # Rules documentation: http://phpmd.org/rules/index.html
72 MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
75 @echo "-----------------"
76 @echo "PHP MESS DETECTOR"
77 @echo "-----------------"
80 mess_detector: mess_title
81 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
83 ### - all warnings + HTML output contains links to PHPMD's documentation
85 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
86 --reportfile phpmd.html || exit 0
88 ### - warnings grouped by message, sorted by descending frequency order
89 mess_detector_grouped: mess_title
90 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
91 | cut -f 2 | sort | uniq -c | sort -nr
93 ### - summary: number of warnings by rule set
94 mess_detector_summary: mess_title
95 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
96 warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
97 printf "$$warnings\t$$rule\n"; \
101 # Checks source file & script permissions
104 @echo "----------------------"
105 @echo "Check file permissions"
106 @echo "----------------------"
107 @for file in `git ls-files | grep -v docker`; do \
108 if [ -x $$file ]; then \
110 echo "$${file} is executable"; \
112 done; [ -z $$errors ] || false
116 # Runs unitary and functional tests
117 # Generates an HTML coverage report if Xdebug is enabled
119 # See phpunit.xml for configuration
120 # https://phpunit.de/manual/current/en/appendixes.configuration.html
126 @mkdir -p sandbox coverage
127 @$(BIN)/phpunit --coverage-php coverage/main.cov --bootstrap tests/bootstrap.php --testsuite unit-tests
132 --coverage-php coverage/$(firstword $(subst _, ,$*)).cov \
133 --bootstrap tests/languages/bootstrap.php \
134 --testsuite language-$(firstword $(subst _, ,$*))
136 all_tests: test locale_test_de_DE locale_test_en_US locale_test_fr_FR
137 @$(BIN)/phpcov merge --html coverage coverage
138 @# --text doesn't work with phpunit 4.* (v5 requires PHP 5.6)
139 @#$(BIN)/phpcov merge --text coverage/txt coverage
142 # Custom release archive generation
144 # For each tagged revision, GitHub provides tar and zip archives that correspond
145 # to the output of git-archive
147 # These targets produce similar archives, featuring 3rd-party dependencies
148 # to ease deployment on shared hosting.
150 ARCHIVE_VERSION := shaarli-$$(git describe)-full
151 ARCHIVE_PREFIX=Shaarli/
153 release_archive: release_tar release_zip
155 ### download 3rd-party PHP libraries
156 composer_dependencies: clean
157 composer install --no-dev --prefer-dist
158 find vendor/ -name ".git" -type d -exec rm -rf {} +
160 ### download 3rd-party frontend libraries
161 frontend_dependencies:
164 ### Build frontend dependencies
165 build_frontend: frontend_dependencies
168 ### generate a release tarball and include 3rd-party dependencies and translations
169 release_tar: composer_dependencies htmldoc translate build_frontend
170 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD
171 tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/
172 tar rvf $(ARCHIVE_VERSION).tar --transform "s|^doc/html|$(ARCHIVE_PREFIX)doc/html|" doc/html/
173 tar rvf $(ARCHIVE_VERSION).tar --transform "s|^tpl|$(ARCHIVE_PREFIX)tpl|" tpl/
174 gzip $(ARCHIVE_VERSION).tar
176 ### generate a release zip and include 3rd-party dependencies and translations
177 release_zip: composer_dependencies htmldoc translate build_frontend
178 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD
179 mkdir -p $(ARCHIVE_PREFIX)/{doc,vendor}
180 rsync -a doc/html/ $(ARCHIVE_PREFIX)doc/html/
181 zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)doc/
182 rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/
183 zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/
184 rsync -a tpl/ $(ARCHIVE_PREFIX)tpl/
185 zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)tpl/
186 rm -rf $(ARCHIVE_PREFIX)
189 # Targets for repository and documentation maintenance
192 ### remove all unversioned files
197 ### generate the AUTHORS file from Git commit information
199 @cp .github/mailmap .mailmap
200 @git shortlog -sne > AUTHORS
203 ### generate Doxygen documentation
208 ### generate HTML documentation from Markdown pages with MkDocs
210 python3 -m venv venv/
211 bash -c 'source venv/bin/activate; \
212 pip install mkdocs; \
213 mkdocs build --clean'
214 find doc/html/ -type f -exec chmod a-x '{}' \;
218 ### Generate Shaarli's translation compiled file (.mo)
220 @find inc/languages/ -name shaarli.po -execdir msgfmt shaarli.po -o shaarli.mo \;
222 ### Run ESLint check against Shaarli's JS files
224 @yarn run eslint -c .dev/.eslintrc.js assets/vintage/js/
225 @yarn run eslint -c .dev/.eslintrc.js assets/default/js/
227 ### Run CSSLint check against Shaarli's SCSS files
229 @yarn run sass-lint -c .dev/.sasslintrc 'assets/default/scss/*.scss' -v -q