default_pre_build &&
cd "${SOURCE_DIRECTORY}" &&

sedit "/OPJ_STATIC$/d" source/fitz/load-jpx.c &&
sedit "s:-DOPJ_STATIC::" Makethird &&
apply_patch_dir "patches-${VERSION%.*}" &&

rm -rf thirdparty/{curl,freeglut,freetype,harfbuzz,glfw,jbig2dec,jpeg,libjpeg,zlib} &&

# building against older system OpenJPEG library is unsupported
if spell_ok openjpeg && ! is_version_less $(installed_version openjpeg) 2.0; then
  rm -rf thirdparty/openjpeg
else
  patch -p0 < "${SPELL_DIRECTORY}/opj_malloc.patch"
fi &&

sed -e "/zlib.h/i#include <limits.h>" \
    -e "s;z_const;const;" \
    -i source/fitz/compress.c &&
sed "/zlib.h/i#include <limits.h>" \
    -i source/fitz/load-png.c source/pdf/pdf-write.c
