forked from chipsalliance/VeeR-ISS
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGNUmakefile
214 lines (168 loc) · 6.78 KB
/
GNUmakefile
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
INSTALL_DIR := .
PROJECT := whisper
PY_PROJECT := py$(PROJECT)$(shell python3-config --extension-suffix)
# For Dynamic linking to Boost Library use:
# make STATIC_LINK=0
STATIC_LINK := 1
# We use boost 1.67.
# Set the BOOST_ROOT environment variable to point to the base install
# location of the Boost Libraries
BOOST_ROOT ?= /wdc/apps/utilities/boost-1.67
BOOST_DIR := $(BOOST_ROOT)
# For Various Installation types of Boost Library
BOOST_INC := $(wildcard $(BOOST_DIR) $(BOOST_DIR)/include)
# These boost libraries must be compiled with: "g++ -std=c++14" or "g++ -std=c++17"
# For Various Installation types of Boost Library
BOOST_LIB_DIR := $(wildcard $(BOOST_DIR)/stage/lib $(BOOST_DIR)/lib)
# Specify only the basename of the Boost libraries
BOOST_LIBS := boost_program_options
# Add extra dependency libraries here
EXTRA_LIBS := -lpthread -lm -lz -ldl -static-libstdc++ -lrt
ifdef SOFT_FLOAT
override CPPFLAGS += -I$(PWD)/third_party/softfloat/source/include
override CPPFLAGS += -DSOFT_FLOAT
soft_float_build := $(wildcard $(PWD)/third_party/softfloat/build/RISCV-GCC)
soft_float_lib := $(soft_float_build)/softfloat.a
endif
PCI := 1
ifdef PCI
override CPPFLAGS += -I$(PWD)/pci
pci_build := $(wildcard $(PWD)/pci/)
pci_lib := $(PWD)/pci/libpci.a
endif
TRACE_READER := 1
ifdef TRACE_READER
override CPPFLAGS += -I$(PWD)/trace-reader
trace_reader_build := $(wildcard $(PWD)/trace-reader/)
trace_reader_lib := $(PWD)/trace-reader/TraceReader.a
endif
MEM_CALLBACKS := 1
ifeq ($(MEM_CALLBACKS), 1)
ifdef FAST_SLOPPY
$(warning "FAST_SLOPPY not compatible with MEM_CALLBACKS, turning off MEM_CALLBACKS")
MEM_CALLBACKS := 0
else
override CPPFLAGS += -DMEM_CALLBACKS
endif
endif
ifdef FAST_SLOPPY
override CPPFLAGS += -DFAST_SLOPPY
endif
ifdef LZ4_COMPRESS
override CPPFLAGS += -DLZ4_COMPRESS
EXTRA_LIBS += -llz4
endif
# Add External Library location paths here
LINK_DIRS += $(addprefix -L,$(BOOST_LIB_DIR))
# Generating the Linker options for dependent libraries
ifeq ($(STATIC_LINK), 1)
LINK_LIBS := $(addprefix -l:lib, $(addsuffix .a, $(BOOST_LIBS))) $(EXTRA_LIBS)
else
COMMA := ,
LINK_DIRS += $(addprefix -Wl$(COMMA)-rpath=, $(BOOST_LIB_DIR))
LINK_LIBS := $(addprefix -l, $(BOOST_LIBS)) $(EXTRA_LIBS)
endif
ifeq (Darwin,$(shell uname))
EXTRA_LIBS := -lpthread -lm -lz -ldl -lc++
LINK_LIBS := $(BOOST_LIB_DIR)/lib$(BOOST_LIBS).a $(EXTRA_LIBS)
else
LINK_LIBS += -Wl,-export-dynamic
endif
ifeq (x86_64,$(shell uname -p))
ARCH_FLAGS := -mfma
else
ARCH_FLAGS :=
endif
# For out of source build
BUILD_DIR := build-$(shell uname -s)
MKDIR_P ?= mkdir -p
RM := rm -rf
# Optimization flags. Use -g for debug.
OFLAGS ?= -O3
# Include paths.
IFLAGS := $(addprefix -isystem ,$(BOOST_INC)) -isystem third_party -I.
CXX_STD ?= c++20
# Command to compile .cpp files.
override CXXFLAGS += -MMD -MP $(ARCH_FLAGS) -std=$(CXX_STD) $(OFLAGS) $(IFLAGS)
override CXXFLAGS += -fPIC -pedantic -Wall -Wextra -Wformat -Wwrite-strings
# Rule to make a .o from a .cpp file.
$(BUILD_DIR)/%.cpp.o: %.cpp
@if [ ! -d "$(dir $@)" ]; then $(MKDIR_P) $(dir $@); fi
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
# Main target.(only linking)
$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/whisper.cpp.o \
$(BUILD_DIR)/librvcore.a \
$(soft_float_lib) \
$(pci_lib)
$(CXX) -o $@ $(OFLAGS) $^ $(LINK_DIRS) $(LINK_LIBS)
$(BUILD_DIR)/$(PY_PROJECT): $(BUILD_DIR)/py-bindings.cpp.o \
$(BUILD_DIR)/librvcore.a \
$(soft_float_lib) \
$(pci_lib)
$(CXX) -shared -o $@ $(OFLAGS) $^ $(LINK_DIRS) $(LINK_LIBS)
# Rule to make whisper.cpp.o. Always recompile to get latest GIT SHA into the help
# message.
$(BUILD_DIR)/Args.cpp.o: .FORCE
@if [ ! -d "$(dir $@)" ]; then $(MKDIR_P) $(dir $@); fi
sha=`git rev-parse --verify HEAD || echo unknown`; \
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DGIT_SHA="$$sha" -c -o $@ Args.cpp
# Rule to make PY_PROJECT .so
$(BUILD_DIR)/py-bindings.cpp.o: .FORCE
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(shell python3 -m pybind11 --includes) -c -o $@ py-bindings.cpp
# List of all CPP sources needed for librvcore.a
RVCORE_SRCS := IntRegs.cpp CsRegs.cpp FpRegs.cpp instforms.cpp \
Memory.cpp Hart.cpp InstEntry.cpp Triggers.cpp \
PerfRegs.cpp gdb.cpp HartConfig.cpp \
Server.cpp Interactive.cpp Disassembler.cpp printTrace.cpp \
Syscall.cpp PmaManager.cpp DecodedInst.cpp snapshot.cpp \
PmpManager.cpp VirtMem.cpp Core.cpp System.cpp Cache.cpp \
Tlb.cpp VecRegs.cpp vector.cpp wideint.cpp float.cpp bitmanip.cpp \
amo.cpp SparseMem.cpp InstProfile.cpp Isa.cpp Mcm.cpp \
crypto.cpp Decoder.cpp Trace.cpp cbo.cpp Uart8250.cpp \
Uartsf.cpp hypervisor.cpp vector-crypto.cpp WhisperMessage.cpp \
Imsic.cpp Args.cpp Session.cpp PerfApi.cpp dot-product.cpp
# List of All CPP Sources for the project
SRCS_CXX += $(RVCORE_SRCS) whisper.cpp
# List of All C Sources for the project
SRCS_C :=
# List of all object files for the project
OBJS_GEN := $(SRCS_CXX:%=$(BUILD_DIR)/%.o) $(SRCS_C:%=$(BUILD_DIR)/%.o)
# List of all auto-genreated dependency files.
DEPS_FILES := $(OBJS_GEN:.o=.d)
# Include Generated Dependency files if available.
-include $(DEPS_FILES)
# Object files needed for librvcore.a
OBJS := $(RVCORE_SRCS:%=$(BUILD_DIR)/%.o) $(SRCS_C:%=$(BUILD_DIR)/%.o)
$(BUILD_DIR)/librvcore.a: $(OBJS)
$(AR) cr $@ $^
$(soft_float_lib):
$(MAKE) -C $(soft_float_build)
$(pci_lib):
$(MAKE) -C $(pci_build) CXX=$(CXX)
$(trace_reader_lib):
$(MAKE) -C $(trace_reader_build)
all: $(BUILD_DIR)/$(PROJECT) $(BUILD_DIR)/$(PY_PROJECT)
install: $(BUILD_DIR)/$(PROJECT)
@if test "." -ef "$(INSTALL_DIR)" -o "" == "$(INSTALL_DIR)" ; \
then echo "INSTALL_DIR is not set or is same as current dir" ; \
else echo cp $^ $(INSTALL_DIR); cp $^ $(INSTALL_DIR); \
fi
install-py: $(BUILD_DIR)/$(PY_PROJECT)
@if test "." -ef "$(INSTALL_DIR)" -o "" == "$(INSTALL_DIR)" ; \
then echo "INSTALL_DIR is not set or is same as current dir" ; \
else echo cp $^ $(INSTALL_DIR); cp $^ $(INSTALL_DIR); \
fi
clean:
$(RM) $(BUILD_DIR)/$(PROJECT) $(BUILD_DIR)/$(PY_PROJECT) $(OBJS_GEN) $(BUILD_DIR)/librvcore.a $(DEPS_FILES) ; \
$(if $(soft_float_build),$(MAKE) -C $(soft_float_build) clean ;,) \
$(if $(pci_build),$(MAKE) -C $(pci_build) clean;,) \
$(if $(trace_reader_build),$(MAKE) -C $(trace_reader_build) clean;,)
help:
@echo "Possible targets: $(BUILD_DIR)/$(PROJECT) $(BUILD_DIR)/$(PY_PROJECT) all install install-py clean"
@echo "To compile for debug: make OFLAGS=-g"
@echo "To install: make INSTALL_DIR=<target> install"
@echo "To browse source code: make cscope"
cscope:
( find . \( -name \*.cpp -or -name \*.hpp -or -name \*.c -or -name \*.h \) -print | xargs cscope -b ) && cscope -d && $(RM) cscope.out
.FORCE:
.PHONY: all install install-py clean help cscope .FORCE