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

pkgname=gsm
pkgver=%version%
pkgrel=%release%
pkgdesc="Shared libraries for GSM 06.10 lossy speech compression"
arch=('x86_64')
url="https://www.quut.com/gsm/"
license=('custom')
depends=('glibc')
source=("https://www.quut.com/$pkgname/$pkgname-$pkgver.tar.gz" gsm-shared.patch gsm-fix-toast-install.patch)
sha512sums=('f4284f096ed4d606ddece5c1b28edb63feacc26a0b664f1350c040dbf50113d27bedfd9896bf1620cb4fc3a6c8f6a5244955a6c625ded833dcee607c63c97dd2'
            '5833f9157ab5adf68b3ad0b6316ec563389fe39dd7b99ee04acc08a32bfccf9f517b9289ce3bfd32e191ab8a4b674c08ea1fbba9411e43c0d44f78f24bf885cd'
            '88f3214e92d4f5b9dae9c5d67073abb36c7889cdcb90a00fb023794ae474c0560d8ea5098ce3e5424a1021fe44cd4f6b91d86c77e4b864fe97b51d69debf0c5d')

prepare() {
  cd $pkgname-${pkgver%.*}-pl${pkgver##*.}

  patch -p0 -i ../gsm-shared.patch
  patch -p0 -i ../gsm-fix-toast-install.patch
}

build() {
  cd $pkgname-${pkgver%.*}-pl${pkgver##*.}

  make CCFLAGS="-c ${CFLAGS} -fPIC"
}

package() {
  cd $pkgname-${pkgver%.*}-pl${pkgver##*.}

  # Prepare directories
  install -m755 -d "$pkgdir"/usr/{bin,lib,include/gsm,share/{licenses/$pkgname,man/man{1,3}}}

  make -j1 INSTALL_ROOT="$pkgdir"/usr \
    GSM_INSTALL_INC="$pkgdir"/usr/include/gsm \
    GSM_INSTALL_MAN="$pkgdir"/usr/share/man/man3 \
    TOAST_INSTALL_MAN="$pkgdir"/usr/share/man/man1 \
    install

  # Install license
  install -m644 COPYRIGHT "$pkgdir"/usr/share/licenses/$pkgname/license.txt
}
