1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-07 16:26:11 +02:00

Fix makefile generation problems with resource configurations

This commit is contained in:
Leo Treggiari 2005-01-28 03:40:20 +00:00
parent 39fbe46d19
commit 07a476a1fe
2 changed files with 73 additions and 34 deletions

View file

@ -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<toolFlags.length; i++) {
flags[4+i] = toolFlags[i];
}
IManagedCommandLineGenerator cmdLGen = tools[0].getCommandLineGenerator();
cmdLInfo = cmdLGen.generateCommandLineInfo( tools[0], cmd, flags, outflag, outputPrefix,
outputFile, inputs, tools[0].getCommandLinePattern() );
buildCmd = cmdLInfo.getCommandLine();
} else {
String cmd = info.getToolForSource(inputExtension);
String buildFlags = "-MM -MG -P -w " + info.getFlagsForSource(inputExtension); //$NON-NLS-1$
String[] flags = buildFlags.split( "\\s" ); //$NON-NLS-1$
cmdLInfo = info.generateCommandLineInfo( inputExtension, flags, outflag, outputPrefix,
outputFile, inputs );
// The command to build
if( cmdLInfo == null ) buildCmd =
cmd +
IManagedBuilderMakefileGenerator.WHITESPACE +
"-MM -MG -P -w" + //$NON-NLS-1$
IManagedBuilderMakefileGenerator.WHITESPACE +
"-MM -MG -P -w " + //$NON-NLS-1$
buildFlags +
IManagedBuilderMakefileGenerator.WHITESPACE +
IManagedBuilderMakefileGenerator.IN_MACRO +
IManagedBuilderMakefileGenerator.WHITESPACE +
IManagedBuilderMakefileGenerator.IN_MACRO;
else {
buildCmd = cmdLInfo.getCommandLine();
}
}
buffer.append(IManagedBuilderMakefileGenerator.TAB +
buildCmd +
IManagedBuilderMakefileGenerator.WHITESPACE +
">>" + //$NON-NLS-1$
IManagedBuilderMakefileGenerator.WHITESPACE +
depRule);
return buffer.toString();
}

View file

@ -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$