matos/Makefile

73 lines
2.2 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-11-16 14:47:21 +01:00
#LDFLAGS += -m32 -nostdlib -mkernel -fno-stack-protector
2018-11-09 10:50:20 +01:00
LDFLAGS += -m32 -nostdlib -static -fno-common -fno-use-cxa-atexit -fno-exceptions -fno-non-call-exceptions -fno-weak -fno-rtti -fno-stack-protector
CFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-pie -fno-stack-protector -fno-tree-vectorize
CXXFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-rtti -fno-pie
DEBUG_FLAGS += -g -Og -DDEBUG -fno-omit-frame-pointer -fno-inline
2018-07-20 15:41:58 +02:00
2021-10-05 22:01:13 +02:00
QEMU_OPT += -hda disk.img
2020-04-27 23:45:38 +02:00
ARCH?=x86
SUBDIRS := core drivers tests arch/$(ARCH)
2018-07-20 15:41:58 +02:00
INCDIRS += $(foreach dir, $(SUBDIRS), -I$(dir))
CPPFLAGS += $(INCDIRS)
2018-07-20 15:41:58 +02:00
2021-10-31 00:04:01 +02:00
asmsrc=
2018-07-20 15:41:58 +02:00
asmobj=$(asmsrc:%.asm=%.o)
2021-10-31 00:04:01 +02:00
gasmsrc=$(wildcard arch/$(ARCH)/*.S arch/$(ARCH)/boot/*.S)
gasmobj=$(gasmsrc:%.S=%.o)
2018-07-20 15:41:58 +02:00
csrc=$(shell find $(SUBDIRS) -type f -name "*.c")# $(wildcard *.c)
2021-10-31 00:04:01 +02:00
cobj=$(csrc:%.c=%.o)
deps=$(csrc:%.c=%.d) $(gasmsrc:%.S=%.d)
2018-07-20 15:41:58 +02:00
2021-10-31 00:04:01 +02:00
kernel kernel.sym &: $(asmobj) $(gasmobj) $(cobj) linker.ld
$(CC) -m32 -ffreestanding -nostdlib $(cobj) $(gasmobj) $(asmobj) -o kernel -T linker.ld -lgcc
objcopy --only-keep-debug kernel kernel.sym
objcopy --strip-debug kernel
2018-07-20 17:10:58 +02:00
2018-07-20 16:55:41 +02:00
fd.iso: kernel
mkdir -p isodir/boot/grub
cp $< isodir/boot/
@printf "menuentry \"myos\" {\n\tmultiboot /boot/kernel\n}" > isodir/boot/grub/grub.cfg
2018-07-20 16:55:41 +02:00
grub-mkrescue -o $@ isodir
2021-11-04 20:14:48 +01:00
disk.img: disk.sfdisk
qemu-img create -f raw $@ 32M
sfdisk $@ < disk.sfdisk
2018-07-20 15:41:58 +02:00
%.o:%.asm
$(AS) $(ASFLAGS) -o $@ $<
%.o: %.S
2021-10-31 00:04:01 +02:00
$(CC) $(CFLAGS) $(CPPFLAGS) -c "$<" -o "$@"
2021-01-26 17:58:33 +01:00
test: CFLAGS += -DRUN_TEST
2021-10-05 22:07:17 +02:00
test: clean kernel disk.img
2021-10-05 22:01:13 +02:00
qemu-system-x86_64 -kernel kernel -serial stdio -m 32M $(QEMU_OPT)
2018-11-08 22:09:12 +01:00
2021-10-05 22:07:17 +02:00
run:kernel disk.img
2021-10-05 22:01:13 +02:00
qemu-system-x86_64 -kernel $< $(QEMU_OPT)
2018-07-20 15:41:58 +02:00
2021-01-26 17:58:33 +01:00
debug: CFLAGS += $(DEBUG_FLAGS) -DRUN_TEST
2018-11-16 14:47:21 +01:00
debug: CXXFLAGS += $(DEBUG_FLAGS)
debug:kernel kernel.sym
#qemu-system-x86_64 -s -S -kernel kernel&
2020-08-18 13:55:52 +02:00
#qemu-system-i386 -s -S -kernel kernel&
#gdb -s kernel.sym -ex "target remote localhost:1234" -ex "dir core:driver:arch/$(ARCH))'"
2021-10-25 21:29:02 +02:00
gdb -q -x debug.gdb
2021-01-26 17:58:33 +01:00
debug_test: CFLAGS += $(DEBUG_FLAGS) -DRUN_TEST
debug_test: debug
2018-07-20 15:41:58 +02:00
clean:
2021-10-31 00:04:01 +02:00
$(RM) kernel $(asmobj) $(gasmobj) $(cobj) $(deps) fd.iso kernel.sym
2019-01-09 17:21:51 +01:00
$(RM) -r isodir
2018-07-20 15:41:58 +02:00
ifneq ($(MAKECMDGOALS),clean)
-include $(deps)
endif