summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile111
1 files changed, 38 insertions, 73 deletions
diff --git a/Makefile b/Makefile
index b633722..00f34f4 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,7 @@
# #
#####################
-#TODO: use implicit rules !!
-
+#improve implicit rules
#lets use the size of a 1.44 floppy for a start for our boot img
IMAGE_SIZE=1474560
@@ -14,99 +13,65 @@ IMAGE_SIZE=1474560
FONT_DATA_START=25600
#data starts at 0x8000
-DATA_START=32768
-
-#final image
-all: FoolOS.img
-
-#assembling of final image
-FoolOS.img: Fool.img FoolData.img fill.bin
- cat $^ | head -c $(IMAGE_SIZE) > $@
-
-Fool.img: mbr.bin kernel.bin fill.bin
- cat $^ | head -c $(FONT_DATA_START) > $@
+#DATA_START=32768
-FoolData.img: binfont.bin
- cat $^ > $@
+SOURCES=$(wildcard ./kernel/*.c)
+SOURCES+=$(wildcard ./lib/*/*.c)
+ASMSOURCES=$(wildcard ./asm/*.asm)
-binfont.bin: data/binfont.src
- python tools/binarize.py $< $@
-#some data just to fill up to the target image_size
-fill.bin: boot/fill.asm
- nasm -f bin $^ -o $@
+OBJECTS=$(patsubst %.c, %.o, $(SOURCES))
+ASMOBJECTS=$(patsubst %.asm, %.o, $(ASMSOURCES))
-#this is the MASTER BOOT RECORD, where our bootloader lives
-mbr.bin: boot/mbr.asm
- nasm -f bin $^ -o $@
+MBR=./boot/mbr.bin
+KERNEL_ENTRY=./boot/kernel_entry.o
+FILLUP=./data/fill.bin
-kernel_entry.o: boot/kernel_entry.asm
- nasm -f elf $^ -o $@
+CFLAGS=-ffreestanding -std=gnu99 -m32 -fno-asynchronous-unwind-tables -O0
-read_eip.o: asm/read_eip.asm
- nasm -f elf $^ -o $@
+#default target
+#final image
+all: FoolOS.img
-copy_page_physical.o: asm/copy_page_physical.asm
+# some implicit rule patterns for aseembling (elf and binary)
+%.o: %.asm
nasm -f elf $^ -o $@
-kernel.o: kernel/kernel.c kernel/console.h
- gcc -ffreestanding -std=gnu99 -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
-
-x86.o: kernel/x86.c
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
-
-floppy.o: kernel/floppy.c
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
-
-vmem.o: kernel/vmem.c
- gcc -ffreestanding -std=gnu99 -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
-
-mem.o: kernel/mem.c
- gcc -ffreestanding --std=gnu99 -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
+%.bin: %.asm
+ nasm -f bin $^ -o $@
-e1000.o: kernel/e1000.c
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
-
-pci.o: kernel/pci.c
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
+# explicit rule to create fool-font data binary
+binfont.bin: data/binfont.src
+ python tools/binarize.py $< $@
-console.o: kernel/console.c kernel/console.h
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
+#assembling of final image
+FoolOS.img: Fool.img FoolData.img $(FILLUP)
+ cat $^ | head -c $(IMAGE_SIZE) > $@
-interrupts.o: kernel/interrupts.c kernel/interrupts.h
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
+Fool.img: $(MBR) kernel.bin $(FILLUP)
+ cat $^ | head -c $(FONT_DATA_START) > $@
-keyboard.o: kernel/keyboard.c
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
+FoolData.img: binfont.bin
+ cat $^ > $@
-vesa.o: kernel/vesa.c
- gcc -ffreestanding -std=gnu99 -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
-
-timer.o: kernel/timer.c
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
-
-shell.o: kernel/shell.c
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
+# kernel_entry.o needs to be FIRST!!
+kernel.bin: $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS)
+ ld -o $@ -Ttext 0x1000 --oformat binary -melf_i386 $^ -O0
-log.o: lib/logger/log.c
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
+##### cleanup #####
-printf.o: lib/printf/printf.c
- gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
+clean:
+ -rm *.bin *.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR)
-kernel.bin: kernel_entry.o kernel.o console.o interrupts.o keyboard.o timer.o floppy.o x86.o shell.o mem.o vmem.o pci.o e1000.o vesa.o log.o printf.o read_eip.o copy_page_physical.o
- ld -o $@ -Ttext 0x1000 --oformat binary -melf_i386 $^ -O0
+###### virtual machine stuff ######
# dump from vbox
-dump: FoolOS.img
- vboxmanage debugvm FoolOs dumpguestcore --filename dump.elf
- xxd dump.elf > dump.xxd
+#dump: FoolOS.img
+# vboxmanage debugvm FoolOs dumpguestcore --filename dump.elf
+# xxd dump.elf > dump.xxd
# run in our local bochs
run: FoolOS.img
~/opt/bochs-2.6.6/bochs -q
-clean:
- -rm *.bin *.o *.img dump.elf dump.xxd bochs.log
-
.PHONY: all clean