From ae91bed93ff3334d7ef2e779f79d80f230020a49 Mon Sep 17 00:00:00 2001 From: Alexander Myltsev Date: Fri, 27 Jan 2023 12:25:39 +0000 Subject: [PATCH] Fix Linux build. --- Makefile | 12 +++++++----- tools/mbrpad.c | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 002227f..7e69da5 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,12 @@ GDB=gdb +OBJCOPY=objcopy 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 +OBJCOPY=x86_64-elf-objcopy endif CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \ @@ -78,18 +80,18 @@ bootmain.o: bootmain.c %.o: %.S $(CC) -m32 -ffreestanding -c -g $^ -o $@ -mbr.bin: mbr.raw tools/mbrpad - cp $< $@ +mbr.bin: mbr.elf tools/mbrpad + $(OBJCOPY) -S -O binary -j .text $< $@ tools/mbrpad $@ mbr.raw: mbr.o bootmain.o - $(LD) -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@ + $(LD) -N -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@ mbr.elf: mbr.o bootmain.o - $(LD) -m elf_i386 -Ttext=0x7c00 $^ -o $@ + $(LD) -N -m elf_i386 -Ttext=0x7c00 $^ -o $@ clean: - rm -f *.elf *.img *.bin *.o */*.o tools/mkfs ejudge.sh + rm -f *.elf *.img *.bin *.raw *.o */*.o tools/mkfs ejudge.sh tools/%: tools/%.c gcc -Wall -Werror -g $^ -o $@ diff --git a/tools/mbrpad.c b/tools/mbrpad.c index 267b8a8..7a42dce 100644 --- a/tools/mbrpad.c +++ b/tools/mbrpad.c @@ -1,6 +1,7 @@ #include #include #include +#include int main(int argc, char* argv[]) { if (argc != 2) { @@ -11,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: %llu)\n", - filename, length); + fprintf(stderr, "file %s is larger than 510 bytes (size: %ju)\n", + filename, (uintmax_t)length); return 1; } lseek(fd, 510, SEEK_SET);