# Set "draft" to 1 to speed up package building during preparation stages.
# Do not use for final release.
%define draft	0
%if %{draft}
%define _binary_payload		w3.zstdio
%undefine __brp_check_rpaths
%undefine __brp_mangle_shebangs
%undefine __brp_python_hardlink
%undefine __brp_remove_la_files
%undefine __brp_python_bytecompile
%undefine py_auto_byte_compile
%endif

# disable python byte compiler
%global _python_bytecompile_extra 0

%global __requires_exclude ^perl\\((PDF::Reuse.*|Pedigree.*|Text::Unidecode|Tie::Watch|SelfLoader|TeXLive.*|Tk::path_tre|only|pdfTeX|script::MakeSPList)\\)|/usr/local/bin/fontforge|/bin/wish|bin/texlua
%global __requires_exclude_from %{?__requires_exclude_from:%__requires_exclude_from|}^%{_docdir}|^/usr/share/texmf-dist/doc
%global __provides_exclude_from %{?__provides_exclude_from:%__provides_exclude_from|}^%{_docdir}|^/usr/share/texmf-dist/doc
# filter out bogus auto-requires
%global __requires_exclude %{?__requires_exclude:%__requires_exclude|}^/usr/bin/lua
%global __requires_exclude %{?__requires_exclude:%__requires_exclude|}^/usr/bin/texlua
%global __requires_exclude %{?__requires_exclude:%__requires_exclude|}^/usr/bin/wish

%define enable_asymptote	0
%define enable_xindy		1

%define with_system_psutils	1
%define with_system_tex4ht	0

%define texmfbindir		%{_bindir}
%define texmfdir		%{_datadir}/texmf
%define texmfdistdir		%{_datadir}/texmf-dist
%define texmflocaldir		%{_datadir}/texmf-local
%define texmfextradir		%{_datadir}/texmf-extra
%define texmffontsdir		%{_datadir}/texmf-fonts
%define texmfprojectdir	%{_datadir}/texmf-project
%define texmfvardir		%{_localstatedir}/lib/texmf
%define texmfconfdir		%{_sysconfdir}/texmf


%define	__jar_repack %{nil}
%define	_enable_debug_packages %{nil}
%define	__debug_package %{nil}
%define __debug_install_post %{nil}

%define relYear 2020
%define subrel 5

Name:		texlive-texmf
Version:	%{relYear}0406
Release:	%mkrel 7
Summary:	The TeX formatting system
Group:		Publishing
License:	https://www.tug.org/texlive/LICENSE.TL
URL:		https://tug.org/texlive/
Source0:	ftp://tug.org/historic/systems/texlive/%{relYear}/texlive-%{version}-texmf.tar.xz
Source1:	ftp://tug.org/historic/systems/texlive/%{relYear}/texlive-%{version}-texmf.tar.xz.sha512
Source2:	XDvi-color
Source3:	https://www.tug.org/texlive/LICENSE.TL
Source4:	ftp://tug.org/historic/systems/texlive/%{relYear}/install-tl-unx.tar.gz#/install-tl-unx-%{relYear}.tgz
# Source5:	http://mirror.hmc.edu/ctan/systems/texlive/tlnet/tlpkg/texlive.tlpdb
Source6:	updmap-collection-basic.cfg
Source7:	updmap-dist.cfg
Source8:	updmap-fontsextra.cfg
Source9:	collection.basic
Source10:	fonts.extra
Source11:	fonts.asian
Source12:	fonts.sources

BuildArch:	noarch
# for pathfix.py
BuildRequires:	python3
BuildRequires:	pkgconfig(python3)
# for _javadir def
BuildRequires:	javapackages-filesystem

#-----------------------------------------------------------------------
Requires:	perl-Algorithm-Diff
Requires(post):	/sbin/install-info
Requires(preun): /sbin/install-info
Requires:	xdg-utils
Requires:	texlive
Requires:	texlive-collection-basic = %{version}
Requires:	texlive-dist = %{version}-%{release}

Obsoletes:	tetex-cmsuper <= 0.3.3
%if !%{with_system_tex4ht}
Obsoletes:	tex4ht <= 1:1.0.2008_02_28_2058
%endif
Obsoletes:     tetex-afm <= 3.1
Provides:	texmf-data = %version-%release
# latex-beamer functionality is already included in texlive-texmf
Obsoletes:	latex-beamer < 3.13
Provides:	latex-beamer = %version-%release

Patch4:		texlive-20160523-texmf-mageia-kpfix.patch
Patch5:		0001-Fix-italian-spelling-in-yplan.sty.patch
Patch6:		texlive-20200406-texmf-fix-mptopdf-et-al-sh-bang.patch

# fix doc package deps:
%global __provides_exclude %{?__provides_exclude:%__provides_exclude|}^pear\\(animals.php\\)$

#-----------------------------------------------------------------------
%description
This package will install the standard TeX Live and MetaFont distribution.
It provides a comprehensive TeX system. It includes all the major
TeX-related programs, macro packages, and fonts that are free software,
including support for many languages around the world.

%files

#-----------------------------------------------------------------------
%package	-n texlive-collection-basic
Summary:	TeX Live essential package
Group:		Publishing
Requires:	pstoedit
Requires:	texlive
Requires(post):	texlive
Conflicts:	texlive-texmf < %{version}
Conflicts:	texlive-dist < %{version}

%description	-n texlive-collection-basic
This package installs the essential TeX Live distribution packages.  They
should be sufficient for most users of TeX or TeX-related programs.

