-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
64 lines (53 loc) · 1.59 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Settings
VARIANT ?= release
ifeq ($(VARIANT),release)
ADDITIONAL_FLAGS = -O2 -DNDEBUG
else ifeq ($(VARIANT),debug)
ADDITIONAL_FLAGS = -ggdb3
else
ADDITIONAL_FLAGS = $(error Unknown variant, set VARIANT={debug|release})
endif
CXXFLAGS = -Wall -Wextra -std=c++11 $(ADDITIONAL_FLAGS)
LFLAGS = -Wall $(DEBUG)
# Files
BUILDDIR = $(VARIANT)
TARGET = $(BUILDDIR)/puzzle
TEST_TARGET = $(BUILDDIR)/test
CPPS = src/puzzle.cpp
MAIN = src/main.cpp
TEST = src/test.cpp
HEADERS = puzzle.hpp fraction.hpp
HPPS = $(patsubst %,src/%,$(HEADERS))
MAIN_OBJS = $(patsubst src/%.cpp,$(BUILDDIR)/%.o,$(CPPS) $(MAIN))
TEST_OBJS = $(patsubst src/%.cpp,$(BUILDDIR)/%.o,$(CPPS) $(TEST))
# Main target
$(TARGET): $(MAIN_OBJS)
$(CXX) $(LFLAGS) -o $@ $(MAIN_OBJS)
# Google Test shenanigans. Some distributions don't provide libgtest.so.
# So we have to compile it for ourselves first. Well that is fun.
ifdef GTEST_PREFIX
GTEST_DIR = $(GTEST_PREFIX)/src/gtest
GTEST_OBJ = $(BUILDDIR)/gtest-all.o $(BUILDDIR)/gtest_main.o
GTEST = $(GTEST_OBJ)
ifneq ($(GTEST_PREFIX),/usr)
CXXFLAGS += -I$(GTEST_PREFIX)/include
endif
$(GTEST_OBJ): $(BUILDDIR)/%.o: $(GTEST_DIR)/src/%.cc | $(BUILDDIR)/
$(CXX) -c $(CXXFLAGS) -I$(GTEST_DIR) -o $@ $^
else
GTEST = -lgtest -lgtest_main
endif
# Test binary
$(TEST_TARGET): $(TEST_OBJS) $(GTEST_OBJ) | $(BUILDDIR)/
$(CXX) $(LFLAGS) $(GTEST) -lpthread -o $@ $(TEST_OBJS)
# Object files
$(BUILDDIR)/%.o: src/%.cpp $(HPPS) | $(BUILDDIR)/
$(CXX) -c $(CXXFLAGS) -o $@ $<
$(BUILDDIR)/:
mkdir $(BUILDDIR)
# Tests
test: $(TEST_TARGET)
./$(TEST_TARGET)
clean:
-rm $(BUILDDIR)/*.o $(TARGET) $(TEST_TARGET)
.PHONY: test clean