diff options
author | Benji Dial <benji@benjidial.net> | 2024-05-18 21:53:38 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-05-18 21:53:38 -0400 |
commit | b1a912a8a6ff472a49b2e0a09cfd433adfc2cb24 (patch) | |
tree | 5009d4415ba13e4baa37f3d0271852528130fd3b /makefile | |
parent | a8a80d326de9550b2a25b1255a2093ab43219ede (diff) | |
download | hilbert-os-b1a912a8a6ff472a49b2e0a09cfd433adfc2cb24.tar.gz |
reorganization, cross compiler
Diffstat (limited to 'makefile')
-rw-r--r-- | makefile | 205 |
1 files changed, 118 insertions, 87 deletions
@@ -1,93 +1,124 @@ -GPP_ARGS = -std=c++17 -Wall -Wextra -O3 -ggdb -nostdinc \ - -fno-exceptions -ffreestanding -fno-rtti -mno-sse -KGPP_ARGS = ${GPP_ARGS} -I kernel/include -I mintsuki-freestanding-headers -AGPP_ARGS = ${GPP_ARGS} -I libraries/euler/include \ - -I libraries/daguerre/include +LIMINE_DIR = $(abspath dependencies/limine) +TOOLCHAIN_DIR = $(abspath toolchain) -LD_ARGS = -z noexecstack -KLD_ARGS = -T kernel/link.ld ${LD_ARGS} -ALD_ARGS = -T applications/link.ld ${LD_ARGS} -LLD_ARGS = ${LD_ARGS} +HILBERT_NASM = nasm -f elf64 +HILBERT_CC = ${TOOLCHAIN_DIR}/usr/bin/x86_64-elf-c++ -std=c++17 -Wall \ + -Wextra -O3 -ggdb -static -fno-exceptions -fno-rtti -mno-sse -I include \ + -I $(abspath dependencies/mintsuki-headers) -I $(abspath euler/include) \ + -I $(abspath libraries/daguerre/include) +HILBERT_AR = ${TOOLCHAIN_DIR}/usr/bin/x86_64-elf-ar +HILBERT_LD = ${TOOLCHAIN_DIR}/usr/bin/x86_64-elf-ld -z noexecstack -all: out/disk.iso +.EXPORT_ALL_VARIABLES: -run: out/disk.iso +LIB_DIR = toolchain/usr/x86_64-elf/lib/ + +LIMINE_DEP = dependencies/.limine-done +MINTSUKI_HEADERS_DEP = dependencies/.mintsuki-headers-done +BINUTILS_DEP = toolchain/.binutils-done +GCC_DEP = toolchain/.gcc-done +LIBGCC_DEP = toolchain/.libgcc-done + +EULER_DEP = toolchain/.euler-done +DAGUERRE_DEP = toolchain/.daguerre-done + +APP_DEPS = ${GCC_DEP} ${LIBGCC_DEP} ${EULER_DEP} ${MINTSUKI_HEADERS_DEP} +LIBRARY_DEPS = ${GCC_DEP} ${MINTSUKI_HEADERS_DEP} + +.PHONY: default run clean clean-dependencies + +default: build/disk.iso + +run: build/disk.iso gdb -x qemu.gdb clean: - rm -rf obj out - -dist-clean: - rm -rf limine mintsuki-freestanding-headers - -limine: - git clone --depth=1 -b v6.x-branch \ - https://github.com/limine-bootloader/limine.git limine - cd limine && ./bootstrap && ./configure -q --enable-bios --enable-bios-cd - +make -C limine - -mintsuki-freestanding-headers: - git clone --depth=1 \ - https://github.com/mintsuki/freestanding-headers.git \ - mintsuki-freestanding-headers - -obj/kernel/entry.cpp.o: kernel/entry.cpp limine mintsuki-freestanding-headers - @mkdir -p $(@D) - g++ -c ${KGPP_ARGS} $< -o $@ - -obj/kernel/%.cpp.o: kernel/%.cpp mintsuki-freestanding-headers - @mkdir -p $(@D) - g++ -c ${KGPP_ARGS} $< -o $@ - -obj/kernel/%.asm.o: kernel/%.asm - @mkdir -p $(@D) - nasm -f elf64 $< -o $@ - -KERNEL_OBJECTS = allocator.cpp application.cpp entry.cpp framebuffer.cpp \ - paging.asm paging.cpp storage.cpp storage/bd/memory.cpp terminal.cpp \ - storage/fs/tarfs.cpp utility.cpp vfile.cpp syscall.asm syscall.cpp \ - interrupts.asm interrupts.cpp input.cpp panic.cpp -obj/kernel.elf: ${KERNEL_OBJECTS:%=obj/kernel/%.o} - ld ${KLD_ARGS} $^ -o $@ - -obj/%.cpp.o: %.cpp mintsuki-freestanding-headers - @mkdir -p $(@D) - g++ -c ${AGPP_ARGS} $< -o $@ - -obj/%.asm.o: %.asm - @mkdir -p $(@D) - nasm -f elf64 $< -o $@ - -EULER_OBJECTS = entry.cpp syscall.asm cassert.cpp allocator.cpp cstdio.cpp \ - cctype.cpp -obj/euler.o: ${EULER_OBJECTS:%=obj/libraries/euler/%.o} - ld -r ${LLD_ARGS} $^ -o $@ - -DAGUERRE_OBJECTS = ppm.cpp -obj/daguerre.o: ${DAGUERRE_OBJECTS:%=obj/libraries/daguerre/%.o} - ld -r ${LLD_ARGS} $^ -o $@ - -INIT_OBJECTS = main.cpp -obj/initfs/bin/init.elf: ${INIT_OBJECTS:%=obj/applications/init/%.o} \ - obj/euler.o obj/daguerre.o - @mkdir -p $(@D) - ld ${ALD_ARGS} $^ -o $@ - -obj/initfs/.skeleton: - @mkdir -p obj/initfs - cp -r skeleton/* obj/initfs/ - @touch obj/initfs/.skeleton - -APPLICATIONS = init -obj/initfs.tgz: ${APPLICATIONS:%=obj/initfs/bin/%.elf} obj/initfs/.skeleton - tar czf obj/initfs.tgz -C obj/initfs . - -out/disk.iso: obj/kernel.elf obj/initfs.tgz limine - mkdir -p obj/iso out - cp obj/kernel.elf obj/initfs.tgz limine/bin/limine-bios.sys \ - limine/bin/limine-bios-cd.bin limine.cfg obj/iso/ - cp terminus/ter-u16b.psf obj/iso/termfont.psf - xorriso -as mkisofs -quiet -no-emul-boot -boot-info-table \ - -boot-load-size 4 -b limine-bios-cd.bin obj/iso -o $@ - limine/bin/limine bios-install $@ - rm -rf obj/iso + rm -rf build ${EULER_DEP} ${DAGUERRE_DEP} + make -C euler clean + make -C kernel clean + make -C applications/init clean + make -C libraries/daguerre clean + +clean-dependencies: clean + rm -rf toolchain dependencies + +${LIMINE_DEP}: + mkdir -p dependencies + test -e dependencies/limine || git clone --depth 1 -b v7.5.1 https://github.com/limine-bootloader/limine dependencies/limine + cd ${LIMINE_DIR} && ./bootstrap + cd ${LIMINE_DIR} && ./configure --enable-bios --enable-bios-cd + +make -C ${LIMINE_DIR} + touch $@ + +${MINTSUKI_HEADERS_DEP}: + mkdir -p dependencies + test -e dependencies/mintsuki-headers || git clone --depth 1 https://github.com/mintsuki/freestanding-headers dependencies/mintsuki-headers + touch $@ + +${BINUTILS_DEP}: + mkdir -p dependencies toolchain/usr + test -e dependencies/binutils || (git clone --depth 1 -b binutils-2_42 https://sourceware.org/git/binutils-gdb dependencies/binutils && cd dependencies/binutils && git apply ../../patches/binutils.txt) + mkdir -p dependencies/binutils/build + cd dependencies/binutils/build && ../configure --disable-gdb \ + --target=x86_64-elf --prefix=${TOOLCHAIN_DIR}/usr + +make -C dependencies/binutils/build + +make -C dependencies/binutils/build install + touch $@ + +${GCC_DEP}: ${BINUTILS_DEP} + mkdir -p toolchain/usr/include + test -e dependencies/gcc || git clone --depth 1 -b releases/gcc-14.1.0 https://gcc.gnu.org/git/gcc dependencies/gcc + mkdir -p dependencies/gcc/build + cd dependencies/gcc/build && ../configure --disable-fixed-point \ + --disable-gcov --disable-multilib --disable-shared --enable-languages=c++ \ + --target=x86_64-elf --prefix=${TOOLCHAIN_DIR}/usr --without-headers + +make -C dependencies/gcc/build all-gcc + +make -C dependencies/gcc/build install-gcc + touch $@ + +${LIBGCC_DEP}: ${GCC_DEP} + +make -C dependencies/gcc/build all-target-libgcc + +make -C dependencies/gcc/build install-target-libgcc + touch $@ + +${EULER_DEP}: ${GCC_DEP} ${MINTSUKI_HEADERS_DEP} + +make -C euler build/crt0.o build/libc.a build/libg.a build/libm.a \ + build/libstdc++.a + mkdir -p toolchain/usr/x86_64-elf/lib + cp euler/build/crt0.o euler/build/libc.a euler/build/libg.a \ + euler/build/libm.a euler/build/libstdc++.a ${LIB_DIR} + touch $@ + +${DAGUERRE_DEP}: ${LIBRARY_DEPS} + +make -C libraries/daguerre build/libdaguerre.a + cp libraries/daguerre/build/libdaguerre.a ${LIB_DIR} + touch $@ + +kernel/build/kernel.elf: ${GCC_DEP} ${MINTSUKI_HEADERS_DEP} ${LIMINE_DEP} + +make -C kernel build/kernel.elf + +applications/init/build/init.elf: ${APP_DEPS} ${DAGUERRE_DEP} + +make -C applications/init build/init.elf + +build/initfs.tgz: applications/init/build/init.elf + @mkdir -p build + rm -rf build/initfs + cp -r skeleton build/initfs + mkdir build/initfs/bin + cp applications/init/build/init.elf build/initfs/bin/init + cd build/initfs && tar czf ../initfs.tgz . + +build/disk.iso: kernel/build/kernel.elf build/initfs.tgz ${LIMINE_DEP} + @mkdir -p build + rm -rf build/iso + mkdir build/iso + cp kernel/build/kernel.elf ${LIMINE_DIR}/bin/limine-bios.sys \ + ${LIMINE_DIR}/bin/limine-bios-cd.bin build/initfs.tgz build/iso/ + echo 'TIMEOUT=0' > build/iso/limine.cfg + echo ':Hilbert OS' >> build/iso/limine.cfg + echo 'PROTOCOL=limine' >> build/iso/limine.cfg + echo 'KERNEL_PATH=boot:///kernel.elf' >> build/iso/limine.cfg + echo 'MODULE_PATH=$$boot:///initfs.tgz' >> build/iso/limine.cfg + echo 'MODULE_CMDLINE=initfs' >> build/iso/limine.cfg + xorriso -as mkisofs -b limine-bios-cd.bin -no-emul-boot -boot-load-size 4 \ + -boot-info-table --protective-msdos-label build/iso -o $@ |