Bug 541709 Figure out toolchain for Makefile projects.

The config is not valid without this. Using the same algorithm CMake
projects do to find the default toolchain.

Change-Id: I871da3019b7d440fbd6c1b2a4935d424f084a603
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakefileBuildConfigurationProvider.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakefileBuildConfigurationProvider.java
index 81c7bae..9a318d5 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakefileBuildConfigurationProvider.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakefileBuildConfigurationProvider.java
@@ -10,15 +10,20 @@
  *******************************************************************************/
 package org.eclipse.cdt.make.core;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.eclipse.cdt.core.build.ICBuildConfiguration;
 import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
 import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
 import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.cdt.core.build.IToolChainManager;
 import org.eclipse.cdt.core.build.StandardBuildConfiguration;
 import org.eclipse.core.resources.IBuildConfiguration;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
 
 /**
  * @since 7.4
@@ -34,6 +39,34 @@
 
 	@Override
 	public ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
+		if (config.getName().equals(IBuildConfiguration.DEFAULT_CONFIG_NAME)) {
+			IToolChain toolChain = null;
+
+			// try the toolchain for the local target
+			Map<String, String> properties = new HashMap<>();
+			properties.put(IToolChain.ATTR_OS, Platform.getOS());
+			properties.put(IToolChain.ATTR_ARCH, Platform.getOSArch());
+			IToolChainManager toolChainManager = MakeCorePlugin.getService(IToolChainManager.class);
+			for (IToolChain tc : toolChainManager.getToolChainsMatching(properties)) {
+				toolChain = tc;
+				break;
+			}
+
+			// local didn't work, try and find one that does
+			if (toolChain == null) {
+				for (IToolChain tc : toolChainManager.getToolChainsMatching(new HashMap<>())) {
+					toolChain = tc;
+					break;
+				}
+			}
+
+			if (toolChain != null) {
+				return new StandardBuildConfiguration(config, name, toolChain, "run"); //$NON-NLS-1$
+			} else {
+				// No valid combinations
+				return null;
+			}
+		}
 		return new StandardBuildConfiguration(config, name);
 	}