89 lines
2.6 KiB
Makefile
89 lines
2.6 KiB
Makefile
.phony: run clean all debug user_programs_clean user_programs fatcopy_clean
|
|
|
|
C_SRC=$(wildcard src/*/*/*.c src/*/*.c src/*.c)
|
|
ASM_SRC=$(wildcard src/*/*/*.asm src/*/*.asm)
|
|
O_FILES=$(C_SRC:src/%.c=build/%.o)
|
|
O_FILES+=$(ASM_SRC:src/%.asm=build/%.asm.o)
|
|
|
|
#kernel.asm.o must be first, then the rest
|
|
FILES=build/kernel.asm.o $(O_FILES)
|
|
|
|
INCLUDES = -Isrc -Isrc/libk
|
|
FLAGS = -D__KERNEL__ -g -ffreestanding -falign-jumps -falign-functions -falign-labels -falign-loops -fstrength-reduce -fomit-frame-pointer -finline-functions -Wno-unused-function -fno-builtin -Werror -Wno-unused-label -Wno-cpp -Wno-unused-parameter -nostdlib -nostartfiles -nodefaultlibs -Wall -O0 -Iinc -std=gnu99
|
|
|
|
CC=i686-elf-gcc
|
|
LD=i686-elf-ld
|
|
NASM=nasm
|
|
QEMU=qemu-system-i386
|
|
GDB=gdb
|
|
|
|
all: clean fatcopy_clean run
|
|
|
|
bin/os.bin: bin/boot.bin bin/kernel.bin hello.txt user_programs external/fatcopy/fatcopy
|
|
mkdir -p bin
|
|
rm -f bin/os.bin
|
|
dd if=bin/boot.bin >> bin/os.bin
|
|
dd if=bin/kernel.bin >> bin/os.bin
|
|
dd if=/dev/zero bs=1048576 count=16 >> bin/os.bin
|
|
./external/fatcopy/fatcopy bin/os.bin hello.txt hello.txt
|
|
./external/fatcopy/fatcopy bin/os.bin programs/blank/blank.elf blank.elf
|
|
./external/fatcopy/fatcopy bin/os.bin programs/shell/shell.elf shell.elf
|
|
./external/fatcopy/fatcopy bin/os.bin programs/stdlib/testlib.elf testlib.elf
|
|
|
|
external/fatcopy/configure:
|
|
cd external/fatcopy && autoreconf -iv
|
|
|
|
external/fatcopy/Makefile:
|
|
cd external/fatcopy && ./configure
|
|
|
|
external/fatcopy/fatcopy:
|
|
cd external/fatcopy && $(MAKE)
|
|
|
|
fatcopy_clean:
|
|
cd external/fatcopy && $(MAKE) clean
|
|
|
|
bin/kernel.bin: $(FILES)
|
|
mkdir -p bin
|
|
$(LD) -g -relocatable $(FILES) -o build/kernelfull.o
|
|
$(CC) $(FLAGS) -T src/linker.ld -o bin/kernel.bin -ffreestanding -O0 -nostdlib build/kernelfull.o
|
|
|
|
bin/boot.bin: boot/boot.asm
|
|
mkdir -p bin
|
|
$(NASM) -f bin $< -o $@
|
|
|
|
build/%.o: src/%.c
|
|
mkdir -p $(dir $@)
|
|
$(CC) $(INCLUDES) $(FLAGS) -I$(dir $<) -c $< -o $@
|
|
|
|
build/fs/fat/fat16.o: src/fs/fat/fat16.c
|
|
mkdir -p build/fs/fat
|
|
$(CC) $(INCLUDES) $(FLAGS) -Isrc/fs -Isrc/fs/fat -c $< -o $@
|
|
|
|
build/video/bga/bga.o: src/video/bga/bga.c
|
|
mkdir -p build/video/bga
|
|
$(CC) $(INCLUDES) $(FLAGS) -Isrc/video -Isrc/video/bga -c $< -o $@
|
|
|
|
clean: user_programs_clean
|
|
rm -rf bin
|
|
rm -rf build
|
|
|
|
build/%.asm.o: src/%.asm
|
|
mkdir -p $(dir $@)
|
|
$(NASM) -f elf -g $< -o $@
|
|
|
|
run: bin/os.bin
|
|
$(QEMU) -hda bin/os.bin
|
|
|
|
debug: bin/os.bin debug.gdb
|
|
$(GDB) --command=debug.gdb
|
|
|
|
user_programs:
|
|
cd programs/stdlib && $(MAKE) all
|
|
cd programs/blank && $(MAKE) all
|
|
cd programs/shell && $(MAKE) all
|
|
|
|
user_programs_clean:
|
|
cd programs/stdlib && $(MAKE) clean
|
|
cd programs/blank && $(MAKE) clean
|
|
cd programs/shell && $(MAKE) clean
|