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

name                proxmark3-iceman

github.setup        RfidResearchGroup proxmark3 4.20728 v
github.tarball_from archive
checksums           sha256  aeb05460feba72e84d00e3da48d3bbe79cac924fb92b770eae48fcebe39e63db \
                    rmd160  b8d87689edf5326b7e5933353492a1e7695aa6d2 \
                    size    34548588

revision            0
license             GPL-3+
categories          science comms

description         RRG/Iceman version of proxmark3 RFID Instrument Client/FW

long_description    ${description}. By default, the repository is built for PM3RDV4. \
                    To build for other hardware releases, please check the package \
                    variants.

maintainers         {@linuxgemini linuxgemini.space:proxmark3packaging} openmaintainer

depends_lib-append  port:gd2 \
                    port:lz4 \
                    port:bzip2 \
                    port:lua54 \
                    port:jansson \
                    port:readline \
                    port:openssl11 \
                    port:python312 \
                    port:py312-pexpect \
                    port:py312-bitstring \
                    port:py312-ansicolors \
                    port:py312-sslcrypto

# Although port:pkgconfig is required (see comments below), because the qt5 PortGroup
# includes it, its not listed here.
depends_build-append \
                    port:arm-none-eabi-gcc \
                    port:arm-none-eabi-binutils \
                    path:libexec/coreutils/libstdbuf.so:coreutils

# although the upstream repository does not have a ./configure script,
# the buildsystem itself does rely on things usually found in ./configure
# like for instance, pkg-config.
#
# this is why i (@linuxgemini) has decided to set variables related to
# configure phase instead of making new ones before passing them
# to build and destroot envs.

set python_version  3.12
set python_prefix   ${frameworks_dir}/Python.framework/Versions/${python_version}
configure.python    ${prefix}/bin/python${python_version}

configure.pkg_config \
                    ${prefix}/bin/pkg-config
configure.pkg_config_path-append \
                    ${python_prefix}/lib/pkgconfig

# pm3 does not have a ./configure script
use_configure       no

# PKG_CONFIG_ENV is used by the upstream buildsystem,
# which basically is a variable to point out PKG_CONFIG_PATH
# to shell calls inside Makefiles.
build.env-append    USE_BREW=0 \
                    USE_MACPORTS=1 \
                    PREFIX=${prefix} \
                    SKIPWHEREAMISYSTEM=1 \
                    MACPORTS_PREFIX=${prefix} \
                    PATH=${prefix}/libexec/gnubin:$env(PATH) \
                    PKG_CONFIG_PATH=${configure.pkg_config_path}

build.args-append   CC=${configure.cc} \
                    CXX=${configure.cxx} \
                    CPP=${configure.cpp} \
                    LD=${configure.cxx} \
                    PKG_CONFIG_ENV=PKG_CONFIG_PATH=${configure.pkg_config_path}

variant pm3generic description {Build firmware for PM3GENERIC instead of PM3RDV4} {
    build.args-append   PLATFORM=PM3GENERIC
    destroot.args-append \
                        PLATFORM=PM3GENERIC
}
variant pm3easy requires pm3generic description {Build firmware for PM3GENERIC \
with fixed LED order for Proxmark3 Easy/RDV3 devices} {
    build.args-append   LED_ORDER=PM3EASY
    destroot.args-append \
                        LED_ORDER=PM3EASY
}

variant pm3icopyx conflicts pm3generic description {Build firmware for ICOPY-X \
and PM3 Max} {
    build.args-append   PLATFORM=PM3ICOPYX \
                        PLATFORM_EXTRAS=FLASH
    destroot.args-append \
                        PLATFORM=PM3ICOPYX \
                        PLATFORM_EXTRAS=FLASH
}

variant pm3ultimate conflicts pm3generic pm3icopyx description {Build firmware for \
PM3 Ultimate} {
    build.args-append   PLATFORM=PM3ULTIMATE
    destroot.args-append \
                        PLATFORM=PM3ULTIMATE
}

# buildsystem quirk: "make install" calls "make all" as well
destroot.args       {*}${build.args}
destroot.env        {*}${build.env}
