Makefile
1.8 KB61 lines Opens in site
Directory
Raw
Download
# Makefile — rgui / ttgui (zero-dependency C++20)
CXX ?= g++
CXXFLAGS ?= -std=c++20 -Wall -Wextra -Wpedantic -O2
ASANFLAGS ?= -std=c++20 -g -fsanitize=address,undefined -Wall -Wextra -Wpedantic
TEST_SRCS := $(sort $(wildcard tests/test_*.cpp))
# Batched compilation: every test file compiles to its own object file.
# This works exactly like the old single-shot build (same compiler, same
# flags, same ./run_tests and ./run_tests_asan binaries) but:
# - changing one test (or one header) recompiles only what depends on it,
# - `make -j2 tests` compiles files in parallel batches (keep -j low:
# ttgui.hpp is large and each TU needs substantial RAM),
# - a compile error names the single failing file instead of a 24-file
# command line.
# Objects live under build/ so `make clean` restores a pristine tree.
OBJDIR := build/obj
ASAN_OBJDIR := build/obj_asan
TEST_OBJS := $(patsubst tests/%.cpp,$(OBJDIR)/%.o,$(TEST_SRCS))
ASAN_OBJS := $(patsubst tests/%.cpp,$(ASAN_OBJDIR)/%.o,$(TEST_SRCS))
.PHONY: all demo tests asan run check selftest dump-config golden clean
all: demo tests
demo: demo.cpp ttgui.hpp
$(CXX) $(CXXFLAGS) demo.cpp -o demo
tests: run_tests
run_tests: $(TEST_OBJS)
$(CXX) $(TEST_OBJS) -o run_tests
asan: run_tests_asan
run_tests_asan: $(ASAN_OBJS)
$(CXX) -fsanitize=address,undefined $(ASAN_OBJS) -o run_tests_asan
$(OBJDIR)/%.o: tests/%.cpp ttgui.hpp tttest.hpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(ASAN_OBJDIR)/%.o: tests/%.cpp ttgui.hpp tttest.hpp
@mkdir -p $(dir $@)
$(CXX) $(ASANFLAGS) -c $< -o $@
run: run_tests
./run_tests
check: demo run_tests
./run_tests
./demo --dump-config > /dev/null
./demo --help > /dev/null
selftest: demo run_tests
./demo --selftest
dump-config: demo
./demo --dump-config
golden: run_tests
./run_tests --tags [golden]
clean:
rm -rf build demo run_tests run_tests_asan