Makefile 3.5 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
	$(MAKE) clean -Ctest
N
Niels 已提交
16

N
Niels 已提交
17 18 19 20 21

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

N
Niels 已提交
22 23 24
# build unit tests
json_unit:
	@$(MAKE) -C test
N
Niels 已提交
25

N
Niels 已提交
26 27 28
# run unit tests
check: json_unit
	test/json_unit "*"
N
Niels 已提交
29

N
Niels 已提交
30

N
Niels 已提交
31 32 33 34 35 36
##########################################################################
# documentation tests
##########################################################################

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


40 41 42 43
##########################################################################
# fuzzing
##########################################################################

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

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

57

N
Niels 已提交
58 59 60
##########################################################################
# static analyzer
##########################################################################
N
Niels 已提交
61

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

N
Niels 已提交
66 67 68 69 70 71 72

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

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

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

N
Niels 已提交
85 86 87 88

##########################################################################
# benchmarks
##########################################################################
N
Niels 已提交
89 90

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


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

N
Niels 已提交
101 102
NEXT_VERSION ?= "unreleased"

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