Makefile 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. .PHONY: pretty clean ChangeLog.md release
  2. ##########################################################################
  3. # configuration
  4. ##########################################################################
  5. # directory to recent compiler binaries
  6. COMPILER_DIR=/Users/niels/Documents/projects/compilers/local/bin
  7. # find GNU sed to use `-i` parameter
  8. SED:=$(shell command -v gsed || which sed)
  9. ##########################################################################
  10. # source files
  11. ##########################################################################
  12. # the list of sources in the include folder
  13. SRCS=$(shell find include -type f | sort)
  14. # the single header (amalgamated from the source files)
  15. AMALGAMATED_FILE=single_include/nlohmann/json.hpp
  16. ##########################################################################
  17. # documentation of the Makefile's targets
  18. ##########################################################################
  19. # main target
  20. all:
  21. @echo "amalgamate - amalgamate file single_include/nlohmann/json.hpp from the include/nlohmann sources"
  22. @echo "ChangeLog.md - generate ChangeLog file"
  23. @echo "check - compile and execute test suite"
  24. @echo "check-amalgamation - check whether sources have been amalgamated"
  25. @echo "clean - remove built files"
  26. @echo "coverage - create coverage information with lcov"
  27. @echo "cppcheck - analyze code with cppcheck"
  28. @echo "cpplint - analyze code with cpplint"
  29. @echo "clang_tidy - analyze code with Clang-Tidy"
  30. @echo "clang_analyze - analyze code with Clang-Analyzer"
  31. @echo "doctest - compile example files and check their output"
  32. @echo "fuzz_testing - prepare fuzz testing of the JSON parser"
  33. @echo "fuzz_testing_bson - prepare fuzz testing of the BSON parser"
  34. @echo "fuzz_testing_cbor - prepare fuzz testing of the CBOR parser"
  35. @echo "fuzz_testing_msgpack - prepare fuzz testing of the MessagePack parser"
  36. @echo "fuzz_testing_ubjson - prepare fuzz testing of the UBJSON parser"
  37. @echo "json_unit - create single-file test executable"
  38. @echo "pedantic_clang - run Clang with maximal warning flags"
  39. @echo "pedantic_gcc - run GCC with maximal warning flags"
  40. @echo "pretty - beautify code with Artistic Style"
  41. @echo "run_benchmarks - build and run benchmarks"
  42. ##########################################################################
  43. # unit tests
  44. ##########################################################################
  45. # build unit tests
  46. json_unit:
  47. @$(MAKE) json_unit -C test
  48. # run unit tests
  49. check:
  50. $(MAKE) check -C test
  51. ##########################################################################
  52. # coverage
  53. ##########################################################################
  54. coverage:
  55. rm -fr build_coverage
  56. mkdir build_coverage
  57. cd build_coverage ; cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DJSON_Coverage=ON -DJSON_MultipleHeaders=ON
  58. cd build_coverage ; ninja
  59. cd build_coverage ; ctest -j10
  60. cd build_coverage ; ninja lcov_html
  61. open build_coverage/test/html/index.html
  62. ##########################################################################
  63. # documentation tests
  64. ##########################################################################
  65. # compile example files and check output
  66. doctest:
  67. $(MAKE) check_output -C doc
  68. ##########################################################################
  69. # warning detector
  70. ##########################################################################
  71. # calling Clang with all warnings, except:
  72. # -Wno-c++2a-compat: u8 literals will behave differently in C++20...
  73. # -Wno-deprecated-declarations: the library deprecated some functions
  74. # -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
  75. # -Wno-exit-time-destructors: warning in json code triggered by NLOHMANN_JSON_SERIALIZE_ENUM
  76. # -Wno-float-equal: not all comparisons in the tests can be replaced by Approx
  77. # -Wno-keyword-macro: unit-tests use "#define private public"
  78. # -Wno-padded: padding is nothing to warn about
  79. # -Wno-range-loop-analysis: items tests "for(const auto i...)"
  80. # -Wno-switch-enum -Wno-covered-switch-default: pedantic/contradicting warnings about switches
  81. # -Wno-weak-vtables: exception class is defined inline, but has virtual method
  82. pedantic_clang:
  83. $(MAKE) json_unit CXX=c++ CXXFLAGS=" \
  84. -std=c++11 -Wno-c++98-compat -Wno-c++98-compat-pedantic \
  85. -Werror \
  86. -Weverything \
  87. -Wno-c++2a-compat \
  88. -Wno-deprecated-declarations \
  89. -Wno-documentation-unknown-command \
  90. -Wno-exit-time-destructors \
  91. -Wno-float-equal \
  92. -Wno-keyword-macro \
  93. -Wno-padded \
  94. -Wno-range-loop-analysis \
  95. -Wno-switch-enum -Wno-covered-switch-default \
  96. -Wno-weak-vtables"
  97. # calling GCC with most warnings
  98. pedantic_gcc:
  99. $(MAKE) json_unit CXX=/usr/local/bin/g++-9 CXXFLAGS=" \
  100. -std=c++11 \
  101. -Waddress \
  102. -Waddress-of-packed-member \
  103. -Waggressive-loop-optimizations \
  104. -Waligned-new=all \
  105. -Wall \
  106. -Walloc-zero \
  107. -Walloca \
  108. -Warray-bounds \
  109. -Warray-bounds=2 \
  110. -Wattribute-alias=2 \
  111. -Wattribute-warning \
  112. -Wattributes \
  113. -Wbool-compare \
  114. -Wbool-operation \
  115. -Wbuiltin-declaration-mismatch \
  116. -Wbuiltin-macro-redefined \
  117. -Wcannot-profile \
  118. -Wcast-align \
  119. -Wcast-function-type \
  120. -Wcast-qual \
  121. -Wcatch-value=3 \
  122. -Wchar-subscripts \
  123. -Wclass-conversion \
  124. -Wclass-memaccess \
  125. -Wclobbered \
  126. -Wcomment \
  127. -Wcomments \
  128. -Wconditionally-supported \
  129. -Wconversion \
  130. -Wconversion-null \
  131. -Wcoverage-mismatch \
  132. -Wcpp \
  133. -Wctor-dtor-privacy \
  134. -Wdangling-else \
  135. -Wdate-time \
  136. -Wdelete-incomplete \
  137. -Wdelete-non-virtual-dtor \
  138. -Wdeprecated \
  139. -Wdeprecated-copy \
  140. -Wdeprecated-copy-dtor \
  141. -Wdeprecated-declarations \
  142. -Wdisabled-optimization \
  143. -Wdiv-by-zero \
  144. -Wdouble-promotion \
  145. -Wduplicated-branches \
  146. -Wduplicated-cond \
  147. -Weffc++ \
  148. -Wempty-body \
  149. -Wendif-labels \
  150. -Wenum-compare \
  151. -Wexpansion-to-defined \
  152. -Werror \
  153. -Wextra \
  154. -Wextra-semi \
  155. -Wfloat-conversion \
  156. -Wformat \
  157. -Wformat-contains-nul \
  158. -Wformat-extra-args \
  159. -Wformat-nonliteral \
  160. -Wformat-overflow=2 \
  161. -Wformat-security \
  162. -Wformat-signedness \
  163. -Wformat-truncation=2 \
  164. -Wformat-y2k \
  165. -Wformat-zero-length \
  166. -Wformat=2 \
  167. -Wframe-address \
  168. -Wfree-nonheap-object \
  169. -Whsa \
  170. -Wif-not-aligned \
  171. -Wignored-attributes \
  172. -Wignored-qualifiers \
  173. -Wimplicit-fallthrough=5 \
  174. -Winherited-variadic-ctor \
  175. -Winit-list-lifetime \
  176. -Winit-self \
  177. -Winline \
  178. -Wint-in-bool-context \
  179. -Wint-to-pointer-cast \
  180. -Winvalid-memory-model \
  181. -Winvalid-offsetof \
  182. -Winvalid-pch \
  183. -Wliteral-suffix \
  184. -Wlogical-not-parentheses \
  185. -Wlogical-op \
  186. -Wlto-type-mismatch \
  187. -Wmain \
  188. -Wmaybe-uninitialized \
  189. -Wmemset-elt-size \
  190. -Wmemset-transposed-args \
  191. -Wmisleading-indentation \
  192. -Wmissing-attributes \
  193. -Wmissing-braces \
  194. -Wmissing-declarations \
  195. -Wmissing-field-initializers \
  196. -Wmissing-format-attribute \
  197. -Wmissing-include-dirs \
  198. -Wmissing-noreturn \
  199. -Wmissing-profile \
  200. -Wmultichar \
  201. -Wmultiple-inheritance \
  202. -Wmultistatement-macros \
  203. -Wnarrowing \
  204. -Wno-deprecated-declarations \
  205. -Wno-float-equal \
  206. -Wno-long-long \
  207. -Wno-namespaces \
  208. -Wno-padded \
  209. -Wno-switch-enum \
  210. -Wno-system-headers \
  211. -Wno-templates \
  212. -Wno-undef \
  213. -Wnoexcept \
  214. -Wnoexcept-type \
  215. -Wnon-template-friend \
  216. -Wnon-virtual-dtor \
  217. -Wnonnull \
  218. -Wnonnull-compare \
  219. -Wnonportable-cfstrings \
  220. -Wnormalized \
  221. -Wnull-dereference \
  222. -Wodr \
  223. -Wold-style-cast \
  224. -Wopenmp-simd \
  225. -Woverflow \
  226. -Woverlength-strings \
  227. -Woverloaded-virtual \
  228. -Wpacked \
  229. -Wpacked-bitfield-compat \
  230. -Wpacked-not-aligned \
  231. -Wparentheses \
  232. -Wpedantic \
  233. -Wpessimizing-move \
  234. -Wplacement-new=2 \
  235. -Wpmf-conversions \
  236. -Wpointer-arith \
  237. -Wpointer-compare \
  238. -Wpragmas \
  239. -Wprio-ctor-dtor \
  240. -Wpsabi \
  241. -Wredundant-decls \
  242. -Wredundant-move \
  243. -Wregister \
  244. -Wreorder \
  245. -Wrestrict \
  246. -Wreturn-local-addr \
  247. -Wreturn-type \
  248. -Wscalar-storage-order \
  249. -Wsequence-point \
  250. -Wshadow \
  251. -Wshadow-compatible-local \
  252. -Wshadow-local \
  253. -Wshadow=compatible-local \
  254. -Wshadow=global \
  255. -Wshadow=local \
  256. -Wshift-count-negative \
  257. -Wshift-count-overflow \
  258. -Wshift-negative-value \
  259. -Wshift-overflow=2 \
  260. -Wsign-compare \
  261. -Wsign-conversion \
  262. -Wsign-promo \
  263. -Wsized-deallocation \
  264. -Wsizeof-array-argument \
  265. -Wsizeof-pointer-div \
  266. -Wsizeof-pointer-memaccess \
  267. -Wstack-protector \
  268. -Wstrict-aliasing=3 \
  269. -Wstrict-null-sentinel \
  270. -Wstrict-overflow=5 \
  271. -Wstringop-overflow=4 \
  272. -Wstringop-truncation \
  273. -Wsubobject-linkage \
  274. -Wsuggest-attribute=cold \
  275. -Wsuggest-attribute=const \
  276. -Wsuggest-attribute=format \
  277. -Wsuggest-attribute=malloc \
  278. -Wsuggest-attribute=noreturn \
  279. -Wsuggest-attribute=pure \
  280. -Wsuggest-final-methods \
  281. -Wsuggest-final-types \
  282. -Wsuggest-override \
  283. -Wswitch \
  284. -Wswitch-bool \
  285. -Wswitch-default \
  286. -Wswitch-unreachable \
  287. -Wsync-nand \
  288. -Wsynth \
  289. -Wtautological-compare \
  290. -Wterminate \
  291. -Wtrampolines \
  292. -Wtrigraphs \
  293. -Wtype-limits \
  294. -Wuninitialized \
  295. -Wunknown-pragmas \
  296. -Wunreachable-code \
  297. -Wunsafe-loop-optimizations \
  298. -Wunused \
  299. -Wunused-but-set-parameter \
  300. -Wunused-but-set-variable \
  301. -Wunused-const-variable=2 \
  302. -Wunused-function \
  303. -Wunused-label \
  304. -Wunused-local-typedefs \
  305. -Wunused-macros \
  306. -Wunused-parameter \
  307. -Wunused-result \
  308. -Wunused-value \
  309. -Wunused-variable \
  310. -Wuseless-cast \
  311. -Wvarargs \
  312. -Wvariadic-macros \
  313. -Wvector-operation-performance \
  314. -Wvirtual-inheritance \
  315. -Wvirtual-move-assign \
  316. -Wvla \
  317. -Wvolatile-register-var \
  318. -Wwrite-strings \
  319. -Wzero-as-null-pointer-constant \
  320. "
  321. ##########################################################################
  322. # benchmarks
  323. ##########################################################################
  324. run_benchmarks:
  325. rm -fr build_benchmarks
  326. mkdir build_benchmarks
  327. cd build_benchmarks ; cmake ../benchmarks -GNinja -DCMAKE_BUILD_TYPE=Release
  328. cd build_benchmarks ; ninja
  329. cd build_benchmarks ; ./json_benchmarks
  330. ##########################################################################
  331. # fuzzing
  332. ##########################################################################
  333. # the overall fuzz testing target
  334. fuzz_testing:
  335. rm -fr fuzz-testing
  336. mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
  337. $(MAKE) parse_afl_fuzzer -C test CXX=afl-clang++
  338. mv test/parse_afl_fuzzer fuzz-testing/fuzzer
  339. find test/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
  340. @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
  341. fuzz_testing_bson:
  342. rm -fr fuzz-testing
  343. mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
  344. $(MAKE) parse_bson_fuzzer -C test CXX=afl-clang++
  345. mv test/parse_bson_fuzzer fuzz-testing/fuzzer
  346. find test/data -size -5k -name *.bson | xargs -I{} cp "{}" fuzz-testing/testcases
  347. @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
  348. fuzz_testing_cbor:
  349. rm -fr fuzz-testing
  350. mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
  351. $(MAKE) parse_cbor_fuzzer -C test CXX=afl-clang++
  352. mv test/parse_cbor_fuzzer fuzz-testing/fuzzer
  353. find test/data -size -5k -name *.cbor | xargs -I{} cp "{}" fuzz-testing/testcases
  354. @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
  355. fuzz_testing_msgpack:
  356. rm -fr fuzz-testing
  357. mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
  358. $(MAKE) parse_msgpack_fuzzer -C test CXX=afl-clang++
  359. mv test/parse_msgpack_fuzzer fuzz-testing/fuzzer
  360. find test/data -size -5k -name *.msgpack | xargs -I{} cp "{}" fuzz-testing/testcases
  361. @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
  362. fuzz_testing_ubjson:
  363. rm -fr fuzz-testing
  364. mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
  365. $(MAKE) parse_ubjson_fuzzer -C test CXX=afl-clang++
  366. mv test/parse_ubjson_fuzzer fuzz-testing/fuzzer
  367. find test/data -size -5k -name *.ubjson | xargs -I{} cp "{}" fuzz-testing/testcases
  368. @echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
  369. fuzzing-start:
  370. afl-fuzz -S fuzzer1 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
  371. afl-fuzz -S fuzzer2 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
  372. afl-fuzz -S fuzzer3 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
  373. afl-fuzz -S fuzzer4 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
  374. afl-fuzz -S fuzzer5 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
  375. afl-fuzz -S fuzzer6 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
  376. afl-fuzz -S fuzzer7 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
  377. afl-fuzz -M fuzzer0 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer
  378. fuzzing-stop:
  379. -killall fuzzer
  380. -killall afl-fuzz
  381. ##########################################################################
  382. # Static analysis
  383. ##########################################################################
  384. # call cppcheck <http://cppcheck.sourceforge.net>
  385. # Note: this target is called by Travis
  386. cppcheck:
  387. cppcheck --enable=warning --inline-suppr --inconclusive --force --std=c++11 $(AMALGAMATED_FILE) --error-exitcode=1
  388. # call Clang Static Analyzer <https://clang-analyzer.llvm.org>
  389. clang_analyze:
  390. rm -fr clang_analyze_build
  391. mkdir clang_analyze_build
  392. cd clang_analyze_build ; CCC_CXX=$(COMPILER_DIR)/clang++ CXX=$(COMPILER_DIR)/clang++ $(COMPILER_DIR)/scan-build cmake .. -GNinja
  393. cd clang_analyze_build ; \
  394. $(COMPILER_DIR)/scan-build \
  395. -enable-checker alpha.core.BoolAssignment,alpha.core.CallAndMessageUnInitRefArg,alpha.core.CastSize,alpha.core.CastToStruct,alpha.core.Conversion,alpha.core.DynamicTypeChecker,alpha.core.FixedAddr,alpha.core.PointerArithm,alpha.core.PointerSub,alpha.core.SizeofPtr,alpha.core.StackAddressAsyncEscape,alpha.core.TestAfterDivZero,alpha.deadcode.UnreachableCode,core.builtin.BuiltinFunctions,core.builtin.NoReturnFunctions,core.CallAndMessage,core.DivideZero,core.DynamicTypePropagation,core.NonnilStringConstants,core.NonNullParamChecker,core.NullDereference,core.StackAddressEscape,core.UndefinedBinaryOperatorResult,core.uninitialized.ArraySubscript,core.uninitialized.Assign,core.uninitialized.Branch,core.uninitialized.CapturedBlockVariable,core.uninitialized.UndefReturn,core.VLASize,cplusplus.InnerPointer,cplusplus.Move,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,cplusplus.SelfAssignment,deadcode.DeadStores,nullability.NullableDereferenced,nullability.NullablePassedToNonnull,nullability.NullableReturnedFromNonnull,nullability.NullPassedToNonnull,nullability.NullReturnedFromNonnull \
  396. --use-c++=$(COMPILER_DIR)/clang++ -analyze-headers -o report ninja
  397. open clang_analyze_build/report/*/index.html
  398. # call cpplint <https://github.com/cpplint/cpplint>
  399. # Note: some errors expected due to false positives
  400. cpplint:
  401. third_party/cpplint/cpplint.py \
  402. --filter=-whitespace,-legal,-readability/alt_tokens,-runtime/references,-runtime/explicit \
  403. --quiet --recursive $(SRCS)
  404. # call Clang-Tidy <https://clang.llvm.org/extra/clang-tidy/>
  405. clang_tidy:
  406. $(COMPILER_DIR)/clang-tidy $(AMALGAMATED_FILE) -- -Iinclude -std=c++11
  407. # call PVS-Studio Analyzer <https://www.viva64.com/en/pvs-studio/>
  408. pvs_studio:
  409. rm -fr pvs_studio_build
  410. mkdir pvs_studio_build
  411. cd pvs_studio_build ; cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=On
  412. cd pvs_studio_build ; pvs-studio-analyzer analyze -j 10
  413. cd pvs_studio_build ; plog-converter -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs
  414. open pvs_studio_build/pvs/index.html
  415. # call Infer <https://fbinfer.com> static analyzer
  416. infer:
  417. rm -fr infer_build
  418. mkdir infer_build
  419. cd infer_build ; infer compile -- cmake .. ; infer run -- make -j 4
  420. # call OCLint <http://oclint.org> static analyzer
  421. oclint:
  422. oclint $(SRCS) -report-type html -enable-global-analysis -o oclint_report.html -max-priority-1=10000 -max-priority-2=10000 -max-priority-3=10000 -- -std=c++11 -Iinclude
  423. open oclint_report.html
  424. # execute the test suite with Clang sanitizers (address and undefined behavior)
  425. clang_sanitize:
  426. rm -fr clang_sanitize_build
  427. mkdir clang_sanitize_build
  428. cd clang_sanitize_build ; CXX=$(COMPILER_DIR)/clang++ cmake .. -DJSON_Sanitizer=On -DJSON_MultipleHeaders=ON -GNinja
  429. cd clang_sanitize_build ; ninja
  430. cd clang_sanitize_build ; ctest -j10
  431. ##########################################################################
  432. # Code format and source amalgamation
  433. ##########################################################################
  434. # call the Artistic Style pretty printer on all source files
  435. pretty:
  436. astyle \
  437. --style=allman \
  438. --indent=spaces=4 \
  439. --indent-modifiers \
  440. --indent-switches \
  441. --indent-preproc-block \
  442. --indent-preproc-define \
  443. --indent-col1-comments \
  444. --pad-oper \
  445. --pad-header \
  446. --align-pointer=type \
  447. --align-reference=type \
  448. --add-brackets \
  449. --convert-tabs \
  450. --close-templates \
  451. --lineend=linux \
  452. --preserve-date \
  453. --suffix=none \
  454. --formatted \
  455. $(SRCS) $(AMALGAMATED_FILE) test/src/*.cpp benchmarks/src/benchmarks.cpp doc/examples/*.cpp
  456. # create single header file
  457. amalgamate: $(AMALGAMATED_FILE)
  458. # call the amalgamation tool and pretty print
  459. $(AMALGAMATED_FILE): $(SRCS)
  460. third_party/amalgamate/amalgamate.py -c third_party/amalgamate/config.json -s . --verbose=yes
  461. $(MAKE) pretty
  462. # check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources
  463. # Note: this target is called by Travis
  464. check-amalgamation:
  465. @mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~
  466. @$(MAKE) amalgamate
  467. @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)
  468. @mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE)
  469. # check if every header in nlohmann includes sufficient headers to be compiled individually
  470. check-single-includes:
  471. @for x in $(SRCS); do \
  472. echo "Checking self-sufficiency of $$x..." ; \
  473. echo "#include <$$x>\nint main() {}\n" | sed 's|include/||' > single_include_test.cpp; \
  474. $(CXX) $(CXXFLAGS) -Iinclude -std=c++11 single_include_test.cpp -o single_include_test; \
  475. rm -f single_include_test.cpp single_include_test; \
  476. done
  477. ##########################################################################
  478. # CMake
  479. ##########################################################################
  480. # grep "^option" CMakeLists.txt test/CMakeLists.txt | sed 's/(/ /' | awk '{print $2}' | xargs
  481. # check if all flags of our CMake files work
  482. check_cmake_flags_do:
  483. $(CMAKE_BINARY) --version
  484. for flag in '' JSON_BuildTests JSON_Install JSON_MultipleHeaders JSON_Sanitizer JSON_Valgrind JSON_NoExceptions JSON_Coverage; do \
  485. rm -fr cmake_build; \
  486. mkdir cmake_build; \
  487. echo "$(CMAKE_BINARY) .. -D$$flag=On" ; \
  488. cd cmake_build ; \
  489. CXX=g++-8 $(CMAKE_BINARY) .. -D$$flag=On -DCMAKE_CXX_COMPILE_FEATURES="cxx_std_11;cxx_range_for" -DCMAKE_CXX_FLAGS="-std=gnu++11" ; \
  490. test -f Makefile || exit 1 ; \
  491. cd .. ; \
  492. done;
  493. # call target `check_cmake_flags_do` twice: once for minimal required CMake version 3.1.0 and once for the installed version
  494. check_cmake_flags:
  495. wget https://github.com/Kitware/CMake/releases/download/v3.1.0/cmake-3.1.0-Darwin64.tar.gz
  496. tar xfz cmake-3.1.0-Darwin64.tar.gz
  497. CMAKE_BINARY=$(abspath cmake-3.1.0-Darwin64/CMake.app/Contents/bin/cmake) $(MAKE) check_cmake_flags_do
  498. CMAKE_BINARY=$(shell which cmake) $(MAKE) check_cmake_flags_do
  499. ##########################################################################
  500. # ChangeLog
  501. ##########################################################################
  502. # Create a ChangeLog based on the git log using the GitHub Changelog Generator
  503. # (<https://github.com/github-changelog-generator/github-changelog-generator>).
  504. # variable to control the diffs between the last released version and the current repository state
  505. NEXT_VERSION ?= "unreleased"
  506. ChangeLog.md:
  507. github_changelog_generator -o ChangeLog.md --simple-list --release-url https://github.com/nlohmann/json/releases/tag/%s --future-release $(NEXT_VERSION)
  508. $(SED) -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md
  509. $(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
  510. ##########################################################################
  511. # Release files
  512. ##########################################################################
  513. # Create the files for a release and add signatures and hashes. We use `-X` to make the resulting ZIP file
  514. # reproducible, see <https://content.pivotal.io/blog/barriers-to-deterministic-reproducible-zip-files>.
  515. release:
  516. rm -fr release_files
  517. mkdir release_files
  518. zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) meson.build
  519. gpg --armor --detach-sig include.zip
  520. mv include.zip include.zip.asc release_files
  521. gpg --armor --detach-sig $(AMALGAMATED_FILE)
  522. cp $(AMALGAMATED_FILE) release_files
  523. mv $(AMALGAMATED_FILE).asc release_files
  524. cd release_files ; shasum -a 256 json.hpp > hashes.txt
  525. cd release_files ; shasum -a 256 include.zip >> hashes.txt
  526. ##########################################################################
  527. # Maintenance
  528. ##########################################################################
  529. # clean up
  530. clean:
  531. rm -fr json_unit json_benchmarks fuzz fuzz-testing *.dSYM test/*.dSYM oclint_report.html
  532. rm -fr benchmarks/files/numbers/*.json
  533. rm -fr cmake-3.1.0-Darwin64.tar.gz cmake-3.1.0-Darwin64
  534. rm -fr build_coverage build_benchmarks fuzz-testing clang_analyze_build pvs_studio_build infer_build clang_sanitize_build cmake_build
  535. $(MAKE) clean -Cdoc
  536. $(MAKE) clean -Ctest
  537. ##########################################################################
  538. # Thirdparty code
  539. ##########################################################################
  540. update_hedley:
  541. rm -f include/nlohmann/thirdparty/hedley/hedley.hpp include/nlohmann/thirdparty/hedley/hedley_undef.hpp
  542. curl https://raw.githubusercontent.com/nemequ/hedley/master/hedley.h -o include/nlohmann/thirdparty/hedley/hedley.hpp
  543. gsed -i 's/HEDLEY_/JSON_HEDLEY_/g' include/nlohmann/thirdparty/hedley/hedley.hpp
  544. grep "[[:blank:]]*#[[:blank:]]*undef" include/nlohmann/thirdparty/hedley/hedley.hpp | grep -v "__" | sort | uniq | gsed 's/ //g' | gsed 's/undef/undef /g' > include/nlohmann/thirdparty/hedley/hedley_undef.hpp
  545. $(MAKE) amalgamate