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-braces \ 160 --squeeze-lines=2 \ 161 --convert-tabs \ 162 --close-templates \ 163 --lineend=linux \ 164 --preserve-date \ 165 --suffix=none \ 166 --formatted \ 167 $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) docs/examples/*.cpp 168 169# call the Clang-Format on all source files 170pretty_format: 171 for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done 172 173# create single header files and pretty print 174amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) 175 $(MAKE) pretty 176 177# call the amalgamation tool for json.hpp 178$(AMALGAMATED_FILE): $(SRCS) 179 tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json.json -s . --verbose=yes 180 181# call the amalgamation tool for json_fwd.hpp 182$(AMALGAMATED_FWD_FILE): $(SRCS) 183 tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json_fwd.json -s . --verbose=yes 184 185# check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources 186# Note: this target is called by Travis 187check-amalgamation: 188 @mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~ 189 @mv $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~ 190 @$(MAKE) amalgamate 191 @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) 192 @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) 193 @mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE) 194 @mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE) 195 196BUILD.bazel: $(SRCS) 197 cmake -P cmake/scripts/gen_bazel_build_file.cmake 198 199########################################################################## 200# ChangeLog 201########################################################################## 202 203# Create a ChangeLog based on the git log using the GitHub Changelog Generator 204# (<https://github.com/github-changelog-generator/github-changelog-generator>). 205 206# variable to control the diffs between the last released version and the current repository state 207NEXT_VERSION ?= "unreleased" 208 209ChangeLog.md: 210 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) 211 $(SED) -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md 212 $(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 213 214 215########################################################################## 216# Release files 217########################################################################## 218 219# Create a tar.gz archive that contains sufficient files to be used as CMake project (e.g., using FetchContent). The 220# archive is created according to the advices of <https://reproducible-builds.org/docs/archives/>. 221json.tar.xz: 222 mkdir json 223 rsync -R $(shell find LICENSE.MIT nlohmann_json.natvis CMakeLists.txt cmake/*.in include single_include -type f) json 224 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 225 rm -fr json 226 227# We use `-X` to make the resulting ZIP file reproducible, see 228# <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>. 229include.zip: BUILD.bazel 230 zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) BUILD.bazel WORKSPACE.bazel meson.build LICENSE.MIT 231 232# Create the files for a release and add signatures and hashes. 233release: include.zip json.tar.xz 234 rm -fr release_files 235 mkdir release_files 236 gpg --armor --detach-sig include.zip 237 gpg --armor --detach-sig $(AMALGAMATED_FILE) 238 gpg --armor --detach-sig $(AMALGAMATED_FWD_FILE) 239 gpg --armor --detach-sig json.tar.xz 240 cp $(AMALGAMATED_FILE) release_files 241 cp $(AMALGAMATED_FWD_FILE) release_files 242 mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files 243 cd release_files ; shasum -a 256 json.hpp include.zip json.tar.xz > hashes.txt 244 245 246########################################################################## 247# Maintenance 248########################################################################## 249 250# clean up 251clean: 252 rm -fr fuzz fuzz-testing *.dSYM tests/*.dSYM 253 rm -fr benchmarks/files/numbers/*.json 254 rm -fr cmake-build-benchmarks fuzz-testing cmake-build-pvs-studio release_files 255 $(MAKE) clean -Cdocs 256 257 258########################################################################## 259# Thirdparty code 260########################################################################## 261 262update_hedley: 263 rm -f include/nlohmann/thirdparty/hedley/hedley.hpp include/nlohmann/thirdparty/hedley/hedley_undef.hpp 264 curl https://raw.githubusercontent.com/nemequ/hedley/master/hedley.h -o include/nlohmann/thirdparty/hedley/hedley.hpp 265 $(SED) -i 's/HEDLEY_/JSON_HEDLEY_/g' include/nlohmann/thirdparty/hedley/hedley.hpp 266 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 267 $(SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley.hpp 268 $(SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley_undef.hpp 269 $(MAKE) amalgamate 270 271########################################################################## 272# serve_header.py 273########################################################################## 274 275serve_header: 276 ./tools/serve_header/serve_header.py --make $(MAKE) 277 278########################################################################## 279# REUSE 280########################################################################## 281 282reuse: 283 pipx run reuse addheader --recursive single_include include -tjson --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2022" 284 pipx run reuse addheader $(TESTS_SRCS) --style=c -tjson_support --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2022" 285 pipx run reuse lint 286