c1ad0fc5/1/2026, 8:41:11 PM
~build.sh
.sh
Shell
(text/x-sh)
#!/bin/sh
set -e

# build.sh - builds the TinyCrystalOS prototype (kernel + ISO)
# Place this at the project root (same dir as Makefile). Run: chmod +x build.sh && ./build.sh

# Ensure required tools
echo "Checking toolchain..."
for cmd in gcc ld objcopy grub-mkrescue qemu-system-x86_64; do
  if ! command -v "$cmd" >/dev/null 2>&1; then
    echo "Warning: $cmd not found."
  fi
done

# Build kernel and modules via Makefile
echo "Building project using Makefile..."
if [ ! -f Makefile ]; then
  echo "Makefile not found in current directory."
  exit 1
fi

make clean || true
if ! make; then
  echo "Build failed."
  exit 1
fi

# Optionally create ISO if grub-mkrescue exists
if command -v grub-mkrescue >/dev/null 2>&1; then
  echo "Creating ISO with grub-mkrescue..."
  # Ensure iso/boot/grub/grub.cfg exists (Makefile should have created it)
  if [ ! -f iso/boot/grub/grub.cfg ]; then
    echo "GRUB config not found, creating default grub.cfg..."
    mkdir -p iso/boot/grub
    cat > iso/boot/grub/grub.cfg <<'EOF'
set timeout=0
set default=0
menuentry "CrystalOS" {
  multiboot2 /boot/kernel.bin
}
EOF
  fi
  grub-mkrescue -o tinyos.iso iso || { echo "grub-mkrescue failed"; exit 1; }
  echo "ISO created: tinyos.iso"
else
  echo "grub-mkrescue not available; skip ISO creation. kernel.bin produced."
fi

# Optionally create a compressed archive of the build
ARCHIVE="tinycrystalos-build.tar.gz"
echo "Packaging build artifacts into $ARCHIVE..."
tar -czf "$ARCHIVE" kernel.bin kernel/*.o modules/*.o modules/*.c kernel/*.c kernel/*.S kernel/linker.ld || true
echo "Packaged build artifacts."

echo "Done."
echo "To run in QEMU (if tinyos.iso was created):"
echo "  qemu-system-x86_64 -cdrom tinyos.iso -m 512"