-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
92 lines (70 loc) · 2.25 KB
/
Makefile
File metadata and controls
92 lines (70 loc) · 2.25 KB
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
ARCH:=i686-elf
CFLAGS:=-g -ffreestanding -Wall -Wextra -lgcc -nostdlib -m32 -Wl,--build-id=none -Iinclude
ASFLAGS:=
DEBUGFLAGS:= -D DEBUG
TESTFLAGS:= -D TEST
CC:=$(ARCH)-gcc
ASM:=nasm
LIBS:=-nostdlib -lk -lgcc
QEMUFLAGS:= -smp cpus=4 -D qemu_log.txt -monitor stdio -d int -no-reboot
KERNDIR:=kernel
BOOTDIR:=boot
INCLUDEDIR:=include
KERNELDIR:=boot/iso/boot
KERNELNAME:=nowos
INCLUDE_DIR:= include
TEST_DIR := kernel/tests
SYS_DIR:= sysroot/usr
ifdef DEBUG
CFLAGS := $(CFLAGS) $(DEBUGFLAGS)
endif
ifdef TEST
CLFAGS := $(CFLAGS) $(TESTFLAGS)
endif
SYS_ROOT:="$(PWD)/sysroot"
KERN_OBJS:= $(patsubst %.c,%.o,$(wildcard kernel/*.c))
BOOT_OBJS:= boot/boot.o
ARCH_OBJS:= $(patsubst %.s,%.o,$(wildcard arch/*.s))
ARCH_OBJS+= $(patsubst %.c,%.o,$(wildcard arch/*.c))
KLIB_OBJS:= $(patsubst %.c,%.o,$(wildcard klib/*.c))
TEST_OBJS:= $(patsubst %.c,%.o,$(wildcard kernel/tests/*.c))
OBJS:= $(BOOT_OBJS) $(KLIB_OBJS) $(KERN_OBJS) $(ARCH_OBJS) $(TEST_OBJS)
.PHONY: all clean run iso bochs-run qemu-run
.SUFFIXES: .o .c .s
all: clean nowos.kernel
install-headers:
mkdir -p $(SYS_DIR)/$(INCLUDE_DIR)
cp -R --preserve=timestamps include/. $(SYS_DIR)/$(INCLUDE_DIR)
nowos.kernel: install-headers $(OBJS) boot/linker.ld
echo $(SYS_ROOT)
$(CC) -T boot/linker.ld -o $(KERNELDIR)/$(KERNELNAME).kernel $(CFLAGS) $(OBJS)
sh scripts/check-multiboot.sh $(KERNELDIR) $(KERNELNAME)
qemu-run: all
qemu-system-i386 -kernel $(KERNELDIR)/$(KERNELNAME).kernel -serial file:serial.log $(QEMUFLAGS)
bochs-run: iso1
bochs -q
iso1: all
genisoimage -R \
-b boot/grub/stage2_eltorito \
-no-emul-boot \
-boot-load-size 4 \
-A nowos \
-input-charset utf8 \
-quiet \
-boot-info-table \
-o nowos.iso \
boot/iso
iso2: all
grub-mkrescue -o nowos.iso boot/iso
clean:
rm -f bx_enh_dbg.ini
rm -f nowos.iso
rm -f qemu_log.txt
rm -f $(KERNELDIR)/$(KERNELNAME).kernel
rm -f $(OBJS)
rm -rf $(SYS_DIR)
rm -rf sysroot
.c.o:
$(CC) -c $< -o $@ -std=gnu11 $(CFLAGS)
.s.o:
$(ASM) -felf32 $< -o $@ $(ASMFLAGS)