File transmission.spec of Package transmission

# norootforbuild

%define use_libevent_intree 1

Name:           transmission
Version:        2.51
Release:        1.1
Summary:        Lightweight, yet powerful BitTorrent client
Source:         http://download.m0k.org/transmission/files/transmission-%{version}.tar.bz2
Source9:        http://monkey.org/~provos/libevent-2.0.18-stable.tar.gz
Source10:       transmission.desktop
Source100:	transmission-daemon.sysconfig
Source101:	transmission-daemon.init
Url:            http://www.transmissionbt.com/
Group:          Productivity/Networking/Other
License:        GPLv2 ; MIT License (or similar)
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Provides:       %{name}-ui = %{version}
Requires(post): update-alternatives
Requires(postun): update-alternatives
BuildRequires:  gcc gcc-c++ gettext gettext-devel glibc-devel intltool libpng-devel make
BuildRequires:  openssl-devel update-desktop-files zlib-devel


%if %suse_version >= 1140
BuildRequires:  gtk2-devel >= 2.22
BuildRequires:  glib2-devel >= 2.28
%endif

BuildRequires:  libevent-devel >= 2.0.0
BuildRequires:  libqt4-devel

BuildRequires:  dbus-1-glib-devel gconf2-devel
BuildRequires:  libnotify-devel
BuildRequires:  libcurl-devel >= 7.21.0
Requires:  libcurl4 >= 7.21.0

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

%description
A lightweight, yet powerful BitTorrent client.
Its simple, intuitive interface is designed to integrate tightly with whatever
computing environment you choose to use.
Transmission strikes a balance between providing useful functionality without
feature bloat. Furthermore, it is free for anyone to use or modify.

%if %suse_version >= 1140
%package gtk
License:        GPLv2 ; MIT License (or similar)
Summary:        Lightweight, yet powerful BitTorrent client
Group:          Productivity/Networking/Other
Requires:       %{name} = %{version}
Requires(post): update-alternatives
Requires(postun): update-alternatives

%description gtk
A lightweight, yet powerful BitTorrent client.
Its simple, intuitive interface is designed to integrate tightly with whatever
computing environment you choose to use.
Transmission strikes a balance between providing useful functionality without
feature bloat. Furthermore, it is free for anyone to use or modify.

This package contains a GTK2 graphical user interface to %{name}.
%endif

%package qt
License:        GPLv2 ; MIT License (or similar)
Summary:        Lightweight, yet powerful BitTorrent client
Group:          Productivity/Networking/Other
Requires:       %{name} = %{version}
Requires(post): update-alternatives
Requires(postun): update-alternatives
Provides:       %{name}-ui = %{version}

%description qt
Transmission is a fast, easy, and free multi-platform BitTorrent client
with a focus on being lightweight yet feature-filled. Its simple,
intuitive interface is designed to integrate tightly with whatever
computing environment you choose to use. Transmission strikes a balance
between providing useful functionality without feature bloat.
Furthermore, it is free for anyone to use or modify.

This package contains a graphical user interface to transmission.


%package daemon
License:        GPLv2 ; MIT License (or similar)
Summary:        Lightweight, yet powerful BitTorrent client
Group:          Productivity/Networking/Other
%description daemon
A lightweight, yet powerful BitTorrent client.
Its simple, intuitive interface is designed to integrate tightly with whatever
computing environment you choose to use.
Transmission strikes a balance between providing useful functionality without
feature bloat. Furthermore, it is free for anyone to use or modify.

This package contains a daemon to %{name}.



%prep
%setup -q -n transmission-%{version}

%if 0%{?use_libevent_intree}
%__tar xf "%{SOURCE9}"
%endif

%build
export CFLAGS=${RPM_OPT_FLAGS/-O2/-Os}
export CXXFLAGS=${RPM_OPT_FLAGS/-O2/-Os}
%if 0%{?suse_version} > 1000
export CFLAGS="$CFLAGS -fPIE -fstack-protector -fvisibility=protected"
export CXXFLAGS="$CXXFLAGS -fPIE -fstack-protector -fvisibility=protected"
%endif
export LDFLAGS="-Wl,--as-needed"

%if 0%{?use_libevent_intree}
# in-tree libevent
INTREE_LIBEVENT="$PWD/in-tree-libevent"
pushd libevent-*
./configure \
    --prefix="$INTREE_LIBEVENT" \
    --includedir="$INTREE_LIBEVENT/include" \
    --libdir="$INTREE_LIBEVENT/lib" \
    --enable-static \
    --disable-shared
%__make %{?jobs:-j%{jobs}}
%__make install
popd #libevent-*

%__rm -f "${INTREE_LIBEVENT}/lib"/libevent*.so "${INTREE_LIBEVENT}/lib"/libevent.so.*

export LIBEVENT_CFLAGS="-I${INTREE_LIBEVENT}/include"
export LIBEVENT_LIBS="${INTREE_LIBEVENT}/lib/libevent.a"
# ${INTREE_LIBEVENT}/lib/libevent_core.a ${INTREE_LIBEVENT}/lib/libevent_extra.a"
%endif


%configure \
%if %suse_version >= 1140
           --enable-gtk \
%endif
	   --disable-libcanberra \
           --enable-utp \
           --enable-cli \
           --enable-daemon \
           --enable-nls \
           --enable-dht \
           --with-inotify

%__make %{?jobs:-j%{jobs}} V=1

cd qt
qmake QMAKE_CXXFLAGS="$RPM_OPT_FLAGS -fPIC" qtr.pro
%__make %{?jobs:-j%{jobs}} V=1


%install
%makeinstall

