-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
75 lines (54 loc) · 2.28 KB
/
Makefile
File metadata and controls
75 lines (54 loc) · 2.28 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
# Compiler and flags
CC = i686-elf-gcc
CCFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -lgcc -Wall -Wextra -Werror -c -I$$cc_prefix/lib/gcc/$$cc_target/9.4.0/include -Isrc/lib -Isrc -c
AS = nasm
ASFLAGS = -f elf
LDFLAGS = -T src/link.ld -nostdlib --verbose -L$$cc_prefix/lib/gcc/$$cc_target/9.4.0 -lgcc
# Source files and objects
SOURCES = src/drivers/gdt.c src/loader.c src/kmain.c src/memory.c \
src/drivers/framebuffer.c src/drivers/serial.c src/drivers/sound.c src/drivers/irq.c src/drivers/irq_asm.c src/drivers/clocks.c src/drivers/sys_calls.c \
src/keyboard/keyboard.c \
src/user/cmd.c \
src/utils/io.c src/utils/log.c \
src/lib/naOS/string.c src/lib/naOS/math.c src/lib/printf.c \
src/filesystem/fileops.c \
OBJECTS = $(SOURCES:.c=.o)
# Additional objects
PROGRAM_OBJECTS = src/modules/initfpu.out src/modules/interrupt.out
PROGRAM_BIN = src/modules/initfpu.bin src/modules/interrupt.bin
# Targets
TARGET = kernel.elf
ISO_TARGET = os.iso
.PHONY: test_c_compilation test_asm_compilation test_program_bin_generation test_iso_creation all clean setup run
all: $(ISO_TARGET)
$(ISO_TARGET): $(TARGET)
cp $(TARGET) iso/boot/$(TARGET)
grub-mkrescue -o $(ISO_TARGET) iso
$(TARGET): $(OBJECTS) $(PROGRAM_BIN)
$(CC) --verbose $(LDFLAGS) $(OBJECTS) $(PROGRAM_OBJECTS) $$cc_prefix/lib/gcc/$$cc_target/9.4.0/libgcc.a -o $(TARGET)
%.o: %.c
$(CC) --verbose $(CCFLAGS) $< -o $@
%.o: %.asm
$(AS) $(ASFLAGS) $< -o $@
%.bin: %.out
ld -m elf_i386 -Ttext 0x0 --oformat binary $< -o $@
cp $@ iso/boot/
%.out: %.s
nasm -f elf32 $< -o $@
run: run-q
run-q: $(ISO_TARGET)
qemu-system-i386 -drive format=raw,media=disk,file=$(ISO_TARGET) -m 4M -serial file:qemu_com1.out -soundhw pcspk -rtc base=localtime -d int,cpu_reset,pcall,guest_errors,unimp -no-reboot
run-b: $(ISO_TARGET)
bochs -f bochsrc.txt -q
clean:
rm -rf $(OBJECTS) $(TARGET) $(PROGRAM_OBJECTS) $(PROGRAM_BIN) $(ISO_TARGET) iso/boot/*.bin iso/boot/*.elf iso/boot/*.bin
setup:
bash ./configure
test_c_compilation: $(OBJECTS)
@echo "C compilation successful"
test_asm_compilation: $(PROGRAM_OBJECTS)
@echo "Assembly compilation successful"
test_program_bin_generation: $(PROGRAM_BIN)
@echo "Program binary generation successful"
test_iso_creation: $(ISO_TARGET)
@echo "ISO creation successful"