%{!?_pkgdocdir: %global _pkgdocdir %{_docdir}/%{name}-%{version}}
%global _vendorperllibdir %{_datadir}/perl5/vendor_perl

Summary: A text formatting system based on SGML
Summary(ja): SGML に基づいたテキスト整形システム
Name: linuxdoc-tools
Version: 0.9.68
Release: 1%{?_dist_release}
License: distributable
Group: Applications/Text

Source0: http://http.us.debian.org/debian/pool/main/l/linuxdoc-tools/%{name}_%{version}.tar.gz
Patch0: linuxdoc-tools-0.9.13-letter.patch
Patch1: linuxdoc-tools-0.9.20-lib64.patch
Patch2: linuxdoc-tools-0.9.68-flex.patch

# Vine Patches
Patch100: linuxdoc-tools-0.9.68-platex.patch
#Patch101: linuxdoc-tools-0.9.21-replace_dvips.patch
# use ISO entities in 'sgml-common' package
Patch103: linuxdoc-tools-0.9.21-catalog_file.patch

Requires(post): sgml-common >= 0.5
Requires(postun): sgml-common >= 0.5
Requires: openjade, sgml-common >= 0.5
Requires: docbook-utils, texlive, gawk, groff
BuildRequires: openjade, flex, sgml-common >= 0.5
BuildRequires: task-texlive
BuildRequires: texinfo
Obsoletes: sgml-tools
Provides: sgml-tools
#Conflicts: docbook-dtds
Buildroot: %{_tmppath}/%{name}-%{version}-root

Vendor: Project Vine
Distribution: Vine Linux
Packager: daisuke

%description
linuxdoc-tools is a SGML-based text formatter which allows you to
produce a variety of output formats.  You can create PostScript and
dvi (with LaTeX), plain text (with groff), HTML, and texinfo files
from a single SGML source file.

%description -l ja
linuxdoc-tools は SGML-Tools のバグフィックス版です。
LinuxDoc DTD をサポートしており、SGML ソースファイルから PostScript,
(LaTeX による) dvi、(groff による)プレーンテキスト、HTML、texinfo
ファイルを生成できます。

DocBook DTD など、LinuxDoc DTD 以外のDTDを処理する場合には
このパッケージのかわりに、sgml-tools-2.x と docbook が必要になります。

%prep
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1

%patch100 -p1 -b .platex
#%patch101 -p1 -b .dvips
#%patch103 -p1 -b .catalog
#perl -i.bak -p -e "s/^(OPTIMIZE=).*$/\$1${RPM_OPT_FLAGS}/" Makefile.in sgmls-1.1/Makefile

%build
%configure --with-installed-iso-entities
# Packaging brain-damage
( cd entity-map
  autoconf
  %configure
)
make OPTIMIZE="$RPM_OPT_FLAGS"
perl -pi -e 's,\$main::prefix/share/sgml/iso-entities-8879.1986/iso-entities.cat,/usr/share/sgml/sgml-iso-entities-8879.1986/catalog,' \
           perl5lib/LinuxDocTools.pm

