# Maintainer: Christian Hesse <mail@eworm.de>
# Contributor: Eric Bélanger <eric@archlinux.org>

pkgname=links
pkgver=2.29
pkgrel=1
pkgdesc='A text WWW browser, similar to Lynx'
arch=('x86_64')
url='http://links.twibright.com/'
license=('GPL')
depends=('brotli' 'libbrotlidec.so' 'bzip2' 'libbz2.so' 'gpm' 'libgpm.so'
         'libevent' 'openssl' 'xz' 'zstd' 'libzstd.so')
makedepends=('libtiff' 'libpng' 'libxt' 'librsvg')
optdepends=('libx11: for using xlinks'
	    'libtiff: for using xlinks'
	    'libpng: for using xlinks'
	    'librsvg: for using xlinks')
source=("http://links.twibright.com/download/${pkgname}-${pkgver}.tar.bz2"
        'links.desktop')
sha256sums=('22aa96c0b38e1a6f8f7ed9d7a4167a47fc37246097759ef6059ecf8f9ead7998'
            'f96bf2638e9c309bfdb857bd62a732b980231b3a683cd585ec872b249c2c1b19')

configure_options=(
  --prefix=/usr
  --mandir=/usr/share/man
  --disable-javascript
)

prepare() {
  cd ${pkgname}-${pkgver}
  sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" configure
}

build() {
  cd ${pkgname}-${pkgver}
  (cd intl; ./gen-intl; ./synclang)
  ./configure \
    "${configure_options[@]}" \
    --enable-graphics \
    --with-x \
    --with-fb
  make
  mv links xlinks

  ./configure \
    "${configure_options[@]}" \
    --disable-graphics \
    --without-x \
    --without-fb
  make
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install

  install -D -m0755 xlinks "${pkgdir}/usr/bin/xlinks"
  ln -s links.1.gz "${pkgdir}/usr/share/man/man1/xlinks.1.gz"

  install -D -m0644 "${srcdir}/links.desktop" "${pkgdir}/usr/share/applications/links.desktop"
  install -d "${pkgdir}/usr/share/pixmaps"
  install -m0644 links_16x16_1.xpm links_16x16_2.xpm links_32x32.xpm links-48x48.xpm "${pkgdir}/usr/share/pixmaps/"

  install -d "${pkgdir}/usr/share/doc/links/calibration"
  install -m0644 doc/links_cal/* "${pkgdir}/usr/share/doc/links/calibration/"
}
