# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

pkgbase=mingw-w64-texlive-bin
pkgname=("${MINGW_PACKAGE_PREFIX}-texlive-bin" "${MINGW_PACKAGE_PREFIX}-libsynctex")
pkgver=2023.20230523
pkgdesc="TeX Live binaries (mingw-w64)"
pkgrel=9
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url='https://tug.org/texlive/'
msys2_repository_url="https://github.com/Tex-Live/texlive-source"
msys2_references=(
  "cpe: cpe:/a:tug:texlive"
)
license=('spdx:GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-2.1-or-later AND LGPL-2.0-or-later AND LPPL-1.3c')
makedepends=(
    "${MINGW_PACKAGE_PREFIX}-perl"
    "${MINGW_PACKAGE_PREFIX}-cairo"
    "${MINGW_PACKAGE_PREFIX}-pixman"
    "${MINGW_PACKAGE_PREFIX}-graphite2"
    "${MINGW_PACKAGE_PREFIX}-libsigsegv"
    "${MINGW_PACKAGE_PREFIX}-zziplib"
    "${MINGW_PACKAGE_PREFIX}-libpng"
    "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
    "${MINGW_PACKAGE_PREFIX}-freetype"
    "${MINGW_PACKAGE_PREFIX}-icu"
    "${MINGW_PACKAGE_PREFIX}-harfbuzz"
    "${MINGW_PACKAGE_PREFIX}-gmp"
    "${MINGW_PACKAGE_PREFIX}-mpfr"
    "${MINGW_PACKAGE_PREFIX}-potrace"
    "${MINGW_PACKAGE_PREFIX}-libpaper"
    "${MINGW_PACKAGE_PREFIX}-ffcall"
    "${MINGW_PACKAGE_PREFIX}-libgd"
    "${MINGW_PACKAGE_PREFIX}-lua"
    "${MINGW_PACKAGE_PREFIX}-luajit"
    "${MINGW_PACKAGE_PREFIX}-ghostscript"
    "${MINGW_PACKAGE_PREFIX}-autotools"
    "${MINGW_PACKAGE_PREFIX}-cc"
    "${MINGW_PACKAGE_PREFIX}-pkgconf"
    # perl dependencies
    "${MINGW_PACKAGE_PREFIX}-perl-win32-api"
    "${MINGW_PACKAGE_PREFIX}-perl-win32-console"
    "${MINGW_PACKAGE_PREFIX}-perl-win32-shortcut"
    "${MINGW_PACKAGE_PREFIX}-perl-win32-tieregistry"
    "${MINGW_PACKAGE_PREFIX}-perl-win32-winerror"
    "${MINGW_PACKAGE_PREFIX}-perl-win32api-registry"
    "${MINGW_PACKAGE_PREFIX}-perl-file-which"
    "${MINGW_PACKAGE_PREFIX}-perl-io-string"
)
_commit=871c7a2856d70e1a9703d1f72f0587b9995dba5f # svn://tug.org/texlive/branches/branch2023/Build/source@66984
source=(
    "texlive-source-${_commit}.tar.gz::https://github.com/Tex-Live/texlive-source/archive/${_commit}.tar.gz"
    "0001-Remove-DLUASOCKET_INET_PTON-from-Makefile.patch"
    "0002-fix-lauchers-mingw32.patch"
    "0003-runscript-always-quote-args.patch"
    "0004-add-missing-includes-dvisvgm.patch"
    "0005-untighten_version_check_zlib.patch"
    "0006-workaround-pathconf.patch"
    "0007-stat.patch")
