--- Portfile.orig	2016-02-19 02:29:46.000000000 +0100
+++ Portfile	2016-02-19 02:18:44.000000000 +0100
@@ -2,10 +2,10 @@
 # $Id: Portfile 143827 2015-12-23 04:48:08Z devans@macports.org $
 
 PortSystem 1.0
-PortGroup               qt4 1.0
+PortGroup               cxx11 1.0
 
 name                    ipe
-version                 7.1.10
+version                 7.2.2
 set branch              [join [lrange [split ${version} .] 0 1] .]
 categories              graphics
 maintainers             gmail.com:m7.thon openmaintainer
@@ -18,32 +18,38 @@
                         Acrobat Reader.
 license                 GPL-3+
 homepage                http://ipe.otfried.org
-platforms               darwin
+platforms               macosx
 master_sites            https://dl.bintray.com/otfried/generic/ipe/${branch}
 distname                ${name}-${version}-src
 worksrcdir              ${name}-${version}/src
 
-checksums               sha1    1fec414df0ce63fe7da2694a56ab808224c37288 \
-                        rmd160  6a2c3404a3673d901728f09f902601b9a3ba6947
+checksums               sha1    a0934e9c01487219ae4726ab1cac42cc6fd27e96 \
+                        rmd160  12fdc48bf37a477b5f6dddd2f18cbdafa1dd8ca0
 
 depends_lib-append      port:freetype \
                         path:lib/pkgconfig/cairo.pc:cairo \
                         port:lua \
-                        path:lib/libjpeg.dylib:jpeg \
                         port:libpng \
                         port:zlib
 
-patchfiles              patch-ipelib-ipebitmap_unix.cpp.diff \
-                        patch-common.mak.diff \
-                        patch-ipelets-lua-Makefile.diff
+patchfiles              patch-ipe-mainmenu.xib.diff
 
 use_configure           no
+universal_variant       no
 
-variant universal {}
+variant qt4 conflicts qt5 description {Build using Qt4 based gui} {
+    PortGroup           qt4 1.0
+    build.args-append   QT_CFLAGS="`pkg-config --cflags QtGui QtCore`" \
+                        QT_LIBS="`pkg-config --libs QtGui QtCore`"
+}
+
+variant qt5 conflicts qt4 description {Build using Qt5 based gui} {
+    PortGroup           qt5 1.0
+}
 
 variant qvoronoi description {Add qvoronoi ipelet} {
     depends_lib-append  port:qhull
-    build.post_args     IPEQVORONOI=1 QHULL_CFLAGS=-I${prefix}/include/qhull
+    build.args-append   IPEQVORONOI=1 QHULL_CFLAGS=-I${prefix}/include/qhull
     destroot.post_args  IPEQVORONOI=1
 }
 
@@ -51,42 +57,49 @@
 
 pre-build {
     build.env           CXXFLAGS="[get_canonical_archflags cxx]" \
-                        LDFLAGS="[get_canonical_archflags ld]" \
-                        PKG_CONFIG_PATH=\$PKG_CONFIG_PATH:${qt_pkg_config_dir}
-
-    build.args          IPEPREFIX=${prefix} \
-                        ZLIB_CFLAGS="`pkg-config --cflags zlib`" \
-                        ZLIB_LIBS="`pkg-config --libs zlib`" \
-                        JPEG_LIBS="-ljpeg" \
-                        PNG_CFLAGS="`pkg-config --cflags libpng`" \
-                        PNG_LIBS="`pkg-config --libs libpng`" \
-                        FREETYPE_CFLAGS="`pkg-config --cflags freetype2`" \
-                        FREETYPE_LIBS="`pkg-config --libs freetype2`" \
-                        CAIRO_CFLAGS="`pkg-config --cflags cairo`" \
-                        CAIRO_LIBS="`pkg-config --libs cairo`" \
-                        LUA_CFLAGS="`pkg-config --cflags lua`" \
-                        LUA_LIBS="`pkg-config --libs lua`" \
-                        QT_CFLAGS="`pkg-config --cflags QtGui QtCore`" \
-                        QT_LIBS="`pkg-config --libs QtGui QtCore`" \
-                        MOC=${qt_moc_cmd} \
-                        CXX=${configure.cxx}
+                        LDFLAGS="[get_canonical_archflags ld]"
+    build.args-append   IPEPREFIX=${prefix} \
+                        CXX=${configure.cxx} \
+                        LUA_PACKAGE="lua" \
+                        JPEG_LIBS="-framework ApplicationServices" \
+                        IPECONFIGMAK="config.mak"
+    if {[variant_isset qt4] || [variant_isset qt5]} {
+        build.env-append    PKG_CONFIG_PATH=\$PKG_CONFIG_PATH:${qt_pkg_config_dir}
+        build.args-append   IPEUI="QT" \
+                            MOC=${qt_moc_cmd}
+    } else {
+        build.args-append   IPEBUNDLE=1
+    }
 }
 
