# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Andreas Hauser <andy-aur@splashground.de>

_langs=(afr amh ara asm aze aze_cyrl bel ben bod bos bre bul cat ceb ces
    chi_sim chi_tra chr cos cym dan dan_frak deu deu_frak div dzo ell eng enm epo
    equ est eus fao fas fil fin fra frk frm fry gla gle glg grc guj hat heb
    hin hrv hun hye iku ind isl ita ita_old jav jpn jpn_vert kan kat kat_old kaz khm
    kir kmr kor kor_vert lao lat lav lit ltz mal mar mkd mlt mon mri msa
    mya nep nld nor oci ori pan pol por pus que ron rus san sin slk
    slk_frak slv snd spa spa_old sqi srp srp_latn sun swa swe syr tam tat
    tel tgk tgl tha tir ton tur uig ukr urd uzb uzb_cyrl vie yid yor)

pkgname=tesseract
pkgver=5.4.1
pkgrel=1.1
pkgdesc='An OCR program'
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://github.com/tesseract-ocr/tesseract"
license=('APACHE')
depends=(gcc-libs curl libarchive leptonica)
makedepends=(icu pango asciidoc)
optdepends=('icu: for text2image'
            'pango: for text2image')
for _lang in "${_langs[@]}"; do
  optdepends+=("${_lang/#/tesseract-data-}: OCR data ($_lang)")
done
provides=(libtesseract.so)
source=("$url/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('c4bc2a81c12a472f445b7c2fb4705a08bd643ef467f51ec84f0e148bd368051b')

build() {
  cd "$srcdir"/$pkgname-${pkgver}
  [ -x configure ] || ./autogen.sh
  [ -f Makefile ] || ./configure --prefix=/usr
  make
  make training
}

package() {
  # The virtual package 'tessdata' is provided by all of the packaged language
  # packs. All languages are listed as optdepends but at least one is required
  # for basic functionality. These are in package() so they do not turn up in
  # makedepends=() where they would be circular.
  depends+=(tessdata tesseract-data-osd)
  cd "$srcdir"/$pkgname-${pkgver}
  make DESTDIR="$pkgdir" install
  make DESTDIR="$pkgdir" training-install
}
