Debian Codegraph @

Makefile

raw symbols SCIP
1 .PHONY: pretty clean ChangeLog.md release
2
3 ##########################################################################
4 # configuration
5 ##########################################################################
6
7 # find GNU sed to use `-i` parameter
8 SED:=$(shell command -v gsed || which sed)
9
10
11 ##########################################################################
12 # source files
13 ##########################################################################
14
15 # the list of sources in the include folder
16 SRCS=$(shell find include -type f | sort)
17
18 # the list of sources in the tests folder
19 TESTS_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)
22 AMALGAMATED_FILE=single_include/nlohmann/json.hpp
23 AMALGAMATED_FWD_FILE=single_include/nlohmann/json_fwd.hpp
24
25
26 ##########################################################################
27 # documentation of the Makefile's targets
28 ##########################################################################
29
30 # main target
31 all:
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 # benchmarks
48 ##########################################################################
49
50 run_benchmarks:
51 rm -fr cmake-build-benchmarks
52 mkdir cmake-build-benchmarks
53 cd cmake-build-benchmarks ; cmake ../tests/benchmarks -GNinja -DCMAKE_BUILD_TYPE=Release
54 cd cmake-build-benchmarks ; ninja
55 cd cmake-build-benchmarks ; ./json_benchmarks
56
57
58 ##########################################################################
59 # fuzzing
60 ##########################################################################
61
62 # the overall fuzz testing target
63 fuzz_testing:
64 rm -fr fuzz-testing
65 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
66 $(MAKE) parse_afl_fuzzer -C tests CXX=afl-clang++
67 mv tests/parse_afl_fuzzer fuzz-testing/fuzzer
68 find tests/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
69 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
70
71 fuzz_testing_bson:
72 rm -fr fuzz-testing
73 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
74 $(MAKE) parse_bson_fuzzer -C tests CXX=afl-clang++
75 mv tests/parse_bson_fuzzer fuzz-testing/fuzzer
76 find tests/data -size -5k -name *.bson | xargs -I{} cp "{}" fuzz-testing/testcases
77 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
78
79 fuzz_testing_cbor:
80 rm -fr fuzz-testing
81 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
82 $(MAKE) parse_cbor_fuzzer -C tests CXX=afl-clang++
83 mv tests/parse_cbor_fuzzer fuzz-testing/fuzzer
84 find tests/data -size -5k -name *.cbor | xargs -I{} cp "{}" fuzz-testing/testcases
85 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
86
87 fuzz_testing_msgpack:
88 rm -fr fuzz-testing
89 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
90 $(MAKE) parse_msgpack_fuzzer -C tests CXX=afl-clang++
91 mv tests/parse_msgpack_fuzzer fuzz-testing/fuzzer
92 find tests/data -size -5k -name *.msgpack | xargs -I{} cp "{}" fuzz-testing/testcases
93 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
94
95 fuzz_testing_ubjson:
96 rm -fr fuzz-testing
97 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
98 $(MAKE) parse_ubjson_fuzzer -C tests CXX=afl-clang++
99 mv tests/parse_ubjson_fuzzer fuzz-testing/fuzzer
100 find tests/data -size -5k -name *.ubjson | xargs -I{} cp "{}" fuzz-testing/testcases
101 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
102
103 fuzzing-start:
104 afl-fuzz -S fuzzer1 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
105 afl-fuzz -S fuzzer2 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
106 afl-fuzz -S fuzzer3 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
107 afl-fuzz -S fuzzer4 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
108 afl-fuzz -S fuzzer5 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
109 afl-fuzz -S fuzzer6 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
110 afl-fuzz -S fuzzer7 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
111 afl-fuzz -M fuzzer0 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer
112
113 fuzzing-stop:
114 -killall fuzzer
115 -killall afl-fuzz
116
117
118 ##########################################################################
119 # Static analysis
120 ##########################################################################
121
122 # call PVS-Studio Analyzer <https://www.viva64.com/en/pvs-studio/>
123 pvs_studio:
124 rm -fr cmake-build-pvs-studio
125 mkdir cmake-build-pvs-studio
126 cd cmake-build-pvs-studio ; cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DJSON_MultipleHeaders=ON
127 cd cmake-build-pvs-studio ; pvs-studio-analyzer analyze -j 10
128 cd cmake-build-pvs-studio ; plog-converter -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs
129 open cmake-build-pvs-studio/pvs/index.html
130
131
132 ##########################################################################
133 # Code format and source amalgamation
134 ##########################################################################
135
136 ASTYLE=tools/astyle/venv/bin/astyle
137
138 install_astyle:
139 @test -d tools/astyle/venv || python3 -mvenv tools/astyle/venv ; tools/astyle/venv/bin/pip3 install --quiet --upgrade pip
140 @test -f $(ASTYLE) || tools/astyle/venv/bin/pip3 install --quiet -r tools/astyle/requirements.txt
141 @$(ASTYLE) --version
142
143 # call the Artistic Style pretty printer on all source files
144 pretty: install_astyle
145 $(ASTYLE) --project=tools/astyle/.astylerc $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) docs/mkdocs/docs/examples/*.cpp
146
147 # call the Clang-Format on all source files
148 pretty_format:
149 for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/mkdocs/docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done
150
151 # create single header files and pretty print
152 amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE)
153 $(MAKE) pretty
154
155 # call the amalgamation tool for json.hpp
156 $(AMALGAMATED_FILE): $(SRCS)
157 tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json.json -s . --verbose=yes
158
159 # call the amalgamation tool for json_fwd.hpp
160 $(AMALGAMATED_FWD_FILE): $(SRCS)
161 tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json_fwd.json -s . --verbose=yes
162
163 # check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources
164 # Note: this target is called by Travis
165 check-amalgamation:
166 @mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~
167 @mv $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~
168 @$(MAKE) amalgamate
169 @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)
170 @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)
171 @mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE)
172 @mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE)
173
174 BUILD.bazel: $(SRCS)
175 cmake -P cmake/scripts/gen_bazel_build_file.cmake
176
177 ##########################################################################
178 # ChangeLog
179 ##########################################################################
180
181 # Create a ChangeLog based on the git log using the GitHub Changelog Generator
182 # (<https://github.com/github-changelog-generator/github-changelog-generator>).
183
184 # variable to control the diffs between the last released version and the current repository state
185 NEXT_VERSION ?= "unreleased"
186
187 ChangeLog.md:
188 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)
189 $(SED) -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md
190 $(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
191
192
193 ##########################################################################
194 # Release files
195 ##########################################################################
196
197 # Create a tar.xz archive that contains sufficient files to be used as CMake project (e.g., using FetchContent). The
198 # archive is created according to the advices of <https://reproducible-builds.org/docs/archives/>.
199 json.tar.xz:
200 mkdir json
201 rsync -R $(shell find LICENSE.MIT nlohmann_json.natvis CMakeLists.txt cmake/*.in include single_include -type f) json
202 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
203 rm -fr json
204
205 # We use `-X` to make the resulting ZIP file reproducible, see
206 # <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>.
207 include.zip: BUILD.bazel
208 zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) BUILD.bazel WORKSPACE.bazel meson.build LICENSE.MIT
209
210 # Create the files for a release and add signatures and hashes.
211 release: include.zip json.tar.xz
212 rm -fr release_files
213 mkdir release_files
214 gpg --armor --detach-sig include.zip
215 gpg --armor --detach-sig $(AMALGAMATED_FILE)
216 gpg --armor --detach-sig $(AMALGAMATED_FWD_FILE)
217 gpg --armor --detach-sig json.tar.xz
218 cp $(AMALGAMATED_FILE) release_files
219 cp $(AMALGAMATED_FWD_FILE) release_files
220 mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
221 cd release_files ; shasum -a 256 json.hpp include.zip json.tar.xz > hashes.txt
222
223
224 ##########################################################################
225 # Maintenance
226 ##########################################################################
227
228 # clean up
229 clean:
230 rm -fr fuzz fuzz-testing *.dSYM tests/*.dSYM
231 rm -fr benchmarks/files/numbers/*.json
232 rm -fr cmake-build-benchmarks fuzz-testing cmake-build-pvs-studio release_files
233 $(MAKE) clean -Cdocs
234
235
236 ##########################################################################
237 # Thirdparty code
238 ##########################################################################
239
240 update_hedley:
241 rm -f include/nlohmann/thirdparty/hedley/hedley.hpp include/nlohmann/thirdparty/hedley/hedley_undef.hpp
242 curl https://raw.githubusercontent.com/nemequ/hedley/master/hedley.h -o include/nlohmann/thirdparty/hedley/hedley.hpp
243 $(SED) -i 's/HEDLEY_/JSON_HEDLEY_/g' include/nlohmann/thirdparty/hedley/hedley.hpp
244 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
245 $(SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley.hpp
246 $(SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley_undef.hpp
247 $(MAKE) amalgamate
248
249 ##########################################################################
250 # serve_header.py
251 ##########################################################################
252
253 serve_header:
254 ./tools/serve_header/serve_header.py --make $(MAKE)
255
256 ##########################################################################
257 # REUSE
258 ##########################################################################
259
260 reuse:
261 pipx run reuse annotate --recursive single_include include -tjson --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2025" --merge-copyrights
262 pipx run reuse annotate $(TESTS_SRCS) -tjson_support --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2025" --merge-copyrights
263 pipx run reuse lint
264
265 spdx:
266 pipx run reuse spdx --output nlohmann_json.spdx --creator-person "Niels Lohmann" --add-license-concluded