Blob Blame Raw
%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
%global with_gcj %{!?_without_gcj:1}%{?_without_gcj:0}
Summary:        Real-time Midi I/O Library
Name:           portmidi
Version:        200
Release:        5%{?dist}
License:        MIT
Group:          System Environment/Libraries
URL:            http://portmedia.sourceforge.net/
Source0:        http://downloads.sourceforge.net/portmedia/%{name}-src-%{version}.zip
Source1:        pmdefaults.desktop
# Build fixes:
Patch0:         portmidi-cmake.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires:  alsa-lib-devel
BuildRequires:  cmake
BuildRequires:  desktop-file-utils
BuildRequires:  java-devel >= 1.5
BuildRequires:  jpackage-utils
BuildRequires:  python-devel
BuildRequires:  doxygen
BuildRequires:  tex(latex)
BuildRequires:    java-gcj-compat-devel >= 1.0.31

%description
PortMedia is a set of simple clean APIs and cross-platform library
implementations for music and other media. PortMidi subproject provides a
real-time MIDI input/output library. This package contains the PortMidi
libraries.

%package devel
Summary:        Headers for developing programs that will use %{name}
Group:          System Environment/Libraries
Requires:       %{name} = %{version}-%{release}

%description devel
PortMedia is a set of simple clean APIs and cross-platform library
implementations for music and other media. PortMidi subproject provides a
real-time MIDI input/output library. This package contains the header files
and the documentation of PortMidi libraries.

%package -n python-%{name}
Summary:        Python wrapper for %{name}
Group:          System Environment/Libraries
Requires:       %{name} = %{version}-%{release}

%description -n python-%{name}
PortMedia is a set of simple clean APIs and cross-platform library
implementations for music and other media. PortMidi subproject provides a
real-time MIDI input/output library. This package contains the python
bindings of PortMidi libraries. It can send and receive MIDI data in
real-time from Python.

%package tools
Summary:          Tools to configure and use %{name}
Group:            Applications/Multimedia
Requires:         hicolor-icon-theme
Requires:         java >= 1.5
Requires:         jpackage-utils
Requires:         %{name} = %{version}-%{release}
Requires(post):   java-gcj-compat >= 1.0.31
Requires(postun): java-gcj-compat >= 1.0.31

%description tools
PortMedia is a set of simple clean APIs and cross-platform library
implementations for music and other media. PortMidi subproject provides a
real-time MIDI input/output library. This package contains the PortMidi
configuration utility "pmdefaults" and some test applications.

%prep
%setup -q -n %{name}
%patch0 -p1 -b .buildfix

