caos-with-snake/Makefile

110 lines
2.7 KiB
Makefile
Raw Normal View History

2022-11-25 09:57:00 +00:00
GDB=gdb
2023-01-27 12:25:39 +00:00
OBJCOPY=objcopy
2022-11-25 09:57:00 +00:00
2022-11-25 09:18:38 +00:00
ifeq ($(shell uname -s),Darwin)
2022-09-21 16:53:45 +03:00
AS=x86_64-elf-as
LD=x86_64-elf-ld
2022-09-21 18:25:06 +03:00
CC=x86_64-elf-gcc
2022-11-25 09:57:00 +00:00
GDB=x86_64-elf-gdb
2023-01-27 12:25:39 +00:00
OBJCOPY=x86_64-elf-objcopy
2022-11-25 09:18:38 +00:00
endif
2022-09-21 16:53:45 +03:00
2022-11-25 12:57:49 +03:00
CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \
2022-11-30 14:48:13 +00:00
-Wall -ggdb -m32 -Werror -fno-omit-frame-pointer
2022-11-25 12:57:49 +03:00
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
2023-01-24 00:26:33 +03:00
ASMFLAGS = -m32 -ffreestanding -c -g
ifeq ($(LLVM),on)
#AS=llvm-as
LD=ld.lld
CC=clang
CFLAGS += -target elf-i386
ASMFLAGS = -target elf-i386 -ffreestanding -c -g
LDKERNELFLAGS = --script=script.ld
endif
2022-11-25 12:57:49 +03:00
2023-01-28 13:22:17 +04:00
OBJECTS = kernel.o console.o drivers/vga.o drivers/uart.o drivers/keyboard.o \
cpu/idt.o cpu/gdt.o cpu/swtch.o cpu/vectors.o lib/mem.o proc.o lib/string.o \
2023-01-31 15:37:14 +04:00
fs/fs.o drivers/ata.o lib/mem.o lib/string.o proc.o drivers/pit.o
2023-01-28 13:22:17 +04:00
2022-09-21 18:25:06 +03:00
run: image.bin
2022-11-21 00:53:29 +03:00
qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio
2022-09-21 16:53:45 +03:00
2022-11-30 14:48:13 +00:00
run-nox: image.bin
qemu-system-i386 -nographic -drive format=raw,file=$< -serial mon:stdio
2022-11-30 18:11:06 +03:00
debug-boot-nox: image.bin mbr.elf
2022-11-25 09:57:00 +00:00
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S &
$(GDB) mbr.elf \
2022-11-20 22:17:13 +03:00
-ex "set architecture i8086" \
-ex "target remote localhost:1234" \
-ex "break *0x7c00" \
-ex "continue"
2022-11-18 18:33:40 +03:00
debug-boot: image.bin mbr.elf
qemu-system-i386 -drive format=raw,file=$< -s -S &
2022-11-25 09:57:00 +00:00
$(GDB) mbr.elf \
2022-11-30 18:11:06 +03:00
-ex "set architecture i8086" \
2022-11-18 18:33:40 +03:00
-ex "target remote localhost:1234" \
2022-11-30 18:11:06 +03:00
-ex "break *0x7c00" \
2022-11-18 18:33:40 +03:00
-ex "continue"
2023-01-24 00:26:33 +03:00
debug-server: image.bin
qemu-system-i386 -drive format=raw,file=$< -s -S
debug-server-nox: image.bin
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S
2022-09-21 18:25:06 +03:00
debug: image.bin
2022-09-21 17:37:27 +03:00
qemu-system-i386 -drive format=raw,file=$< -s -S &
2022-11-25 09:57:00 +00:00
$(GDB) kernel.bin \
2022-09-21 17:37:27 +03:00
-ex "target remote localhost:1234" \
2022-11-18 18:33:40 +03:00
-ex "break _start" \
2022-09-21 17:37:27 +03:00
-ex "continue"
2022-11-30 14:48:13 +00:00
debug-nox: image.bin
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S &
$(GDB) kernel.bin \
-ex "target remote localhost:1234" \
-ex "break _start" \
-ex "continue"
2022-12-14 17:02:15 +03:00
fs.img: kernel.bin tools/mkfs user/false user/greet user/div0
tools/mkfs $@ $< user/false user/greet user/div0
2022-11-18 22:58:49 +03:00
2022-11-21 01:50:02 +03:00
LDFLAGS=-m elf_i386
user/%: user/%.o user/crt.o
2022-12-14 09:00:32 +03:00
$(LD) $(LDFLAGS) -o $@ -Ttext 0x1000 $^
2022-11-21 01:50:02 +03:00
2022-11-18 22:58:49 +03:00
image.bin: mbr.bin fs.img
2022-09-21 18:25:06 +03:00
cat $^ >$@
2023-01-28 13:22:17 +04:00
kernel.bin: $(OBJECTS)
2023-01-27 13:49:52 +04:00
$(LD) $(LDFLAGS) $(LDKERNELFLAGS) -o $@ -Ttext 0x9000 $^
2023-01-27 13:15:37 +04:00
bootmain.o: bootmain.c
$(CC) $(CFLAGS) -Os -c $< -o $@
2022-09-21 18:25:06 +03:00
%.o: %.c
2022-11-25 12:57:49 +03:00
$(CC) $(CFLAGS) -c $< -o $@
2022-09-21 18:25:06 +03:00
2022-09-21 16:53:45 +03:00
%.o: %.S
2023-01-24 00:26:33 +03:00
$(CC) $(ASMFLAGS) $^ -o $@
2022-09-21 16:53:45 +03:00
2023-01-27 12:25:39 +00:00
mbr.bin: mbr.elf tools/mbrpad
$(OBJCOPY) -S -O binary -j .text $< $@
2023-01-27 13:15:37 +04:00
tools/mbrpad $@
mbr.raw: mbr.o bootmain.o
2023-01-27 12:25:39 +00:00
$(LD) -N -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@
2022-09-21 16:53:45 +03:00
2023-01-27 13:15:37 +04:00
mbr.elf: mbr.o bootmain.o
2023-01-27 12:25:39 +00:00
$(LD) -N -m elf_i386 -Ttext=0x7c00 $^ -o $@
2022-11-18 18:33:40 +03:00
2022-09-21 17:37:27 +03:00
clean:
2023-01-27 12:25:39 +00:00
rm -f *.elf *.img *.bin *.raw *.o */*.o tools/mkfs ejudge.sh
2022-11-18 22:58:49 +03:00
tools/%: tools/%.c
gcc -Wall -Werror -g $^ -o $@