# Builds every .cpp in this tree into a binary next to its source. # Incremental: a file is recompiled only when its .cpp is newer than its binary. # Flags come from the compile_flags.txt nearest the source (the file clangd # reads), falling back to the one at the repo root. CXX := clang++ ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) SRCS := $(shell find $(ROOT) -name '*.cpp') BINS := $(basename $(SRCS)) # The `@:` recipe is a deliberate no-op. Without it, make prints # "Nothing to be done for 'all'" whenever everything is already up to date. all: $(BINS) @: %: %.cpp @flags=$$(cat $(dir $<)compile_flags.txt 2>/dev/null || cat $(ROOT)compile_flags.txt 2>/dev/null); \ echo "compiling $(notdir $<)"; \ $(CXX) $$flags $< -o $@ clean: @rm -f $(BINS) @echo "cleaned" .PHONY: all clean