%define mono_dir %{_prefix}/lib/mono
%define monodoc_dir %{_prefix}/lib/monodoc
%define moonlight_dir %{_prefix}/lib/moonlight
%define pkgconfigdir %{_datadir}/pkgconfig
%define included_mono 2.6.1
%define included_basic 2.6
Summary:  An open source implementation of Silverlight
Summary(ja): Silverlight のオープンソースによる実装
Name: moonlight
Version: 2.3
Release: 2%{?_dist_release}
Group: Applications/Multimedia
License: LGPL v2.0 only ; MIT License (or similar) ; Ms-Pl
URL: http://go-mono.com/moonlight/
Source0: ftp://ftp.novell.com/pub/mono/sources/moon/%{version}/moonlight-%{version}.tar.bz2
Source1: ftp://ftp.novell.com/pub/mono/sources/moon/%{version}/mono-%{included_mono}.tar.bz2
Source2: ftp://ftp.novell.com/pub/mono/sources/moon/%{version}/mono-basic-%{included_basic}.tar.bz2
Patch0: bad-register.patch
Patch1: r159607.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: mono-devel >= 2.6
BuildRequires: gtk-sharp2
BuildRequires: rsvg2-sharp
BuildRequires: wnck-sharp
BuildRequires: gcc-c++
BuildRequires: gtk2-devel
BuildRequires: alsa-lib-devel
BuildRequires: xulrunner-devel
BuildRequires: bison
BuildRequires: autoconf
ExclusiveArch: %ix86 x86_64

%description
Moonlight is an open source implementation of Microsoft Silverlight for
Unix systems.

%description -l ja
Moonlight は Unix 系システムのための，Microsoft Silverlight のオープン
ソースな実装です．


%package libs
Summary: Moonlight libmoon
Group: System Environment/Libraries
License: LGPL v2.0 only
Requires: mono-core >= 2.6

%description libs
Moonlight libmoon

%package devel
Summary: Moonlight libmoon C/C++ development files
Group: Development/Libraries
License: LGPL v2.0 only
Requires: %{name}-libs == %{version}

%description devel
Development files for libmoon

%package tools
Summary: Moonlight tools
Group: Development/Tools
Requires: %{name}-libs == %{version}

%description tools
Moonlight tools (mopen, xamlg, xaml2html, mxap, respack, svg2xaml)

%package plugin
Summary: Moonlight browser plugin
Group: Applications/Internet
Requires: %{name}-libs == %{version}
Requires: mono-core >= 2.6

%description plugin
Browser plugin for Novell Moonlight

%package web-devel
Summary: Development files for Moonlight Web
Group: Development/Libraries
License: MIT License (or similar) ; Ms-Pl
Requires: %{name}-plugin == %{version}

%description web-devel
Development files for creating Moonlight web applications.

%package desktop
Summary: Mono bindings for Moonlight Desktop
Group: Development/Libraries
License: MIT License (or similar) ; Ms-Pl
Requires: %{name}-libs == %{version}

%description desktop
Mono bindings for Novell Moonlight.

%package desktop-devel
Summary: Development files for Moonlight Desktop
Group: Development/Libraries
License: MIT License (or similar) ; Ms-Pl
Requires: %{name}-libs == %{version}
Requires: glib2-devel
Requires: gtk-sharp2
Requires: %{name}-desktop == %{version}
Requires: %{name}-tools == %{version}

%description desktop-devel
Development files for Moonlight Desktop.

%package sharp
Summary: Moonlight sharp
Group: Development/Libraries
Requires: %{name}-libs == %{version}

%description sharp
Provides a gtk-sharp object that can be used to embed a moonlight surface in a desktop application.


%prep
%setup -q
%setup -q -T -D -b 1 -n %{name}-%{version}
%setup -q -T -D -b 2 -n %{name}-%{version}
pushd ../mono-%{included_mono}
%patch0
popd
%patch1


%build
# The plugin requires a complete build of it's own mono
pushd ../mono-%{included_mono}
./configure \
	--prefix=%{_builddir}/install \
	--with-mcs-docs=no \
	--with-ikvm-native=no \
	;
# mono is not strictly -j safe
%{__make} EXTERNAL_MCS=false EXTERNAL_RUNTIME=false
%{__make} install
find %{_builddir}/install -name \*.la -delete
popd

