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

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

%define with_babel 1

%define ptexlivever	20100711
%define texlivesrcver   20091107
%define texlivever      20091107

## we provides e-pTeX and upTeX
%define with_uptex	0
%define with_eptex	1
%define uptexver	0.30
%define uptex_fontver	0.30
%define eptexver	100420

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

Autoreq: 0

Summary: The TeX text formatting system
Summary(ja): TeX 文書整形システム
Name: texlive
Version: 2009
Release: 13%{?_dist_release}
License: distributable
Group: Applications/Publishing
## The TeX Live is located on http://www.tug.org/texlive/
## e-pTeX: http://eptex.sourceforge.jp/
## upTeX: http://homepage3.nifty.com/ttk/comp/tex/uptex.html
URL: http://tutimura.ath.cx/ptexlive/

## original TeX Live sources
Source: http://tutimura.ath.cx/~nob/tex/ptexlive/ptexlive-%{ptexlivever}.tar.gz

##Source1: ftp://tug.org/historic/systems/texlive/2009/%{name}-%{texlivesrcver}-source.tar.xz
##Source2: ftp://tug.org/historic/systems/texlive/2009/%{name}-%{texlivever}-texmf.tar.xz
##Source3: ftp://tug.org/historic/systems/texlive/2009/%{name}-%{texlivever}-extra.tar.xz
##Source4: ftp://tug.org/historic/systems/texlive/2009/%{name}-%{texlivever}-bin.tar.xz
##Source5: ftp://tug.org/historic/systems/texlive/2009/tlnet/install-tl-unx.tar.gz

## pxdvi
Source10: pxdvi.desktop

## dvipdfmx
#Source20: 

## texdoc
## http://github.com/mpg/texdoc
## Downloaded mpg-texdoc-0.72-0-gfdb7657.tar.gz
## Renamed this archive: 
# $ tar zxf mpg-texdoc-0.72-0-gfdb7657.tar.gz
# $ mv mpg-texdoc-b66e1e3 texdoc-0.72
# $ tar zcf texdoc-0.72.tar.gz texdoc-0.72
#Source90: texdoc-%{texdocver}.tar.gz

## Japanese ptex


# ## Babel
# ## See [texqa:37398] http://oku.edu.mie-u.ac.jp/~okumura/texfaq/qa/37398.html
# Source40: http://www.ctan.org/tex-archive/obsolete/systems/win32/fptex/0.7/collection/tex-langother.zip
# Source41: http://www.ctan.org/tex-archive/obsolete/systems/win32/fptex/0.7/package/texlive-base.zip


## e-pTeX, upTeX
Source50: http://homepage3.nifty.com/ttk/comp/tex/uptex-%{uptexver}.tar.gz
Source51: http://homepage3.nifty.com/ttk/comp/tex/uptex_font-%{uptex_fontver}.tar.gz
Source52: http://sourceforge.jp/projects/eptex/downloads/43841/eptex-%{eptexver}.tar.bz2

## etc...
Source100: texlive.cron
Source101: dvi-to-ps.fpi
Source102: http://auemath.aichi-edu.ac.jp/~khotta/ghost/disk1/jtygm.sty
Source103: ps-morisawa.map
Source104: ps-morisawa-noEmbed.map


# ## do not provide any perl deps (#516350)
# %define __perl_provides	%{nil}


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

## vine
Patch0:		ptexlive-%{ptexlivever}-vine.patch
Patch1:		texlive-%{texlivesrcver}-set-selfautodir.patch
##Patch1:	texlive-2009-texmfcnf-selfautodir-vine.patch
Patch2:		texlive-%{texlivesrcver}-texmfcnf-vine.patch

## (p)xdvik
Patch10:	ptexlive-%{ptexlivever}-pxdvik-vine.patch
Patch11:	texlive-%{texlivesrcver}-xdvik-vine.patch

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

## e-pTeX + upTeX
Patch50:	eptex-100420-vine.patch
Patch51:	http://sourceforge.jp/projects/eptex/wiki/FrontPage/attach/eptex-100420-patch1.diff

