-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (93 loc) · 3.38 KB
/
Copy pathMakefile
File metadata and controls
135 lines (93 loc) · 3.38 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# PiOuS Makefile
#
# TODO: Having a DEBUG flag that disabled compiler optimization
# and enabled a debugf function or something would be nice.
#----- User Variables (EDIT THESE) -----#
ARMGNU ?= arm-none-eabi
ARM_CC_OPS := -Wall -nostdlib -nostartfiles -ffreestanding \
-mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a \
-mtune=cortex-a7
ARM_S_OPS :=
X86_CC_OPS := -m32 -std=gnu99 -ffreestanding -O2 -Wextra -Wall -DARCH_X86
X86_S_OPS := --32
ARM_SRC_DIR := arch/arm
X86_SRC_DIR := arch/x86
DRIVERS_DIR := drivers
INCLUDE_DIR := include
PI_BUILD_DIR := build_pi
QEMU_BUILD_DIR := build_qemu
PI_SRC := $(ARM_SRC_DIR)/boot.s main.c $(ARM_SRC_DIR)/asm_utils.s \
framebuffer.c mbox.c utils.c $(DRIVERS_DIR)/led_pi2.c \
$(DRIVERS_DIR)/hdmi_pi2.c \
$(DRIVERS_DIR)/framebuffer.c \
$(DRIVERS_DIR)/uart_pi2.c \
libs/stdio.c \
# $(DRIVERS_DIR)/tty_stub.c
QEMU_SRC := $(X86_SRC_DIR)/boot.s main.c utils.c $(DRIVERS_DIR)/led_stub.c \
$(DRIVERS_DIR)/vga_x86.c $(DRIVERS_DIR)/ps2-x86.c
#----- Derived Variables (LEAVE ALONE) -----#
PI_INTER_1 := $(PI_SRC:.c=.o)
PI_INTER_2 := $(PI_INTER_1:.s=.o)
QEMU_INTER_1 := $(QEMU_SRC:.c=.o)
QEMU_INTER_2 := $(QEMU_INTER_1:.s=.o)
PI_BUILD_OBJS := $(addprefix $(PI_BUILD_DIR)/, $(PI_INTER_2))
QEMU_BUILD_OBJS := $(addprefix $(QEMU_BUILD_DIR)/, $(QEMU_INTER_2))
PI_TARGET := $(PI_BUILD_DIR)/kernel
QEMU_TARGET := $(QEMU_BUILD_DIR)/kernel
#----- Make Commands -----#
.PHONY: depend clean
all: pi qemu
pi: kernel7.img
qemu: kernel.elf
depend: .pi-depend .qemu-depend
clean:
rm -f *.o
rm -f *.bin
rm -f *.hex
rm -f *.elf
rm -f *.list
rm -f *.img
rm -f *.bc
rm -f *.clang.s
rm -f .*depend
rm -f .*.bak
rm -rf $(PI_BUILD_DIR)
rm -rf $(QEMU_BUILD_DIR)
#----- Products -----#
kernel7.img: $(PI_BUILD_OBJS) $(ARM_SRC_DIR)/linker
$(ARMGNU)-ld $(PI_BUILD_OBJS) -T $(ARM_SRC_DIR)/linker -o $(PI_TARGET).elf
$(ARMGNU)-objdump -D $(PI_TARGET).elf > $(PI_TARGET).list
$(ARMGNU)-objcopy $(PI_TARGET).elf -O ihex $(PI_TARGET).hex
$(ARMGNU)-objcopy $(PI_TARGET).elf -O binary kernel7.img
kernel.elf: $(QEMU_BUILD_OBJS) $(X86_SRC_DIR)/linker
ld -melf_i386 -T $(X86_SRC_DIR)/linker $(QEMU_BUILD_OBJS) -o kernel.elf
objdump -D kernel.elf > $(QEMU_TARGET).list
objcopy kernel.elf -O ihex $(QEMU_TARGET).hex
objcopy kernel.elf -O binary $(QEMU_TARGET).bin
#----- Track Dependencies -----#
.PHONY: .pi-depend .qemu-depend
.pi-depend: $(PI_SRC)
$(ARMGNU)-gcc $(ARM_CC_OPS) -I $(INCLUDE_DIR) -MM $^ > ./.pi-depend
sed -i.bak 's .*\.o $(PI_BUILD_DIR)/& ' .pi-depend
rm -f .pi-depend.bak
.qemu-depend: $(QEMU_SRC)
gcc $(X86_CC_OPS) -I $(INCLUDE_DIR) -MM $^ > ./.qemu-depend
sed -i.bak 's .*\.o $(QEMU_BUILD_DIR)/& ' .qemu-depend
rm -f .qemu-depend.bak
-include .pi-depend .qemu-depend
#----- Object Files -----#
$(PI_BUILD_DIR)/%.o: %.c | $(PI_BUILD_DIR)
$(ARMGNU)-gcc $(ARM_CC_OPS) -I $(INCLUDE_DIR) -c $< -o $@
$(PI_BUILD_DIR)/%.o: %.s | $(PI_BUILD_DIR)
$(ARMGNU)-as $(ARM_S_OPS) -I $(INCLUDE_DIR) $< -o $@
$(QEMU_BUILD_DIR)/%.o: %.c | $(QEMU_BUILD_DIR)
gcc $(X86_CC_OPS) -I $(INCLUDE_DIR) -c $< -o $@
$(QEMU_BUILD_DIR)/%.o: %.s | $(QEMU_BUILD_DIR)
as $(X86_S_OPS) -I $(INCLUDE_DIR) $< -o $@
#----- Build Directories -----$
$(PI_BUILD_DIR):
mkdir -p $(PI_BUILD_DIR)/$(ARM_SRC_DIR)
mkdir -p $(PI_BUILD_DIR)/$(DRIVERS_DIR)
$(QEMU_BUILD_DIR):
mkdir -p $(QEMU_BUILD_DIR)/$(X86_SRC_DIR)
mkdir -p $(QEMU_BUILD_DIR)/$(DRIVERS_DIR)