# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 107446 2013-06-29 14:28:43Z and.damore@macports.org $

PortSystem  1.0
PortGroup   conflicts_build 1.0
PortGroup   muniversal 1.0
PortGroup   compiler_blacklist_versions 1.0

name        webkit-gtk
epoch       2
version     2.0.3
description Apple's WebKit HTML rendering library for GTK+
long_description ${description}
maintainers jeremyhu devans
categories  www gnome
platforms   darwin freebsd
license     LGPL-2+ BSD
homepage    http://webkitgtk.org/
master_sites    http://webkitgtk.org/releases/

use_xz      yes
distname    webkitgtk-${version}

checksums           sha1    136c649c34956cadfaac9b13bbad368b70d38820 \
                    rmd160  e93b4841ce298b6ab4f991a5995ebdbad4c15f7d \
                    sha256  9bf8a32afbf087c4fc2c652b193a52c44b180735ba9c7c8db88137904d458e1b

depends_lib \
        path:lib/pkgconfig/glib-2.0.pc:glib2 \
        port:enchant \
        port:geoclue \
        port:gobject-introspection \
        port:gtk2 \
        port:harfbuzz-icu \
        port:libxslt \
        port:libpng \
        port:libsecret \
        port:libsoup \
        port:mesa \
        port:sqlite3 \
        port:webp \
        port:xorg-libXt

depends_build   \
        port:gtk-doc \
        port:pkgconfig

# case-insensitive.patch: https://bugs.webkit.org/show_bug.cgi?id=65811
# our-icu.patch: No upstream bug report, probably not wanted
# ruby-1.8.patch: http://trac.macports.org/ticket/37740
# ListableHandler.patch: https://trac.macports.org/ticket/37828
# execinfo.patch: https://trac.macports.org/ticket/37882
# ppc.patch: https://bugs.webkit.org/show_bug.cgi?id=96005
# tiger.patch: No upstream bug, http://trac.macports.org/ticket/35923

patchfiles \
        clang-assertions.patch \
        case-insensitive.patch \
        our-icu.patch \
        execinfo.patch \
        ruby-1.8.patch \
        ListableHandler.patch \
        ppc.patch \
        tiger.patch

conflicts_build     google-test

# https://trac.macports.org/ticket/36329
configure.python    /usr/bin/python

configure.args  \
        --with-gtk=2.0 \
        --disable-webkit2 \
        --enable-introspection \
        --disable-video \
        --enable-svg \
        --enable-geolocation \
        --enable-media-stream \
        --enable-webgl

# https://bugs.webkit.org/show_bug.cgi?id=94488
configure.universal_args-delete --disable-dependency-tracking

# gobject-introspection uses g-ir-scanner, which uses $CC from env
if {[variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_args(${arch})     CC='${configure.cc} -arch ${arch}'
        lappend merger_destroot_args(${arch})  CC='${configure.cc} -arch ${arch}'
    }
} else {
    build.args-append       CC="${configure.cc} ${configure.cc_archflags}"
    destroot.args-append    CC="${configure.cc} ${configure.cc_archflags}"
}

# In 1.10.1:
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp: In constructor 'WebCore::FFTFrame::FFTFrame(unsigned int)':
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp:48: error: 'm_complexData' was not declared in this scope
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp:48: error: 'GstFFTF32Complex' was not declared in this scope
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp:48: error: no matching function for call to 'fastNewArray(size_t)'
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp:50: error: 'gst_fft_next_fast_length' was not declared in this scope
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp:51: error: 'm_fft' was not declared in this scope
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp:51: error: 'FALSE' was not declared in this scope
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp:51: error: 'gst_fft_f32_new' was not declared in this scope
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp:52: error: 'm_inverseFft' was not declared in this scope
# Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp:52: error: 'TRUE' was not declared in this scope
#        --enable-web-audio \

# We don't want to use the headers from the installed WebKit
configure.cppflags-delete -I${prefix}/include

# google-test suite build fix
configure.cppflags-append -DGTEST_USE_OWN_TR1_TUPLE=1

autoreconf.env-append ACLOCAL="aclocal -I Source/autotools"
use_autoreconf  yes
autoreconf.args -fvi

# configure checks that we're clang 3.0, gcc 4.7, or better
compiler.blacklist-append gcc-3.3 gcc-4.0 apple-gcc-4.0 gcc-4.2 apple-gcc-4.2 llvm-gcc-4.2 macports-llvm-gcc-4.2
compiler.blacklist-append macports-gcc-4.2 macports-gcc-4.3 macports-gcc-4.4 macports-gcc-4.5 macports-gcc-4.6
compiler.blacklist-append {clang < 300} macports-clang-2.9

