From b63cf3bbdb0cd48b3e2846852204031034faa596 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Fri, 28 Nov 2014 14:43:58 +0100
Subject: [PATCH] Major C-code reshuffle.

---
 .gitignore                                    |  14 +-
 compiler/2006/Java_CodeGen.jrag               |  12 -
 compiler/2006/LabComm.java                    |   6 +-
 compiler/build.xml                            |  17 ++
 examples/simple/compile.sh                    |  15 +-
 examples/twoway/Makefile                      |   6 +-
 lib/Makefile                                  |   2 +-
 lib/c/2006/Makefile                           | 169 ++++++++++++
 lib/c/2006/labcomm2006.c                      |  55 ++--
 lib/c/2006/labcomm2006.h                      |   5 +-
 lib/c/2006/labcomm2006_compat_vxworks.h       |  19 +-
 lib/c/2006/labcomm2006_decoder.c              |  13 +-
 lib/c/2006/labcomm2006_default_memory.h       |   1 -
 .../2006/labcomm2006_dynamic_buffer_writer.c  |   4 +-
 lib/c/2006/labcomm2006_encoder.c              |   8 +-
 lib/c/2006/labcomm2006_fd_reader.c            |   2 +-
 lib/c/2006/labcomm2006_fd_writer.c            |   2 +-
 lib/c/2006/labcomm2006_private.h              | 102 +++-----
 lib/c/2006/labcomm2006_scheduler_private.h    |   7 +-
 lib/c/{ => 2006}/test/another_encoding.lc     |   0
 lib/c/2006/{ => test}/cppmacros.h             |   0
 lib/c/2006/test/generated_encoding.lc         |   7 +
 lib/c/{ => 2006}/test/labcomm_mem_reader.c    |   0
 lib/c/{ => 2006}/test/labcomm_mem_reader.h    |   0
 lib/c/{ => 2006}/test/labcomm_mem_writer.c    |   0
 lib/c/{ => 2006}/test/labcomm_mem_writer.h    |   0
 lib/c/{ => 2006}/test/more_types.lc           |   0
 lib/c/2006/test/test_labcomm.c                | 213 +++++++++++++++
 .../test/test_labcomm_basic_type_encoding.c   | 143 +++++++++++
 lib/c/2006/test/test_labcomm_copy.c           | 242 ++++++++++++++++++
 lib/c/{ => 2006}/test/test_labcomm_errors.c   |   0
 lib/c/{ => 2006}/test/test_labcomm_errors.h   |   0
 .../test/test_labcomm_generated_encoding.c    | 219 ++++++++++++++++
 .../test/test_labcomm_pthread_scheduler.c     |  82 ++++++
 lib/c/{ => 2006}/test/test_sample.lc          |   0
 lib/c/2006/test/test_signature_numbers.c      |  24 ++
 lib/c/2014/Makefile                           | 169 ++++++++++++
 .../experimental/ThrottleDrv/display.h        |   0
 .../experimental/ThrottleDrv/ethernet_drv.c   |   0
 .../experimental/ThrottleDrv/ethernet_drv.h   |   0
 .../experimental/ThrottleDrv/throttle_drv.c   |   0
 .../experimental/ThrottleDrv/throttle_drv.h   |   0
 lib/c/{ => 2014}/experimental/ethaddr.c       |   0
 lib/c/{ => 2014}/experimental/ethaddr.h       |   0
 .../experimental/labcomm_sig_parser.c         |   0
 .../experimental/labcomm_sig_parser.h         |   0
 .../experimental/labcomm_thr_reader_writer.c  |   0
 .../experimental/labcomm_thr_reader_writer.h  |   0
 .../experimental/labcomm_udp_reader_writer.c  |   0
 .../experimental/labcomm_udp_reader_writer.h  |   0
 lib/c/{ => 2014}/experimental/pack.c          |   0
 .../{ => 2014}/experimental/test_sig_parser.c |   0
 .../experimental/throttlenet/throttlenet.lc   |   0
 lib/c/{ => 2014}/experimental/udp_hack.c      |   0
 lib/c/{ => 2014}/experimental/udp_hack.h      |   0
 lib/c/{ => 2014}/labcomm.c                    |   4 +-
 lib/c/{ => 2014}/labcomm.h                    |   2 +-
 .../{ => 2014}/labcomm_compat_arm_cortexm3.h  |   0
 lib/c/{ => 2014}/labcomm_compat_osx.h         |   0
 lib/c/{ => 2014}/labcomm_compat_vxworks.h     |   0
 lib/c/{ => 2014}/labcomm_decoder.c            |   2 +-
 .../labcomm_default_error_handler.c           |   0
 .../labcomm_default_error_handler.h           |   0
 lib/c/{ => 2014}/labcomm_default_memory.c     |   0
 lib/c/{ => 2014}/labcomm_default_memory.h     |   0
 lib/c/{ => 2014}/labcomm_default_scheduler.c  |   0
 lib/c/{ => 2014}/labcomm_default_scheduler.h  |   0
 .../labcomm_dynamic_buffer_writer.c           |   0
 .../labcomm_dynamic_buffer_writer.h           |   0
 lib/c/{ => 2014}/labcomm_encoder.c            |   0
 lib/c/{ => 2014}/labcomm_error.c              |   0
 lib/c/{ => 2014}/labcomm_error.h              |   0
 lib/c/{ => 2014}/labcomm_fd_reader.c          |   0
 lib/c/{ => 2014}/labcomm_fd_reader.h          |   0
 lib/c/{ => 2014}/labcomm_fd_writer.c          |   0
 lib/c/{ => 2014}/labcomm_fd_writer.h          |   0
 lib/c/{ => 2014}/labcomm_ioctl.h              |   0
 lib/c/{ => 2014}/labcomm_memory.c             |   0
 lib/c/{ => 2014}/labcomm_private.h            |   2 +-
 lib/c/{ => 2014}/labcomm_pthread_scheduler.c  |   0
 lib/c/{ => 2014}/labcomm_pthread_scheduler.h  |   0
 lib/c/{ => 2014}/labcomm_scheduler.c          |   0
 lib/c/{ => 2014}/labcomm_scheduler.h          |   0
 lib/c/{ => 2014}/labcomm_scheduler_private.h  |   0
 lib/c/{ => 2014}/labcomm_time.c               |   0
 lib/c/2014/test/another_encoding.lc           |   2 +
 lib/c/{ => 2014/test}/cppmacros.h             |   0
 lib/c/{ => 2014}/test/generated_encoding.lc   |   0
 lib/c/2014/test/labcomm_mem_reader.c          |  80 ++++++
 lib/c/2014/test/labcomm_mem_reader.h          |  19 ++
 lib/c/2014/test/labcomm_mem_writer.c          | 146 +++++++++++
 lib/c/2014/test/labcomm_mem_writer.h          |  25 ++
 lib/c/2014/test/more_types.lc                 |   7 +
 lib/c/{ => 2014}/test/test_labcomm.c          |   0
 .../test/test_labcomm_basic_type_encoding.c   |   0
 lib/c/{ => 2014}/test/test_labcomm_copy.c     |   0
 lib/c/2014/test/test_labcomm_errors.c         | 173 +++++++++++++
 lib/c/2014/test/test_labcomm_errors.h         |   6 +
 .../test/test_labcomm_generated_encoding.c    |   0
 .../test/test_labcomm_pthread_scheduler.c     |   0
 lib/c/2014/test/test_sample.lc                |   1 +
 .../{ => 2014}/test/test_signature_numbers.c  |   0
 lib/c/Makefile                                | 175 +------------
 lib/c/labcomm.linkscript                      |  12 -
 lib/c/liblabcomm.so                           |   1 -
 lib/c/os_compat.mk                            |  20 +-
 lib/c/version_compare.py                      |  55 ++++
 test/Makefile                                 |   4 +-
 108 files changed, 1950 insertions(+), 344 deletions(-)
 create mode 100644 lib/c/2006/Makefile
 rename lib/c/{ => 2006}/test/another_encoding.lc (100%)
 rename lib/c/2006/{ => test}/cppmacros.h (100%)
 create mode 100644 lib/c/2006/test/generated_encoding.lc
 rename lib/c/{ => 2006}/test/labcomm_mem_reader.c (100%)
 rename lib/c/{ => 2006}/test/labcomm_mem_reader.h (100%)
 rename lib/c/{ => 2006}/test/labcomm_mem_writer.c (100%)
 rename lib/c/{ => 2006}/test/labcomm_mem_writer.h (100%)
 rename lib/c/{ => 2006}/test/more_types.lc (100%)
 create mode 100644 lib/c/2006/test/test_labcomm.c
 create mode 100644 lib/c/2006/test/test_labcomm_basic_type_encoding.c
 create mode 100644 lib/c/2006/test/test_labcomm_copy.c
 rename lib/c/{ => 2006}/test/test_labcomm_errors.c (100%)
 rename lib/c/{ => 2006}/test/test_labcomm_errors.h (100%)
 create mode 100644 lib/c/2006/test/test_labcomm_generated_encoding.c
 create mode 100644 lib/c/2006/test/test_labcomm_pthread_scheduler.c
 rename lib/c/{ => 2006}/test/test_sample.lc (100%)
 create mode 100644 lib/c/2006/test/test_signature_numbers.c
 create mode 100644 lib/c/2014/Makefile
 rename lib/c/{ => 2014}/experimental/ThrottleDrv/display.h (100%)
 rename lib/c/{ => 2014}/experimental/ThrottleDrv/ethernet_drv.c (100%)
 rename lib/c/{ => 2014}/experimental/ThrottleDrv/ethernet_drv.h (100%)
 rename lib/c/{ => 2014}/experimental/ThrottleDrv/throttle_drv.c (100%)
 rename lib/c/{ => 2014}/experimental/ThrottleDrv/throttle_drv.h (100%)
 rename lib/c/{ => 2014}/experimental/ethaddr.c (100%)
 rename lib/c/{ => 2014}/experimental/ethaddr.h (100%)
 rename lib/c/{ => 2014}/experimental/labcomm_sig_parser.c (100%)
 rename lib/c/{ => 2014}/experimental/labcomm_sig_parser.h (100%)
 rename lib/c/{ => 2014}/experimental/labcomm_thr_reader_writer.c (100%)
 rename lib/c/{ => 2014}/experimental/labcomm_thr_reader_writer.h (100%)
 rename lib/c/{ => 2014}/experimental/labcomm_udp_reader_writer.c (100%)
 rename lib/c/{ => 2014}/experimental/labcomm_udp_reader_writer.h (100%)
 rename lib/c/{ => 2014}/experimental/pack.c (100%)
 rename lib/c/{ => 2014}/experimental/test_sig_parser.c (100%)
 rename lib/c/{ => 2014}/experimental/throttlenet/throttlenet.lc (100%)
 rename lib/c/{ => 2014}/experimental/udp_hack.c (100%)
 rename lib/c/{ => 2014}/experimental/udp_hack.h (100%)
 rename lib/c/{ => 2014}/labcomm.c (98%)
 rename lib/c/{ => 2014}/labcomm.h (98%)
 rename lib/c/{ => 2014}/labcomm_compat_arm_cortexm3.h (100%)
 rename lib/c/{ => 2014}/labcomm_compat_osx.h (100%)
 rename lib/c/{ => 2014}/labcomm_compat_vxworks.h (100%)
 rename lib/c/{ => 2014}/labcomm_decoder.c (99%)
 rename lib/c/{ => 2014}/labcomm_default_error_handler.c (100%)
 rename lib/c/{ => 2014}/labcomm_default_error_handler.h (100%)
 rename lib/c/{ => 2014}/labcomm_default_memory.c (100%)
 rename lib/c/{ => 2014}/labcomm_default_memory.h (100%)
 rename lib/c/{ => 2014}/labcomm_default_scheduler.c (100%)
 rename lib/c/{ => 2014}/labcomm_default_scheduler.h (100%)
 rename lib/c/{ => 2014}/labcomm_dynamic_buffer_writer.c (100%)
 rename lib/c/{ => 2014}/labcomm_dynamic_buffer_writer.h (100%)
 rename lib/c/{ => 2014}/labcomm_encoder.c (100%)
 rename lib/c/{ => 2014}/labcomm_error.c (100%)
 rename lib/c/{ => 2014}/labcomm_error.h (100%)
 rename lib/c/{ => 2014}/labcomm_fd_reader.c (100%)
 rename lib/c/{ => 2014}/labcomm_fd_reader.h (100%)
 rename lib/c/{ => 2014}/labcomm_fd_writer.c (100%)
 rename lib/c/{ => 2014}/labcomm_fd_writer.h (100%)
 rename lib/c/{ => 2014}/labcomm_ioctl.h (100%)
 rename lib/c/{ => 2014}/labcomm_memory.c (100%)
 rename lib/c/{ => 2014}/labcomm_private.h (99%)
 rename lib/c/{ => 2014}/labcomm_pthread_scheduler.c (100%)
 rename lib/c/{ => 2014}/labcomm_pthread_scheduler.h (100%)
 rename lib/c/{ => 2014}/labcomm_scheduler.c (100%)
 rename lib/c/{ => 2014}/labcomm_scheduler.h (100%)
 rename lib/c/{ => 2014}/labcomm_scheduler_private.h (100%)
 rename lib/c/{ => 2014}/labcomm_time.c (100%)
 create mode 100644 lib/c/2014/test/another_encoding.lc
 rename lib/c/{ => 2014/test}/cppmacros.h (100%)
 rename lib/c/{ => 2014}/test/generated_encoding.lc (100%)
 create mode 100644 lib/c/2014/test/labcomm_mem_reader.c
 create mode 100644 lib/c/2014/test/labcomm_mem_reader.h
 create mode 100644 lib/c/2014/test/labcomm_mem_writer.c
 create mode 100644 lib/c/2014/test/labcomm_mem_writer.h
 create mode 100644 lib/c/2014/test/more_types.lc
 rename lib/c/{ => 2014}/test/test_labcomm.c (100%)
 rename lib/c/{ => 2014}/test/test_labcomm_basic_type_encoding.c (100%)
 rename lib/c/{ => 2014}/test/test_labcomm_copy.c (100%)
 create mode 100644 lib/c/2014/test/test_labcomm_errors.c
 create mode 100644 lib/c/2014/test/test_labcomm_errors.h
 rename lib/c/{ => 2014}/test/test_labcomm_generated_encoding.c (100%)
 rename lib/c/{ => 2014}/test/test_labcomm_pthread_scheduler.c (100%)
 create mode 100644 lib/c/2014/test/test_sample.lc
 rename lib/c/{ => 2014}/test/test_signature_numbers.c (100%)
 delete mode 100644 lib/c/labcomm.linkscript
 delete mode 120000 lib/c/liblabcomm.so
 create mode 100755 lib/c/version_compare.py

diff --git a/.gitignore b/.gitignore
index 24cebf1..e3dfb09 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,14 +10,16 @@ lib/c/liblabcomm2006.a
 lib/c/liblabcomm2014.so.1
 lib/c/liblabcomm2014.so
 lib/c/liblabcomm2014.a
-lib/c/test/test_labcomm
-lib/c/test/test_labcomm_basic_type_encoding
-lib/c/test/test_labcomm_copy
-lib/c/test/test_labcomm_generated_encoding
-lib/c/test/test_labcomm_pthread_scheduler
-lib/c/test/test_signature_numbers
+lib/c/20*/test/test_labcomm
+lib/c/20*/test/test_labcomm_basic_type_encoding
+lib/c/20*/test/test_labcomm_copy
+lib/c/20*/test/test_labcomm_generated_encoding
+lib/c/20*/test/test_labcomm_pthread_scheduler
+lib/c/20*/test/test_signature_numbers
 compiler/AST/
 compiler/labcomm_compiler.jar
+compiler/labcomm2006_compiler.jar
+compiler/labcomm2014_compiler.jar
 encoded_data
 encoded_data06
 gen
diff --git a/compiler/2006/Java_CodeGen.jrag b/compiler/2006/Java_CodeGen.jrag
index 478a0ac..0a1ac1f 100644
--- a/compiler/2006/Java_CodeGen.jrag
+++ b/compiler/2006/Java_CodeGen.jrag
@@ -339,11 +339,6 @@ aspect Java_Class {
     env.println("e.register(dispatcher);");
     env.unindent();
     env.println("}");
-    env.println("public static void registerSampleRef(Encoder e) throws IOException{");
-    env.indent();
-    env.println("e.registerSampleRef(dispatcher);");
-    env.unindent();
-    env.println("}");
     env.println();
   }
 
@@ -435,11 +430,6 @@ aspect Java_Class {
     env.println("d.register(dispatcher, h);");
     env.unindent();
     env.println("}");
-    env.println("public static void registerSampleRef(Decoder d) throws IOException {");
-    env.indent();
-    env.println("d.registerSampleRef(dispatcher);");
-    env.unindent();
-    env.println("}");
     env.println();
 
 
@@ -652,7 +642,6 @@ aspect Java_Class {
       case LABCOMM_FLOAT: { env.print("e.encodeFloat"); } break;
       case LABCOMM_DOUBLE: { env.print("e.encodeDouble"); } break;
       case LABCOMM_STRING: { env.print("e.encodeString"); } break;
-      case LABCOMM_SAMPLE: { env.print("e.encodeSampleRef"); } break;
     }
     env.println("(" + name + ");");
   }
@@ -743,7 +732,6 @@ aspect Java_Class {
       case LABCOMM_FLOAT: { env.println("d.decodeFloat();"); } break;
       case LABCOMM_DOUBLE: { env.println("d.decodeDouble();"); } break;
       case LABCOMM_STRING: { env.println("d.decodeString();"); } break;
-      case LABCOMM_SAMPLE: { env.println("d.decodeSampleRef();"); } break;
     }
   }
 
