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

PortSystem          1.0
PortGroup           conflicts_build 1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.1

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup        radareorg radare2 6.1.2
revision            0
categories          devel
license             LGPL-3+
maintainers         {i0ntempest @i0ntempest} openmaintainer
description         Opensource tools to disasm, debug, analyze and manipulate binary files.
long_description    ${name} provides {*}${description}.
homepage            https://www.radare.org
checksums           rmd160  eb5fa51e6629e2725ce054bf517773d13356de5d \
                    sha256  f0677266eeb505bec4df12961cbb2adb92cf8202ff3dab05690bcb24c4bf5c52 \
                    size    11205131
github.tarball_from archive

# FIXME: add proper support for ppc thread state.
# See: https://github.com/radareorg/radare2/issues/25144

depends_build       path:bin/git:git \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:capstone \
                    port:libmagic \
                    path:lib/pkgconfig/libuv.pc:libuv \
                    port:libzip \
                    port:zlib

conflicts_build     ${name}

# Type redefinition
compiler.c_standard 2011

configure.args-append \
                    --with-libuv \
                    --with-syscapstone \
                    --with-sysmagic \
                    --with-syszip

if {[string match *clang* ${configure.compiler}]} {
    configure.args-append \
                    --with-compiler=clang
} elseif {[string match *gcc* ${configure.compiler}]} {
    configure.args-append \
                    --with-compiler=gcc
}

post-patch {
    # 5.7.8: r_fs library fails to build without -lzip. Check again in the next version.
    reinplace "s|LDFLAGS+=\$(SHLR)/grub/libgrubfs.a|LDFLAGS+=\$(SHLR)/grub/libgrubfs.a -lzip|g" ${worksrcpath}/libr/fs/Makefile
}

build.env-append    HOST_CC=${configure.cc}

variant openssl description "Use OpenSSL library" {
    PortGroup       openssl 1.0

    configure.args-append \
                    --with-ssl \
                    --with-ssl-crypto
}

default_variants    +openssl
