Name:           cups-pdf
Summary:        Extension for creating pdf-Files with CUPS
Summary(ja):    CUPS を用いた仮想 PDF プリンター
Version:        3.0.1
Release:        2%{?_dist_release}
Group:          publishing
Vendor:         Project Vine
Distribution:   Vine Linux

License:        GPLv2+
URL:            https://www.cups-pdf.de/
Source0:        https://www.cups-pdf.de/src/%{name}_%{version}.tar.gz
Source1:        INSTALL.cups-pdf

Patch0:         cups-pdf-conf-vine.patch
# Handle ${DESKTOP} from config
Patch2:         cups-pdf-desktop.patch
# Handle new lines in title
Patch3:         cups-pdf-title.patch
# Fix build warning
Patch4:         cups-pdf-build.patch
# Report error/success in log
Patch5:         cups-pdf-result.patch
# Replace removed gs .setpdfwrite option
Patch6:         cups-pdf-setpdfwrite.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires:    cups-devel
Requires:         ghostscript, cups
Requires(post):   cups
Requires(postun): cups

# These are the defaults paths defined in config.h
# CUPS-PDF spool directory
%global CPSPOOL   %{_localstatedir}/spool/cups-pdf/SPOOL

# CUPS-PDF output directory
%global CPOUT     %{_localstatedir}/spool/cups-pdf

# CUPS-PDF log directory
%global CPLOG     %{_localstatedir}/log/cups

# CUPS-PDF cups-pdf.conf config file
%global ETCCUPS   %(cups-config --serverroot 2>/dev/null || echo %{_sysconfdir}/cups)

# Additional path to backend directory
%global CPBACKEND %(cups-config --serverbin  2>/dev/null || echo %{_libdir}/cups)/backend


%description
"cups-pdf" is a backend script for use with CUPS - the "Common UNIX Printing
System" (see more for CUPS under http://www.cups.org/). 
"cups-pdf" uses the ghostscript pdfwrite device to produce PDF Files.

This version has been modified to store the PDF files on the Desktop of the 
user. This behavior can be changed by editing the configuration file.