diff --git a/compiler/2006/LabComm.java b/compiler/2006/LabComm.java
index 58234a5..04ade97 100644
--- a/compiler/2006/LabComm.java
+++ b/compiler/2006/LabComm.java
@@ -127,7 +127,7 @@ public class LabComm {
     String coreName = null;
     String prefix = null;
     boolean verbose = false;
-    int ver = 2013; //Version 2013 as default
+    int ver = 2006; // Version 2006 fixed
     String cFile = null;
     String hFile = null;
     Vector cIncludes = new Vector();
@@ -192,8 +192,8 @@ public class LabComm {
         } else if (args[i].equals("-v")) {
   	verbose=true;
         } else if (args[i].startsWith("--ver=")) {
-          ver = Integer.parseInt(args[i].substring(6));
-          checkVersion(ver);
+          /* ver = Integer.parseInt(args[i].substring(6));
+             checkVersion(ver); */
         } else if (args[i].equals("-C")) {
   	cFile = coreName + ".c";
   	hFile = coreName + ".h";
diff --git a/compiler/build.xml b/compiler/build.xml
index 32c5448..492a7f1 100644
--- a/compiler/build.xml
+++ b/compiler/build.xml
@@ -53,8 +53,25 @@
   <delete dir="${package}"/>
 </target>
 
+<target name="jar_version" depends="build">
+  <jar destfile="labcomm${version}_compiler.jar">
+    <fileset dir="gen" 
+             includes="se/lth/control/labcomm${version}/compiler/*.class"/>
+    <zipfileset src="tools/beaver-rt.jar" includes="beaver/*.class"/>
+    <manifest>
+      <attribute name="Main-Class" 
+                 value="se.lth.control.labcomm${version}.compiler.LabComm"/>
+    </manifest>
+  </jar>
+</target>
 
 <target name="jar" depends="build">
+  <antcall target="jar_version">
+    <param name="version" value="2006"/>
+  </antcall>
+  <antcall target="jar_version">
+    <param name="version" value="2014"/>
+  </antcall>
   <jar destfile="labcomm_compiler.jar">
     <fileset dir="gen" includes="**/*.class"/>
     <zipfileset src="tools/beaver-rt.jar" includes="beaver/*.class"/>
diff --git a/examples/simple/compile.sh b/examples/simple/compile.sh
index 61c171d..91c3b76 100644
--- a/examples/simple/compile.sh
+++ b/examples/simple/compile.sh
@@ -1,3 +1,6 @@
+#!/bin/sh
+set -x
+set -e
 ### Example compile script, showing the steps required to build a labcomm application
 ### (including compiler and libs). Also illustrates how versions 2013 and 2006 coexist
 
@@ -10,12 +13,12 @@ java -jar ../../compiler/labcomm_compiler.jar --java=gen --c=gen/simple.c --h=ge
 javac -cp ../../lib/java/labcomm2014.jar:. gen/*.java Encoder.java Decoder.java
 
 gcc -Wall -Werror -Wno-unused-function \
-    -I. -I../../lib/c -L../../lib/c \
+    -I. -I../../lib/c/2014 -L../../lib/c \
     -o example_encoder example_encoder.c gen/simple.c \
-    -llabcomm2014 -Tlabcomm.linkscript
-gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
+    -llabcomm2014 
+gcc -Wall -Werror -I . -I ../../lib/c/2014 -L../../lib/c \
     -o example_decoder example_decoder.c gen/simple.c \
-    -llabcomm2014 -Tlabcomm.linkscript
+    -llabcomm2014 
 
 # For version 2006
 
@@ -26,10 +29,10 @@ javac -cp ../../lib/java/labcomm2006.jar:. gen06/*.java Encoder06.java Decoder06
 
 gcc -Wall -Werror -I.  -I../../lib/c/2006 -L../../lib/c \
     -o example_encoder06 example_encoder06.c gen06/simple.c \
-    -llabcomm -Tlabcomm.linkscript
+    -llabcomm2006
 gcc -Wall -Werror -I . -I ../../lib/c/2006 -L../../lib/c \
     -o example_decoder06 example_decoder06.c gen06/simple.c \
-    -llabcomm -Tlabcomm.linkscript
+    -llabcomm2006 
 
 #gcc -o example_encoder -I . -I ../../lib/c example_encoder.c gen/simple.c ../../lib/c/labcomm.c ../../lib/c/labcomm_fd_reader_writer.c
 
diff --git a/examples/twoway/Makefile b/examples/twoway/Makefile
index 6c34928..5a686f1 100644
--- a/examples/twoway/Makefile
+++ b/examples/twoway/Makefile
@@ -2,7 +2,7 @@ TARGETS=client server
 LABCOMM_JAR=../../compiler/labcomm_compiler.jar
 LABCOMM=java -jar $(LABCOMM_JAR) 
 
-CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I. -Wno-unused-function
+CFLAGS=-O3 -g -Wall -Werror -I../../lib/c/2014 -I. -Wno-unused-function
 
 all: $(TARGETS:%=gen/%)
 
@@ -26,11 +26,11 @@ gen/%.c gen/%.h: %.lc | gen/.dir
 
 gen/client: client.c 
 	$(CC) -o $@ $(CFLAGS) $^ -lpthread \
-		-L../../lib/c -llabcomm 
+		-L../../lib/c -llabcomm2014
 
 gen/server: server.c 
 	$(CC) -o $@ $(CFLAGS) $^ -lpthread \
-		-L../../lib/c -llabcomm 
+		-L../../lib/c -llabcomm2014 
 
 .PHONY: clean distclean
 clean distclean:
diff --git a/lib/Makefile b/lib/Makefile
index 8f5b6da..5a16cab 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -4,7 +4,7 @@ all:
 	cd java ; make
 
 test:
-	$(MAKE) -C c -e run-test
+	$(MAKE) -C c test
 
 clean:
 	cd c ; make clean
diff --git a/lib/c/2006/Makefile b/lib/c/2006/Makefile
new file mode 100644
index 0000000..1fbd2fe
--- /dev/null
+++ b/lib/c/2006/Makefile
@@ -0,0 +1,169 @@
+## Macros
+VERSION=2006
+LIBVERSION=2006
+
+include ../os_compat.mk
+
+ALL_DEPS=../liblabcomm$(LIBVERSION).a ../liblabcomm$(LIBVERSION).so.1
+
+# TODO: Support for Codesourcery ARM toolchain.
+
+OBJS=labcomm$(VERSION).o \
+     labcomm$(VERSION)_memory.o \
+     labcomm$(VERSION)_error.o \
+     labcomm$(VERSION)_default_error_handler.o \
+     labcomm$(VERSION)_default_memory.o \
+     labcomm$(VERSION)_default_scheduler.o \
+     labcomm$(VERSION)_time.o \
+     labcomm$(VERSION)_scheduler.o \
+     labcomm$(VERSION)_encoder.o \
+     labcomm$(VERSION)_decoder.o \
+     labcomm$(VERSION)_dynamic_buffer_writer.o \
+     labcomm$(VERSION)_fd_reader.o \
+     labcomm$(VERSION)_fd_writer.o \
+     labcomm$(VERSION)_pthread_scheduler.o 
+
+LABCOMM_JAR=../../../compiler/labcomm$(VERSION)_compiler.jar
+LABCOMM=java -jar $(LABCOMM_JAR) 
+
+TESTS=test_labcomm_basic_type_encoding \
+      test_labcomm_generated_encoding \
+      test_signature_numbers \
+      test_labcomm \
+      test_labcomm_pthread_scheduler \
+      test_labcomm_copy
+#FIXME: test_labcomm_errors
+
+TEST_DIR=test
+
+#VPATH=$(TEST_DIR)
+
+## Targets
+
+.PHONY: all 
+all: $(ALL_DEPS)
+
+.PHONY: test 
+test: all $(TESTS:%=run-test-%)
+
+.PHONY: clean 
+clean:
+	$(RM) *.o
+	$(RM) experimental/*.o 
+	$(RM) experimental/ThrottleDrv/*.o
+	$(RM) test/*.o
+	$(RM) test/*.gch
+	$(RM) test/test_labcomm_errors
+	$(RM) test/testdata/gen/*.[cho]
+	$(RM) test/gen/*.[cho]
+	$(RM) -rf test/gen
+	for x in $(TESTS); do \
+		$(RM) $(TEST_DIR)/$$x ; \
+	done
+
+.PHONY: distclean
+distclean: clean
+	$(RM) ../liblabcomm$(LIBVERSION).so.1
+	$(RM) ../liblabcomm$(LIBVERSION).a
+
+# rules invoked by 'all'
+../liblabcomm$(LIBVERSION).so.1: $(OBJS:%.o=%.pic.o)
+	$(call MAKESHARED,$@,$@,$^)
+
+../liblabcomm$(LIBVERSION).a: $(OBJS)
+	ar -r $@ $^
+
+# compilation rules 
+%.pic.o: %.c
+	$(CC) -fPIC $(CFLAGS) -c -o $@ $<
+
+%.o: %.c %.h
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+
+# rules invoked by 'test'
+.PHONY: run-test-%
+run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen
+	$<
+
+$(TEST_DIR)/gen/%: $(TEST_DIR)/gen/%.o | $(TEST_DIR)/gen
+	$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) 
+
+$(TEST_DIR)/gen/%.o: $(TEST_DIR)/%.c | $(TEST_DIR)/gen
+	$(CC) $(CFLAGS_TEST) -o $@ -c $<
+
+# Extra compilation dependencies
+labcomm_fd_reader.o: \
+	labcomm_private.h
+labcomm_fd_writer.o: \
+	labcomm_private.h
+labcomm_dynamic_buffer_writer.o: \
+	labcomm_private.h
+
+labcomm$(VERSION).o: \
+	labcomm$(VERSION).c \
+	labcomm$(VERSION).h \
+	labcomm$(VERSION)_private.h
+
+labcomm$(VERSION)_fd_reader_writer.o: \
+	labcomm$(VERSION)_fd_reader_writer.c \
+	labcomm$(VERSION)_fd_reader_writer.h  \
+	labcomm$(VERSION).h \
+	labcomm$(VERSION)_private.h
+
+$(TEST_DIR)/gen/test_labcomm_basic_type_encoding.o: \
+	labcomm$(VERSION)_private.h
+
+$(TEST_DIR)/gen/test_labcomm_generated_encoding.o: \
+	labcomm$(VERSION)_private.h \
+	$(TEST_DIR)/gen/generated_encoding.h
+
+$(TEST_DIR)/gen/test_labcomm_generated_encoding: \
+	$(TEST_DIR)/gen/generated_encoding.o
+
+$(TEST_DIR)/gen/test_signature_numbers.c: \
+	$(TEST_DIR)/gen/another_encoding.h \
+	$(TEST_DIR)/gen/generated_encoding.h				
+
+$(TEST_DIR)/gen/test_signature_numbers: \
+	$(TEST_DIR)/gen/another_encoding.o \
+	$(TEST_DIR)/gen/generated_encoding.o
+
+$(TEST_DIR)/gen/test_labcomm:  \
+	$(TEST_DIR)/gen/test_sample.o
+
+$(TEST_DIR)/gen/test_labcomm_copy: \
+	$(TEST_DIR)/gen/generated_encoding.o \
+	$(TEST_DIR)/gen/test_sample.o \
+	$(TEST_DIR)/gen/more_types.o
+
+#$(TEST_DIR)/labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h
+
+#$(TEST_DIR)/labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h
+
+ethaddr.o: ethaddr.c
+
+.PRECIOUS: $(TEST_DIR)/%
+
+$(TEST_DIR)/gen:
+	mkdir -p $@
+
+.PRECIOUS: $(TEST_DIR)/gen/%.c
+.PRECIOUS: $(TEST_DIR)/gen/%.h
+$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
+	$(LABCOMM) \
+		--c=$(TEST_DIR)/gen/$*.c \
+		--h=$(TEST_DIR)/gen/$*.h \
+		$<
+
+$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
+					 $(LABCOMM_JAR) | $(TEST_GEN_DIR)
+	$(LABCOMM) \
+		--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
+
+$(LABCOMM_JAR):
+	@echo "======Building LabComm compiler======"
+	cd $(shell dirname $(LABCOMM_JAR)); ant jar
+	@echo "======End building LabComm compiler======"
+
+
diff --git a/lib/c/2006/labcomm2006.c b/lib/c/2006/labcomm2006.c
index 111ec2f..8f628cf 100644
--- a/lib/c/2006/labcomm2006.c
+++ b/lib/c/2006/labcomm2006.c
@@ -62,7 +62,7 @@ int labcomm2006_reader_free(struct labcomm2006_reader *r,
 int labcomm2006_reader_start(struct labcomm2006_reader *r, 
                          struct labcomm2006_reader_action_context *action_context,
 			 int local_index, int remote_index,
-			 struct labcomm2006_signature *signature,
+			  const struct labcomm2006_signature *signature,
 			 void *value)
 {
   UNWRAP(start, r, action_context, local_index, remote_index, signature, value);
@@ -81,10 +81,10 @@ int labcomm2006_reader_fill(struct labcomm2006_reader *r,
 }
 
 int labcomm2006_reader_ioctl(struct labcomm2006_reader *r, 
-                         struct labcomm2006_reader_action_context *action_context,
-                         int local_index, int remote_index,
-                         struct labcomm2006_signature *signature, 
-                         uint32_t ioctl_action, va_list args)
+                             struct labcomm2006_reader_action_context *action_context,
+                             int local_index, int remote_index,
+                             const struct labcomm2006_signature *signature, 
+                             uint32_t ioctl_action, va_list args)
 {
   UNWRAP(ioctl, r, action_context, 
 	 local_index, remote_index, signature, ioctl_action, args);
@@ -104,7 +104,7 @@ int labcomm2006_writer_free(struct labcomm2006_writer *w,
 
 int labcomm2006_writer_start(struct labcomm2006_writer *w, 
                          struct labcomm2006_writer_action_context *action_context,
-                         int index, struct labcomm2006_signature *signature,
+                         int index, const struct labcomm2006_signature *signature,
                          void *value)
 {
   UNWRAP(start, w, action_context, index, signature, value);
@@ -125,7 +125,7 @@ int labcomm2006_writer_flush(struct labcomm2006_writer *w,
 int labcomm2006_writer_ioctl(struct labcomm2006_writer *w, 
                          struct labcomm2006_writer_action_context *action_context, 
                          int index, 
-                         struct labcomm2006_signature *signature, 
+                         const struct labcomm2006_signature *signature, 
                          uint32_t ioctl_action, va_list args)
 {
   UNWRAP(ioctl, w, action_context, index, signature, ioctl_action, args);
@@ -156,31 +156,30 @@ const char *labcomm2006_error_get_str(enum labcomm2006_error error_id)
   return error_str;
 }
 
-#if 0 //XXX hack to avoid name clash. is this really the same as in 2013?
-void on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...)
-{
 #ifndef LABCOMM_NO_STDIO
+void labcomm2006_on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...)
+{
   const char *err_msg = labcomm2006_error_get_str(error_id); // The final string to print.
   if (err_msg == NULL) {
     err_msg = "Error with an unknown error ID occured.";
   }
   fprintf(stderr, "%s\n", err_msg);
-
- if (nbr_va_args > 0) {
-   va_list arg_pointer;
-   va_start(arg_pointer, nbr_va_args);
-
-   fprintf(stderr, "%s\n", "Extra info {");
-   char *print_format = va_arg(arg_pointer, char *);
-   vfprintf(stderr, print_format, arg_pointer);
-   fprintf(stderr, "}\n");
-
-   va_end(arg_pointer);
- } 
+  
+  if (nbr_va_args > 0) {
+    va_list arg_pointer;
+    va_start(arg_pointer, nbr_va_args);
+    
+    fprintf(stderr, "%s\n", "Extra info {");
+    char *print_format = va_arg(arg_pointer, char *);
+    vfprintf(stderr, print_format, arg_pointer);
+    fprintf(stderr, "}\n");
+    
+    va_end(arg_pointer);
+  } 
+}
 #else
  ; // If labcomm can't be compiled with stdio the user will have to make an own error callback functionif he/she needs error reporting.
-#endif
-}
+  #error Define LABCOMM2006_ON_ERROR_FPRINTF
 #endif
 
 
@@ -244,22 +243,22 @@ void labcomm2006_set_local_index(struct labcomm2006_signature *signature)
 {
   if (signature->index != 0) {
     labcomm2006_error_fatal_global(LABCOMM_ERROR_SIGNATURE_ALREADY_SET,
-			       "%s", signature->name);
+                                   "Signature already set: %s", signature->name);
   }
   signature->index = local_index;
   local_index++;
 }
 
-int labcomm2006_get_local_index(struct labcomm2006_signature *signature)
+int labcomm2006_get_local_index(const struct labcomm2006_signature *signature)
 {
   if (signature->index == 0) {
     labcomm2006_error_fatal_global(LABCOMM_ERROR_SIGNATURE_NOT_SET,
-			       "%s", signature->name);
+                                   "Signature not set: %s", signature->name);
   }
   return signature->index;
 }
 
-int labcomm2006_internal_sizeof(struct labcomm2006_signature *signature,
+int labcomm2006_internal_sizeof(const struct labcomm2006_signature *signature,
                             void *v)
 {
   int length = signature->encoded_size(v);
diff --git a/lib/c/2006/labcomm2006.h b/lib/c/2006/labcomm2006.h
index fc7919e..1ea5aae 100644
--- a/lib/c/2006/labcomm2006.h
+++ b/lib/c/2006/labcomm2006.h
@@ -23,8 +23,6 @@
 #ifndef _LABCOMM_H_
 #define _LABCOMM_H_
 
-#define LABCOMM_VERSION "LabComm2006"
-
 #include <stdarg.h>
 
 #ifdef LABCOMM_COMPAT
@@ -33,6 +31,7 @@
   #include <stdint.h>
   #include <unistd.h>
 #endif
+
 #include "labcomm2006_error.h"
 #include "labcomm2006_scheduler.h"
 
@@ -71,7 +70,7 @@ typedef void (*labcomm2006_error_handler_callback)(enum labcomm2006_error error_
 /* Default error handler, prints message to stderr. 
  * Extra info about the error can be supplied as char* as VA-args. Especially user defined errors should supply a describing string. if nbr_va_args > 1 the first variable argument must be a printf format string and the possibly following arguments are passed as va_args to vprintf. 
  */
-void on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...);
+void labcomm2006_on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...);
 
 /* Register a callback for the error handler for this encoder. */
 void labcomm2006_register_error_handler_encoder(struct labcomm2006_encoder *encoder, labcomm2006_error_handler_callback callback);
diff --git a/lib/c/2006/labcomm2006_compat_vxworks.h b/lib/c/2006/labcomm2006_compat_vxworks.h
index f05ee78..9a830b1 100644
--- a/lib/c/2006/labcomm2006_compat_vxworks.h
+++ b/lib/c/2006/labcomm2006_compat_vxworks.h
@@ -1,7 +1,21 @@
-#ifndef  __VXWORKS__
+#ifndef _LABCOMM2006_COMPAT_VXWORKS_H_
+#define _LABCOMM2006_COMPAT_VXWORKS_H_
+
+#ifndef __VXWORKS__
 #error "__VXWORKS__" not defined
 #endif
 
+#include <types/vxTypes.h>
+#include <selectLib.h>
+#include <types.h>
+#include <timers.h>
+#include <stdio.h>
+#include <private/stdioP.h>
+
+#ifdef __INT64_MAX__
+#undef INT64_MAX
+#define INT64_MAX __INT64_MAX__
+
 #if (CPU == PPC603)
   #undef _LITTLE_ENDIAN
 #endif
@@ -10,3 +24,6 @@
   #undef _BIG_ENDIAN
 #endif
 
+extern unsigned int cpuFrequency;
+
+#endif
diff --git a/lib/c/2006/labcomm2006_decoder.c b/lib/c/2006/labcomm2006_decoder.c
index d472cdf..885f67e 100644
--- a/lib/c/2006/labcomm2006_decoder.c
+++ b/lib/c/2006/labcomm2006_decoder.c
@@ -26,7 +26,7 @@
 
 struct sample_entry {
   int remote_index;
-  struct labcomm2006_signature *signature;
+  const struct labcomm2006_signature *signature;
   labcomm2006_decoder_function decode;
   labcomm2006_handler_function handler;
   void *context;
@@ -181,7 +181,8 @@ static int decode_typedef_or_sample(struct labcomm2006_decoder *d, int kind)
     .pos = 0,
     .error = 0,
   };
