setos

拙OS
Log | Files | Refs | LICENSE

commit a00a9885bf786943d80d29d6bb5908cb07bf4a06
parent 8dbccc7fa779d7c4f57ef9734d464708b4735040
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Thu,  4 Apr 2024 15:30:07 +0900

unify Makefile. Is it a good idea?

Diffstat:
Msys/src/Makefile | 46++++++++++++++++++++++++++++++++++++++--------
Dsys/src/boot/Makefile | 16----------------
Dsys/src/kernel/Makefile | 25-------------------------
Dsys/src/libc/Makefile | 12------------
4 files changed, 38 insertions(+), 61 deletions(-)

diff --git a/sys/src/Makefile b/sys/src/Makefile @@ -1,6 +1,18 @@ TARGETS = boot kernel libc -disk.img: targets +BOOTCC = x86_64-w64-mingw32-gcc +BOOTCFLAGS = -I ../include \ + -nostdlib -fpic -mno-red-zone -fno-stack-protector -static \ + -fno-builtin -g -mabi=sysv \ + -mno-stack-arg-probe -Wall -e EfiMain + +CC = gcc +LD = ld +CFLAGS = -I ../include -nostdlib -fpic -mno-red-zone -Wall -g \ + -ffreestanding -fno-builtin +LDFLAGS = -Llibc -static + +disk.img: boot/boot.efi kernel/main.elf qemu-img create -f raw disk.img 200M mkfs.fat -n 'SETOS' -s 2 -f 2 -R 32 -F 32 disk.img mkdir -p image @@ -10,10 +22,28 @@ disk.img: targets doas cp kernel/main.elf image/setos.elf doas umount image -targets: - for t in $(TARGETS); do \ - (cd $$t && make); \ - done +boot/boot.efi: boot/boot.dll + objcopy --target=efi-app-x86_64 boot/boot.dll $@ +boot/boot.dll: boot/boot.c boot/utils.c + $(BOOTCC) $(BOOTCFLAGS) -o $@ boot/boot.c boot/utils.c + +kernel/main.elf: kernel/main.o kernel/draw.o kernel/alloc.o kernel/console.o kernel/memmap.ld libc/libc.a + $(LD) $(LDFLAGS) -e kernel_main -T kernel/memmap.ld -o $@ \ + kernel/main.o kernel/draw.o kernel/alloc.o kernel/console.o \ + -lc +kernel/main.o: kernel/main.c + $(CC) $(CFLAGS) -c -o $@ kernel/main.c +kernel/draw.o: kernel/draw.c + $(CC) $(CFLAGS) -c -o $@ kernel/draw.c +kernel/alloc.o: kernel/alloc.c + $(CC) $(CFLAGS) -c -o $@ kernel/alloc.c +kernel/console.o: kernel/console.c + $(CC) $(CFLAGS) -c -o $@ kernel/console.c + +libc/libc.a: libc/strcpy.o + ar rcs $@ libc/strcpy.o +libc/strcpy.o: libc/strcpy.c + $(CC) $(CFLAGS) -c -o $@ libc/strcpy.c run: disk.img OVMF.fd qemu-system-x86_64 \ @@ -32,6 +62,6 @@ gdb: disk.img OVMF.fd clean: rm -rf disk.img image - for t in $(TARGETS); do \ - (cd $$t && make clean); \ - done + rm -f boot/boot.efi boot/boot.dll + rm -f kernel/*.o kernel/main.elf + rm -f libc/*.o libc/*.a diff --git a/sys/src/boot/Makefile b/sys/src/boot/Makefile @@ -1,16 +0,0 @@ -CC = x86_64-w64-mingw32-gcc -CFLAGS = -I ../../include \ - -nostdlib -fpic -mno-red-zone -fno-stack-protector -static \ - -fno-builtin -g -mabi=sysv \ - -mno-stack-arg-probe -Wall -e EfiMain - -all: boot.efi - -boot.efi: boot.dll - objcopy --target=efi-app-x86_64 boot.dll $@ - -boot.dll: boot.c utils.c - $(CC) $(CFLAGS) -o $@ boot.c utils.c - -clean: - rm -f boot.efi boot.dll diff --git a/sys/src/kernel/Makefile b/sys/src/kernel/Makefile @@ -1,24 +0,0 @@ -CC = gcc -LD = ld -CFLAGS = -I ../../include -nostdlib -fpic -mno-red-zone -Wall -g \ - -ffreestanding -fno-builtin -LDFLAGS = -e kernel_main -static -OBJS = main.o draw.o alloc.o console.o -LIBS = libc -LIBOBJ = ../libc/libc.o - -all: main.elf - -main.elf: $(OBJS) libs memmap.ld - $(LD) $(LDFLAGS) -T memmap.ld -o $@ $(OBJS) $(LIBOBJ) - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - -libs: - for lib in $(LIBS); do \ - cd ../$$lib && make; \ - done - -clean: - rm -f $(OBJS) main.elf -\ No newline at end of file diff --git a/sys/src/libc/Makefile b/sys/src/libc/Makefile @@ -1,12 +0,0 @@ -CC = gcc -CFLAGS = -I ../../include -nostdlib -fpic -mno-red-zone -Wall -g \ - -ffreestanding -fno-builtin -SRC = strcpy.c - -all: libc.o - -libc.o: $(SRC) - $(CC) $(CFLAGS) -c -o $@ $(SRC) - -clean: - rm -f libc.o