changed link argument sent to makefile:

instead of using linker, user may specify linker line including tools
This commit is contained in:
fros4943 2007-09-05 14:00:59 +00:00
parent 661a76408a
commit db74bb6566
2 changed files with 149 additions and 95 deletions

View File

@ -1,4 +1,4 @@
# $Id: Makefile.cooja,v 1.18 2007/05/21 14:57:47 fros4943 Exp $ # $Id: Makefile.cooja,v 1.19 2007/09/05 14:04:17 fros4943 Exp $
## The COOJA Simulator Contiki platform Makefile ## The COOJA Simulator Contiki platform Makefile
## ##
@ -48,7 +48,7 @@ endif ## QUICKSTART
OUTPUT_DIR = obj_cooja OUTPUT_DIR = obj_cooja
LIBFILE = $(OUTPUT_DIR)/$(TYPEID).library LIBFILE = $(OUTPUT_DIR)/$(TYPEID).library
DEPFILE = $(OUTPUT_DIR)/$(TYPEID).a ARFILE = $(OUTPUT_DIR)/$(TYPEID).a
MAPFILE = $(OUTPUT_DIR)/$(TYPEID).map MAPFILE = $(OUTPUT_DIR)/$(TYPEID).map
MAINFILE = $(OUTPUT_DIR)/$(TYPEID).co MAINFILE = $(OUTPUT_DIR)/$(TYPEID).co
@ -79,19 +79,19 @@ CFLAGSNO = $(EXTRA_CC_ARGS) -Wall -g -I/usr/local/include
CFLAGS = $(CFLAGSNO) CFLAGS = $(CFLAGSNO)
### Define custom targets ### Define custom targets
$(LIBFILE): $(MAINFILE) $(PROJECT_OBJECTFILES) $(DEPFILE) $(LIBFILE): $(MAINFILE) $(PROJECT_OBJECTFILES) $(ARFILE)
ifdef SYMBOLS ifdef SYMBOLS
# Recreate symbols file and relink with final memory layout (twice) # Recreate symbols file and relink with final memory layout (twice)
$(CC) $(CFLAGS) -c symbols.c -o $(OBJECTDIR)/symbols.o $(CC) $(CFLAGS) -c symbols.c -o $(OBJECTDIR)/symbols.o
$(LD) -Map=$(MAPFILE) -shared $(LD_ARGS_1) -o $@ $^ $(LD_ARGS_2) $(LINK_COMMAND_1) $^ $(LINK_COMMAND_2)
${CONTIKI}/tools/make-symbols-nm $(LIBFILE) ${CONTIKI}/tools/make-symbols-nm $(LIBFILE)
$(CC) $(CFLAGS) -c symbols.c -o $(OBJECTDIR)/symbols.o $(CC) $(CFLAGS) -c symbols.c -o $(OBJECTDIR)/symbols.o
$(LD) -Map=$(MAPFILE) -shared $(LD_ARGS_1) -o $@ $^ $(LD_ARGS_2) $(LINK_COMMAND_1) $^ $(LINK_COMMAND_2)
else else
$(LD) -Map=$(MAPFILE) -shared $(LD_ARGS_1) -o $@ $^ $(LD_ARGS_2) $(LINK_COMMAND_1) $^ $(LINK_COMMAND_2)
endif endif
$(DEPFILE): ${addprefix $(OBJECTDIR)/, $(CONTIKI_SOURCEFILES:.c=.o)} $(ARFILE): ${addprefix $(OBJECTDIR)/, $(CONTIKI_SOURCEFILES:.c=.o)}
$(AR) rcf $@ $^ $(AR) rcf $@ $^
ifndef WINDIR ifndef WINDIR

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ContikiMoteTypeDialog.java,v 1.32 2007/05/28 07:26:51 fros4943 Exp $ * $Id: ContikiMoteTypeDialog.java,v 1.33 2007/09/05 14:00:59 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -53,14 +53,14 @@ import se.sics.cooja.dialogs.ProjectDirectoriesDialog;
* libraries. Allows user to change mote type specific data such as * libraries. Allows user to change mote type specific data such as
* descriptions, which processes should be started at mote initialization and * descriptions, which processes should be started at mote initialization and
* which interfaces the type should support. * which interfaces the type should support.
* *
* The dialog takes a Contiki mote type as argument and pre-selects the values * The dialog takes a Contiki mote type as argument and pre-selects the values
* already set in that mote type before showing the dialog. Any changes made to * already set in that mote type before showing the dialog. Any changes made to
* the settings are written to the mote type if the compilation is successful * the settings are written to the mote type if the compilation is successful
* and the user presses OK. * and the user presses OK.
* *
* This dialog uses external tools to scan for sources and compile libraries. * This dialog uses external tools to scan for sources and compile libraries.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public class ContikiMoteTypeDialog extends JDialog { public class ContikiMoteTypeDialog extends JDialog {
@ -103,7 +103,7 @@ public class ContikiMoteTypeDialog extends JDialog {
private Vector<File> moteTypeProjectDirs = new Vector<File>(); // Mote type project directories private Vector<File> moteTypeProjectDirs = new Vector<File>(); // Mote type project directories
private Vector<File> compilationFiles = null; private Vector<File> compilationFiles = null;
private Vector<MoteType> allOtherTypes = null; // Used to check for private Vector<MoteType> allOtherTypes = null; // Used to check for
// conflicting parameters // conflicting parameters
@ -113,7 +113,7 @@ public class ContikiMoteTypeDialog extends JDialog {
/** /**
* Shows a dialog for configuring a Contiki mote type and compiling the shared * Shows a dialog for configuring a Contiki mote type and compiling the shared
* library it uses. * library it uses.
* *
* @param parentFrame * @param parentFrame
* Parent frame for dialog * Parent frame for dialog
* @param simulation * @param simulation
@ -128,7 +128,7 @@ public class ContikiMoteTypeDialog extends JDialog {
final ContikiMoteTypeDialog myDialog = new ContikiMoteTypeDialog( final ContikiMoteTypeDialog myDialog = new ContikiMoteTypeDialog(
parentFrame); parentFrame);
myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
myDialog.myMoteType = moteTypeToConfigure; myDialog.myMoteType = moteTypeToConfigure;
myDialog.myGUI = simulation.getGUI(); myDialog.myGUI = simulation.getGUI();
myDialog.allOtherTypes = simulation.getMoteTypes(); myDialog.allOtherTypes = simulation.getMoteTypes();
@ -217,10 +217,11 @@ public class ContikiMoteTypeDialog extends JDialog {
.getProjectDirs(); .getProjectDirs();
String projectText = null; String projectText = null;
for (File projectDir : myDialog.moteTypeProjectDirs) { for (File projectDir : myDialog.moteTypeProjectDirs) {
if (projectText == null) if (projectText == null) {
projectText = "'" + projectDir.getPath() + "'"; projectText = "'" + projectDir.getPath() + "'";
else } else {
projectText += ", '" + projectDir.getPath() + "'"; projectText += ", '" + projectDir.getPath() + "'";
}
} }
myDialog.textProjectDirs.setText(projectText); myDialog.textProjectDirs.setText(projectText);
} }
@ -232,7 +233,7 @@ public class ContikiMoteTypeDialog extends JDialog {
// Set preset communication stack // Set preset communication stack
myDialog.commStackComboBox.setSelectedItem(moteTypeToConfigure.getCommunicationStack()); myDialog.commStackComboBox.setSelectedItem(moteTypeToConfigure.getCommunicationStack());
// Scan directories for processes, sensors and core interfaces // Scan directories for processes, sensors and core interfaces
// TODO Really do this without starting a separate thread? // TODO Really do this without starting a separate thread?
myDialog.updateVisualFields(); myDialog.updateVisualFields();
@ -255,7 +256,7 @@ public class ContikiMoteTypeDialog extends JDialog {
if (!foundAndSelectedProcess) { if (!foundAndSelectedProcess) {
// Let user choose whether to add process // Let user choose whether to add process
Object[] options = { "Add", "Cancel" }; Object[] options = { "Add", "Cancel" };
String question = "The configuration file contains a process " String question = "The configuration file contains a process "
+ "(" + presetProcess + ") not found during scan." + "(" + presetProcess + ") not found during scan."
+ "\nDo you want to include this anyway?"; + "\nDo you want to include this anyway?";
@ -263,7 +264,7 @@ public class ContikiMoteTypeDialog extends JDialog {
int answer = JOptionPane.showOptionDialog(myDialog, question, title, int answer = JOptionPane.showOptionDialog(myDialog, question, title,
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]); options, options[0]);
if (answer == JOptionPane.YES_OPTION) { if (answer == JOptionPane.YES_OPTION) {
// Create new check box // Create new check box
JCheckBox newCheckBox = new JCheckBox(presetProcess, true); JCheckBox newCheckBox = new JCheckBox(presetProcess, true);
@ -296,7 +297,7 @@ public class ContikiMoteTypeDialog extends JDialog {
if (!foundAndSelectedSensor) { if (!foundAndSelectedSensor) {
// Let user choose whether to add sensor // Let user choose whether to add sensor
Object[] options = { "Add", "Cancel" }; Object[] options = { "Add", "Cancel" };
String question = "The configuration file contains a sensor " String question = "The configuration file contains a sensor "
+ "(" + presetSensor + ") not found during scan." + "(" + presetSensor + ") not found during scan."
+ "\nDo you want to include this anyway?"; + "\nDo you want to include this anyway?";
@ -304,7 +305,7 @@ public class ContikiMoteTypeDialog extends JDialog {
int answer = JOptionPane.showOptionDialog(myDialog, question, title, int answer = JOptionPane.showOptionDialog(myDialog, question, title,
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]); options, options[0]);
if (answer == JOptionPane.YES_OPTION) { if (answer == JOptionPane.YES_OPTION) {
// Create new check box // Create new check box
JCheckBox newCheckBox = new JCheckBox(presetSensor, true); JCheckBox newCheckBox = new JCheckBox(presetSensor, true);
@ -339,7 +340,7 @@ public class ContikiMoteTypeDialog extends JDialog {
if (!foundAndSelectedCoreInterface) { if (!foundAndSelectedCoreInterface) {
// Let user choose whether to add interface // Let user choose whether to add interface
Object[] options = { "Add", "Cancel" }; Object[] options = { "Add", "Cancel" };
String question = "The configuration file contains a core interface " String question = "The configuration file contains a core interface "
+ "(" + presetCoreInterface + ") not found during scan." + "(" + presetCoreInterface + ") not found during scan."
+ "\nDo you want to include this anyway?"; + "\nDo you want to include this anyway?";
@ -347,7 +348,7 @@ public class ContikiMoteTypeDialog extends JDialog {
int answer = JOptionPane.showOptionDialog(myDialog, question, title, int answer = JOptionPane.showOptionDialog(myDialog, question, title,
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]); options, options[0]);
if (answer == JOptionPane.YES_OPTION) { if (answer == JOptionPane.YES_OPTION) {
// Create new check box // Create new check box
JCheckBox newCheckBox = new JCheckBox(presetCoreInterface, true); JCheckBox newCheckBox = new JCheckBox(presetCoreInterface, true);
@ -396,7 +397,7 @@ public class ContikiMoteTypeDialog extends JDialog {
.length()); .length());
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
if (maxSize != null && if (maxSize != null &&
(myDialog.getSize().getWidth() > maxSize.getWidth() (myDialog.getSize().getWidth() > maxSize.getWidth()
|| myDialog.getSize().getHeight() > maxSize.getHeight())) { || myDialog.getSize().getHeight() > maxSize.getHeight())) {
Dimension newSize = new Dimension(); Dimension newSize = new Dimension();
@ -405,7 +406,7 @@ public class ContikiMoteTypeDialog extends JDialog {
logger.info("Resizing dialog: " + myDialog.getSize() + " -> " + newSize); logger.info("Resizing dialog: " + myDialog.getSize() + " -> " + newSize);
myDialog.setSize(newSize); myDialog.setSize(newSize);
} }
myDialog.setVisible(true); myDialog.setVisible(true);
if (myDialog.myMoteType != null) { if (myDialog.myMoteType != null) {
@ -525,30 +526,33 @@ public class ContikiMoteTypeDialog extends JDialog {
textField.setText("[enter description here]"); textField.setText("[enter description here]");
textField.getDocument().addDocumentListener(new DocumentListener() { textField.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
if (myDialog.isVisible()) if (myDialog.isVisible()) {
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
updateVisualFields(); updateVisualFields();
} }
}); });
}
} }
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
if (myDialog.isVisible()) if (myDialog.isVisible()) {
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
updateVisualFields(); updateVisualFields();
} }
}); });
}
} }
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
if (myDialog.isVisible()) if (myDialog.isVisible()) {
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
updateVisualFields(); updateVisualFields();
} }
}); });
}
} }
}); });
@ -652,7 +656,7 @@ public class ContikiMoteTypeDialog extends JDialog {
pathsWereUpdated(); pathsWereUpdated();
} }
}); });
smallPane.add(label); smallPane.add(label);
smallPane.add(Box.createHorizontalStrut(10)); smallPane.add(Box.createHorizontalStrut(10));
smallPane.add(Box.createHorizontalGlue()); smallPane.add(Box.createHorizontalGlue());
@ -699,7 +703,7 @@ public class ContikiMoteTypeDialog extends JDialog {
commStackComboBox = new JComboBox(CommunicationStack.values()); commStackComboBox = new JComboBox(CommunicationStack.values());
commStackComboBox.setSelectedIndex(0); commStackComboBox.setSelectedIndex(0);
smallPane.add(label); smallPane.add(label);
smallPane.add(Box.createHorizontalStrut(10)); smallPane.add(Box.createHorizontalStrut(10));
smallPane.add(Box.createHorizontalGlue()); smallPane.add(Box.createHorizontalGlue());
@ -781,15 +785,19 @@ public class ContikiMoteTypeDialog extends JDialog {
showAdvancedCheckBox.addActionListener(new ActionListener() { showAdvancedCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (((JCheckBox) e.getSource()).isSelected()) { if (((JCheckBox) e.getSource()).isSelected()) {
if (entireCoreInterfacePane != null) if (entireCoreInterfacePane != null) {
entireCoreInterfacePane.setVisible(true); entireCoreInterfacePane.setVisible(true);
if (entireSensorPane != null) }
if (entireSensorPane != null) {
entireSensorPane.setVisible(true); entireSensorPane.setVisible(true);
}
} else { } else {
if (entireCoreInterfacePane != null) if (entireCoreInterfacePane != null) {
entireCoreInterfacePane.setVisible(false); entireCoreInterfacePane.setVisible(false);
if (entireSensorPane != null) }
if (entireSensorPane != null) {
entireSensorPane.setVisible(false); entireSensorPane.setVisible(false);
}
} }
} }
}); });
@ -1031,8 +1039,9 @@ public class ContikiMoteTypeDialog extends JDialog {
progressDialog.setVisible(true); progressDialog.setVisible(true);
// Create temp output directory if not already exists // Create temp output directory if not already exists
if (!ContikiMoteType.tempOutputDirectory.exists()) if (!ContikiMoteType.tempOutputDirectory.exists()) {
ContikiMoteType.tempOutputDirectory.mkdir(); ContikiMoteType.tempOutputDirectory.mkdir();
}
// Parse selected sensors // Parse selected sensors
Vector<String> sensors = new Vector<String>(); Vector<String> sensors = new Vector<String>();
@ -1163,8 +1172,9 @@ public class ContikiMoteTypeDialog extends JDialog {
libraryCreatedOK = false; libraryCreatedOK = false;
} else { } else {
libraryCreatedOK = true; libraryCreatedOK = true;
if (!libFile.exists() || !depFile.exists() || !mapFile.exists()) if (!libFile.exists() || !depFile.exists() || !mapFile.exists()) {
libraryCreatedOK = false; libraryCreatedOK = false;
}
} }
if (libraryCreatedOK) { if (libraryCreatedOK) {
@ -1186,7 +1196,7 @@ public class ContikiMoteTypeDialog extends JDialog {
* Generates new source file by reading default source template and replacing * Generates new source file by reading default source template and replacing
* fields with sensors, core interfaces and processes. Also includes default * fields with sensors, core interfaces and processes. Also includes default
* processes from GUI external configuration. * processes from GUI external configuration.
* *
* @param id * @param id
* Mote type ID (decides name of new source file) * Mote type ID (decides name of new source file)
* @param sensors * @param sensors
@ -1207,39 +1217,44 @@ public class ContikiMoteTypeDialog extends JDialog {
String sensorString = ""; String sensorString = "";
String externSensorDefs = ""; String externSensorDefs = "";
for (String sensor : sensors) { for (String sensor : sensors) {
if (!sensorString.equals("")) if (!sensorString.equals("")) {
sensorString += ", "; sensorString += ", ";
}
sensorString += "&" + sensor; sensorString += "&" + sensor;
externSensorDefs += "extern const struct sensors_sensor " + sensor externSensorDefs += "extern const struct sensors_sensor " + sensor
+ ";\n"; + ";\n";
} }
if (!sensorString.equals("")) if (!sensorString.equals("")) {
sensorString = "SENSORS(" + sensorString + ");"; sensorString = "SENSORS(" + sensorString + ");";
else } else {
sensorString = "SENSORS(NULL);"; sensorString = "SENSORS(NULL);";
}
// CORE INTERFACES // CORE INTERFACES
String interfaceString = ""; String interfaceString = "";
String externInterfaceDefs = ""; String externInterfaceDefs = "";
for (String coreInterface : coreInterfaces) { for (String coreInterface : coreInterfaces) {
if (!interfaceString.equals("")) if (!interfaceString.equals("")) {
interfaceString += ", "; interfaceString += ", ";
}
interfaceString += "&" + coreInterface; interfaceString += "&" + coreInterface;
externInterfaceDefs += "SIM_INTERFACE_NAME(" + coreInterface + ");\n"; externInterfaceDefs += "SIM_INTERFACE_NAME(" + coreInterface + ");\n";
} }
if (!interfaceString.equals("")) if (!interfaceString.equals("")) {
interfaceString = "SIM_INTERFACES(" + interfaceString + ");"; interfaceString = "SIM_INTERFACES(" + interfaceString + ");";
else } else {
interfaceString = "SIM_INTERFACES(NULL);"; interfaceString = "SIM_INTERFACES(NULL);";
}
// PROCESSES (including any default processes) // PROCESSES (including any default processes)
String userProcessString = ""; String userProcessString = "";
String externProcessDefs = ""; String externProcessDefs = "";
for (String process : userProcesses) { for (String process : userProcesses) {
if (!userProcessString.equals("")) if (!userProcessString.equals("")) {
userProcessString += ", "; userProcessString += ", ";
}
userProcessString += "&" + process; userProcessString += "&" + process;
externProcessDefs += "PROCESS_NAME(" + process + ");\n"; externProcessDefs += "PROCESS_NAME(" + process + ");\n";
} }
@ -1248,8 +1263,9 @@ public class ContikiMoteTypeDialog extends JDialog {
String defaultProcesses[] = GUI.getExternalToolsSetting( String defaultProcesses[] = GUI.getExternalToolsSetting(
"CONTIKI_STANDARD_PROCESSES").split(";"); "CONTIKI_STANDARD_PROCESSES").split(";");
for (String process : defaultProcesses) { for (String process : defaultProcesses) {
if (!defaultProcessString.equals("")) if (!defaultProcessString.equals("")) {
defaultProcessString += ", "; defaultProcessString += ", ";
}
defaultProcessString += "&" + process; defaultProcessString += "&" + process;
} }
@ -1259,15 +1275,17 @@ public class ContikiMoteTypeDialog extends JDialog {
} }
String processString; String processString;
if (!defaultProcessString.equals("")) if (!defaultProcessString.equals("")) {
processString = "PROCINIT(" + defaultProcessString + ");"; processString = "PROCINIT(" + defaultProcessString + ");";
else } else {
processString = "PROCINIT(NULL);"; processString = "PROCINIT(NULL);";
}
if (!userProcessString.equals("")) if (!userProcessString.equals("")) {
processString += "\nAUTOSTART_PROCESSES(" + userProcessString + ");"; processString += "\nAUTOSTART_PROCESSES(" + userProcessString + ");";
else } else {
processString += "\nAUTOSTART_PROCESSES(NULL);"; processString += "\nAUTOSTART_PROCESSES(NULL);";
}
// CHECK JNI CLASS AVAILABILITY // CHECK JNI CLASS AVAILABILITY
String libString = CoreComm.getAvailableClassName(); String libString = CoreComm.getAvailableClassName();
@ -1323,10 +1341,12 @@ public class ContikiMoteTypeDialog extends JDialog {
sourceFile.close(); sourceFile.close();
} catch (Exception e) { } catch (Exception e) {
try { try {
if (destFile != null) if (destFile != null) {
destFile.close(); destFile.close();
if (sourceFile != null) }
if (sourceFile != null) {
sourceFile.close(); sourceFile.close();
}
} catch (Exception e2) { } catch (Exception e2) {
} }
@ -1339,7 +1359,7 @@ public class ContikiMoteTypeDialog extends JDialog {
/** /**
* Compiles a mote type shared library using the standard Contiki makefile. * Compiles a mote type shared library using the standard Contiki makefile.
* *
* @param identifier * @param identifier
* Mote type identifier * Mote type identifier
* @param contikiDir * @param contikiDir
@ -1362,48 +1382,53 @@ public class ContikiMoteTypeDialog extends JDialog {
identifier + ContikiMoteType.librarySuffix); identifier + ContikiMoteType.librarySuffix);
File mapFile = new File(ContikiMoteType.tempOutputDirectory, File mapFile = new File(ContikiMoteType.tempOutputDirectory,
identifier + ContikiMoteType.mapSuffix); identifier + ContikiMoteType.mapSuffix);
File depFile = new File(ContikiMoteType.tempOutputDirectory, File arFile = new File(ContikiMoteType.tempOutputDirectory,
identifier + ContikiMoteType.dependSuffix); identifier + ContikiMoteType.dependSuffix);
// Recheck that contiki path exists // Recheck that contiki path exists
if (!contikiDir.exists()) { if (!contikiDir.exists()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad Contiki OS path"); errorStream.println("Bad Contiki OS path");
}
logger.fatal("Contiki path does not exist: " + contikiDir.getAbsolutePath()); logger.fatal("Contiki path does not exist: " + contikiDir.getAbsolutePath());
return false; return false;
} }
if (!contikiDir.isDirectory()) { if (!contikiDir.isDirectory()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad Contiki OS path"); errorStream.println("Bad Contiki OS path");
}
logger.fatal("Contiki path is not a directory"); logger.fatal("Contiki path is not a directory");
return false; return false;
} }
if (libFile.exists()) { if (libFile.exists()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad output filenames"); errorStream.println("Bad output filenames");
}
logger.fatal("Could not overwrite already existing library"); logger.fatal("Could not overwrite already existing library");
return false; return false;
} }
if (CoreComm.hasLibraryFileBeenLoaded(libFile)) { if (CoreComm.hasLibraryFileBeenLoaded(libFile)) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad output filenames"); errorStream.println("Bad output filenames");
logger }
.fatal("A library has already been loaded with the same name before"); logger.fatal("A library has already been loaded with the same name before");
return false; return false;
} }
if (depFile.exists()) { if (arFile.exists()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad output filenames"); errorStream.println("Bad output filenames");
}
logger.fatal("Could not overwrite already existing dependency file"); logger.fatal("Could not overwrite already existing dependency file");
return false; return false;
} }
if (mapFile.exists()) { if (mapFile.exists()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad output filenames"); errorStream.println("Bad output filenames");
}
logger.fatal("Could not overwrite already existing map file"); logger.fatal("Could not overwrite already existing map file");
return false; return false;
} }
@ -1419,13 +1444,27 @@ public class ContikiMoteTypeDialog extends JDialog {
String sourceDirs = System.getProperty("PROJECTDIRS", ""); String sourceDirs = System.getProperty("PROJECTDIRS", "");
String sourceFileNames = ""; String sourceFileNames = "";
// Prepare compilation command
String ccFlags = GUI.getExternalToolsSetting("COMPILER_ARGS", ""); String ccFlags = GUI.getExternalToolsSetting("COMPILER_ARGS", "");
String link1 = GUI.getExternalToolsSetting("LINK_COMMAND_1", "");
// Replace Java home references String link2 = GUI.getExternalToolsSetting("LINK_COMMAND_2", "");
if (ccFlags.contains("$(JAVA_HOME)")) {
String javaHome = (String) System.getenv().get("JAVA_HOME"); link1 = link1.replace("$(MAPFILE)", mapFile.getPath().replace(File.separatorChar, '/'));
ccFlags = ccFlags.replace("$(JAVA_HOME)", javaHome); link2 = link2.replace("$(MAPFILE)", mapFile.getPath().replace(File.separatorChar, '/'));
} ccFlags = ccFlags.replace("$(MAPFILE)", mapFile.getPath().replace(File.separatorChar, '/'));
link1 = link1.replace("$(LIBFILE)", libFile.getPath().replace(File.separatorChar, '/'));
link2 = link2.replace("$(LIBFILE)", libFile.getPath().replace(File.separatorChar, '/'));
ccFlags = ccFlags.replace("$(LIBFILE)", libFile.getPath().replace(File.separatorChar, '/'));
link1 = link1.replace("$(ARFILE)", arFile.getPath().replace(File.separatorChar, '/'));
link2 = link2.replace("$(ARFILE)", arFile.getPath().replace(File.separatorChar, '/'));
ccFlags = ccFlags.replace("$(DEPFILE)", arFile.getPath().replace(File.separatorChar, '/'));
link1 = link1.replace("$(JAVA_HOME)", System.getenv().get("JAVA_HOME"));
link2 = link2.replace("$(JAVA_HOME)", System.getenv().get("JAVA_HOME"));
ccFlags = ccFlags.replace("$(JAVA_HOME)", System.getenv().get("JAVA_HOME"));
for (File sourceFile : sourceFiles) { for (File sourceFile : sourceFiles) {
if (sourceFile.isDirectory()) { if (sourceFile.isDirectory()) {
@ -1449,7 +1488,7 @@ public class ContikiMoteTypeDialog extends JDialog {
// Add communication stack source files // Add communication stack source files
sourceFileNames += commStack.getSourceFilenamesString(); sourceFileNames += commStack.getSourceFilenamesString();
logger.info("-- Compiling --"); logger.info("-- Compiling --");
logger.info("Project dirs: " + sourceDirs); logger.info("Project dirs: " + sourceDirs);
logger.info("Project sources: " + sourceFileNames); logger.info("Project sources: " + sourceFileNames);
@ -1458,8 +1497,8 @@ public class ContikiMoteTypeDialog extends JDialog {
String[] env = new String[]{ String[] env = new String[]{
"CONTIKI=" + contikiDir.getPath().replace(File.separatorChar, '/'), "CONTIKI=" + contikiDir.getPath().replace(File.separatorChar, '/'),
"TARGET=cooja", "TYPEID=" + identifier, "TARGET=cooja", "TYPEID=" + identifier,
"LD_ARGS_1=" + GUI.getExternalToolsSetting("LINKER_ARGS_1", ""), "LINK_COMMAND_1=" + link1,
"LD_ARGS_2=" + GUI.getExternalToolsSetting("LINKER_ARGS_2", ""), "LINK_COMMAND_2=" + link2,
"EXTRA_CC_ARGS=" + ccFlags, "EXTRA_CC_ARGS=" + ccFlags,
"SYMBOLS=" + (includeSymbols?"1":""), "SYMBOLS=" + (includeSymbols?"1":""),
"CC=" + GUI.getExternalToolsSetting("PATH_C_COMPILER"), "CC=" + GUI.getExternalToolsSetting("PATH_C_COMPILER"),
@ -1476,7 +1515,7 @@ public class ContikiMoteTypeDialog extends JDialog {
System.out.println("Environment:\n"); System.out.println("Environment:\n");
for (String s: env) for (String s: env)
System.out.print(s + "\n"); System.out.print(s + "\n");
*/ */
Process p = Runtime.getRuntime().exec(cmd, env, null); Process p = Runtime.getRuntime().exec(cmd, env, null);
final BufferedReader input = new BufferedReader(new InputStreamReader(p final BufferedReader input = new BufferedReader(new InputStreamReader(p
@ -1489,8 +1528,9 @@ public class ContikiMoteTypeDialog extends JDialog {
String readLine; String readLine;
try { try {
while ((readLine = input.readLine()) != null) { while ((readLine = input.readLine()) != null) {
if (outputStream != null && readLine != null) if (outputStream != null && readLine != null) {
outputStream.println(readLine); outputStream.println(readLine);
}
} }
} catch (IOException e) { } catch (IOException e) {
logger.warn("Error while reading from process"); logger.warn("Error while reading from process");
@ -1503,8 +1543,9 @@ public class ContikiMoteTypeDialog extends JDialog {
String readLine; String readLine;
try { try {
while ((readLine = err.readLine()) != null) { while ((readLine = err.readLine()) != null) {
if (errorStream != null && readLine != null) if (errorStream != null && readLine != null) {
errorStream.println(readLine); errorStream.println(readLine);
}
} }
} catch (IOException e) { } catch (IOException e) {
logger.warn("Error while reading from process"); logger.warn("Error while reading from process");
@ -1536,7 +1577,7 @@ public class ContikiMoteTypeDialog extends JDialog {
/** /**
* Scans a directory for sourcefiles which defines a Contiki process. * Scans a directory for sourcefiles which defines a Contiki process.
* *
* @param rootDirectory * @param rootDirectory
* Top directory to search in * Top directory to search in
* @return Process definitions found under rootDirectory, {sourcefile, * @return Process definitions found under rootDirectory, {sourcefile,
@ -1601,7 +1642,7 @@ public class ContikiMoteTypeDialog extends JDialog {
/** /**
* Scans a directory and all subdirectories for sourcefiles which defines a * Scans a directory and all subdirectories for sourcefiles which defines a
* Contiki sensor. * Contiki sensor.
* *
* @param rootDirectory * @param rootDirectory
* Top directory to search in * Top directory to search in
* @return Sensor definitions found under rootDirectory, {sourcefile, * @return Sensor definitions found under rootDirectory, {sourcefile,
@ -1646,8 +1687,9 @@ public class ContikiMoteTypeDialog extends JDialog {
BufferedReader err = new BufferedReader(new InputStreamReader(p BufferedReader err = new BufferedReader(new InputStreamReader(p
.getErrorStream())); .getErrorStream()));
if (err.ready()) if (err.ready()) {
logger.warn("Error occured during scan:"); logger.warn("Error occured during scan:");
}
while ((line = err.readLine()) != null) { while ((line = err.readLine()) != null) {
logger.warn(line); logger.warn(line);
} }
@ -1665,7 +1707,7 @@ public class ContikiMoteTypeDialog extends JDialog {
/** /**
* Scans a directory and all subdirectories for sourcefiles which defines a * Scans a directory and all subdirectories for sourcefiles which defines a
* COOJA core interface. * COOJA core interface.
* *
* @param rootDirectory * @param rootDirectory
* Top directory to search in * Top directory to search in
* @return Core interface definitions found under rootDirectory, {sourcefile, * @return Core interface definitions found under rootDirectory, {sourcefile,
@ -1711,8 +1753,9 @@ public class ContikiMoteTypeDialog extends JDialog {
BufferedReader err = new BufferedReader(new InputStreamReader(p BufferedReader err = new BufferedReader(new InputStreamReader(p
.getErrorStream())); .getErrorStream()));
if (err.ready()) if (err.ready()) {
logger.warn("Error occured during scan:"); logger.warn("Error occured during scan:");
}
while ((line = err.readLine()) != null) { while ((line = err.readLine()) != null) {
logger.warn(line); logger.warn(line);
} }
@ -1730,7 +1773,7 @@ public class ContikiMoteTypeDialog extends JDialog {
/** /**
* Scans given file for an autostart expression and returns all process names * Scans given file for an autostart expression and returns all process names
* found. * found.
* *
* @param sourceFile * @param sourceFile
* Source file to scan * Source file to scan
* @return Autostart process names or null * @return Autostart process names or null
@ -1771,19 +1814,23 @@ public class ContikiMoteTypeDialog extends JDialog {
File sourceFile = new File(textCoreDir.getText(), sourceFilename); File sourceFile = new File(textCoreDir.getText(), sourceFilename);
boolean foundFile = sourceFile.exists(); boolean foundFile = sourceFile.exists();
if (!foundFile) if (!foundFile) {
for (File projectDir : myGUI.getProjectDirs()) { for (File projectDir : myGUI.getProjectDirs()) {
sourceFile = new File(projectDir, sourceFilename); sourceFile = new File(projectDir, sourceFilename);
if (foundFile = sourceFile.exists()) if (foundFile = sourceFile.exists()) {
break; break;
}
} }
}
if (!foundFile) if (!foundFile) {
for (File projectDir : moteTypeProjectDirs) { for (File projectDir : moteTypeProjectDirs) {
sourceFile = new File(projectDir, sourceFilename); sourceFile = new File(projectDir, sourceFilename);
if (foundFile = sourceFile.exists()) if (foundFile = sourceFile.exists()) {
break; break;
}
} }
}
if (!foundFile) { if (!foundFile) {
// Die quietly // Die quietly
@ -1968,11 +2015,11 @@ public class ContikiMoteTypeDialog extends JDialog {
* Scans Contiki base + (optional) project directories for Contiki processes, * Scans Contiki base + (optional) project directories for Contiki processes,
* sensors and core interfaces. The new mote type config is recreated every * sensors and core interfaces. The new mote type config is recreated every
* time this method is run. If any project directories are specified, it reads * time this method is run. If any project directories are specified, it reads
* the configuration files, and appends it to the new mote type config. * the configuration files, and appends it to the new mote type config.
* By reading those configs all available mote interfaces are parsed - * By reading those configs all available mote interfaces are parsed -
* which will all be selected initially. This method also selects the core * which will all be selected initially. This method also selects the core
* interfaces needed by the mote interfaces. * interfaces needed by the mote interfaces.
* *
* Finally any pre-specified processes (via shortcut start) will be selected. * Finally any pre-specified processes (via shortcut start) will be selected.
*/ */
private void rescanDirectories() { private void rescanDirectories() {
@ -2057,28 +2104,31 @@ public class ContikiMoteTypeDialog extends JDialog {
ActionListener, ActionListener,
DocumentListener { DocumentListener {
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
if (myDialog.isVisible()) if (myDialog.isVisible()) {
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
pathsWereUpdated(); pathsWereUpdated();
} }
}); });
}
} }
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
if (myDialog.isVisible()) if (myDialog.isVisible()) {
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
pathsWereUpdated(); pathsWereUpdated();
} }
}); });
}
} }
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
if (myDialog.isVisible()) if (myDialog.isVisible()) {
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
pathsWereUpdated(); pathsWereUpdated();
} }
}); });
}
} }
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("cancel")) { if (e.getActionCommand().equals("cancel")) {
@ -2090,8 +2140,9 @@ public class ContikiMoteTypeDialog extends JDialog {
File objectDir = ContikiMoteType.tempOutputDirectory; File objectDir = ContikiMoteType.tempOutputDirectory;
if (objectDir.exists() && objectDir.isDirectory()) { if (objectDir.exists() && objectDir.isDirectory()) {
File[] objectFiles = objectDir.listFiles(); File[] objectFiles = objectDir.listFiles();
for (File objectFile : objectFiles) for (File objectFile : objectFiles) {
objectFile.delete(); objectFile.delete();
}
objectDir.delete(); objectDir.delete();
} }
@ -2156,7 +2207,7 @@ public class ContikiMoteTypeDialog extends JDialog {
// Set "using symbols" // Set "using symbols"
myMoteType.setHasSystemSymbols(symbolsCheckBox.isSelected()); myMoteType.setHasSystemSymbols(symbolsCheckBox.isSelected());
// Set communication stack // Set communication stack
myMoteType.setCommunicationStack( myMoteType.setCommunicationStack(
(ContikiMoteType.CommunicationStack) commStackComboBox.getSelectedItem()); (ContikiMoteType.CommunicationStack) commStackComboBox.getSelectedItem());
@ -2189,10 +2240,11 @@ public class ContikiMoteTypeDialog extends JDialog {
moteTypeProjectDirs = newProjectDirs; moteTypeProjectDirs = newProjectDirs;
String projectDirText = null; String projectDirText = null;
for (File projectDir : newProjectDirs) { for (File projectDir : newProjectDirs) {
if (projectDirText == null) if (projectDirText == null) {
projectDirText = "'" + projectDir.getPath() + "'"; projectDirText = "'" + projectDir.getPath() + "'";
else } else {
projectDirText += " + '" + projectDir.getPath() + "'"; projectDirText += " + '" + projectDir.getPath() + "'";
}
} }
textProjectDirs.setText(projectDirText); textProjectDirs.setText(projectDirText);
@ -2431,13 +2483,15 @@ public class ContikiMoteTypeDialog extends JDialog {
} }
} }
if (!processWasSelected || sourceFilename == null) if (!processWasSelected || sourceFilename == null) {
return; return;
}
autoSelectDependencyProcesses(processName, sourceFilename, true); autoSelectDependencyProcesses(processName, sourceFilename, true);
} else } else {
logger.warn("Unhandled action: " + e.getActionCommand()); logger.warn("Unhandled action: " + e.getActionCommand());
}
createButton.setEnabled(libraryCreatedOK = false); createButton.setEnabled(libraryCreatedOK = false);