# -*- 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
PortGroup       makefile 1.0

name            elftoolchain
version         0.7.1
revision        1
categories      devel
platforms       darwin
license         BSD
maintainers     {raimue @raimue}
description     Compilation tools and libraries for ELF
long_description \
    BSD-licensed compilation tools and libaries for handling the ELF file \
    format. This includes implementations of libelf and libdwarf along with \
    the tools nm, ar, as, elfdump and more.

homepage        http://elftoolchain.sourceforge.net/
master_sites    sourceforge:project/${name}/Sources/${name}-${version}/
use_bzip2 yes

checksums       rmd160  9e341f86573d80dd2b390d79cf82f239ecd279ff \
                sha256  44f14591fcf21294387215dd7562f3fb4bec2f42f476cf32420a6bbabb2bd2b5 \
                size    5361427

depends_build   port:bmake \
                port:bison \
                port:flex

depends_lib     port:libarchive

patchfiles      patch-byteorder-macros.diff \
                patch-libelftc-make-toolchain-version.diff \
                patch-mk.diff \
                patch-mk-elftoolchain.tex.mk.diff

universal_variant no

makefile.prefix_name prefix

build.type      bsd
build.cmd       ${prefix}/bin/bmake
build.args      BINDIR=${prefix}/bin \
                LIBDIR=${prefix}/lib/elftoolchain \
                SHLIBDIR=${prefix}/lib/elftoolchain \
                INCSDIR=${prefix}/include/elftoolchain \
                MANDIR=${prefix}/share/man \
                MANTARGET=man

# Exclude test to avoid pulling in large build targets
build.args-append WITH_TESTS=no

# Exclude docs to avoid pulling in a full TeX distribution
build.args-append MKTEX=no

destroot.args   {*}${build.args}

# Do not strip binaries as that leads to errors
destroot.args-append STRIP=

pre-destroot {
    file mkdir ${destroot}${prefix}/lib/elftoolchain
    file mkdir ${destroot}${prefix}/include/elftoolchain
    file mkdir ${destroot}${prefix}/libexec/elftoolchain
}

# Add elftc- prefix to all binaries to avoid conflicts
post-destroot {
    foreach f [glob -tails -directory ${destroot}${prefix}/bin *] {
        set nf elftc-$f
        move ${destroot}${prefix}/bin/$f ${destroot}${prefix}/bin/$nf
        ln -s ../../bin/$nf ${destroot}${prefix}/libexec/${name}/$f
    }
    foreach f [glob ${destroot}${prefix}/share/man/man{1,5}/*] {
        move $f [file dirname $f]/elftc-[file tail $f]
    }
}

notes "
    The tools provided by elftoolchain are prefixed with the string 'elftc-' by\
    default to distinguish them from the commands provided by your default\
    toolchain. For example, nm becomes elftc-nm and size becomes elftc-size.

    If you want to use the tools provided by elftoolchain by default, add this\
    directory to the front of your PATH environment variable:
        ${prefix}/libexec/elftoolchain
"

livecheck.type  regex
livecheck.url   http://sourceforge.net/projects/elftoolchain/files/Sources/
livecheck.regex ${name}-(\\d+(\\.\\d+)+)
