From d955ac3b10753b16879c1f924c22c346b64ce6d9 Mon Sep 17 00:00:00 2001 From: Alexander Myltsev Date: Sat, 10 Feb 2024 01:09:08 +0400 Subject: [PATCH] Fixes for Windows. --- Makefile | 29 ++++++++++++++++++++--------- tools/mbrpad.c | 4 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index a9ab49c..18643dd 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,14 @@ GDB=gdb OBJCOPY=objcopy +UNAME=uname +CAT=cat -ifeq ($(shell uname -s),Darwin) +ifeq ($(OS),Windows_NT) + UNAME=ver + CAT=type +endif + +ifeq ($(shell $(UNAME) -s),Darwin) AS=x86_64-elf-as LD=x86_64-elf-ld CC=x86_64-elf-gcc @@ -17,16 +24,20 @@ ASMFLAGS = -m32 -ffreestanding -c -g ifeq ($(LLVM),on) #AS=llvm-as -LD=PATH=/usr/local/opt/llvm/bin:$(PATH) ld.lld +ifeq ($(shell $(UNAME) -s),Darwin) + LD=PATH=/usr/local/opt/llvm/bin:$(PATH) ld.lld +else + LD=ld.lld +endif CC=clang CFLAGS += -target elf-i386 ASMFLAGS = -target elf-i386 -ffreestanding -c -g LDKERNELFLAGS = --script=script.ld endif -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 +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 run: image.bin qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio @@ -43,7 +54,7 @@ ejudge.sh: image.bin chmod +x $@ diag: - -uname -a + -$(UNAME) -a -$(CC) --version -$(LD) -v -gcc --version @@ -85,8 +96,8 @@ debug-nox: image.bin -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 +fs.img: ./kernel.bin ./tools/mkfs ./user/false ./user/greet ./user/div0 + ./tools/mkfs $@ $< ./user/false ./user/greet ./user/div0 LDFLAGS=-m elf_i386 @@ -94,7 +105,7 @@ user/%: user/%.o user/crt.o $(LD) $(LDFLAGS) -o $@ -Ttext 0x1000 $^ image.bin: mbr.bin fs.img - cat $^ >$@ + $(CAT) $^ >$@ kernel.bin: $(OBJECTS) $(LD) $(LDFLAGS) $(LDKERNELFLAGS) -o $@ -Ttext 0x9000 $^ diff --git a/tools/mbrpad.c b/tools/mbrpad.c index 7a42dce..4f2059d 100644 --- a/tools/mbrpad.c +++ b/tools/mbrpad.c @@ -12,8 +12,8 @@ int main(int argc, char* argv[]) { int fd = open(filename, O_RDWR); off_t length = lseek(fd, 0, SEEK_END); if (length > 510) { - fprintf(stderr, "file %s is larger than 510 bytes (size: %ju)\n", - filename, (uintmax_t)length); + fprintf(stderr, "file %s is larger than 510 bytes (size: %llu)\n", + filename, (unsigned long long)length); return 1; } lseek(fd, 510, SEEK_SET);