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

name                gts
set                 snapshot 121130
version             0.7.6-20${snapshot}
revision            1
categories          math
platforms           darwin
maintainers         {ryandesign @ryandesign} openmaintainer
license             LGPL-2+

description         The GNU Triangulated Surface library

long_description    GTS stands for the GNU Triangulated Surface Library. \
                    It is an Open Source Free Software Library intended \
                    to provide a set of useful functions to deal with \
                    3D surfaces meshed with interconnected triangles.

homepage            http://gts.sourceforge.net/
distname            ${name}-snapshot-${snapshot}
master_sites        http://gts.sourceforge.net/tarballs

checksums           rmd160  24b3c469d5a35b658825eb342ae03e9e9d93afb8 \
                    sha256  c23f72ab74bbf65599f8c0b599d6336fabe1ec2a09c19b70544eeefdc069b73b \
                    size    880569

depends_build       port:pkgconfig

depends_lib         path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:libnetpbm

test.run            yes
test.target         check
post-extract {
    # test files do not have the correct permissions
    foreach file [glob ${worksrcpath}/test/**/*.sh] {
        file attributes ${file} -permissions +x
    }
}

if {${universal_possible} && [variant_isset universal]} {
    # Find architectures which will not run on build platform.
    if {${os.major} >= 9 && [sysctl hw.cpu64bit_capable] == 1} {
        set cpu64bit_capable yes
    } else {
        set cpu64bit_capable no
    }
    if {${os.arch} eq "i386"} {
        set cross_archs "ppc64"
        if {${os.major} >= 11} {
            set cross_archs "ppc ${cross_archs}"
        }
        if {!${cpu64bit_capable}} {
            set cross_archs "x86_64 ${cross_archs}"
        }
    } else {
        set cross_archs "i386 x86_64"
        if {!${cpu64bit_capable}} {
            set cross_archs "ppc64 ${cross_archs}"
        }
    }
    
    post-configure {
        system -W ${worksrcpath}-${build_arch}/src "MACOSX_DEPLOYMENT_TARGET=${macosx_deployment_target} ${build.cmd} predicates_init"
        foreach arch ${cross_archs} {
            if {[file exists ${worksrcpath}-${arch}/src/Makefile]} {
                reinplace "s|\\./predicates_init|${worksrcpath}-${build_arch}/src/predicates_init|" \
                    ${worksrcpath}-${arch}/src/Makefile
            }
        }
    }
}

platform darwin arm {
    depends_build-append    port:automake

    post-patch {
        # Use newer config.guess and config.sub to support Apple Silicon.
        set automake_dirs [glob -directory ${prefix}/share automake-*]
        set automake_dir [lindex [lsort -command vercmp $automake_dirs] end]
        copy -force ${automake_dir}/config.guess ${automake_dir}/config.sub \
            ${worksrcpath}
    }
}

livecheck.regex     {gts-snapshot-(\d+(?:\.\d+)*)}
livecheck.version   ${snapshot}
