## -*- coding: utf-8-unix -*-
%bcond_with firstbuild

# * texmf/web2c/texmf.cnf
# use BUILD
# * texmf/xdvi
# use BUILD

# * depend libX*
# inimf
# mf
# pdfclose
# pdfopen
# pxdvi-motif
# xdvi-motif

%global _use_internal_dependency_generator 0
%global __find_provides %{SOURCE99}
%global __find_requires %{nil}

%define texlivesrcver   20120701
%define texlivever      20120701

%define aliasttfdir	%{texmfsysvar}/fonts/truetype/vine
%define texmfsysconfig	%{_sysconfdir}/texmf
%define texmfsysvar	%{_var}/lib/texmf
%define vartexfonts	%{texmfsysvar}/fonts

%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: The TeX text formatting system
Summary(ja): TeX 文書整形システム
Name: texlive
Version: 2012
Release: 2%{?_dist_release}
License: distributable
Group: Applications/Publishing
URL: http://www.tug.org/texlive/

## original TeX Live source
Source: ftp://tug.org/historic/systems/texlive/%{version}/%{name}-%{texlivesrcver}-source.tar.xz

## pxdvi pmetapost
# $ wget -N http://www.logic.at/people/preining/build-tlptexlive-latest.zip
# $ stat -c %y build-tlptexlive-latest.zip
# 2012-11-07 09:23:34.000000000 +0900
# $ sha1sum build-tlptexlive-latest.zip  
# d863f331ce51257bba2266ddff15c90ad59bef96  build-tlptexlive-latest.zip
# $ mv build-tlptexlive-latest.zip build-tlptexlive-20121107.zip
Source1: http://www.logic.at/people/preining/build-tlptexlive-20121107.zip
Source2: http://www.tug.org/texlive/updmap-kanji.html

## texmf dir.
Source5: texlive-sources-%{texlivesrcver}-texmf.tar.xz
#Source6: updmap-hdr.cfg.texlive-%{texlivesrcver}
Source7: updmap.cfg.texlive-%{texlivesrcver}

## desktop files
Source10: pxdvi.desktop
Source11: texdoctk.desktop

## find library sonames for libkpathsea and libptexenc
Source99: find-provides-texlive.sh

## etc...
#Source100: texlive.cron
Source101: http://auemath.aichi-edu.ac.jp/~khotta/ghost/disk1/jtygm.sty
Source102: http://mirrors.ctan.org/obsolete/support/pdftexenc/cmex.enc


######
# TeX patches
######

## vine
Patch0:		reautoconf-parallel.diff
Patch1:		texlive-%{texlivesrcver}-vine.patch
Patch2:		texlive-%{texlivesrcver}-texmfcnf-vine.patch
Patch3:		texlive-%{texlivesrcver}-set-selfautoparent-vine.patch
Patch10:	texlive-%{texlivesrcver}-pxdvik-vine.patch

## security

Requires:    coreutils
Requires:    ed mktemp
Requires:    tmpwatch
Requires:    zlib
Requires:    libpng
Requires:    gd
Requires:    ncurses
Requires:    libjpeg
Requires:    t1lib
Requires:    freetype2
Requires:    openMotif
Requires:    poppler >= 0.20
Requires:    openssl
Requires:    libpaper
Requires:    fontconfig
Requires:    perl-Tk perl-Tk-TableMatrix
Requires:    nkf
Requires:    ghostscript >= 8.71
Requires:    libkpathsea = %{version}-%{release}
Requires:    libptexenc = %{version}-%{release}
%{!?with_firstbuild:Requires: jvf >= 7.1}
Requires:    fontconfig >= 2.6.0-2
Requires(post,postun): fontconfig >= 2.6.0-2
Requires(post): ed mktemp
Requires(post): vutils >= 7.1
%{!?with_firstbuild:Requires: texlive-common = %{version}}
#BuildRequires: texlive-sources = %{version}
BuildRequires: xz
BuildRequires: unzip
BuildRequires: bison flex
BuildRequires: bzip2-devel
BuildRequires: zlib-devel
BuildRequires: libpng-devel
BuildRequires: gd-devel
BuildRequires: ncurses-devel
BuildRequires: libjpeg-devel
BuildRequires: t1lib-devel
BuildRequires: XOrg-devel 
BuildRequires: freetype2-devel >= 2.1.10
BuildRequires: autoconf >= 2.68
BuildRequires: openMotif-devel
BuildRequires: poppler-devel >= 0.20
BuildRequires: openssl-devel
BuildRequires: libpaper-devel
BuildRequires: fontconfig-devel
BuildRequires: nkf

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

Vendor:       Project Vine
Distribution: Vine Linux
Packager:     munepi


%description
The TeX Live software distribution offers a complete TeX system for a
variety of Unix, Macintosh, Windows and other platforms. It
encompasses programs for editing, typesetting, previewing and printing
of TeX documents in many different languages, and a large collection
of TeX macros and font libraries.

The distribution includes extensive general documentation about TeX,
as well as the documentation for the included software packages.


%description -l ja
TeX Live ソフトウェアディストリビューションは、
さまざまな Unix, Macintosh, Windows、および
他のプラットホームに対して完全な TeX システムを提供します。
多くの異なった言語を含む TeX ドキュメントの
編集、組版、閲覧、印刷するためのプログラム、
そして、TeX マクロやフォントライブラリの大きなコレクションを
同梱しています。

