-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
87 lines (70 loc) · 2.35 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
# Makefile for JamesM's kernel tutorials.
SUB_PROJECTS="libc"
INCLUDES="src/include/ libc/include/"
CSOURCES=$(shell find ./src/ -name *.c -not -name "\.*")
COBJECTS=$(patsubst %.c, %.o, $(CSOURCES))
SSOURCES=$(shell find ./src/ -name *.s -not -name "\.*")
SOBJECTS=$(patsubst %.s, %.o, $(SSOURCES))
ALLFILES=$(shell find . \( ! -regex '.*/\..*' \) -type f)
CC=gcc
LD=ld
CFLAGS=-Wall -g -nostdlib -nostdinc -fno-builtin -m32 -Isrc/include/ -Ilibc/include/ -pipe
LDFLAGS=-melf_i386 -Tlink.ld
ASFLAGS=-felf
all: clean subprojects $(COBJECTS) $(SOBJECTS) link update
update:
@echo Updating floppy image
@-mkdir mnt/
@sudo mount -o loop floppy.img mnt/
@sudo cp kernel mnt/
@sleep 1
@sudo umount mnt/
@sleep 1
@-rm -rf mnt/
clean:
@echo Removing object files
@for file in $(COBJECTS) $(SOBJECTS) kernel kernel.sym initrd.img emilos.tgz; do if [ -f $$file ]; then rm $$file; fi; done
@for proj in $(SUB_PROJECTS); do if [ -d "$$proj/" ]; then $(MAKE) -C $$proj/ clean; fi; done
link:
@echo " LD *.o"
@$(LD) $(LDFLAGS) -o kernel $(SOBJECTS) $(COBJECTS) libc/libc.a
@objcopy --only-keep-debug kernel kernel.sym
@objcopy --strip-debug kernel
.s.o:
@echo " NASM $<"
@nasm $(ASFLAGS) $<
.c.o:
@echo " CC $<"
@$(CC) $(CFLAGS) -o $@ -c $<
subprojects:
@echo Building sub projects...
@for proj in $(SUB_PROJECTS); do if [ -d "$$proj/" ]; then $(MAKE) -C $$proj/; fi; done
run: clean all
@echo Starting QEMU
@qemu -fda floppy.img&
debug: clean all
@echo Starting QEMU
@qemu -s -S -fda floppy.img&
@echo Starting GDB
@echo To connect type: target remote localhost:1234
@gdb --symbols=kernel.sym
srcdist:
@tar czf emilos.tgz $(ALLFILES)
todos:
-@for file in $(ALLFILES); do grep -H TODO $$file; done; true
fixmes:
-@for file in $(ALLFILES); do grep -H FIXME $$file; done; true
help:
@echo "Available make targets:"
@echo
@echo "all - build kernel"
@echo "run - run the kernel in qemu"
@echo "debug - like run, but with debugging enabled and gdb started"
@echo "clean - remove all object files"
@echo "update - update floppy image"
@echo "subprojects - build all related subprojects"
@echo "srcdist - build emilos.tgz (source tarball)"
@echo "todos - list all TODO comments in the sources"
@echo "fixmes - list all FIXME comments in the sources"
@echo "help - print this list"
.PHONY: all kernel run debug update subprojects clean srcdist todos fixmes help