-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
70 lines (52 loc) · 1.4 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
CFLAGS = -Iinclude -Wall -Wextra -MMD #-Werror
CURDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
O ?= build
ifeq ($(O), $(CURDIR)/build)
OUT := $(CURDIR)
else
OUT := $(O)
endif
LIBGDBSTUB = $(OUT)/libgdbstub.a
SHELL_HACK := $(shell mkdir -p $(OUT))
GIT_HOOKS := .git/hooks/applied
LIBSRCS = $(shell find ./lib -name '*.c')
_LIB_OBJ = $(notdir $(LIBSRCS))
LIB_OBJ = $(_LIB_OBJ:%.c=$(OUT)/%.o)
TEST_OBJ = $(OUT)/test.obj
TEST_BIN = $(OUT)/test.bin
vpath %.c $(sort $(dir $(LIBSRCS)))
.PHONY: all debug test clean
all: CFLAGS += -O3
all: LDFLAGS += -O3
all: $(LIBGDBSTUB)
debug: CFLAGS += -O3 -g -DDEBUG
debug: LDFLAGS += -O3
debug: $(LIBGDBSTUB)
$(GIT_HOOKS):
@scripts/install-git-hooks
@echo
$(OUT)/%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
$(LIBGDBSTUB): $(LIB_OBJ)
$(AR) -rcs $@ $^
$(TEST_OBJ): tests/test.c
riscv32-unknown-elf-gcc -march=rv32g -Wl,-Ttext=0x0 -nostdlib -g -o $@ $<
$(TEST_BIN): $(TEST_OBJ)
riscv32-unknown-elf-objcopy -O binary $< $@
build-emu: $(LIBGDBSTUB)
$(MAKE) -C emu
run-gdbstub: $(TEST_BIN) build-emu
emu/build/emu $(TEST_BIN)
GDBSTUB_COMM = 127.0.0.1:1234
run-gdb: $(TEST_OBJ)
riscv32-unknown-elf-gdb \
-ex "file $(TEST_OBJ)" \
-ex "set debug remote 1" \
-ex "target remote $(GDBSTUB_COMM)" \
clean:
$(RM) $(LIB_OBJ)
$(RM) $(LIBGDBSTUB)
$(RM) $(TEST_BIN)
$(RM) $(TEST_OBJ)
$(RM) $(OUT)/*.d
-include $(OUT)/*.d