From 5b9982babf7fc9dc6f0cee8fd5bf79cedb005554 Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Tue, 10 Oct 2017 12:10:25 +0000
Subject: [PATCH] Fixed build scripts to properly call the linker with static
 libraries. refs 3079

---
 .../generator/executable/RaspberryPIExecutable.java    | 10 +++++++---
 .../raspberry/generator/templates/ConfigureFile.stg    |  8 ++++++--
 .../raspberry/generator/templates/MainFile.stg         |  2 ++
 .../raspberry/generator/templates/MakedefsFile.stg     |  5 +++--
 .../raspberry/generator/templates/RasPiCTemplates.java |  3 ++-
 5 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java
index 80041c8c..e3e3332f 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java
@@ -68,6 +68,9 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
 	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!
+	private static final String LIB_NAMES = "af3pihal rt pthread";
 
 	/** Constructor. */
 	public RaspberryPIExecutable(RaspberryPi modelElement) {
@@ -87,7 +90,7 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
 			addLogicalComponentCode(deployedComponents, context, sourcePackage);
 			addEclipseCProjectFiles(sourcePackage, modelElement.getName());
 			addStaticLibraries(sourcePackage);
-			addConfigureAndMakedefsFiles(sourcePackage, modelElement.getName());
+			addConfigureAndMakedefsFiles(sourcePackage, modelElement.getName(), LIB_NAMES);
 			addMainFile(sourcePackage, deployedComponents, deployedPorts, context);
 		} catch(Exception ex) {
 			error(AF3PlatformRaspberryActivator.getDefault(), ex.getMessage(), ex);
@@ -106,8 +109,9 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
 	}
 
 	/** Adds the build process files: configure and Makedefs. */
-	private void addConfigureAndMakedefsFiles(CSourcePackage sourcePackage, String binaryName) {
-		sourcePackage.addUnit(getConfigureFile(binaryName));
+	private void addConfigureAndMakedefsFiles(CSourcePackage sourcePackage, String binaryName,
+			String libNames) {
+		sourcePackage.addUnit(getConfigureFile(binaryName, libNames));
 		sourcePackage.addUnit(getMakedefsFile());
 	}
 
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/ConfigureFile.stg b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/ConfigureFile.stg
index 9357649f..a2dde566 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/ConfigureFile.stg
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/ConfigureFile.stg
@@ -1,6 +1,6 @@
 group ConfigureFile;
 
-ConfigureFile(UNIT_NAME) ::= <<
+ConfigureFile(UNIT_NAME, LIB_NAMES) ::= <<
 #!/bin/sh
 
 # The application's name.
@@ -9,9 +9,11 @@ APPL="$UNIT_NAME$";
 # The root path for this script.
 if [ -z "\$ROOT" ]; then ROOT="."; fi;
 
-# The include and source paths.
+# The include, source and library paths.
 IPATH=". inc-lib inc-gen inc";
 VPATH=". src-lib src-gen src";
+LPATH="lib";
+LIBS="$LIB_NAMES$";
 
 # The include file for common make definitions.
 MAKEDEFS="Makedefs";
@@ -46,6 +48,8 @@ echo ""
 echo "# The include and source paths."                                                    \>\> \$MF;
 echo "IPATH=\$IPATH"                                                                       \>\> \$MF;
 echo "VPATH=\$VPATH"                                                                       \>\> \$MF;
+echo "LPATH=\$LPATH"                                                                       \>\> \$MF;
+echo "LIBS=\$LIBS"                                                                       \>\> \$MF;
 echo ""                                                                                   \>\> \$MF;
 echo "# Include the common make definitions."                                             \>\> \$MF;
 echo "include \$MAKEDEFS"                                                                  \>\> \$MF;
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg
index 4eeca49f..b274e5ff 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg
@@ -43,6 +43,8 @@ static void worker() {
 	$WORKER_CODE$
 }
 
+int global_debug_print_level = DEBUG_PRINT_LEVEL_NONE;
+
 int main(int argc, char** argv) {
 	// initialize CAN interface with catalog implementation
 	can_catalog_initialize(can_device, $WAITING_SLEEPTIME_IN_MICROS$);
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MakedefsFile.stg b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MakedefsFile.stg
index 6d2f56de..a0bc6cbc 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MakedefsFile.stg
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MakedefsFile.stg
@@ -23,7 +23,8 @@ endif
 
 # The flags which are passed to the compiler and the linker.
 CCFLAGS+=-std=c99 -Wall -pedantic -c \${patsubst %,-I%,\${subst :, ,\${IPATH}}}
-LDFLAGS+=-std=c99 -Wall -pedantic
+LDFLAGS+=-std=c99 -Wall -pedantic \${patsubst %,-L%,\${subst :, ,\${LPATH}}} 
+LIBFLAGS=\${patsubst %,-l%,\${subst :, ,\${LIBS}}}
 
 # The default rules, i.e. the entry point.
 all: \${BPATH}
@@ -47,7 +48,7 @@ clean:
 # The rule for linking an application.
 \${BPATH}/%.run:
 	@echo "linking application '\${@}' ..."
-	@\${CROSSLD} \${LDFLAGS} -o \${@} \$(filter %.o %.a, \${^})
+	@\${CROSSLD} \${LDFLAGS} -o \${@} \$(filter %.o %.a, \${^}) \${LIBFLAGS}
 	
 # The rule to clean and remove generated Makefile
 mrproper: clean
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java
index 7eeb36d8..9e05e647 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java
@@ -66,9 +66,10 @@ public final class RasPiCTemplates {
 	}
 
 	/** Returns the 'configure' file used to create a Makefile. */
-	public static AbstractUnit getConfigureFile(String binaryName) {
+	public static AbstractUnit getConfigureFile(String binaryName, String libNames) {
 		StringTemplate template = makeTemplate("ConfigureFile.stg", "ConfigureFile");
 		template.setAttribute("UNIT_NAME", binaryName);
+		template.setAttribute("LIB_NAMES", libNames);
 		return createStaticContentSourceUnit("configure", template.toString(), true);
 	}
 
-- 
GitLab