# Configure against the junk install of mono
export PATH=%{_builddir}/install/bin:${PATH}
export LD_LIBRARY_PATH=%{_builddir}/install/lib:${LD_LIBRARY_PATH}
export PKG_CONFIG_PATH=%{_builddir}/install/lib/pkgconfig:${PKG_CONFIG_PATH}
# Only needed when there are Makefile.am or configure.ac patches
autoreconf -f -i -Wnone
%configure \
	--with-ffmpeg=no \
	--with-cairo=system \
	--with-curl=system \
	--with-mcspath=%{_builddir}/mono-%{included_mono}/mcs \
	--with-mono-basic-path=%{_builddir}/mono-basic-%{included_basic} \
	--with-ff3=yes \
	--with-testing=no \
	--with-performance=no \
	--with-examples=no \
	--with-debug=no \
	--with-sanity-checks=no \
	--without-testing \
	--without-performance \
	--without-examples \
	--disable-debug \
	--disable-sanity \
	;

export MONO_GAC_PREFIX=%{_builddir}/install:%{_prefix}
%{__make} %{?_smp_mflags}


%install
rm -rf %{buildroot}
export PATH=%{_builddir}/install/bin:${PATH}
export LD_LIBRARY_PATH=%{_builddir}/install/lib:${LD_LIBRARY_PATH}
export PKG_CONFIG_PATH=%{_builddir}/install/lib/pkgconfig:${PKG_CONFIG_PATH}
make install DESTDIR=%{buildroot} pkgconfigdir=%{pkgconfigdir}

install -m 644 %{_builddir}/install/lib/libmono.so.0 %{buildroot}%{_libdir}/moonlight/
chrpath -r %{_libdir}/moonlight %{buildroot}%{_libdir}/moonlight/plugin/libmoonplugin.so
chrpath -r  %{_libdir}/moonlight %{buildroot}%{_libdir}/moonlight/plugin/libmoonplugin.so

mkdir -p %{buildroot}%{_libdir}/mozilla/plugins
ln -s %{_libdir}/moonlight/plugin/libmoonloader.so \
	%{buildroot}%{_libdir}/mozilla/plugins/libmoonloader.so

# remove unuse files
rm -f %{buildroot}%{_libdir}/libshocker.so
find %{buildroot} -name \*.la -delete


%post libs -p /sbin/ldconfig
%postun libs -p /sbin/ldconfig
%clean
rm -rf %{buildroot}


%files libs
%defattr(-, root, root)
%doc AUTHORS COPYING ChangeLog README TODO NEWS
%{_libdir}/libmoon.so.*
%dir %{_libdir}/moonlight
%{_libdir}/moonlight/libmono.so.0

%files devel
%defattr(-, root, root)
%{_libdir}/libmoon.so

%files tools
%defattr(-, root, root)
%{_bindir}/mopen
%{_bindir}/munxap
%{_bindir}/mxap
%{_bindir}/respack
%{_bindir}/sockpol
%{_bindir}/unrespack
%{_bindir}/xaml2html
%{_bindir}/xamlg
%{_libdir}/moonlight/mopen.exe*
%{_libdir}/moonlight/munxap.exe
%{_libdir}/moonlight/mxap.exe
%{_libdir}/moonlight/respack.exe
%{_libdir}/moonlight/xaml2html.exe
%{_libdir}/moonlight/xamlg.exe
%{_libdir}/moonlight/sockpol.exe
%{_mandir}/man1/mopen.1.gz
%{_mandir}/man1/mxap.1.gz
%{_mandir}/man1/respack.1.gz
%{_mandir}/man1/svg2xaml.1.gz
%{_mandir}/man1/xamlg.1.gz
%{_mandir}/man1/sockpol.1.gz

%files plugin
%defattr(-, root, root)
%dir %{_libdir}/moonlight/plugin
%{_libdir}/moonlight/plugin/Microsoft.VisualBasic.dll
%{_libdir}/moonlight/plugin/System.Core.dll*
%{_libdir}/moonlight/plugin/System.Net.dll*
%{_libdir}/moonlight/plugin/System.Runtime.Serialization.dll*
%{_libdir}/moonlight/plugin/System.ServiceModel.Web.dll*
%{_libdir}/moonlight/plugin/System.ServiceModel.dll*
%{_libdir}/moonlight/plugin/System.Windows.Browser.dll*
%{_libdir}/moonlight/plugin/System.Windows.dll*
%{_libdir}/moonlight/plugin/System.Xml.dll*
%{_libdir}/moonlight/plugin/System.dll*
%{_libdir}/moonlight/plugin/libmoonloader.so
%{_libdir}/moonlight/plugin/libmoonplugin-curlbridge.so
%{_libdir}/moonlight/plugin/libmoonplugin-ff3bridge.so
%{_libdir}/moonlight/plugin/libmoonplugin.so
%{_libdir}/moonlight/plugin/mscorlib.dll*
%{_libdir}/mozilla/plugins/libmoonloader.so

