# cerbero - a multi-platform build system for Open Source software
# Copyright (C) 2012 Andoni Morales Alastruey <ylatuya@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

import os
import tempfile
import shutil

from cerbero.bootstrap import BootstraperBase
from cerbero.bootstrap.bootstraper import register_bootstraper
from cerbero.config import Distro, DistroVersion
from cerbero.utils import shell


class OSXBootstraper (BootstraperBase):

    GCC_BASE_URL = 'https://github.com/downloads/kennethreitz/'\
                   'osx-gcc-installer/'
    GCC_TAR = {
        DistroVersion.OS_X_MOUNTAIN_LION: 'GCC-10.7-v2.pkg',
        DistroVersion.OS_X_LION: 'GCC-10.7-v2.pkg',
        DistroVersion.OS_X_SNOW_LEOPARD: 'GCC-10.6.pkg'}

    def start(self):
        # FIXME: enable it when buildbots are properly configured
        return
        tar = self.GCC_TAR[self.config.distro_version]
        url = os.path.join(self.GCC_BASE_URL, tar)
        pkg = os.path.join(self.config.local_sources, tar)
        shell.download(url, pkg, check_cert=False)
        shell.call('sudo installer -pkg %s -target /' % pkg)


def register_all():
    register_bootstraper(Distro.OS_X, OSXBootstraper)

@@ -1425,29 +1425,136 @@
 g'%7D%0A
-%0A    def start(self):
+    CPANM_URL = 'https://raw.github.com/miyagawa/cpanminus/master/cpanm'%0A%0A    def start(self):%0A        self._install_perl_deps()
 %0A   
@@ -1909,16 +1909,384 @@
 %25 pkg)%0A%0A
+    def _install_perl_deps(self):%0A        # Install cpan-minus, a zero-conf CPAN wrapper%0A        cpanm_installer = tempfile.NamedTemporaryFile().name%0A        shell.download(self.CPANM_URL, cpanm_installer)%0A        shell.call('chmod +x %25s' %25 cpanm_installer)%0A        # Install XML::Parser, required for intltool%0A        shell.call(%22%25s XML::Parser%22 %25 cpanm_installer)%0A%0A%0A
 %0Adef reg

install XML::Parse required for intltool