--- Portfile.orig	2013-12-22 10:30:22.000000000 +0100
+++ Portfile	2014-03-30 16:32:26.000000000 +0200
@@ -2,14 +2,124 @@
 # $Id: Portfile 115019 2013-12-22 09:29:46Z ryandesign@macports.org $
 
 PortSystem      1.0
-PortGroup       cmake 1.0
+PortGroup       github 1.0
 
+#PortGroup       cmake 1.0
+# ffmpeg, optional dependency, currenly requires openjpeg15, but vxl uses/packs openjpeg (2.0)
+# The cmake portgroup includes the prefix as cflags, what prevent internal openjpeg paths to be included before all others, even through include_directories(BEFORE ...)
+# https://trac.macports.org/ticket/42872
+# currently append ${prefix}/var/macports/sources/rsync.macports.org/release/tarballs/ports/_resources/port1.0/group/cmake-1.0.tcl it here until the issue is resolved
+# standard place to install extra CMake modules
+set cmake_share_module_dir ${prefix}/share/cmake/modules
+
+depends_build-append port:cmake
+
+#FIXME: ccache works with cmake on linux
+configure.ccache    no
+
+configure.cmd       ${prefix}/bin/cmake
+
+configure.pre_args  -DCMAKE_INSTALL_PREFIX=${prefix}
+
+configure.args      -DCMAKE_VERBOSE_MAKEFILE=ON \
+                    -DCMAKE_COLOR_MAKEFILE=ON \
+                    -DCMAKE_BUILD_TYPE=Release \
+                    -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
+                    -DCMAKE_INSTALL_RPATH=${prefix}/lib \
+                    -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \
+                    -DCMAKE_SYSTEM_PREFIX_PATH="${prefix}\;/usr" \
+                    -DCMAKE_MODULE_PATH=${cmake_share_module_dir} \
+                    -DCMAKE_FIND_FRAMEWORK=LAST \
+                    -Wno-dev
+
+# CMake honors set environment variables CFLAGS, CXXFLAGS, and LDFLAGS when it
+# is first run in a build directory to initialize CMAKE_C_FLAGS,
+# CMAKE_CXX_FLAGS, CMAKE_[EXE|SHARED|MODULE]_LINKER_FLAGS. However, be aware
+# that a CMake script can always override these flags when it runs, as they
+# are frequently set internally in functions of other CMake build variables!
+#
+# Attention: If you want to be sure that no compiler flags are passed via
+# configure.args, you have to manually clear configure.optflags, as it is set
+# to "-Os" by default and added to all language-specific flags. If you want to
+# turn off optimization, explicitly set configure.optflags to "-O0".
+
+# TODO: Handle configure.objcflags (cf. to CMake upstream ticket #4756
+#       "CMake needs an Objective-C equivalent of CMAKE_CXX_FLAGS"
+#       <http://public.kitware.com/Bug/view.php?id=4756>)
+
+# TODO: Handle the Fortran-specific configure.* variables:
+#       configure.fflags, configure.fcflags, configure.f90flags
+
+# TODO: Handle the Java-specific configure.classpath variable.
+
+pre-configure {
+    # The environment variable CPPFLAGS is not considered by CMake.
+    # (CMake upstream ticket #12928 "CMake silently ignores CPPFLAGS"
+    # <http://www.cmake.org/Bug/view.php?id=12928>).
+    # Thus, we have to add them manually to the CFLAGS and CXXFLAGS in the
+    # pre-configure phase.
+#    if {${configure.cppflags} ne ""} {
+#        configure.cflags-append ${configure.cppflags}
+#        configure.cxxflags-append ${configure.cppflags}
+#    }
+
+    # In addition, CMake provides build-type-specific flags for
+    # Release (-O3 -DNDEBUG), Debug (-g), MinSizeRel (-Os -DNDEBUG), and
+    # RelWithDebInfo (-O2 -g -DNDEBUG). If the configure.optflags have been
+    # set (-Os by default), we have to remove the optimization flags from the
+    # from the concerned Release build type so that configure.optflags
+    # gets honored (Debug used by the +debug variant does not set
+    # optimization flags by default).
+    if {${configure.optflags} ne ""} {
+        configure.args-append -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
+                              -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG"
+    }
+
+    platform darwin {
+        if {[variant_exists universal] && [variant_isset universal]} {
+            if {[info exists universal_archs_supported]} {
+                global merger_configure_args
+                foreach arch ${universal_archs_to_use} {
+                    lappend merger_configure_args(${arch}) -DCMAKE_OSX_ARCHITECTURES=${arch}
+                }
+            } else {
+                configure.universal_args-append \
+                    -DCMAKE_OSX_ARCHITECTURES="[join ${configure.universal_archs} \;]"
+            }
+        } else {
+            configure.args-append \
+                -DCMAKE_OSX_ARCHITECTURES="${configure.build_arch}"
+        }
+        if {${configure.sdkroot} != ""} {
+            configure.args-append -DCMAKE_OSX_SYSROOT="${configure.sdkroot}"
+        } else {
+            # Witout this, cmake will choose an SDK and deployment target on its own.
+            configure.args-append -DCMAKE_OSX_SYSROOT=/ -DCMAKE_OSX_DEPLOYMENT_TARGET=""
+        }
+    }
+}
+
+configure.universal_args-delete --disable-dependency-tracking
+
+variant debug description "Enable debug binaries" {
+    configure.args-delete   -DCMAKE_BUILD_TYPE=Release
+    configure.args-append   -DCMAKE_BUILD_TYPE=Debug
+}
+
+# cmake doesn't like --enable-debug, so in case a portfile sets
+# --enable-debug (regardless of variant) we remove it
+if {[string first "--enable-debug" ${configure.args}] > -1} {
+    configure.args-delete     --enable-debug
+}
+# end of copy
+
+github.setup    vxl vxl 22e5ccd9fa
 name            vxl
 version         1.17.0
