From 40270306e0803d4396338310c955153c0deb9371 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 19 Jun 2014 19:49:47 +0200 Subject: [PATCH] Allow variants to define an initVariant() function that is called at startup. See #2080 --- app/src/processing/app/debug/Compiler.java | 33 ++++++++++++++-------- hardware/arduino/cores/arduino/main.cpp | 7 +++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 14a7377c3..919da722d 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -186,19 +186,28 @@ public class Compiler implements MessageConsumer { includePaths.remove(includePaths.size() - 1); } - // 3. compile the core, outputting .o files to and then - // collecting them into the core.a library file. + // 3. compile the core, outputting .o files to and then + // collecting them into the core.a library file. - sketch.setCompilingProgress(50); - includePaths.clear(); - includePaths.add(corePath); // include path for core only - if (variantPath != null) includePaths.add(variantPath); - List coreObjectFiles = - compileFiles(avrBasePath, buildPath, includePaths, - findFilesInPath(corePath, "S", true), - findFilesInPath(corePath, "c", true), - findFilesInPath(corePath, "cpp", true), - boardPreferences); + sketch.setCompilingProgress(50); + includePaths.clear(); + includePaths.add(corePath); // include path for core only + if (variantPath != null) + includePaths.add(variantPath); + List coreObjectFiles = compileFiles( // + avrBasePath, buildPath, includePaths, // + findFilesInPath(corePath, "S", true), // + findFilesInPath(corePath, "c", true), // + findFilesInPath(corePath, "cpp", true), // + boardPreferences); + + if (variantPath != null) + objectFiles.addAll(compileFiles( // + avrBasePath, buildPath, includePaths, // + findFilesInPath(variantPath, "S", true), // + findFilesInPath(variantPath, "c", true), // + findFilesInPath(variantPath, "cpp", true), // + boardPreferences)); String runtimeLibraryName = buildPath + File.separator + "core.a"; List baseCommandAR = new ArrayList(Arrays.asList(new String[] { diff --git a/hardware/arduino/cores/arduino/main.cpp b/hardware/arduino/cores/arduino/main.cpp index 0ad696215..091c365fc 100644 --- a/hardware/arduino/cores/arduino/main.cpp +++ b/hardware/arduino/cores/arduino/main.cpp @@ -19,10 +19,17 @@ #include +// Weak empty variant initialization function. +// May be redefined by variant files. +void initVariant() __attribute__((weak)); +void initVariant() { } + int main(void) { init(); + initVariant(); + #if defined(USBCON) USBDevice.attach(); #endif