From 5672ee7f5cbf831a39765cb52ade591fd219f124 Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Thu, 7 Jun 2018 10:14:01 +0200
Subject: [PATCH] Some rework of RasPi generator supporting pre-installed
 libraries.

Signed-off-by: Florian Hoelzl <hoelzl@fortiss.org>
---
 .../raspberry/generator/extension/.ratings    |  2 +-
 .../RaspberryPIGeneratorExtension.java        | 49 +++++++++---------
 .../generator/extension/library/.ratings      |  5 +-
 .../BrickLibraryGeneratorExtensionBase.java   | 21 ++++++--
 .../PiHALLibraryGeneratorExtensionBase.java   | 21 ++++++--
 .../VescLibraryGeneratorExtensionBase.java    | 51 +++++++++++++++++++
 .../generator/extension/motorcontrol/.ratings |  4 +-
 .../MotorControlGeneratorExtensionBase.java   |  6 ++-
 .../MotorControlInputGeneratorExtension.java  | 16 ++++--
 .../raspberry/generator/framework/.ratings    | 10 ++--
 ...IPreinstalledHeaderGeneratorExtension.java | 28 ++++++++++
 ...PreinstalledLibraryGeneratorExtension.java | 33 ++++++++++++
 ...IRasPiCopiedHeaderGeneratorExtension.java} |  4 +-
 ...CopiedLibraryBasedGeneratorExtension.java} | 10 +++-
 ...iCopiedSourceBasedGeneratorExtension.java} |  5 +-
 .../IWriteableGeneratorExtension.java         |  6 +--
 16 files changed, 215 insertions(+), 56 deletions(-)
 create mode 100644 org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/VescLibraryGeneratorExtensionBase.java
 create mode 100644 org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IPreinstalledHeaderGeneratorExtension.java
 create mode 100644 org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IPreinstalledLibraryGeneratorExtension.java
 rename org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/{IRasPiHeaderGeneratorExtension.java => IRasPiCopiedHeaderGeneratorExtension.java} (90%)
 rename org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/{IRasPiLibraryBasedGeneratorExtension.java => IRasPiCopiedLibraryBasedGeneratorExtension.java} (83%)
 rename org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/{IRasPiSourceBasedGeneratorExtension.java => IRasPiCopiedSourceBasedGeneratorExtension.java} (90%)

diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/.ratings
index 3f66f2c4..b7df1d74 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/.ratings
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/.ratings
@@ -4,5 +4,5 @@ CanTransmissionCatalog.java 959d488ebec4ae6a50c3f699d42aad535b1ae0c3 YELLOW
 ConsoleOutputGeneratorExtension.java d57db44d57630a50e26c9eeed90d6631bf99db5d YELLOW
 MultiUnitMainGenerator.java 458754b89c2d79db3fee08baa444424772e40fb7 RED
 PWMActuatorGeneratorExtension.java 8cbfd72070cfc1c8a4da4ccc1d18a6b3e75cea7f YELLOW
-RaspberryPIGeneratorExtension.java 9822dd93e32d3287c1446eb94333d2ca55ff4274 RED
+RaspberryPIGeneratorExtension.java c81d5606099b3922c70aecd103b2a7269b90f0a6 RED
 SingleUnitMainGenerator.java 93d0370b01330ab023e02761df818d36fac42b0f RED
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/RaspberryPIGeneratorExtension.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/RaspberryPIGeneratorExtension.java
index 9822dd93..c81d5606 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/RaspberryPIGeneratorExtension.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/RaspberryPIGeneratorExtension.java
@@ -52,31 +52,23 @@ import org.fortiss.af3.platform.model.ExecutionUnit;
 import org.fortiss.af3.platform.model.PlatformConnectorUnit;
 import org.fortiss.af3.platform.model.TransmissionUnit;
 import org.fortiss.af3.platform.raspberry.AF3PlatformRaspberryActivator;
-import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiHeaderGeneratorExtension;
-import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiLibraryBasedGeneratorExtension;
-import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiSourceBasedGeneratorExtension;
+import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedHeaderGeneratorExtension;
+import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedLibraryBasedGeneratorExtension;
+import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedSourceBasedGeneratorExtension;
 import org.fortiss.af3.platform.raspberry.model.CanBus;
 import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
 import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
 import org.fortiss.tooling.kernel.extension.exception.ChainTransformationFailedException;
 
 /** {@link ExecutionUnitExecutableBase} for the {@link RaspberryPi} platform. */
