# Define if you want to build the sane backend (default)
%define sane_backend 1

Summary: HP OfficeJet low level driver infrastructure
Name: hpoj
Version: 0.91
Release: 0vl2
License: GPL
Group: System Environment/Daemons
Source: http://hpoj.sourceforge.net/download/%{name}-%{version}.tgz
Source1: hpoj.png
# Wrapper script to start "xojpanel" with device auto-detection
Source2: allxojpanels
Patch0: hpoj-ppc.patch
Patch2: hpoj-lib64.patch
Patch5: hpoj-0.90-quiet.patch
Patch6: hpoj-0.90-perl.patch
Patch7: hpoj-0.90-netsnmp.patch
Patch8: hpoj-selinux.patch
Patch9: hpoj-0.91-kernel26.patch
Patch10: hpoj-pack.patch
Url: http://hpoj.sourceforge.net
Requires: net-snmp
Prereq: glibc
%if %{sane_backend}
BuildRequires: sane-devel
%endif
BuildRequires: net-snmp-devel, qt-devel >= 3.0.0, openssl-devel, libusb-devel
BuildRoot: %{_tmppath}/%{name}-buildroot
ExcludeArch: s390 s390x

%description

This is an HP-sponsored project to add Linux support for most
Hewlett-Packard OfficeJet, PSC, and LaserJet all-in-one peripherals
(also known as Multi-Function Peripherals or MFPs), which can print,
scan, copy, and (on some models) fax.

It is work in progress, but printing, scanning, and photo-card access
are supported on most models, when either connected to the parallel
port or USB on a Linux (Intel or Alpha) workstation, or to a LAN with
selected HP JetDirect print servers.


%if %{sane_backend}
%package -n libsane-hpoj
Summary: SANE driver for scanners in HP's multi-function devices (from HPOJ)
Group: System Environment/Daemons
Requires: sane
%endif

%if %{sane_backend}
%description -n libsane-hpoj
SANE driver for scanners in HP's multi-function devices (from HPOJ)
%endif

%package -n hpoj-devel
Summary: Headers required to compile against the "hpoj" library
Group: Development/Libraries
Requires: hpoj = %{version}-%{release}
Provides: hpoj-devel = %{version}-%{release}

%description -n hpoj-devel
This package contains all the files which are required to compiles programs
using the "hpoj" libraries.

%package -n xojpanel
Summary: Graphical tool displaying the contents of the LCD of HP printers
Group: Applications/System
Requires: hpoj
Conflicts: hpoj < 0.90

%description -n xojpanel
Graphical tool displaying the contents of the LCD of HP multi-function
devices and laser printers. Very useful to monitor the state (paper, ink,
running job) of a printer directly on one's workstation's screen.

%prep
rm -rf $RPM_BUILD_DIR/%{name}-%{version}
%setup -q -n %{name}-%{version}

%ifarch ppc
%patch0 -p1
%endif

# lib64 fixes
%patch2 -p1 -b .lib64
# Quieten init script (bug #79870).
%patch5 -p1 -b .quiet
# Work around bug #82652.
%patch6 -p1 -b .perl
# Use libnetsnmp not libsnmp (bug #105847).
%patch7 -p1 -b .netsnmp
# Fix up security contexts (bug #120054).
%patch8 -p1 -b .selinux
# Work with 2.6 kernel.
%patch9 -p1 -b .kernel26
# David Mosberger patch to avoid packing structs with fn ptrs.
%patch10 -p1 -b .pack

%build
# Fix hard-coded paths, also take into account paths mentioned in the docs
for i in `find . -type f -print`; do
    perl -p -i -e "s!doc/hpoj!doc/%{name}-%{version}!" $i
done
autoconf

%if !%{sane_backend}
WITHOUT_SANE="--without-sane"
%endif
unset QTDIR && . /etc/profile.d/qt.sh
%configure --enable-mt $WITHOUT_SANE --with-snmp=%{_includedir}/net-snmp/ucd-snmp

# Do not use the macro, it has parallelizing problems
make etcdir=%{_sysconfdir} docdir=%{_docdir}/%{name}-%{version}


%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_initrddir}

%makeinstall etcdir=%{buildroot}%{_sysconfdir}

# install menu icon
mkdir -p $RPM_BUILD_ROOT%{_datadir}/icons/Locolor/16x16/apps/
install -m 644 %{SOURCE1} $RPM_BUILD_ROOT%{_datadir}/icons/Locolor/16x16/apps/