sha256sums=('d3eca31c6a16a168f66471ce3837b7c950826967162eab04d58233f52462527e'
            '86ef2a99b2f0caed42777419837d9b539af1d1c8a101701e539e5467bb88662e'
            'decff8db61302c2a1760cfd4b42aaf0e25fcb7d2b9621cea3ec3f4c2557976a1'
            'c22ad079777082ebb7fe90e64d3f0d20b75756e50af776f2d4c1b9f9e692dba3'
            '46d9572ae1e178377f9ab4c11696cb1fbff0999b9719c6e17b5dbbe790b267a3'
            'f805930ee0396aea3c6d189c078ad57d4c5c9212f6f3cb7f25e0c74b8151e0b1'
            'e0fd72b6863156520bc7f30e446a991df6f35ec36de7a5ab2f767a091c2ea451'
            'e4682accd42f3cde2df65628a13c1ba2b19fb779207dc6dad832d1c7b7cb4ab6')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
    mv -f "$srcdir/texlive-source-${_commit}" "$srcdir/texlive-source"
    cd "$srcdir/texlive-source"
    apply_patch_with_msg 0001-Remove-DLUASOCKET_INET_PTON-from-Makefile.patch
    apply_patch_with_msg 0003-runscript-always-quote-args.patch
    apply_patch_with_msg 0004-add-missing-includes-dvisvgm.patch

    # https://github.com/msys2/MINGW-packages/issues/18251
    # https://github.com/debian-tex/texlive-bin/blob/6dae83df50df3edc/debian/patches/untighten_version_check_zlib.diff
    apply_patch_with_msg 0005-untighten_version_check_zlib.patch

    # Remove when https://github.com/msys2/msys2-runtime/issues/208 is fixed:
    apply_patch_with_msg 0006-workaround-pathconf.patch

    # https://github.com/TeX-Live/texlive-source/commit/1622d0ff6363d5cb2a4a81cdffb72b78fe7c6ef9
    # https://github.com/TeX-Live/texlive-source/commit/21a44442e9932284f5d7dc724ac35ef01bd683dc
    apply_patch_with_msg 0007-stat.patch

    # from https://github.com/archlinux/svntogit-packages/blob/packages/texlive-bin/trunk/PKGBUILD#L21
    # bibtex-x needs kpathsea flags
    sed -i '/AC_SEARCH_LIBS/a KPSE_KPATHSEA_FLAGS' texk/bibtex-x/configure.ac

    # t4ht expects to be un /usr/share/texmf/bin/t4ht (FS#27251)
    sed -i s/SELFAUTOPARENT/TEXMFROOT/ texk/tex4htk/t4ht.c

    msg2 "Running autoreconf for all (sub-)projects with changed configuration files"
    ./reautoconf -v
}

