diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..7b7298a78 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +--- +BasedOnStyle: LLVM +SortIncludes: + Enabled: true + IgnoreCase: false diff --git a/Makefile b/Makefile index 29f047184..b506d8bed 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ VERSION?=$(SPECVERSION) RELEASE?=cmark-$(VERSION) INSTALL_PREFIX?=/usr/local CLANG_CHECK?=clang-check -CLANG_FORMAT=clang-format -style llvm -sort-includes=0 -i +CLANG_FORMAT=clang-format -i AFL_PATH?=/usr/local/bin .PHONY: all cmake_build leakcheck clean fuzztest test debug ubsan asan mingw archive newbench bench format update-spec afl libFuzzer lint @@ -141,15 +141,7 @@ $(SRCDIR)/case_fold.inc: $(DATADIR)/CaseFolding.txt # We include scanners.c in the repository, so this shouldn't # normally need to be generated. $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re - @case "$$(re2c -v)" in \ - *\ 0.13.*|*\ 0.14|*\ 0.14.1) \ - echo "re2c >= 0.14.2 is required"; \ - false; \ - ;; \ - esac - re2c -W -Werror -b -i --no-generation-date \ - -o $@ $< - $(CLANG_FORMAT) $@ + ./tools/make_scanners $< $@ # We include entities.inc in the repository, so normally this # doesn't need to be regenerated: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 523b2cb82..4ccb445b9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,12 +5,49 @@ configure_file(libcmark.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY) +find_program(PYTHON3_EXECUTABLE python3 OPTIONAL) + +if(PYTHON3_EXECUTABLE) + add_custom_command( + OUTPUT case_fold.inc + COMMAND ${PYTHON3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/../tools/make_case_fold_inc.py + < ${CMAKE_CURRENT_SOURCE_DIR}/../data/CaseFolding.txt + > case_fold.inc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../data/CaseFolding.txt + VERBATIM) + add_custom_command( + OUTPUT entities.inc + COMMAND ${PYTHON3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/../tools/make_entities_inc.py + > entities.inc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../tools/make_entities_inc.py + VERBATIM) +endif() + +find_program(RE2C_EXECUTABLE re2c OPTIONAL) +find_program(CLANG_FORMAT_EXECUTABLE clang-format OPTIONAL) + +if(RE2C_EXECUTABLE AND CLANG_FORMAT_EXECUTABLE) + add_custom_command( + OUTPUT scanners.c + COMMAND RE2C_EXECUTABLE=${RE2C_EXECUTABLE} + CLANG_FORMAT_EXECUTABLE=${CLANG_FORMAT_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/../tools/make_scanners + ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re + scanners.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re + VERBATIM) +endif() + add_library(cmark blocks.c buffer.c + case_fold.inc cmark.c cmark_ctype.c commonmark.c + entities.inc houdini_href_e.c houdini_html_e.c houdini_html_u.c diff --git a/tools/make_scanners b/tools/make_scanners new file mode 100755 index 000000000..b982d92a0 --- /dev/null +++ b/tools/make_scanners @@ -0,0 +1,24 @@ +#!/bin/sh + +# Creates C scanner code using re2c. +# Usage: ./tools/make_scanners src/scanners.re src/scanners.c +# Environment variable: RE2C_EXECUTABLE, CLANG_FORMAT_EXECUTABLE + +set -eu + +in=${1?no input file} +out=${2?no output file} + +: "${RE2C_EXECUTABLE:=re2c}" +: "${CLANG_FORMAT_EXECUTABLE:=clang-format}" + +case "$("$RE2C_EXECUTABLE" -v)" in + *\ 0.13.*|*\ 0.14|*\ 0.14.1) + echo "re2c >= 0.14.2 is required" + false + ;; +esac + +"$RE2C_EXECUTABLE" -W -Werror -b -i --no-generation-date \ + -o "$out" "$in" +"$CLANG_FORMAT_EXECUTABLE" -i "$out"