%define jppatchsrcver	jp20110708
%define jppatch		l2h-2K8-jp2.1b1.13.patch

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

Summary:	LaTeX to HTML converter
Summary(ja):	LaTeX ファイルを HTML 形式に変換するツール
Name:		latex2html
Version:	2008
Release:	3%{?_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

Requires:	texlive >= 2013
Requires:	ghostscript
Requires:	perl
Requires:	netpbm-progs
BuildRequires:  texlive-vtlpkg >= 2013
BuildRequires:	texlive >= 2013
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
Packager:	munepi

%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 \
    --with-dvips=%{_bindir}/dvips \
    --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%{_tl_texmfvine}/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
%_tl_touch_run texhash
exit 0

%postun
if [ "$1" = 0 ]; then
   %_tl_touch_run texhash
fi
exit 0

%posttrans
%{_tl_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}
%{_tl_texmfvine}/tex/latex/html/


%changelog
* Thu Aug 29 2013 Munehiro Yamamoto <munepi@vinelinux.org> 2008-3
- added BuildRequires: texlive-vtlpkg >= 2013
- added some scriptlets to run mktexlsr

* Sat Jan 28 2012 Munehiro Yamamoto <munepi@vinelinux.org> 2008-2
- l2h-2K8-jp20110708
- Requires, BuildRequires: s/texlive/texlive-common/ (for vl6 or higher)

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