Reformatting project structure 2: Added shell scripts

This commit is contained in:
lucic71 2022-06-28 19:40:51 +03:00
parent 7e177539b3
commit a694be4662
8 changed files with 83 additions and 0 deletions

7
build.sh Executable file
View File

@ -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

11
clean.sh Executable file
View File

@ -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

28
config.sh Executable file
View File

@ -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

2
default-host.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo i686-elf

9
headers.sh Executable file
View File

@ -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

15
iso.sh Executable file
View File

@ -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

5
qemu.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
set -e
. ./iso.sh
qemu-system-$(./target-triplet-to-arch.sh $HOST) -cdrom os.iso

6
target-triplet-to-arch.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
if echo "$1" | grep -Eq 'i[[:digit:]]86-'; then
echo i386
else
echo "$1" | grep -Eo '^[[:alnum:]_]*'
fi