# -*- 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       clang_dependency 1.0
PortGroup       gnulib 1.0
PortGroup       muniversal 1.0

name            m4
version         1.4.21
categories      devel
license         GPL-3+
installs_libs   no
maintainers     nomaintainer
description     GNU macro processor

long_description \
    GNU `m4' is an implementation of the traditional Unix macro         \
    processor.  It is mostly SVR4 compatible, although it has some      \
    extensions (for example, handling more than 9 positional parameters \
    to macros). `m4' also has built-in functions for including files,   \
    running shell commands, doing arithmetic, etc. Autoconf needs GNU   \
    `m4' for generating `configure' scripts, but not for running them.

homepage        https://www.gnu.org/software/m4/
master_sites    gnu
use_bzip2       yes

depends_build   port:gettext
depends_lib     port:gettext-runtime port:libiconv

checksums       rmd160  30acaf0a3435bee28d905f58694167a8ca97d75b \
                sha256  dc487e11d2f0c9e01555bb1af26be4eae983ec8f0726746505b4327186eb21fc \
                size    2608929

configure.args  --disable-silent-rules \
                --program-prefix=g \
                --with-packager=MacPorts \
                --with-packager-version="revision $revision" \
                --with-packager-bug-reports=https://trac.macports.org/wiki/Tickets \
                ac_cv_libsigsegv=no

configure.checks.implicit_function_declaration.whitelist-append strchr

# Fix for Rosetta: https://trac.macports.org/ticket/64487
platform darwin {
    if {${os.arch} eq "arm" && ${configure.build_arch} eq "x86_64"} {
        configure.args-append --host=${configure.build_arch}-apple-darwin${os.major}
    } elseif {${os.major} == 10 && ${configure.build_arch} eq "ppc"} {
        configure.args-append --host=powerpc-apple-darwin${os.major}
    }
}

post-destroot {
    move ${destroot}${prefix}/share/info/m4.info ${destroot}${prefix}/share/info/gm4.info

    set docdir ${prefix}/share/doc/${name}-${version}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} AUTHORS COPYING ChangeLog NEWS README THANKS \
        TODO ${destroot}${docdir}

    xinstall -m 755 -d ${destroot}${prefix}/libexec/gnubin
    foreach binary [glob -tails -directory ${destroot}${prefix}/bin g*] {
        ln -s ${prefix}/bin/${binary} ${destroot}${prefix}/libexec/gnubin/[string range $binary 1 end]
    }
    xinstall -m 755 -d ${destroot}${prefix}/libexec/gnubin/man/man1
    foreach manpage [glob -tails -directory ${destroot}${prefix}/share/man/man1 g*] {
        ln -s ${prefix}/share/man/man1/${manpage}.gz ${destroot}${prefix}/libexec/gnubin/man/man1/[string range $manpage 1 end].gz
    }
}

test.run        yes
test.target     check
test.env        TMPDIR=/tmp
