%define isClean 1

%define debug 0

%define build_for_ftp 0

%define strip_bin 0
%define final 0
%define rpm_clean 1

%define desktop_file 1
%define desktop_file_utils_version 0.2.93

%define kbattleship 0
%define ktron 0

%define qt_version 3.1.1

Version: 3.1
Release: 4
Epoch: 6
Summary: K Desktop Environment - Games
Name: kdegames
Prefix: /usr
License: GPL
Group: Amusements/Games
BuildRoot: %{_tmppath}/%{name}-buildroot

Source: ftp://ftp.kde.org/pub/kde/stable/%{version}/src/%{name}-%{version}.tar.bz2
Patch: kde-libtool.patch

%if %{build_for_ftp}
ExclusiveArch: %{ix86}
%endif

%if %{desktop_file}
BuildRequires:desktop-file-utils >= %{desktop_file_utils_version}
%endif

Requires: kdelibs >= 6:%{version}-7

BuildRequires: libjpeg-devel
BuildRequires: libpng-devel
BuildRequires: zlib-devel
BuildRequires: kdelibs-devel >= 6:%{version}-7
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: libtool
BuildRequires: glibc-devel
BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: libstdc++-devel
BuildRequires: qt-devel >= %{qt_version}
BuildRequires: perl

%description
Games and gaming libraries for the K Desktop Environment.
Included with this package are: kenolaba, kasteroids, kblackbox, kmahjongg,
kmines, konquest, kpat, kpoker, kreversi, ksame, kshisen, ksokoban, ksmiletris,
ksnake, ksirtet, katomic, kjumpingcube, ktuberling.

%package devel
Summary: Development files for kdegames
Group: Development/Libraries
Requires: %{name} = %{epoch}:%{version}-%{release}

%description devel
Development files for the KDE gaming libraries.
Install kdegames-devel if you wish to develop or compile games for the
KDE desktop.

%prep
%setup -q
%patch -p1 -b .libtool

# Workaround for legacy auto* tools
[ -x /usr/bin/autoconf-2.5? ] && ln -s /usr/bin/autoconf-2.5? autoconf
[ -x /usr/bin/autoheader-2.5? ] && ln -s /usr/bin/autoheader-2.5? autoheader
[ -x /usr/bin/aclocal-1.5 ] && ln -s /usr/bin/aclocal-1.5 aclocal
[ -x /usr/bin/automake-1.5 ] && ln -s /usr/bin/automake-1.5 automake
export PATH=`pwd`:$PATH
# End workaround

make -f Makefile.cvs

%build
unset QTDIR || : ; . /etc/profile.d/qt.sh

%if %{kbattleship}
DO_NOT_COMPILE="kbattleship"
rm -rf rm -rf doc/kbattleship kbattleship
%endif

%if %{ktron}
DO_NOT_COMPILE="$DO_NOT_COMPILE ktron"
rm -rf doc/ktron ktron
%endif

export DO_NOT_COMPILE
export KDEDIR=%{prefix}

FLAGS="$RPM_OPT_FLAGS -DNO_DEBUG -DNDEBUG -fno-use-cxa-atexit"

CFLAGS="$FLAGS" \
CXXFLAGS="$FLAGS -fno-check-new" \
%configure \
   --includedir=%{prefix}/include/kde \
   --with-qt-libraries=$QTDIR/lib \
   --enable-final

# workaround for gcc bug
%ifarch alpha
perl -pi -e "s|-O2|-O0|g" kmines/solver/Makefile
%endif

make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT

%if %{strip_bin}
make install-strip DESTDIR=$RPM_BUILD_ROOT
%else
make install DESTDIR=$RPM_BUILD_ROOT
%endif

# Make symlinks relative
pushd $RPM_BUILD_ROOT/usr/share/doc/HTML/en
for i in *; do
   if [ -d $i -a -L $i/common ]; then
      rm -f $RPM_BUILD_ROOT/usr/share/doc/HTML/en/$i/common
      ln -sf ../common $RPM_BUILD_ROOT/usr/share/doc/HTML/en/$i
   fi
done
popd

%if %{desktop_file}
mkdir -p $RPM_BUILD_ROOT%{_datadir}/applications

desktop-file-install --vendor kde \
  --dir $RPM_BUILD_ROOT%{_datadir}/applications \
  --add-category "Application;Game;StrategyGame;X-Red-Hat-Base" \
  --delete-original \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/TacticStrategy/katomic.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/TacticStrategy/konquest.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/TacticStrategy/ksokoban.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Kidsgames/ktuberling.desktop