## texdoc
#Patch90:	texdoc-0.72-support-zipped-vine.patch

## others
## libpoppler-0.12 from texlive-bin_2009-7.diff.gz
Patch100:	texlive-2009-pdftexdir-libpoppler-0.12.patch
Patch101:	texlive-2009-luatexdir-libpoppler-0.12.patch

## security
## from Debian
#Patch1000:	texlive-2009-CVE-2010-0739.patch
Patch1001:	texlive-2009-CVE-2010-0827.patch
## this overrides the incomplete fix for CVE-2010-0793
Patch1002:	texlive-2009-CVE-2010-1440.patch


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
Requires:    openssl
Requires:    libpaper
Requires:    fontconfig
Requires:    perl-Tk
Requires:    nkf
Requires:    ghostscript >= 8.63
%if %{?_dist_release} == "vl6"
Requires:    libkpathsea = %{version}-%{release}
Requires:    libptexenc = %{version}-%{release}
%endif
%{!?with_firstbuild:Requires: texlive-common = %{version}}
%{!?with_firstbuild:Requires: texlive-macros = %{version}}
%if %{?_dist_release} == "vl6"
%{!?with_firstbuild:Requires: jvf >= 2.0-5}
%endif
%if %{?_dist_release} == "vl5"
%{!?with_firstbuild:Requires: texlive-jvf >= 2.0-5}
%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: 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.63
BuildRequires: openMotif-devel
BuildRequires: poppler-devel
BuildRequires: openssl-devel
BuildRequires: libpaper-devel
BuildRequires: fontconfig-devel
BuildRequires: nkf
BuildRequires: t1utils

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.

This package provides a Japanese TeX environment 
based on ptexlive-%{ptexlivever}. 


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

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

このパッケージは ptexlive-%{ptexlivever} を元にした
日本語 TeX 環境を提供します。


%package doc
Summary: TeX Live: Documentation files of %{name}
Group: Applications/Publishing
Requires: %{name} = %{version}-%{release}
%if %{?_dist_release} != "vl5"
BuildArch: noarch
%endif

%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 -n ptexlive-%{ptexlivever} -a 90
%setup -q -n ptexlive-%{ptexlivever}

## extract texlive-source
%__tar Jxf %{texlive_src}/source/%{name}-%{texlivesrcver}-source.tar.xz || exit 1

## move texlive-source to build/
%__mkdir_p build && \
    %__mv %{name}-%{texlivesrcver}-source build/ || exit 1

## apply ptexlive
%patch0 -p1 -b .orig

## fix $SELFAUTODIR to /usr/share
%patch1 -p1 -b .orig

%__cat <<EOF > ptexlive.cfg
#KANJI_CODE=EUC
KANJI_CODE=UTF8

TEXLIVE_VERSION=2009
ISO_DIR=%{texlive_src}
TEXLIVE_DIR=%{texlive_src}
##SRC_DIR=%{_sourcedir}
SRC_TAR=%{SOURCE0}

##PREFIX=%{tex_destdir}
PREFIX=$(pwd)/Vine
TMP_PREFIX=$(pwd)/build
TEXSRC_EXTRACTED=$(pwd)/build/%{name}-%{texlivesrcver}-source
##SRC_TAR=%{SOURCE1}
##TEXMFDIST=$(pwd)/build/%{name}-%{texlivesrcver}-source/inst/texmf-dist
TEXMFDIST=%{texlive_src}/texmf-dist

XDVI=echo
PSPDF=echo

make_option vartexfonts=%{vartexfonts}

conf_option --enable-luatex
conf_option --enable-xetex
conf_option --enable-xdv2pdf
conf_option --enable-xdvipdfmx

conf_option --with-xdvi-x-toolkit=motif
# conf_option --without-x
# conf_option --disable-xdvik
# conf_option --disable-oxdvik
# conf_option --disable-pxdvik

