-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (39 loc) · 1.92 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
NAME = prsim
DEPEND = interpret_prs interpret_boolean interpret_ucs prs boolean ucs parse_spice parse_dot parse_prs parse_expression parse_ucs parse common
SRCDIR = src
TESTDIR = tests
GTEST := ../../googletest
GTEST_I := -I$(GTEST)/googletest/include -I.
GTEST_L := -L$(GTEST)/build/lib -L.
INCLUDE_PATHS = $(DEPEND:%=-I../../lib/%) -I.
LIBRARY_PATHS = $(DEPEND:%=-L../../lib/%) -I.
LIBRARIES = $(DEPEND:%=-l%)
CXXFLAGS = -std=c++14 -O2 -g -Wall -fmessage-length=0
LDFLAGS =
SOURCES := $(shell mkdir -p $(SRCDIR); find $(SRCDIR) -name '*.cpp')
OBJECTS := $(SOURCES:%.cpp=build/%.o)
DEPS := $(shell mkdir -p build/$(SRCDIR); find build/$(SRCDIR) -name '*.d')
TARGET = $(NAME)
TESTS := $(shell mkdir -p tests; find $(TESTDIR) -name '*.cpp')
TEST_OBJECTS := $(TESTS:%.cpp=build/%.o) build/$(TESTDIR)/gtest_main.o
TEST_DEPS := $(shell mkdir -p build/$(TESTDIR); find build/$(TESTDIR) -name '*.d')
TEST_TARGET = test
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CXX) $(LIBRARY_PATHS) $(CXXFLAGS) $(OBJECTS) -o $(TARGET) $(LIBRARIES)
build/$(SRCDIR)/%.o: $(SRCDIR)/%.cpp
@mkdir -p $(dir $@)
@$(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDE_PATHS) -MM -MF $(patsubst %.o,%.d,$@) -MT $@ -c $<
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDE_PATHS) -c -o $@ $<
$(TEST_TARGET): $(TEST_OBJECTS) $(filter-out build/$(SRCDIR)/main.o, $(OBJECTS))
$(CXX) $(LIBRARY_PATHS) $(CXXFLAGS) $(GTEST_L) $(INCLUDE_PATHS) $^ -pthread -lgtest -o $(TEST_TARGET) $(LIBRARIES)
build/$(TESTDIR)/%.o: $(TESTDIR)/%.cpp
@mkdir -p $(dir $@)
@$(CXX) $(CXXFLAGS) $(GTEST_I) $(INCLUDE_PATHS) -MM -MF $(patsubst %.o,%.d,$@) -MT $@ -c $<
$(CXX) $(CXXFLAGS) $(GTEST_I) $(INCLUDE_PATHS) $< -c -o $@
build/$(TESTDIR)/gtest_main.o: $(GTEST)/googletest/src/gtest_main.cc
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(GTEST_I) $< -c -o $@
include $(DEPS) $(TEST_DEPS)
clean:
rm -rf build $(TARGET) $(TEST_TARGET)