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

github.setup            pmougin F-Script e9aa94f2a5ec3409423f907c9423f7d1d845b893
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
name                    FScript
version                 2.1
revision                2
categories              aqua lang
platforms               darwin
license                 BSD
maintainers             {ciserlohn @ci42}

description             Open-source interactive Cocoa scripting environment
long_description        F-Script is an open-source interactive and scripting \
                        environment for Cocoa.  Based on Smalltalk, F-Script \
                        provides a pure object-oriented environment that \
                        leverages Mac OS X technologies and frameworks.  It \
                        aims to be a useful and fun tool for both beginners \
                        and experts, allowing interactively exploring, testing \
                        and using Cocoa-based objects and frameworks.

checksums               rmd160  bdb19590caa1e8fca0253bf5b287b9046d59bd7d \
                        sha256  e4a793f292d1afab3f6cb699da2d095a76c253eea901bea53cb1aebc5a86f9cc \
                        size    1087478

patchfiles              patch-FScript.xcodeproj-project.pbxproj.diff

xcode.target            FScriptFramework F-Script
xcode.destroot.settings SKIP_INSTALL=NO
xcode.destroot.type     ""

set is_xcode_4_x [expr [vercmp $xcodeversion 4] >= 0]

if {!$is_xcode_4_x} {
    default_variants        +ib_plugin
}

# It is wrong that MacPorts chooses an SDK based on deployment target.
macosx_deployment_target 10.6
compiler.blacklist {clang < 300}

platform darwin 11 {
    if {! [file exists ${configure.sdkroot}]} {
        depends_lib
        depends_run
        pre-fetch {
            ui_error "$name requires the 10.6 SDK to install on Lion."
            error "unsupported platform"
        }
    }
}

platform darwin {
    if {${os.major} >= 12} {
        depends_lib
        depends_run
        pre-fetch {
            ui_error "$name does not build on Mountain Lion or later."
            error "unsupported platform"
        }
    }
}

variant ib_plugin description "Install the Interface Builder Plug-in" {
        xcode.target-append FScriptIBPlugin
        destroot.violate_mtree yes
}

variant injection_service description "Enable F-Script injection service" {
    master_sites-append     http://www.fscript.org/download:injection_service
    distfiles-append        F-ScriptInjectionService.zip:injection_service

    checksums-append        F-ScriptInjectionService.zip \
                            sha1   58436fe48375abdfed6251a2fc2ee2b2a39d6bf1 \
                            rmd160 dd7dbf0580584f14742c5e38a5f59df4bbb5c951

    destroot.violate_mtree  yes
}

pre-configure {
    if {[variant_isset ib_plugin] && $is_xcode_4_x} {
        ui_error "Xcode 4.x does not support Interface Builder plug-ins.\n \
                  Please install ${name} without the Interface Builder plug-in:\n \
                  sudo port install ${name} -ib_plugin"
        return -code error "incompatible xcode version"
    }
}

pre-build {
            reinplace "s|MACPORTS_APP_DIR|${applications_dir}|g" ${worksrcpath}/FScript.xcodeproj/project.pbxproj
            reinplace "s|MACPORTS_FRAMEWORK_DIR|${frameworks_dir}|g" ${worksrcpath}/FScript.xcodeproj/project.pbxproj
}

post-destroot {
        if {[variant_isset ib_plugin]} {
            set ibplugin_dir "${developer_dir}/Platforms/MacOSX.platform/Developer/Library/Interface Builder/Plug-ins"
            xinstall -d -m 755 ${destroot}${ibplugin_dir}
            file rename ${destroot}${applications_dir}/FScriptIBPlugin.ibplugin ${destroot}${ibplugin_dir}
        }

        if {[variant_isset injection_service]} {
            xinstall -d ${destroot}/Library/Services
            file rename "${workpath}/F-ScriptInjectionService/Inject F-Script into application.workflow" ${destroot}/Library/Services/
            reinplace "s|/Library/Frameworks|${frameworks_dir}|g" "${destroot}/Library/Services/Inject F-Script into application.workflow/Contents/document.wflow"
        }
}
