SUMMARY="A comprehensive TeX system - texmf tree"
DESCRIPTION="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."
HOMEPAGE="http://tug.org/texlive/"
COPYRIGHT="1996 by collaboration between the TeX user groups."
LICENSE="GNU GPL v2"
REVISION="1"
fullVersion=20210325
SOURCE_URI="ftp://tug.org/historic/systems/texlive/$portVersion/install-tl-unx.tar.gz"
SOURCE_URI_2="ftp://tug.org/historic/systems/texlive/$portVersion/texlive-$fullVersion-texmf.tar.xz"
SOURCE_URI_3="ftp://tug.org/historic/systems/texlive/$portVersion/texlive-$fullVersion-extra.tar.xz"
CHECKSUM_SHA256="74eac0855e1e40c8db4f28b24ef354bd7263c1f76031bdc02b52156b572b7a1d"
CHECKSUM_SHA256_2="ff12d436c23e99fb30aad55924266104356847eb0238c193e839c150d9670f1c"
CHECKSUM_SHA256_3="46a3f385d0b30893eec6b39352135d2929ee19a0a81df2441bfcaa9f6c78339c"
SOURCE_DIR="install-tl-20210324"
SOURCE_DIR_2="texlive-$fullVersion-texmf"
SOURCE_DIR_3="texlive-$fullVersion-extra"
ADDITIONAL_FILES="
	texlive.profile
	texlive_postinstall.sh
	"

POST_INSTALL_SCRIPTS="$relativePostInstallDir/texlive_postinstall.sh"
ARCHITECTURES="?any"
DISABLE_SOURCE_PACKAGE="yes"

PROVIDES="
	texlive = $portVersion
	"
REQUIRES="
	haiku
	# this is a placeholder for the main texlive_core package
	cmd:kpsewhich
	"

PROVIDES_doc="
	texlive_doc = $portVersion
	"
REQUIRES_doc="
	cmd:kpsewhich
	"

BUILD_REQUIRES="
	haiku_devel
	cmd:kpsewhich
	"
BUILD_PREREQUIRES="
	cmd:perl
	"

