# okular 25.04.3 — el visor de documentos de KDE. 8va APP del escritorio.
# Patrón KF6 app (dynamic, wrapper zig, ECM). Dep nueva clave: poppler 25.02.0 (Qt6) = el generador PDF.
# ZLIB es REQUIRED. okular marca sus generadores TYPE REQUIRED pero ofrece el flag OFICIAL
# `FORCE_NOT_REQUIRED_DEPENDENCIES` (lo sugiere el propio feature_summary al abortar) ⇒ se degradan los que
# no tenemos sellados: DocTools, Purpose, TIFF, LibSpectre (PS), KExiv2Qt6, DjVuLibre, EPub, Discount
# (markdown), QMobipocket6. Sí entran: poppler (PDF, lo importante), kimgio (imágenes), txt, comicbook
# (pide KF6Pty), fictionbook, xps. Aprovechados por estar ya sellados: kwallet (claves de PDF), phonon
# (sonido), qtspeech (lectura en voz), plasma-activities (REQUIRED).
#
# GOTCHA musl: core/synctex/synctex_parser.c usa vasprintf (extensión GNU) y compila con -std=c99; en modo
# estricto (__STRICT_ANSI__) musl NO declara vasprintf en stdio.h (sólo bajo _GNU_SOURCE/_BSD_SOURCE) ⇒
# "call to undeclared function 'vasprintf'" con -Werror=implicit-function-declaration. Fix: CMAKE_C_FLAGS=-D_GNU_SOURCE.
name    = "okular"
version = "25.04.3"
license = "GPL-2.0-or-later"

[source]
tarball = "https://download.kde.org/stable/release-service/25.04.3/src/okular-25.04.3.tar.xz"
sha256  = "d0b5bb0b0eeab46aa2367c8d81096185bd2261710701c84f1c6e2398e5058bfb"

[build]
compiler = "zig-cc"
target   = "x86_64-linux-musl"
link     = "dynamic"
flags    = []

[build.phases]
configure = '''
rm -rf po doc
sed -i '/add_subdirectory(doc)/d' CMakeLists.txt
sed -i '/kdoctools_install/d' CMakeLists.txt
ZW="$PWD/.zwrap"; mkdir -p "$ZW"
cat > "$ZW/cc"  <<'W'
#!/bin/sh
a=""; for x in "$@"; do [ "$x" = "-Wl,--fatal-warnings" ] && continue; a="$a $x"; done
exec /opt/zig/zig cc -mcpu=baseline $a
W
cat > "$ZW/cxx" <<'W'
#!/bin/sh
a=""; for x in "$@"; do [ "$x" = "-Wl,--fatal-warnings" ] && continue; a="$a $x"; done
exec /opt/zig/zig c++ -mcpu=baseline $a
W
chmod +x "$ZW/cc" "$ZW/cxx"
cmake -B build -G Ninja -Wno-dev \
  -DCMAKE_C_COMPILER="$ZW/cc" -DCMAKE_CXX_COMPILER="$ZW/cxx" -DCMAKE_ASM_COMPILER="$ZW/cc" \
  -DCMAKE_C_FLAGS="-D_GNU_SOURCE" \
  -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_PREFIX_PATH=/usr \
  -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF -DBUILD_TESTING=OFF \
  -DFORCE_NOT_REQUIRED_DEPENDENCIES="KF6DocTools;KF6Purpose;TIFF;LibSpectre;KExiv2Qt6;DjVuLibre;EPub;Discount;QMobipocket6"
'''
compile = "cmake --build build"
install = "DESTDIR=/out cmake --install build"

[deps]
build = ["cmake", "samurai", "python3", "pkgconf", "qtbase", "qtsvg", "dbus", "extra-cmake-modules",
  "qttools", "gettext-tiny", "mesa", "libdrm", "libxkbcommon", "wayland", "qtdeclarative",
  "poppler", "freetype-shared", "fontconfig-shared", "zlib-shared", "lcms2",
  "libjpeg-turbo-shared", "libpng-shared", "expat", "phonon", "qtspeech", "qtmultimedia",
  "karchive", "kbookmarks", "kcompletion", "kconfig", "kconfigwidgets", "kcoreaddons", "ki18n",
  "kio", "threadweaver", "kwindowsystem", "kxmlgui", "kparts", "kcolorscheme", "kcrash",
  "kiconthemes", "kitemviews", "ktextwidgets", "kwidgetsaddons",
  "kservice", "kjobwidgets", "kcodecs", "kguiaddons", "solid", "sonnet", "attica", "kpackage",
  "kirigami", "kglobalaccel", "kauth", "icu4c", "knotifications", "kitemmodels", "plasma-activities",
  "kpty", "kwallet",
  "libX11", "xorgproto", "libXau", "libXdmcp", "libXext", "libXrender", "libXfixes", "libXi",
  "libxcb", "xcb-util", "xcb-util-keysyms", "xcb-util-wm", "xcb-util-image", "xcb-util-renderutil"]
