-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
114 lines (89 loc) · 3.11 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
CC=gcc
OPT_FLAG = -O2 -flto=auto
ifeq (${DEBUG},1)
OPT_FLAG = -Og
endif
# CFLAGS ?= -g -O3 -flto=auto -march=native -mtune=native -MMD -MP -I. -Iinclude -DCONFIG_INT128
CFLAGS ?= -g ${OPT_FLAG} -MMD -MP -I. -Iinclude -Ibuild -Wall -Werror
LDFLAGS ?= -lm -lrt -rdynamic ${OPT_FLAG}
ifeq (${GDB},1)
CFLAGS += -DCONFIG_GDB
GDB_SOURCES := gdbserver.c
endif
ifeq (${CLI},1)
CFLAGS += -DCONFIG_CLI
endif
ifeq (${DIFF},1)
CFLAGS += -DCONFIG_DIFF -fPIC
endif
ifeq (${PERF},1)
CFLAGS += -DCONFIG_PERF
endif
ifeq (${CORE},)
CFLAGS += -D__CORE__=la464
else
CFLAGS += -D__CORE__=$(CORE)
endif
ifeq (${PLUGIN},1)
LDFLAGS += -ldl
CFLAGS += -DCONFIG_PLUGIN
endif
arch := $(shell gcc -dumpmachine)
ifeq ($(arch),loongarch64-linux-gnu)
LDFLAGS+=-Wl,-Tlink_script/loongarch64.lds
endif
ifeq (${DIFF},1)
LDFLAGS += -shared -fPIC -Wl,--no-undefined
endif
BUILD_DIR := ./build
SRC_DIRS := ./
USER_SOURCES := fpu_helper.c host-utils.c int128.c interpreter.c main.c softfloat.c vec_helper.c tcg-runtime-gvec.c syscall.c ${GDB_SOURCES} debug_cli.c cpu.c checkpoint.c
USER_OBJS := $(addprefix $(BUILD_DIR)/, $(patsubst %.c,%_user.o,$(USER_SOURCES)))
USER_DEPS := $(USER_OBJS:.o=.d)
KERNEL_SOURCES := fpu_helper.c host-utils.c int128.c interpreter.c main.c softfloat.c tlb_helper.c cpu_helper.c vec_helper.c tcg-runtime-gvec.c serial.c serial_plus.c ${GDB_SOURCES} debug_cli.c cpu.c fifo.c checkpoint.c
KERNEL_OBJS := $(addprefix $(BUILD_DIR)/, $(patsubst %.c,%_kernel.o,$(KERNEL_SOURCES)))
KERNEL_DEPS := $(KERNEL_OBJS:.o=.d)
DIFF_SOURCES := $(KERNEL_SOURCES) difftest.c
DIFF_OBJS := $(addprefix $(BUILD_DIR)/, $(patsubst %.c,%_diff.o,$(DIFF_SOURCES)))
DIFF_DEPS := $(DIFF_OBJS:.o=.d)
$(info $$USER_SOURCES is [${USER_SOURCES}])
$(info $$USER_OBJS is [${USER_OBJS}])
$(info $$USER_DEPS is [${USER_DEPS}])
$(info $$KERNEL_SOURCES is [${KERNEL_SOURCES}])
$(info $$KERNEL_OBJS is [${KERNEL_OBJS}])
$(info $$KERNEL_DEPS is [${KERNEL_DEPS}])
$(info $$DIFF_SOURCES is [${DIFF_SOURCES}])
$(info $$DIFF_OBJS is [${DIFF_OBJS}])
$(info $$DIFF_DEPS is [${DIFF_DEPS}])
ifeq (${DIFF},1)
TARGETS = $(BUILD_DIR)/la_emu_ref.so
else
TARGETS = $(BUILD_DIR)/la_emu_user $(BUILD_DIR)/la_emu_kernel
endif
all: $(TARGETS)
make -C plugins -j
${USER_OBJS} ${KERNEL_OBJS} ${DIFF_OBJS} : $(BUILD_DIR)/trans_la.c.inc
$(BUILD_DIR)/trans_la.c.inc: insns.decode
@mkdir -p $(BUILD_DIR)
python3 ./scripts/decodetree.py ./insns.decode -o $(BUILD_DIR)/decode-insns.c.inc
python3 ./scripts/emu_cpu_put_ic.py $(BUILD_DIR)/decode-insns.c.inc > $(BUILD_DIR)/trans_la.c.inc
$(BUILD_DIR)/la_emu_user : ${USER_OBJS}
$(CC) $(USER_OBJS) -o $@ $(LDFLAGS)
$(BUILD_DIR)/%_user.o : %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -DCONFIG_USER_ONLY=1 -c -o $@ $<
$(BUILD_DIR)/la_emu_kernel : ${KERNEL_OBJS}
$(CC) $(KERNEL_OBJS) -o $@ $(LDFLAGS)
$(BUILD_DIR)/%_kernel.o : %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/la_emu_ref.so : ${DIFF_OBJS}
$(CC) $(DIFF_OBJS) -o $@ $(LDFLAGS)
$(BUILD_DIR)/%_diff.o : %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -rf build $(BUILD_DIR)/trans_la.c.inc
.EXTRA_PREREQS = Makefile
-include $(USER_DEPS)
-include $(KERNEL_DEPS)