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

github.setup            IoLanguage io 2017.09.06
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
revision                10
name                    Io
categories              lang
# mostly BSD, but some LGPL and GPL files
license                 GPL-2
platforms               macosx
maintainers             {mark @markemer} openmaintainer

description             Io is small prototype-based programming language

long_description        {*}${description}. The ideas in Io are mostly inspired \
                        by Smalltalk (all values are objects), Self, \
                        NewtonScript and Act1 (prototype-based differential \
                        inheritance, actors and futures for concurrency), \
                        LISP (code is a runtime inspectable / modifiable \
                        tree) and Lua (small, embeddable).

homepage                http://www.iolanguage.com/

checksums               rmd160  ebf5d206b115329456df169aaaad33f431a92bfc \
                        sha256  febf9b6f4174e3d9fee179b5d41a81dba8b9660ece7a1cecee7452f5e9e460ea \
                        size    9154022

depends_lib             path:lib/pkgconfig/cairo.pc:cairo \
                        port:freetype \
                        path:lib/pkgconfig/glib-2.0.pc:glib2 \
                        port:gmp \
                        path:include/turbojpeg.h:libjpeg-turbo \
                        port:libedit \
                        port:libevent \
                        port:libffi \
                        port:libiconv \
                        port:libidn \
                        port:libmemcached \
                        port:libogg \
                        port:libpng \
                        port:libsndfile \
                        port:libtheora \
                        port:libvorbis \
                        port:libxml2 \
                        port:loudmouth \
                        port:lzo2 \
                        port:ncurses \
                        path:lib/libssl.dylib:openssl \
                        port:ossp-uuid \
                        path:lib/pkgconfig/pango.pc:pango \
                        port:pcre \
                        port:python37 \
                        port:readline \
                        port:sqlite3 \
                        port:tiff \
                        port:yajl \
                        port:zlib

patchfiles              Cairo-clang-warnings.patch \
                        EditLine-clang-warnings.patch \
                        Foundation.patch \
                        IoImage-clang-warnings.patch \
                        SHA1-clang-warnings.patch \
                        version.patch \
                        AppleSMC.h-fix-includes.patch

# Io2Objc.m: error: '-fobjc-exceptions' is required to enable Objective-C exception syntax
if {[string match *gcc* ${configure.compiler}]} {
    patchfiles-append   CMakeLists-fix-ObjC.patch
}

if {${configure.build_arch} ni [list i386 x86_64]} {
    # https://github.com/IoLanguage/io/issues/474
    patchfiles-append   CMakeLists-drop-breaking-simd-flag.patch
}

configure.python        ${prefix}/bin/python3.7

# AppleSMC.h: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘flag’
compiler.blacklist-append \
                        *gcc-4.0 *gcc-4.2

# Builds currently fail on apple silicon even in universal mode
supported_archs         ppc ppc64 i386 x86_64
universal_variant       no

# ../../_build/binaries/io_static: No such file or directory
use_parallel_build      no

post-destroot {
    set libstofix \
        [list libIoObjcBridge.dylib \
              libIoOpenGL.dylib \
              libIoRegex.dylib \
              libIoTheora.dylib \
              libIoVorbis.dylib]
    fs-traverse destlib ${destroot}${prefix}/lib {
        if {[file isfile ${destlib}] && [file extension ${destlib}] == ".dylib"} {
            set lib [strsed ${destlib} "s|^${destroot}||"]
            set cmd "install_name_tool -id '${lib}'"
            if {[lsearch ${libstofix} [file tail ${destlib}]] > -1} {
                foreach linkedlibname {Blowfish Box MD5 Ogg Range Socket SystemCall Yajl} {
                    set linkedlib "libIo${linkedlibname}.dylib"
                    append cmd " -change '${prefix}/lib/${linkedlib}' '${prefix}/lib/io/addons/${linkedlibname}/_build/dll/${linkedlib}'"
                }
            }
            append cmd " '${destlib}'"
            ui_debug "Assembled command: '${cmd}'"
            system "${cmd}"
        }
    }
}

test.run                yes
test.cmd                ${worksrcpath}/_build/binaries/io_static ${worksrcpath}/libs/iovm/tests/correctness/run.io
test.target
