# -*- 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           github 1.0
PortGroup           cmake 1.1

cmake.out_of_source yes

github.setup        libproxy libproxy 0.4.15
revision            2
epoch               1
categories          net
maintainers         {devans @dbevans} openmaintainer
platforms           darwin
license             LGPL-2.1+
homepage            https://libproxy.github.io/libproxy

description         A library that provides automatic proxy configuration management.


long_description    Libproxy exists to answer the question: Given a \
                    network resource, how do I reach it? It handles all \
                    the details, enabling you to get back to programming.

checksums           rmd160  67300e2554c8e51ab1ca815b41ddcfdf523a56c4 \
                    sha256  7a1eaecbbd483ea21330aec126033032ef79743351cb967183c332dd46524f81

patchfiles          patch-libproxy-cmake.diff \
                    patch-libproxy-test-CMakeLists.txt.diff \
                    patch-bindings-perl-src-CMakeLists.txt.diff

depends_build-append \
                    port:pkgconfig

depends_lib         path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:vala

#
# webkit and mozjs pacrunners disabled by default due to the
# following issues
#
# webkit pacrunner circular dependency problem
# webkit-gtk -> libsoup -> libproxy -> webkit-gtk (#26261)
#
# pac files support not available on Tiger (#24127)
#
# TODO: add variants that safely enable these features
#

use_parallel_build no

# use default GNOME build which targets GNOME3 (gsettings) instead of GNOME2 (gconf)
# perl bindings disabled due to unpredictable configuration
# kde binding (KDE4/KF5) tests at runtime for kreadconfig5 kreadconfig in that order

configure.args-append \
                    -DMP_MACOSX=NO \
                    -DWITH_WEBKIT=NO \
                    -DWITH_WEBKIT3=NO \
                    -DWITH_VALA=YES \
                    -DWITH_PERL=NO \
                    -DWITH_PYTHON2=NO \
                    -DWITH_PYTHON3=NO \
                    -DWITH_KDE=YES

# Fix an issue with clang-900 (Xcode 9) using the Sierra SDK, <rdar://problem/31263056>
configure.cppflags-append -D_DARWIN_C_SOURCE=1

variant python27 conflicts python35 python36 python37 description {Build Bindings for Python 2.7} {
    set python_prefix ${frameworks_dir}/Python.framework/Versions/2.7
    depends_lib-append port:python27
    configure.args-delete \
                    -DWITH_PYTHON2=NO
    configure.args-append \
                    -DWITH_PYTHON2=YES \
                    -DPYTHON2_EXECUTABLE=${prefix}/bin/python2.7 \
                    -DPYTHON2_SITEPKG_DIR=${python_prefix}/lib/python2.7/site-packages
}

variant python35 conflicts python27 python36 python37 description {Build Bindings for Python 3.5} {
    set python_prefix ${frameworks_dir}/Python.framework/Versions/3.5
    depends_lib-append port:python35
    configure.args-delete \
                    -DWITH_PYTHON3=NO
    configure.args-append \
                    -DWITH_PYTHON3=YES \
                    -DPYTHON3_EXECUTABLE=${prefix}/bin/python3.5 \
                    -DPYTHON3_SITEPKG_DIR=${python_prefix}/lib/python3.5/site-packages
}

variant python36 conflicts python27 python35 python37 description {Build Bindings for Python 3.6} {
    set python_prefix ${frameworks_dir}/Python.framework/Versions/3.6
    depends_lib-append port:python36
    configure.args-delete \
                    -DWITH_PYTHON3=NO
    configure.args-append \
                    -DWITH_PYTHON3=YES \
                    -DPYTHON3_EXECUTABLE=${prefix}/bin/python3.6 \
                    -DPYTHON3_SITEPKG_DIR=${python_prefix}/lib/python3.6/site-packages
}

variant python37 conflicts python27 python35 python36 description {Build Bindings for Python 3.7} {
    set python_prefix ${frameworks_dir}/Python.framework/Versions/3.7
    depends_lib-append port:python37
    configure.args-delete \
                    -DWITH_PYTHON3=NO
    configure.args-append \
                    -DWITH_PYTHON3=YES \
                    -DPYTHON3_EXECUTABLE=${prefix}/bin/python3.7 \
                    -DPYTHON3_SITEPKG_DIR=${python_prefix}/lib/python3.7/site-packages
}

# build Python 2.7 bindings by default for compatibility

if {![variant_isset python35] && ![variant_isset python36] && ![variant_isset python37]} {
    default_variants    +python27
}

post-patch {
	if {${os.major} < 13 && [string match "*clang*" ${configure.compiler}]} {
		# <rdar://problem/12941376>
		reinplace "s:-D_POSIX_C_SOURCE=200112L:-D_POSIX_C_SOURCE=200112L -D_DARWIN_C_SOURCE=1:" ${worksrcpath}/libproxy/CMakeLists.txt
	}
}