summaryrefslogtreecommitdiff
path: root/makefile
blob: 07e10f2eb1810663c6462472d73f5f2aace04aeb (plain) (blame)
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
disk: kernel boot skel init hello
	mkdir -p obj out
	/sbin/mkfs.fat -C -f 1 -F 16 -n "PORTLAND OS" -R 65 -s 1 -S 512 obj/shadow.img 8192
	echo -n -e '\xeb\x3c' > obj/jmp.bin
	dd if=obj/jmp.bin of=obj/shadow.img obs=2 conv=notrunc
	dd if=out/boot.bin of=obj/shadow.img obs=1 seek=62 conv=notrunc
	dd if=out/kernel.bin of=obj/shadow.img seek=1 conv=notrunc
	mv obj/shadow.img out/disk.img
	mcopy -i out/disk.img -s out/fs/* ::/

vdi-file: disk
	VBoxManage convertfromraw out/disk.img out/disk.vdi --uuid a61929ed-3bf2-45ff-b98a-44f87c616dba

debug: disk
	gdb -x qemu-debug.gdb

clean:
	rm -r obj out || true

skel:
	mkdir -p out/fs
	cp -r fs-skel/* out/fs/

kgccargs = -Wall -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=malloc -m32 -Og -ffreestanding -fno-asynchronous-unwind-tables
ugccargs = ${kgccargs} -Isrc/user/include
nasmargs = -f elf32
partlink = -r -m elf_i386

init: knob
	mkdir -p obj/init out/fs/bin

	gcc ${ugccargs} -c src/user/init/main.c -o obj/init/main.o

	ld -T src/user/elf.ld obj/init/main.o obj/knob.o -o obj/init.elf
	objcopy -S obj/init.elf out/fs/bin/init.elf

hello: knob
	mkdir -p obj/hello out/fs/bin

	gcc ${ugccargs} -c src/user/hello/hello.c -o obj/hello/hello.o

	ld -T src/user/elf.ld obj/hello/hello.o obj/knob.o -o obj/hello.elf
	objcopy -S obj/hello.elf out/fs/bin/hello.elf

knob:
	mkdir -p obj/knob

	gcc ${ugccargs} -c src/user/knob/env.c     -o obj/knob/env.o
	gcc ${ugccargs} -c src/user/knob/file.c    -o obj/knob/file.o
	gcc ${ugccargs} -c src/user/knob/format.c  -o obj/knob/format.o
	gcc ${ugccargs} -c src/user/knob/heap.c    -o obj/knob/heap.o
	gcc ${ugccargs} -c src/user/knob/quit.c    -o obj/knob/quit.o
	gcc ${ugccargs} -c src/user/knob/user.c    -o obj/knob/user.o
	gcc ${ugccargs} -c src/user/knob/task.c    -o obj/knob/task.o
	nasm ${nasmargs}   src/user/knob/entry.asm -o obj/knob/entry.o

	ld ${partlink} obj/knob/*.o -o obj/knob.o

kernel:
	mkdir -p obj/kernel out

	gcc ${kgccargs} -c src/kernel/drive.c  -o obj/kernel/drive.o
	gcc ${kgccargs} -c src/kernel/fat.c    -o obj/kernel/fat.o
	gcc ${kgccargs} -c src/kernel/ide.c    -o obj/kernel/ide.o
	gcc ${kgccargs} -c src/kernel/idt.c    -o obj/kernel/idt.o
	gcc ${kgccargs} -c src/kernel/log.c    -o obj/kernel/log.o
	gcc ${kgccargs} -c src/kernel/main.c   -o obj/kernel/main.o
	gcc ${kgccargs} -c src/kernel/main2.c  -o obj/kernel/main2.o
	gcc ${kgccargs} -c src/kernel/pmap.c   -o obj/kernel/pmap.o
	gcc ${kgccargs} -c src/kernel/paging.c -o obj/kernel/paging.o
	gcc ${kgccargs} -c src/kernel/panic.c  -o obj/kernel/panic.o
	gcc ${kgccargs} -c src/kernel/pci.c    -o obj/kernel/pci.o
	gcc ${kgccargs} -c src/kernel/elf.c    -o obj/kernel/elf.o
	gcc ${kgccargs} -c src/kernel/serial.c -o obj/kernel/serial.o
	gcc ${kgccargs} -c src/kernel/task.c   -o obj/kernel/task.o
	gcc ${kgccargs} -c src/kernel/util.c   -o obj/kernel/util.o
	gcc ${kgccargs} -c src/kernel/vga.c    -o obj/kernel/vga.o
	nasm ${nasmargs}   src/kernel/isrs.asm -o obj/kernel/isrs.o

	ld -T src/kernel/elf-link.ld obj/kernel/*.o -o obj/kernel.elf
	objcopy -O binary obj/kernel.elf out/kernel.bin

boot:
	mkdir -p out
	nasm src/boot.asm -o out/boot.bin