From 9e99cba44d49fa29f99fc2e5184193babb3becec Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Tue, 17 Dec 2024 19:50:51 +0100 Subject: [PATCH] Makefile: Clean up cmake invocations Use cmake command to build and install instead of invoking make. Also use -G option consistently. This allows to use other generators like Ninja: make GENERATOR=Ninja Use cmake -B option instead of switching directories. --- .editorconfig | 3 +++ .gitattributes | 1 + Makefile | 73 +++++++++++++++++++++++++------------------------- Makefile.nmake | 62 ++++++++++++++++++++---------------------- 4 files changed, 70 insertions(+), 69 deletions(-) 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..f7b2a3ca0 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 $< > $@ \ diff --git a/Makefile.nmake b/Makefile.nmake index 42e6b3189..fdf400e30 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -1,33 +1,29 @@ -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 +SPEC=test/spec.txt +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: $(SPEC) 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