# Maintainer: Martchus <martchus@gmx.net>

# All my PKGBUILDs are managed at https://github.com/Martchus/PKGBUILDs where
# you also find the URL of a binary repository.

# set the web view provider: either webkit, webengine, auto or none
_webview_provider=${TAGEDITOR_WEBVIEW_PROVIDER:-none}

# set the JavaScript provider: either script, qml, auto or none
_js_provider=${TAGEDITOR_JS_PROVIDER:-qml}

# whether the Qt GUI is enabled: ON or OFF
_qt_gui=${TAGEDITOR_QT_GUI:-ON}

# whether the experimental JSON export is enabled: ON or OFF
_json_export=${TAGEDITOR_JSON_EXPORT:-OFF}

_reponame=tageditor
pkgname=static-compat-tageditor
_name=${pkgname#static-compat-}
pkgver=3.9.11
pkgrel=1.1
arch=('i686' 'x86_64' 'armv6h' 'armv7h' 'aarch64')
pkgdesc='A tag editor with Qt GUI and command-line interface supporting MP4/M4A/AAC (iTunes), ID3, Vorbis, Opus, FLAC and Matroska'
license=(GPL-2.0-or-later)
depends=('static-compat-c++utilities' 'static-compat-openssl')
[[ $_webview_provider == none ]] && [[ $_js_provider == none ]] && [[ $_qt_gui == ON ]] && depends+=('static-compat-qt6-base')
[[ $_webview_provider == webkit ]] && depends+=('static-compat-qt6-webkit')
[[ $_webview_provider == webengine ]] && depends+=('static-compat-qt6-webengine')
[[ $_js_provider == script ]] && depends+=('static-compat-qt6-script')
[[ $_js_provider == qml ]] && depends+=('qt6-declarative')
makedepends=('static-compat-cmake'  'static-compat-tagparser' 'ninja')
[[ $_json_export == ON ]] && makedepends+=('reflective-rapidjson')
[[ $_qt_gui == ON ]] && makedepends+=('static-compat-qtutilities' 'static-compat-qt6-svg' 'static-compat-qt6-wayland' 'static-compat-qt6-tools' 'static-compat-qt6-translations' 'breeze-icons' 'clang')
checkdepends=('static-compat-cppunit' 'jq')
url="https://github.com/Martchus/${_reponame}"
source=("${_name}-${pkgver}.tar.gz::https://github.com/Martchus/${_reponame}/archive/v${pkgver}.tar.gz")
sha256sums=('ccb04b41cae2455852839bdaef94456fadc4254619b97a8736f71a0b031dcffe')

build() {
  check_buildoption ccache y && ccache_args='
    -DCMAKE_C_COMPILER_LAUNCHER=ccache
    -DCMAKE_CXX_COMPILER_LAUNCHER=ccache'
  export CXXFLAGS+=' -static-libgcc -static-libstdc++'
  export LDFLAGS+=' -static-libgcc -static-libstdc++'
  source static-compat-environment
  export PATH=$PWD:$PATH
  printf '#!/usr/bin/bash\nexec /usr/bin/pkg-config --static "$@"\n' > pkg-config
  chmod +x pkg-config
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame-$pkgver}"

  static-compat-cmake -G Ninja \
    $ccache_args \
    -DCMAKE_SKIP_INSTALL_RPATH=ON \
    -DQT_PACKAGE_PREFIX:STRING='Qt6' \
    -DBUILTIN_TRANSLATIONS:BOOL=ON \
    -DBUILTIN_TRANSLATIONS_OF_QT:BOOL=ON \
    -DWEBVIEW_PROVIDER="${_webview_provider}" \
    -DJS_PROVIDER="${_js_provider}" \
    -DBUILTIN_ICON_THEMES:STRING='breeze;breeze-dark' \
    -DIMAGE_FORMAT_SUPPORT:STRING='Gif;ICO;Jpeg' \
    -DSVG_SUPPORT:BOOL=ON \
    -DSVG_ICON_SUPPORT:BOOL=ON \
    -DBoost_USE_STATIC_RUNTIME:BOOL=ON \
    -DGLIB2_USE_PKG_CONFIG:BOOL=ON \
    -DWAYLAND_USE_PKG_CONFIG:BOOL=ON \
    -DCMAKE_DISABLE_FIND_PACKAGE_harfbuzz=TRUE \
    -DSETUP_TOOLS:BOOL=ON \
    -DINJECT_ENV_LIST:STRING=OPENSSL_CONF= \
    .
  ninja
}

check() {
  source static-compat-environment
  export PATH=$PWD:$PATH
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame-$pkgver}"
  if [[ $TEST_FILE_PATH ]]; then
    ninja check
  else
    msg2 'Skipping execution of testsuite because the environment variable TEST_FILE_PATH is not set.'
  fi
}

package() {
  source static-compat-environment
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame-$pkgver}"
  DESTDIR="${pkgdir}" ninja install
}
