-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
73 lines (55 loc) · 1.6 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
TOOLCHAIN = arm-none-eabi
TARGET = kernel.elf
ARMARCH = armv7-a
CORE = cortex-a9
CC = $(TOOLCHAIN)-gcc
AS = $(TOOLCHAIN)-as
SIZE = $(TOOLCHAIN)-size
DUMP = $(TOOLCHAIN)-objdump
SRCDIR = src
OBJDIR = obj
BINDIR = bin
LFILE = $(SRCDIR)/linker.ld
# Compile flags here
CFLAGS = -std=gnu11 -Wall -nostartfiles -fno-exceptions -mcpu=$(CORE) -static -g
AFLAGS =
LINKER = $(CC) -o
# linking flags here
LFLAGS = -Wall -T $(LFILE) -nostartfiles -fno-exceptions --specs=nosys.specs -mcpu=$(CORE) -static -g -lc -Wl,--print-map > bin/mapfile.map
GDB = gdb-multiarch
QEMU = qemu-system-arm
QEMU_OPTS = -M vexpress-a9 -audio sdl -drive file=bin/sd.img,format=raw,if=sd -serial mon:stdio -kernel
C_FILES := $(wildcard $(SRCDIR)/*.c)
AS_FILES := $(wildcard $(SRCDIR)/*.S)
OBJECTS_C := $(addprefix $(OBJDIR)/,$(notdir $(C_FILES:.c=.o)))
OBJECTS_S := $(addprefix $(OBJDIR)/,$(notdir $(AS_FILES:.S=.o)))
OBJECTS_ALL := $(OBJECTS_S) $(OBJECTS_C)
rm = rm -f
$(BINDIR)/$(TARGET): $(OBJECTS_ALL)
@mkdir -p $(@D)
@$(LINKER) $@ $(LFLAGS) $(OBJECTS_ALL)
@echo "Linking complete!"
@$(SIZE) $@
$(OBJECTS_ALL) : | obj
$(OBJDIR):
@mkdir -p $@
$(OBJDIR)/%.o : $(SRCDIR)/%.c
@$(CC) $(CFLAGS) -c $< -o $@
@echo "Compiled "$<" successfully!"
$(OBJDIR)/%.o : $(SRCDIR)/%.S
@$(AS) $(AFLAGS) $< -o $@
@echo "Assembled "$<" successfully!"
qemu:
$(QEMU) $(QEMU_OPTS) $(BINDIR)/$(TARGET)
gdb:
$(GDB) $(BINDIR)/$(TARGET)
dqemu:
$(QEMU) -s -S $(QEMU_OPTS) $(BINDIR)/$(TARGET)
.PHONY: clean
clean:
@$(rm) $(OBJECTS_ALL)
@echo "Cleanup complete!"
.PHONY: remove
remove: clean
@$(rm) $(BINDIR)/$(TARGET)
@echo "Executable removed!"