Index: tools/build/v2/build/toolset.jam
===================================================================
--- tools/build/v2/build/toolset.jam	(revision 49367)
+++ tools/build/v2/build/toolset.jam	(working copy)
@@ -11,12 +11,13 @@
 import generators ;
 import numbers ;
 import path ;
+import project ;
 import property ;
+import property-set ;
 import regex ;
 import sequence ;
 import set ;
 
-
 .flag-no = 1 ;
 
 .ignore-requirements = ;
@@ -152,7 +153,24 @@
         condition = [ normalize-condition $(condition) ] ;
     }
 
-    add-flag $(rule-or-module) : $(variable-name) : $(condition) : $(values) ;
+    local caller-location = [ modules.binding $(caller) ] ;
+    caller-location = $(caller-location:D) ;
+
+    local new-values = ;
+    for local v in $(values)
+    {
+        local target = [ MATCH (.*)//(.*) : $(v) ] ;
+        if $(target) && ! [ path.is-rooted $(target[1]) ] && $(caller-location)
+        {
+            new-values += $(caller-location)/$(v) ;
+        }
+        else
+        {
+            new-values += $(v) ;
+        }
+    }
+
+    add-flag $(rule-or-module) : $(variable-name) : $(condition) : $(new-values) ;
 }
 
 
@@ -224,6 +242,24 @@
     return $(result) ;
 }
 
+rule actualize-target-from-qualified-reference ( value : property-set )
+{
+    import targets ;
+    local result ;
+    if ! $(value:G)
+    {
+        local target = [ MATCH (.*)//(.*) : $(v) ] ;
+        if $(target) && ! $(v:G)
+        {
+            local project-module = [ project.find $(target[1]) : . ] ;
+            local project = [ project.target $(project-module) ] ;
+            local generated-target = [ targets.generate-from-reference
+                $(target[2]) : $(project) : $(property-set) ] ;
+            result += [ $(generated-target[2]).actualize ] ;
+        }
+    }
+    return $(result) ;
+}
 
 # Returns a value to be added to some flag for some target based on the flag's
 # value definition and the given target's property set.
@@ -275,12 +311,52 @@
     }
     else
     {
-        result += $(value) ;
+        local target = [ actualize-target-from-qualified-reference
+            $(value) : [ property-set.create $(properties) ] ] ;
+
+        if $(target)
+        {
+            result += $(target) ;
+        }
+        else
+        {
+            result += $(value) ;
+        }
     }
     return $(result) ;
 }
 
+rule find-dependency-flags-aux ( rule-or-module : property-set )
+{
+    local result ;
+    properties = [ $(property-set).raw ] ;
+    for local f in $(.$(rule-or-module).flags)
+    {
+        local variable = $(.$(rule-or-module).variable.$(f)) ;
+        local condition = $(.$(rule-or-module).condition.$(f)) ;
+        local values = $(.$(rule-or-module).values.$(f)) ;
 
+        if ! $(condition) ||
+            [ find-property-subset $(condition) : $(properties) ]
+        {
+            local processed ;
+            for local v in $(values)
+            {
+                result += [ actualize-target-from-qualified-reference
+                    $(v) : $(property-set) ] ;
+            }
+        }
+    }
+
+    # Strip away last dot separated part and recurse.
+    local next = [ MATCH ^(.+)\\.([^\\.])* : $(rule-or-module) ] ;
+    if $(next)
+    {
+        result += [ find-dependency-flags-aux $(next[1]) : $(property-set) ] ;
+    }
+    return $(result) ;
+}
+
 # Given a rule name and a property set, returns a list of interleaved variables
 # names and values which must be set on targets for that rule/property-set
 # combination.
@@ -335,7 +411,9 @@
         {
             settings = none ;
         }
+
         .stv.$(key) = $(settings) ;
+        .stvdep.$(key) = [ find-dependency-flags-aux $(rule-or-module) : $(property-set) ] ;
     }
 
     if $(settings) != none
@@ -353,6 +431,7 @@
                 var-name = $(name-or-value) ;
             }
         }
+        DEPENDS $(targets) : $(.stvdep.$(key)) ;
     }
 }
 