%description -l ja
cups-pdf は CUPS (Common UNIX Printing System, http://www.cups.org/) を用いたいわゆる仮想 PDF プリンタのためのバックエンドスクリプトです。
cups-pdf は PDF ファイルを生成するために Ghostscript の pdfwrite デバイスを使います。

CUPS が動作しているときに %{name} をインストールすると、自動的に "CUPS-PDF Printer" として CUPS の設定を行います。


%debug_package


%prep
%setup -n %{name}-%{version}
%patch0 -p1 -b .vine
%patch2 -p0 -b .desktop
%patch3 -p0 -b .title
%patch4 -p0 -b .build
%patch5 -p0 -b .result
%patch6 -p0 -b .setpdfwrite

cp -p %{SOURCE1} INSTALL.RPM


%build
pushd src
%{__cc} $RPM_OPT_FLAGS -lcups -o cups-pdf cups-pdf.c
popd


%install
%__rm -rf ${RPM_BUILD_ROOT}

%__mkdir_p $RPM_BUILD_ROOT%{CPBACKEND}
%__mkdir_p $RPM_BUILD_ROOT%{CPSPOOL}
%__mkdir_p $RPM_BUILD_ROOT%{CPOUT}
%__mkdir_p $RPM_BUILD_ROOT%{CPLOG}
%__mkdir_p $RPM_BUILD_ROOT%{CPBACKEND}
%__mkdir_p $RPM_BUILD_ROOT%{ETCCUPS}
%__mkdir_p $RPM_BUILD_ROOT%{_datadir}/cups/model/
%__install -m644 extra/{CUPS-PDF_noopt,CUPS-PDF_opt}.ppd  %{buildroot}%{_datadir}/cups/model/
%__install -m644 extra/cups-pdf.conf $RPM_BUILD_ROOT%{ETCCUPS}/
%__install -m755 src/cups-pdf $RPM_BUILD_ROOT%{CPBACKEND}


%clean
[ "%{buildroot}" != "/" ] && %__rm -rf %{buildroot}


%post
# First install : create the printer if cupsd is running
if [ "$1" -eq "1" -a -f "%{_var}/run/cupsd.pid" ]
then
    /sbin/service cups condrestart
    if [ -d /proc/$(cat %{_var}/run/cupsd.pid) ]
    then
	echo "Install CUPS-PDF Printer ... "
        /usr/sbin/lpadmin -p Cups-PDF -v cups-pdf:/ -m CUPS-PDF.ppd -E || :
    fi
fi

%postun
if [ "$1" -eq "0" ]; then
    # Delete the printer
    echo "Remove CUPS-PDF Printer ... "
    /usr/sbin/lpadmin -x Cups-PDF || :
fi


%files
%defattr(-,root,root)
%license COPYING
%doc ChangeLog README INSTALL.RPM
%dir %{CPSPOOL}
%dir %{CPOUT}
%attr(700, root, root) %{CPBACKEND}/cups-pdf
%config(noreplace) %{ETCCUPS}/cups-pdf.conf
%{_datadir}/cups/model/CUPS-PDF*.ppd


%changelog
* Sun Jul 11 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.0.1-2
- imported Patch6 from rawhide for newer ghostscript.

* Tue May 28 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.0.1-1
- new upstream release.
- updated Patch2-5.

* Sun Mar 15 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 2.6.1-1
- new upstream release
- updated Patch0
- added Patch3, 4 and 5 from Fedora
  * Mon Sep 23 2013 Remi Collet <remi@fedoraproject.org> 2.6.1-7
  - report success/error in log file #1010434
  * Tue Mar 19 2013 Remi Collet <remi@fedoraproject.org> 2.6.1-4
  - fix title detection
  - fix build warning

* Fri Feb 25 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2.5.1-1
- new upstream release
- fixed %%description -l ja

* Sun Jul 26 2009 Munehiro Yamamoto <munepi@vinelinux.org> 2.5.0-4
- rename Patch0 to cups-pdf-conf-vine.patch
- updated cups-pdf-conf-vine.patch
  - set Truncate 256
- change cups-pdf.conf to %%config(noreplace) in %%files section

* Wed Jul 08 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 2.5.0-3
- updated cups-pdf.conf.vl.patch: set DecodeHexStrings 1 (Experimental)

* Tue Jul 07 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 2.5.0-2
- added cups-pdf_2.5.0-4.diff.gz from Ubuntu
  - applied 60_cups-pdf_remove-contrib-SELinux-HOWTO-bashisms.patch
  - applied 70_cups-pdf_support-pdf-workflow.patch
- added some comments in %%description -l ja
- added echo "install/remove CUPS-PDF Printer" in %%post and %%postun
- removed INSTALL and added README in %%doc

* Sat Feb 14 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 2.5.0-1
- new upstream release
- updated the URL tag
- correct the License tag

* Tue Dec 30 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 2.4.8-2
- fixed typo in spec

* Wed Oct 29 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 2.4.8-1
- new upstream release

* Sun Sep 21 2008 Shu KONNO <owa@bg.wakwak.com> 2.4.6-1vl5
- applied new versioning policy, spec in utf-8

* Thu Jun 28 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 2.4.6-0vl2
- rebuld for VineSeed

* Thu Jun 28 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 2.4.6-0vl1
- source update
- delete -dNOKANJI option of Ghostscript

* Sun Mar 25 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 2.4.5-0vl1
- initial build for Vine Linux 4.1

* Mon Sep 26 2005	Christian Ellsworth C. <k.ellsworth@gmail.com>
- adapted to fit the new runtime config file of version 2.0

* Sat Mar 05 2005	Christian Ellsworth C. <k.ellsworth@gmail.com>
- adapted to cups-pdf 1.7.0
- added auto configure a cups-pdf printer

* Tue Feb 22 2005	Christian Ellsworth C. <k.ellsworth@gmail.com>
- adapted to cups-pdf 1.6.6

* Thu Aug 12 2004	Volker Behr <vrbehr@cip.physik.uni-wuerzburg.de>
- adapted to cups-pdf 1.5.2 

* Sat Jan 31 2004	Volker Behr <vrbehr@cip.physik.uni-wuerzburg.de>
- adapetd to cups-pdf 1.4.0 and new building environment

* Wed Jan 14 2004	Mark Lane <harddata.com>
- fixed the specfile so that x86_64 version installs the filter
- in /usr/lib64 instead of /usr/lib

* Sun Nov 02 2003	Volker Behr <vrbehr@cip.physik.uni-wuerzburg.de>
- third release of cups-pdf, RPM-Edition for cups-pdf 1.3

* Tue Sep 09 2003	Dirk Schwier <rpms@raumhochdrei.de>
- second Release of cups-pdf, RPM-Edition for cups-pdf 1.1

* Tue May 27 2003	Dirk Schwier <rpms@raumhochdrei.de>
- we're proud to present the first version of cups-pdf, RPM-Edition

# end of file
