-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
48 lines (33 loc) · 1.7 KB
/
Makefile
File metadata and controls
48 lines (33 loc) · 1.7 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
NAME=kfs.iso
SRC_DIR=srcs/
BUILD_DIR=build/
INCLUDE_DIR=includes
BOOTL_DIR=boot/
BOOTL_FILES=boot.s gdt_flush.s idt_exceptions.s load_idt.s irqs.s paging.s
BOOTL_SRCS=$(addprefix $(SRC_DIR), $(addprefix $(BOOTL_DIR), $(BOOTL_FILES)))
KERNEL_DIR=kernel/
KERNEL_FILES=kernel.c string.c term.c init_term.c gdt.c printk.c idt.c exception_handler.c puts.c irq_handler.c install_irq.c system_timer.c keyboard.c shell.c readline.c print_stack.c get_mem_max_addr.c init_physical_memory.c physical_memory_manager.c init_virtual_memory.c virtual_memory_manager.c vmalloc.c kmalloc.c print_physical_memory.c demos.c
KERNEL_SRCS=$(addprefix $(SRC_DIR), $(addprefix $(KERNEL_DIR), $(KERNEL_FILES)))
SRCS=$(KERNEL_FILES) $(BOOTL_FILES)
OBJS=$(addprefix $(BUILD_DIR), $(KERNEL_FILES:.c=.o) $(BOOTL_FILES:.s=.o))
.PHONY: all run clean fclean
all: $(NAME)
$(NAME): isodir/boot/kfs.bin
@grub-file --is-x86-multiboot ./isodir/boot/kfs.bin && echo "multiboot check \033[32;1mOK\033[0m" || echo "multiboot check \033[31;1mFAILED\033[0m"
grub-mkrescue -o kfs.iso isodir
isodir/boot/kfs.bin: $(OBJS)
i686-elf-gcc -T linker.ld -o ./isodir/boot/kfs.bin -ffreestanding -fno-builtin -fno-exceptions -fno-stack-protector -nodefaultlibs -nostdlib $(OBJS) -lgcc
$(BUILD_DIR)%.o: $(SRC_DIR)/$(BOOTL_DIR)%.s
mkdir build 2>/dev/null || true
nasm -felf32 $< -o $@
$(BUILD_DIR)%.o: $(SRC_DIR)/$(KERNEL_DIR)%.c
mkdir build 2>/dev/null || true
i686-elf-gcc -c $< -o $@ -std=gnu99 -ffreestanding -fno-builtin -fno-exceptions -fno-stack-protector -nostdlib -nodefaultlibs -Wall -Wextra -I $(INCLUDE_DIR)
run: all
qemu-system-i386 -boot d -cdrom kfs.iso
clean:
rm -rf $(BUILD_DIR)
fclean: clean
rm -rf ./isodir/boot/kfs.bin
rm -rf ./kfs.iso
re: fclean all