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 ### generate a release tarball and include 3rd-party dependencies and translations
161 release_tar: composer_dependencies htmldoc translate
162 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD
163 tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/
164 tar rvf $(ARCHIVE_VERSION).tar --transform "s|^doc/html|$(ARCHIVE_PREFIX)doc/html|" doc/html/
165 gzip $(ARCHIVE_VERSION).tar
167 ### generate a release zip and include 3rd-party dependencies and translations
168 release_zip: composer_dependencies htmldoc translate
169 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD
170 mkdir -p $(ARCHIVE_PREFIX)/{doc,vendor}
171 rsync -a doc/html/ $(ARCHIVE_PREFIX)doc/html/
172 zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)doc/
173 rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/
174 zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/
175 rm -rf $(ARCHIVE_PREFIX)
178 # Targets for repository and documentation maintenance
181 ### remove all unversioned files
186 ### generate the AUTHORS file from Git commit information
188 @cp .github/mailmap .mailmap
189 @git shortlog -sne > AUTHORS
192 ### generate Doxygen documentation
195 @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
197 ### generate HTML documentation from Markdown pages with MkDocs
199 python3 -m venv venv/
200 bash -c 'source venv/bin/activate; \
201 pip install mkdocs; \
203 find doc/html/ -type f -exec chmod a-x '{}' \;
207 ### Generate Shaarli's translation compiled file (.mo)
209 @find inc/languages/ -name shaarli.po -execdir msgfmt shaarli.po -o shaarli.mo \;