%define snapshot	20051030
%define desktop_file	1

Name:		licq
Version:	1.3.2
Release:	%{!?snapshot:1}%{?snapshot:0.%{snapshot}}.100asp
Summary:	An ICQ clone for online messaging.
License:	GPL
Group:		Applications/Communications
URL:		http://www.licq.org
Source0:	http://licq.org/%{name}-%{!?snapshot:%{version}}%{?snapshot:daily}.tar.bz2
Source1:	licq-wrapper.sh
Source4:	licq-ru.po.gz
Patch0:		licq-1.3.0-cdk.asp.patch
Patch1:		licq-20050601-htmlview.asp.patch
BuildRoot:	%{_tmppath}/%{name}-root
BuildPrereq:	libtool, XFree86-devel, libmng-devel
BuildPrereq:	openssl-devel pkgconfig
BuildRequires:	autoconf >= 2.53, automake >= 1.5
BuildRequires:	qt-devel >= 3.0, qt-designer >= 3.0

%define osd_en	0

%if %osd_en
BuildRequires:	xosd-devel >= 2.1
Requires:	xosd >= 2.1
%endif

BuildRequires:	perl >= 5.005
BuildRequires:	XFree86-devel fam-devel
# always build qt plugin with KDE support
BuildRequires:	kdelibs-devel
BuildRequires:  cdk-devel >= 4.9.0
Requires:	htmlview
Requires:	cdk >= 4.9.0
Obsoletes:	licq-base licq-plugins 
Conflicts:	licq-data < 1.6
%if %desktop_file
BuildRequires:	desktop-file-utils
%endif
Obsoletes:	licq-gtk
Obsoletes:	licq-text
Obsoletes:	licq-gnome

%define osd_lang	licq_osd_plugin

%description
Licq is an ICQ online messaging system clone, written in C++ using the
Qt widget set. Licq supports all of the major features of ICQ,
including messaging, URLs, chat, file transfer, and user information.
Additionally, Licq is very configurable and supports skins and
different icon packs.

%package	devel
Summary:	Development collection for licq.
Provides:	licq-devel
Requires:	%{name} = %{version}
Group:		Applications/Communications

%description devel
Licq is an ICQ online messaging system clone.
Licq supports all of the major features of ICQ, including messaging, URLs,
chat, file transfer, and user information.

Licq-devel is a development collection for licq.

%package kde
Summary:	KDE frontend for licq.
Provides:	licq-frontend
Requires:	%{name} = %{version}
Group:		Applications/Communications

%description kde
Licq is an ICQ online messaging system clone.
Licq supports all of the major features of ICQ, including messaging, URLs,
chat, file transfer, and user information.

Licq-kde is a KDE frontend for licq.

%package qt
Summary:	Qt frontend for licq.
Provides:	licq-frontend
Requires:	%{name} = %{version}
Group:		Applications/Communications
Obsoletes:	licq-ui-qt

%description qt
Licq is an ICQ online messaging system clone. Licq supports all of
the major features of ICQ, including messaging, URLs, chat, file
transfer, and user information.

Licq-qt is a graphical frontend for licq, written in Qt.

%prep
%if %snapshot
%setup -q -T -b 0 -n %{name}-%{snapshot}
%else
%setup -q -T -b 0
%endif

%patch0 -p1 -b .cdk
%patch1 -p1 -b .htmlview

# remove console plugin
rm -rf plugins/console

# put ru.po
%if 0
zcat %{SOURCE4} > po/ru.po
perl -pi -e 's|^(\s*[^\#\s]+.*[^\s]+)\s*$|$1 ru\n|' po/LINGUAS
%endif

# Don't confuse make
find . -type d -name CVS | xargs rm -rf
find . -type d -name autom4te.cache | xargs rm -rf

ln -sf . include/licq
# ugly hack: prevent libtoolize (called by %%configure) from
# messing with us!
make -f Makefile.cvs

%build
if pkg-config openssl ; then
 export CFLAGS="$CFLAGS $RPM_OPT_FLAGS `pkg-config --cflags openssl`"
 export CPPFLAGS="$CPPFLAGS `pkg-config --cflags-only-I openssl`"
 export LDFLAGS="$LDFLAGS `pkg-config --libs-only-L openssl`"
fi

TOPDIR=`pwd`

[ -z "$QTDIR" ] && source %{_sysconfdir}/profile.d/qt.sh

CXXFLAGS="$RPM_OPT_FLAGS" CFLAGS="$RPM_OPT_FLAGS" \
%configure
make

