• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.PHONY: pretty clean ChangeLog.md release
2
3##########################################################################
4# configuration
5##########################################################################
6
7# find GNU sed to use `-i` parameter
8SED:=$(shell command -v gsed || which sed)
9
10
11##########################################################################
12# source files
13##########################################################################
14
15# the list of sources in the include folder
16SRCS=$(shell find include -type f | sort)
17
18# the list of sources in the tests folder
19TESTS_SRCS=$(shell find tests -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
20
21# the single headers (amalgamated from the source files)
22AMALGAMATED_FILE=single_include/nlohmann/json.hpp
23AMALGAMATED_FWD_FILE=single_include/nlohmann/json_fwd.hpp
24
25
26##########################################################################
27# documentation of the Makefile's targets
28##########################################################################
29
30# main target
31all:
32	@echo "amalgamate - amalgamate files single_include/nlohmann/json{,_fwd}.hpp from the include/nlohmann sources"
33	@echo "ChangeLog.md - generate ChangeLog file"
34	@echo "check-amalgamation - check whether sources have been amalgamated"
35	@echo "clean - remove built files"
36	@echo "doctest - compile example files and check their output"
37	@echo "fuzz_testing - prepare fuzz testing of the JSON parser"
38	@echo "fuzz_testing_bson - prepare fuzz testing of the BSON parser"
39	@echo "fuzz_testing_cbor - prepare fuzz testing of the CBOR parser"
40	@echo "fuzz_testing_msgpack - prepare fuzz testing of the MessagePack parser"
41	@echo "fuzz_testing_ubjson - prepare fuzz testing of the UBJSON parser"
42	@echo "pretty - beautify code with Artistic Style"
43	@echo "run_benchmarks - build and run benchmarks"
44
45
46##########################################################################
47# documentation tests
48##########################################################################
49
50# compile example files and check output
51doctest:
52	$(MAKE) check_output -C docs
53
54
55##########################################################################
56# benchmarks
57##########################################################################
58
59run_benchmarks:
60	rm -fr cmake-build-benchmarks
61	mkdir cmake-build-benchmarks
62	cd cmake-build-benchmarks ; cmake ../tests/benchmarks -GNinja -DCMAKE_BUILD_TYPE=Release
63	cd cmake-build-benchmarks ; ninja
64	cd cmake-build-benchmarks ; ./json_benchmarks
65
66
67##########################################################################
68# fuzzing
69##########################################################################
70
71# the overall fuzz testing target
72fuzz_testing:
73	rm -fr fuzz-testing
74	mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
75	$(MAKE) parse_afl_fuzzer -C tests CXX=afl-clang++
76	mv tests/parse_afl_fuzzer fuzz-testing/fuzzer
77	find tests/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
78	@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
79
80fuzz_testing_bson:
81	rm -fr fuzz-testing
82	mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
83	$(MAKE) parse_bson_fuzzer -C tests CXX=afl-clang++
84	mv tests/parse_bson_fuzzer fuzz-testing/fuzzer
85	find tests/data -size -5k -name *.bson | xargs -I{} cp "{}" fuzz-testing/testcases
86	@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
87
88fuzz_testing_cbor:
89	rm -fr fuzz-testing
90	mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
91	$(MAKE) parse_cbor_fuzzer -C tests CXX=afl-clang++
92	mv tests/parse_cbor_fuzzer fuzz-testing/fuzzer
93	find tests/data -size -5k -name *.cbor | xargs -I{} cp "{}" fuzz-testing/testcases
94	@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
95
96fuzz_testing_msgpack:
97	rm -fr fuzz-testing
98	mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
99	$(MAKE) parse_msgpack_fuzzer -C tests CXX=afl-clang++
100	mv tests/parse_msgpack_fuzzer fuzz-testing/fuzzer
101	find tests/data -size -5k -name *.msgpack | xargs -I{} cp "{}" fuzz-testing/testcases
102	@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
103
104fuzz_testing_ubjson:
105	rm -fr fuzz-testing
106	mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
107	$(MAKE) parse_ubjson_fuzzer -C tests CXX=afl-clang++
108	mv tests/parse_ubjson_fuzzer fuzz-testing/fuzzer
109	find tests/data -size -5k -name *.ubjson | xargs -I{} cp "{}" fuzz-testing/testcases
110	@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
111
112fuzzing-start:
113	afl-fuzz -S fuzzer1 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
114	afl-fuzz -S fuzzer2 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
115	afl-fuzz -S fuzzer3 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
116	afl-fuzz -S fuzzer4 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
117	afl-fuzz -S fuzzer5 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
118	afl-fuzz -S fuzzer6 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
119	afl-fuzz -S fuzzer7 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
120	afl-fuzz -M fuzzer0 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer
121
122fuzzing-stop:
123	-killall fuzzer
124	-killall afl-fuzz
125
126
127##########################################################################
128# Static analysis
129##########################################################################
130
131# call PVS-Studio Analyzer <https://www.viva64.com/en/pvs-studio/>
132pvs_studio:
133	rm -fr cmake-build-pvs-studio
134	mkdir cmake-build-pvs-studio
135	cd cmake-build-pvs-studio ; cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DJSON_MultipleHeaders=ON
136	cd cmake-build-pvs-studio ; pvs-studio-analyzer analyze -j 10
137	cd cmake-build-pvs-studio ; plog-converter -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs
138	open cmake-build-pvs-studio/pvs/index.html
139
140
141##########################################################################
142# Code format and source amalgamation
143##########################################################################
144
145# call the Artistic Style pretty printer on all source files
146pretty:
147	astyle \
148	    --style=allman \
149	    --indent=spaces=4 \
150	    --indent-modifiers \
151	    --indent-switches \
152	    --indent-preproc-block \
153	    --indent-preproc-define \
154	    --indent-col1-comments \
155	    --pad-oper \
156	    --pad-header \
157	    --align-pointer=type \
158	    --align-reference=type \
159	    --add-brackets \
160	    --convert-tabs \
161	    --close-templates \
162	    --lineend=linux \
163	    --preserve-date \
164	    --suffix=none \
165	    --formatted \
166	   $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) docs/examples/*.cpp
167
168# call the Clang-Format on all source files
169pretty_format:
170	for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done
171
172# create single header files and pretty print
173amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE)
174	$(MAKE) pretty
175
176# call the amalgamation tool for json.hpp
177$(AMALGAMATED_FILE): $(SRCS)
178	tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json.json -s . --verbose=yes
179
180# call the amalgamation tool for json_fwd.hpp
181$(AMALGAMATED_FWD_FILE): $(SRCS)
182	tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json_fwd.json -s . --verbose=yes
183
184# check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources
185# Note: this target is called by Travis
186check-amalgamation:
187	@mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~
188	@mv $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~
189	@$(MAKE) amalgamate
190	@diff $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~ || (echo "===================================================================\n  Amalgamation required! Please read the contribution guidelines\n  in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE) ; false)
191	@diff $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~ || (echo "===================================================================\n  Amalgamation required! Please read the contribution guidelines\n  in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE) ; false)
192	@mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE)
193	@mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE)
194
195
196##########################################################################
197# ChangeLog
198##########################################################################
199
200# Create a ChangeLog based on the git log using the GitHub Changelog Generator
201# (<https://github.com/github-changelog-generator/github-changelog-generator>).
202
203# variable to control the diffs between the last released version and the current repository state
204NEXT_VERSION ?= "unreleased"
205
206ChangeLog.md:
207	github_changelog_generator -o ChangeLog.md --user nlohmann --project json --simple-list --release-url https://github.com/nlohmann/json/releases/tag/%s --future-release $(NEXT_VERSION)
208	$(SED) -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md
209	$(SED) -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
210
211
212##########################################################################
213# Release files
214##########################################################################
215
216# Create a tar.gz archive that contains sufficient files to be used as CMake project (e.g., using FetchContent). The
217# archive is created according to the advices of <https://reproducible-builds.org/docs/archives/>.
218json.tar.xz:
219	mkdir json
220	rsync -R $(shell find LICENSE.MIT nlohmann_json.natvis CMakeLists.txt cmake/*.in include single_include -type f) json
221	gtar --sort=name --mtime="@$(shell git log -1 --pretty=%ct)" --owner=0 --group=0 --numeric-owner --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime --create --file - json | xz --compress -9e --threads=2 - > json.tar.xz
222	rm -fr json
223
224# We use `-X` to make the resulting ZIP file reproducible, see
225# <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>.
226include.zip:
227	zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) meson.build LICENSE.MIT
228
229# Create the files for a release and add signatures and hashes.
230release: include.zip json.tar.xz
231	rm -fr release_files
232	mkdir release_files
233	gpg --armor --detach-sig include.zip
234	gpg --armor --detach-sig $(AMALGAMATED_FILE)
235	gpg --armor --detach-sig $(AMALGAMATED_FWD_FILE)
236	gpg --armor --detach-sig json.tar.xz
237	cp $(AMALGAMATED_FILE) release_files
238	cp $(AMALGAMATED_FWD_FILE) release_files
239	mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
240	cd release_files ; shasum -a 256 json.hpp include.zip json.tar.xz > hashes.txt
241
242
243##########################################################################
244# Maintenance
245##########################################################################
246
247# clean up
248clean:
249	rm -fr fuzz fuzz-testing *.dSYM tests/*.dSYM
250	rm -fr benchmarks/files/numbers/*.json
251	rm -fr cmake-build-benchmarks fuzz-testing cmake-build-pvs-studio release_files
252	$(MAKE) clean -Cdocs
253
254
255##########################################################################
256# Thirdparty code
257##########################################################################
258
259update_hedley:
260	rm -f include/nlohmann/thirdparty/hedley/hedley.hpp include/nlohmann/thirdparty/hedley/hedley_undef.hpp
261	curl https://raw.githubusercontent.com/nemequ/hedley/master/hedley.h -o include/nlohmann/thirdparty/hedley/hedley.hpp
262	$(SED) -i 's/HEDLEY_/JSON_HEDLEY_/g' include/nlohmann/thirdparty/hedley/hedley.hpp
263	grep "[[:blank:]]*#[[:blank:]]*undef" include/nlohmann/thirdparty/hedley/hedley.hpp | grep -v "__" | sort | uniq | $(SED) 's/ //g' | $(SED) 's/undef/undef /g' > include/nlohmann/thirdparty/hedley/hedley_undef.hpp
264	$(SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley.hpp
265	$(SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley_undef.hpp
266	$(MAKE) amalgamate
267
268##########################################################################
269# serve_header.py
270##########################################################################
271
272serve_header:
273	./tools/serve_header/serve_header.py --make $(MAKE)
274
275##########################################################################
276# REUSE
277##########################################################################
278
279reuse:
280	pipx run reuse addheader --recursive single_include include -tjson --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2022"
281	pipx run reuse addheader $(TESTS_SRCS) --style=c -tjson_support --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2022"
282	pipx run reuse lint
283