=== modified file 'cmdline/apt-get.cc'
--- cmdline/apt-get.cc	2012-06-18 11:19:47 +0000
+++ cmdline/apt-get.cc	2012-08-04 22:58:56 +0000
@@ -2895,11 +2895,15 @@
 	    if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep)
 	    {
 	       size_t const colon = D->Package.find(":");
-	       if (colon != string::npos &&
-		   (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0))
-		  Pkg = Cache->FindPkg(D->Package.substr(0,colon));
+	       if (colon != string::npos)
+	       {
+		  if (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0)
+		     Pkg = Cache->FindPkg(D->Package.substr(0,colon));
+		  else
+		     Pkg = Cache->FindPkg(D->Package);
+	       }
 	       else
-		  Pkg = Cache->FindPkg(D->Package);
+		  Pkg = Cache->FindPkg(D->Package, hostArch);
 
 	       // a bad version either is invalid or doesn't satify dependency
 	       #define BADVER(Ver) (Ver.end() == true || \
@@ -2918,13 +2922,13 @@
 	       }
 	       if (verlist.empty() == true)
 	       {
-		  pkgCache::PkgIterator HostPkg = Cache->FindPkg(D->Package, hostArch);
-		  if (HostPkg.end() == false)
+		  pkgCache::PkgIterator BuildPkg = Cache->FindPkg(D->Package, "native");
+		  if (BuildPkg.end() == false && Pkg != BuildPkg)
 		  {
-		     pkgCache::VerIterator Ver = (*Cache)[HostPkg].InstVerIter(*Cache);
+		     pkgCache::VerIterator Ver = (*Cache)[BuildPkg].InstVerIter(*Cache);
 		     if (BADVER(Ver) == false)
 			verlist.insert(Ver);
-		     Ver = (*Cache)[HostPkg].CandidateVerIter(*Cache);
+		     Ver = (*Cache)[BuildPkg].CandidateVerIter(*Cache);
 		     if (BADVER(Ver) == false)
 			verlist.insert(Ver);
 		  }
@@ -2943,6 +2947,8 @@
 			Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
 		     else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
 			forbidden = "Multi-Arch: none";
+		     else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
+			Pkg = Ver.ParentPkg().Group().FindPkg("native");
 		  }
 		  else if (Ver->MultiArch == pkgCache::Version::Same)
 		  {
@@ -2950,11 +2956,15 @@
 			Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
 		     else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
 			forbidden = "Multi-Arch: same";
-		     // :native gets the buildArch
+		     else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
+			Pkg = Ver.ParentPkg().Group().FindPkg("native");
 		  }
 		  else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
 		  {
-		     if (colon != string::npos)
+		     if (colon == string::npos)
+			Pkg = Ver.ParentPkg().Group().FindPkg("native");
+		     else if (strcmp(D->Package.c_str() + colon, ":any") == 0 ||
+			      strcmp(D->Package.c_str() + colon, ":native") == 0)
 			forbidden = "Multi-Arch: foreign";
 		  }
 		  else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
@@ -2972,7 +2982,8 @@
 			if (Pkg.end() == true)
 			   Pkg = Grp.FindPreferredPkg(true);
 		     }
-		     // native gets buildArch
+		     else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
+			Pkg = Ver.ParentPkg().Group().FindPkg("native");
 		  }
 
 		  if (forbidden.empty() == false)
@@ -3004,7 +3015,7 @@
 	    else
 	       Pkg = Cache->FindPkg(D->Package);
 
-	    if (Pkg.end() == true)
+	    if (Pkg.end() == true || (Pkg->VersionList == 0 && Pkg->ProvidesList == 0))
             {
                if (_config->FindB("Debug::BuildDeps",false) == true)
                     cout << " (not found)" << (*D).Package << endl;
@@ -3087,7 +3098,7 @@
 	       }
 	    }
 