GLOBAL_WRITABLE_FILES="
	settings/texlive/ls-R auto-merge
	var/texlive/ls-R auto-merge
	var/texlive/tex/generic/config/language.dat auto-merge
	var/texlive/tex/generic/config/language.dat.lua auto-merge
	var/texlive/tex/generic/config/language.def auto-merge
	var/texlive/web2c/aleph/aleph.fmt
	var/texlive/web2c/aleph/aleph.log
	var/texlive/web2c/eptex/eptex.fmt
	var/texlive/web2c/eptex/eptex.log
	var/texlive/web2c/eptex/platex-dev.fmt
	var/texlive/web2c/eptex/platex-dev.log
	var/texlive/web2c/eptex/platex.fmt
	var/texlive/web2c/eptex/platex.log
	var/texlive/web2c/euptex/euptex.fmt
	var/texlive/web2c/euptex/euptex.log
	var/texlive/web2c/euptex/uplatex-dev.fmt
	var/texlive/web2c/euptex/uplatex-dev.log
	var/texlive/web2c/euptex/uplatex.fmt
	var/texlive/web2c/euptex/uplatex.log
	var/texlive/web2c/luahbtex/luahbtex.fmt
	var/texlive/web2c/luahbtex/luahbtex.log
	var/texlive/web2c/luahbtex/lualatex-dev.fmt
	var/texlive/web2c/luahbtex/lualatex-dev.log
	var/texlive/web2c/luahbtex/lualatex.fmt
	var/texlive/web2c/luahbtex/lualatex.log
	var/texlive/web2c/luajithbtex/luajithbtex.fmt
	var/texlive/web2c/luajithbtex/luajithbtex.log
	var/texlive/web2c/luajittex/luajittex.fmt
	var/texlive/web2c/luajittex/luajittex.log
	var/texlive/web2c/luatex/dvilualatex-dev.fmt
	var/texlive/web2c/luatex/dvilualatex-dev.log
	var/texlive/web2c/luatex/dvilualatex.fmt
	var/texlive/web2c/luatex/dvilualatex.log
	var/texlive/web2c/luatex/dviluatex.fmt
	var/texlive/web2c/luatex/dviluatex.log
	var/texlive/web2c/luatex/luacsplain.fmt
	var/texlive/web2c/luatex/luacsplain.log
	var/texlive/web2c/luatex/luatex.fmt
	var/texlive/web2c/luatex/luatex.log
	var/texlive/web2c/luatex/optex.fmt
	var/texlive/web2c/luatex/optex.log
	var/texlive/web2c/luatex/pdfcsplain.fmt
	var/texlive/web2c/luatex/pdfcsplain.log
	var/texlive/web2c/metafont/mf.base
	var/texlive/web2c/metafont/mf.log
	var/texlive/web2c/pdftex/amstex.fmt
	var/texlive/web2c/pdftex/amstex.log
	var/texlive/web2c/pdftex/cont-en.fmt
	var/texlive/web2c/pdftex/cont-en.log
	var/texlive/web2c/pdftex/cslatex.fmt
	var/texlive/web2c/pdftex/cslatex.log
	var/texlive/web2c/pdftex/csplain.fmt
	var/texlive/web2c/pdftex/csplain.log
	var/texlive/web2c/pdftex/eplain.fmt
	var/texlive/web2c/pdftex/eplain.log
	var/texlive/web2c/pdftex/etex.fmt
	var/texlive/web2c/pdftex/etex.log
	var/texlive/web2c/pdftex/jadetex.fmt
	var/texlive/web2c/pdftex/jadetex.log
	var/texlive/web2c/pdftex/latex-dev.fmt
	var/texlive/web2c/pdftex/latex-dev.log
	var/texlive/web2c/pdftex/latex.fmt
	var/texlive/web2c/pdftex/latex.log
	var/texlive/web2c/pdftex/mex.fmt
	var/texlive/web2c/pdftex/mex.log
	var/texlive/web2c/pdftex/mllatex.fmt
	var/texlive/web2c/pdftex/mllatex.log
	var/texlive/web2c/pdftex/mltex.fmt
	var/texlive/web2c/pdftex/mltex.log
	var/texlive/web2c/pdftex/mptopdf.fmt
	var/texlive/web2c/pdftex/mptopdf.log
	var/texlive/web2c/pdftex/pdfcslatex.fmt
	var/texlive/web2c/pdftex/pdfcslatex.log
	var/texlive/web2c/pdftex/pdfcsplain.fmt
	var/texlive/web2c/pdftex/pdfcsplain.log
	var/texlive/web2c/pdftex/pdfetex.fmt
	var/texlive/web2c/pdftex/pdfetex.log
	var/texlive/web2c/pdftex/pdfjadetex.fmt
	var/texlive/web2c/pdftex/pdfjadetex.log
	var/texlive/web2c/pdftex/pdflatex-dev.fmt
	var/texlive/web2c/pdftex/pdflatex-dev.log
	var/texlive/web2c/pdftex/pdflatex.fmt
	var/texlive/web2c/pdftex/pdflatex.log
	var/texlive/web2c/pdftex/pdfmex.fmt
	var/texlive/web2c/pdftex/pdfmex.log
	var/texlive/web2c/pdftex/pdftex.fmt
	var/texlive/web2c/pdftex/pdftex.log
	var/texlive/web2c/pdftex/pdfxmltex.fmt
	var/texlive/web2c/pdftex/pdfxmltex.log
	var/texlive/web2c/pdftex/texsis.fmt
	var/texlive/web2c/pdftex/texsis.log
	var/texlive/web2c/pdftex/utf8mex.fmt
	var/texlive/web2c/pdftex/utf8mex.log
	var/texlive/web2c/pdftex/xmltex.fmt
	var/texlive/web2c/pdftex/xmltex.log
	var/texlive/web2c/ptex/ptex.fmt
	var/texlive/web2c/ptex/ptex.log
	var/texlive/web2c/tex/lollipop.fmt
	var/texlive/web2c/tex/lollipop.log
	var/texlive/web2c/tex/tex.fmt
	var/texlive/web2c/tex/tex.log
	var/texlive/web2c/uptex/uptex.fmt
	var/texlive/web2c/uptex/uptex.log
	var/texlive/web2c/xetex/cont-en.fmt
	var/texlive/web2c/xetex/cont-en.log
	var/texlive/web2c/xetex/pdfcsplain.fmt
	var/texlive/web2c/xetex/pdfcsplain.log
	var/texlive/web2c/xetex/xelatex-dev.fmt
	var/texlive/web2c/xetex/xelatex-dev.log
	var/texlive/web2c/xetex/xelatex.fmt
	var/texlive/web2c/xetex/xelatex.log
	var/texlive/web2c/xetex/xetex.fmt
	var/texlive/web2c/xetex/xetex.log
	"

