# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           clang_dependency 1.0
PortGroup           conflicts_build 1.0

name                pkgconfig
version             0.29.2
categories          devel
maintainers         {ryandesign @ryandesign}
license             GPL-2+
installs_libs       no
homepage            https://pkg-config.freedesktop.org/
master_sites        ${homepage}releases/
distname            pkg-config-${version}
platforms           darwin freebsd linux
use_parallel_build  yes
conflicts           pkgconf

description         pkg-config, a system for managing library compile and \
                    link flags

long_description    The pkg-config program is used to retrieve information \
                    about installed libraries in the system. It is typically \
                    used to compile and link against one or more libraries.

checksums           rmd160  31e6a17810893d95fd33967c2e433beb2175cd8a \
                    sha256  6fc69c01688c9458a57eb9a1664c9aba372ccda420a02bf4429fe610e7e7d591 \
                    size    2016830

depends_lib         port:libiconv

patchfiles          patch-glib-configure.diff \
                    patch-glib-glib-gmessages.c.diff

set docdir          ${prefix}/share/doc/${name}

# Also needed by later clangs.
if {${os.platform} eq "darwin" && ${os.major} < 11 && ${cxx_stdlib} eq "libc++"} {
    clang_dependency.extra_versions 3.7
}

conflicts_build     libuuid

# garray.c:1808: internal compiler error: Abort trap
compiler.blacklist-append  *llvm-gcc-4.2

configure.args      --disable-silent-rules \
                    --disable-host-tool \
                    --with-internal-glib \
                    --docdir=${docdir}

configure.args-append       --with-pc-path=${prefix}/lib/pkgconfig:${prefix}/share/pkgconfig

# See https://github.com/spack/spack/issues/6962#issuecomment-359020851
# error GNU libiconv not in use but included iconv.h is from libiconv
# pkgconfig builds if libiconv isn't available during the configure phase
# If libiconv is available, the build will fail without --with-libiconv=gnu
platform linux {
    depends_lib
    if {![catch {registry_active libiconv}]} {
        configure.args-append   --with-libiconv=gnu
    }
}

configure.env-append       PKG_CONFIG=false

post-configure {
    system "ed - ${worksrcpath}/glib/config.h < ${filespath}/glib-config.h.ed"
}

test.run            yes
test.target         check

destroot.keepdirs   ${destroot}${prefix}/lib/pkgconfig ${destroot}${prefix}/share/pkgconfig

post-destroot {
    xinstall -m 644 -W ${worksrcpath} \
        AUTHORS \
        COPYING \
        NEWS \
        README \
        ${destroot}${docdir}
}

if {(${os.platform} eq "darwin" && ${os.major} >= 23) || [string match macports-clang-1* ${configure.compiler}]} {
    # error: incompatible integer to pointer conversion
    # https://gitlab.freedesktop.org/pkg-config/pkg-config/-/issues/81
    # Not sure which compilers support this flag but clang 10 does.
    configure.cflags-append -Wno-error=int-conversion
}

livecheck.type      regex
livecheck.url       "${homepage}releases/?C=M&O=D"
livecheck.regex     pkg-config-(\[0-9.\]+)\\.tar
