2019-03-28 13:22:48 +00:00
.PHONY : pretty clean ChangeLog .md release
2017-08-14 12:41:01 +00:00
2019-03-28 13:22:48 +00:00
##########################################################################
# configuration
##########################################################################
2018-01-29 10:21:11 +00:00
2019-03-28 13:22:48 +00:00
# find GNU sed to use `-i` parameter
SED := $( shell command -v gsed || which sed)
##########################################################################
# source files
##########################################################################
# the list of sources in the include folder
SRCS = $( shell find include -type f | sort)
2022-07-30 19:59:13 +00:00
# the list of sources in the tests folder
2022-07-31 13:28:01 +00:00
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)
2022-07-30 19:59:13 +00:00
2022-08-07 11:57:32 +00:00
# the single headers (amalgamated from the source files)
2019-03-28 13:22:48 +00:00
AMALGAMATED_FILE = single_include/nlohmann/json.hpp
2022-08-07 11:57:32 +00:00
AMALGAMATED_FWD_FILE = single_include/nlohmann/json_fwd.hpp
2019-03-28 13:22:48 +00:00
##########################################################################
# documentation of the Makefile's targets
##########################################################################
2017-08-14 12:41:01 +00:00
# main target
2016-11-27 15:19:26 +00:00
all :
2022-08-07 11:57:32 +00:00
@echo "amalgamate - amalgamate files single_include/nlohmann/json{,_fwd}.hpp from the include/nlohmann sources"
2017-10-04 17:27:35 +00:00
@echo "ChangeLog.md - generate ChangeLog file"
2018-01-14 12:08:28 +00:00
@echo "check-amalgamation - check whether sources have been amalgamated"
2017-10-04 17:27:35 +00:00
@echo "clean - remove built files"
@echo "doctest - compile example files and check their output"
@echo "fuzz_testing - prepare fuzz testing of the JSON parser"
2018-10-24 13:43:37 +00:00
@echo "fuzz_testing_bson - prepare fuzz testing of the BSON parser"
2017-10-04 17:27:35 +00:00
@echo "fuzz_testing_cbor - prepare fuzz testing of the CBOR parser"
@echo "fuzz_testing_msgpack - prepare fuzz testing of the MessagePack parser"
2018-01-27 17:38:11 +00:00
@echo "fuzz_testing_ubjson - prepare fuzz testing of the UBJSON parser"
2017-10-04 17:27:35 +00:00
@echo "pretty - beautify code with Artistic Style"
2018-02-10 13:46:39 +00:00
@echo "run_benchmarks - build and run benchmarks"
2015-02-13 21:12:27 +00:00
2019-03-28 13:22:48 +00:00
2016-02-14 15:42:48 +00:00
##########################################################################
# documentation tests
##########################################################################
# compile example files and check output
doctest :
2022-05-01 07:41:50 +00:00
$( MAKE) check_output -C docs
2016-05-29 12:06:43 +00:00
2018-02-10 13:46:39 +00:00
##########################################################################
# benchmarks
##########################################################################
run_benchmarks :
2020-07-23 11:02:53 +00:00
rm -fr cmake-build-benchmarks
mkdir cmake-build-benchmarks
2022-05-01 07:41:50 +00:00
cd cmake-build-benchmarks ; cmake ../tests/benchmarks -GNinja -DCMAKE_BUILD_TYPE= Release
2020-07-23 11:02:53 +00:00
cd cmake-build-benchmarks ; ninja
cd cmake-build-benchmarks ; ./json_benchmarks
2018-02-10 13:46:39 +00:00
2022-01-25 18:53:02 +00:00
2016-02-12 09:35:08 +00:00
##########################################################################
# fuzzing
##########################################################################
2016-02-14 17:38:29 +00:00
# the overall fuzz testing target
fuzz_testing :
rm -fr fuzz-testing
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
2022-05-01 07:41:50 +00:00
$( MAKE) parse_afl_fuzzer -C tests CXX = afl-clang++
mv tests/parse_afl_fuzzer fuzz-testing/fuzzer
find tests/data/json_tests -size -5k -name *json | xargs -I{ } cp "{}" fuzz-testing/testcases
2016-12-22 10:09:26 +00:00
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
2016-02-14 17:38:29 +00:00
2018-10-24 13:43:37 +00:00
fuzz_testing_bson :
rm -fr fuzz-testing
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
2022-05-01 07:41:50 +00:00
$( MAKE) parse_bson_fuzzer -C tests CXX = afl-clang++
mv tests/parse_bson_fuzzer fuzz-testing/fuzzer
find tests/data -size -5k -name *.bson | xargs -I{ } cp "{}" fuzz-testing/testcases
2018-10-24 13:43:37 +00:00
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
2016-12-22 11:08:36 +00:00
fuzz_testing_cbor :
rm -fr fuzz-testing
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
2022-05-01 07:41:50 +00:00
$( MAKE) parse_cbor_fuzzer -C tests CXX = afl-clang++
mv tests/parse_cbor_fuzzer fuzz-testing/fuzzer
find tests/data -size -5k -name *.cbor | xargs -I{ } cp "{}" fuzz-testing/testcases
2016-12-22 11:08:36 +00:00
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
2016-12-25 15:18:56 +00:00
fuzz_testing_msgpack :
rm -fr fuzz-testing
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
2022-05-01 07:41:50 +00:00
$( MAKE) parse_msgpack_fuzzer -C tests CXX = afl-clang++
mv tests/parse_msgpack_fuzzer fuzz-testing/fuzzer
find tests/data -size -5k -name *.msgpack | xargs -I{ } cp "{}" fuzz-testing/testcases
2016-12-25 15:18:56 +00:00
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
2018-01-27 17:38:11 +00:00
fuzz_testing_ubjson :
rm -fr fuzz-testing
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
2022-05-01 07:41:50 +00:00
$( MAKE) parse_ubjson_fuzzer -C tests CXX = afl-clang++
mv tests/parse_ubjson_fuzzer fuzz-testing/fuzzer
find tests/data -size -5k -name *.ubjson | xargs -I{ } cp "{}" fuzz-testing/testcases
2018-01-27 17:38:11 +00:00
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
2016-12-25 15:36:43 +00:00
fuzzing-start :
afl-fuzz -S fuzzer1 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer2 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer3 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer4 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer5 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer6 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer7 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -M fuzzer0 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer
fuzzing-stop :
-killall fuzzer
-killall afl-fuzz
2016-02-12 09:35:08 +00:00
2019-03-28 13:22:48 +00:00
2015-06-21 19:24:03 +00:00
##########################################################################
2019-03-28 13:22:48 +00:00
# Static analysis
2015-06-21 19:24:03 +00:00
##########################################################################
2015-02-13 21:12:27 +00:00
2019-03-28 13:22:48 +00:00
# call PVS-Studio Analyzer <https://www.viva64.com/en/pvs-studio/>
2019-03-16 23:30:08 +00:00
pvs_studio :
2020-07-23 11:02:53 +00:00
rm -fr cmake-build-pvs-studio
mkdir cmake-build-pvs-studio
cd cmake-build-pvs-studio ; cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS= On -DJSON_MultipleHeaders= ON
cd cmake-build-pvs-studio ; pvs-studio-analyzer analyze -j 10
cd cmake-build-pvs-studio ; plog-converter -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs
open cmake-build-pvs-studio/pvs/index.html
2019-03-16 23:30:08 +00:00
2022-01-25 18:53:02 +00:00
2015-06-21 19:24:03 +00:00
##########################################################################
2019-03-28 13:22:48 +00:00
# Code format and source amalgamation
2015-06-21 19:24:03 +00:00
##########################################################################
2019-03-28 13:22:48 +00:00
# call the Artistic Style pretty printer on all source files
2015-02-13 21:12:27 +00:00
pretty :
2019-03-28 13:22:48 +00:00
astyle \
2022-08-07 11:57:32 +00:00
--style= allman \
--indent= spaces = 4 \
--indent-modifiers \
2019-03-28 13:22:48 +00:00
--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 \
--lineend= linux \
--preserve-date \
--suffix= none \
--formatted \
2022-08-07 11:57:32 +00:00
$( SRCS) $( TESTS_SRCS) $( AMALGAMATED_FILE) $( AMALGAMATED_FWD_FILE) docs/examples/*.cpp
2016-01-26 21:59:57 +00:00
2020-07-27 07:15:57 +00:00
# call the Clang-Format on all source files
pretty_format :
2022-07-30 19:59:13 +00:00
for FILE in $( SRCS) $( TESTS_SRCS) $( AMALGAMATED_FILE) docs/examples/*.cpp; do echo $$ FILE; clang-format -i $$ FILE; done
2020-07-27 07:15:57 +00:00
2022-08-07 11:57:32 +00:00
# create single header files and pretty print
amalgamate : $( AMALGAMATED_FILE ) $( AMALGAMATED_FWD_FILE )
$( MAKE) pretty
2018-01-09 22:15:06 +00:00
2022-08-07 11:57:32 +00:00
# call the amalgamation tool for json.hpp
2018-01-29 10:21:11 +00:00
$(AMALGAMATED_FILE) : $( SRCS )
2022-08-07 11:57:32 +00:00
tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json.json -s . --verbose= yes
# call the amalgamation tool for json_fwd.hpp
$(AMALGAMATED_FWD_FILE) : $( SRCS )
tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json_fwd.json -s . --verbose= yes
2018-01-09 22:15:06 +00:00
2019-03-28 13:22:48 +00:00
# check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources
# Note: this target is called by Travis
2018-01-14 12:08:28 +00:00
check-amalgamation :
2018-01-29 10:21:11 +00:00
@mv $( AMALGAMATED_FILE) $( AMALGAMATED_FILE) ~
2022-08-07 11:57:32 +00:00
@mv $( AMALGAMATED_FWD_FILE) $( AMALGAMATED_FWD_FILE) ~
2018-01-14 09:10:23 +00:00
@$( MAKE) amalgamate
2018-01-29 10:21:11 +00:00
@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 )
2022-08-07 11:57:32 +00:00
@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 )
2018-01-29 10:21:11 +00:00
@mv $( AMALGAMATED_FILE) ~ $( AMALGAMATED_FILE)
2022-08-07 11:57:32 +00:00
@mv $( AMALGAMATED_FWD_FILE) ~ $( AMALGAMATED_FWD_FILE)
2018-01-14 09:10:23 +00:00
2022-09-18 06:15:12 +00:00
BUILD.bazel : $( SRCS )
cmake -P cmake/scripts/gen_bazel_build_file.cmake
2019-03-28 13:22:48 +00:00
##########################################################################
# ChangeLog
##########################################################################
# Create a ChangeLog based on the git log using the GitHub Changelog Generator
# (<https://github.com/github-changelog-generator/github-changelog-generator>).
# variable to control the diffs between the last released version and the current repository state
2016-07-31 11:37:04 +00:00
NEXT_VERSION ?= "unreleased"
2016-01-26 21:59:57 +00:00
ChangeLog.md :
2020-05-12 17:36:33 +00:00
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)
2019-03-28 13:22:48 +00:00
$( SED) -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md
$( 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
2018-02-04 12:29:23 +00:00
##########################################################################
2019-03-28 13:22:48 +00:00
# Release files
2018-02-04 12:29:23 +00:00
##########################################################################
2022-01-25 18:53:02 +00:00
# Create a tar.gz archive that contains sufficient files to be used as CMake project (e.g., using FetchContent). The
# archive is created according to the advices of <https://reproducible-builds.org/docs/archives/>.
json.tar.xz :
mkdir json
rsync -R $( shell find LICENSE.MIT nlohmann_json.natvis CMakeLists.txt cmake/*.in include single_include -type f) json
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
rm -fr json
2019-03-28 13:22:48 +00:00
2022-01-25 18:53:02 +00:00
# We use `-X` to make the resulting ZIP file reproducible, see
# <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>.
2022-09-25 10:00:44 +00:00
include.zip : BUILD .bazel
zip -9 --recurse-paths -X include.zip $( SRCS) $( AMALGAMATED_FILE) $( AMALGAMATED_FWD_FILE) BUILD.bazel WORKSPACE.bazel meson.build LICENSE.MIT
2022-01-25 18:53:02 +00:00
# Create the files for a release and add signatures and hashes.
release : include .zip json .tar .xz
2019-03-28 13:22:48 +00:00
rm -fr release_files
2018-02-11 15:50:01 +00:00
mkdir release_files
2018-02-04 12:29:23 +00:00
gpg --armor --detach-sig include.zip
2019-03-28 13:22:48 +00:00
gpg --armor --detach-sig $( AMALGAMATED_FILE)
2022-08-07 18:33:34 +00:00
gpg --armor --detach-sig $( AMALGAMATED_FWD_FILE)
2022-01-25 18:53:02 +00:00
gpg --armor --detach-sig json.tar.xz
2019-03-28 13:22:48 +00:00
cp $( AMALGAMATED_FILE) release_files
2022-08-07 18:33:34 +00:00
cp $( AMALGAMATED_FWD_FILE) release_files
mv $( AMALGAMATED_FILE) .asc $( AMALGAMATED_FWD_FILE) .asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
2022-01-25 18:53:02 +00:00
cd release_files ; shasum -a 256 json.hpp include.zip json.tar.xz > hashes.txt
2019-03-28 13:22:48 +00:00
##########################################################################
# Maintenance
##########################################################################
# clean up
clean :
2022-05-01 07:41:50 +00:00
rm -fr fuzz fuzz-testing *.dSYM tests/*.dSYM
2019-03-28 13:22:48 +00:00
rm -fr benchmarks/files/numbers/*.json
2022-01-25 18:53:02 +00:00
rm -fr cmake-build-benchmarks fuzz-testing cmake-build-pvs-studio release_files
2022-05-01 07:41:50 +00:00
$( MAKE) clean -Cdocs
2019-07-01 20:24:39 +00:00
2022-01-25 18:53:02 +00:00
2019-07-01 20:37:30 +00:00
##########################################################################
# Thirdparty code
##########################################################################
2019-07-01 20:24:39 +00:00
update_hedley :
rm -f include/nlohmann/thirdparty/hedley/hedley.hpp include/nlohmann/thirdparty/hedley/hedley_undef.hpp
curl https://raw.githubusercontent.com/nemequ/hedley/master/hedley.h -o include/nlohmann/thirdparty/hedley/hedley.hpp
2020-07-13 12:44:40 +00:00
$( SED) -i 's/HEDLEY_/JSON_HEDLEY_/g' include/nlohmann/thirdparty/hedley/hedley.hpp
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
2021-03-24 06:15:18 +00:00
$( SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley.hpp
$( SED) -i '1s/^/#pragma once\n\n/' include/nlohmann/thirdparty/hedley/hedley_undef.hpp
2019-07-01 20:24:39 +00:00
$( MAKE) amalgamate
2022-05-01 11:52:52 +00:00
##########################################################################
# serve_header.py
##########################################################################
serve_header :
./tools/serve_header/serve_header.py --make $( MAKE)
2022-07-20 10:38:07 +00:00
##########################################################################
# REUSE
##########################################################################
reuse :
pipx run reuse addheader --recursive single_include include -tjson --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2022"
2022-07-31 13:28:01 +00:00
pipx run reuse addheader $( TESTS_SRCS) --style= c -tjson_support --license MIT --copyright "Niels Lohmann <https://nlohmann.me>" --year "2013-2022"
2022-07-20 10:38:07 +00:00
pipx run reuse lint