MINGW_INSTALL=/clangarm64
_subcatalogdir=$(cygpath -m ${MINGW_INSTALL}/etc/xml/)
_rootcatalog=$(cygpath -m ${MINGW_INSTALL}/etc/xml/catalog)
# export MSYS2_ARG_CONV_EXCL="-//OASIS"

post_install() {
  if [ -e ${MINGW_XML_CATALOG}/catalog.preserve ]; then
    mv ${MINGW_XML_CATALOG}/catalog.preserve ${MINGW_XML_CATALOG}/catalog
  elif [ ! -e ${MINGW_INSTALL}/etc/xml/catalog ]; then
    ${MINGW_PREFIX}/bin/xmlcatalog  --noout --create ${MINGW_XML_CATALOG}/catalog
  fi

  for v in 5.{0,0.1,1}; do
      ${MINGW_PREFIX}/bin/xmlcatalog --noout --add "delegatePublic" \
        "-//OASIS//DTD DocBook XML ${v}//EN" \
        "./docbook-${v}.xml" \
        ${_rootcatalog}
  done
}

# arg 1:  the new package version
# arg 2:  the old package version
pre_upgrade() {
  if [ $(vercmp $2 4.5) -lt 0 ]; then
    ${MINGW_PREFIX}/bin/xmlcatalog --del "${MINGW_XML_CATALOG}/docbook-5.0.xml" \
    ${MINGW_XML_CATALOG}/catalog > ${MINGW_XML_CATALOG}/catalog.preserve
  fi
}

post_upgrade() {
  if [ $(vercmp $2 4.5) -ge 0 ]; then
    post_remove
  fi
  post_install
}

post_remove() {
  for v in 5.{0,0.1,1}; do
    ${MINGW_PREFIX}/bin/xmlcatalog --noout --del \
       "./docbook-${v}.xml" \
       ${_rootcatalog}
  done
}
