7c7b625
--- com.redhat.eclipse.cdt.autotools/src/com/redhat/eclipse/cdt/autotools/AutotoolsMakefileBuilder.java.fix	2006-08-08 14:47:55.000000000 -0400
7c7b625
+++ com.redhat.eclipse.cdt.autotools/src/com/redhat/eclipse/cdt/autotools/AutotoolsMakefileBuilder.java	2006-08-08 14:48:25.000000000 -0400
7c7b625
@@ -18,12 +18,19 @@ import java.util.Vector;
7c7b625
 
7c7b625
 import org.eclipse.cdt.make.core.IMakeBuilderInfo;
7c7b625
 import org.eclipse.cdt.make.core.MakeCorePlugin;
7c7b625
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
7c7b625
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
7c7b625
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
7c7b625
+import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
7c7b625
+import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
7c7b625
 import org.eclipse.cdt.managedbuilder.internal.core.GeneratedMakefileBuilder;
7c7b625
+import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
7c7b625
 import org.eclipse.core.resources.ICommand;
7c7b625
 import org.eclipse.core.resources.IProject;
7c7b625
 import org.eclipse.core.resources.IProjectDescription;
7c7b625
 import org.eclipse.core.runtime.CoreException;
7c7b625
 import org.eclipse.core.runtime.IProgressMonitor;
7c7b625
+import org.eclipse.core.runtime.NullProgressMonitor;
7c7b625
 
7c7b625
 /**
7c7b625
  * This is the incremental builder associated with a managed build project. It dynamically 
7c7b625
@@ -34,6 +41,8 @@ import org.eclipse.core.runtime.IProgres
7c7b625
 public class AutotoolsMakefileBuilder extends GeneratedMakefileBuilder {
7c7b625
 	public static final String BUILDER_NAME = "genmakebuilder"; //$NON-NLS-1$
7c7b625
 	public static final String BUILDER_ID = AutotoolsPlugin.getUniqueIdentifier() + "." + BUILDER_NAME; //$NON-NLS-1$
7c7b625
+	public static final String MANAGED_BUILDER_ID = ManagedBuilderCorePlugin.getUniqueIdentifier() + "." + BUILDER_NAME; //$NON-NLS-1$
7c7b625
+	public static final String AUTOTOOLS_CONFIG_ID = AutotoolsPlugin.getUniqueIdentifier() + ".configuration1"; //$NON-NLS-1$
7c7b625
 
7c7b625
 	private IMakeBuilderInfo info;
7c7b625
 	
7c7b625
@@ -46,16 +55,21 @@ public class AutotoolsMakefileBuilder ex
7c7b625
 		IProjectDescription description = project.getDescription();
7c7b625
 		ICommand[] commands = description.getBuildSpec();
7c7b625
 
7c7b625
-		// TODO Remove this when the new StandardBuild nature adds the cbuilder
7c7b625
+		// TODO Remove the cbuilder check when the new StandardBuild nature adds the cbuilder
7c7b625
 		for (int i = 0; i < commands.length; i++) {
7c7b625
 			ICommand command = commands[i];
7c7b625
-			if (command.getBuilderName().equals("org.eclipse.cdt.core.cbuilder")) { //$NON-NLS-1$
7c7b625
+			String builderName = command.getBuilderName();
7c7b625
+			// If there is a ManagedMake makefile generator, remove it as it will
7c7b625
+			// cause an additional build "all" to occur when we are making any target.
7c7b625
+			if (builderName.equals("org.eclipse.cdt.core.cbuilder") ||
7c7b625
+					builderName.equals(MANAGED_BUILDER_ID)) { //$NON-NLS-1$
7c7b625
 				// Remove the command
7c7b625
 				Vector vec = new Vector(Arrays.asList(commands));
7c7b625
 				vec.removeElementAt(i);
7c7b625
 				vec.trimToSize();
7c7b625
 				ICommand[] tempCommands = (ICommand[]) vec.toArray(new ICommand[commands.length-1]); 
7c7b625
 				description.setBuildSpec(tempCommands);
7c7b625
+				project.setDescription(description, null);
7c7b625
 				break;
7c7b625
 			}
7c7b625
 		}
7c7b625
@@ -84,12 +98,18 @@ public class AutotoolsMakefileBuilder ex
7c7b625
 	
7c7b625
 	public static boolean hasTargetBuilder(IProject project) {
7c7b625
 		try {
7c7b625
-			IProjectDescription description = project.getDescription();
7c7b625
-			ICommand[] commands = description.getBuildSpec();
7c7b625
-			// See if the builder is already there
7c7b625
-			
7c7b625
-			for (int i = 0; i < commands.length; ++i) {
7c7b625
-				if (commands[i].getBuilderName().equals(BUILDER_ID)) {
7c7b625
+			// When a project is converted to an Autotools project, we
7c7b625
+			// replace the ManagedMake builder with a special one that
7c7b625
+			// handles MakeTargets.  If a project is brought into Eclipse and
7c7b625
+			// uses the New Project Wizard to create a ManagedMake project that
7c7b625
+			// is of type: Autotools, this added step is not done.  If we know
7c7b625
+			// we have an Autotools project from the configuration id, then
7c7b625
+			// we should add the builder now and return true.
7c7b625
+			if (project.getNature(ManagedCProjectNature.MNG_NATURE_ID) != null) {
7c7b625
+				IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
7c7b625
+				IConfiguration config = info.getDefaultConfiguration();
7c7b625
+				if (config.getParent().getId().equals(AUTOTOOLS_CONFIG_ID)) {
7c7b625
+					addAutotoolsBuilder(project, new NullProgressMonitor());
7c7b625
 					return true;
7c7b625
 				}
7c7b625
 			}