diff --git a/.gitignore b/.gitignore index 941b7af..6c03106 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,9 @@ /tests/test*.log /tests/test*.trs +/build/* +!/build/.keep + /examples/assert_guards /examples/assert_simple /examples/cmdline diff --git a/build/.keep b/build/.keep new file mode 100644 index 0000000..e69de29 diff --git a/config/dev b/config/dev index a80bf53..aab5181 100755 --- a/config/dev +++ b/config/dev @@ -4,4 +4,6 @@ set -e REPO="$(realpath "$(dirname "$(realpath "$0")")/..")" +if [ -f "$REPO/Makefile" ]; then make -C "$REPO" distclean; fi + "$REPO/configure" --enable-assert --enable-guard diff --git a/config/i386 b/config/i386 index e9fbb16..fb3ce73 100755 --- a/config/i386 +++ b/config/i386 @@ -8,6 +8,8 @@ REPO="$(realpath "$(dirname "$(realpath "$0")")/..")" PREFIX="$REPO/vendor/cross" BIN="$PREFIX/bin" +if [ -f "$REPO/Makefile" ]; then make -C "$REPO" distclean; fi + export AR="$BIN/$HOST-ar" export CC="$BIN/$HOST-gcc" export RANLIB="$BIN/$HOST-ranlib" diff --git a/config/x86_64 b/config/x86_64 index 2d9c211..74172e4 100755 --- a/config/x86_64 +++ b/config/x86_64 @@ -8,6 +8,8 @@ REPO="$(realpath "$(dirname "$(realpath "$0")")/..")" PREFIX="$REPO/vendor/cross" BIN="$PREFIX/bin" +if [ -f "$REPO/Makefile" ]; then make -C "$REPO" distclean; fi + export AR="$BIN/$HOST-ar" export CC="$BIN/$HOST-gcc" export RANLIB="$BIN/$HOST-ranlib" diff --git a/config/x86_64-stivale2 b/config/x86_64-stivale2 new file mode 100755 index 0000000..74172e4 --- /dev/null +++ b/config/x86_64-stivale2 @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +ARCH='x86_64' +HOST="$ARCH-elf" +REPO="$(realpath "$(dirname "$(realpath "$0")")/..")" +PREFIX="$REPO/vendor/cross" +BIN="$PREFIX/bin" + +if [ -f "$REPO/Makefile" ]; then make -C "$REPO" distclean; fi + +export AR="$BIN/$HOST-ar" +export CC="$BIN/$HOST-gcc" +export RANLIB="$BIN/$HOST-ranlib" + +export CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector' + +"$REPO/configure" --host="$HOST" --enable-assert --enable-guard --with-libc diff --git a/examples/bootloader-multiboot2-grub/.gitignore b/examples/bootloader-multiboot2-grub/.gitignore index 6631cd5..30152cb 100644 --- a/examples/bootloader-multiboot2-grub/.gitignore +++ b/examples/bootloader-multiboot2-grub/.gitignore @@ -1,3 +1,6 @@ +/build-libkernaux/* +!/build-libkernaux/.keep + /image.iso /output.txt /rootfs/boot/kernel diff --git a/examples/bootloader-multiboot2-grub/Makefile b/examples/bootloader-multiboot2-grub/Makefile index 3a642ee..9824809 100644 --- a/examples/bootloader-multiboot2-grub/Makefile +++ b/examples/bootloader-multiboot2-grub/Makefile @@ -5,11 +5,13 @@ CCPREFIX = ../../vendor/cross/bin/i386-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc +CONFIG_LIBKERNAUX = ../../config/i386 DIFF = diff GRUB_FILE = grub-file GRUB_MKRESCUE = grub-mkrescue QEMU = qemu-system-i386 +BUILD_LIBKERNAUX = build-libkernaux EXPECTED = expected.txt IMAGE = image.iso LINKERSCR = linker.ld @@ -39,15 +41,20 @@ run: $(IMAGE) $(QEMU) -cdrom $< -serial stdio -display none | tee $(OUTPUT) clean: + make -C $(BUILD_LIBKERNAUX) distclean || true rm -f $(OUTPUT) $(IMAGE) $(KERNEL) $(OBJS) $(IMAGE): $(GRUBCFG) $(KERNEL) $(GRUB_MKRESCUE) $(ROOTFS) -o $@ -$(KERNEL): $(LINKERSCR) $(OBJS) - $(CC) -T $(LINKERSCR) -o $@ $(OBJS) -ffreestanding -nostdlib -lgcc -lkernaux -Wl,-L../.. +$(KERNEL): $(LINKERSCR) $(OBJS) build-libkernaux.a + $(CC) -T $(LINKERSCR) -o $@ $(OBJS) -ffreestanding -nostdlib -lgcc -lkernaux -Wl,-L$(BUILD_LIBKERNAUX) $(GRUB_FILE) --is-x86-multiboot2 $@ +build-libkernaux.a: + cd $(BUILD_LIBKERNAUX) && ../$(CONFIG_LIBKERNAUX) + cd $(BUILD_LIBKERNAUX) && make libkernaux.a + %.c.o: %.c $(CC) -c $< -o $@ $(CFLAGS) diff --git a/examples/bootloader-multiboot2-grub/build-libkernaux/.keep b/examples/bootloader-multiboot2-grub/build-libkernaux/.keep new file mode 100644 index 0000000..e69de29 diff --git a/examples/bootloader-multiboot2-limine/.gitignore b/examples/bootloader-multiboot2-limine/.gitignore index e59723f..9c867b4 100644 --- a/examples/bootloader-multiboot2-limine/.gitignore +++ b/examples/bootloader-multiboot2-limine/.gitignore @@ -1,3 +1,6 @@ +/build-libkernaux/* +!/build-libkernaux/.keep + /image.iso /output.txt /rootfs/boot/kernel diff --git a/examples/bootloader-multiboot2-limine/Makefile b/examples/bootloader-multiboot2-limine/Makefile index 4e296b1..8a2e536 100644 --- a/examples/bootloader-multiboot2-limine/Makefile +++ b/examples/bootloader-multiboot2-limine/Makefile @@ -5,12 +5,14 @@ CCPREFIX = ../../vendor/cross/bin/i386-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc +CONFIG_LIBKERNAUX = ../../config/i386 DIFF = diff GRUB_FILE = grub-file LIMINE = ../../vendor/limine/build/bin QEMU = qemu-system-x86_64 XORRISO = xorriso +BUILD_LIBKERNAUX = build-libkernaux EXPECTED = expected.txt IMAGE = image.iso LINKERSCR = linker.ld @@ -54,14 +56,15 @@ run: $(IMAGE) $(QEMU) -cdrom $< -serial stdio -display none | tee $(OUTPUT) clean: + make -C $(BUILD_LIBKERNAUX) distclean || true rm -f $(OUTPUT) $(IMAGE) $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) $(OBJS) $(IMAGE): $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) $(XORRISO) -as mkisofs -b $(REL_LIMINE_CD) -no-emul-boot -boot-load-size 4 -boot-info-table --efi-boot $(REL_LIMINE_ELTORITO) -efi-boot-part --efi-boot-image --protective-msdos-label $(ROOTFS) -o $@ $(LIMINE_INSTALL) $@ -$(FULL_KERNEL): $(LINKERSCR) $(OBJS) - $(CC) -T $(LINKERSCR) -o $@ $(OBJS) -ffreestanding -nostdlib -lgcc -lkernaux -Wl,-L../.. +$(FULL_KERNEL): $(LINKERSCR) $(OBJS) build-libkernaux.a + $(CC) -T $(LINKERSCR) -o $@ $(OBJS) -ffreestanding -nostdlib -lgcc -lkernaux -Wl,-L$(BUILD_LIBKERNAUX) $(GRUB_FILE) --is-x86-multiboot2 $@ $(FULL_LIMINE_CD): @@ -73,6 +76,10 @@ $(FULL_LIMINE_ELTORITO): $(FULL_LIMINE_SYS): cp -f $(LIMINE_SYS) $(FULL_LIMINE_SYS) +build-libkernaux.a: + cd $(BUILD_LIBKERNAUX) && ../$(CONFIG_LIBKERNAUX) + cd $(BUILD_LIBKERNAUX) && make libkernaux.a + %.c.o: %.c $(CC) -c $< -o $@ $(CFLAGS) diff --git a/examples/bootloader-multiboot2-limine/build-libkernaux/.keep b/examples/bootloader-multiboot2-limine/build-libkernaux/.keep new file mode 100644 index 0000000..e69de29 diff --git a/examples/bootloader-stivale2-limine/.gitignore b/examples/bootloader-stivale2-limine/.gitignore index d9e790b..f4d8c1d 100644 --- a/examples/bootloader-stivale2-limine/.gitignore +++ b/examples/bootloader-stivale2-limine/.gitignore @@ -1,3 +1,6 @@ +/build-libkernaux/* +!/build-libkernaux/.keep + /image.iso /main.c.d /output.txt diff --git a/examples/bootloader-stivale2-limine/Makefile b/examples/bootloader-stivale2-limine/Makefile index b27f3fc..df57b3c 100644 --- a/examples/bootloader-stivale2-limine/Makefile +++ b/examples/bootloader-stivale2-limine/Makefile @@ -5,11 +5,13 @@ CCPREFIX = ../../vendor/cross/bin/x86_64-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc +CONFIG_LIBKERNAUX = ../../config/x86_64-stivale2 DIFF = diff LIMINE = ../../vendor/limine/build/bin QEMU = qemu-system-x86_64 XORRISO = xorriso +BUILD_LIBKERNAUX = build-libkernaux EXPECTED = expected.txt IMAGE = image.iso LINKERSCR = linker.ld @@ -63,14 +65,15 @@ run: $(IMAGE) $(QEMU) -cdrom $< -serial stdio -display none | tee $(OUTPUT) clean: + make -C $(BUILD_LIBKERNAUX) distclean || true rm -f $(OUTPUT) $(IMAGE) $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) $(OBJS) $(IMAGE): $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) $(XORRISO) -as mkisofs -b $(REL_LIMINE_CD) -no-emul-boot -boot-load-size 4 -boot-info-table --efi-boot $(REL_LIMINE_ELTORITO) -efi-boot-part --efi-boot-image --protective-msdos-label $(ROOTFS) -o $@ $(LIMINE_INSTALL) $@ -$(FULL_KERNEL): $(LINKERSCR) $(OBJS) - $(CC) -T $(LINKERSCR) -o $@ $(OBJS) -ffreestanding -nostdlib -zmax-page-size=0x1000 -static -lgcc # -lkernaux -Wl,-L../.. +$(FULL_KERNEL): $(LINKERSCR) $(OBJS) build-libkernaux.a + $(CC) -T $(LINKERSCR) -o $@ $(OBJS) -ffreestanding -nostdlib -zmax-page-size=0x1000 -static -lgcc -lkernaux -Wl,-L$(BUILD_LIBKERNAUX) $(FULL_LIMINE_CD): cp -f $(LIMINE_CD) $(FULL_LIMINE_CD) @@ -81,6 +84,10 @@ $(FULL_LIMINE_ELTORITO): $(FULL_LIMINE_SYS): cp -f $(LIMINE_SYS) $(FULL_LIMINE_SYS) +build-libkernaux.a: + cd $(BUILD_LIBKERNAUX) && ../$(CONFIG_LIBKERNAUX) + cd $(BUILD_LIBKERNAUX) && make libkernaux.a + %.c.o: %.c $(CC) -c $< -o $@ $(CFLAGS) diff --git a/examples/bootloader-stivale2-limine/build-libkernaux/.keep b/examples/bootloader-stivale2-limine/build-libkernaux/.keep new file mode 100644 index 0000000..e69de29