]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - Makefile
Keep up with master changes
[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
f3e89f50 14
00f98bda 15BIN = vendor/bin
a52e8435
A
16PHP_SOURCE = index.php application tests plugins
17PHP_COMMA_SOURCE = index.php,application,tests,plugins
00f98bda 18
fc17813b 19all: static_analysis_summary check_permissions test
00f98bda
V
20
21##
22# Concise status of the project
00f98bda
V
23# These targets are non-blocking: || exit 0
24##
f3e89f50 25
00f98bda 26static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
ca74886f 27 @echo
00f98bda
V
28
29##
30# PHP_CodeSniffer
00f98bda 31# Detects PHP syntax errors
00f98bda
V
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##
f3e89f50 36
00f98bda
V
37code_sniffer: code_sniffer_full
38
3e25f245
V
39### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
40PHPCS_%:
41 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
42
f3e89f50 43### - errors by Git author
00f98bda
V
44code_sniffer_blame:
45 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
46
f3e89f50 47### - all errors/warnings
00f98bda
V
48code_sniffer_full:
49 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
50
f3e89f50 51### - errors grouped by kind
00f98bda
V
52code_sniffer_source:
53 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
54
55##
56# PHP Copy/Paste Detector
00f98bda 57# Detects code redundancy
00f98bda
V
58# Documentation: https://github.com/sebastianbergmann/phpcpd
59##
f3e89f50 60
00f98bda
V
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
00f98bda 70# Detects PHP syntax errors, sorted by category
00f98bda 71# Rules documentation: http://phpmd.org/rules/index.html
f3e89f50 72##
ca74886f 73MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
f3e89f50 74
00f98bda
V
75mess_title:
76 @echo "-----------------"
77 @echo "PHP MESS DETECTOR"
78 @echo "-----------------"
79
f3e89f50 80### - all warnings
00f98bda 81mess_detector: mess_title
ca74886f 82 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
00f98bda 83
f3e89f50 84### - all warnings + HTML output contains links to PHPMD's documentation
00f98bda 85mess_detector_html:
ca74886f 86 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
00f98bda
V
87 --reportfile phpmd.html || exit 0
88
f3e89f50 89### - warnings grouped by message, sorted by descending frequency order
00f98bda
V
90mess_detector_grouped: mess_title
91 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
92 | cut -f 2 | sort | uniq -c | sort -nr
93
f3e89f50 94### - summary: number of warnings by rule set
00f98bda
V
95mess_detector_summary: mess_title
96 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
ca74886f 97 warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
00f98bda
V
98 printf "$$warnings\t$$rule\n"; \
99 done;
1acc87ee 100
fc17813b
V
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
ca74886f
V
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##
d0ce99e5 123test:
ca74886f
V
124 @echo "-------"
125 @echo "PHPUNIT"
126 @echo "-------"
4bf35ba5 127 @mkdir -p sandbox
ca74886f
V
128 @$(BIN)/phpunit tests
129
559315ba
V
130##
131# Custom release archive generation
132#
133# For each tagged revision, GitHub provides tar and zip archives that correspond
134# to the output of git-archive
135#
136# These targets produce similar archives, featuring 3rd-party dependencies
137# to ease deployment on shared hosting.
138##
139ARCHIVE_VERSION := shaarli-$$(git describe)-full
594477f9 140ARCHIVE_PREFIX=Shaarli/
559315ba
V
141
142release_archive: release_tar release_zip
143
144### download 3rd-party PHP libraries
145composer_dependencies: clean
146 composer update --no-dev
147 find vendor/ -name ".git" -type d -exec rm -rf {} +
148
149### generate a release tarball and include 3rd-party dependencies
150release_tar: composer_dependencies
594477f9
V
151 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD
152 tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/
153 gzip $(ARCHIVE_VERSION).tar
559315ba
V
154
155### generate a release zip and include 3rd-party dependencies
156release_zip: composer_dependencies
594477f9
V
157 git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD
158 mkdir $(ARCHIVE_PREFIX)
159 rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/
160 zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/
161 rm -rf $(ARCHIVE_PREFIX)
559315ba 162
1acc87ee 163##
164# Targets for repository and documentation maintenance
f3e89f50 165##
166
167### remove all unversioned files
1acc87ee 168clean:
d0ce99e5 169 @git clean -df
4bf35ba5 170 @rm -rf sandbox
1acc87ee 171
05af6f53
V
172### generate Doxygen documentation
173doxygen: clean
174 @rm -rf doxygen
175 @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
176
f3e89f50 177### update the local copy of the documentation
1acc87ee 178doc: clean
d0ce99e5
V
179 @rm -rf doc
180 @git clone https://github.com/shaarli/Shaarli.wiki.git doc
181 @rm -rf doc/.git
82af78b2 182
992af0b9
V
183### Generate a custom sidebar
184#
185# Sidebar content:
186# - convert GitHub-flavoured relative links to standard Markdown
187# - trim HTML, only keep the list (<ul>[...]</ul>) part
188htmlsidebar:
189 @echo '<div id="local-sidebar">' > doc/sidebar.html
190 @awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
191 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
192 '!m { print $$0 }' doc/_Sidebar.md > doc/tmp.md
193 @pandoc -f markdown -t html5 -s doc/tmp.md | awk '/(ul>|li>)/' >> doc/sidebar.html
194 @echo '</div>' >> doc/sidebar.html
195 @rm doc/tmp.md
196
82af78b2 197### Convert local markdown documentation to HTML
992af0b9
V
198#
199# For all pages:
200# - infer title from the file name
201# - convert GitHub-flavoured relative links to standard Markdown
202# - insert the sidebar menu
203htmlpages:
204 @for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
205 base=`basename $$file .md`; \
206 sed -i "1i #$${base//-/ }" $$file; \
207 awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
208 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
209 '!m { print $$0 }' $$file > doc/tmp.md; \
210 mv doc/tmp.md $$file; \
211 pandoc -f markdown_github -t html5 -s \
212 -c "github-markdown.css" \
213 -T Shaarli -M pagetitle:"$${base//-/ }" -B doc/sidebar.html \
214 -o doc/$$base.html $$file; \
ca74886f 215 done;
992af0b9
V
216
217htmldoc: doc htmlsidebar htmlpages