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

# strndup
legacysupport.newest_darwin_requires_legacy 10

name                flashrom
version             1.3.0
categories          sysutils
license             GPL-2
maintainers         {ra1nb0w @ra1nb0w} openmaintainer
description         universal flash programming utility
long_description    utility for identifying, reading, writing, verifying and erasing flash chips.\
                    It is designed to flash BIOS/EFI/coreboot/firmware/optionROM images on \
                    mainboards, network/graphics/storage controller cards, and various other \
                    programmer devices.
homepage            https://www.flashrom.org/Flashrom
master_sites        https://download.flashrom.org/releases/
distname            ${name}-v${version}
use_bzip2           yes

checksums           rmd160  760f21c1580c910304583777304de664d6ae1aad \
                    sha256  a053234453ccd012e79f3443bdcc61625cf97b7fd7cb4cdd8bfbffbe8b149623 \
                    size    489782
revision            3

# Blacklist compilers that have issues with missing initializer fields.
# This applies to clang < 10.x.  The equivalent gcc version is unknown,
# so we blacklist all gccs with no loss of generality, since the only
# systems where Xcode uses gcc don't work for other reasons.
#
# This will probably become unnecessary after the next upstream release,
# which is also adding fixes for 10.5 adn 10.6.
#
# This fix is sufficient for 10.7-10.12, and a NOP on 10.13+.
compiler.blacklist  *gcc-4.* {clang < 1000}

depends_build       path:bin/pkg-config:pkgconfig

# NOTE: The build procedure tests for pci.h and libpci, even though all
# programmers that would use libpci are disabled in this build.  Thus,
# any such references seen in trace mode can be ignored.

depends_lib         port:libftdi1 \
                    port:libusb-compat

use_configure       no
build.args-append   CC=${configure.cc} \
                    CXX=${configure.cxx} \
                    CPP=${configure.cpp} \
                    CFLAGS="${configure.cflags} [get_canonical_archflags cc]" \
                    LDFLAGS="${configure.ldflags} [get_canonical_archflags ld]"

build.env-append    CONFIG_ENABLE_LIBPCI_PROGRAMMERS=0 \
                    CONFIG_GFXNVIDIA=0 \
                    CONFIG_NIC3COM=0 \
                    CONFIG_NICREALTEK=0 \
                    CONFIG_NICNATSEMI=0 \
                    CONFIG_NICINTEL=0 \
                    CONFIG_NICINTEL_SPI=0 \
                    CONFIG_NICINTEL_EEPROM=0 \
                    CONFIG_OGP_SPI=0 \
                    CONFIG_SATAMV=0 \
                    CONFIG_SATASII=0 \
                    CONFIG_DRKAISER=0 \
                    CONFIG_RAYER_SPI=0 \
                    CONFIG_INTERNAL=0 \
                    CONFIG_IT8212=0 \
                    CONFIG_ATAHPT=0 \
                    CONFIG_ATAVIA=0 \
                    CONFIG_INTERNAL_X86=0

destroot.env        {*}${build.env}

pre-build {
    reinplace "s|sbin|bin|g" ${worksrcpath}/Makefile
    reinplace "s|/usr/local|${prefix}|g" ${worksrcpath}/Makefile
}

test.run            yes
test.cmd            ./flashrom --version

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     ${name}-v(\\d+\\.\\d+(\\.\\d+)*)${extract.suffix}