このディストリビューションは
同梱しているソフトウェアパッケージのためのドキュメントばかりでなく、
TeX に関するたくさんの一般的なドキュメントを含んでいます。


%package doc
Summary: TeX Live: Documentation files of %{name}
Group: Applications/Publishing
Requires: %{name} = %{version}-%{release}
BuildArch: noarch

%description doc
This package contains documentation files of %{name}.

%package -n libkpathsea
Summary: path search library for the TeX Live
Summary(ja): TeX Live 用パス検索ライブラリ
Group: System Environment/Libraries

%description -n libkpathsea
This package includes runtime part of the Kpathsea library.


%package -n libkpathsea-devel
Summary: path search libary and header files for the TeX Live
Summary(ja): TeX Live 用パス検索ライブラリとヘッダファイル
Group: Development/Libraries
Requires: libkpathsea = %{version}-%{release}

%description -n libkpathsea-devel
This package includes static library and header files of the Kpathsea library.


%package -n libptexenc
Summary: Kanji code convert library for Japanese pTeX
Summary(ja): 日本語 pTeX 用漢字コード変換ライブラリ
Group: System Environment/Libraries
Requires: libkpathsea = %{version}-%{release}

%description -n libptexenc
This package includes runtime part of the ptexenc library.


%package -n libptexenc-devel
Summary: Kanji code convert library and header files for Japanese pTeX
Summary(ja): 日本語 pTeX 用漢字コード変換ライブラリとヘッダファイル
Group: Development/Libraries
Requires: libptexenc = %{version}-%{release}

%description -n libptexenc-devel
This package includes header files of the ptexenc library.


%prep
[ -n "%{buildroot}" -a "%{buildroot}" != / ] && %__rm -rf %{buildroot}

%setup -q -n %{name}-%{texlivesrcver}-source -a 1

%patch0 -p0 -b .parallel
%patch1 -p1 -b .vine
%patch2 -p1 -b .vine
%patch3 -p1 -b .vine

## Applying tlptexlive that provides pxdvi(k) and pmpost
sedwrite(){
  echo "rewriting `basename $1` by \"$2\""
  if [ ! -f "$1" ]; then 
    echo -e "'$1' does not exist"; exit 1
  fi
  perl -pi -e  "$2" "$1" || exit 1
}

# pxdvi
echo "preparing pxdvi"
%__cp -pR texk/xdvik texk/pxdvik
# echo "patching pxdvi patches"
# #patch -d texk/pxdvik -p1 < $(pwd)/build-tlptexlive/xdvik-20111212-texlive2011.diff 
echo "patching with xdvik-20120415-texlive2011.diff"
patch -d texk/pxdvik -p1 < $(pwd)/build-tlptexlive/xdvik-20120415-texlive2011.diff
echo "patching with pxdvik-20111126-density.diff"
patch -d texk/pxdvik -p1 < $(pwd)/build-tlptexlive/pxdvik-20111126-density.diff
echo "patching with pxdvik-20111212-uptex.diff"
patch -d texk/pxdvik -p1 < $(pwd)/build-tlptexlive/pxdvik-20111212-uptex.diff 
sedwrite libs/freetype2/freetype-2.4.*/modules.cfg 's/# (AUX_MODULES \+= otvalid)/\1/'
sedwrite m4/kpse-pkgs.m4 "s/xdvik/xdvik\npxdvik/"

# customize pxdvik for Vine Linux
%patch10 -p1 -b .vine

# # include in svn r26399
# # make sure that the web version of ovp2ovf is built
# echo "patching for wovp2ovf"
# patch -d texk -p0 < $(pwd)/build-tlptexlive/ovp2ovf_web.patch

# pmpost
echo "patching pmpost"
patch -d texk -p0 < $(pwd)/build-tlptexlive/pmpost-20121106-tl12.diff
patch -d texk -p0 < $(pwd)/build-tlptexlive/pmpost-svg-20120119-tl11.diff 

echo "running reautoconf"
./reautoconf || exit 1


%build
set -x
unset TEXINPUTS || :
unset HOME || :

export CFLAGS="$RPM_OPT_FLAGS" \
       CXXFLAGS="$RPM_OPT_FLAGS" \
       LANG=C

PREFIX=$(pwd)/work

TL_CONF_XDVI_TOOLKIT=--with-xdvi-x-toolkit=motif
TL_MAKE_FLAGS=-j$(/usr/bin/getconf _NPROCESSORS_ONLN)

TL_CONFIGURE_ARGS=" \
    --disable-multiplatform \
    --disable-native-texlive-build \
    --with-banner-add=\"/Vine Linux\" \
    --enable-shared --disable-static \
    --enable-compiler-warnings=max \
    --without-cxx-runtime-hack \
    \
    --enable-web2c \
    --enable-web-progs --enable-dvipdfmx --enable-mendexk \
    --enable-makejvf --enable-pxdvik --enable-dvipsk \
    --enable-tetex --enable-texlive \
    \
    --with-system-xpdf \
    --with-system-gd \
    --with-system-t1lib \
    --with-system-libpng \
    --with-system-zlib \
    --with-system-freetype2 \
    --with-freetype2-include=$(freetype-config --cflags | %__sed -e 's/-I//' -e 's/ .*//') \
    --with-pic \
    --with-xdvi-x-toolkit=motif \
    \
    --disable-xindy --disable-xindy-docs --disable-xindy-make-rules \
    --disable-dvi2tty \
    --disable-t1utils --disable-psutils --disable-detex \
    --disable-dvipng --disable-lcdf-typetools \
"

