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