## TODO: update latex2html-2008
%define ver	2002
%define srcver	2002-2-1
%define jpver	1.9
%define _prefix	/usr
%define exec_texhash	[ -x %{_bindir}/texhash ] && %{_bindir}/env - %{_bindir}/texhash 2> /dev/null

Summary: LaTeX to HTML converter.
Summary(ja): LaTeX ファイルを HTML 形式に変換するツール
Name: latex2html
Version: %{ver}
Release: 7%{?_dist_release}
License: distributable
Group: Applications/Publishing
Url: http://www.latex2html.org/
Source0: http://saftsack.fs.uni-bayreuth.de/~latex2ht/current/latex2html-%{srcver}.tar.gz
Source1: l2h-japanese.perl
# vine patch
Patch0: http://takeno.iee.niit.ac.jp/~shige/TeX/latex2html/data/l2h-%{srcver}+jp%{jpver}.patch.gz
Patch1: l2h-vine.patch
Patch2: latex2html.gs510.diff
Patch3: l2h-netpbm-10.25.patch
BuildArch: noarch
Requires: tetex >= 3.0, perl, ghostscript >= 5.50
Requires: netpbm-progs
BuildPrereq: netpbm-progs, perl, tetex, dvipdfmx, netpbm >= 9.12
Buildroot: %{_tmppath}/%{name}-root
Vendor: Project Vine
Distribution: Vine Linux

%define ownlibdir %{_libdir}/%{name}

%description
Elaborate perl program to convert latex documents to html, using LaTeX
to process images and equations.  

%description -l ja
Latex ファイルを HTML形式に変換するperlプログラムです.

%prep
%setup -q -n latex2html-%{srcver} 
%patch -p1
%patch1 -p0
cp -f %{SOURCE1} styles/japanese.perl
cd config
%patch2 -p0
cd ..
%patch3 -p1

%build
TMP=/var/tmp ./configure \
        --with-gs=%{_bindir}/gs \
        --without-mktexlsr \
        --with-perl=%{__perl} \
        --prefix=%{_prefix} \
	--enable-png \
	--disable-gif \
	--libdir=%{ownlibdir} \
	--shlibdir=%{ownlibdir}
#./configure --prefix=%{_prefix} --sysconfdir=/etc --host=localhost\
#	--enable-png --disable-gif --without-mktexlsr
make

##
## make several l2hconf.pm and wrapper
##
sed -e 's/"jarticle"/"article"/' -e 's/japanese/english/' \
    -e 's/UNUSEACCENT = 1/UNUSEACCENT = 0/' \
    -e 's/texexpand/texexpand-en/' \
    l2hconf.pm > l2hconf_en.pm
sed -e 's/#$TOHTML/$TOHTML = "|nkf -j";/' \
    -e 's/#$charset/$charset = "iso-2022-jp";/' \
    l2hconf.pm > l2hconf_jis.pm
sed -e 's/#$TOHTML/$TOHTML = "|nkf -s";/' \
    -e 's/#$charset/$charset = "Shift_JIS";/' \
    l2hconf.pm > l2hconf_sjis.pm
sed -e 's/#$TOHTML/$TOHTML = "|nkf -e";/' \
    -e 's/#$charset/$charset = "EUC-JP";/' \
    l2hconf.pm > l2hconf_euc.pm
sed -e 's/#$TOHTML/$TOHTML = "|nkf -w";/' \
    -e 's/#$charset/$charset = "UTF-8";/' \
    l2hconf.pm > l2hconf_utf8.pm
cp l2hconf.pm l2hconf_png_ja.pm
sed -e 's/"jarticle"/"article"/' -e 's/japanese/english/' \
    l2hconf.pm > l2hconf_png_en.pm
sed 's/png gif/gif png/' l2hconf.pm > l2hconf_gif_ja.pm
sed 's/png gif/gif png/' l2hconf_png_en.pm > l2hconf_gif_en.pm
sed -e 's/${FROMNATIVE} $infile |/<$infile/' texexpand > texexpand-en
sed -e "s@LIBDIR@%{ownlibdir}@" -e "s@BINDIR@%{_bindir}@" l2h-wrapper-temp > l2h-wrapper


%install
# fake root directory
sed -e 's|/usr|'"${RPM_BUILD_ROOT}"'/usr|' \
	-e 's|bin/latex|bin/platex|' cfgcache.pm > cfgcache.pm.new
mv cfgcache.pm.new cfgcache.pm
mkdir -p $RPM_BUILD_ROOT%{_datadir}/texmf/tex/latex/html
make install

