# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shutil

from cerbero.errors import FatalError
from cerbero.utils import shell
from cerbero.build.build import modify_environment
from cerbero.build.filesprovider import FilesProvider

class Recipe(recipe.Recipe):
    name = 'longomatch-coes'
    version = '0.20.3'
    licenses = [License.GPL]
    remotes = {'origin': 'git@github.com:ylatuya/longomatch.git'}
    config_sh = 'sh autogen.sh'
    commit = 'origin/coes'
    deps = ['gstreamer', 'gst-plugins-base', 'libav']

    platform_deps = {
        Platform.WINDOWS: ['longomatch-deps'],
        Platform.LINUX: ['mono', 'mono-addins', 'db4o', 'gtk-sharp'],
        Platform.DARWIN: ['mono', 'mono-addins', 'db4o', 'gtk-sharp'],
        }

    files_bins = ['avconv']
    platform_files_libs = {
        Platform.DARWIN: ['libcesarplayer'],
        Platform.WINDOWS: ['libcesarplayer'],
    }
    files_lang = ['longomatch']
    files_share = ['share/longomatch']
    files_plugins = ['lib/longomatch/plugins']
    files_mscorlib = [
        'lib/mono/4.0/mscorlib.dll',]
    files_mono = [
        'lib/mono/4.0/Mono.Cairo.dll',
        'lib/mono/4.0/Mono.Posix.dll',
        'lib/mono/4.0/Mono.Security.dll',
        'lib/mono/4.0/Mono.Security.dll',
        'lib/mono/4.0/WindowsBase.dll',
        'lib/mono/4.0/System.dll',
        'lib/mono/4.0/System.Configuration.dll',
        'lib/mono/4.0/System.Core.dll',
        'lib/mono/4.0/System.Drawing.dll',
        'lib/mono/4.0/System.Xml.dll',
        'lib/mono/4.0/System.Xaml.dll',
        'lib/mono/4.0/System.Security.dll',
        'lib/mono/mono-addins/Mono.Addins.dll',
    ]
    files_longomatch = [
        'lib/longomatch/LongoMatch.Addins.dll',
        'lib/longomatch/LongoMatch.Addins.dll.mdb',
        'lib/longomatch/LongoMatch.GUI.Multimedia.dll',
        'lib/longomatch/LongoMatch.GUI.dll',
        'lib/longomatch/LongoMatch.GUI.dll.mdb',
        'lib/longomatch/LongoMatch.Multimedia.dll',
        'lib/longomatch/LongoMatch.Multimedia.dll.config',
        'lib/longomatch/LongoMatch.Multimedia.dll.mdb',
        'lib/longomatch/LongoMatch.Services.dll',
        'lib/longomatch/LongoMatch.Services.dll.mdb',
        'lib/longomatch/LongoMatch.dll',
        'lib/longomatch/LongoMatch.dll.mdb',
        'lib/longomatch/OxyPlotMono.dll',
        'lib/longomatch/LongoMatchGtk.exe',
        'lib/longomatch/plugins',
    ]
    platform_files_longomatch = {
        Platform.DARWIN: [
            'lib/longomatch/libcesarplayer.0.dylib'
        ],
        # We need a copy of LongoMatch.Addins in the same folder as LongoMatchGtk.exe
        Platform.WINDOWS: [
            'bin/LongoMatch.Addins.dll',
        ]
    }
    platform_files_mono = {
        Platform.DARWIN: [
            'lib/cli/Db4objects.Db4o-8.0/Db4objects.Db4o.dll',
        ],
        Platform.WINDOWS: [
            'lib/mono/db4o/Db4objects.Db4o.dll',
        ],
    }
    platform_files_bin = {
        Platform.WINDOWS: ['%(sdir)s/LongoMatchGtk.exe'],
    }
    platform_files_bins = {
        Platform.DARWIN: ['longomatch'],
        Platform.LINUX: ['longomatch']
    }

    platform_files_share = {
        Platform.LINUX: ['share/applications/longomatch.desktop',
                         'share/icons/hicolor/48x48/apps/longomatch.png',
                         'share/icons/hicolor/scalable/apps/longomatch.svg']
    }
    platform_files_deps = {
        Platform.WINDOWS: [
            'bin/zlib1.dll', 'bin/intl.dll', 'bin/mono-2.0.dll',
            'bin/MonoPosixHelper.dll', 'bin/atksharpglue-2.dll',
            'bin/gdksharpglue-2.dll', 'bin/gdksharpglue-2.dll',
            'bin/glibsharpglue-2.dll', 'bin/gtksharpglue-2.dll',
            'bin/pangosharpglue-2.dll']
            }

    def prepare(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            search_paths = ['lib/longomatch', 'lib/cli/Db4objects.Db4o-8.0']
            search_paths = [os.path.join(self.config.prefix, f) for f in search_paths]
            if self.config.target_platform == Platform.WINDOWS:
                self.new_env['MONO_PATH'] = ';'.join(search_paths)
                sdir = 'bin'
            else:
                self.new_env['MONO_PATH'] = ':'.join(search_paths)
                sdir = 'lib/mono/4.0'
            if self.config.target_platform == Platform.DARWIN:
                self.new_env['AS'] = 'as -arch i386'
            cc = os.environ.get('CC', 'gcc')
            self.new_env['CC'] = '%s %s' % (cc, os.environ['CFLAGS'])

    @modify_environment
    def post_install(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            longomatchlib = os.path.join(self.config.prefix, 'lib', 'longomatch')
            if self.config.target_platform == Platform.WINDOWS:
                dll = 'libcesarplayer-0%(srext)s' % self.extensions
                libcesarplayer = os.path.join(longomatchlib, dll)
                shutil.copy(os.path.join(longomatchlib, '..', 'bin', dll),
                            libcesarplayer)
                shutil.copy(os.path.join(longomatchlib, 'LongoMatch.Addins.dll'),
                            os.path.join(self.config.prefix, 'bin'))
                libdir = os.path.join(self.config.prefix, 'bin')
            elif self.config.target_platform == Platform.DARWIN:
                libcesarplayer = os.path.join(longomatchlib,
                    'libcesarplayer.0%(srext)s' % self.extensions)
                libdir = os.path.join(self.config.prefix, 'lib', 'mono', '4.0')
            bindir = os.path.join(self.config.prefix, 'bin')
            shutil.copy(libcesarplayer, libdir)

            if self.config.target_platform == Platform.WINDOWS:
                binary = os.path.join(self.config.prefix, self.extensions['sdir'],
                        'LongoMatchGtk.exe')
                assembly = os.path.join(longomatchlib, 'LongoMatchGtk.exe')
                mkbundle = 'mkbundle -o %s %s --config %s --nodeps --keeptemp ' % (binary, assembly,
                        os.path.join(self.config.prefix, 'etc', 'mono', 'config'))
                shell.call(mkbundle, self.build_dir)
                rebuild_bundle = '$CC $CFLAGS -o %s %s `pkg-config --cflags --libs mono-2 glib-2.0` temp.o' % \
                    (binary, self.relative_path ('temp.c'))
                shell.call(rebuild_bundle, self.build_dir)

8c349976ead957c5f969c98bdd38c237e8b001d8
<mask token>


class Recipe(recipe.Recipe):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    @modify_environment
    def post_install(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            longomatchlib = os.path.join(self.config.prefix, 'lib',
                'longomatch')
            if self.config.target_platform == Platform.WINDOWS:
                dll = 'libcesarplayer-0%(srext)s' % self.extensions
                libcesarplayer = os.path.join(longomatchlib, dll)
                shutil.copy(os.path.join(longomatchlib, '..', 'bin', dll),
                    libcesarplayer)
                shutil.copy(os.path.join(longomatchlib,
                    'LongoMatch.Addins.dll'), os.path.join(self.config.
                    prefix, 'bin'))
                libdir = os.path.join(self.config.prefix, 'bin')
            elif self.config.target_platform == Platform.DARWIN:
                libcesarplayer = os.path.join(longomatchlib, 
                    'libcesarplayer.0%(srext)s' % self.extensions)
                libdir = os.path.join(self.config.prefix, 'lib', 'mono', '4.0')
            bindir = os.path.join(self.config.prefix, 'bin')
            shutil.copy(libcesarplayer, libdir)
            if self.config.target_platform == Platform.WINDOWS:
                binary = os.path.join(self.config.prefix, self.extensions[
                    'sdir'], 'LongoMatchGtk.exe')
                assembly = os.path.join(longomatchlib, 'LongoMatchGtk.exe')
                mkbundle = (
                    'mkbundle -o %s %s --config %s --nodeps --keeptemp ' %
                    (binary, assembly, os.path.join(self.config.prefix,
                    'etc', 'mono', 'config')))
                shell.call(mkbundle, self.build_dir)
                rebuild_bundle = (
                    '$CC $CFLAGS -o %s %s `pkg-config --cflags --libs mono-2 glib-2.0` temp.o'
                     % (binary, self.relative_path('temp.c')))
                shell.call(rebuild_bundle, self.build_dir)

<mask token>


class Recipe(recipe.Recipe):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def prepare(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            search_paths = ['lib/longomatch', 'lib/cli/Db4objects.Db4o-8.0']
            search_paths = [os.path.join(self.config.prefix, f) for f in
                search_paths]
            if self.config.target_platform == Platform.WINDOWS:
                self.new_env['MONO_PATH'] = ';'.join(search_paths)
                sdir = 'bin'
            else:
                self.new_env['MONO_PATH'] = ':'.join(search_paths)
                sdir = 'lib/mono/4.0'
            if self.config.target_platform == Platform.DARWIN:
                self.new_env['AS'] = 'as -arch i386'
            cc = os.environ.get('CC', 'gcc')
            self.new_env['CC'] = '%s %s' % (cc, os.environ['CFLAGS'])

    @modify_environment
    def post_install(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            longomatchlib = os.path.join(self.config.prefix, 'lib',
                'longomatch')
            if self.config.target_platform == Platform.WINDOWS:
                dll = 'libcesarplayer-0%(srext)s' % self.extensions
                libcesarplayer = os.path.join(longomatchlib, dll)
                shutil.copy(os.path.join(longomatchlib, '..', 'bin', dll),
                    libcesarplayer)
                shutil.copy(os.path.join(longomatchlib,
                    'LongoMatch.Addins.dll'), os.path.join(self.config.
                    prefix, 'bin'))
                libdir = os.path.join(self.config.prefix, 'bin')
            elif self.config.target_platform == Platform.DARWIN:
                libcesarplayer = os.path.join(longomatchlib, 
                    'libcesarplayer.0%(srext)s' % self.extensions)
                libdir = os.path.join(self.config.prefix, 'lib', 'mono', '4.0')
            bindir = os.path.join(self.config.prefix, 'bin')
            shutil.copy(libcesarplayer, libdir)
            if self.config.target_platform == Platform.WINDOWS:
                binary = os.path.join(self.config.prefix, self.extensions[
                    'sdir'], 'LongoMatchGtk.exe')
                assembly = os.path.join(longomatchlib, 'LongoMatchGtk.exe')
                mkbundle = (
                    'mkbundle -o %s %s --config %s --nodeps --keeptemp ' %
                    (binary, assembly, os.path.join(self.config.prefix,
                    'etc', 'mono', 'config')))
                shell.call(mkbundle, self.build_dir)
                rebuild_bundle = (
                    '$CC $CFLAGS -o %s %s `pkg-config --cflags --libs mono-2 glib-2.0` temp.o'
                     % (binary, self.relative_path('temp.c')))
                shell.call(rebuild_bundle, self.build_dir)

<mask token>


class Recipe(recipe.Recipe):
    name = 'longomatch-coes'
    version = '0.20.3'
    licenses = [License.GPL]
    remotes = {'origin': 'git@github.com:ylatuya/longomatch.git'}
    config_sh = 'sh autogen.sh'
    commit = 'origin/coes'
    deps = ['gstreamer', 'gst-plugins-base', 'libav']
    platform_deps = {Platform.WINDOWS: ['longomatch-deps'], Platform.LINUX:
        ['mono', 'mono-addins', 'db4o', 'gtk-sharp'], Platform.DARWIN: [
        'mono', 'mono-addins', 'db4o', 'gtk-sharp']}
    files_bins = ['avconv']
    platform_files_libs = {Platform.DARWIN: ['libcesarplayer'], Platform.
        WINDOWS: ['libcesarplayer']}
    files_lang = ['longomatch']
    files_share = ['share/longomatch']
    files_plugins = ['lib/longomatch/plugins']
    files_mscorlib = ['lib/mono/4.0/mscorlib.dll']
    files_mono = ['lib/mono/4.0/Mono.Cairo.dll',
        'lib/mono/4.0/Mono.Posix.dll', 'lib/mono/4.0/Mono.Security.dll',
        'lib/mono/4.0/Mono.Security.dll', 'lib/mono/4.0/WindowsBase.dll',
        'lib/mono/4.0/System.dll', 'lib/mono/4.0/System.Configuration.dll',
        'lib/mono/4.0/System.Core.dll', 'lib/mono/4.0/System.Drawing.dll',
        'lib/mono/4.0/System.Xml.dll', 'lib/mono/4.0/System.Xaml.dll',
        'lib/mono/4.0/System.Security.dll',
        'lib/mono/mono-addins/Mono.Addins.dll']
    files_longomatch = ['lib/longomatch/LongoMatch.Addins.dll',
        'lib/longomatch/LongoMatch.Addins.dll.mdb',
        'lib/longomatch/LongoMatch.GUI.Multimedia.dll',
        'lib/longomatch/LongoMatch.GUI.dll',
        'lib/longomatch/LongoMatch.GUI.dll.mdb',
        'lib/longomatch/LongoMatch.Multimedia.dll',
        'lib/longomatch/LongoMatch.Multimedia.dll.config',
        'lib/longomatch/LongoMatch.Multimedia.dll.mdb',
        'lib/longomatch/LongoMatch.Services.dll',
        'lib/longomatch/LongoMatch.Services.dll.mdb',
        'lib/longomatch/LongoMatch.dll',
        'lib/longomatch/LongoMatch.dll.mdb',
        'lib/longomatch/OxyPlotMono.dll',
        'lib/longomatch/LongoMatchGtk.exe', 'lib/longomatch/plugins']
    platform_files_longomatch = {Platform.DARWIN: [
        'lib/longomatch/libcesarplayer.0.dylib'], Platform.WINDOWS: [
        'bin/LongoMatch.Addins.dll']}
    platform_files_mono = {Platform.DARWIN: [
        'lib/cli/Db4objects.Db4o-8.0/Db4objects.Db4o.dll'], Platform.
        WINDOWS: ['lib/mono/db4o/Db4objects.Db4o.dll']}
    platform_files_bin = {Platform.WINDOWS: ['%(sdir)s/LongoMatchGtk.exe']}
    platform_files_bins = {Platform.DARWIN: ['longomatch'], Platform.LINUX:
        ['longomatch']}
    platform_files_share = {Platform.LINUX: [
        'share/applications/longomatch.desktop',
        'share/icons/hicolor/48x48/apps/longomatch.png',
        'share/icons/hicolor/scalable/apps/longomatch.svg']}
    platform_files_deps = {Platform.WINDOWS: ['bin/zlib1.dll',
        'bin/intl.dll', 'bin/mono-2.0.dll', 'bin/MonoPosixHelper.dll',
        'bin/atksharpglue-2.dll', 'bin/gdksharpglue-2.dll',
        'bin/gdksharpglue-2.dll', 'bin/glibsharpglue-2.dll',
        'bin/gtksharpglue-2.dll', 'bin/pangosharpglue-2.dll']}

    def prepare(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            search_paths = ['lib/longomatch', 'lib/cli/Db4objects.Db4o-8.0']
            search_paths = [os.path.join(self.config.prefix, f) for f in
                search_paths]
            if self.config.target_platform == Platform.WINDOWS:
                self.new_env['MONO_PATH'] = ';'.join(search_paths)
                sdir = 'bin'
            else:
                self.new_env['MONO_PATH'] = ':'.join(search_paths)
                sdir = 'lib/mono/4.0'
            if self.config.target_platform == Platform.DARWIN:
                self.new_env['AS'] = 'as -arch i386'
            cc = os.environ.get('CC', 'gcc')
            self.new_env['CC'] = '%s %s' % (cc, os.environ['CFLAGS'])

    @modify_environment
    def post_install(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            longomatchlib = os.path.join(self.config.prefix, 'lib',
                'longomatch')
            if self.config.target_platform == Platform.WINDOWS:
                dll = 'libcesarplayer-0%(srext)s' % self.extensions
                libcesarplayer = os.path.join(longomatchlib, dll)
                shutil.copy(os.path.join(longomatchlib, '..', 'bin', dll),
                    libcesarplayer)
                shutil.copy(os.path.join(longomatchlib,
                    'LongoMatch.Addins.dll'), os.path.join(self.config.
                    prefix, 'bin'))
                libdir = os.path.join(self.config.prefix, 'bin')
            elif self.config.target_platform == Platform.DARWIN:
                libcesarplayer = os.path.join(longomatchlib, 
                    'libcesarplayer.0%(srext)s' % self.extensions)
                libdir = os.path.join(self.config.prefix, 'lib', 'mono', '4.0')
            bindir = os.path.join(self.config.prefix, 'bin')
            shutil.copy(libcesarplayer, libdir)
            if self.config.target_platform == Platform.WINDOWS:
                binary = os.path.join(self.config.prefix, self.extensions[
                    'sdir'], 'LongoMatchGtk.exe')
                assembly = os.path.join(longomatchlib, 'LongoMatchGtk.exe')
                mkbundle = (
                    'mkbundle -o %s %s --config %s --nodeps --keeptemp ' %
                    (binary, assembly, os.path.join(self.config.prefix,
                    'etc', 'mono', 'config')))
                shell.call(mkbundle, self.build_dir)
                rebuild_bundle = (
                    '$CC $CFLAGS -o %s %s `pkg-config --cflags --libs mono-2 glib-2.0` temp.o'
                     % (binary, self.relative_path('temp.c')))
                shell.call(rebuild_bundle, self.build_dir)

import shutil
from cerbero.errors import FatalError
from cerbero.utils import shell
from cerbero.build.build import modify_environment
from cerbero.build.filesprovider import FilesProvider


class Recipe(recipe.Recipe):
    name = 'longomatch-coes'
    version = '0.20.3'
    licenses = [License.GPL]
    remotes = {'origin': 'git@github.com:ylatuya/longomatch.git'}
    config_sh = 'sh autogen.sh'
    commit = 'origin/coes'
    deps = ['gstreamer', 'gst-plugins-base', 'libav']
    platform_deps = {Platform.WINDOWS: ['longomatch-deps'], Platform.LINUX:
        ['mono', 'mono-addins', 'db4o', 'gtk-sharp'], Platform.DARWIN: [
        'mono', 'mono-addins', 'db4o', 'gtk-sharp']}
    files_bins = ['avconv']
    platform_files_libs = {Platform.DARWIN: ['libcesarplayer'], Platform.
        WINDOWS: ['libcesarplayer']}
    files_lang = ['longomatch']
    files_share = ['share/longomatch']
    files_plugins = ['lib/longomatch/plugins']
    files_mscorlib = ['lib/mono/4.0/mscorlib.dll']
    files_mono = ['lib/mono/4.0/Mono.Cairo.dll',
        'lib/mono/4.0/Mono.Posix.dll', 'lib/mono/4.0/Mono.Security.dll',
        'lib/mono/4.0/Mono.Security.dll', 'lib/mono/4.0/WindowsBase.dll',
        'lib/mono/4.0/System.dll', 'lib/mono/4.0/System.Configuration.dll',
        'lib/mono/4.0/System.Core.dll', 'lib/mono/4.0/System.Drawing.dll',
        'lib/mono/4.0/System.Xml.dll', 'lib/mono/4.0/System.Xaml.dll',
        'lib/mono/4.0/System.Security.dll',
        'lib/mono/mono-addins/Mono.Addins.dll']
    files_longomatch = ['lib/longomatch/LongoMatch.Addins.dll',
        'lib/longomatch/LongoMatch.Addins.dll.mdb',
        'lib/longomatch/LongoMatch.GUI.Multimedia.dll',
        'lib/longomatch/LongoMatch.GUI.dll',
        'lib/longomatch/LongoMatch.GUI.dll.mdb',
        'lib/longomatch/LongoMatch.Multimedia.dll',
        'lib/longomatch/LongoMatch.Multimedia.dll.config',
        'lib/longomatch/LongoMatch.Multimedia.dll.mdb',
        'lib/longomatch/LongoMatch.Services.dll',
        'lib/longomatch/LongoMatch.Services.dll.mdb',
        'lib/longomatch/LongoMatch.dll',
        'lib/longomatch/LongoMatch.dll.mdb',
        'lib/longomatch/OxyPlotMono.dll',
        'lib/longomatch/LongoMatchGtk.exe', 'lib/longomatch/plugins']
    platform_files_longomatch = {Platform.DARWIN: [
        'lib/longomatch/libcesarplayer.0.dylib'], Platform.WINDOWS: [
        'bin/LongoMatch.Addins.dll']}
    platform_files_mono = {Platform.DARWIN: [
        'lib/cli/Db4objects.Db4o-8.0/Db4objects.Db4o.dll'], Platform.
        WINDOWS: ['lib/mono/db4o/Db4objects.Db4o.dll']}
    platform_files_bin = {Platform.WINDOWS: ['%(sdir)s/LongoMatchGtk.exe']}
    platform_files_bins = {Platform.DARWIN: ['longomatch'], Platform.LINUX:
        ['longomatch']}
    platform_files_share = {Platform.LINUX: [
        'share/applications/longomatch.desktop',
        'share/icons/hicolor/48x48/apps/longomatch.png',
        'share/icons/hicolor/scalable/apps/longomatch.svg']}
    platform_files_deps = {Platform.WINDOWS: ['bin/zlib1.dll',
        'bin/intl.dll', 'bin/mono-2.0.dll', 'bin/MonoPosixHelper.dll',
        'bin/atksharpglue-2.dll', 'bin/gdksharpglue-2.dll',
        'bin/gdksharpglue-2.dll', 'bin/glibsharpglue-2.dll',
        'bin/gtksharpglue-2.dll', 'bin/pangosharpglue-2.dll']}

    def prepare(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            search_paths = ['lib/longomatch', 'lib/cli/Db4objects.Db4o-8.0']
            search_paths = [os.path.join(self.config.prefix, f) for f in
                search_paths]
            if self.config.target_platform == Platform.WINDOWS:
                self.new_env['MONO_PATH'] = ';'.join(search_paths)
                sdir = 'bin'
            else:
                self.new_env['MONO_PATH'] = ':'.join(search_paths)
                sdir = 'lib/mono/4.0'
            if self.config.target_platform == Platform.DARWIN:
                self.new_env['AS'] = 'as -arch i386'
            cc = os.environ.get('CC', 'gcc')
            self.new_env['CC'] = '%s %s' % (cc, os.environ['CFLAGS'])

    @modify_environment
    def post_install(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            longomatchlib = os.path.join(self.config.prefix, 'lib',
                'longomatch')
            if self.config.target_platform == Platform.WINDOWS:
                dll = 'libcesarplayer-0%(srext)s' % self.extensions
                libcesarplayer = os.path.join(longomatchlib, dll)
                shutil.copy(os.path.join(longomatchlib, '..', 'bin', dll),
                    libcesarplayer)
                shutil.copy(os.path.join(longomatchlib,
                    'LongoMatch.Addins.dll'), os.path.join(self.config.
                    prefix, 'bin'))
                libdir = os.path.join(self.config.prefix, 'bin')
            elif self.config.target_platform == Platform.DARWIN:
                libcesarplayer = os.path.join(longomatchlib, 
                    'libcesarplayer.0%(srext)s' % self.extensions)
                libdir = os.path.join(self.config.prefix, 'lib', 'mono', '4.0')
            bindir = os.path.join(self.config.prefix, 'bin')
            shutil.copy(libcesarplayer, libdir)
            if self.config.target_platform == Platform.WINDOWS:
                binary = os.path.join(self.config.prefix, self.extensions[
                    'sdir'], 'LongoMatchGtk.exe')
                assembly = os.path.join(longomatchlib, 'LongoMatchGtk.exe')
                mkbundle = (
                    'mkbundle -o %s %s --config %s --nodeps --keeptemp ' %
                    (binary, assembly, os.path.join(self.config.prefix,
                    'etc', 'mono', 'config')))
                shell.call(mkbundle, self.build_dir)
                rebuild_bundle = (
                    '$CC $CFLAGS -o %s %s `pkg-config --cflags --libs mono-2 glib-2.0` temp.o'
                     % (binary, self.relative_path('temp.c')))
                shell.call(rebuild_bundle, self.build_dir)

# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shutil

from cerbero.errors import FatalError
from cerbero.utils import shell
from cerbero.build.build import modify_environment
from cerbero.build.filesprovider import FilesProvider

class Recipe(recipe.Recipe):
    name = 'longomatch-coes'
    version = '0.20.3'
    licenses = [License.GPL]
    remotes = {'origin': 'git@github.com:ylatuya/longomatch.git'}
    config_sh = 'sh autogen.sh'
    commit = 'origin/coes'
    deps = ['gstreamer', 'gst-plugins-base', 'libav']

    platform_deps = {
        Platform.WINDOWS: ['longomatch-deps'],
        Platform.LINUX: ['mono', 'mono-addins', 'db4o', 'gtk-sharp'],
        Platform.DARWIN: ['mono', 'mono-addins', 'db4o', 'gtk-sharp'],
        }

    files_bins = ['avconv']
    platform_files_libs = {
        Platform.DARWIN: ['libcesarplayer'],
        Platform.WINDOWS: ['libcesarplayer'],
    }
    files_lang = ['longomatch']
    files_share = ['share/longomatch']
    files_plugins = ['lib/longomatch/plugins']
    files_mscorlib = [
        'lib/mono/4.0/mscorlib.dll',]
    files_mono = [
        'lib/mono/4.0/Mono.Cairo.dll',
        'lib/mono/4.0/Mono.Posix.dll',
        'lib/mono/4.0/Mono.Security.dll',
        'lib/mono/4.0/Mono.Security.dll',
        'lib/mono/4.0/WindowsBase.dll',
        'lib/mono/4.0/System.dll',
        'lib/mono/4.0/System.Configuration.dll',
        'lib/mono/4.0/System.Core.dll',
        'lib/mono/4.0/System.Drawing.dll',
        'lib/mono/4.0/System.Xml.dll',
        'lib/mono/4.0/System.Xaml.dll',
        'lib/mono/4.0/System.Security.dll',
        'lib/mono/mono-addins/Mono.Addins.dll',
    ]
    files_longomatch = [
        'lib/longomatch/LongoMatch.Addins.dll',
        'lib/longomatch/LongoMatch.Addins.dll.mdb',
        'lib/longomatch/LongoMatch.GUI.Multimedia.dll',
        'lib/longomatch/LongoMatch.GUI.dll',
        'lib/longomatch/LongoMatch.GUI.dll.mdb',
        'lib/longomatch/LongoMatch.Multimedia.dll',
        'lib/longomatch/LongoMatch.Multimedia.dll.config',
        'lib/longomatch/LongoMatch.Multimedia.dll.mdb',
        'lib/longomatch/LongoMatch.Services.dll',
        'lib/longomatch/LongoMatch.Services.dll.mdb',
        'lib/longomatch/LongoMatch.dll',
        'lib/longomatch/LongoMatch.dll.mdb',
        'lib/longomatch/OxyPlotMono.dll',
        'lib/longomatch/LongoMatchGtk.exe',
        'lib/longomatch/plugins',
    ]
    platform_files_longomatch = {
        Platform.DARWIN: [
            'lib/longomatch/libcesarplayer.0.dylib'
        ],
        # We need a copy of LongoMatch.Addins in the same folder as LongoMatchGtk.exe
        Platform.WINDOWS: [
            'bin/LongoMatch.Addins.dll',
        ]
    }
    platform_files_mono = {
        Platform.DARWIN: [
            'lib/cli/Db4objects.Db4o-8.0/Db4objects.Db4o.dll',
        ],
        Platform.WINDOWS: [
            'lib/mono/db4o/Db4objects.Db4o.dll',
        ],
    }
    platform_files_bin = {
        Platform.WINDOWS: ['%(sdir)s/LongoMatchGtk.exe'],
    }
    platform_files_bins = {
        Platform.DARWIN: ['longomatch'],
        Platform.LINUX: ['longomatch']
    }

    platform_files_share = {
        Platform.LINUX: ['share/applications/longomatch.desktop',
                         'share/icons/hicolor/48x48/apps/longomatch.png',
                         'share/icons/hicolor/scalable/apps/longomatch.svg']
    }
    platform_files_deps = {
        Platform.WINDOWS: [
            'bin/zlib1.dll', 'bin/intl.dll', 'bin/mono-2.0.dll',
            'bin/MonoPosixHelper.dll', 'bin/atksharpglue-2.dll',
            'bin/gdksharpglue-2.dll', 'bin/gdksharpglue-2.dll',
            'bin/glibsharpglue-2.dll', 'bin/gtksharpglue-2.dll',
            'bin/pangosharpglue-2.dll']
            }

    def prepare(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            search_paths = ['lib/longomatch', 'lib/cli/Db4objects.Db4o-8.0']
            search_paths = [os.path.join(self.config.prefix, f) for f in search_paths]
            if self.config.target_platform == Platform.WINDOWS:
                self.new_env['MONO_PATH'] = ';'.join(search_paths)
                sdir = 'bin'
            else:
                self.new_env['MONO_PATH'] = ':'.join(search_paths)
                sdir = 'lib/mono/4.0'
            if self.config.target_platform == Platform.DARWIN:
                self.new_env['AS'] = 'as -arch i386'
            cc = os.environ.get('CC', 'gcc')
            self.new_env['CC'] = '%s %s' % (cc, os.environ['CFLAGS'])

    @modify_environment
    def post_install(self):
        if self.config.target_platform in [Platform.WINDOWS, Platform.DARWIN]:
            longomatchlib = os.path.join(self.config.prefix, 'lib', 'longomatch')
            if self.config.target_platform == Platform.WINDOWS:
                dll = 'libcesarplayer-0%(srext)s' % self.extensions
                libcesarplayer = os.path.join(longomatchlib, dll)
                shutil.copy(os.path.join(longomatchlib, '..', 'bin', dll),
                            libcesarplayer)
                shutil.copy(os.path.join(longomatchlib, 'LongoMatch.Addins.dll'),
                            os.path.join(self.config.prefix, 'bin'))
                libdir = os.path.join(self.config.prefix, 'bin')
            elif self.config.target_platform == Platform.DARWIN:
                libcesarplayer = os.path.join(longomatchlib,
                    'libcesarplayer.0%(srext)s' % self.extensions)
                libdir = os.path.join(self.config.prefix, 'lib', 'mono', '4.0')
            bindir = os.path.join(self.config.prefix, 'bin')
            shutil.copy(libcesarplayer, libdir)

            if self.config.target_platform == Platform.WINDOWS:
                binary = os.path.join(self.config.prefix, self.extensions['sdir'],
                        'LongoMatchGtk.exe')
                assembly = os.path.join(longomatchlib, 'LongoMatchGtk.exe')
                mkbundle = 'mkbundle -o %s %s --config %s --nodeps --keeptemp ' % (binary, assembly,
                        os.path.join(self.config.prefix, 'etc', 'mono', 'config'))
                shell.call(mkbundle, self.build_dir)
                rebuild_bundle = '$CC $CFLAGS -o %s %s `pkg-config --cflags --libs mono-2 glib-2.0` temp.o' % \
                    (binary, self.relative_path ('temp.c'))
                shell.call(rebuild_bundle, self.build_dir)
