-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
85 lines (69 loc) · 2.39 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
NAME = interpret_sch
DEPEND = sch phy ucs interpret_ucs parse_spice parse_ucs parse common
SRCDIR = $(NAME)
TESTDIR = tests
GTEST := ../../googletest
GTEST_I := -I$(GTEST)/googletest/include -I.
GTEST_L := -L$(GTEST)/build/lib -L.
CXXFLAGS = -std=c++17 -O2 -g -Wall -fmessage-length=0 $(DEPEND:%=-I../%) -I.
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 = lib$(NAME).a
TESTS := $(shell mkdir -p $(TESTDIR); 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
ifeq ($(OS),Windows_NT)
CXXFLAGS += -D WIN32
ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
CXXFLAGS += -D AMD64
else
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
CXXFLAGS += -D AMD64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
CXXFLAGS += -D IA32
endif
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CXXFLAGS += -D LINUX
endif
ifeq ($(UNAME_S),Darwin)
CXXFLAGS += -D OSX -mmacos-version-min=12.0 -Wno-varargs
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
CXXFLAGS += -D AMD64
endif
ifneq ($(filter %86,$(UNAME_P)),)
CXXFLAGS += -D IA32
endif
ifneq ($(filter arm%,$(UNAME_P)),)
CXXFLAGS += -D ARM
endif
endif
all: lib
lib: $(TARGET)
tests: lib $(TEST_TARGET)
$(TARGET): $(OBJECTS)
ar rvs $(TARGET) $(OBJECTS)
build/$(SRCDIR)/%.o: $(SRCDIR)/%.cpp
@mkdir -p $(dir $@)
@$(CXX) $(CXXFLAGS) $(LDFLAGS) -MM -MF $(patsubst %.o,%.d,$@) -MT $@ -c $<
$(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $<
$(TEST_TARGET): $(TEST_OBJECTS)
$(CXX) $(CXXFLAGS) $(GTEST_L) $^ -pthread -l$(NAME) -lgtest -o $(TEST_TARGET)
build/$(TESTDIR)/%.o: $(TESTDIR)/%.cpp
@mkdir -p $(dir $@)
@$(CXX) $(CXXFLAGS) $(GTEST_I) -MM -MF $(patsubst %.o,%.d,$@) -MT $@ -c $<
$(CXX) $(CXXFLAGS) $(GTEST_I) $< -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)