%files		-n texlive-collection-basic -f %{SOURCE9}
%{texmfbindir}/*
%{_datadir}/X11/app-defaults/XDvi*
%{_infodir}/*
%{_mandir}/man1/*
%{_mandir}/man5/*
%{texmfdistdir}/chktex
%if %{enable_asymptote}
%{texmfdistdir}/asymptote
%doc %{texmfdistdir}/doc/asymptote
%endif
%{texmfdistdir}/dvipdfmx
%{texmfdistdir}/hbf2gf
%{texmfdistdir}/LICENSE.TL
%{texmfdistdir}/texconfig
%{texmfdistdir}/texdoctk
%{texmfdistdir}/tlpkg
%{texmfdistdir}/ttf2pk
%{texmfdistdir}/xdvi
%if %{enable_xindy}
%{texmfdistdir}/xindy
%doc %{texmfdistdir}/doc/xindy
%endif
%{texmfdistdir}/bibtex
%{texmfdistdir}/dvips
%{texmfdistdir}/makeindex
%{texmfdistdir}/metafont
%{texmfdistdir}/metapost
%{texmfdistdir}/mft
%{texmfdistdir}/omega
%{texmfdistdir}/pbibtex
%{texmfdistdir}/scripts
%{texmfdistdir}/web2c
%if !%{with_system_tex4ht}
%{texmfdistdir}/tex4ht
%{_javadir}/tex4ht.jar
%endif
%{texmfdistdir}/texdoc
%dir %{texmflocaldir}
%ghost %{texmfdistdir}/ls-R
%ghost %{texmflocaldir}/ls-R

#context
%exclude %{texmfbindir}/context
%exclude %{texmfbindir}/contextjit
%exclude %{texmfbindir}/luatools
%exclude %{texmfbindir}/mptopdf
%exclude %{texmfbindir}/mtxrun
%exclude %{texmfbindir}/mtxrunjit
%exclude %{texmfbindir}/texexec
%exclude %{texmfbindir}/texmfstart
%exclude %{texmfdistdir}/bibtex/bst/context
%exclude %{texmfdistdir}/scripts/context
%exclude %{texmfdistdir}/tex/generic/context
%exclude %{texmfdistdir}/fonts/map/pdftex/context
%exclude %{texmfdistdir}/metapost/context

%post -n texlive-collection-basic
cp %{texmfdistdir}/web2c/updmap-collection-basic.cfg %{texmfdistdir}/web2c/updmap.cfg
%{_bindir}/texhash > /dev/null 2>&1
%{_bindir}/updmap-sys --syncwithtrees --force > /dev/null 2>&1
%{_bindir}/fmtutil-sys --no-strict --all > /dev/null 2>&1


#-----------------------------------------------------------------------
%package	-n texlive-dist
Summary:	TeX Live distribution package
Group:		Publishing
Requires:	texlive-texmf >= %{version}-%{release}
Requires(post):	texlive-collection-basic = %{version}
#Requires(postun):	texlive-collection-basic
Requires(post):	texlive
Requires(postun):	texlive
Conflicts:	texlive-texmf < 20120701-5

%description -n texlive-dist
This package brings the main TeX Live distribution packages (fonts and
TeX-related libraries) that are missing from the texlive-basic package.

%files		-n texlive-dist -f excludes
%{texmfdistdir}/psutils/paper.cfg
%{texmfdistdir}/fonts/afm/*
%{texmfdistdir}/fonts/cid
%{texmfdistdir}/fonts/cmap/*
%{texmfdistdir}/fonts/enc/*
%{texmfdistdir}/fonts/map/*
%{texmfdistdir}/fonts/misc
%{texmfdistdir}/fonts/ofm
%{texmfdistdir}/fonts/opentype/*
%{texmfdistdir}/fonts/ovf
%{texmfdistdir}/fonts/ovp
%{texmfdistdir}/fonts/sfd
%{texmfdistdir}/fonts/pk/ljfour/public/*
%{texmfdistdir}/fonts/tfm/*
%{texmfdistdir}/fonts/truetype/*
%{texmfdistdir}/fonts/type1/*
%{texmfdistdir}/fonts/vf/*
%{texmfdistdir}/tex/*

#context
%exclude %{texmfdistdir}/fonts/afm/hoekwater/context
%exclude %{texmfdistdir}/fonts/enc/dvips/context
%exclude %{texmfdistdir}/fonts/map/dvips/context
%exclude %{texmfdistdir}/fonts/map/luatex/context
%exclude %{texmfdistdir}/fonts/tfm/hoekwater/context
%exclude %{texmfdistdir}/fonts/type1/hoekwater/context
%exclude %{texmfdistdir}/tex/context
%exclude %{texmfdistdir}/tex/generic/context
%exclude %{texmfdistdir}/tex/latex/context
%exclude %{texmfdistdir}/fonts/misc/xetex/fontmapping/context

# xypic
%exclude %{texmfdistdir}/dvips/xypic
%exclude %{texmfdistdir}/fonts/afm/public/xypic
%exclude %{texmfdistdir}/fonts/enc/dvips/xypic
%exclude %{texmfdistdir}/fonts/map/dvips/xypic
%exclude %{texmfdistdir}/fonts/tfm/public/xypic
%exclude %{texmfdistdir}/fonts/type1/public/xypic
%exclude %{texmfdistdir}/tex/generic/xypic

# xetexconfig
%exclude %{texmfdistdir}/tex/xelatex/xetexconfig

%post -n texlive-dist
cp %{texmfdistdir}/web2c/updmap-dist.cfg %{texmfdistdir}/web2c/updmap.cfg
%{_bindir}/texhash > /dev/null 2>&1
%{_bindir}/updmap-sys --syncwithtrees --force > /dev/null 2>&1
%{_bindir}/fmtutil-sys --no-strict --all > /dev/null 2>&1

%postun -n texlive-dist
cp %{texmfdistdir}/web2c/updmap-collection-basic.cfg %{texmfdistdir}/web2c/updmap.cfg
%{_bindir}/texhash > /dev/null 2>&1
%{_bindir}/updmap-sys --syncwithtrees --force > /dev/null 2>&1
%{_bindir}/fmtutil-sys --no-strict --all > /dev/null 2>&1


#-----------------------------------------------------------------------
%package	-n texlive-context
Summary:	Tex Live ConTeXt Package
Group:		Publishing
Requires:	texlive-texmf >= %{version}-%{release}
Requires:	ruby

%description	-n texlive-context
This is the ConTeXt package of the TeX Live distribution. Use this only
if you rely on context for building tex documents.

%files		-n texlive-context
%{texmfdistdir}/fonts/afm/hoekwater/context
%{texmfdistdir}/fonts/enc/dvips/context
%{texmfdistdir}/fonts/map/dvips/context
%{texmfdistdir}/fonts/map/luatex/context
%{texmfdistdir}/fonts/map/pdftex/context
%{texmfdistdir}/fonts/misc/xetex/fontmapping/context
%{texmfdistdir}/fonts/tfm/hoekwater/context
%{texmfdistdir}/fonts/type1/hoekwater/context
%{texmfbindir}/context
%{texmfbindir}/contextjit
%{texmfbindir}/luatools
%{texmfbindir}/mptopdf
%{texmfbindir}/mtxrun
%{texmfbindir}/mtxrunjit
%{texmfbindir}/texexec
%{texmfbindir}/texmfstart
%{texmfdistdir}/context
%{texmfdistdir}/scripts/context
%{texmfdistdir}/tex/context
%{texmfdistdir}/tex/latex/context
%{texmfdistdir}/bibtex/bst/context
%{texmfdistdir}/tex/generic/context
%{texmfdistdir}/metapost/context
%exclude %{texmfdistdir}/scripts/context/stubs/source
%exclude %{texmfdistdir}/scripts/context/stubs/setup
%exclude %{texmfdistdir}/scripts/context/stubs/install
%exclude %{texmfdistdir}/scripts/context/stubs/mswin
%exclude %{texmfdistdir}/scripts/context/stubs/win64

%post -n texlive-context
cp %{texmfdistdir}/web2c/updmap-dist.cfg %{texmfdistdir}/web2c/updmap.cfg
%{_bindir}/texhash > /dev/null 2>&1
%{_bindir}/updmap-sys --syncwithtrees --force > /dev/null 2>&1
%{_bindir}/fmtutil-sys --no-strict --all > /dev/null 2>&1
%{_bindir}/mtxrun --generate > /dev/null 2>&1

%postun -n texlive-context
cp %{texmfdistdir}/web2c/updmap-collection-basic.cfg %{texmfdistdir}/web2c/updmap.cfg
%{_bindir}/texhash > /dev/null 2>&1
%{_bindir}/updmap-sys --syncwithtrees --force > /dev/null 2>&1
%{_bindir}/fmtutil-sys --no-strict --all > /dev/null 2>&1


#-----------------------------------------------------------------------
%package	-n texlive-doc
Summary:	Tex Live documentation
Group:		Publishing
Obsoletes:	tetex-doc <= 3.1
Requires:	texlive-texmf >= %{version}-%{release}

%description	-n texlive-doc
TeX Live is an easy way to get up and running with the TeX document
production system. It provides a comprehensive TeX system. It includes
all the major TeX-related programs, macro packages, and fonts that are
free software, including support for many languages around the world.

%files		-n texlive-doc
#{texmfdistdir}/doc/*
%if %{enable_asymptote}
%exclude %{texmfdistdir}/doc/asymptote
%endif
%if %{enable_xindy}
%exclude %{texmfdistdir}/doc/xindy
%endif
%{texmfdistdir}/doc

#-----------------------------------------------------------------------
%package	-n texlive-fontsextra
Summary:	TeX Live extra fonts
Group:		Publishing
Requires:	texlive-texmf = %{version}
Requires(post):	texlive-dist = %{version}-%{release}
Requires(postun):	texlive

%description	-n texlive-fontsextra
TeX Live is an easy way to get up and running with the TeX document
production system. It provides a comprehensive TeX system. It includes
all the major TeX-related programs, macro packages, and fonts that are
free software, including support for many languages around the world.

%files		-n texlive-fontsextra -f %{SOURCE10}

%post		-n texlive-fontsextra
cp %{texmfdistdir}/web2c/updmap-fontsextra.cfg %{texmfdistdir}/web2c/updmap.cfg
%{_bindir}/texhash > /dev/null 2>&1
%{_bindir}/updmap-sys --syncwithtrees --force > /dev/null 2>&1
%{_bindir}/fmtutil-sys --no-strict --all > /dev/null 2>&1

%postun		-n texlive-fontsextra
cp %{texmfdistdir}/web2c/updmap-dist.cfg %{texmfdistdir}/web2c/updmap.cfg
%{_bindir}/texhash > /dev/null 2>&1
%{_bindir}/updmap-sys --syncwithtrees --force > /dev/null 2>&1
%{_bindir}/fmtutil-sys --no-strict --all > /dev/null 2>&1

#-----------------------------------------------------------------------
%package	-n texlive-fonts-asian
Summary:	TeX Live extra fonts for Asian languages
Group:		Publishing
Requires:	texlive-texmf = %{version}
Requires(post):	texlive-dist = %{version}-%{release}
Requires(postun):	texlive

%description	-n texlive-fonts-asian
TeX Live is an easy way to get up and running with the TeX document
production system. It provides a comprehensive TeX system. It includes
all the major TeX-related programs, macro packages, and fonts that are
free software, including support for many languages around the world.

%files		-n texlive-fonts-asian -f %{SOURCE11}

%post		-n texlive-fonts-asian
cp %{texmfdistdir}/web2c/updmap-fontsextra.cfg %{texmfdistdir}/web2c/updmap.cfg
%{_bindir}/texhash > /dev/null 2>&1
%{_bindir}/updmap-sys --syncwithtrees --force > /dev/null 2>&1
%{_bindir}/fmtutil-sys --no-strict --all > /dev/null 2>&1

%postun		-n texlive-fonts-asian
cp %{texmfdistdir}/web2c/updmap-dist.cfg %{texmfdistdir}/web2c/updmap.cfg
%{_bindir}/texhash > /dev/null 2>&1
%{_bindir}/updmap-sys --syncwithtrees --force > /dev/null 2>&1
%{_bindir}/fmtutil-sys --no-strict --all > /dev/null 2>&1

#-----------------------------------------------------------------------
%package	-n texlive-fonts-sources
Summary:	TeX Live font sources
Group:		Publishing
Requires:	texlive = %{version}
Requires(postun):	texlive

%description	-n texlive-fonts-sources
This package contains the source (mf) files for all fonts. This is usually only
needed if you build applications.

%files		-n texlive-fonts-sources -f %{SOURCE12}

%post		-n texlive-fonts-sources
%{_bindir}/texhash > /dev/null 2>&1

%postun		-n texlive-fonts-sources
%{_bindir}/texhash > /dev/null 2>&1

#-----------------------------------------------------------------------

%prep
%setup -q -n texlive-%{version}-texmf

#remove source, as we don't need it and it saves some space
rm -rf texmf-dist/source
#remove all windows bat files
find . -name \*.bat -exec rm -f {} \;

%patch4 -p1
%patch5 -p1
%patch6 -p1

perl -pi -e 's%^(TEXMFMAIN\s+= ).*%$1%{texmfdistdir}%;'		  \
	 -e 's%^(TEXMFDIST\s+= ).*%$1%{texmfdistdir}%;'		  \
	 -e 's%^(TEXMF\s+= .*)\}$%$1,%{texmfdir}\}%;'			  \
	 -e 's%^(TEXMFLOCAL\s+= ).*%$1%{texmflocaldir}%;'		  \
	 -e 's%^(TEXMFSYSVAR\s+= ).*%$1%{texmfvardir}%;'		  \
	 -e 's%^(TEXMFSYSCONFIG\s+= ).*%$1%{texmfconfdir}%;'		  \
	 -e 's%^(TEXMFHOME\s+= ).*%$1\$HOME/texmf%;'			  \
	 -e 's%^(TEXMFVAR\s+= ).*%$1\$HOME/.texlive%{relYear}/texmf-var%;'	  \
	 -e 's%^(TEXMFCONFIG\s+= ).*%$1\$HOME/.texlive%{relYear}/texmf-config%;'\
	 -e 's%^(OSFONTDIR\s+= ).*%$1%{_datadir}/fonts%;'		  \
	texmf-dist/web2c/texmf.cnf

perl -pi -e 's%^(\s*TEXMFMAIN\s+=\s+").*%$1%{texmfdistdir}",%;'				\
	 -e 's%\bTEXMFCONTEXT\b%TEXMFDIST%g;'						\
	 -e 's%^(\s*TEXMFDIST\s+=\s+).*%$1"%{texmfdistdir}",%;'				\
	 -e 's%^(TEXMF\s+= .*)\}$%$1,%{texmfdir}\}%;'					\
	 -e 's%^(\s*TEXMFLOCAL\s+=\s+).*%$1"%{texmflocaldir}",%;'			\
	 -e 's%^(\s*TEXMFSYSVAR\s+=\s+).*%$1"%{texmfvardir}",%;'			\
	 -e 's%^(\s*TEXMFSYSCONFIG\s+=\s+).*%$1"%{texmfconfdir}",%;'			\
	 -e 's%^(\s*TEXMFHOME\s+=\s+").*%$1\$HOME/texmf",%;'				\
	 -e 's%^(\s*TEXMFVAR\s+=\s+").*%$1\$HOME/.texlive%{relYear}/texmf-var",%;'		\
	 -e 's%^(\s*TEXMFCONFIG\s+=\s+").*%$1\$HOME/.texlive%{relYear}/texmf-config",%;'	\
	 -e 's%^(\s*FONTCONFIG_PATH\s+=\s+").*%$1%{_sysconfdir}/fonts",%;'		\
	 -e 's|^local texmflocal.*$||;'							\
	 -e 's|^texmflocal.*$||;'							\
	texmf-dist/web2c/texmfcnf.lua

perl -pi -e 's%^# (viewer_pdf = )xpdf.*%$1xdg-open%;'	\
	texmf-dist/texdoc/texdoc.cnf

# fix python shebangs
%{_bindir}/pathfix.py -pni "%{__python3} %{py3_shbang_opts}" \
	. \
	texmf-dist/scripts/pdfbook2/pdfbook2 \
	texmf-dist/scripts/de-macro/de-macro \


#-----------------------------------------------------------------------
%build
cat %{SOURCE9} %{SOURCE10} %{SOURCE11} %{SOURCE12} > excludes
perl -pi -e 's%\%\{texmfdistdir\}%\%exclude \%\{texmfdistdir\}%g;' excludes

#-----------------------------------------------------------------------
%install
mkdir -p %{buildroot}%{texmfdistdir}
cp -la texmf-dist/* %{buildroot}%{texmfdistdir}

mkdir -p %{buildroot}%{texmfbindir}

pushd %{buildroot}%{texmfbindir}
	ln -sf %{texmfdistdir}/scripts/a2ping/a2ping.pl				a2ping
	ln -sf %{texmfdistdir}/scripts/pfarrei/a5toa4.tlu			a5toa4
	ln -sf %{texmfdistdir}/scripts/adhocfilelist/adhocfilelist.sh		adhocfilelist
	ln -sf %{texmfdistdir}/scripts/fontools/afm2afm				afm2afm
	ln -sf %{texmfdistdir}/scripts/texlive-extra/allcm.sh			allcm
	ln -sf %{texmfdistdir}/scripts/texlive-extra/allcm.sh			allec
	ln -sf %{texmfdistdir}/scripts/texlive-extra/allneeded.sh		allneeded
	ln -sf %{texmfdistdir}/scripts/arara/arara.sh				arara
	ln -sf %{texmfdistdir}/scripts/bundledoc/arlatex			arlatex
	ln -sf %{texmfdistdir}/scripts/authorindex/authorindex			authorindex
	ln -sf %{texmfdistdir}/scripts/fontools/autoinst			autoinst
	ln -sf %{texmfdistdir}/scripts/crossrefware/bbl2bib.pl			bbl2bib
	ln -sf %{texmfdistdir}/scripts/bib2gls/bib2gls.sh			bib2gls
	ln -sf %{texmfdistdir}/scripts/crossrefware/bibdoiadd.pl		bibdoiadd
	ln -sf %{texmfdistdir}/scripts/bibexport/bibexport.sh			bibexport
	ln -sf %{texmfdistdir}/scripts/crossrefware/bibmradd.pl			bibmradd
	ln -sf %{texmfdistdir}/scripts/crossrefware/biburl2doi.pl		biburl2doi
	ln -sf %{texmfdistdir}/scripts/crossrefware/bibzbladd.pl		bibzbladd
	ln -sf %{texmfdistdir}/scripts/bundledoc/bundledoc			bundledoc
	ln -sf %{texmfdistdir}/scripts/cachepic/cachepic.tlu			cachepic
	ln -sf %{texmfdistdir}/scripts/checkcites/checkcites.lua		checkcites
	ln -sf %{texmfdistdir}/scripts/checklistings/checklistings.sh		checklistings
	ln -sf %{texmfdistdir}/scripts/chklref/chklref.pl			chklref
	ln -sf %{texmfdistdir}/scripts/citation-style-language/citeproc.lua	citeproc
	ln -sf %{texmfdistdir}/scripts/cjk-gs-integrate/cjk-gs-integrate.pl	cjk-gs-integrate
	ln -sf %{texmfdistdir}/scripts/cluttex/cluttex.lua			cluttex
	ln -sf %{texmfdistdir}/scripts/context/stubs/unix/context		context
	ln -sf %{texmfdistdir}/scripts/context/stubs/unix/contextjit		contextjit
	ln -sf %{texmfdistdir}/scripts/convbkmk/convbkmk.rb			convbkmk
	ln -sf %{texmfdistdir}/scripts/bib2gls/convertgls2bib.sh		convertgls2bib
	ln -sf %{texmfdistdir}/scripts/ctanbib/ctanbib				ctanbib
	ln -sf %{texmfdistdir}/scripts/ctanify/ctanify				ctanify
	ln -sf %{texmfdistdir}/scripts/ctan-o-mat/ctan-o-mat.pl			ctan-o-mat
	ln -sf %{texmfdistdir}/scripts/ctanupload/ctanupload.pl			ctanupload
	ln -sf %{texmfdistdir}/scripts/de-macro/de-macro			de-macro
	ln -sf %{texmfdistdir}/scripts/pythontex/depythontex.py			depythontex
	ln -sf %{texmfdistdir}/scripts/diadia/diadia.lua			diadia
	ln -sf %{texmfdistdir}/scripts/dosepsbin/dosepsbin.pl			dosepsbin
	ln -sf %{texmfdistdir}/scripts/dtxgen/dtxgen				dtxgen
	ln -sf %{texmfdistdir}/scripts/texlive-extra/dvi2fax.sh			dvi2fax
	ln -sf %{texmfdistdir}/scripts/dviasm/dviasm.py				dviasm
	ln -sf %{texmfdistdir}/scripts/dviinfox/dviinfox.pl			dviinfox
	ln -sf %{_bindir}/luatex						dvilualatex-dev
	ln -sf %{texmfdistdir}/scripts/texlive-extra/dvired.sh			dvired
	ln -sf %{texmfdistdir}/scripts/texlive-extra/e2pall.pl			e2pall
	ln -sf %{texmfdistdir}/scripts/epspdf/epspdf.tlu			epspdf
	ln -sf %{texmfdistdir}/scripts/epspdf/epspdftk.tcl			epspdftk
	ln -sf %{texmfdistdir}/scripts/epstopdf/epstopdf.pl			epstopdf
	ln -sf %{texmfdistdir}/scripts/exceltex/exceltex			exceltex
	ln -sf %{texmfdistdir}/scripts/fig4latex/fig4latex			fig4latex
	ln -sf %{texmfdistdir}/scripts/findhyph/findhyph			findhyph
	ln -sf %{texmfdistdir}/scripts/texlive/fmtutil.pl			fmtutil
	ln -sf %{texmfdistdir}/scripts/texlive/fmtutil-sys.sh			fmtutil-sys
	ln -sf %{texmfdistdir}/scripts/texlive/fmtutil-user.sh			fmtutil-user
	ln -sf %{texmfdistdir}/scripts/texlive-extra/fontinst.sh		fontinst
	ln -sf %{texmfdistdir}/scripts/fragmaster/fragmaster.pl			fragmaster
	ln -sf %{texmfdistdir}/scripts/getmap/getmapdl.lua			getmapdl
%if !%{with_system_tex4ht}
	ln -sf %{texmfdistdir}/scripts/tex4ht/ht.sh				ht
	ln -sf %{texmfdistdir}/scripts/tex4ht/htcontext.sh			htcontext
	ln -sf %{texmfdistdir}/scripts/tex4ht/htlatex.sh			htlatex
	ln -sf %{texmfdistdir}/scripts/tex4ht/htmex.sh				htmex
	ln -sf %{texmfdistdir}/scripts/tex4ht/httex.sh				httex
	ln -sf %{texmfdistdir}/scripts/tex4ht/httexi.sh				httexi
	ln -sf %{texmfdistdir}/scripts/tex4ht/htxelatex.sh			htxelatex
	ln -sf %{texmfdistdir}/scripts/tex4ht/htxetex.sh			htxetex
	ln -sf %{texmfdistdir}/scripts/make4ht/make4ht				make4ht
	ln -sf %{texmfdistdir}/scripts/tex4ht/mk4ht.pl				mk4ht
	ln -sf %{texmfdistdir}/scripts/tex4ebook/tex4ebook			tex4ebook
%endif
	ln -sf %{texmfdistdir}/scripts/installfont/installfont-tl		installfont-tl
	ln -sf %{texmfdistdir}/scripts/jfmutil/jfmutil.pl			jfmutil
	ln -sf %{texmfdistdir}/scripts/ptex-fontmaps/kanji-config-updmap.pl	kanji-config-updmap
	ln -sf %{texmfdistdir}/scripts/ptex-fontmaps/kanji-config-updmap-sys.sh	kanji-config-updmap-sys
	ln -sf %{texmfdistdir}/scripts/ptex-fontmaps/kanji-config-updmap-user.sh kanji-config-updmap-user
	ln -sf %{texmfdistdir}/scripts/ptex-fontmaps/kanji-fontmap-creator.pl	kanji-fontmap-creator
	ln -sf %{texmfdistdir}/scripts/texlive-extra/kpsetool.sh		kpsepath
	ln -sf %{texmfdistdir}/scripts/texlive-extra/kpsetool.sh		kpsetool
	ln -sf %{texmfdistdir}/scripts/texlive-extra/kpsewhere.sh		kpsewhere
	ln -sf %{texmfdistdir}/scripts/texlive-extra/kpsetool.sh		kpsexpand
	ln -sf %{texmfdistdir}/scripts/l3build/l3build.lua			l3build
	ln -sf %{texmfdistdir}/scripts/latex2man/latex2man			latex2man
	ln -sf %{texmfdistdir}/scripts/texdef/texdef.pl				latexdef
	ln -sf %{texmfdistdir}/scripts/latexdiff/latexdiff.pl			latexdiff
	ln -sf %{texmfdistdir}/scripts/latexdiff/latexdiff-vc.pl		latexdiff-vc
	ln -sf %{texmfdistdir}/scripts/latexfileversion/latexfileversion	latexfileversion
	ln -sf %{texmfdistdir}/scripts/latexindent/latexindent.pl		latexindent
	ln -sf %{texmfdistdir}/scripts/latex-papersize/latex-papersize.py	latex-papersize
	ln -sf %{texmfdistdir}/scripts/latexmk/latexmk.pl			latexmk
	ln -sf %{texmfdistdir}/scripts/latexpand/latexpand			latexpand
	ln -sf %{texmfdistdir}/scripts/latexdiff/latexrevise.pl			latexrevise
	ln -sf %{_bindir}/pdftex						latex-dev
	ln -sf %{texmfdistdir}/scripts/listbib/listbib				listbib
	ln -sf %{texmfdistdir}/scripts/listings-ext/listings-ext.sh		listings-ext.sh
	ln -sf %{_bindir}/tex							lollipop
	ln -sf %{texmfdistdir}/scripts/crossrefware/ltx2crossrefxml.pl		ltx2crossrefxml
	ln -sf %{texmfdistdir}/scripts/ltxfileinfo/ltxfileinfo			ltxfileinfo
	ln -sf %{texmfdistdir}/scripts/ltximg/ltximg.pl				ltximg
	ln -sf %{_bindir}/luatex						luacsplain
	ln -sf %{_bindir}/luahbtex						lualatex-dev
	ln -sf %{texmfdistdir}/scripts/luaotfload/luaotfload-tool.lua		luaotfload-tool
	ln -sf %{texmfdistdir}/scripts/context/stubs/unix/luatools		luatools
	ln -sf %{texmfdistdir}/scripts/lwarp/lwarpmk.lua			lwarpmk
	ln -sf %{texmfdistdir}/scripts/makedtx/makedtx.pl			makedtx
	ln -sf %{texmfdistdir}/scripts/glossaries/makeglossaries		makeglossaries
	ln -sf %{texmfdistdir}/scripts/match_parens/match_parens		match_parens
	ln -sf %{texmfdistdir}/scripts/mathspic/mathspic.pl			mathspic
	ln -sf %{texmfdistdir}/scripts/mf2pt1/mf2pt1.pl				mf2pt1
	ln -sf %{texmfdistdir}/scripts/mkgrkindex/mkgrkindex			mkgrkindex
	ln -sf %{texmfdistdir}/scripts/mkjobtexmf/mkjobtexmf.pl			mkjobtexmf
	ln -sf %{texmfdistdir}/scripts/mkpic/mkpic				mkpic
	ln -sf %{texmfdistdir}/scripts/accfonts/mkt1font			mkt1font
	ln -sf %{texmfdistdir}/scripts/texlive/fmtutil.pl			mktexfmt
	ln -sf %{texmfdistdir}/scripts/texlive/mktexlsr				mktexlsr
	ln -sf %{texmfdistdir}/scripts/texlive/mktexmf				mktexmf
	ln -sf %{texmfdistdir}/scripts/texlive/mktexpk				mktexpk
	ln -sf %{texmfdistdir}/scripts/texlive/mktextfm				mktextfm
	ln -sf %{texmfdistdir}/scripts/context/perl/mptopdf.pl			mptopdf
	ln -sf %{texmfdistdir}/scripts/context/stubs/unix/mtxrun		mtxrun
	ln -sf %{texmfdistdir}/scripts/context/stubs/unix/mtxrunjit		mtxrunjit
	ln -sf %{texmfdistdir}/scripts/multibibliography/multibibliography.pl	multibibliography
	ln -sf %{texmfdistdir}/scripts/musixtex/musixflx.lua			musixflx
	ln -sf %{texmfdistdir}/scripts/musixtex/musixtex.lua			musixtex
	ln -sf %{_bindir}/luatex						optex
	ln -sf %{texmfdistdir}/scripts/fontools/ot2kpx				ot2kpx
	ln -sf %{_bindir}/otfinfo-texlive					otfinfo
	ln -sf %{texmfdistdir}/scripts/clojure-pamphlet/pamphletangler		pamphletangler
	ln -sf %{texmfdistdir}/scripts/pax/pdfannotextractor.pl			pdfannotextractor
	ln -sf %{texmfdistdir}/scripts/attachfile2/pdfatfi.pl			pdfatfi
	ln -sf %{texmfdistdir}/scripts/pdfbook2/pdfbook2			pdfbook2
	ln -sf %{texmfdistdir}/scripts/pdfcrop/pdfcrop.pl			pdfcrop
	ln -sf %{texmfdistdir}/scripts/pdfjam/pdfjam				pdfjam
	ln -sf %{texmfdistdir}/scripts/pdflatexpicscale/pdflatexpicscale.pl	pdflatexpicscale
	ln -sf %{_bindir}/pdftex						pdflatex-dev
	ln -sf %{texmfdistdir}/scripts/pdftex-quiet/pdftex-quiet		pdftex-quiet
	ln -sf %{texmfdistdir}/scripts/pdfxup/pdfxup				pdfxup
	ln -sf %{texmfdistdir}/scripts/pedigree-perl/pedigree.pl		pedigree
	ln -sf %{texmfdistdir}/scripts/perltex/perltex.pl			perltex
	ln -sf %{texmfdistdir}/scripts/pfarrei/pfarrei.tlu			pfarrei
	ln -sf %{_bindir}/eptex							platex-dev
	ln -sf %{texmfdistdir}/scripts/pkfix/pkfix.pl				pkfix
	ln -sf %{texmfdistdir}/scripts/pkfix-helper/pkfix-helper		pkfix-helper
	ln -sf %{texmfdistdir}/scripts/pmxchords/pmxchords.lua			pmxchords
	ln -sf %{texmfdistdir}/scripts/petri-nets/pn2pdf			pn2pdf
	ln -sf %{texmfdistdir}/scripts/texlive-extra/ps2frag.sh			ps2frag
	ln -sf %{texmfdistdir}/scripts/pst-pdf/ps4pdf				ps4pdf
	ln -sf %{texmfdistdir}/scripts/texlive-extra/pslatex.sh			pslatex
	ln -sf %{texmfdistdir}/scripts/pst2pdf/pst2pdf.pl			pst2pdf
	ln -sf %{texmfdistdir}/scripts/ptex2pdf/ptex2pdf.lua			ptex2pdf
	ln -sf %{texmfdistdir}/scripts/purifyeps/purifyeps			purifyeps
	ln -sf %{texmfdistdir}/scripts/pygmentex/pygmentex.py			pygmentex
	ln -sf %{texmfdistdir}/scripts/pythontex/pythontex.py			pythontex
	ln -sf %{_bindir}/epstopdf						repstopdf
	ln -sf %{_bindir}/pdfcrop						rpdfcrop
	ln -sf %{texmfdistdir}/scripts/rubik/rubikrotation.pl			rubikrotation
	ln -sf %{texmfdistdir}/scripts/texlive/rungs.tlu			rungs
	ln -sf %{texmfdistdir}/scripts/simpdftex/simpdftex			simpdftex
	ln -sf %{texmfdistdir}/scripts/splitindex/splitindex.pl			splitindex
	ln -sf %{texmfdistdir}/scripts/srcredact/srcredact.pl			srcredact
	ln -sf %{texmfdistdir}/scripts/sty2dtx/sty2dtx.pl			sty2dtx
	ln -sf %{texmfdistdir}/scripts/svn-multi/svn-multi.pl			svn-multi
	ln -sf %{texmfdistdir}/scripts/texlive-extra/texconfig.sh		texconfig
	ln -sf %{texmfdistdir}/scripts/texlive-extra/texconfig-dialog.sh	texconfig-dialog
	ln -sf %{texmfdistdir}/scripts/texlive-extra/texconfig-sys.sh		texconfig-sys
	ln -sf %{texmfdistdir}/scripts/texcount/texcount.pl			texcount
	ln -sf %{texmfdistdir}/scripts/texdef/texdef.pl				texdef
	ln -sf %{texmfdistdir}/scripts/texdiff/texdiff				texdiff
	ln -sf %{texmfdistdir}/scripts/texdirflatten/texdirflatten		texdirflatten
	ln -sf %{texmfdistdir}/scripts/texdoc/texdoc.tlu			texdoc
	ln -sf %{texmfdistdir}/scripts/texdoctk/texdoctk.pl			texdoctk
	ln -sf %{texmfdistdir}/scripts/context/stubs/unix/texexec		texexec
	ln -sf %{texmfdistdir}/scripts/texfot/texfot.pl				texfot
	ln -sf %{texmfdistdir}/scripts/texlive/mktexlsr				texhash
	ln -sf %{texmfdistdir}/scripts/texlive-extra/texlinks.sh		texlinks
	ln -sf %{texmfdistdir}/scripts/texliveonfly/texliveonfly.py		texliveonfly
	ln -sf %{texmfdistdir}/scripts/texloganalyser/texloganalyser		texloganalyser
	ln -sf %{texmfdistdir}/scripts/context/stubs/unix/texmfstart		texmfstart
	ln -sf %{texmfdistdir}/scripts/texosquery/texosquery.sh			texosquery
	ln -sf %{texmfdistdir}/scripts/texosquery/texosquery-jre5.sh		texosquery-jre5
	ln -sf %{texmfdistdir}/scripts/texosquery/texosquery-jre8.sh		texosquery-jre8
	ln -sf %{texmfdistdir}/scripts/thumbpdf/thumbpdf.pl			thumbpdf
	ln -sf %{texmfdistdir}/scripts/typeoutfileinfo/typeoutfileinfo.sh	typeoutfileinfo
	ln -sf %{texmfdistdir}/scripts/ulqda/ulqda.pl				ulqda
	ln -sf %{texmfdistdir}/scripts/texlive/updmap.pl			updmap
	ln -sf %{texmfdistdir}/scripts/texlive/updmap-sys.sh			updmap-sys
	ln -sf %{texmfdistdir}/scripts/texlive/updmap-user.sh			updmap-user
	ln -sf %{_bindir}/euptex						uplatex
	ln -sf %{_bindir}/euptex						uplatex-dev
	ln -sf %{texmfdistdir}/scripts/urlbst/urlbst				urlbst
	ln -sf %{texmfdistdir}/scripts/vpe/vpe.pl				vpe
	ln -sf %{texmfdistdir}/scripts/accfonts/vpl2ovp				vpl2ovp
	ln -sf %{texmfdistdir}/scripts/accfonts/vpl2vpl				vpl2vpl
	ln -sf %{_bindir}/xetex							xelatex-dev
	ln -sf %{texmfdistdir}/scripts/xindex/xindex.lua			xindex
	ln -sf %{texmfdistdir}/scripts/yplan/yplan				yplan
	ln -sf %{texmfdistdir}/scripts/wordcount/wordcount.sh			wordcount
popd

    (cd  %{buildroot}%{texmfdistdir}/tex/generic/config ; ln -sf ../tex-ini-files/pdftexconfig.tex .)

	mkdir -p %{buildroot}%{_datadir}/X11/app-defaults
	pushd %{buildroot}%{_datadir}/X11/app-defaults
	ln -sf %{texmfdistdir}/xdvi/XDvi XDvi
	cp %{SOURCE2} %{buildroot}%{_datadir}/X11/app-defaults
    popd

pushd %{buildroot}%{texmfdistdir}
%if !%{enable_asymptote}
    rm -fr asymptote doc/asymptote doc/info/asy* tex/latex/asymptote
%endif
%if !%{enable_xindy}
    rm -fr xindy doc/xindy scripts/xindy
%endif
    rm -fr dvipdfm
    perl -pi -e 's%/usr/local%/usr%;' dvipdfmx/dvipdfmx.cfg
    rm -f ls-R README
    rm -fr doc/gzip
    cp -f %{SOURCE3} .

    find doc/man \( -name Makefile -o -name \*.pdf \) -exec rm -f {} \;

# with_system_psutils (avoid man page conflicts)
%if %{with_system_psutils}
    rm -f doc/man/man1/{epsffit,extractres,fixdlsrps,fixfmps,fixmacps,fixpsditps,fixpspps,fixscribeps,fixtpps,fixwfwps,fixwpps,fixwwps,getafm,includeres,psbook,psmerge,psnup,psresize,psselect,pstops,psjoin,psutils}.1
%endif

    mkdir -p %{buildroot}%{_mandir}
    mv -f doc/man/* %{buildroot}%{_mandir}
    mkdir -p %{buildroot}%{_infodir}
    mv -f doc/info/*.info %{buildroot}%{_infodir}
popd

pushd %{buildroot}%{texmfdistdir}
%if %{with_system_tex4ht}
    rm -fr tex4ht
%endif
    rm -f ls-R README
    # .in files in documentation confuse find-provides
    rm -f doc/bibtex/urlbst/*.in
popd

%if !%{with_system_tex4ht}
	mkdir %{buildroot}%{_javadir}
	pushd %{buildroot}%{_javadir}
	    ln -sf %{texmfdistdir}/tex4ht/bin/tex4ht.jar tex4ht.jar
	popd
%endif
pushd %{buildroot}%{texmfdistdir}/doc/fonts
 find . -name \*.pdf -exec rm -rf {} \;
 rm -rf gnu-freefont/tools
popd


tar zxf %{SOURCE4}
mkdir -p %{buildroot}%{texmfdistdir}/tlpkg
cp -la install-tl-*/tlpkg/TeXLive %{buildroot}%{texmfdistdir}/tlpkg
cp -la install-tl-*/tlpkg/installer %{buildroot}%{texmfdistdir}/tlpkg
rm -rf %{buildroot}%{texmfdistdir}/tlpkg/installer/wget
rm -rf %{buildroot}%{texmfdistdir}/tlpkg/installer/xz


perl -pi -e 's|-var-value=TEXMFROOT|-var-value=TEXMFMAIN|g;'			\
    %{buildroot}%{texmfdistdir}/scripts/texlive/updmap.pl

mkdir -p %{buildroot}%{texmflocaldir}

touch %{buildroot}%{texmfdistdir}/ls-R
touch %{buildroot}%{texmflocaldir}/ls-R

pushd %{buildroot}%{texmfdistdir}
cp %{_sourcedir}/updmap-*.cfg web2c/

# fix executable permission
chmod 755 \
	%{buildroot}%{texmfdistdir}/scripts/attachfile2/pdfatfi.pl \
	%{buildroot}%{texmfdistdir}/scripts/pst2pdf/pst2pdf.pl

%if %{draft}
export QA_CHECK_RPATHS=0
%endif
#-----------------------------------------------------------------------