export TL_CONF_XDVI_TOOLKIT TL_MAKE_FLAGS TL_CONFIGURE_ARGS

TL_MAKE=%__make ./Build || exit 1

%install
## prepare %%install session
[ -n "%{buildroot}" -a "%{buildroot}" != / ] && %__rm -rf %{buildroot}

## copy inst dir. to /usr
%__mkdir_p %{buildroot}
%__cp -a inst %{buildroot}%{_prefix} || exit 1
%ifarch x86_64
%__mv %{buildroot}%{_prefix}/lib %{buildroot}%{_libdir}
%endif
## replace texmf with that of texlive-sources
%__rm -rf %{build_texmf} %{build_texmf}-dist || exit 1
%__tar -C %{buildroot}%{_datadir} -xpf %{SOURCE5} || exit 1
## override texmf/web2c/texmf.cnf and texmf/xdvi dir.
%__cp -a inst/share/texmf/web2c/texmf.cnf %{build_texmf}/web2c/texmf.cnf || exit 1
%__rm -rf %{build_texmf}/xdvi || exit 1
%__cp -a inst/share/texmf/xdvi %{build_texmf}/xdvi || exit 1

## make some fundamental texmf trees
%__mkdir_p %{build_texmf}-{local,dist}
%__mkdir_p %{buildroot}%{texmfsysconfig}
%__mkdir_p %{buildroot}%{texmfsysvar}
%__mkdir_p %{build_texmf}/fonts/{truetype,opentype}
texmf_local_dirs=(
  bibtex/bib/local
  bibtex/bst/local
  dvips/local
  fonts/source/local
  fonts/tfm/local
  fonts/opentype/local
  fonts/truetype/local
  fonts/type1/local
  fonts/vf/local
  metapost/local
  pbibtex/bib/local
  pbibtex/bst/local
  tex/latex/local
  tex/plain/local
  tex/platex/local
  web2c
)
for x in ${texmf_local_dirs[@]}; do
    %__mkdir_p %{build_texmf}-local/${x}
done


