#!/bin/bash
if [[ `uname` == MINGW64* ]]
then 
   MAMEHOME=/c/prg/mame
   SCRP=mameprep_msys2
   SUFF=".exe"
else
   MAMEHOME=$HOME/mame
   SCRP=mameprep
   SUFF=""
fi

test -d $MAMEHOME || mkdir -p $MAMEHOME

# Install programs
for prg in castool chdman floptool imgtool jedutil ldresample ldverify nltool nlwav pngcmp regrep romcmp split testkeys unidasm mame mamed 
do
   if [ -f mame/${prg}${SUFF} ]
   then
      cp mame/${prg}${SUFF} $MAMEHOME/
   fi
done

cp mameprep* $MAMEHOME/

# Install support files
for supp in artwork bgfx ctrlr docs hash hlsl ini language plugins roms samples
do
   cp -R mame/$supp $MAMEHOME
done

if [ ! -f $MAMEHOME/roms/ti99_4a.zip ]
then
   echo "This is obviously the first time you install MAME. We need to fetch the"
   echo "ROMs from the server and create some start batch files."
   echo "For that, please go to the MAME installation directory (cd $MAMEHOME)"
   echo "and run ./$SCRP from there."
fi

cd $MAMEHOME