-  struct labcomm2006_signature signature, *local_signature;
+  struct labcomm2006_signature signature;
+  const struct labcomm2006_signature *local_signature;
   int remote_index, local_index, err;
   
   local_signature = NULL;
@@ -264,7 +265,7 @@ struct call_handler_context {
   struct labcomm2006_reader *reader;
   int local_index;
   int remote_index;
-  struct labcomm2006_signature *signature;
+  const struct labcomm2006_signature *signature;
   labcomm2006_handler_function handler;
   void *context;
 };
@@ -300,7 +301,7 @@ int labcomm2006_decoder_decode_one(struct labcomm2006_decoder *d)
     result = d->reader->error;
     goto out;
   }
-  if (remote_index == LABCOMM_TYPEDEF || remote_index == LABCOMM_SAMPLE) {
+  if (remote_index == LABCOMM_SAMPLE) {
     result = decode_typedef_or_sample(d, remote_index); 
   } else {
     int *local_index;
@@ -366,7 +367,7 @@ int labcomm2006_decoder_ioctl(struct labcomm2006_decoder *d,
 }
 
 int labcomm2006_internal_decoder_ioctl(struct labcomm2006_decoder *d, 
-				   struct labcomm2006_signature *signature,
+				   const struct labcomm2006_signature *signature,
 				   uint32_t action, va_list va)
 {
   int result;
@@ -387,7 +388,7 @@ int labcomm2006_internal_decoder_ioctl(struct labcomm2006_decoder *d,
 
 int labcomm2006_internal_decoder_register(
   struct labcomm2006_decoder *d,
-  struct labcomm2006_signature *signature,
+  const struct labcomm2006_signature *signature,
   labcomm2006_decoder_function decode, 
   labcomm2006_handler_function handler,
   void *context)
diff --git a/lib/c/2006/labcomm2006_default_memory.h b/lib/c/2006/labcomm2006_default_memory.h
index 86b97f8..4f46f42 100644
--- a/lib/c/2006/labcomm2006_default_memory.h
+++ b/lib/c/2006/labcomm2006_default_memory.h
@@ -21,7 +21,6 @@
 
 #include <stdlib.h>
 #include "labcomm2006.h"
-#include "labcomm2006_private.h"
 
 extern struct labcomm2006_memory *labcomm2006_default_memory;
 
diff --git a/lib/c/2006/labcomm2006_dynamic_buffer_writer.c b/lib/c/2006/labcomm2006_dynamic_buffer_writer.c
index c931ec0..d9e2bbe 100644
--- a/lib/c/2006/labcomm2006_dynamic_buffer_writer.c
+++ b/lib/c/2006/labcomm2006_dynamic_buffer_writer.c
@@ -56,7 +56,7 @@ static int dyn_free(struct labcomm2006_writer *w,
 static int dyn_start(struct labcomm2006_writer *w, 
 		     struct labcomm2006_writer_action_context *action_context,
 		     int index,
-		     struct labcomm2006_signature *signature,
+		     const struct labcomm2006_signature *signature,
 		     void *value)
 {
   void *tmp;
@@ -103,7 +103,7 @@ static int dyn_flush(struct labcomm2006_writer *w,
 static int dyn_ioctl(struct labcomm2006_writer *w, 
 		     struct labcomm2006_writer_action_context *action_context, 
 		     int signature_index,
-		     struct labcomm2006_signature *signature,
+		     const struct labcomm2006_signature *signature,
 		     uint32_t action, va_list arg)
 {
   int result = -ENOTSUP;
diff --git a/lib/c/2006/labcomm2006_encoder.c b/lib/c/2006/labcomm2006_encoder.c
index 9e17a60..4eb8eca 100644
--- a/lib/c/2006/labcomm2006_encoder.c
+++ b/lib/c/2006/labcomm2006_encoder.c
@@ -69,7 +69,7 @@ void labcomm2006_encoder_free(struct labcomm2006_encoder* e)
 
 int labcomm2006_internal_encoder_register(
   struct labcomm2006_encoder *e,
-  struct labcomm2006_signature *signature,
+  const struct labcomm2006_signature *signature,
   labcomm2006_encoder_function encode)
 {
   int result = -EINVAL;
@@ -104,7 +104,7 @@ out:
 
 int labcomm2006_internal_encode(
   struct labcomm2006_encoder *e,
-  struct labcomm2006_signature *signature,
+  const struct labcomm2006_signature *signature,
   labcomm2006_encoder_function encode,
   void *value)
 {
@@ -150,8 +150,8 @@ out:
 }
 
 int labcomm2006_internal_encoder_ioctl(struct labcomm2006_encoder *encoder, 
-				   struct labcomm2006_signature *signature,
-				   uint32_t action, va_list va)
+                                       const struct labcomm2006_signature *signature,
+                                       uint32_t action, va_list va)
 {
   int result = -ENOTSUP;
   int index;
diff --git a/lib/c/2006/labcomm2006_fd_reader.c b/lib/c/2006/labcomm2006_fd_reader.c
index 15f1bfb..4269563 100644
--- a/lib/c/2006/labcomm2006_fd_reader.c
+++ b/lib/c/2006/labcomm2006_fd_reader.c
@@ -86,7 +86,7 @@ static int fd_fill(struct labcomm2006_reader *r,
     int err;
     
     r->pos = 0;
-    err = read(fd_reader->fd, (char *) r->data, r->data_size);
+    err = read(fd_reader->fd, (char *)r->data, r->data_size);
     if (err <= 0) {
       r->count = 0;
       r->error = -EPIPE;
diff --git a/lib/c/2006/labcomm2006_fd_writer.c b/lib/c/2006/labcomm2006_fd_writer.c
index 69f30bb..a763db6 100644
--- a/lib/c/2006/labcomm2006_fd_writer.c
+++ b/lib/c/2006/labcomm2006_fd_writer.c
@@ -79,7 +79,7 @@ static int fd_free(struct labcomm2006_writer *w,
 static int fd_start(struct labcomm2006_writer *w, 
 		    struct labcomm2006_writer_action_context *action_context,
 		    int index,
-		    struct labcomm2006_signature *signature,
+		    const struct labcomm2006_signature *signature,
 		    void *value)
 {
   w->pos = 0;
diff --git a/lib/c/2006/labcomm2006_private.h b/lib/c/2006/labcomm2006_private.h
index b8f7b78..4c33610 100644
--- a/lib/c/2006/labcomm2006_private.h
+++ b/lib/c/2006/labcomm2006_private.h
@@ -39,13 +39,13 @@
 /*
  * Predeclared aggregate type indices
  */
-#define LABCOMM_TYPEDEF  0x01
 #define LABCOMM_SAMPLE   0x02
 #define LABCOMM_ARRAY    0x10
 #define LABCOMM_STRUCT   0x11
+#define LABCOMM_USER     0x80   /* ..0xffffffff */
 
 /*
- * Predeclared primitive type indices
+ * Predefined primitive type indices
  */
 #define LABCOMM_BOOLEAN  0x20 
 #define LABCOMM_BYTE     0x21
@@ -56,11 +56,6 @@
 #define LABCOMM_DOUBLE   0x26
 #define LABCOMM_STRING   0x27
 
-/*
- * Start index for user defined types
- */
-#define LABCOMM_USER     0x80
-
 /*
  * Macro to automagically call constructors in modules compiled 
  * with the labcomm compiler. If __attribute__((constructor)) is
@@ -124,7 +119,7 @@ struct labcomm2006_reader_action {
   int (*start)(struct labcomm2006_reader *r, 
 	       struct labcomm2006_reader_action_context *action_context,
 	       int local_index, int remote_index,
-	       struct labcomm2006_signature *signature,
+	       const struct labcomm2006_signature *signature,
 	       void *value);
   int (*end)(struct labcomm2006_reader *r, 
 	     struct labcomm2006_reader_action_context *action_context);
@@ -133,7 +128,7 @@ struct labcomm2006_reader_action {
   int (*ioctl)(struct labcomm2006_reader *r, 
 	       struct labcomm2006_reader_action_context *action_context,
 	       int local_index, int remote_index,
-	       struct labcomm2006_signature *signature, 
+	       const struct labcomm2006_signature *signature, 
 	       uint32_t ioctl_action, va_list args);
 };
 
@@ -156,23 +151,23 @@ struct labcomm2006_reader {
 };
 
 int labcomm2006_reader_alloc(struct labcomm2006_reader *r, 
-			 struct labcomm2006_reader_action_context *action_context);
+                             struct labcomm2006_reader_action_context *action_context);
 int labcomm2006_reader_free(struct labcomm2006_reader *r, 
-			struct labcomm2006_reader_action_context *action_context);
+                            struct labcomm2006_reader_action_context *action_context);
 int labcomm2006_reader_start(struct labcomm2006_reader *r, 
-			 struct labcomm2006_reader_action_context *action_context,
-			 int local_index, int remote_index,
-			 struct labcomm2006_signature *signature,
-			 void *value);
+                             struct labcomm2006_reader_action_context *action_context,
+                             int local_index, int remote_index,
+                             const struct labcomm2006_signature *signature,
+                             void *value);
 int labcomm2006_reader_end(struct labcomm2006_reader *r, 
-		       struct labcomm2006_reader_action_context *action_context);
+                           struct labcomm2006_reader_action_context *action_context);
 int labcomm2006_reader_fill(struct labcomm2006_reader *r, 
-			struct labcomm2006_reader_action_context *action_context);
+                            struct labcomm2006_reader_action_context *action_context);
 int labcomm2006_reader_ioctl(struct labcomm2006_reader *r, 
-			 struct labcomm2006_reader_action_context *action_context,
-			 int local_index, int remote_index,
-			 struct labcomm2006_signature *signature, 
-			 uint32_t ioctl_action, va_list args);
+                             struct labcomm2006_reader_action_context *action_context,
+                             int local_index, int remote_index,
+                             const struct labcomm2006_signature *signature, 
+                             uint32_t ioctl_action, va_list args);
 
 /*
  * Non typesafe registration function to be called from
@@ -180,14 +175,14 @@ int labcomm2006_reader_ioctl(struct labcomm2006_reader *r,
  */
 int labcomm2006_internal_decoder_register(
   struct labcomm2006_decoder *d, 
-  struct labcomm2006_signature *s, 
+  const struct labcomm2006_signature *s, 
   labcomm2006_decoder_function decoder,
   labcomm2006_handler_function handler,
   void *context);
 
 int labcomm2006_internal_decoder_ioctl(struct labcomm2006_decoder *decoder, 
-				   struct labcomm2006_signature *signature,
-				   uint32_t ioctl_action, va_list args);
+                                       const struct labcomm2006_signature *signature,
+                                       uint32_t ioctl_action, va_list args);
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 
@@ -235,35 +230,9 @@ LABCOMM_DECODE(long, long long)
 LABCOMM_DECODE(float, float)
 LABCOMM_DECODE(double, double)
 
-//compatibility with 2013 version
+// compatibility with 2014 version
 #define labcomm2006_read_packed32 labcomm2006_read_int
 
-#if 0
-static inline unsigned int labcomm2006_read_packed32(struct labcomm2006_reader *r)
-{
-  unsigned int result = 0;
-  
-  while (1) {
-    unsigned char tmp;
-
-    if (r->pos >= r->count) {	
-      labcomm2006_reader_fill(r, r->action_context);
-      if (r->error != 0) {
-	goto out;
-      }
-    }
-    tmp = r->data[r->pos];
-    r->pos++;
-    result = (result << 7) | (tmp & 0x7f);
-    if ((tmp & 0x80) == 0) { 
-      break; 
-    }
-  }
-out:
-  return result;
-}
-#endif 
-
 static inline char *labcomm2006_read_string(struct labcomm2006_reader *r)
 {
   char *result = NULL;
@@ -271,6 +240,11 @@ static inline char *labcomm2006_read_string(struct labcomm2006_reader *r)
   
   length = labcomm2006_read_packed32(r);
   result = labcomm2006_memory_alloc(r->memory, 1, length + 1);
+  if (!result) {
+    labcomm2006_on_error_fprintf(LABCOMM_ERROR_MEMORY, 4, "%d byte at %s:%d",
+                     length+1, __FUNCTION__, __LINE__);
+    return NULL;
+  }
   for (pos = 0 ; pos < length ; pos++) {
     if (r->pos >= r->count) {	
       labcomm2006_reader_fill(r, r->action_context);
@@ -290,7 +264,7 @@ out:
  * Semi private encoder declarations
  */
 typedef int (*labcomm2006_encoder_function)(struct labcomm2006_writer *,
-					void *value);
+                                            void *value);
 struct labcomm2006_writer_action_context;
 
 struct labcomm2006_writer_action {
@@ -309,7 +283,7 @@ struct labcomm2006_writer_action {
    */
   int (*start)(struct labcomm2006_writer *w, 
 	       struct labcomm2006_writer_action_context *action_context,
-	       int index, struct labcomm2006_signature *signature,
+	       int index, const struct labcomm2006_signature *signature,
 	       void *value);
   int (*end)(struct labcomm2006_writer *w, 
 	     struct labcomm2006_writer_action_context *action_context);
@@ -317,7 +291,7 @@ struct labcomm2006_writer_action {
 	       struct labcomm2006_writer_action_context *action_context); 
   int (*ioctl)(struct labcomm2006_writer *w, 
 	       struct labcomm2006_writer_action_context *action_context, 
-	       int index, struct labcomm2006_signature *signature, 
+	       int index, const struct labcomm2006_signature *signature, 
 	       uint32_t ioctl_action, va_list args);
 };
 
@@ -345,7 +319,7 @@ int labcomm2006_writer_free(struct labcomm2006_writer *w,
 			struct labcomm2006_writer_action_context *action_context);
 int labcomm2006_writer_start(struct labcomm2006_writer *w, 
 			 struct labcomm2006_writer_action_context *action_context,
-			 int index, struct labcomm2006_signature *signature,
+			 int index, const struct labcomm2006_signature *signature,
 			 void *value);
 int labcomm2006_writer_end(struct labcomm2006_writer *w, 
 		       struct labcomm2006_writer_action_context *action_context);
@@ -353,25 +327,25 @@ int labcomm2006_writer_flush(struct labcomm2006_writer *w,
 			 struct labcomm2006_writer_action_context *action_context); 
 int labcomm2006_writer_ioctl(struct labcomm2006_writer *w, 
 			 struct labcomm2006_writer_action_context *action_context, 
-			 int index, struct labcomm2006_signature *signature, 
+			 int index, const struct labcomm2006_signature *signature, 
 			 uint32_t ioctl_action, va_list args);
 
 int labcomm2006_internal_encoder_register(
   struct labcomm2006_encoder *encoder, 
-  struct labcomm2006_signature *signature, 
+  const struct labcomm2006_signature *signature, 
   labcomm2006_encoder_function encode);
 
 int labcomm2006_internal_encode(
   struct labcomm2006_encoder *encoder, 
-  struct labcomm2006_signature *signature, 
+  const struct labcomm2006_signature *signature, 
   labcomm2006_encoder_function encode,
   void *value);
 
 int labcomm2006_internal_encoder_ioctl(struct labcomm2006_encoder *encoder, 
-				   struct labcomm2006_signature *signature,
-				   uint32_t ioctl_action, va_list args);
+                                       const struct labcomm2006_signature *signature,
+                                       uint32_t ioctl_action, va_list args);
 
-int labcomm2006_internal_sizeof(struct labcomm2006_signature *signature,
+int labcomm2006_internal_sizeof(const struct labcomm2006_signature *signature,
                                 void *v);
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -490,8 +464,8 @@ static inline int labcomm2006_size_packed32(unsigned int data)
   name.data = (kind *)NULL; /* typechecking */
 
 void *labcomm2006_signature_array_ref(struct labcomm2006_memory * memory,
-				  int *first, int *last, void **data,
-				  int size, int index);
+                                      int *first, int *last, void **data,
+                                      int size, int index);
 /*
  * NB: the pointer returned by LABCOMM_SIGNATURE_ARRAY_REF might be
  *     rendered invalid by a subsequent call to LABCOMM_SIGNATURE_ARRAY_REF
@@ -514,6 +488,6 @@ void *labcomm2006_signature_array_ref(struct labcomm2006_memory * memory,
 void labcomm2006_set_local_index(struct labcomm2006_signature *signature);
 
 /* Get the local index for a signature */
-int labcomm2006_get_local_index(struct labcomm2006_signature *s);
+int labcomm2006_get_local_index(const struct labcomm2006_signature *s);
 
 #endif
diff --git a/lib/c/2006/labcomm2006_scheduler_private.h b/lib/c/2006/labcomm2006_scheduler_private.h
index 4ed6bb1..1c80b36 100644
--- a/lib/c/2006/labcomm2006_scheduler_private.h
+++ b/lib/c/2006/labcomm2006_scheduler_private.h
@@ -22,7 +22,12 @@
 #ifndef _LABCOMM_SCHEDULER_PRIVATE_H_
 #define _LABCOMM_SCHEDULER_PRIVATE_H_
 
-#include <unistd.h>
+#ifdef LABCOMM_COMPAT
+ #include LABCOMM_COMPAT
+#else
+ #include <unistd.h>
+#endif
+
 #include "labcomm2006_scheduler.h"
 
 struct labcomm2006_time {
diff --git a/lib/c/test/another_encoding.lc b/lib/c/2006/test/another_encoding.lc
similarity index 100%
rename from lib/c/test/another_encoding.lc
rename to lib/c/2006/test/another_encoding.lc
diff --git a/lib/c/2006/cppmacros.h b/lib/c/2006/test/cppmacros.h
similarity index 100%
rename from lib/c/2006/cppmacros.h
rename to lib/c/2006/test/cppmacros.h
diff --git a/lib/c/2006/test/generated_encoding.lc b/lib/c/2006/test/generated_encoding.lc
new file mode 100644
index 0000000..f1f4b9b
--- /dev/null
+++ b/lib/c/2006/test/generated_encoding.lc
@@ -0,0 +1,7 @@
+sample void V;
+sample byte B;
+sample struct {
+  int i;
+} S1;
+sample int I[_];
+sample struct { int i; } P[_];
diff --git a/lib/c/test/labcomm_mem_reader.c b/lib/c/2006/test/labcomm_mem_reader.c
similarity index 100%
rename from lib/c/test/labcomm_mem_reader.c
rename to lib/c/2006/test/labcomm_mem_reader.c
diff --git a/lib/c/test/labcomm_mem_reader.h b/lib/c/2006/test/labcomm_mem_reader.h
similarity index 100%
rename from lib/c/test/labcomm_mem_reader.h
rename to lib/c/2006/test/labcomm_mem_reader.h
diff --git a/lib/c/test/labcomm_mem_writer.c b/lib/c/2006/test/labcomm_mem_writer.c
similarity index 100%
rename from lib/c/test/labcomm_mem_writer.c
rename to lib/c/2006/test/labcomm_mem_writer.c
diff --git a/lib/c/test/labcomm_mem_writer.h b/lib/c/2006/test/labcomm_mem_writer.h
similarity index 100%
rename from lib/c/test/labcomm_mem_writer.h
rename to lib/c/2006/test/labcomm_mem_writer.h
diff --git a/lib/c/test/more_types.lc b/lib/c/2006/test/more_types.lc
similarity index 100%
rename from lib/c/test/more_types.lc
rename to lib/c/2006/test/more_types.lc
diff --git a/lib/c/2006/test/test_labcomm.c b/lib/c/2006/test/test_labcomm.c
new file mode 100644
index 0000000..088f1b5
--- /dev/null
+++ b/lib/c/2006/test/test_labcomm.c
@@ -0,0 +1,213 @@
+/*
+  test_labcomm.c -- Various labcomm tests
+
+  Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>
+
+  This file is part of LabComm.
+
+  LabComm is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LabComm is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdint.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "labcomm2006_private.h"
+#include "labcomm2006_default_error_handler.h"
+#include "labcomm2006_default_memory.h"
+#include "labcomm2006_default_scheduler.h"
+#include "test/gen/test_sample.h"
+
+static unsigned char buffer[512];
+
+static int writer_alloc(struct labcomm2006_writer *w, 
+			struct labcomm2006_writer_action_context *action_context)
+{
+  w->data = buffer;
+  w->data_size = sizeof(buffer);
+  w->count = sizeof(buffer);
+  
+  return 0;
+}
+static int writer_start(struct labcomm2006_writer *w, 
+                        struct labcomm2006_writer_action_context *action_context,
+                        int index, const struct labcomm2006_signature *signature,
+                        void *value)
+{
+  return 0;
+}
+const struct labcomm2006_writer_action writer_action = {
+  .alloc = writer_alloc,
+  .start = writer_start,
+};
+static struct labcomm2006_writer_action_context writer_action_context = {
+  .next = NULL,
+  .action = &writer_action,
+  .context = NULL
+}; 
+static struct labcomm2006_writer writer =  {
+  .action_context = &writer_action_context,
+  .data = buffer,
+  .data_size = sizeof(buffer),
+  .count = sizeof(buffer),
+  .pos = 0,
+  .error = 0,
+};
+
+static int reader_alloc(struct labcomm2006_reader *r, 
+			struct labcomm2006_reader_action_context *action_context)
+{
+  r->data = buffer;
+  r->data_size = sizeof(buffer);
+  r->count = 0;
+  r->memory = labcomm2006_default_memory;
+  
+  return 0;
+}
+static int reader_fill(struct labcomm2006_reader *r, 
+		       struct labcomm2006_reader_action_context *action_context)
+{
+  r->error = -ENOMEM;
+  return r->error;
+}
+const struct labcomm2006_reader_action reader_action = {
+  .alloc = reader_alloc,
+  .fill = reader_fill,
+};
+static struct labcomm2006_reader_action_context reader_action_context = {
+  .next = NULL,
+  .action = &reader_action,
+  .context = NULL
+}; 
+static struct labcomm2006_reader reader =  {
+  .action_context = &reader_action_context,
+  .data = buffer,
+  .data_size = sizeof(buffer),
+  .count = 0,
+  .pos = 0,
+  .error = 0,
+};
+
+static int32_t encoder_data[256];
+static test_sample_test_var encoder_var = {
+  .n_0 = 1,
+  .n_1 = 1,
+  .a = encoder_data,
+};
+static int32_t decoder_data[256];
+static test_sample_test_var decoder_var = {
+  .n_0 = 1,
+  .n_1 = 1,
+  .a = decoder_data,
+};;
+
+void handle_test_var(test_sample_test_var *v, void *ctx)
+{
+  decoder_var.a[0] = v->a[0];  
+}
+
+int test_decode_one(struct labcomm2006_decoder *decoder)
+{
+  int result;
+
+  for (reader.count = 0 ; reader.count < writer.pos ; reader.count++) {
+    reader.error = 0;
+    reader.pos = 0;
+    result = labcomm2006_decoder_decode_one(decoder); 
+    if (result >= 0 ) {
+      fprintf(stderr, "Got result from buffer with bogus length (%d)\n",
+	      result);
+      exit(1);
+    }
+  }
+  reader.error = 0;
+  reader.pos = 0;
+  reader.count = writer.pos;
+  result = labcomm2006_decoder_decode_one(decoder);
+  if (result < 0) {
+    int i;
+
+    fprintf(stderr, "Got result from buffer with correct length (%d, %d)\n",
+	    result, writer.pos);
+    for (i = 0 ; i < writer.pos ; i++) {
+      fprintf(stderr, "%02x ", buffer[i]);
+    }
+    exit(1);
+  }
+  return result;
+}
+
+static void test_encode_decode(struct labcomm2006_encoder *encoder,
+			       struct labcomm2006_decoder *decoder,
+			       int expected, uint32_t n_0, uint32_t n_1)
+{
+  int err;
+
+  writer.pos = 0;
+  encoder_var.n_0 = n_0;
+  encoder_var.n_1 = n_1;
+  encoder_var.a[0] = 314;
+  labcomm2006_encode_test_sample_test_var(encoder, &encoder_var);
+  err = test_decode_one(decoder);
+  fprintf(stderr, "decode of sample %u * %u -> size=%d err=%d\n", 
+	  n_0, n_1, writer.pos, err);
+  if (writer.pos != labcomm2006_sizeof_test_sample_test_var(&encoder_var)) {
+    fprintf(stderr, "Incorrect sizeof %u * %u (%d != %d)\n",
+	    n_0, n_1, 
+	    writer.pos, labcomm2006_sizeof_test_sample_test_var(&encoder_var));
+    exit(1);
+  }
+  if (writer.pos != expected) {
+    fprintf(stderr, "Unexpected size %u * %u (%d != %d)\n",
+	    n_0, n_1, 
+	    writer.pos, expected);
+    exit(1);
+  }
+}
+
+int main(void)
+{
+  int err, i;
+  struct labcomm2006_encoder *encoder = labcomm2006_encoder_new(
+    &writer, 
+    labcomm2006_default_error_handler,
+    labcomm2006_default_memory,
+    labcomm2006_default_scheduler);
+  struct labcomm2006_decoder *decoder = labcomm2006_decoder_new(
+    &reader,
+    labcomm2006_default_error_handler,
+    labcomm2006_default_memory,
+    labcomm2006_default_scheduler);
+  labcomm2006_decoder_register_test_sample_test_var(decoder,
+						handle_test_var, 
+						NULL);
+  labcomm2006_encoder_register_test_sample_test_var(encoder);
+  err = test_decode_one(decoder);
+  fprintf(stderr, "decode of register -> index %d\n", err);
+  test_encode_decode(encoder, decoder, 16, 1, 1);
+  if (decoder_var.a[0] != encoder_var.a[0]) {
+    fprintf(stderr, "Failed to decode correct value %d != %d\n", 
+	    encoder_var.a[0], decoder_var.a[0]);
+    exit(1);
+  }
+  test_encode_decode(encoder, decoder, 28, 2, 2);
+  test_encode_decode(encoder, decoder, 12, 0, 0);
+  for (i = 1 ; i <= 4 ; i++) {
+    test_encode_decode(encoder, decoder, 12, 0, (1<<(7*i))-1);
+    test_encode_decode(encoder, decoder, 12, 0, (1<<(7*i)));
+  }
+  test_encode_decode(encoder, decoder, 12, 0, 4294967295);
+  return 0;
+}
diff --git a/lib/c/2006/test/test_labcomm_basic_type_encoding.c b/lib/c/2006/test/test_labcomm_basic_type_encoding.c
new file mode 100644
index 0000000..f6582e2
--- /dev/null
+++ b/lib/c/2006/test/test_labcomm_basic_type_encoding.c
@@ -0,0 +1,143 @@
+/*
+  test_labcomm_basic_type_encoding.c -- LabComm tests of basic encoding
+
+  Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>
+
+  This file is part of LabComm.
+
+  LabComm is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LabComm is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdint.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdlib.h>
+#include "labcomm2006_private.h"
+
+static int line;
+
+static unsigned char buffer[128];
+
+static struct labcomm2006_writer writer =  {
+  .action_context = NULL,
+  .data = buffer,
+  .data_size = sizeof(buffer),
+  .count = sizeof(buffer),
+  .pos = 0,
+  .error = 0,
+};
+
+static struct labcomm2006_reader reader =  {
+  .action_context = NULL,
+  .data = buffer,
+  .data_size = sizeof(buffer),
+  .count = 0,
+  .pos = 0,
+};
+
+typedef uint32_t packed32;
+
+#define TEST_WRITE_READ(type, ltype, format, value, expect_count, expect_bytes) \
+  {									\
+    type decoded;							\
+    line = __LINE__;							\
+    writer.pos = 0;							\
+    labcomm2006_write_##ltype(&writer, value);				\
+    writer_assert(#ltype, expect_count, (uint8_t*)expect_bytes);	\
+    reader.count = writer.pos;						\
+    reader.pos = 0;							\
+    decoded = labcomm2006_read_##ltype(&reader);                        \
+    if (decoded != value) {						\
+      fprintf(stderr, "Decode error" format " != " format " @%s:%d \n", \
+	      value, decoded, __FILE__, __LINE__);					\
+      exit(1);								\
+    }									\
+  }
+
+static void writer_assert(char *type,
+			  int count,
+			  uint8_t *bytes)
+{
+  if (writer.pos != count) {
+    fprintf(stderr, 
+	    "Wrong number of bytes written for '%s' (%d != %d) @%s:%d\n",
+	    type, writer.pos, count, __FILE__, line);
+    exit(1);
+  }
+  if (memcmp(writer.data, bytes, count) != 0) {
+    int i;
+
+    fprintf(stderr, "Wrong bytes written for '%s' ( ", type);
+    for (i = 0 ; i < count ; i++) {
+      fprintf(stderr, "%2.2x ", writer.data[i]);
+    }
+    fprintf(stderr, "!= ");
+    for (i = 0 ; i < count ; i++) {
+      fprintf(stderr, "%2.2x ", bytes[i]);
+    }
+    fprintf(stderr, ") @%s:%d\n", __FILE__, line);
+    exit(1);
+  }
+}
+
+int main(void)
+{
+  TEST_WRITE_READ(packed32, packed32, "%d", 0x00000000, 4, "\x00\x00\x00\x00");
+  TEST_WRITE_READ(packed32, packed32, "%d", 0x0000007f, 4, "\x00\x00\x00\x7f");
+  TEST_WRITE_READ(packed32, packed32, "%d", 0x00000080, 4, "\x00\x00\x00\x80");
+  TEST_WRITE_READ(packed32, packed32, "%d", 0x00003fff, 4, "\x00\x00\x3f\xff");
+  TEST_WRITE_READ(packed32, packed32, "%d", 0x00004000, 4, "\x00\x00\x40\x00");
+  TEST_WRITE_READ(packed32, packed32, "%d", 0x001fffff, 4, "\x00\x1f\xff\xff");
+  TEST_WRITE_READ(packed32, packed32, "%d", 0x00200000, 4, "\x00\x20\x00\x00");
+  TEST_WRITE_READ(packed32, packed32, "%d", 0x0fffffff, 4, "\x0f\xff\xff\xff");
+  TEST_WRITE_READ(packed32, packed32, "%d", 0x10000000, 4, "\x10\x00\x00\x00");
+  TEST_WRITE_READ(packed32, packed32, "%d", 0xffffffff, 4, "\xff\xff\xff\xff");
+  TEST_WRITE_READ(uint8_t, boolean, "%d", 0, 1, "\x00");
+  TEST_WRITE_READ(uint8_t, boolean, "%d", 1, 1, "\x01");
+  TEST_WRITE_READ(uint8_t, byte, "%d", 0, 1, "\x00");
+  TEST_WRITE_READ(uint8_t, byte, "%d", 1, 1, "\x01");
+  TEST_WRITE_READ(uint8_t, byte, "%d", 0xff, 1, "\xff");
+  TEST_WRITE_READ(int16_t, short, "%d", 0, 2, "\x00\x00");
+  TEST_WRITE_READ(int16_t, short, "%d", 0x7fff, 2, "\x7f\xff");
+  TEST_WRITE_READ(int16_t, short, "%d", -1, 2, "\xff\xff");
+  TEST_WRITE_READ(int32_t, int, "%d", 0, 4, "\x00\x00\x00\x00");
+  TEST_WRITE_READ(int32_t, int, "%d", 0x7fffffff, 4, "\x7f\xff\xff\xff");
+  TEST_WRITE_READ(int32_t, int, "%d", -1, 4, "\xff\xff\xff\xff");
+  TEST_WRITE_READ(int64_t, long, "%" PRId64, INT64_C(0), 8, "\x00\x00\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(int64_t, long, "%" PRId64, INT64_C(0x7fffffffffffffff), 8, "\x7f\xff\xff\xff\xff\xff\xff\xff");
+  TEST_WRITE_READ(int64_t, long, "%" PRId64, INT64_C(-1), 8, "\xff\xff\xff\xff\xff\xff\xff\xff");
+  TEST_WRITE_READ(float, float, "%f", 0.0, 4, "\x00\x00\x00\x00");
+  TEST_WRITE_READ(float, float, "%f", 1.0, 4, "\x3f\x80\x00\x00");
+  TEST_WRITE_READ(float, float, "%f", 2.0, 4, "\x40\x00\x00\x00");
+  TEST_WRITE_READ(float, float, "%f", 0.5, 4, "\x3f\x00\x00\x00");
+  TEST_WRITE_READ(float, float, "%f", 0.25, 4, "\x3e\x80\x00\x00");
+  TEST_WRITE_READ(float, float, "%f", -0.0, 4, "\x80\x00\x00\x00");
+  TEST_WRITE_READ(float, float, "%f", -1.0, 4, "\xbf\x80\x00\x00");
+  TEST_WRITE_READ(float, float, "%f", -2.0, 4, "\xc0\x00\x00\x00");
+  TEST_WRITE_READ(float, float, "%f", -0.5, 4, "\xbf\x00\x00\x00");
+  TEST_WRITE_READ(float, float, "%f", -0.25, 4, "\xbe\x80\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", 0.0, 8, "\x00\x00\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", 1.0, 8, "\x3f\xf0\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", 2.0, 8, "\x40\x00\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", 0.5, 8, "\x3f\xe0\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", 0.25, 8, "\x3f\xd0\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", -0.0, 8, "\x80\x00\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", -1.0, 8, "\xbf\xf0\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", -2.0, 8, "\xc0\x00\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", -0.5, 8, "\xbf\xe0\x00\x00\x00\x00\x00\x00");
+  TEST_WRITE_READ(double, double, "%f", -0.25, 8, "\xbf\xd0\x00\x00\x00\x00\x00\x00");
+  fprintf(stderr, "%s succeded\n", __FILE__);
+  return 0;
+}
+
diff --git a/lib/c/2006/test/test_labcomm_copy.c b/lib/c/2006/test/test_labcomm_copy.c
new file mode 100644
index 0000000..e554e1e
--- /dev/null
+++ b/lib/c/2006/test/test_labcomm_copy.c
@@ -0,0 +1,242 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <err.h>
+
+#include "labcomm2006.h"
+#include "labcomm2006_private.h"
+#include "labcomm2006_default_error_handler.h"
+#include "labcomm2006_default_memory.h"
+#include "labcomm2006_default_scheduler.h"
+#include "labcomm2006_fd_writer.h"
+#include "labcomm2006_fd_reader.h"
+#include "test/gen/generated_encoding.h"
+#include "test/gen/test_sample.h"
+#include "test/gen/more_types.h"
+
+#define DATA_FILE "copy_test.dat"
+
+static void handle_s1(generated_encoding_S1 *v, void *context)
+{
+  labcomm2006_copy_generated_encoding_S1(labcomm2006_default_memory, context, v);
+}
+
+static void handle_b(generated_encoding_B *v, void *context)
+{
+  labcomm2006_copy_generated_encoding_B(labcomm2006_default_memory, context, v);
+}
+
+static void handle_i(generated_encoding_I *v, void *context)
+{
+  labcomm2006_copy_generated_encoding_I(labcomm2006_default_memory, context, v);
+}
+
+static void handle_p(generated_encoding_P *v, void *context)
+{
+  labcomm2006_copy_generated_encoding_P(labcomm2006_default_memory, context, v);
+}
+
+static void handle_test_var(test_sample_test_var *v, void *context)
+{
+  labcomm2006_copy_test_sample_test_var(labcomm2006_default_memory, context, v);
+}
+
+static void handle_a(more_types_A *v, void *context)
+{
+  labcomm2006_copy_more_types_A(labcomm2006_default_memory, context, v);
+}
+
+static void handle_s(more_types_S *v, void *context)
+{
+  labcomm2006_copy_more_types_S(labcomm2006_default_memory, context, v);
+}
+
+static void handle_ns(more_types_NS *v, void *context)
+{
+  labcomm2006_copy_more_types_NS(labcomm2006_default_memory, context, v);
+}
+
+static void handle_as(more_types_AS *v, void *context)
+{
+  labcomm2006_copy_more_types_AS(labcomm2006_default_memory, context, v);
+}
+
+int main(int argc, char **argv)
+{
+  struct labcomm2006_encoder *encoder;
+  struct labcomm2006_decoder *decoder;
+  int fd;
+  generated_encoding_S1 s1;
+  generated_encoding_S1 cache_s1;
+  generated_encoding_B b;
+  generated_encoding_B cache_b;
+  generated_encoding_I I;
+  generated_encoding_I cache_I;
+  generated_encoding_P p;
+  generated_encoding_P cache_p;
+  test_sample_test_var test_var;
+  test_sample_test_var cache_test_var;
+  more_types_A a;
+  more_types_A cache_a;
+  more_types_S s;
+  more_types_S cache_s = NULL;
+  more_types_NS ns;
+  more_types_NS cache_ns;
+  more_types_AS as;
+  more_types_AS cache_as;
+
+  fd = open(DATA_FILE, O_RDWR | O_CREAT | O_TRUNC, 0644);
+  if (fd == -1)
+    err(1, "open()");
+  encoder =
+    labcomm2006_encoder_new(labcomm2006_fd_writer_new(labcomm2006_default_memory, fd, 0),
+			labcomm2006_default_error_handler,
+			labcomm2006_default_memory,
+			labcomm2006_default_scheduler);
+
+  labcomm2006_encoder_register_generated_encoding_S1(encoder);
+  s1.i = 1;
+  labcomm2006_encode_generated_encoding_S1(encoder, &s1);
+
+  labcomm2006_encoder_register_generated_encoding_B(encoder);
+  b = 2;
+  labcomm2006_encode_generated_encoding_B(encoder, &b);
+
+  labcomm2006_encoder_register_generated_encoding_I(encoder);
+  I.n_0 = 3;
+  I.a = calloc(I.n_0, sizeof(I.a[0]));
+  I.a[0] = 4;
+  I.a[1] = 5;
+  I.a[2] = 6;
+  labcomm2006_encode_generated_encoding_I(encoder, &I);
+
+  labcomm2006_encoder_register_generated_encoding_P(encoder);
+  p.n_0 = 7;
+  p.a = calloc(p.n_0, sizeof(p.a[0]));
+  for (int i = 0; i < p.n_0; i++)
+    p.a[i].i = 8 + i;
+  labcomm2006_encode_generated_encoding_P(encoder, &p);
+
+  labcomm2006_encoder_register_test_sample_test_var(encoder);
+  test_var.n_0 = 2;
+  test_var.n_1 = 7;
+  test_var.a = calloc(test_var.n_0 * test_var.n_1, sizeof(*test_var.a));
+  for (int i = 0; i < test_var.n_0; i++)
+    for (int j = 0; j < test_var.n_1; j++)
+      test_var.a[i] = 10 * i + j;
+  labcomm2006_encode_test_sample_test_var(encoder, &test_var);
+
+  labcomm2006_encoder_register_more_types_A(encoder);
+  for (int i = 0; i < sizeof(a.a) / sizeof(a.a[0]); i++)
+    a.a[i] = i;
+  labcomm2006_encode_more_types_A(encoder, &a);
+
+  labcomm2006_encoder_register_more_types_S(encoder);
+  s = "this is a string";
+  labcomm2006_encode_more_types_S(encoder, &s);
+
+  labcomm2006_encoder_register_more_types_NS(encoder);
+  ns.s1 = "this is a string";
+  ns.s2 = "this is a another string";
+  labcomm2006_encode_more_types_NS(encoder, &ns);
+
+  labcomm2006_encoder_register_more_types_AS(encoder);
+  as.n_0 = 3;
+  as.a = calloc(as.n_0, sizeof(as.a[0]));
+  as.a[0] = "string 0";
+  as.a[1] = "string 1";
+  as.a[2] = "string 2";
+  labcomm2006_encode_more_types_AS(encoder, &as);
+
+  labcomm2006_encoder_free(encoder);
+  encoder = NULL;
+  lseek(fd, 0, SEEK_SET);
+  decoder =
+    labcomm2006_decoder_new(labcomm2006_fd_reader_new(labcomm2006_default_memory, fd, 0),
+			labcomm2006_default_error_handler,
+			labcomm2006_default_memory,
+			labcomm2006_default_scheduler);
+
+  labcomm2006_decoder_register_generated_encoding_S1(decoder, handle_s1, &cache_s1);
+  labcomm2006_decoder_register_generated_encoding_B(decoder, handle_b, &cache_b);
+  labcomm2006_decoder_register_generated_encoding_I(decoder, handle_i, &cache_I);
+  labcomm2006_decoder_register_generated_encoding_P(decoder, handle_p, &cache_p);
+  labcomm2006_decoder_register_test_sample_test_var(decoder, handle_test_var,
+						&cache_test_var);
+  labcomm2006_decoder_register_more_types_A(decoder, handle_a, &cache_a);
+  labcomm2006_decoder_register_more_types_S(decoder, handle_s, &cache_s);
+  labcomm2006_decoder_register_more_types_NS(decoder, handle_ns, &cache_ns);
+  labcomm2006_decoder_register_more_types_AS(decoder, handle_as, &cache_as);
+
+  while (labcomm2006_decoder_decode_one(decoder) > 0) ;
+
+  assert(cache_s1.i == s1.i);
+  puts("S1 copied ok");
+
+  assert(cache_b == b);
+  puts("B copied ok");
+
+  assert(cache_I.n_0 == I.n_0);
+  assert(cache_I.a[0] == I.a[0]);
+  assert(cache_I.a[1] == I.a[1]);
+  assert(cache_I.a[2] == I.a[2]);
+  free(I.a);
+  puts("I copied ok");
+
+  assert(cache_p.n_0 == p.n_0);
+  for (int i = 0; i < p.n_0; i++)
+    assert(cache_p.a[i].i == p.a[i].i);
+  free(p.a);
+  puts("P copied ok");
+
+  assert(cache_test_var.n_0 == test_var.n_0);
+  assert(cache_test_var.n_1 == test_var.n_1);
+  for (int i = 0; i < test_var.n_0; i++)
+    for (int j = 0; j < test_var.n_1; j++)
+      assert(cache_test_var.a[p.n_0 * i + j] == test_var.a[p.n_0 * i + j]);
+  free(test_var.a);
+  puts("test_var copied ok");
+
+  for (int i = 0; i < sizeof(a.a) / sizeof(a.a[0]); i++)
+    assert(cache_a.a[i] == a.a[i]);
+  puts("A copied ok");
+
+  assert(!strcmp(cache_s, s));
+  puts("S copied ok");
+
+  assert(!strcmp(cache_ns.s1, ns.s1));
+  assert(!strcmp(cache_ns.s2, ns.s2));
+  puts("NS copied ok");
+
+  for (int i = 0; i < as.n_0; i++)
+    assert(!strcmp(cache_as.a[i], as.a[i]));
+  free(as.a);
+  puts("AS copied ok");
+
+  labcomm2006_decoder_free(decoder);
+  close(fd);
+  unlink(DATA_FILE);
+
+  labcomm2006_copy_free_generated_encoding_S1(labcomm2006_default_memory, &cache_s1);
+  puts("S1 deallocated ok");
+  labcomm2006_copy_free_generated_encoding_B(labcomm2006_default_memory, &cache_b);
+  puts("B deallocated ok");
+  labcomm2006_copy_free_generated_encoding_I(labcomm2006_default_memory, &cache_I);
+  puts("I deallocated ok");
+  labcomm2006_copy_free_generated_encoding_P(labcomm2006_default_memory, &cache_p);
+  puts("P deallocated ok");
+  labcomm2006_copy_free_test_sample_test_var(labcomm2006_default_memory, &cache_test_var);
+  puts("test_var deallocated ok");
+  labcomm2006_copy_free_more_types_A(labcomm2006_default_memory, &cache_a);
+  puts("A deallocated ok");
+  labcomm2006_copy_free_more_types_S(labcomm2006_default_memory, &cache_s);
+  puts("S deallocated ok");
+  labcomm2006_copy_free_more_types_NS(labcomm2006_default_memory, &cache_ns);
+  puts("NS deallocated ok");
+  labcomm2006_copy_free_more_types_AS(labcomm2006_default_memory, &cache_as);
+  puts("AS deallocated ok");
+}
diff --git a/lib/c/test/test_labcomm_errors.c b/lib/c/2006/test/test_labcomm_errors.c
similarity index 100%
rename from lib/c/test/test_labcomm_errors.c
rename to lib/c/2006/test/test_labcomm_errors.c
diff --git a/lib/c/test/test_labcomm_errors.h b/lib/c/2006/test/test_labcomm_errors.h
similarity index 100%
rename from lib/c/test/test_labcomm_errors.h
rename to lib/c/2006/test/test_labcomm_errors.h
diff --git a/lib/c/2006/test/test_labcomm_generated_encoding.c b/lib/c/2006/test/test_labcomm_generated_encoding.c
new file mode 100644
index 0000000..ad116a8
--- /dev/null
+++ b/lib/c/2006/test/test_labcomm_generated_encoding.c
@@ -0,0 +1,219 @@
+/*
+  test_labcomm_generated_encoding.c -- LabComm tests of generated encoding
+
+  Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>
+
+  This file is part of LabComm.
+
+  LabComm is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LabComm is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "labcomm2006_private.h"
+#include "labcomm2006_default_error_handler.h"
+#include "labcomm2006_default_memory.h"
+#include "labcomm2006_pthread_scheduler.h"
+#include "test/gen/generated_encoding.h"
+
+#define IOCTL_WRITER_ASSERT_BYTES 4096
+#define IOCTL_WRITER_RESET 4097
+
+static unsigned char buffer[128];
+struct labcomm2006_writer *writer;
+
+static int buf_writer_alloc(
+  struct labcomm2006_writer *w, 
+  struct labcomm2006_writer_action_context *action_context)
+{
+  writer = w; /* Hack */
+  w->data_size = sizeof(buffer);
+  w->count = w->data_size;
+  w->data = buffer;
+  w->pos = 0;
+  
+  return 0;
+}
+
+static int buf_writer_free(
+  struct labcomm2006_writer *w, 
+  struct labcomm2006_writer_action_context *action_context)
+{
+  return 0;
+}
+
+static int buf_writer_start(
+  struct labcomm2006_writer *w,
+  struct labcomm2006_writer_action_context *action_context,
+  int index,
+  const struct labcomm2006_signature *signature,
+  void *value)
+{
+  return 0;
+}
+
+static int buf_writer_end(
+  struct labcomm2006_writer *w, 
+  struct labcomm2006_writer_action_context *action_context)
+{
+  return 0;
+}
+
+static int buf_writer_flush(
+  struct labcomm2006_writer *w, 
+  struct labcomm2006_writer_action_context *action_context)
+{
+  fprintf(stderr, "Should not come here %s:%d\n", __FILE__, __LINE__);
+  exit(1);
+  
+  return 0;
+}
+
+static int buf_writer_ioctl(
+  struct labcomm2006_writer *w, 
+  struct labcomm2006_writer_action_context *action_context,
+  int signature_index, const struct labcomm2006_signature *signature,
+  uint32_t action, va_list arg)
+{
+  int result = -ENOTSUP;
+  switch (action) {
+    case IOCTL_WRITER_ASSERT_BYTES: {
+      int line = va_arg(arg, int);
+      int count = va_arg(arg, int);
+      int *expected = va_arg(arg, int *);
+      int i, mismatch;
+
+      if (w->pos != count) {
+	fprintf(stderr, "Invalid length encoded %d != %d (%s:%d)\n", 
+		w->pos, count, __FILE__, line);
+	mismatch = 1;
+      } 
+      for (mismatch = 0, i = 0 ; i < count ; i++) {
+	if (expected[i] >= 0 && expected[i] != buffer[i]) {
+	  mismatch = 1;
+	}
+      }
+      if (mismatch) {
+	fprintf(stderr, "Encoder mismatch (%s:%d)\n",
+		__FILE__, line);
+
+	for (i = 0 ; i < w->pos ; i++) {
+	  printf("%2.2x ", w->data[i]);
+	}
+	printf("\n");
+	for (i = 0 ; i < count ; i++) {
+	  if (expected[i] < 0) {
+	    printf(".. ");
+	  } else {
+	    printf("%2.2x ", expected[i] );
+	  }
+	}
+	printf("\n");
+	exit(1);
+      }
+      result = 0;
+    } break;
+    case IOCTL_WRITER_RESET: {
+      w->pos = 0;
+      result = 0;
+    }
+  }
+  return result;
+}
+
+const struct labcomm2006_writer_action writer_action = {
+  .alloc = buf_writer_alloc,
+  .free = buf_writer_free,
+  .start = buf_writer_start,
+  .end = buf_writer_end,
+  .flush = buf_writer_flush,
+  .ioctl = buf_writer_ioctl
+};
+
+static struct labcomm2006_writer_action_context action_context = {
+  .next = NULL,
+  .action = &writer_action,
+  .context = NULL
+}; 
+static struct labcomm2006_writer buffer_writer = {
+  .action_context = &action_context,
+  .data = buffer,
+  .data_size = sizeof(buffer),
+  .count = sizeof(buffer),
+  .pos = 0,
+  .error = 0,
+};
+
+void dump_encoder(struct labcomm2006_encoder *encoder)
+{
+  int i;
+  
+  for (i = 0 ; i < writer->pos ; i++) {
+    printf("%2.2x ", writer->data[i]);
+  }
+  printf("\n");
+}
+
+#define EXPECT(...)							\
+  {									\
+    int expected[] = __VA_ARGS__;					\
+    labcomm2006_encoder_ioctl(encoder, IOCTL_WRITER_ASSERT_BYTES,       \
+			  __LINE__,					\
+			  sizeof(expected)/sizeof(expected[0]),		\
+			  expected);					\
+  }
+
+int main(void)
+{
+  generated_encoding_B B = 1;
+
+  struct labcomm2006_encoder *encoder = labcomm2006_encoder_new(
+    &buffer_writer, 
+    labcomm2006_default_error_handler,
+    labcomm2006_default_memory,
+    labcomm2006_pthread_scheduler_new(labcomm2006_default_memory));
+
+  labcomm2006_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
+  /* Register twice to make sure that only one registration gets encoded */
+  labcomm2006_encoder_register_generated_encoding_V(encoder);
+  labcomm2006_encoder_register_generated_encoding_V(encoder);
+  EXPECT({ 0x00, 0x00, 0x00, 0x02,
+           0x00, 0x00, 0x00, -1, 
+           0x00, 0x00, 0x00, 0x01, 'V', 
+           0x00, 0x00, 0x00, 0x11, 
+           0x00, 0x00, 0x00, 0x00 });
+
+  labcomm2006_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
+  /* Register twice to make sure that only one registration gets encoded */
+  labcomm2006_encoder_register_generated_encoding_B(encoder);
+  labcomm2006_encoder_register_generated_encoding_B(encoder);
+  EXPECT({ 0x00, 0x00, 0x00, 0x02, 
+           0x00, 0x00, 0x00, -1, 
+           0x00, 0x00, 0x00, 0x01, 'B', 
+           0x00, 0x00, 0x00, 0x21});
+
+  labcomm2006_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
+  // was: labcomm2006_encode_generated_encoding_V(encoder, &V);
+  labcomm2006_encode_generated_encoding_V(encoder);
+  EXPECT({0x00, 0x00, 0x00, -1 });
+
+  labcomm2006_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
+  labcomm2006_encode_generated_encoding_B(encoder, &B);
+  EXPECT({ 0x00, 0x00, 0x00, -1, 1});
+
+  return 0;
+}
+
diff --git a/lib/c/2006/test/test_labcomm_pthread_scheduler.c b/lib/c/2006/test/test_labcomm_pthread_scheduler.c
new file mode 100644
index 0000000..c89dca5
--- /dev/null
+++ b/lib/c/2006/test/test_labcomm_pthread_scheduler.c
@@ -0,0 +1,82 @@
+/*
+  test_labcomm_pthread_scheduler.c -- test labcomm pthread based task 
+                                      coordination
+
+  Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>
+
+  This file is part of LabComm.
+
+  LabComm is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LabComm is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "labcomm2006_default_memory.h"
+#include "labcomm2006_scheduler.h"
+#include "labcomm2006_pthread_scheduler.h"
+
+#define TICK 100000
+struct func_arg {
+  struct labcomm2006_scheduler *scheduler;
+  int i;
+};
+
+static void func(void *arg) 
+{
+  struct func_arg *func_arg = arg;
+  
+  printf("%p %d\n", arg, func_arg->i);
+  if (func_arg->i == 999) {
+    labcomm2006_scheduler_wakeup(func_arg->scheduler);
+  }
+}
+
+void enqueue(struct labcomm2006_scheduler *scheduler, 
+	     int first, int last)
+{
+  int i;
+  
+  for (i = first ; i <= last ; i++) {
+    struct func_arg *tmp = malloc(sizeof(*tmp));
+    
+    tmp->scheduler = scheduler;
+    tmp->i = i;
+    labcomm2006_scheduler_enqueue(scheduler, i*TICK, func, tmp);
+  }
+}
+
+int main(int argc, char *argv[])
+{
+  struct labcomm2006_scheduler *scheduler;
+  struct labcomm2006_time *time;
+
+  scheduler = labcomm2006_pthread_scheduler_new(labcomm2006_default_memory);
+  enqueue(scheduler, 0, 5);
+  enqueue(scheduler, 0, 1);
+  enqueue(scheduler, 1, 3);
+  enqueue(scheduler, 7, 10);
+  {
+    struct func_arg *tmp = malloc(sizeof(*tmp));
+    
+    tmp->scheduler = scheduler;
+    tmp->i = 999;
+    labcomm2006_scheduler_enqueue(scheduler, 6*TICK, func, tmp);
+  }
+  time = labcomm2006_scheduler_now(scheduler);
+  labcomm2006_time_add_usec(time, 12*TICK);
+  labcomm2006_scheduler_sleep(scheduler, NULL);
+  labcomm2006_scheduler_sleep(scheduler, time);
+
+  return 0;
+}
diff --git a/lib/c/test/test_sample.lc b/lib/c/2006/test/test_sample.lc
similarity index 100%
rename from lib/c/test/test_sample.lc
rename to lib/c/2006/test/test_sample.lc
diff --git a/lib/c/2006/test/test_signature_numbers.c b/lib/c/2006/test/test_signature_numbers.c
new file mode 100644
index 0000000..9d79b4a
--- /dev/null
+++ b/lib/c/2006/test/test_signature_numbers.c
@@ -0,0 +1,24 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "labcomm2006_private.h"
+#include "test/gen/another_encoding.h"
+#include "test/gen/generated_encoding.h"
+
+static void info(char *name, char *full_name, 
+		 const struct labcomm2006_signature *signature) {
+  printf("%s %s %p -> %d\n", name,  full_name, signature, 
+	 labcomm2006_get_local_index(signature));
+  if (labcomm2006_get_local_index(signature) < 0x40) {
+    exit(1);
+  }
+};
+
+int main(int argc, char *argv[])
+{
+#define FUNC(name, full_name) \
+  info( #name, #full_name, labcomm2006_signature_##full_name)
+
+  LABCOMM_FORALL_SAMPLES_generated_encoding(FUNC, ;);
+  LABCOMM_FORALL_SAMPLES_another_encoding(FUNC, ;);
+  return 0;
+}
diff --git a/lib/c/2014/Makefile b/lib/c/2014/Makefile
new file mode 100644
index 0000000..5fb5c8b
--- /dev/null
+++ b/lib/c/2014/Makefile
@@ -0,0 +1,169 @@
+## Macros
+VERSION=
+LIBVERSION=2014
+
+include ../os_compat.mk
+
+ALL_DEPS=../liblabcomm$(LIBVERSION).a ../liblabcomm$(LIBVERSION).so.1
+
+# TODO: Support for Codesourcery ARM toolchain.
+
+OBJS=labcomm$(VERSION).o \
+     labcomm$(VERSION)_memory.o \
+     labcomm$(VERSION)_error.o \
+     labcomm$(VERSION)_default_error_handler.o \
+     labcomm$(VERSION)_default_memory.o \
+     labcomm$(VERSION)_default_scheduler.o \
+     labcomm$(VERSION)_time.o \
+     labcomm$(VERSION)_scheduler.o \
+     labcomm$(VERSION)_encoder.o \
+     labcomm$(VERSION)_decoder.o \
+     labcomm$(VERSION)_dynamic_buffer_writer.o \
+     labcomm$(VERSION)_fd_reader.o \
+     labcomm$(VERSION)_fd_writer.o \
+     labcomm$(VERSION)_pthread_scheduler.o 
+
+#FIXME: labcomm_mem_reader.o labcomm_mem_writer.o
+LABCOMM_JAR=../../../compiler/labcomm_compiler.jar
+LABCOMM=java -jar $(LABCOMM_JAR) 
+
+TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
+      test_signature_numbers \
+      test_labcomm \
+      test_labcomm_pthread_scheduler \
+      test_labcomm_copy
+#
+#FIXME: test_labcomm test_labcomm_errors
+TEST_DIR=test
+
+VPATH=$(TEST_DIR)
+
+# Enable experimental objects by invoking make like `make LABCOMM_EXPERIMENTAL=true`
+ifeq ($(LABCOMM_EXPERIMENTAL),true)
+	OBJS += experimental/udp_hack.o experimental/ethaddr.o \
+		experimental/labcomm_thr_reader_writer.o \
+		experimental/ThrottleDrv/ethernet_drv.o \
+		experimental/ThrottleDrv/throttle_drv.o \
+		experimental/labcomm_udp_reader_writer.o\
+		experimental/labcomm_sig_parser.o 
+
+
+experimental/test_sig_parser : experimental/labcomm_sig_parser.o experimental/test_sig_parser.c
+endif
+
+## Targets
+
+.PHONY: all run-test clean distclean
+
+all: $(ALL_DEPS)
+
+test: all $(TESTS:%=run-test-%)
+
+clean:
+	$(RM) *.o
+	$(RM) experimental/*.o 
+	$(RM) experimental/ThrottleDrv/*.o
+	$(RM) test/*.o
+	$(RM) test/*.gch
+	$(RM) test/test_labcomm_errors
+	$(RM) test/testdata/gen/*.[cho]
+	$(RM) test/gen/*.[cho]
+	-rmdir test/gen
+	for x in $(TESTS); do \
+		$(RM) $(TEST_DIR)/$$x ; \
+	done
+
+distclean: clean
+	$(RM) ../liblabcomm$(LIBVERSION).so.1
+	$(RM) ../liblabcomm$(LIBVERSION).a
+
+
+# rules invoked by 'all'
+../liblabcomm$(LIBVERSION).a: $(OBJS)
+	ar -r $@ $^
+
+../liblabcomm$(LIBVERSION).so.1: $(OBJS:%.o=%.pic.o)
+	$(call MAKESHARED,$@,$@,$^)
+
+# compilation rules 
+%.pic.o:	%.c
+	$(CC) -fPIC $(CFLAGS) -c -o $@ $<
+
+%.o: %.c %.h
+
+# rules invoked by 'test'
+
+# Extra compilation dependencies
+labcomm$(VERSION).o: \
+	labcomm$(VERSION).c \
+	labcomm$(VERSION).h \
+	labcomm$(VERSION)_private.h
+
+labcomm$(VERSION)_fd_reader_writer.o: \
+	labcomm$(VERSION)_fd_reader_writer.c \
+	labcomm$(VERSION)_fd_reader_writer.h  \
+	labcomm$(VERSION).h \
+	labcomm$(VERSION)_private.h
+
+labcomm.o : labcomm.c labcomm.h  labcomm_private.h
+
+labcomm_fd_reader_writer.o : labcomm_fd_reader_writer.c  labcomm_fd_reader_writer.h  labcomm.h  labcomm_private.h
+
+2006/labcomm2006.o : 2006/labcomm2006.c 2006/labcomm2006.h  2006/labcomm2006_private.h
+
+2006/labcomm2006_fd_reader_writer.o : 2006/labcomm2006_fd_reader_writer.c  2006/labcomm2006_fd_reader_writer.h  labcomm.h  2006/labcomm2006_private.h
+
+#$(TEST_DIR)/labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h
+
+#$(TEST_DIR)/labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h
+
+ethaddr.o: ethaddr.c
+
+run-test-%: $(TEST_DIR)/% | $(TEST_DIR)
+	$<
+
+$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
+	$(CC) $(CFLAGS) -o $@ -c $<
+
+.PRECIOUS: $(TEST_DIR)/%
+$(TEST_DIR)/%: $(TEST_DIR)/%.o 
+	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) 
+
+$(TEST_DIR)/gen:
+	mkdir -p $@
+
+.PRECIOUS: $(TEST_DIR)/gen/%.c
+.PRECIOUS: $(TEST_DIR)/gen/%.h
+$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
+	$(LABCOMM) \
+		--c=$(TEST_DIR)/gen/$*.c \
+		--h=$(TEST_DIR)/gen/$*.h \
+		$<
+
+$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
+					 $(LABCOMM_JAR) | $(TEST_GEN_DIR)
+	$(LABCOMM) \
+		--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
+
+$(LABCOMM_JAR):
+	@echo "======Building LabComm compiler======"
+	cd $(shell dirname $(LABCOMM_JAR)); ant jar
+	@echo "======End building LabComm compiler======"
+
+
+# Extra dependencies
+$(TEST_DIR)/test_labcomm_basic_type_encoding.o: labcomm_private.h
+
+$(TEST_DIR)/test_labcomm_generated_encoding.o: labcomm_private.h
+$(TEST_DIR)/test_labcomm_generated_encoding.o: $(TEST_DIR)/gen/generated_encoding.h
+$(TEST_DIR)/test_labcomm_generated_encoding : $(TEST_DIR)/gen/generated_encoding.o
+
+$(TEST_DIR)/test_labcomm:  $(TEST_DIR)/gen/test_sample.o
+$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/another_encoding.h
+$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/generated_encoding.h
+$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/another_encoding.o
+$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/generated_encoding.o
+$(TEST_DIR)/test_labcomm_copy:  $(TEST_DIR)/gen/generated_encoding.o $(TEST_DIR)/gen/test_sample.o $(TEST_DIR)/gen/more_types.o
+labcomm_fd_reader.o: labcomm_private.h
+labcomm_fd_writer.o: labcomm_private.h
+labcomm_dynamic_buffer_writer.o: labcomm_private.h
diff --git a/lib/c/experimental/ThrottleDrv/display.h b/lib/c/2014/experimental/ThrottleDrv/display.h
similarity index 100%
rename from lib/c/experimental/ThrottleDrv/display.h
rename to lib/c/2014/experimental/ThrottleDrv/display.h
diff --git a/lib/c/experimental/ThrottleDrv/ethernet_drv.c b/lib/c/2014/experimental/ThrottleDrv/ethernet_drv.c
similarity index 100%
rename from lib/c/experimental/ThrottleDrv/ethernet_drv.c
rename to lib/c/2014/experimental/ThrottleDrv/ethernet_drv.c
diff --git a/lib/c/experimental/ThrottleDrv/ethernet_drv.h b/lib/c/2014/experimental/ThrottleDrv/ethernet_drv.h
similarity index 100%
rename from lib/c/experimental/ThrottleDrv/ethernet_drv.h
rename to lib/c/2014/experimental/ThrottleDrv/ethernet_drv.h
diff --git a/lib/c/experimental/ThrottleDrv/throttle_drv.c b/lib/c/2014/experimental/ThrottleDrv/throttle_drv.c
similarity index 100%
rename from lib/c/experimental/ThrottleDrv/throttle_drv.c
rename to lib/c/2014/experimental/ThrottleDrv/throttle_drv.c
diff --git a/lib/c/experimental/ThrottleDrv/throttle_drv.h b/lib/c/2014/experimental/ThrottleDrv/throttle_drv.h
similarity index 100%
rename from lib/c/experimental/ThrottleDrv/throttle_drv.h
rename to lib/c/2014/experimental/ThrottleDrv/throttle_drv.h
diff --git a/lib/c/experimental/ethaddr.c b/lib/c/2014/experimental/ethaddr.c
similarity index 100%
rename from lib/c/experimental/ethaddr.c
rename to lib/c/2014/experimental/ethaddr.c
diff --git a/lib/c/experimental/ethaddr.h b/lib/c/2014/experimental/ethaddr.h
similarity index 100%
rename from lib/c/experimental/ethaddr.h
rename to lib/c/2014/experimental/ethaddr.h
diff --git a/lib/c/experimental/labcomm_sig_parser.c b/lib/c/2014/experimental/labcomm_sig_parser.c
similarity index 100%
rename from lib/c/experimental/labcomm_sig_parser.c
rename to lib/c/2014/experimental/labcomm_sig_parser.c
diff --git a/lib/c/experimental/labcomm_sig_parser.h b/lib/c/2014/experimental/labcomm_sig_parser.h
similarity index 100%
rename from lib/c/experimental/labcomm_sig_parser.h
rename to lib/c/2014/experimental/labcomm_sig_parser.h
diff --git a/lib/c/experimental/labcomm_thr_reader_writer.c b/lib/c/2014/experimental/labcomm_thr_reader_writer.c
similarity index 100%
rename from lib/c/experimental/labcomm_thr_reader_writer.c
rename to lib/c/2014/experimental/labcomm_thr_reader_writer.c
diff --git a/lib/c/experimental/labcomm_thr_reader_writer.h b/lib/c/2014/experimental/labcomm_thr_reader_writer.h
similarity index 100%
rename from lib/c/experimental/labcomm_thr_reader_writer.h
rename to lib/c/2014/experimental/labcomm_thr_reader_writer.h
diff --git a/lib/c/experimental/labcomm_udp_reader_writer.c b/lib/c/2014/experimental/labcomm_udp_reader_writer.c
similarity index 100%
rename from lib/c/experimental/labcomm_udp_reader_writer.c
rename to lib/c/2014/experimental/labcomm_udp_reader_writer.c
diff --git a/lib/c/experimental/labcomm_udp_reader_writer.h b/lib/c/2014/experimental/labcomm_udp_reader_writer.h
similarity index 100%
rename from lib/c/experimental/labcomm_udp_reader_writer.h
rename to lib/c/2014/experimental/labcomm_udp_reader_writer.h
diff --git a/lib/c/experimental/pack.c b/lib/c/2014/experimental/pack.c
similarity index 100%
rename from lib/c/experimental/pack.c
rename to lib/c/2014/experimental/pack.c
diff --git a/lib/c/experimental/test_sig_parser.c b/lib/c/2014/experimental/test_sig_parser.c
similarity index 100%
rename from lib/c/experimental/test_sig_parser.c
rename to lib/c/2014/experimental/test_sig_parser.c
diff --git a/lib/c/experimental/throttlenet/throttlenet.lc b/lib/c/2014/experimental/throttlenet/throttlenet.lc
similarity index 100%
rename from lib/c/experimental/throttlenet/throttlenet.lc
rename to lib/c/2014/experimental/throttlenet/throttlenet.lc
diff --git a/lib/c/experimental/udp_hack.c b/lib/c/2014/experimental/udp_hack.c
similarity index 100%
rename from lib/c/experimental/udp_hack.c
rename to lib/c/2014/experimental/udp_hack.c
diff --git a/lib/c/experimental/udp_hack.h b/lib/c/2014/experimental/udp_hack.h
similarity index 100%
rename from lib/c/experimental/udp_hack.h
rename to lib/c/2014/experimental/udp_hack.h
diff --git a/lib/c/labcomm.c b/lib/c/2014/labcomm.c
similarity index 98%
rename from lib/c/labcomm.c
rename to lib/c/2014/labcomm.c
index e14a980..a1994af 100644
--- a/lib/c/labcomm.c
+++ b/lib/c/2014/labcomm.c
@@ -37,8 +37,6 @@
 #include "labcomm_ioctl.h"
 #include "labcomm_dynamic_buffer_writer.h"
 
-#define CURRENT_VERSION "LabComm2014"
-
 /* Unwrapping reader/writer functions */
 #define UNWRAP_ac(rw, ac, ...) ac
 #define UNWRAP(func, ...)	     \
@@ -158,7 +156,7 @@ const char *labcomm_error_get_str(enum labcomm_error error_id)
   return error_str;
 }
 
-void on_error_fprintf(enum labcomm_error error_id, size_t nbr_va_args, ...)
+void labcomm2014_on_error_fprintf(enum labcomm_error error_id, size_t nbr_va_args, ...)
 {
 #ifndef LABCOMM_NO_STDIO
   const char *err_msg = labcomm_error_get_str(error_id); // The final string to print.
diff --git a/lib/c/labcomm.h b/lib/c/2014/labcomm.h
similarity index 98%
rename from lib/c/labcomm.h
rename to lib/c/2014/labcomm.h
index 5b60299..4bc6b6c 100644
--- a/lib/c/labcomm.h
+++ b/lib/c/2014/labcomm.h
@@ -70,7 +70,7 @@ typedef void (*labcomm_error_handler_callback)(enum labcomm_error error_id,
 /* Default error handler, prints message to stderr. 
  * Extra info about the error can be supplied as char* as VA-args. Especially user defined errors should supply a describing string. if nbr_va_args > 1 the first variable argument must be a printf format string and the possibly following arguments are passed as va_args to vprintf. 
  */
-void on_error_fprintf(enum labcomm_error error_id, size_t nbr_va_args, ...);
+void labcomm2014_on_error_fprintf(enum labcomm_error error_id, size_t nbr_va_args, ...);
 
 /* Register a callback for the error handler for this encoder. */
 void labcomm_register_error_handler_encoder(struct labcomm_encoder *encoder, labcomm_error_handler_callback callback);
diff --git a/lib/c/labcomm_compat_arm_cortexm3.h b/lib/c/2014/labcomm_compat_arm_cortexm3.h
similarity index 100%
rename from lib/c/labcomm_compat_arm_cortexm3.h
rename to lib/c/2014/labcomm_compat_arm_cortexm3.h
diff --git a/lib/c/labcomm_compat_osx.h b/lib/c/2014/labcomm_compat_osx.h
similarity index 100%
rename from lib/c/labcomm_compat_osx.h
rename to lib/c/2014/labcomm_compat_osx.h
diff --git a/lib/c/labcomm_compat_vxworks.h b/lib/c/2014/labcomm_compat_vxworks.h
similarity index 100%
rename from lib/c/labcomm_compat_vxworks.h
rename to lib/c/2014/labcomm_compat_vxworks.h
diff --git a/lib/c/labcomm_decoder.c b/lib/c/2014/labcomm_decoder.c
similarity index 99%
rename from lib/c/labcomm_decoder.c
rename to lib/c/2014/labcomm_decoder.c
index f9efca7..54575ee 100644
--- a/lib/c/labcomm_decoder.c
+++ b/lib/c/2014/labcomm_decoder.c
@@ -71,7 +71,7 @@ struct labcomm_decoder *labcomm_decoder_new(
     result->error = error;
     result->memory = memory;
     result->scheduler = scheduler;
-    result->on_error = on_error_fprintf;
+    result->on_error = labcomm2014_on_error_fprintf;
     LABCOMM_SIGNATURE_ARRAY_INIT(result->local, struct sample_entry);
     LABCOMM_SIGNATURE_ARRAY_INIT(result->remote_to_local, int);
     LABCOMM_SIGNATURE_ARRAY_INIT(result->local_ref, 
diff --git a/lib/c/labcomm_default_error_handler.c b/lib/c/2014/labcomm_default_error_handler.c
similarity index 100%
rename from lib/c/labcomm_default_error_handler.c
rename to lib/c/2014/labcomm_default_error_handler.c
diff --git a/lib/c/labcomm_default_error_handler.h b/lib/c/2014/labcomm_default_error_handler.h
similarity index 100%
rename from lib/c/labcomm_default_error_handler.h
rename to lib/c/2014/labcomm_default_error_handler.h
diff --git a/lib/c/labcomm_default_memory.c b/lib/c/2014/labcomm_default_memory.c
similarity index 100%
rename from lib/c/labcomm_default_memory.c
rename to lib/c/2014/labcomm_default_memory.c
diff --git a/lib/c/labcomm_default_memory.h b/lib/c/2014/labcomm_default_memory.h
similarity index 100%
rename from lib/c/labcomm_default_memory.h
rename to lib/c/2014/labcomm_default_memory.h
diff --git a/lib/c/labcomm_default_scheduler.c b/lib/c/2014/labcomm_default_scheduler.c
similarity index 100%
rename from lib/c/labcomm_default_scheduler.c
rename to lib/c/2014/labcomm_default_scheduler.c
diff --git a/lib/c/labcomm_default_scheduler.h b/lib/c/2014/labcomm_default_scheduler.h
similarity index 100%
rename from lib/c/labcomm_default_scheduler.h
rename to lib/c/2014/labcomm_default_scheduler.h
diff --git a/lib/c/labcomm_dynamic_buffer_writer.c b/lib/c/2014/labcomm_dynamic_buffer_writer.c
similarity index 100%
rename from lib/c/labcomm_dynamic_buffer_writer.c
rename to lib/c/2014/labcomm_dynamic_buffer_writer.c
diff --git a/lib/c/labcomm_dynamic_buffer_writer.h b/lib/c/2014/labcomm_dynamic_buffer_writer.h
similarity index 100%
rename from lib/c/labcomm_dynamic_buffer_writer.h
rename to lib/c/2014/labcomm_dynamic_buffer_writer.h
diff --git a/lib/c/labcomm_encoder.c b/lib/c/2014/labcomm_encoder.c
similarity index 100%
rename from lib/c/labcomm_encoder.c
rename to lib/c/2014/labcomm_encoder.c
diff --git a/lib/c/labcomm_error.c b/lib/c/2014/labcomm_error.c
similarity index 100%
rename from lib/c/labcomm_error.c
rename to lib/c/2014/labcomm_error.c
diff --git a/lib/c/labcomm_error.h b/lib/c/2014/labcomm_error.h
similarity index 100%
rename from lib/c/labcomm_error.h
rename to lib/c/2014/labcomm_error.h
diff --git a/lib/c/labcomm_fd_reader.c b/lib/c/2014/labcomm_fd_reader.c
similarity index 100%
rename from lib/c/labcomm_fd_reader.c
rename to lib/c/2014/labcomm_fd_reader.c
diff --git a/lib/c/labcomm_fd_reader.h b/lib/c/2014/labcomm_fd_reader.h
similarity index 100%
rename from lib/c/labcomm_fd_reader.h
rename to lib/c/2014/labcomm_fd_reader.h
diff --git a/lib/c/labcomm_fd_writer.c b/lib/c/2014/labcomm_fd_writer.c
similarity index 100%
rename from lib/c/labcomm_fd_writer.c
rename to lib/c/2014/labcomm_fd_writer.c
diff --git a/lib/c/labcomm_fd_writer.h b/lib/c/2014/labcomm_fd_writer.h
similarity index 100%
rename from lib/c/labcomm_fd_writer.h
rename to lib/c/2014/labcomm_fd_writer.h
diff --git a/lib/c/labcomm_ioctl.h b/lib/c/2014/labcomm_ioctl.h
similarity index 100%
rename from lib/c/labcomm_ioctl.h
rename to lib/c/2014/labcomm_ioctl.h
diff --git a/lib/c/labcomm_memory.c b/lib/c/2014/labcomm_memory.c
similarity index 100%
rename from lib/c/labcomm_memory.c
rename to lib/c/2014/labcomm_memory.c
diff --git a/lib/c/labcomm_private.h b/lib/c/2014/labcomm_private.h
similarity index 99%
rename from lib/c/labcomm_private.h
rename to lib/c/2014/labcomm_private.h
index fc87365..95900fe 100644
--- a/lib/c/labcomm_private.h
+++ b/lib/c/2014/labcomm_private.h
@@ -275,7 +275,7 @@ static inline char *labcomm_read_string(struct labcomm_reader *r)
   length = labcomm_read_packed32(r);
   result = labcomm_memory_alloc(r->memory, 1, length + 1);
   if (!result) {
-    on_error_fprintf(LABCOMM_ERROR_MEMORY, 4, "%d byte at %s:%d",
+    labcomm2014_on_error_fprintf(LABCOMM_ERROR_MEMORY, 4, "%d byte at %s:%d",
 		     length+1, __FUNCTION__, __LINE__);
     return NULL;
   }
diff --git a/lib/c/labcomm_pthread_scheduler.c b/lib/c/2014/labcomm_pthread_scheduler.c
similarity index 100%
rename from lib/c/labcomm_pthread_scheduler.c
rename to lib/c/2014/labcomm_pthread_scheduler.c
diff --git a/lib/c/labcomm_pthread_scheduler.h b/lib/c/2014/labcomm_pthread_scheduler.h
similarity index 100%
rename from lib/c/labcomm_pthread_scheduler.h
rename to lib/c/2014/labcomm_pthread_scheduler.h
diff --git a/lib/c/labcomm_scheduler.c b/lib/c/2014/labcomm_scheduler.c
similarity index 100%
rename from lib/c/labcomm_scheduler.c
rename to lib/c/2014/labcomm_scheduler.c
diff --git a/lib/c/labcomm_scheduler.h b/lib/c/2014/labcomm_scheduler.h
similarity index 100%
rename from lib/c/labcomm_scheduler.h
rename to lib/c/2014/labcomm_scheduler.h
diff --git a/lib/c/labcomm_scheduler_private.h b/lib/c/2014/labcomm_scheduler_private.h
similarity index 100%
rename from lib/c/labcomm_scheduler_private.h
rename to lib/c/2014/labcomm_scheduler_private.h
diff --git a/lib/c/labcomm_time.c b/lib/c/2014/labcomm_time.c
similarity index 100%
rename from lib/c/labcomm_time.c
rename to lib/c/2014/labcomm_time.c
diff --git a/lib/c/2014/test/another_encoding.lc b/lib/c/2014/test/another_encoding.lc
new file mode 100644
index 0000000..2c545af
--- /dev/null
+++ b/lib/c/2014/test/another_encoding.lc
@@ -0,0 +1,2 @@
+sample void V;
+sample byte B;
diff --git a/lib/c/cppmacros.h b/lib/c/2014/test/cppmacros.h
similarity index 100%
rename from lib/c/cppmacros.h
rename to lib/c/2014/test/cppmacros.h
diff --git a/lib/c/test/generated_encoding.lc b/lib/c/2014/test/generated_encoding.lc
similarity index 100%
rename from lib/c/test/generated_encoding.lc
rename to lib/c/2014/test/generated_encoding.lc
diff --git a/lib/c/2014/test/labcomm_mem_reader.c b/lib/c/2014/test/labcomm_mem_reader.c
new file mode 100644
index 0000000..e111433
--- /dev/null
+++ b/lib/c/2014/test/labcomm_mem_reader.c
@@ -0,0 +1,80 @@
+#include "labcomm_mem_reader.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* This implementation assumes labcomm will call end exactly once after each start
+ * It is not allowed to save data in mcontext->enc_data,
+ * this pointer will be set to NULL after decoding.
+ */
+/* NOTE!!!!
+ * start will be run first, once a signature or a data section is decoded
+ * end will be run and then start again. If end of encoded data is reached this
+ * must be handled in start.
+ */
+
+// TODO make labcomm use result!
+int labcomm_mem_reader(labcomm_reader_t *r, 
+		       labcomm_reader_action_t action,
+		       ...)
+{
+  int result = -EINVAL;
+  labcomm_mem_reader_context_t *mcontext = (labcomm_mem_reader_context_t *) r->context;
+
+  switch (action) {
+    case labcomm_reader_alloc: {
+      r->data = NULL;
+      r->data_size = 0;
+      r->pos = 0;
+      r->count = 0;
+      } break;
+    case labcomm_reader_start: {
+      if (r->data == NULL && mcontext->enc_data != NULL) {
+        r->data = (unsigned char *) malloc(mcontext->size);
+        if(r->data != NULL) {
+          memcpy(r->data, mcontext->enc_data, mcontext->size);
+          r->data_size = mcontext->size;
+          r->count = mcontext->size;
+          r->pos = 0;
+          result = r->data_size;
+        } else {
+          r->data_size = 0;
+          result = -ENOMEM;
+        }
+      } else if (r->data == NULL && mcontext->enc_data == NULL) {
+        result = -1;
+      } else {
+        result = r->count - r->pos;
+      }
+    } break;
+    case labcomm_reader_continue: {
+      if (r->pos < r->count) {
+        result = r->count - r->pos;
+      } else {
+        // TODO set some describing error here
+        result = -1;
+      }
+    } break;
+    case labcomm_reader_end: {
+      if (r->pos >= r->count) {
+        free(r->data);
+        r->data = NULL;
+        r->data_size = 0;
+        mcontext->enc_data = NULL;
+        mcontext->size = 0;
+      }
+      result = r->count - r->pos;
+    } break;
+    case labcomm_reader_free: {
+      r->count = 0;
+      r->pos = 0;
+      result = 0;
+    } break;
+    case labcomm_reader_ioctl: {
+      result = -ENOTSUP;
+    }
+  }
+  return result;
+}
+
diff --git a/lib/c/2014/test/labcomm_mem_reader.h b/lib/c/2014/test/labcomm_mem_reader.h
new file mode 100644
index 0000000..55b8ea9
--- /dev/null
+++ b/lib/c/2014/test/labcomm_mem_reader.h
@@ -0,0 +1,19 @@
+#ifndef LABCOMM_MEM_READER_H
+#define LABCOMM_MEM_READER_H
+
+#include "labcomm.h"
+
+/* enc_data: The data to be decoded
+ * size: the size of the data to be decoded
+ */
+typedef struct labcomm_mem_reader_context_t labcomm_mem_reader_context_t;
+struct labcomm_mem_reader_context_t {
+  size_t size;
+  unsigned char *enc_data;
+};
+
+int labcomm_mem_reader(labcomm_reader_t *r, 
+		       labcomm_reader_action_t action,
+		       ...);
+
+#endif
diff --git a/lib/c/2014/test/labcomm_mem_writer.c b/lib/c/2014/test/labcomm_mem_writer.c
new file mode 100644
index 0000000..4370361
--- /dev/null
+++ b/lib/c/2014/test/labcomm_mem_writer.c
@@ -0,0 +1,146 @@
+#include "labcomm_mem_writer.h"
+
+#include <stddef.h>  // For size_t.
+#include <stdarg.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "labcomm.h"
+#include "cppmacros.h"
+
+#define BUFFER_SIZE 150 // Suitable size is at least the size of a fully encoded message. Found by inspecting size of file genreated from the labcomm_fs_reader_writer.c on the same message type.
+
+// Put encdoded data directly in mcontext->mbuf or malloc new temporary memory.
+// 1 == Allocate new memory.
+// 2 == Use mcontext->buf directly. But _beware_; you can not then later change 
+// mcontext->buf to something else since the writer gets a reference to this 
+// buffer!
+#if defined(MEM_WRITER_ENCODED_BUFFER) && (EMPTY(MEM_WRITER_ENCODED_BUFFER) != 1)
+  #define ENCODED_BUFFER MEM_WRITER_ENCODED_BUFFER
+#else
+  #define ENCODED_BUFFER 1
+#endif
+
+static int get_writer_available(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontext);
+static void copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontext, unsigned char *mbuf);
+
+/*
+ * Write encoded messages to memory. w->context is assumed to be a pointer to a
+ * labcomm_mem_writer_context_t structure.
+ */
+int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action, ...)
+{
+  int result = 0;
+  // Unwrap pointers for easy access.
+  labcomm_mem_writer_context_t *mcontext = (labcomm_mem_writer_context_t *) w->context;
+  unsigned char *mbuf = mcontext->buf;
+
+  switch (action) {
+  case labcomm_writer_alloc: {
+#if (ENCODED_BUFFER == 1)
+    w->data = malloc(BUFFER_SIZE); // Buffer that LabComm will use for putting the encoded data.
+    if (w->data == NULL) {
+      result = -ENOMEM;
+      w->data_size = 0;
+      w->count = 0;
+      w->pos = 0;
+    } else {
+      w->data_size = BUFFER_SIZE;
+      w->count = BUFFER_SIZE;
+      w->pos = 0;
+    }
+#elif (ENCODED_BUFFER == 2)
+    w->data = mbuf;
+    int bytes_left = (mcontext->length - mcontext->write_pos);
+    w->data_size = bytes_left;
+    w->count = bytes_left;
+    w->pos = mcontext->write_pos;
+#endif
+     } break;
+  case labcomm_writer_free:{
+#if (ENCODED_BUFFER == 1)
+    free(w->data);
+#endif
+    w->data = 0;
+    w->data_size = 0;
+    w->count = 0;
+    w->pos = 0;
+   } break;
+  case labcomm_writer_start:
+    case labcomm_writer_start_signature: {
+#if (ENCODED_BUFFER == 1)
+    w->pos = 0;
+#elif (ENCODED_BUFFER == 2)
+    w->pos = mcontext->write_pos;
+#endif
+    } break;
+  case labcomm_writer_continue:
+  case labcomm_writer_continue_signature: { 
+    // Encode-buffer(w->data) is full; empty/handle it. (w->pos == w->count) most likely.
+#if (ENCODED_BUFFER == 1)
+    copy_data(w, mcontext, mbuf);
+    result = w->pos; // Assume result here should be number of bytes written.
+    w->pos = 0;
+#elif (ENCODED_BUFFER == 2)
+    mcontext->write_pos = w->pos;
+#endif
+     result = 0;
+    } break;
+  case labcomm_writer_end:
+  case labcomm_writer_end_signature:{ // Nothing more to encode, handle encode-buffer(w->data).
+#if (ENCODED_BUFFER == 1)
+    copy_data(w, mcontext, mbuf);
+    result = w->pos;
+    w->pos = 0;
+#elif (ENCODED_BUFFER == 2)
+    mcontext->write_pos = w->pos;
+#endif
+    result = 0;
+    } break;
+  }
+  return result;
+}
+
+labcomm_mem_writer_context_t *labcomm_mem_writer_context_t_new(size_t init_pos, size_t length, unsigned char *buf)
+{
+  labcomm_mem_writer_context_t *mcontext = (labcomm_mem_writer_context_t *) malloc(sizeof(labcomm_mem_writer_context_t));
+  if (mcontext == NULL) {
+    //fprintf(stderr, "error: Can not allocate labcomm_mem_writer_context_t.\n");
+  } else {
+    mcontext->write_pos = init_pos;
+    mcontext->length = length;
+    mcontext->buf = buf;
+  }
+  return mcontext;
+}
+
+void labcomm_mem_writer_context_t_free(labcomm_mem_writer_context_t **mcontext)
+{
+  free(*mcontext);
+  *mcontext = NULL;
+}
+
+// Get the number of available bytes in the mcontext->buf buffer.
+static int get_writer_available(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontext)
+{
+  return (mcontext->length - mcontext->write_pos);
+}
+
+// Copy data from encoded buffer to mbuf.
+static void copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontext, unsigned char *mbuf)
+{
+        int writer_available = get_writer_available(w, mcontext);
+  if (( writer_available - w->pos) < 0) {
+    w->on_error(LABCOMM_ERROR_ENC_BUF_FULL, 3, "labcomm_writer_t->pos=%i, but available in mcontext is %i", w->pos, writer_available); 
+  } else {
+    int i;
+    for (i = 0; i < w->pos; ++i, mcontext->write_pos++) {
+      mbuf[mcontext->write_pos] = w->data[i];
+    }
+  }
+}
+
+void test_copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontext, unsigned char *mbuf)
+{
+  copy_data(w, mcontext, mbuf); 
+}
diff --git a/lib/c/2014/test/labcomm_mem_writer.h b/lib/c/2014/test/labcomm_mem_writer.h
new file mode 100644
index 0000000..7506342
--- /dev/null
+++ b/lib/c/2014/test/labcomm_mem_writer.h
@@ -0,0 +1,25 @@
+#ifndef LABCOMM_MEM_WRITER_H
+#define LABCOMM_MEM_WRITER_H
+
+#include "labcomm.h"
+
+/* Wrapper structure for the memory buffer including a writer position. */
+typedef struct labcomm_mem_writer_context_t labcomm_mem_writer_context_t;
+struct labcomm_mem_writer_context_t {
+  size_t write_pos;  // Position where next write should be.
+  size_t length;  // Length of the buffer.
+  unsigned char *buf;  // Allocated destination buffer.
+};
+
+int labcomm_mem_writer(labcomm_writer_t *w, labcomm_writer_action_t action, ...);
+
+/* Wrapper the internal static function copy_data. This is needed so that the exceptions can be unit tested. */
+void test_copy_data(labcomm_writer_t *w, labcomm_mem_writer_context_t *mcontext, unsigned char *mbuf);
+
+/* Allocate new labcomm_mem_writer_context_t. */
+labcomm_mem_writer_context_t *labcomm_mem_writer_context_t_new(size_t init_pos, size_t length, unsigned char *buf);
+
+/* Deallocate mcontext. */
+void labcomm_mem_writer_context_t_free(labcomm_mem_writer_context_t **mcontext);
+
+#endif
diff --git a/lib/c/2014/test/more_types.lc b/lib/c/2014/test/more_types.lc
new file mode 100644
index 0000000..91fb935
--- /dev/null
+++ b/lib/c/2014/test/more_types.lc
@@ -0,0 +1,7 @@
+sample string S;
+sample int A[8];
+sample struct {
+  string s1;
+  string s2;
+} NS;
+sample string AS[_];
diff --git a/lib/c/test/test_labcomm.c b/lib/c/2014/test/test_labcomm.c
similarity index 100%
rename from lib/c/test/test_labcomm.c
rename to lib/c/2014/test/test_labcomm.c
diff --git a/lib/c/test/test_labcomm_basic_type_encoding.c b/lib/c/2014/test/test_labcomm_basic_type_encoding.c
similarity index 100%
rename from lib/c/test/test_labcomm_basic_type_encoding.c
rename to lib/c/2014/test/test_labcomm_basic_type_encoding.c
diff --git a/lib/c/test/test_labcomm_copy.c b/lib/c/2014/test/test_labcomm_copy.c
similarity index 100%
rename from lib/c/test/test_labcomm_copy.c
rename to lib/c/2014/test/test_labcomm_copy.c
diff --git a/lib/c/2014/test/test_labcomm_errors.c b/lib/c/2014/test/test_labcomm_errors.c
new file mode 100644
index 0000000..7808504
--- /dev/null
+++ b/lib/c/2014/test/test_labcomm_errors.c
@@ -0,0 +1,173 @@
+#include "test_labcomm_errors.h"
+
+#include <stdlib.h>
+
+#include <labcomm.h>
+#include <labcomm_private.h>
+#include <labcomm_mem_writer.h>
+#include <labcomm_mem_reader.h>
+
+static enum labcomm_error callback_error_id;
+
+int assert_callback(enum labcomm_error expected, const char *name, const char *err_msg)
+{
+  int success;
+  printf("----> %s()\n", name);
+  if (callback_error_id == expected) {
+    printf("Succeeded.\n");
+    success = 1;
+  } else {
+    printf("Failed! %s\n", err_msg);
+    success = 0;
+  }
+  return success;
+}
+
+/* Our callback that just logs which error_id that the library reported. */
+void test_callback(enum labcomm_error error_id, size_t nbr_va_args, ...)
+{
+   va_list arg_pointer;
+   va_start(arg_pointer, nbr_va_args);
+   va_end(arg_pointer);
+   callback_error_id = error_id;
+}
+ 
+void reset_callback_erro_id()
+{
+  callback_error_id = -128;
+}
+
+int encoded_size_mock(struct labcomm_signature *signature, void *voidp)
+{
+  return 0;
+}
+
+int test_enc_not_reg_encoder_sign()
+{
+  reset_callback_erro_id();
+  unsigned char *buf = (unsigned char *) "a";
+  labcomm_mem_writer_context_t *mcontext = labcomm_mem_writer_context_t_new(0, 1, buf);
+  labcomm_encoder_t *encoder = labcomm_encoder_new(labcomm_mem_writer, mcontext);
+  labcomm_register_error_handler_encoder(encoder, test_callback);
+  
+  labcomm_signature_t signature = {
+    .type = 0, 
+    .name = "test_signature", 
+    .encoded_size = encoded_size_mock, 
+    .size = 0, 
+    .signature = (unsigned char *) "0"};
+  encoder->do_encode(encoder, &signature, NULL);
+
+  return assert_callback(LABCOMM_ERROR_ENC_NO_REG_SIGNATURE, __FUNCTION__, "");
+}
+
+int test_enc_missing_do_reg()
+{
+  reset_callback_erro_id();
+  unsigned char *buf = (unsigned char *) "a";
+  labcomm_mem_writer_context_t *mcontext = labcomm_mem_writer_context_t_new(0, 1, buf);
+  labcomm_encoder_t *encoder = labcomm_encoder_new(labcomm_mem_writer, mcontext);
+  labcomm_register_error_handler_encoder(encoder, test_callback);
+
+  encoder->do_register = NULL;
+  labcomm_internal_encoder_register(encoder, NULL, NULL);
+
+  return assert_callback(LABCOMM_ERROR_ENC_MISSING_DO_REG, __FUNCTION__, "");
+}
+
+int test_enc_missing_do_encode()
+{
+  reset_callback_erro_id();
+  unsigned char *buf = (unsigned char *) "a";
+  labcomm_mem_writer_context_t *mcontext = labcomm_mem_writer_context_t_new(0, 1, buf);
+  labcomm_encoder_t *encoder = labcomm_encoder_new(labcomm_mem_writer, mcontext);
+  labcomm_register_error_handler_encoder(encoder, test_callback);
+
+  encoder->do_encode = NULL;
+  labcomm_internal_encode(encoder, NULL, NULL);
+
+  return assert_callback(LABCOMM_ERROR_ENC_MISSING_DO_ENCODE, __FUNCTION__, "");
+}
+
+int test_enc_buf_full()
+{
+  reset_callback_erro_id();
+  unsigned char *buf = (unsigned char *) "a";
+  labcomm_mem_writer_context_t *mcontext = labcomm_mem_writer_context_t_new(0, 1, buf);
+  labcomm_encoder_t *encoder = labcomm_encoder_new(labcomm_mem_writer, mcontext);
+  labcomm_register_error_handler_encoder(encoder, test_callback);
+
+  unsigned char *mbuf = mcontext->buf;
+  labcomm_writer_t writer = encoder->writer;
+  writer.data = malloc(1);
+  writer.pos = 1;
+  mcontext->write_pos = 1;
+  test_copy_data(&writer, mcontext, mbuf);
+
+  return assert_callback(LABCOMM_ERROR_ENC_BUF_FULL, __FUNCTION__, "");
+}
+
+void labcomm_decoder_typecast_t_mock(struct labcomm_decoder *decoder, labcomm_handler_typecast_t handler, void *voidp)
+{
+        ;
+}
+
+void labcomm_handler_typecast_t_mock(void *arg1, void *arg2)
+{
+        ;
+}
+
+int test_dec_missing_do_reg()
+{
+  reset_callback_erro_id();
+  unsigned char *buf = (unsigned char *) "a";
+  labcomm_mem_reader_context_t *mcontext = (labcomm_mem_reader_context_t *) malloc(sizeof(labcomm_mem_reader_context_t));
+  labcomm_decoder_t *decoder = labcomm_decoder_new(labcomm_mem_reader, mcontext);
+  labcomm_register_error_handler_decoder(decoder, test_callback);
+  
+  decoder->do_register = NULL;
+  labcomm_internal_decoder_register(decoder, NULL, labcomm_decoder_typecast_t_mock, labcomm_handler_typecast_t_mock, buf);
+
+  return assert_callback(LABCOMM_ERROR_DEC_MISSING_DO_REG, __FUNCTION__, "");
+}
+
+int test_dec_missing_do_decode_one()
+{
+  reset_callback_erro_id();
+  labcomm_mem_reader_context_t *mcontext = (labcomm_mem_reader_context_t *) malloc(sizeof(labcomm_mem_reader_context_t));
+  labcomm_decoder_t *decoder = labcomm_decoder_new(labcomm_mem_reader, mcontext);
+  labcomm_register_error_handler_decoder(decoder, test_callback);
+  
+  decoder->do_decode_one = NULL;
+  labcomm_decoder_decode_one(decoder);
+
+  return assert_callback(LABCOMM_ERROR_DEC_MISSING_DO_DECODE_ONE, __FUNCTION__, "");
+}
+
+int main()
+{
+  printf("####> Begin tests.\n");
+  unsigned int nbr_succeed = 0;
+  unsigned int nbr_tests = 6; // Increment this when new tests are written.
+  nbr_succeed += test_enc_not_reg_encoder_sign();
+  nbr_succeed += test_enc_missing_do_reg();
+  nbr_succeed += test_enc_missing_do_encode();
+  nbr_succeed += test_enc_buf_full();
+  nbr_succeed += test_dec_missing_do_reg();
+  nbr_succeed += test_dec_missing_do_decode_one();
+
+  // Too tedius to test really...
+  //nbr_succeed += test_dec_unknown_datatype();
+  //nbr_succeed += test_dec_index_mismatch();
+  //nbr_succeed += test_dec_type_not_found();
+
+  //nbr_succeed += test_unimplemented_func(); // This test will be obsolete in the future ;-)
+  //nbr_succeed += test_user_def();           // There are no user defined errors in the library of course.
+
+  printf("####> End tests.\nSummary: %u/%u tests succeed.\n", nbr_succeed, nbr_tests);
+  if (nbr_succeed == nbr_tests) {
+	  return EXIT_SUCCESS;
+  } else {
+  	  return EXIT_FAILURE;
+  }
+}
diff --git a/lib/c/2014/test/test_labcomm_errors.h b/lib/c/2014/test/test_labcomm_errors.h
new file mode 100644
index 0000000..8cc3918
--- /dev/null
+++ b/lib/c/2014/test/test_labcomm_errors.h
@@ -0,0 +1,6 @@
+#ifndef TEST_LABCOMM_ERRORS_H
+#define TEST_LABCOMM_ERRORS_H
+
+void test_not_reg_encoder_sign();
+
+#endif
diff --git a/lib/c/test/test_labcomm_generated_encoding.c b/lib/c/2014/test/test_labcomm_generated_encoding.c
similarity index 100%
rename from lib/c/test/test_labcomm_generated_encoding.c
rename to lib/c/2014/test/test_labcomm_generated_encoding.c
diff --git a/lib/c/test/test_labcomm_pthread_scheduler.c b/lib/c/2014/test/test_labcomm_pthread_scheduler.c
similarity index 100%
rename from lib/c/test/test_labcomm_pthread_scheduler.c
rename to lib/c/2014/test/test_labcomm_pthread_scheduler.c
diff --git a/lib/c/2014/test/test_sample.lc b/lib/c/2014/test/test_sample.lc
new file mode 100644
index 0000000..bac6bb6
--- /dev/null
+++ b/lib/c/2014/test/test_sample.lc
@@ -0,0 +1 @@
+sample int test_var[_,_];
diff --git a/lib/c/test/test_signature_numbers.c b/lib/c/2014/test/test_signature_numbers.c
similarity index 100%
rename from lib/c/test/test_signature_numbers.c
rename to lib/c/2014/test/test_signature_numbers.c
diff --git a/lib/c/Makefile b/lib/c/Makefile
index 8a3f47c..6067a26 100644
--- a/lib/c/Makefile
+++ b/lib/c/Makefile
@@ -1,173 +1,6 @@
-## Macros
-include os_compat.mk
+VERSIONS=2006 2014
 
-ALL_DEPS=liblabcomm.a liblabcomm.so.1 liblabcomm2006.a liblabcomm2006.so.1  liblabcomm2014.a liblabcomm2014.so.1
+all:
 
-# TODO: Support for Codesourcery ARM toolchain.
-
-OBJS2006=2006/labcomm2006_memory.o \
-     2006/labcomm2006_error.o \
-     2006/labcomm2006_default_error_handler.o \
-     2006/labcomm2006_default_memory.o \
-     2006/labcomm2006_default_scheduler.o \
-     2006/labcomm2006_time.o 2006/labcomm2006_scheduler.o \
-     2006/labcomm2006_encoder.o 2006/labcomm2006_decoder.o \
-     2006/labcomm2006.o \
-     2006/labcomm2006_dynamic_buffer_writer.o \
-     2006/labcomm2006_fd_reader.o 2006/labcomm2006_fd_writer.o \
-     2006/labcomm2006_pthread_scheduler.o 
-
-OBJS=labcomm_memory.o \
-     labcomm_error.o \
-     labcomm_default_error_handler.o \
-     labcomm_default_memory.o \
-     labcomm_default_scheduler.o \
-     labcomm_time.o labcomm_scheduler.o \
-     labcomm_encoder.o labcomm_decoder.o \
-     labcomm.o \
-     labcomm_dynamic_buffer_writer.o \
-     labcomm_fd_reader.o labcomm_fd_writer.o \
-     labcomm_pthread_scheduler.o 
-
-#FIXME: labcomm_mem_reader.o labcomm_mem_writer.o
-LABCOMM_JAR=../../compiler/labcomm_compiler.jar
-LABCOMM=java -jar $(LABCOMM_JAR) 
-
-TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
-      test_signature_numbers \
-      test_labcomm \
-      test_labcomm_pthread_scheduler \
-      test_labcomm_copy
-#
-#FIXME: test_labcomm test_labcomm_errors
-TEST_DIR=test
-
-VPATH=$(TEST_DIR)
-
-# Enable experimental objects by invoking make like `make LABCOMM_EXPERIMENTAL=true`
-ifeq ($(LABCOMM_EXPERIMENTAL),true)
-	OBJS += experimental/udp_hack.o experimental/ethaddr.o \
-		experimental/labcomm_thr_reader_writer.o \
-		experimental/ThrottleDrv/ethernet_drv.o \
-		experimental/ThrottleDrv/throttle_drv.o \
-		experimental/labcomm_udp_reader_writer.o\
-		experimental/labcomm_sig_parser.o 
-
-
-experimental/test_sig_parser : experimental/labcomm_sig_parser.o experimental/test_sig_parser.c
-endif
-
-## Targets
-
-.PHONY: all run-test clean distclean
-
-all: $(ALL_DEPS)
-
-liblabcomm.a: $(OBJS) $(OBJS2006)
-	ar -r $@ $^
-
-liblabcomm.so.1: $(OBJS:%.o=%.pic.o) $(OBJS2006:%.o=%.pic.o)
-	$(call MAKESHARED,$@,$@,$^)
-
-liblabcomm2014.a: $(OBJS)
-	ar -r $@ $^
-
-liblabcomm2014.so.1: $(OBJS:%.o=%.pic.o)
-	$(call MAKESHARED,$@,$@,$^)
-
-liblabcomm2006.a: $(OBJS2006)
-	ar -r $@ $^
-
-liblabcomm2006.so.1: $(OBJS2006:%.o=%.pic.o)
-	$(call MAKESHARED,$@,$@,$^)
-
-labcomm.o : labcomm.c labcomm.h  labcomm_private.h
-
-labcomm_fd_reader_writer.o : labcomm_fd_reader_writer.c  labcomm_fd_reader_writer.h  labcomm.h  labcomm_private.h
-
-2006/labcomm2006.o : 2006/labcomm2006.c 2006/labcomm2006.h  2006/labcomm2006_private.h
-
-2006/labcomm2006_fd_reader_writer.o : 2006/labcomm2006_fd_reader_writer.c  2006/labcomm2006_fd_reader_writer.h  labcomm.h  2006/labcomm2006_private.h
-
-#$(TEST_DIR)/labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h
-
-#$(TEST_DIR)/labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h
-
-ethaddr.o: ethaddr.c
-
-run-test: $(TESTS:%=run-test-%)
-
-run-test-%: $(TEST_DIR)/% | $(TEST_DIR)
-	$<
-
-$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
-	$(CC) $(CFLAGS) -o $@ -c $<
-
-.PRECIOUS: $(TEST_DIR)/%
-$(TEST_DIR)/%: $(TEST_DIR)/%.o 
-	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) 
-
-$(TEST_DIR)/gen:
-	mkdir -p $@
-
-.PRECIOUS: $(TEST_DIR)/gen/%.c
-.PRECIOUS: $(TEST_DIR)/gen/%.h
-$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
-	$(LABCOMM) \
-		--c=$(TEST_DIR)/gen/$*.c \
-		--h=$(TEST_DIR)/gen/$*.h \
-		$<
-
-$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
-					 $(LABCOMM_JAR) | $(TEST_GEN_DIR)
-	$(LABCOMM) \
-		--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
-
-$(LABCOMM_JAR):
-	@echo "======Building LabComm compiler======"
-	cd $(shell dirname $(LABCOMM_JAR)); ant jar
-	@echo "======End building LabComm compiler======"
-
-%.pic.o:	%.c
-	$(CC) -fPIC $(CFLAGS) -c -o $@ $<
-
-%.o: %.c %.h
-
-clean:
-	$(RM) *.o
-	$(RM) 2006/*.o
-	$(RM) experimental/*.o experimental/ThrottleDrv/*.o
-	$(RM) test/*.o
-	$(RM) test/*.gch
-	$(RM) test/test_labcomm_errors
-	$(RM) test/testdata/gen/*.[cho]
-	$(RM) test/gen/*.[cho]
-	-rmdir test/gen
-	for x in $(TESTS); do \
-		$(RM) $(TEST_DIR)/$$x ; \
-	done
-
-distclean: clean
-	$(RM) liblabcomm.so.1
-	$(RM) liblabcomm.a
-	$(RM) liblabcomm2006.so.1
-	$(RM) liblabcomm2006.a
-	$(RM) liblabcomm2014.so.1
-	$(RM) liblabcomm2014.a
-
-# Extra dependencies
-$(TEST_DIR)/test_labcomm_basic_type_encoding.o: labcomm_private.h
-
-$(TEST_DIR)/test_labcomm_generated_encoding.o: labcomm_private.h
-$(TEST_DIR)/test_labcomm_generated_encoding.o: $(TEST_DIR)/gen/generated_encoding.h
-$(TEST_DIR)/test_labcomm_generated_encoding : $(TEST_DIR)/gen/generated_encoding.o
-
-$(TEST_DIR)/test_labcomm:  $(TEST_DIR)/gen/test_sample.o
-$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/another_encoding.h
-$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/generated_encoding.h
-$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/another_encoding.o
-$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/generated_encoding.o
-$(TEST_DIR)/test_labcomm_copy:  $(TEST_DIR)/gen/generated_encoding.o $(TEST_DIR)/gen/test_sample.o $(TEST_DIR)/gen/more_types.o
-labcomm_fd_reader.o: labcomm_private.h
-labcomm_fd_writer.o: labcomm_private.h
-labcomm_dynamic_buffer_writer.o: labcomm_private.h
+%: 
+	for v in $(VERSIONS) ; do $(MAKE) -C $${v} $@ || exit 1 ; done
diff --git a/lib/c/labcomm.linkscript b/lib/c/labcomm.linkscript
deleted file mode 100644
index 1e3397a..0000000
--- a/lib/c/labcomm.linkscript
+++ /dev/null
@@ -1,12 +0,0 @@
-/* Hack to get a link error with (hopefully) useful information if not linked
-   with -Tlabcomm.linkscript */
-"You need to link with '-Tlabcomm.linkscript'"=0;
-
-SECTIONS { 
-  labcomm : {
-    labcomm_first_signature = ABSOLUTE(.) ;
-    *(labcomm)
-    labcomm_last_signature = ABSOLUTE(.) ;
-  }
-}
-INSERT AFTER .data;
diff --git a/lib/c/liblabcomm.so b/lib/c/liblabcomm.so
deleted file mode 120000
index 8b0c62d..0000000
--- a/lib/c/liblabcomm.so
+++ /dev/null
@@ -1 +0,0 @@
-liblabcomm.so.1
\ No newline at end of file
diff --git a/lib/c/os_compat.mk b/lib/c/os_compat.mk
index 553d0b1..23366e3 100644
--- a/lib/c/os_compat.mk
+++ b/lib/c/os_compat.mk
@@ -2,11 +2,12 @@
 UNAME_S=$(shell uname -s)
 
 ifeq ($(UNAME_S),Linux)
-  CFLAGS=-std=c99 -g -Wall -Werror -O3  -I. -Itest -I2006
   CC=$(CROSS_COMPILE)gcc
-  LD=$(CROSS_COMPILE)ld
-  LDFLAGS=-L.
-  LDLIBS=-llabcomm -llabcomm2006 -lrt
+  LD=$(CROSS_COMPILE)gcc
+  CFLAGS=-std=c99 -g -Wall -Werror -O3  -I. 
+  CFLAGS_TEST=$(CFLAGS) -Itest
+  LDFLAGS=-L..
+  LDLIBS=-llabcomm$(LIBVERSION) -lrt
   MAKESHARED=gcc -o $1 -shared -Wl,-soname,$2 $3 -lc -lrt
 else ifeq ($(UNAME_S),Darwin)
   CC=$(CROSS_COMPILE)clang
@@ -14,19 +15,20 @@ else ifeq ($(UNAME_S),Darwin)
   CFLAGS=-g -Wall -Werror -O3  -I. -Itest \
 	 -DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
 	 -Wno-tautological-compare -Wno-unused-function
-  LDFLAGS=-L.
-  LDLIBS=-llabcomm -llabcomm2006 
+  LDFLAGS=-L..
+  LDLIBS=-llabcomm$(LIBVERSION)
   MAKESHARED=clang -o $1 -shared -Wl,-install_name,$2 $3 -lc
 else ifneq ($(findstring CYGWIN,$(UNAME_S)),)
-  CFLAGS=-std=c99 -g -Wall -Werror -O3  -I. -Itest
   CC=$(CROSS_COMPILE)gcc
   LD=$(CROSS_COMPILE)ld
-  LDFLAGS=-L.
-  LDLIBS=-llabcomm -lrt
+  CFLAGS=-std=c99 -g -Wall -Werror -O3  -I. 
+  LDFLAGS=-L..
+  LDLIBS=-llabcomm$(LIBVERSION) -lrt
   ALL_DEPS:=$(filter-out %.so.1, $(ALL_DEPS)) # No -fPIC supported in windows?
 else
   $(error Unknown system $(UNAME_S))
 endif
+CFLAGS_TEST=$(CFLAGS) -Itest -DVERSION=$(VERSION)
 
 ifeq ($(CROSS_COMPILE),i586-wrs-vxworks-)
   ALL_DEPS:=$(filter-out %.so.1, $(ALL_DEPS)) # PIC is only supported for RTPs
diff --git a/lib/c/version_compare.py b/lib/c/version_compare.py
new file mode 100755
index 0000000..1b04ee7
--- /dev/null
+++ b/lib/c/version_compare.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+
+import os
+import sys
+import difflib
+import re
+
+class File:
+
+    def __init__(self, path, match, replacement):
+        def replace(s):
+            return re.sub('[ \t]+', ' ', s).replace(match, replacement)
+        self.name = path.replace(match, replacement)
+        self.path = path
+        with open(path) as f:
+            self.lines = map(replace, f.readlines())
+
+    def __cmp__(self, other):
+        if other == None:
+            return cmp(self.name, other)
+        return cmp(self.name, other.name)
+
+def readfiles(root, match, replacement):
+    result = []
+    for n in os.listdir(root):
+        path = os.path.join(root, n)
+        if os.path.islink(path):
+            pass
+        elif os.path.isdir(path):
+            for f in filter(None, readfiles(path, match, replacement)):
+                result.append(f)
+        else:
+            result.append(File(path, match, replacement))
+    for f in sorted(result):
+        yield f
+    yield None
+
+if __name__ == '__main__':
+    A = readfiles(*sys.argv[1:4])
+    B = readfiles(*sys.argv[4:7])
+    a = A.next()
+    b = B.next()
+    while a != None or b != None:
+        if b == None or a.name < b.name:
+            print "Only in %s:" %sys.argv[1], a.path
+            a = A.next()
+        elif a == None or a.name > b.name: 
+            print "Only in %s:" %sys.argv[4], b.path
+            b = B.next()
+        else:
+            print a.path, b.path
+            print ''.join(difflib.unified_diff(a.lines, b.lines, 
+                                                 a.path, b.path))
+            a = A.next() 
+            b = B.next() 
diff --git a/test/Makefile b/test/Makefile
index 128a5e4..0293534 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -65,8 +65,8 @@ gen/%/c_relay.c: gen/%/typeinfo relay_gen_c.py Makefile
 
 .PRECIOUS: gen/%/c_relay
 gen/%/c_relay: gen/%/c_relay.c gen/%/c_code.c Makefile
-	$(CC) $(CFLAGS) -o $@ $< -I../lib/c -I. -L..//lib/c \
-		gen/$*/c_code.c -llabcomm
+	$(CC) $(CFLAGS) -o $@ $< -I../lib/c/2014 -I. -L../lib/c \
+		gen/$*/c_code.c -llabcomm2014
 
 # C# relay test rules
 .PRECIOUS: gen/%/cs_code.cs
-- 
GitLab