## if the real file of a symlink on /usr/bin is contained 
## in texlive-collection-*, remove its symlink
del_symlnks=(
texlive-collection-bibtexextra,/usr/bin/bibexport,/usr/share/texmf-dist/scripts/bibexport/bibexport.sh
texlive-collection-bibtexextra,/usr/bin/listbib,/usr/share/texmf-dist/scripts/listbib/listbib
texlive-collection-bibtexextra,/usr/bin/urlbst,/usr/share/texmf-dist/scripts/urlbst/urlbst
texlive-collection-binextra,/usr/bin/arlatex,/usr/share/texmf-dist/scripts/bundledoc/arlatex
texlive-collection-binextra,/usr/bin/bundledoc,/usr/share/texmf-dist/scripts/bundledoc/bundledoc
texlive-collection-binextra,/usr/bin/ctanify,/usr/share/texmf-dist/scripts/ctanify/ctanify
texlive-collection-binextra,/usr/bin/ctanupload,/usr/share/texmf-dist/scripts/ctanupload/ctanupload.pl
texlive-collection-binextra,/usr/bin/de-macro,/usr/share/texmf-dist/scripts/de-macro/de-macro
texlive-collection-binextra,/usr/bin/dviasm,/usr/share/texmf-dist/scripts/dviasm/dviasm.py
texlive-collection-binextra,/usr/bin/findhyph,/usr/share/texmf-dist/scripts/findhyph/findhyph
texlive-collection-binextra,/usr/bin/fragmaster,/usr/share/texmf-dist/scripts/fragmaster/fragmaster.pl
texlive-collection-binextra,/usr/bin/installfont-tl,/usr/share/texmf-dist/scripts/installfont/installfont-tl
texlive-collection-binextra,/usr/bin/latex2man,/usr/share/texmf-dist/scripts/latex2man/latex2man
texlive-collection-binextra,/usr/bin/latexdiff,/usr/share/texmf-dist/scripts/latexdiff/latexdiff.pl
texlive-collection-binextra,/usr/bin/latexdiff-vc,/usr/share/texmf-dist/scripts/latexdiff/latexdiff-vc.pl
texlive-collection-binextra,/usr/bin/latexfileversion,/usr/share/texmf-dist/scripts/latexfileversion/latexfileversion
texlive-collection-binextra,/usr/bin/latexmk,/usr/share/texmf-dist/scripts/latexmk/latexmk.pl
texlive-collection-binextra,/usr/bin/latexrevise,/usr/share/texmf-dist/scripts/latexdiff/latexrevise.pl
texlive-collection-binextra,/usr/bin/listings-ext.sh,/usr/share/texmf-dist/scripts/listings-ext/listings-ext.sh
texlive-collection-binextra,/usr/bin/match_parens,/usr/share/texmf-dist/scripts/match_parens/match_parens
texlive-collection-binextra,/usr/bin/mkjobtexmf,/usr/share/texmf-dist/scripts/mkjobtexmf/mkjobtexmf.pl
texlive-collection-binextra,/usr/bin/pdf180,/usr/share/texmf-dist/scripts/pdfjam/pdf180
texlive-collection-binextra,/usr/bin/pdf270,/usr/share/texmf-dist/scripts/pdfjam/pdf270
texlive-collection-binextra,/usr/bin/pdf90,/usr/share/texmf-dist/scripts/pdfjam/pdf90
texlive-collection-binextra,/usr/bin/pdfbook,/usr/share/texmf-dist/scripts/pdfjam/pdfbook
texlive-collection-binextra,/usr/bin/pdfcrop,/usr/share/texmf-dist/scripts/pdfcrop/pdfcrop.pl
texlive-collection-binextra,/usr/bin/pdfflip,/usr/share/texmf-dist/scripts/pdfjam/pdfflip
texlive-collection-binextra,/usr/bin/pdfjam,/usr/share/texmf-dist/scripts/pdfjam/pdfjam
texlive-collection-binextra,/usr/bin/pdfjam-pocketmod,/usr/share/texmf-dist/scripts/pdfjam/pdfjam-pocketmod
texlive-collection-binextra,/usr/bin/pdfjam-slides3up,/usr/share/texmf-dist/scripts/pdfjam/pdfjam-slides3up
texlive-collection-binextra,/usr/bin/pdfjam-slides6up,/usr/share/texmf-dist/scripts/pdfjam/pdfjam-slides6up
texlive-collection-binextra,/usr/bin/pdfjoin,/usr/share/texmf-dist/scripts/pdfjam/pdfjoin
texlive-collection-binextra,/usr/bin/pdfnup,/usr/share/texmf-dist/scripts/pdfjam/pdfnup
texlive-collection-binextra,/usr/bin/pdfpun,/usr/share/texmf-dist/scripts/pdfjam/pdfpun
texlive-collection-binextra,/usr/bin/pkfix,/usr/share/texmf-dist/scripts/pkfix/pkfix.pl
texlive-collection-binextra,/usr/bin/pkfix-helper,/usr/share/texmf-dist/scripts/pkfix-helper/pkfix-helper
texlive-collection-binextra,/usr/bin/purifyeps,/usr/share/texmf-dist/scripts/purifyeps/purifyeps
texlive-collection-binextra,/usr/bin/sty2dtx,/usr/share/texmf-dist/scripts/sty2dtx/sty2dtx.pl
texlive-collection-binextra,/usr/bin/texcount,/usr/share/texmf-dist/scripts/texcount/texcount.pl
texlive-collection-binextra,/usr/bin/texdef,/usr/share/texmf-dist/scripts/texdef/texdef.pl
texlive-collection-binextra,/usr/bin/texdiff,/usr/share/texmf-dist/scripts/texdiff/texdiff
texlive-collection-binextra,/usr/bin/texdirflatten,/usr/share/texmf-dist/scripts/texdirflatten/texdirflatten
texlive-collection-binextra,/usr/bin/texliveonfly,/usr/share/texmf-dist/scripts/texliveonfly/texliveonfly.py
texlive-collection-binextra,/usr/bin/texloganalyser,/usr/share/texmf-dist/scripts/texloganalyser/texloganalyser
texlive-collection-binextra,/usr/bin/typeoutfileinfo,/usr/share/texmf-dist/scripts/typeoutfileinfo/typeoutfileinfo.sh
texlive-collection-fontutils,/usr/bin/afm2afm,/usr/share/texmf-dist/scripts/fontools/afm2afm
texlive-collection-fontutils,/usr/bin/autoinst,/usr/share/texmf-dist/scripts/fontools/autoinst
texlive-collection-fontutils,/usr/bin/dosepsbin,/usr/share/texmf-dist/scripts/dosepsbin/dosepsbin.pl
texlive-collection-fontutils,/usr/bin/epstopdf,/usr/share/texmf-dist/scripts/epstopdf/epstopdf.pl
texlive-collection-fontutils,/usr/bin/mf2pt1,/usr/share/texmf-dist/scripts/mf2pt1/mf2pt1.pl
texlive-collection-fontutils,/usr/bin/mkt1font,/usr/share/texmf-dist/scripts/accfonts/mkt1font
texlive-collection-fontutils,/usr/bin/ot2kpx,/usr/share/texmf-dist/scripts/fontools/ot2kpx
texlive-collection-fontutils,/usr/bin/vpl2ovp,/usr/share/texmf-dist/scripts/accfonts/vpl2ovp
texlive-collection-fontutils,/usr/bin/vpl2vpl,/usr/share/texmf-dist/scripts/accfonts/vpl2vpl
texlive-collection-htmlxml,/usr/bin/ht,/usr/share/texmf-dist/scripts/tex4ht/ht.sh
texlive-collection-htmlxml,/usr/bin/htcontext,/usr/share/texmf-dist/scripts/tex4ht/htcontext.sh
texlive-collection-htmlxml,/usr/bin/htlatex,/usr/share/texmf-dist/scripts/tex4ht/htlatex.sh
texlive-collection-htmlxml,/usr/bin/htmex,/usr/share/texmf-dist/scripts/tex4ht/htmex.sh
texlive-collection-htmlxml,/usr/bin/httex,/usr/share/texmf-dist/scripts/tex4ht/httex.sh
texlive-collection-htmlxml,/usr/bin/httexi,/usr/share/texmf-dist/scripts/tex4ht/httexi.sh
texlive-collection-htmlxml,/usr/bin/htxelatex,/usr/share/texmf-dist/scripts/tex4ht/htxelatex.sh
texlive-collection-htmlxml,/usr/bin/htxetex,/usr/share/texmf-dist/scripts/tex4ht/htxetex.sh
texlive-collection-htmlxml,/usr/bin/mk4ht,/usr/share/texmf-dist/scripts/tex4ht/mk4ht.pl
texlive-collection-langcjk,/usr/bin/convbkmk,/usr/share/texmf-dist/scripts/uptex/convbkmk.rb
texlive-collection-langcjk,/usr/bin/updmap-setup-kanji,/usr/share/texmf-dist/scripts/jfontmaps/updmap-setup-kanji.pl
texlive-collection-langgreek,/usr/bin/mkgrkindex,/usr/share/texmf-dist/scripts/mkgrkindex/mkgrkindex
texlive-collection-langindic,/usr/bin/ebong,/usr/share/texmf-dist/scripts/ebong/ebong.py
texlive-collection-latex,/usr/bin/mptopdf,/usr/share/texmf-dist/scripts/context/perl/mptopdf.pl
texlive-collection-latex,/usr/bin/pdfatfi,/usr/share/texmf-dist/scripts/oberdiek/pdfatfi.pl
texlive-collection-latexextra,/usr/bin/authorindex,/usr/share/texmf-dist/scripts/authorindex/authorindex
texlive-collection-latexextra,/usr/bin/exceltex,/usr/share/texmf-dist/scripts/exceltex/exceltex
texlive-collection-latexextra,/usr/bin/makeglossaries,/usr/share/texmf-dist/scripts/glossaries/makeglossaries
texlive-collection-latexextra,/usr/bin/pdfannotextractor,/usr/share/texmf-dist/scripts/pax/pdfannotextractor.pl
texlive-collection-latexextra,/usr/bin/perltex,/usr/share/texmf-dist/scripts/perltex/perltex.pl
texlive-collection-latexextra,/usr/bin/ps4pdf,/usr/share/texmf-dist/scripts/pst-pdf/ps4pdf
texlive-collection-latexextra,/usr/bin/splitindex,/usr/share/texmf-dist/scripts/splitindex/perl/splitindex.pl
texlive-collection-latexextra,/usr/bin/svn-multi,/usr/share/texmf-dist/scripts/svn-multi/svn-multi.pl
texlive-collection-latexextra,/usr/bin/vpe,/usr/share/texmf-dist/scripts/vpe/vpe.pl
texlive-collection-latexrecommended,/usr/bin/thumbpdf,/usr/share/texmf-dist/scripts/thumbpdf/thumbpdf.pl
texlive-collection-luatex,/usr/bin/checkcites,/usr/share/texmf-dist/scripts/checkcites/checkcites.lua
texlive-collection-luatex,/usr/bin/mkluatexfontdb,/usr/share/texmf-dist/scripts/luaotfload/mkluatexfontdb.lua
texlive-collection-music,/usr/bin/m-tx,/usr/share/texmf-dist/scripts/m-tx/m-tx.lua
texlive-collection-music,/usr/bin/musixflx,/usr/share/texmf-dist/scripts/musixtex/musixflx.lua
texlive-collection-music,/usr/bin/musixtex,/usr/share/texmf-dist/scripts/musixtex/musixtex.lua
texlive-collection-music,/usr/bin/pmx2pdf,/usr/share/texmf-dist/scripts/pmx/pmx2pdf.lua
texlive-collection-pictures,/usr/bin/cachepic,/usr/share/texmf-dist/scripts/cachepic/cachepic.tlu
texlive-collection-pictures,/usr/bin/epspdf,/usr/share/texmf-dist/scripts/epspdf/epspdf.rb
texlive-collection-pictures,/usr/bin/epspdftk,/usr/share/texmf-dist/scripts/epspdf/epspdftk.tcl
texlive-collection-pictures,/usr/bin/fig4latex,/usr/share/texmf-dist/scripts/fig4latex/fig4latex
texlive-collection-pictures,/usr/bin/mathspic,/usr/share/texmf-dist/scripts/mathspic/mathspic.pl
texlive-collection-pstricks,/usr/bin/pedigree,/usr/share/texmf-dist/scripts/pedigree-perl/pedigree.pl
texlive-collection-pstricks,/usr/bin/pst2pdf,/usr/share/texmf-dist/scripts/pst2pdf/pst2pdf
texlive-collection-science,/usr/bin/ulqda,/usr/share/texmf-dist/scripts/ulqda/ulqda.pl
)
for i in ${del_symlnks[@]}; do
    %__rm -f %{buildroot}$(echo $i | cut -f 2 -d",") || exit 1
done

## we replace texmf/web2c/updmap{,-hdr}.cfg with our updmap files
%__cp -a %{SOURCE7} %{build_texmf}/web2c/updmap.cfg || exit 1
%__mkdir_p %{buildroot}%{texmfsysconfig}/web2c
%__cp -a %{SOURCE7} %{buildroot}%{texmfsysconfig}/web2c/updmap.cfg || exit 1

## use our map files for dvipdfmx
%__mkdir_p %{buildroot}%{aliasttfdir}
%__mkdir_p %{buildroot}%{texmfsysvar}/fonts/map/dvipdfmx/vine
for x in ptex uptex otf otf-up; do 
    touch %{buildroot}%{texmfsysvar}/fonts/map/dvipdfmx/vine/${x}-vine.map
done
for x in FutoGo-Bold FutoMin-Bold Gothic-Medium MaruGo-Medium Mincho-Medium; do
    touch %{buildroot}%{aliasttfdir}/${x}.ttf
done

## install updmap-kanji.html
%__mkdir_p %{build_texmf}/doc/fonts/jfontmaps
%__install -m0644 %{SOURCE2} %{build_texmf}/doc/fonts/jfontmaps/ || exit 1
## install jtygm.sty
%__mkdir_p %{build_texmf}/tex/platex/base
%__install -m0644 %{SOURCE101} %{build_texmf}/tex/platex/base/ || exit 1
## install cmex.enc
%__mkdir_p %{build_texmf}/fonts/enc/pdftex/cmex
%__install -m0644 %{SOURCE102} %{build_texmf}/fonts/enc/pdftex/cmex/ || exit 1

## desktop things
%__mkdir_p %{buildroot}%{_datadir}/applications
%__install -m0644 -c %{SOURCE10} %{SOURCE11} \
    %{buildroot}%{_datadir}/applications/

# for created fonts
%__mkdir_p %{buildroot}%{vartexfonts}
# %__mkdir_p %{buildroot}%{_sysconfdir}/cron.daily
# %__install -m 755 %{SOURCE100} %{buildroot}%{_sysconfdir}/cron.daily/

## set executable bit for the library
%__chmod a+x %{buildroot}%{_libdir}/libkpathsea.so.*.*
%__chmod a+x %{buildroot}%{_libdir}/libptexenc.so.*.*

# configure ConTeXt
for x in context ctxtools luatools texexec texmfstart; do
  %__sed -i -e 's|mtxrun|export TEXMF=%{texmf}-dist TEXMFCNF=%{texmf}/web2c TEXMFCACHE=%{texmfsysvar}; mtxrun|' %{buildroot}%{_bindir}/${x}
done

# touch ghosts
touch %{build_texmf}/ls-R
touch %{build_texmf}-dist/ls-R
touch %{buildroot}%{texmfsysconfig}/ls-R
touch %{buildroot}%{texmfsysvar}/ls-R

## remove unpackaging files
find %{buildroot} | %__grep -e "\\.\(la\|a\)$" | xargs %__rm -f || exit 1
find %{buildroot} | %__grep -e "\\.\(diff\|patch\)$" | xargs %__rm -f || exit 1
%__rm -f %{buildroot}%{_bindir}/tlmgr || exit 1
find %{build_texmf}/fonts/map -type d | %__grep "updmap" | xargs %__rm -rf || exit 1
find %{buildroot} -type d | grep asymptote | xargs %__rm -rf || exit 1
%__rm -f %{build_texmf}/dvipdfm/config/config-win32 || exit 1
%__rm -f %{buildroot}%{_infodir}/*


### Files list
find %{buildroot} -type f -or -type l | \
    %__sed -e "s|%{buildroot}||g" | \
    %__grep -v -e ".patch$" -e "\.diff$" -e "\.orig$" | \
    %__grep -v "%{_includedir}" | \
    %__grep -v "%{_libdir}" | \
    %__grep -v "%{_infodir}" | \
    %__sed -e "s|.*ls-R$|%ghost &|" \
           -e "s|%{texmfsysvar}/fonts/map/dvipdfmx/vine/.*\.map$|%ghost &|" \
           -e "s|%{aliasttfdir}/.*\.ttf$|%ghost &|" \
           -e "s|.*/updmap.*\.cfg$|%config(noreplace) &|" \
           -e "s|.*/dvipdfmx\.cfg$|%config(noreplace) &|" \
           -e "s|.*xdvi\.cfg$|%config(noreplace) &|" \
           -e "s|.*\.cnf$|%config(noreplace) &|" \
	   -e "s|%{texmf}*/xdvi/XDvi|%config(noreplace) &|" \
           -e "s|%{texmf}/web2c/texmfcnf\.lua$|%config(noreplace) &|" \
	   -e "s|^.*/updmap/$|%config &|" \
           -e "s|%{texmf}*/texconfig/tcfmgr.map$|%config &|" \
	   -e "s|%{texmf}*/dvips/config/.*$|%config &|" \
           -e "s|%{texmf}*/dvips/tetex/config.*$|%config &|" \
           -e "s|%{texmf}*/dvipdfm/config/config$|%config &|" \
           -e "s|%{texmf}*/fonts/map/dvips/tetex/.*.map$|%config &|" \
           -e "s|%{texmf}*/fonts/map/dvipdfmx/.*.map$|%config &|" \
	   -e "s|%{texmf}*/tex/generic/config/.*|%config &|" \
           -e "s|%{texmf}*/ttf2pk/ttf2pk\.cfg$|%config &|" \
           -e "s|%{texmf}*/hbf2gf/.*\.cfg$|%config &|" \
           -e "s|%{texmf}*/chktex/chktexrc$|%config &|" \
	   -e "s|%{_mandir}/.*|&*|" \
	> %{_builddir}/filelist.full

find %{buildroot}%{texmf}* -type d | \
    %__sed -e "s|^%{buildroot}|%dir |" \
	   -e "s|$|/|" >> %{_builddir}/filelist.full

## subpackages
%__grep -e "/texmf/doc/" -e "/texdoc" %{_builddir}/filelist.full > %{_builddir}/filelist.doc
cat %{_builddir}/filelist.doc \
    %{_builddir}/filelist.full | \
    sort | uniq -u > %{_builddir}/filelist.tmp
%__mv -f %{_builddir}/filelist.tmp %{_builddir}/filelist.full


%clean
%__rm -rf %{buildroot}


%pretrans
rpm -q texlive | grep -q -e 2009 -e 2011
[ $? -eq 1 ] && exit 0
## upgrade TeX Live to 2012
_trans_time=$(date +%Y%m%d)
echo "Running transitional process of your TeX system ... "
for dir in %{texmf}-var %{texmf}-config; do
    _trans_dir=${dir}.${_trans_time}.rpmorig
    [ -d ${_trans_dir}.old ] && \
        echo -n "  " && \
        echo "Found ${_trans_dir}.old: " && \
        echo -n "    " && \
        %__rm -rvf ${_trans_dir}.old
    [ -d ${_trans_dir} ] && \
        echo -n "  " && \
        echo "Found ${_trans_dir}: " && \
        echo -n "    " && \
        %__mv -v ${_trans_dir} ${_trans_dir}.old
    [ -d ${dir} ] && \
        echo -n "  " && \
        echo "Found ${dir}: " && \
        echo -n "    " && \
        %__mv -v ${dir} ${_trans_dir}
done
echo "done."

%preun
if [ "$1" = 0 ]; then
    %__rm -rf %{vartexfonts}
fi
exit 0

%post
%touch_run texhash
%touch_run updmap
%touch_run mtxrun
%touch_run fmtutil
exit 0

%posttrans
%__mkdir_p %{vartexfonts}
%__chmod 1777 %{vartexfonts}
## create our map files {ptex,uptex,otf,otf-up}-vine.map
( %{exec_upddeffont} ) ||:

%{exec_texhash}
%{exec_mtxrun}
%{exec_updmap}
%{exec_fmtutil}
exit 0

%post -n libkpathsea
/sbin/ldconfig
# for x in kpathsea tds web2c; do 
#     /sbin/install-info %{_infodir}/${x}.info.* %{_infodir}/dir
# done

# %preun -n libkpathsea
# if [ "$1" = 0 ]; then
#     for x in kpathsea tds web2c; do 
#         /sbin/install-info --delete %{_infodir}/${x}.info.* %{_infodir}/dir
#     done
# fi

%postun -n libkpathsea
/sbin/ldconfig

%post -n libptexenc
/sbin/ldconfig

%postun -n libptexenc
/sbin/ldconfig

%triggerin -- ghostscript
%__rm -f %{texmf}/fonts/cmap/ghostscript
if [ -d "%{_datadir}/ghostscript/$(gs --version| cut -d . -f 1-2)/Resource/CMap" ] ; then
    %__ln_s %{_datadir}/ghostscript/$(gs --version| cut -d . -f 1-2)/Resource/CMap %{texmf}/fonts/cmap/ghostscript
elif [ -d "%{_datadir}/ghostscript/Resource/CMap" ] ; then
    %__ln_s %{_datadir}/ghostscript/Resource/CMap %{texmf}/fonts/cmap/ghostscript
fi
%touch_run texhash
exit 0


%files -f %{_builddir}/filelist.full
%defattr(-,root,root)
%dir %{aliasttfdir}
%attr(1777,root,root) %dir %{vartexfonts}
# %config %{_sysconfdir}/cron.daily/texlive.cron

%files doc -f %{_builddir}/filelist.doc
%defattr(-,root,root)

%files -n libkpathsea
%defattr(-,root,root)
%{_libdir}/libkpathsea.so.*
# %{_infodir}/kpathsea.info*

%files -n libkpathsea-devel
%defattr(-,root,root)
%{_libdir}/libkpathsea.so
%dir %{_includedir}/kpathsea
%{_includedir}/kpathsea/*

%files -n libptexenc
%defattr(-,root,root)
%{_libdir}/libptexenc.so.*

%files -n libptexenc-devel
%defattr(-,root,root)
%{_libdir}/libptexenc.so
%dir %{_includedir}/ptexenc
%{_includedir}/ptexenc/*


%changelog
* Mon Nov 26 2012 Munehiro Yamamoto <munepi@vinelinux.org> 2012-2
- fixed Source7: updmap.cfg.texlive-20120701 
  (upto /etc/texmf/web2c/updmap.cfg)
- fixex %%triggerin -- ghostscript
  - replaced %%exec_texhash with %%touch_run texhash

* Wed Nov 21 2012 Munehiro Yamamoto <munepi@vinelinux.org> 2012-1
- TeX Live 2012 + tlptexlive 20121107

* Tue Oct 30 2012 Munehiro Yamamoto <munepi@vinelinux.org> 2011-7
- drop BR: poppler-devel temporaly
  - modify tl11supp-120120-vine.patch, texlive-20110705-vine.patch to do that

* Mon May 28 2012 Munehiro Yamamoto <munepi@vinelinux.org> 2011-6
- build with poppler-0.18.4
- remove tlmgr

* Thu Jan 26 2012 Munehiro Yamamoto <munepi@vinelinux.org> 2011-5
- updated to tl11supp-120120
- run %%{exec_fmtutil} at %%post when upgrading

* Sat Dec 17 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2011-4
- updated to tl11supp-111214

* Sat Dec  3 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2011-3
- added BuildRequires: texlive-common
  - Babel needs docstrip.tex, which is contained in texlive-collection-latex
  - check japanese.ldf
- updated tl11supp-111120-vine.patch
  - added the following options to $$TL_CONFIGURE_ARGS: 
    --disable-detex 
    --disable-dvipng
    --disable-lcdf-typetools
- remove some files of asymptote
- remove a man file of latexmk
- remove man files of lcdf-typetools
- remove man files of dvipng
- remove a man file of detex

* Mon Nov 28 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2011-2
- added find-provides-texlive.sh and set it to %%__find_provides
  - use to find library sonames for libkpathsea and libptexenc
- added cmex.enc (%%{SOURCE110})
  - do not install cmex.enc in our TDS, yet
- removed some unused directories in texmf/fonts/map
- removed man files of lcdf-typetools
- moved texdoc{,tk} and its related files to texlive-doc

* Wed Nov 23 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2011-1
- TeX Live 2011 + tl11supp-111120

* Thu Oct 13 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-22
- make the directory VARTEXFONTS (%%posttrans)
  - dropped %%triggerpostun -- texlive < 2009-17vl6

* Tue Jul 19 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-21
- fixed ptexlive-20100711-dvipdfmx-vine.patch
  - for dvipdfmx.cfg, given some ps2pdf's parameters mistaked

* Thu Jun 16 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-20
- added %%pre to avoid conflictions of texmf-{config,var}

* Sun May 22 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-19
- dropped Requires: texlive-common
- added perl-Tk-TableMatrix
  - supported texdoctk
- removed broken symbolic links in /usr/bin
  - for each these symbolic links, the package of its real file/path 
    should be its owner. 

* Thu May 19 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-18
- added %%triggerpostun -- texlive < 2009-17vl6
  - make the directory VARTEXFONTS

* Tue May 10 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-17
- fixed %%dir VARTEXFONTS around in %%files
- dropped BuildRequires: t1utils

* Tue Apr 26 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-16
- updated texlive-20091107-texmfcnf-vine.patch, texlive.cron
  - changed VARTEXFONTS to /var/lib/texmf/fonts

* Mon Apr 25 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-15
- fixed updmap.cfg

* Sun Mar 27 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-14
- dropped Requires: texlive-macros

* Sat Jan 15 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-13
- updated ptexlive-20100711-pxdvik-vine.patch 
  and added texlive-20091107-xdvik-vine.patch
  - fixed to adjust X resources in texmf/xdvi/XDvi for (p)xdvi

* Sat Jan 08 2011 Munehiro Yamamoto <munepi@vinelinux.org> 2009-12
- supported Vine Linux 5
  - for vl5, changed a requirement of Japanese VF package
    - added Requires: texlive-jvf = 2009 (vl5)
- dropped dependencies of Provides:/Obsoletes: tags
  - merged these dependencies in texlive-common-vl.spec

* Wed Dec 01 2010 Shu KONNO <owa@bg.wakwak.com> 2009-11
- rebuilt with poppler-0.14.2 (libpoppler has been up to so.7)

* Fri Sep 24 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-10
- applied some security patches from Debian
  - texlive-2009-CVE-2010-0827.patch
  - texlive-2009-CVE-2010-1440.patch
- applied texlive-2009-pdftexdir-libpoppler-0.12.patch from Debian
- applied texlive-2009-luatexdir-libpoppler-0.12.patch
  based on texlive-2009-pdftexdir-libpoppler-0.12.patch
- fixed some dependencies

* Mon Aug 09 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-9
- added BuildArch: noarch in %%package doc
- removed some comment-out sentences

* Tue Jul 20 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-8
- separeted texmf-dist to texlive-common package

* Mon Jul 19 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-7
- unpacked texlive-20091107-source.tar.xz
- babel is available now
- applied eptex-100420 and some patches: 
  - eptex-100420-vine.patch
  - eptex-100420-patch1.diff

* Tue Jul 13 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-6
- updated ptexlive-20100711

* Sat Jun 12 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-5
- customized updmap.cfg to correspond installed fonts

* Mon May 31 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-4
- fixed insttexfont()

* Mon May 17 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-3
- added jvf of MORISAWA basic 5 fonts
- added cm-super, mathdesign in fntlst

* Sun May 16 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-2
- define insttexfont() in %%install
  - copy almost compatible tetex-3.0

* Sat May 08 2010 Munehiro Yamamoto <munepi@vinelinux.org> 2009-1
- ptexlive-20090322 + TeXLive 2009
- added BuildRequires: openssl-devel

* Sun Dec 06 2009 Munehiro Yamamoto <munepi@vinelinux.org> 2008-0.20091206
- ptexlive-20091009 + TeXLive 2008
