--- base/src/macports1.0/macports.tcl.orig	2008-08-06 02:31:39.000000000 -0600
+++ base/src/macports1.0/macports.tcl	2008-08-19 01:45:44.000000000 -0600
@@ -1715,35 +1715,52 @@
     foreach depspec $depends {
         # grab the portname portion of the depspec
         set dep_portname [lindex [split $depspec :] end]
-        
-        # Find the porturl
-        if {[catch {set res [mportsearch $dep_portname false exact]} error]} {
-            global errorInfo
-            ui_debug "$errorInfo"
-            ui_error "Internal error: port search failed: $error"
-            return 1
-        }
-        
-        unset -nocomplain porturl
-        foreach {name array} $res {
-            array set portinfo $array
-            if {[info exists portinfo(porturl)]} {
-                set porturl $portinfo(porturl)
+
+        unset -nocomplain firstchoice
+        foreach {dep_portname_choice} [split $dep_portname |] {
+            if {![info exists firstchoice]} {
+                set firstchoice $dep_portname_choice
+            }
+            # Find the porturl
+            if {[catch {set res [mportsearch $dep_portname_choice false exact]} error]} {
+                global errorInfo
+                ui_debug "$errorInfo"
+                ui_error "Internal error: port search failed: $error"
+                return 1
+            }
+            
+            unset -nocomplain porturl
+            foreach {name array} $res {
+                array set portinfo $array
+                if {[info exists portinfo(porturl)]} {
+                    set porturl $portinfo(porturl)
+                    break
+                }
+            }
+    
+            if {![info exists porturl]} {
+                ui_error "Dependency '$dep_portname_choice' not found."
+                return 1
+            }
+    
+            set options [ditem_key $mport options]
+            set variations [ditem_key $mport variations]
+    
+            # Figure out the subport.   
+            set subport [mportopen $porturl $options $variations]
+            if {[_mportispresent $subport $depspec]} {
                 break
+            } else {
+                mportclose $subport
+                unset subport
             }
         }
 
-        if {![info exists porturl]} {
-            ui_error "Dependency '$dep_portname' not found."
-            return 1
+        if {![info exists subport]} {
+            array set firstchoiceinfo [lindex [mportsearch $firstchoice false exact] 1]
+            set subport [mportopen $firstchoiceinfo(porturl) $options $variations]
         }
 
-        set options [ditem_key $mport options]
-        set variations [ditem_key $mport variations]
-
-        # Figure out the subport.   
-        set subport [mportopen $porturl $options $variations]
-
         # Is that dependency satisfied or this port installed?
         # If we don't skip or if it is not, add it to the list.
         if {!$skipSatisfied || ![_mportispresent $subport $depspec]} {

