matos/Makefile

52 lines
1.5 KiB
Makefile
Raw Normal View History

2018-07-20 15:41:58 +02:00
# Used to generated .d file that deal with header dependencies
CPPFLAGS = -MMD
AS=nasm
ASFLAGS += -f elf32
2018-07-20 17:10:58 +02:00
LDFLAGS += -g -m32 -nostdlib -static -fno-common -fno-use-cxa-atexit -fno-exceptions -fno-non-call-exceptions -fno-weak -fno-rtti -fno-stack-protector
CFLAGS += -g -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-pie -fno-stack-protector
CXXFLAGS += -g -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-rtti -fno-pie
2018-07-20 15:41:58 +02:00
SUBDIRS := core drivers
CPPFLAGS += $(foreach dir, $(SUBDIRS), -I$(dir))
asmsrc=$(wildcard *.asm)
asmobj=$(asmsrc:%.asm=%.o)
csrc=$(shell find $(SUBDIRS) -type f -name "*.c")# $(wildcard *.c)
cobj=$(csrc:%.c=%.o)
deps = $(csrc:%.c=%.d)
kernel:$(asmobj) $(cobj) linker.ld
2018-07-20 16:41:32 +02:00
$(CC) -m32 -ffreestanding -nostdlib $(cobj) $(asmobj) -o $@ -T linker.ld
2018-07-20 17:10:58 +02:00
objcopy --only-keep-debug $@ $@.sym
objcopy --strip-debug $@
2018-07-20 15:41:58 +02:00
2018-07-20 16:55:41 +02:00
fd.iso: kernel
mkdir -p isodir/boot/grub
cp $< isodir/boot/grub/
@echo -e "menuentry \"myos\" {\n\tmultiboot /boot/kernel\n}" > isodir/boot/grub/grub.cfg
grub-mkrescue -o $@ isodir
2018-07-20 15:41:58 +02:00
#https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#x86-Function-Attributes
core/exception_handler.o:core/exception_handler.c
$(CC) $(CPPFLAGS) $(CFLAGS) -mgeneral-regs-only -c $< -o $@
core/irq_handler.o:core/irq_handler.c
$(CC) $(CPPFLAGS) $(CFLAGS) -mgeneral-regs-only -c $< -o $@
%.o:%.asm
$(AS) $(ASFLAGS) -o $@ $<
test:kernel
2018-07-20 16:41:32 +02:00
qemu-system-x86_64 -kernel $<
2018-07-20 15:41:58 +02:00
clean:
2018-07-20 17:10:58 +02:00
$(RM) kernel $(asmobj) $(cobj) $(deps) fd.iso kernel.sym
2018-07-20 15:41:58 +02:00
ifneq ($(MAKECMDGOALS),clean)
-include $(deps)
endif