-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
71 lines (51 loc) · 2.26 KB
/
Makefile
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
CC=i686-elf-gcc
QEMU=qemu-system-i386
AS=i686-elf-as
CXX=i686-elf-g++
CFLAGS=-std=c99 -ffreestanding -Og -ggdb3 -Wall -Wextra -nostdlib
SFLAGS=-g
TEST_CFLAGS=$(CFLAGS) -DENABLE_TESTS
ARCH=i386
BUILD_DIR=build/$(ARCH)
CRTBEGIN_OBJ:=$(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o)
CRTEND_OBJ:=$(shell $(CC) $(CFLAGS) -print-file-name=crtend.o)
# Standart traget: build multiboot enabled kernel binary
#
all: i386
i386: $(BUILD_DIR)/kernel.bin
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/%.o: %.c $(BUILD_DIR)
$(CC) -c $< -o $@ $(CFLAGS)
$(BUILD_DIR)/%.o: kernel/%.c $(BUILD_DIR)
$(CC) -c $< -o $@ $(CFLAGS)
$(BUILD_DIR)/%.o: arch/i386/%.s $(BUILD_DIR)
$(AS) $< $(SFLAGS) -o $@
$(BUILD_DIR)/kernel.bin: $(BUILD_DIR)/kernel.o $(BUILD_DIR)/bootstrap.o $(BUILD_DIR)/vga.o $(BUILD_DIR)/gdt.o arch/i386/kernel.ld $(BUILD_DIR)/crti.o $(BUILD_DIR)/crtn.o
$(CC) -T arch/i386/kernel.ld -o $(BUILD_DIR)/kernel.bin $(CFLAGS) $(BUILD_DIR)/crti.o $(CRTBEGIN) $(BUILD_DIR)/bootstrap.o $(BUILD_DIR)/vga.o $(BUILD_DIR)/gdt.o $(BUILD_DIR)/kernel.o $(CRTEND) $(BUILD_DIR)/crtn.o -lgcc
# Tests
#
$(BUILD_DIR)/tests:
mkdir -p $(BUILD_DIR)/tests
$(BUILD_DIR)/tests/%.o: tests/%.c $(BUILD_DIR)/tests
$(CC) -c $< -o $@ $(TEST_CFLAGS)
$(BUILD_DIR)/tests/kernel.o: kernel/kernel.c $(BUILD_DIR)/tests
$(CC) -c $< -o $@ $(TEST_CFLAGS)
# every test gets an own kernel image to ensure consistent state
$(BUILD_DIR)/tests/kernel_%.bin: $(BUILD_DIR)/tests/%.o $(BUILD_DIR)/tests/kernel.o $(BUILD_DIR)/bootstrap.o $(BUILD_DIR)/vga.o $(BUILD_DIR)/gdt.o arch/i386/kernel.ld $(BUILD_DIR)/crti.o $(BUILD_DIR)/crtn.o
$(CC) -T arch/i386/kernel.ld -o $@ $(TEST_CFLAGS) $(BUILD_DIR)/crti.o $(CRTBEGIN) $(BUILD_DIR)/bootstrap.o $(BUILD_DIR)/vga.o $(BUILD_DIR)/gdt.o $(BUILD_DIR)/tests/kernel.o $< $(CRTEND) $(BUILD_DIR)/crtn.o -lgcc
# Convinience
#
qemu: $(BUILD_DIR)/kernel.bin
$(QEMU) -kernel $(BUILD_DIR)/kernel.bin
test_vga: $(BUILD_DIR)/tests/kernel_vga_test.bin
$(QEMU) -s -S -kernel $(BUILD_DIR)/tests/kernel_vga_test.bin
test_gdt: $(BUILD_DIR)/tests/kernel_gdt_test.bin
$(QEMU) -s -S -kernel $(BUILD_DIR)/tests/kernel_gdt_test.bin
tests: test_vga test_gdt
clean:
rm $(BUILD_DIR)/*.o
rm $(BUILD_DIR)/*.bin
rm $(BUILD_DIR)/tests/*.bin
rm $(BUILD_DIR)/tests/*.o
.PHONY: qemu tests test_vga test_gdt clean i386