(cd %{buildroot}
perl -pi -e 's@iso-8859-1@euc-jp@g' %{_bindir}/latex2html
for i in `grep -ir -l %{buildroot} *`;
do
    perl -pi -e "s@%{buildroot}@@g" $i
    chmod 755 $i
done
for i in `grep -ir -l %{_builddir} *`;
do
    perl -pi -e "s@%{_builddir}@@g" $i
    chmod 755 $i
done
)

# fix perl path in a few places:

perl -pi -e 's#/usr/local/bin/perl#%{__perl}#'  $RPM_BUILD_ROOT%{ownlibdir}/cweb2html/cweb2html
perl -pi -e 's#/usr/local/bin/perl#%{__perl}#'  $RPM_BUILD_ROOT%{ownlibdir}/makeseg/makeseg
perl -pi -e 's#/usr/local/bin/perl#%{__perl}#'  $RPM_BUILD_ROOT%{ownlibdir}/makemap

perl -pi -e "s#$RPM_BUILD_DIR/%{name}-%{version}#%{_libdir}/%{name}#" $RPM_BUILD_ROOT%{ownlibdir}/cfgcache.pm

(cd $RPM_BUILD_ROOT%{_datadir}/texmf/tex/latex/html
rm -f floatflt.ins latin9.def url.sty
)

(cd docs 
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
# platex manual
# platex manual
# platex manual
make clean
make LATEX=platex manual.dvi
dvipdfm manual.dvi)

#### l2h wrapper install
cp l2hconf_{gif,png}_{ja,en}.pm $RPM_BUILD_ROOT%{ownlibdir}
install -c -m 0755 l2h-wrapper $RPM_BUILD_ROOT%{_bindir}/l2h

## NO use perl(Win32), which is required by perl(L2hos::Win32)
sed -i -e 's/use Win32;/## RPM requires perl(Win32)\n# use Win32;/' \
    $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 docs/ example/ tests/
%doc dot.latex2html-init
%{_bindir}/*
%{_libdir}/%{name}
%{_datadir}/texmf/tex/latex/html/

%changelog
* Sun Mar 29 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 2002-7
- comment out "use Win32;" in %{ownlibdir}/L2hos/Win32.pm

* Sun Mar 29 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 2002-6
- applied new versioning policy
- spec in utf8
- corrected generating docs/manual.pdf process

* Wed Aug 31 2005 KOBAYASHI Taizo <tkoba@vinelinux.org> 2002-0vl5
- source update

* Wed Jun 11 2003 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 2002-0vl4
- patch2 update
- source update (23-May-2003 07:15)

* Tue Oct 08 2002 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 2002-0vl3
- source update

* Fri Jun 21 2002 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 2002-0vl2
- source update

* Sun Jun 09 2002 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 2002-0vl1
- update to 2002
- added BuildPrereq: netpbm >= 9.12

* Fri Mar 29 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2000.1-0.1vl4
- added BuildPreReq: tetex

* Fri Mar 29 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2000.1-0.1vl3
- %%post and %%postun fixed ([VineSeed:06257], thanks Tsuchimura-san)

* Wed Jul 18 2001 KOBAYASHI R. Taizo <tkoba@ike-dyn.ritsumei.ac.jp> 0.1vl2
- source update
- fix requires tag

* Wed Jul 18 2001 KOBAYASHI R. Taizo <tkoba@ike-dyn.ritsumei.ac.jp>
- latex2html-2000.1-0.1vl1
- update for teTeX

* Thu Aug 17 2000 Jun Nishii <jun@vinelinux.org>
- latex2html-99.2-0.8vl2
- fix requires tag

* Mon Jul 31 2000 Jun Nishii <jun@vinelinux.org>
- latex2html-99.2-0.8vl1
- use png

* Fri Jan 28 2000 Yasuhide OOMORI <baoying@flatout.org>
- [latex2html-98.1p1-5]
- Modified to show generator correctly.
- Setup quietly.

* Fri Jan  7 2000 Jun Nishii <jun@vinelinux.org>
- [latex2html-98.1p1-4]
- change group

* Sun Nov 14 1999 Jun Nishii <jun@flatout.org>
- build for Vine-2.0

* Mon May 3 1999 Jun Nishii <jun@flatout.org>
- modify post installation script
- build for Vine

* Tue Nov 10 1998 Jun Nishii <jun@flatout.org>
- first build for PJE-0.3alpha

