-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
76 lines (58 loc) · 2.25 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
include tools/functions.mk
GCC_FLAGS := -I. -fno-omit-frame-pointer \
-Iinclude -fno-builtin -O1 -static -Wall -ggdb \
-m32 -gstabs -nostdinc -fno-stack-protector
ifndef TEST
SRC = main kernel arch lib
KERNEL_SRC = $(shell find $(SRC) -type f -regex '.*\.[S|c]') # list of source files
KERNEL_OBJS = $(filter %.o,$(KERNEL_SRC:.S=.o) $(KERNEL_SRC:.c=.o)) # list of object files
else
SRC = kernel arch lib
KERNEL_SRC = $(shell find $(SRC) -type f -regex '.*\.[S|c]') $(TEST) # list of source files
KERNEL_OBJS = $(filter %.o,$(KERNEL_SRC:.S=.o) $(KERNEL_SRC:.c=.o)) # list of object files
endif
OBJ = bin/obj
all: GCC_FLAGS += -D NDEBUG
all: corn.img
debug: corn.img
gdb: corn.img
qemu-system-i386 -S -s -hda ./bin/$<
.PHONY: test
test:
make -C ./test/lib test
corn.img: boot_block kernel_objs
@ld -m elf_i386 -nostdlib -T tools/kernel.ld -o bin/corn_kernel \
$(patsubst %, bin/obj/%, $(KERNEL_OBJS))
@dd if=/dev/zero of=bin/$@ count=10000
@dd if=bin/boot_block of=bin/$@ conv=notrunc
@dd if=bin/corn_kernel of=bin/$@ seek=1 conv=notrunc
#--------------- compile all kernel .o files -------------------
kernel_objs: $(KERNEL_OBJS) # target
@echo $(KERNEL_OBJS)
%.o: %.S
@mkdir -p $(shell dirname $(OBJ)/$@)
@gcc $(GCC_FLAGS) -o $(OBJ)/$@ -c $<
%.o: %.c
@mkdir -p $(shell dirname $(OBJ)/$@)
@gcc $(GCC_FLAGS) -o $(OBJ)/$@ -c $<
#--------------------------- boot loader ------------------------------
boot_block: bootasm.o bootmain.o mbr_sign
@ld -m elf_i386 -nostdlib -N -T tools/boot.ld -e start \
bin/obj/boot/bootasm.o bin/obj/boot/bootmain.o -o bin/obj/bootblock.o
@objcopy -S -O binary bin/obj/bootblock.o bin/obj/bootblock.out
@bin/tools/mbr_sign bin/obj/bootblock.out bin/$@
bootasm.o: boot
@if [ ! -d "./bin/obj/boot" ]; then mkdir -p "bin/obj/boot"; fi
@gcc $(GCC_FLAGS) -Os \
-c boot/bootasm.S -o bin/obj/boot/bootasm.o
bootmain.o: boot
@if [ ! -d "./bin/obj/boot" ]; then mkdir -p "bin/obj/boot"; fi
@gcc -Iboot/ $(GCC_FLAGS) -Os \
-c boot/bootmain.c -o bin/obj/boot/bootmain.o
mbr_sign: tools/mbr_sign.c
@if [ ! -d "./bin/tools" ]; then mkdir -p "bin/tools"; fi
@gcc -O2 $< -o ./bin/tools/$@
#----------------------------------------------------------------------
clean:
rm -rf ./bin
make -C ./test/lib clean