--- mkspecs/features/qt_functions.prf.orig	2012-05-11 10:33:49.000000000 -0400
+++ mkspecs/features/qt_functions.prf	2012-05-25 13:15:09.000000000 -0400
@@ -16,24 +16,54 @@
 }
 
 defineTest(qtAddLibrary) {
+#    message(qtAddLibrary: 'LIBS' before $$1 is '$${LIBS}')
+#    message(qtAddLibrary: 'INCLUDEPATH' before $$1 is '$${INCLUDEPATH}')
+#    message(qtAddLibrary: 'QMAKE_LFLAGS' before $$1 is '$${QMAKE_LFLAGS}')
+
+    # reorder the includes path: user, this library, Qt headers
+    INCLUDEPATH -= $$QMAKE_INCDIR_QT
     INCLUDEPATH -= $$QMAKE_INCDIR_QT/$$1
-    INCLUDEPATH = $$QMAKE_INCDIR_QT/$$1 $$INCLUDEPATH
+    INCLUDEPATH += $$QMAKE_INCDIR_QT/$$1 $$QMAKE_INCDIR_QT
+
+    # first time through, append the path for Qt's installed libraries:
+    # -after- all of the other necessary libraries and paths
+
+    mac:!static:contains(QT_CONFIG, qt_framework) {
+      isEmpty(QMAKE_FRAMEWORKDIR_QT) {
+         !contains(LIBS,-F$$[QT_INSTALL_PREFIX]/Library/Frameworks) {
+	   LIBS = $$LIBS -F$$[QT_INSTALL_PREFIX]/Library/Frameworks
+	 }
+      } else {
+        !contains(LIBS,-F$$QMAKE_FRAMEWORKDIR_QT) {
+ 	  LIBS = $$LIBS -F$$QMAKE_FRAMEWORKDIR_QT
+	}
+      }
+      isEmpty(QMAKE_LIBDIR_QT) {
+         !contains(LIBS,-F$$[QT_INSTALL_PREFIX]/lib) {
+	   LIBS = $$LIBS -F$$[QT_INSTALL_PREFIX]/lib
+	 }
+      } else {
+        !contains(LIBS,-F$$QMAKE_LIBDIR_QT) {
+ 	  LIBS = $$LIBS -F$$QMAKE_LIBDIR_QT
+	}
+      }
+    }
+    isEmpty(QMAKE_LIBDIR_QT) {
+       !contains(LIBS,-L$$[QT_INSTALL_PREFIX]/lib) {
+         LIBS = $$LIBS -L$$[QT_INSTALL_PREFIX]/lib
+       }
+    } else {
+      !contains(LIBS,-L$$QMAKE_LIBDIR_QT) {
+        LIBS = $$LIBS -L$$QMAKE_LIBDIR_QT
+      }
+    }
 
     LIB_NAME = $$1
     unset(LINKAGE)
-    mac {
-       CONFIG(qt_framework, qt_framework|qt_no_framework) { #forced
-          QMAKE_FRAMEWORKPATH *= $${QMAKE_LIBDIR_QT}
-          FRAMEWORK_INCLUDE = $$QMAKE_LIBDIR_QT/$${LIB_NAME}.framework/Headers
-          !qt_no_framework_direct_includes:exists($$FRAMEWORK_INCLUDE) {
-             INCLUDEPATH -= $$FRAMEWORK_INCLUDE
-             INCLUDEPATH = $$FRAMEWORK_INCLUDE $$INCLUDEPATH
-           }
-           LINKAGE = -framework $${LIB_NAME}$${QT_LIBINFIX}
-        } else:!qt_no_framework { #detection
-           for(frmwrk_dir, $$list($$QMAKE_LIBDIR_QT $$QMAKE_LIBDIR $$(DYLD_FRAMEWORK_PATH) /Library/Frameworks)) {
-       	      exists($${frmwrk_dir}/$${LIB_NAME}.framework) {
-                QMAKE_FRAMEWORKPATH *= $${frmwrk_dir}
+    mac:!qt_no_framework {
+       for(frmwrk_dir, $$list($$QMAKE_FRAMEWORKDIR_QT $$QMAKE_LIBDIR_QT $$QMAKE_LIBDIR $$(DYLD_FRAMEWORK_PATH))) {
+           exists($${frmwrk_dir}/$${LIB_NAME}.framework) {
+               QMAKE_FRAMEWORKPATH *= $${frmwrk_dir}
     	        FRAMEWORK_INCLUDE = $$frmwrk_dir/$${LIB_NAME}.framework/Headers
     	        !qt_no_framework_direct_includes:exists($$FRAMEWORK_INCLUDE) {
     	          INCLUDEPATH -= $$FRAMEWORK_INCLUDE
@@ -42,8 +72,7 @@
     	        LINKAGE = -framework $${LIB_NAME}
        	        break()
               }
-           }
-       }
+         }
     }
     symbian {
         isEqual(LIB_NAME, QtCore) {
@@ -73,7 +102,16 @@
     isEmpty(LINKAGE) {
        if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
            win32:LINKAGE = -l$${LIB_NAME}$${QT_LIBINFIX}d
-           mac:LINKAGE = -l$${LIB_NAME}$${QT_LIBINFIX}_debug
+	   # special for mac: cannot build QtWebKit as debug,
+	   # no-framework, and universal.  If things got here,
+	   # then this is no-framwork; just take care of the rest.
+	   mac {
+	       contains(QT_CONFIG, x86):contains(QT_CONFIG, x86_64):isEqual(LIB_NAME, QtWebKit) {
+	           LINKAGE = -l$${LIB_NAME}$${QT_LIBINFIX}
+	       } else {
+                   LINKAGE = -l$${LIB_NAME}$${QT_LIBINFIX}_debug
+               }
+           }
        }
        isEmpty(LINKAGE):LINKAGE = -l$${LIB_NAME}$${QT_LIBINFIX}
     }
@@ -83,6 +121,9 @@
         QMAKE_LFLAGS *= --lsb-shared-libs=$${LIB_NAME}$${QT_LIBINFIX}
     }
     LIBS += $$LINKAGE
+#    message(qtAddLibrary: 'LIBS' after $$1 is now '$${LIBS}')
+#    message(qtAddLibrary: 'INCLUDEPATH' after $$1 is now '$${INCLUDEPATH}')
+#    message(qtAddLibrary: 'QMAKE_LFLAGS' after $$1 is now '$${QMAKE_LFLAGS}')
     export(LIBS)
     export(INCLUDEPATH)
     export(QMAKE_FRAMEWORKPATH)
@@ -119,4 +160,3 @@
 
     return(true)
 }
-