conf_option --with-system-ncurses
conf_option --with-system-zlib
conf_option --with-system-pnglib
conf_option --with-system-t1lib
conf_option --with-system-xpdf
conf_option --with-system-freetype
conf_option --with-system-freetype2
conf_option --with-freetype2-include=`freetype-config --cflags | sed -e 's/-I//' -e 's/ .*//'`
conf_option --with-system-gd
EOF

## For vl5, libkpathsea and libptexenc libraries are static link
%if %{enable_sharedlib}
%__cat <<EOF >> ptexlive.cfg
conf_option --enable-shared
EOF
%endif

%__cat <<EOF >> ptexlive.cfg
conf_option --enable-kanji-iconv

conf_option --disable-multiplatform
make_option %{?_smp_mflags}
EOF

## exec 2extract-src.sh
%__make x

## texmf.cnf for Vine Linux
%patch2 -p1 -b .orig

## (p)xdvik for Vine Linux
%patch10 -p1 -b .orig
%patch11 -p1 -b .orig

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

## eptex
(cd .. 
%__tar jxf %{SOURCE52}
cd eptex-%{eptexver}
%patch50 -p1 -b .orig
%patch51 -p1 -b .orig
## apply eptex: exec almost 0eptex.sh
%if %with_eptex
./0eptex.sh
%endif
)

## texdoc
#%patch90 -p0 -b .orig

## libpoppler-0.12
%if %{?_dist_release} != "vl5"
(cd build/%{name}-%{texlivesrcver}-source
%patch100 -p1 -b .xpdf
%patch101 -p1 -b .xpdf
)
%endif

## apply security patches
(cd build/%{name}-%{texlivesrcver}-source
#%patch1000 
%patch1001 -p1 -b .security
%patch1002 -p1 -b .security
)


%build
## NOTE: 
## In this setion, 
## execute almostly 3make-install.sh
set -x
unset TEXINPUTS || :
unset HOME || :

. ./common.sh

export CFLAGS="$RPM_OPT_FLAGS" CXXFLAGS="$RPM_OPT_FLAGS" LANG=C
##%__make c

PREF=${TEXSRC_EXTRACTED}/inst

%__mkdir_p ${PREF}/texmf 
%__mkdir_p ${PREF}/../Work
pushd ${PREF}/../Work
../configure --host=%{_host} --build=%{_build} \
    --prefix=${PREF} \
    --datadir=${PREF} \
    \
    --disable-native-texlive-build \
    --enable-multiplatform \
    --disable-omfonts \
    --enable-compiler-warnings=max \
    --without-cxx-runtime-hack \
    --enable-kanji=$KANJI_CODE \
    --with-ptexenc=$KANJI_CODE \
    --disable-all-pkgs \
    --enable-web2c \
    --disable-luatex \
    --disable-xetex \
    --enable-mf \
    --enable-mf-nowin \
    --enable-mp \
    --enable-web-progs \
    --enable-dvipdfmx \
    --enable-dvipsk \
    --enable-pdvipsk \
    --enable-gsftopk \
    --enable-makeindexk \
    --enable-makejvf \
    --enable-mendexk \
    --enable-ps2pkm \
    --enable-xdvik \
    --enable-pxdvik \
    --enable-tetex \
    --enable-texlive \
    $CONF_OPTION


(cd ..
## Avoid pollution from internal libraries.
%__rm -rf ./libs/{expat,freetype,freetype2,gd,jpeg,libpng,libttf,ncurses,type1,t1lib,unzip,xpdf,zlib}

## XXX Hacks to avoid accidental version clashs with system libraries.
hack_libs=(
    zlib
    libpng
    t1lib
    freetype
    freetype2
    gd
    xpdf
)
for i in  "${hack_libs[@]}"; do 
    %__mkdir_p ./libs/${i}
    touch ./libs/${i}/configure
done
)

%__make world $MAKE_OPTION %{?_smp_mflags}
popd


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

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

. ./common.sh

PREF=${TEXSRC_EXTRACTED}/inst

