cd $BUILD_DIRECTORY &&
mk_source_dir "$SOURCE_DIRECTORY" &&
verify_file '' &&
xz -dc $SOURCE_CACHE/$SOURCE | tar -xf - &&

# find all the pdfs, strip the extension and then check if their source is
# also present. If it is, remove the pdf.
if [[ $TTMF_SMALL == y ]]; then
  find "$SOURCE_DIRECTORY" -type f -iname "*.pdf" | sed 's,....$,,' |
    while read p; do
      if [[ -e "$p.pdf" && -e "$p.tex" ]]; then
        rm "$p.pdf"
      fi
    done
fi &&


cd ${SOURCE_DIRECTORY} &&
# patch texmfcnf.lua for luatex
patch -p0 < ${SPELL_DIRECTORY}/texmfcnf.lua_fix.patch            &&

patch -p1 < ${SPELL_DIRECTORY}/upstream_updmap-ignoring-settings &&
patch -p1 < ${SPELL_DIRECTORY}/fix-natbib-add-spaces             &&
patch -p1 < ${SPELL_DIRECTORY}/dvipdfmx.cfg_whitespace           &&

# rm texmf.cnf so it doesn't overwrite patched version
rm ${SOURCE_DIRECTORY}/texmf/web2c/texmf.cnf
