-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
68 lines (52 loc) · 1.82 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
TARGET = NarcOS
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
OBJDUMP = arm-none-eabi-objdump
CFLAGS = -mcpu=Cortex-A53 -ffreestanding -fpic -O2 -lgcc -c -Wall -Wextra -std=gnu99
ASFLAGS = -mcpu=Cortex-A53 -ffreestanding -fpic -c
LDFLAGS = -ffreestanding -O2 -nostdlib
SRCDIR = src
OBJDIR = obj
BINDIR = bin
LISTDIR = list
LDDIR = linker
CSRCDIR = $(SRCDIR)/c
CINCDIR = $(SRCDIR)/c/include
ASMSRCDIR = $(SRCDIR)/asm
CLISTDIR = $(LISTDIR)/c
ASMLISTDIR = $(LISTDIR)/asm
COBJDIR = $(OBJDIR)/c
ASMOBJDIR = $(OBJDIR)/asm
COBJS = $(patsubst $(CSRCDIR)/%.c, $(COBJDIR)/%.o, $(wildcard $(CSRCDIR)/*.c))
ASMOBJS = $(patsubst $(ASMSRCDIR)/%.s, $(ASMOBJDIR)/%.o, $(wildcard $(ASMSRCDIR)/*.s))
CLISTS = $(patsubst $(CSRCDIR)/%.c, $(CLISTDIR)/%.lst, $(wildcard $(CSRCDIR)/*.c))
ASMLISTS = $(patsubst $(ASMSRCDIR)/%.s, $(ASMLISTDIR)/%.lst, $(wildcard $(ASMSRCDIR)/*.s))
OUTPUT_ELF = kernel.elf
OUTPUT_IMG = kernel.img
$(COBJDIR)/%.o : $(CSRCDIR)/%.c
@echo "Compiling C code"
@$(CC) $(CFLAGS) -I$(CINCDIR) -o $@ $^
$(ASMOBJDIR)/%.o : $(ASMSRCDIR)/%.s
@echo "Assembling ASM code"
@$(CC) $(ASFLAGS) -o $@ $^
$(CLISTDIR)/%.lst : $(COBJDIR)/%.o
@echo "Generating C list"
@rm -f $@
@$(OBJDUMP) -D $^ >> $@
$(ASMLISTDIR)/%.lst : $(ASMOBJDIR)/%.o
@echo "Generating ASM list"
@rm -f $@
@$(OBJDUMP) -D $^ >> $@
$(TARGET): $(COBJS) $(ASMOBJS) $(CLISTS) $(ASMLISTS)
@echo "Building binary"
@$(CC) $(LDFLAGS) -T $(LDDIR)/linker.ld -o $(BINDIR)/$(OUTPUT_ELF) $(COBJS) $(ASMOBJS)
@echo "Generated kernel.elf"
@$(OBJCOPY) $(BINDIR)/$(OUTPUT_ELF) -O binary $(BINDIR)/$(OUTPUT_IMG)
@echo "Generated kernel.img"
all: $(TARGET)
clean:
@echo "Cleaning"
@rm -f $(COBJDIR)/* $(ASMOBJDIR)/* $(CLISTDIR)/* $(ASMLISTDIR)/* $(BINDIR)/*
emulate: all
@echo "Starting emulation"
@qemu-system-arm -kernel $(BINDIR)/$(OUTPUT_ELF) -m 256 -M raspi2 -serial stdio