Merge pull request #598 from tkruse/fix-bad-chars2
[CppCoreGuidelines.git] / scripts / Makefile
blobada1344e037fa39167e5c7edd85de73a2d29f5f9
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 cpplint-all \
21 check-badchars
23 $(BUILD_DIR):
24 mkdir -p $(BUILD_DIR)
26 #### clean: remove all files generated by the productive rules
27 .PHONY: clean
28 clean:
29 rm -rf $(BUILD_DIR)
31 #### distclean: remove all helper executables that may be downloaded by the Makefile
32 .PHONY: distclean
33 distclean:
34 rm -rf ./nodejs/node_modules
37 #### check markdown
39 ## run remark markdown checker based on configuration in .remarkrc
40 .PHONY: check-markdown
41 check-markdown: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile
42 ## run remark, paste output to temporary file
43 cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed --frail
45 ## show a diff with changes remark suggests
46 .PHONY: show-diff
47 show-diff: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile
48 cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed
49 ## compare temporary file to original, error and fail with message if differences exist
50 diff $(SOURCEPATH) $(BUILD_DIR)/$(SOURCEFILE).fixed -u3 || \
51 (echo "Error: remark found bad markdown syntax, see output above" && false)
54 .PHONY: check-references
55 check-references: $(SOURCEPATH) $(BUILD_DIR) Makefile
56 ## check references unique
57 rm -f $(BUILD_DIR)/$(SOURCEFILE).uniq
58 grep -oP '(?<=<a name=")[^\"]+' $(SOURCEPATH) | uniq -d > $(BUILD_DIR)/$(SOURCEFILE).uniq
59 ## check if output has data
60 if [ -s "build/CppCoreGuidelines.md.uniq" ]; then echo 'Found duplicate anchors:'; cat $(BUILD_DIR)/$(SOURCEFILE).uniq; false; fi
62 .PHONY: check-notabs
63 check-notabs: $(SOURCEPATH) $(BUILD_DIR) Makefile
64 # find lines with tabs
65 # old file still might be around
66 rm -f $(BUILD_DIR)/CppCoreGuidelines.md.tabs
67 # print file, add line numbers, remove tabs from nl tool, grep for remaining tabs, replace with stars
68 cat ../CppCoreGuidelines.md | nl -ba | sed -s 's/\(^[^\t]*\)\t/\1--/g' | grep -P '\t' | sed -s 's/\t/\*\*\*\*/g' > $(BUILD_DIR)/CppCoreGuidelines.md.tabs
69 if [ -s $(BUILD_DIR)/CppCoreGuidelines.md.tabs ]; then echo 'Warning: Tabs found:'; cat $(BUILD_DIR)/CppCoreGuidelines.md.tabs; false; fi;
71 .PHONY: check-badchars
72 check-badchars: $(SOURCEPATH) $(BUILD_DIR) Makefile
73 # find lines with tabs
74 # old file still might be around
75 rm -f $(BUILD_DIR)/CppCoreGuidelines.md.badchars
76 # print file, add line numbers, grep for bad chars
77 cat ../CppCoreGuidelines.md | nl -ba | grep -P '’|‘|”|“|¸|–|…|¦' > $(BUILD_DIR)/CppCoreGuidelines.md.badchars || true
78 if [ -s $(BUILD_DIR)/CppCoreGuidelines.md.badchars ]; then echo 'Warning: Undesired chars (–’‘“”¸…¦) found, use straight quotes instead:'; cat $(BUILD_DIR)/CppCoreGuidelines.md.badchars; false; fi;
82 #### Cpplint
84 .PHONY: cpplint-all
85 cpplint-all: $(BUILD_DIR)/codeblocks $(BUILD_DIR)/Makefile python/Makefile.in
86 cd $(BUILD_DIR)/codeblocks; $(MAKE) cpplint-all -k
88 #### generic makefile for sourceblocks (need to be evaluated after c++ file generation)
90 $(BUILD_DIR)/Makefile: python/Makefile.in
91 cp python/Makefile.in $(BUILD_DIR)/codeblocks/Makefile
93 #### split md file into plain text and code
95 $(BUILD_DIR)/codeblocks: splitfile
97 $(BUILD_DIR)/plain.txt: splitfile
99 .PHONY: splitfile
100 splitfile: $(SOURCEPATH) ./python/md-split.py
101 python ./python/md-split.py $(SOURCEPATH) $(BUILD_DIR)/plain.txt $(BUILD_DIR)/codeblocks
103 #### install npm modules
104 # install/update npm dependencies defined in file package.json
105 # requires npm (nodejs package manager)
106 nodejs/node_modules/%: nodejs/package.json
107 @cd nodejs; npm install