The setup will be as follows:
OSdir
|
| Makefile
| -- src
| | Makefile
| | -- srcfiles.c
|
| -- build
| | -- kernel
| | -- other object files
Here is the makefile that should go into the top of your OS directory. It will go into the source directory and build sources, link all the object files together, and provide an option to clean up all those pesky object files when you're done with them.
I generalized the C compiler and linker, as well as flags and the directory that your floppy image (that's what I use at least)
Code: Select all
[email protected]
LD=i386-elf-ld
LDFLAGS=-Tsrc/link.ld
ImageDir=/Volumes/No\ NAME/boot
all: source link
source:
@cd src && make
clean:
@rm src/*.o build/kernel build/*.o
link:
@$(LD) $(LDFLAGS) -o build/kernel build/*.o
@cp build/kernel $(ImageDir)
~
Then put this makefile into your src directory:
This makefile will compile all the source files and place their build objects into the build directory. Again, the C compiler and flags have been genericized, so you can put your own in where needed.
Code: Select all
CC=i386-elf-gcc-3.4.6
ASM=nasm
LEVEL1SOURCE=loader.o
LEVEL2SOURCE=common.o monitor.o
KERNEL=kernel.o
LDFLAGS=-T../src/link.ld
CFLAGS=-nostdlib -nostdinc -fno-builtin -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wstrict-prototypes -nostartfiles
ASFLAGS=-felf
all: $(LEVEL1SOURCE) $(LEVEL2SOURCE) $(KERNEL)
.s.o:
@$(ASM) $(ASFLAGS) $< -o ../build/$@
.c.o:
@$(CC) $(CFLAGS) $< -c -o ../build/$@