%files web-devel
%defattr(-, root, root)
%{_bindir}/smcs
%dir %{moonlight_dir}/2.0-redist
%{moonlight_dir}/2.0-redist/System.Windows.Controls.Data.dll*
%{moonlight_dir}/2.0-redist/System.Windows.Controls.dll*
%{moonlight_dir}/2.0-redist/System.Xml.Linq.dll*
%dir %{moonlight_dir}/2.0
%{moonlight_dir}/2.0/Microsoft.VisualBasic.dll*
%{moonlight_dir}/2.0/Mono.CompilerServices.SymbolWriter.dll*
%{moonlight_dir}/2.0/System.Core.dll*
%{moonlight_dir}/2.0/System.Net.dll*
%{moonlight_dir}/2.0/System.Runtime.Serialization.dll*
%{moonlight_dir}/2.0/System.ServiceModel.Web.dll*
%{moonlight_dir}/2.0/System.ServiceModel.dll*
%{moonlight_dir}/2.0/System.Windows.Browser.dll*
%{moonlight_dir}/2.0/System.Windows.dll*
%{moonlight_dir}/2.0/System.Xml.dll*
%{moonlight_dir}/2.0/System.dll*
%{moonlight_dir}/2.0/mscorlib.dll*
%{moonlight_dir}/2.0/respack.exe*
%{moonlight_dir}/2.0/smcs
%{moonlight_dir}/2.0/smcs.exe*
%{moonlight_dir}/2.0/buildversion
%{pkgconfigdir}/moonlight-web-2.0.pc

%files desktop
%defattr(-, root, root)
%{mono_dir}/gac/Moon.Windows.Desktop
%{mono_dir}/gac/Moonlight.Gtk
%{mono_dir}/gac/System.Windows
%{mono_dir}/gac/System.Windows.Browser
%{mono_dir}/gac/System.Windows.Controls
%{mono_dir}/gac/System.Windows.Controls.Data

%files desktop-devel
%defattr(-, root, root)
%dir %{mono_dir}/moonlight
%{mono_dir}/moonlight/Moon.Windows.Desktop.dll*
%{mono_dir}/moonlight/System.Windows.Browser.dll*
%{mono_dir}/moonlight/System.Windows.Controls.Data.dll*
%{mono_dir}/moonlight/System.Windows.Controls.dll*
%{mono_dir}/moonlight/System.Windows.dll*
%{pkgconfigdir}/moonlight-desktop-2.0.pc
# It may make sense in the future to have a moonlight-gtk package
%{mono_dir}/moonlight/Moonlight.Gtk.dll*
%{monodoc_dir}/sources/moonlight-gtk.source
%{monodoc_dir}/sources/moonlight-gtk.tree
%{monodoc_dir}/sources/moonlight-gtk.zip
%{pkgconfigdir}/moonlight-gtk-2.0.pc


%changelog
* Sun Oct 10 2010 Shu KONNO <owa@bg.wakwak.com> 2.3-2
- rebuilt with mono-2.8
- added bad-register.patch, r159607.patch (from suse)
- added BR: autoconf (use autoreconf in %%build)
- installed %%{_libdir}/moonlight/libmono.so.0 (obsoleted in mono-2.8)

* Tue Oct 05 2010 Shu KONNO <owa@bg.wakwak.com> 2.3-1
- updated moonlightautoconf to 2.3
- updated mono to 2.6.1
- updated mono-basic to 2.6
- added BR: bison

* Wed Sep 08 2010 Shu KONNO <owa@bg.wakwak.com> 2.0-3
- export PATH, LD_LIBRARY_PATH, PKG_CONFIG_PATH, MONO_GAC_PREFIX

* Sat Sep  4 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0-2
- fixed Group
- added BR: wnck-sharp

* Thu Dec 31 2009 Shu KONNO <owa@bg.wakwak.com> 2.0-1
- updated moonlight to 2.0

* Thu Jul 09 2009 Shu KONNO <owa@bg.wakwak.com> 1.0.1-1
- updated moon to 1.0.1
- dropt missing-files.patch (included in source)
- built with latest rpm to update mono-dependencies

* Sun Apr 19 2009 Shu KONNO <owa@bg.wakwak.com> 0.8.1-2
- changed plugin Group to Applications/Internet
- changed other sub packages Group to Development/Libraries
- added %%pkgconfigdir macro

* Sat Sep 27 2008 Shu KONNO <owa@bg.wakwak.com> 0.8.1-1
- new upstream release
- added missing-files.patch from suse
- added --with-managed=desktop

* Wed Sep 17 2008 Shu KONNO <owa@bg.wakwak.com> 0.8-1
- initial build for VineSeed
    - moonlight 0.8
    - vine versioning policy
    - spec in utf-8