-public class RaspberryPIGeneratorExtension extends ExecutionUnitExecutableBase<RaspberryPi, CSourcePackage> {
+public class RaspberryPIGeneratorExtension extends
+		ExecutionUnitExecutableBase<RaspberryPi, CSourcePackage> {
 	/** Folder name for library source files. */
 	private static final String SRC_LIB_SUB_PACKAGE_NAME = "src-lib";
 	/** Folder name for library include files. */
 	public static final String INC_LIB_SUB_PACKAGE_NAME = "inc-lib";
 	/** Folder name for linkable static library files. */
 	private static final String LIB_SUB_PACKAGE_NAME = "lib";
-	/** Default library names to be used always. */
-	// Note that the order is important (GCC linker crap!)
-	private static final String LIB_NAMES = "af3pihal rt pthread";
-	/** Default library names extended with brick. */
-	// Note that the order is important (GCC linker crap!)
-	private static final String LIB_NAMES_WITH_BRICK = "brick " + LIB_NAMES;
-	/** Default library names extended with vesc. */
-	// Note that the order is important (GCC linker crap!)
-	private static final String LIB_NAMES_WITH_VESC = LIB_NAMES_WITH_BRICK + " vesc";
 
 	// code generator input and intermediary data
 	/** The transformation context provided by the deployment generator framework. */
@@ -90,6 +82,12 @@ public class RaspberryPIGeneratorExtension extends ExecutionUnitExecutableBase<R
 	/** The map from platform elements to executables. */
 	private Map<PlatformConnectorUnit, ExecutableBase<?>> platformConnector2ExecutableBase =
 			new HashMap<>();
+	/** Set of headers to be included. */
+	private Set<String> includedHeaders = new HashSet<>();
+	/** Set of source files to be included. */
+	private Set<String> includedSources = new HashSet<>();
+	/** Set of libraries to be included. */
+	private List<String> includedLibraries = new ArrayList<String>();
 
 	// code generator output
 	/** The C source package produced by this generator. */
@@ -128,16 +126,14 @@ public class RaspberryPIGeneratorExtension extends ExecutionUnitExecutableBase<R
 	 */
 	private Set<String> addPlatformElementsCode(
 			List<Pair<PlatformConnectorUnit, Port>> deployedPorts) {
-		Set<String> includedHeaders = new HashSet<>();
-		Set<String> includedSources = new HashSet<>();
-		Set<String> includedLibraries = new HashSet<>();
 		for(Pair<PlatformConnectorUnit, Port> pair : deployedPorts) {
 			PlatformConnectorUnit pcu = pair.getFirst();
 			ExecutableBase<?> executable =
 					createTransformedObjectWithoutExceptionFor(pcu, ExecutableBase.class, context);
 			platformConnector2ExecutableBase.put(pcu, executable);
-			if(executable instanceof IRasPiHeaderGeneratorExtension) {
-				IRasPiHeaderGeneratorExtension headerExec = (IRasPiHeaderGeneratorExtension)executable;
+			if(executable instanceof IRasPiCopiedHeaderGeneratorExtension) {
+				IRasPiCopiedHeaderGeneratorExtension headerExec =
+						(IRasPiCopiedHeaderGeneratorExtension)executable;
 				if(!includedHeaders.contains(headerExec.getHeaderFileName())) {
 					generatorResult.getSubPackage(INC_LIB_SUB_PACKAGE_NAME).addUnit(
 							headerExec.getHeaderFileContent());
@@ -145,8 +141,9 @@ public class RaspberryPIGeneratorExtension extends ExecutionUnitExecutableBase<R
 				}
 				// ignore header file, since it is already included
 			}
-			if(executable instanceof IRasPiSourceBasedGeneratorExtension) {
-				IRasPiSourceBasedGeneratorExtension srcExec = (IRasPiSourceBasedGeneratorExtension)executable;
+			if(executable instanceof IRasPiCopiedSourceBasedGeneratorExtension) {
+				IRasPiCopiedSourceBasedGeneratorExtension srcExec =
+						(IRasPiCopiedSourceBasedGeneratorExtension)executable;
 				if(!includedSources.contains(srcExec.getSourceFileName())) {
 					generatorResult.getSubPackage(SRC_LIB_SUB_PACKAGE_NAME).addUnit(
 							srcExec.getSourceFileContent());
@@ -154,12 +151,14 @@ public class RaspberryPIGeneratorExtension extends ExecutionUnitExecutableBase<R
 				}
 				// ignore source file, since it is already included
 			}
-			if(executable instanceof IRasPiLibraryBasedGeneratorExtension) {
-				IRasPiLibraryBasedGeneratorExtension libExec = (IRasPiLibraryBasedGeneratorExtension)executable;
+			if(executable instanceof IRasPiCopiedLibraryBasedGeneratorExtension) {
+				IRasPiCopiedLibraryBasedGeneratorExtension libExec =
+						(IRasPiCopiedLibraryBasedGeneratorExtension)executable;
 				if(!includedLibraries.contains(libExec.getLibraryFileName())) {
 					generatorResult.getSubPackage(LIB_SUB_PACKAGE_NAME).addUnit(
 							libExec.getLibraryFileContent());
 					includedLibraries.add(libExec.getLibraryFileName());
+					includedLibraries.addAll(libExec.getDependencyLibraries());
 				}
 				// ignore library file, since it is already included
 			}
@@ -257,7 +256,11 @@ public class RaspberryPIGeneratorExtension extends ExecutionUnitExecutableBase<R
 
 	/** Adds the build process files: configure and Makedefs. */
 	private void addConfigureAndMakedefsFiles() {
-		generatorResult.addUnit(getConfigureFile(modelElement.getName(), LIB_NAMES_WITH_VESC));
+		StringBuilder sb = new StringBuilder();
+		for(String s : includedLibraries) {
+			sb.append(s).append(' ');
+		}
+		generatorResult.addUnit(getConfigureFile(modelElement.getName(), sb.toString()));
 		generatorResult.addUnit(getMakedefsFile());
 	}
 
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/.ratings
index cbbb5eae..28e361a9 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/.ratings
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/.ratings
@@ -1,2 +1,3 @@
-BrickLibraryGeneratorExtensionBase.java a02f7030ddcc539c8e48488e8e3c29858edaf1f7 YELLOW
-PiHALLibraryGeneratorExtensionBase.java 74752cafe6b83d8c00dc88945bf001507704022b YELLOW
+BrickLibraryGeneratorExtensionBase.java 2b22b7ef042ef6eced32f227fd4d682bab421722 YELLOW
+PiHALLibraryGeneratorExtensionBase.java d6678cf07b655b33844329dae89603d7827c63b1 YELLOW
+VescLibraryGeneratorExtensionBase.java 1227d3de77cab52a396b3d9751a6b43a8c373b31 YELLOW
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/BrickLibraryGeneratorExtensionBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/BrickLibraryGeneratorExtensionBase.java
index a02f7030..2b22b7ef 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/BrickLibraryGeneratorExtensionBase.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/BrickLibraryGeneratorExtensionBase.java
@@ -15,22 +15,26 @@
 +--------------------------------------------------------------------------*/
 package org.fortiss.af3.platform.raspberry.generator.extension.library;
 
+import static java.util.Arrays.asList;
 import static org.fortiss.af3.generator.common.utils.SourceModelElementFactory.createByteContentUnitForPluginFileInRCP;
 
+import java.util.List;
+
 import org.eclipse.emf.ecore.EObject;
 import org.fortiss.af3.generator.common.model.source.ByteContentUnit;
 import org.fortiss.af3.platform.language.executable.ExecutableBase;
 import org.fortiss.af3.platform.raspberry.AF3PlatformRaspberryActivator;
-import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiHeaderGeneratorExtension;
-import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiLibraryBasedGeneratorExtension;
+import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedHeaderGeneratorExtension;
+import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedLibraryBasedGeneratorExtension;
 
 /**
  * Base class for executables using the AF3 Pi HAL library.
  * 
  * @author hoelzl
  */
-public abstract class BrickLibraryGeneratorExtensionBase<T extends EObject> extends ExecutableBase<T>
-		implements IRasPiLibraryBasedGeneratorExtension, IRasPiHeaderGeneratorExtension {
+public abstract class BrickLibraryGeneratorExtensionBase<T extends EObject> extends
+		ExecutableBase<T> implements IRasPiCopiedLibraryBasedGeneratorExtension,
+		IRasPiCopiedHeaderGeneratorExtension {
 	/** Constructor. */
 	public BrickLibraryGeneratorExtensionBase(T modelElement) {
 		super(modelElement);
@@ -39,7 +43,14 @@ public abstract class BrickLibraryGeneratorExtensionBase<T extends EObject> exte
 	/** {@inheritDoc} */
 	@Override
 	public final String getLibraryFileName() {
-		return "libbrick.a";
+		return "brick";
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public List<String> getDependencyLibraries() {
+		// Note that the order is important (GCC linker crap!)
+		return asList("rt", "pthread");
 	}
 
 	/** {@inheritDoc} */
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/PiHALLibraryGeneratorExtensionBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/PiHALLibraryGeneratorExtensionBase.java
index 74752caf..d6678cf0 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/PiHALLibraryGeneratorExtensionBase.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/PiHALLibraryGeneratorExtensionBase.java
@@ -15,22 +15,26 @@
 +--------------------------------------------------------------------------*/
 package org.fortiss.af3.platform.raspberry.generator.extension.library;
 
+import static java.util.Arrays.asList;
 import static org.fortiss.af3.generator.common.utils.SourceModelElementFactory.createByteContentUnitForPluginFileInRCP;
 
+import java.util.List;
+
 import org.eclipse.emf.ecore.EObject;
 import org.fortiss.af3.generator.common.model.source.ByteContentUnit;
 import org.fortiss.af3.platform.language.executable.ExecutableBase;
 import org.fortiss.af3.platform.raspberry.AF3PlatformRaspberryActivator;
-import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiHeaderGeneratorExtension;
-import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiLibraryBasedGeneratorExtension;
+import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedHeaderGeneratorExtension;
+import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedLibraryBasedGeneratorExtension;
 
 /**
  * Base class for executables using the AF3 Pi HAL library.
  * 
  * @author hoelzl
  */
-public abstract class PiHALLibraryGeneratorExtensionBase<T extends EObject> extends ExecutableBase<T>
-		implements IRasPiLibraryBasedGeneratorExtension, IRasPiHeaderGeneratorExtension {
+public abstract class PiHALLibraryGeneratorExtensionBase<T extends EObject> extends
+		ExecutableBase<T> implements IRasPiCopiedLibraryBasedGeneratorExtension,
+		IRasPiCopiedHeaderGeneratorExtension {
 	/** Constructor. */
 	public PiHALLibraryGeneratorExtensionBase(T modelElement) {
 		super(modelElement);
@@ -39,7 +43,14 @@ public abstract class PiHALLibraryGeneratorExtensionBase<T extends EObject> exte
 	/** {@inheritDoc} */
 	@Override
 	public final String getLibraryFileName() {
-		return "libaf3pihal.a";
+		return "af3pihal";
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public List<String> getDependencyLibraries() {
+		// Note that the order is important (GCC linker crap!)
+		return asList("rt", "pthread");
 	}
 
 	/** {@inheritDoc} */
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/VescLibraryGeneratorExtensionBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/VescLibraryGeneratorExtensionBase.java
new file mode 100644
index 00000000..1227d3de
--- /dev/null
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/library/VescLibraryGeneratorExtensionBase.java
@@ -0,0 +1,51 @@
+/*-------------------------------------------------------------------------+
+| Copyright 2018 fortiss GmbH                                              |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.af3.platform.raspberry.generator.extension.library;
+
+import static java.util.Arrays.asList;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.fortiss.af3.platform.language.executable.ExecutableBase;
+import org.fortiss.af3.platform.raspberry.generator.framework.IPreinstalledHeaderGeneratorExtension;
+import org.fortiss.af3.platform.raspberry.generator.framework.IPreinstalledLibraryGeneratorExtension;
+
+/**
+ * Base class for executables using the Vesc library.
+ * 
+ * @author hoelzl
+ */
+public abstract class VescLibraryGeneratorExtensionBase<T extends EObject> extends
+		ExecutableBase<T> implements IPreinstalledLibraryGeneratorExtension,
+		IPreinstalledHeaderGeneratorExtension {
+	/** Constructor. */
+	public VescLibraryGeneratorExtensionBase(T modelElement) {
+		super(modelElement);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public String getHeaderIncludes() {
+		return "#include \"hal.h\"\n" + "#include \"commands.h\"\n";
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public List<String> getLibraryNames() {
+		return asList("vesc");
+	}
+}
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/.ratings
index 233f8d12..c0e60d56 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/.ratings
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/.ratings
@@ -1,3 +1,3 @@
-MotorControlGeneratorExtensionBase.java 3144ca92ff4dd5c7aff891c8a5e6df2a63d18e33 RED
-MotorControlInputGeneratorExtension.java 46e45f37f30b48fe50a7167799adaab015b8abd3 RED
+MotorControlGeneratorExtensionBase.java 3b62fdf7052bc212bc565c8b891fc3da0912b04b RED
+MotorControlInputGeneratorExtension.java fc4f86caf0867d5ec27e2db2461d2e6365eb2dd2 RED
 MotorControlOutputGeneratorExtension.java 9ab48031ad519db2aed2cab21c5219d6c8feeefb RED
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/MotorControlGeneratorExtensionBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/MotorControlGeneratorExtensionBase.java
index 3144ca92..3b62fdf7 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/MotorControlGeneratorExtensionBase.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/MotorControlGeneratorExtensionBase.java
@@ -24,8 +24,8 @@ import org.fortiss.af3.platform.raspberry.generator.framework.ISingletonInitiali
  * 
  * @author hoelzl
  */
-abstract class MotorControlGeneratorExtensionBase<T extends EObject> extends ExecutableBase<T> implements
-		ISingletonInitializationGeneratorExtension {
+abstract class MotorControlGeneratorExtensionBase<T extends EObject> extends ExecutableBase<T>
+		implements ISingletonInitializationGeneratorExtension {
 	/** Constructor. */
 	public MotorControlGeneratorExtensionBase(T modelElement) {
 		super(modelElement);
@@ -46,6 +46,8 @@ abstract class MotorControlGeneratorExtensionBase<T extends EObject> extends Exe
 	/** {@inheritDoc} */
 	@Override
 	public final String getSingletonAuxiliaryFunctions(String singletonPostfix) {
+		// return "extern void initUSB(char* device, int baudRate);\n"
+		// + "extern void uint8_t get_values();";
 		return null;
 	}
 
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/MotorControlInputGeneratorExtension.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/MotorControlInputGeneratorExtension.java
index 46e45f37..fc4f86ca 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/MotorControlInputGeneratorExtension.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/motorcontrol/MotorControlInputGeneratorExtension.java
@@ -15,17 +15,27 @@
 +--------------------------------------------------------------------------*/
 package org.fortiss.af3.platform.raspberry.generator.extension.motorcontrol;
 
-import org.fortiss.af3.platform.language.executable.ExecutableBase;
+import org.fortiss.af3.component.model.InputPort;
+import org.fortiss.af3.expression.model.terms.IExpressionTerm;
+import org.fortiss.af3.platform.language.executable.IReadableExecutable;
 import org.fortiss.af3.platform.raspberry.model.motorcontrol.MotorControlInput;
 
 /**
- * {@link ExecutableBase} for {@link MotorControlInput}.
+ * Generator extension for {@link MotorControlInput}.
  * 
  * @author hoelzl
  */
-public class MotorControlInputGeneratorExtension extends MotorControlGeneratorExtensionBase<MotorControlInput> {
+public class MotorControlInputGeneratorExtension extends
+		MotorControlGeneratorExtensionBase<MotorControlInput> implements IReadableExecutable {
 	/** Constructor. */
 	public MotorControlInputGeneratorExtension(MotorControlInput modelElement) {
 		super(modelElement);
 	}
+
+	/** {@inheritDoc} */
+	@Override
+	public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/.ratings
index a129066a..8072dbe7 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/.ratings
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/.ratings
@@ -1,11 +1,13 @@
 IInstanceGeneratorExtension.java 9d20878f9a1b9f82bd8f9f090bd989af1f08c8ab YELLOW
 IInstanceInitializationGeneratorExtension.java ae145d29cb2abbc492380c6af303a12fc2a0daa6 YELLOW
 IInstanceTerminationGeneratorExtension.java d9632d04207a484bbe46110ec5925c9850228f30 YELLOW
-IRasPiHeaderGeneratorExtension.java ba484bfa345f324e8998004868bb0a815ccc1ada YELLOW
-IRasPiLibraryBasedGeneratorExtension.java 7759d1510fa776727afaa3c38f881c2209dc97a2 YELLOW
-IRasPiSourceBasedGeneratorExtension.java 4aa645389a5f4538d7004ff7d6f6a29008bf29e7 YELLOW
+IPreinstalledHeaderGeneratorExtension.java 120c52d35969b35b5ff1ea50570401d5451ba221 YELLOW
+IPreinstalledLibraryGeneratorExtension.java 437fafdb45561b1acc6c54db2c43c39c48033280 YELLOW
+IRasPiCopiedHeaderGeneratorExtension.java 8c08db84c6dfe01b6eb242ea584f3765210fdc56 YELLOW
+IRasPiCopiedLibraryBasedGeneratorExtension.java edac836e2553f72a0487ac6455ae87d87d3f6aae YELLOW
+IRasPiCopiedSourceBasedGeneratorExtension.java 28e43319dab6ffb353c06be952b5671c3eb59164 YELLOW
 IReadableGeneratorExtension.java cb46973bf8d1635c9893f15d4c37a60c570b5377 YELLOW
 ISingletonGeneratorExtension.java c345a55893508b1707f0fbe3cebae7c761f3277d YELLOW
 ISingletonInitializationGeneratorExtension.java 50394cc39e0937785c093b7042f7b4a89027aa33 YELLOW
 ISingletonTerminationGeneratorExtension.java 5f15352e7343ca551b754f6259dd2324a16b55a8 YELLOW
-IWriteableGeneratorExtension.java dd4da2e4939a947d9ff343d94bb8e86a7f15439c YELLOW
+IWriteableGeneratorExtension.java b390c0116e7cf823f27c620950f94e7bc14545d4 YELLOW
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IPreinstalledHeaderGeneratorExtension.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IPreinstalledHeaderGeneratorExtension.java
new file mode 100644
index 00000000..120c52d3
--- /dev/null
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IPreinstalledHeaderGeneratorExtension.java
@@ -0,0 +1,28 @@
+/*-------------------------------------------------------------------------+
+| Copyright 2018 fortiss GmbH                                              |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.af3.platform.raspberry.generator.framework;
+
+/**
+ * Interface for generator extensions, which require one or more header files to be imported in the
+ * created main file. This is usually the case when the header files in question are pre-installed
+ * (e.g. C standard library headers).
+ * 
+ * @author hoelzl
+ */
+public interface IPreinstalledHeaderGeneratorExtension {
+	/** Returns the included header files. */
+	public String getHeaderIncludes();
+}
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IPreinstalledLibraryGeneratorExtension.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IPreinstalledLibraryGeneratorExtension.java
new file mode 100644
index 00000000..437fafdb
--- /dev/null
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IPreinstalledLibraryGeneratorExtension.java
@@ -0,0 +1,33 @@
+/*-------------------------------------------------------------------------+
+| Copyright 2018 fortiss GmbH                                              |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.af3.platform.raspberry.generator.framework;
+
+import java.util.List;
+
+/**
+ * Interface for generator extensions, which require one or more library files to be included during
+ * the linker pass. This is usually the case when the libraries in question are pre-installed
+ * (e.g. C standard libraries). Note that the generator will automatically add the "lib" prefix when
+ * necessary. Also the implementor is required to provide all library names including any
+ * dependencies: if {@code LibA} depends on {@code LibB} then returned list must be {@code LibA}
+ * followed by {@code LibB}, i.e., libraries must be included before libraries they depend on.
+ * 
+ * @author hoelzl
+ */
+public interface IPreinstalledLibraryGeneratorExtension {
+	/** Returns the list of library files. */
+	public List<String> getLibraryNames();
+}
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiHeaderGeneratorExtension.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiCopiedHeaderGeneratorExtension.java
similarity index 90%
rename from org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiHeaderGeneratorExtension.java
rename to org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiCopiedHeaderGeneratorExtension.java
index ba484bfa..8c08db84 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiHeaderGeneratorExtension.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiCopiedHeaderGeneratorExtension.java
@@ -18,11 +18,11 @@ package org.fortiss.af3.platform.raspberry.generator.framework;
 import org.fortiss.af3.generator.common.model.source.ByteContentUnit;
 
 /**
- * Interface for generator extensions, which require a header file to be included.
+ * Interface for generator extensions, which provide a header file to be copied to target directory.
  * 
  * @author hoelzl
  */
-public interface IRasPiHeaderGeneratorExtension {
+public interface IRasPiCopiedHeaderGeneratorExtension {
 	/** Returns the name of the header file required by this executable. */
 	String getHeaderFileName();
 
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiLibraryBasedGeneratorExtension.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiCopiedLibraryBasedGeneratorExtension.java
similarity index 83%
rename from org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiLibraryBasedGeneratorExtension.java
rename to org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiCopiedLibraryBasedGeneratorExtension.java
index 7759d151..edac836e 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiLibraryBasedGeneratorExtension.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiCopiedLibraryBasedGeneratorExtension.java
@@ -15,17 +15,23 @@
 +--------------------------------------------------------------------------*/
 package org.fortiss.af3.platform.raspberry.generator.framework;
 
+import java.util.List;
+
 import org.fortiss.af3.generator.common.model.source.ByteContentUnit;
 
 /**
- * Interface for generator extensions, which require a static library to be included.
+ * Interface for generator extensions, which provide a static library to be copied to the target
+ * folder.
  * 
  * @author hoelzl
  */
-public interface IRasPiLibraryBasedGeneratorExtension {
+public interface IRasPiCopiedLibraryBasedGeneratorExtension {
 	/** Returns the name of the library required by this executable. */
 	String getLibraryFileName();
 
+	/** Returns the list of libraries the copied library depends on. */
+	List<String> getDependencyLibraries();
+
 	/** Returns the library as {@link ByteContentUnit} binary. */
 	ByteContentUnit getLibraryFileContent();
 }
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiSourceBasedGeneratorExtension.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiCopiedSourceBasedGeneratorExtension.java
similarity index 90%
rename from org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiSourceBasedGeneratorExtension.java
rename to org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiCopiedSourceBasedGeneratorExtension.java
index 4aa64538..28e43319 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiSourceBasedGeneratorExtension.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IRasPiCopiedSourceBasedGeneratorExtension.java
@@ -18,11 +18,12 @@ package org.fortiss.af3.platform.raspberry.generator.framework;
 import org.fortiss.af3.generator.common.model.source.ByteContentUnit;
 
 /**
- * Interface for generator extensions, which require a source file to be included.
+ * Interface for generator extensions, which provide a source file to be copied to the target
+ * folder.
  * 
  * @author hoelzl
  */
-public interface IRasPiSourceBasedGeneratorExtension {
+public interface IRasPiCopiedSourceBasedGeneratorExtension {
 	/** Returns the name of the source file required by this executable. */
 	String getSourceFileName();
 
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IWriteableGeneratorExtension.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IWriteableGeneratorExtension.java
index dd4da2e4..b390c011 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IWriteableGeneratorExtension.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/framework/IWriteableGeneratorExtension.java
@@ -18,9 +18,9 @@ package org.fortiss.af3.platform.raspberry.generator.framework;
 import org.fortiss.af3.component.model.OutputPort;
 
 /**
- * Executable for platform elements that can be written (e.g. actuators and busses). Each method
- * is provided a value by the calling code generator, which should be used to obtain the
- * value to be written. Implementors are also provided a {@code postfix} and a
+ * Interface for generator extensions for platform elements that can be written (e.g. actuators and
+ * busses). Each method is provided a value by the calling code generator, which should be used to
+ * obtain the value to be written. Implementors are also provided a {@code postfix} and a
  * {@code singletonPostfix} if they also implement {@link IInstanceGeneratorExtension} and
  * {@link ISingletonGeneratorExtension}, respectively. The code generator also provides the deployed
  * {@link OutputPort} in case an implementor needs additional data from the model (e.g. the type of
-- 
GitLab