From a694be46628d02844eff053adf5b0ad7881bc70f Mon Sep 17 00:00:00 2001 From: lucic71 Date: Tue, 28 Jun 2022 19:40:51 +0300 Subject: [PATCH] Reformatting project structure 2: Added shell scripts --- build.sh | 7 +++++++ clean.sh | 11 +++++++++++ config.sh | 28 ++++++++++++++++++++++++++++ default-host.sh | 2 ++ headers.sh | 9 +++++++++ iso.sh | 15 +++++++++++++++ qemu.sh | 5 +++++ target-triplet-to-arch.sh | 6 ++++++ 8 files changed, 83 insertions(+) create mode 100755 build.sh create mode 100755 clean.sh create mode 100755 config.sh create mode 100755 default-host.sh create mode 100755 headers.sh create mode 100755 iso.sh create mode 100755 qemu.sh create mode 100755 target-triplet-to-arch.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..ac56821 --- /dev/null +++ b/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +. ./headers.sh + +for PROJECT in $PROJECTS; do + (echo "\nMoving in $PROJECT" && cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install) +done diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..30878ba --- /dev/null +++ b/clean.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e +. ./config.sh + +for PROJECT in $PROJECTS; do + (echo "\nMoving in $PROJECT" && cd $PROJECT && $MAKE clean) +done + +rm -rf sysroot +rm -rf isodir +rm -rf os.iso diff --git a/config.sh b/config.sh new file mode 100755 index 0000000..a662e38 --- /dev/null +++ b/config.sh @@ -0,0 +1,28 @@ +SYSTEM_HEADER_PROJECTS="libc kernel" +PROJECTS="libc kernel" + +export MAKE=${MAKE:-make} +export HOST=${HOST:-$(./default-host.sh)} + +export AR=${HOST}-ar +export AS=${HOST}-as +export CC=${HOST}-gcc + +export PREFIX=/usr +export EXEC_PREFIX=$PREFIX +export BOOTDIR=/boot +export LIBDIR=$EXEC_PREFIX/lib +export INCLUDEDIR=$PREFIX/include + +export CFLAGS='-g3' +export CPPFLAGS='' + +# Configure the cross-compiler to use the desired system root. +export SYSROOT="$(pwd)/sysroot" +export CC="$CC --sysroot=$SYSROOT" + +# 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 + export CC="$CC -isystem=$INCLUDEDIR" +fi diff --git a/default-host.sh b/default-host.sh new file mode 100755 index 0000000..7e0f795 --- /dev/null +++ b/default-host.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo i686-elf diff --git a/headers.sh b/headers.sh new file mode 100755 index 0000000..41e8255 --- /dev/null +++ b/headers.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e +. ./config.sh + +mkdir -p $SYSROOT + +for PROJECT in $SYSTEM_HEADER_PROJECTS; do + (echo "\nMoving to $PROJECT" && cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install-headers) +done diff --git a/iso.sh b/iso.sh new file mode 100755 index 0000000..12bb4b6 --- /dev/null +++ b/iso.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -e +. ./build.sh + +mkdir -p isodir +mkdir -p isodir/boot +mkdir -p isodir/boot/grub + +cp sysroot/boot/os.kernel isodir/boot/os.kernel +cat > isodir/boot/grub/grub.cfg << EOF +menuentry "os" { + multiboot /boot/os.kernel +} +EOF +grub-mkrescue -o os.iso isodir diff --git a/qemu.sh b/qemu.sh new file mode 100755 index 0000000..238371d --- /dev/null +++ b/qemu.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +. ./iso.sh + +qemu-system-$(./target-triplet-to-arch.sh $HOST) -cdrom os.iso diff --git a/target-triplet-to-arch.sh b/target-triplet-to-arch.sh new file mode 100755 index 0000000..3557285 --- /dev/null +++ b/target-triplet-to-arch.sh @@ -0,0 +1,6 @@ +#!/bin/sh +if echo "$1" | grep -Eq 'i[[:digit:]]86-'; then + echo i386 +else + echo "$1" | grep -Eo '^[[:alnum:]_]*' +fi