-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtoolchain.mk
67 lines (54 loc) · 1.57 KB
/
toolchain.mk
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
# external parameters
DEBUG = 1
OPT_LEVEL = 2
# judge if is debug mode
ifeq ($(DEBUG), 0)
C_DEBUG_ARG = -DNDEBUG
C_OPT_ARG = -O$(OPT_LEVEL)
YU_OPT_ARG = -O $(OPT_LEVEL)
else
C_DEBUG_ARG = -g
C_OPT_ARG = -O0
YU_OPT_ARG = -O 0
endif
# cross compile toolchain prefix
LLVM_BIN := /usr/local/opt/llvm/bin
YU_BIN := /Users/maxxing/Programming/MyRepo/YuLang/build
# cross Yu compiler
YUFLAGS := -Werror $(YU_OPT_ARG)
YUFLAGS += -tt riscv32-unknown-elf -tc generic-rv32 -tf +m,+a
export YUC := $(YU_BIN)/yuc $(YUFLAGS)
# cross C compiler
CFLAGS := -Wall -Werror -c -static $(C_DEBUG_ARG) $(C_OPT_ARG)
CFLAGS += -fno-builtin -fno-pic
CFLAGS += -target riscv32-unknown-elf -march=rv32ima -mabi=ilp32
export CC := $(LLVM_BIN)/clang $(CFLAGS)
# native C++ compiler
CXXFLAGS := -Wall -Werror -c $(C_DEBUG_ARG) $(C_OPT_ARG)
CXXFLAGS += -std=c++17
export CXX := clang++ $(CXXFLAGS)
# cross LLVM compiler
LLCFLAGS := $(C_OPT_ARG) -filetype=obj
LLCFLAGS += -march=riscv32 -mcpu=generic-rv32 -mattr=+m,+a
export LLC := $(LLVM_BIN)/llc $(LLCFLAGS)
# cross linker
LDFLAGS := -nostdlib -melf32lriscv
export LD := $(LLVM_BIN)/ld.lld $(LDFLAGS)
# native linker
NLDFLAGS :=
export NLD := clang++ $(NLDFLAGS)
# objcopy
OBJCFLAGS := -O binary
export OBJC := $(LLVM_BIN)/llvm-objcopy $(OBJCFLAGS)
# objdump
OBJDFLAGS := -D
export OBJD := objdump $(OBJDFLAGS)
# strip
STRIPFLAGS := --strip-unneeded --strip-sections
export STRIP := $(LLVM_BIN)/llvm-strip $(STRIPFLAGS)
# archiver
ARFLAGS := ru
export AR := $(LLVM_BIN)/llvm-ar $(ARFLAGS)
# ranlib
RANLIBFLAGS :=
export RANLIB := $(LLVM_BIN)/llvm-ranlib $(RANLIBFLAGS)