pkgname=binutils
pkgver=2.45
pkgdesc='A set of programs to assemble and manipulate binary and object files'
homepage='https://www.gnu.org/software/binutils/'
license=(GPL-2.0-or-later GPL-3.0-or-later LGPL-2.0-or-later LGPL-3.0-or-later GFDL-1.3 FSFAP)
sources=("${pkgname}-${pkgver}.tar.xz")
urls=("https://sourceware.org/pub/binutils/releases/${sources[0]}")
md5sums=("dee5b4267e0305a99a3c9d6131f45759")


src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  mkdir -v build
  cd       build
}

src_build() {
  ../configure --prefix=/usr                           \
               --sysconfdir="${pkgdir}"/etc            \
               --enable-gold                           \
               --enable-ld=default                     \
               --enable-plugins                        \
               --enable-shared                         \
               --disable-werror                        \
               --enable-64-bit-bfd                     \
               --enable-new-dtags                      \
               --with-system-zlib                      \
               --enable-default-hash-style=gnu
  make tooldir=/usr
}

src_check() {
  make -k CFLAGS_FOR_TARGET="-O2 -g" \
    CXXFLAGS="-O2 -no-pie -fno-PIC" \
    CFLAGS="-O2 -no-pie" \
    LDFLAGS="" \
    check
}

src_install() {
  make prefix="${pkgdir}"/usr tooldir="${pkgdir}"/usr install
  rm -fv "${pkgdir}"/usr/lib/lib{bfd,ctf,ctf-nobfd,gprofng,opcodes,sframe}.a
}
