[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] fix for 62644
|
This patch provides capability in the makefile generator to
generate macros and rules for arbitrary types of files. This enables one
to, for example, define a tool which will build assembly files (.asm or .s)
into .o files, and then link them together with C/C++ object files.
Sample generated makefiles are attached to the Bugzilla
entry if you are interested in seeing how this is done.
___________________________________________
Chris Recoskie
Texas Instruments, Toronto
|
Index: src/org/eclipse/cdt/managedbuilder/core/ITool.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java,v
retrieving revision 1.5
diff -r1.5 ITool.java
12a13,14
> import java.util.List;
>
92a95,102
>
> // fix for Bugzilla 62644
> /**
> * Return a list of the extentions that this tool knows how to build.
> * @return List
> */
> public List getInputExtensions();
> // end fix for Bugzilla 62644
cvs server: Diffing src/org/eclipse/cdt/managedbuilder/internal
cvs server: Diffing src/org/eclipse/cdt/managedbuilder/internal/core
Index: src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java,v
retrieving revision 1.17
diff -r1.17 MakefileGenerator.java
49a50,55
> import org.eclipse.cdt.managedbuilder.core.ITarget;
> import org.eclipse.cdt.managedbuilder.core.ITool;
> import java.util.Collection;
> import java.util.HashMap;
> import java.util.HashSet;
> import java.util.Set;
425a432,505
>
> // fix for Bugzilla 62644
> protected Set getOutputExtentions()
> {
>
> // get the target for this project
> ITarget myTarget = info.getDefaultTarget();
>
> // get the list of tools associated with our target
> ITool toolArray[] = myTarget.getTools();
>
> // The set of output extensions which will be produced by this tool.
> // It is presumed that this set is not very large (likely < 10) so
> // a HashSet should provide good performance.
> HashSet outputExtensionsSet = new HashSet();
>
> // For each tool for the target, lookup the kinds of sources it outputs
> // and add that to our list of output extensions.
> // TODO Change the ITool interface so we can just directly get the set of extensions?
>
> for(int k = 0; k < toolArray.length; k++)
> {
> List extensionsList = toolArray[k].getInputExtensions();
>
> // iterate over all extensions that the tool knows how to handle
> Iterator exListIterator = extensionsList.iterator();
>
> while(exListIterator.hasNext())
> {
>
> // get the extension name
> String extensionName = exListIterator.next().toString();
>
> // get the output extension for this type of input file and store for later use
> String outputExtension = toolArray[k].getOutputExtension(extensionName);
>
> if(outputExtension != null)
> {
> outputExtensionsSet.add(outputExtension);
> }
> }
>
> }
>
> return outputExtensionsSet;
> }
>
>
> protected StringBuffer getMacroName(String extensionName)
> {
> StringBuffer macroName = new StringBuffer();
>
> // We need to handle case sensitivity in file extensions (e.g. .c vs .C), so if the
> // extension was already upper case, tack on an "UPPER_" to the macro name.
> // In theory this means there could be a conflict if you had for example,
> // extensions .c_upper, and .C, but realistically speaking the chances of this are
> // practically nil so it doesn't seem worth the hassle of generating a truly
> // unique name.
> if(extensionName.equals(extensionName.toUpperCase()))
> {
> macroName.append(extensionName.toUpperCase() + "_UPPER");
> }
>
> else
> {
> // lower case... no need for "UPPER_"
> macroName.append(extensionName.toUpperCase());
> }
>
> macroName.append("_SRCS");
>
> return macroName;
> }
> // end fix for Bugzilla 62644
448,452c528,599
< buffer.append("C_SRCS := " + NEWLINE); //$NON-NLS-1$
< buffer.append("CC_SRCS := " + NEWLINE); //$NON-NLS-1$
< buffer.append("CXX_SRCS := " + NEWLINE); //$NON-NLS-1$
< buffer.append("CAPC_SRCS := " + NEWLINE); //$NON-NLS-1$
< buffer.append("CPP_SRCS := " + NEWLINE + NEWLINE); //$NON-NLS-1$
---
>
> // fix for Bugzilla 62644
> // generate make rules for each type of "source"
>
> // Master list of "object" dependencies, i.e. dependencies between input files and output files.
> StringBuffer objDeps = new StringBuffer();
> objDeps.append("OBJS =");;
> // Dependencies for generated files will not appear here. I.e., if you have a tool which turns
> // A into B, and then another tool which turns B into C, you will only get dependency info
> // which says that B depends on A.
> // TODO Handle dependencies for complex chains of the form A->B->C
>
>
> // get the target for this project
> ITarget myTarget = info.getDefaultTarget();
>
> // get the list of tools associated with our target
> ITool toolArray[] = myTarget.getTools();
>
> // get the set of output extensions for all tools
> Set outputExtensionsSet = getOutputExtentions();
>
> // set of input extensions for which rules have been created so far
> HashSet handledInputExtensionsSet = new HashSet();
>
> // Look at each input extension and generate an appropriate macro for that extension
> // based on whether the file is generated or not. We do not want to create rules for
> // generated files due to the current way the makefile is structured.
> for(int k = 0; k < toolArray.length; k++)
> {
> List extensionsList = toolArray[k].getInputExtensions();
>
> // iterate over all extensions that the tool knows how to handle
> Iterator exListIterator = extensionsList.iterator();
>
> while(exListIterator.hasNext())
> {
>
> // create a macro of the form "EXTENSION_SRCS :="
> String extensionName = exListIterator.next().toString();
>
> // If we are a regular file we get added to the list of object dependencies
> // if we have not already created a rule for this filetype. It is assumed that
> // if multiple tools can handle the same input file extension that they will
> // all map the input extension to the same output extension. This is not explicitly
> // checked however.
>
> // Generated files should not appear in the list.
> if(!outputExtensionsSet.contains(extensionName) && !handledInputExtensionsSet.contains(extensionName))
> {
> handledInputExtensionsSet.add(extensionName);
>
> StringBuffer macroName = getMacroName(extensionName);
>
> buffer.append(macroName + WHITESPACE + ":=" + WHITESPACE + NEWLINE);
>
> // create dependency rule of the form
> // OBJS = $(macroName1: $(ROOT)/%.input1=%.output1) ... $(macroNameN: $(ROOT)/%.inputN=%.outputN)
> objDeps.append(WHITESPACE + "$(" + macroName + COLON + "$(ROOT)" + SEPARATOR + WILDCARD
> + DOT + extensionName + "=" + WILDCARD + DOT +
> toolArray[k].getOutputExtension(extensionName) + ")" );
>
> }
> }
>
> }
>
> buffer.append(NEWLINE + NEWLINE);
>
> objDeps.append(NEWLINE);
> // end fix for Bugzilla 62644
>
472c619,621
< buffer.append("OBJS = $(C_SRCS:$(ROOT)/%.c=%.o) $(CC_SRCS:$(ROOT)/%.cc=%.o) $(CXX_SRCS:$(ROOT)/%.cxx=%.o) $(CAPC_SRCS:$(ROOT)/%.C=%.o) $(CPP_SRCS:$(ROOT)/%.cpp=%.o)" + NEWLINE); //$NON-NLS-1$
---
> buffer.append(objDeps); //$NON-NLS-1$
> buffer.append(NEWLINE);
>
524a674,724
> // fix for Bugzilla 62644
> // generate make rules for each type of "source"
>
> // get the target for this project
> ITarget myTarget = info.getDefaultTarget();
>
> // get the list of tools associated with our target
> ITool toolArray[] = myTarget.getTools();
>
> // For each tool for the target, lookup the kinds of sources it can handle and
> // create a map which will map its extension to a string which holds its list of sources.
>
> HashMap extensionToRuleStringMap = new HashMap();
>
> // get the set of output extensions for all tools
> Set outputExtensionsSet = getOutputExtentions();
>
> // put in rules if the file type is not a generated file
> for(int k = 0; k < toolArray.length; k++)
> {
> List extensionsList = toolArray[k].getInputExtensions();
>
> // iterate over all extensions that the tool knows how to handle
> Iterator exListIterator = extensionsList.iterator();
>
> while(exListIterator.hasNext())
> {
> // create a macro of the form "EXTENSION_SRCS := "
> String extensionName = exListIterator.next().toString();
>
> if(!extensionToRuleStringMap.containsKey(extensionName) && // do we already have a map entry?
> !outputExtensionsSet.contains(extensionName)) // is the file generated?
> {
>
> StringBuffer macroName = getMacroName(extensionName);
>
> // there is no entry in the map, so create a buffer for this extension
> StringBuffer tempBuffer = new StringBuffer();
> tempBuffer.append(macroName + WHITESPACE + "+=" + WHITESPACE + LINEBREAK + NEWLINE);
> tempBuffer.append("${addprefix $(ROOT)/" + relativePath + "," + LINEBREAK + NEWLINE);
>
> // have to store the buffer in String form as StringBuffer is not a sublcass of
> // Object
> extensionToRuleStringMap.put(extensionName, tempBuffer.toString());
> }
>
> }
>
> }
>
>
527,536d726
< StringBuffer cBuffer = new StringBuffer("C_SRCS += " + LINEBREAK + NEWLINE); //$NON-NLS-1$
< cBuffer.append("${addprefix $(ROOT)/" + relativePath + "," + LINEBREAK + NEWLINE); //$NON-NLS-1$//$NON-NLS-2$
< StringBuffer ccBuffer = new StringBuffer("CC_SRCS += \\" + NEWLINE); //$NON-NLS-1$
< ccBuffer.append("${addprefix $(ROOT)/" + relativePath + "," + LINEBREAK + NEWLINE); //$NON-NLS-1$//$NON-NLS-2$
< StringBuffer cxxBuffer = new StringBuffer("CXX_SRCS += \\" + NEWLINE); //$NON-NLS-1$
< cxxBuffer.append("${addprefix $(ROOT)/" + relativePath + "," + LINEBREAK + NEWLINE); //$NON-NLS-1$//$NON-NLS-2$
< StringBuffer capcBuffer = new StringBuffer("CAPC_SRCS += \\" + NEWLINE); //$NON-NLS-1$
< capcBuffer.append("${addprefix $(ROOT)/" + relativePath + "," + LINEBREAK + NEWLINE); //$NON-NLS-1$//$NON-NLS-2$
< StringBuffer cppBuffer = new StringBuffer("CPP_SRCS += \\" + NEWLINE); //$NON-NLS-1$
< cppBuffer.append("${addprefix $(ROOT)/" + relativePath + "," + LINEBREAK + NEWLINE); //$NON-NLS-1$//$NON-NLS-2$
549,558c739,751
< if (new String("c").equals(ext)) { //$NON-NLS-1$
< cBuffer.append(resource.getName() + WHITESPACE + LINEBREAK + NEWLINE);
< } else if (new String("cc").equalsIgnoreCase(ext)) { //$NON-NLS-1$
< ccBuffer.append(resource.getName() + WHITESPACE + LINEBREAK + NEWLINE);
< } else if (new String("cxx").equalsIgnoreCase(ext)) { //$NON-NLS-1$
< cxxBuffer.append(resource.getName() + WHITESPACE + LINEBREAK + NEWLINE);
< } else if (new String("C").equals(ext)) { //$NON-NLS-1$
< capcBuffer.append(resource.getName() + WHITESPACE + LINEBREAK + NEWLINE);
< } else {
< cppBuffer.append(resource.getName() + WHITESPACE + LINEBREAK + NEWLINE);
---
>
> // look for the extension in the map
> StringBuffer bufferForExtension = new StringBuffer();
> bufferForExtension.append(extensionToRuleStringMap.get(ext).toString());
>
> if(bufferForExtension != null &&
> !outputExtensionsSet.contains(bufferForExtension.toString()))
> {
> bufferForExtension.append(resource.getName() + WHITESPACE + LINEBREAK + NEWLINE);
>
> // re-insert string in the map
> extensionToRuleStringMap.put(ext, bufferForExtension.toString());
>
559a753
>
568,573c762,779
< buffer.append(cBuffer.append("}" + NEWLINE + NEWLINE)); //$NON-NLS-1$
< buffer.append(ccBuffer.append("}" + NEWLINE + NEWLINE)); //$NON-NLS-1$
< buffer.append(cxxBuffer.append("}" + NEWLINE + NEWLINE)); //$NON-NLS-1$
< buffer.append(capcBuffer.append("}" + NEWLINE + NEWLINE)); //$NON-NLS-1$
< buffer.append(cppBuffer.append("}" + NEWLINE + NEWLINE)); //$NON-NLS-1$
<
---
> Collection bufferCollection = extensionToRuleStringMap.values();
>
> Iterator collectionIterator = bufferCollection.iterator();
>
> while(collectionIterator.hasNext())
> {
>
> // close off the rule and put two newlines to the buffer
> StringBuffer currentBuffer = new StringBuffer();
> currentBuffer.append(collectionIterator.next().toString());
> currentBuffer.append("}" + NEWLINE + NEWLINE); //$NON-NLS-1$)
>
> // append the contents of the buffer to the master buffer for the whole file
> buffer.append(currentBuffer);
>
>
> }
>
574a781
> // end fix for Bugzilla 62644
Index: src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java,v
retrieving revision 1.17
diff -r1.17 ManagedBuildInfo.java
172c172,178
< return tool.buildsFileType(srcExt);
---
>
> // fix for Bugzilla 62644
> // If the tool does not build the type do not just return.
> // Keep checking until we find one that does or run out of tools.
> if(tool.buildsFileType(srcExt))
> return true;
> // end fix for Bugzilla 62644
177c183,189
< return tool.buildsFileType(srcExt);
---
>
> // fix for Bugzilla 62644
> // If the tool does not build the type do not just return.
> // Keep checking until we find one that does or run out of tools.
> if(tool.buildsFileType(srcExt))
> return true;
> // end fix for Bugzilla 62644
181c193,199
< return tool.buildsFileType(srcExt);
---
>
> // fix for Bugzilla 62644
> // If the tool does not build the type do not just return.
> // Keep checking until we find one that does or run out of tools.
> if(tool.buildsFileType(srcExt))
> return true;
> // end fix for Bugzilla 62644
611a630,634
>
> // fix for Bugzilla 62644
> String outputExtension = null;
> // end fix for Bugzilla 62644
>
616c639,645
< return tool.getOutputExtension(resourceExtension);
---
>
> // fix for Bugzilla 62644
> // don't just return if you get null. Look through all tools first
> outputExtension = tool.getOutputExtension(resourceExtension);
> if(outputExtension != null)
> return outputExtension;
> // end fix for Bugzilla 62644
621c650,656
< return tool.getOutputExtension(resourceExtension);
---
>
> // fix for Bugzilla 62644
> // don't just return if you get null. Look through all tools first
> outputExtension = tool.getOutputExtension(resourceExtension);
> if(outputExtension != null)
> return outputExtension;
> // end fix for Bugzilla 62644
625c660,667
< return tool.getOutputExtension(resourceExtension);
---
>
> // fix for Bugzilla 62644
> // don't just return if you get null. Look through all tools first
> outputExtension = tool.getOutputExtension(resourceExtension);
> if(outputExtension != null)
> return outputExtension;
> // end fix for Bugzilla 62644
>
Index: src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java,v
retrieving revision 1.14
diff -r1.14 Tool.java
188c188
< private List getInputExtensions() {
---
> public List getInputExtensions() {
Index: src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java,v
retrieving revision 1.15
diff -r1.15 ToolReference.java
483a484,494
> // fix for Bugzilla 62644
> /**
> * Return a list of the extentions that this tool knows how to build.
> * @return List
> */
> public List getInputExtensions()
> {
> return this.getTool().getInputExtensions();
> }
> // end fix for Bugzilla 62644
>
cvs server: Diffing src/org/eclipse/cdt/managedbuilder/internal/scannerconfig
cvs server: Diffing src/org/eclipse/cdt/managedbuilder/scannerconfig
*****CVS exited normally with code 1*****