%define tlversion	2012

%define vinepl		vine.pls-1.2
%define tfmdir		%{texmf}/fonts/tfm/ptex

%define __pltotf	%{_bindir}/ppltotf
%define __makejvf	%{_bindir}/makejvf
%define __nkf		%{_bindir}/nkf

%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}

## use some macros for %post, %posttrans
%define touch_run(%1)	%{expand:( %__mkdir_p /var/run/texlive; touch /var/run/texlive/run-%1; )
}
%define exec_upddeffont	[ -x %{_sbindir}/update-defaultfont ] && \\\
    %{_sbindir}/update-defaultfont 2> /dev/null
%define exec_texhash	[ -e /var/run/texlive/run-texhash ] && ( \\\
    [ -x %{_bindir}/texhash ] && \\\
    echo -n "    "; echo -n "Running texhash... "; \\\
    %{_bindir}/texhash 2> /dev/null; \\\
    echo "done." ) && %__rm -f /var/run/texlive/run-texhash;
%define exec_mtxrun	[ -e /var/run/texlive/run-mtxrun ] && ( \\\
    [ -x %{_bindir}/mtxrun ] && \\\
    echo -n "    "; echo -n "Running mtxrun... "; \\\
    export TEXMF=%{texmf}-dist TEXMFCNF=%{texmf}/web2c TEXMFCACHE=%{texmfsysvar}; \\\
    %{_bindir}/mtxrun --generate &> /dev/null; \\\
    echo "done." ) && %__rm -f /var/run/texlive/run-mtxrun; 
%define exec_fmtutil	[ -e /var/run/texlive/run-fmtutil ] && ( \\\
    [ -x %{_bindir}/fmtutil-sys ] && \\\
    echo -n "    "; echo -n "Running fmtutil-sys... "; \\\
    %{_bindir}/fmtutil-sys --all &> /dev/null; \\\
    echo "done." ) && %__rm -f /var/run/texlive/run-fmtutil; 
%define exec_updmap	[ -e /var/run/texlive/run-updmap ] && ( \\\
    [ -x %{_bindir}/updmap-sys ] && \\\
    echo -n "    "; echo -n "Running updmap-sys... "; \\\
    %{_bindir}/updmap-sys --nohash --quiet &> /dev/null; \\\
    echo "done." ) && %__rm -f /var/run/texlive/run-updmap; 

Summary: Japanese Virtual Fonts
Summary(ja): 日本語仮想フォントです.
Name: jvf
Version: 7.1
Release: 1%{?_dist_release}
License: distributable
Group: Applications/Publishing
Source0: %{vinepl}.tar.gz
Source1: http://oku.edu.mie-u.ac.jp/~okumura/texfaq/jis-pl.zip
Requires(post): sh-utils
Requires: texlive = %{tlversion}
BuildRequires: nkf
BuildRequires: unzip
## NOTE: makejvf and ppltotf: contained in texlive
BuildRequires: texlive = %{tlversion}
## NOTE: tfm/vf files of pTeX: 
## almostly contained in texmf-dist/ of texlive-sources
#BuildRequires: texlive-sources = %{tlversion}

BuildArch: noarch
Buildroot: %{_tmppath}/%{name}-%{version}-root

Obsoletes: texlive-jvf <= 2.0

Vendor:       Project Vine
Distribution: Vine Linux
Packager:     munepi

%description
Japanese Virtual Fonts required by dvipsk built by makejvf.

%description -l ja
dvipsk の実行に必要な, 日本語仮想フォント(virtual fonts)、
多書体用フォントメトリックです。

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

