From f671adba0656ad5ae67180dce9570d8f2bd9bef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uko=20Kok=C5=86evi=C4=8Ds?= Date: Wed, 20 Jul 2022 16:42:13 +0300 Subject: [PATCH] Make build system more portable --- config.sh | 12 ++++++++++++ iso.sh | 2 +- kernel/Makefile | 8 ++++---- libc/Makefile | 6 +++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/config.sh b/config.sh index 6299fc0..7b8871f 100755 --- a/config.sh +++ b/config.sh @@ -21,6 +21,18 @@ export CPPFLAGS='' export SYSROOT="$(pwd)/sysroot" export CC="$CC --sysroot=$SYSROOT" +if command -V grub2-file >/dev/null 2>&1; then + export GRUB_FILE="grub2-file" +else + export GRUB_FILE="grub-file" +fi + +if command -V grub2-mkrescue >/dev/null 2>&1; then + export GRUB_MKRESCUE="grub2-mkrescue" +else + export GRUB_MKRESCUE="grub-mkrescue" +fi + # Work around that the -elf gcc targets doesn't have a system include directory # because it was configured with --without-headers rather than --with-sysroot. if echo "$HOST" | grep -Eq -- '-elf($|-)'; then diff --git a/iso.sh b/iso.sh index 565c179..5cd3fd7 100755 --- a/iso.sh +++ b/iso.sh @@ -12,4 +12,4 @@ menuentry "rockOS" { multiboot /boot/rockos.kernel } EOF -grub2-mkrescue -o rockos.iso isodir +"${GRUB_MKRESCUE}" -o rockos.iso isodir diff --git a/kernel/Makefile b/kernel/Makefile index cef1f87..5f1701f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,6 +1,6 @@ -DEFAULT_HOST!=../default-host.sh +DEFAULT_HOST=$(shell ../default-host.sh) HOST?=DEFAULT_HOST -HOSTARCH!=../target-triplet-to-arch.sh $(HOST) +HOSTARCH=$(shell ../target-triplet-to-arch.sh $(HOST)) CFLAGS?=-O3 -g CPPFLAGS?= @@ -55,7 +55,7 @@ all: rockos.kernel rockos.kernel: $(OBJS) $(ARCHDIR)/linker.ld $(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST) - grub2-file --is-x86-multiboot rockos.kernel + $(GRUB_FILE) --is-x86-multiboot rockos.kernel $(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o: OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@ @@ -75,7 +75,7 @@ install: install-headers install-kernel install-headers: mkdir -p $(DESTDIR)$(INCLUDEDIR) - cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/. + cp -Rp include/. $(DESTDIR)$(INCLUDEDIR)/. install-kernel: rockos.kernel mkdir -p $(DESTDIR)$(BOOTDIR) diff --git a/libc/Makefile b/libc/Makefile index 49639af..cd77597 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -1,6 +1,6 @@ -DEFAULT_HOST!=../default-host.sh +DEFAULT_HOST=$(shell ../default-host.sh) HOST?=DEFAULT_HOST -HOSTARCH!=../target-triplet-to-arch.sh $(HOST) +HOSTARCH=$(shell ../target-triplet-to-arch.sh $(HOST)) CFLAGS?=-O3 -g CPPFLAGS?= @@ -89,7 +89,7 @@ install: install-headers install-libs install-headers: mkdir -p $(DESTDIR)$(INCLUDEDIR) - cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/. + cp -Rp include/. $(DESTDIR)$(INCLUDEDIR)/. install-libs: $(BINARIES) mkdir -p $(DESTDIR)$(LIBDIR)