-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
138 lines (114 loc) · 3.48 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
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
136
137
138
# assembler
ASM = nasm
# compiler
CC = gcc
# linker
LD = ld
# grub iso creator
GRUB = grub-mkrescue
# sources
SRC = src
ASM_SRC = $(SRC)/asm
# objects
OBJ = obj
ASM_OBJ = $(OBJ)/asm
CONFIG = ./config
OUT = out
INC = ./include
INCLUDE=-I$(INC)
MKDIR= mkdir -p
CP = cp -f
DEFINES=
# assembler flags
ASM_FLAGS = -f elf32
# compiler flags
CC_FLAGS = $(INCLUDE) $(DEFINES) -m32 -std=gnu99 -ffreestanding -Wall -Wextra
# linker flags, for linker add linker.ld file too
LD_FLAGS = -m elf_i386 -T $(CONFIG)/linker.ld -nostdlib
# target file to create in linking
TARGET=$(OUT)/Terminal.bin
# iso file target to create
TARGET_ISO=$(OUT)/Terminal.iso
ISO_DIR=$(OUT)/isodir
OBJECTS=$(ASM_OBJ)/entry.o $(ASM_OBJ)/load_gdt.o\
$(ASM_OBJ)/load_idt.o $(ASM_OBJ)/exception.o $(ASM_OBJ)/irq.o\
$(OBJ)/io_ports.o $(OBJ)/vga.o\
$(OBJ)/string.o $(OBJ)/console.o\
$(OBJ)/gdt.o $(OBJ)/idt.o $(OBJ)/isr.o $(OBJ)/8259_pic.o\
$(OBJ)/keyboard.o\
$(OBJ)/kernel.o
all: $(OBJECTS)
@printf "[ linking... ]\n"
$(LD) $(LD_FLAGS) -o $(TARGET) $(OBJECTS)
grub-file --is-x86-multiboot $(TARGET)
@printf "\n"
@printf "[ building ISO... ]\n"
$(MKDIR) $(ISO_DIR)/boot/grub
$(CP) $(TARGET) $(ISO_DIR)/boot/
$(CP) $(CONFIG)/grub.cfg $(ISO_DIR)/boot/grub/
$(GRUB) -o $(TARGET_ISO) $(ISO_DIR)
rm -f $(TARGET)
$(ASM_OBJ)/entry.o : $(ASM_SRC)/entry.asm
@printf "[ $(ASM_SRC)/entry.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/entry.asm -o $(ASM_OBJ)/entry.o
@printf "\n"
$(ASM_OBJ)/load_gdt.o : $(ASM_SRC)/load_gdt.asm
@printf "[ $(ASM_SRC)/load_gdt.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/load_gdt.asm -o $(ASM_OBJ)/load_gdt.o
@printf "\n"
$(ASM_OBJ)/load_idt.o : $(ASM_SRC)/load_idt.asm
@printf "[ $(ASM_SRC)/load_idt.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/load_idt.asm -o $(ASM_OBJ)/load_idt.o
@printf "\n"
$(ASM_OBJ)/exception.o : $(ASM_SRC)/exception.asm
@printf "[ $(ASM_SRC)/exception.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/exception.asm -o $(ASM_OBJ)/exception.o
@printf "\n"
$(ASM_OBJ)/irq.o : $(ASM_SRC)/irq.asm
@printf "[ $(ASM_SRC)/irq.asm ]\n"
$(ASM) $(ASM_FLAGS) $(ASM_SRC)/irq.asm -o $(ASM_OBJ)/irq.o
@printf "\n"
$(OBJ)/io_ports.o : $(SRC)/io_ports.c
@printf "[ $(SRC)/io_ports.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/io_ports.c -o $(OBJ)/io_ports.o
@printf "\n"
$(OBJ)/vga.o : $(SRC)/vga.c
@printf "[ $(SRC)/vga.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/vga.c -o $(OBJ)/vga.o
@printf "\n"
$(OBJ)/string.o : $(SRC)/string.c
@printf "[ $(SRC)/string.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/string.c -o $(OBJ)/string.o
@printf "\n"
$(OBJ)/console.o : $(SRC)/console.c
@printf "[ $(SRC)/console.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/console.c -o $(OBJ)/console.o
@printf "\n"
$(OBJ)/gdt.o : $(SRC)/gdt.c
@printf "[ $(SRC)/gdt.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/gdt.c -o $(OBJ)/gdt.o
@printf "\n"
$(OBJ)/idt.o : $(SRC)/idt.c
@printf "[ $(SRC)/idt.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/idt.c -o $(OBJ)/idt.o
@printf "\n"
$(OBJ)/isr.o : $(SRC)/isr.c
@printf "[ $(SRC)/isr.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/isr.c -o $(OBJ)/isr.o
@printf "\n"
$(OBJ)/8259_pic.o : $(SRC)/8259_pic.c
@printf "[ $(SRC)/8259_pic.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/8259_pic.c -o $(OBJ)/8259_pic.o
@printf "\n"
$(OBJ)/keyboard.o : $(SRC)/keyboard.c
@printf "[ $(SRC)/keyboard.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/keyboard.c -o $(OBJ)/keyboard.o
@printf "\n"
$(OBJ)/kernel.o : $(SRC)/kernel.c
@printf "[ $(SRC)/kernel.c ]\n"
$(CC) $(CC_FLAGS) -c $(SRC)/kernel.c -o $(OBJ)/kernel.o
@printf "\n"
clean:
rm -f $(OBJ)/*.o
rm -f $(ASM_OBJ)/*.o
rm -rf $(OUT)/*