# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Anatol Pomozov <anatol.pomozov@gmail.com>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>

pkgbase=gdb
# gdb-common is a package that contains files common for all cross compiled versions
# of gdb (for arm/avr/...)
pkgname=(gdb gdb-common)
pkgver=15.1
pkgrel=1.1
pkgdesc='The GNU Debugger'
url='https://www.gnu.org/software/gdb/'
license=(GPL3)
ncxfab_makedepends=(base-devel texinfo boost)
ncxfat_makedepends=(glibc gcc-libs guile ncurses expat xz mpfr readline binutils)
source=(https://ftp.gnu.org/gnu/gdb/${pkgname}-${pkgver}.tar.xz{,.sig})
sha1sums=('2b4e9357e498c66bbedf791883569104edea0472'
          'SKIP')
b2sums=('e05133a9f98a1a00cbfb49294f534e3b8830b48ac9526af3312a3b9a0381e0e652bc3f5fdc8528ceb16c890529cefbd7745bed97298a1fecb64c726d09c8aacb'
        'SKIP')
validpgpkeys=('F40ADB902B24264AA42E50BF92EDB04BFF325CF3') # Joel Brobecker
options=(!lto)

build() {
  cd gdb-$pkgver

  mkdir -p build && cd build
  ../configure \
    --prefix=$MPKG_USRPATH \
    --host=$MPKG_TARGETMACHINE \
    --disable-nls \
    --disable-source-highlight \
    --enable-tui \
    --enable-targets=all \
    --enable-languages=all \
    --enable-multilib \
    --enable-interwork \
    --with-system-readline \
    --with-libexpat-prefix=$MPKG_BUILDSYSROOT \
    --with-python=no \
    --with-system-gdbinit=$MPKG_ETCPATH/gdb/gdbinit
  make -j$(nproc)
}

package_gdb-common() {
  depends=(guile)

  cd gdb-$pkgver/build
  make -C gdb/data-directory DESTDIR="$pkgdir" install
}

package_gdb() {
  #ncxfah_depends=(source-highlight)
  ncxfat_depends=(glibc ncurses libncursesw.so gcc-libs expat xz mpfr gdb-common=$pkgver
           readline libreadline.so guile libelf)
  backup=($MPKG_BACKUPETCPATH/gdb/gdbinit)

  cd gdb-$pkgver/build
  make -C gdb DESTDIR="$pkgdir" install
  make -C gdbserver DESTDIR="$pkgdir" install

  # install "custom" system gdbinit
  install -dm 755 "$pkgdir$MPKG_ETCPATH/gdb"
  touch "$pkgdir$MPKG_ETCPATH/gdb/gdbinit"

  # comes from gdb-common
  rm -r "$pkgdir$MPKG_USRPATH/share/gdb/"
}

# vim: ts=2 sw=2 et:
