GTEST_DIR = ../deps/gtest/googletest
TARGET_DIR = $(GTEST_DIR)/build

MKDIR_P := mkdir -p

# Flags passed to the preprocessor.
# Set Google Test's header directory as a system directory, such that
# the compiler doesn't generate warnings in Google Test headers.
CPPFLAGS += -isystem $(GTEST_DIR)/include -std=c++11

# Flags passed to the C++ compiler.
CXXFLAGS += -g -pthread

# All Google Test headers.  Usually you shouldn't change this
# definition.
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
                $(GTEST_DIR)/include/gtest/internal/*.h

# House-keeping build targets.
all : $(TARGET_DIR)/libgtest_main.a $(TARGET_DIR)/libgtest.a
clean :
	rm -f $(TARGET_DIR)/libgtest.a $(TARGET_DIR)/libgtest_main.a $(TARGET_DIR)/*.o
# Builds libgtest.a and libgtest_main.a.

# Usually you shouldn't tweak such internal variables, indicated by a
# trailing _.
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)

# For simplicity and to avoid depending on Google Test's
# implementation details, the dependencies specified below are
# conservative and not optimized.  This is fine as Google Test
# compiles fast and for ordinary users its source rarely changes.
$(TARGET_DIR)/gtest-all.o : $(GTEST_SRCS_)
	$(MKDIR_P) $(@D)
	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
            $(GTEST_DIR)/src/gtest-all.cc -o $@

$(TARGET_DIR)/gtest_main.o : $(GTEST_SRCS_)
	$(MKDIR_P) $(@D)
	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
            $(GTEST_DIR)/src/gtest_main.cc -o $@

$(TARGET_DIR)/libgtest.a : $(TARGET_DIR)/gtest-all.o
	$(AR) $(ARFLAGS) $@ $^

$(TARGET_DIR)/libgtest_main.a : $(TARGET_DIR)/gtest-all.o $(TARGET_DIR)/gtest_main.o
	$(AR) $(ARFLAGS) $@ $^
