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

PortSystem              1.0
PortGroup               xcode 1.0
PortGroup               github 1.0

github.setup            AquaTerm AquaTerm 1.1.1 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
name                    aquaterm
categories              aqua math science
maintainers             nomaintainer
license                 BSD
description             AquaTerm is a viewer that displays vector graphics on Mac OS X
long_description        AquaTerm is a viewer app that displays vector \
                        graphics.  Other apps connect to AquaTerm using a \
                        simple remote object messaging protocol.  By adding \
                        \"adapters\" to legacy code very little coding is \
                        needed to bring it to OS X.
homepage                http://aquaterm.sourceforge.net/

checksums               rmd160  007db0806a2b1b1263043647035fa428b15560e3 \
                        sha256  8e35cb81f5f024382ba4b2c96569631b34cf798966aa2870258f272e551c0e34

build.dir               ${worksrcpath}/aquaterm

patchfiles              no-NSMailDelivery.patch project-copyfiles.patch

xcode.target            AquaTerm
xcode.configuration     Default

xcode.build.settings    LOCAL_APPS_DIR=${applications_dir} \
                        LOCAL_FRAMEWORKS_DIR=${frameworks_dir}
xcode.destroot.settings LOCAL_APPS_DIR=${applications_dir} \
                        LOCAL_FRAMEWORKS_DIR=${frameworks_dir}
xcode.destroot.type     mixed

post-patch {
    # Try to open the right version of AquaTerm.app.
    # (If incompatible version is installed in /Applications,
    #  we need to make sure that the one from MacPorts is found first.)
    reinplace "s|/Applications/AquaTerm.app|${applications_dir}/AquaTerm.app|" \
        ${worksrcpath}/aquaterm/AQTClientManager.m

    reinplace "s|# FRAMEWORKS_DIR.*|FRAMEWORKS_DIR = ${frameworks_dir}|" \
        ${worksrcpath}/adapters/c/Makefile \
        ${worksrcpath}/adapters/fortran/Makefile

    reinplace "s|/usr/local|${prefix}|g" \
        ${worksrcpath}/adapters/pgplot/ChangeLog \
        ${worksrcpath}/adapters/pgplot/g77_gcc_AQT.conf \
        ${worksrcpath}/adapters/pgplot/xlf_gcc_AQT.conf

    # those are not really needed, it's just cosmetics
    reinplace "s|/*<PREFIX>|${prefix}|g" \
        ${worksrcpath}/adapters/pgplot/g77_cc_AQT.conf \
        ${worksrcpath}/adapters/pgplot/g77_gcc_AQT.conf \
        ${worksrcpath}/adapters/pgplot/xlf_gcc_AQT.conf
    reinplace "s|/sw|${prefix}|g" \
        ${worksrcpath}/adapters/pgplot/ReadMe
}

# this port does not build with the new xcode build system at present
if {[vercmp ${xcodeversion} 10.0] >= 0} {
    build.pre_args      -UseNewBuildSystem=NO
    destroot.pre_args   -UseNewBuildSystem=NO
}

post-destroot {
    xinstall -d -m 0755 ${destroot}${prefix}/share/AquaTerm
    copy ${worksrcpath}/adapters ${destroot}${prefix}/share/AquaTerm
}
