lib: flatten all loose components into one lib

lib/ was starting to get messy and inconsitent. Files being either
dumped in the root or in sub-directories without a clear plan.
Move all library components into one single folder and call it 'os'.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 2e42a63..3101afc 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1,15 +1,8 @@
-zephyr_sources(thread_entry.c work_q.c)
-zephyr_sources(fdtable.c)
-add_subdirectory(crc)
-add_subdirectory_ifdef(CONFIG_JSON_LIBRARY          json)
 if(NOT CONFIG_NATIVE_APPLICATION)
 add_subdirectory(libc)
 endif()
-add_subdirectory_if_kconfig(ring_buffer)
-add_subdirectory_if_kconfig(base64)
-add_subdirectory(mempool)
 add_subdirectory_ifdef(CONFIG_POSIX_API            posix)
 add_subdirectory_ifdef(CONFIG_CMSIS_RTOS_V1        cmsis_rtos_v1)
 add_subdirectory_ifdef(CONFIG_CMSIS_RTOS_V2        cmsis_rtos_v2)
-add_subdirectory(rbtree)
 add_subdirectory(gui)
+add_subdirectory(os)
diff --git a/lib/Kconfig b/lib/Kconfig
index 6861a2c..1f83cc9 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -8,29 +8,14 @@
 
 menu "Additional libraries"
 
-config JSON_LIBRARY
-	bool "Build JSON library"
-	help
-	  Build a minimal JSON parsing/encoding library. Used by sample
-	  applications such as the NATS client.
-
-config RING_BUFFER
-	bool "Enable ring buffers"
-	help
-	  Enable usage of ring buffers. This is similar to kernel FIFOs but ring
-	  buffers manage their own buffer memory and can store arbitrary data.
-	  For optimal performance, use buffer sizes that are a power of 2.
-
-config BASE64
-	bool "Enable base64 encoding and decoding"
-	help
-	  Enable base64 encoding and decoding functionality
-
-source "lib/posix/Kconfig"
-
 source "lib/cmsis_rtos_v1/Kconfig"
+
 source "lib/cmsis_rtos_v2/Kconfig"
 
 source "lib/gui/Kconfig"
 
+source "lib/os/Kconfig"
+
+source "lib/posix/Kconfig"
+
 endmenu
diff --git a/lib/base64/CMakeLists.txt b/lib/base64/CMakeLists.txt
deleted file mode 100644
index e3c4aaf..0000000
--- a/lib/base64/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-zephyr_sources(base64.c)
diff --git a/lib/crc/CMakeLists.txt b/lib/crc/CMakeLists.txt
deleted file mode 100644
index 29ae1e4..0000000
--- a/lib/crc/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-zephyr_sources(crc32_sw.c crc16_sw.c crc8_sw.c crc7_sw.c)
diff --git a/lib/json/CMakeLists.txt b/lib/json/CMakeLists.txt
deleted file mode 100644
index da12bb1..0000000
--- a/lib/json/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-zephyr_library()
-zephyr_library_sources(json.c)
diff --git a/lib/mempool/CMakeLists.txt b/lib/mempool/CMakeLists.txt
deleted file mode 100644
index b3cb3c1..0000000
--- a/lib/mempool/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-zephyr_sources(mempool.c)
diff --git a/lib/os/CMakeLists.txt b/lib/os/CMakeLists.txt
new file mode 100644
index 0000000..bd82096
--- /dev/null
+++ b/lib/os/CMakeLists.txt
@@ -0,0 +1,17 @@
+zephyr_sources_if_kconfig(base64.c)
+
+zephyr_sources(
+  crc32_sw.c
+  crc16_sw.c
+  crc8_sw.c
+  crc7_sw.c
+  fdtable.c
+  mempool.c
+  rb.c
+  thread_entry.c
+  work_q.c
+  )
+
+zephyr_sources_ifdef(CONFIG_JSON_LIBRARY json.c)
+
+zephyr_sources_if_kconfig(ring_buffer.c)
diff --git a/lib/os/Kconfig b/lib/os/Kconfig
new file mode 100644
index 0000000..b89ddd1
--- /dev/null
+++ b/lib/os/Kconfig
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2016 Intel Corporation
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+menu "OS Support Library"
+
+config JSON_LIBRARY
+	bool "Build JSON library"
+	help
+	  Build a minimal JSON parsing/encoding library. Used by sample
+	  applications such as the NATS client.
+
+config RING_BUFFER
+	bool "Enable ring buffers"
+	help
+	  Enable usage of ring buffers. This is similar to kernel FIFOs but ring
+	  buffers manage their own buffer memory and can store arbitrary data.
+	  For optimal performance, use buffer sizes that are a power of 2.
+
+config BASE64
+	bool "Enable base64 encoding and decoding"
+	help
+	  Enable base64 encoding and decoding functionality
+
+endmenu
diff --git a/lib/base64/base64.c b/lib/os/base64.c
similarity index 100%
rename from lib/base64/base64.c
rename to lib/os/base64.c
diff --git a/lib/crc/crc16_sw.c b/lib/os/crc16_sw.c
similarity index 100%
rename from lib/crc/crc16_sw.c
rename to lib/os/crc16_sw.c
diff --git a/lib/crc/crc32_sw.c b/lib/os/crc32_sw.c
similarity index 100%
rename from lib/crc/crc32_sw.c
rename to lib/os/crc32_sw.c
diff --git a/lib/crc/crc7_sw.c b/lib/os/crc7_sw.c
similarity index 100%
rename from lib/crc/crc7_sw.c
rename to lib/os/crc7_sw.c
diff --git a/lib/crc/crc8_sw.c b/lib/os/crc8_sw.c
similarity index 100%
rename from lib/crc/crc8_sw.c
rename to lib/os/crc8_sw.c
diff --git a/lib/fdtable.c b/lib/os/fdtable.c
similarity index 100%
rename from lib/fdtable.c
rename to lib/os/fdtable.c
diff --git a/lib/json/json.c b/lib/os/json.c
similarity index 100%
rename from lib/json/json.c
rename to lib/os/json.c
diff --git a/lib/mempool/mempool.c b/lib/os/mempool.c
similarity index 100%
rename from lib/mempool/mempool.c
rename to lib/os/mempool.c
diff --git a/lib/rbtree/rb.c b/lib/os/rb.c
similarity index 100%
rename from lib/rbtree/rb.c
rename to lib/os/rb.c
diff --git a/lib/ring_buffer/ring_buffer.c b/lib/os/ring_buffer.c
similarity index 100%
rename from lib/ring_buffer/ring_buffer.c
rename to lib/os/ring_buffer.c
diff --git a/lib/thread_entry.c b/lib/os/thread_entry.c
similarity index 100%
rename from lib/thread_entry.c
rename to lib/os/thread_entry.c
diff --git a/lib/work_q.c b/lib/os/work_q.c
similarity index 100%
rename from lib/work_q.c
rename to lib/os/work_q.c
diff --git a/lib/rbtree/CMakeLists.txt b/lib/rbtree/CMakeLists.txt
deleted file mode 100644
index 04156c6..0000000
--- a/lib/rbtree/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-zephyr_sources(rb.c)
diff --git a/lib/ring_buffer/CMakeLists.txt b/lib/ring_buffer/CMakeLists.txt
deleted file mode 100644
index 25e8ce0..0000000
--- a/lib/ring_buffer/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-zephyr_sources(ring_buffer.c)