This repository has been archived by the owner on Aug 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
136 lines (97 loc) · 4.18 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
ifndef OS
uname := $(shell uname)
ifeq ($(uname),Darwin)
OS = OSX
else
ifeq ($(uname),Linux)
OS = LINUX
else
$(error Unrecognized operating system $(uname))
endif
endif
endif
LIBUNWIND_DIR = deps/libunwind
LIBUNWIND_INCLUDEDIR = $(LIBUNWIND_DIR)/include
LLVM_CONFIG := $(shell ./detect-llvm.sh)
LLVM_INCLUDEDIR := `$(LLVM_CONFIG) --includedir`
LLVM_CXXFLAGS := `$(LLVM_CONFIG) --cxxflags`
LLVM_LDFLAGS := `$(LLVM_CONFIG) --ldflags --libs --system-libs core mcjit x86`
C_CXX_FLAGS_COMMON = -fPIC -Wall -I $(LIBUNWIND_INCLUDEDIR) -pthread
override CFLAGS += -std=gnu11 $(C_CXX_FLAGS_COMMON)
override CXXFLAGS += -std=gnu++11 $(C_CXX_FLAGS_COMMON)
ifeq ($(OS),LINUX)
override LDFLAGS += -ldl
endif
TARGET = target
YUGONG_DIR = yugong
YUGONG_CXX_SRCS = $(wildcard $(YUGONG_DIR)/*.cpp)
YUGONG_CXX_HDRS = $(wildcard $(YUGONG_DIR)/*.hpp)
YUGONG_CXX_OUTS = $(foreach F,$(YUGONG_CXX_SRCS),$(patsubst $(YUGONG_DIR)/%.cpp,$(TARGET)/%.o,$(F)))
YUGONG_ASM_SRCS = $(wildcard $(YUGONG_DIR)/*.S)
YUGONG_ASM_HDRS = $(wildcard $(YUGONG_DIR)/*.S.inc)
YUGONG_ASM_OUTS = $(foreach F,$(YUGONG_ASM_SRCS),$(patsubst $(YUGONG_DIR)/%.S,$(TARGET)/%.o,$(F)))
YUGONG_SRCS = $(YUGONG_CXX_SRCS) $(YUGONG_ASM_SRCS)
YUGONG_HDRS = $(YUGONG_CXX_HDRS) $(YUGONG_ASM_HDRS)
YUGONG_OUTS = $(YUGONG_CXX_OUTS) $(YUGONG_ASM_OUTS)
YUGONG_AR = $(TARGET)/libyugong.a
YUGONG_LLVM_DIR = yugong-llvm
YUGONG_LLVM_SRCS = $(wildcard $(YUGONG_LLVM_DIR)/*.cpp)
YUGONG_LLVM_HDRS = $(wildcard $(YUGONG_LLVM_DIR)/*.hpp)
YUGONG_LLVM_OUTS = $(foreach F,$(YUGONG_LLVM_SRCS),$(patsubst $(YUGONG_LLVM_DIR)/%.cpp,$(TARGET)/%.o,$(F)))
YUGONG_LLVM_CXXFLAGS = $(CXXFLAGS) -I $(YUGONG_DIR) $(LLVM_CXXFLAGS)
YUGONG_LLVM_AR = $(TARGET)/libyugong-llvm.a
TESTS_DIR = tests
TESTS_SRCS = $(wildcard $(TESTS_DIR)/test_*.cpp)
TESTS_HDRS = $(wildcard $(TESTS_DIR)/test_*.hpp)
TESTS_OUTS = $(foreach F,$(TESTS_SRCS),$(patsubst $(TESTS_DIR)/%.cpp,$(TARGET)/%,$(F)))
TESTS_CXXFLAGS = $(CXXFLAGS) -I $(YUGONG_DIR)
TESTS_LLVM_SRCS = $(wildcard $(TESTS_DIR)/test-llvm_*.cpp)
TESTS_LLVM_HDRS = $(wildcard $(TESTS_DIR)/test-llvm_*.hpp)
TESTS_LLVM_OUTS = $(foreach F,$(TESTS_LLVM_SRCS),$(patsubst $(TESTS_DIR)/%.cpp,$(TARGET)/%,$(F)))
TESTS_LLVM_CXXFLAGS = $(CXXFLAGS) $(LLVM_CXXFLAGS) -I $(YUGONG_DIR) -I $(YUGONG_LLVM_DIR)
LIBUNWIND_AR = $(TARGET)/libunwind-build/lib/libunwind.a
.SECONDEXPANSION:
.PHONY: all dir libunwind src yugong yugong-llvm
all: dir libunwind src tests
dir: $(TARGET)
$(TARGET):
mkdir -p $(TARGET)
libunwind: $(LIBUNWIND_AR)
$(LIBUNWIND_AR):
mkdir -p $(TARGET)/libunwind-build
(cd $(TARGET)/libunwind-build; cmake ../../deps/libunwind -DLLVM_CONFIG_PATH=`which $(LLVM_CONFIG)` $(LIBUNWIND_CONF) && make -j $(LIBUNWIND_MAKE))
.PHONY: recompilelibunwind
recompilelibunwind:
(cd $(TARGET)/libunwind-build; make)
$(AR) cr $(LIBUNWIND_AR) $(TARGET)/libunwind-build/src/CMakeFiles/unwind.dir/*.o
# yugong-llvm needs a major rewriting. Disabled for now.
#src: yugong yugong-llvm
src: yugong
yugong: $(YUGONG_AR)
yugong-llvm: $(YUGONG_LLVM_AR)
$(YUGONG_AR): $(YUGONG_OUTS)
$(AR) cr $(YUGONG_AR) $(YUGONG_OUTS)
$(YUGONG_CXX_OUTS): $(TARGET)/%.o: $(YUGONG_DIR)/%.cpp $(YUGONG_HDRS)
$(CXX) -c $(CXXFLAGS) $< -o $@
$(YUGONG_ASM_OUTS): $(TARGET)/%.o: $(YUGONG_DIR)/%.S $(YUGONG_ASM_HDRS)
$(CXX) -c $(CXXFLAGS) $< -o $@
$(YUGONG_LLVM_AR): $(YUGONG_LLVM_OUTS)
$(AR) cr $(YUGONG_LLVM_AR) $(YUGONG_LLVM_OUTS)
$(YUGONG_LLVM_OUTS): $(TARGET)/%.o: $(YUGONG_LLVM_DIR)/%.cpp $(YUGONG_HDRS) $(YUGONG_LLVM_HDRS)
$(CXX) -c $(YUGONG_LLVM_CXXFLAGS) $< -o $@
.PHONY: tests
# yugong-llvm needs a major rewriting. Disabled for now.
# tests: $(TESTS_OUTS) $(TESTS_LLVM_OUTS)
tests: $(TESTS_OUTS)
$(TESTS_OUTS): $(TARGET)/%: $(TESTS_DIR)/%.cpp $(TESTS_HDRS) $(YUGONG_AR) $(LIBUNWIND_AR)
$(CXX) $(TESTS_CXXFLAGS) $< $(YUGONG_AR) $(LIBUNWIND_AR) $(LDFLAGS) -o $@
$(TESTS_LLVM_OUTS): $(TARGET)/%: $(TESTS_DIR)/%.cpp $(TESTS_HDRS) $(TESTS_LLVM_HDRS) $(YUGONG_AR) $(YUGONG_LLVM_AR) $(LIBUNWIND_AR)
$(CXX) $(TESTS_LLVM_CXXFLAGS) $< $(YUGONG_AR) $(YUGONG_LLVM_AR) $(LIBUNWIND_AR) $(LDFLAGS) $(LLVM_LDFLAGS) -o $@
.PHONY: clean
clean:
rm -r $(TARGET)
.PHONY: showincludedirs
showincludedirs:
@echo $(realpath $(YUGONG_DIR))
@echo $(realpath $(YUGONG_LLVM_DIR))
@echo $(LLVM_INCLUDEDIR)