desktop-file-install --vendor kde \
  --dir $RPM_BUILD_ROOT%{_datadir}/applications \
  --add-category "Application;Game;ArcadeGame;X-Red-Hat-Base" \
  --delete-original \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Arcade/kasteroids.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Arcade/kbounce.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Arcade/kfouleggs.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Arcade/ksirtet.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Arcade/ksmiletris.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Arcade/kspaceduel.desktop

desktop-file-install --vendor kde \
  --dir $RPM_BUILD_ROOT%{_datadir}/applications \
  --add-category "Application;Game;BoardGame;X-Red-Hat-Base" \
  --delete-original \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Board/kbackgammon.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Board/kblackbox.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Board/kenolaba.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Board/kshisen.desktop

desktop-file-install --vendor kde \
  --dir $RPM_BUILD_ROOT%{_datadir}/applications \
  --add-category "Application;Game;CardGame;X-Red-Hat-Base" \
  --delete-original \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Card/kpoker.desktop \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Games/Card/lskat.desktop

for i in Arcade Board Card TacticStrategy ; do
  case "$i" in
    Arcade) d="ArcadeGame" ;;
    Board) d="BoardGame" ;;
    Card) d="CardGame" ;;
    TacticStrategy) d="StrategyGame";;
    *) d="$i" ;;
  esac
  if /bin/ls $RPM_BUILD_ROOT%{_datadir}/applnk/Games/$i/*.desktop >& /dev/null ; then
    desktop-file-install --vendor kde \
      --dir $RPM_BUILD_ROOT%{_datadir}/applications \
      --add-category "Application;Game;$d;X-Red-Hat-Base" \
      --add-only-show-in KDE \
      --delete-original \
      $RPM_BUILD_ROOT%{_datadir}/applnk/Games/$i/*.desktop
  fi
done

desktop-file-install --vendor kde \
  --dir $RPM_BUILD_ROOT%{_datadir}/applications \
  --add-category "Application;Toys;X-Red-Hat-Base" \
  --add-only-show-in KDE \
  --delete-original \
  $RPM_BUILD_ROOT%{_datadir}/applnk/Toys/*.desktop
%endif

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%clean
%if %{rpm_clean}
rm -rf $RPM_BUILD_ROOT
%endif

%files
%defattr(-,root,root)
%{_bindir}/*
%{_libdir}/*.so*
%{_libdir}/*.la
%{_libdir}/kde3/*
%{_datadir}/apps/*
%{_datadir}/icons/*/*/*/*
%{_datadir}/services/*
%{_datadir}/config/magic/*
%{_datadir}/mimelnk/application/*
%if %{desktop_file}
%{_datadir}/applications/*
%else
%{_datadir}/applnk/*
%endif
%doc %{_docdir}/HTML/en/*

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

%changelog
* Mon Feb 24 2003 Elliot Lee <sopwith@redhat.com>
- debuginfo rebuild

* Fri Feb 21 2003 Than Ngo <than@redhat.com> 3.1-3
- get rid of gcc path from dependency_libs

* Thu Feb 13 2003 Than Ngo <than@redhat.com> 3.1-2
- rebuild against new arts

* Tue Jan 28 2003 Than Ngo <than@redhat.com> 3.1-1
- 3.1 final

* Mon Jan 27 2003 Than Ngo <than@redhat.com> 3.1-0.6
- add missing plugins
- cleanup specfile

* Thu Jan 23 2003 Tim Powers <timp@redhat.com> 6:3.1-0.5
- rebuild

* Tue Jan 14 2003 Thomas Woerner <twoerner@redhat.com> 3.1-0.3
- fixed missing file

* Tue Jan 14 2003 Thomas Woerner <twoerner@redhat.com> 3.1-0.3
- rc6
- removed size_t check
- excluded ia64

* Fri Nov 29 2002 Than Ngo <than@redhat.com> 3.1-0.2
- desktop file issues

* Wed Nov 27 2002 Than Ngo <than@redhat.com> 3.1-0.1
- update to 3.1 rc4

* Sun Nov 10 2002 Than Ngo <than@redhat.com> 3.0.5-1
- update to 3.0.5

* Tue Oct 15 2002 Than Ngo <than@redhat.com> 3.0.4-1
- 3.0.4

* Fri Sep 13 2002 Than Ngo <than@redhat.com> 3.0.3-3.1
- Fixed to build on x86_64

* Thu Aug 29 2002 Preston Brown <pbrown@redhat.com>
- remove kbattleship and ktron (#72763)

* Fri Aug 23 2002 Than Ngo <than@redhat.com> 3.0.3-2
- desktop files issues (bug #72408)

* Mon Aug 12 2002 Than Ngo <than@redhat.com> 3.0.3-1
- 3.0.3
- desktop files issues

* Tue Jul 23 2002 Tim Powers <timp@redhat.com> 3.0.2-2
- build using gcc-3.2-0.1

* Tue Jul 09 2002 Than Ngo <than@redhat.com> 3.0.2-1
- 3.0.2
- use desktop-file-install

* Fri Jun 21 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Thu May 23 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Fri May 10 2002 Bernhard Rosenkraenzer <bero@redhat.com> 3.0.1-1
- 3.0.1

* Tue Apr 16 2002 Bernhard Rosenkraenzer <bero@redhat.com> 3.0.0-2
- Change sonames

* Wed Mar 27 2002 Than Ngo <than@redhat.com> 3.0.0-1
- final

* Wed Mar  6 2002 Bernhard Rosenkraenzer <bero@redhat.com> 3.0.0-0.cvs20020306.1
- Fix packaging glitch in monolithic version

* Tue Mar  5 2002 Bernhard Rosenkraenzer <bero@redhat.com> 3.0.0-0.cvs20020305.1
- Make splits a buildtime option (off by default) on request

* Mon Jan  7 2002 Bernhard Rosenkraenzer <bero@redhat.com> 3.0.0-0.cvs20020107.1
- Update to work with latest kdelibs changes

* Wed Dec 26 2001 Bernhard Rosenkraenzer <bero@redhat.com> 3.0.0-0.cvs20011226.1
- Update
- Add missing %{_bindir}/kbattleship

* Sat Dec 15 2001 Bernhard Rosenkraenzer <bero@redhat.com> 3.0.0-0.cvs20011215.1
- Update
- Split into several packages (one package per game)

* Sun Jul 22 2001 Bernhard Rosenkraenzer <bero@redhat.com> 2.2-0.cvs20010722.1
- Update
- Work around ia64 breakages
- Add build requirements (#48977)

* Thu Feb 22 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- Fix problem when changing the card type (Bug #28824)

* Wed Feb 21 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- 2.1-respin

* Tue Feb 20 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- 2.1

* Sun Feb 11 2001 Than Ngo <than@redhat.com>
- don't use make -j CPU, it's broken

* Thu Feb  1 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- Run ldconfig in %%post and %%postun to make libkdegames happy
- Replace absolute symlinks with relative symlinks (#24787)

* Mon Jan 22 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- Update
- includedir=/usr/include/kde,
  now that libkdegames installs kcarddeck.h

* Wed Jan 17 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- Get rid of the gcc bug workaround, it's no longer needed

* Mon Jan  1 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- Update
- Don't exclude ia64

* Wed Nov 15 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- Update to HEAD

* Sat Oct 28 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- Update to KDE_2_0_BRANCH, now that the ".0 release" bugs are fixed.

* Mon Oct 16 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- 2.0 final

* Tue Oct  3 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- 2.0

* Mon Oct  2 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- new CVS
- work around g++ bugs (in kjumpingcube)

* Thu Aug 24 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- 1.93

* Mon Aug  7 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- new version

* Wed Jul 19 2000 Than Ngo <than@redhat.de>
- fix docdir
- rebuild 16 July snapshot

* Thu Jul 13 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- SMPify
- don't hardcode QTDIR

* Tue Jul 11 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- use gcc 2.96
- new snapshot

* Tue Jun 20 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- new snapshot
- ExcludeArch ia64 for now

* Sat Mar 18 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- new snapshot
- move it to /usr, where it belongs

* Fri Oct 22 1999 Bernhard Rosenkraenzer <bero@redhat.de>
- 2.0 snapshot

* Fri Sep 24 1999 Preston Brown <pbrown@redhat.com>
- mark doc files as such

* Thu Sep 09 1999 Preston Brown <pbrown@redhat.com>
- 1.1.2 release.

* Fri Jun 11 1999 Preston Brown <pbrown@redhat.com>
- snapshot, includes kde 1.1.1 + fixes

* Mon Apr 19 1999 Preston Brown <pbrown@redhat.com>
- last snapshot before release
- ripped out asteroids and sirtet

* Mon Apr 12 1999 Preston Brown <pbrown@redhat.com>
- latest stable snapshot

* Wed Feb 24 1999 Preston Brown <pbrown@redhat.com>
- Injected new description and group.

* Mon Feb 08 1999 Preston Brown <pbrown@redhat.com>
- upgraded to KDE 1.1 final.

* Fri Feb 05 1999 Preston Brown <pbrown@redhat.com>
- rebuilt for new libstdc++ etc.

* Wed Jan 06 1999 Preston Brown <pbrown@redhat.com>
- re-merged updates from Duncan Haldane, change /opt/kde --> /usr