caos-with-snake/Makefile

125 lines
3.0 KiB
Makefile
Raw Normal View History

2023-01-13 12:56:54 +04:00
GDB=gdb
2023-01-27 12:25:39 +00:00
OBJCOPY=objcopy
2023-01-13 12:56:54 +04:00
ifeq ($(shell uname -s),Darwin)
AS=x86_64-elf-as
LD=x86_64-elf-ld
CC=x86_64-elf-gcc
GDB=x86_64-elf-gdb
2023-01-27 12:25:39 +00:00
OBJCOPY=x86_64-elf-objcopy
2023-01-13 12:56:54 +04:00
endif
CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \
-Wall -ggdb -m32 -Werror -fno-omit-frame-pointer
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
2023-01-13 12:56:54 +04: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 \
fs/fs.o
2023-01-28 13:22:17 +04:00
2023-01-13 12:56:54 +04:00
run: image.bin
qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio
run-nox: image.bin
qemu-system-i386 -nographic -drive format=raw,file=$< -serial mon:stdio
ejudge.sh: image.bin
echo >$@ "#!/bin/sh"
echo >>$@ "base64 -d <<===EOF | gunzip >image.bin"
gzip <$^ | base64 >>$@
echo >>$@ "===EOF"
echo >>$@ "exec qemu-system-i386 -nographic -drive format=raw,file=image.bin -serial mon:stdio"
chmod +x $@
2023-02-01 14:51:48 +04:00
diag:
-uname -a
-$(CC) --version
-$(LD) -v
-gcc --version
-ld -v
2023-01-13 12:56:54 +04:00
debug-boot-nox: image.bin mbr.elf
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S &
$(GDB) mbr.elf \
-ex "set architecture i8086" \
-ex "target remote localhost:1234" \
-ex "break *0x7c00" \
-ex "continue"
debug-boot: image.bin mbr.elf
qemu-system-i386 -drive format=raw,file=$< -s -S &
$(GDB) mbr.elf \
-ex "set architecture i8086" \
-ex "target remote localhost:1234" \
-ex "break *0x7c00" \
-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
2023-01-13 12:56:54 +04:00
debug: image.bin
qemu-system-i386 -drive format=raw,file=$< -s -S &
$(GDB) kernel.bin \
-ex "target remote localhost:1234" \
-ex "break _start" \
-ex "continue"
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"
fs.img: kernel.bin tools/mkfs user/false user/greet user/div0
tools/mkfs $@ $< user/false user/greet user/div0
2023-01-13 12:56:54 +04:00
LDFLAGS=-m elf_i386
user/%: user/%.o user/crt.o
$(LD) $(LDFLAGS) -o $@ -Ttext 0x1000 $^
image.bin: mbr.bin fs.img
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 $@
2023-01-13 12:56:54 +04:00
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.S
2023-01-24 00:26:33 +03:00
$(CC) $(ASMFLAGS) $^ -o $@
2023-01-13 12:56:54 +04: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 $@
2023-01-13 12:56:54 +04: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 $@
2023-01-13 12:56:54 +04:00
clean:
2023-01-27 12:25:39 +00:00
rm -f *.elf *.img *.bin *.raw *.o */*.o tools/mkfs ejudge.sh
2023-01-13 12:56:54 +04:00
tools/%: tools/%.c
gcc -Wall -Werror -g $^ -o $@