I am now studying C++. I want a makefile which will compile all of the cpp files in the current directory to separate executables. For example:
My answer builds on top of the answer by @Haatschii
I don't prefer to have the .out
prefix to my binaries. Also I used his existing Make syntax to perform clean as well.
CXX=clang++
CXXFLAGS=-Wall -Werror -std=c++11
all: $(patsubst %.cpp, %.out, $(wildcard *.cpp))
%.out: %.cpp Makefile
$(CXX) $(CXXFLAGS) $< -o $(@:.out=)
clean: $(patsubst %.cpp, %.clean, $(wildcard *.cpp))
%.clean:
rm -f $(@:.clean=)