# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgbase=doxygen
pkgname=(doxygen doxygen-docs)
pkgver=%version%
pkgrel=%release%
pkgdesc='Documentation system for C++, C, Java, IDL and PHP'
url='http://www.doxygen.nl'
arch=(x86_64)
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() {
  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 \
    -Duse_libclang:BOOL=ON
  cmake --build build --verbose
  cmake --build build --target docs
}

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

package_doxygen() {
  depends=(
    clang
    fmt libfmt.so
    gcc-libs
    glibc
    sqlite libsqlite3.so
  )
  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:
