%define name		icewm
%define version		1.0.9
# ICEwm actually made the release part of the full version number.
# Leave the 2 intact.  (will need to do "2.n" for any patch updates).
%define release		2
%define group		User Interface/Desktops

%define prefix		%{_prefix}
%define exec_prefix	%{_prefix}
%define sysconfdir	%{_sysconfdir}
%define bindir		%{exec_prefix}/bin/
%define libdir		%{exec_prefix}/lib/X11/%{name}/
%define locdir		%{prefix}/share/locale/
%define docdir		%{_defaultdocdir}

# We configure and build 3 different versions of the executables --
#  default, gnome, and lite (minimal).  The primary app names are
#  symlinked to the default version, but all versions are available in
#  this package (e.g. icewm and icewm-default, icewm-gnome, and icewm-lite).
# 
%define default_apps	icewm icewmbg icewmhint icehelp
%define gnome_apps	icewm icewmbg icewmhint icehelp
%define all_apps	icewm icewmbg icewmhint icehelp

# ==============================================================================

Name:		%{name}
Version:	%{version}
Release:	%{release}
Summary:	IceWM X11 Window Manager
Group:		%{group}
Copyright:	LGPL
URL:		http://www.icewm.org/
Source:		http://download.sourceforge.net/icewm/%{name}-%{version}-%{release}.tar.gz
Patch0:		%{name}-%{version}-aix.patch
BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-buildroot
Requires:       imlib, gnome-libs
Provides:       %{name}-bin = %{version}-%{release}

%description
Window Manager for X Window System. Can emulate the look of Windows'95, OS/2
Warp 3,4, Motif or the Java Metal GUI. Tries to take the best features of the
above systems. Features multiple workspaces, opaque move/resize, task bar,
window list, mailbox status, digital clock. Fast and small.


%prep
%setup -q
%patch0 -p2 -b .aix

for i in default lite gnome; do
  mkdir -p ${i} && (cd ${i} && gzip -dc %{SOURCE0} | tar xf - ) 
  (cd ${i}/%{name}-%{version} && patch -p2 -b --suffix .aix -s < %{PATCH0} ) 
done


%build
(cd default/%{name}-%{version} # --------------- build the default version ---
  CXXFLAGS="$RPM_OPT_FLAGS" ./configure \
    --prefix=%{prefix} --exec-prefix=%{exec_prefix} --with-docdir=%{docdir} \
    --disable-debug --disable-i18n --enable-nls --disable-guievents \
    --without-gnome-menus --with-imlib
  make
)

(cd lite/%{name}-%{version} # --------------------- build the lite version ---
  CXXFLAGS="$RPM_OPT_FLAGS" ./configure \
    --prefix=%{prefix} --exec-prefix=%{exec_prefix} --with-docdir=%{docdir} \
    --disable-debug --disable-i18n --disable-nls --disable-guievents \
    --without-gnome-menus --with-xpm
  make
)

(cd gnome/%{name}-%{version} # ------------------- build the GNOME version ---
  {
    CXXFLAGS="$RPM_OPT_FLAGS" ./configure \
      --prefix=%{prefix} --exec-prefix=%{exec_prefix} --with-docdir=%{docdir} \
      --disable-debug --disable-i18n --enable-nls --disable-guievents \
      --with-gnome-menus --with-imlib && \
    make
  } || { \
    echo WARNING: Creating stub scripts because GNOME is not available.
    for stub in %{gnome_apps}; do
      cat >> src/$stub <<.
#!/bin/sh

cat <<+
The GNOME version of $stub %{version} was not compiled because
no development packages of GNOME were installed on `hostname`
building this RPM package.

Try to install the default binary package or the rebuild the
gnome package on a system having the GNOME development packages
installed.
+
.
      chmod a+x src/$stub
    done
  }
)

( cd default/%{name}-%{version} # --------------------- build documentation ---
  make docs icewm.lsm
)


%install
# ---------------------------- rename the binaries to ${basename}-${variant} ---
rm -fr $RPM_BUILD_ROOT

(cd default/%{name}-%{version}
  make install \
    prefix=$RPM_BUILD_ROOT%{prefix} \
    exec_prefix=$RPM_BUILD_ROOT%{exec_prefix} \
    sysconfdir=$RPM_BUILD_ROOT%{sysconfdir} \
    DOCDIR=$RPM_BUILD_ROOT%{docdir}
)

#variant from default was already installed via make install above
for variant in lite gnome; do
  for binary in %{all_apps}; do
    cp ${variant}/%{name}-%{version}/src/${binary} \
    	$RPM_BUILD_ROOT%{bindir}${binary}-${variant} || :
  done
done

# Move the default binaries to *-default, then symlink them.
# Users may want to relink the primary names to the gnome or lite versions
# on their own.
( cd $RPM_BUILD_ROOT%{bindir}
   for binary in %{default_apps}; do
      mv ${binary} ${binary}-default
      ln -s ${binary}-default ${binary}
   done
)

