%global fontfamilyname %{name}

%define _fontdir %{_datadir}/fonts/%{name}

Name:          mscore
Summary:       Music Composition & Notation Software
Version:       1.3
Release:       2%{?_dist_release}
# rtf2html is LGPLv2+
# paper4.png paper5.png are LGPLv3
# the rest is GPLv2
License:       GPLv2 and LGPLv2+ and LGPLv3 and CC-BY
Group:         Applications/Multimedia
URL:           http://musescore.org/en
# Upstream tarball contains a non-free soundfont "Gort's Minipiano"
# And one demo file which is CC-BY-NC-SA (non-free)
# We generate our own tarball by removing these files via:
#    wget http://download.sourceforge.net/mscore/mscore-1.3.tar.bz2
#    tar jxf mscore-1.3.tar.bz2
#    rm -f mscore-*/mscore/mscore/data/piano1.sf2
#    rm -f mscore-*/mscore/demos/prelude.mscx
#    tar jcf mscore-1.3-free.tar.bz2 mscore-1.3/
Source0:       %{name}-%{version}-free.tar.bz2
# For mime types
Source2:       %{name}.xml
# Use Fedora's default soundfont instead of the removed one:
Patch0:        %{name}-use-default-soundfont.patch
# We don't build the common files (font files, wallpapers, demo song, instrument
# list) into the binary executable to reduce its size. This is also useful to 
# inform the users about the existence of different choices for common files.
# The font files need to be separated due to the font packaging guidelines.
Patch1:        %{name}-separate-commonfiles.patch
# Split the large documentation into a separate package
Patch2:        %{name}-split-doc.patch
# Fix some gcc warnings
Patch4:        %{name}-fix-gcc-warnings.patch
# Fix DSO linking. Seems to have fixed in trunk, but misssing in the tarball
# http://musescore.org/en/node/5817
Patch5:        %{name}-dso-linking.patch
# Use system qtsingleapplication
Patch6:        %{name}-system-qtsingleapplication.patch
# Fix crash on Accidentals click RHBZ#738044 From upstream trunk rev 3193
Patch8:        %{name}-fix-accidentals-crash.patch
# Remove prelude from cmake files
Patch9:        mscore-1.3-no-prelude.patch

## VINE: fix build with freetype-2.5.1 and up
Patch100:      mscore-1.3-fix-build-with-freetype251.patch
## VINE: use alsa on default
Patch101:      mscore-1.3-vine-alsa.patch

BuildRequires: freetype2-devel
BuildRequires: alsa-lib-devel
BuildRequires: cmake
BuildRequires: desktop-file-utils
BuildRequires: jack-audio-connection-kit-devel
BuildRequires: libsndfile-devel
BuildRequires: portaudio-devel
BuildRequires: qt4-devel
BuildRequires: qtsingleapplication-devel
BuildRequires: qt4-devel
BuildRequires: perl(Pod::Usage)

Requires:      %{name}-fonts = %{version}-%{release}
Requires:      soundfont2-default
# For scripting
Requires:      qtscriptbindings


# Doxygen documentation is huge and it is for musescore development only. 
# Hence we don't build it for now. Otherwise it needs:
# BuildRequires: graphviz doxygen texlive-latex texlive-dvips

Provides:      musescore = %{name}-%{version}-%{release}

%description
MuseScore is a free cross platform WYSIWYG music notation program. Some
highlights:

    * WYSIWYG, notes are entered on a "virtual note sheet"
    * Unlimited number of staves
    * Up to four voices per staff
    * Easy and fast note entry with mouse, keyboard or MIDI
    * Integrated sequencer and FluidSynth software synthesizer
    * Import and export of MusicXML and Standard MIDI Files (SMF)
    * Translated in 26 languages

%package doc
Summary:       MuseScore documentation
Group:         Documentation
License:       CC-BY
Requires:      %{name} = %{version}-%{release}
BuildArch:     noarch

%description doc
MuseScore is a free cross platform WYSIWYG music notation program.

This package contains the user manual of MuseScore in different languages.

%package fonts
Summary:       MuseScore fonts
Group:         User Interface/X
License:       GPL+ with exceptions and OFL
BuildArch:     noarch
BuildRequires: fontforge
BuildRequires: t1utils
BuildRequires: texlive
BuildRequires: texlive-common
BuildRequires: texlive-collection-fontutils
BuildRequires: texlive-collection-fontsextra
BuildRequires: texlive-collection-metapost

%description fonts
MuseScore is a free cross platform WYSIWYG music notation program.

This package contains the musical notation fonts for use of MuseScore.

%prep
%setup -q 

