From 5e6940a54915f316d47c8124eaa836c3aa3d6484 Mon Sep 17 00:00:00 2001
From: Dominik Loidolt <dominik.loidolt@univie.ac.at>
Date: Thu, 9 Nov 2023 14:05:05 +0100
Subject: [PATCH] Restructure file layout

Split lib folder into common, decompress, icu_compress rdcu_compress
Move cmp_tool files into programs directory
---
 INSTALL.md                                    |  4 +-
 doc/doxygen/meson.build                       |  2 +-
 include/meson.build                           | 13 ----
 {include => lib}/cmp_icu.h                    |  2 +-
 {include => lib}/cmp_rdcu.h                   |  4 +-
 {include => lib/common}/byteorder.h           |  0
 {include => lib/common}/cmp_cal_up_model.h    |  0
 lib/{ => common}/cmp_data_types.c             | 10 ++--
 {include => lib/common}/cmp_data_types.h      |  4 +-
 {include => lib/common}/cmp_debug.h           |  0
 lib/{ => common}/cmp_entity.c                 | 16 ++---
 {include => lib/common}/cmp_entity.h          |  4 +-
 lib/{ => common}/cmp_max_used_bits.c          |  2 +-
 {include => lib/common}/cmp_max_used_bits.h   |  0
 lib/{ => common}/cmp_support.c                |  8 +--
 {include => lib/common}/cmp_support.h         |  4 +-
 {include => lib/common}/compiler.h            |  0
 {include => lib/common}/leon_inttypes.h       |  0
 {include => lib/common}/list.h                |  0
 lib/common/meson.build                        |  6 ++
 {include => lib}/decmp.h                      |  0
 lib/{ => decompress}/cmp_max_used_bits_list.c |  4 +-
 .../decompress}/cmp_max_used_bits_list.h      |  2 +-
 lib/{ => decompress}/decmp.c                  | 16 ++---
 lib/decompress/meson.build                    |  4 ++
 lib/{ => icu_compress}/cmp_icu.c              | 12 ++--
 lib/icu_compress/meson.build                  |  3 +
 lib/meson.build                               | 32 +++-------
 lib/{ => rdcu_compress}/cmp_rdcu.c            | 10 ++--
 lib/{ => rdcu_compress}/cmp_rdcu_cfg.c        |  8 +--
 {include => lib/rdcu_compress}/cmp_rdcu_cfg.h |  2 +-
 lib/rdcu_compress/meson.build                 |  8 +++
 lib/{ => rdcu_compress}/rdcu_cmd.c            |  6 +-
 {include => lib/rdcu_compress}/rdcu_cmd.h     |  0
 lib/{ => rdcu_compress}/rdcu_ctrl.c           |  8 +--
 {include => lib/rdcu_compress}/rdcu_ctrl.h    |  0
 lib/{ => rdcu_compress}/rdcu_rmap.c           |  6 +-
 {include => lib/rdcu_compress}/rdcu_rmap.h    |  0
 lib/{ => rdcu_compress}/rmap.c                |  4 +-
 {include => lib/rdcu_compress}/rmap.h         |  2 +-
 meson.build                                   | 59 ++++++++++++++-----
 meson_options.txt                             |  2 +
 {lib => programs}/cmp_guess.c                 |  0
 {include => programs}/cmp_guess.h             |  0
 {lib => programs}/cmp_io.c                    |  0
 {include => programs}/cmp_io.h                |  0
 cmp_tool.c => programs/cmp_tool.c             |  0
 programs/meson.build                          | 28 +++++++++
 {lib => programs}/rdcu_pkt_to_file.c          |  0
 {include => programs}/rdcu_pkt_to_file.h      |  0
 test/cmp_icu/meson.build                      | 14 -----
 test/cmp_icu/test_cmp_icu.c                   |  2 +-
 test/cmp_tool/cmp_tool_integration_test.py    |  6 +-
 test/decmp/meson.build                        | 12 ++++
 test/{cmp_icu => decmp}/test_decmp.c          |  4 +-
 test/meson.build                              |  4 +-
 test/tools/meson.build                        |  2 +-
 57 files changed, 195 insertions(+), 144 deletions(-)
 rename {include => lib}/cmp_icu.h (98%)
 rename {include => lib}/cmp_rdcu.h (96%)
 rename {include => lib/common}/byteorder.h (100%)
 rename {include => lib/common}/cmp_cal_up_model.h (100%)
 rename lib/{ => common}/cmp_data_types.c (99%)
 rename {include => lib/common}/cmp_data_types.h (99%)
 rename {include => lib/common}/cmp_debug.h (100%)
 rename lib/{ => common}/cmp_entity.c (99%)
 rename {include => lib/common}/cmp_entity.h (99%)
 rename lib/{ => common}/cmp_max_used_bits.c (99%)
 rename {include => lib/common}/cmp_max_used_bits.h (100%)
 rename lib/{ => common}/cmp_support.c (99%)
 rename {include => lib/common}/cmp_support.h (99%)
 rename {include => lib/common}/compiler.h (100%)
 rename {include => lib/common}/leon_inttypes.h (100%)
 rename {include => lib/common}/list.h (100%)
 create mode 100644 lib/common/meson.build
 rename {include => lib}/decmp.h (100%)
 rename lib/{ => decompress}/cmp_max_used_bits_list.c (97%)
 rename {include => lib/decompress}/cmp_max_used_bits_list.h (96%)
 rename lib/{ => decompress}/decmp.c (99%)
 create mode 100644 lib/decompress/meson.build
 rename lib/{ => icu_compress}/cmp_icu.c (99%)
 create mode 100644 lib/icu_compress/meson.build
 rename lib/{ => rdcu_compress}/cmp_rdcu.c (99%)
 rename lib/{ => rdcu_compress}/cmp_rdcu_cfg.c (99%)
 rename {include => lib/rdcu_compress}/cmp_rdcu_cfg.h (97%)
 create mode 100644 lib/rdcu_compress/meson.build
 rename lib/{ => rdcu_compress}/rdcu_cmd.c (99%)
 rename {include => lib/rdcu_compress}/rdcu_cmd.h (100%)
 rename lib/{ => rdcu_compress}/rdcu_ctrl.c (99%)
 rename {include => lib/rdcu_compress}/rdcu_ctrl.h (100%)
 rename lib/{ => rdcu_compress}/rdcu_rmap.c (99%)
 rename {include => lib/rdcu_compress}/rdcu_rmap.h (100%)
 rename lib/{ => rdcu_compress}/rmap.c (99%)
 rename {include => lib/rdcu_compress}/rmap.h (99%)
 rename {lib => programs}/cmp_guess.c (100%)
 rename {include => programs}/cmp_guess.h (100%)
 rename {lib => programs}/cmp_io.c (100%)
 rename {include => programs}/cmp_io.h (100%)
 rename cmp_tool.c => programs/cmp_tool.c (100%)
 create mode 100644 programs/meson.build
 rename {lib => programs}/rdcu_pkt_to_file.c (100%)
 rename {include => programs}/rdcu_pkt_to_file.h (100%)
 create mode 100644 test/decmp/meson.build
 rename test/{cmp_icu => decmp}/test_decmp.c (99%)

