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

name                    libiconv
version                 1.17
revision                0
checksums               rmd160  5fd15d5f8ed7bd8e410b432495f5d892598ae965 \
                        sha256  8f74213b56238c85a50a5329f77e06198771e70dd9a739779f4c02f65d971313 \
                        size    5413283

categories              textproc
license                 {LGPL-2+ GPL-3+}
maintainers             {ryandesign @ryandesign}
platforms               darwin freebsd linux
homepage                https://www.gnu.org/software/libiconv/
master_sites            gnu
use_parallel_build      yes

description \
    Character set conversion library

long_description \
    A character-set conversion library which implements the \
    iconv() API for dealing with unicode and other types of \
    conversion.

depends_build           port:gperf
depends_skip_archcheck  gperf

patchfiles              patch-src-Makefile.in-darwin.diff

# Also needed by later clangs.
if {${os.platform} eq "darwin" && ${os.major} < 11 && ${cxx_stdlib} eq "libc++"} {
    clang_dependency.extra_versions 3.7
}

configure.checks.implicit_function_declaration.whitelist-append strchr
configure.cmd-prepend   mv Makefile.devel Makefile.devel.orig \
                        && sed -E {"s|^(CFLAGS *=).*|\1 $CFLAGS|"} < Makefile.devel.orig \
                        | sed -E {"/^CFLAGS *=/s| -arch +[^ ]+||"} > Makefile.devel &&
configure.cppflags
configure.ldflags
configure.args \
    ac_cv_prog_AWK=/usr/bin/awk \
    ac_cv_path_GREP=/usr/bin/grep \
    ac_cv_path_SED=/usr/bin/sed \
    --enable-static \
    --docdir=${prefix}/share/doc/${name} \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    --disable-nls \
    --enable-extra-encodings

build.cmd               ${build.cmd} CC=${configure.cc} -f Makefile.devel && ${build.cmd}

test.run                yes
test.target             check

platform darwin {
    patchfiles-append patch-utf8mac.diff
}

platform freebsd {
    patchfiles-append patch-Makefile.devel
}

post-destroot {
    if {[file exists ${destroot}${prefix}/lib/charset.alias]} {
        delete ${destroot}${prefix}/lib/charset.alias
    }
}

if {${universal_possible} && [variant_isset universal]} {
    # When cross-compiling, can guess wrong endian value.
    configure.env.ppc-append    cl_cv_sys_endian='big endian'
    configure.env.ppc64-append  cl_cv_sys_endian='big endian'
    configure.env.i386-append   cl_cv_sys_endian='little endian'
    configure.env.x86_64-append cl_cv_sys_endian='little endian'
    configure.env.arm64-append  cl_cv_sys_endian='little endian'

    # See https://trac.macports.org/ticket/18440
    configure.env-append        ac_cv_func_malloc_0_nonnull='yes' \
                                gl_cv_func_malloc_0_nonnull='1' \
                                am_cv_func_iconv='yes' \
                                am_cv_proto_iconv_arg1='const'
}
