Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: Clean up cmake invocations #568

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
79 changes: 40 additions & 39 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 Expand Up @@ -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 \
Expand Down
61 changes: 28 additions & 33 deletions Makefile.nmake
Original file line number Diff line number Diff line change
@@ -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
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading