# Maintainer: Konstantin Gizdov <arch at kge dot pw>
# Contributor: Baptiste Jonglez <archlinux at bitsofnetworks.org>
# Contributor: Christian Hesse <mail@eworm.de>
# Contributor: Andreas Wagner <andreas.wagner@lowfatcomputing.org>
# Contributor: Jeff Mickey <jeff@archlinux.org>

pkgname=icmake
pkgver=13.00.02
pkgrel=1
pkgdesc='A program maintenance (make) utility using a C-like grammar'
arch=('x86_64' 'aarch64')
url='https://fbb-git.gitlab.io/icmake/'
license=('GPL-3.0-or-later')
source=("https://gitlab.com/fbb-git/${pkgname}/-/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz"
        icmake-13.02.00-restore-IFS.patch
        icmake-13.02.00-missing-CXXFLAGS.patch)
b2sums=('625dfc3bde3d822fa4e763296beded3703d6cb1860cade87c60c4724d387360802538f39b2328e26d8918654a04fb3387e10295dbd8603706927000ec17f8ed4'
        '8bfcd05bed40ec8c7da79f11160a768e30c870d0a72d64e03bad6c6d794131eb2d4f8ef71b21695f774ec261e70f7098d54a33144d7e9dc46ee048c0a44131d8'
        '7a8e26e68ab22f24d7e16bd1435d960005b23efbe3f05f2cad0e8c88156eefc2f7d1d0a38fc18b2be642cd922a1dc6004e43aece6b0cfa5335cced268a9cf933')
depends=('libunwind')

prepare() {
    cd "${srcdir}/${pkgname}-${pkgver}"

    # https://gitlab.com/fbb-git/icmake/-/issues/9
    # Restore IFS to stop LDFLAGS being treated as a single option
    patch -Np1 -i ../icmake-13.02.00-restore-IFS.patch
    # https://gitlab.com/fbb-git/icmake/-/issues/12
    # Add CXXFLAGS missing from two g++ invocations
    patch -Np1 -i ../icmake-13.02.00-missing-CXXFLAGS.patch

    # fix paths
    sed -i 's|usr/libexec/icmake|usr/lib/icmake|' icmake/INSTALL.im

    # https://gitlab.com/fbb-git/icmake/-/issues/10
    # broken custom LIBDDIR support in ./install
    sed -i 's|tmp${LIBDIR}|tmp/usr/libexec/icmake|' icmake/install
}

build() {
    cd "${srcdir}/${pkgname}-${pkgver}/${pkgname}"

    CXXFLAGS="${CXXFLAGS/ -Wp,-D_GLIBCXX_ASSERTIONS/} -std=c++26"

    ./prepare /
    ./buildlib /
    ICMAKE_CPPSTD="-std=c++26" ./build all
}

package() {
    cd "${srcdir}/${pkgname}-${pkgver}/${pkgname}"

    ./install all "${pkgdir}"
}
