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

name                proxmark3-iceman

github.setup        RfidResearchGroup proxmark3 4.21611 v
github.tarball_from archive
checksums           sha256  e149802a10acb3358ad452f424f83527c00ee38fbb65d6400a4acd570d4aaef8 \
                    rmd160  5aa06dd858f5d7f2f59b2d4305152ccb5be2ccf4 \
                    size    34955713

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

# upstream quirk: some binaries use openssl 3 while some use openssl 1.1
depends_lib-append  port:gd2 \
                    port:lz4 \
                    port:bzip2 \
                    port:lua54 \
                    port:jansson \
                    port:openssl \
                    port:readline \
                    port:openssl11 \
                    port:python314 \
                    port:py314-pexpect \
                    port:py314-bitstring \
                    port:py314-ansicolors \
                    port:py314-sslcrypto

# Although port:pkgconfig is required (see comments below), because the qt6 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.14
set python_prefix   ${frameworks_dir}/Python.framework/Versions/${python_version}
configure.python    ${prefix}/bin/python${python_version}

# Qt6 is not symlinked under regular pkg-config dirs
# so we use qt6.dir (via the qt6 group) to add it as path
configure.pkg_config \
                    ${prefix}/bin/pkg-config
configure.pkg_config_path-append \
                    ${qt6.dir}/lib/pkgconfig \
                    ${python_prefix}/lib/pkgconfig

# pm3 checks for Qt6Core Qt6Widgets Qt6Gui at build time
qt6.depends_lib     qtbase

# 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} \
                    PKG_CONFIG_PATH=${configure.pkg_config_path} \
                    PATH=${qt6.dir}/bin:${prefix}/libexec/gnubin:$env(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}