-            if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false) == true)
+            if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false,false) == true)
             {
                // We successfully installed something; skip remaining alternatives
                skipAlternatives = hasAlternatives;

=== modified file 'test/integration/test-bug-632221-cross-dependency-satisfaction'
--- test/integration/test-bug-632221-cross-dependency-satisfaction	2012-07-12 18:39:59 +0000
+++ test/integration/test-bug-632221-cross-dependency-satisfaction	2012-08-04 22:40:40 +0000
@@ -63,6 +63,7 @@
 Inst specific (1.0 unstable [amd64])
 Conf libc6 (1.0 unstable [amd64])
 Conf specific (1.0 unstable [amd64])' aptget build-dep source-specific-amd64 -s -a armel
+
 testequal 'Reading package lists...
 Building dependency tree...
 The following NEW packages will be installed:

=== added file 'test/integration/test-bug-683786-build-dep-on-virtual-packages'
--- test/integration/test-bug-683786-build-dep-on-virtual-packages	1970-01-01 00:00:00 +0000
+++ test/integration/test-bug-683786-build-dep-on-virtual-packages	2012-08-04 22:04:12 +0000
@@ -0,0 +1,81 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'amd64' 'armel'
+
+insertinstalledpackage 'build-essential' 'all' '11.5' 'Multi-Arch: foreign'
+
+insertpackage 'unstable' 'po-debconf' 'all' '1'
+insertsource 'unstable' 'dash' 'any' '1' 'Build-Depends: po-debconf'
+insertpackage 'unstable' 'make-po-debconf-pure-virtual' 'armel' '1' 'Depends: po-debconf'
+
+insertpackage 'unstable' 'po-debconf' 'amd64' '1'
+insertsource 'unstable' 'diffutils' 'any' '1' 'Build-Depends: texi2html'
+
+insertpackage 'unstable' 'libselinux1-dev' 'amd64' '1' 'Provides: libselinux-dev'
+insertsource 'unstable' 'sed' 'any' '1' 'Build-Depends: libselinux-dev'
+
+insertpackage 'unstable' 'libsehurd1-dev' 'amd64,armel' '1' 'Provides: libsehurd-dev'
+insertsource 'unstable' 'sed2' 'any' '1' 'Build-Depends: libsehurd-dev'
+
+setupaptarchive
+
+testequal 'Package: po-debconf:armel
+Versions: 
+
+Reverse Depends: 
+  make-po-debconf-pure-virtual:armel,po-debconf:armel
+Dependencies: 
+Provides: 
+Reverse Provides: ' aptcache showpkg po-debconf:armel
+testequal 'N: Unable to locate package texi2html' aptcache showpkg texi2html:armel -q=0
+
+testequal 'Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+  po-debconf
+0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
+Inst po-debconf (1 unstable, unstable [all])
+Conf po-debconf (1 unstable, unstable [all])' aptget build-dep dash -s
+
+testequal 'Reading package lists...
+Building dependency tree...
+E: Build-Depends dependency for dash cannot be satisfied because the package po-debconf cannot be found' aptget build-dep -aarmel dash -s
+
+testequal 'Reading package lists...
+Building dependency tree...
+E: Build-Depends dependency for diffutils cannot be satisfied because the package texi2html cannot be found' aptget build-dep -aarmel diffutils -s
+
+testequal "Reading package lists...
+Building dependency tree...
+Note, selecting 'libselinux1-dev' instead of 'libselinux-dev'
+The following NEW packages will be installed:
+  libselinux1-dev
+0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
+Inst libselinux1-dev (1 unstable [amd64])
+Conf libselinux1-dev (1 unstable [amd64])" aptget build-dep sed -s
+
+testequal 'Reading package lists...
+Building dependency tree...
+E: Build-Depends dependency for sed cannot be satisfied because the package libselinux-dev cannot be found' aptget build-dep -aarmel sed -s
+
+testequal "Reading package lists...
+Building dependency tree...
+Note, selecting 'libsehurd1-dev' instead of 'libsehurd-dev'
+The following NEW packages will be installed:
+  libsehurd1-dev
+0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
+Inst libsehurd1-dev (1 unstable [amd64])
+Conf libsehurd1-dev (1 unstable [amd64])" aptget build-dep sed2 -s
+
+testequal "Reading package lists...
+Building dependency tree...
+Note, selecting 'libsehurd1-dev:armel' instead of 'libsehurd-dev:armel'
+The following NEW packages will be installed:
+  libsehurd1-dev:armel
+0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
+Inst libsehurd1-dev:armel (1 unstable [armel])
+Conf libsehurd1-dev:armel (1 unstable [armel])" aptget build-dep -aarmel sed2 -s