-revision        1
+revision        2
 set branch      [join [lrange [split ${version} .] 0 1] .]
 categories      devel
-maintainers     nomaintainer
+maintainers     nomaintainer gmail:christian.frisson
 description     C++ libraries for computer vision
 long_description \
     VXL (the Vision-something-Libraries) is a collection of C++ libraries \
@@ -20,11 +130,17 @@
 homepage        http://vxl.sourceforge.net/
 platforms       darwin
 
-master_sites    sourceforge:project/vxl/vxl/${branch}
-use_zip         yes
-checksums       md5     95b5ecbbe164d1b540ab52fd0ca26b47 \
-                sha1    bfa7e9df3fb8807ef3b14921c31d568e94f3edf4 \
-                rmd160  a00d811aa86b2d3a2dad292ff94991c034092434
+# Checksums for non-git release
+#master_sites    sourceforge:project/vxl/vxl/${branch}
+#use_zip         yes
+#checksums       md5     95b5ecbbe164d1b540ab52fd0ca26b47 \
+#                sha1    bfa7e9df3fb8807ef3b14921c31d568e94f3edf4 \
+#                rmd160  a00d811aa86b2d3a2dad292ff94991c034092434
+
+# Checksums for git version
+checksums           md5     7858eaa862f150fe78031e2a37fbe1d9 \
+                    sha1    b6068e8145244f6fb12ba739e94ed668630e8474 \
+                    rmd160  5c8ce5bfa9911149cf71906e5d36081d26ad77bd
 
 # licenses in vxl:
 # (see also: http://anonscm.debian.org/viewvc/debian-med/trunk/packages/vxl/trunk/debian/copyright?revision=10688&view=markup)
@@ -45,9 +161,15 @@
 # disable ffmpeg support that fails to build with current ffmpeg versions
 # disable broken contrib/prip code
 
-patchfiles      patch-use-embedded-openjpeg2.diff \
-                patch-disable-broken-ffmpeg.diff \
-                patch-disable-contrib-prip.diff
+# Patches for non-git release
+#patchfiles      patch-use-embedded-openjpeg2.diff \
+#                patch-disable-broken-ffmpeg.diff \
+#                patch-disable-contrib-prip.diff
+
+# Patches for git version
+patchfiles      patch-fix-include-openjpeg.diff \
+                patch-fix-ffmpeg-support.diff \
+                patch-fix-find-X11.diff
                 
 depends_lib-append \
                 port:jpeg \
@@ -58,14 +180,16 @@
                 port:bzip2 \
                 port:libdc1394
 
-if {[string match *clang* ${configure.compiler}]} {
-    configure.cxxflags-append -Werror=gnu -Wno-error=vla
-}
+# This fails with the git version
+#if {[string match *clang* ${configure.compiler}]} {
+#    configure.cxxflags-append -Werror=gnu -Wno-error=vla
+#}
 
 configure.args-append \
     -DBUILD_SHARED_LIBS=YES \
     -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib/${name} \
-    -DBUILD_BRL=NO
+    -DBUILD_BRL=NO \
+    -DVXL_FORCE_V3P_OPENJPEG2=ON
 
 # shuffle directories around to turn ${prefix}/lib into ${prefix}/lib/${name}
 post-destroot {
