-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
70 lines (54 loc) · 2.12 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
ARCH=i386
ARCHDIR=arch/$(ARCH)
CC=i686-elf-gcc -g -O3
CPP=i686-elf-g++ -g -O3
LD=i686-elf-ld -g -O3
AS=nasm
INCLUDES=-Iinclude -Iinclude/libc
CFLSHARED=-ffreestanding -Wall -Wextra -fstack-protector -fno-builtin -fno-leading-underscore
CFLAGS=-std=gnu11 $(CFLSHARED) $(INCLUDES)
CPPFLAGS=-std=gnu++11 -fno-exceptions -fno-rtti -fno-use-cxa-atexit $(CFLSHARED) $(INCLUDES)
LDFLAGS=-melf_i386 -nostdlib -L.
ASFLAGS=-felf32
CRT_BEGIN=$(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o)
CRT_END=$(shell $(CC) $(CFLAGS) -print-file-name=crtend.o)
objects_arch_c =$(patsubst $(ARCHDIR)/%.c,$(ARCHDIR)/%.o,$(wildcard $(ARCHDIR)/*.c))
objects_arch_cpp=$(patsubst $(ARCHDIR)/%.cpp,$(ARCHDIR)/%.o,$(wildcard $(ARCHDIR)/*.cpp))
objects_arch_asm=$(patsubst $(ARCHDIR)/%.asm,$(ARCHDIR)/%.o,$(wildcard $(ARCHDIR)/*.asm))
objects_arch=$(objects_arch_c) $(objects_arch_cpp) $(objects_arch_asm)
objects_kernel_c =$(patsubst kernel/%.c,kernel/%.o,$(wildcard kernel/*.c))
objects_kernel_cpp=$(patsubst kernel/%.cpp,kernel/%.o,$(wildcard kernel/*.cpp))
objects_kernel=$(objects_kernel_c) $(objects_kernel_cpp)
objects=crti.o $(objects_arch) $(objects_kernel) crtn.o
kernel.bin: $(objects)
$(LD) -Tlinker.ld -o $@ $(LDFLAGS) $(CRT_BEGIN) $(objects) $(CRT_END) -lgcc
%.o: %.asm
nasm -felf32 -o $@ $<
$(ARCHDIR)/%.o: $(ARCHDIR)/%.c
$(CC) -c -o $@ $< $(CFLAGS)
$(ARCHDIR)/%.o: $(ARCHDIR)/%.cpp
$(CPP) -c -o $@ $< $(CPPFLAGS)
$(ARCHDIR)/%.o: $(ARCHDIR)/%.asm
$(AS) -o $@ $< $(ASFLAGS)
kernel/%.o: kernel/%.c
$(CC) -c -o $@ $< $(CFLAGS)
kernel/%.o: kernel/%.cpp
$(CPP) -c -o $@ $< $(CPPFLAGS)
clean:
rm -rf $(objects) iso/
run: kernel.bin
qemu-system-i386 -serial stdio -kernel kernel.bin -m 256M # -no-reboot-d int,cpu_reset
runvbox: benos.iso
virtualbox --startvm BenOS
benos.iso: kernel.bin grub.cfg
mkdir -p iso/boot/grub
cp kernel.bin iso/boot/kernel.bin
cp grub.cfg iso/boot/grub/grub.cfg
grub-mkrescue -o $@ iso/
install: kernel.bin
sudo cp $< /boot/benos.bin
device ?= "100101"
burn: benos.iso
if [ "$(device)" = "100101" ]; then echo device is empty; exit 1; fi
sudo dd bs=4M if=$< of=$(device) conv=fdatasync
.PHONY: clean run runvbox install burn