# -*- 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
# $Id: Portfile 92670 2012-05-03 14:47:00Z ciserlohn@macports.org $

PortSystem              1.0
PortGroup               xcode 1.0

name                    FScript
version                 2.1
revision                1
categories              aqua lang
platforms               darwin
license                 BSD
maintainers             ciserlohn

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.

homepage                http://www.fscript.org/

master_sites            https://github.com/pmougin/F-Script/zipball/v${version}:fscript

distfiles               pmougin-F-Script-v2.1-0-g25c850c.zip:fscript

checksums               pmougin-F-Script-v2.1-0-g25c850c.zip \
                        sha1    5f1afa244f41ab372953a616d27a72a1573f4a15 \
                        rmd160  aa38b5e587bd3c0a8aeb1a8df8a38445d0036952

use_zip                 yes

post-extract {
    file rename [glob ${workpath}/pmougin-F-Script-*] ${worksrcpath}
}

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
}

if {${configure.compiler} == "clang"} {
    configure.compiler llvm-gcc-4.2
}

macosx_deployment_target 10.6

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"
        }
}

livecheck.type      regex
livecheck.url       https://github.com/pmougin/F-Script/branches
livecheck.regex     "/pmougin/F-Script/commits/v(\\d+\\.\\d+(\\.\\d+)?)"
