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

github.setup        fortran-lang fpm 0.10.1 v
revision            0
categories          devel fortran
license             MIT
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
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  c27064b9afdbcf8add3eeaaad7bc7da3a21f094c \
                    sha256  835db9ea28b2983b5db3e71de8e8530ac0d3f63c4e1bd99d4253fe40e7c817cb \
                    size    252512
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
}

# https://github.com/fortran-lang/fpm/issues/1059
# Drop this block upon the next release. Also drop it from fortran PG.
compiler.blacklist-append \
                        macports-gcc-14
if {${os.platform} ne "darwin" || ${os.major} > 9} {
    default_variants    +gcc13
}

# 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/
}