Makefile 4.0 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
	rm -fr benchmarks/files/numbers/*.json
N
Niels 已提交
14
	$(MAKE) clean -Cdoc
N
Niels 已提交
15

N
Niels 已提交
16 17 18 19 20 21

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

# additional flags
N
Niels 已提交
22
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 已提交
23

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

N
Niels 已提交
28

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

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


38 39 40 41
##########################################################################
# fuzzing
##########################################################################

N
Niels 已提交
42 43 44 45 46 47
# 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
48
	find test/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
N
Niels 已提交
49 50 51
	@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzz"

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

55

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

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

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

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

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

N
Niels 已提交
73 74 75 76 77 78
# 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 已提交
79
	   --lineend=linux --preserve-date --suffix=none --formatted \
80
	   src/json.hpp src/json.hpp.re2c test/src/unit.cpp test/src/fuzz.cpp benchmarks/benchmarks.cpp doc/examples/*.cpp
N
Niels 已提交
81

N
Niels 已提交
82 83 84 85

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

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


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

N
Niels 已提交
98 99
NEXT_VERSION ?= "unreleased"

N
Niels 已提交
100
ChangeLog.md:
N
Niels 已提交
101
	github_changelog_generator -o ChangeLog.md --simple-list --release-url https://github.com/nlohmann/json/releases/tag/%s --future-release $(NEXT_VERSION)
N
Niels 已提交
102
	gsed -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md
N
Niels 已提交
103
	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