%patch0 -p1 -b .default.soundfont
%patch1 -p1 -b .separatecommon
%patch2 -p1 -b .splitdoc
%patch4 -p1 -b .warnings
%patch5 -p1 -b .dso
%patch6 -p1 -b .qtsingleapp
%patch8 -p1 -b .accidentals
%patch9 -p1 -b .noprelude

## VINE
%if %{?_dist_release} >= "vl7"
%patch100 -p1 -b .fixbuild
%endif
%patch101 -p1 -b .vine-alsa

# Remove the precompiled binary
rm mscore/rtf2html/rtf2html

# Force Fedora specific flags:
find . -name CMakeLists.txt -exec sed -i -e 's|-m32|%{optflags}|' -e 's|-O3|%{optflags}|' {} \;

# Do not build the bundled qt scripting interface:
sed -i 's|BUILD_SCRIPTGEN TRUE|BUILD_SCRIPTGEN FALSE|' %{name}/CMakeLists.txt

# Fix EOL encoding
sed 's|\r||' %{name}/rtf2html/README > tmpfile
touch -r %{name}/rtf2html/README tmpfile
mv -f tmpfile %{name}/rtf2html/README

# Remove preshipped fonts. We will build them from source
rm -f %{name}/%{name}/fonts/*.ttf

# Change font name according to our conventions
sed -i 's|MuseJazz.ttf|%{fontfamilyname}-MuseJazz.ttf|' %{name}/%{name}/fonts/gen-jazz.pe

# Disable rpath
sed -i '/rpath/d' %{name}/%{name}/CMakeLists.txt

# We don't use this 3rd party lib but remove anyways
rm -fr mscore/singleapp/ mscore/scriptgen/

%build
# Build the actual program
mkdir build
pushd build
   export PATH=${PATH}:%{_libdir}/qt4/bin
   export CMAKE_INCLUDE_PATH=%{_qt4_headerdir}
   export CMAKE_LIBRARY_PATH=%{_qt4_libdir}
   %cmake -DCMAKE_BUILD_TYPE=RELEASE         \
          -DCMAKE_CXX_FLAGS="%{optflags}"    \
          -DUSE_SYSTEM_QTSINGLEAPPLICATION=1 \
          ../mscore
   make lupdate %{?_smp_flags}
   make lrelease %{?_smp_flags}
   make %{?_smp_flags} VERBOSE=1
popd

# Build fonts from source:
pushd %{name}/%{name}/fonts
   ./genFont
   fontforge gen-jazz.pe
popd

%install
%{__rm} -rf %{buildroot}
make install DESTDIR=%{buildroot}

# Install fonts
mkdir -p %{buildroot}/%{_fontdir}
install -pm 644 %{name}/%{name}/fonts/%{fontfamilyname}*.ttf %{buildroot}/%{_fontdir}

# Mime type
mkdir -p %{buildroot}/%{_datadir}/mime/packages
install -pm 644 %{SOURCE2} %{buildroot}/%{_datadir}/mime/packages/

# Desktop file
desktop-file-install \
   --dir=%{buildroot}/%{_datadir}/applications \
   --add-category="X-Notation" \
   --remove-category="Sequencer" \
   --remove-category="AudioVideoEditing" \
   --add-mime-type="audio/midi" \
   --add-mime-type="text/x-lilypond" \
   --add-mime-type="application/xml" \
   %{buildroot}/%{_datadir}/applications/%{name}.desktop

# Move images to the freedesktop location
mkdir -p %{buildroot}/%{_datadir}/icons/hicolor/{32x32,64x64}/apps/
mkdir -p %{buildroot}/%{_datadir}/icons/hicolor/{32x32,64x64}/mimetypes/
cp -a %{buildroot}/%{_datadir}/pixmaps/%{name}.xpm \
   %{buildroot}/%{_datadir}/icons/hicolor/32x32/mimetypes/application-x-musescore.xpm
mv %{buildroot}/%{_datadir}/pixmaps/%{name}.xpm \
   %{buildroot}/%{_datadir}/icons/hicolor/32x32/apps/
cp -a %{buildroot}/%{_datadir}/pixmaps/%{name}.png \
   %{buildroot}/%{_datadir}/icons/hicolor/64x64/mimetypes/application-x-musescore.png
mv %{buildroot}/%{_datadir}/pixmaps/%{name}.png \
   %{buildroot}/%{_datadir}/icons/hicolor/64x64/apps/

# Manpage
mkdir -p %{buildroot}/%{_mandir}/man1
install -pm 644 %{name}/packaging/%{name}.1 %{buildroot}/%{_mandir}/man1/

# Openoffice templates
cp -a %{name}/utils/OOoMuseScore/ %{buildroot}/%{_datadir}/%{name}-%{version}

# There are many doc files spread around the tarball. Let's collect them
pushd %{name}
   mv rtf2html/ChangeLog        ChangeLog.rtf2html
   mv rtf2html/COPYING.LESSER   COPYING.LESSER.rtf2html
   mv rtf2html/README           README.rtf2html
   mv rtf2html/README.mscore    README.mscore.rtf2html
   mv rtf2html/README.ru        README.ru.rtf2html
   mv osdabzip/README           README.osdabzip
   mv osdabzip/README.mscore    README.mscore.osdabzip
   mv share/wallpaper/COPYRIGHT COPYING.wallpaper
popd

%check
# iotest seems outdated. Skipping.
# rendertest needs the X server. Skipping.

%clean
%{__rm} -rf %{buildroot}

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

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

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


%files
%defattr(-,root,root,-)
%doc mscore/{ChangeLog*,COPYING*,NEWS,README*}
%{_bindir}/%{name}
%{_datadir}/%{name}-%{version}/
%exclude %{_datadir}/%{name}-%{version}/man/
%{_datadir}/icons/hicolor/*/*/*
%{_datadir}/applications/%{name}.desktop
%{_datadir}/mime/packages/%{name}.xml
%{_datadir}/soundfonts/TimGM6mb.sf2
%{_mandir}/man1/*
%{_qt4_plugindir}/designer/libawlplugin.so

%files doc
%defattr(-,root,root,-)
%doc %{_datadir}/%{name}-%{version}/man/

%files fonts
%defattr(-,root,root,-)
%{_datadir}/fonts/%{name}/%{fontfamilyname}*.ttf


%changelog
* Thu Jan  9 2014 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.3-2
- initial build for Vine Linux
- add Patch100 to fix build failure with freetype2 > 2.5

* Fri Apr 12 2013 Tom Callaway <spot@fedoraproject.org> - 1.3-2
- perl(Pod::Usage) needed for font generation

* Fri Apr 12 2013 Tom Callaway <spot@fedoraproject.org> - 1.3-1
- update to 1.3
- remove mscore/demos/prelude.mscx from source tarball (it is non-free, see bz951379)

* Thu Feb 14 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.2-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild

* Fri Jul 20 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

* Tue Mar 13 2012 Orcan Ogetbil <oget[DOT]fedora[AT]gmail[DOT]com> - 1.2-1
- Update to 1.2.

* Sat Mar 03 2012 Orcan Ogetbil <oget[DOT]fedora[AT]gmail[DOT]com> - 1.1-4
- Fix accidontals crash RHBZ#738044

* Tue Feb 28 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.1-3
- Rebuilt for c++ ABI breakage

* Fri Jan 13 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild

* Thu Jul 28 2011 Orcan Ogetbil <oget[DOT]fedora[AT]gmail[DOT]com> - 1.1-1
- Update to 1.1.

* Tue Feb 08 2011 Orcan Ogetbil <oget[DOT]fedora[AT]gmail[DOT]com> - 1.0-1
- Update to 1.0.

* Tue Feb 08 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.9.6.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild

* Sun Sep 26 2010 Orcan Ogetbil <oget[DOT]fedora[AT]gmail[DOT]com> - 0.9.6.3-1
- Update to 0.9.6.3

* Thu Aug 19 2010 Orcan Ogetbil <oget[DOT]fedora[AT]gmail[DOT]com> - 0.9.6.2-1
- Update to 0.9.6.2

* Tue Jul 20 2010 Orcan Ogetbil <oget[DOT]fedora[AT]gmail[DOT]com> - 0.9.6.1-1
- Update to 0.9.6.1

* Mon Jun 14 2010 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.6-1
- Update to 0.9.6
- Split documentation into its own package
- Move some gcc warning fixes into a patch

* Tue Dec 22 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.5-3
- Fix build flags on F-11

* Tue Dec 22 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.5-2
- Add default soundfont support for exported audio files
- Rebuild against new libsndfile for additional functionality
- Drop F-10 related bits from specfile
- Make fonts subpackage noarch
- Fix build failure on arm architecture

* Fri Aug 21 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.5-1
- Update to 0.9.5

* Wed Aug 05 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.4-6
- Update the .desktop file

* Sat Jul 25 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.9.4-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild

* Thu Jun 11 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.4-4
- Font package cleanup for F-12 (RHBZ#493463)
- One specfile for all releases

* Mon Mar 23 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.4-3.fc10.1
- Add BR: tetex-font-cm-lgc for Fedora < 11

* Mon Mar 23 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.4-3
- Add Provides: musescore = %%{name}-%%{version}
- Replace "fluid-soundfont" requirement with "soundfont2-default"

* Fri Mar 06 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.4-2
- Add extra BR:tex-cm-lgc for F-11+. This is necessary to build the fonts from source
- Update icon scriptlets according to the new guidelines

* Sat Feb 21 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 0.9.4-1
- Initial Fedora build
