# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Jakub Klinkovský <lahwaacz at archlinux dot org>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Dan McGee <dan@archlinux.org>

pkgbase=doxygen
pkgname=(doxygen doxygen-docs)
pkgver=1.10.0
pkgrel=3.1
pkgdesc='Documentation system for C++, C, Java, IDL and PHP'
url='http://www.doxygen.nl'
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(GPL-2.0-or-later)
makedepends=(
  clang
  cmake
  flex
  fmt
  gcc-libs
  ghostscript
  glibc
  graphviz
  llvm
  python
  qt6-base
  spdlog
  sqlite
  texlive-fontsrecommended
  texlive-fontutils
  texlive-latexextra
  texlive-plaingeneric
)
source=(${pkgbase}-${pkgver}.tar.gz::https://github.com/doxygen/doxygen/archive/Release_${pkgver//./_}.tar.gz)
sha512sums=('d8731796d5513ff5939c234f32f7f31aabc45f5557947741a330b3d33b368fb5ad770ef1d3d7384a402d98229eafeb1f955ef76e9932310b83c1d35a2eef500f')
b2sums=('e9eaf70e106aa022bb0edc99082e6bccd5c6879c41be40ce69d2d5e4eb7d1c5ff078fd8f9132206bf546fa78aab7f8bef4584fd1f2d6e1e84b01d2e65933375e')

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

prepare() {
  cd ${pkgbase}-Release_${pkgver//./_}
  # Install the man pages in the right place
  sed -i 's:DESTINATION man/man1:DESTINATION "${CMAKE_INSTALL_PREFIX}/share/man/man1":g' \
    doc/CMakeLists.txt
}

build() {
  #FIXME: on powerpc64le doxygen pulls in clang which breaks libreoffice
  case "${CARCH}" in
    powerpc64le) _cmake_options=(-Duse_libclang:BOOL=OFF) ;;
    *)           _cmake_options=(-Duse_libclang:BOOL=ON) ;;
  esac

  cmake -B build -S $pkgbase-Release_${pkgver//./_} \
    -DCMAKE_BUILD_TYPE:STRING=None \
    -DCMAKE_INSTALL_PREFIX:PATH=/usr \
    -DDOC_INSTALL_DIR:PATH=share/doc/doxygen \
    -Dbuild_doc:BOOL=ON \
    -Dbuild_wizard:BOOL=ON \
    -Duse_sys_spdlog:BOOL=ON \
    -Duse_sys_sqlite3:BOOL=ON \
    ${_cmake_options[@]}
  cmake --build build --verbose
  cmake --build build --target docs
}

check() {
  ctest --test-dir build --output-on-failure
}

package_doxygen() {
  depends=(
    fmt libfmt.so
    gcc-libs
    glibc
    sqlite libsqlite3.so
  )
  depends_powerpc=(clang)
  depends_powerpc64=(clang)
  depends_riscv64=(clang)
  depends_x86_64=(clang)
  optdepends=(
    'graphviz: for caller/callee graph generation'
    'qt6-base: for doxywizard'
    'texlive-fontsrecommended: for generating LaTeX, Postscript and PDF output'
    'texlive-fontutils: for generating LaTeX, Postscript and PDF output'
    'texlive-latexextra: for generating LaTeX, Postscript and PDF output'
    'texlive-plaingeneric: for generating LaTeX, Postscript and PDF output'
  )

  DESTDIR="$pkgdir" cmake --install build
  (
    cd "$pkgdir"
    _pick $pkgbase-docs usr/share/doc
  )
  install -vDm 644 $pkgbase-Release_${pkgver//./_}/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}

package_doxygen-docs() {
  pkgdesc='Developer documentation for doxygen'

  mv -v $pkgname/* "$pkgdir"
  install -vDm 644 $pkgbase-Release_${pkgver//./_}/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}

# vim: ts=2 sw=2 et:
