# -*- 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
# $Id: Portfile 68596 2010-06-07 15:39:36Z jmr@macports.org $

PortSystem 1.0
PortGroup  muniversal  1.0

name            gmp
version         5.0.1
categories      devel math
maintainers     mcalhoun openmaintainer
platforms       darwin
description     GNU multiple precision arithmetic library
long_description \
    GNU MP is a library for arbitrary precision arithmetic, operating on\
    signed integers, rational numbers, and floating point numbers. It   \
    has a rich set of functions, and the functions have a regular       \
    interface. GNU MP is designed to be as fast as possible, both for   \
    small operands and for huge operands. The speed is achieved by using\
    fullwords as the basic arithmetic type, by using fast algorithms, by\
    carefully optimized assembly code for the most common inner loops   \
    for a lots of CPUs, and by a general emphasis on speed (instead of  \
    simplicity or elegance).

homepage        http://gmplib.org/
master_sites    gnu

checksums           md5     6bac6df75c192a13419dfd71d19240a7 \
                    sha1    6340edc7ceb95f9015a758c7c0d196eb0f441d49 \
                    rmd160  3e89ebf5294639e1c926b92d9786bbdd0c8fa587

use_bzip2       yes
use_parallel_build yes

# See http://trac.macports.org/ticket/16634
patchfiles      patch-gmp-h.in.diff

configure.args  --infodir=${prefix}/share/info \
                --enable-cxx

# if CFLAGS and CXXFLAGS are undefined, configure script tries to build fastest library for build machine.
# On PowerPC machines, CFLAGS must be empty to get -force_cpusubtype_ALL.
configure.cc_archflags
configure.cxx_archflags
configure.cflags
configure.cxxflags
configure.pipe  no

# Since CFLAGS and CXXFLAGS must be empty, append -arch ... to CC and CXX.
merger_arch_compiler yes

test.run        yes
test.cmd        make
test.target     check

post-destroot {
    # For the upgrade 4.3.2 -> 5.0.1, do not force all packages which depend on GMP to be rebuilt.
    ln -s libgmp.dylib ${destroot}${prefix}/lib/libgmp.3.dylib
}

if {![variant_isset universal]} {
    if {${build_arch} == "x86_64"} {
        configure.env   ABI=64
        #if {${os.platform} == "darwin"} {
            ## fails to automatically detect that i7 is x86_64 capable
            #configure.args-append --build=core2-apple-darwin${os.major}
        #}
    } elseif {${build_arch} == "ppc64"} {
        configure.env   ABI=mode64
    } else {
        configure.env   ABI=32
    }
} else {
    # Keep configure.cflags and configure.cxxflags empty.
    set merger_arch_flag no

    array set merger_configure_env {
        ppc     ABI=32
        i386    ABI=32
        ppc64   ABI=mode64
        x86_64  ABI=64
    }

    if { ${os.arch}=="i386" } {
        set merger_configure_env(ppc)     "NM='/usr/bin/nm -p'"
        set merger_configure_env(ppc64)   "NM='/usr/bin/nm -p'"
    } else {
        set merger_configure_env(i386)    "NM='/usr/bin/nm -p'"
        set merger_configure_env(x86_64)  "NM='/usr/bin/nm -p'"
    }

    # universal_archs_to_use might not be set before pre-fetch.
    pre-destroot {
        global merger_dont_diff merger_configure_env

        # PortGroup muniversal has difficulty merging three files.
        if  { [llength ${universal_archs_to_use}] == 3 } {
            set merger_dont_diff "${prefix}/include/gmp.h"
        }
    }

    # For cross-compiling, set C compiler and pre-precessor.
    if { ${os.arch}=="i386" } {
        if { ${os.major} >= 10 } {
            lappend merger_configure_env(ppc)  CC_FOR_BUILD=${configure.cc} CPP_FOR_BUILD=${configure.cpp}
        }
        lappend merger_configure_env(ppc64)    CC_FOR_BUILD=${configure.cc} CPP_FOR_BUILD=${configure.cpp}
    } else {
        lappend merger_configure_env(i386)     CC_FOR_BUILD=${configure.cc} CPP_FOR_BUILD=${configure.cpp}
        lappend merger_configure_env(x86_64)   CC_FOR_BUILD=${configure.cc} CPP_FOR_BUILD=${configure.cpp}
    }
}

platform powerpc {
    # See http://trac.macports.org/ticket/9053
    patchfiles-append  patch-config.guess.diff
}
