%define ver     4.13b
%define rel 28

Summary: Converts text and other types of files to PostScript(TM).
Name: a2ps
Version: %{ver}
Release: %{rel}
License: GPL
Group: Applications/Publishing
Source: ftp://ftp.enst.fr/pub/unix/a2ps/%{name}-%{version}.tar.gz
Source1: ftp://ftp.enst.fr/pub/unix/a2ps/i18n-fonts-0.1.tar.gz
Patch0: a2ps-4.13-conf.patch
Patch1: a2ps-4.13-etc.patch
Patch2: a2ps-4.13-flex.patch
Patch3: a2ps-4.13-security.patch
Patch4: a2ps-4.13-glibcpaper.patch
Patch5: a2ps-4.13-varargs.patch
# EUC-JP support
Patch10: a2ps-4.13-eucjp.patch.bz2
Patch11: a2ps-4.13-autoenc.patch
Patch12: a2ps-4.13b-attr.patch
Patch13: a2ps-4.13b-numeric.patch
Patch14: a2ps-4.13b-encoding.patch
Patch15: a2ps-4.13b-tilde.patch
Patch16: a2ps-4.13b-rm.patch
Patch17: a2ps-4.13-euckr.patch
Requires: fileutils sh-utils info
Buildrequires: /usr/bin/emacs
Url: http://www.inf.enst.fr/~demaille/a2ps/
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Requires: psutils
Obsoletes: a2ps-i18n
Provides: a2ps-i18n

%description
The a2ps filter converts text and other types of files to PostScript(TM).
A2ps has pretty-printing capabilities and includes support for a wide
number of programming languages, encodings (ISO Latins, Cyrillic, etc.),
and medias.

%prep
%setup -q -n %{name}-4.13 -a 1
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1 -b .security
%patch4 -p1 -b .glibcpaper
%patch5 -p1

%patch10 -p1 -b .euc
%patch11 -p1 -b .ae
%patch12 -p1 -b .attr

# Use C locale's decimal point style (bug #53715).
%patch13 -p1 -b .numeric

# Use locale to determine a sensible default encoding (bug #64584).
%patch14 -p1 -b .encoding

# Fix koi8 tilde (bug #66393).
%patch15 -p1 -b .tilde

# Prevent configure from going interactive (bug #70333).
%patch16 -p1 -b .rm

# Add Korean resource file (bug #81421).
%patch17 -p1 -b .euckr

libtoolize --copy --force

%build
chmod 644 {po/ja.po,encoding/euc-jp.edf,README.eucJP}.euc
chmod 644 encoding/euc-kr.edf.euckr
touch `find $PWD`
EMACS=emacs ./configure \
  --prefix=%{_prefix} \
  --libdir=%{_libdir} \
  --sysconfdir=%{_sysconfdir} \
  --infodir=%{_infodir} \
  --mandir=%{_mandir} \
  --datadir=%{_datadir} \
  --with-medium=_glibc \
  --enable-kanji

# Remove prebuilt info files to force regeneration at build time
find . -name "*.info*" -exec rm -f {} \;
# force rebuilding scanners by flex - patched or not
find src lib -name '*.l' -exec touch {} \;
# these scanners use 'lineno' - incompatible with -CFe flex flags
(
    cd src
    /bin/sh ../auxdir/ylwrap "flex" sheets-map.l lex.yy.c sheets-map.c --
    /bin/sh ../auxdir/ylwrap "flex" lexssh.l lex.yy.c lexssh.c --
    cd ../lib
    /bin/sh ../auxdir/ylwrap "flex" lexppd.l lex.yy.c lexppd.c --
)

make

%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

mkdir -p %{buildroot}%{_datadir}/a2ps/{afm,fonts}
pushd i18n-fonts-0.1/afm
install -m 0644 *.afm %{buildroot}%{_datadir}/a2ps/afm
pushd ../fonts
install -m 0644 *.pfb %{buildroot}%{_datadir}/a2ps/fonts
popd
popd

