]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - Makefile
Merge branch 'pandoc' into next
[github/shaarli/Shaarli.git] / Makefile
1 # Shaarli, the personal, minimalist, super-fast, no-database delicious clone.
2 # Makefile for PHP code analysis & testing
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
12 BIN = vendor/bin
13 PHP_SOURCE = index.php
14 MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode
15
16 all: static_analysis_summary
17
18 ##
19 # Concise status of the project
20 # These targets are non-blocking: || exit 0
21 ##
22
23 static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary
24
25 ##
26 # PHP_CodeSniffer
27 # Detects PHP syntax errors
28 # Documentation (usage, output formatting):
29 # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php
30 # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
31 ##
32
33 code_sniffer: code_sniffer_full
34
35 ### - errors by Git author
36 code_sniffer_blame:
37 @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame
38
39 ### - all errors/warnings
40 code_sniffer_full:
41 @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200
42
43 ### - errors grouped by kind
44 code_sniffer_source:
45 @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0
46
47 ##
48 # PHP Copy/Paste Detector
49 # Detects code redundancy
50 # Documentation: https://github.com/sebastianbergmann/phpcpd
51 ##
52
53 copy_paste:
54 @echo "-----------------------"
55 @echo "PHP COPY/PASTE DETECTOR"
56 @echo "-----------------------"
57 @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0
58 @echo
59
60 ##
61 # PHP Mess Detector
62 # Detects PHP syntax errors, sorted by category
63 # Rules documentation: http://phpmd.org/rules/index.html
64 ##
65
66 mess_title:
67 @echo "-----------------"
68 @echo "PHP MESS DETECTOR"
69 @echo "-----------------"
70
71 ### - all warnings
72 mess_detector: mess_title
73 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__'
74
75 ### - all warnings + HTML output contains links to PHPMD's documentation
76 mess_detector_html:
77 @$(BIN)/phpmd $(PHP_SOURCE) html $(MESS_DETECTOR_RULES) \
78 --reportfile phpmd.html || exit 0
79
80 ### - warnings grouped by message, sorted by descending frequency order
81 mess_detector_grouped: mess_title
82 @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \
83 | cut -f 2 | sort | uniq -c | sort -nr
84
85 ### - summary: number of warnings by rule set
86 mess_detector_summary: mess_title
87 @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \
88 warnings=$$($(BIN)/phpmd $(PHP_SOURCE) text $$rule | wc -l); \
89 printf "$$warnings\t$$rule\n"; \
90 done;
91
92 ##
93 # Targets for repository and documentation maintenance
94 ##
95
96 ### remove all unversioned files
97 clean:
98 @git clean -df
99
100 ### update the local copy of the documentation
101 doc: clean
102 @rm -rf doc
103 @git clone https://github.com/shaarli/Shaarli.wiki.git doc
104 @rm -rf doc/.git
105
106 ### Convert local markdown documentation to HTML
107 htmldoc:
108 for file in `find doc/ -maxdepth 1 -name "*.md"`; do \
109 pandoc -f markdown_github -t html5 -s -c "github-markdown.css" -o doc/`basename $$file .md`.html "$$file"; \
110 done;