diff --git a/INSTALL.md b/INSTALL.md
index 5162e704972513f43923b91aacd97d51a1a35010..70a4e0c93824557bbba73313085c476c6502d8c7 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -45,7 +45,7 @@ cd builddir
 meson compile cmp_tool
 ```
 
-Now you should find the cmp\_tool executable in the folder.
+Now you should find the cmp\_tool executable in the programs folder.
 
 ### Release Build
 
@@ -57,7 +57,7 @@ cd build_relase_dir
 meson compile cmp_tool
 ```
 
-You find the build executable in the `build_relase_dir` directory
+You find the build cmp\_tool executable in the `build_relase_dir/programs` directory.
 
 ### Build for Windows
 
diff --git a/doc/doxygen/meson.build b/doc/doxygen/meson.build
index 5c6a0d038f73c447de4b10b8b2ed0918d6ca4a07..05010211d9d8214aaa22a5969fafaf80ca3c3643 100644
--- a/doc/doxygen/meson.build
+++ b/doc/doxygen/meson.build
@@ -37,7 +37,7 @@ if doxygen.found()
   custom_target('doc',
     input : doxy_file,
     output : 'generated_documentation',
-    depend_files : [doxy_file, doc_layout_files, doxygen_awesome_css_files, main, cmplib_sources], # test files are missing
+    depend_files : [doxy_file, doc_layout_files, doxygen_awesome_css_files, cmp_tool_src, common_sources, decompress_sources, icu_compress_sources, rdcu_compress_sources], # test files are missing
     command : [doxygen, '@INPUT@'],
     build_by_default : false,
     console : true,
diff --git a/include/meson.build b/include/meson.build
index 491eef5ecebc527e3df0fb677d7e81907bcb9895..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -1,13 +0,0 @@
-# generate the configuration file
-cdata = configuration_data()
-cdata.set_quoted('PROGRAM_NAME', 'cmp_tool')
-cdata.set_quoted('CMP_TOOL_VERSION', meson.project_version())
-if get_option('argument_input_mode')
-  cdata.set('ARGUMENT_INPUT_MODE', '')
-endif
-
-configure_file(
-  output : 'cmp_tool-config.h',
-  configuration : cdata)
-
-incdir = include_directories('.')
diff --git a/include/cmp_icu.h b/lib/cmp_icu.h
similarity index 98%
rename from include/cmp_icu.h
rename to lib/cmp_icu.h
index 9fc0f42f4446386022314d2920be393bc2675b29..1dedf3ebda3cb13d2b7082fc7a7b7d34457dabac 100644
--- a/include/cmp_icu.h
+++ b/lib/cmp_icu.h
@@ -20,7 +20,7 @@
 #ifndef CMP_ICU_H
 #define CMP_ICU_H
 
-#include <cmp_support.h>
+#include "common/cmp_support.h"
 
 #define CMP_PAR_UNUSED 0
 
diff --git a/include/cmp_rdcu.h b/lib/cmp_rdcu.h
similarity index 96%
rename from include/cmp_rdcu.h
rename to lib/cmp_rdcu.h
index 0e4ef1c0b905bc81a7df24c516bea97946b4e0d4..30bf45e3d71c6d25483da9a59e174eb74951f509 100644
--- a/include/cmp_rdcu.h
+++ b/lib/cmp_rdcu.h
@@ -20,8 +20,8 @@
 #ifndef CMP_RDCU_H
 #define CMP_RDCU_H
 
-#include <cmp_support.h>
-#include <cmp_rdcu_cfg.h>
+#include "common/cmp_support.h"
+#include "rdcu_compress/cmp_rdcu_cfg.h"
 
 
 /* Compression Error Register bits definition, see RDCU-FRS-FN-0952 */
diff --git a/include/byteorder.h b/lib/common/byteorder.h
similarity index 100%
rename from include/byteorder.h
rename to lib/common/byteorder.h
diff --git a/include/cmp_cal_up_model.h b/lib/common/cmp_cal_up_model.h
similarity index 100%
rename from include/cmp_cal_up_model.h
rename to lib/common/cmp_cal_up_model.h
diff --git a/lib/cmp_data_types.c b/lib/common/cmp_data_types.c
similarity index 99%
rename from lib/cmp_data_types.c
rename to lib/common/cmp_data_types.c
index 00861cd9f5514cac64f5603206db98d9307875e5..ef9ae20ccf44a45e05b63604b1446f9c9d53198a 100644
--- a/lib/cmp_data_types.c
+++ b/lib/common/cmp_data_types.c
@@ -20,12 +20,10 @@
 #include <stdint.h>
 #include <limits.h>
 
-
-#include <cmp_support.h>
-#include <cmp_data_types.h>
-#include <cmp_debug.h>
-#include <byteorder.h>
-
+#include "byteorder.h"
+#include "cmp_debug.h"
+#include "cmp_support.h"
+#include "cmp_data_types.h"
 
 
 /**
diff --git a/include/cmp_data_types.h b/lib/common/cmp_data_types.h
similarity index 99%
rename from include/cmp_data_types.h
rename to lib/common/cmp_data_types.h
index e10ae811fb269c34f8eec662ea12545646cd881d..4a25ff02dcdb3d13fba0449fba6ce0e2fb7691b2 100644
--- a/include/cmp_data_types.h
+++ b/lib/common/cmp_data_types.h
@@ -36,8 +36,8 @@
 
 #include <stdint.h>
 
-#include <compiler.h>
-#include <cmp_support.h>
+#include "compiler.h"
+#include "../common/cmp_support.h"
 
 
 /* size of the source data header structure for multi entry packet */
diff --git a/include/cmp_debug.h b/lib/common/cmp_debug.h
similarity index 100%
rename from include/cmp_debug.h
rename to lib/common/cmp_debug.h
diff --git a/lib/cmp_entity.c b/lib/common/cmp_entity.c
similarity index 99%
rename from lib/cmp_entity.c
rename to lib/common/cmp_entity.c
index 5f9c9f01a1c8943ad2b8defe051fb9d7475e5c94..f79e8cf840b45e4cc5b86431e81370e0aba29d1d 100644
--- a/lib/cmp_entity.c
+++ b/lib/common/cmp_entity.c
@@ -19,8 +19,8 @@
 
 
 #include <stdint.h>
-#include <stdio.h>
 #include <string.h>
+#include <stdio.h>
 
 #ifndef ICU_ASW
 #  if defined __has_include
@@ -33,12 +33,12 @@
 #  endif
 #endif
 
-#include <byteorder.h>
-#include <cmp_debug.h>
-#include <cmp_support.h>
-#include <cmp_data_types.h>
-#include <cmp_entity.h>
-#include <leon_inttypes.h>
+#include "byteorder.h"
+#include "cmp_debug.h"
+#include "cmp_support.h"
+#include "cmp_data_types.h"
+#include "cmp_entity.h"
+#include "leon_inttypes.h"
 
 
 #ifdef HAS_TIME_H
@@ -1725,7 +1725,7 @@ int32_t cmp_ent_get_cmp_data(struct cmp_entity *ent, uint32_t *data_buf,
 		uint32_t cmp_data_len_32;
 
 		if (cmp_size_byte > data_buf_size) {
-			fprintf(stderr, "Error: data_buf size to small to hold the data.\n");
+			debug_print("Error: data_buf size to small to hold the data.\n");
 			return -1;
 		}
 
diff --git a/include/cmp_entity.h b/lib/common/cmp_entity.h
similarity index 99%
rename from include/cmp_entity.h
rename to lib/common/cmp_entity.h
index 8efff2459e561cc9717db22b1d911ecf9907b545..93e27e66d838d7978d7476ec07177163921c0bac 100644
--- a/include/cmp_entity.h
+++ b/lib/common/cmp_entity.h
@@ -29,8 +29,8 @@
 
 #include <stdint.h>
 
-#include <compiler.h>
-#include <cmp_support.h>
+#include "compiler.h"
+#include "cmp_support.h"
 
 
 #define GENERIC_HEADER_SIZE 32
diff --git a/lib/cmp_max_used_bits.c b/lib/common/cmp_max_used_bits.c
similarity index 99%
rename from lib/cmp_max_used_bits.c
rename to lib/common/cmp_max_used_bits.c
index 553c0a5c3a21782d78532252cde2c720eaf41359..eaedea3d83e203a960ef056e4bd7fd9c99bbeffa 100644
--- a/lib/cmp_max_used_bits.c
+++ b/lib/common/cmp_max_used_bits.c
@@ -19,7 +19,7 @@
 
 #include <stdint.h>
 
-#include <cmp_data_types.h>
+#include "cmp_data_types.h"
 
 
 #define MAX_USED_NC_IMAGETTE_BITS		16
diff --git a/include/cmp_max_used_bits.h b/lib/common/cmp_max_used_bits.h
similarity index 100%
rename from include/cmp_max_used_bits.h
rename to lib/common/cmp_max_used_bits.h
diff --git a/lib/cmp_support.c b/lib/common/cmp_support.c
similarity index 99%
rename from lib/cmp_support.c
rename to lib/common/cmp_support.c
index 77003ac3895635567becff44d68e595a0e196b80..24cfaaab12a17bbb01b1ef1b919e4471bdfc8689 100644
--- a/lib/cmp_support.c
+++ b/lib/common/cmp_support.c
@@ -17,11 +17,11 @@
  * @see Data Compression User Manual PLATO-UVIE-PL-UM-0001
  */
 
-#include <compiler.h>
+#include "compiler.h"
 
-#include <cmp_support.h>
-#include <cmp_debug.h>
-#include <leon_inttypes.h>
+#include "cmp_support.h"
+#include "cmp_debug.h"
+#include "leon_inttypes.h"
 
 
 /**
diff --git a/include/cmp_support.h b/lib/common/cmp_support.h
similarity index 99%
rename from include/cmp_support.h
rename to lib/common/cmp_support.h
index 3212703ef927e7935454d8fc7c962970739b8cbe..aee7bbb3764ede0ef4527a5ff93440a52d4d9237 100644
--- a/include/cmp_support.h
+++ b/lib/common/cmp_support.h
@@ -22,8 +22,8 @@
 #include <stdint.h>
 #include <stddef.h>
 
-#include <cmp_max_used_bits.h>
-#include <cmp_cal_up_model.h>
+#include "cmp_max_used_bits.h"
+#include "cmp_cal_up_model.h"
 
 
 /* return code if the bitstream buffer is too small to store the whole bitstream */
diff --git a/include/compiler.h b/lib/common/compiler.h
similarity index 100%
rename from include/compiler.h
rename to lib/common/compiler.h
diff --git a/include/leon_inttypes.h b/lib/common/leon_inttypes.h
similarity index 100%
rename from include/leon_inttypes.h
rename to lib/common/leon_inttypes.h
diff --git a/include/list.h b/lib/common/list.h
similarity index 100%
rename from include/list.h
rename to lib/common/list.h
diff --git a/lib/common/meson.build b/lib/common/meson.build
new file mode 100644
index 0000000000000000000000000000000000000000..c4d8b68cca24c0148eddfc042604639d236760dd
--- /dev/null
+++ b/lib/common/meson.build
@@ -0,0 +1,6 @@
+common_sources = files([
+  'cmp_data_types.c',
+  'cmp_entity.c',
+  'cmp_max_used_bits.c',
+  'cmp_support.c'
+])
diff --git a/include/decmp.h b/lib/decmp.h
similarity index 100%
rename from include/decmp.h
rename to lib/decmp.h
diff --git a/lib/cmp_max_used_bits_list.c b/lib/decompress/cmp_max_used_bits_list.c
similarity index 97%
rename from lib/cmp_max_used_bits_list.c
rename to lib/decompress/cmp_max_used_bits_list.c
index dfcec17a1856829e03a9a41feecaef150f10f121..f4844ffc58da55b555523afe7281315fd0ae9491 100644
--- a/lib/cmp_max_used_bits_list.c
+++ b/lib/decompress/cmp_max_used_bits_list.c
@@ -22,8 +22,8 @@
 
 #include <stdlib.h>
 
-#include <list.h>
-#include <cmp_max_used_bits.h>
+#include "../common/list.h"
+#include "../common/cmp_max_used_bits.h"
 
 
 struct list_item {
diff --git a/include/cmp_max_used_bits_list.h b/lib/decompress/cmp_max_used_bits_list.h
similarity index 96%
rename from include/cmp_max_used_bits_list.h
rename to lib/decompress/cmp_max_used_bits_list.h
index b533b01f19e366688766c260d70b55aeff07b12e..35506c2ffca24601aed6d4bd6de3769c89e34128 100644
--- a/include/cmp_max_used_bits_list.h
+++ b/lib/decompress/cmp_max_used_bits_list.h
@@ -25,7 +25,7 @@
 
 #include <stdint.h>
 
-#include <cmp_data_types.h>
+#include "../common/cmp_data_types.h"
 
 
 struct cmp_max_used_bits *cmp_max_used_bits_list_get(uint8_t version);
diff --git a/lib/decmp.c b/lib/decompress/decmp.c
similarity index 99%
rename from lib/decmp.c
rename to lib/decompress/decmp.c
index 1fe53c3fb4014f33730d78472a5b49527e9005b6..f73cb6313ed16bff251e8e5a4af5fe5f2486deca 100644
--- a/lib/decmp.c
+++ b/lib/decompress/decmp.c
@@ -28,14 +28,14 @@
 #include <string.h>
 #include <assert.h>
 
-#include <byteorder.h>
-#include <compiler.h>
-
-#include <cmp_debug.h>
-#include <cmp_support.h>
-#include <cmp_entity.h>
-#include <cmp_max_used_bits.h>
-#include <cmp_max_used_bits_list.h>
+#include "../common/byteorder.h"
+#include "../common/compiler.h"
+
+#include "../common/cmp_debug.h"
+#include "../common/cmp_support.h"
+#include "../common/cmp_entity.h"
+#include "../common/cmp_max_used_bits.h"
+#include "cmp_max_used_bits_list.h"
 
 
 #define MAX_CW_LEN_RDCU 16 /* maximum RDCU Golomb code word bit length */
diff --git a/lib/decompress/meson.build b/lib/decompress/meson.build
new file mode 100644
index 0000000000000000000000000000000000000000..08da610cfc6ae1e4af843f77c64ed70254d884c0
--- /dev/null
+++ b/lib/decompress/meson.build
@@ -0,0 +1,4 @@
+decompress_sources = files([
+  'cmp_max_used_bits_list.c',
+  'decmp.c'
+])
diff --git a/lib/cmp_icu.c b/lib/icu_compress/cmp_icu.c
similarity index 99%
rename from lib/cmp_icu.c
rename to lib/icu_compress/cmp_icu.c
index 2fa7e677123eb9951c41751768fcb11b7be7b47e..0abc646b4f0a410bd1d0415e2ecc6b88e2b078ad 100644
--- a/lib/cmp_icu.c
+++ b/lib/icu_compress/cmp_icu.c
@@ -32,13 +32,13 @@
 #include <string.h>
 #include <limits.h>
 
-#include <byteorder.h>
-#include <cmp_debug.h>
-#include <cmp_data_types.h>
-#include <cmp_support.h>
-#include <cmp_entity.h>
+#include "../common/byteorder.h"
+#include "../common/cmp_debug.h"
+#include "../common/cmp_data_types.h"
+#include "../common/cmp_support.h"
+#include "../common/cmp_entity.h"
 
-#include <cmp_icu.h>
+#include "../cmp_icu.h"
 
 
 /**
diff --git a/lib/icu_compress/meson.build b/lib/icu_compress/meson.build
new file mode 100644
index 0000000000000000000000000000000000000000..01f4d370992dd60de5a047e2a0ce7bd850b6825f
--- /dev/null
+++ b/lib/icu_compress/meson.build
@@ -0,0 +1,3 @@
+icu_compress_sources = files([
+  'cmp_icu.c'
+])
diff --git a/lib/meson.build b/lib/meson.build
index 2d35635c0590646b27fa4374fd0acc0381505a32..8d40f7c0c80292390699ffff5815ff2840af89d9 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -1,25 +1,11 @@
-cmplib_sources = files([
-  'cmp_data_types.c',
-  'cmp_icu.c',
-  'cmp_support.c',
-  'rdcu_ctrl.c',
-  'rmap.c',
-  'cmp_entity.c',
-  'cmp_io.c',
-  'decmp.c',
-  'rdcu_pkt_to_file.c',
-  'cmp_guess.c',
-  'cmp_rdcu_cfg.c',
-  'cmp_rdcu.c',
-  'rdcu_cmd.c',
-  'rdcu_rmap.c',
-  'cmp_max_used_bits.c',
-  'cmp_max_used_bits_list.c'
-])
+subdir('common')
+subdir('decompress')
+subdir('icu_compress')
+subdir('rdcu_compress')
 
-cmp_lib = static_library('cmp_lib',
-  sources : cmplib_sources,
-  include_directories : incdir,
-  c_args : ['-DDEBUGLEVEL=1'],
-#  install : 'true' # linking under windows mingw only works if this is set
+
+incdir = include_directories('.', 'common', 'decompress', 'icu_compress', 'rdcu_compress')
+
+cmp_lib = static_library('cmp',
+  sources : [ common_sources, decompress_sources, icu_compress_sources, rdcu_compress_sources]
 )
diff --git a/lib/cmp_rdcu.c b/lib/rdcu_compress/cmp_rdcu.c
similarity index 99%
rename from lib/cmp_rdcu.c
rename to lib/rdcu_compress/cmp_rdcu.c
index 2e0a4082987bc2c3267eedb3c2e2e5eda498bed5..133bffcd570057f8c5f17ea7c330a2c1f330b27e 100644
--- a/lib/cmp_rdcu.c
+++ b/lib/rdcu_compress/cmp_rdcu.c
@@ -30,11 +30,11 @@
 #include <stdint.h>
 #include <stdio.h>
 
-#include <cmp_debug.h>
-#include <cmp_support.h>
-#include <cmp_rdcu_cfg.h>
-#include <rdcu_ctrl.h>
-#include <rdcu_rmap.h>
+#include "../common/cmp_debug.h"
+#include "../common/cmp_support.h"
+#include "cmp_rdcu_cfg.h"
+#include "rdcu_ctrl.h"
+#include "rdcu_rmap.h"
 
 
 #define RDCU_INTR_SIG_ENA 1 /* RDCU interrupt signal enabled */
diff --git a/lib/cmp_rdcu_cfg.c b/lib/rdcu_compress/cmp_rdcu_cfg.c
similarity index 99%
rename from lib/cmp_rdcu_cfg.c
rename to lib/rdcu_compress/cmp_rdcu_cfg.c
index 3d8c1ec64aaa476ad82c96d7844633b46528a52e..7b2ece5cfbc0c2e8b645d791f8679cbd711580dd 100644
--- a/lib/cmp_rdcu_cfg.c
+++ b/lib/rdcu_compress/cmp_rdcu_cfg.c
@@ -21,10 +21,10 @@
 #include <stdint.h>
 #include <string.h>
 
-#include <cmp_debug.h>
-#include <cmp_support.h>
-#include <rdcu_cmd.h>
-#include <cmp_rdcu_cfg.h>
+#include "../common/cmp_debug.h"
+#include "../common/cmp_support.h"
+#include "rdcu_cmd.h"
+#include "cmp_rdcu_cfg.h"
 
 
 /**
diff --git a/include/cmp_rdcu_cfg.h b/lib/rdcu_compress/cmp_rdcu_cfg.h
similarity index 97%
rename from include/cmp_rdcu_cfg.h
rename to lib/rdcu_compress/cmp_rdcu_cfg.h
index 19e6f97401d53d4f343100e3145cda9ce6e7a32e..46a597662cb89729e7ea3252d9f8f839b4b1c433 100644
--- a/include/cmp_rdcu_cfg.h
+++ b/lib/rdcu_compress/cmp_rdcu_cfg.h
@@ -19,7 +19,7 @@
 #ifndef CMP_RDCU_CFG_H
 #define CMP_RDCU_CFG_H
 
-#include <cmp_support.h>
+#include "../common/cmp_support.h"
 
 
 struct cmp_cfg rdcu_cfg_create(enum cmp_data_type data_type, enum cmp_mode cmp_mode,
diff --git a/lib/rdcu_compress/meson.build b/lib/rdcu_compress/meson.build
new file mode 100644
index 0000000000000000000000000000000000000000..cad28df11e5ae6c67fe70fb9d90e7a3caab617ad
--- /dev/null
+++ b/lib/rdcu_compress/meson.build
@@ -0,0 +1,8 @@
+rdcu_compress_sources = files([
+  'cmp_rdcu.c',
+  'cmp_rdcu_cfg.c',
+  'rdcu_cmd.c',
+  'rdcu_ctrl.c',
+  'rdcu_rmap.c',
+  'rmap.c'
+])
diff --git a/lib/rdcu_cmd.c b/lib/rdcu_compress/rdcu_cmd.c
similarity index 99%
rename from lib/rdcu_cmd.c
rename to lib/rdcu_compress/rdcu_cmd.c
index 26b15d2d1f5429fda71dd0665ab6df0e89439a48..79ac6148f034bd44c775c0a341f11717b1f63d2e 100644
--- a/lib/rdcu_cmd.c
+++ b/lib/rdcu_compress/rdcu_cmd.c
@@ -18,9 +18,9 @@
  */
 
 
-#include <rmap.h>
-#include <rdcu_cmd.h>
-#include <rdcu_rmap.h>
+#include "rmap.h"
+#include "rdcu_cmd.h"
+#include "rdcu_rmap.h"
 
 
 /**
diff --git a/include/rdcu_cmd.h b/lib/rdcu_compress/rdcu_cmd.h
similarity index 100%
rename from include/rdcu_cmd.h
rename to lib/rdcu_compress/rdcu_cmd.h
diff --git a/lib/rdcu_ctrl.c b/lib/rdcu_compress/rdcu_ctrl.c
similarity index 99%
rename from lib/rdcu_ctrl.c
rename to lib/rdcu_compress/rdcu_ctrl.c
index 4b58d6e2c00e376e324873590c7c12b67e0b6838..79a28d13539388132eb478befdf9cd669a7e4884 100644
--- a/lib/rdcu_ctrl.c
+++ b/lib/rdcu_compress/rdcu_ctrl.c
@@ -62,10 +62,10 @@
 #include <stdint.h>
 #include <string.h>
 
-#include <byteorder.h>
-#include <rdcu_cmd.h>
-#include <rdcu_ctrl.h>
-#include <rdcu_rmap.h>
+#include "../common/byteorder.h"
+#include "rdcu_cmd.h"
+#include "rdcu_ctrl.h"
+#include "rdcu_rmap.h"
 
 
 static struct rdcu_mirror *rdcu;
diff --git a/include/rdcu_ctrl.h b/lib/rdcu_compress/rdcu_ctrl.h
similarity index 100%
rename from include/rdcu_ctrl.h
rename to lib/rdcu_compress/rdcu_ctrl.h
diff --git a/lib/rdcu_rmap.c b/lib/rdcu_compress/rdcu_rmap.c
similarity index 99%
rename from lib/rdcu_rmap.c
rename to lib/rdcu_compress/rdcu_rmap.c
index e6a8567c3561eb5ca01662f231bdd148331eefbe..39721470065a0b8a5214961517ac71a7e09242ed 100644
--- a/lib/rdcu_rmap.c
+++ b/lib/rdcu_compress/rdcu_rmap.c
@@ -66,9 +66,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <byteorder.h>
-#include <rmap.h>
-#include <rdcu_rmap.h>
+#include "../common/byteorder.h"
+#include "rmap.h"
+#include "rdcu_rmap.h"
 
 #define RDCU_CONFIG_DEBUG 0
 
diff --git a/include/rdcu_rmap.h b/lib/rdcu_compress/rdcu_rmap.h
similarity index 100%
rename from include/rdcu_rmap.h
rename to lib/rdcu_compress/rdcu_rmap.h
diff --git a/lib/rmap.c b/lib/rdcu_compress/rmap.c
similarity index 99%
rename from lib/rmap.c
rename to lib/rdcu_compress/rmap.c
index b07663a86ae2e71645f921d3669c897ed7e28d30..9db4358a488bcd7a77c2997677a9b9ae3ecfc322 100644
--- a/lib/rmap.c
+++ b/lib/rdcu_compress/rmap.c
@@ -24,8 +24,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include <leon_inttypes.h>
-#include <rmap.h>
+#include "../common/leon_inttypes.h"
+#include "rmap.h"
 
 
 /**
diff --git a/include/rmap.h b/lib/rdcu_compress/rmap.h
similarity index 99%
rename from include/rmap.h
rename to lib/rdcu_compress/rmap.h
index 53472b536010cc63df2f862bfbce5d853494bc40..3dde00952ef8241ea944406b67f622463d83b562 100644
--- a/include/rmap.h
+++ b/lib/rdcu_compress/rmap.h
@@ -22,7 +22,7 @@
 #include <stdint.h>
 #include <stddef.h>
 
-#include <compiler.h>
+#include "../common/compiler.h"
 
 /**
  * valid RMAP command codes, see Table 5-1 of ECSS‐E‐ST‐50‐52C
diff --git a/meson.build b/meson.build
index e617be18e978a4d85ff8ab387c084180ee498fb9..a317df37f0876141b90478309bb214b20b10c834 100644
--- a/meson.build
+++ b/meson.build
@@ -1,13 +1,50 @@
 project('cmp_tool', 'c',
-  version : '0.12-b1',
+  version : '0.12-b2',
   meson_version : '>= 0.56',
   license : 'GPL-2.0',
-  default_options : ['warning_level=3', 'c_std=gnu99']
+  default_options : [
+    'warning_level=3',
+    'c_std=gnu99'
+  ]
 )
 
-add_project_arguments('-DDEBUGLEVEL=1', language : 'c')
+cc = meson.get_compiler('c')
 
-if (host_machine.system() == 'windows' or host_machine.system() == 'cygwin') and meson.get_compiler('c').get_id() == 'gcc'
+# Built-in options
+use_debug = get_option('debug')
+
+# Custom options
+debug_level = get_option('debug_level')
+feature_argument_input_mode = get_option('argument_input_mode')
+
+
+# Compiler flags
+cc_flags = ['-DDEBUGLEVEL=@0@'.format(debug_level)]
+if use_debug
+  debug_flags = [
+    '-Wstrict-aliasing=1',
+    '-Wcast-align',
+    '-Wredundant-decls',
+    '-Wundef',
+    '-Wshadow',
+    '-Wdeclaration-after-statement',
+    '-Wstrict-prototypes',
+    '-Wpointer-arith',
+    '-Wvla',
+    '-Wformat=2',
+    '-Winit-self',
+    '-Wfloat-equal',
+    '-Wwrite-strings',
+    '-Wold-style-definition',
+    '-Waggregate-return',
+    '-Wmissing-declarations',
+    '-Wmissing-include-dirs'
+  ]
+  cc_flags += cc.get_supported_arguments(debug_flags)
+endif
+add_project_arguments(cc_flags, language : 'c')
+
+if ['windows', 'cygwin'].contains(host_machine.system()) and cc.get_id() == 'gcc'
   # by default, MinGW on win32 behaves as if it ignores __attribute__((packed)),
   # you need to add -mno-ms-bitfields to make it work as expected.
   # See: https://wintermade.it/blog/posts/__attribute__packed-on-windows-is-ignored-with-mingw.html
@@ -15,17 +52,9 @@ if (host_machine.system() == 'windows' or host_machine.system() == 'cygwin') and
   add_global_link_arguments('-static', language: 'c')
 endif
 
-subdir('include')
-subdir('lib')
-
-main = files('cmp_tool.c')
-
-cmp_tool_exe = executable('cmp_tool',
-  sources : main,
-  include_directories : incdir,
-  link_with : cmp_lib,
-  install : 'true'
-)
 
+# Subdirs
+subdir('lib')
+subdir('programs')
 subdir('test')
 subdir('doc/doxygen')
diff --git a/meson_options.txt b/meson_options.txt
index fe8670ef9356c298fd3cc2fe813aeca7165d35f5..fc27689bb4a6e18bc5c1c4beb04579af179ea3d2 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,2 +1,4 @@
+option('debug_level', type: 'integer', min: 0, max: 9, value: 1,
+  description: 'Enable run-time debug. See lib/common/cmp_debug.h')
 option('argument_input_mode', type : 'boolean', value : false,
   description : 'If set, the data file is set with the first argument and the model file with the second one')
diff --git a/lib/cmp_guess.c b/programs/cmp_guess.c
similarity index 100%
rename from lib/cmp_guess.c
rename to programs/cmp_guess.c
diff --git a/include/cmp_guess.h b/programs/cmp_guess.h
similarity index 100%
rename from include/cmp_guess.h
rename to programs/cmp_guess.h
diff --git a/lib/cmp_io.c b/programs/cmp_io.c
similarity index 100%
rename from lib/cmp_io.c
rename to programs/cmp_io.c
diff --git a/include/cmp_io.h b/programs/cmp_io.h
similarity index 100%
rename from include/cmp_io.h
rename to programs/cmp_io.h
diff --git a/cmp_tool.c b/programs/cmp_tool.c
similarity index 100%
rename from cmp_tool.c
rename to programs/cmp_tool.c
diff --git a/programs/meson.build b/programs/meson.build
new file mode 100644
index 0000000000000000000000000000000000000000..ad9de48a3134ba7fb5b529796e34b9a835d49500
--- /dev/null
+++ b/programs/meson.build
@@ -0,0 +1,28 @@
+cmp_tool_src = files([
+  'cmp_guess.c',
+  'cmp_io.c',
+  'cmp_tool.c',
+  'rdcu_pkt_to_file.c'
+])
+
+
+# generate the cmp_tool-config.h configuration file
+cdata = configuration_data()
+cdata.set_quoted('PROGRAM_NAME', 'cmp_tool')
+cdata.set_quoted('CMP_TOOL_VERSION', meson.project_version())
+if feature_argument_input_mode
+  cdata.set('ARGUMENT_INPUT_MODE', 1)
+endif
+
+configure_file(
+  output : 'cmp_tool-config.h',
+  configuration : cdata
+)
+
+
+cmp_tool_exe = executable('cmp_tool',
+  sources : cmp_tool_src,
+  include_directories : incdir,
+  link_with : cmp_lib,
+  install : 'true'
+)
diff --git a/lib/rdcu_pkt_to_file.c b/programs/rdcu_pkt_to_file.c
similarity index 100%
rename from lib/rdcu_pkt_to_file.c
rename to programs/rdcu_pkt_to_file.c
diff --git a/include/rdcu_pkt_to_file.h b/programs/rdcu_pkt_to_file.h
similarity index 100%
rename from include/rdcu_pkt_to_file.h
rename to programs/rdcu_pkt_to_file.h
diff --git a/test/cmp_icu/meson.build b/test/cmp_icu/meson.build
index c22293c8a9cf78189d14c5bbefba2850f5f518cd..f92d5ee1ef58c281d453cc92869046d2f887c752 100644
--- a/test/cmp_icu/meson.build
+++ b/test/cmp_icu/meson.build
@@ -10,17 +10,3 @@ test_cmp_icu = executable('test_cmp_icu',
 )
 
 test('cmp_icu Unit Tests', test_cmp_icu)
-
-
-test_case = files('test_decmp.c')
-test_runner = test_runner_generator.process(test_case)
-
-test_decmp = executable('test_decmp',
-   test_case, test_runner,
-   include_directories : incdir,
-   link_with : cmp_lib,
-   dependencies : unity_dep,
-   build_by_default : false
-)
-
-test('Decompression Unit Tests', test_decmp)
diff --git a/test/cmp_icu/test_cmp_icu.c b/test/cmp_icu/test_cmp_icu.c
index b0bf2e1da1ec124bd84ff3837da75f1b3b1292e7..5c67b7cb3416aa5647df618dbdb68a31d1483e1a 100644
--- a/test/cmp_icu/test_cmp_icu.c
+++ b/test/cmp_icu/test_cmp_icu.c
@@ -32,7 +32,7 @@
 #include "../test_common/test_common.h"
 
 #include <cmp_icu.h>
-#include "../lib/cmp_icu.c" /* this is a hack to test static functions */
+#include "../../lib/icu_compress/cmp_icu.c" /* this is a hack to test static functions */
 
 
 /**
diff --git a/test/cmp_tool/cmp_tool_integration_test.py b/test/cmp_tool/cmp_tool_integration_test.py
index c0718295c369235388d924b199729b9ced11a01f..403490b3c47bb0c220e93f7a70ef7c7ad4f421da 100755
--- a/test/cmp_tool/cmp_tool_integration_test.py
+++ b/test/cmp_tool/cmp_tool_integration_test.py
@@ -26,7 +26,7 @@ NON_IMAGETTE_HEADER_SIZE = GENERIC_HEADER_SIZE+32
 WINE_TEST_SETUP = False
 my_env=None
 if sys.platform != 'win32' and sys.platform != 'cygwin':
-    if Path('cmp_tool.exe').exists():
+    if Path('programs/cmp_tool.exe').exists():
         # try to detect cross compile setup
         # and use wine to run windows executable
         WINE_TEST_SETUP = True
@@ -36,9 +36,9 @@ if sys.platform != 'win32' and sys.platform != 'cygwin':
 
 def call_cmp_tool(args):
     if WINE_TEST_SETUP:
-        args = shlex.split("wine64 cmp_tool.exe " + args)
+        args = shlex.split("wine64 programs/cmp_tool.exe " + args)
     else:
-        args = shlex.split("./cmp_tool " + args)
+        args = shlex.split("./programs/cmp_tool " + args)
     print(args)
 
     try:
diff --git a/test/decmp/meson.build b/test/decmp/meson.build
new file mode 100644
index 0000000000000000000000000000000000000000..4c7778a171aaf083705dadea4b7904fb168dea01
--- /dev/null
+++ b/test/decmp/meson.build
@@ -0,0 +1,12 @@
+test_case = files('test_decmp.c')
+test_runner = test_runner_generator.process(test_case)
+
+test_decmp = executable('test_decmp',
+   test_case, test_runner,
+   include_directories : incdir,
+   link_with : cmp_lib,
+   dependencies : unity_dep,
+   build_by_default : false
+)
+
+test('Decompression Unit Tests', test_decmp)
diff --git a/test/cmp_icu/test_decmp.c b/test/decmp/test_decmp.c
similarity index 99%
rename from test/cmp_icu/test_decmp.c
rename to test/decmp/test_decmp.c
index a773ff169017c14d78650603c99774f0abe8246c..5696c5b9f5ffe0caca797f1d6242b1313a8ae626 100644
--- a/test/cmp_icu/test_decmp.c
+++ b/test/decmp/test_decmp.c
@@ -24,8 +24,8 @@
 
 #include <compiler.h>
 #include <cmp_entity.h>
-#include "../../lib/cmp_icu.c" /* .c file included to test static functions */
-#include "../../lib/decmp.c" /* .c file included to test static functions */
+#include "../../lib/icu_compress/cmp_icu.c" /* .c file included to test static functions */
+#include "../../lib/decompress//decmp.c" /* .c file included to test static functions */
 
 #define MAX_VALID_CW_LEM 32
 
diff --git a/test/meson.build b/test/meson.build
index 49bf2a8d23698b0d14fa366ea79270efd1b38484..63da2db81129ecc31764b1bd5faf24b609fa0a2a 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -8,7 +8,8 @@ if checkpatch.found()
     '--ignore', 'SPDX_LICENSE_TAG,PREFER_DEFINED_ATTRIBUTE_MACRO,EMBEDDED_FILENAME,BLOCK_COMMENT_STYLE,EMBEDDED_FUNCTION_NAME',
   ]
   run_target('syntax-check',
-  command : [checkpatch, checkpatch_args, main, cmplib_sources])
+  command : [checkpatch, checkpatch_args, main, common_sources, decompress_sources,
+             icu_compress_sources, rdcu_compress_sources])
 endif
 
 # add cppcheck inspector target
@@ -34,6 +35,7 @@ subdir('cmp_tool')
 unity_dep = dependency('unity', fallback : ['unity', 'unity_dep'])
 
 subdir('test_common')
+subdir('decmp')
 subdir('cmp_icu')
 subdir('cmp_decmp')
 subdir('cmp_data_types')
diff --git a/test/tools/meson.build b/test/tools/meson.build
index 9c9f43761c09cd2f58813ca4513f9e99a6e4a3e9..194699721da7140cdb8383a92a726faf58559135 100644
--- a/test/tools/meson.build
+++ b/test/tools/meson.build
@@ -15,6 +15,6 @@ if checkpatch.found()
     '--ignore', 'SPDX_LICENSE_TAG,PREFER_DEFINED_ATTRIBUTE_MACRO,EMBEDDED_FILENAME,BLOCK_COMMENT_STYLE,EMBEDDED_FUNCTION_NAME',
   ]
   run_target('syntax-check',
-  command : [checkpatch, checkpatch_args, main, cmplib_sources])
+  command : [checkpatch, checkpatch_args, cmp_tool_src, common_sources, decompress_sources, icu_compress_sources, rdcu_compress_sources])
 endif