-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathMakefile
87 lines (68 loc) · 2.39 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
export CC := gcc
export LD := ld
export AR := ar
export OBJCOPY := objcopy
export OBJDUMP := objdump
export ROOTDIR := $(shell pwd)
export OBJDIR := obj
SUBDIRS := fs kernel lib user
LDFLAGS := -m elf_i386
KHANDER := -I $(ROOTDIR)/include/
UHANDER := -I $(ROOTDIR)/include/
export INC := $(KHANDER)
CFLAGE := -O1 -fno-builtin -fno-stack-protector -fno-omit-frame-pointer -nostdlib
CFLAGE += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32 -fno-tree-ch
export UCFLAGS := $(UHANDER) $(CFLAGE) -DUSER
export KCFLAGS := $(KHANDER) $(CFLAGE) -DKERNEL -DCONFIG_PAE -DCONFIG_DEBUG
export KLDFLAGS := $(LDFLAGS) -T kernel.ld
export ULDFLAGS := -T user.ld $(LDFLAGS)
export V := @
export GCC_LIB := $(shell $(CC) $(CFLAGE) -print-libgcc-file-name)
IMAGES := kenrel.iso
BOCHS := bochs
QEMU := qemu-system-i386
QEMUOPTS := -m 60M -smp 4
GRUB := grub-mkrescue
IOSDIR := iso
#
OBJFILE := kernel/init kernel/mm kernel/char kernel/syscall\
kernel/trap kernel/block fs/minix1fs fs/rootfs fs/ramfs fs/ttyfs fs/pipefs fs kernel
OBJFILE := $(patsubst %,%/*.S,$(OBJFILE)) $(patsubst %,%/*.c,$(OBJFILE))
OBJFILE := $(wildcard $(OBJFILE))
OBJFILE := $(patsubst %,$(ROOTDIR)/$(OBJDIR)/%,$(OBJFILE))
OBJFILE := $(patsubst %.S,%.c,$(OBJFILE))
OBJFILE := $(patsubst %.c,%.o,$(OBJFILE))
USEROBJ := $(ROOTDIR)/user/*.c
USEROBJ := $(wildcard $(USEROBJ))
USEROBJ := $(patsubst %.c,%,$(USEROBJ))
USEROBJ := $(notdir $(USEROBJ))
USEROBJ := $(patsubst %,$(OBJDIR)/user/%.bin,$(USEROBJ))
FILE := $(ROOTDIR)/fs/*.sh
FILE := $(wildcard $(FILE))
FILE := $(notdir $(FILE))
FILE := $(patsubst %.sh,$(OBJDIR)/fs/%.bin,$(FILE))
OBJFILE += obj/lib/string.o obj/lib/printfmt.o
# Eliminate default suffix rules
.SUFFIXES:
# Delete target files if there is an error (or make is interrupted)
.DELETE_ON_ERROR:
all:$(SUBDIRS) $(ROOTDIR)/kern $(IMAGES)
$(ROOTDIR)/kern:$(OBJFILE) $(USEROBJ)
@echo $(LD) -o $@ $(KLDFLAGS) $(OBJFILE) $(USEROBJ) $(FILE) $(GCC_LIB)
$(V)$(LD) -o $@ $(KLDFLAGS) $(OBJFILE) $(USEROBJ) $(FILE) $(GCC_LIB)
$(V)cp kern $(IOSDIR)/boot/
$(V)$(GRUB) -o $(IMAGES) $(IOSDIR)
$(V)$(OBJDUMP) -S kern > asm.S
$(SUBDIRS):E
$(V)make -s -C $@
E:
$(IMAGES):$(ROOTDIR)/kern $(IOSDIR)/boot/grub/grub.cfg
$(V)cp kern $(IOSDIR)/boot/
$(V)$(GRUB) -o $@ $(IOSDIR)
boch:all
$(V)$(BOCHS) -q -f bochsrc
qemu:all
$(V)$(QEMU) $(QEMUOPTS) $(IMAGES)
.PHONY:clean
clean:
$(V)rm -rf $(OBJDIR) kern