-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
68 lines (52 loc) · 1.71 KB
/
Makefile
File metadata and controls
68 lines (52 loc) · 1.71 KB
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
ARMGNU ?= aarch64-linux-gnu
COPS = -Wall -nostdlib -Iinclude -mgeneral-regs-only -ffreestanding -nostartfiles -g -O0
ASMOPS = -Iinclude -D__ASSEMBLY__ -g -O0
BUILD_DIR = build
SRC_DIR = src
offsets-file := include/asm-offsets.h
define sed-y
"/^->/{s:->#\(.*\):/* \1 */:; \
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
s:->::; p;}"
endef
define cmd_offsets
(set -e; \
echo "#ifndef __ASM_OFFSETS_H__"; \
echo "#define __ASM_OFFSETS_H__"; \
echo "/*"; \
echo " * DO NOT MODIFY."; \
echo " *"; \
echo " * This file was generated by Kbuild"; \
echo " *"; \
echo " */"; \
echo ""; \
sed -ne $(sed-y) $<; \
echo ""; \
echo "#endif" ) > $@
endef
$(BUILD_DIR)/asm-offsets.s : src/asm-offsets.c
mkdir -p $(@D)
gcc -Iinclude -S $< -o $@
$(offsets-file) : $(BUILD_DIR)/asm-offsets.s
@$(cmd_offsets)
all : rpios.bin
clean :
rm -rf $(BUILD_DIR) *.img
run :
qemu-system-aarch64 -machine raspi3 -nographic -kernel rpios.img
debug :
qemu-system-aarch64 -machine raspi3 -nographic -kernel rpios.img -S -s
$(BUILD_DIR)/%_c.o: $(SRC_DIR)/%.c
mkdir -p $(@D)
$(ARMGNU)-gcc $(COPS) -MMD -c $< -o $@
$(BUILD_DIR)/%_s.o: $(SRC_DIR)/%.S
$(ARMGNU)-gcc $(ASMOPS) -MMD -c $< -o $@
C_FILES = $(filter-out $(SRC_DIR)/asm-offsets.c, $(wildcard $(SRC_DIR)/*.c))
ASM_FILES = $(wildcard $(SRC_DIR)/*.S)
OBJ_FILES = $(C_FILES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%_c.o)
OBJ_FILES += $(ASM_FILES:$(SRC_DIR)/%.S=$(BUILD_DIR)/%_s.o)
DEP_FILES = $(OBJ_FILES:%.o=%.d)
-include $(DEP_FILES)
rpios.bin: $(SRC_DIR)/linker.ld $(OBJ_FILES)
$(ARMGNU)-ld -T $(SRC_DIR)/linker.ld -o $(BUILD_DIR)/rpios.elf $(OBJ_FILES)
$(ARMGNU)-objcopy $(BUILD_DIR)/rpios.elf -O binary rpios.img