Replace R.5 exception and examples with moving a BigObject to the heap to save stack
[CppCoreGuidelines.git] / scripts / Makefile
blob8ed3311f2842fc855df4b0111347507c0046541a
1 # This Makefile is supposed to run on the Travis CI server and also locally
2 # it assumes the nodejs package managaer npm is installed
4 # make magic not needed
5 MAKEFLAGS += --no-builtin-rules
6 .SUFFIXES:
8 BUILD_DIR=build
9 SOURCEFILE = CppCoreGuidelines.md
10 SOURCEPATH = ../$(SOURCEFILE)
12 .PHONY: default
13 default: all
15 .PHONY: all
16 all: \
17 check-markdown \
18 check-references \
19 check-notabs \
20 hunspell-check \
21 cpplint-all \
22 check-badchars
24 $(BUILD_DIR):
25 @mkdir -p $(BUILD_DIR)
27 #### clean: remove all files generated by the productive rules
28 .PHONY: clean
29 clean:
30 rm -rf $(BUILD_DIR)
32 #### distclean: remove all helper executables that may be downloaded by the Makefile
33 .PHONY: distclean
34 distclean:
35 rm -rf ./nodejs/node_modules
38 #### check markdown
40 ## run remark markdown checker based on configuration in .remarkrc
41 .PHONY: check-markdown
42 check-markdown: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile
43 echo '##################### Markdown check ##################'
44 ## run remark, paste output to temporary file
45 cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed --frail
47 ## show a diff with changes remark suggests
48 .PHONY: show-diff
49 show-diff: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile
50 cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed
51 ## compare temporary file to original, error and fail with message if differences exist
52 diff $(SOURCEPATH) $(BUILD_DIR)/$(SOURCEFILE).fixed -u3 || \
53 (echo "Error: remark found bad markdown syntax, see output above" && false)
56 .PHONY: check-references
57 check-references: $(SOURCEPATH) $(BUILD_DIR) Makefile
58 @echo '##################### References check ##################'
59 ## check references unique
60 @rm -f $(BUILD_DIR)/$(SOURCEFILE).uniq
61 @cat $(SOURCEPATH) | perl -ne 'print "$$1\n" if (/<a name="([^\"]+)/)' | sort | uniq -d > $(BUILD_DIR)/$(SOURCEFILE).uniq
62 ## check if output has data
63 @if [ -s "build/CppCoreGuidelines.md.uniq" ]; then echo 'Found duplicate anchors:'; cat $(BUILD_DIR)/$(SOURCEFILE).uniq; false; fi
65 .PHONY: check-notabs
66 check-notabs: $(SOURCEPATH) $(BUILD_DIR) Makefile
67 @echo '##################### Tabs check ##################'
68 # find lines with tabs
69 # old file still might be around
70 @rm -f $(BUILD_DIR)/CppCoreGuidelines.md.tabs
71 # print file, add line numbers, remove tabs from nl tool, grep for remaining tabs, replace with stars
72 @cat ../$(SOURCEFILE) | nl -ba | perl -pe 's/(^[^\t]*)\t/$1--/g' | perl -ne 'print if /\t/' | perl -pe 's/\t/\*\*\*\*/g' > $(BUILD_DIR)/$(SOURCEFILE).tabs
73 @if [ -s $(BUILD_DIR)/CppCoreGuidelines.md.tabs ]; then echo 'Warning: Tabs found:'; cat $(BUILD_DIR)/CppCoreGuidelines.md.tabs; false; fi;
75 .PHONY: check-badchars
76 check-badchars: $(SOURCEPATH) $(BUILD_DIR) Makefile
77 @echo '##################### Bad chars check ##################'
78 # find lines with tabs
79 # old file still might be around
80 @rm -f $(BUILD_DIR)/CppCoreGuidelines.md.badchars
81 # print file, add line numbers, grep for bad chars
82 @cat ../$(SOURCEFILE) | nl -ba | perl -ne 'print if /’|‘|”|“|¸| |–|…|¦/' > $(BUILD_DIR)/$(SOURCEFILE).badchars || true
83 @if [ -s $(BUILD_DIR)/CppCoreGuidelines.md.badchars ]; then echo 'Warning: Undesired chars (–’‘“”¸…¦) or Unicode EN SPACE found, use markdown-compatible symbols instead:'; cat $(BUILD_DIR)/CppCoreGuidelines.md.badchars; false; fi;
86 .PHONY: hunspell-check
87 hunspell-check: $(BUILD_DIR)/plain-nohtml.txt
88 @echo '##################### Spell check ##################'
89 sed -e 's!http\(s\)\{0,1\}://[^[:space:]]*!!g' build/plain-nohtml.txt | hunspell -d hunspell/en_US -p hunspell/isocpp.dic -u > $(BUILD_DIR)/hunspell-report.txt
90 @if [ -s $(BUILD_DIR)/hunspell-report.txt ]; then echo 'Warning: Spellcheck failed, fix words or add to dictionary:'; cat $(BUILD_DIR)/hunspell-report.txt; false; fi;
92 # only list words that are not in dict
93 # to include all add them to bottom of hunspell/isocpp.dict, and run
94 # cat hunspell/isocpp.dic | sort | uniq > hunspell/isocpp.dic2; mv hunspell/isocpp.dic2 hunspell/isocpp.dic
95 .PHONY: hunspell-list
96 hunspell-list: $(BUILD_DIR)/plain.txt
97 sed -e 's!http\(s\)\{0,1\}://[^[:space:]]*!!g' build/plain-nohtml.txt | hunspell -p hunspell/isocpp.dic -l
99 #### Cpplint
101 .PHONY: cpplint-all
102 cpplint-all: $(BUILD_DIR)/codeblocks $(BUILD_DIR)/Makefile python/Makefile.in
103 @echo '##################### C++ Style check ##################'
104 cd $(BUILD_DIR)/codeblocks; $(MAKE) cpplint-all -k
106 #### generic makefile for sourceblocks (need to be evaluated after c++ file generation)
108 $(BUILD_DIR)/Makefile: python/Makefile.in
109 @cp python/Makefile.in $(BUILD_DIR)/codeblocks/Makefile
111 #### split md file into plain text and code
113 $(BUILD_DIR)/codeblocks: splitfile
115 $(BUILD_DIR)/plain.txt: splitfile
117 $(BUILD_DIR)/plain-nohtml.txt: $(BUILD_DIR)/plain.txt
118 sed 's;<a \(name\|href\)=".*</a>;;g' $(BUILD_DIR)/plain.txt > $(BUILD_DIR)/plain-nohtml.txt
120 .PHONY: splitfile
121 splitfile: $(SOURCEPATH) ./python/md-split.py
122 @python ./python/md-split.py $(SOURCEPATH) $(BUILD_DIR)/plain.txt $(BUILD_DIR)/codeblocks
124 #### install npm modules
125 # install/update npm dependencies defined in file package.json
126 # requires npm (nodejs package manager)
127 nodejs/node_modules/%: nodejs/package.json
128 @cd nodejs; npm install