-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
executable file
·182 lines (121 loc) · 4.86 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
BUILD_PATH:= build
ENTRY_POINT = 0xc0001500
KERNEL_PATH:=./kernel
DEVICE_PATH:=./device
LIB_KERNEL_PATH= ./lib/kernel
LIB = -I lib/ -I lib/kernel/ -I lib/user/ -I kernel/ -I device/ -I thread/ -I userprog/ -I fs/ -I shell/
CFLAGS:= -c -m32 $(LIB) -fno-stack-protector -fno-builtin -Wall -W -Wstrict-prototypes -Wmissing-prototypes
# -W -Wmissing-prototypes -Wsystem-headers
LDFLAGS = -Ttext $(ENTRY_POINT) -e main -m elf_i386
#-Map $(BUILD_PATH)/kernel.map
TARGET_IMG_PATH:= hd.img
OBJS = $(BUILD_PATH)/main.o $(BUILD_PATH)/init.o $(BUILD_PATH)/interrupt.o \
$(BUILD_PATH)/timer.o $(BUILD_PATH)/kernel.o $(BUILD_PATH)/print.o $(BUILD_PATH)/memory.o \
$(BUILD_PATH)/debug.o $(BUILD_PATH)/bitmap.o $(BUILD_PATH)/string.o $(BUILD_PATH)/thread.o \
$(BUILD_PATH)/list.o $(BUILD_PATH)/switch.o $(BUILD_PATH)/sync.o $(BUILD_PATH)/console.o \
$(BUILD_PATH)/ioqueue.o $(BUILD_PATH)/keyboard.o $(BUILD_PATH)/tss.o $(BUILD_PATH)/process.o \
$(BUILD_PATH)/syscall-init.o $(BUILD_PATH)/syscall.o $(BUILD_PATH)/stdio.o $(BUILD_PATH)/stdio-kernel.o $(BUILD_PATH)/ide.o \
$(BUILD_PATH)/fs.o $(BUILD_PATH)/file.o $(BUILD_PATH)/dir.o $(BUILD_PATH)/inode.o $(BUILD_PATH)/fork.o $(BUILD_PATH)/shell.o \
$(BUILD_PATH)/assert.o $(BUILD_PATH)/buildin_cmd.o
AS = nasm
CC = gcc
LD = ld
.PHONY : mkdir run write clean build mk_dir restart clear_disk fdisk fix
run: write fix
bochs -f bochsrc
clear_disk:
dd if=/dev/zero of=hd80M.img bs=10M count=8 conv=notrunc
fdisk:
fdisk hd80M.img < fdisk.txt
reformat_disk:
make clear_disk
make fdisk
clean:
$(MAKE) -C boot clean
#$(MAKE) -C kernel clean
rm -rf build/*
rm -f bochs.out
dd if=/dev/zero of=hd.img bs=4M count=10 conv=notrunc
restart:
$(MAKE) -C ./ clean
$(MAKE) -C ./ run
write: build
$(MAKE) -C boot write
dd if=$(BUILD_PATH)/kernel.bin of=$(TARGET_IMG_PATH) bs=512 count=300 seek=9 conv=notrunc
build: mk_dir $(BUILD_PATH)/kernel.bin
mk_dir:
# - mkdir build
if [ ! -d $(BUILD_PATH) ];then mkdir $(BUILD_PATH);fi
fix:
- rm *.lock
install_dependency:
- sudo apt install qemu nasm bochs qemu -y
bootstrap: install_dependency build
release: build
### compile
$(BUILD_PATH)/print.o: $(LIB_KERNEL_PATH)/print.S
$(AS) -f elf32 $< -o $@
$(BUILD_PATH)/kernel.o: $(KERNEL_PATH)/kernel.S
$(AS) -f elf32 $< -o $@
$(BUILD_PATH)/switch.o: thread/switch.S
$(AS) -f elf32 $< -o $@
$(BUILD_PATH)/main.o: $(KERNEL_PATH)/main.c $(LIB_KERNEL_PATH)/print.h lib/stdint.h $(KERNEL_PATH)/init.h
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/init.o: $(KERNEL_PATH)/init.c $(KERNEL_PATH)/init.h $(LIB_KERNEL_PATH)/print.h lib/stdint.h $(KERNEL_PATH)/interrupt.h $(DEVICE_PATH)/timer.h
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/interrupt.o: $(KERNEL_PATH)/interrupt.c $(KERNEL_PATH)/interrupt.h lib/stdint.h $(KERNEL_PATH)/global.h $(LIB_KERNEL_PATH)/io.h $(LIB_KERNEL_PATH)/print.h
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/timer.o: $(DEVICE_PATH)/timer.c $(DEVICE_PATH)/timer.h lib/stdint.h $(LIB_KERNEL_PATH)/io.h $(LIB_KERNEL_PATH)/print.h
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/memory.o: $(KERNEL_PATH)/memory.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/string.o: lib/string.c lib/string.h lib/stdint.h $(KERNEL_PATH)/global.h lib/stdint.h $(KERNEL_PATH)/debug.h
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/bitmap.o: $(LIB_KERNEL_PATH)/bitmap.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/debug.o: $(KERNEL_PATH)/debug.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/sync.o: thread/sync.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/thread.o: thread/thread.c thread/switch.S
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/list.o: $(LIB_KERNEL_PATH)/list.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/console.o: $(DEVICE_PATH)/console.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/ioqueue.o: $(DEVICE_PATH)/ioqueue.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/keyboard.o: $(DEVICE_PATH)/keyboard.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/tss.o: userprog/tss.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/process.o: userprog/process.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/fork.o: userprog/fork.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/syscall-init.o: userprog/syscall-init.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/syscall.o: lib/user/syscall.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/stdio.o: lib/stdio.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/stdio-kernel.o: lib/kernel/stdio-kernel.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/ide.o: device/ide.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/inode.o: fs/inode.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/file.o: fs/file.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/dir.o: fs/dir.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/fs.o: fs/fs.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/shell.o: shell/shell.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/assert.o: lib/user/assert.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/buildin_cmd.o: shell/buildin_cmd.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_PATH)/kernel.bin: $(OBJS)
$(LD) $(LDFLAGS) $^ -o $@