# -*- 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           compiler_blacklist_versions 1.0

github.setup        steveicarus iverilog 20250103 s
github.tarball_from archive

revision            0
set major           12
set minor           0

categories          science
license             GPL-2+
maintainers         {keeh.net:paf @padf} openmaintainer
description         Icarus Verilog
long_description    Icarus Verilog is a Verilog simulation and synthesis tool. \
                    It operates as a compiler, compiling source code writen in \
                    Verilog (IEEE-1364) into some target format. For batch \
                    simulation, the compiler can generate C++ code that is \
                    compiled and linked with a run time library (called \
                    \"vvm\") then executed as a command to run the simulation. \
                    For synthesis, the compiler generates netlists in the \
                    desired format.

homepage            http://iverilog.icarus.com/

checksums           rmd160  41f0a34641ce8bf4955f2248ee606707deedbf92 \
                    sha256  eed6e7569eb9111a6384ed2088e38b51541236a1806ed469208419f41b8224ae \
                    size    3111119

depends_lib-append      port:bzip2 \
                        port:readline \
                        port:zlib

depends_build-append    port:bison \
                        port:autoconf \
                        port:gperf

use_autoconf        yes

configure.args-append --enable-libvvp
configure.ldflags-append -Wl,-rpath,${prefix}/lib

patchfiles-append patch-vvp-Makefile.in.diff

platform darwin {
    #under MacOS, this is needed, the library references were incorrect as-is
    configure.cxxflags-append -fPIC
}

compiler.cxx_standard 2011

if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
    configure.ldflags-append -stdlib=${configure.cxx_stdlib}
}

test.run            yes
test.target         check

destroot.destdir    prefix=${destroot}${prefix}

post-destroot {
    if {[file exists ${destroot}${prefix}/lib/libvvp.so]} {
        # Fix just the library's install name
        system "install_name_tool -id ${prefix}/lib/libvvp.so ${destroot}${prefix}/lib/libvvp.so"
    }
}

# g++-4.2: -E, -S, -save-temps and -M options are not allowed with multiple -arch flags
universal_variant   no

subport ${name}-docs {
    description         Documentation for Icarus Verilog
    long_description    This subport provides the documentation for Icarus Verilog, \
                        including user guides and API references.

    depends_build-append       port:py312-sphinx \
                               port:sphinx

    worksrcdir          ${github.project}-${github.version}

    pre-build {
        reinplace "s|sphinx-build|sphinx-build-3.12|" ${worksrcpath}/Documentation/Makefile
    }

    build {
        system -W ${worksrcpath}/Documentation "make html"
    }

    destroot {
        set docdir ${destroot}${prefix}/share/doc/${name}
        xinstall -d ${docdir}
        system "cp -R ${worksrcpath}/Documentation/_build/html/* ${docdir}/"
    }

    depends_lib
}
