Makefile 3.9 KB
Newer Older
N
Niels 已提交
1
.PHONY: pretty clean ChangeLog.md
N
Niels 已提交
2

N
Niels 已提交
3 4
# used programs
RE2C = re2c
N
Niels 已提交
5
SED = sed
N
Niels 已提交
6

N
Niels 已提交
7
# main target
N
Niels 已提交
8 9 10 11
all: json_unit

# clean up
clean:
N
Niels 已提交
12
	rm -fr json_unit json_benchmarks fuzz fuzz-testing *.dSYM
N
Niels 已提交
13
	$(MAKE) clean -Cdoc
N
Niels 已提交
14

N
Niels 已提交
15 16 17 18 19 20

##########################################################################
# unit tests
##########################################################################

# additional flags
N
Niels 已提交
21
FLAGS = -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder -Wdeprecated -Wfloat-equal
N
Niels 已提交
22

23 24
# build unit tests (TODO: Does this want its own makefile?)
json_unit: test/src/unit.cpp src/json.hpp test/src/catch.hpp
25
	$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src -I test $< $(LDFLAGS) -o $@
N
Niels 已提交
26

N
Niels 已提交
27

N
Niels 已提交
28 29 30 31 32 33
##########################################################################
# documentation tests
##########################################################################

# compile example files and check output
doctest:
N
Niels 已提交
34 35 36
	$(MAKE) check_output -C doc


37 38 39 40
##########################################################################
# fuzzing
##########################################################################

N
Niels 已提交
41 42 43 44 45 46
# the overall fuzz testing target
fuzz_testing:
	rm -fr fuzz-testing
	mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
	$(MAKE) fuzz CXX=afl-clang++
	mv fuzz fuzz-testing
47
	find test/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
N
Niels 已提交
48 49 50
	@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzz"

# the fuzzer binary
51
fuzz: test/src/fuzz.cpp src/json.hpp
N
Niels 已提交
52 53
	$(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src $< $(LDFLAGS) -o $@

54

N
Niels 已提交
55 56 57
##########################################################################
# static analyzer
##########################################################################
N
Niels 已提交
58

N
Niels 已提交
59
# call cppcheck on the main header file
N
Niels 已提交
60 61 62
cppcheck:
	cppcheck --enable=all --inconclusive --std=c++11 src/json.hpp

N
Niels 已提交
63 64 65 66 67 68 69

##########################################################################
# maintainer targets
##########################################################################

# create scanner with re2c
re2c: src/json.hpp.re2c
N
Niels 已提交
70
	$(RE2C) --bit-vectors --nested-ifs --no-debug-info $< | $(SED) '1d' > src/json.hpp
N
Niels 已提交
71

N
Niels 已提交
72 73 74 75 76 77
# pretty printer
pretty:
	astyle --style=allman --indent=spaces=4 --indent-modifiers \
	   --indent-switches --indent-preproc-block --indent-preproc-define \
	   --indent-col1-comments --pad-oper --pad-header --align-pointer=type \
	   --align-reference=type --add-brackets --convert-tabs --close-templates \
N
Niels 已提交
78
	   --lineend=linux --preserve-date --suffix=none --formatted \
79
	   src/json.hpp src/json.hpp.re2c test/src/unit.cpp test/src/fuzz.cpp benchmarks/benchmarks.cpp doc/examples/*.cpp
N
Niels 已提交
80

N
Niels 已提交
81 82 83 84

##########################################################################
# benchmarks
##########################################################################
N
Niels 已提交
85 86

# benchmarks
N
Niels 已提交
87
json_benchmarks: benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp src/json.hpp
N
Niels 已提交
88 89
	$(CXX) -std=c++11 $(CXXFLAGS) -O3 -flto -I src -I benchmarks $< $(LDFLAGS) -o $@
	./json_benchmarks
N
Niels 已提交
90 91 92 93 94 95 96


##########################################################################
# changelog
##########################################################################

ChangeLog.md:
N
Niels 已提交
97
	github_changelog_generator -o ChangeLog.md --simple-list --release-url https://github.com/nlohmann/json/releases/tag/%s
N
Niels 已提交
98
	gsed -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md
N
Niels 已提交
99
	gsed -i '2i All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).' ChangeLog.md