forked from Segfah/KFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
79 lines (58 loc) · 1.36 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
src_asm = boot.S \
gdt.S \
multiboot.S \
src_c = print_stack.c
vpath %.c $(src_dir)
vpath %.S $(src_dir)
src_dir = src
build_dir = build
iso_path := iso
boot_path := ${iso_path}/boot
grub_path := ${boot_path}/grub
iso = kfs.iso
bin = ${build_dir}/kernel
cfg = grub.cfg
LD := ld
ldfile := linker.ld
LDFLAGS := -m elf_i386 -T ${ldfile}
AS := nasm
ASFLAGS := -f elf32
CC := gcc
CCFLAGS := -m32
MKRESCUE := grub-mkrescue
objs_asm := $(addprefix ${build_dir}/, ${src_asm:.S=.o})
objs_c := $(addprefix ${build_dir}/, ${src_c:.c=.o})
objs := ${objs_asm} ${objs_c}
.PHONY: all
all: build link iso
.PHONY: build
build: ${objs_asm} ${objs_c}
@printf "\033[0;36m0bject file created\033[m\n"
${build_dir}/%.o: ${src_dir}/%.S
@mkdir -p ${build_dir}
${AS} ${ASFLAGS} $< -o $@
${build_dir}/%.o: ${src_dir}/%.c
@mkdir -p ${build_dir}
${CC} ${CCFLAGS} -c $< -o $@
.PHONY: link
link: build ${ldfile}
${LD} ${LDFLAGS} ${objs_asm} ${objs_c} -o ${bin}
@printf "\033[0;34mLinking completed\033[m\n"
.PHONY: iso
iso: link ${bin}
@mkdir -p ${grub_path}
@cp ${bin} ${boot_path}
@cp ${cfg} ${grub_path}
@${MKRESCUE} -o ${iso} ${iso_path}
@printf "\033[0;32mIso file created\033[m\n"
.PHONY: clean
clean:
@/bin/rm -rf ${build_dir}
.PHONY: fclean
fclean: clean
@/bin/rm -rf ${iso} ${iso_path}
.PHONY: re
re: fclean all
.PHONY: run
run: iso ${iso}
qemu-system-i386 -s -cdrom ${iso}