-destroot.args-append    IPEPREFIX=${prefix}
-
 use_parallel_build      no
 
+destroot.args-append    IPEPREFIX=${prefix} \
+                        IPECONFIGMAK="config.mak"
+if {[variant_isset qt4] || [variant_isset qt5]} {
+    destroot.args-append    IPEUI="QT"
+} else {
+    destroot.args-append    IPEBUNDLE=1
+    destroot.target         app
+}
+
 platform macosx {
-    depends_build-append port:makeicns
     post-destroot {
-        set app Ipe
-        xinstall -d ${destroot}${applications_dir}/${app}.app/Contents/MacOS \
-            ${destroot}${applications_dir}/${app}.app/Contents/Resources
-        xinstall -m 644 ${filespath}/Info.plist.in ${destroot}${applications_dir}/${app}.app/Contents/Info.plist
-        reinplace "s|@VERSION@|${version}|g" ${destroot}${applications_dir}/${app}.app/Contents/Info.plist
-        reinplace "s|@PREFIX@|${prefix}|g" ${destroot}${applications_dir}/${app}.app/Contents/Info.plist
-        ln -s ${prefix}/bin/ipe ${destroot}${applications_dir}/${app}.app/Contents/MacOS/${app}
-        system "${prefix}/bin/makeicns -in ${worksrcpath}/ipe/icons/ipe.png -out ${destroot}${applications_dir}/${app}.app/Contents/Resources/${name}.icns"
+        if {[variant_isset qt4] || [variant_isset qt5]} {
+            set app Ipe
+            xinstall -d ${destroot}${applications_dir}/${app}.app/Contents/MacOS \
+                ${destroot}${applications_dir}/${app}.app/Contents/Resources
+            xinstall -m 644 ${filespath}/Info.plist.in ${destroot}${applications_dir}/${app}.app/Contents/Info.plist
+            reinplace "s|@VERSION@|${version}|g" ${destroot}${applications_dir}/${app}.app/Contents/Info.plist
+            reinplace "s|@PREFIX@|${prefix}|g" ${destroot}${applications_dir}/${app}.app/Contents/Info.plist
+            ln -s ${prefix}/bin/ipe ${destroot}${applications_dir}/${app}.app/Contents/MacOS/${app}
+            xinstall -m 644 ${worksrcpath}/ipe/ipe.icns ${destroot}${applications_dir}/${app}.app/Contents/Resources/ipe.icns
+        } else {
+            copy ${worksrcpath}/../build/Ipe.app ${destroot}${applications_dir}/Ipe.app
+            reinplace "s|/usr/local/bin|/usr/local/bin:${prefix}/bin|g" ${destroot}${applications_dir}/Ipe.app/Contents/Info.plist
+            xinstall -m 755 ${filespath}/ipe.in ${destroot}${prefix}/bin/ipe
+            reinplace "s|@APPLICATIONSDIR@|${applications_dir}|g" ${destroot}${prefix}/bin/ipe
+        }
     }
 }
 