cd qt
%__make install INSTALL_ROOT=%{buildroot}%{_prefix}
cd ..

touch %{buildroot}%{_bindir}/transmission
chmod 0755 %{buildroot}%{_bindir}/transmission
%if %suse_version >= 1140
touch %{buildroot}%{_mandir}/man1/transmission.1.gz


%suse_update_desktop_file transmission-gtk
%endif
%suse_update_desktop_file -i transmission-qt


%__rm -rf "%{buildroot}%{_datadir}/locale"/{an,ast,az,bn,bo,br,bs,ceb,ckb,eo,fa,fil,fo,hy,gv,ka,kk,ku,li,mk,ml,ms,mt,oc,si,sq,ta_LK,te,tl,ug,ur,uz}

install -d -m 755 $RPM_BUILD_ROOT/var/adm/fillup-templates
install -m 644 %{SOURCE100} $RPM_BUILD_ROOT/var/adm/fillup-templates/sysconfig.transmission-daemon
install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
install -m 755 %{SOURCE101} $RPM_BUILD_ROOT/etc/init.d/transmission-daemon
install -d -m 755 $RPM_BUILD_ROOT/var/cache/transmission

%if %suse_version >= 1140
%__rm -rf $RPM_BUILD_ROOT%{_datadir}/applications/transmission-gtk.desktop
install -m 644 %{SOURCE10} $RPM_BUILD_ROOT%{_datadir}/applications/transmission.desktop
%endif

#%__strip $RPM_BUILD_ROOT%{_bindir}/*


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

%post
update-alternatives --install %{_bindir}/transmission           transmission      %{_bindir}/transmission-cli 5         \
                    --slave   %{_mandir}/man1/transmission.1.gz transmission.1.gz %{_mandir}/man1/transmission-cli.1.gz

%if %suse_version >= 1140
%post gtk
update-alternatives --install %{_bindir}/transmission           transmission      %{_bindir}/transmission-gtk 15        \
                    --slave   %{_mandir}/man1/transmission.1.gz transmission.1.gz %{_mandir}/man1/transmission-gtk.1.gz
%if 0%{?suse_version} > 1130
%desktop_database_post
%endif
%endif

%post qt
update-alternatives --install %{_bindir}/transmission           transmission      %{_bindir}/transmission-qt 10         \
                    --slave   %{_mandir}/man1/transmission.1.gz transmission.1.gz %{_mandir}/man1/transmission-qt.1.gz
%if 0%{?suse_version} > 1130
%desktop_database_post
%endif

%postun
# Note: we don't use "$1 -eq 0", to avoid issues if the package gets renamed
if [ ! -f %{_bindir}/transmission-cli ]; then
  update-alternatives --remove transmission %{_bindir}/transmission-cli
fi


%if %suse_version >= 1140
%postun gtk
# Note: we don't use "$1 -eq 0", to avoid issues if the package gets renamed
if [ ! -f %{_bindir}/transmission-gtk ]; then
  update-alternatives --remove transmission %{_bindir}/transmission-gtk
fi
%if 0%{?suse_version} > 1130
%desktop_database_postun
%endif
%endif

%postun qt
# Note: we don't use "$1 -eq 0", to avoid issues if the package gets renamed
if [ ! -f %{_bindir}/transmission-qt ]; then
  update-alternatives --remove transmission %{_bindir}/transmission-qt
fi
%if 0%{?suse_version} > 1130
%desktop_database_postun
%endif

%pre daemon
/usr/sbin/useradd -r -o -g nogroup -u 55555 -s /bin/false -c "Transmission daemon" -d /var/cache/transmission transmission 2> /dev/null || :

%post daemon
%{fillup_and_insserv transmission-daemon}

%preun daemon
%stop_on_removal transmission-daemon

%postun daemon
%restart_on_update transmission-daemon
%{insserv_cleanup}
%verifyscript

%files
%defattr(-,root,root)
%doc AUTHORS web/LICENSE NEWS README COPYING
%{_bindir}/transmission-cli
%{_bindir}/transmission-create
%{_bindir}/transmission-show
%{_bindir}/transmission-remote
%{_bindir}/transmission-edit

%doc %{_mandir}/man1/transmission-remote.1*
%doc %{_mandir}/man1/transmission-create.1*
%doc %{_mandir}/man1/transmission-show.1*
%doc %{_mandir}/man1/transmission-edit.1*
%doc %{_mandir}/man1/transmission-cli.1*
%dir %{_datadir}/transmission
%{_datadir}/transmission/web

%if %suse_version >= 1140
%files gtk
%defattr(-,root,root)
%doc AUTHORS NEWS README COPYING
%{_bindir}/transmission-gtk
%{_datadir}/applications/transmission.desktop
%{_datadir}/pixmaps/%{name}.png
%{_datadir}/icons/*/*/apps/transmission.*
%doc %{_mandir}/man1/transmission-gtk.1*
%{_datadir}/locale/*/LC_MESSAGES/transmission-gtk.mo
%endif

%files qt
%defattr(-,root,root)
%doc AUTHORS NEWS README COPYING
%ghost %{_bindir}/transmission
%{_bindir}/transmission-qt
%{_datadir}/applications/transmission-qt.desktop
%if %suse_version >= 1140
%ghost %doc %{_mandir}/man1/transmission.1*
%endif
%doc %{_mandir}/man1/transmission-qt.1*

%files daemon
%defattr(-,root,root)
%{_bindir}/transmission-daemon
%config /etc/init.d/transmission-daemon
/var/adm/fillup-templates/sysconfig.transmission-daemon
%attr(-,transmission,nogroup)/var/cache/transmission
%doc %{_mandir}/man1/transmission-daemon.1*

%changelog