1.PHONY: pretty clean ChangeLog.md release 2 3########################################################################## 4# configuration 5########################################################################## 6 7# directory to recent compiler binaries 8COMPILER_DIR=/usr/local/opt/llvm/bin 9 10# find GNU sed to use `-i` parameter 11SED:=$(shell command -v gsed || which sed) 12 13 14########################################################################## 15# source files 16########################################################################## 17 18# the list of sources in the include folder 19SRCS=$(shell find include -type f | sort) 20 21# the single header (amalgamated from the source files) 22AMALGAMATED_FILE=single_include/nlohmann/json.hpp 23 24 25########################################################################## 26# documentation of the Makefile's targets 27########################################################################## 28 29# main target 30all: 31 @echo "amalgamate - amalgamate file single_include/nlohmann/json.hpp from the include/nlohmann sources" 32 @echo "ChangeLog.md - generate ChangeLog file" 33 @echo "check-amalgamation - check whether sources have been amalgamated" 34 @echo "clean - remove built files" 35 @echo "doctest - compile example files and check their output" 36 @echo "fuzz_testing - prepare fuzz testing of the JSON parser" 37 @echo "fuzz_testing_bson - prepare fuzz testing of the BSON parser" 38 @echo "fuzz_testing_cbor - prepare fuzz testing of the CBOR parser" 39 @echo "fuzz_testing_msgpack - prepare fuzz testing of the MessagePack parser" 40 @echo "fuzz_testing_ubjson - prepare fuzz testing of the UBJSON parser" 41 @echo "pretty - beautify code with Artistic Style" 42 @echo "run_benchmarks - build and run benchmarks" 43 44 45########################################################################## 46# documentation tests 47########################################################################## 48 49# compile example files and check output 50doctest: 51 $(MAKE) check_output -C doc 52 53 54########################################################################## 55# benchmarks 56########################################################################## 57 58run_benchmarks: 59 rm -fr cmake-build-benchmarks 60 mkdir cmake-build-benchmarks 61 cd cmake-build-benchmarks ; cmake ../benchmarks -GNinja -DCMAKE_BUILD_TYPE=Release -DJSON_BuildTests=On 62 cd cmake-build-benchmarks ; ninja 63 cd cmake-build-benchmarks ; ./json_benchmarks 64 65########################################################################## 66# fuzzing 67########################################################################## 68 69# the overall fuzz testing target 70fuzz_testing: 71 rm -fr fuzz-testing 72 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out 73 $(MAKE) parse_afl_fuzzer -C test CXX=afl-clang++ 74 mv test/parse_afl_fuzzer fuzz-testing/fuzzer 75 find test/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases 76 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer" 77 78fuzz_testing_bson: 79 rm -fr fuzz-testing 80 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out 81 $(MAKE) parse_bson_fuzzer -C test CXX=afl-clang++ 82 mv test/parse_bson_fuzzer fuzz-testing/fuzzer 83 find test/data -size -5k -name *.bson | xargs -I{} cp "{}" fuzz-testing/testcases 84 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer" 85 86fuzz_testing_cbor: 87 rm -fr fuzz-testing 88 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out 89 $(MAKE) parse_cbor_fuzzer -C test CXX=afl-clang++ 90 mv test/parse_cbor_fuzzer fuzz-testing/fuzzer 91 find test/data -size -5k -name *.cbor | xargs -I{} cp "{}" fuzz-testing/testcases 92 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer" 93 94fuzz_testing_msgpack: 95 rm -fr fuzz-testing 96 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out 97 $(MAKE) parse_msgpack_fuzzer -C test CXX=afl-clang++ 98 mv test/parse_msgpack_fuzzer fuzz-testing/fuzzer 99 find test/data -size -5k -name *.msgpack | xargs -I{} cp "{}" fuzz-testing/testcases 100 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer" 101 102fuzz_testing_ubjson: 103 rm -fr fuzz-testing 104 mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out 105 $(MAKE) parse_ubjson_fuzzer -C test CXX=afl-clang++ 106 mv test/parse_ubjson_fuzzer fuzz-testing/fuzzer 107 find test/data -size -5k -name *.ubjson | xargs -I{} cp "{}" fuzz-testing/testcases 108 @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer" 109 110fuzzing-start: 111 afl-fuzz -S fuzzer1 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null & 112 afl-fuzz -S fuzzer2 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null & 113 afl-fuzz -S fuzzer3 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null & 114 afl-fuzz -S fuzzer4 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null & 115 afl-fuzz -S fuzzer5 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null & 116 afl-fuzz -S fuzzer6 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null & 117 afl-fuzz -S fuzzer7 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null & 118 afl-fuzz -M fuzzer0 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer 119 120fuzzing-stop: 121 -killall fuzzer 122 -killall afl-fuzz 123 124 125########################################################################## 126# Static analysis 127########################################################################## 128 129# call PVS-Studio Analyzer <https://www.viva64.com/en/pvs-studio/> 130pvs_studio: 131 rm -fr cmake-build-pvs-studio 132 mkdir cmake-build-pvs-studio 133 cd cmake-build-pvs-studio ; cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DJSON_MultipleHeaders=ON 134 cd cmake-build-pvs-studio ; pvs-studio-analyzer analyze -j 10 135 cd cmake-build-pvs-studio ; plog-converter -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs 136 open cmake-build-pvs-studio/pvs/index.html 137 138########################################################################## 139# Code format and source amalgamation 140########################################################################## 141 142# call the Artistic Style pretty printer on all source files 143pretty: 144 astyle \ 145 --style=allman \ 146 --indent=spaces=4 \ 147 --indent-modifiers \ 148 --indent-switches \ 149 --indent-preproc-block \ 150 --indent-preproc-define \ 151 --indent-col1-comments \ 152 --pad-oper \ 153 --pad-header \ 154 --align-pointer=type \ 155 --align-reference=type \ 156 --add-brackets \ 157 --convert-tabs \ 158 --close-templates \ 159 --lineend=linux \ 160 --preserve-date \ 161 --suffix=none \ 162 --formatted \ 163 $(SRCS) $(AMALGAMATED_FILE) test/src/*.cpp test/src/*.hpp benchmarks/src/benchmarks.cpp doc/examples/*.cpp 164 165# call the Clang-Format on all source files 166pretty_format: 167 for FILE in $(SRCS) $(AMALGAMATED_FILE) test/src/*.cpp test/src/*.hpp benchmarks/src/benchmarks.cpp doc/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done 168 169# create single header file 170amalgamate: $(AMALGAMATED_FILE) 171 172# call the amalgamation tool and pretty print 173$(AMALGAMATED_FILE): $(SRCS) 174 third_party/amalgamate/amalgamate.py -c third_party/amalgamate/config.json -s . --verbose=yes 175 $(MAKE) pretty 176 177# check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources 178# Note: this target is called by Travis 179check-amalgamation: 180 @mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~ 181 @$(MAKE) amalgamate 182 @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) 183 @mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE) 184 185 186########################################################################## 187# ChangeLog 188########################################################################## 189 190# Create a ChangeLog based on the git log using the GitHub Changelog Generator 191# (<https://github.com/github-changelog-generator/github-changelog-generator>). 192 193# variable to control the diffs between the last released version and the current repository state 194NEXT_VERSION ?= "unreleased" 195 196ChangeLog.md: 197 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) 198 $(SED) -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md 199 $(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 200 201 202########################################################################## 203# Release files 204########################################################################## 205 206# Create the files for a release and add signatures and hashes. We use `-X` to make the resulting ZIP file 207# reproducible, see <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>. 208 209release: 210 rm -fr release_files 211 mkdir release_files 212 zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) meson.build LICENSE.MIT 213 gpg --armor --detach-sig include.zip 214 mv include.zip include.zip.asc release_files 215 gpg --armor --detach-sig $(AMALGAMATED_FILE) 216 cp $(AMALGAMATED_FILE) release_files 217 mv $(AMALGAMATED_FILE).asc release_files 218 cd release_files ; shasum -a 256 json.hpp > hashes.txt 219 cd release_files ; shasum -a 256 include.zip >> hashes.txt 220 221 222########################################################################## 223# Maintenance 224########################################################################## 225 226# clean up 227clean: 228 rm -fr json_unit json_benchmarks fuzz fuzz-testing *.dSYM test/*.dSYM oclint_report.html 229 rm -fr benchmarks/files/numbers/*.json 230 rm -fr cmake-3.1.0-Darwin64.tar.gz cmake-3.1.0-Darwin64 231 rm -fr cmake-build-benchmarks cmake-build-pedantic fuzz-testing cmake-build-clang-analyze cmake-build-pvs-studio cmake-build-infer cmake_build 232 $(MAKE) clean -Cdoc 233 234########################################################################## 235# Thirdparty code 236########################################################################## 237 238update_hedley: 239 rm -f include/nlohmann/thirdparty/hedley/hedley.hpp include/nlohmann/thirdparty/hedley/hedley_undef.hpp 240 curl https://raw.githubusercontent.com/nemequ/hedley/master/hedley.h -o include/nlohmann/thirdparty/hedley/hedley.hpp 241 $(SED) -i 's/HEDLEY_/JSON_HEDLEY_/g' include/nlohmann/thirdparty/hedley/hedley.hpp 242 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 243 $(SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley.hpp 244 $(SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley_undef.hpp 245 $(MAKE) amalgamate 246