# -*- 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 118103 2014-03-22 17:51:24Z devans@macports.org $

PortSystem      1.0

name            cogl
version         1.18.0
set branch      [join [lrange [split ${version} .] 0 1] .]
categories      graphics
description     A hardware accelerated 3D graphics API
long_description \
                Cogl is a small open source library for using 3D graphics hardware \
                for rendering. The API departs from the flat state machine style \
                of OpenGL and is designed to make it easy to write orthogonal \
                components that can render without stepping on each others toes.
license         LGPL-2+
maintainers     devans openmaintainer
platforms       darwin
homepage        https://wiki.gnome.org/Projects/Clutter
master_sites    gnome:sources/${name}/${branch}

use_xz          yes

checksums       rmd160  4aab31afc68a80e9611a99a68339c07d12587018 \
                sha256  a4d91ebf7e7aba362eb5c6e4ffebbf1167ff4ac87fabae104912d879a5390f5e

# Pulling in port:grep due to this error observed on the Lion buildbot:
# libtool: link: /usr/bin/grep -E -e "^(cogl|_cogl_debug_flags|_cogl_atlas_new|_cogl_atlas_add_reorganize_callback|_cogl_atlas_reserve_space|_cogl_callback|_cogl_util_get_eye_planes_for_screen_poly|_cogl_atlas_texture_remove_reorganize_callback|_cogl_atlas_texture_add_reorganize_callback|_cogl_texture_foreach_sub_texture_in_region|_cogl_profile_trace_message|_cogl_context_get_default|_cogl_framebuffer_get_stencil_bits|_cogl_clip_stack_push_rectangle|_cogl_framebuffer_get_modelview_stack|_cogl_object_default_unref|_cogl_pipeline_foreach_layer_internal|_cogl_clip_stack_push_primitive|_cogl_buffer_unmap_for_fill_or_fallback|_cogl_framebuffer_draw_primitive|_cogl_debug_instances|_cogl_framebuffer_get_projection_stack|_cogl_pipeline_layer_get_texture|_cogl_buffer_map_for_fill_or_fallback|_cogl_framebuffer_get_clip_state|_cogl_texture_can_hardware_repeat|_cogl_pipeline_prune_to_n_layers|_cogl_primitive_draw|test_|unit_test_).*" ".libs/libcogl.exp" > ".libs/libcogl.expT"
# grep: Regular expression too big
depends_build   port:pkgconfig port:grep

depends_lib     path:lib/pkgconfig/cairo.pc:cairo \
                path:lib/pkgconfig/pango.pc:pango \
                port:gobject-introspection

patchfiles      leopard.patch \
                patch-clock_gettime.diff

use_autoreconf  yes
autoreconf.args -fvi

configure.args  --enable-introspection=yes \
                --enable-cogl-pango=yes \
                --disable-silent-rules

use_parallel_build no

#
# if clutter is installed and version is less than 1.12.0
# deactivate clutter before activating cogl to avoid conflict
#
# previous versions included cogl in port clutter
#

pre-activate {
    if { [file exists ${prefix}/lib/pkgconfig/clutter-1.0.pc]
        && ![catch {set vers [lindex [registry_active clutter] 0]}]
        && [vercmp [lindex $vers 1] 1.12.0] < 0} {
        
        registry_deactivate clutter "" "" "" [list ports_nodepcheck 1]
    }
}

# gobject-introspection uses g-ir-scanner, which uses $CC from env
build.args-append       CC="${configure.cc} ${configure.cc_archflags}"
destroot.args-append    CC="${configure.cc} ${configure.cc_archflags}"

variant x11 conflicts quartz {
    patchfiles-append     patch-disable-quartz.diff
    depends_lib-append    port:gdk-pixbuf2 \
                          port:mesa \
                          port:xorg-libXcomposite \
                          port:xorg-libXdamage \
                          port:xorg-libXext \
                          port:xorg-libXfixes \
                          port:xorg-libXrandr
    configure.args-append --with-x \
                          --x-includes=${prefix}/include \
                          --x-libraries=${prefix}/lib \
                          --enable-glx=yes \
                          --enable-gdk-pixbuf=yes \
                          --enable-quartz-image=no
}

variant quartz conflicts x11 {
    configure.args-append --enable-glx=no \
                          --enable-gdk-pixbuf=no \
                          --enable-quartz-image=yes \
                          --without-x
    configure.ldflags-append    \
                          -framework ApplicationServices \
                          -framework QuartzCore
}

variant debug description {Enable debugging} {
    configure.optflags -g -O0
    configure.args-append --enable-debug=yes
}

variant examples description {Install simple example applications} {
    configure.args-append --enable-examples-install=yes
}

variant gstreamer description {Enable GStreamer support} {
    configure.args-append --enable-cogl-gst

    depends_lib-append    port:gstreamer1
}

if {![variant_isset quartz]} {
    default_variants +x11
}

livecheck.type  gnome
