Skip to content

Commit

Permalink
Makefile: Clean up cmake invocations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nwellnhof authored and jgm committed Dec 17, 2024
1 parent ce6e762 commit 9e99cba
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ indent_size = 2
trim_trailing_whitespace = true
indent_style = tab
indent_size = 8

[Makefile.nmake]
end_of_line = crlf
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto eol=lf
Makefile.nmake eol=crlf
73 changes: 37 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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 $< > $@ \
Expand Down
62 changes: 29 additions & 33 deletions Makefile.nmake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9e99cba

Please sign in to comment.