#!/bin/sh

echo "getting sources..."
  svn co http://xbmc.svn.sourceforge.net/svnroot/xbmc/branches/Dharma/ xbmc-dharma-latest

echo "getting version..."
  cd xbmc-dharma-latest
    SVN_REV=`LANG=C svn info 2>/dev/null | grep Revision: | sed -e 's/.*\: //'`
    echo $SVN_REV
  cd ..

echo "copying sources..."
  rm -rf xbmc-dharma-$SVN_REV
  cp -R xbmc-dharma-latest xbmc-dharma-$SVN_REV
  echo "$SVN_REV" > xbmc-dharma-$SVN_REV/svn.version

echo "cleaning sources..."
  find xbmc-dharma-$SVN_REV -name .svn -exec rm -rf {} ";"

echo "seperating theme..."
  rm -rf xbmc-theme-Confluence-$SVN_REV
  mv xbmc-dharma-$SVN_REV/addons/skin.confluence xbmc-dharma-theme-Confluence-$SVN_REV

echo "cleaning sources..."
  rm -rf xbmc-dharma-$SVN_REV/visualisations
  rm -rf xbmc-dharma-$SVN_REV/lib/libSDL-*
  rm -rf xbmc-dharma-$SVN_REV/lib/libcurl-*
  rm -rf xbmc-dharma-$SVN_REV/project

  for i in "Changelog" "Fake\ Episode\ Maker" "MingwBuildEnvironment" \
           "PackageMaker" "Translator" "XBMCLive" "XprPack" \
           "HardwareConfigure" "Mach5" "osx" "UpdateThumbs.py" "XBMCTex"; do
    rm -rf xbmc-dharma-$SVN_REV/tools/$i
  done

  for i in dll a lib so bat; do
    find xbmc-dharma-$SVN_REV -name *.$i -exec rm -rf {} ";"
  done

  # bundled win32 binaries
  rm -r xbmc-dharma-$SVN_REV/xbmc/visualizations/XBMCProjectM/win32

echo "packing sources..."
  tar cvjf xbmc-dharma-$SVN_REV.tar.bz2 xbmc-dharma-$SVN_REV
  tar cvjf xbmc-dharma-theme-Confluence-$SVN_REV.tar.bz2 xbmc-dharma-theme-Confluence-$SVN_REV

echo "remove temporary sourcedir..."
  rm -rf xbmc-dharma-$SVN_REV
  rm -rf xbmc-dharma-theme-Confluence-$SVN_REV