pushd ${PREF}/../Work
## the following two lines are useful for
## "rpmbuild -ba --short-circuit  ~/rpm/SPECS/texlive-vl.spec"
%__rm -rf ${PREF}
%__make world $MAKE_OPTION
popd

## execute almostly 4extract-texmf.sh
%__mv ${PREF}/texmf-dist ${PREF}/texmf-dist.install  || exit # never use
%__mv ${PREF}/texmf ${PREF}/texmf.install            || exit
%__cp -r %{texlive_src}/texmf ${PREF}/          || exit
%__cp -rf ${PREF}/texmf.install/* ${PREF}/texmf/     || exit

## copy almost compatible TeX system of teTeX-3.0
## NOTE: The size of texmf-dist is about 2GB below: 
# 890M	doc
# 660M	fonts
# 103M	source
# 
# 68M	tex/latex
# 46M	tex/generic
# 27M	tex/context
##%__ln_s -f %{texlive_src}/texmf-dist ${PREF}/
%__mkdir_p ${PREF}/texmf-dist
##!! [FAKE] copy all directries except doc, fonts, source, tex4ht in texmf-dist
(cd %{texlive_src}/texmf-dist
    %__cp -r README metapost scripts bibtex dvips makeindex mft \
             tlpkg context metafont tex omega vtex \
	${PREF}/texmf-dist/
)
## copy some fonts (almost tetex + tetex-extra)
## NOTE: this part is in texlive-common since texlive-8vl6

#### customize updmap.cfg for each font's map files
%{!?with_firstbuild: \
    %__sed -i -e "s,^\(Map\|MixedMap\),#! \1,g" ${PREF}/texmf/web2c/updmap.cfg}

## make some fundamental texmf trees
%__mkdir_p ${PREF}/texmf-config
%__mkdir_p ${PREF}/texmf-var
%__mkdir_p ${PREF}/texmf-local

## NOTE: need texmf-dist/tex/latex/ltxmisc url.sty
./4extract-texmf.sh %{?with_firstbuild: || :}%{!?with_firstbuild: || exit 1}

## post 0eptex.sh
%if %with_eptex
(cd ../eptex-%{eptexver}
## copying distfiles
echo "[copying]    eptex.src"
%__mkdir -p ${TEXMF}/ptex/plain/base
%__cp eptex.src ${TEXMF}/ptex/plain/base/ || exit 1
echo "[copying]    eptexdefs.lib"
cp eptexdefs.lib $TEXMF/ptex/plain/base/ || exit 1
echo "[copying]    language.def"
%__mkdir -p ${TEXMF}/ptex/generic/config
%__cp language.def ${TEXMF}/ptex/generic/config/ || exit 1
)
%endif

##!! DO NOT execute 5macro.sh
# ./5macro.sh clean default utf %{?with_firstbuild: || :}%{!?with_firstbuild: || exit 1}
# ./5macro.sh otf %{?with_firstbuild: || :}%{!?with_firstbuild: || exit 1}

## execute 6babel.sh
%if %with_babel
# %__unzip -o -d babel %{SOURCE40} 
# %__unzip -o -d babel %{SOURCE41}
# %__install -m0644 \
#       babel/texmf/tex/generic/hyphen/cathyph.tex \
#       babel/texmf/tex/generic/hyphen/cyhyph.tex \
#     ${TEXMF}/tex/generic/hyphen/ || exit 1
%{!?with_firstbuild: ../eptex-%{eptexver}/6babel.sh || exit 1}
## check 6babel.sh
%{!?with_firstbuild: [ -f ${PREF}/texmf/doc/japanese/sample.tex ] || exit 1}
%endif

# ## update texdoc
# cd texdoc-%{texdocver} || exit 1
# %__rm -rf ${PREF}/texmf/texdoc || exit 1
# %__mkdir_p ${PREF}/texmf/texdoc
# %__cp -fa texdoc.cnf ${PREF}/texmf/texdoc/ || exit 1

# %__rm -rf ${PREF}/texmf/scripts/texdoc || exit 1
# %__rm -f script/*.orig || exit 1
# %__cp -ra script ${PREF}/texmf/scripts/texdoc || exit 1
# %__chmod 755 ${PREF}/texmf/scripts/texdoc/* || exit 1

# %__rm -rf ${PREF}/texmf/doc/texdoc || exit 1
# %__cp -ra doc ${PREF}/texmf/doc/texdoc || exit 1
# %__cp -a News Todo ${PREF}/texmf/doc/texdoc/ || exit 1
# cd -
# # TODO: 
# # %{!?with_firstbuild: \
# #     cd ${PREF}/texmf/doc/texdoc && %__make || exit 1}


## install
%__mkdir_p %{buildroot}%{_prefix}
(cd ${PREF}
%__rm -f bin/man
%__cp -r bin %{buildroot}%{_bindir}
%__cp -r lib %{buildroot}%{_libdir}
%__cp -r include %{buildroot}%{_includedir}

##NOTE: use man, info files from texlive-sources
%__rm -rf texmf/doc/info
%__rm -rf texmf/doc/man

%__mkdir_p %{build_tex_destdir}
## NOTE: texmf-dist is contained in texlive-common package
##%__cp -r texmf{,-dist,-config,-var,-local} %{build_tex_destdir}/ || exit 1
%__cp -r texmf{,-config,-var,-local} %{build_tex_destdir}/ || exit 1
)

%__mkdir_p %{build_texmf}/fonts/truetype
%__mkdir_p %{build_texmf}/fonts/opentype

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

## delete useless files (conflict with jvf package)
# rm -rf %{build_texmf}/fonts/vf/ptex
# rm -rf %{build_texmf}/fonts/tfm/ptex/*[a-zA-Z].tfm
%__rm %{build_texmf}/fonts/vf/ptex/{min,tmin,goth,tgoth}{5,6,7,8,9,10}.vf || exit 1

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

## morisawa map files remaped PS Kanji (CIDFont) Name
%__install -m 0644 %{SOURCE103} %{SOURCE104} \
    %{buildroot}%{texmf}/fonts/map/dvipdfm/ptexlive/


## remove asymptote directries, which provides asymptote package
find %{buildroot} -regex ".*asymptote.*" | xargs %__rm -rf
# find %{buildroot} -name "Makefile" | xargs %__rm -f

# ## remove xindy
# find %{buildroot} -regex ".*xindy.*" | xargs %__rm -rf

# ## remove tex4ht
# find %{buildroot} -regex ".*tex4ht.*" | xargs %__rm -rf

## 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
popd

# ## compress pdf files in texmf/doc
# find %{build_tex_destdir}/texmf/doc -name "*.pdf" -exec xz {} \;

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

## desktop things
%__mkdir_p %{buildroot}%{_datadir}/applications
%__install -c %{SOURCE10} %{buildroot}%{_datadir}/applications/pxdvi.desktop

# 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}/.*|&*|" \
	> filelist.full

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

## subpackages
%__grep "/texmf/doc/" filelist.full > filelist.doc
cat filelist.doc filelist.full | sort | uniq -u > filelist.tmp
%__mv -f filelist.tmp filelist.full


%clean
%__rm -rf %{buildroot}


%post
## dvipdfmx
## Create our own cid-x.map
( %{exec_upddeffont} ) ||:

%{exec_texhash}
%{exec_updmap} --enable KanjiMap vine.map >/dev/null 2>&1
# echo -n "    "
# echo -n "Running updmap ... " && %{exec_updmap} >/dev/null 2>&1 && echo "done."
# echo -n "    "
# echo -n "Running fmtutil ... " && %{exec_fmtutil} && echo "done."


%preun
%__rm -rf %{_var}/lib/texmf/*
if [ "$1" = 0 ]; then
    ## 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


%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 filelist.full
%defattr(-,root,root)
%attr(1777,root,root) %dir %{_var}/lib/texmf
%config %{_sysconfdir}/cron.daily/texlive.cron

%files doc -f 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 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
