forked from Mustafa-khann/TinyOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·49 lines (37 loc) · 1.24 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
ARMGNU ?= arm-none-eabi
CC = $(ARMGNU)-gcc
AS = $(ARMGNU)-as
LD = $(ARMGNU)-ld
OBJCOPY = $(ARMGNU)-objcopy
OBJDUMP = $(ARMGNU)-objdump
# Remove -O2 for now to disable optimizations
CFLAGS = -mcpu=cortex-a7 -fpic -ffreestanding -Wall -Wextra -I./include -g -O0
ASMFLAGS = -mcpu=cortex-a7
LDFLAGS = -T linker.ld -Map=$(BUILD_DIR)/kernel.map
SRC_DIR = .
BUILD_DIR = build
# Explicitly list all C source files
C_SOURCES = $(wildcard kernel/*.c drivers/*.c)
ASM_SOURCES = $(wildcard boot/*.S)
OBJ_FILES = $(patsubst %.c,$(BUILD_DIR)/%.o,$(C_SOURCES))
OBJ_FILES += $(patsubst %.S,$(BUILD_DIR)/%.o,$(ASM_SOURCES))
all: $(BUILD_DIR)/kernel.img
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o: %.S
@mkdir -p $(@D)
$(AS) $(ASMFLAGS) $< -o $@
$(BUILD_DIR)/kernel.elf: $(OBJ_FILES)
$(LD) $(LDFLAGS) -o $@ $^
$(OBJDUMP) -D $@ > $(BUILD_DIR)/kernel_disassembly.txt
$(OBJDUMP) -s -j .rodata $@ > $(BUILD_DIR)/rodata_dump.txt
$(BUILD_DIR)/kernel.img: $(BUILD_DIR)/kernel.elf
$(OBJCOPY) $< -O binary $@
clean:
rm -rf $(BUILD_DIR)
run: $(BUILD_DIR)/kernel.img
qemu-system-arm -M raspi2b -kernel $< -serial stdio
debug: $(BUILD_DIR)/kernel.elf
qemu-system-arm -M raspi2b -kernel $< -serial stdio -s -S
.PHONY: all clean run debug