%setup -q -c %{name}-%{version}
[ -d %{vinepl} ] && %__mv %{vinepl}/* . && %__rm -r %{vinepl} || exit 1
%__unzip -oqq %{SOURCE1}

%build
## Macro definition
mkvf(){ # <$1: jfm name> <$2: jfm name of PS font>
    for size in 5 6 7 8 9 10 ; do
        %__makejvf %{tfmdir}/$1${size}.tfm $2 || exit 1
    done
}

## now, build basic vf fonts
mkvf min rml
mkvf tmin rmlv
mkvf goth gbm
mkvf tgoth gbmv

# jis font metric and vf fonts
for pl in jis jisi tjis tjisi \
          min mini tmin tmini; do
    %__nkf --jis --overwrite $pl.pl
    %__pltotf $pl.pl
done
%__ln_s -f jis.tfm   jisg.tfm
%__ln_s -f jisi.tfm  jisgi.tfm
%__ln_s -f tjis.tfm  tjisg.tfm
%__ln_s -f tjisi.tfm tjisgi.tfm

%__makejvf  jis.tfm   rml
%__makejvf tjis.tfm   rmlv  # 縦
%__makejvf  jisi.tfm  rmli  # italic
%__makejvf tjisi.tfm  rmlvi

%__makejvf  jisg.tfm  gbm
%__makejvf tjisg.tfm  gbmv
%__makejvf  jisgi.tfm gbmi
%__makejvf tjisgi.tfm gbmvi

## new JIS font metric
# make *.tfm
for pl in jis jisn jis-v jisn-v; do
    %__pltotf $pl.pl
done
%__ln_s -f jis.tfm    jisg.tfm
%__ln_s -f jis-v.tfm  jisg-v.tfm
%__ln_s -f jisn.tfm   jisgn.tfm
%__ln_s -f jisn-v.tfm jisgn-v.tfm

# make *.vf
%__makejvf jis.tfm     rml
%__makejvf jisn.tfm    rmln # 中点修正
%__makejvf jis-v.tfm   rmlv # 縦
%__makejvf jisn-v.tfm  rmlnv

%__makejvf jisg.tfm    gbm
%__makejvf jisgn.tfm   gbmn
%__makejvf jisg-v.tfm  gbmv
%__makejvf jisgn-v.tfm gbmnv


# extrafonts metric and vf fonts
for i in goth gyo pop lei dfmin dfgt dfgyo dfpop dflei lxmin lxgt lxpop lxmgt lxgtb dfminb dfkaib dfpostb dffry dfbrrb ; do
    %__ln_s -f min.tfm    ${i}.tfm
    %__ln_s -f mini.tfm   ${i}i.tfm
    %__ln_s -f tmin.tfm  t${i}.tfm
    %__ln_s -f tmini.tfm t${i}i.tfm
done
for i in min goth gyo pop lei dfmin dfgt dfgyo dfpop dflei lxmin lxgt lxpop lxmgt lxgtb dfminb dfkaib dfpostb dffry dfbrrb; do
    %__makejvf ${i}.tfm ${i}
    %__makejvf ${i}i.tfm ${i}i
    %__makejvf t${i}.tfm t${i}
    %__makejvf t${i}i.tfm t${i}i

#    %__ln_s -f ${i}.vf df${i}.vf
#    %__ln_s -f ${i}i.vf df${i}i.vf
#    %__ln_s -f t${i}.vf dft${i}.vf
#    %__ln_s -f t${i}i.vf dft${i}i.vf
done

# change same file to symbolic link
for f in *.vf; do
    if [ ! -L $f ]; then
	for g in *.vf; do
	    if [ ! -L $g -a $f != $g ]; then
		cmp $f $g > /dev/null && (%__rm -f $g; %__ln_s $f $g)
	    fi
	done
    fi
done


# ## avoid conflicts in texmf-dist
# %__rm -f jvf-filelist.conflict
# for i in $(find %{texlive_src}/texmf-dist/fonts/{tfm,vf,source}/ptex/ -type f); do
#     [ ! -z "$(find $(pwd) -type f | %__grep -e "/$(basename ${i})")" ] && \
#        echo -n "${i}: " >> jvf-filelist.conflict && \
#        %__rm -fv $(find $(pwd) -type f | %__grep -e "/$(basename ${i})") >> jvf-filelist.conflict && \
#        %__ln_s $(echo ${i} | %__sed -e "s,%{texlive_src},%{tex_destdir},") . ||:
# done


%install
%__rm -rf $RPM_BUILD_ROOT
%__mkdir_p %{build_texmf}/fonts/{tfm,source,vf}/ptex
%__cp -dfp *.tfm %{build_texmf}/fonts/tfm/ptex/
%__cp -dfp *.pl  %{build_texmf}/fonts/source/ptex/
%__cp -dfp *.vf  %{build_texmf}/fonts/vf/ptex/


%clean
%__rm -rf $RPM_BUILD_ROOT

%post
%touch_run texhash
exit 0

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

%posttrans
%{exec_texhash}
exit 0


%files
%defattr(-,root,root)
%doc README
%{texmf}/fonts/tfm/ptex/
%{texmf}/fonts/source/ptex/
%{texmf}/fonts/vf/ptex/


%changelog
* Fri Nov 23 2012 Munehiro Yamamoto <munepi@vinelinux.org> 7.1-1
- TeX Live 2012

* Sat Nov 26 2011 Munehiro Yamamoto <munepi@vinelinux.org> 7.0-1
- increase version number to match with distro version
- TeX Live 2011

* Sat Jan 15 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2.0-6
- added Obsoletes: texlive-jvf <= 2.0
  - for TeX Live 2009 of VinePlus/5, supported texlive-jvf

* Sun May 16 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2.0-5
- use texlive-2009 + ptexlive-20100322
  - dropped Requires: tetex, BuildRequires: tetex
  - addeded Requires: texlive, BuildRequires: texlive
- use some rpm macros

* Wed Oct 07 2009 Munehiro Yamamoto <munepi@vinelinux.org> 2.0-4
- added BuildRequires: unzip
- dropped BuildRequires: %%{_prefix}/bin/pltotf %%{tfmdir}/min5.tfm
  - %%{_prefix}/bin/pltotf %%{tfmdir}/min5.tfm are provided by tetex

* Sun Sep 27 2009 Munehiro Yamamoto <munepi@vinelinux.org> 2.0-3
- added BuildRequires: nkf
- dropped BuildRequires: makejvf
  - /usr/bin/makejvf is provided from tetex, which is with ptexenc
- converted euc-encode to jis-encode for *.pl in vine.pls-1.2

* Sun Jan 11 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 2.0-2
- spec in utf8 (again)

* Fri Aug 15 2008 Shu KONNO <owa@bg.wakwak.com> 2.0-1vl5
- applied new versioning policy, spec in utf-8

* Fri Jan 14 2005 Daisuke SUZUKI <daisuke@linux.or.jp> 2.0-0vl1
- add new dynafont for Vine Linux 3.1CR

* Fri Apr 18 2003 Nobuyuki Tsuchimura <tutimura@nn.iij4u.or.jp> 1.1a-0vl3
- change tetex-ptex -> tetex

* Mon Mar 25 2002 Jun Nishii <jun@vinelinux.org> 1.1a-0vl2
- added symlinks for lxricoh fonts

* Sat Mar 24 2001 Nobuyuki Tsuchimura <tutimura@nn.iij4u.or.jp>
- 1.1a-0vl1
- use symbolic link for same *.vf

* Sat Jan 20 2001 Jun Nishii <jun@vinelinux.org>
- 1.0-6
- cp jis.pl min.pl and fix glue for "「,（,..." in min.pl to use DynaFonts
  Should I rename min.* as dyna.*?

* Fri Jan 21 2000 Jun Nishii <jun@vinelinux.org>
- 1.0-5
- make vfs for dynafonts
- tjis, tjisi, tmin, tmini,...
- correct installation of tfm

* Fri Jan  7 2000 Jun Nishii <jun@vinelinux.org>
- install makejvf

* Fri Oct 29 1999 Norihito Ohmori <ohmori@flatout.org>
- change group
- add defattr(-,root.root)

* Thu Jul 13 1999 Jun Nishii <jun@flatout.org>
- include jis fonts

* Mon Feb 8 1999 Jun Nishii <jun@flatout.org>
- build vfs by makejvf
- obsoletes vfkanji
