#!/bin/sh
################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
#  This Program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  This Program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with OpenELEC.tv; see the file COPYING.  If not, write to
#  the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

echo "getting Mozilla sources..."
  [ ! -d fennec-latest ] && \
  hg clone http://hg.mozilla.org/mozilla-central fennec-latest || \
  cd fennec-latest && \
    hg pull && \
    hg update && \
  cd ..

echo "getting Fennec sources..."
  [ ! -d fennec-latest/mobile ] && \
  hg clone http://hg.mozilla.org/mobile-browser fennec-latest/mobile || \
  cd fennec-latest/mobile && \
    hg pull && \
    hg update && \
  cd ../..

echo "getting Mozilla Revision..."
  cd fennec-latest
    MOZ_REV=`LANG=C hg tip --template={rev}`
  cd ..

echo "getting Fennec Revision..."
  cd fennec-latest/mobile
    FEN_REV=`LANG=C hg tip --template={rev}`
  cd ../..

echo "copying sources..."
  rm -rf fennec-$MOZ_REV.$FEN_REV
  cp -R fennec-latest fennec-$MOZ_REV.$FEN_REV

echo "creating configfiles..."
  cd fennec-$MOZ_REV.$FEN_REV
    autoconf-2.13
    rm -rf autom*
  cd ..

echo "cleaning sources..."
  find fennec-$MOZ_REV.$FEN_REV -name ".hg*" -exec rm -rf {} ";"

echo "packing sources..."
  tar cvjf fennec-$MOZ_REV.$FEN_REV.tar.bz2 fennec-$MOZ_REV.$FEN_REV

echo "remove temporary sourcedir..."
  rm -rf fennec-$MOZ_REV.$FEN_REV
