# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('libtool' 'libltdl')
pkgver=2.4.7
_gccver=11.2.0
pkgrel=3
pkgdesc="A generic library support script"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/libtool/"
license=('spdx:GPL-2.0-or-later')
makedepends=("gcc>=${_gccver}" 'autotools' 'help2man')
source=(https://ftp.gnu.org/pub/gnu/libtool/${pkgname}-${pkgver}.tar.xz{,.sig}
        #https://alpha.gnu.org/gnu/libtool/${pkgname}-${pkgver}.tar.xz{,.sig}
        #${pkgname}-${pkgver}::git+https://git.savannah.gnu.org/git/libtool.git
        0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch
        0003-Pass-various-runtime-library-flags-to-GCC.mingw.patch
        0005-Fix-seems-to-be-moved.patch
        0006-Fix-strict-ansi-vs-posix.patch
        0007-fix-cr-for-awk-in-configure.all.patch
        0009-libtool-2.4.2.418-msysize.patch
        0010-libtool-2.4.2-include-process-h.patch
        0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch
        0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch
        0013-Allow-statically-linking-compiler-support-libraries-.patch
        0014-Support-llvm-objdump-f-output.patch
        0015-Allow-statically-linking-Flang-support-libraries.patch)
sha256sums=('4f7f217f057ce655ff22559ad221a0fd8ef84ad1fc5fcb6990cecc333aa1635d'
            'SKIP'
            'fe8b80efd34f9385220ebc90aaec945e44de8c343c75719d6ac0d4e472a6eed5'
            '37d46a7964cf56617b897feb566537d847dee5e8f53e4771255d3cccf722918d'
            'dc39fbe066958178f96108f07db62b48b9339efddf2c21f800ff8d67110ca393'
            '6a94ada08b0a0aa36240efd9ccb826e22ab94ef0969270f2edb8be344dc8c62b'
            'd96beecfc5d15f94ce46bbe0e89d6e6fdb973a25ad6be98c30504b58453792c1'
            '1a858a13592a1a5bd56ae3c4e610408ca19ec9d318ebdfd96bebcfc585b2924f'
            '0f3defa657d353b9f55469f6d514abd96494ce7459ef76bbd63980d8994cafe9'
            'c727b2b017163cfdeca60820d3cff2dac8968c5630745602b150f92b159af313'
            'c95a65e890b1ae6362807abc66809e72cf81aeea5f9f556e38f9752f974bf435'
            '8069e887aeeab7491f15e00547fa66d9b9e86407f5a23f37a6d8c7d165de752e'
            'db16cd322e0ebc578c906e94b0788810af17ce617c700a50db2e3c598dbbed7e'
            '9fe454603a519e9ac50b32de125d4c5293520142c34a895c6e392a190719ff52')

 validpgpkeys=('CFE2BE707B538E8B26757D84151308092983D606'  # Gary Vaughan (Free Software Developer) <gary@vaughan.pe>
               '7C5FBB96BE82B954AC20DF5F6EAC957F8EEB55C0') # Alex Ameen <alex.ameen.tx@gmail.com>

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd ${srcdir}/${pkgbase}-${pkgver}

  apply_patch_with_msg \
    0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch \
    0003-Pass-various-runtime-library-flags-to-GCC.mingw.patch \
    0005-Fix-seems-to-be-moved.patch \
    0006-Fix-strict-ansi-vs-posix.patch \
    0007-fix-cr-for-awk-in-configure.all.patch \
    \
    0009-libtool-2.4.2.418-msysize.patch \
    0010-libtool-2.4.2-include-process-h.patch \
    0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch \
    0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch \
    0013-Allow-statically-linking-compiler-support-libraries-.patch \
    0014-Support-llvm-objdump-f-output.patch \
    0015-Allow-statically-linking-Flang-support-libraries.patch

}

build() {
  cd ${srcdir}/${pkgbase}-${pkgver}
  ./configure --prefix=/usr lt_cv_sys_lib_dlsearch_path_spec="/usr/lib /lib"
  make -j1
}

check() {
  cd ${srcdir}/${pkgbase}-${pkgver}
  timeout 15m make check || warning "Tests failed"
}

package_libtool() {
  depends=('sh' "libltdl=${pkgver}" 'tar')

  cd ${srcdir}/${pkgbase}-${pkgver}

  make DESTDIR=${pkgdir} install-binSCRIPTS install-man install-info \
                         install-data-local
}

package_libltdl() {
  pkgdesc="A system independent dlopen wrapper for GNU libtool"
  options=('staticlibs')

  cd ${srcdir}/${pkgbase}-${pkgver}
  make DESTDIR=${pkgdir} install-libLTLIBRARIES install-includeHEADERS \
                         install-ltdlincludeHEADERS

  install -Dm644 "${srcdir}/${pkgbase}-${pkgver}/COPYING" "${pkgdir}/usr/share/licenses/${pkgbase}/COPYING"
}
