# 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=10.03.03
pkgrel=2
pkgdesc='A program maintenance (make) utility using a C-like grammar'
arch=('x86_64' 'aarch64')
url='https://fbb-git.gitlab.io/icmake/'
license=('AGPL-3.0-or-later')
source=("https://gitlab.com/fbb-git/${pkgname}/-/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz"
        'disable-clear-screen.patch'
        'icmake-10.03.03-1-cstdint.patch')
b2sums=('4711dee5d66882afeeb6e7206b97341690e2e1c0e511fcf9f43d41ec04bec2ecf5fee10113bba47475b3166dc8dc53f7b236c42dcf0969582a59bbf30b7ca618'
        '6689ce74a985742e079f95bfaa22dcee22ad667f45cf21f79d4c3d2271f925f53bcd6729ca762a7cfa6a63af9b0fd48c2b9c024bd35ca580e83a6a54758a7bed'
        '8c80ee554855f3466ad89006a6d5f73413f069c456be47cf40bd50586de95bbb3a0f253a0aca99953e58cd27f1be5f076ecc3c9778d2f56997bdba8cc83591a5')
makedepends=('icmake' 'yodl')
depends=('libbobcat' 'libunwind')

prepare() {
    cd "${srcdir}/${pkgname}-${pkgver}"
    patch -Np1 -i "${srcdir}/disable-clear-screen.patch"
    patch -Np1 -i "${srcdir}/icmake-10.03.03-1-cstdint.patch"

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

    # for some reason we have to do this
    sed -e '/verbinclude(\/home\/frank\/.icmake\/AUTHOR)/d' -i icmake/doc/manpage/icmconf.yo
    export AUTHOR="Frank B. Brokken (f.b.brokken@rug.nl)"
    echo "${AUTHOR}" > AUTHOR
}

build() {
    cd "${srcdir}/${pkgname}-${pkgver}"
    # when upgrading to new SONAME, remove ./manpages from HOME variable
    # to allow compiling the package without invoiking icmake itself
    HOME=./ ./manpages

    cd "${srcdir}/${pkgname}-${pkgver}/${pkgname}"

    export CXXFLAGS="${CXXFLAGS} -Wp,-U_GLIBCXX_ASSERTIONS -std=c++20"

    ./icm_prepare /
    ./icm_bootstrap /
}

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

    ./icm_install all "${pkgdir}"
}