diff --git a/INSTALL.md b/INSTALL.md
index 5162e70..70a4e0c 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 5c6a0d0..0501021 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 491eef5..e69de29 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 9fc0f42..1dedf3e 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 0e4ef1c..30bf45e 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 00861cd..ef9ae20 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 e10ae81..4a25ff0 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 5f9c9f0..f79e8cf 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 8efff24..93e27e6 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 553c0a5..eaedea3 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 77003ac..24cfaaa 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 3212703..aee7bbb 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 0000000..c4d8b68
--- /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 dfcec17..f4844ff 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 b533b01..35506c2 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 1fe53c3..f73cb63 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 0000000..08da610
--- /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 2fa7e67..0abc646 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 0000000..01f4d37
--- /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 2d35635..8d40f7c 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 2e0a408..133bffc 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 3d8c1ec..7b2ece5 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 19e6f97..46a5976 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 0000000..cad28df
--- /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 26b15d2..79ac614 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 4b58d6e..79a28d1 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 e6a8567..3972147 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 b07663a..9db4358 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 53472b5..3dde009 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 e617be1..a317df3 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 fe8670e..fc27689 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 0000000..ad9de48
--- /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 c22293c..f92d5ee 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 b0bf2e1..5c67b7c 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 c071829..403490b 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 0000000..4c7778a
--- /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 a773ff1..5696c5b 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 49bf2a8..63da2db 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 9c9f437..1946997 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
 
-- 
GitLab