]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - Makefile
Bump Shaarli version to v0.8.7
[github/shaarli/Shaarli.git] / Makefile
CommitLineData
2d97aa77 1# The personal, minimalist, super-fast, database free, bookmarking service.
559315ba 2# Makefile for PHP code analysis & testing, documentation and release generation
f3e89f50 3
00f98bda
V
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
ca74886f
V
11# - install Xdebug for PHPUnit code coverage reports:
12# - see http://xdebug.org/docs/install
13# - enable in php.ini
754ee049 14SHELL := /bin/bash
f3e89f50 15
00f98bda 16BIN = vendor/bin
a52e8435
A
17PHP_SOURCE = index.php application tests plugins
18PHP_COMMA_SOURCE = index.php,application,tests,plugins
00f98bda 19
fc17813b 20all: static_analysis_summary check_permissions test
00f98bda
V
21
22##
23# Concise status of the project
00f98bda
V
24# These targets are non-blocking: || exit 0
25##
f3e89f50 26
00f98bda 27static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
ca74886f 28 @echo
00f98bda
V
29
30##
31# PHP_CodeSniffer
00f98bda 32# Detects PHP syntax errors
00f98bda
V
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##
f3e89f50 37
00f98bda
V
38code_sniffer: code_sniffer_full
39
3e25f245
V
40### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
41PHPCS_%:
42 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
43
f3e89f50 44### - errors by Git author
00f98bda
V
45code_sniffer_blame:
46 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
47
f3e89f50 48### - all errors/warnings
00f98bda
V
49code_sniffer_full:
50 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
51
f3e89f50 52### - errors grouped by kind
00f98bda
V
53code_sniffer_source:
54 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
55
56##
57# PHP Copy/Paste Detector
00f98bda 58# Detects code redundancy
00f98bda
V
59# Documentation: https://github.com/sebastianbergmann/phpcpd
60##
f3e89f50 61
00f98bda
V
62copy_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
00f98bda 71# Detects PHP syntax errors, sorted by category
00f98bda 72# Rules documentation: http://phpmd.org/rules/index.html
f3e89f50 73##
ca74886f 74MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
f3e89f50 75
00f98bda
V
76mess_title:
77 @echo "-----------------"
78 @echo "PHP MESS DETECTOR"
79 @echo "-----------------"
80
f3e89f50 81### - all warnings
00f98bda 82mess_detector: mess_title
ca74886f 83 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
00f98bda 84
f3e89f50 85### - all warnings + HTML output contains links to PHPMD's documentation
00f98bda 86mess_detector_html:
ca74886f 87 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
00f98bda
V
88 --reportfile phpmd.html || exit 0
89
f3e89f50 90### - warnings grouped by message, sorted by descending frequency order
00f98bda
V
91mess_detector_grouped: mess_title
92 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
93 | cut -f 2 | sort | uniq -c | sort -nr
94
f3e89f50 95### - summary: number of warnings by rule set
00f98bda
V
96mess_detector_summary: mess_title
97 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
ca74886f 98 warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
00f98bda
V
99 printf "$$warnings\t$$rule\n"; \
100 done;
1acc87ee 101
fc17813b
V
102##
103# Checks source file & script permissions
104##
105check_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
ca74886f
V
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##
d0ce99e5 124test:
ca74886f
V
125 @echo "-------"
126 @echo "PHPUNIT"
127 @echo "-------"
4bf35ba5 128 @mkdir -p sandbox
ca74886f
V
129 @$(BIN)/phpunit tests
130
559315ba
V
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##
140ARCHIVE_VERSION := shaarli-$$(git describe)-full
ca0ed5ca 141ARCHIVE_PREFIX=Shaarli/
559315ba
V
142
143release_archive: release_tar release_zip
144
145### download 3rd-party PHP libraries
146composer_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
151release_tar: composer_dependencies
ca0ed5ca
V
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
559315ba
V
155
156### generate a release zip and include 3rd-party dependencies
157release_zip: composer_dependencies
ca0ed5ca
V
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)
559315ba 163
1acc87ee 164##
165# Targets for repository and documentation maintenance
f3e89f50 166##
167
168### remove all unversioned files
1acc87ee 169clean:
d0ce99e5 170 @git clean -df
4bf35ba5 171 @rm -rf sandbox
1acc87ee 172
05af6f53
V
173### generate Doxygen documentation
174doxygen: clean
175 @rm -rf doxygen
176 @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
177
f3e89f50 178### update the local copy of the documentation
1acc87ee 179doc: clean
d0ce99e5
V
180 @rm -rf doc
181 @git clone https://github.com/shaarli/Shaarli.wiki.git doc
182 @rm -rf doc/.git
82af78b2 183
992af0b9
V
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
189htmlsidebar:
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
82af78b2 198### Convert local markdown documentation to HTML
992af0b9
V
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
204htmlpages:
205 @for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
206 base=`basename $$file .md`; \
754ee049 207 sed -i "1i # $${base//-/ }" $$file; \
992af0b9
V
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; \
754ee049
V
212 pandoc -f gfm \
213 -t html5 \
214 -s \
992af0b9 215 -c "github-markdown.css" \
754ee049
V
216 -T Shaarli \
217 -M pagetitle:"$${base//-/ }" \
218 -B doc/sidebar.html \
992af0b9 219 -o doc/$$base.html $$file; \
ca74886f 220 done;
992af0b9
V
221
222htmldoc: doc htmlsidebar htmlpages