CppCoreGuidelines/scripts/Makefile

108 lines
3.9 KiB
Makefile
Raw Normal View History

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 \
check-references \
2016-04-19 02:42:52 +08:00
check-notabs \
cpplint-all \
2016-04-19 02:42:52 +08:00
check-badchars
2016-04-09 16:54:33 +08:00
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
#### 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
## run remark markdown checker based on configuration in .remarkrc
.PHONY: check-markdown
check-markdown: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile
## run remark, paste output to temporary file
cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed --frail
## show a diff with changes remark suggests
.PHONY: show-diff
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
## 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
## check references unique
rm -f $(BUILD_DIR)/$(SOURCEFILE).uniq
2016-04-09 16:54:33 +08:00
grep -oP '(?<=<a name=")[^\"]+' $(SOURCEPATH) | uniq -d > $(BUILD_DIR)/$(SOURCEFILE).uniq
## check if output has data
if [ -s "build/CppCoreGuidelines.md.uniq" ]; then echo 'Found duplicate anchors:'; cat $(BUILD_DIR)/$(SOURCEFILE).uniq; false; fi
.PHONY: check-notabs
check-notabs: $(SOURCEPATH) $(BUILD_DIR) Makefile
# find lines with tabs
# old file still might be around
rm -f $(BUILD_DIR)/CppCoreGuidelines.md.tabs
# print file, add line numbers, remove tabs from nl tool, grep for remaining tabs, replace with stars
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
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
# find lines with tabs
# old file still might be around
rm -f $(BUILD_DIR)/CppCoreGuidelines.md.badchars
# print file, add line numbers, grep for bad chars
cat ../CppCoreGuidelines.md | nl -ba | grep -P '||”|“|¸||…|¦' > $(BUILD_DIR)/CppCoreGuidelines.md.badchars || true
2016-04-25 04:25: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
#### Cpplint
.PHONY: cpplint-all
cpplint-all: $(BUILD_DIR)/codeblocks $(BUILD_DIR)/Makefile python/Makefile.in
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
cp python/Makefile.in $(BUILD_DIR)/codeblocks/Makefile
#### split md file into plain text and code
$(BUILD_DIR)/codeblocks: splitfile
$(BUILD_DIR)/plain.txt: splitfile
.PHONY: splitfile
splitfile: $(SOURCEPATH) ./python/md-split.py
python ./python/md-split.py $(SOURCEPATH) $(BUILD_DIR)/plain.txt $(BUILD_DIR)/codeblocks
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