-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
90 lines (59 loc) · 1.85 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
################################################################
OO_DIR = /e/AGRV/AgRV_pio/packages/tool-agrv_logic/openocd/
OPENOCD = $(OO_DIR)/bin/openocd.exe -c "set ADAPTER cmsis-dap; set CONNECT_UNDER_RESET 1" -f $(OO_DIR)/agrv2k.cfg
CROSS = riscv64-unknown-elf-
CC = $(CROSS)gcc
AS = $(CROSS)gcc
LD = $(CROSS)gcc
OBJCOPY = $(CROSS)objcopy
OBJDUMP = $(CROSS)objdump
GDB = $(CROSS)gdb
TARGET = agrv32.elf
modules = main cherryusb tntfs
################################################################
make_module_dirs := $(shell mkdir -p $(addprefix objs/, $(modules)) )
OBJS :=
INCDIR := -Iinc
DEFS :=
LDFLAGS := -fno-builtin -nostartfiles -nodefaultlibs
include $(addsuffix /Makefile, $(modules))
CFLAGS := -Wall -g -MMD -fno-builtin $(DEFS) $(INCDIR)
TOBJS = $(addprefix objs/, $(OBJS))
DEPENDS = $(patsubst %.o, %.d, $(TOBJS))
all: $(TARGET)
clean:
rm -f $(TOBJS) $(TARGET) $(TARGET).bin $(TARGET).dump
$(TARGET): $(TOBJS)
ifeq ($(V), 1)
@echo $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
@echo $(OBJDUMP) -xd $@ >[email protected]
@echo $(OBJCOPY) -O binary -R .comment -R .note* $@ [email protected]
else
@echo linking $@ ...
endif
@$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
@$(OBJDUMP) -xd $@ >[email protected]
@$(OBJCOPY) -O binary -R .comment -R .note* $@ [email protected]
-include $(DEPENDS)
objs/%.o: %.c
ifeq ($(V), 1)
@echo $(CC) $(CFLAGS) -c $< -o $@
else
@echo Compile $< ...
endif
@$(CC) $(CFLAGS) -c $< -o $@
objs/%.o: %.S
ifeq ($(V), 1)
@echo $(CC) -D__ASSEMBLY__ $(CFLAGS) $(ASFLAG) -c $< -o $@
else
@echo Compile $< ...
endif
@$(CC) -D__ASSEMBLY__ $(CFLAGS) $(ASFLAG) -c $< -o $@
################################################################
dl: $(TARGET)
$(OPENOCD) -c "flash write_image erase agrv32.elf.bin 0x80000000" -c "reset" -c "exit"
gdb:
start $(OPENOCD)
$(GDB) --tui -ex "target remote 127.0.0.1:3333" agrv32.elf
oohlp:
$(OPENOCD) -c "help" -c "exit"