-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (82 loc) · 2.66 KB
/
Makefile
File metadata and controls
122 lines (82 loc) · 2.66 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
EXEC = SaharaOS
INITRD = fs_gen/initrd.img.o
CC = ${TARGET}-gcc
LD = ${TARGET}-ld
CFLAGS = -fno-PIC -mno-red-zone -g -ffreestanding -pedantic -Wall -Wextra
LFLAGS = -nostdlib -ffreestanding -lgcc
BOOTLOADER_DIR = ./bootloader
BOOTLOADER = $(BOOTLOADER_DIR)/bootloader.bin
ASM_DIR = ./kernel/asm
KERNEL_ENTRY = $(BOOTLOADER_DIR)/kernel_entry/kernel_entry.o
KERNEL_ENTRY_FILE = $(BOOTLOADER_DIR)/kernel_entry/kernel_entry.asm
KERNEL = ./kernel.bin
KDEBUG = ./symbol-debug-kernel
KERNEL_DIR = ./kernel
KERNEL_SRC_DIR = $(KERNEL_DIR)/src
KERNEL_INC_DIR = $(KERNEL_DIR)/includes
KERNEL_OBJ_DIR = $(KERNEL_DIR)/obj
DRIVERS_DIR = ./drivers
DRIVERS_OBJ_DIR = $(DRIVERS_DIR)/obj
ASM_SRC = $(wildcard $(ASM_DIR)/*.asm)
BOOTLOADER_SRC = $(wildcard $(BOOTLOADER_DIR)/assembly/*.asm)
KERNEL_OBJ = $(wildcard $(KERNEL_OBJ)/*.o)
KERNEL_SRC = $(wildcard $(KERNEL_SRC_DIR)/*.c)
KERNEL_INC = $(wildcard $(KERNEL_INC_DIR)/*.h)
DRIVERS_SRC = $(wildcard $(DRIVERS_DIR)/*/src/*.c)
DRIVERS_INC = $(wildcard $(DRIVERS_DIR)/*/includes/*.h)
OBJ_K = $(KERNEL_SRC:.c=.o)
OBJ_D = $(DRIVERS_SRC:.c=.o)
OBJ_ASM_K = $(ASM_SRC:.asm=.o)
####### Qemu options #######
QEMU_CFG = -soundhw pcspk -no-reboot -no-shutdown -drive id=disk,file=disk.img,if=none
# gdb remote tcp:1234
QEMU_CFG_DEBUG = -d int -s -S $(QEMU_CFG) -D qemu_logs.txt
############################
all : run
$(EXEC) : assemble
debug : $(EXEC) $(KDEBUG)
qemu-system-i386 $(QEMU_CFG_DEBUG) $<
run : $(EXEC)
qemu-system-i386 $(QEMU_CFG) $<
disassemble : $(KERNEL)
ndisasm -b 32 $? | cat
assemble : $(BOOTLOADER) $(KERNEL)
cat $^ > $(EXEC)
qemu-img resize $(EXEC) +20K
OBJDUMP : $(KERNEL_ENTRY) $(OBJ_D) $(OBJ_K) $(OBJ_ASM_K) $(INITRD)
$(CC) -T dscript.ld -o $@ $^ $(LFLAGS)
#Kernel build and drivers
$(KERNEL) : $(KERNEL_ENTRY) $(OBJ_D) $(OBJ_K) $(OBJ_ASM_K) $(INITRD)
$(CC) -T rscript.ld -o $@ $^ $(LFLAGS)
$(KDEBUG) : $(KERNEL_ENTRY) $(OBJ_D) $(OBJ_K) $(OBJ_ASM_K) $(INITRD)
$(CC) -T dscript.ld -o $@ $^ $(LFLAGS)
%.o : %.c $(KERNEL_INC) $(DRIVERS_INC)
$(CC) $(CFLAGS) -c -g $< -o $@
%.o : %.asm
nasm -f elf32 -F dwarf -g $< -o $@
#Bootloader build
KERNEL_ENTRY : $(KERNEL_ENTRY)
BOOTLOADER : $(BOOTLOADER)
$(KERNEL_ENTRY):
nasm -f elf32 -F dwarf -g $(KERNEL_ENTRY_FILE) -o $@
$(BOOTLOADER) :
nasm $(BOOTLOADER_DIR)/assembly/boot.asm -i $(BOOTLOADER_DIR)/assembly -f bin -o $@
#Init ram disk creation
$(INITRD):
./fs_gen/compile.sh
#Clean up
remove_obj :
find . -type f -name "*.o" -delete
remove_kernel :
rm $(KERNEL_BIN)
remove_bootloader :
rm $(BOOTLOADER)
remove_exec :
rm $(EXEC)
clean :
rm -f $(KERNEL)
rm -f $(KDEBUG)
rm -f $(BOOTLOADER)
rm -f $(EXEC)
rm -f OBJDUMP
find . -type f -name "*.o" -delete