fetchTexLiveInstaller()
{
	# Put the texmf-dist into the correct location
	rm -rv texmf-dist || true
	ln -sv $sourceDir2/texmf-dist/ texmf-dist

	# Link our binaries to bin/{i386,x86_64}-haiku

	if [ $targetArchitecture = x86_gcc2 ] || [ $targetArchitecture = x86 ]; then
		if [ ! -e bin/i386-haiku ] ; then
			mkdir -p bin
			ln -s /boot/system/bin bin/i386-haiku
		fi

	else
		if [ ! -e bin/${targetArchitecture}-haiku ] ; then
			mkdir -p bin
			ln -s /boot/system/bin bin/${targetArchitecture}-haiku
		fi
	fi

	# link or copy the needed files from the "extra" sources
	rm -v tlpkg/{texlive.tlpdb,tlpostcode} readme-{html,txt}.dir README{,.usergroups} {index,doc}.html || true
	ln -sv $sourceDir3/tlpkg/{texlive.tlpdb,tlpostcode} tlpkg
	ln -sv $sourceDir3/readme-{html,txt}.dir .
	cp -v $sourceDir3/{README{,.usergroups},{index,doc}.html} .
}

PATCH() {
	sed -i "s|\`kpsewhich -var-value=SELFAUTOPARENT\`|\"$dataDir/texlive\"|" $sourceDir/tlpkg/TeXLive/TLUtils.pm
	sed -i "s|\`kpsewhich -var-value=FC_CACHEDIR\`|\"$sharedStateDir/texlive/fonts/cache\"|" $sourceDir3/tlpkg/tlpostcode/xetex.pl
	sed -i "s|\`kpsewhich -var-value=FONTCONFIG_PATH\`|\"$sharedStateDir/texlive/fonts/conf\"|" $sourceDir3/tlpkg/tlpostcode/xetex.pl
}

INSTALL()
{
	fetchTexLiveInstaller
	export TEXLIVE_INSTALL_PREFIX=$dataDir/texlive
	export TEXLIVE_INSTALL_TEXMFSYSVAR=$sharedStateDir/texlive
	export TEXLIVE_INSTALL_TEXMFSYSCONFIG=$sysconfDir/texlive
	export TEXLIVE_INSTALL_TEXMFLOCAL=/boot/system/non-packaged/data/texmf-dist
	export TEXLIVE_INSTALL_TEXMFVAR=/boot/home/config/var/texmf
	export TEXLIVE_INSTALL_TEXMFCONFIG=/boot/home/config/settings/texmf/config
	export TEXLIVE_INSTALL_TEXMFHOME=/boot/home/config/settings
	# hmm, need to work-around /boot/system/non-packaged not existing....
	# the texfm local tree should probably be done with a post-install script, perhaps
	sed -i -e 's/make_local_skeleton \".*//' install-tl
	# run the TeX Live installer, and specify all our paths, once more, to be sure... ;-)
	export PATH=bin/i386-haiku:bin/${targetArchitecture}-haiku:$binDir:$PATH
	if [ $targetArchitecture = x86_gcc2 ] || [ $targetArchitecture = x86 ]; then
		customBinDir=bin/i386-haiku/
	else
		customBinDir=bin/${targetArchitecture}-haiku/
	fi
	sed -e "s@dataDir@$dataDir@g" \
		-e "s@sharedStateDir@$sharedStateDir@g" \
		-e "s@sysconfDir@$sysconfDir@g" \
		$portDir/additional-files/texlive.profile > texlive.profile
	install-tl --custom-bin=$customBinDir --profile=texlive.profile

	# somewhere along the way, a texmf.cnf gets created with ALL the wrong paths...
	# replace it with the known working version from the main texlive_core package
	cp -f /boot/system/data/texmf-dist/web2c/texmf.cnf $dataDir/texlive/texmf-dist/web2c/texmf.cnf

	# remove useless libtool files and other unneeded files
	rm -f $libDir/*.la

	rm -rf $dataDir/texlive/bin
	rm -f $dataDir/texlive/install-tl*

	mkdir -p $postInstallDir
	install -t $postInstallDir -m 755 $portDir/additional-files/texlive_postinstall.sh

	# texmf_doc package
	packageEntries doc \
		$dataDir/texlive/texmf-dist/doc

	# exit 1
}