# Install "xojpanel" wrapper
install -m 755 %{SOURCE2} $RPM_BUILD_ROOT%{_bindir}

# Install startup script
cat <<"EOF" >> %{buildroot}%{_initrddir}/hpoj
#!/bin/bash
# chkconfig: 2345 54 61
# description: ptal-init is the init script and device setup utility \
#              for the HP OfficeJet Linux driver.
# Should be started before and stopped after your print spooler (lpd or CUPS).
exec %{_sbindir}/ptal-init "$@"
EOF
chmod a+x %{buildroot}%{_initrddir}/hpoj

# Backend filter for CUPS
install -d %{buildroot}%{_libdir}/cups/backend
mv %{buildroot}%{_sbindir}/ptal-cups %{buildroot}%{_libdir}/cups/backend/ptal

# Make SANE scanner driver modules available in the right place (SANE
# only finds them in /usr/lib/sane, not in /usr/lib
%if %{sane_backend}
install -d %{buildroot}%{_libdir}/sane
ln -sf %{_libdir}/libsane-hpoj.so.1.0 %{buildroot}%{_libdir}/sane
ln -sf %{_libdir}/libsane-hpoj.so.1 %{buildroot}%{_libdir}/sane
ln -sf %{_libdir}/libsane-hpoj.so %{buildroot}%{_libdir}/sane
%endif

%post
# Let HPOJ daemon be automatically started at boot time
/sbin/chkconfig --add hpoj
/sbin/ldconfig

%if %{sane_backend}
%post -n libsane-hpoj
/sbin/ldconfig
# Add HPOJ driver to /etc/sane.d/dll.conf
if ! grep ^hpoj /etc/sane.d/dll.conf >/dev/null 2>/dev/null ; then \
	echo hpoj >> /etc/sane.d/dll.conf; \
fi
%endif

%preun
if [ "$1" = "0" ]; then
	/sbin/service hpoj stop > /dev/null 2>&1
	/sbin/chkconfig --del hpoj
fi
exit 0

%postun
/sbin/ldconfig
if [ "$1" -ge "1" ]; then
	/sbin/service hpoj condrestart > /dev/null 2>&1
fi
exit 0

%if %{sane_backend}
%preun -n libsane-hpoj
# Remove HPOJ driver from /etc/sane.d/dll.conf
if [ "$1" = 0 ]; then \
	if grep ^hpoj %{_sysconfdir}/sane.d/dll.conf >/dev/null 2>&1 ; then \
		sed '/^hpoj$/d' %{_sysconfdir}/sane.d/dll.conf > \
			%{_sysconfdir}/sane.d/dll.conf.rpmmod; \
		mv -f %{_sysconfdir}/sane.d/dll.conf.rpmmod \
			%{_sysconfdir}/sane.d/dll.conf; \
	fi; \
fi
%endif

%if %{sane_backend}
%postun -n libsane-hpoj -p /sbin/ldconfig
%endif

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%config(noreplace) %{_initrddir}/*
%{_sbindir}/*
%{_bindir}/ptal*
%{_bindir}/hpojip-test
%doc %{_defaultdocdir}/%{name}-%{version}
%{_libdir}/libptal*.so.*
%{_libdir}/libhpojip*.so.*
# CUPS backend
%{_libdir}/cups/backend/ptal

%if %{sane_backend}
%files -n libsane-hpoj
%defattr(-,root,root)
%{_libdir}/libsane-hpoj*.so*
%{_libdir}/sane/libsane-hpoj*.so*
%endif

%files -n xojpanel
%defattr(-,root,root)
%{_bindir}/xojpanel
%{_bindir}/allxojpanels
%{_datadir}/icons/Locolor/16x16/apps/*

%files -n hpoj-devel
%defattr(-,root,root)
%{_includedir}/ptal*
%{_includedir}/hpojip*


%changelog
* Tue Jan 04 2005 SAtoshi MACHINO <machino@vinelinux.org> 0.91-0vl2
- rebuilt for VineSeed

* Tue Jan 04 2005 Satoshi MACHINO <machino@vinelinux.org> 0.91-0vl0.31
- rebuilt for VineLinux 3.1
- fixed Requires of libsane-hpoj

* Mon Jan 03 2005 Satoshi MACHINO <machino@vinelinux.org> 0.91-0vl1
- rebuilt for VineLinux

* Fri Dec 10 2004 Tim Waugh <twaugh@rehdat.com> 0.91-11
- Ship CUPS backend in the right directory to avoid the need for a symbolic
  link (bug #123589).

* Fri Nov 12 2004 Tim Waugh <twaugh@rehdat.com> 0.91-10
- David Mosberger patch to avoid packing structs with fn ptrs.

* Wed Sep 22 2004 Than Ngo <than@redhat.com> 0.91-9
- add Prereq: /sbin/ldconfig

* Tue Jun 15 2004 Elliot Lee <sopwith@redhat.com>
- rebuilt

* Wed May  5 2004 Tim Waugh <twaugh@redhat.com> 0.91-7
- Fix up security contexts (bug #120054).

* Wed Mar  3 2004 Tim Waugh <twaugh@redhat.com> 0.91-6
- Updated Till Kamppeter's 2.6 kernel patch.

* Tue Mar 02 2004 Elliot Lee <sopwith@redhat.com>
- rebuilt

* Mon Mar  1 2004 Tim Waugh <twaugh@redhat.com> 0.91-5
- Really fix init script start-up order (bug #117206).

* Mon Feb 23 2004 Tim Waugh <twaugh@redhat.com> 0.91-4
- Apply Till Kamppeter's patch for 2.6 kernel support.

* Fri Feb 13 2004 Elliot Lee <sopwith@redhat.com>
- rebuilt

* Mon Dec  8 2003 Tim Waugh <twaugh@redhat.com> 0.91-2
- Fix init script start-up order (bug #111633).

* Mon Dec  1 2003 Tim Waugh <twaugh@redhat.com> 0.91-1
- 0.91.

* Tue Sep 30 2003 Tim Waugh <twaugh@redhat.com> 0.90-19
- Fix postun scriptlet.

* Mon Sep 29 2003 Tim Waugh <twaugh@redhat.com> 0.90-18
- Use libnetsnmp not libsnmp (bug #105847).

* Wed Jun 04 2003 Elliot Lee <sopwith@redhat.com> 0.90-17
- rebuilt

* Mon Apr  7 2003 Tim Waugh <twaugh@redhat.com> 0.90-16
- Make the initscript a separate file on its own.

* Mon Mar 24 2003 Tim Waugh <twaugh@redhat.com>
- The initscript shouldn't be a symlink into /usr.

* Tue Mar 18 2003 Tim Waugh <twaugh@redhat.com> 0.90-15
- Really really work around bug #82652.

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

* Sun Feb 23 2003 Tim Waugh <twaugh@redhat.com> 0.90-13
- Really work around bug #82652.

* Tue Feb 11 2003 Tim Waugh <twaugh@redhat.com> 0.90-12
- Work around bug #82652.

* Wed Jan 22 2003 Tim Powers <timp@redhat.com> 0.90-11
- rebuilt

* Thu Jan  9 2003 Tim Waugh <twaugh@redhat.com> 0.90-10
- Fix rebuild problem.

* Tue Jan  7 2003 Nalin Dahyabhai <nalin@redhat.com> 0.90-9
- Rebuild

* Sun Dec 29 2002 Florian La Roche <Florian.LaRoche@redhat.de>
- exclude mainframe

* Thu Dec 26 2002 Tim Waugh <twaugh@redhat.com> 0.90-7
- Update description.
- Don't create /dev/ptal-mlcd and ptal-printd.  These aren't used by
  hpoj anymore.

* Tue Dec 17 2002 Tim Waugh <twaugh@redhat.com> 0.90-6
- Quieten init script (bug #79870).

* Thu Dec 12 2002 Tim Waugh <twaugh@redhat.com> 0.90-5
- Fix and apply the libdir patch.
- Fix configure.in.

* Wed Dec 11 2002 Tim Waugh <twaugh@redhat.com> 0.90-4
- Adapted from contrib package (0.90-1).
- Changed group.
- Removed --with-qt=...
- Fix scriptlets.

* Sat Aug 10 2002 Till Kamppeter <till@mandrakesoft.com> 0.90-3mdk
- Rebuilt with gcc-3.2-0.3mdk.

* Sat Aug 10 2002 Pixel <pixel@mandrakesoft.com> 0.90-2mdk
- fix glob with spaces to please perl-base (especially for DrakX)

* Thu Aug  8 2002 Till Kamppeter <till@mandrakesoft.com> 0.90-1mdk
- Updated to HPOJ 0.9 final.

* Wed Aug  7 2002 Till Kamppeter <till@mandrakesoft.com> 0.90-0.12mdk
- BuildRequires: libopenssl-devel

* Wed Aug  7 2002 Till Kamppeter <till@mandrakesoft.com> 0.90-0.11mdk
- The "xojpanel" package conflicts with older "hpoj" package versions, added
  appropriate "Conflicts:" entry.

* Mon Aug  5 2002 Till Kamppeter <till@mandrakesoft.com> 0.90-0.10mdk
- Updated to current CVS (lock file name fix and documentation fixes).

* Mon Jul 29 2002 Gwenole Beauchesne <gbeauchesne@mandrakesoft.com> 0.90-0.9mdk
- Patch4: lib64 fixes in libraries lookup
- Let it build without SANE circularae dependency

* Sat Jul 27 2002 Till Kamppeter <till@mandrakesoft.com> 0.90-0.8mdk
- Updated to current CVS (Fixed xscanimage segfaulting when clicking
  on the preview area).

* Wed Jul 24 2002 Till Kamppeter <till@mandrakesoft.com> 0.90-0.7mdk
- Updated to current CVS (2nd release candidate for HPOJ 0.90).
- Corrected version number to 0.90.

* Mon Jul 22 2002 Till Kamppeter <till@mandrakesoft.com> 0.9-0.6mdk
- Updated to current CVS (1st release candidate for HPOJ 0.90).

* Thu Jun 27 2002 Till Kamppeter <till@mandrakesoft.com> 0.9-0.5mdk
- Updated to current CVS (last CVS broke printing after one or two 
  printouts).

* Mon Jun 24 2002 Till Kamppeter <till@mandrakesoft.com> 0.9-0.4mdk
- Moved menu updating in %%post and %%postun from main package to "xojpanel"
  sub package.

* Mon Jun 24 2002 Till Kamppeter <till@mandrakesoft.com> 0.9-0.3mdk
- Updated to current CVS.
- Separated off the xojpanel, so that the main package can easily be
  installed on an X-less server.

* Tue Jun 18 2002 Till Kamppeter <till@mandrakesoft.com> 0.9-0.2mdk
- Updated to current CVS
- Fixed setup for scanning (set links to scanner driver libraries, entry
  in /etc/sane.d/dll.conf)
- "ptal" backend for CUPS is in this package now
- Added "BuildRequires" line.

* Tue May 28 2002 Till Kamppeter <till@mandrakesoft.com> 0.9-0.1mdk
- Corrected path to QT 3 to make "xojpanel" getting compiled.
- Updated "allxojpanels" script.
- Bumped version number to 0.9.

* Tue May 28 2002 Till Kamppeter <till@mandrakesoft.com> 0.8-8mdk
- Updated to current CVS, version 0.8 is not compatible to gcc 3.1.
- Rebuilt for new libstdc++ and gcc 3.1.

* Sat Mar  2 2002 Till Kamppeter <till@mandrakesoft.com> 0.8-7mdk
- Fixed menu entry for "xojpanel", now a wrapper script searches for
  configured devices and starts "xojpanel" for these devices. 

* Fri Mar  1 2002 Till Kamppeter <till@mandrakesoft.com> 0.8-6mdk
- Patches for known problems from http://hpoj.sourceforge.net/todo.shtml
  (Patch2, Patch3)

* Wed Oct 24 2001 Vincent Saugey <vince@mandrakesoft.com> 0.8-5mdk
- Replace ucd-snmp require by libsnmp0

* Mon Oct 22 2001 Till Kamppeter <till@mandrakesoft.com> 0.8-4mdk
- Added patch to generate directories for the HPOJ daemons in the DevFS
  file system

* Sat Oct 20 2001 Stew Benedict <sbenedict@mandrakesoft.com> 0.8-3mdk
- patch for PPC build

* Wed Oct 10 2001 Till Kamppeter <till@mandrakesoft.com> 0.8-2mdk
- Rebuilt for libpng3.

* Wed Aug  8 2001 Till Kamppeter <till@mandrakesoft.com> 0.8-1mdk
- initial release