# -*- 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           compilers 1.0
PortGroup           github 1.0

github.setup        fortran-lang fpm 0.11.0 v
revision            0
categories          devel fortran
license             MIT
maintainers         nomaintainer
description         Fortran Package Manager
long_description    Fortran Package Manager (fpm) is a package manager and build system for Fortran. \
                    Its key goal is to improve the user experience of Fortran programmers. \
                    It does so by making it easier to build your Fortran program or library, \
                    run the executables, tests and examples, and distribute it as a dependency \
                    to other Fortran projects.
homepage            https://fpm.fortran-lang.org
checksums           rmd160  70165608dc38e5b72ff8cdccaaa5d58edf6c4225 \
                    sha256  46eeda5e5fa56307d51e30aee556da732d4ed43253dbcf520bac9a6c6cf0dabd \
                    size    263484
github.tarball_from archive

depends_build-append \
                    port:curl

if {${os.platform} eq "darwin" && ${os.major} < 13} {
    # Lion+ (with Xcode 4.1+) have git; earlier need to bring their own.
    # On 10.8.5 git fetch fails with ssl error.
    depends_build-append    port:git
    git.cmd                 ${prefix}/bin/git
}

patchfiles          patch-install.diff

post-patch {
    reinplace "s,@FC@,${configure.fc}," ${worksrcpath}/install.sh
    reinplace "s,@PREFIX@,${worksrcpath}${prefix}," ${worksrcpath}/install.sh

    file attributes ${worksrcpath}/install.sh -permissions +x
}

# Xcode clang of 10.7 fails with error: invalid instruction mnemonic 'cvtsi2ssl'
compiler.blacklist-append \
                    {clang < 500} {*gcc-[34].*} {macports-gcc-[56]}
compilers.setup     require_fortran

use_configure       no

build.cmd           ${worksrcpath}/install.sh
build.target
build.cmd-prepend   FPM_CFLAGS="${configure.cflags} [get_canonical_archflags cc]" \
                    FPM_LDFLAGS="${configure.ldflags} [get_canonical_archflags ld]"

destroot {
    xinstall -d -m 0755 ${destroot}${prefix}/bin
    copy ${worksrcpath}${prefix}/bin/${name} ${destroot}${prefix}/bin/
}
