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
17 PHP_SOURCE = index.php application tests plugins
18 PHP_COMMA_SOURCE = index.php,application,tests,plugins
20 all: static_analysis_summary check_permissions test
23 # Concise status of the project
24 # These targets are non-blocking: || exit 0
27 static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
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
38 code_sniffer: code_sniffer_full
40 ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
42 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
44 ### - errors by Git author
46 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
48 ### - all errors/warnings
50 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
52 ### - errors grouped by kind
54 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
57 # PHP Copy/Paste Detector
58 # Detects code redundancy
59 # Documentation: https://github.com/sebastianbergmann/phpcpd
63 @echo "-----------------------"
64 @echo "PHP COPY/PASTE DETECTOR"
65 @echo "-----------------------"
66 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
71 # Detects PHP syntax errors, sorted by category
72 # Rules documentation: http://phpmd.org/rules/index.html
74 MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
77 @echo "-----------------"
78 @echo "PHP MESS DETECTOR"
79 @echo "-----------------"
82 mess_detector: mess_title
83 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
85 ### - all warnings + HTML output contains links to PHPMD's documentation
87 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
88 --reportfile phpmd.html || exit 0
90 ### - warnings grouped by message, sorted by descending frequency order
91 mess_detector_grouped: mess_title
92 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
93 | cut -f 2 | sort | uniq -c | sort -nr
95 ### - summary: number of warnings by rule set
96 mess_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"; \
103 # Checks source file & script permissions
106 @echo "----------------------"
107 @echo "Check file permissions"
108 @echo "----------------------"
109 @for file in `git ls-files`; do \
110 if [ -x $$file ]; then \
112 echo "$${file} is executable"; \
114 done; [ -z $$errors ] || false
118 # Runs unitary and functional tests
119 # Generates an HTML coverage report if Xdebug is enabled
121 # See phpunit.xml for configuration
122 # https://phpunit.de/manual/current/en/appendixes.configuration.html
129 @$(BIN)/phpunit tests
132 # Custom release archive generation
134 # For each tagged revision, GitHub provides tar and zip archives that correspond
135 # to the output of git-archive
137 # These targets produce similar archives, featuring 3rd-party dependencies
138 # to ease deployment on shared hosting.
140 ARCHIVE_VERSION := shaarli-$$(git describe)-full
141 ARCHIVE_PREFIX=Shaarli/
143 release_archive: release_tar release_zip
145 ### download 3rd-party PHP libraries
146 composer_dependencies: clean
147 composer update --no-dev
148 find vendor/ -name ".git" -type d -exec rm -rf {} +
150 ### generate a release tarball and include 3rd-party dependencies
151 release_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
156 ### generate a release zip and include 3rd-party dependencies
157 release_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)
165 # Targets for repository and documentation maintenance
168 ### remove all unversioned files
173 ### generate Doxygen documentation
176 @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
178 ### update the local copy of the documentation
181 @git clone https://github.com/shaarli/Shaarli.wiki.git doc
184 ### Generate a custom sidebar
187 # - convert GitHub-flavoured relative links to standard Markdown
188 # - trim HTML, only keep the list (<ul>[...]</ul>) part
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
198 ### Convert local markdown documentation to HTML
201 # - infer title from the file name
202 # - convert GitHub-flavoured relative links to standard Markdown
203 # - insert the sidebar menu
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; \
215 -c "github-markdown.css" \
217 -M pagetitle:"$${base//-/ }" \
218 -B doc/sidebar.html \
219 -o doc/$$base.html $$file; \
222 htmldoc: doc htmlsidebar htmlpages