89 lines
2.6 KiB
Makefile
Raw Normal View History

.phony: run clean all debug user_programs_clean user_programs fatcopy_clean
2022-11-18 21:27:35 -05:00
2022-12-19 23:55:10 -05:00
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
2022-12-19 23:55:10 -05:00
CC=i686-elf-gcc
LD=i686-elf-ld
NASM=nasm
QEMU=qemu-system-i386
GDB=gdb
all: clean fatcopy_clean run
2022-11-18 21:27:35 -05:00
bin/os.bin: bin/boot.bin bin/kernel.bin hello.txt user_programs external/fatcopy/fatcopy
mkdir -p bin
2022-11-18 21:27:35 -05:00
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
2022-11-18 21:27:35 -05:00
bin/kernel.bin: $(FILES)
mkdir -p bin
2022-12-19 23:55:10 -05:00
$(LD) -g -relocatable $(FILES) -o build/kernelfull.o
$(CC) $(FLAGS) -T src/linker.ld -o bin/kernel.bin -ffreestanding -O0 -nostdlib build/kernelfull.o
2022-12-19 23:55:10 -05:00
bin/boot.bin: boot/boot.asm
mkdir -p bin
2022-12-19 23:55:10 -05:00
$(NASM) -f bin $< -o $@
2022-11-21 05:18:03 -05:00
2022-12-19 23:55:10 -05:00
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
2022-12-19 23:55:10 -05:00
$(CC) $(INCLUDES) $(FLAGS) -Isrc/fs -Isrc/fs/fat -c $< -o $@
2022-11-26 20:12:33 -05:00
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
2022-11-18 21:27:35 -05:00
2022-12-19 23:55:10 -05:00
build/%.asm.o: src/%.asm
mkdir -p $(dir $@)
$(NASM) -f elf -g $< -o $@
2022-11-18 21:27:35 -05:00
run: bin/os.bin
2022-12-19 23:55:10 -05:00
$(QEMU) -hda bin/os.bin
debug: bin/os.bin debug.gdb
2022-12-19 23:55:10 -05:00
$(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