# -*- 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

name                    mingw-w64-pkgconfig
version                 0.0.2
categories              cross
maintainers             {@gcenx}

supported_archs         noarch
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.

if {${subport} eq ${name}} {
    PortGroup           stub 1.0
    depends_run         port:i686-w64-mingw32-pkgconfig \
                        port:x86_64-w64-mingw32-pkgconfig

    post-deactivate {
        # When this port is deactivated, i686-w64-mingw32-pkgconfig should also be.
        if {![catch {set installed [lindex [registry_active i686-w64-mingw32-pkgconfig] 0]}]} {
            registry_deactivate_composite i686-w64-mingw32-pkgconfig "" [list ports_nodepcheck 1]
        }

        # When this port is deactivated, x86_64-w64-mingw32-pkgconfig should also be.
        if {![catch {set installed [lindex [registry_active x86_64-w64-mingw32-pkgconfig] 0]}]} {
            registry_deactivate_composite x86_64-w64-mingw32-pkgconfig "" [list ports_nodepcheck 1]
        }
    }
}

subport i686-w64-mingw32-pkgconfig {
    set mingw_target    i686-w64-mingw32
}

subport x86_64-w64-mingw32-pkgconfig {
    set mingw_target    x86_64-w64-mingw32
}

distfiles
patchfiles
use_configure           no
depends_run             path:bin/pkg-config:pkgconfig

build {}

destroot {
    set pkg [open "${destroot}${prefix}/bin/${mingw_target}-pkg-config" w 0755]
    puts ${pkg} "#!/bin/sh"
    puts ${pkg} "export PKG_CONFIG_LIBDIR=${prefix}/${mingw_target}/lib/pkgconfig:${prefix}/${mingw_target}/share/pkgconfig"
    puts ${pkg} "export PKG_CONFIG_PATH=\$\{PKG_CONFIG_PATH_CUSTOM\}:${prefix}/${mingw_target}/lib/pkgconfig:${prefix}/${mingw_target}/share/pkgconfig\}"
    puts ${pkg} "${prefix}/bin/pkg-config \$\{\@\}"
    close ${pkg}
}
