#!/bin/bash
   echo "RetroForth, Release 6"
   echo "-----------------------------------------------------------"
if [ $1 ]; then

if [ $1 == "native" ]; then
echo "Building Native"
  nasm retro.asm -oretro -Dplatform.native -DVGA
  nasm loaders/dos.asm -oimages/retro.com
  nasm loaders/fat12.asm -oimages/fat12
  nasm loaders/raw.asm -oimages/rawfloppy
fi

if [ $1 == "linux" ]; then
echo "Building Linux"

  echo "  Console"
  nasm retro.asm -felf -oretro.o -Dplatform.linux -g
  ld retro.o -oimages/rf
  chmod u+s images/rf

  echo "  svgalib"
  nasm retro.asm -felf -oretro.o -Dplatform.linux.vga -DVGA -g
  gcc retro.o -lvga -oimages/rf-vga
  chmod u+s images/rf-vga

  echo "  SDL"
  nasm retro.asm -felf -oretro.o -Dplatform.linux.sdl -DVGA -g
  gcc retro.o -lsdl -oimages/rf-sdl
  chmod u+s images/rf-sdl

  if [ $2 == "-s" ]; then
    echo "Stripping debug information..."
    strip images/rf*
  fi
fi


else
   echo "To use the build script, call with the name of the port you"
   echo "wish to build."
   echo ""
   echo "To build the linux port(s), do:"
   echo "  ./build linux"
   echo ""
   echo "Valid ports are: native linux"
   echo "Adding a '-s' after the port name will strip debugging info"
fi

echo "Cleaning up..."
  rm -f retro.o
  rm -f retro
