libyang REFACTOR config.h code split
... into compat.h and version.h.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fba0fdb..7a38570 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -125,7 +125,7 @@
set(CMAKE_C_FLAGS_ABICHECK "-g -Og")
include_directories(${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src)
-configure_file(${PROJECT_SOURCE_DIR}/src/config.h.in ${PROJECT_BINARY_DIR}/src/config.h @ONLY)
+configure_file(${PROJECT_SOURCE_DIR}/src/version.h.in ${PROJECT_BINARY_DIR}/src/version.h @ONLY)
#set(EXTENSIONS_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/extensions")
#set(USER_TYPES_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/user_types")
@@ -198,6 +198,7 @@
tools/re/main.c)
set(headers
+ src/version.h
src/libyang.h
src/context.h
src/dict.h
diff --git a/CMakeModules/UseCompat.cmake b/CMakeModules/UseCompat.cmake
index bac4027..1e92bb7 100644
--- a/CMakeModules/UseCompat.cmake
+++ b/CMakeModules/UseCompat.cmake
@@ -21,8 +21,8 @@
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
# header and object file
- configure_file(${PROJECT_SOURCE_DIR}/compat/compat.h.in ${PROJECT_BINARY_DIR}/compat.h @ONLY)
- include_directories(${PROJECT_BINARY_DIR})
+ configure_file(${PROJECT_SOURCE_DIR}/compat/compat.h.in ${PROJECT_BINARY_DIR}/compat/compat.h @ONLY)
+ include_directories(${PROJECT_BINARY_DIR}/compat)
add_library(compat OBJECT ${PROJECT_SOURCE_DIR}/compat/compat.c)
set_property(TARGET compat PROPERTY POSITION_INDEPENDENT_CODE ON)
endmacro()
diff --git a/compat/compat.h.in b/compat/compat.h.in
index b69a339..bc84305 100644
--- a/compat/compat.h.in
+++ b/compat/compat.h.in
@@ -37,6 +37,14 @@
# endif
#endif
+#if (@CMAKE_C_COMPILER_ID@ == GNU) || (@CMAKE_C_COMPILER_ID@ == Clang)
+# define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
+# define _PACKED __attribute__((__packed__))
+#else
+# define UNUSED(x) UNUSED_ ## x
+# define _PACKED
+#endif
+
#cmakedefine HAVE_VDPRINTF
#cmakedefine HAVE_ASPRINTF
#cmakedefine HAVE_VASPRINTF
diff --git a/src/common.h b/src/common.h
index eb1cbf6..f7f9b77 100644
--- a/src/common.h
+++ b/src/common.h
@@ -19,8 +19,6 @@
#include <stddef.h>
#include <stdint.h>
-#include "config.h"
-
#include "context.h"
#include "dict.h"
#include "hash_table.h"
diff --git a/src/hash_table.c b/src/hash_table.c
index 0e4d512..5eee58b 100644
--- a/src/hash_table.c
+++ b/src/hash_table.c
@@ -20,6 +20,7 @@
#include <pthread.h>
#include <assert.h>
+#include "compat.h"
#include "common.h"
#include "dict.h"
diff --git a/src/hash_table.h b/src/hash_table.h
index 00593fa..9958c98 100644
--- a/src/hash_table.h
+++ b/src/hash_table.h
@@ -20,7 +20,7 @@
#include <stddef.h>
#include <stdint.h>
-#include "config.h"
+#include "compat.h"
#include "log.h"
/**
diff --git a/src/parser_json.c b/src/parser_json.c
index d69ccef..86102b5 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -20,7 +20,6 @@
#include "common.h"
#include "compat.h"
-#include "config.h"
#include "context.h"
#include "json.h"
#include "parser_internal.h"
diff --git a/src/plugins_types.c b/src/plugins_types.c
index 319875d..4dc7753 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -25,7 +25,6 @@
#include "common.h"
#include "compat.h"
-#include "config.h"
#include "dict.h"
#include "path.h"
#include "set.h"
diff --git a/src/printer_json.c b/src/printer_json.c
index 65f0393..c0ea3c5 100644
--- a/src/printer_json.c
+++ b/src/printer_json.c
@@ -17,7 +17,6 @@
#include <string.h>
#include "common.h"
-#include "config.h"
#include "log.h"
#include "parser_data.h"
#include "plugins_types.h"
diff --git a/src/printer_lyb.c b/src/printer_lyb.c
index c1a7365..0cb070d 100644
--- a/src/printer_lyb.c
+++ b/src/printer_lyb.c
@@ -23,7 +23,6 @@
#include "common.h"
#include "compat.h"
-#include "config.h"
#include "context.h"
#include "hash_table.h"
#include "log.h"
diff --git a/src/printer_schema.c b/src/printer_schema.c
index 5c5de8a..cd283ba 100644
--- a/src/printer_schema.c
+++ b/src/printer_schema.c
@@ -17,8 +17,8 @@
#include <stdio.h>
#include <unistd.h>
+#include "compat.h"
#include "common.h"
-#include "config.h"
#include "log.h"
#include "printer.h"
#include "printer_internal.h"
diff --git a/src/tree_data.c b/src/tree_data.c
index a203557..a6963ba 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -29,7 +29,6 @@
#include "common.h"
#include "compat.h"
-#include "config.h"
#include "context.h"
#include "dict.h"
#include "diff.h"
diff --git a/src/tree_data_hash.c b/src/tree_data_hash.c
index 2625452..beca3b0 100644
--- a/src/tree_data_hash.c
+++ b/src/tree_data_hash.c
@@ -17,8 +17,8 @@
#include <stdlib.h>
#include <string.h>
+#include "compat.h"
#include "common.h"
-#include "config.h"
#include "hash_table.h"
#include "log.h"
#include "plugins_types.h"
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index 22843af..3352134 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -14,8 +14,8 @@
#include <stdlib.h>
+#include "compat.h"
#include "common.h"
-#include "config.h"
#include "plugins_exts.h"
#include "plugins_types.h"
#include "tree.h"
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index 8500b55..e6f4d3b 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -21,8 +21,8 @@
#include <string.h>
#include <time.h>
+#include "compat.h"
#include "common.h"
-#include "config.h"
#include "context.h"
#include "hash_table.h"
#include "log.h"
diff --git a/src/validation.c b/src/validation.c
index 7ee6fdb..b5e86d9 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -19,8 +19,8 @@
#include <stdlib.h>
#include <string.h>
+#include "compat.h"
#include "common.h"
-#include "config.h"
#include "diff.h"
#include "hash_table.h"
#include "log.h"
diff --git a/src/config.h.in b/src/version.h.in
similarity index 63%
rename from src/config.h.in
rename to src/version.h.in
index eccc1e9..1f56e10 100644
--- a/src/config.h.in
+++ b/src/version.h.in
@@ -1,9 +1,9 @@
/**
- * @file config.h
+ * @file version.h
* @author Radek Krejci <rkrejci@cesnet.cz>
- * @brief various variables detected by cmake
+ * @brief libyang version definitions
*
- * Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
+ * Copyright (c) 2020 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
@@ -12,22 +12,12 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#ifndef LY_CONFIG_H_
-#define LY_CONFIG_H_
-
-/**
- * @brief Compiler flag for unused function attributes
- */
-#define UNUSED(x) @COMPILER_UNUSED_ATTR@
-
-/**
- * @brief Compiler flag for packed data types.
- */
-#define _PACKED @COMPILER_PACKED_ATTR@
+#ifndef LY_VERSION_H_
+#define LY_VERSION_H_
#define LY_VERSION_MAJOR @LIBYANG_MAJOR_SOVERSION@ /**< libyang major version number */
#define LY_VERSION_MINOR @LIBYANG_MINOR_SOVERSION@ /**< libyang minor version number */
#define LY_VERSION_MICRO @LIBYANG_MICRO_SOVERSION@ /**< libyang micro version number */
#define LY_VERSION "@LIBYANG_SOVERSION_FULL@" /**< libyang version string */
-#endif /* LY_CONFIG_H_ */
+#endif /* LY_VERSION_H_ */
diff --git a/src/xpath.h b/src/xpath.h
index a5ea377..4fb601a 100644
--- a/src/xpath.h
+++ b/src/xpath.h
@@ -18,7 +18,7 @@
#include <stdint.h>
#include <stddef.h>
-#include "config.h"
+#include "compat.h"
#include "log.h"
#include "plugins_types.h"
#include "tree_schema.h"
diff --git a/tests/style/check_includes.sh b/tests/style/check_includes.sh
index 530edfd..29dd0c9 100755
--- a/tests/style/check_includes.sh
+++ b/tests/style/check_includes.sh
@@ -17,6 +17,17 @@
done
}
+function check_compat_macro {
+ FILES=`grep -rE "([^[:alnum:]]|^)$1([^[:alnum:]]|$)" --include=\*.{c,h} $SRC | cut -d: -f1 | uniq`
+ for f in $FILES; do
+ grep -q "#include \"compat.h\"" $f
+ if [ $? -ne 0 ]; then
+ echo "Missing #include \"compat.h\" in file $f for macro $1"
+ RETVAL=$((RETVAL+1))
+ fi
+ done
+}
+
check_compat_func asprintf
check_compat_func get_current_dir_name
check_compat_func getline
@@ -24,5 +35,7 @@
check_compat_func strnstr
check_compat_func vasprintf
check_compat_func vdprintf
+check_compat_func UNUSED
+check_compat_macro _PACKED
exit $RETVAL