From 3563089a91eee49275662fb5bacd507ad51db664 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 10 Nov 2010 13:11:43 +0000 Subject: [PATCH] reimplemented initial support for referencing contiki source files in cooja projects --- platform/cooja/Makefile.cooja | 5 +- .../cooja/contikimote/ContikiMoteType.java | 6 ++- .../se/sics/cooja/dialogs/CompileContiki.java | 54 ++++++++++++++++++- .../dialogs/ContikiMoteCompileDialog.java | 7 ++- 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/platform/cooja/Makefile.cooja b/platform/cooja/Makefile.cooja index 63592947b..b132184f5 100644 --- a/platform/cooja/Makefile.cooja +++ b/platform/cooja/Makefile.cooja @@ -1,4 +1,4 @@ -# $Id: Makefile.cooja,v 1.41 2010/06/11 15:17:26 fros4943 Exp $ +# $Id: Makefile.cooja,v 1.42 2010/11/10 13:11:43 fros4943 Exp $ ## The COOJA Simulator Contiki platform Makefile ## @@ -50,6 +50,9 @@ CONTIKI_APP_OBJ = $(CONTIKI_APP).co COOJA = $(CONTIKI)/platform/$(TARGET) CONTIKI_TARGET_DIRS = . dev lib sys cfs net +# (COOJA_SOURCEDIRS contains additional sources dirs set from simulator) +vpath %.c $(COOJA_SOURCEDIRS) + COOJA_BASE = simEnvChange.c cooja_mt.c cooja_mtarch.c rtimer-arch.c slip.c watchdog.c COOJA_INTFS = beep.c button-sensor.c ip.c leds-arch.c moteid.c \ diff --git a/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteType.java b/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteType.java index ebaf69d53..ce80fdce6 100644 --- a/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteType.java +++ b/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ContikiMoteType.java,v 1.43 2010/03/24 12:29:33 fros4943 Exp $ + * $Id: ContikiMoteType.java,v 1.44 2010/11/10 13:11:43 fros4943 Exp $ */ package se.sics.cooja.contikimote; @@ -295,6 +295,10 @@ public class ContikiMoteType implements MoteType { libFile, archiveFile, javaClassName); + CompileContiki.redefineCOOJASources( + this, + env + ); } catch (Exception e) { throw (MoteTypeCreationException) new MoteTypeCreationException( "Error when creating environment: " + e.getMessage()).initCause(e); diff --git a/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java b/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java index fbc374dd1..b9f904608 100644 --- a/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java +++ b/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: CompileContiki.java,v 1.6 2010/03/15 11:04:07 fros4943 Exp $ + * $Id: CompileContiki.java,v 1.7 2010/11/10 13:11:43 fros4943 Exp $ */ package se.sics.cooja.dialogs; @@ -49,6 +49,7 @@ import javax.swing.Action; import org.apache.log4j.Logger; import se.sics.cooja.GUI; +import se.sics.cooja.MoteType; import se.sics.cooja.MoteType.MoteTypeCreationException; import se.sics.cooja.contikimote.ContikiMoteType; @@ -450,6 +451,7 @@ public class CompileContiki { env.add(new String[] { "LIBNAME", identifier }); env.add(new String[] { "CLASSNAME", javaClass }); env.add(new String[] { "CONTIKI_APP", contikiAppNoExtension }); + env.add(new String[] { "COOJA_SOURCEDIRS", "" }); env.add(new String[] { "COOJA_SOURCEFILES", "" }); env.add(new String[] { "CC", GUI.getExternalToolsSetting("PATH_C_COMPILER") }); env.add(new String[] { "EXTRA_CC_ARGS", ccFlags }); @@ -463,4 +465,54 @@ public class CompileContiki { env.add(new String[] { "PATH", System.getenv("PATH") }); return env.toArray(new String[0][0]); } + + public static void redefineCOOJASources(MoteType moteType, String[][] env) { + if (moteType == null || env == null) { + return; + } + + /* Check whether cooja projects include additional sources */ + String[] coojaSources = moteType.getConfig().getStringArrayValue(ContikiMoteType.class, "C_SOURCES"); + if (coojaSources == null) { + return; + } + + String sources = ""; + String dirs = ""; + for (String s: coojaSources) { + if (s.trim().isEmpty()) { + continue; + } + File p = moteType.getConfig().getUserProjectDefining(ContikiMoteType.class, "C_SOURCES", s); + if (p == null) { + logger.warn("Project defining C_SOURCES$" + s + " not found"); + continue; + } + /* Redefine sources. TODO Move to createCompilationEnvironment. */ + sources += s + " "; + dirs += p.getPath() + " "; + + /* XXX Cygwin specific directory style */ + if (dirs.contains("C:\\")) { + dirs += p.getPath().replace("C:\\", "/cygdrive/c/") + " "; + } + } + + if (!sources.trim().isEmpty()) { + for (int i=0; i < env.length; i++) { + if (env[i][0].equals("COOJA_SOURCEFILES")) { + env[i][1] = sources; + break; + } + } + } + if (!dirs.trim().isEmpty()) { + for (int i=0; i < env.length; i++) { + if (env[i][0].equals("COOJA_SOURCEDIRS")) { + env[i][1] = dirs.replace("\\", "/"); + break; + } + } + } + } } diff --git a/tools/cooja/java/se/sics/cooja/dialogs/ContikiMoteCompileDialog.java b/tools/cooja/java/se/sics/cooja/dialogs/ContikiMoteCompileDialog.java index 3e4370f4e..d382e121e 100644 --- a/tools/cooja/java/se/sics/cooja/dialogs/ContikiMoteCompileDialog.java +++ b/tools/cooja/java/se/sics/cooja/dialogs/ContikiMoteCompileDialog.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ContikiMoteCompileDialog.java,v 1.7 2010/03/15 11:04:07 fros4943 Exp $ + * $Id: ContikiMoteCompileDialog.java,v 1.8 2010/11/10 13:11:43 fros4943 Exp $ */ package se.sics.cooja.dialogs; @@ -167,6 +167,11 @@ public class ContikiMoteCompileDialog extends AbstractCompileDialog { ((ContikiMoteType)moteType).archiveFile, ((ContikiMoteType)moteType).javaClassName ); + CompileContiki.redefineCOOJASources( + moteType, + env + ); + String[] envOneDimension = new String[env.length]; for (int i=0; i < env.length; i++) { envOneDimension[i] = env[i][0] + "=" + env[i][1];