# TODO: Remove this block once 2.2 is released
compiler.fallback-append macports-clang-3.2
if {[info exists portconfigure::compiler_name_map(${configure.compiler})]} {
    depends_build-append port:$portconfigure::compiler_name_map(${configure.compiler})

    # base 2.1.x ignores the argument and just use ${configure.compiler}
    if {[portconfigure::arch_flag_supported ${configure.compiler}]} {
        depends_skip_archcheck-append $portconfigure::compiler_name_map(${configure.compiler})
    }

    if {[string match macports-gcc* ${configure.compiler}]} {
        depends_lib-append port:$portconfigure::compiler_name_map(${configure.compiler})
    }
}

if {[string match *clang* ${configure.compiler}]} {
    configure.cxxflags-append -Wno-c++11-extensions
}

lappend merger_dont_diff ${prefix}/include/webkitgtk-1.0/webkitdom/WebKitDOMNavigator.h

post-patch {
    # https://bugs.webkit.org/show_bug.cgi?id=88407
    reinplace "s:echo -n:/bin/echo -n:g" \
        ${worksrcpath}/Source/WebCore/GNUmakefile.am

    # https://bugs.webkit.org/show_bug.cgi?id=99683
    reinplace "s:PLATFORM(MAC):OS(DARWIN):g" \
        ${worksrcpath}/Source/JavaScriptCore/heap/VTableSpectrum.cpp \
        ${worksrcpath}/Source/JavaScriptCore/jit/ThunkGenerators.cpp \
        ${worksrcpath}/Source/JavaScriptCore/tools/CodeProfile.cpp

    # https://bugs.webkit.org/show_bug.cgi?id=58737
    reinplace "s:OS(MAC_OS_X):PLATFORM(MAC):" \
        ${worksrcpath}/Source/WTF/wtf/ThreadingPthreads.cpp
}

# TODO: fix this for muniversal
# keep it for debug
#post-destroot {
#    file copy ${worksrcpath}/Programs/.libs/GtkLauncher ${destroot}${prefix}/bin
#}

build.args-append V=1

# see bug #24622
variant quartz {
    configure.args-append --with-target=quartz

    # TODO: See if this will build with OpenGL.framework
    configure.args-delete --enable-webgl
    depends_lib-delete \
        port:mesa \
        port:xorg-libXt

    # quartz-include-widgetbackingstorecairo.patch
    # https://trac.macports.org/ticket/38203
    # https://bugs.webkit.org/show_bug.cgi?id=111598
    patchfiles-append quartz-duplicate-symbols.patch \
                      quartz-include-widgetbackingstorecairo.patch
}

variant video description {Enable HTML5 video support using gstreamer} {
        depends_lib-append      port:gstreamer1-gst-plugins-base
        configure.args-delete   --disable-video
        configure.args-append   --enable-video
}

default_variants +video

platform darwin {
    if {${os.major} < 10} {
        depends_build-append      port:python27
        # https://trac.macports.org/ticket/35793
        configure.python          ${prefix}/bin/python2.7
    }

    if {[string match "*10.5*" ${configure.sdkroot}] ||
        (${os.major} == 9 && ${configure.sdkroot} == "")} {

        # https://trac.macports.org/ticket/37418
        configure.cppflags-append -D__MAC_OS_X_VERSION_MAX_ALLOWED=1050
    }

    if {[string match "*10.4*" ${configure.sdkroot}] ||
        (${os.major} == 8 && ${configure.sdkroot} == "")} {

        # https://trac.macports.org/ticket/37828
        configure.cppflags-append -D__MAC_OS_X_VERSION_MAX_ALLOWED=1040
    }

    if {$macosx_deployment_target == "10.4" ||
        (${os.major} == 8 && $macosx_deployment_target == "")} {

        # https://trac.macports.org/ticket/37828
        configure.cppflags-append -D__MAC_OS_X_VERSION_MIN_REQUIRED=1040
    }
}

platform powerpc {
    # https://trac.macports.org/ticket/37839
    configure.optflags -Os
}

livecheck.type  regex
livecheck.url   http://webkitgtk.org/?page=download
livecheck.regex webkitgtk-(\[0-9\]+\\.\[0-9\]*\[02468\]\\.\[0-9\]+)
