# Maintainer (Arch ARM): smotocel69 
# Contribuitor (Arch ARM): Georges Discry 
# Maintainer: Isaac David <isacdaavid@at@isacdaavid@dot@info>

pkgname=xf86-video-fbturbo-git
_gitname=xf86-video-fbturbo
pkgver=199.f9a6ed7
pkgrel=3
pkgdesc="X.org MALI video driver"
arch=('armv7h')
url="https://github.com/ssvb/xf86-video-fbturbo"
license=('MIT')
makedepends=('xorg-server-devel' 'X-ABI-VIDEODRV_VERSION=24.0' 'git')
backup=('etc/X11/xorg.conf.d/99-fbturbo.conf')
conflicts=('xorg-server<1.20' 'X-ABI-VIDEODRV_VERSION<24' 'X-ABI-VIDEODRV_VERSION>=25')
options=('!libtool')
provides=('xf86-video-fbturbo')
source=('git+https://github.com/ssvb/xf86-video-fbturbo'
        '0001-Use-own-thunk-functions-instead-of-fbdevHW-Weak.patch'
        '0002-GCC-8-fix.patch'
        '99-fbturbo.conf')
sha256sums=('SKIP'
            '64e13e2beaca64feea8a1f6e052522d80964a39226db4abb4130b3adb53cac6f'
            'a88445ee108183530632818976105aa0c71b40350e004adcc4a40a0f37ae1a1e'
            '9922d04c530c59de833c735baa342c490ed148102c9d418fcb0175f3552b0090')

pkgver() {
  cd "${srcdir}/${_gitname}"
  echo $(git rev-list --count master).$(git rev-parse --short master)
}

prepare() {
  cd "${srcdir}/${_gitname}"
  patch -p1 -i ../0001-Use-own-thunk-functions-instead-of-fbdevHW-Weak.patch
  patch -p1 -i ../0002-GCC-8-fix.patch
}

build() {
  cd "${srcdir}/${_gitname}"

  # Since pacman 5.0.2-2, hardened flags are now enabled in makepkg.conf
  # With them, module fail to load with undefined symbol.
  # See https://bugs.archlinux.org/task/55102 / https://bugs.archlinux.org/task/54845
  export CFLAGS=${CFLAGS/-fno-plt}
  export CXXFLAGS=${CXXFLAGS/-fno-plt}
  export LDFLAGS=${LDFLAGS/,-z,now}

  ./autogen.sh
  ./configure --prefix=/usr
  make
}

package() {
  cd "${srcdir}/${_gitname}"
  install -m755 -d "${pkgdir}/etc/X11/xorg.conf.d"
  install -m644 "${srcdir}/99-fbturbo.conf" "${pkgdir}/etc/X11/xorg.conf.d"
  make DESTDIR="${pkgdir}/" install
  install -m755 -d "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/"
}

