1 # The personal, minimalist, super-fast, database free, bookmarking service.
2 # Makefile for PHP code analysis & testing, documentation and release generation
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
11 # - install Xdebug for PHPUnit code coverage reports:
12 # - see http://xdebug.org/docs/install
16 PHP_SOURCE = index.php application tests plugins
17 PHP_COMMA_SOURCE = index.php,application,tests,plugins
19 all: static_analysis_summary check_permissions test
24 # Shaarli sources and vendored libraries are copied from a shared volume
25 # to a user-owned directory to enable running tests as a non-root user.
28 rsync -az /shaarli/ ~/shaarli/
29 cd ~/shaarli && make $*
32 # Concise status of the project
33 # These targets are non-blocking: || exit 0
36 static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
41 # Detects PHP syntax errors
42 # Documentation (usage, output formatting):
43 # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
44 # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
47 code_sniffer: code_sniffer_full
49 ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
51 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
53 ### - errors by Git author
55 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
57 ### - all errors/warnings
59 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
61 ### - errors grouped by kind
63 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
66 # PHP Copy/Paste Detector
67 # Detects code redundancy
68 # Documentation: https://github.com/sebastianbergmann/phpcpd
72 @echo "-----------------------"
73 @echo "PHP COPY/PASTE DETECTOR"
74 @echo "-----------------------"
75 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
80 # Detects PHP syntax errors, sorted by category
81 # Rules documentation: http://phpmd.org/rules/index.html
83 MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
86 @echo "-----------------"
87 @echo "PHP MESS DETECTOR"
88 @echo "-----------------"
91 mess_detector: mess_title
92 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
94 ### - all warnings + HTML output contains links to PHPMD's documentation
96 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
97 --reportfile phpmd.html || exit 0
99 ### - warnings grouped by message, sorted by descending frequency order
100 mess_detector_grouped: mess_title
101 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
102 | cut -f 2 | sort | uniq -c | sort -nr
104 ### - summary: number of warnings by rule set
105 mess_detector_summary: mess_title
106 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
107 warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
108 printf "$$warnings\t$$rule\n"; \
112 # Checks source file & script permissions
115 @echo "----------------------"
116 @echo "Check file permissions"
117 @echo "----------------------"
118 @for file in `git ls-files`; do \
119 if [ -x $$file ]; then \
121 echo "$${file} is executable"; \
123 done; [ -z $$errors ] || false
127 # Runs unitary and functional tests
128 # Generates an HTML coverage report if Xdebug is enabled
130 # See phpunit.xml for configuration
131 # https://phpunit.de/manual/current/en/appendixes.configuration.html
137 @mkdir -p sandbox coverage
138 @$(BIN)/phpunit --coverage-php coverage/main.cov --testsuite unit-tests
143 --coverage-php coverage/$(firstword $(subst _, ,$*)).cov \
144 --bootstrap tests/languages/bootstrap.php \
145 --testsuite language-$(firstword $(subst _, ,$*))
147 all_tests: test locale_test_de_DE locale_test_en_US locale_test_fr_FR
148 @$(BIN)/phpcov merge --html coverage coverage
149 @# --text doesn't work with phpunit 4.* (v5 requires PHP 5.6)
150 @#$(BIN)/phpcov merge --text coverage/txt coverage
153 # Custom release archive generation
155 # For each tagged revision, GitHub provides tar and zip archives that correspond
156 # to the output of git-archive
158 # These targets produce similar archives, featuring 3rd-party dependencies
159 # to ease deployment on shared hosting.
161 ARCHIVE_VERSION := shaarli-$$(git describe)-full
162 ARCHIVE_PREFIX=Shaarli/
164 release_archive: release_tar release_zip
166 ### download 3rd-party PHP libraries
167 composer_dependencies: clean
168 composer install --no-dev --prefer-dist
169 find vendor/ -name ".git" -type d -exec rm -rf {} +
171 ### generate a release tarball and include 3rd-party dependencies
172 release_tar: composer_dependencies htmldoc
173 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD
174 tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/
175 tar rvf $(ARCHIVE_VERSION).tar --transform "s|^doc/html|$(ARCHIVE_PREFIX)doc/html|" doc/html/
176 gzip $(ARCHIVE_VERSION).tar
178 ### generate a release zip and include 3rd-party dependencies
179 release_zip: composer_dependencies htmldoc
180 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD
181 mkdir -p $(ARCHIVE_PREFIX)/{doc,vendor}
182 rsync -a doc/html/ $(ARCHIVE_PREFIX)doc/html/
183 zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)doc/
184 rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/
185 zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/
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
206 @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
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; \
214 find doc/html/ -type f -exec chmod a-x '{}' \;