build/core: Add 'nolog' build option to omit logging entirely
This can be used to avoid dereferencing the global `log_type`
which may be inaccessible on platforms with memory protection.
Change-Id: Ib48468018e3afaf05978018199a9a2022cb49fdf
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
diff --git a/libmctp-log.h b/libmctp-log.h
index 1e574e5..d2b5899 100644
--- a/libmctp-log.h
+++ b/libmctp-log.h
@@ -5,9 +5,24 @@
/* libmctp-internal logging */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef MCTP_NOLOG
+
+__attribute__((format(printf, 2, 3))) static inline void
+mctp_prlog(int level __unused, const char *fmt __unused, ...)
+{
+}
+
+#else
+
void mctp_prlog(int level, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
+#endif
+
#ifndef pr_fmt
#define pr_fmt(x) x
#endif
diff --git a/meson.build b/meson.build
index 7f44a46..ab16cab 100644
--- a/meson.build
+++ b/meson.build
@@ -14,7 +14,6 @@
sources = [
'core.c',
'alloc.c',
- 'log.c',
]
headers = [
@@ -68,6 +67,12 @@
add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c')
endif
+if get_option('nolog')
+ add_project_arguments('-DMCTP_NOLOG', language : 'c')
+else
+ libmctp_sources += ['log.c']
+endif
+
feat_fileio = get_option('fileio').require(
compiler.links('''
#include <poll.h>
diff --git a/meson.options b/meson.options
index 73c23be..fda6e56 100644
--- a/meson.options
+++ b/meson.options
@@ -37,3 +37,9 @@
value: false,
description: 'Use fixed application-provided allocators',
)
+option(
+ 'nolog',
+ type: 'boolean',
+ value: false,
+ description: 'Don\'t include any logging functionality',
+)