diff --git a/app/.classpath b/app/.classpath
index 26775c499..4589f3f47 100644
--- a/app/.classpath
+++ b/app/.classpath
@@ -2,19 +2,11 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java
index 99138ce3a..1ab981ee0 100644
--- a/app/src/processing/app/Base.java
+++ b/app/src/processing/app/Base.java
@@ -960,9 +960,9 @@ public class Base {
try {
//Find the current target. Get the platform, and then select the correct name and core path.
- String platformname = this.getBoardPreferences().get("platform");
- String targetname = this.getPlatformPreferences(platformname).get("name");
- String libraryPath = this.getPlatformPreferences(platformname).get("library.core.path");
+ String platformname = getBoardPreferences().get("platform");
+ String targetname = getPlatformPreferences(platformname).get("name");
+ String libraryPath = getPlatformPreferences(platformname).get("library.core.path");
JMenuItem platformItem = new JMenuItem(targetname);
platformItem.setEnabled(false);
@@ -1554,7 +1554,7 @@ public class Base {
static public Target getTarget() {
System.out.println("Base.targetsTable.get(Preferences.get(\"target\"))" + Base.targetsTable.get(Preferences.get("target")));
- System.out.println("Preferences.get(\"target\")" + Preferences.get("target"));
+ System.out.println("Preferences.get(\"target\") = " + Preferences.get("target"));
Target target = Base.targetsTable.get(Preferences.get("target"));
if (target == null) {
System.out.println("default target is not in list. Replace with default.");
@@ -1642,16 +1642,17 @@ static public Map getPlatformPreferences() {
return map;
}
-
-static public Map getBoardPreferences() {
+
+ static public Map getBoardPreferences() {
Target target = getTarget();
- Map map = new LinkedHashMap();
- if (target != null) {
- map = target.getBoards();
- map = (Map) map.get(Preferences.get("board"));
- }
- return map;
- }
+ if (target != null) {
+ Map> map = target.getBoards();
+ Map res = map.get(Preferences.get("board"));
+ if (res != null)
+ return res;
+ }
+ return new HashMap();
+ }
static public File getSketchbookFolder() {
return new File(Preferences.get("sketchbook.path"));
diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java
index e80438433..e2b1abdc7 100644
--- a/app/src/processing/app/debug/Compiler.java
+++ b/app/src/processing/app/debug/Compiler.java
@@ -1,81 +1,94 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
- Part of the Processing project - http://processing.org
+ Part of the Processing project - http://processing.org
- Copyright (c) 2004-08 Ben Fry and Casey Reas
- Copyright (c) 2001-04 Massachusetts Institute of Technology
+ Copyright (c) 2004-08 Ben Fry and Casey Reas
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
package processing.app.debug;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import processing.app.Base;
import processing.app.Preferences;
import processing.app.Sketch;
import processing.app.SketchCode;
-import processing.core.*;
-
-import java.io.*;
-import java.util.*;
-import java.util.zip.*;
-import java.text.MessageFormat;
-
+import processing.core.PApplet;
public class Compiler implements MessageConsumer {
- static final String BUGS_URL =
- "http://code.google.com/p/arduino/issues/list";
- static final String SUPER_BADNESS =
- "Compiler error, please submit this code to " + BUGS_URL;
+ static final String BUGS_URL = "http://code.google.com/p/arduino/issues/list";
+
+ static final String SUPER_BADNESS = "Compiler error, please submit this code to "
+ + BUGS_URL;
Sketch sketch;
+
String buildPath;
+
String primaryClassName;
+
String platform;
+
String board;
boolean verbose;
-
- RunnerException exception;
-
- HashMap configPreferences;
- HashMap boardPreferences;
- HashMap platformPreferences;
-
- String avrBasePath;
- String corePath;
-
- List objectFiles;
- ArrayList includePaths;
- public Compiler() { }
+ RunnerException exception;
+
+ Map configPreferences;
+
+ Map boardPreferences;
+
+ Map platformPreferences;
+
+ String avrBasePath;
+
+ List objectFiles;
+
+ public Compiler() {
+ }
/**
* Compile with avr-gcc.
- *
- * @param sketch Sketch object to be compiled.
- * @param buildPath Where the temporary files live and will be built from.
- * @param primaryClassName the name of the combined sketch file w/ extension
+ *
+ * @param sketch
+ * Sketch object to be compiled.
+ * @param buildPath
+ * Where the temporary files live and will be built from.
+ * @param primaryClassName
+ * the name of the combined sketch file w/ extension
* @return true if successful.
- * @throws RunnerException Only if there's a problem. Only then.
+ * @throws RunnerException
+ * Only if there's a problem. Only then.
*/
- public boolean compile(Sketch sketch,
- String buildPath,
- String primaryClassName,
- boolean verbose) throws RunnerException {
+ public boolean compile(Sketch sketch, String buildPath,
+ String primaryClassName, boolean verbose)
+ throws RunnerException {
this.sketch = sketch;
this.buildPath = buildPath;
this.primaryClassName = primaryClassName;
@@ -83,285 +96,268 @@ public class Compiler implements MessageConsumer {
objectFiles = new ArrayList();
// the pms object isn't used for anything but storage
- MessageStream pms = new MessageStream(this);
+ // MessageStream pms = new MessageStream(this);
Map boardPreferences = Base.getBoardPreferences();
-
- //Check for null platform, and use system default if not found
- platform = boardPreferences.get("platform");
- if (platform == null)
- {
- platformPreferences = new HashMap(Base.getPlatformPreferences());
- }
- else
- {
- platformPreferences = new HashMap(Base.getPlatformPreferences(platform));
- }
-
- System.out.println("////////////////////////////compiler.java is doing stuff/////////////////");
- //Put all the global preference configuration into one Master configpreferences
- configPreferences = mergePreferences( Preferences.getMap(), platformPreferences, boardPreferences);
- avrBasePath = configPreferences.get("compiler.path");
- if (avrBasePath == null)
- {
- avrBasePath = Base.getAvrBasePath();
- System.out.println("avrBasePath: " + avrBasePath);
- }
- else
- {
- System.out.println("avrBasePath:exists: " + avrBasePath);
- //Put in the system path in the compiler path if available
- MessageFormat compileFormat = new MessageFormat(avrBasePath);
- String basePath = System.getProperty("user.dir");
- if (Base.isMacOS()) {
- //logger.debug("basePath: " + basePath);
- basePath += "/Arduino.app/Contents/Resources/Java";
- }
- Object[] Args = {basePath};
- avrBasePath = compileFormat.format( Args );
- System.out.println("avrBasePath:new: " + avrBasePath);
+ // Check for null platform, and use system default if not found
+ platform = boardPreferences.get("platform");
+ if (platform == null)
+ platformPreferences = new HashMap(Base.getPlatformPreferences());
+ else
+ platformPreferences = new HashMap(Base.getPlatformPreferences(platform));
+ System.out.println("-> compiler.java is doing stuff");
+ // Put all the global preference configuration into one Master
+ // configpreferences
+ configPreferences = mergePreferences(Preferences.getMap(),
+ platformPreferences, boardPreferences);
- }
- this.board = configPreferences.get("board");
- if (this.board == "")
- {
- this.board = "_UNKNOWN";
- }
-
- String core = configPreferences.get("build.core");
+ avrBasePath = configPreferences.get("compiler.path");
+ if (avrBasePath == null) {
+ avrBasePath = Base.getAvrBasePath();
+ // System.out.println("avrBasePath: " + avrBasePath);
+ } else {
+ // System.out.println("avrBasePath:exists: " + avrBasePath);
+
+ // Put in the system path in the compiler path if available
+ String basePath = System.getProperty("user.dir");
+ if (Base.isMacOS()) {
+ // logger.debug("basePath: " + basePath);
+ basePath += "/Arduino.app/Contents/Resources/Java";
+ }
+ Object[] Args = { basePath };
+ avrBasePath = new MessageFormat(avrBasePath).format(Args);
+ // System.out.println("avrBasePath:new: " + avrBasePath);
+ }
+ board = configPreferences.get("board");
+ if (board == "")
+ board = "_UNKNOWN";
+
+ String core = configPreferences.get("build.core");
if (core == null) {
- RunnerException re = new RunnerException("No board selected; please choose a board from the Tools > Board menu.");
+ RunnerException re = new RunnerException(
+ "No board selected; please choose a board from the Tools > Board menu.");
re.hideStackTrace();
throw re;
}
+
String corePath, systemPath;
-
+ File coreFolder;
+ Target target;
if (core.indexOf(':') == -1) {
- Target t = Base.getTarget();
- File coreFolder = new File(new File(t.getFolder(), "cores"), core);
+ target = Base.getTarget();
+ coreFolder = new File(new File(target.getFolder(), "cores"), core);
corePath = coreFolder.getAbsolutePath();
- systemPath = new File(t.getFolder(), "system").getAbsolutePath();
+
+ systemPath = new File(target.getFolder(), "system").getAbsolutePath();
} else {
- Target t = Base.targetsTable.get(core.substring(0, core.indexOf(':')));
- File coreFolder = new File(t.getFolder(), "cores");
+ target = Base.targetsTable.get(core.substring(0, core.indexOf(':')));
+ coreFolder = new File(target.getFolder(), "cores");
coreFolder = new File(coreFolder, core.substring(core.indexOf(':') + 1));
corePath = coreFolder.getAbsolutePath();
- systemPath = new File(t.getFolder(), "system").getAbsolutePath();
+ systemPath = new File(target.getFolder(), "system").getAbsolutePath();
}
+ List systemExtraSrc = new ArrayList();
+ String extraSystem = configPreferences.get("system.extra_source_dirs");
+ if (extraSystem != null)
+ for (String dir : extraSystem.split("\\|"))
+ systemExtraSrc.add(systemPath + File.separator + dir);
+
+ List coreExtraSrc = new ArrayList();
+ String extraCore = configPreferences.get("core.extra_source_dirs");
+ if (extraCore != null)
+ for (String dir : extraCore.split("\\|"))
+ coreExtraSrc.add(coreFolder.getParent() + File.separator + dir);
+
+ List includePaths = new ArrayList();
+ String extraInclude = configPreferences.get("build.extra_include_dirs");
+ if (extraInclude != null)
+ for (String dir : extraInclude.split("\\|"))
+ includePaths.add(target.getFolder() + File.separator + dir);
+ includePaths.add(systemPath);
+ includePaths.add(corePath);
+
String pins = configPreferences.get("build.pins");
String pinsPath = null;
-
+ List variantExtraSrc = new ArrayList();
+ File pinsFolder = null;
+
if (pins != null) {
if (pins.indexOf(':') == -1) {
- Target t = Base.getTarget();
- File pinsFolder = new File(new File(t.getFolder(), "variants"), pins);
- pinsPath = pinsFolder.getAbsolutePath();
+ Target t = Base.getTarget();
+ pinsFolder = new File(new File(t.getFolder(), "variants"), pins);
+ pinsPath = pinsFolder.getAbsolutePath();
} else {
- Target t = Base.targetsTable.get(pins.substring(0, pins.indexOf(':')));
- File pinsFolder = new File(t.getFolder(), "variants");
- pinsFolder = new File(pinsFolder, pins.substring(pins.indexOf(':') + 1));
- pinsPath = pinsFolder.getAbsolutePath();
+ Target t = Base.targetsTable.get(pins.substring(0, pins.indexOf(':')));
+ pinsFolder = new File(t.getFolder(), "variants");
+ pinsFolder = new File(pinsFolder, pins.substring(pins.indexOf(':') + 1));
+ pinsPath = pinsFolder.getAbsolutePath();
}
+ includePaths.add(pinsPath);
+ includePaths.add(pinsFolder.getParent());
+
+ String extraDirs = configPreferences.get("variants.extra_source_dirs");
+ for (String dir : extraDirs.split("\\|"))
+ variantExtraSrc.add(pinsFolder.getParent() + File.separator + dir);
}
+ // 0. include paths for core + all libraries
+ for (File file : sketch.getImportedLibraries())
+ includePaths.add(file.getPath());
- // 0. include paths for core + all libraries
+ // 1. compile the sketch (already in the buildPath)
+ System.out.println("1. compileSketch");
+ compileSketch(avrBasePath, buildPath, includePaths, configPreferences);
- ArrayList includePaths = new ArrayList();
- includePaths.add(corePath);
- includePaths.add(systemPath);
- if (pinsPath != null) includePaths.add(pinsPath);
- for (File file : sketch.getImportedLibraries()) {
- includePaths.add(file.getPath());
- }
+ // 2. compile the libraries, outputting .o files to: //
+ // Doesn't really use configPreferences
+ System.out.println("2. compileLibraries");
+ compileLibraries(avrBasePath, buildPath, includePaths, configPreferences);
+ /*
+ *
+ * for (File libraryFolder : sketch.getImportedLibraries()) { File
+ * outputFolder = new File(buildPath, libraryFolder.getName()); File
+ * utilityFolder = new File(libraryFolder, "utility");
+ * createFolder(outputFolder); // this library can use includes in its
+ * utility/ folder includePaths.add(utilityFolder.getAbsolutePath());
+ * objectFiles.addAll( compileFiles(avrBasePath,
+ * outputFolder.getAbsolutePath(), includePaths,
+ * findFilesInFolder(libraryFolder, "S", false),
+ * findFilesInFolder(libraryFolder, "c", false),
+ * findFilesInFolder(libraryFolder, "cpp", false), boardPreferences));
+ * outputFolder = new File(outputFolder, "utility");
+ * createFolder(outputFolder); objectFiles.addAll( compileFiles(avrBasePath,
+ * outputFolder.getAbsolutePath(), includePaths,
+ * findFilesInFolder(utilityFolder, "S", false),
+ * findFilesInFolder(utilityFolder, "c", false),
+ * findFilesInFolder(utilityFolder, "cpp", false), boardPreferences)); //
+ * other libraries should not see this library's utility/ folder
+ * includePaths.remove(includePaths.size() - 1); }
+ */
- // 1. compile the sketch (already in the buildPath)
- System.out.println("1. compileSketch");
- compileSketch(avrBasePath, buildPath, includePaths, configPreferences);
+ // 3. compile the core, outputting .o files to and then
+ // collecting them into the core.a library file.
+ System.out.println("3. compileCore");
+ System.out.println("corePath: " + corePath);
+ compileCore(includePaths, corePath, coreExtraSrc, systemPath,
+ systemExtraSrc, variantExtraSrc, configPreferences);
-
- // 2. compile the libraries, outputting .o files to: //
- // 2. compile the libraries, outputting .o files to:
- // //
- //Doesn't really use configPreferences
- System.out.println("2. compileLibraries");
- compileLibraries(avrBasePath, buildPath, includePaths, configPreferences);
-/*
-
- for (File libraryFolder : sketch.getImportedLibraries()) {
- File outputFolder = new File(buildPath, libraryFolder.getName());
- File utilityFolder = new File(libraryFolder, "utility");
- createFolder(outputFolder);
- // this library can use includes in its utility/ folder
- includePaths.add(utilityFolder.getAbsolutePath());
- objectFiles.addAll(
- compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths,
- findFilesInFolder(libraryFolder, "S", false),
- findFilesInFolder(libraryFolder, "c", false),
- findFilesInFolder(libraryFolder, "cpp", false),
- boardPreferences));
- outputFolder = new File(outputFolder, "utility");
- createFolder(outputFolder);
- objectFiles.addAll(
- compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths,
- findFilesInFolder(utilityFolder, "S", false),
- findFilesInFolder(utilityFolder, "c", false),
- findFilesInFolder(utilityFolder, "cpp", false),
- boardPreferences));
- // other libraries should not see this library's utility/ folder
- includePaths.remove(includePaths.size() - 1);
- }
-*/
-
- // 3. compile the core, outputting .o files to and then
- // collecting them into the core.a library file.
- System.out.println("3. compileCore");
- System.out.println("corePath: " + corePath);
- compileCore(avrBasePath, buildPath, corePath, systemPath, pins, pinsPath, configPreferences);
-
-
-/*
- includePaths.clear();
- includePaths.add(corePath); // include path for core only
- if (pinsPath != null) includePaths.add(pinsPath);
- List coreObjectFiles =
- compileFiles(avrBasePath, buildPath, includePaths,
- findFilesInPath(corePath, "S", true),
- findFilesInPath(corePath, "c", true),
- findFilesInPath(corePath, "cpp", true),
- boardPreferences);
-
- String runtimeLibraryName = buildPath + File.separator + "core.a";
- List baseCommandAR = new ArrayList(Arrays.asList(new String[] {
- avrBasePath + "avr-ar",
- "rcs",
- runtimeLibraryName
- }));
- for(File file : coreObjectFiles) {
- List commandAR = new ArrayList(baseCommandAR);
- commandAR.add(file.getAbsolutePath());
- execAsynchronously(commandAR);
- }
-*/
+ /*
+ * includePaths.clear(); includePaths.add(corePath); // include path for
+ * core only if (pinsPath != null) includePaths.add(pinsPath); List
+ * coreObjectFiles = compileFiles(avrBasePath, buildPath, includePaths,
+ * findFilesInPath(corePath, "S", true), findFilesInPath(corePath, "c",
+ * true), findFilesInPath(corePath, "cpp", true), boardPreferences);
+ *
+ * String runtimeLibraryName = buildPath + File.separator + "core.a"; List
+ * baseCommandAR = new ArrayList(Arrays.asList(new String[] { avrBasePath +
+ * "avr-ar", "rcs", runtimeLibraryName })); for(File file : coreObjectFiles)
+ * { List commandAR = new ArrayList(baseCommandAR);
+ * commandAR.add(file.getAbsolutePath()); execAsynchronously(commandAR); }
+ */
// 4. link it all together into the .elf file
System.out.println("4. compileLink");
- compileLink(avrBasePath, buildPath, corePath, includePaths, configPreferences);
+ compileLink(avrBasePath, buildPath, corePath, includePaths, pinsPath,
+ configPreferences);
-/*
- List baseCommandLinker = new ArrayList(Arrays.asList(new String[] {
- avrBasePath + "avr-gcc",
- "-Os",
- "-Wl,--gc-sections",
- "-mmcu=" + boardPreferences.get("build.mcu"),
- "-o",
- buildPath + File.separator + primaryClassName + ".elf"
- }));
-
- for (File file : objectFiles) {
- baseCommandLinker.add(file.getAbsolutePath());
- }
-
- baseCommandLinker.add(runtimeLibraryName);
- baseCommandLinker.add("-L" + buildPath);
- baseCommandLinker.add("-lm");
-
- execAsynchronously(baseCommandLinker);
-
- List baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] {
- avrBasePath + "avr-objcopy",
- "-O",
- "-R",
- }));
-
- List commandObjcopy;
-*/
+ /*
+ * List baseCommandLinker = new ArrayList(Arrays.asList(new String[] {
+ * avrBasePath + "avr-gcc", "-Os", "-Wl,--gc-sections", "-mmcu=" +
+ * boardPreferences.get("build.mcu"), "-o", buildPath + File.separator +
+ * primaryClassName + ".elf" }));
+ *
+ * for (File file : objectFiles) {
+ * baseCommandLinker.add(file.getAbsolutePath()); }
+ *
+ * baseCommandLinker.add(runtimeLibraryName); baseCommandLinker.add("-L" +
+ * buildPath); baseCommandLinker.add("-lm");
+ *
+ * execAsynchronously(baseCommandLinker);
+ *
+ * List baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] {
+ * avrBasePath + "avr-objcopy", "-O", "-R", }));
+ *
+ * List commandObjcopy;
+ */
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
System.out.println("5. compileEep");
compileEep(avrBasePath, buildPath, includePaths, configPreferences);
-
+
// 6. build the .hex file
System.out.println("6. compileHex");
compileHex(avrBasePath, buildPath, includePaths, configPreferences);
-
+
return true;
}
-
- private List compileFiles(String avrBasePath,
- String buildPath, ArrayList includePaths,
- ArrayList sSources,
- ArrayList cSources, ArrayList cppSources,
+ private List compileFiles(String avrBasePath, String buildPath,
+ List includePaths,
+ List sSources, List cSources,
+ List cppSources,
Map boardPreferences)
- throws RunnerException {
+ throws RunnerException {
List objectPaths = new ArrayList();
-
+
for (File file : sSources) {
String objectPath = buildPath + File.separator + file.getName() + ".o";
objectPaths.add(new File(objectPath));
- execAsynchronously(getCommandCompilerS(avrBasePath, includePaths,
- file.getAbsolutePath(),
- objectPath,
- configPreferences));
+ execAsynchronously(getCommandCompilerS(avrBasePath, includePaths, file
+ .getAbsolutePath(), objectPath, configPreferences));
}
-
+
for (File file : cSources) {
- String objectPath = buildPath + File.separator + file.getName() + ".o";
- objectPaths.add(new File(objectPath));
- execAsynchronously(getCommandCompilerC(avrBasePath, includePaths,
- file.getAbsolutePath(),
- objectPath,
- configPreferences));
+ String objectPath = buildPath + File.separator + file.getName() + ".o";
+ objectPaths.add(new File(objectPath));
+ execAsynchronously(getCommandCompilerC(avrBasePath, includePaths, file
+ .getAbsolutePath(), objectPath, configPreferences));
}
for (File file : cppSources) {
- String objectPath = buildPath + File.separator + file.getName() + ".o";
- objectPaths.add(new File(objectPath));
- execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths,
- file.getAbsolutePath(),
- objectPath,
- configPreferences));
+ String objectPath = buildPath + File.separator + file.getName() + ".o";
+ objectPaths.add(new File(objectPath));
+ execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths, file
+ .getAbsolutePath(), objectPath, configPreferences));
}
-
+
return objectPaths;
}
-
boolean firstErrorFound;
+
boolean secondErrorFound;
/**
* Either succeeds or throws a RunnerException fit for public consumption.
*/
private void execAsynchronously(String[] command) throws RunnerException {
-
- //eliminate any empty array entries
- List stringList = new ArrayList();
- for(String string : command) {
- string = string.trim();
- if(string != null && string.length() > 0) {
- stringList.add(string);
- }
- }
- command = stringList.toArray(new String[stringList.size()]);
-
- int result = 0;
-
- if (verbose || Preferences.getBoolean("build.verbose")) {
- for(int j = 0; j < command.length; j++) {
- System.out.print(command[j] + " ");
- }
- System.out.println();
- }
- firstErrorFound = false; // haven't found any errors yet
+ // eliminate any empty array entries
+ List stringList = new ArrayList();
+ for (String string : command) {
+ string = string.trim();
+ if (string != null && string.length() > 0) {
+ stringList.add(string);
+ }
+ }
+ command = stringList.toArray(new String[stringList.size()]);
+
+ int result = 0;
+
+ // if (verbose || Preferences.getBoolean("build.verbose")) {
+ System.out.print("EXEC: ");
+ for (String c : command)
+ System.out.print(c + " ");
+ System.out.println();
+ // }
+
+ firstErrorFound = false; // haven't found any errors yet
secondErrorFound = false;
Process process;
-
+
try {
process = Runtime.getRuntime().exec(command);
} catch (IOException e) {
@@ -373,7 +369,7 @@ public class Compiler implements MessageConsumer {
MessageSiphon in = new MessageSiphon(process.getInputStream(), this);
MessageSiphon err = new MessageSiphon(process.getErrorStream(), this);
- // wait for the process to finish. if interrupted
+ // wait for the process to finish. if interrupted
// before waitFor returns, continue waiting
boolean compiling = true;
while (compiling) {
@@ -383,9 +379,10 @@ public class Compiler implements MessageConsumer {
if (err.thread != null)
err.thread.join();
result = process.waitFor();
- //System.out.println("result is " + result);
+ // System.out.println("result is " + result);
compiling = false;
- } catch (InterruptedException ignored) { }
+ } catch (InterruptedException ignored) {
+ }
}
// an error was queued up by message(), barf this back to compile(),
@@ -393,8 +390,10 @@ public class Compiler implements MessageConsumer {
// discerning the imagery, consider how cows regurgitate their food
// to digest it, and the fact that they have five stomaches.
//
- //System.out.println("throwing up " + exception);
- if (exception != null) { throw exception; }
+ // System.out.println("throwing up " + exception);
+ if (exception != null) {
+ throw exception;
+ }
if (result > 1) {
// a failure in the tool (e.g. unable to locate a sub-executable)
@@ -406,15 +405,14 @@ public class Compiler implements MessageConsumer {
re.hideStackTrace();
throw re;
}
- System.out.println("execAsync: Done.");
+ // System.out.println("execAsync: Done.");
}
-
/**
- * Part of the MessageConsumer interface, this is called
- * whenever a piece (usually a line) of error message is spewed
- * out from the compiler. The errors are parsed for their contents
- * and line number, which is then reported back to Editor.
+ * Part of the MessageConsumer interface, this is called whenever a piece
+ * (usually a line) of error message is spewed out from the compiler. The
+ * errors are parsed for their contents and line number, which is then
+ * reported back to Editor.
*/
public void message(String s) {
int i;
@@ -424,245 +422,228 @@ public class Compiler implements MessageConsumer {
// have meaning in a regular expression.
if (!verbose) {
while ((i = s.indexOf(buildPath + File.separator)) != -1) {
- s = s.substring(0, i) + s.substring(i + (buildPath + File.separator).length());
+ s = s.substring(0, i)
+ + s.substring(i + (buildPath + File.separator).length());
}
}
-
+
// look for error line, which contains file name, line number,
// and at least the first line of the error message
String errorFormat = "([\\w\\d_]+.\\w+):(\\d+):\\s*error:\\s*(.*)\\s*";
String[] pieces = PApplet.match(s, errorFormat);
-// if (pieces != null && exception == null) {
-// exception = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1);
-// if (exception != null) exception.hideStackTrace();
-// }
-
+ // if (pieces != null && exception == null) {
+ // exception = sketch.placeException(pieces[3], pieces[1],
+ // PApplet.parseInt(pieces[2]) - 1);
+ // if (exception != null) exception.hideStackTrace();
+ // }
+
if (pieces != null) {
- RunnerException e = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1);
+ RunnerException e = sketch.placeException(pieces[3], pieces[1], PApplet
+ .parseInt(pieces[2]) - 1);
// replace full file path with the name of the sketch tab (unless we're
// in verbose mode, in which case don't modify the compiler output)
if (e != null && !verbose) {
SketchCode code = sketch.getCode(e.getCodeIndex());
- String fileName = code.isExtension(sketch.getDefaultExtension()) ? code.getPrettyName() : code.getFileName();
- s = fileName + ":" + e.getCodeLine() + ": error: " + e.getMessage();
+ String fileName = code.isExtension(sketch.getDefaultExtension()) ? code
+ .getPrettyName() : code.getFileName();
+ s = fileName + ":" + e.getCodeLine() + ": error: " + e.getMessage();
}
-
+
if (pieces[3].trim().equals("SPI.h: No such file or directory")) {
- e = new RunnerException("Please import the SPI library from the Sketch > Import Library menu.");
- s += "\nAs of Arduino 0019, the Ethernet library depends on the SPI library." +
- "\nYou appear to be using it or another library that depends on the SPI library.";
+ e = new RunnerException(
+ "Please import the SPI library from the Sketch > Import Library menu.");
+ s += "\nAs of Arduino 0019, the Ethernet library depends on the SPI library."
+ + "\nYou appear to be using it or another library that depends on the SPI library.";
}
-
+
if (pieces[3].trim().equals("'BYTE' was not declared in this scope")) {
e = new RunnerException("The 'BYTE' keyword is no longer supported.");
- s += "\nAs of Arduino 1.0, the 'BYTE' keyword is no longer supported." +
- "\nPlease use Serial.write() instead.";
+ s += "\nAs of Arduino 1.0, the 'BYTE' keyword is no longer supported."
+ + "\nPlease use Serial.write() instead.";
}
-
+
if (exception == null && e != null) {
exception = e;
exception.hideStackTrace();
- }
+ }
}
-
+
System.err.print(s);
}
- /////////////////////////////////////////////////////////////////////////////
-/*
- static private List getCommandCompilerS(String avrBasePath, List includePaths,
- String sourceName, String objectName, Map boardPreferences) {
- List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] {
- avrBasePath + "avr-gcc",
- "-c", // compile, don't link
- "-g", // include debugging info (so errors include line numbers)
- "-assembler-with-cpp",
- "-mmcu=" + boardPreferences.get("build.mcu"),
- "-DF_CPU=" + boardPreferences.get("build.f_cpu"),
- "-DARDUINO=" + Base.REVISION,
- }));
+ // ///////////////////////////////////////////////////////////////////////////
+ /*
+ * static private List getCommandCompilerS(String avrBasePath, List
+ * includePaths, String sourceName, String objectName, Map
+ * boardPreferences) { List baseCommandCompiler = new
+ * ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-c", //
+ * compile, don't link "-g", // include debugging info (so errors include line
+ * numbers) "-assembler-with-cpp", "-mmcu=" +
+ * boardPreferences.get("build.mcu"), "-DF_CPU=" +
+ * boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, }));
+ *
+ * for (int i = 0; i < includePaths.size(); i++) {
+ * baseCommandCompiler.add("-I" + (String) includePaths.get(i)); }
+ *
+ * baseCommandCompiler.add(sourceName); baseCommandCompiler.add("-o"+
+ * objectName);
+ *
+ * return baseCommandCompiler; }
+ */
- for (int i = 0; i < includePaths.size(); i++) {
- baseCommandCompiler.add("-I" + (String) includePaths.get(i));
- }
+ // ///////////////////////////////////////////////////////////////////////////
+ static private String[] getCommandCompilerS(
+ String avrBasePath,
+ List includePaths,
+ String sourceName,
+ String objectName,
+ Map configPreferences) {
+ System.out.println("getCommandCompilerS: start");
+ String baseCommandString = configPreferences.get("recipe.cpp.o.pattern");
+ MessageFormat compileFormat = new MessageFormat(baseCommandString);
+ // getIncludes to String
- baseCommandCompiler.add(sourceName);
- baseCommandCompiler.add("-o"+ objectName);
+ String includes = preparePaths(includePaths);
+ Object[] Args = { avrBasePath, configPreferences.get("compiler.cpp.cmd"),
+ configPreferences.get("compiler.S.flags"),
+ configPreferences.get("compiler.cpudef"),
+ configPreferences.get("build.mcu"),
+ configPreferences.get("build.f_cpu"),
+ configPreferences.get("software"), Base.REVISION, includes, sourceName,
+ objectName };
- return baseCommandCompiler;
+ String command = compileFormat.format(Args);
+ String[] commandArray = command.split("\\|");
+ return commandArray;
}
-*/
- // ///////////////////////////////////////////////////////////////////////////
- static private String[] getCommandCompilerS(String avrBasePath,
- ArrayList includePaths, String sourceName, String objectName,
- HashMap configPreferences)
- {
- System.out.println("getCommandCompilerS: start");
- String baseCommandString = configPreferences.get("recipe.cpp.o.pattern");
- MessageFormat compileFormat = new MessageFormat(baseCommandString);
- //getIncludes to String
-
- String includes = preparePaths(includePaths);
- Object[] Args = {
- avrBasePath,
- configPreferences.get("compiler.cpp.cmd"),
- configPreferences.get("compiler.S.flags"),
- configPreferences.get("compiler.cpudef"),
- configPreferences.get("build.mcu"),
- configPreferences.get("build.f_cpu"),
- configPreferences.get("software"),
- Base.REVISION,
- includes,
- sourceName,
- objectName
- };
-
- String command = compileFormat.format( Args );
- String[] commandArray = command.split("\\|");
- return commandArray;
- }
+ /*
+ *
+ * static private List getCommandCompilerC(String avrBasePath, List
+ * includePaths, String sourceName, String objectName, Map
+ * boardPreferences) {
+ *
+ * List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] {
+ * avrBasePath + "avr-gcc", "-c", // compile, don't link "-g", // include
+ * debugging info (so errors include line numbers) "-Os", // optimize for size
+ * "-w", // surpress all warnings "-ffunction-sections", // place each
+ * function in its own section "-fdata-sections", "-mmcu=" +
+ * boardPreferences.get("build.mcu"), "-DF_CPU=" +
+ * boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, }));
+ *
+ * for (int i = 0; i < includePaths.size(); i++) {
+ * baseCommandCompiler.add("-I" + (String) includePaths.get(i)); }
+ *
+ * baseCommandCompiler.add(sourceName); baseCommandCompiler.add("-o"+
+ * objectName);
+ *
+ * return baseCommandCompiler; }
+ */
-/*
-
- static private List getCommandCompilerC(String avrBasePath, List includePaths,
- String sourceName, String objectName, Map boardPreferences) {
+ // removed static
+ private String[] getCommandCompilerC(String avrBasePath,
+ List includePaths,
+ String sourceName, String objectName,
+ Map configPreferences) {
+ // System.out.println("getCommandCompilerC: start");
+ String baseCommandString = configPreferences.get("recipe.c.o.pattern");
+ MessageFormat compileFormat = new MessageFormat(baseCommandString);
+ // getIncludes to String
+ String includes = preparePaths(includePaths);
- List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] {
- avrBasePath + "avr-gcc",
- "-c", // compile, don't link
- "-g", // include debugging info (so errors include line numbers)
- "-Os", // optimize for size
- "-w", // surpress all warnings
- "-ffunction-sections", // place each function in its own section
- "-fdata-sections",
- "-mmcu=" + boardPreferences.get("build.mcu"),
- "-DF_CPU=" + boardPreferences.get("build.f_cpu"),
- "-DARDUINO=" + Base.REVISION,
- }));
-
- for (int i = 0; i < includePaths.size(); i++) {
- baseCommandCompiler.add("-I" + (String) includePaths.get(i));
- }
+ Object[] Args = { avrBasePath, // 0
+ configPreferences.get("compiler.c.cmd"), // 1
+ configPreferences.get("compiler.c.flags"), // 2
+ configPreferences.get("compiler.cpudef"), // 3
+ configPreferences.get("build.mcu"), // 4
+ configPreferences.get("build.f_cpu"), // 5
+ configPreferences.get("software"), // 6
+ Base.REVISION, // 7
+ includes, // 8
+ sourceName, // 9
+ objectName, // 10
+ configPreferences.get("build.extra_flags") // 11
+ };
- baseCommandCompiler.add(sourceName);
- baseCommandCompiler.add("-o"+ objectName);
-
- return baseCommandCompiler;
+ String command = compileFormat.format(Args);
+ String[] commandArray = command.split("\\|");
+ return commandArray;
}
- */
-
- //removed static
- private String[] getCommandCompilerC(String avrBasePath,
- ArrayList includePaths, String sourceName, String objectName,
- HashMap configPreferences)
- {
- System.out.println("getCommandCompilerC: start");
- String baseCommandString = configPreferences.get("recipe.c.o.pattern");
- MessageFormat compileFormat = new MessageFormat(baseCommandString);
- //getIncludes to String
- String includes = preparePaths(includePaths);
- Object[] Args = {
- avrBasePath,
- configPreferences.get("compiler.c.cmd"),
- configPreferences.get("compiler.c.flags"),
- configPreferences.get("compiler.cpudef"),
- configPreferences.get("build.mcu"),
- configPreferences.get("build.f_cpu"),
- configPreferences.get("software"),
- Base.REVISION,
- includes,
- sourceName,
- objectName
- };
-
- String command = compileFormat.format( Args );
- String[] commandArray = command.split("\\|");
- return commandArray;
- }
-/*
-
- static private List getCommandCompilerCPP(String avrBasePath,
- List includePaths, String sourceName, String objectName,
- Map boardPreferences) {
-
- List baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] {
- avrBasePath + "avr-g++",
- "-c", // compile, don't link
- "-g", // include debugging info (so errors include line numbers)
- "-Os", // optimize for size
- "-w", // surpress all warnings
- "-fno-exceptions",
- "-ffunction-sections", // place each function in its own section
- "-fdata-sections",
- "-mmcu=" + boardPreferences.get("build.mcu"),
- "-DF_CPU=" + boardPreferences.get("build.f_cpu"),
- "-DARDUINO=" + Base.REVISION,
- }));
+ /*
+ *
+ * static private List getCommandCompilerCPP(String avrBasePath, List
+ * includePaths, String sourceName, String objectName, Map
+ * boardPreferences) {
+ *
+ * List baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] {
+ * avrBasePath + "avr-g++", "-c", // compile, don't link "-g", // include
+ * debugging info (so errors include line numbers) "-Os", // optimize for size
+ * "-w", // surpress all warnings "-fno-exceptions", "-ffunction-sections", //
+ * place each function in its own section "-fdata-sections", "-mmcu=" +
+ * boardPreferences.get("build.mcu"), "-DF_CPU=" +
+ * boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, }));
+ *
+ * for (int i = 0; i < includePaths.size(); i++) {
+ * baseCommandCompilerCPP.add("-I" + (String) includePaths.get(i)); }
+ *
+ * baseCommandCompilerCPP.add(sourceName); baseCommandCompilerCPP.add("-o"+
+ * objectName);
+ *
+ * return baseCommandCompilerCPP; }
+ */
- for (int i = 0; i < includePaths.size(); i++) {
- baseCommandCompilerCPP.add("-I" + (String) includePaths.get(i));
- }
+ static private String[] getCommandCompilerCPP(
+ String avrBasePath,
+ List includePaths,
+ String sourceName,
+ String objectName,
+ Map configPreferences) {
+ // System.out.println("getCommandCompilerCPP: start");
+ String baseCommandString = configPreferences.get("recipe.cpp.o.pattern");
+ MessageFormat compileFormat = new MessageFormat(baseCommandString);
+ // getIncludes to String
+ String includes = preparePaths(includePaths);
- baseCommandCompilerCPP.add(sourceName);
- baseCommandCompilerCPP.add("-o"+ objectName);
+ Object[] Args = { avrBasePath, // 0
+ configPreferences.get("compiler.cpp.cmd"), // 1
+ configPreferences.get("compiler.cpp.flags"), // 2
+ configPreferences.get("compiler.cpudef"), // 3
+ configPreferences.get("build.mcu"), // 4
+ configPreferences.get("build.f_cpu"), // 5
+ configPreferences.get("software"), // 6
+ Base.REVISION, // 7
+ includes, // 8
+ sourceName, // 9
+ objectName, // 10
+ configPreferences.get("build.extra_flags") // 11
+ };
- return baseCommandCompilerCPP;
+ String command = compileFormat.format(Args);
+ String[] commandArray = command.split("\\|");
+
+ // System.out.println("command:" + command);
+ // for (int ii = 0; ii < commandArray.length; ii++) {
+ // System.out.println("'" + commandArray[ii] + "'");
+ // }
+
+ return commandArray;
}
-*/
- static private String[] getCommandCompilerCPP(String avrBasePath,
- ArrayList includePaths, String sourceName, String objectName,
- HashMap configPreferences)
- {
- System.out.println("getCommandCompilerCPP: start");
- String baseCommandString = configPreferences.get("recipe.cpp.o.pattern");
- MessageFormat compileFormat = new MessageFormat(baseCommandString);
- //getIncludes to String
- String includes = preparePaths(includePaths);
-
- Object[] Args = {
- avrBasePath,
- configPreferences.get("compiler.cpp.cmd"),
- configPreferences.get("compiler.cpp.flags"),
- configPreferences.get("compiler.cpudef"),
- configPreferences.get("build.mcu"),
- configPreferences.get("build.f_cpu"),
- configPreferences.get("software"),
- Base.REVISION,
- includes,
- sourceName,
- objectName
- };
-
- String command = compileFormat.format( Args );
- String[] commandArray = command.split("\\|");
-
- /*
- System.out.println("command:" + command);
- for (int ii = 0; ii < commandArray.length; ii++)
- {
- System.out.println("'" + commandArray[ii] + "'");
- }
- */
- return commandArray;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////////////////////////////
static private void createFolder(File folder) throws RunnerException {
- if (folder.isDirectory()) return;
+ if (folder.isDirectory())
+ return;
if (!folder.mkdir())
throw new RunnerException("Couldn't create: " + folder);
}
/**
- * Given a folder, return a list of the header files in that folder (but
- * not the header files in its sub-folders, as those should be included from
+ * Given a folder, return a list of the header files in that folder (but not
+ * the header files in its sub-folders, as those should be included from
* within the header files at the top-level).
*/
static public String[] headerListFromIncludePath(String path) {
@@ -671,301 +652,289 @@ public class Compiler implements MessageConsumer {
return name.endsWith(".h");
}
};
-
+
return (new File(path)).list(onlyHFiles);
}
-
+
static public ArrayList findFilesInPath(String path, String extension,
boolean recurse) {
- System.out.println("findFilesInPath: " + path);
+ System.out.println("findFilesInPath: " + path);
return findFilesInFolder(new File(path), extension, recurse);
}
-
- static public ArrayList findFilesInFolder(File folder, String extension,
+
+ static public ArrayList findFilesInFolder(File folder,
+ String extension,
boolean recurse) {
ArrayList files = new ArrayList();
-
- if (folder.listFiles() == null) return files;
-
+
+ if (folder.listFiles() == null)
+ return files;
+
for (File file : folder.listFiles()) {
- if (file.getName().startsWith(".")) continue; // skip hidden files
-
+ if (file.getName().startsWith("."))
+ continue; // skip hidden files
+
if (file.getName().endsWith("." + extension))
files.add(file);
-
+
if (recurse && file.isDirectory()) {
files.addAll(findFilesInFolder(file, extension, true));
}
}
-
+
return files;
}
-
-
- // 1. compile the sketch (already in the buildPath)
- void compileSketch(String avrBasePath, String buildPath, ArrayList includePaths, HashMap configPreferences)
- throws RunnerException
- {
- System.out.println("compileSketch: start");
- System.out.println("includePaths: ");
- for (int i = 0; i < includePaths.size(); i++) {
- System.out.println("-I" + (String) includePaths.get(i));
- }
-
- //logger.debug("compileSketch: start");
- this.objectFiles.addAll(compileFiles(avrBasePath, buildPath, includePaths,
- findFilesInPath(buildPath, "S", false),
- findFilesInPath(buildPath, "c", false),
- findFilesInPath(buildPath, "cpp", false),
- configPreferences));
- }
-
- // 2. compile the libraries, outputting .o files to:
- // //
- void compileLibraries (String avrBasePath, String buildPath, ArrayList includePaths, HashMap configPreferences)
- throws RunnerException
- {
- System.out.println("compileLibraries: start");
-
- for (File libraryFolder : sketch.getImportedLibraries()) {
- System.out.println("libraryFolder: " + libraryFolder);
- File outputFolder = new File(buildPath, libraryFolder.getName());
- File utilityFolder = new File(libraryFolder, "utility");
- createFolder(outputFolder);
- // this library can use includes in its utility/ folder
- includePaths.add(utilityFolder.getAbsolutePath());
- //debug includePaths
- System.out.println("includePaths: ");
- for (int i = 0; i < includePaths.size(); i++) {
- System.out.println("-I" + (String) includePaths.get(i));
+
+ // 1. compile the sketch (already in the buildPath)
+ void compileSketch(String avrBasePath, String buildPath,
+ List includePaths,
+ Map configPreferences)
+ throws RunnerException {
+ System.out.println("compileSketch: start");
+ System.out.println("includePaths: ");
+ for (int i = 0; i < includePaths.size(); i++) {
+ System.out.println("-I" + (String) includePaths.get(i));
}
-
- objectFiles.addAll(
- compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths,
- findFilesInFolder(libraryFolder, "S", false),
- findFilesInFolder(libraryFolder, "c", false),
- findFilesInFolder(libraryFolder, "cpp", false),
- boardPreferences));
- outputFolder = new File(outputFolder, "utility");
- createFolder(outputFolder);
- objectFiles.addAll(
- compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths,
- findFilesInFolder(utilityFolder, "S", false),
- findFilesInFolder(utilityFolder, "c", false),
- findFilesInFolder(utilityFolder, "cpp", false),
- boardPreferences));
- // other libraries should not see this library's utility/ folder
- includePaths.remove(includePaths.size() - 1);
- }
+ // logger.debug("compileSketch: start");
+ objectFiles.addAll(compileFiles(avrBasePath, buildPath, includePaths,
+ findFilesInPath(buildPath, "S", false),
+ findFilesInPath(buildPath, "c", false),
+ findFilesInPath(buildPath, "cpp", false),
+ configPreferences));
}
-
- // 3. compile the core, outputting .o files to and then
- // collecting them into the core.a library file.
- void compileCore (String avrBasePath, String buildPath, String corePath, String systemPath, String pins, String pinsPath, HashMap configPreferences)
- throws RunnerException
- {
- System.out.println("compileCore(...) start");
- ArrayList includePaths = new ArrayList();
- includePaths.add(corePath); //include core path only
- includePaths.add(systemPath);
- if (pinsPath != null) includePaths.add(pinsPath);
-
- //debug includePaths
- System.out.println("includePaths: ");
- for (int i = 0; i < includePaths.size(); i++) {
- System.out.println("-I" + (String) includePaths.get(i));
- }
+ // 2. compile the libraries, outputting .o files to:
+ // //
+ void compileLibraries(String avrBasePath, String buildPath,
+ List includePaths,
+ Map configPreferences)
+ throws RunnerException {
+ // System.out.println("compileLibraries: start");
- String baseCommandString = configPreferences.get("recipe.ar.pattern");
- String commandString = "";
- MessageFormat compileFormat = new MessageFormat(baseCommandString);
- System.out.println("corePath: " + corePath);
- List coreObjectFiles = compileFiles(
- avrBasePath,
- buildPath,
- includePaths,
- findFilesInPath(corePath, "S", true),
- findFilesInPath(corePath, "c", true),
- findFilesInPath(corePath, "cpp", true),
- configPreferences);
-
- for (File file : coreObjectFiles) {
- //List commandAR = new ArrayList(baseCommandAR);
- //commandAR = commandAR + file.getAbsolutePath();
-
- Object[] Args = {
- avrBasePath,
- configPreferences.get("compiler.ar.cmd"),
- configPreferences.get("compiler.ar.flags"),
- //corePath,
- buildPath + File.separator,
- "core.a",
- //objectName
- file.getAbsolutePath()
- };
- System.out.println("compileCore(...) substitute");
+ for (File libraryFolder : sketch.getImportedLibraries()) {
+ // System.out.println("libraryFolder: " + libraryFolder);
+ File outputFolder = new File(buildPath, libraryFolder.getName());
+ File utilityFolder = new File(libraryFolder, "utility");
+ createFolder(outputFolder);
+ // this library can use includes in its utility/ folder
+ includePaths.add(utilityFolder.getAbsolutePath());
+ // debug includePaths
+ // System.out.println("includePaths: ");
+ // for (int i = 0; i < includePaths.size(); i++) {
+ // System.out.println("-I" + (String) includePaths.get(i));
+ // }
- commandString = compileFormat.format( Args );
- String[] commandArray = commandString.split("\\|");
- execAsynchronously(commandArray);
-
-
- }
- }
-
- // 4. link it all together into the .elf file
- void compileLink(String avrBasePath, String buildPath, String corePath, ArrayList includePaths, HashMap configPreferences)
- throws RunnerException
- {
- System.out.println("compileLink: start");
- String baseCommandString = configPreferences.get("recipe.c.combine.pattern");
- String commandString = "";
- MessageFormat compileFormat = new MessageFormat(baseCommandString);
- String objectFileList = "";
-
- for (File file : objectFiles) {
- objectFileList = objectFileList + file.getAbsolutePath() + "|";
- }
- System.out.println("objectFileList: " + objectFileList);
+ objectFiles.addAll(compileFiles(avrBasePath, outputFolder
+ .getAbsolutePath(), includePaths, findFilesInFolder(libraryFolder,
+ "S", false),
+ findFilesInFolder(libraryFolder, "c",
+ false),
+ findFilesInFolder(libraryFolder, "cpp",
+ false),
+ boardPreferences));
+ outputFolder = new File(outputFolder, "utility");
+ createFolder(outputFolder);
+ objectFiles.addAll(compileFiles(avrBasePath, outputFolder
+ .getAbsolutePath(), includePaths, findFilesInFolder(utilityFolder,
+ "S", false),
+ findFilesInFolder(utilityFolder, "c",
+ false),
+ findFilesInFolder(utilityFolder, "cpp",
+ false),
+ boardPreferences));
+ // other libraries should not see this library's utility/ folder
+ includePaths.remove(includePaths.size() - 1);
+ }
+ }
- Object[] Args = {
- avrBasePath,
- configPreferences.get("compiler.c.elf.cmd"),
- configPreferences.get("compiler.c.elf.flags"),
- configPreferences.get("compiler.cpudef"),
- configPreferences.get("build.mcu"),
- buildPath + File.separator,
- primaryClassName,
- objectFileList,
- buildPath + File.separator + "core.a",
- buildPath,
- corePath,
- configPreferences.get("ldscript"),
- };
- commandString = compileFormat.format( Args );
- String[] commandArray = commandString.split("\\|");
- execAsynchronously(commandArray);
- }
+ // 3. compile the core, outputting .o files to and then
+ // collecting them into the core.a library file.
+ void compileCore(List includePaths, String corePath,
+ List coreExtraSrc, String systemPath,
+ List systemExtraSrc, List variantExtraSrc,
+ Map configPreferences)
+ throws RunnerException {
+ // System.out.println("compileCore(...) start");
- // 5. extract EEPROM data (from EEMEM directive) to .eep file.
- void compileEep (String avrBasePath, String buildPath, ArrayList includePaths, HashMap configPreferences)
- throws RunnerException
- {
- //logger.debug("compileEep: start");
- String baseCommandString = configPreferences.get("recipe.objcopy.eep.pattern");
- String commandString = "";
- MessageFormat compileFormat = new MessageFormat(baseCommandString);
- String objectFileList = "";
-
- Object[] Args = {
- avrBasePath,
- configPreferences.get("compiler.objcopy.cmd"),
- configPreferences.get("compiler.objcopy.eep.flags"),
- buildPath + File.separator + primaryClassName,
- buildPath + File.separator + primaryClassName
- };
- commandString = compileFormat.format( Args );
- String[] commandArray = commandString.split("\\|");
- execAsynchronously(commandArray);
- }
-
- // 6. build the .hex file
- void compileHex (String avrBasePath, String buildPath, ArrayList includePaths, HashMap configPreferences)
- throws RunnerException
- {
- //logger.debug("compileHex: start");
- String baseCommandString = configPreferences.get("recipe.objcopy.hex.pattern");
- String commandString = "";
- MessageFormat compileFormat = new MessageFormat(baseCommandString);
- String objectFileList = "";
-
- Object[] Args = {
- avrBasePath,
- configPreferences.get("compiler.elf2hex.cmd"),
- configPreferences.get("compiler.elf2hex.flags"),
- buildPath + File.separator + primaryClassName,
- buildPath + File.separator + primaryClassName
- };
- commandString = compileFormat.format( Args );
- String[] commandArray = commandString.split("\\|");
- execAsynchronously(commandArray);
- }
-
- //merge all the preferences file in the correct order of precedence
- HashMap mergePreferences(Map Preferences, Map platformPreferences, Map boardPreferences)
- {
- HashMap _map = new HashMap();
-
- Iterator iterator = Preferences.entrySet().iterator();
-
- while(iterator.hasNext())
- {
- Map.Entry pair = (Map.Entry)iterator.next();
- if (pair.getValue() == null)
- {
- _map.put(pair.getKey(), "");
- }
- else
- {
- _map.put(pair.getKey(), pair.getValue());
- }
- }
-
- //logger.debug("Done: Preferences");
-
- iterator = platformPreferences.entrySet().iterator();
-
- while(iterator.hasNext())
- {
- Map.Entry pair = (Map.Entry)iterator.next();
-
- if (pair.getValue() == null)
- {
- _map.put(pair.getKey(), "");
- }
- else
- {
- _map.put(pair.getKey(), pair.getValue());
- }
- //System.out.println(pair.getKey() + " = " + pair.getValue());
- }
+ // debug includePaths
+ // System.out.println("includePaths: ");
+ // for (int i = 0; i < includePaths.size(); i++)
+ // System.out.println("-I" + includePaths.get(i));
- //System.out.println("Done: platformPreferences");
- iterator = boardPreferences.entrySet().iterator();
+ String commandString = "";
+ // System.out.println("corePath: " + corePath);
+ List srcDirs = new ArrayList();
+ srcDirs.add(corePath);
+ srcDirs.addAll(systemExtraSrc);
+ srcDirs.addAll(coreExtraSrc);
+ srcDirs.addAll(variantExtraSrc);
- while(iterator.hasNext())
- {
- Map.Entry pair = (Map.Entry)iterator.next();
-
- if (pair.getValue() == null)
- {
- _map.put(pair.getKey(), "");
- }
- else
- {
- _map.put(pair.getKey(), pair.getValue());
- }
- //System.out.println(pair.getKey() + " = " + pair.getValue());
- }
- //System.out.println("Done: boardPreferences");
-
+ List objects = new ArrayList();
+
+ for (String dir : srcDirs) {
+ objects.addAll(compileFiles(avrBasePath, buildPath, includePaths,
+ findFilesInPath(dir, "S", false),
+ findFilesInPath(dir, "c", false),
+ findFilesInPath(dir, "cpp", false),
+ configPreferences));
+ }
+
+ for (File file : objects) {
+ // List commandAR = new ArrayList(baseCommandAR);
+ // commandAR = commandAR + file.getAbsolutePath();
+
+ Object[] Args = { avrBasePath, // 0
+ configPreferences.get("compiler.ar.cmd"), // 1
+ configPreferences.get("compiler.ar.flags"), // 2
+ // corePath,
+ buildPath + File.separator, "core.a", // 3
+ // objectName
+ file.getAbsolutePath() // 4
+ };
+ // System.out.println("compileCore(...) substitute");
+
+ String baseCommandString = configPreferences.get("recipe.ar.pattern");
+ MessageFormat compileFormat = new MessageFormat(baseCommandString);
+ commandString = compileFormat.format(Args);
+
+ String[] commandArray = commandString.split("\\|");
+ execAsynchronously(commandArray);
+ }
+ }
+
+ // 4. link it all together into the .elf file
+ void compileLink(String avrBasePath, String buildPath, String corePath,
+ List includePaths, String pinsPath,
+ Map configPreferences)
+ throws RunnerException {
+ System.out.println("compileLink: start");
+ String baseCommandString = configPreferences
+ .get("recipe.c.combine.pattern");
+ String commandString = "";
+ MessageFormat compileFormat = new MessageFormat(baseCommandString);
+ String objectFileList = "";
+
+ for (File file : objectFiles) {
+ objectFileList = objectFileList + file.getAbsolutePath() + "|";
+ }
+ System.out.println("objectFileList: " + objectFileList);
+
+ Object[] Args = { avrBasePath, // 0
+ configPreferences.get("compiler.c.elf.cmd"), // 1
+ configPreferences.get("compiler.c.elf.flags"), // 2
+ configPreferences.get("compiler.cpudef"), // 3
+ configPreferences.get("build.mcu"), // 4
+ buildPath + File.separator, // 5
+ primaryClassName, // 6
+ objectFileList, // 7
+ buildPath + File.separator + "core.a", // 8
+ buildPath, // 9
+ corePath, // 10
+ pinsPath + File.separator + configPreferences.get("build.ldscript") // 11
+ };
+ commandString = compileFormat.format(Args);
+ String[] commandArray = commandString.split("\\|");
+ execAsynchronously(commandArray);
+ }
+
+ // 5. extract EEPROM data (from EEMEM directive) to .eep file.
+ void compileEep(String avrBasePath, String buildPath,
+ List includePaths,
+ Map configPreferences) throws RunnerException {
+ // logger.debug("compileEep: start");
+ String baseCommandString = configPreferences
+ .get("recipe.objcopy.eep.pattern");
+ String commandString = "";
+ MessageFormat compileFormat = new MessageFormat(baseCommandString);
+ String objectFileList = "";
+
+ Object[] Args = { avrBasePath,
+ configPreferences.get("compiler.objcopy.cmd"),
+ configPreferences.get("compiler.objcopy.eep.flags"),
+ buildPath + File.separator + primaryClassName,
+ buildPath + File.separator + primaryClassName };
+ commandString = compileFormat.format(Args);
+ String[] commandArray = commandString.split("\\|");
+ execAsynchronously(commandArray);
+ }
+
+ // 6. build the .hex file
+ void compileHex(String avrBasePath, String buildPath,
+ List includePaths,
+ Map configPreferences) throws RunnerException {
+ // logger.debug("compileHex: start");
+ String baseCommandString = configPreferences
+ .get("recipe.objcopy.hex.pattern");
+ String commandString = "";
+ MessageFormat compileFormat = new MessageFormat(baseCommandString);
+ String objectFileList = "";
+
+ Object[] Args = { avrBasePath,
+ configPreferences.get("compiler.elf2hex.cmd"),
+ configPreferences.get("compiler.elf2hex.flags"),
+ buildPath + File.separator + primaryClassName,
+ buildPath + File.separator + primaryClassName };
+ commandString = compileFormat.format(Args);
+ String[] commandArray = commandString.split("\\|");
+ execAsynchronously(commandArray);
+ }
+
+ // merge all the preferences file in the correct order of precedence
+ HashMap mergePreferences(Map Preferences, Map platformPreferences,
+ Map boardPreferences) {
+ HashMap _map = new HashMap();
+
+ Iterator iterator = Preferences.entrySet().iterator();
+
+ while (iterator.hasNext()) {
+ Map.Entry pair = (Map.Entry) iterator.next();
+ if (pair.getValue() == null) {
+ _map.put(pair.getKey(), "");
+ } else {
+ _map.put(pair.getKey(), pair.getValue());
+ }
+ }
+
+ // logger.debug("Done: Preferences");
+
+ iterator = platformPreferences.entrySet().iterator();
+
+ while (iterator.hasNext()) {
+ Map.Entry pair = (Map.Entry) iterator.next();
+
+ if (pair.getValue() == null) {
+ _map.put(pair.getKey(), "");
+ } else {
+ _map.put(pair.getKey(), pair.getValue());
+ }
+ // System.out.println(pair.getKey() + " = " + pair.getValue());
+ }
+
+ // System.out.println("Done: platformPreferences");
+ iterator = boardPreferences.entrySet().iterator();
+
+ while (iterator.hasNext()) {
+ Map.Entry pair = (Map.Entry) iterator.next();
+
+ if (pair.getValue() == null) {
+ _map.put(pair.getKey(), "");
+ } else {
+ _map.put(pair.getKey(), pair.getValue());
+ }
+ // System.out.println(pair.getKey() + " = " + pair.getValue());
+ }
+ // System.out.println("Done: boardPreferences");
+
+ return _map;
+ }
+
+ // getIncludes to String
+ private static String preparePaths(List includePaths) {
+ String includes = "";
+ for (int i = 0; i < includePaths.size(); i++)
+ includes += " -I" + includePaths.get(i) + "|";
+ return includes;
+ }
- return _map;
- }
-
- private static String preparePaths(ArrayList includePaths) {
- //getIncludes to String
- //logger.debug("Start: Prepare paths");
- String includes = "";
- for (int i = 0; i < includePaths.size(); i++)
- {
- includes = includes + (" -I" + (String) includePaths.get(i)) + "|";
- }
- //logger.debug("Paths prepared: " + includes);
- return includes;
- }
-
-
}
diff --git a/hardware/sam/boards.txt b/hardware/sam/boards.txt
index 97ab04784..7852a52ff 100644
--- a/hardware/sam/boards.txt
+++ b/hardware/sam/boards.txt
@@ -39,4 +39,16 @@ arduino_due.build.mcu=cortex-m3
arduino_due.build.f_cpu=96000000L
arduino_due.build.core=sam
arduino_due.build.pins=arduino_due
+arduino_due.build.extra_flags=-D__SAM3U4E__
+arduino_due.build.extra_include_dirs=system/libsam|system/libsam/include|system/CMSIS/Include|system/libsam/cmsis/sam3u/source/templates|system/libsam/cmsis/sam3u/include
+arduino_due.core.extra_source_dirs=sam
+arduino_due.system.extra_source_dirs=libsam/source|libsam/cmsis/sam3u/source/templates|libsam/cmsis/sam3u/source/templates/gcc
+arduino_due.variants.extra_source_dirs=arduino_due|common
+#hardware/sam/system/libsam/source/
+#hardware/sam/system/libsam/cmsis/sam3u/source/
+#hardware/sam/variants/arduino_due
+#hardware/sam/variants/common
+#hardware/sam/cores/sam
+arduino_due.build.ldscript=linker_scripts/gcc/flash.ld
+
diff --git a/hardware/sam/platforms.txt b/hardware/sam/platforms.txt
index 2ceee28db..b3a1f812e 100755
--- a/hardware/sam/platforms.txt
+++ b/hardware/sam/platforms.txt
@@ -12,12 +12,12 @@
########sam compile pattern ##########
#sam.recipe.c.o.pattern={0=compiler.path}{1=compiler.c.cmd}{2=compiler.c.flags}{3=compiler.cpudef}{4=build.mcu}-DF_CPU={5=build.f_cpu}-D{7=ARDUINO}={6=Base.REVISION}{7=-I/INCLUDE_PATHS} {8=SOURCE_NAME} -o{9=OBJECT_NAME}
#object name seems to have build path in it.
-sam.recipe.c.o.pattern={0}{1}|{2}|{3}{4}|-DF_CPU={5}|-D{6}={7}|{8}|{9}|-o|{10}
+sam.recipe.c.o.pattern={0}{1}|{2}|{3}{4}|-DF_CPU={5}|-D{6}={7}|{11}|{8}|{9}|-o|{10}
##compile cc object files
#sam.recipe.cc.o.pattern={0=compiler.path}{1=compiler.cc.cmd}{2=compiler.c.flags}{3=compiler.cpudef}{4=build.mcu}-DF_CPU={5=build.f_cpu}-DARDUINO={6=Base.REVISION}{-7=I/INCLUDE_PATHS} {8=SOURCE_NAME} -o{9=BUILD_PATH}{10=OBJECT_NAME}
-sam.recipe.cpp.o.pattern={0}{1}|{2}|{3}{4}|-DF_CPU={5}|-D{6}={7}|{8}|{9}|-o|{10}
+sam.recipe.cpp.o.pattern={0}{1}|{2}|{3}{4}|-DF_CPU={5}|-D{6}={7}|{11}|{8}|{9}|-o|{10}
##create archives
#sam.recipe.ar.pattern={0=compiler.path}{1=compiler.ar.cmd}{2=compiler.ar.flags}{3=BUILD_PATH}{4=CORE_NAME=core.a}{5=BUILD_PATH}{6=OBJECT_NAME}
sam.recipe.ar.pattern={0}{1}|{2}|{3}{4}|{5}
@@ -25,7 +25,7 @@ sam.recipe.ar.pattern={0}{1}|{2}|{3}{4}|{5}
##combine gc-sections| archives, and objects
#sam.recipe.c.combine.pattern={0=compiler.path}{1=compiler.c.cmd}{2=compiler.combine.flags}{3=compiler.cpudef}{4=build.mcu} -o {5=BUILD_PATH}{6=SOURCE_NAME}.elf {7=BUILD_PATH}{8=SOURCE_NAME}.o {9=BUILD_PATH}{10=CORE_NAME=core.a} -L{11=BUILD_PATH} -lm
#sam.recipe.c.combine.pattern={0}{1}|{2}|{3}{4}|-o|{5}{6}.elf|{7}{8}|{9}|-L{10}|-lm
-sam.recipe.c.combine.pattern={0}{1}|{2}|{3}{4}|-o|{5}{6}.elf|{7}|{8}|-L{9}|-lm
+sam.recipe.c.combine.pattern={0}{1}|{2}|{3}{4}|-T{11}|-Wl,-Map,{5}{6}.map|-o|{5}{6}.elf|-L{9}|-lm|-lgcc|-mthumb|-Wl,--cref|-Wl,--check-sections|-Wl,--gc-sections|-Wl,--entry=Reset_Handler|-Wl,--unresolved-symbols=report-all|-Wl,--warn-common|-Wl,--warn-section-align|-Wl,--warn-unresolved-symbols|-Wl,--start-group|{7}|{8}|-Wl,--end-group
##create eeprom
#sam.recipe.objcopy.eep.pattern={0=compiler.path}{1=compiler.objcopy.cmd}{2=compiler.objcopy.eep.flags} {3=BUILD_PATH}{4=SOURCE_NAME}.elf {5=BUILD_PATH}{6=SOURCE_NAME}.eep
@@ -42,17 +42,17 @@ sam.name=Atmel SAM
#sam.compiler.path Official default is correct, only need to change this if you want to overide the initial default
sam.compiler.path={0}/hardware/tools/CodeSourcery_arm/bin/
sam.compiler.c.cmd=arm-none-eabi-gcc
-sam.compiler.c.flags=|-c|-g|-Os|-w|-mthumb|-mlong-calls|-ffunction-sections
+sam.compiler.c.flags=|-c|-g|-Os|-w|-mthumb|-mlong-calls|-ffunction-sections|-nostdlib|--param|max-inline-insns-single=500|-Dprintf=iprintf
sam.compiler.c.elf.flags=|-Os|-Wl,--gc-sections
sam.compiler.c.elf.cmd=arm-none-eabi-gcc
sam.compiler.S.flags=|-c|-g|-assembler-with-cpp
sam.compiler.cpp.cmd=arm-none-eabi-g++
-sam.compiler.cpp.flags=|-c|-g|-Os|-w|-mthumb|-mlong-calls|-ffunction-sections
+sam.compiler.cpp.flags=|-c|-g|-Os|-w|-mthumb|-mlong-calls|-ffunction-sections|-nostdlib|--param|max-inline-insns-single=500|-fno-rtti|-fno-exceptions|-Dprintf=iprintf
sam.compiler.ar.cmd=arm-none-eabi-ar
sam.compiler.ar.flags=rcs
sam.compiler.objcopy.cmd=arm-none-eabi-objcopy
sam.compiler.objcopy.eep.flags=|-O|ihex|-j|.eeprom|--set-section-flags=.eeprom=alloc,load|--no-change-warnings|--change-section-lma|.eeprom=0
-sam.compiler.elf2hex.flags=|-O|ihex|-R|.eeprom
+sam.compiler.elf2hex.flags=|-O|binary
sam.compiler.elf2hex.cmd=arm-none-eabi-objcopy
sam.compiler.ldflags=
sam.compiler.cpudef=-mcpu=