# Maintainer (Arch): Eric Bélanger <eric@archlinux.org>
# Maintainer (Hyperbola): André Silva <emulatorman@hyperbola.info>
# Contributor (Hyperbola): Márcio Silva <coadde@hyperbola.info>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>

pkgname=memtest86+
pkgver=5.01
pkgrel=3
pkgrel+=.par1
pkgdesc="An advanced memory diagnostic tool"
arch=('x86_64' 'i686')
url="http://www.memtest.org"
license=('GPL2')
makedepends_x86_64=('gcc-multilib' 'lib32-glibc')
source=("http://www.memtest.org/download/${pkgver}/${pkgname}-${pkgver}.tar.gz"
        '60_memtest86+'
        'doc-serialconsole.patch'
        'multiboot.patch'
        "${pkgname}-5.01-O0.patch"
        "${pkgname}-5.01-array-size.patch"
        'gcc-5.patch'
        'memtest86+-5.01-test-random-cflags.patch')
sha256sums=('142127b7953fbd829b1057fb64a78d3340c2b771484230a7347e94530a0d9039'
            'e500a8ccd812a64d90f32b7af9ed28a761f7c7f475104cc26e006696a1247a14'
            '58a25113af7346dcde4d0dc46568b620f88a21b140e088aa87ecd695a45f02e2'
            'beee4632ea70e3075a62699aedb654f4cb2f794a1adbe25c20ab4075c008065b'
            '82f2203d5a51a10ed106df304edfd9a8b89259b90e53b4796720bb80ad1ab2f6'
            '6b0607921c15624e3cfe299e07255bfee5e2683e97a0e443d2230ca3ddfdb47b'
            '4c07128e0fc14e5850f8744561115d43e946c46742d74d3a0c726164b5f1ae8f'
            '53f50ee7b803c21159731fb5920e524b1dd7884d60eeeb51851020754400baa4')

prepare() {
  cd ${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/doc-serialconsole.patch
  patch -p1 -i ${srcdir}/multiboot.patch
  patch -p1 -i ${srcdir}/${pkgname}-5.01-O0.patch
  patch -p1 -i ${srcdir}/${pkgname}-5.01-array-size.patch
  patch -p1 -i ${srcdir}/gcc-5.patch
  patch -p1 -i ${srcdir}/memtest86+-5.01-test-random-cflags.patch
  sed -i 's|CC[=]gcc|CC=gcc -I/usr/include|
          s|[-]fno[-]stack[-]protector|-fno-stack-protector -fno-aggressive-loop-optimizations|
          \|scp memtest[.]bin|d
         ' Makefile
}

build() {
  cd ${pkgname}-${pkgver}
  make
}

package() {
  cd ${pkgname}-${pkgver}
  install -D -m644 ${pkgname%86+}.bin ${pkgdir}/boot/memtest86+/${pkgname%86+}.bin
  install -D -m755 ${srcdir}/60_memtest86+ ${pkgdir}/etc/grub.d/60_memtest86+
}
