-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
41 lines (30 loc) · 865 Bytes
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
CXX := g++
CXXFLAGS := -std=c++2a
RELEASE_FLAGS = -O3
SRCDIR = src
TESTDIR = test
BUILDDIR = build
EXEC = $(BUILDDIR)/program
SOURCES = $(wildcard $(SRCDIR)/*.cpp)
OBJECTS = $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SOURCES))
TESTS = $(wildcard $(TESTDIR)/*.cpp)
TESTSOURCES = $(filter-out $(SRCDIR)/main%, $(wildcard $(SRCDIR)/*))
INCLUDES = -Iinclude
INCLUDESTEST = -lgtest -lpthread
.PHONY: all release clean run test
all: $(EXEC)
ifeq ($(wildcard $(BUILDDIR)),)
$(shell mkdir -p $(BUILDDIR))
endif
test: $(TESTS) $(TESTSOURCES)
$(CXX) -o $(BUILDDIR)/test $(TESTS) $(TESTSOURCES) $(INCLUDESTEST) $(INCLUDES)
$(EXEC): $(OBJECTS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ $^
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $<
run: $(EXEC)
./$(EXEC)
release: CXXFLAGS += $(RELEASE_FLAGS)
release: all
clean:
rm -rf $(BUILDDIR)