Makefile (3435B)
1 TARGETS = boot kernel libc 2 ARCH = amd64 3 4 BOOTCC = x86_64-w64-mingw32-gcc 5 BOOTCFLAGS = -I ../include \ 6 -nostdlib -fpic -mno-red-zone -fno-stack-protector -static \ 7 -fno-builtin -g -mabi=sysv \ 8 -mno-stack-arg-probe -Wall -e EfiMain 9 10 CC = gcc # TODO: find portable compiler flags. 11 LD = ld 12 CFLAGS = -I ../include -fpic -mno-red-zone -Wall -g \ 13 -fno-stack-protector -ffreestanding -fno-builtin -nostdlib # -nostdinc 14 LDFLAGS = -L../lib -static 15 16 disk.img: boot/boot.efi kernel/main.elf 17 qemu-img create -f raw disk.img 200M 18 mkfs.fat -n 'SETOS' -s 2 -f 2 -R 32 -F 32 disk.img 19 mkdir -p image 20 doas mount disk.img image 21 doas mkdir -p image/EFI/BOOT 22 doas cp boot/boot.efi image/EFI/BOOT/BOOTX64.EFI 23 doas cp kernel/main.elf image/setos.elf 24 doas umount image 25 26 boot/boot.efi: boot/boot.dll 27 objcopy --target=efi-app-x86_64 boot/boot.dll $@ 28 boot/boot.dll: boot/boot.c boot/utils.c 29 $(BOOTCC) $(BOOTCFLAGS) -o $@ boot/boot.c boot/utils.c 30 31 kernel/main.elf: kernel/memmap.ld \ 32 kernel/$(ARCH)/start.o kernel/main.o kernel/alloc.o kernel/console.o \ 33 kernel/draw.o kernel/pci.o kernel/$(ARCH)/pci.o kernel/$(ARCH)/machine.o \ 34 kernel/xhc.o \ 35 ../lib/libc.a \ 36 kernel/alloc.o kernel/console.o kernel/draw.o \ 37 kernel/$(ARCH)/machine.o kernel/$(ARCH)/pci.o 38 $(LD) $(LDFLAGS) -e kernel_start -T kernel/memmap.ld -o $@ \ 39 kernel/$(ARCH)/start.o kernel/main.o \ 40 kernel/alloc.o kernel/console.o kernel/draw.o kernel/pci.o \ 41 kernel/$(ARCH)/pci.o kernel/$(ARCH)/machine.o \ 42 kernel/xhc.o \ 43 -lc 44 kernel/$(ARCH)/start.o: kernel/$(ARCH)/start.s 45 $(CC) $(CFLAGS) -c -o $@ kernel/$(ARCH)/start.s 46 kernel/main.o: kernel/main.c ../include/uefi.h ../include/libc.h \ 47 ../include/draw.h ../include/console.h ../include/pci.h ../include/xhc.h 48 $(CC) $(CFLAGS) -c -o $@ kernel/main.c 49 kernel/alloc.o: kernel/alloc.c ../include/libc.h 50 $(CC) $(CFLAGS) -c -o $@ kernel/alloc.c 51 kernel/console.o: kernel/console.c ../include/uefi.h ../include/libc.h \ 52 ../include/draw.h ../include/console.h 53 $(CC) $(CFLAGS) -c -o $@ kernel/console.c 54 kernel/draw.o: kernel/draw.c ../include/uefi.h ../include/libc.h \ 55 ../include/draw.h ../include/console.h 56 $(CC) $(CFLAGS) -c -o $@ kernel/draw.c 57 kernel/pci.o: kernel/pci.c ../include/libc.h ../include/pci.h 58 $(CC) $(CFLAGS) -c -o $@ kernel/pci.c 59 kernel/$(ARCH)/pci.o: kernel/$(ARCH)/pci.c kernel/$(ARCH)/pci.h \ 60 ../include/libc.h ../include/pci.h 61 $(CC) $(CFLAGS) -c -o $@ kernel/$(ARCH)/pci.c 62 kernel/$(ARCH)/machine.o: kernel/$(ARCH)/machine.s 63 $(CC) $(CFLAGS) -c -o $@ kernel/$(ARCH)/machine.s 64 kernel/xhc.o: kernel/xhc.c ../include/xhc.h 65 $(CC) $(CFLAGS) -c -o $@ kernel/xhc.c 66 67 ../lib/libc.a: libc/strcpy.o libc/memset.o ../lib 68 ar rcs $@ libc/strcpy.o libc/memset.o 69 libc/strcpy.o: libc/strcpy.c ../include/libc.h 70 $(CC) $(CFLAGS) -c -o $@ libc/strcpy.c 71 libc/memset.o: libc/memset.c ../include/libc.h 72 $(CC) $(CFLAGS) -c -o $@ libc/memset.c 73 74 ../lib: 75 mkdir -p ../lib 76 77 run: disk.img OVMF.fd 78 qemu-system-x86_64 \ 79 -bios OVMF.fd \ 80 -drive format=raw,file=disk.img \ 81 -device nec-usb-xhci,id=xhci \ 82 -device usb-mouse,bus=xhci.0 83 84 gdb: disk.img OVMF.fd 85 qemu-system-x86_64 \ 86 -bios OVMF.fd \ 87 -drive format=raw,file=disk.img \ 88 -gdb tcp::1234 -S 89 90 #OVMF.fd: 91 # curl -OL https://downloads.sourceforge.net/project/edk2/OVMF/OVMF-X64-r15214.zip 92 # unzip OVMF-X64-r15214.zip OVMF.fd 93 94 clean: 95 rm -rf disk.img image 96 rm -f boot/boot.efi boot/boot.dll 97 rm -f kernel/*.o kernel/$(ARCH)/*.o kernel/main.elf 98 rm -rf libc/*.o ../lib