%define name hexchat
%define version 2.12.0
%define release 1%{?_dist_release}

Summary: IRC client based on XChat
Summary(ja): XChat をベースにした IRC クライアント
Name:      %{name}
Version:   %{version}
Release:   %{release}
Group:     Applications/Internet
License:   GPLv2
URL:       http://hexchat.github.io/

Source0: http://dl.hexchat.net/hexchat/hexchat-%{version}.tar.xz
Buildroot: %{_tmppath}/%{name}-%{version}-root

Patch0: xchat-1.8.7-use-sysconf-to-detect-cpus.patch
Patch110: http://takuo.jp/junk/xchat/99_x_dialog.dpatch
Patch200: hexchat-2.9.5_defaultserver-vine.patch

BuildRequires: autoconf
BuildRequires: dbus-devel
BuildRequires: dbus-glib-devel
BuildRequires: desktop-file-utils
BuildRequires: gettext
BuildRequires: glib2-devel >= 2.10.0
BuildRequires: gtk2-devel >= 2.10.0
BuildRequires: openssl-devel
BuildRequires: pciutils-devel
BuildRequires: perl
BuildRequires: pkgconfig
BuildRequires: python-devel
BuildRequires: tcl

%description
HexChat is an easy to use graphical IRC chat client for the X Window System.
It allows you to join multiple IRC channels (chat rooms) at the same time, 
talk publicly, private one-on-one conversations etc. Even file transfers
are possible.


%package devel
Summary: Development files for hexchat
Summary(ja): hexchat を使った開発に必要なファイル
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}

%description devel
Development files for hexchat.

%description -l ja devel
hexchat の開発ファイルです。

%prep
%setup -q

%patch0 -p0 -b .use-sysconf-to-detect-cpus
%patch110 -p1 -b .dialog
%patch200 -p1 -b .servlist

%build
#./autogen.sh

find -type f -exec chmod a-x {} \;
find -name configure -exec chmod a+x {} \;

%configure --disable-textfe \
           --enable-openssl \
           --enable-python \
           --enable-shm \
           --disable-spell \
           --disable-rpath \
           --enable-ipv6

make %{?_smp_mflags}


%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

# Remove unwanted stuff
find $RPM_BUILD_ROOT -type f -name '*.la' -exec rm -rf {} \;

# Remove unused schema
rm -f %{buildroot}%{_sysconfdir}/gconf/schemas/apps_hexchat_url_handler.schemas

desktop-file-install \
    --delete-original \
    --add-mime-type='x-scheme-handler/irc;x-scheme-handler/ircs' \
    --set-key=Exec --set-value='sh -c "hexchat --existing --url %U || exec hexchat"' \
    %{buildroot}/%{_datadir}/applications/hexchat.desktop

%find_lang %{name}

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

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

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

%clean
rm -rf $RPM_BUILD_ROOT

%files -f %{name}.lang
%defattr(-,root,root)
#%doc share/doc/*
%{_bindir}/hexchat
%{_libdir}/hexchat/plugins/*.so
%{_datadir}/appdata/hexchat.appdata.xml
%{_datadir}/applications/hexchat.desktop
%{_datadir}/dbus-1/services/*
%{_datadir}/icons/hicolor/*
%{_mandir}/man1/%{name}.1.gz

%files devel
%defattr(-,root,root)
%{_includedir}/%{name}-plugin.h
%{_libdir}/pkgconfig/hexchat-plugin.pc

%changelog
* Sat Apr 23 2016 Toshiharu Kudoh <toshi.kd2@gmail.com> - 2.12.0-1
- new upstream release

* Sat Jan 24 2015 Toshiharu Kudoh <toshi.kd2@gmail.com> - 2.10.2-1
- new upstream release

* Tue Jul 01 2014 Toshiharu Kudoh <toshi.kd2@gmail.com> - 2.10.0-1
- new upstream release

* Sat Apr 12 2014 Toshiharu Kudoh <toshi.kd2@gmail.com> - 2.9.6.1-2
- rebuilt with new toolchain

* Sat Oct 12 2013 Toshiharu Kudoh <toshi.kd2@gmail.com> - 2.9.6.1-1
- new upstream release

* Sat Aug 31 2013 Toshiharu Kudoh <toshi.kd2@gmail.com> - 2.9.5-1
- new upstream release
