diff --git a/.editorconfig b/.editorconfig index 12032e647..9223a323e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,3 +16,6 @@ indent_size = 2 trim_trailing_whitespace = true indent_style = tab indent_size = 8 + +[Makefile.nmake] +end_of_line = crlf diff --git a/.gitattributes b/.gitattributes index 6313b56c5..92008d5b2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ * text=auto eol=lf +Makefile.nmake eol=crlf diff --git a/Makefile b/Makefile index 0de726ba9..609bbfa56 100644 --- a/Makefile +++ b/Makefile @@ -30,57 +30,56 @@ all: cmake_build man/man3/cmark.3 $(CMARK): cmake_build cmake_build: $(BUILDDIR) - @$(MAKE) -j2 -C $(BUILDDIR) + cmake --build $(BUILDDIR) @echo "Binaries can be found in $(BUILDDIR)/src" $(BUILDDIR): @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1) - mkdir -p $(BUILDDIR); \ - cd $(BUILDDIR); \ - cmake .. \ - -G "$(GENERATOR)" \ - -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ - -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX) \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DBUILD_SHARED_LIBS=YES + cmake \ + -S . -B $(BUILDDIR) -G "$(GENERATOR)" \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX) \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DBUILD_SHARED_LIBS=YES install: $(BUILDDIR) - $(MAKE) -C $(BUILDDIR) install + cmake --install $(BUILDDIR) uninstall: $(BUILDDIR)/install_manifest.txt xargs rm < $< debug: - mkdir -p $(BUILDDIR); \ - cd $(BUILDDIR); \ - cmake .. \ - -DCMAKE_BUILD_TYPE=Debug \ - -DBUILD_SHARED_LIBS=YES; \ - $(MAKE) + cmake \ + -S . -B $(BUILDDIR) -G "$(GENERATOR)" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DBUILD_SHARED_LIBS=YES + cmake --build $(BUILDDIR) ubsan: - mkdir -p $(BUILDDIR); \ - cd $(BUILDDIR); \ - cmake .. -DCMAKE_BUILD_TYPE=Ubsan; \ - $(MAKE) + cmake \ + -S . -B $(BUILDDIR) -G "$(GENERATOR)" \ + -DCMAKE_BUILD_TYPE=Ubsan + cmake --build $(BUILDDIR) asan: - mkdir -p $(BUILDDIR); \ - cd $(BUILDDIR); \ - cmake .. -DCMAKE_BUILD_TYPE=Asan; \ - $(MAKE) + cmake \ + -S . -B $(BUILDDIR) -G "$(GENERATOR)" \ + -DCMAKE_BUILD_TYPE=Asan + cmake --build $(BUILDDIR) prof: - mkdir -p $(BUILDDIR); \ - cd $(BUILDDIR); \ - cmake .. -DCMAKE_BUILD_TYPE=Profile; \ - $(MAKE) + cmake \ + -S . -B $(BUILDDIR) -G "$(GENERATOR)" \ + -DCMAKE_BUILD_TYPE=Profile + cmake --build $(BUILDDIR) afl: @[ -n "$(AFL_PATH)" ] || { echo '$$AFL_PATH not set'; false; } - mkdir -p $(BUILDDIR) - cd $(BUILDDIR) && cmake .. -DBUILD_TESTING=NO -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang - $(MAKE) + cmake \ + -S . -B $(BUILDDIR) -G "$(GENERATOR)" \ + -DBUILD_TESTING=NO \ + -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang + cmake --build $(BUILDDIR) $(AFL_PATH)/afl-fuzz \ -i fuzz/afl_test_cases \ -o fuzz/afl_results \ @@ -90,7 +89,7 @@ afl: libFuzzer: cmake \ - -S . -B $(BUILDDIR) \ + -S . -B $(BUILDDIR) -G "$(GENERATOR)" \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_BUILD_TYPE=Asan \ @@ -110,10 +109,12 @@ lint: $(BUILDDIR) exit $$errs mingw: - mkdir -p $(MINGW_BUILDDIR); \ - cd $(MINGW_BUILDDIR); \ - cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\ - $(MAKE) && $(MAKE) install + cmake \ + -S . -B $(MINGW_BUILDDIR) -G "$(GENERATOR)" \ + -DCMAKE_TOOLCHAIN_FILE=toolchain-mingw32.cmake \ + -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) + cmake --build $(MINGW_BUILDDIR) + cmake --install $(MINGW_BUILDDIR) man/man3/cmark.3: src/cmark.h | $(CMARK) python3 man/make_man_page.py $< > $@ \ @@ -152,11 +153,11 @@ update-spec: curl 'https://raw.githubusercontent.com/jgm/CommonMark/master/spec.txt'\ > $(SPEC) -test: $(SPEC) cmake_build +test: cmake_build ctest --test-dir $(BUILDDIR) --output-on-failure || (cat $(BUILDDIR)/Testing/Temporary/LastTest.log && exit 1) -$(ALLTESTS): $(SPEC) - python3 test/spec_tests.py --spec $< --dump-tests | python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print("\n".join([test["markdown"] for test in tests]))' > $@ +$(ALLTESTS): + python3 test/spec_tests.py --spec $(SPEC) --dump-tests | python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print("\n".join([test["markdown"] for test in tests]))' > $@ leakcheck: $(ALLTESTS) for format in html man xml latex commonmark; do \ diff --git a/Makefile.nmake b/Makefile.nmake index 42e6b3189..47d166563 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -1,33 +1,28 @@ -SRCDIR=src -DATADIR=data -BUILDDIR=build -INSTALLDIR=windows -SPEC=test/spec.txt -PROG=$(BUILDDIR)\src\cmark.exe -GENERATOR=NMake Makefiles - -all: $(BUILDDIR)/CMakeFiles - @cd $(BUILDDIR) && $(MAKE) /nologo && cd .. - -$(BUILDDIR)/CMakeFiles: - @-mkdir $(BUILDDIR) 2> nul - cd $(BUILDDIR) && \ - cmake \ - -G "$(GENERATOR)" \ - -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ - -D CMAKE_INSTALL_PREFIX=$(INSTALLDIR) \ - .. && \ - cd .. - -install: all - @cd $(BUILDDIR) && $(MAKE) /nologo install && cd .. - -clean: - -rmdir /s /q $(BUILDDIR) $(MINGW_INSTALLDIR) 2> nul - -test: $(SPEC) all - @cd $(BUILDDIR) && $(MAKE) /nologo test ARGS="-V" && cd .. - -distclean: clean - del /q src\scanners.c 2> nul - del /q spec.md spec.html 2> nul +SRCDIR=src +DATADIR=data +BUILDDIR=build +INSTALLDIR=windows +PROG=$(BUILDDIR)\src\cmark.exe +GENERATOR=NMake Makefiles + +all: $(BUILDDIR)/CMakeFiles + cmake --build $(BUILDDIR) + +$(BUILDDIR)/CMakeFiles: + cmake \ + -S . -B $(BUILDDIR) -G "$(GENERATOR)" \ + -D CMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -D CMAKE_INSTALL_PREFIX=$(INSTALLDIR) + +install: all + cmake --install $(BUILDDIR) + +clean: + -rmdir /s /q $(BUILDDIR) $(MINGW_INSTALLDIR) 2> nul + +test: all + ctest --test-dir $(BUILDDIR) --output-on-failure + +distclean: clean + del /q src\scanners.c 2> nul + del /q spec.md spec.html 2> nul diff --git a/README.md b/README.md index 5318bcf02..5a6874abc 100644 --- a/README.md +++ b/README.md @@ -84,19 +84,15 @@ For a more portable method, you can use [cmake] manually. [cmake] knows how to create build environments for many build systems. For example, on FreeBSD: - mkdir build - cd build - cmake .. # optionally: -DCMAKE_INSTALL_PREFIX=path - make # executable will be created as build/src/cmark - make test - make install + cmake -S . -B build # optionally: -DCMAKE_INSTALL_PREFIX=path + cmake --build build # executable will be created as build/src/cmark + ctest --test-dir build + cmake --install build Or, to create Xcode project files on OSX: - mkdir build - cd build - cmake -G Xcode .. - open cmark.xcodeproj + cmake -S . -B build -G Xcode + open build/cmark.xcodeproj The GNU Makefile also provides a few other targets for developers. To run a benchmark: