File splix.spec of Package splix

#
# spec file for package splix
#
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%bcond_with jbigkit

Name:           splix
Summary:        Driver for Samsung Printer Language printers
License:        GPL-2.0
Group:          Hardware/Printing
Version:        2.0.0
Release:        0
Url:            http://splix.ap2c.org/
Source0:        http://downloads.sourceforge.net/project/splix/splix/%{version}/%{name}-%{version}.tar.bz2
Source1:        http://splix.ap2c.org/samsung_cms.tar.bz2
Source2:        README.SUSE
Patch0:         %name-2.0.0-gcc45.patch
Patch1:         %name-libs.patch
Patch2:         %name-add-debuginfo.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  cups-devel
BuildRequires:  fdupes
BuildRequires:  gcc-c++
# All printer driver packages should have "BuildRequires: python-cups"
# because python-cups installs special rpm macros that adds Provides tags
# for the printer drivers supported by the package,
# see https://bugzilla.novell.com/show_bug.cgi?id=735865
BuildRequires:  python-cups
%if %{with jbigkit}
BuildRequires:  jbigkit-devel
%endif
Requires:       cups
# The Splix driver PPDs contain either
#   *cupsFilter: "application/vnd.cups-postscript 0 pstoqpdl"
# or
#   *cupsFilter: "application/vnd.cups-raster 0 rastertoqpdl"
# which means both require Ghostscript because
# either /usr/lib/cups/filter/pstoqpdl calls Ghostscript via
# /usr/lib/cups/filter/pstoraster or /usr/lib/cups/filter/gstoraster
# (see the post install scriptlet below)
# or /usr/lib/cups/filter/rastertoqpdl needs CUPS raster data as input
# that is produced by the cups device in Ghostscript
# (even the old ghostscript-library RPM e.g. in SLE11 provides ghostscript):
Requires:       ghostscript
# Provide and obsolete its old RPM package name "cups-drivers-splix"
# see https://bugzilla.novell.com/show_bug.cgi?id=659579
Provides:       cups-drivers-splix >= %version
Obsoletes:      cups-drivers-splix < %version

%description
SpliX is a set of CUPS printer drivers for SPL (Samsung Printer
Language) printers. Some Samsung, Xerox and Dell printers use that
language.

%prep
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1
%__cp %SOURCE2 .

%build
export CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing"
export CXXFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing"
%__make %{!?_with_jbigkit:DISABLE_JBIG=1} %{?jobs:-j%{jobs}} V=1

%install
%makeinstall %{!?_with_jbigkit:DISABLE_JBIG=1} 
pushd $RPM_BUILD_ROOT%_datadir/cups/model/samsung/
%__tar xjvf "%{SOURCE1}"
popd
gzip -9 %buildroot/%_datadir/cups/model/*/*.ppd
# Run fdupes:
# The RPM macro fdupes runs /usr/bin/fdupes that links files with identical content.
# Never run fdupes carelessly over the whole buildroot directory
# because in older openSUSE and SLE11 versions fdupes
# links files with different owner, group, or permissions
# see https://bugzilla.novell.com/show_bug.cgi?id=784670
# and even in current openSUSE versions fdupes links across sub-package boundaries,
# compare https://bugzilla.novell.com/show_bug.cgi?id=784869
# so that fdupes can only run for specific directories where linking files is safe:
%fdupes -s %{buildroot}/%{_datadir}/cups/model/samsung/cms

%clean
rm -fr %buildroot

%post
# Use a real bash script with an explicit "exit 0" at the end to be by default fail safe
# an explicit "exit 1" must be use to enforce package install/upgrade/erase failure where needed
# see the "Shared_libraries" section in http://en.opensuse.org/openSUSE:Packaging_scriptlet_snippets
# Make Splix working also for Ghostscript version >= 9.02:
# In /usr/lib/cups/filter/pstoqpdl there is a hardcoded call for /usr/lib/cups/filter/pstoraster.
# Since Ghostscript version 9.02 /usr/lib/cups/filter/pstoraster is replaced by /usr/lib/cups/filter/gstoraster.
# Accordingly when no /usr/lib/cups/filter/pstoraster exists, create an appropriate symlink
# so that /usr/lib/cups/filter/pstoqpdl works (see https://bugzilla.novell.com/show_bug.cgi?id=803005).
# Intentionally there is no test that /usr/lib/cups/filter/gstoraster exists because
# the required (but not pre-required) ghostscript RPM could be installed after splix.
# Note that only "test -e /usr/lib/cups/filter/pstoraster" (or "test -f") is insufficient because
# test follows symlinks which means when /usr/lib/cups/filter/pstoraster is already a (possibly broken)
# symbolic link to /usr/lib/cups/filter/gstoraster then test results false so that
# additionally it must be tested if /usr/lib/cups/filter/pstoraster is a symlink:
if ! test -e /usr/lib/cups/filter/pstoraster -o -L /usr/lib/cups/filter/pstoraster
then ln -s /usr/lib/cups/filter/gstoraster /usr/lib/cups/filter/pstoraster
fi
exit 0

%files
%defattr(-,root,root)
%doc COPYING README.SUSE
%dir %_datadir/cups
%dir %_datadir/cups/model
%dir %_datadir/cups/model/dell
%dir %_datadir/cups/model/samsung
%dir %_datadir/cups/model/xerox
# Use a plain simple fixed /usr/lib/cups/filter/ according
# to what is actually used by CUPS on all platforms:
%dir /usr/lib/cups/
%dir /usr/lib/cups/filter/
/usr/lib/cups/filter/pstoqpdl
/usr/lib/cups/filter/rastertoqpdl
%_datadir/cups/model/dell/*.ppd.gz
%_datadir/cups/model/samsung/*.ppd.gz
%_datadir/cups/model/samsung/cms
%_datadir/cups/model/xerox/*.ppd.gz

%changelog