# ewwww... binaries
rm -f portmidi_cdt.zip */*.exe */*/*.exe

# Fix permissons and encoding issues:
find . -name "*.c" -exec chmod -x {} \;
find . -name "*.h" -exec chmod -x {} \;
for i in *.txt */*.txt */*/*.txt ; do
   chmod -x $i
   sed 's|\r||' $i > $i.tmp
   touch -r $i $i.tmp
   mv -f $i.tmp $i
done

# Fedora's jni library location is different
sed -i 's|loadLibrary.*|load("%{_libdir}/%{name}/libpmjni.so");|' \
   pm_java/jportmidi/JPortMidiApi.java

# Add shebang, lib and class path
sed -i -e 's|^java|#!/bin/sh\njava \\\
   -Djava.library.path=%{_libdir}/%{name}/|' \
   -e 's|/usr/share/java/|%{_libdir}/%{name}/|' \
   pm_java/pmdefaults/pmdefaults


%build
export JAVA_HOME=%{java_home}
%cmake -DCMAKE_CACHEFILE_DIR=%{_builddir}/%{name}/build -DVERSION=%{version} .
make %{?_smp_flags}

# Build the doxygen documentation:
doxygen
pushd latex
   make %{?_smp_flags}
popd

# Build python modules
PYTHON_VER=$(python -c "from sys import version; print (version[:3])")
PYTHON_INC=$(python -c "from distutils.sysconfig import get_python_inc; print get_python_inc()")
pushd pm_python
   gcc %{optflags} -fPIC -c -o pypm.o -I../pm_common \
       -I../porttime -I$PYTHON_INC pypm.c
   gcc -shared -o pypm.so  pypm.o -lportmidi -lpython$PYTHON_VER -L../build/Release
popd

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

# Install the test applications:
install -d %{buildroot}%{_libdir}/%{name}
for app in latency midiclock midithread midithru mm qtest sysex test; do
   install -m 0755 build/Release/$app %{buildroot}%{_libdir}/%{name}/
done

# Fedora's jni library location is different
mv %{buildroot}%{_libdir}/libpmjni.so \
   %{buildroot}%{_libdir}/%{name}/
mv %{buildroot}%{_javadir}/pmdefaults.jar \
   %{buildroot}%{_libdir}/%{name}/

# pmdefaults icon
mkdir -p %{buildroot}%{_datadir}/icons/hicolor/128x128/apps/
install -pm 644 pm_java/pmdefaults/pmdefaults-icon.png \
   %{buildroot}%{_datadir}/icons/hicolor/128x128/apps/

# desktop file
mkdir -p %{buildroot}%{_desktopdir}/
desktop-file-install \
   --dir=%{buildroot}%{_desktopdir} \
   %{SOURCE1}

# Why don't they install this header file?
install -pm 644 pm_common/pmutil.h %{buildroot}%{_includedir}/

# Install python modules
mkdir -p %{buildroot}%{python_sitearch}
install -pm 755 pm_python/pypm.so %{buildroot}%{python_sitearch}/

# Remove duplicate library
rm -f %{buildroot}%{_libdir}/libportmidi_s.so

# AOT bits
%if %{with_gcj}
   %{_bindir}/aot-compile-rpm
%endif

%clean
rm -rf %{buildroot}

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%post tools
%if %{with_gcj}
   if [ -x %{_bindir}/rebuild-gcj-db ] 
      then
      %{_bindir}/rebuild-gcj-db
   fi
%endif

%postun tools
%if %{with_gcj}
   if [ -x %{_bindir}/rebuild-gcj-db ] 
      then
      %{_bindir}/rebuild-gcj-db
   fi
%endif

%files
%defattr(-,root,root,-)
%doc CHANGELOG.txt license.txt
%{_libdir}/lib*.so.*

%files tools
%defattr(-,root,root,-)
%doc pm_java/pmdefaults/README.txt pm_cl/*
%{_libdir}/%{name}/
%{_bindir}/pmdefaults
%{_datadir}/icons/hicolor/128x128/apps/pmdefaults-icon.png
%{_desktopdir}/pmdefaults.desktop
%if %{with_gcj}
%{_libdir}/gcj/%{name}/
%endif

%files -n python-%{name}
%defattr(-,root,root,-)
%doc pm_python/README.txt pm_python/test.py pm_python/miniTest.py
%{python_sitearch}/pypm.so

%files devel
%defattr(-,root,root,-)
%doc README.txt
%doc html latex/*.pdf
%{_includedir}/*
%{_libdir}/lib*.so

%changelog
* Sat May 14 2011 Daniel Drake <dsd@laptop.org> - 200-5
- move Requires:Java to tools subpackage, its not needed by the main package

* Fri Jul 23 2010 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 200-4
- Fix python module build

* Wed Jul 21 2010 David Malcolm <dmalcolm@redhat.com> - 200-3
- Rebuilt for https://fedoraproject.org/wiki/Features/Python_2.7/MassRebuild

* Sat Jan 30 2010 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 200-2
- Remove duplicate library

* Sat Jan 30 2010 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 200-1
- Update to 200.
- Add python subpackage

* Fri Nov 27 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 184-1
- Update to 184. Build system uses cmake now.

* Sun Jul 26 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 131-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild

* Tue Feb 24 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 131-3
- Include pmutil.h in the devel package

* Tue Jan 27 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 131-2
- Build and add doxygen documentation
- Preserve some timestamps

* Sun Jan 11 2009 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 131-1
- New upstream release.

* Sun Dec 07 2008 Orcan Ogetbil <oget [DOT] fedora [AT] gmail [DOT] com> 82-1
- Initial release.