1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-19 13:54:23 +01:00

Compilation process for ARM (WIP)

This commit is contained in:
Cristian Maglie 2011-09-17 00:02:40 +02:00
parent d1d60447e9
commit bd7e6d89d5
5 changed files with 735 additions and 761 deletions

View File

@ -2,19 +2,11 @@
<classpath> <classpath>
<classpathentry excluding="processing/app/tools/format/" kind="src" path="src"/> <classpathentry excluding="processing/app/tools/format/" kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
<classpathentry combineaccessrules="false" kind="src" path="/dxf"/>
<classpathentry combineaccessrules="false" kind="src" path="/net"/>
<classpathentry combineaccessrules="false" kind="src" path="/opengl">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="opengl/library"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/pdf"/>
<classpathentry combineaccessrules="false" kind="src" path="/serial"/>
<classpathentry combineaccessrules="false" kind="src" path="/video"/>
<classpathentry kind="lib" path="lib/antlr.jar"/> <classpathentry kind="lib" path="lib/antlr.jar"/>
<classpathentry kind="lib" path="lib/jna.jar"/> <classpathentry kind="lib" path="lib/jna.jar"/>
<classpathentry kind="lib" path="lib/ecj.jar"/> <classpathentry kind="lib" path="lib/ecj.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/processing-core"/>
<classpathentry kind="lib" path="lib/apple.jar"/>
<classpathentry kind="lib" path="lib/RXTXcomm.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -960,9 +960,9 @@ public class Base {
try { try {
//Find the current target. Get the platform, and then select the correct name and core path. //Find the current target. Get the platform, and then select the correct name and core path.
String platformname = this.getBoardPreferences().get("platform"); String platformname = getBoardPreferences().get("platform");
String targetname = this.getPlatformPreferences(platformname).get("name"); String targetname = getPlatformPreferences(platformname).get("name");
String libraryPath = this.getPlatformPreferences(platformname).get("library.core.path"); String libraryPath = getPlatformPreferences(platformname).get("library.core.path");
JMenuItem platformItem = new JMenuItem(targetname); JMenuItem platformItem = new JMenuItem(targetname);
platformItem.setEnabled(false); platformItem.setEnabled(false);
@ -1554,7 +1554,7 @@ public class Base {
static public Target getTarget() { static public Target getTarget() {
System.out.println("Base.targetsTable.get(Preferences.get(\"target\"))" + Base.targetsTable.get(Preferences.get("target"))); 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")); Target target = Base.targetsTable.get(Preferences.get("target"));
if (target == null) { if (target == null) {
System.out.println("default target is not in list. Replace with default."); System.out.println("default target is not in list. Replace with default.");
@ -1643,14 +1643,15 @@ static public Map<String, String> getPlatformPreferences() {
return map; return map;
} }
static public Map<String, String> getBoardPreferences() { static public Map<String, String> getBoardPreferences() {
Target target = getTarget(); Target target = getTarget();
Map map = new LinkedHashMap();
if (target != null) { if (target != null) {
map = target.getBoards(); Map<String, Map<String, String>> map = target.getBoards();
map = (Map) map.get(Preferences.get("board")); Map<String, String> res = map.get(Preferences.get("board"));
if (res != null)
return res;
} }
return map; return new HashMap<String, String>();
} }
static public File getSketchbookFolder() { static public File getSketchbookFolder() {

View File

@ -19,63 +19,76 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation, along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package processing.app.debug; 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.Base;
import processing.app.Preferences; import processing.app.Preferences;
import processing.app.Sketch; import processing.app.Sketch;
import processing.app.SketchCode; import processing.app.SketchCode;
import processing.core.*; import processing.core.PApplet;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.text.MessageFormat;
public class Compiler implements MessageConsumer { public class Compiler implements MessageConsumer {
static final String BUGS_URL = static final String BUGS_URL = "http://code.google.com/p/arduino/issues/list";
"http://code.google.com/p/arduino/issues/list";
static final String SUPER_BADNESS = static final String SUPER_BADNESS = "Compiler error, please submit this code to "
"Compiler error, please submit this code to " + BUGS_URL; + BUGS_URL;
Sketch sketch; Sketch sketch;
String buildPath; String buildPath;
String primaryClassName; String primaryClassName;
String platform; String platform;
String board; String board;
boolean verbose; boolean verbose;
RunnerException exception; RunnerException exception;
HashMap<String, String> configPreferences; Map<String, String> configPreferences;
HashMap<String, String> boardPreferences;
HashMap<String, String> platformPreferences; Map<String, String> boardPreferences;
Map<String, String> platformPreferences;
String avrBasePath; String avrBasePath;
String corePath;
List<File> objectFiles; List<File> objectFiles;
ArrayList<String> includePaths;
public Compiler() { } public Compiler() {
}
/** /**
* Compile with avr-gcc. * Compile with avr-gcc.
* *
* @param sketch Sketch object to be compiled. * @param sketch
* @param buildPath Where the temporary files live and will be built from. * Sketch object to be compiled.
* @param primaryClassName the name of the combined sketch file w/ extension * @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. * @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, public boolean compile(Sketch sketch, String buildPath,
String buildPath, String primaryClassName, boolean verbose)
String primaryClassName, throws RunnerException {
boolean verbose) throws RunnerException {
this.sketch = sketch; this.sketch = sketch;
this.buildPath = buildPath; this.buildPath = buildPath;
this.primaryClassName = primaryClassName; this.primaryClassName = primaryClassName;
@ -83,200 +96,190 @@ public class Compiler implements MessageConsumer {
objectFiles = new ArrayList<File>(); objectFiles = new ArrayList<File>();
// the pms object isn't used for anything but storage // the pms object isn't used for anything but storage
MessageStream pms = new MessageStream(this); // MessageStream pms = new MessageStream(this);
Map<String, String> boardPreferences = Base.getBoardPreferences(); Map<String, String> boardPreferences = Base.getBoardPreferences();
//Check for null platform, and use system default if not found // Check for null platform, and use system default if not found
platform = boardPreferences.get("platform"); platform = boardPreferences.get("platform");
if (platform == null) if (platform == null)
{
platformPreferences = new HashMap(Base.getPlatformPreferences()); platformPreferences = new HashMap(Base.getPlatformPreferences());
}
else else
{
platformPreferences = new HashMap(Base.getPlatformPreferences(platform)); platformPreferences = new HashMap(Base.getPlatformPreferences(platform));
}
System.out.println("////////////////////////////compiler.java is doing stuff/////////////////"); System.out.println("-> compiler.java is doing stuff");
//Put all the global preference configuration into one Master configpreferences // Put all the global preference configuration into one Master
configPreferences = mergePreferences( Preferences.getMap(), platformPreferences, boardPreferences); // configpreferences
configPreferences = mergePreferences(Preferences.getMap(),
platformPreferences, boardPreferences);
avrBasePath = configPreferences.get("compiler.path"); avrBasePath = configPreferences.get("compiler.path");
if (avrBasePath == null) if (avrBasePath == null) {
{
avrBasePath = Base.getAvrBasePath(); avrBasePath = Base.getAvrBasePath();
System.out.println("avrBasePath: " + avrBasePath); // System.out.println("avrBasePath: " + avrBasePath);
} } else {
else // System.out.println("avrBasePath:exists: " + avrBasePath);
{
System.out.println("avrBasePath:exists: " + avrBasePath);
//Put in the system path in the compiler path if available // Put in the system path in the compiler path if available
MessageFormat compileFormat = new MessageFormat(avrBasePath);
String basePath = System.getProperty("user.dir"); String basePath = System.getProperty("user.dir");
if (Base.isMacOS()) { if (Base.isMacOS()) {
//logger.debug("basePath: " + basePath); // logger.debug("basePath: " + basePath);
basePath += "/Arduino.app/Contents/Resources/Java"; basePath += "/Arduino.app/Contents/Resources/Java";
} }
Object[] Args = {basePath}; Object[] Args = { basePath };
avrBasePath = compileFormat.format( Args ); avrBasePath = new MessageFormat(avrBasePath).format(Args);
System.out.println("avrBasePath:new: " + avrBasePath); // System.out.println("avrBasePath:new: " + avrBasePath);
}
this.board = configPreferences.get("board");
if (this.board == "")
{
this.board = "_UNKNOWN";
} }
board = configPreferences.get("board");
if (board == "")
board = "_UNKNOWN";
String core = configPreferences.get("build.core"); String core = configPreferences.get("build.core");
if (core == null) { 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(); re.hideStackTrace();
throw re; throw re;
} }
String corePath, systemPath;
String corePath, systemPath;
File coreFolder;
Target target;
if (core.indexOf(':') == -1) { if (core.indexOf(':') == -1) {
Target t = Base.getTarget(); target = Base.getTarget();
File coreFolder = new File(new File(t.getFolder(), "cores"), core); coreFolder = new File(new File(target.getFolder(), "cores"), core);
corePath = coreFolder.getAbsolutePath(); corePath = coreFolder.getAbsolutePath();
systemPath = new File(t.getFolder(), "system").getAbsolutePath();
systemPath = new File(target.getFolder(), "system").getAbsolutePath();
} else { } else {
Target t = Base.targetsTable.get(core.substring(0, core.indexOf(':'))); target = Base.targetsTable.get(core.substring(0, core.indexOf(':')));
File coreFolder = new File(t.getFolder(), "cores"); coreFolder = new File(target.getFolder(), "cores");
coreFolder = new File(coreFolder, core.substring(core.indexOf(':') + 1)); coreFolder = new File(coreFolder, core.substring(core.indexOf(':') + 1));
corePath = coreFolder.getAbsolutePath(); corePath = coreFolder.getAbsolutePath();
systemPath = new File(t.getFolder(), "system").getAbsolutePath(); systemPath = new File(target.getFolder(), "system").getAbsolutePath();
} }
List<String> systemExtraSrc = new ArrayList<String>();
String extraSystem = configPreferences.get("system.extra_source_dirs");
if (extraSystem != null)
for (String dir : extraSystem.split("\\|"))
systemExtraSrc.add(systemPath + File.separator + dir);
List<String> coreExtraSrc = new ArrayList<String>();
String extraCore = configPreferences.get("core.extra_source_dirs");
if (extraCore != null)
for (String dir : extraCore.split("\\|"))
coreExtraSrc.add(coreFolder.getParent() + File.separator + dir);
List<String> 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 pins = configPreferences.get("build.pins");
String pinsPath = null; String pinsPath = null;
List<String> variantExtraSrc = new ArrayList<String>();
File pinsFolder = null;
if (pins != null) { if (pins != null) {
if (pins.indexOf(':') == -1) { if (pins.indexOf(':') == -1) {
Target t = Base.getTarget(); Target t = Base.getTarget();
File pinsFolder = new File(new File(t.getFolder(), "variants"), pins); pinsFolder = new File(new File(t.getFolder(), "variants"), pins);
pinsPath = pinsFolder.getAbsolutePath(); pinsPath = pinsFolder.getAbsolutePath();
} else { } else {
Target t = Base.targetsTable.get(pins.substring(0, pins.indexOf(':'))); Target t = Base.targetsTable.get(pins.substring(0, pins.indexOf(':')));
File pinsFolder = new File(t.getFolder(), "variants"); pinsFolder = new File(t.getFolder(), "variants");
pinsFolder = new File(pinsFolder, pins.substring(pins.indexOf(':') + 1)); pinsFolder = new File(pinsFolder, pins.substring(pins.indexOf(':') + 1));
pinsPath = pinsFolder.getAbsolutePath(); 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 // 0. include paths for core + all libraries
for (File file : sketch.getImportedLibraries())
ArrayList<String> includePaths = new ArrayList();
includePaths.add(corePath);
includePaths.add(systemPath);
if (pinsPath != null) includePaths.add(pinsPath);
for (File file : sketch.getImportedLibraries()) {
includePaths.add(file.getPath()); includePaths.add(file.getPath());
}
// 1. compile the sketch (already in the buildPath) // 1. compile the sketch (already in the buildPath)
System.out.println("1. compileSketch"); System.out.println("1. compileSketch");
compileSketch(avrBasePath, buildPath, includePaths, configPreferences); compileSketch(avrBasePath, buildPath, includePaths, configPreferences);
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/ // 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
// 2. compile the libraries, outputting .o files to: // Doesn't really use configPreferences
// <buildPath>/<library>/
//Doesn't really use configPreferences
System.out.println("2. compileLibraries"); System.out.println("2. compileLibraries");
compileLibraries(avrBasePath, buildPath, includePaths, configPreferences); compileLibraries(avrBasePath, buildPath, includePaths, configPreferences);
/* /*
*
for (File libraryFolder : sketch.getImportedLibraries()) { * for (File libraryFolder : sketch.getImportedLibraries()) { File
File outputFolder = new File(buildPath, libraryFolder.getName()); * outputFolder = new File(buildPath, libraryFolder.getName()); File
File utilityFolder = new File(libraryFolder, "utility"); * utilityFolder = new File(libraryFolder, "utility");
createFolder(outputFolder); * createFolder(outputFolder); // this library can use includes in its
// this library can use includes in its utility/ folder * utility/ folder includePaths.add(utilityFolder.getAbsolutePath());
includePaths.add(utilityFolder.getAbsolutePath()); * objectFiles.addAll( compileFiles(avrBasePath,
objectFiles.addAll( * outputFolder.getAbsolutePath(), includePaths,
compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, * findFilesInFolder(libraryFolder, "S", false),
findFilesInFolder(libraryFolder, "S", false), * findFilesInFolder(libraryFolder, "c", false),
findFilesInFolder(libraryFolder, "c", false), * findFilesInFolder(libraryFolder, "cpp", false), boardPreferences));
findFilesInFolder(libraryFolder, "cpp", false), * outputFolder = new File(outputFolder, "utility");
boardPreferences)); * createFolder(outputFolder); objectFiles.addAll( compileFiles(avrBasePath,
outputFolder = new File(outputFolder, "utility"); * outputFolder.getAbsolutePath(), includePaths,
createFolder(outputFolder); * findFilesInFolder(utilityFolder, "S", false),
objectFiles.addAll( * findFilesInFolder(utilityFolder, "c", false),
compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, * findFilesInFolder(utilityFolder, "cpp", false), boardPreferences)); //
findFilesInFolder(utilityFolder, "S", false), * other libraries should not see this library's utility/ folder
findFilesInFolder(utilityFolder, "c", false), * includePaths.remove(includePaths.size() - 1); }
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 <buildPath> and then // 3. compile the core, outputting .o files to <buildPath> and then
// collecting them into the core.a library file. // collecting them into the core.a library file.
System.out.println("3. compileCore"); System.out.println("3. compileCore");
System.out.println("corePath: " + corePath); System.out.println("corePath: " + corePath);
compileCore(avrBasePath, buildPath, corePath, systemPath, pins, pinsPath, configPreferences); compileCore(includePaths, corePath, coreExtraSrc, systemPath,
systemExtraSrc, variantExtraSrc, configPreferences);
/*
/* * includePaths.clear(); includePaths.add(corePath); // include path for
includePaths.clear(); * core only if (pinsPath != null) includePaths.add(pinsPath); List<File>
includePaths.add(corePath); // include path for core only * coreObjectFiles = compileFiles(avrBasePath, buildPath, includePaths,
if (pinsPath != null) includePaths.add(pinsPath); * findFilesInPath(corePath, "S", true), findFilesInPath(corePath, "c",
List<File> coreObjectFiles = * true), findFilesInPath(corePath, "cpp", true), boardPreferences);
compileFiles(avrBasePath, buildPath, includePaths, *
findFilesInPath(corePath, "S", true), * String runtimeLibraryName = buildPath + File.separator + "core.a"; List
findFilesInPath(corePath, "c", true), * baseCommandAR = new ArrayList(Arrays.asList(new String[] { avrBasePath +
findFilesInPath(corePath, "cpp", true), * "avr-ar", "rcs", runtimeLibraryName })); for(File file : coreObjectFiles)
boardPreferences); * { List commandAR = new ArrayList(baseCommandAR);
* commandAR.add(file.getAbsolutePath()); execAsynchronously(commandAR); }
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 // 4. link it all together into the .elf file
System.out.println("4. compileLink"); 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[] { * List baseCommandLinker = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-gcc", * avrBasePath + "avr-gcc", "-Os", "-Wl,--gc-sections", "-mmcu=" +
"-Os", * boardPreferences.get("build.mcu"), "-o", buildPath + File.separator +
"-Wl,--gc-sections", * primaryClassName + ".elf" }));
"-mmcu=" + boardPreferences.get("build.mcu"), *
"-o", * for (File file : objectFiles) {
buildPath + File.separator + primaryClassName + ".elf" * baseCommandLinker.add(file.getAbsolutePath()); }
})); *
* baseCommandLinker.add(runtimeLibraryName); baseCommandLinker.add("-L" +
for (File file : objectFiles) { * buildPath); baseCommandLinker.add("-lm");
baseCommandLinker.add(file.getAbsolutePath()); *
} * execAsynchronously(baseCommandLinker);
*
baseCommandLinker.add(runtimeLibraryName); * List baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] {
baseCommandLinker.add("-L" + buildPath); * avrBasePath + "avr-objcopy", "-O", "-R", }));
baseCommandLinker.add("-lm"); *
* List commandObjcopy;
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. // 5. extract EEPROM data (from EEMEM directive) to .eep file.
System.out.println("5. compileEep"); System.out.println("5. compileEep");
@ -289,11 +292,10 @@ public class Compiler implements MessageConsumer {
return true; return true;
} }
private List<File> compileFiles(String avrBasePath, String buildPath,
private List<File> compileFiles(String avrBasePath, List<String> includePaths,
String buildPath, ArrayList<String> includePaths, List<File> sSources, List<File> cSources,
ArrayList<File> sSources, List<File> cppSources,
ArrayList<File> cSources, ArrayList<File> cppSources,
Map<String, String> boardPreferences) Map<String, String> boardPreferences)
throws RunnerException { throws RunnerException {
@ -302,35 +304,29 @@ public class Compiler implements MessageConsumer {
for (File file : sSources) { for (File file : sSources) {
String objectPath = buildPath + File.separator + file.getName() + ".o"; String objectPath = buildPath + File.separator + file.getName() + ".o";
objectPaths.add(new File(objectPath)); objectPaths.add(new File(objectPath));
execAsynchronously(getCommandCompilerS(avrBasePath, includePaths, execAsynchronously(getCommandCompilerS(avrBasePath, includePaths, file
file.getAbsolutePath(), .getAbsolutePath(), objectPath, configPreferences));
objectPath,
configPreferences));
} }
for (File file : cSources) { for (File file : cSources) {
String objectPath = buildPath + File.separator + file.getName() + ".o"; String objectPath = buildPath + File.separator + file.getName() + ".o";
objectPaths.add(new File(objectPath)); objectPaths.add(new File(objectPath));
execAsynchronously(getCommandCompilerC(avrBasePath, includePaths, execAsynchronously(getCommandCompilerC(avrBasePath, includePaths, file
file.getAbsolutePath(), .getAbsolutePath(), objectPath, configPreferences));
objectPath,
configPreferences));
} }
for (File file : cppSources) { for (File file : cppSources) {
String objectPath = buildPath + File.separator + file.getName() + ".o"; String objectPath = buildPath + File.separator + file.getName() + ".o";
objectPaths.add(new File(objectPath)); objectPaths.add(new File(objectPath));
execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths, execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths, file
file.getAbsolutePath(), .getAbsolutePath(), objectPath, configPreferences));
objectPath,
configPreferences));
} }
return objectPaths; return objectPaths;
} }
boolean firstErrorFound; boolean firstErrorFound;
boolean secondErrorFound; boolean secondErrorFound;
/** /**
@ -338,11 +334,11 @@ public class Compiler implements MessageConsumer {
*/ */
private void execAsynchronously(String[] command) throws RunnerException { private void execAsynchronously(String[] command) throws RunnerException {
//eliminate any empty array entries // eliminate any empty array entries
List<String> stringList = new ArrayList<String>(); List<String> stringList = new ArrayList<String>();
for(String string : command) { for (String string : command) {
string = string.trim(); string = string.trim();
if(string != null && string.length() > 0) { if (string != null && string.length() > 0) {
stringList.add(string); stringList.add(string);
} }
} }
@ -350,12 +346,12 @@ public class Compiler implements MessageConsumer {
int result = 0; int result = 0;
if (verbose || Preferences.getBoolean("build.verbose")) { // if (verbose || Preferences.getBoolean("build.verbose")) {
for(int j = 0; j < command.length; j++) { System.out.print("EXEC: ");
System.out.print(command[j] + " "); for (String c : command)
} System.out.print(c + " ");
System.out.println(); System.out.println();
} // }
firstErrorFound = false; // haven't found any errors yet firstErrorFound = false; // haven't found any errors yet
secondErrorFound = false; secondErrorFound = false;
@ -383,9 +379,10 @@ public class Compiler implements MessageConsumer {
if (err.thread != null) if (err.thread != null)
err.thread.join(); err.thread.join();
result = process.waitFor(); result = process.waitFor();
//System.out.println("result is " + result); // System.out.println("result is " + result);
compiling = false; compiling = false;
} catch (InterruptedException ignored) { } } catch (InterruptedException ignored) {
}
} }
// an error was queued up by message(), barf this back to compile(), // 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 // discerning the imagery, consider how cows regurgitate their food
// to digest it, and the fact that they have five stomaches. // to digest it, and the fact that they have five stomaches.
// //
//System.out.println("throwing up " + exception); // System.out.println("throwing up " + exception);
if (exception != null) { throw exception; } if (exception != null) {
throw exception;
}
if (result > 1) { if (result > 1) {
// a failure in the tool (e.g. unable to locate a sub-executable) // a failure in the tool (e.g. unable to locate a sub-executable)
@ -406,15 +405,14 @@ public class Compiler implements MessageConsumer {
re.hideStackTrace(); re.hideStackTrace();
throw re; throw re;
} }
System.out.println("execAsync: Done."); // System.out.println("execAsync: Done.");
} }
/** /**
* Part of the MessageConsumer interface, this is called * Part of the MessageConsumer interface, this is called whenever a piece
* whenever a piece (usually a line) of error message is spewed * (usually a line) of error message is spewed out from the compiler. The
* out from the compiler. The errors are parsed for their contents * errors are parsed for their contents and line number, which is then
* and line number, which is then reported back to Editor. * reported back to Editor.
*/ */
public void message(String s) { public void message(String s) {
int i; int i;
@ -424,7 +422,8 @@ public class Compiler implements MessageConsumer {
// have meaning in a regular expression. // have meaning in a regular expression.
if (!verbose) { if (!verbose) {
while ((i = s.indexOf(buildPath + File.separator)) != -1) { 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());
} }
} }
@ -433,32 +432,36 @@ public class Compiler implements MessageConsumer {
String errorFormat = "([\\w\\d_]+.\\w+):(\\d+):\\s*error:\\s*(.*)\\s*"; String errorFormat = "([\\w\\d_]+.\\w+):(\\d+):\\s*error:\\s*(.*)\\s*";
String[] pieces = PApplet.match(s, errorFormat); String[] pieces = PApplet.match(s, errorFormat);
// if (pieces != null && exception == null) { // if (pieces != null && exception == null) {
// exception = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1); // exception = sketch.placeException(pieces[3], pieces[1],
// if (exception != null) exception.hideStackTrace(); // PApplet.parseInt(pieces[2]) - 1);
// } // if (exception != null) exception.hideStackTrace();
// }
if (pieces != null) { 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 // 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) // in verbose mode, in which case don't modify the compiler output)
if (e != null && !verbose) { if (e != null && !verbose) {
SketchCode code = sketch.getCode(e.getCodeIndex()); SketchCode code = sketch.getCode(e.getCodeIndex());
String fileName = code.isExtension(sketch.getDefaultExtension()) ? code.getPrettyName() : code.getFileName(); String fileName = code.isExtension(sketch.getDefaultExtension()) ? code
.getPrettyName() : code.getFileName();
s = fileName + ":" + e.getCodeLine() + ": error: " + e.getMessage(); s = fileName + ":" + e.getCodeLine() + ": error: " + e.getMessage();
} }
if (pieces[3].trim().equals("SPI.h: No such file or directory")) { 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."); e = new RunnerException(
s += "\nAs of Arduino 0019, the Ethernet library depends on the SPI library." + "Please import the SPI library from the Sketch > Import Library menu.");
"\nYou appear to be using it or another library that depends on the SPI library."; 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")) { if (pieces[3].trim().equals("'BYTE' was not declared in this scope")) {
e = new RunnerException("The 'BYTE' keyword is no longer supported."); e = new RunnerException("The 'BYTE' keyword is no longer supported.");
s += "\nAs of Arduino 1.0, 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."; + "\nPlease use Serial.write() instead.";
} }
if (exception == null && e != null) { if (exception == null && e != null) {
@ -470,199 +473,177 @@ public class Compiler implements MessageConsumer {
System.err.print(s); System.err.print(s);
} }
///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////
/* /*
static private List getCommandCompilerS(String avrBasePath, List includePaths, * static private List getCommandCompilerS(String avrBasePath, List
String sourceName, String objectName, Map<String, String> boardPreferences) { * includePaths, String sourceName, String objectName, Map<String, String>
List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { * boardPreferences) { List baseCommandCompiler = new
avrBasePath + "avr-gcc", * ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-c", //
"-c", // compile, don't link * compile, don't link "-g", // include debugging info (so errors include line
"-g", // include debugging info (so errors include line numbers) * numbers) "-assembler-with-cpp", "-mmcu=" +
"-assembler-with-cpp", * boardPreferences.get("build.mcu"), "-DF_CPU=" +
"-mmcu=" + boardPreferences.get("build.mcu"), * boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, }));
"-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)); }
*
for (int i = 0; i < includePaths.size(); i++) { * baseCommandCompiler.add(sourceName); baseCommandCompiler.add("-o"+
baseCommandCompiler.add("-I" + (String) includePaths.get(i)); * objectName);
} *
* return baseCommandCompiler; }
baseCommandCompiler.add(sourceName); */
baseCommandCompiler.add("-o"+ objectName);
return baseCommandCompiler;
}
*/
// /////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////
static private String[] getCommandCompilerS(String avrBasePath, static private String[] getCommandCompilerS(
ArrayList<String> includePaths, String sourceName, String objectName, String avrBasePath,
HashMap<String, String> configPreferences) List<String> includePaths,
{ String sourceName,
String objectName,
Map<String, String> configPreferences) {
System.out.println("getCommandCompilerS: start"); System.out.println("getCommandCompilerS: start");
String baseCommandString = configPreferences.get("recipe.cpp.o.pattern"); String baseCommandString = configPreferences.get("recipe.cpp.o.pattern");
MessageFormat compileFormat = new MessageFormat(baseCommandString); MessageFormat compileFormat = new MessageFormat(baseCommandString);
//getIncludes to String // getIncludes to String
String includes = preparePaths(includePaths); String includes = preparePaths(includePaths);
Object[] Args = { Object[] Args = { avrBasePath, configPreferences.get("compiler.cpp.cmd"),
avrBasePath,
configPreferences.get("compiler.cpp.cmd"),
configPreferences.get("compiler.S.flags"), configPreferences.get("compiler.S.flags"),
configPreferences.get("compiler.cpudef"), configPreferences.get("compiler.cpudef"),
configPreferences.get("build.mcu"), configPreferences.get("build.mcu"),
configPreferences.get("build.f_cpu"), configPreferences.get("build.f_cpu"),
configPreferences.get("software"), configPreferences.get("software"), Base.REVISION, includes, sourceName,
Base.REVISION, objectName };
includes,
sourceName,
objectName
};
String command = compileFormat.format( Args ); String command = compileFormat.format(Args);
String[] commandArray = command.split("\\|"); String[] commandArray = command.split("\\|");
return commandArray; return commandArray;
} }
/*
static private List getCommandCompilerC(String avrBasePath, List includePaths,
String sourceName, String objectName, Map<String, String> 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;
}
*/
//removed static
private String[] getCommandCompilerC(String avrBasePath,
ArrayList<String> includePaths, String sourceName, String objectName,
HashMap<String, String> 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<String, String> 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;
}
*/
static private String[] getCommandCompilerCPP(String avrBasePath,
ArrayList<String> includePaths, String sourceName, String objectName,
HashMap<String, String> 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++) * static private List getCommandCompilerC(String avrBasePath, List
{ * includePaths, String sourceName, String objectName, Map<String, String>
System.out.println("'" + commandArray[ii] + "'"); * 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; }
*/ */
// removed static
private String[] getCommandCompilerC(String avrBasePath,
List<String> includePaths,
String sourceName, String objectName,
Map<String, String> 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, // 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
};
String command = compileFormat.format(Args);
String[] commandArray = command.split("\\|");
return commandArray; return commandArray;
} }
/*
*
* static private List getCommandCompilerCPP(String avrBasePath, List
* includePaths, String sourceName, String objectName, Map<String, String>
* 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; }
*/
///////////////////////////////////////////////////////////////////////////// static private String[] getCommandCompilerCPP(
String avrBasePath,
List<String> includePaths,
String sourceName,
String objectName,
Map<String, String> 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, // 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
};
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 { static private void createFolder(File folder) throws RunnerException {
if (folder.isDirectory()) return; if (folder.isDirectory())
return;
if (!folder.mkdir()) if (!folder.mkdir())
throw new RunnerException("Couldn't create: " + folder); throw new RunnerException("Couldn't create: " + folder);
} }
/** /**
* Given a folder, return a list of the header files in that folder (but * Given a folder, return a list of the header files in that folder (but not
* not the header files in its sub-folders, as those should be included from * the header files in its sub-folders, as those should be included from
* within the header files at the top-level). * within the header files at the top-level).
*/ */
static public String[] headerListFromIncludePath(String path) { static public String[] headerListFromIncludePath(String path) {
@ -681,14 +662,17 @@ public class Compiler implements MessageConsumer {
return findFilesInFolder(new File(path), extension, recurse); return findFilesInFolder(new File(path), extension, recurse);
} }
static public ArrayList<File> findFilesInFolder(File folder, String extension, static public ArrayList<File> findFilesInFolder(File folder,
String extension,
boolean recurse) { boolean recurse) {
ArrayList<File> files = new ArrayList<File>(); ArrayList<File> files = new ArrayList<File>();
if (folder.listFiles() == null) return files; if (folder.listFiles() == null)
return files;
for (File file : folder.listFiles()) { 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)) if (file.getName().endsWith("." + extension))
files.add(file); files.add(file);
@ -701,19 +685,19 @@ public class Compiler implements MessageConsumer {
return files; return files;
} }
// 1. compile the sketch (already in the buildPath) // 1. compile the sketch (already in the buildPath)
void compileSketch(String avrBasePath, String buildPath, ArrayList<String> includePaths, HashMap<String, String> configPreferences) void compileSketch(String avrBasePath, String buildPath,
throws RunnerException List<String> includePaths,
{ Map<String, String> configPreferences)
throws RunnerException {
System.out.println("compileSketch: start"); System.out.println("compileSketch: start");
System.out.println("includePaths: "); System.out.println("includePaths: ");
for (int i = 0; i < includePaths.size(); i++) { for (int i = 0; i < includePaths.size(); i++) {
System.out.println("-I" + (String) includePaths.get(i)); System.out.println("-I" + (String) includePaths.get(i));
} }
//logger.debug("compileSketch: start"); // logger.debug("compileSketch: start");
this.objectFiles.addAll(compileFiles(avrBasePath, buildPath, includePaths, objectFiles.addAll(compileFiles(avrBasePath, buildPath, includePaths,
findFilesInPath(buildPath, "S", false), findFilesInPath(buildPath, "S", false),
findFilesInPath(buildPath, "c", false), findFilesInPath(buildPath, "c", false),
findFilesInPath(buildPath, "cpp", false), findFilesInPath(buildPath, "cpp", false),
@ -722,38 +706,42 @@ public class Compiler implements MessageConsumer {
// 2. compile the libraries, outputting .o files to: // 2. compile the libraries, outputting .o files to:
// <buildPath>/<library>/ // <buildPath>/<library>/
void compileLibraries (String avrBasePath, String buildPath, ArrayList<String> includePaths, HashMap<String, String> configPreferences) void compileLibraries(String avrBasePath, String buildPath,
throws RunnerException List<String> includePaths,
{ Map<String, String> configPreferences)
System.out.println("compileLibraries: start"); throws RunnerException {
// System.out.println("compileLibraries: start");
for (File libraryFolder : sketch.getImportedLibraries()) { for (File libraryFolder : sketch.getImportedLibraries()) {
System.out.println("libraryFolder: " + libraryFolder); // System.out.println("libraryFolder: " + libraryFolder);
File outputFolder = new File(buildPath, libraryFolder.getName()); File outputFolder = new File(buildPath, libraryFolder.getName());
File utilityFolder = new File(libraryFolder, "utility"); File utilityFolder = new File(libraryFolder, "utility");
createFolder(outputFolder); createFolder(outputFolder);
// this library can use includes in its utility/ folder // this library can use includes in its utility/ folder
includePaths.add(utilityFolder.getAbsolutePath()); includePaths.add(utilityFolder.getAbsolutePath());
//debug includePaths // debug includePaths
System.out.println("includePaths: "); // System.out.println("includePaths: ");
for (int i = 0; i < includePaths.size(); i++) { // for (int i = 0; i < includePaths.size(); i++) {
System.out.println("-I" + (String) includePaths.get(i)); // System.out.println("-I" + (String) includePaths.get(i));
} // }
objectFiles.addAll(compileFiles(avrBasePath, outputFolder
objectFiles.addAll( .getAbsolutePath(), includePaths, findFilesInFolder(libraryFolder,
compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, "S", false),
findFilesInFolder(libraryFolder, "S", false), findFilesInFolder(libraryFolder, "c",
findFilesInFolder(libraryFolder, "c", false), false),
findFilesInFolder(libraryFolder, "cpp", false), findFilesInFolder(libraryFolder, "cpp",
false),
boardPreferences)); boardPreferences));
outputFolder = new File(outputFolder, "utility"); outputFolder = new File(outputFolder, "utility");
createFolder(outputFolder); createFolder(outputFolder);
objectFiles.addAll( objectFiles.addAll(compileFiles(avrBasePath, outputFolder
compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, .getAbsolutePath(), includePaths, findFilesInFolder(utilityFolder,
findFilesInFolder(utilityFolder, "S", false), "S", false),
findFilesInFolder(utilityFolder, "c", false), findFilesInFolder(utilityFolder, "c",
findFilesInFolder(utilityFolder, "cpp", false), false),
findFilesInFolder(utilityFolder, "cpp",
false),
boardPreferences)); boardPreferences));
// other libraries should not see this library's utility/ folder // other libraries should not see this library's utility/ folder
includePaths.remove(includePaths.size() - 1); includePaths.remove(includePaths.size() - 1);
@ -762,65 +750,67 @@ public class Compiler implements MessageConsumer {
// 3. compile the core, outputting .o files to <buildPath> and then // 3. compile the core, outputting .o files to <buildPath> and then
// collecting them into the core.a library file. // collecting them into the core.a library file.
void compileCore (String avrBasePath, String buildPath, String corePath, String systemPath, String pins, String pinsPath, HashMap<String, String> configPreferences) void compileCore(List<String> includePaths, String corePath,
throws RunnerException List<String> coreExtraSrc, String systemPath,
{ List<String> systemExtraSrc, List<String> variantExtraSrc,
System.out.println("compileCore(...) start"); Map<String, String> configPreferences)
throws RunnerException {
// System.out.println("compileCore(...) start");
ArrayList<String> includePaths = new ArrayList(); // debug includePaths
includePaths.add(corePath); //include core path only // System.out.println("includePaths: ");
includePaths.add(systemPath); // for (int i = 0; i < includePaths.size(); i++)
if (pinsPath != null) includePaths.add(pinsPath); // System.out.println("-I" + includePaths.get(i));
//debug includePaths String commandString = "";
System.out.println("includePaths: "); // System.out.println("corePath: " + corePath);
for (int i = 0; i < includePaths.size(); i++) { List<String> srcDirs = new ArrayList<String>();
System.out.println("-I" + (String) includePaths.get(i)); srcDirs.add(corePath);
srcDirs.addAll(systemExtraSrc);
srcDirs.addAll(coreExtraSrc);
srcDirs.addAll(variantExtraSrc);
List<File> objects = new ArrayList<File>();
for (String dir : srcDirs) {
objects.addAll(compileFiles(avrBasePath, buildPath, includePaths,
findFilesInPath(dir, "S", false),
findFilesInPath(dir, "c", false),
findFilesInPath(dir, "cpp", false),
configPreferences));
} }
String baseCommandString = configPreferences.get("recipe.ar.pattern"); for (File file : objects) {
String commandString = ""; // List commandAR = new ArrayList(baseCommandAR);
MessageFormat compileFormat = new MessageFormat(baseCommandString); // commandAR = commandAR + file.getAbsolutePath();
System.out.println("corePath: " + corePath);
List<File> coreObjectFiles = compileFiles(
avrBasePath,
buildPath,
includePaths,
findFilesInPath(corePath, "S", true),
findFilesInPath(corePath, "c", true),
findFilesInPath(corePath, "cpp", true),
configPreferences);
for (File file : coreObjectFiles) { Object[] Args = { avrBasePath, // 0
//List commandAR = new ArrayList(baseCommandAR); configPreferences.get("compiler.ar.cmd"), // 1
//commandAR = commandAR + file.getAbsolutePath(); configPreferences.get("compiler.ar.flags"), // 2
// corePath,
Object[] Args = { buildPath + File.separator, "core.a", // 3
avrBasePath, // objectName
configPreferences.get("compiler.ar.cmd"), file.getAbsolutePath() // 4
configPreferences.get("compiler.ar.flags"),
//corePath,
buildPath + File.separator,
"core.a",
//objectName
file.getAbsolutePath()
}; };
System.out.println("compileCore(...) substitute"); // System.out.println("compileCore(...) substitute");
String baseCommandString = configPreferences.get("recipe.ar.pattern");
MessageFormat compileFormat = new MessageFormat(baseCommandString);
commandString = compileFormat.format(Args);
commandString = compileFormat.format( Args );
String[] commandArray = commandString.split("\\|"); String[] commandArray = commandString.split("\\|");
execAsynchronously(commandArray); execAsynchronously(commandArray);
} }
} }
// 4. link it all together into the .elf file // 4. link it all together into the .elf file
void compileLink(String avrBasePath, String buildPath, String corePath, ArrayList<String> includePaths, HashMap<String, String> configPreferences) void compileLink(String avrBasePath, String buildPath, String corePath,
throws RunnerException List<String> includePaths, String pinsPath,
{ Map<String, String> configPreferences)
throws RunnerException {
System.out.println("compileLink: start"); System.out.println("compileLink: start");
String baseCommandString = configPreferences.get("recipe.c.combine.pattern"); String baseCommandString = configPreferences
.get("recipe.c.combine.pattern");
String commandString = ""; String commandString = "";
MessageFormat compileFormat = new MessageFormat(baseCommandString); MessageFormat compileFormat = new MessageFormat(baseCommandString);
String objectFileList = ""; String objectFileList = "";
@ -830,142 +820,121 @@ public class Compiler implements MessageConsumer {
} }
System.out.println("objectFileList: " + objectFileList); System.out.println("objectFileList: " + objectFileList);
Object[] Args = { Object[] Args = { avrBasePath, // 0
avrBasePath, configPreferences.get("compiler.c.elf.cmd"), // 1
configPreferences.get("compiler.c.elf.cmd"), configPreferences.get("compiler.c.elf.flags"), // 2
configPreferences.get("compiler.c.elf.flags"), configPreferences.get("compiler.cpudef"), // 3
configPreferences.get("compiler.cpudef"), configPreferences.get("build.mcu"), // 4
configPreferences.get("build.mcu"), buildPath + File.separator, // 5
buildPath + File.separator, primaryClassName, // 6
primaryClassName, objectFileList, // 7
objectFileList, buildPath + File.separator + "core.a", // 8
buildPath + File.separator + "core.a", buildPath, // 9
buildPath, corePath, // 10
corePath, pinsPath + File.separator + configPreferences.get("build.ldscript") // 11
configPreferences.get("ldscript"),
}; };
commandString = compileFormat.format( Args ); commandString = compileFormat.format(Args);
String[] commandArray = commandString.split("\\|"); String[] commandArray = commandString.split("\\|");
execAsynchronously(commandArray); execAsynchronously(commandArray);
} }
// 5. extract EEPROM data (from EEMEM directive) to .eep file. // 5. extract EEPROM data (from EEMEM directive) to .eep file.
void compileEep (String avrBasePath, String buildPath, ArrayList<String> includePaths, HashMap<String, String> configPreferences) void compileEep(String avrBasePath, String buildPath,
throws RunnerException List<String> includePaths,
{ Map<String, String> configPreferences) throws RunnerException {
//logger.debug("compileEep: start"); // logger.debug("compileEep: start");
String baseCommandString = configPreferences.get("recipe.objcopy.eep.pattern"); String baseCommandString = configPreferences
.get("recipe.objcopy.eep.pattern");
String commandString = ""; String commandString = "";
MessageFormat compileFormat = new MessageFormat(baseCommandString); MessageFormat compileFormat = new MessageFormat(baseCommandString);
String objectFileList = ""; String objectFileList = "";
Object[] Args = { Object[] Args = { avrBasePath,
avrBasePath,
configPreferences.get("compiler.objcopy.cmd"), configPreferences.get("compiler.objcopy.cmd"),
configPreferences.get("compiler.objcopy.eep.flags"), configPreferences.get("compiler.objcopy.eep.flags"),
buildPath + File.separator + primaryClassName, buildPath + File.separator + primaryClassName,
buildPath + File.separator + primaryClassName buildPath + File.separator + primaryClassName };
}; commandString = compileFormat.format(Args);
commandString = compileFormat.format( Args );
String[] commandArray = commandString.split("\\|"); String[] commandArray = commandString.split("\\|");
execAsynchronously(commandArray); execAsynchronously(commandArray);
} }
// 6. build the .hex file // 6. build the .hex file
void compileHex (String avrBasePath, String buildPath, ArrayList<String> includePaths, HashMap<String, String> configPreferences) void compileHex(String avrBasePath, String buildPath,
throws RunnerException List<String> includePaths,
{ Map<String, String> configPreferences) throws RunnerException {
//logger.debug("compileHex: start"); // logger.debug("compileHex: start");
String baseCommandString = configPreferences.get("recipe.objcopy.hex.pattern"); String baseCommandString = configPreferences
.get("recipe.objcopy.hex.pattern");
String commandString = ""; String commandString = "";
MessageFormat compileFormat = new MessageFormat(baseCommandString); MessageFormat compileFormat = new MessageFormat(baseCommandString);
String objectFileList = ""; String objectFileList = "";
Object[] Args = { Object[] Args = { avrBasePath,
avrBasePath,
configPreferences.get("compiler.elf2hex.cmd"), configPreferences.get("compiler.elf2hex.cmd"),
configPreferences.get("compiler.elf2hex.flags"), configPreferences.get("compiler.elf2hex.flags"),
buildPath + File.separator + primaryClassName, buildPath + File.separator + primaryClassName,
buildPath + File.separator + primaryClassName buildPath + File.separator + primaryClassName };
}; commandString = compileFormat.format(Args);
commandString = compileFormat.format( Args );
String[] commandArray = commandString.split("\\|"); String[] commandArray = commandString.split("\\|");
execAsynchronously(commandArray); execAsynchronously(commandArray);
} }
//merge all the preferences file in the correct order of precedence // merge all the preferences file in the correct order of precedence
HashMap mergePreferences(Map Preferences, Map platformPreferences, Map boardPreferences) HashMap mergePreferences(Map Preferences, Map platformPreferences,
{ Map boardPreferences) {
HashMap _map = new HashMap(); HashMap _map = new HashMap();
Iterator iterator = Preferences.entrySet().iterator(); Iterator iterator = Preferences.entrySet().iterator();
while(iterator.hasNext()) while (iterator.hasNext()) {
{ Map.Entry pair = (Map.Entry) iterator.next();
Map.Entry pair = (Map.Entry)iterator.next(); if (pair.getValue() == null) {
if (pair.getValue() == null)
{
_map.put(pair.getKey(), ""); _map.put(pair.getKey(), "");
} } else {
else
{
_map.put(pair.getKey(), pair.getValue()); _map.put(pair.getKey(), pair.getValue());
} }
} }
//logger.debug("Done: Preferences"); // logger.debug("Done: Preferences");
iterator = platformPreferences.entrySet().iterator(); iterator = platformPreferences.entrySet().iterator();
while(iterator.hasNext()) while (iterator.hasNext()) {
{ Map.Entry pair = (Map.Entry) iterator.next();
Map.Entry pair = (Map.Entry)iterator.next();
if (pair.getValue() == null) if (pair.getValue() == null) {
{
_map.put(pair.getKey(), ""); _map.put(pair.getKey(), "");
} } else {
else
{
_map.put(pair.getKey(), pair.getValue()); _map.put(pair.getKey(), pair.getValue());
} }
//System.out.println(pair.getKey() + " = " + pair.getValue()); // System.out.println(pair.getKey() + " = " + pair.getValue());
} }
//System.out.println("Done: platformPreferences"); // System.out.println("Done: platformPreferences");
iterator = boardPreferences.entrySet().iterator(); iterator = boardPreferences.entrySet().iterator();
while(iterator.hasNext()) while (iterator.hasNext()) {
{ Map.Entry pair = (Map.Entry) iterator.next();
Map.Entry pair = (Map.Entry)iterator.next();
if (pair.getValue() == null) if (pair.getValue() == null) {
{
_map.put(pair.getKey(), ""); _map.put(pair.getKey(), "");
} } else {
else
{
_map.put(pair.getKey(), pair.getValue()); _map.put(pair.getKey(), pair.getValue());
} }
//System.out.println(pair.getKey() + " = " + pair.getValue()); // System.out.println(pair.getKey() + " = " + pair.getValue());
} }
//System.out.println("Done: boardPreferences"); // System.out.println("Done: boardPreferences");
return _map; return _map;
} }
private static String preparePaths(ArrayList<String> includePaths) { // getIncludes to String
//getIncludes to String private static String preparePaths(List<String> includePaths) {
//logger.debug("Start: Prepare paths");
String includes = ""; String includes = "";
for (int i = 0; i < includePaths.size(); i++) for (int i = 0; i < includePaths.size(); i++)
{ includes += " -I" + includePaths.get(i) + "|";
includes = includes + (" -I" + (String) includePaths.get(i)) + "|";
}
//logger.debug("Paths prepared: " + includes);
return includes; return includes;
} }
} }

View File

@ -39,4 +39,16 @@ arduino_due.build.mcu=cortex-m3
arduino_due.build.f_cpu=96000000L arduino_due.build.f_cpu=96000000L
arduino_due.build.core=sam arduino_due.build.core=sam
arduino_due.build.pins=arduino_due 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

View File

@ -12,12 +12,12 @@
########sam compile pattern ########## ########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} #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. #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 ##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.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 ##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=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} 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 ##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=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}|{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 ##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 #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 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.path={0}/hardware/tools/CodeSourcery_arm/bin/
sam.compiler.c.cmd=arm-none-eabi-gcc 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.flags=|-Os|-Wl,--gc-sections
sam.compiler.c.elf.cmd=arm-none-eabi-gcc sam.compiler.c.elf.cmd=arm-none-eabi-gcc
sam.compiler.S.flags=|-c|-g|-assembler-with-cpp sam.compiler.S.flags=|-c|-g|-assembler-with-cpp
sam.compiler.cpp.cmd=arm-none-eabi-g++ 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.cmd=arm-none-eabi-ar
sam.compiler.ar.flags=rcs sam.compiler.ar.flags=rcs
sam.compiler.objcopy.cmd=arm-none-eabi-objcopy 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.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.elf2hex.cmd=arm-none-eabi-objcopy
sam.compiler.ldflags= sam.compiler.ldflags=
sam.compiler.cpudef=-mcpu= sam.compiler.cpudef=-mcpu=