( cd $RPM_BUILD_ROOT

 /usr/bin/strip .%{prefix}/bin/* || :

 mkdir -p usr/bin
    cd usr/bin
    ln -sf ../..%{prefix}/bin/* .
    cd -
)


# --------------------------------------------------------------- file lists ---
%files
%defattr(-,root,root)
%doc README COPYING CHANGES TODO BUGS FAQ* doc/*.html doc/icewm.sgml
%doc default/%{name}-%{version}/icewm.lsm

%config %{libdir}/keys
%config %{libdir}/menu
%config %{libdir}/preferences
%config %{libdir}/toolbar
%config %{libdir}/winoptions

%dir %{libdir}/icons
%dir %{libdir}/ledclock
%dir %{libdir}/mailbox
%dir %{libdir}/taskbar
%dir %{libdir}/themes
%dir %{locdir}

%{libdir}/icons/*
%{libdir}/ledclock/*
%{libdir}/mailbox/*
%{libdir}/taskbar/*
%{libdir}/themes/*
%{locdir}/*

%{bindir}*
/usr/bin/*


# ------------------------------------------------------------------ cleanup ---
%clean
test -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" && rm -rf $RPM_BUILD_ROOT


%changelog
* Thu Oct 25 2001 Kevin Monroe <monroek@us.ibm.com> 1.0.9-2
- Remove ICEWMEXEVARIANT envar; no longer needed
- Upgrade to 1.0.9-2

* Mon Aug 27 2001 Kevin Monroe <monroek@us.ibm.com> 1.0.8-6
- Remove icesound for AIX compatibility
- Add imlib to default version 
- Add environment variable to determine which icewm to use

* Sat Jul 28 2001 David Clissold <cliss@austin.ibm.com> 1.0.8-1
- Consolidate into one package.

* Mon Jul 16 2001 Kevin Monroe <monroek@us.ibm.com>
- Change group to reflect RedHat's group list.
- Change .bz2 and bzip2 references to .gz and gzip.
- Patch default, lite, and gnome sources in %prep.
- Change _os to _target_os to build noarch package.
- Change 'hostname -f' to 'hostname'.
- Incorporate the following from Marc Stephenson <marc@austin,ibm.com>:
  - Change pushd/popd to subshell
  - Change prefix

* Mon May 07 2001 Mathias Hasselmann <mathias.hasselmann@gmx.de> 1.0.8-6
- icewm-default was missed to call make
  -> icewm compiled by %install
  -> binaries contained invalid paths

* Mon Apr 02 2001 Mathias Hasselmann <mathias.hasselmann@gmx.de> 1.0.8-3
- allow to rebuild on systems without GNOME
- removed the virtual icewm-bin from icewm-common
- marked menu, toolbar, keys, preferences and winoptions as %config files

* Fri Mar 23 2001 Mathias Hasselmann <mathias.hasselmann@gmx.de> 1.0.8-1
- move the docs from icewm-common-%{version} to icewm-%{version}
- cleaned (post) installation scripts

* Sun Mar 04 2001 Mathias Hasselmann <mathias.hasselmann@gmx.de> 1.0.7-3
- some icehelp trouble

* Fri Feb 16 2001 Pavel Roskin <proski@gnu.org> 1.0.7-2
- fixed the bash2 problem

* Sat Jan 27 2001 Mathias Hasselmann <mathias.hasselmann@gmx.de> 1.0.7-1
- added icehelp and icesound

* Sat Jan 14 2001 Mathias Hasselmann <mathias.hasselmann@gmx.de> 1.0.6-4
- last minute feature: shadowed title bars

* Fri Jan 12 2001 Mathias Hasselmann <mathias.hasselmann@gmx.de> 1.0.6-3
- renamed again: icewm-common-VERSION-RELEASE.noarch.rpm and
  icewm-{default,lite,gnome}-VERSION-RELEASE.ARCH.rpm
- noarch.rpm is built recursively by the src.rpm
- support for docdir (Mandrake)

* Mon Jan  8 2001 Mathias Hasselmann <mathias.hasselmann@gmx.de> 1.0.6-2
- translated messages weren't packaged
- new macros: bindir, libdir, localedir

* Mon Jan  8 2001 Mathias Hasselmann <mathias.hasselmann@gmx.de> 1.0.6-1
- "Backported" to RPM3 (%make variable)
- icewm.lsm was not packaged
- changed icewm-{lite,default,gnome} to icewm-{lite,default,gnome} to
  avoid confusion
- extended default description

* Thu Jan  4 2001 Alexander Skwar <ASkwar@DigitalProjects.com> 1.0.5-1
- Completely rewrote spec file to do away with needing
  three different src.rpm's
