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

name                binutils
version             2.43.1
revision            0

checksums           rmd160  6f8ed9d308d81752726f80939826621ed441d11b \
                    sha256  13f74202a3c4c51118b797a39ea4200d3f6cfbe224da6d1d95bb938480132dfd \
                    size    28174300

description         FSF Binutils for native development.
long_description    Free Software Foundation development toolchain ("binutils") \
                    for native development. Tools are prefixed with g to avoid \
                    conflicts with original tools.

categories          devel
license             GPL-3+
maintainers         nomaintainer
homepage            https://www.gnu.org/software/binutils/binutils.html
master_sites        gnu:binutils
use_xz              yes

# Source unconditionally includes a header which may not exist.
# It was added in https://github.com/torvalds/linux/commit/ea3de9ce8aa280c5175c835bd3e94a3a9b814b74
patchfiles-append   patch-fix-riscv.diff

depends_build-append \
                    port:gettext

# Enforce systems nm on 10.10 and earlier,
# See: https://trac.macports.org/ticket/65621
if {${os.platform} eq "darwin" && ${os.major} <= 14} {
    build.env-append \
                    NM=/usr/bin/nm
    build.args-append \
                    lt_cv_path_NM=/usr/bin/nm
}

depends_lib-append  port:gettext-runtime \
                    port:libiconv \
                    port:zlib \
                    port:zstd

# bfd.c: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘bfd_error_type’
compiler.thread_local_storage yes

# --enable-shared leads to Undefined symbols, avoid it
# See: https://sourceware.org/bugzilla/show_bug.cgi?id=31056
configure.args      --infodir='${prefix}/share/info' \
                    --mandir='${prefix}/share/man' \
                    --disable-silent-rules \
                    --disable-werror \
                    --program-prefix=g \
                    --enable-install-libbfd \
                    --enable-install-libiberty

# The Makefile runs configure again in subdirectories.
# It correctly passes along most configure variables (CFLAGS, LDFLAGS, ...),
#    but seems to neglect CPPFLAGS.
build.env-append    CPPFLAGS=-I${prefix}/include

# Binutils violates the mtree layout by creating ${prefix}/<arch>/
destroot.violate_mtree  yes

# We don't want the etc module.
# But leave texi2pod.pl untouched for processing man pages
post-extract {
    move ${worksrcpath}/etc/texi2pod.pl ${worksrcpath}
    delete {*}[glob ${worksrcpath}/etc/*]
    move ${worksrcpath}/texi2pod.pl ${worksrcpath}/etc/texi2pod.pl
}

universal_variant   no

notes "Some of the utilities that ${name} installs can cause some\
other ports to fail to build, due to subtle differences with system\
tools sharing their names. Consider using trace mode if such build\
failures happen to you, or, if that is impossible, consider\
uninstalling ${name}."
