Skip to content

Instantly share code, notes, and snippets.

@honi
Created September 30, 2023 13:59
Show Gist options
  • Save honi/18761505bd12e3e16ea67b9c22a317b5 to your computer and use it in GitHub Desktop.
Save honi/18761505bd12e3e16ea67b9c22a317b5 to your computer and use it in GitHub Desktop.
Makefile to compile cpp files in src/ as individual programs in bin/
CXX := g++
CXX_FLAGS := -pthread --std=c++2a
VPATH := bin/
SRCS := $(shell find src -name '*.cpp')
BINS := $(patsubst src/%.cpp,%,$(SRCS))
RUNS := $(addprefix run-,$(BINS))
all: $(BINS)
$(BINS): %: src/%.cpp
@mkdir -p bin
$(CXX) $(CXX_FLAGS) $< -o bin/$@
$(RUNS): run-%: %
./bin/$*
clean:
rm -rf bin
.PHONY: all clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment