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

%define enable_sharedlib 1
%if %{?_dist_release} == "vl6"
%define enable_sharedlib 0
%endif

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

%define tl11suppver	111214
%define texlivesrcver   20110705
%define texlivever      20110705

%define tl11supp_all_opts		-m -r
%define tl11supp_source_common_sh	cd ${RPM_BUILD_DIR}/%{name}-%{version}/tl11; . ./common.sh %{tl11supp_all_opts}; set -x;

%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
%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/fonts

Summary: The TeX text formatting system
Summary(ja): TeX 文書整形システム
Name: texlive
Version: 2011
Release: 4%{?_dist_release}
License: distributable
Group: Applications/Publishing
URL: http://www.tug.org/texlive/

Source: http://sourceforge.jp/projects/eptex/wiki/TeX_Live_2011/attach/tl11supp-%{tl11suppver}.tar.xz

Source5: updmap-hdr.cfg.texlive-%{texlivesrcver}
Source6: updmap.cfg.texlive-%{texlivesrcver}
Source9: __usr_bin_symlink.sh

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

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

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


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

## vine
Patch0:		tl11supp-%{tl11suppver}-vine.patch
Patch1:		texlive-%{texlivesrcver}-vine.patch
Patch2:		texlive-%{texlivesrcver}-texmfcnf-vine.patch
Patch3:		texlive-%{texlivesrcver}-set-selfautoparent-vine.patch
## pxdvi(k) for Vine Linux
Patch10:	tl11supp-%{tl11suppver}-pxdvik-vine.patch

## dvipdfmx
# Patch20:	ptexlive-%{ptexlivever}-dvipdfmx-vine.patch

## others

## 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.12
Requires:    openssl
Requires:    libpaper
Requires:    fontconfig
Requires:    perl-Tk perl-Tk-TableMatrix
Requires:    nkf
Requires:    ghostscript >= 8.63
%if %{?_dist_release} == "vl7"
Requires:    libkpathsea = %{version}-%{release}
Requires:    libptexenc = %{version}-%{release}
%endif
%if %{?_dist_release} == "vl7"
%{!?with_firstbuild:Requires: jvf >= 7.0}
%endif
%if %{?_dist_release} == "vl6"
%{!?with_firstbuild:Requires: texlive-jvf >= 7.0}
%endif
Requires:    fontconfig >= 2.6.0-2
Requires(post,postun): fontconfig >= 2.6.0-2
Requires(post): ed mktemp
Requires(post): vutils >= 2.0.5
%{!?with_firstbuild:BuildRequires: 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.12
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}.

%if %{enable_sharedlib}
%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.
%endif


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

%setup -q -c %{name}-%{version}

## 
[ -f %{texlive_src}/source/texlive-%{texlivesrcver}-source.tar.xz ] && \
  %__ln_s -f %{texlive_src}/source/texlive-%{texlivesrcver}-source.tar.xz tl11/

## apply tl11supp
%patch0 -p1 -b .vine
%__chmod +x tl11/scripts/build-post.sh || exit 1

## fix $TLSRCDIR
%__sed -i -e "s,TLSRCDIR=/opt/home-supp/tl11,TLSRCDIR=%{_builddir}/%{name}-%{version}/tl11," %{_builddir}/%{name}-%{version}/tl11/common.sh || exit 1

## exec scripts/unpack.sh
%{tl11supp_source_common_sh}

scripts/unpack.sh %{tl11supp_all_opts} || exit 1

## some hacks for Vine Linux
(cd ../
## vine
%patch1 -p1 -b .vine
%patch2 -p1 -b .vine
%patch3 -p1 -b .vine
%patch10 -p1 -b .vine
)

# ## dvipdfmx for Vine Linux
# %patch20 -p1 -b .orig
# )

## apply security patches


%build
set -x
unset TEXINPUTS || :
unset HOME || :
%{tl11supp_source_common_sh}

## exec scripts/build.sh
export CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" \
       CXXFLAGS="$RPM_OPT_FLAGS" \
       LANG=C

scripts/build.sh %{tl11supp_all_opts} || exit 1


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

set -x
unset TEXINPUTS || :
unset HOME || :
%{tl11supp_source_common_sh}

## The following lines are useful for the call of 
## "rpmbuild -ba --short-circuit ~/rpm/SPECS/texlive-vl.spec"
%__rm -rf ${SRCDIR}/inst
(cd ${SRCDIR}/Work
%__make world
)

## exec scripts/build-post.sh (Vine Linux only)
scripts/build-post.sh %{tl11supp_all_opts} || exit 1
[ -d $SRCDIR/inst/texmf.orig ] && %__rm -rf $SRCDIR/inst/texmf.orig || exit 1

## almostly exec scripts/texmf.sh
scripts/texmf.sh %{tl11supp_all_opts} || exit 1

## almostly exec scripts/font.sh
yes N | scripts/font.sh %{tl11supp_all_opts} || exit 1

## replace updmap{,-hdr}.cfg with our updmap{,-hdr}.cfg respectively
%__cp -af %{SOURCE5} $SRCDIR/inst/texmf/web2c/updmap-hdr.cfg || exit 1
%__cp -af %{SOURCE6} $SRCDIR/inst/texmf/web2c/updmap.cfg || exit 1

## almostly exec scripts/install.sh
%__mkdir_p %{build_tex_destdir}
(cd $SRCDIR/inst && tar cf - *) \
    | (cd %{build_tex_destdir} && tar xf -) || exit  1

## check japanese.ldf (Babel for Japanese)
%if %{without firstbuild}
[ -f %{build_texmf}/tex/platex/japanese/japanese.ldf ] || exit 1
[ -f %{build_texmf}/tex/platex/japanese/ptex.log ] || exit 1
[ -f %{build_texmf}/tex/platex/japanese/texput.log ] && exit 1
%endif

## remove the symbolic link texmf-dist@
[ -L %{build_tex_destdir}/texmf-dist ] && \
  %__rm -f %{build_tex_destdir}/texmf-dist || exit 1
## remove lcdf-typetools-for-tex-live directory
#%__rm -r %{build_tex_destdir}/lcdf-typetools-for-tex-live || exit 1
## remove unused directories in texmf/fonts/map
%__rm -rf %{build_texmf}/fonts/map/dvips/updmap || exit 1
%__rm -rf %{build_texmf}/fonts/map/pdftex/updmap || exit 1

## move bin, lib include, man, info to /usr, resp. 
%__rm -f %{build_tex_destdir}/bin/man || exit 1
%__mv %{build_tex_destdir}/bin %{buildroot}%{_bindir} || exit 1
%__mv %{build_tex_destdir}/lib %{buildroot}%{_libdir} || exit 1
%__mv %{build_tex_destdir}/include %{buildroot}%{_includedir} || exit 1
%__cp -ar %{build_texmf}/doc/man %{buildroot}%{_mandir} || exit 1
#%__mv %{build_texmf}/doc/info %{buildroot}%{_infodir} || exit 1

## move dvipdfmx/newmap/{ptex,otf} to dvipdfmx/{ptex,otf}, resp. 
%__mv %{build_texmf}/fonts/map/dvipdfmx/newmap/* %{build_texmf}/fonts/map/dvipdfmx/ || exit 1
%__rm -rf %{build_texmf}/fonts/map/dvipdfmx/newmap

## make some fundamental texmf trees
%__mkdir_p %{build_texmf}-{config,var,local,dist}
%__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 i in ${texmf_local_dirs[@]}; do
    %__mkdir_p %{build_texmf}-local/${i}
done

## copy texmf-dist/README
%__cp -a %{texlive_src}/texmf-dist/README %{build_texmf}-dist/ || exit 1

## customize updmap.cfg
%__sed -i -e "s,^\(Map\|MixedMap\),#! \1,g" %{build_texmf}/web2c/updmap.cfg

## dvipdfmx: our map file
%__mkdir_p %{build_texmf}/fonts/map/dvipdfmx
touch %{build_texmf}/fonts/map/dvipdfmx/vine.map

## install jtygm.sty
%__mkdir_p %{build_texmf}/tex/platex/base/
%__install -m0644 %{SOURCE102} %{build_texmf}/tex/platex/base/ || exit 1

## relocate binaries to %{_bindir} and fix relative symlinks
pushd %{buildroot}%{_bindir}
for i in `find . -type l`; do
if [ "`readlink $i | grep '..' | wc -l`" == "1" ]; then
l=`readlink $i | sed s,../,../share/,`
%__ln_s -f $l $i
fi
done
## if the real file of a symlink on /usr/bin is contained 
## in texlive-collection-*, remove its symlink
## See __usr_bin_symlink.sh
del_symlnks=(
texlive-collection-bibtexextra,/usr/bin/bibexport,/usr/share/texmf-dist/scripts/bibexport/bibexport.sh
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/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/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/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/texloganalyser,/usr/share/texmf-dist/scripts/texloganalyser/texloganalyser
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/cmap2enc,/usr/share/texmf-dist/scripts/fontools/cmap2enc
texlive-collection-fontutils,/usr/bin/epstopdf,/usr/share/texmf-dist/scripts/epstopdf/epstopdf.pl
texlive-collection-fontutils,/usr/bin/font2afm,/usr/share/texmf-dist/scripts/fontools/font2afm
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/pfm2kpx,/usr/share/texmf-dist/scripts/fontools/pfm2kpx
texlive-collection-fontutils,/usr/bin/showglyphs,/usr/share/texmf-dist/scripts/fontools/showglyphs
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-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/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/pdfthumb,/usr/share/texmf-dist/scripts/ppower4/pdfthumb.tlu
texlive-collection-latexextra,/usr/bin/perltex,/usr/share/texmf-dist/scripts/perltex/perltex.pl
texlive-collection-latexextra,/usr/bin/ppower4,/usr/share/texmf-dist/scripts/ppower4/ppower4.tlu
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/mkluatexfontdb,/usr/share/texmf-dist/scripts/luaotfload/mkluatexfontdb.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-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/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

## remove man files of psutils
%__rm \
  %{buildroot}%{_mandir}/man1/epsffit.1 \
  %{buildroot}%{_mandir}/man1/extractres.1 \
  %{buildroot}%{_mandir}/man1/fixdlsrps.1 \
  %{buildroot}%{_mandir}/man1/fixfmps.1 \
  %{buildroot}%{_mandir}/man1/fixpsditps.1 \
  %{buildroot}%{_mandir}/man1/fixpspps.1 \
  %{buildroot}%{_mandir}/man1/fixscribeps.1 \
  %{buildroot}%{_mandir}/man1/fixtpps.1 \
  %{buildroot}%{_mandir}/man1/fixwfwps.1 \
  %{buildroot}%{_mandir}/man1/fixwpps.1 \
  %{buildroot}%{_mandir}/man1/fixwwps.1 \
  %{buildroot}%{_mandir}/man1/getafm.1 \
  %{buildroot}%{_mandir}/man1/includeres.1 \
  %{buildroot}%{_mandir}/man1/psbook.1 \
  %{buildroot}%{_mandir}/man1/psmerge.1 \
  %{buildroot}%{_mandir}/man1/psnup.1 \
  %{buildroot}%{_mandir}/man1/psresize.1 \
  %{buildroot}%{_mandir}/man1/psselect.1 \
  %{buildroot}%{_mandir}/man1/pstops.1 \
  || exit 1
## remove man files of lcdf-typetools
%__rm \
  %{buildroot}%{_mandir}/man1/cfftot1.1 \
  %{buildroot}%{_mandir}/man1/mmafm.1 \
  %{buildroot}%{_mandir}/man1/mmpfb.1 \
  %{buildroot}%{_mandir}/man1/otfinfo.1 \
  %{buildroot}%{_mandir}/man1/otftotfm.1 \
  %{buildroot}%{_mandir}/man1/t1dotlessj.1 \
  %{buildroot}%{_mandir}/man1/t1lint.1 \
  %{buildroot}%{_mandir}/man1/t1rawafm.1 \
  %{buildroot}%{_mandir}/man1/t1reencode.1 \
  %{buildroot}%{_mandir}/man1/t1testpage.1 \
  %{buildroot}%{_mandir}/man1/ttftotype42.1 \
  || exit 1
## remove man files of dvipng
%__rm \
  %{buildroot}%{_mandir}/man1/dvigif.1 \
  %{buildroot}%{_mandir}/man1/dvipng.1 \
  || exit 1
## remove some files of asymptote
%__rm \
  %{buildroot}%{_mandir}/man1/asy.1 \
  %{buildroot}%{_mandir}/man1/xasy.1 \
  %{build_texmf}/tex/latex/asymptote/asymptote.sty \
  %{build_texmf}/tex/latex/asymptote/ocg.sty \
  || exit 1
## remove a man file of latexmk
%__rm \
  %{buildroot}%{_mandir}/man1/latexmk.1 \
  || exit 1
## remove a man file of detex
%__rm \
  %{buildroot}%{_mandir}/man1/detex.1 \
  || exit 1

# remove unpackaged files
find $RPM_BUILD_ROOT -name *.la -exec %__rm -f {} \;
find %{buildroot}%{_datadir} -name ls-R -exec %__rm -f {} \;
find %{buildroot}%{_mandir} -name Makefile -exec %__rm -f {} \;
find %{buildroot}%{_mandir} -name *.pdf -exec %__rm -f {} \;


# ## compress info files
# %__rm -f %{buildroot}%{_infodir}/dir
# %__gzip -9nf %{buildroot}%{_infodir}/*info* ||:

## 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
%if %{enable_sharedlib}
%__chmod a+x %{buildroot}%{_libdir}/libkpathsea.so.*.*
%__chmod a+x %{buildroot}%{_libdir}/libptexenc.so.*.*
%endif

## remove unpackaging files
find %{buildroot} | %__grep -e "\\.\(la\|a\)$" | xargs %__rm -f
find %{buildroot} | %__grep -e "\\.\(diff\|patch\)$" | xargs %__rm -f

### Files list
find %{buildroot} -type f -or -type l | \
    %__sed -e "s|%{buildroot}||g" | \
    %__grep -v -e "^%{_sysconfdir}" -e ".patch$" -e "\.diff$" -e "\.orig$" | \
    %__grep -v "%{_includedir}" | \
    %__grep -v "%{_libdir}" | \
    %__grep -v "%{_infodir}" | \
    %__sed -e "s|.*\.\(cnf\|cfg\)$|%config(noreplace) &|" \
	   -e "s|.*ls-R$|%ghost &|" \
	   -e "s|^.*/updmap$|%config &|" \
	   -e "s|%{texmf}*/dvips/config/\(psfonts.*\|ps2pk.*\|pdftex.*\|dvipdfm.*\|.*35\)\.map$|%ghost &|" \
	   -e "s|%{texmf}*/web2c/.*\.\(fmt\|efmt\|log\|base\|mem\|oft\)$|%config &|" \
	   -e "s|%{texmf}*/dvips/config/config\.\(generic\|pdf\|ps\|www\)$|%config &|" \
	   -e "s|%{texmf}*/tex/generic/config/.*|%config &|" \
	   -e "s|%{texmf}*/pdftex/config/pdftex.cfg$|%config &|" \
	   -e "s|%{texmf}*/xdvi/vfontmap$|%config &|" \
	   -e "s|%{texmf}*/xdvi/XDvi|%config &|" \
	   -e "s|%{_mandir}/.*|&*|" \
	> %{_builddir}/%{name}-%{version}/filelist.full

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

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


%clean
%__rm -rf %{buildroot}


%pretrans
rpm -q texlive | grep -q 2009
[ $? -eq 1 ] && exit 0
## upgrade TeX Live from 2009 to 2011
_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."


%post
## create our own vine.map (cid-x.map) to use dvipdfmx
( %{exec_upddeffont} ) ||:

%{exec_texhash}
%{exec_updmap} --syncwithtrees --nomkmap &>/dev/null
%{exec_updmap} --enable KanjiMap vine.map >/dev/null 2>&1
exit 0

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

    ## dvipdfmx
    for i in %{texmf}/fonts/truetype/*; do
	if [ -L "$i" ]; then
	    %__rm -f "$i"
	fi
    done
fi


%if %{enable_sharedlib}
%post -n libkpathsea
/sbin/ldconfig
# /sbin/install-info %{_infodir}/kpathsea.info.* %{_infodir}/dir

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

%postun -n libkpathsea
/sbin/ldconfig

%post -n libptexenc
/sbin/ldconfig

%postun -n libptexenc
/sbin/ldconfig
%endif

%posttrans
%__mkdir_p %{vartexfonts}
%__chmod 1777 %{vartexfonts}


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


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

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

%if %{enable_sharedlib}
%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/*
%endif


%changelog
* 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