build() {
   cd "$srcdir/texlive-source"

   #############################################################
   ### configure
   mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

   echo "--> Initial configuration..."
   export lt_cv_deplibs_check_method='pass_all'
   CXX+=" -std=gnu++17"
   CFLAGS+=" -Wno-error=incompatible-pointer-types"
   # we use temporary prefix to avoid messing the existing
   # $pkgdir/usr/share/texmf tree
   ../configure -C \
     --prefix="${MINGW_PREFIX}" \
     --disable-static \
     --enable-shared \
     --disable-missing \
     --disable-native-texlive-build \
     --with-banner-add="/Built by MSYS2 project" \
     --disable-multiplatform \
     --disable-t1utils \
     --disable-bibtexu \
     --with-system-zlib \
     --with-system-zziplib \
     --with-system-libpng \
     --with-system-ncurses \
     --with-system-gd \
     --with-system-freetype2 \
     --with-system-pixman \
     --with-system-cairo \
     --with-system-harfbuzz \
     --with-system-graphite2 \
     --with-system-icu \
     --with-system-gmp \
     --with-system-mpfr \
     --with-system-potrace \
     --with-system-libpaper \
     --with-xdvi-x-toolkit=xaw \
     --disable-dump-share \
     --enable-aleph \
     --disable-xpdfopen
   #############################################################
   ### make
   echo "-------------------------------------------------------"
   echo "--> Building the whole beast ..."
   echo "-------------------------------------------------------"
   make

   msg "Building Launchers"
   # let's build launchers first
   # it is present in ../texk/texlive/windows_mingw_wrapper wrapper

   # first delete *.exe and *.dll from the locations
   rm -f ../texk/texlive/windows_mingw_wrapper/*.exe ../texk/texlive/windows_mingw_wrapper/*.dll \
      ../texk/texlive/windows_mingw_wrapper/context/*.exe ../texk/texlive/windows_mingw_wrapper/context/*.dll
   cp "libs/lua53/.libs/texlua.dll" ../texk/texlive/windows_mingw_wrapper
   cp "libs/lua53/.libs/libtexlua53.dll.a" ../texk/texlive/windows_mingw_wrapper
   cd ../texk/texlive/windows_mingw_wrapper

   echo '1 ICON "tlmgr.ico"'>texlive.rc
   windres texlive.rc texlive.o

   cc -Os -s -shared -Wl,--out-implib=librunscript.dll.a -o runscript.dll runscript_dll.c -L./ -ltexlua53
   cc -Os -s -o runscript.exe runscript_exe.c texlive.o -L./ -lrunscript
   cc -mwindows -Os -s -o wrunscript.exe wrunscript_exe.c texlive.o -L./ -lrunscript

   cd context
   cc -Os -s -shared -Wl,--out-implib=libmtxrun.dll.a -o mtxrun.dll mtxrun_dll.c
   cc -Os -s -o mtxrun.exe mtxrun_exe.c -L./ -lmtxrun
   cd ..
   #cleanup
   rm texlive.rc texlive.o texlua.dll libtexlua53.dll.a
}

package_libsynctex() {
    pkgdesc='Library for synchronization between TeX files and resulting file (mingw-w64)'
    depends=("${MINGW_PACKAGE_PREFIX}-zlib")

    cd "${srcdir}/texlive-source/build-${MSYSTEM}"
    make -C texk/web2c DESTDIR="${pkgdir}" \
        install-data-am install-libLTLIBRARIES

    rm -f "$pkgdir"/${MINGW_PREFIX}/share/man/man1/hi*.*
}

package_texlive-bin() {
  pkgdesc="TeX Live binaries"
  depends=(
    "${MINGW_PACKAGE_PREFIX}-cairo"
    "${MINGW_PACKAGE_PREFIX}-pixman"
    "${MINGW_PACKAGE_PREFIX}-graphite2"
    "${MINGW_PACKAGE_PREFIX}-libsigsegv"
    "${MINGW_PACKAGE_PREFIX}-zziplib"
    "${MINGW_PACKAGE_PREFIX}-libpng"
    "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
    "${MINGW_PACKAGE_PREFIX}-freetype"
    "${MINGW_PACKAGE_PREFIX}-icu"
    "${MINGW_PACKAGE_PREFIX}-harfbuzz"
    "${MINGW_PACKAGE_PREFIX}-gmp"
    "${MINGW_PACKAGE_PREFIX}-mpfr"
    "${MINGW_PACKAGE_PREFIX}-potrace"
    "${MINGW_PACKAGE_PREFIX}-libpaper"
    "${MINGW_PACKAGE_PREFIX}-libgd"
    "${MINGW_PACKAGE_PREFIX}-libsynctex"
    "${MINGW_PACKAGE_PREFIX}-lua"
    "${MINGW_PACKAGE_PREFIX}-luajit"
    "${MINGW_PACKAGE_PREFIX}-ghostscript"
    # perl dependencies
    "${MINGW_PACKAGE_PREFIX}-perl-win32-api"
    "${MINGW_PACKAGE_PREFIX}-perl-win32-console"
    "${MINGW_PACKAGE_PREFIX}-perl-win32-shortcut"
    "${MINGW_PACKAGE_PREFIX}-perl-win32-tieregistry"
    "${MINGW_PACKAGE_PREFIX}-perl-win32-winerror"
    "${MINGW_PACKAGE_PREFIX}-perl-win32api-registry"
    "${MINGW_PACKAGE_PREFIX}-perl-file-which"
    "${MINGW_PACKAGE_PREFIX}-perl-io-string")
  provides=(
    "${MINGW_PACKAGE_PREFIX}-lcdf-typetools"
    "${MINGW_PACKAGE_PREFIX}-kpathsea"
    #"${MINGW_PACKAGE_PREFIX}-xindy" #once clisp is build this needs to be enabled
  )
  #optdepends=('ed: for texconfig'
  #            'biber: for bibliography processing')
  options=('!strip')

  cd "$srcdir/texlive-source"

  #############################################################
  ### install
  echo "-------------------------------------------------------"
  echo "--> Proceeding with make install ..."
  echo "-------------------------------------------------------"
  cd build-${MSYSTEM}
  make DESTDIR="${pkgdir}" texmf="${pkgdir}${MINGW_PREFIX}"/share/texmf install
  rm -rf "${pkgdir}${MINGW_PREFIX}"/{texmf,share/texmf-dist}

  # should be updated with what arch does.
  ## symlink engines by hand. texlinks has moved to texlive-core...
  cd "${pkgdir}${MINGW_PREFIX}"/bin
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/bin
  install -D -m755 eptex.exe "${pkgdir}"${MINGW_PREFIX}/bin/platex.exe
  install -D -m755 euptex.exe "${pkgdir}"${MINGW_PREFIX}/bin/uplatex.exe
  install -D -m755 luatex.exe "${pkgdir}"${MINGW_PREFIX}/bin/dvilualatex.exe
  install -D -m755 luatex.exe "${pkgdir}"${MINGW_PREFIX}/bin/dviluatex.exe
  install -D -m755 luahbtex.exe "${pkgdir}"${MINGW_PREFIX}/bin/lualatex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/amstex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/cslatex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/csplain.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/eplain.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/etex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/jadetex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/latex.exe
  install -D -m755 tex.exe "${pkgdir}"${MINGW_PREFIX}/bin/lollipop.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/mex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/mllatex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/mltex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/pdfetex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/pdfcslatex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/pdfcsplain.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/pdfjadetex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/pdflatex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/pdfmex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/pdfxmltex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/texsis.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/utf8mex.exe
  install -D -m755 pdftex.exe "${pkgdir}"${MINGW_PREFIX}/bin/xmltex.exe
  install -D -m755 xetex.exe "${pkgdir}"${MINGW_PREFIX}/bin/xelatex.exe

  # install mtxrun.dll
  install -D -m755 "${srcdir}/texlive-source/texk/texlive/windows_mingw_wrapper/context/mtxrun.dll" \
      "${pkgdir}${MINGW_PREFIX}/bin/mtxrun.dll"

  for _script in context contextjit luatools mtxrun mtxrunjit texexec texmfstart
  do
    install -D -m755 "${srcdir}/texlive-source/texk/texlive/windows_mingw_wrapper/context/mtxrun.exe" \
        "${pkgdir}${MINGW_PREFIX}/bin/${_script}.exe"
  done

   # remove dangling executables, they are available in seperate pacakges
   # automatically generated from msys2-texlive project.
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/adhocfilelist.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/bibexport.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/checklistings.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ctanbib.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/dtxgen.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/git-latexdiff.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/installfont-tl.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latexfileversion.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/listbib.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/listings-ext.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ltxfileinfo.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pagelayoutapi.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/textestvis.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pdfbook2.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pdfjam.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pdftex-quiet.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pdfxup.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ps4pdf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/simpdftex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texaccents.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/allcm.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/allneeded.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/dvi2fax.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/dvired.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/fontinst.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/kpsetool.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/kpsewhere.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ps2frag.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pslatex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/rubibtex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/rumakeindex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texconfig-dialog.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texconfig-sys.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texconfig.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texlinks.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/xetex-unsafe.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/xelatex-unsafe.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texosquery.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texosquery-jre5.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texosquery-jre8.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/tikztosvg.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/typeoutfileinfo.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/wordcount.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/a2ping.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mkt1font.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/vpl2ovp.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/vpl2vpl.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/albatross.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/arara.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pdfatfi.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/authorindex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/bib2gls.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/convertgls2bib.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/bibcop.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/arlatex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/bundledoc.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/cachepic.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/checkcites.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/citeproc-lua.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/chklref.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/cjk-gs-integrate.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pamphletangler.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/cluttex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mptopdf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/convbkmk.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/bbl2bib.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/bibdoiadd.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/bibmradd.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/biburl2doi.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/bibzbladd.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ltx2crossrefxml.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ctan-o-mat.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ctanify.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ctanupload.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/de-macro.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/diadia.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/digestif.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/dosepsbin.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/dviasm.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/dviinfox.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ebong.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/epspdf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/epspdftk.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/epstopdf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/exceltex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/fig4latex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/findhyph.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/afm2afm.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/autoinst.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ot2kpx.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/fragmaster.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/getmapdl.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/makeglossaries.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/makeglossaries-lite.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/hyperxmp-add-bytecount.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/jfmutil.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ketcindy.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/jamo-normalize.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/komkindex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ttf2kotexfont.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/l3build.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latex-git-log.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latex-papersize.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latex2man.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latex2nemeth.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latexdiff-vc.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latexdiff.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latexrevise.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latexindent.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latexmk.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/latexpand.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/llmk.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/lily-glyph-commands.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/lily-image-commands.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/lily-rebuild-pdfs.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ltximg.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/luafindfont.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/luaotfload-tool.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/lwarpmk.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/m-tx.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/makedtx.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/make4ht.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/match_parens.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mathspic.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mf2pt1.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mkgrkindex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mkjobtexmf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mkpic.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/multibibliography.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/musixflx.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/musixtex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/optexcount.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pdfannotextractor.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pdfcrop.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pdflatexpicscale.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pedigree.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/perltex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pn2pdf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/a5toa4.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pfarrei.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pkfix-helper.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pkfix.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pmxchords.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pst2pdf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/kanji-config-updmap-sys.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/kanji-config-updmap-user.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/kanji-config-updmap.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/kanji-fontmap-creator.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ptex2pdf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/purifyeps.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pygmentex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/depythontex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/pythontex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/rubikrotation.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/spix.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/splitindex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/srcredact.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/sty2dtx.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/svn-multi.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/tex4ebook.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texcount.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texdef.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texdiff.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texdirflatten.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texdoc.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texfot.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/fmtutil-sys.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/fmtutil-user.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/fmtutil.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mktexlsr.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mktexmf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mktexpk.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/mktextfm.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/rungs.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/tlmgr.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/updmap-sys.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/updmap-user.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/updmap.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/e2pall.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texliveonfly.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texloganalyser.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texlogfilter.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texlogsieve.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/texplate.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/thumbpdf.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/tlcockpit.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/tlshell.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/ulqda.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/urlbst.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/vpe.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/webquiz.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/xindex.exe"
   rm -f "${pkgdir}${MINGW_PREFIX}/bin/yplan.exe"
   # remove libsynctex
   rm -f "${pkgdir}${MINGW_PREFIX}"/include/synctex/*
   rm -f "${pkgdir}${MINGW_PREFIX}"/lib/libsynctex.*
   rm -f "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/synctex.pc
   rm -f "${pkgdir}${MINGW_PREFIX}"/share/man/man*/synctex.*
   rm -f "${pkgdir}${MINGW_PREFIX}"/bin/libsynctex-2.dll
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
