11package it .baeyens .arduino .toolchain ;
22
3- import it .baeyens .arduino .common .ArduinoConst ;
4- import it .baeyens .arduino .common .Common ;
5-
63import java .io .ByteArrayInputStream ;
74import java .io .IOException ;
85import java .io .InputStream ;
8582import org .eclipse .core .runtime .Status ;
8683import org .eclipse .core .runtime .SubProgressMonitor ;
8784
85+ import it .baeyens .arduino .common .ArduinoConst ;
86+ import it .baeyens .arduino .common .Common ;
87+
8888/**
8989 * This is a specialized makefile generator that takes advantage of the extensions present in Gnu Make.
9090 *
@@ -251,9 +251,9 @@ public boolean visit(IResourceProxy proxy) throws CoreException {
251251 if (rcInfo instanceof IFolderInfo ) {
252252 String ext = resource .getFileExtension ();
253253 if (((IFolderInfo ) rcInfo ).buildsFileType (ext ) &&
254- // If this file resource is a generated resource, then
255- // it is uninteresting
256- !generator .isGeneratedResource (resource )) {
254+ // If this file resource is a generated resource, then
255+ // it is uninteresting
256+ !generator .isGeneratedResource (resource )) {
257257 willBuild = true ;
258258 }
259259 } else {
@@ -284,11 +284,11 @@ public boolean visit(IResourceProxy proxy) throws CoreException {
284284
285285 // String constants for makefile contents and messages
286286 private static final String COMMENT = "MakefileGenerator.comment" ; //$NON-NLS-1$
287- //private static final String AUTO_DEP = COMMENT + ".autodeps"; //$NON-NLS-1$
288- //private static final String MESSAGE = "ManagedMakeBuilder.message"; //$NON-NLS-1$
289- //private static final String BUILD_ERROR = MESSAGE + ".error"; //$NON-NLS-1$
287+ // private static final String AUTO_DEP = COMMENT + ".autodeps"; //$NON-NLS-1$
288+ // private static final String MESSAGE = "ManagedMakeBuilder.message"; //$NON-NLS-1$
289+ // private static final String BUILD_ERROR = MESSAGE + ".error"; //$NON-NLS-1$
290290
291- //private static final String DEP_INCL = COMMENT + ".module.dep.includes"; //$NON-NLS-1$
291+ // private static final String DEP_INCL = COMMENT + ".module.dep.includes"; //$NON-NLS-1$
292292 private static final String HEADER = COMMENT + ".header" ; //$NON-NLS-1$
293293
294294 protected static final String MESSAGE_FINISH_BUILD = ManagedMakeMessages .getResourceString ("MakefileGenerator.message.finish.build" ); //$NON-NLS-1$
@@ -297,7 +297,7 @@ public boolean visit(IResourceProxy proxy) throws CoreException {
297297 protected static final String MESSAGE_START_FILE = ManagedMakeMessages .getResourceString ("MakefileGenerator.message.start.file" ); //$NON-NLS-1$
298298 protected static final String MESSAGE_START_DEPENDENCY = ManagedMakeMessages .getResourceString ("MakefileGenerator.message.start.dependency" ); //$NON-NLS-1$
299299 protected static final String MESSAGE_NO_TARGET_TOOL = ManagedMakeMessages .getResourceString ("MakefileGenerator.message.no.target" ); //$NON-NLS-1$
300- //private static final String MOD_INCL = COMMENT + ".module.make.includes"; //$NON-NLS-1$
300+ // private static final String MOD_INCL = COMMENT + ".module.make.includes"; //$NON-NLS-1$
301301 private static final String MOD_LIST = COMMENT + ".module.list" ; //$NON-NLS-1$
302302 private static final String MOD_VARS = COMMENT + ".module.variables" ; //$NON-NLS-1$
303303 private static final String MOD_RULES = COMMENT + ".build.rule" ; //$NON-NLS-1$
@@ -775,8 +775,8 @@ public MultiStatus generateMakefiles(IResourceDelta delta) throws CoreException
775775 // TODO: fix error message
776776 for (IResource res : getInvalidDirList ()) {
777777 IContainer subDir = (IContainer ) res ;
778- status .add (new Status (IStatus .WARNING , ManagedBuilderCorePlugin .getUniqueIdentifier (), SPACES_IN_PATH , subDir . getFullPath ()
779- .toString (), null ));
778+ status .add (new Status (IStatus .WARNING , ManagedBuilderCorePlugin .getUniqueIdentifier (), SPACES_IN_PATH ,
779+ subDir . getFullPath () .toString (), null ));
780780 }
781781 } else {
782782 status = new MultiStatus (ManagedBuilderCorePlugin .getUniqueIdentifier (), IStatus .OK , new String (), null );
@@ -1220,12 +1220,12 @@ protected StringBuffer addTopHeader() {
12201220 }
12211221
12221222 /**
1223- */
1223+ */
12241224 private StringBuffer addMacros () {
12251225 StringBuffer buffer = new StringBuffer ();
12261226
12271227 // Add the ROOT macro
1228- //buffer.append("ROOT := .." + NEWLINE); //$NON-NLS-1$
1228+ // buffer.append("ROOT := .." + NEWLINE); //$NON-NLS-1$
12291229 // buffer.append(NEWLINE);
12301230
12311231 // include makefile.init supplementary makefile
@@ -1236,8 +1236,8 @@ private StringBuffer addMacros() {
12361236 buffer .append ("RM := " ); //$NON-NLS-1$
12371237
12381238 // support macros in the clean command
1239- String cleanCommand = "rm -rf " ; // config.getCleanCommand(); Modded by
1240- // JABA
1239+ String cleanCommand = "rm -f " ; // config.getCleanCommand(); Modded by
1240+ // JABA
12411241
12421242 // try {
12431243 // cleanCommand =
@@ -1274,7 +1274,7 @@ private StringBuffer addMacros() {
12741274 }
12751275
12761276 // Change the include of the "root" (our sketch) folder to be before libraries and other files
1277- //buffer.append("-include subdir.mk" + NEWLINE); //$NON-NLS-1$
1277+ // buffer.append("-include subdir.mk" + NEWLINE); //$NON-NLS-1$
12781278
12791279 buffer .append ("-include objects.mk" + NEWLINE + NEWLINE ); //$NON-NLS-1$
12801280
@@ -1474,8 +1474,8 @@ private StringBuffer addTargets(List<String> outputVarsAdditionsList, boolean re
14741474 dependency = escapeWhitespaces (dependency );
14751475 managedProjectOutputs .add (dependency );
14761476 // }
1477- buffer .append (TAB
1478- + "-cd" + WHITESPACE + escapeWhitespaces ( buildDir ) + WHITESPACE + LOGICAL_AND + WHITESPACE + "$(MAKE) " + depTargets + NEWLINE ); //$NON-NLS-1$ //$NON-NLS-2$
1477+ buffer .append (TAB + "-cd" + WHITESPACE + escapeWhitespaces ( buildDir ) + WHITESPACE + LOGICAL_AND + WHITESPACE + "$(MAKE) " + depTargets //$NON-NLS-1$ //$NON-NLS-2$
1478+ + NEWLINE );
14791479 }
14801480 // }
14811481 buffer .append (NEWLINE );
@@ -1601,7 +1601,7 @@ private StringBuffer addTargetsRules(ITool targetTool, List<String> outputVarsAd
16011601 buffer .append (TAB + "-$(RM)" + WHITESPACE ); //$NON-NLS-1$
16021602 for (Entry <String , List <IPath >> entry : buildOutVars .entrySet ()) {
16031603 String macroName = entry .getKey ();
1604- buffer .append ("$(" + macroName + ")" ); //$NON-NLS-1$ //$NON-NLS-2$
1604+ buffer .append ("$(" + macroName + ")" ); //$NON-NLS-1$ //$NON-NLS-2$
16051605 }
16061606 String outputPrefix = EMPTY_STRING ;
16071607 if (targetTool != null ) {
@@ -1612,7 +1612,7 @@ private StringBuffer addTargetsRules(ITool targetTool, List<String> outputVarsAd
16121612 completeBuildTargetName = completeBuildTargetName + DOT + buildTargetExt ;
16131613 }
16141614 if (completeBuildTargetName .contains (" " )) { //$NON-NLS-1$
1615- buffer .append (WHITESPACE + "\" " + completeBuildTargetName + "\" " ); //$NON-NLS-1$ //$NON-NLS-2$
1615+ buffer .append (WHITESPACE + "\" " + completeBuildTargetName + "\" " ); //$NON-NLS-1$ //$NON-NLS-2$
16161616 } else {
16171617 buffer .append (WHITESPACE + completeBuildTargetName );
16181618 }
@@ -1721,10 +1721,8 @@ protected boolean addRuleForTool(ITool tool, StringBuffer buffer, boolean bTarge
17211721 String command = tool .getToolCommand ();
17221722 try {
17231723 // try to resolve the build macros in the tool command
1724- String resolvedCommand = ManagedBuildManager
1725- .getBuildMacroProvider ()
1726- .resolveValueToMakefileFormat (command , EMPTY_STRING , WHITESPACE , IBuildMacroProvider .CONTEXT_FILE ,
1727- new FileContextData (null , null , null , tool )).replaceFirst (" -w " , " " );
1724+ String resolvedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValueToMakefileFormat (command , EMPTY_STRING , WHITESPACE ,
1725+ IBuildMacroProvider .CONTEXT_FILE , new FileContextData (null , null , null , tool )).replaceFirst (" -w " , " " );
17281726 if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
17291727 command = resolvedCommand ;
17301728
@@ -1754,10 +1752,8 @@ protected boolean addRuleForTool(ITool tool, StringBuffer buffer, boolean bTarge
17541752 // resolve any remaining macros in the command after it has been
17551753 // generated
17561754 try {
1757- String resolvedCommand = ManagedBuildManager
1758- .getBuildMacroProvider ()
1759- .resolveValueToMakefileFormat (buildCmd , EMPTY_STRING , WHITESPACE , IBuildMacroProvider .CONTEXT_FILE ,
1760- new FileContextData (null , null , null , tool )).replaceFirst (" -w " , " " );
1755+ String resolvedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValueToMakefileFormat (buildCmd , EMPTY_STRING , WHITESPACE ,
1756+ IBuildMacroProvider .CONTEXT_FILE , new FileContextData (null , null , null , tool )).replaceFirst (" -w " , " " );
17611757 if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
17621758 buildCmd = resolvedCommand ;
17631759
@@ -1963,8 +1959,8 @@ private StringBuffer addSubdirectories() {
19631959
19641960 // Get all the module names
19651961 for (IResource container : getSubdirList ()) {
1966- updateMonitor (ManagedMakeMessages
1967- .getFormattedString ("MakefileGenerator.message.adding.source.folder" , container .getFullPath ().toString ())); //$NON-NLS-1$
1962+ updateMonitor (
1963+ ManagedMakeMessages .getFormattedString ("MakefileGenerator.message.adding.source.folder" , container .getFullPath ().toString ())); //$NON-NLS-1$
19681964 // Check the special case where the module is the project root
19691965 if (container .getFullPath () == project .getFullPath ()) {
19701966 buffer .append (DOT + WHITESPACE + LINEBREAK );
@@ -2042,8 +2038,8 @@ protected StringBuffer addSources(IContainer module) throws CoreException {
20422038 rcInfo = config .getResourceInfo (rcProjRelPath , false );
20432039 // if( (rcInfo.isExcluded()) )
20442040 // continue;
2045- addFragmentMakefileEntriesForSource (buildVarToRuleStringMap , ruleBuffer , folder , relativePath , resource ,
2046- getPathForResource ( resource ), rcInfo , null , false );
2041+ addFragmentMakefileEntriesForSource (buildVarToRuleStringMap , ruleBuffer , folder , relativePath , resource , getPathForResource ( resource ),
2042+ rcInfo , null , false );
20472043 }
20482044 }
20492045
@@ -2073,9 +2069,8 @@ protected StringBuffer addSources(IContainer module) throws CoreException {
20732069 *
20742070 * @param generatedSource if <code>true</code>, this file was generated by another tool in the tool-chain
20752071 */
2076- protected void addFragmentMakefileEntriesForSource (LinkedHashMap <String , String > buildVarToRuleStringMap , StringBuffer ruleBuffer ,
2077- IFolder folder , String relativePath , IResource resource , IPath sourceLocation , IResourceInfo rcInfo , String varName ,
2078- boolean generatedSource ) {
2072+ protected void addFragmentMakefileEntriesForSource (LinkedHashMap <String , String > buildVarToRuleStringMap , StringBuffer ruleBuffer , IFolder folder ,
2073+ String relativePath , IResource resource , IPath sourceLocation , IResourceInfo rcInfo , String varName , boolean generatedSource ) {
20792074
20802075 // Determine which tool, if any, builds files with this extension
20812076 String ext = sourceLocation .getFileExtension ();
@@ -2320,15 +2315,19 @@ private IManagedCommandLineInfo generateToolCommandLineInfo(ITool tool, String s
23202315 if ((inputLocation != null && inputLocation .toString ().indexOf (" " ) != -1 ) || //$NON-NLS-1$
23212316 (outputLocation != null && outputLocation .toString ().indexOf (" " ) != -1 )) //$NON-NLS-1$
23222317 {
2323- resolvedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValue (cmd , "" , //$NON-NLS-1$
2324- " " , //$NON-NLS-1$
2325- IBuildMacroProvider .CONTEXT_FILE , new FileContextData (inputLocation , outputLocation , null , tool )).replaceFirst (" -w " , " " );
2318+ resolvedCommand = ManagedBuildManager .getBuildMacroProvider ()
2319+ .resolveValue (cmd , "" , //$NON-NLS-1$
2320+ " " , //$NON-NLS-1$
2321+ IBuildMacroProvider .CONTEXT_FILE , new FileContextData (inputLocation , outputLocation , null , tool ))
2322+ .replaceFirst (" -w " , " " );
23262323 }
23272324
23282325 else {
2329- resolvedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValueToMakefileFormat (cmd , "" , //$NON-NLS-1$
2330- " " , //$NON-NLS-1$
2331- IBuildMacroProvider .CONTEXT_FILE , new FileContextData (inputLocation , outputLocation , null , tool )).replaceFirst (" -w " , " " );
2326+ resolvedCommand = ManagedBuildManager .getBuildMacroProvider ()
2327+ .resolveValueToMakefileFormat (cmd , "" , //$NON-NLS-1$
2328+ " " , //$NON-NLS-1$
2329+ IBuildMacroProvider .CONTEXT_FILE , new FileContextData (inputLocation , outputLocation , null , tool ))
2330+ .replaceFirst (" -w " , " " );
23322331 }
23332332 if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
23342333 cmd = resolvedCommand ;
@@ -2351,18 +2350,18 @@ private IManagedCommandLineInfo generateToolCommandLineInfo(ITool tool, String s
23512350 * @echo Building file: $<
23522351 * @echo Invoking tool xxx
23532352 * @echo <tool> <flags> <output_flag><output_prefix>$@ $<
2354- * @<tool> <flags> <output_flag><output_prefix>$@ $< && \ echo -n $(@:%.o=%.d) ' <relative_path>/' >> $(@:%.o=%.d) && \ <tool> -P -MM -MG <flags>
2355- * $< >> $(@:%.o=%.d)
2353+ * @<tool> <flags> <output_flag><output_prefix>$@ $< && \ echo -n $(@:%.o=%.d) ' <relative_path>/' >> $(@:%.o=%.d) && \ <tool> -P -MM -MG
2354+ * <flags> $< >> $(@:%.o=%.d)
23562355 * @echo Finished building: $<
23572356 * @echo ' '
23582357 *
23592358 * Note that the macros all come from the build model and are resolved to a real command before writing to the module makefile, so a real
23602359 * command might look something like: source1/%.o: ../source1/%.cpp
23612360 * @echo Building file: $<
23622361 * @echo Invoking tool xxx
2363- * @echo g++ -g -O2 -c -I/cygdrive/c/eclipse/workspace/Project/headers -o$@ $<
2364- * @g++ -g -O2 -c -I/cygdrive/c/eclipse/workspace/Project/headers -o$@ $< && \ echo -n $(@:%.o=%.d) ' source1/' >> $(@:%.o=%.d) && \ g++ -P -MM
2365- * -MG -g -O2 -c -I/cygdrive/c/eclipse/workspace/Project/headers $< >> $(@:%.o=%.d)
2362+ * @echo g++ -g -O2 -c -I/cygdrive/c/eclipse/workspace/Project/headers -o$@ $< @g++ -g -O2 -c -I/cygdrive/c/eclipse/workspace/Project/headers -o$@
2363+ * $< && \ echo -n $(@:%.o=%.d) ' source1/' >> $(@:%.o=%.d) && \ g++ -P -MM -MG -g -O2 -c -I/cygdrive/c/eclipse/workspace/Project/headers $<
2364+ * >> $(@:%.o=%.d)
23662365 * @echo Finished building: $<
23672366 * @echo ' '
23682367 *
@@ -2518,29 +2517,24 @@ protected void addRuleForSource(String relativePath, StringBuffer buffer, IResou
25182517 boolean resourceNameRequiresExplicitRule = (resource .isLinked () && containsSpecialCharacters (sourceLocation .toString ()))
25192518 || (!resource .isLinked () && containsSpecialCharacters (resource .getProjectRelativePath ().toString ()));
25202519
2521- boolean needExplicitRuleForFile = resourceNameRequiresExplicitRule
2522- || BuildMacroProvider .getReferencedExplitFileMacros (tool ).length > 0
2523- || BuildMacroProvider .getReferencedExplitFileMacros (tool .getToolCommand (), IBuildMacroProvider .CONTEXT_FILE , new FileContextData (
2524- sourceLocation , outputLocation , null , tool )).length > 0 ;
2520+ boolean needExplicitRuleForFile = resourceNameRequiresExplicitRule || BuildMacroProvider .getReferencedExplitFileMacros (tool ).length > 0
2521+ || BuildMacroProvider .getReferencedExplitFileMacros (tool .getToolCommand (), IBuildMacroProvider .CONTEXT_FILE ,
2522+ new FileContextData (sourceLocation , outputLocation , null , tool )).length > 0 ;
25252523
25262524 // Get and resolve the command
25272525 String cmd = tool .getToolCommand ();
25282526
25292527 try {
25302528 String resolvedCommand = null ;
25312529 if (!needExplicitRuleForFile ) {
2532- resolvedCommand = ManagedBuildManager
2533- .getBuildMacroProvider ()
2534- .resolveValueToMakefileFormat (cmd , EMPTY_STRING , WHITESPACE , IBuildMacroProvider .CONTEXT_FILE ,
2535- new FileContextData (sourceLocation , outputLocation , null , tool )).replaceFirst (" -w " , " " );
2530+ resolvedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValueToMakefileFormat (cmd , EMPTY_STRING , WHITESPACE ,
2531+ IBuildMacroProvider .CONTEXT_FILE , new FileContextData (sourceLocation , outputLocation , null , tool )).replaceFirst (" -w " , " " );
25362532 } else {
25372533 // if we need an explicit rule then don't use any builder
25382534 // variables, resolve everything
25392535 // to explicit strings
2540- resolvedCommand = ManagedBuildManager
2541- .getBuildMacroProvider ()
2542- .resolveValue (cmd , EMPTY_STRING , WHITESPACE , IBuildMacroProvider .CONTEXT_FILE ,
2543- new FileContextData (sourceLocation , outputLocation , null , tool )).replaceFirst (" -w " , " " );
2536+ resolvedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValue (cmd , EMPTY_STRING , WHITESPACE ,
2537+ IBuildMacroProvider .CONTEXT_FILE , new FileContextData (sourceLocation , outputLocation , null , tool )).replaceFirst (" -w " , " " );
25442538 }
25452539
25462540 if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
@@ -3327,7 +3321,7 @@ protected void calculateOutputsForSource(ITool tool, String relativePath, IResou
33273321 enumeratedSecondaryOutputs .add (resolvePercent (outPath , sourceLocation ));
33283322 }
33293323 }
3330- }// MODDED BY JABA ADDED
3324+ } // MODDED BY JABA ADDED
33313325 } else
33323326 // 4. If outputNames is specified, use it
33333327 if (outputNames != null ) {
0 commit comments