Makefile 31 KB

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