# Maintainer: Giancarlo Razzolini <grazzolini@archlinux.org>
# Maintainer: Frederik Schwan <freswa at archlinux dot org>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: judd <jvinet@zeroflux.org>

# NOTE: requires rebuilt with each new gcc version

pkgname=libtool
pkgver=2.4.7+83+g7b091831
_commit=7b0918310776395e1cbafe6a08b8df8f8a8a3e21
pkgrel=1
_gccver=14.1.1
pkgdesc='A generic library support script'
arch=(x86_64 aarch64)
url='https://www.gnu.org/software/libtool'
license=(GPL)
depends=(sh tar glibc)
makedepends=("gcc>=$_gccver" git help2man)
checkdepends=(gcc-fortran)
provides=("libltdl=$pkgver" "libtool-multilib=$pkgver")
conflicts=(libltdl libtool-multilib)
replaces=(libltdl libtool-multilib)
source=(
  git+https://https.git.savannah.gnu.org/git/libtool.git#commit=$_commit
  git+https://https.git.savannah.gnu.org/git/gnulib.git
  gnulib-bootstrap::git+https://github.com/gnulib-modules/bootstrap.git
  disable-lto-link-order2.patch
)
b2sums=('4609c9a44262e2ae1133eb62609c2dba06629ae77cfad1746dd086f02f85cdde43bde96dcd1113aac03ddc103c43f4ba5cf44c6390f56e20544433f6b2a5abd8'
        'SKIP'
        'SKIP'
        '9d1e0460b9ef56ba33ac498814b409d1b1d7c3e8ed41a3aed2a86d86341ed7051ca88a5adfa92bd87da968460514230058c3d490b58537d95722e68d7d1687ff')

pkgver() {
  cd libtool
  git describe --tags | sed 's/-/+/g;s/^v//'
}

prepare() {
  cd libtool

  # test 67 is broken with lto
  # this patch removes the -flto flag for this very test
  # adapt when -ffat-lto-objects is enabled by Arch
  patch -Np1 -i "${srcdir}"/disable-lto-link-order2.patch

  git submodule init
  git config --local submodule.gnulib.url "${srcdir}"/gnulib
  git config --local submodule.gl-mod/bootstrap.url "${srcdir}"/gnulib-bootstrap
  git -c protocol.file.allow=always submodule update

  ./bootstrap
}

build() {
  cd libtool
  ./configure --prefix=/usr lt_cv_sys_lib_dlsearch_path_spec="/usr/lib /usr/lib32"
  make
}

check() {
  cd libtool
  make check gl_public_submodule_commit=
}

package() {
  cd libtool
  make DESTDIR="$pkgdir" install
}
