# -*- 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           legacysupport   1.1

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup        jart blink 1.1.0
revision            1
epoch               1

description         tiniest x86-64-linux emulator

long_description    \
    ${name} is a virtual machine that runs x86-64-linux programs on different \
    operating systems and hardware architectures. It's designed to do the \
    same thing as the qemu-x86_64 command, except that it is smaller, runs on \
    any POSIX platform, runs 2x faster than qemu-x86_64 on some benchmarks, \
    and is also faster at running ephemeral programs such as compilers.

categories          emulators
installs_libs       no
license             ISC
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

checksums           rmd160  39a9d2d2c08388e705bd8a7f11af52b357952e44 \
                    sha256  2649793e1ebf12027f5e240a773f452434cefd9494744a858cd8bff8792dba68 \
                    size    2984430

depends_build-append \
                    port:gmake

# Uses C17 atomics.
# https://github.com/jart/blink/issues/148
compiler.c_standard 2017

# https://github.com/jart/blink/pull/142
build.cmd           ${prefix}/bin/gmake
build.target

# blinkenlights.c:3609:29: error: use of undeclared identifier
# 'F_DUPFD_CLOEXEC' on macOS <10.7
# https://github.com/jart/blink/pull/197
# remove this if it will be merged upstream
patchfiles-append   patch-f-dupfd-cloexec.diff

platform darwin {
    # incompatibility with the new Xcode 15 linker
    if {([vercmp ${xcodeversion} 15] >= 0) || ([vercmp ${xcodecltversion} 15] >= 0)} {
        configure.ldflags-append \
                    -Wl,-ld_classic
    }
}

destroot {
    xinstall -m 0755 \
        ${worksrcpath}/o/blink/blink ${worksrcpath}/o/blink/blinkenlights \
        ${destroot}${prefix}/bin/
}