%install
[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf $RPM_BUILD_ROOT

mkdir -p $RPM_BUILD_ROOT/%{_vendorperllibdir}
make install DESTDIR=$RPM_BUILD_ROOT perl5libdir=%{_vendorperllibdir}
[ $RPM_BUILD_ROOT%{_docdir}/%{name} = $RPM_BUILD_ROOT%{_pkgdocdir} ] \
           || mv $RPM_BUILD_ROOT%{_docdir}/%{name} $RPM_BUILD_ROOT%{_pkgdocdir}
perl -pi -e 's,/usr/share/sgml/iso-entities-8879.1986/iso-entities.cat,\$main::prefix/share/sgml/sgml-iso-entities-8879.1986/catalog,' \
           $RPM_BUILD_ROOT%{_vendorperllibdir}/LinuxDocTools.pm
#Copy license files for parts into docdir
mkdir -p $RPM_BUILD_ROOT%{_pkgdocdir}/sgmls-1.1
cp -p sgmls-1.1/LICENSE $RPM_BUILD_ROOT%{_pkgdocdir}/sgmls-1.1/LICENSE
mkdir -p $RPM_BUILD_ROOT%{_pkgdocdir}/iso-entities
cp -p iso-entities/COPYING $RPM_BUILD_ROOT%{_pkgdocdir}/iso-entities/COPYING
mkdir -p $RPM_BUILD_ROOT%{_pkgdocdir}/entity-map
cp -p entity-map/COPYING $RPM_BUILD_ROOT%{_pkgdocdir}/entity-map/COPYING
cp -p COPYING $RPM_BUILD_ROOT%{_pkgdocdir}/


# Some files need moving around.
rm -f $RPM_BUILD_ROOT%{_datadir}/%{name}/epsf.*
rm -f $RPM_BUILD_ROOT%{_datadir}/%{name}/url.sty
install -d $RPM_BUILD_ROOT%{_datadir}/texmf/tex/latex/misc
mv $RPM_BUILD_ROOT%{_datadir}/%{name}/*.sty \
  $RPM_BUILD_ROOT%{_datadir}/texmf/tex/latex/misc

%clean
[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf $RPM_BUILD_ROOT

%post
# Update the centralized catalog corresponding to this version of the DTD
%{_bindir}/install-catalog --add %{_sysconfdir}/sgml/linuxdoc.cat %{_datadir}/linuxdoc-tools/linuxdoc-tools.catalog > /dev/null

%postun
if [ "$1" = 0 ]; then
# Update the centralized catalog corresponding to this version of the DTD
	%{_bindir}/install-catalog --remove %{_sysconfdir}/sgml/linuxdoc.cat %{_datadir}/linuxdoc-tools/linuxdoc-tools.catalog > /dev/null
fi

%files
%defattr(-,root,root)
%doc COPYING* ChangeLog INSTALL README VERSION debian/
%{_bindir}/*
%{_datadir}/entity-map
%{_datadir}/linuxdoc-tools
%{_datadir}/texmf/tex/latex/misc/*.sty
%dir %{_vendorperllibdir}/Text
%{_vendorperllibdir}/Text/EntityMap.pm
%dir %{_vendorperllibdir}/LinuxDocTools
%{_vendorperllibdir}/LinuxDocTools.pm
%{_vendorperllibdir}/LinuxDocTools/*.pm
%{_mandir}/*/*

%changelog
* Tue Jun 17 2014 Daisuke SUZUKI <daisuke@vinelinux.org> 0.9.68-1
- update to 0.9.68
- add BR: texinfo, task-texlive

* Sun Aug 08 2010 Munehiro Yamamoto <munepi@Vvinelinux.org> 0.9.21-2
- TeX Live 2009

* Mon Jun  9 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.9.21-1
- applied new versioning policy
- built with perl-5.10.0-2, installed perl modules to vendor_perl dir
- spec in UTF-8

* Sun Sep 17 2006 NAKAMURA Kenta <kenta@vinelinux.org> 0.9.21-0vl5
- added lib64.patch to have lib64 in perl path on 64bit machine

* Tue Apr 13 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.9.21-0vl4
- added patch1, 2 from mandrake package
  (prevent patch0--2 was moved 100--102)
- added Requires: tetex, gawk, groff
- added BuildRequires: docbook-utils
- fixed spec file

* Mon Apr 12 2004 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 0.9.21-0vl3
- remove Conflicts docbook-dtds

* Tue Jun  3 2003 Jun Nishii <jun@vinelinux.org> 0.9.21-0vl2
- added Conflicts docbook-dtds

* Sun May  4 2003 IWAI Masaharu <iwai@alib.jp> 0.9.21-0vl1
- upsteam release
- use rpmmacros
- update patches
  - platex.patch (Patch0)
  - replace_dvips.patch (Patch1)
  - catalog_file.patch (Patch2)

* Mon Jan  7 2002 IWAI Masaharu <iwaim@cc.mbn.or.jp> 0.9.1-0vl6
- sgml-common's super catalog support
- added PreReq: sgml-common >= 0.5

* Wed Jul 18 2001 KOBAYASHI R. Taizo <tkoba@vinelinux.org>
- 0.9.1-0vl5: remove url.sty which is provided from tetex

* Mon Apr 23 2001 <sagami@vinelinux.org>
- 0.9.1-0vl4: move manpages to %%{_mandir}

* Tue Jan 23 2001 Yasuhide OOMORI <dasen@icntv.ne.jp>
- 0.9.1-0vl3
- fixed $ENV{SGML_CATALOG_FILES}
- Maybe it's a bug... but it won't work without iso-entities-8879.1986

* Tue Jan 23 2001 Yasuhide OOMORI <dasen@icntv.ne.jp>
- 0.9.1-0vl2
- fixed some in description

* Sun Jan 21 2001 Jun Nishii <jun@vinelinux.org>
- 0.9.1-0vl1
- updated to 0.9.1

* Tue Nov 21 2000 Yasuhide OOMORI <dasen@icntv.ne.jp>
- 0.7.4-0vl3
- now you can choose jlatex for sgml2latex
- set '-l ja' as default

* Sun Nov 19 2000 Yasuhide OOMORI <dasen@icntv.ne.jp>
- 0.7.4-0vl2
- setup quietly
- create symlinks for sgml2latex
- use %{_prefix} macro
- use platex as default in sgml2latex
- use ${RPM_OPT_FLAGS}

* Tue Nov 14 2000 Yasuhide OOMORI <dasen@icntv.ne.jp>
- 0.7.4-0vl1
- updated to 0.7.4
- Modified URL for Source
- remove RPM_BUILD_ROOT first in %install
- renamed directory which contains users' guide
- remove RPM_BUILD_ROOT in %clean

* Wed Jul 12 2000 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 0.6.1-0vl2
- Obsoletes: sgml_tools -> sgml-tools :-)
- added Provides: sgml-tools (for compatibility with indexhtml)

* Thu Jun 29 2000 Jun Nishii <jun@vinelinux.org>
- 0.6.1-0vl1
- first build
