From 440660c80b8818b4c1878b984c041374f004f511 Mon Sep 17 00:00:00 2001 From: Sean Evoy Date: Fri, 27 Feb 2004 14:54:22 +0000 Subject: [PATCH] Added a header to the automatically generated makefiles to alert users not to edit them. Also added includes directives to bring in user-supplied makefiles to support additional targets, macro definitions, and custom build steps. Strings are externalized. --- .../ChangeLog | 10 ++- .../internal/core/MakefileGenerator.java | 62 ++++++++++++++++++- .../internal/core/PluginResources.properties | 1 + 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/ChangeLog b/build/org.eclipse.cdt.managedbuilder.core/ChangeLog index 408138f6781..359ee9e3af3 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/ChangeLog +++ b/build/org.eclipse.cdt.managedbuilder.core/ChangeLog @@ -1,4 +1,12 @@ -2004-02-26 +2004-02-26 Jeremiah Lott + Added a header to the automatically generated makefiles to alert users + not to edit them. Also added includes directives to bring in user-supplied + makefiles to support additional targets, macro definitions, and custom + build steps. Strings are externalized. + * src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties + * src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java + +2004-02-26 Sean Evoy Work for C14, add the ability to inherit a tool description via a tool reference. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java index 6b790935fdc..9e77e677ccf 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java @@ -49,10 +49,15 @@ import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; public class MakefileGenerator { + + // this is used to draw a "comment line" + private static final int COLS_PER_LINE = 80; + // String constants for messages private static final String MESSAGE = "ManagedMakeBuilder.message"; //$NON-NLS-1$ private static final String BUILD_ERROR = MESSAGE + ".error"; //$NON-NLS-1$ private static final String COMMENT = "ManagedMakeBuilder.comment"; //$NON-NLS-1$ + private static final String HEADER = COMMENT + ".header"; //$NON-NLS-1$ private static final String MOD_LIST = COMMENT + ".module.list"; //$NON-NLS-1$ private static final String SRC_LISTS = COMMENT + ".source.list"; //$NON-NLS-1$ private static final String MOD_RULES = COMMENT + ".build.rule"; //$NON-NLS-1$ @@ -74,6 +79,9 @@ public class MakefileGenerator { protected static final String WHITESPACE = " "; //$NON-NLS-1$ protected static final String WILDCARD = "%"; //$NON-NLS-1$ protected static final String COMMENT_SYMBOL = "#"; //$NON-NLS-1$ + protected static final String MAKEFILE_INIT = "makefile.init"; //$NON-NLS-1$ + protected static final String MAKEFILE_DEFS = "makefile.defs"; //$NON-NLS-1$ + protected static final String MAKEFILE_TARGETS = "makefile.targets"; //$NON-NLS-1$ // Local variables needed by generator protected IManagedBuildInfo info; @@ -388,6 +396,34 @@ public class MakefileGenerator { } } + protected StringBuffer addTopHeader() { + return addDefaultHeader(); + } + + protected StringBuffer addFragmentMakefileHeader() { + return addDefaultHeader(); + } + + protected StringBuffer addFragmentDependenciesHeader() { + return addDefaultHeader(); + } + + protected void outputCommentLine(StringBuffer buffer) { + for (int i = 0; i < COLS_PER_LINE; i++) { + buffer.append(COMMENT_SYMBOL); + } + buffer.append(NEWLINE); + } + + protected StringBuffer addDefaultHeader() { + StringBuffer buffer = new StringBuffer(); + outputCommentLine(buffer); + buffer.append(COMMENT_SYMBOL+WHITESPACE+ManagedBuilderCorePlugin.getResourceString(HEADER)+NEWLINE); + outputCommentLine(buffer); + buffer.append(NEWLINE); + return buffer; + } + /* (non-javadoc) * @param buffer * @param info @@ -397,10 +433,16 @@ public class MakefileGenerator { // Add the ROOT macro buffer.append("ROOT := .." + NEWLINE); + buffer.append(NEWLINE); + // include makefile.init supplementary makefile + buffer.append("-include $(ROOT)" + SEPARATOR + MAKEFILE_INIT + NEWLINE); + buffer.append(NEWLINE); + // Get the clean command from the build model buffer.append("RM := "); - buffer.append(info.getCleanCommand() + NEWLINE + NEWLINE); + buffer.append(info.getCleanCommand() + NEWLINE); + buffer.append(NEWLINE); buffer.append(COMMENT_SYMBOL + WHITESPACE + ManagedBuilderCorePlugin.getResourceString(SRC_LISTS) + NEWLINE); buffer.append("C_SRCS := " + NEWLINE); @@ -457,8 +499,12 @@ public class MakefileGenerator { buffer.append(NEWLINE); buffer.append(COMMENT_SYMBOL +WHITESPACE + ManagedBuilderCorePlugin.getResourceString(MOD_INCL) + NEWLINE); buffer.append("-include ${patsubst %, %/subdir.mk, $(SUBDIRS)}" + NEWLINE); - - buffer.append(NEWLINE + NEWLINE); + buffer.append(NEWLINE); + + // Include makefile.defs supplemental makefile + buffer.append("-include $(ROOT)" + SEPARATOR + MAKEFILE_DEFS + NEWLINE); + + buffer.append(NEWLINE); return buffer; } @@ -629,6 +675,11 @@ public class MakefileGenerator { buffer.append(COMMENT_SYMBOL + WHITESPACE + ManagedBuilderCorePlugin.getResourceString(DEP_INCL) + NEWLINE); buffer.append("-include ${patsubst %, %/subdir.dep, $(SUBDIRS)}" + NEWLINE); + buffer.append(NEWLINE); + + // Include makefile.targets supplemental makefile + buffer.append("-include $(ROOT)" + SEPARATOR + MAKEFILE_TARGETS + NEWLINE); + return buffer; } @@ -926,6 +977,9 @@ public class MakefileGenerator { protected void populateTopMakefile(IFile fileHandle, boolean rebuild) throws CoreException { StringBuffer buffer = new StringBuffer(); + // Add the header + buffer.append(addTopHeader()); + // Add the macro definitions buffer.append(addMacros()); @@ -958,11 +1012,13 @@ public class MakefileGenerator { // Create a module makefile IFile modMakefile = createFile(moduleOutputDir.addTrailingSeparator().append(MODFILE_NAME)); StringBuffer makeBuf = new StringBuffer(); + makeBuf.append(addFragmentMakefileHeader()); makeBuf.append(addSources(module)); // Create a module dep file IFile modDepfile = createFile(moduleOutputDir.addTrailingSeparator().append(DEPFILE_NAME)); StringBuffer depBuf = new StringBuffer(); + depBuf.append(addFragmentDependenciesHeader()); depBuf.append(addSourceDependencies(module)); // Save the files diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties index 9da4fb7f9ab..3d92c50da41 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties @@ -25,3 +25,4 @@ ManagedMakeBuilder.comment.build.rule = Each subdirectory must supply rules for ManagedMakeBuilder.comment.module.make.includes = Include the makefiles for each source subdirectory ManagedMakeBuilder.comment.module.dep.includes = Include automatically-generated dependency list: ManagedMakeBuilder.comment.autodeps = Automatically-generated dependency list: +ManagedMakeBuilder.comment.header = Automatically-generated file. Do not edit! \ No newline at end of file