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
22 # Concise status of the project
23 # These targets are non-blocking: || exit 0
26 static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
31 # Detects PHP syntax errors
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
37 code_sniffer: code_sniffer_full
39 ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend...
41 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$*
43 ### - errors by Git author
45 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
47 ### - all errors/warnings
49 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
51 ### - errors grouped by kind
53 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
56 # PHP Copy/Paste Detector
57 # Detects code redundancy
58 # Documentation: https://github.com/sebastianbergmann/phpcpd
62 @echo "-----------------------"
63 @echo "PHP COPY/PASTE DETECTOR"
64 @echo "-----------------------"
65 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
70 # Detects PHP syntax errors, sorted by category
71 # Rules documentation: http://phpmd.org/rules/index.html
73 MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
76 @echo "-----------------"
77 @echo "PHP MESS DETECTOR"
78 @echo "-----------------"
81 mess_detector: mess_title
82 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
84 ### - all warnings + HTML output contains links to PHPMD's documentation
86 @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \
87 --reportfile phpmd.html || exit 0
89 ### - warnings grouped by message, sorted by descending frequency order
90 mess_detector_grouped: mess_title
91 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
92 | cut -f 2 | sort | uniq -c | sort -nr
94 ### - summary: number of warnings by rule set
95 mess_detector_summary: mess_title
96 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
97 warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \
98 printf "$$warnings\t$$rule\n"; \
102 # Checks source file & script permissions
105 @echo "----------------------"
106 @echo "Check file permissions"
107 @echo "----------------------"
108 @for file in `git ls-files`; do \
109 if [ -x $$file ]; then \
111 echo "$${file} is executable"; \
113 done; [ -z $$errors ] || false
117 # Runs unitary and functional tests
118 # Generates an HTML coverage report if Xdebug is enabled
120 # See phpunit.xml for configuration
121 # https://phpunit.de/manual/current/en/appendixes.configuration.html
128 @$(BIN)/phpunit tests
131 # Custom release archive generation
133 # For each tagged revision, GitHub provides tar and zip archives that correspond
134 # to the output of git-archive
136 # These targets produce similar archives, featuring 3rd-party dependencies
137 # to ease deployment on shared hosting.
139 ARCHIVE_VERSION := shaarli-$$(git describe)-full
140 ARCHIVE_PREFIX=Shaarli/
142 release_archive: release_tar release_zip
144 ### download 3rd-party PHP libraries
145 composer_dependencies: clean
146 composer update --no-dev
147 find vendor/ -name ".git" -type d -exec rm -rf {} +
149 ### generate a release tarball and include 3rd-party dependencies
150 release_tar: composer_dependencies
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
155 ### generate a release zip and include 3rd-party dependencies
156 release_zip: composer_dependencies
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)
164 # Targets for repository and documentation maintenance
167 ### remove all unversioned files
172 ### generate the AUTHORS file from Git commit information
174 @cp .github/mailmap .mailmap
175 @git shortlog -sne > AUTHORS
178 ### generate Doxygen documentation
181 @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
183 ### update the local copy of the documentation
186 @git clone https://github.com/shaarli/Shaarli.wiki.git doc
189 ### Generate a custom sidebar
192 # - convert GitHub-flavoured relative links to standard Markdown
193 # - trim HTML, only keep the list (<ul>[...]</ul>) part
195 @echo '<div id="local-sidebar">' > doc/sidebar.html
196 @awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
197 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
198 '!m { print $$0 }' doc/_Sidebar.md > doc/tmp.md
199 @pandoc -f markdown -t html5 -s doc/tmp.md | awk '/(ul>|li>)/' >> doc/sidebar.html
200 @echo '</div>' >> doc/sidebar.html
203 ### Convert local markdown documentation to HTML
206 # - infer title from the file name
207 # - convert GitHub-flavoured relative links to standard Markdown
208 # - insert the sidebar menu
210 @for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
211 base=`basename $$file .md`; \
212 sed -i "1i #$${base//-/ }" $$file; \
213 awk 'BEGIN { FS = "[\\[\\]]{2}" }'\
214 'm = /\[/ { t=$$2; gsub(/ /, "-", $$2); print $$1"["t"]("$$2".html)"$$3 }'\
215 '!m { print $$0 }' $$file > doc/tmp.md; \
216 mv doc/tmp.md $$file; \
217 pandoc -f markdown_github -t html5 -s \
218 -c "github-markdown.css" \
219 -T Shaarli -M pagetitle:"$${base//-/ }" -B doc/sidebar.html \
220 -o doc/$$base.html $$file; \
223 htmldoc: authors doc htmlsidebar htmlpages