%define jppatchsrcver	jp20100514
%define jppatch		l2h-2K8-jp2.1b1.12.patch

%define tex_destdir	%{_datadir}
%define texmf		%{tex_destdir}/texmf
%define texlive_src	%{tex_destdir}/texlive-sources
%define build_tex_destdir	%{buildroot}%{tex_destdir}
%define build_texmf	%{buildroot}%{texmf}

%define exec_mktexlsr  [ -x %{_bindir}/texconfig-sys ] && PATH=%{_bindir}:$PATH %{_bindir}/texconfig-sys rehash
%define exec_texhash  [ -x %{_bindir}/texhash ] && PATH=%{_bindir}:$PATH %{_bindir}/texhash
%define exec_updmap   [ -x %{_bindir}/updmap-sys ] && PATH=%{_bindir}:$PATH %{_bindir}/updmap-sys --nostop
%define exec_fmtutil  [ -x %{_bindir}/fmtutil-sys ] && PATH=%{_bindir}:$PATH %{_bindir}/fmtutil-sys --all >/dev/null
%define exec_upddeffont    [ -x %{_sbindir}/update-defaultfont ] && %{_sbindir}/update-defaultfont 2> /dev/null
%define vartexfonts %{_var}/lib/texmf

%define ownlibdir	%{_prefix}/lib/%{name}

Summary:	LaTeX to HTML converter
Summary(ja):	LaTeX ファイルを HTML 形式に変換するツール
Name:		latex2html
Version:	2008
Release:	1%{?_dist_release}
License:	GPL
Group:		Applications/Publishing
Url:		http://www.latex2html.org/
Source0:	http://saftsack.fs.uni-bayreuth.de/~latex2ht/current/%{name}-%{version}.tar.gz
Source1:	http://takeno.iee.niit.ac.jp/~shige/TeX/latex2html/current/data/l2h-2K8-%{jppatchsrcver}.tar.gz

Patch0:		l2h-vine.patch

%if %{?_dist_release} == "vl5"
Requires:	tetex
%endif
%if %{?_dist_release} == "vl6"
Requires:	texlive
%endif
Requires:	ghostscript
Requires:	perl
Requires:	netpbm-progs
%if %{?_dist_release} == "vl5"
BuildRequires:	tetex
%endif
%if %{?_dist_release} == "vl6"
BuildRequires:	texlive
%endif
BuildRequires:	ghostscript
BuildRequires:	perl
BuildRequires:	netpbm-progs
BuildRequires:	netpbm >= 9.12

Conflicts:	latex2html2002

BuildArch:	noarch
Buildroot:	%{_tmppath}/%{name}-%{version}-root
Vendor:		Project Vine
Distribution:	Vine Linux

%description
LATEX2HTML is a conversion tool that allows documents written in LATEX to 
become part of the World-Wide Web. In addition, it offers an easy migration 
path towards authoring complex hyper-media documents using familiar 
word-processing concepts, including the power of a LATEX-like macro language 
capable of producing correctly structured HTML tags.

LATEX2HTML replicates the basic structure of a LATEX document as a set of 
interconnected HTML files which can be explored using automatically generated 
navigation panels. The cross-references, citations, footnotes, the 
table-of-contents and the lists of figures and tables, are also translated 
into hypertext links. Formatting information which has equivalent “tags” in 
HTML (lists, quotes, paragraph-breaks, type-styles, etc.) is also converted 
appropriately. The remaining heavily formatted items such as mathematical 
equations, pictures etc. are converted to images which are placed 
automatically at the correct position in the final HTML document. 

LATEX2HTML extends LATEX by supporting arbitrary hypertext links and symbolic 
cross-references between evolving remote documents. It also allows the 
specification of conditional text and the inclusion of raw HTML commands. 
These hyper-media extensions to LATEX are available as new commands and 
environments from within a LATEX document.


%prep
%setup -q
%__tar zxvf %{SOURCE1} -C $RPM_BUILD_DIR || exit 1
%__patch -p1 < %{jppatch}

%patch0 -p0 -b .vine

# fix perl path in a few places:
%__sed -i -e "s|^#!/perl|#!%{__perl}|" l2hconf.pin || exit 1

%build
./configure \
    --prefix=%{_prefix} \
    --libdir=%{ownlibdir} \
    --shlibdir=%{ownlibdir} \
    \
    --with-perl=%{__perl} \
    --enable-images \
    --disable-pk \
    --enable-eps \
    --enable-png \
    --enable-gif \
    --with-gs=%{_bindir}/gs \
%if %{?_dist_release} == "vl6"
    --with-dvips=%{_bindir}/pdvips \
%endif
    --with-latex=%{_bindir}/platex \
    --without-mktexlsr \
    --with-kanji=utf8 \
	;
%__make


%install
%__rm -rf $RPM_BUILD_ROOT

## fake root directory
%__sed -e 's|/usr|'"${RPM_BUILD_ROOT}"'/usr|' \
	-e 's|bin/latex|bin/platex|' cfgcache.pm > cfgcache.pm.new || exit 1
%__mv cfgcache.pm.new cfgcache.pm || exit 1

%__make install

(cd %{buildroot}
    for i in `grep -ir -l %{buildroot} *`; do
	%__perl -pi -e "s@%{buildroot}@@g" $i || exit 1
	%__chmod 755 $i
    done
    for i in `grep -ir -l %{_builddir} *`;
    do
	%__perl -pi -e "s@%{_builddir}@@g" $i || exit 1
	%__chmod 755 $i
    done
)

## fix perl path in a few places:
%__perl -pi -e "s#$RPM_BUILD_DIR/%{pkgname}-%{version}#%{ownlibdir}#" $RPM_BUILD_ROOT%{ownlibdir}/cfgcache.pm || exit 1

## latin9.def url.sty: provided by texlive-collection-latex package
(cd $RPM_BUILD_ROOT%{_datadir}/texmf/tex/latex/html
    %__rm -f floatflt.ins latin9.def url.sty
)

(cd docs
    # ## changebar.sty: provided by texlive-collection-latexextra
    # %__rm -f changebar.sty
    export TEXINPUTS=:.:../texinputs

    ## article.cls don't provide \address.
    %__sed -i -e 's/\\author{\(.*\)}/\\author{\1/' -e 's!\\address{!\\\\hoge!' manual.tex || exit 1
    %__make clean
    %__make LATEX=platex manual.dvi
    %{_bindir}/dvipdfm manual.dvi || exit 1
)

## NO use perl(Win32), which is required by perl(L2hos::Win32)
%__rm -f $RPM_BUILD_ROOT%{ownlibdir}/L2hos/Win32.pm


%post
%{exec_texhash}
exit 0


%postun
%{exec_texhash}
exit 0


%clean
%__rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%doc BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO
%doc README.notice.jp README.patch-99.1jp README.patch-jp-pre README.tech.jp
%doc docs/ example/ tests/
%doc dot.latex2html-init
%{_bindir}/*
%{ownlibdir}
%{_datadir}/texmf/tex/latex/html/

%changelog
* Sun Sep 26 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2008-1
- first release
