From 07a476a1fe494e403697db250886a6fcb03f03ec Mon Sep 17 00:00:00 2001 From: Leo Treggiari Date: Fri, 28 Jan 2005 03:40:20 +0000 Subject: [PATCH] Fix makefile generation problems with resource configurations --- .../gnu/DefaultGCCDependencyCalculator.java | 77 ++++++++++++++++--- .../makegen/gnu/GnuMakefileGenerator.java | 30 ++------ 2 files changed, 73 insertions(+), 34 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator.java index cfdeb0ec479..63c890aa19a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/DefaultGCCDependencyCalculator.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2004 IBM Corporation and others. + * Copyright (c) 2004,2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,13 @@ **********************************************************************/ package org.eclipse.cdt.managedbuilder.makegen.gnu; +import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator; +import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo; +import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; +import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator; import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator; import org.eclipse.core.resources.IContainer; @@ -22,6 +28,8 @@ import org.eclipse.core.resources.IResource; */ public class DefaultGCCDependencyCalculator implements IManagedDependencyGenerator { + private static final String[] EMPTY_STRING_ARRAY = new String[0]; + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderDependencyCalculator#findDependencies(org.eclipse.core.resources.IResource) */ @@ -47,14 +55,18 @@ public class DefaultGCCDependencyCalculator implements IManagedDependencyGenerat * */ StringBuffer buffer = new StringBuffer(); - + // Get what we need to create the dependency generation command + IConfiguration config = info.getDefaultConfiguration(); + + // We need to check whether we have any resource specific build information. + IResourceConfiguration resConfig = null; + if( config != null ) resConfig = config.getResourceConfiguration(resource.getFullPath().toString()); + String inputExtension = resource.getFileExtension(); - String cmd = info.getToolForSource(inputExtension); String outputExtension = info.getOutputExtension(inputExtension); - String buildFlags = info.getFlagsForSource(inputExtension); - // Work out the build-relative path + // Work out the build-relative path for the output files IContainer resourceLocation = resource.getParent(); String relativePath = new String(); if (resourceLocation != null) { @@ -90,20 +102,61 @@ public class DefaultGCCDependencyCalculator implements IManagedDependencyGenerat IManagedBuilderMakefileGenerator.WHITESPACE + IManagedBuilderMakefileGenerator.LINEBREAK); - // Add the line that will do the work - buffer.append(IManagedBuilderMakefileGenerator.TAB + + // Add the line that will do the work to calculate dependencies + IManagedCommandLineInfo cmdLInfo = null; + String buildCmd = null; + String[] inputs= new String[1]; inputs[0] = IManagedBuilderMakefileGenerator.IN_MACRO; + String outflag = ""; //$NON-NLS-1$ + String outputPrefix = ""; //$NON-NLS-1$ + String outputFile = ""; //$NON-NLS-1$ + if( resConfig != null) { + ITool[] tools = resConfig.getTools(); + String cmd = tools[0].getToolCommand(); + String[] toolFlags = null; + try { + toolFlags = tools[0].getCommandFlags(); + } catch( BuildException ex ) { + // TODO add some routines to catch this + toolFlags = EMPTY_STRING_ARRAY; + } + String[] flags = new String[toolFlags.length + 4]; + flags[0] = "-MM"; //$NON-NLS-1$ + flags[1] = "-MG"; //$NON-NLS-1$ + flags[2] = "-P"; //$NON-NLS-1$ + flags[3] = "-w"; //$NON-NLS-1$ + for (int i=0; i>" + //$NON-NLS-1$ IManagedBuilderMakefileGenerator.WHITESPACE + depRule); - + return buffer.toString(); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java index 66014d8170c..0630d1eb4e7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2003,2004 IBM Corporation and others. + * Copyright (c) 2003,2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v0.5 * which accompanies this distribution, and is available at @@ -220,7 +220,9 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { private static final String MOD_INCL = COMMENT + ".module.make.includes"; //$NON-NLS-1$ private static final String MOD_LIST = COMMENT + ".module.list"; //$NON-NLS-1$ private static final String MOD_RULES = COMMENT + ".build.rule"; //$NON-NLS-1$ - private static final String SRC_LISTS = COMMENT + ".source.list"; //$NON-NLS-1$ + private static final String SRC_LISTS = COMMENT + ".source.list"; //$NON-NLS-1$ + + private static final String[] EMPTY_STRING_ARRAY = new String[0]; // Local variables needed by generator private String buildTargetName; @@ -333,7 +335,6 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { * @param resource */ private void addRule(String relativePath, StringBuffer buffer, IResource resource) { - String buildFlags = null; String resourceName = getFileName(resource); String inputExtension = resource.getFileExtension(); String cmd = info.getToolForSource(inputExtension); @@ -403,34 +404,19 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { buffer.append(TAB + AT + ECHO + WHITESPACE + SINGLE_QUOTE + MESSAGE_START_FILE + WHITESPACE + IN_MACRO + SINGLE_QUOTE + NEWLINE); IManagedCommandLineInfo cmdLInfo = null; - String[] inputs = null; + String[] inputs; if( resConfig != null) { ITool[] tools = resConfig.getTools(); - try { - buildFlags = tools[0].getToolFlags(); - } catch (BuildException e) { - buildFlags = null; - } outflag = tools[0].getOutputFlag(); outputPrefix = tools[0].getOutputPrefix(); cmd = tools[0].getToolCommand(); - // The command to build - - String fileName; - String rootDir = "../"; //$NON-NLS-1$ - if (isItLinked) { - fileName = resourcePath; - } else { - fileName = rootDir + relativePath + resConfig.getName(); - } - - inputs = new String[1]; inputs[0] = fileName; + inputs = new String[1]; inputs[0] = IN_MACRO; String[] flags = null; try { flags = tools[0].getCommandFlags(); } catch( BuildException ex ) { // TODO add some routines to catch this - flags = null; + flags = EMPTY_STRING_ARRAY; } IManagedCommandLineGenerator cmdLGen = tools[0].getCommandLineGenerator(); cmdLInfo = cmdLGen.generateCommandLineInfo( tools[0], cmd, flags, outflag, outputPrefix, @@ -440,7 +426,7 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator { buffer.append(TAB + AT + ECHO + WHITESPACE + buildCmd + NEWLINE); buffer.append(TAB + AT + buildCmd); } else { - buildFlags = info.getFlagsForSource(inputExtension); + String buildFlags = info.getFlagsForSource(inputExtension); outflag = info.getOutputFlag(outputExtension); outputPrefix = info.getOutputPrefix(outputExtension); String[] flags = buildFlags.split( "\\s" ); //$NON-NLS-1$