--- a/libpp/profile_spec.cpp
+++ b/libpp/profile_spec.cpp
@@ -256,10 +256,8 @@
 }
 
 
-bool profile_spec::match(string const & filename) const
-{
-	filename_spec spec(filename);
-
+bool profile_spec::match(filename_spec const & spec) const
+{
 	// PP:3.3 if spec was defined through sample-file: match it directly
 	if (sample_file_set) {
 		return file_spec.match(spec, binary);
@@ -394,11 +392,13 @@
 
 
 bool valid_candidate(string const & filename, profile_spec const & spec,
-		     bool exclude_dependent)
-{
-	if (spec.match(filename)) {
-		if (exclude_dependent &&
-		    filename.find("{dep}") != string::npos)
+		     bool exclude_dependent, bool exclude_cg)
+{
+	if (exclude_cg && filename.find("{cg}") != string::npos)
+		return false;
+	filename_spec file_spec(filename);
+	if (spec.match(file_spec)) {
+		if (exclude_dependent && file_spec.is_dependant())
 			return false;
 		return true;
 	}
@@ -409,7 +409,8 @@
 }  // anonymous namespace
 
 
-list<string> profile_spec::generate_file_list(bool exclude_dependent) const
+list<string> profile_spec::generate_file_list(bool exclude_dependent,
+  bool exclude_cg) const
 {
 	// FIXME: isn't remove_duplicates faster than doing this, then copy() ?
 	set<string> unique_files;
@@ -453,7 +454,8 @@
 		list<string>::const_iterator it = files.begin();
 		list<string>::const_iterator fend = files.end();
 		for (; it != fend; ++it) {
-			if (valid_candidate(*it, *this, exclude_dependent)) {
+			if (valid_candidate(*it, *this, exclude_dependent,
+			    exclude_cg)) {
 				unique_files.insert(*it);
 			}
 		}