caos-with-snake/Makefile

154 lines
3.9 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
2024-02-10 01:09:08 +04:00
CAT=cat
2023-01-13 12:56:54 +04:00
2024-02-10 01:09:08 +04:00
ifeq ($(OS),Windows_NT)
CAT=type
2024-02-10 01:17:15 +04:00
else
OS=$(shell uname -s)
2024-02-10 01:09:08 +04:00
endif
2024-02-10 01:17:15 +04:00
ifeq ($(OS),Darwin)
2023-01-13 12:56:54 +04:00
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 \
2024-02-03 14:59:25 +04:00
-mno-sse \
2025-01-17 21:46:47 +04:00
-I. \
-Wall -Wno-unused-result -Wno-unused-variable -Wno-unused-but-set-variable -ggdb -m32 -Werror -fno-omit-frame-pointer -Os
2023-01-13 12:56:54 +04:00
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
2026-04-06 05:20:00 +03:00
CFLAGS += -Wno-unused-variable -Wno-unused-function
ASMFLAGS = -m32 -ffreestanding -c -g -I.
2023-01-24 00:26:33 +03:00
ifeq ($(LLVM),on)
2024-02-10 01:17:15 +04:00
ifeq ($(OS),Darwin)
2025-01-18 15:57:47 +04:00
LD=PATH=/usr/local/opt/llvm/bin:"$(PATH)" ld.lld
2024-02-10 01:09:08 +04:00
else
LD=ld.lld
endif
2024-02-10 01:17:15 +04:00
2023-01-24 00:26:33 +03:00
CC=clang
CFLAGS += -target elf-i386
2025-01-18 15:57:47 +04:00
ASMFLAGS += -target elf-i386
2023-01-24 00:26:33 +03:00
LDKERNELFLAGS = --script=script.ld
endif
2023-01-13 12:56:54 +04:00
2025-01-18 15:52:48 +04:00
OBJECTS = ./kernel/kstart.o ./kernel.o ./console.o ./drivers/vga.o ./drivers/uart.o ./drivers/keyboard.o \
2025-02-01 17:25:59 +04:00
./drivers/graphics.o \
2025-01-18 15:52:48 +04:00
./cpu/idt.o ./cpu/gdt.o ./cpu/swtch.o ./cpu/vectors.o ./kernel/mem.o ./proc.o ./lib/string.o \
2025-01-18 15:46:43 +04:00
./fs/fs.o ./drivers/ata.o ./lib/string.o ./proc.o ./drivers/pit.o ./kernel/vm.o
2023-01-28 13:22:17 +04:00
2026-04-08 01:44:22 +03:00
run-with-pulseaudio: image.bin
2026-04-06 16:40:50 +03:00
qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio -qmp unix:qemu-monitor-socket,server,nowait \
-audiodev pa,id=SAUND \
-machine pcspk-audiodev=SAUND
2023-01-13 12:56:54 +04:00
2026-04-08 01:44:22 +03:00
run: image.bin
qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio -qmp unix:qemu-monitor-socket,server,nowait
2023-01-13 12:56:54 +04:00
run-nox: image.bin
2026-02-10 00:07:44 +03:00
qemu-system-i386 -nographic -drive format=raw,file=$< -serial mon:stdio -qmp unix:qemu-monitor-socket,server,nowait
test: tests.py
python3 tests.py --nox
test-x: tests.py
python3 tests.py
2023-01-13 12:56:54 +04:00
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:
2024-02-10 01:09:08 +04:00
-$(UNAME) -a
2023-02-01 14:51:48 +04:00
-$(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" \
2025-01-17 21:46:47 +04:00
-ex "break kmain" \
2023-01-13 12:56:54 +04:00
-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"
USERPROGS=./user/false ./user/greet ./user/div0 ./user/shout ./user/badputs ./user/bss ./user/player ./user/getc ./snake/snake
2025-01-21 00:29:31 +04:00
fs.img: ./kernel.bin ./tools/mkfs $(USERPROGS)
./tools/mkfs $@ $< $(USERPROGS)
2023-01-13 12:56:54 +04:00
LDFLAGS=-m elf_i386
user/%: user/%.o user/crt.o
$(LD) $(LDFLAGS) -o $@ -Ttext 0x401000 $^
2023-01-13 12:56:54 +04:00
snake/snake: snake/snake.o user/crt.o
$(LD) $(LDFLAGS) -o $@ -Ttext 0x401000 $^
2023-01-28 13:22:17 +04:00
kernel.bin: $(OBJECTS)
2025-01-17 23:29:01 +04:00
$(LD) $(LDFLAGS) $(LDKERNELFLAGS) -o $@ -Ttext 0x80009000 $^
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
2024-02-10 01:39:02 +04:00
image.bin: mbr.elf tools/mbrpad fs.img
2023-01-27 12:25:39 +00:00
$(OBJCOPY) -S -O binary -j .text $< $@
2024-02-10 01:39:02 +04:00
tools/mbrpad $@ fs.img
2023-01-27 13:15:37 +04:00
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 -Wno-unused-result -Werror -g $^ -o $@