%if %{?_dist_release} == "vl5"
%define kde KDE4
%else
%define kde KDE
%endif

Name:           kmid2
Summary:        A MIDI/karaoke player for %{kde}
Summary(ja):    %{kde} 向け MIDI/カラオケプレーヤー
Version:        2.3.0
Release:        4%{?_dist_release}

Group:          Applications/Multimedia
# GPLv2+ for the code and the MMA examples, CC-BY-SA for the MIDI examples
License:        GPLv2+ and CC-BY-SA
URL:            http://userbase.kde.org/KMid2

Source0:        http://downloads.sourceforge.net/project/%{name}/%{version}/kmid-%{version}.tar.bz2

# http://websvn.kde.org/?revision=1134129&view=revision
# Fix a crash in the ALSA backend due to reloadDeviceList (kde#240394)
Patch0:         kmid-2.3.0-kde#240394.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-root

BuildRequires:  kdelibs4-devel
#BuildRequires:  kde-filesystem
BuildRequires:  cmake
BuildRequires:  alsa-lib-devel
BuildRequires:  drumstick-devel >= 0.3
BuildRequires:  gettext
BuildRequires:  desktop-file-utils

#{?_kde4_macros_api:Requires: kde4-macros(api) = %{_kde4_macros_api}}
#{?_kde4_version:Requires: kdelibs4%{?_isa} >= %{_kde4_version}}
Requires:       oxygen-icon-theme
Requires:       drumstick >= 0.3
Requires:       %{name}-libs = %{version}-%{release}

Obsoletes:      kmid < 2.0-1
Provides:       kmid = %{version}-%{release}

%description
KMid2 is a MIDI/karaoke file player, with configurable midi mapper, real
Session Management, drag & drop, customizable fonts, etc. It has a very
nice interface which let you easily follow the tune while changing the
color of the lyrics.
It supports output through external synthesizers, AWE, FM and GUS cards.
It also has a keyboard view to see the notes played by each instrument.

%package libs
Summary:        Runtime libraries for %{name}
Summary(ja):    %{name} のランタイムライブラリ
Group:          System Environment/Libraries
License:        GPLv2+

#{?_kde4_macros_api:Requires: kde4-macros(api) = %{_kde4_macros_api}}
#{?_kde4_version:Requires: kdelibs4%{?_isa} >= %{_kde4_version}}

%description libs
%{summary}.

%package devel
Summary:        Development files for %{name}
Summary(ja):    %{name} の開発用ファイル
Group:          Development/Libraries
License:        GPLv2+

Requires:       %{name}-libs = %{version}-%{release}

Obsoletes:      kmid-devel < 2.0-1
Provides:       kmid-devel = %{version}-%{release}

%description devel
%{summary}.

%prep
%setup -q -n kmid-%{version}
# zap bundled copy of drumstick to guarantee it's never used
rm -rf drumstick
%patch0 -p0 -b .kde#240394


%build
mkdir -p %{_target_platform}
pushd %{_target_platform}
unset QTDIR || : ; . /etc/profile.d/qt4.sh
%cmake \
    -DCMAKE_BUILD_TYPE=release \
    -DCMAKE_INSTALL_PREFIX:PATH=%{_prefix} \
    -DDATA_INSTALL_DIR:PATH=%{_datadir}/kde4/apps \
    -DINCLUDE_INSTALL_DIR:PATH=%{_includedir}/kde4 \
    -DLIB_INSTALL_DIR:PATH=%{_libdir} \
    -DLIBEXEC_INSTALL_DIR:PATH=%{_libexecdir}/kde4 \
    -DSYSCONF_INSTALL_DIR:PATH=%{_sysconfdir} \
    ..
popd

make %{?_smp_mflags} -C %{_target_platform}


%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot} -C %{_target_platform}
desktop-file-validate %{buildroot}%{_datadir}/applications/kde4/kmid.desktop
%find_lang kmid

%clean
rm -rf %{buildroot}


%post
touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :
update-desktop-database &> /dev/null || :

%postun
update-desktop-database &> /dev/null || :
if [ $1 -eq 0 ] ; then
    touch --no-create %{_datadir}/icons/hicolor &>/dev/null
    gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
fi

%posttrans
gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :

%post libs -p /sbin/ldconfig
%postun libs -p /sbin/ldconfig


%files -f kmid.lang
%defattr(-,root,root,-)
%doc ChangeLog COPYING README TODO
%{_bindir}/kmid
%{_datadir}/kde4/apps/kmid/
%{_datadir}/applications/kde4/kmid.desktop
%{_datadir}/config.kcfg/*
%{_datadir}/kde4/services/*
%{_datadir}/kde4/servicetypes/*
%{_datadir}/icons/hicolor/*/apps/*
%{_libdir}/kde4/*
%doc %{_docdir}/HTML/*/kmid/

%files libs
%defattr(-,root,root,-)
%{_libdir}/libkmidbackend.so.*

%files devel
%defattr(-,root,root,-)
%{_libdir}/libkmidbackend.so
%{_includedir}/kde4/kmid/


%changelog
* Sat Feb 26 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 2.3.0-4
- removed --with-kde from %%find_lang

* Sun Jan 16 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 2.3.0-3
- Initial build for Vine Linux

* Fri May 28 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 2.3.0-2
- Fix crash in ALSA backend due to reloadDeviceList (kde#240394, upstream patch)

* Fri May 28 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 2.3.0-1
- Update to 2.3.0 (new versioning scheme)
- BR drumstick-devel >= 0.3
- Requires: drumstick >= 0.3
- Drop obsolete drumstick-version patch
- Examples now partly CC-BY-SA, partly GPLv2+ (instead of CC-BY)
- Use _kde4_version macro
- Add -devel and -libs subpackages
- Package COPYING

* Tue Feb 09 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 0.2.1-2
- Requires: drumstick >= 0.2.99-0.3

* Tue Feb 09 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 0.2.1-1
- Update to 0.2.1
- Drop upstreamed timidity-pulseaudio patch
- Drop dont-translate-output-names patch, should not be needed anymore
- BR drumstick-devel >= 0.2.99-0.3 (0.2.1 needs the 20100208 snapshot)
- relax drumstick version check in CMakeLists.txt as 0.3 is not out yet

* Fri Feb 05 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 0.2.0-3
- Don't translate output names, breaks autospawning sequencers

* Sun Jan 31 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 0.2.0-2
- Support PulseAudio when autospawning TiMidity++ (-OO -opulse switches)

* Sun Jan 31 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 0.2.0-1
- Update to 0.2.0
- The examples with copyright issues have been dropped by upstream
- BR drumstick-devel instead of aseqmm-devel

* Wed Jan 27 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 0.1.1-4
- Fix the kde4-config output parsing for 4.4 ("KDE Development Platform:")

* Wed Jan 27 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 0.1.1-3
- Correctly require at least the kdelibs version used for building

* Wed Jan 27 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 0.1.1-2
- Remove nonsense Requires: kdelibs4 >= %%{version}, as %%{version} is 0.1.1

* Fri Jan 22 2010 Kevin Kofler <Kevin@tigcc.ticalc.org> - 0.1.1-1
- First Fedora package, replaces kmid