OS Makefile
Posted: Fri Nov 12, 2010 4:20 pm
New to OS development but thought I'd share my Makefile as it has already proven itself invaluable to the process:
Sure, it's not the prettiest thing in the world, and I've used some unconventional names, and there are a thousand other holes that The Internet will love to pick in it, but if it is useful to just one person other than me then sharing it (and all the flames I get whenever I share anything on the world wide web) was worthwhile.
Usage:
"make" on its own does the same as "make test"
"make test" will create and run a bootable floppy disk
"make bootfloppy.img" will create a bootable floppy disk
"make testcd" will create and run a bootable ISO
"make YourNameHere.iso" will create a bootable ISO
It's fairly obvious from a simple dissection what the source naming convention is, and it wouldn't be too much effort for somebody to abstract this naming convention into Makefile variables (eg SRCDIR=src/, etc.).
Oh yeah and it should also be fairly obvious that it's aimed at a Linux environment with qemu installed. Again, it shouldn't take -too- much effort to abstract the linux-specific stuff nor the qemu stuff. I just tend to err on the side of brevity rather than concision/portability.
Have fun hacking it, anyway.
License: Public Domain
Code: Select all
CC=gcc
OSNAME=YourNameHere
default: test
# bootfloppy.img is a testing image with JUST the bootloader
bootfloppy.img: obj/boot.bin
dd if=obj/boot.bin bs=512 of=bootfloppy.img
obj:
mkdir obj
iso:
mkdir iso
$(OSNAME).iso: iso/$(OSNAME).bin
mkisofs -o $(OSNAME).iso -b $(OSNAME).bin -boot-load-size 4 -no-emul-boot ./iso/
obj/kernel.bin: src/kernel.c obj
$(CC) -c src/kernel.c -o obj/kernel.o
ld obj/kernel.o -o obj/kernel.bin --oformat=binary -Ttext=0x100000
obj/boot.bin: src/boot.s obj
nasm src/boot.s -f bin -o obj/boot.bin
iso/$(OSNAME).bin: obj/boot.bin obj/kernel.bin iso
cat obj/boot.bin obj/kernel.bin > iso/$(OSNAME).bin
libc.o:
make -C src/libc libc.o
clean:
@echo -n removing obj directory...
@rm -rf obj
@echo done
bin-clean:
@make clean # remove everything clean removes
@echo -n removing boot images...
@rm -f $(OSNAME).iso # delete boot CD
@rm -f bootfloppy.img # delete bootable floppy
@echo done
test: bootfloppy.img
qemu -fda bootfloppy.img -boot order=a
testcd: $(OSNAME).iso
qemu -cdrom $(OSNAME).iso -boot order=d
Usage:
"make" on its own does the same as "make test"
"make test" will create and run a bootable floppy disk
"make bootfloppy.img" will create a bootable floppy disk
"make testcd" will create and run a bootable ISO
"make YourNameHere.iso" will create a bootable ISO
It's fairly obvious from a simple dissection what the source naming convention is, and it wouldn't be too much effort for somebody to abstract this naming convention into Makefile variables (eg SRCDIR=src/, etc.).
Oh yeah and it should also be fairly obvious that it's aimed at a Linux environment with qemu installed. Again, it shouldn't take -too- much effort to abstract the linux-specific stuff nor the qemu stuff. I just tend to err on the side of brevity rather than concision/portability.
Have fun hacking it, anyway.
License: Public Domain