Index: Portfile
===================================================================
--- Portfile	(revision 140736)
+++ Portfile	(working copy)
@@ -238,15 +238,26 @@
 patchfiles-append   \
     patch-tools_macdeployqt_shared_shared.cpp.diff
 
-# error out if trying to build on a new OSX version (> 10.10).
+# (23) remove ColorSync usage from qpaintengine.
 
+# This patch allows for building using the 10.11 SDK, and is also
+# backward compatible with prior OS versions since it just removes API
+# usage but does not otherwise add any. This patch does roughly the
+# same thing as that from Qt5 commit b06304e16:
+# http://code.qt.io/cgit/qt/qtbase.git/commit/?id=b06304e164ba47351fa292662c1e6383c081b5ca
+
+patchfiles-append   \
+    patch-src_gui_painting_qpaintengine_mac.diff
+
+# error out if trying to build on a new OSX version (> 10.11).
+
 platform darwin {
-    if {${MINOR} > 10} {
+    if {${MINOR} > 11} {
         # This project needs to be updated to build with clang++ against libc++
         depends_lib
         depends_run
         pre-fetch {
-            ui_error "$name does not currently build on OSX later than 10.10 'Yosemite'."
+            ui_error "$name does not currently build on OSX later than 10.11 'El Capitan'."
             error "unsupported platform"
         }
     }
Index: files/patch-src_gui_painting_qpaintengine_mac.diff
===================================================================
--- files/patch-src_gui_painting_qpaintengine_mac.diff	(nonexistent)
+++ files/patch-src_gui_painting_qpaintengine_mac.diff	(working copy)
@@ -0,0 +1,106 @@
+--- src/gui/painting/qpaintengine_mac.cpp.orig
++++ src/gui/painting/qpaintengine_mac.cpp
+@@ -289,7 +289,7 @@ static CGMutablePathRef qt_mac_compose_path(const QPainterPath &p, float off=0)
+ }
+ 
+ CGColorSpaceRef QCoreGraphicsPaintEngine::m_genericColorSpace = 0;
+-QHash<QWidget*, CGColorSpaceRef> QCoreGraphicsPaintEngine::m_displayColorSpaceHash; // window -> color space
++QHash<CGDirectDisplayID, CGColorSpaceRef> QCoreGraphicsPaintEngine::m_displayColorSpaceHash;
+ bool QCoreGraphicsPaintEngine::m_postRoutineRegistered = false;
+ 
+ CGColorSpaceRef QCoreGraphicsPaintEngine::macGenericColorSpace()
+@@ -318,48 +318,31 @@ CGColorSpaceRef QCoreGraphicsPaintEngine::macGenericColorSpace()
+ 
+ CGColorSpaceRef QCoreGraphicsPaintEngine::macDisplayColorSpace(const QWidget *widget)
+ {
+-    // The color space depends on which screen the widget's window is on.
+-    // widget == 0 is a spacial case where we use the main display.
+-    QWidget *window = widget ? widget->window() : 0;
++    CGColorSpaceRef colorSpace;
+ 
+-    // Check for cached color space and return if found.
+-    if (m_displayColorSpaceHash.contains(window))
+-        return m_displayColorSpaceHash.value(window);
+-
+-    // Find which display the window is on.
+     CGDirectDisplayID displayID;
+-    if (window == 0) {
++    if (widget == 0) {
+         displayID = CGMainDisplayID();
+     } else {
+-        const QRect &qrect = window->geometry();
++        const QRect &qrect = widget->window()->geometry();
+         CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height());
+         CGDisplayCount throwAway;
+         CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway);
+         if (dErr != kCGErrorSuccess)
+-            displayID = CGMainDisplayID();
+-    }
+-
+-    // Get the color space from the display profile.
+-    CGColorSpaceRef colorSpace = 0;
+-    CMProfileRef displayProfile = 0;
+-    CMError err = CMGetProfileByAVID((CMDisplayIDType)displayID, &displayProfile);
+-    if (err == noErr) {
+-        colorSpace = CGColorSpaceCreateWithPlatformColorSpace(displayProfile);
+-        CMCloseProfile(displayProfile);
++            return macDisplayColorSpace(0); // fall back on main display
+     }
++    if ((colorSpace = m_displayColorSpaceHash.value(displayID)))
++        return colorSpace;
+ 
+-    // Fallback: use generic DeviceRGB
++    colorSpace = CGDisplayCopyColorSpace(displayID);
+     if (colorSpace == 0)
+         colorSpace = CGColorSpaceCreateDeviceRGB();
+ 
+-    // Install cleanup routines
++    m_displayColorSpaceHash.insert(displayID, colorSpace);
+     if (!m_postRoutineRegistered) {
+         m_postRoutineRegistered = true;
+         qAddPostRoutine(QCoreGraphicsPaintEngine::cleanUpMacColorSpaces);
+     }
+-
+-    // Cache and return.
+-    m_displayColorSpaceHash.insert(window, colorSpace);
+     return colorSpace;
+ }
+ 
+@@ -369,7 +352,7 @@ void QCoreGraphicsPaintEngine::cleanUpMacColorSpaces()
+         CFRelease(m_genericColorSpace);
+         m_genericColorSpace = 0;
+     }
+-    QHash<QWidget*, CGColorSpaceRef>::const_iterator it = m_displayColorSpaceHash.constBegin();
++    QHash<CGDirectDisplayID, CGColorSpaceRef>::const_iterator it = m_displayColorSpaceHash.constBegin();
+     while (it != m_displayColorSpaceHash.constEnd()) {
+         if (it.value())
+             CFRelease(it.value());
+@@ -1069,7 +1052,16 @@ void QCoreGraphicsPaintEngine::cleanup()
+ 
+ void QCoreGraphicsPaintEngine::clearColorSpace(QWidget* w)
+ {
+-    m_displayColorSpaceHash.remove(w);
++    CGDirectDisplayID displayID = CGMainDisplayID();
++    if (w != 0) {
++        const QRect &qrect = w->window()->geometry();
++        CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height());
++        CGDisplayCount throwAway;
++        CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway);
++        if (dErr != kCGErrorSuccess)
++	    displayID = CGMainDisplayID();
++    }
++    m_displayColorSpaceHash.remove(displayID);
+ }
+ 
+ CGContextRef
+--- src/gui/painting/qpaintengine_mac_p.h.orig
++++ src/gui/painting/qpaintengine_mac_p.h
+@@ -135,7 +135,7 @@ protected:
+ private:
+     static bool m_postRoutineRegistered;
+     static CGColorSpaceRef m_genericColorSpace;
+-    static QHash<QWidget*, CGColorSpaceRef> m_displayColorSpaceHash; // window -> color space
++    static QHash<CGDirectDisplayID, CGColorSpaceRef> m_displayColorSpaceHash;
+     static void cleanUpMacColorSpaces();
+     Q_DISABLE_COPY(QCoreGraphicsPaintEngine)
+ };
