2016-04-09 16:54:33 +08:00
|
|
|
|
# This Makefile is supposed to run on the Travis CI server and also locally
|
|
|
|
|
# it assumes the nodejs package managaer npm is installed
|
|
|
|
|
|
|
|
|
|
# make magic not needed
|
|
|
|
|
MAKEFLAGS += --no-builtin-rules
|
|
|
|
|
.SUFFIXES:
|
|
|
|
|
|
|
|
|
|
BUILD_DIR=build
|
|
|
|
|
SOURCEFILE = CppCoreGuidelines.md
|
|
|
|
|
SOURCEPATH = ../$(SOURCEFILE)
|
|
|
|
|
|
|
|
|
|
.PHONY: default
|
|
|
|
|
default: all
|
|
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
|
all: \
|
|
|
|
|
check-markdown \
|
2016-04-18 00:55:21 +08:00
|
|
|
|
check-references \
|
2016-04-19 02:42:52 +08:00
|
|
|
|
check-notabs \
|
2016-05-13 22:14:52 +08:00
|
|
|
|
hunspell-check \
|
2016-04-25 04:19:50 +08:00
|
|
|
|
cpplint-all \
|
2016-04-19 02:42:52 +08:00
|
|
|
|
check-badchars
|
2016-04-09 16:54:33 +08:00
|
|
|
|
|
|
|
|
|
$(BUILD_DIR):
|
2016-07-29 05:09:05 +08:00
|
|
|
|
@mkdir -p $(BUILD_DIR)
|
2016-04-09 16:54:33 +08:00
|
|
|
|
|
|
|
|
|
#### clean: remove all files generated by the productive rules
|
|
|
|
|
.PHONY: clean
|
|
|
|
|
clean:
|
|
|
|
|
rm -rf $(BUILD_DIR)
|
|
|
|
|
|
|
|
|
|
#### distclean: remove all helper executables that may be downloaded by the Makefile
|
|
|
|
|
.PHONY: distclean
|
|
|
|
|
distclean:
|
|
|
|
|
rm -rf ./nodejs/node_modules
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### check markdown
|
|
|
|
|
|
2016-08-23 17:04:01 +08:00
|
|
|
|
## run remark markdown checker based on configuration in .remarkrc
|
2016-04-09 16:54:33 +08:00
|
|
|
|
.PHONY: check-markdown
|
2016-08-23 17:04:01 +08:00
|
|
|
|
check-markdown: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile
|
|
|
|
|
echo '##################### Markdown check ##################'
|
2016-04-09 16:54:33 +08:00
|
|
|
|
## run remark, paste output to temporary file
|
2016-08-23 17:04:01 +08:00
|
|
|
|
cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed --frail
|
2016-04-09 16:54:33 +08:00
|
|
|
|
|
|
|
|
|
## show a diff with changes remark suggests
|
|
|
|
|
.PHONY: show-diff
|
2016-08-23 17:04:01 +08:00
|
|
|
|
show-diff: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile
|
|
|
|
|
cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed
|
2016-04-09 16:54:33 +08:00
|
|
|
|
## compare temporary file to original, error and fail with message if differences exist
|
|
|
|
|
diff $(SOURCEPATH) $(BUILD_DIR)/$(SOURCEFILE).fixed -u3 || \
|
|
|
|
|
(echo "Error: remark found bad markdown syntax, see output above" && false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: check-references
|
|
|
|
|
check-references: $(SOURCEPATH) $(BUILD_DIR) Makefile
|
2016-08-23 17:04:01 +08:00
|
|
|
|
@echo '##################### References check ##################'
|
2016-04-09 16:54:33 +08:00
|
|
|
|
## check references unique
|
2016-07-29 05:09:05 +08:00
|
|
|
|
@rm -f $(BUILD_DIR)/$(SOURCEFILE).uniq
|
2017-02-04 03:44:20 +08:00
|
|
|
|
@cat $(SOURCEPATH) | perl -ne 'print "$$1\n" if (/<a name="([^\"]+)/)' | sort | uniq -d > $(BUILD_DIR)/$(SOURCEFILE).uniq
|
2016-04-09 16:54:33 +08:00
|
|
|
|
## check if output has data
|
2016-07-29 05:09:05 +08:00
|
|
|
|
@if [ -s "build/CppCoreGuidelines.md.uniq" ]; then echo 'Found duplicate anchors:'; cat $(BUILD_DIR)/$(SOURCEFILE).uniq; false; fi
|
2016-04-09 16:54:33 +08:00
|
|
|
|
|
2016-04-18 00:55:21 +08:00
|
|
|
|
.PHONY: check-notabs
|
|
|
|
|
check-notabs: $(SOURCEPATH) $(BUILD_DIR) Makefile
|
2016-08-23 17:04:01 +08:00
|
|
|
|
@echo '##################### Tabs check ##################'
|
2016-04-18 00:55:21 +08:00
|
|
|
|
# find lines with tabs
|
|
|
|
|
# old file still might be around
|
2016-07-29 05:09:05 +08:00
|
|
|
|
@rm -f $(BUILD_DIR)/CppCoreGuidelines.md.tabs
|
2016-04-18 00:55:21 +08:00
|
|
|
|
# print file, add line numbers, remove tabs from nl tool, grep for remaining tabs, replace with stars
|
2017-02-04 03:44:20 +08:00
|
|
|
|
@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
|
2016-07-29 05:09:05 +08:00
|
|
|
|
@if [ -s $(BUILD_DIR)/CppCoreGuidelines.md.tabs ]; then echo 'Warning: Tabs found:'; cat $(BUILD_DIR)/CppCoreGuidelines.md.tabs; false; fi;
|
2016-04-09 16:54:33 +08:00
|
|
|
|
|
2016-04-19 02:42:52 +08:00
|
|
|
|
.PHONY: check-badchars
|
|
|
|
|
check-badchars: $(SOURCEPATH) $(BUILD_DIR) Makefile
|
2016-08-23 17:04:01 +08:00
|
|
|
|
@echo '##################### Bad chars check ##################'
|
2016-04-19 02:42:52 +08:00
|
|
|
|
# find lines with tabs
|
|
|
|
|
# old file still might be around
|
2016-07-29 05:09:05 +08:00
|
|
|
|
@rm -f $(BUILD_DIR)/CppCoreGuidelines.md.badchars
|
2016-04-19 02:42:52 +08:00
|
|
|
|
# print file, add line numbers, grep for bad chars
|
2017-02-04 03:44:20 +08:00
|
|
|
|
@cat ../$(SOURCEFILE) | nl -ba | perl -ne 'print if /’|‘|”|“|¸|–|…|¦/' > $(BUILD_DIR)/$(SOURCEFILE).badchars || true
|
2016-07-29 05:09:05 +08:00
|
|
|
|
@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;
|
2016-04-19 02:42:52 +08:00
|
|
|
|
|
2016-04-25 04:19:50 +08:00
|
|
|
|
|
2016-05-13 22:14:52 +08:00
|
|
|
|
.PHONY: hunspell-check
|
|
|
|
|
hunspell-check: $(BUILD_DIR)/plain-nohtml.txt
|
2016-08-23 17:04:01 +08:00
|
|
|
|
@echo '##################### Spell check ##################'
|
2017-02-08 04:46:04 +08:00
|
|
|
|
hunspell -d hunspell/en_US -p hunspell/isocpp.dic -u < build/plain-nohtml.txt > $(BUILD_DIR)/hunspell-report.txt
|
2016-08-23 17:04:01 +08:00
|
|
|
|
@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;
|
2016-05-13 22:14:52 +08:00
|
|
|
|
|
|
|
|
|
# only list words that are not in dict
|
|
|
|
|
# to include all add them to bottom of hunspell/isocpp.dict, and run
|
|
|
|
|
# cat hunspell/isocpp.dic | sort | uniq > hunspell/isocpp.dic2; mv hunspell/isocpp.dic2 hunspell/isocpp.dic
|
|
|
|
|
.PHONY: hunspell-list
|
|
|
|
|
hunspell-list: $(BUILD_DIR)/plain.txt
|
|
|
|
|
hunspell -p hunspell/isocpp.dic -l < build/plain-nohtml.txt
|
2016-04-25 04:19:50 +08:00
|
|
|
|
|
|
|
|
|
#### Cpplint
|
|
|
|
|
|
|
|
|
|
.PHONY: cpplint-all
|
|
|
|
|
cpplint-all: $(BUILD_DIR)/codeblocks $(BUILD_DIR)/Makefile python/Makefile.in
|
2016-08-23 17:04:01 +08:00
|
|
|
|
@echo '##################### C++ Style check ##################'
|
2016-04-25 04:19:50 +08:00
|
|
|
|
cd $(BUILD_DIR)/codeblocks; $(MAKE) cpplint-all -k
|
|
|
|
|
|
|
|
|
|
#### generic makefile for sourceblocks (need to be evaluated after c++ file generation)
|
|
|
|
|
|
|
|
|
|
$(BUILD_DIR)/Makefile: python/Makefile.in
|
2016-07-29 05:09:05 +08:00
|
|
|
|
@cp python/Makefile.in $(BUILD_DIR)/codeblocks/Makefile
|
2016-04-25 04:19:50 +08:00
|
|
|
|
|
|
|
|
|
#### split md file into plain text and code
|
|
|
|
|
|
|
|
|
|
$(BUILD_DIR)/codeblocks: splitfile
|
|
|
|
|
|
|
|
|
|
$(BUILD_DIR)/plain.txt: splitfile
|
|
|
|
|
|
2016-05-13 22:14:52 +08:00
|
|
|
|
$(BUILD_DIR)/plain-nohtml.txt: $(BUILD_DIR)/plain.txt
|
|
|
|
|
sed 's;<a \(name\|href\)=".*</a>;;g' $(BUILD_DIR)/plain.txt > $(BUILD_DIR)/plain-nohtml.txt
|
|
|
|
|
|
2016-04-25 04:19:50 +08:00
|
|
|
|
.PHONY: splitfile
|
|
|
|
|
splitfile: $(SOURCEPATH) ./python/md-split.py
|
2016-07-29 05:09:05 +08:00
|
|
|
|
@python ./python/md-split.py $(SOURCEPATH) $(BUILD_DIR)/plain.txt $(BUILD_DIR)/codeblocks
|
2016-04-25 04:19:50 +08:00
|
|
|
|
|
2016-04-09 16:54:33 +08:00
|
|
|
|
#### install npm modules
|
|
|
|
|
# install/update npm dependencies defined in file package.json
|
|
|
|
|
# requires npm (nodejs package manager)
|
|
|
|
|
nodejs/node_modules/%: nodejs/package.json
|
|
|
|
|
@cd nodejs; npm install
|