# -*- 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               muniversal       1.1
PortGroup               xcode_workaround 1.0

name                    gmp
version                 6.3.0
revision                0
categories              devel math
license                 LGPL-3+
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
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                https://gmplib.org/
master_sites            gnu

checksums               rmd160  ce893dd234e66923adc879473b48ad0459d345cc \
                        sha256  ac28211a7cfb609bae2e2c8d6058d66c8fe96434f740cf6fe2e47b000d1c20cb \
                        size    2643888

use_bzip2               yes

depends_build-append    port:m4
configure.env           M4=${prefix}/bin/gm4

configure.args          --enable-cxx

# Clear all options that affect CFLAGS and CXXFLAGS, since the configure
# script tries to build the fastest library for the build machine if
# CFLAGS and CXXFLAGS are undefined.
#
# On PowerPC machines, CFLAGS must be empty to get -force_cpusubtype_ALL.
#
# Append all extra flags to compiler name, which is a far from ideal solution.

# Append the -stdlib flags to CXX, since we still want to select the C++ STL.
rename portconfigure::should_add_stdlib  should_add_stdlib
rename portconfigure::should_add_cxx_abi should_add_cxx_abi
proc portconfigure::should_add_stdlib  {} {return no}
proc portconfigure::should_add_cxx_abi {} {return no}
if {[should_add_stdlib] && ${configure.cxx_stdlib} ne ""} {
    configure.cxx-append    -stdlib=${configure.cxx_stdlib}
}
if {[should_add_cxx_abi]} {
    configure.cxx-append    -D_GLIBCXX_USE_CXX11_ABI=0
}

compiler.limit_flags        yes

configure.cflags
configure.cxxflags
configure.pipe              no

test.run                    yes
test.target                 check

variant native description {Build optimized for your machine's specific processor} {
    archive_sites

    # config.guess: "Print the host system CPU-VENDOR-OS."
    # config.guess calls configfsf.guess and then tries to improve the result
    #
    # prior to 5.0.2, configfsf.guess returned
    #   i386-apple-darwinX.X.X or powerpc-apple-darwinX.X.X
    #    even on 64-bit processors
    # if config.guess were unable to improve on the result
    #    (e.g. a new unrecognized processor), then the configure script
    #    used i386 or powerpc as the CPU type and a 64-bit build attempt
    #    resulted in an error (see #28892)
    # as of 5.0.2, configfsf.guess can return
    #    x86_64-apple-darwinX.X.X and powerpc64-apple-darwinX.X.X, which,
    #    if not improved, would at least produce a (slow) 64-bit build
    #
    # up to 6.0.0a, all improved CPU types on x86 macs were of the form
    #    core2 or corei* (coreisbr for Sandy Bridge, coreihwl for Haswell, etc.)
    # starting with 6.1.0, improved CPU types on x86 macs have less uniform
    #    names (sandybridge for Sandy Bridge, haswell for Haswell, etc.)
    #
    # in an attempt to accommodate all situations,
    #    test if the CPU was improved and warn if it was not
    #
    pre-configure {
        if { [option muniversal.is_cross.${muniversal.build_arch}] } {
            return
        }
        set build_cpu       [lindex [split [exec -ignorestderr /usr/bin/env CC=${configure.cc} ${worksrcpath}/config.guess] -] 0]
        if { ${build_cpu} in {aarch64 x86_64 i386 powerpc powerpc64} } {
            ui_warn "No processor dependent assembly code being used. gmp might be slower."
        }
    }
}
if { ![variant_isset native] } {
    triplet.add_host        all
}

# keep configure.cflags and configure.cxxflags empty
# since CFLAGS and CXXFLAGS must be empty, append -arch ... to CC and CXX
muniversal.arch_flag        no
muniversal.arch_compiler    yes

configure.env.arm64-append  ABI=64
configure.env.x86_64-append ABI=64
configure.env.i386-append   ABI=32
configure.env.ppc-append    ABI=32
configure.env.ppc64-append  ABI=mode64

triplet.cpu.arm64           applem1
triplet.cpu.x86_64          core2
triplet.cpu.i386            pentiumm
triplet.cpu.ppc             powerpc750
triplet.cpu.ppc64           powerpc970

xcode_workaround.type       append_to_compiler_name

if { [llength ${muniversal.architectures}] == 3 } {
    # muniversal PortGroup has difficulty merging three files
    muniversal.dont_diff    ${prefix}/include/gmp.h
}

if { ${configure.compiler} in {gcc-4.2 llvm-gcc-4.2} } {
    # avoid "suffix or operands invalid for `movq'" in several assembly files
    triplet.cpu.x86_64      x86_64
}

if { ${configure.compiler} in {apple-gcc-4.2 gcc-4.2 gcc-4.0} } {
    configure.append_build_flags_to_compiler    yes
    configure.cflags_for_build                  -std=gnu99
    configure.cxxflags_for_build
}

# see https://trac.macports.org/ticket/59493
if {${os.platform} eq "darwin" && ${os.major} < 10 && [string match *clang* ${configure.compiler}]} {
    depends_build-append    port:cctools
    configure.env-append    NM=${prefix}/bin/nm
    configure.args-append   lt_cv_path_NM=${prefix}/bin/nm
}
