File transmission.spec of Package transmission

# norootforbuild

%define use_libevent_intree 1


%if %suse_version >= 1320
%define use_qt 1
%else
%define use_qt 0
%endif

Name:           transmission
Version:        2.94
Release:        1.1
Summary:        Lightweight, yet powerful BitTorrent client
Source:         http://download.m0k.org/transmission/files/transmission-%{version}.tar.bz2
Source4:        transmission-qt.appdata.xml
Source9:        https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
Source10:       transmission.desktop
Source100:	transmission-daemon.sysconfig
Source101:	transmission-daemon.init

%if %suse_version >= 1200
Source102:      transmission-daemon-systemd
BuildRequires:  systemd-devel
%endif
# PATCH-FIX-UPSTREAM transmission-appdata.patch badshah400@gmail.com -- Add and install appdata files for both gtk and qt applications; enable translations for the gtk metainfo
Patch0:         transmission-appdata.patch
# Patch0 touches autotool files

Patch100:	const_increment-2.81.patch

Url:            http://www.transmissionbt.com/
Group:          Productivity/Networking/Other
License:        GPL-2 ; MIT
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
BuildRequires:  automake
BuildRequires:  libtool

%if %suse_version >= 1220
BuildRequires:  gtk3-devel
#BuildRequires:  glib2-devel
%endif

BuildRequires:  libevent-devel >= 2.0.0
%if %suse_version >= 1220
%if %use_qt
BuildRequires:  libqt5-linguist
BuildRequires:  libqt5-qtbase-devel
%endif
BuildRequires:  libminiupnpc-devel
%endif

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 >= 1220
%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

%if %use_qt
%if %suse_version >= 1210
%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.
%endif
%endif

%package daemon
License:        GPLv2 ; MIT License (or similar)
Summary:        Lightweight, yet powerful BitTorrent client
Group:          Productivity/Networking/Other
%if %suse_version >= 1200
%{?systemd_requires}
%endif

%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
%patch0 -p1
%patch100 -p1

%build
export CFLAGS=${RPM_OPT_FLAGS/-O2/-Os -fno-strict-aliasing}
export CXXFLAGS=${RPM_OPT_FLAGS/-O2/-Os -fno-strict-aliasing}
%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

# Prevent m4_copy error when running aclocal
# m4_copy: won't overwrite defined macro: glib_DEFUN
rm m4/glib-gettext.m4 || exit 1
autoreconf
%configure \
%if %suse_version >= 1220
           --enable-gtk \
%endif
	   --disable-libcanberra \
           --enable-utp \
           --enable-cli \
           --enable-daemon \
           --enable-nls \
           --enable-dht \
           --with-inotify

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

%if %use_qt
%if %suse_version >= 1210
cd qt
qmake-qt5 QMAKE_CXXFLAGS="%{optflags} -fPIC" qtr.pro
%__make %{?jobs:-j%{jobs}} V=1
%endif
%endif

%install
%makeinstall

%if %use_qt
%if %suse_version >= 1210
cd qt
%__make install INSTALL_ROOT=%{buildroot}%{_prefix}
cd ..
install -Dm0644 %{S:4} %{buildroot}%{_datadir}/appdata/transmission-qt.appdata.xml
%endif
%endif

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

%if %use_qt
%if %suse_version >= 1210
%suse_update_desktop_file -i transmission-qt
%endif
%endif

%__rm -rf "%{buildroot}%{_datadir}/locale"/{an,ast,az,bn,bo,br,bs,ceb,ckb,eo,fa,fil,fo,hy,gv,ka,kk,ku,ky,li,mk,ml,ms,my,mt,oc,si,sq,sw,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 >= 1200
install -D -m 0644 %{S:102} %{buildroot}%{_unitdir}/transmission-daemon.service
%endif

%if %suse_version >= 1220
%__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 >= 1220
%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

%if %use_qt
%if %suse_version >= 1210
%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
%desktop_database_post
%endif
%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 >= 1220
%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

%if %use_qt
%if %suse_version >= 1210
%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
%endif
%endif

%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

%ghost %{_bindir}/transmission

%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 >= 1220
%dir %{_datadir}/appdata
%endif

%if %suse_version >= 1220
%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.*
%{_datadir}/appdata/transmission-gtk.appdata.xml
%doc %{_mandir}/man1/transmission-gtk.1*
%{_datadir}/locale/*/LC_MESSAGES/transmission-gtk.mo
%if %suse_version >= 1140
%ghost %doc %{_mandir}/man1/transmission.1*
%endif
%endif

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

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

%changelog