### FIXME ###
inst()
{
mkdir -p %{buildroot}%{_datadir}/emacs/site-lisp/
for f in contrib/emacs/*.el; do \
  install -m 0644 $f %{buildroot}%{_datadir}/emacs/site-lisp/ ; done
}

rm -f $RPM_BUILD_ROOT%{_infodir}/dir
gzip $RPM_BUILD_ROOT%{_infodir}/* || :

%find_lang %name

%clean
rm -rf $RPM_BUILD_ROOT

%post
/sbin/install-info %{_infodir}/a2ps.info.gz %{_infodir}/dir
/sbin/install-info %{_infodir}/ogonkify.info.gz %{_infodir}/dir
/sbin/install-info %{_infodir}/regex.info.gz %{_infodir}/dir
(cd %{_datadir}/a2ps/afm;
        ./make_fonts_map.sh > /dev/null 2>&1 || /bin/true
        if [ -f fonts.map.new ]; then
            mv fonts.map.new fonts.map
        fi
)

%preun
if [ $1 = 0 ]; then
   /sbin/install-info --delete %{_infodir}/a2ps.info.gz %{_infodir}/dir
   /sbin/install-info --delete %{_infodir}/ogonkify.info.gz %{_infodir}/dir
   /sbin/install-info --delete %{_infodir}/regex.info.gz %{_infodir}/dir
fi

%files -f %{name}.lang
%defattr(-,root,root)
%config (noreplace) %{_sysconfdir}/a2ps.cfg
%config(noreplace) %{_sysconfdir}/a2ps-site.cfg
%doc AUTHORS ChangeLog COPYING NEWS README TODO THANKS
%{_bindir}/*
%{_libdir}/*.a
%{_libdir}/*.la
%{_includedir}/*
%{_infodir}/a2ps.info*
%{_infodir}/ogonkify.info*
%{_infodir}/regex.info*
%{_mandir}/*/*
%config %{_datadir}/a2ps/afm/fonts.map
%{_datadir}/a2ps/afm/*.afm
%{_datadir}/a2ps/afm/make_fonts_map.sh
%{_datadir}/a2ps/README
%{_datadir}/a2ps/encoding
%{_datadir}/a2ps/fonts
%{_datadir}/a2ps/ppd
%{_datadir}/a2ps/ps
%{_datadir}/a2ps/sheets
%{_datadir}/ogonkify/
%{_datadir}/emacs/site-lisp/*
%dir %{_datadir}/a2ps/afm
%dir %{_datadir}/a2ps

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

* Thu Jan  9 2003 Tim Waugh <twaugh@redhat.com> 4.13b-27
- Add Korean resource file (bug #81421).

* Tue Jan  7 2003 Jeff Johnson <jbj@redhat.com> 4.13b-26
- don't include -debuginfo files in package.

* Wed Nov 20 2002 Tim Powers <timp@redhat.com>
- rebuild on all arches
- remove lingering files from the buildroot that we aren't shipping
- pass %%{_libdir} and %%{_datadir} to configure so that we are lib64'ized
- fix bad perms on some files

* Mon Aug  5 2002 Tim Waugh <twaugh@redhat.com> 4.13b-24
- Prevent configure from going interactive (bug #70333).
- Try to cope with UTF-8 a little bit (bug #70057).

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

* Fri Jun 21 2002 Tim Waugh <twaugh@redhat.com> 4.13b-22
- Fix koi8 tilde (bug #66393).

* Thu May 30 2002 Tim Waugh <twaugh@redhat.com> 4.13b-21
- Provide a2ps-i18n (bug #65231).
- Fix default encoding (bug #64584).

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

* Mon Feb 25 2002 Tim Waugh <twaugh@redhat.com> 4.13b-19
- Rebuild in new environment.

* Tue Jan 22 2002 Tim Waugh <twaugh@redhat.com> 4.13b-18
- Fix a2ps-4.13-conf.patch (bug #31360).
- Add documentation about the default behaviour concerning LC_PAPER
  (bug #43829).

* Wed Jan 09 2002 Tim Powers <timp@redhat.com> 4.13b-17
- automated rebuild

* Wed Jan  9 2002 Tim Waugh <twaugh@redhat.com>
- Fix build with newer compiler.
- s/Copyright:/License:/.
- Use C locale's decimal point style (bug #53715).

* Fri Jun  1 2001 Oliver Paukstadt <oliver.paukstadt@millenux.com>
- fixed varargs-usage in title.c

* Thu Apr 26 2001 Florian La Roche <Florian.LaRoche@redhat.de>
- call libtoolize to allow easy porting to new archs

* Thu Feb 28 2001 SATO Satoru <ssato@redhat.com>
- bunzip2-ed all patches except eucjp

* Thu Feb 22 2001 SATO Satoru <ssato@redhat.com>
- support Japanese
- bzip2-ed all patches
- replace macros (%%makeinstall, %%configure) with traditional
  commands to avoid some troubles those macros caused.

* Tue Feb 20 2001 Trond Eivind Glomsrød <teg@redhat.com>
- Using letter is as weird as oz, fl. oz, Fahrenheit, lb etc.
  Add a patch for using the glibc media type for giving US
  letter for en_US (only locale with this paper), and A4
  for everyone else.

* Tue Feb 20 2001 Tim Powers <timp@redhat.com>
- changed default medium back to letter (bug 27794)

* Mon Feb 19 2001 Trond Eivind Glomsrød <teg@redhat.com>
- langify
- use %%{_tmppath}

* Mon Feb 12 2001 Tim Waugh <twaugh@redhat.com>
- Fix tmpfile security patch so that it actually _works_ (bug #27155).

* Sun Jan 21 2001 Tim Waugh <twaugh@redhat.com>
- New-style prereq line.
- %%post script requires fileutils (mv) and sh-utils (true).  This
  should fix bug #24251).

* Mon Jan 08 2001 Trond Eivind Glomsrød <teg@redhat.com>
- Add /usr/bin/emacs to BuildRequires
- A4
- specify use of GNU Emacs for building

* Fri Jan 05 2001 Preston Brown <pbrown@redhat.com>
- security patch for tmpfile creation from Olaf Kirch <okir@lst.de>

* Mon Dec 11 2000 Preston Brown <pbrown@redhat.com>
- obsoleted old a2ps-i18n package (it was tiny) and included those fonts
  directly here.

* Thu Dec  7 2000 Tim Powers <timp@redhat.com>
- built for dist-7.1

* Mon Aug 07 2000 Tim Powers <timp@redhat.com>
- update to 4.13b to fix some bugs, thanks to czar@acm.org for giving me a
  heads up on this (bug #15679)

* Mon Jul 24 2000 Prospector <prospector@redhat.com>
- rebuilt

* Mon Jul 10 2000 Tim Powers <timp@redhat.com>
- rebuilt

* Fri Jun 23 2000 Tim Powers <timp@redhat.com>
- info pages weren't getting gzipped.
- stdout & stderror redirected to /dev/null in post section

* Mon Jun 19 2000 Tim Powers <timp@redhat.com>
- fixed bug 12451 which was a stupid mistake by me.
- quiet the post section
- added patches from michal@ellpspace.math.ualberta.ca and did some spec file
  magic he suggested as well.

* Fri Jun 2 2000 Tim Powers <timp@redhat.com>
- fixed bug 5876, was not setting the paper size to Letter again :(
- man pages and info pages to /usr/share, FHS compliant.
- used macros wherever possible

* Wed May 31 2000 Tim Powers <timp@rehat.com>
- fixed bug #11078, now requires psutils

* Wed Apr 26 2000 Tim Powers <timp@redhat.com>
- updated to 4.13
- compress man pages

* Thu Feb 10 2000 Tim Powers <timp@redhat.com>
- gzip man pages
- strip binaries

* Mon Jan 24 2000 Tim Powers <timp@redhat.com>
- had to be more specific since the i18n stuff was removed from the package.
        There is a new a2ps-i18n package which treats the
        /usr/share/a2ps/afm/fonts.map file as a config file

* Wed Oct 27 1999 Tim Powers <timp@redhat.com>
- added the --with-medium=Letter option to the configure process

* Thu Aug 5 1999 Tim Powers <timp@redhat.com>
- fixed problems with missing dirs as reported in bug 3822
- built for powertools

* Tue Jul 6 1999 Tim Powers <timp@redhat.com>
- rebuilt for powertools 6.1

* Wed May 12 1999 Bill Nottingham <notting@redhat.com>
- add a2ps-site.cfg

* Mon Apr 26 1999 Preston Brown <pbrown@redhat.com>
- update to 4.12 for Powertools 6.0

* Sat Oct 24 1998 Jeff Johnson <jbj@redhat.com>
- narrower range of %files splats.
- install info correctly.
- new description/summary text.

* Tue Oct 06 1998 Michael Maher <mike@redhat.com>
- updated source

* Sat Jul 04 1998 Michael Maher <mike@redhat.com>
- built package