# build plugins
for i in plugins/*; do
  if [ -d $i ]; then
    cd $i
	[ -f Makefile.cvs ] && make -f Makefile.cvs
	CXXFLAGS="$RPM_OPT_FLAGS" CFLAGS="$RPM_OPT_FLAGS" \
	%configure --with-kde --with-licq-includes=$TOPDIR/include
	make CFLAGS="$RPM_OPT_FLAGS \
		    -DPACKAGE=\\\"licq\\\" -DVERSION=\\\"%{version}\\\" \
                    -DHAVE_ERRNO_H"
    cd ../..
  fi
done

# Hack: build the Qt GUI plugin again. We need it both with and without KDE
# support.
cd plugins/qt-gui
rm -f config.cache src/*.lo src/.libs/*.o
%configure
make

# qt3 localization
lrelease qt-gui.pro
cd ../..

%install
rm -rf $RPM_BUILD_ROOT

export KDEDIR=$RPM_BUILD_ROOT/usr
mkdir -p $RPM_BUILD_ROOT/usr/share/applnk

mkdir -p $RPM_BUILD_ROOT%{_bindir}
mkdir -p $RPM_BUILD_ROOT%{_includedir}
%makeinstall \
	    plugindir="$RPM_BUILD_ROOT%{_libdir}/licq" \
	    sharedir="$RPM_BUILD_ROOT%{_datadir}/licq" \
	    includedir="$RPM_BUILD_ROOT%{_includedir}/licq"

# install plugins
for i in plugins/*; do
  if [ -d $i ]; then
    if echo $i |grep qt-gui; then # the Qt GUI Makefiles are BROKEN!
      make -C $i prefix="$RPM_BUILD_ROOT%{_prefix}" \
    	    sharedir="$RPM_BUILD_ROOT%{_datadir}/licq" \
	    plugindir="$RPM_BUILD_ROOT%{_libdir}/licq" \
	    install
    else
      make -C $i DESTDIR="$RPM_BUILD_ROOT" \
    	    sharedir="$RPM_BUILD_ROOT%{_datadir}/licq" \
	    plugindir="$RPM_BUILD_ROOT%{_libdir}/licq" \
	    install
    fi
  fi
done
( cd plugins
  for i in *; do
    if [ -d $i/doc ]; then
      cp -a $i/doc ../doc/$i
    else
      mkdir ../doc/$i
    fi
    cp -f $i/README* ../doc/$i
  done
)
install -c -m755 plugins/qt-gui*/src/.libs/licq_kde-gui.lai $RPM_BUILD_ROOT%{_libdir}/licq/licq_kde-gui.la
install -c -m755 plugins/qt-gui*/src/.libs/licq_kde-gui.so $RPM_BUILD_ROOT%{_libdir}/licq

mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/X11
mv $KDEDIR/share/applnk $RPM_BUILD_ROOT%{_sysconfdir}/X11
mv $RPM_BUILD_ROOT%{_bindir}/licq $RPM_BUILD_ROOT%{_libdir}/licq/licq-bin

chmod 0755 $RPM_BUILD_ROOT%{_datadir}/licq
chmod 0755 $RPM_BUILD_ROOT%{_datadir}/licq/qt-gui
chmod 0755 $RPM_BUILD_ROOT%{_datadir}/licq/qt-gui/*

perl -p -e 's|\@LIBDIR\@|%{_libdir}|g' \
	%{SOURCE1} > $RPM_BUILD_ROOT%{_bindir}/licq
chmod 0755 $RPM_BUILD_ROOT%{_bindir}/licq

# Licq
%find_lang %{name}

# OSD
%if %osd_en
%find_lang %{osd_lang}
cat %{osd_lang}.lang >> %{name}.lang
%endif

%if %{desktop_file}
mkdir -p $RPM_BUILD_ROOT%{_datadir}/applications
desktop-file-install --delete-original --vendor net \
        --dir $RPM_BUILD_ROOT%{_datadir}/applications \
        --add-category "Application;Network;X-Red-Hat-Extra" \
        $RPM_BUILD_ROOT%{_sysconfdir}/X11/applnk/Internet/licq.desktop
%endif

# fix doc
mv -f README README.new

# remove undesired files
find $RPM_BUILD_ROOT -name "viewurl-*" | xargs rm -f

%clean
rm -rf $RPM_BUILD_ROOT

%files -f %{name}.lang
%defattr (-,root,root)
%doc doc/* upgrade/* README*
%attr(755,root,root) %{_bindir}/licq
%dir %{_libdir}/licq
%{_libdir}/licq/licq-bin
%{_libdir}/licq/*.so
%exclude %{_libdir}/licq/licq_qt-gui*
%exclude %{_libdir}/licq/licq_kde-gui*
%exclude %{_libdir}/licq/*.la
%{_datadir}/licq
%if %{desktop_file}
%{_datadir}/applications/*
%else
%{_sysconfdir}/X11/applnk/Internet/*
%endif

%files devel
%defattr (-,root,root)
%{_includedir}/licq

%files qt
%defattr(-,root,root)
%{_libdir}/licq/licq_qt-gui*

%files kde
%defattr(-,root,root)
%{_libdir}/licq/licq_kde-gui*

%changelog
* Sat Oct 29 2005 Arkady L. Shane <shejn@msiu.ru>
- update to 20051030

* Thu Sep 15 2005 Andy Shevchenko <andriy@asplinux.ru>
- update to 20050915

* Mon Sep 05 2005 Andy Shevchenko <andriy@asplinux.ru>
- update to 20050905

* Tue Jul 19 2005 Andy Shevchenko <andriy@asplinux.ru>
- update to 20050719
- temporary disable console plugin

* Wed Jun 15 2005 Andy Shevchenko <andriy@asplinux.ru>
- update to 20050611
- fix version and release in spec

* Thu Jun 02 2005 Andy Shevchenko <andriy@asplinux.ru>
- update to 20050601
- fix default html viewer

* Thu Sep 30 2004 Andy Shevchenko <andriy@asplinux.ru> 1.3.0
- update to last release
- add patch for cdk
- time to start new changelog
