-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
100 lines (68 loc) · 1.95 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
# A makefile to build the project
# Author: Alex Orlenko
### Setting up the environment ###
INCLUDES := $(shell kernel/incdirs.pl)
WARNINGS = -Wall -Wextra
CC = i686-elf-gcc
CFLAGS := -fno-builtin -std=c99 -g $(INCLUDES) $(WARNINGS)
AS = nasm
ASFLAGS = -felf
LD = i686-elf-ld
LDFLAGS = -Tkernel/link.ld
OBJCOPY = i686-elf-objcopy
STRIP = i686-elf-strip
CP = cp
CFILES := $(shell find kernel -name '*.c')
ASMFILES := $(shell find kernel -name '*.s')
COBJECTS := $(patsubst %.c,%.o,$(CFILES))
ASMOBJECTS := $(patsubst %.s,%.o,$(ASMFILES))
OBJECTS := kernel/x86/boot.o $(patsubst kernel/x86/boot.o,,$(COBJECTS) $(ASMOBJECTS))
DEPENDENCIES := $(patsubst %.c,%.d,$(CFILES))
##
INITRD_FILES := $(shell find initrd/files)
### .PHONY targets ###
.PHONY : all run debug clean clean-all clean-initrd clean-kernel rebuild
all: alpha.iso
run: all
qemu -cdrom alpha.iso
debug: all
qemu -cdrom alpha.iso -s -S &
gdb
clean: clean-initrd clean-kernel
clean-all: clean
-$(RM) isofiles/kernel isofiles/initrd
-$(RM) alpha.iso
clean-initrd:
-$(RM) initrd/initrd initrd/initrd.asm
clean-kernel:
-$(RM) $(OBJECTS) $(DEPENDENCIES) kernel/kernel kernel/kernel.sym
rebuild: clean all
### ISO image ###
alpha.iso: isofiles/initrd isofiles/kernel
@xorrisofs -R -J -r -quiet -iso-level 3 -hide boot.catalog \
-b boot/grub/stage2_eltorito -no-emul-boot \
-boot-load-size 4 -boot-info-table \
-A "Aquarius Alpha by Alex Orlenko" \
-V "Aquaruis Alpha by Alex Orlenko" \
-o alpha.iso isofiles
@echo OK.
isofiles/initrd: initrd/initrd
@$(CP) $< $@
isofiles/kernel: kernel/kernel
@$(CP) $< $@
### Kernel ###
-include $(DEPENDENCIES)
kernel/kernel: $(OBJECTS)
@$(LD) $(LDFLAGS) $(OBJECTS) -o $@
@$(OBJCOPY) --only-keep-debug $@ [email protected]
@$(STRIP) $@
@echo 'The kernel has been built.'
.c.o:
@$(CC) $(CFLAGS) -MD -MP -o $@ -c $<
.s.o:
@$(AS) $(ASFLAGS) $<
### Initial ramdisk ###
initrd/initrd: $(INITRD_FILES)
@cd initrd && ./mkrd
@echo 'Initrd is done.'
### The end. ###