[ovs-dev] [PATCH 2/3] Add BUILD_MESSAGE() macro

Daniele Di Proietto ddiproietto at vmware.com
Fri Aug 8 01:15:37 UTC 2014


This commit introduces the BUILD_MESSAGE() macro. It uses _Pragma("message"),
with compilers that support that, to output a warning-like compile-time message
without blocking the compilation.

Used by next commit.

Signed-off-by: Daniele Di Proietto <ddiproietto at vmware.com>
---
 configure.ac      |  1 +
 lib/compiler.h    | 10 ++++++++++
 m4/openvswitch.m4 |  9 +++++++++
 3 files changed, 20 insertions(+)

diff --git a/configure.ac b/configure.ac
index 971c7b3..97b5cd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -120,6 +120,7 @@ AC_ARG_VAR(KARCH, [Kernel Architecture String])
 AC_SUBST(KARCH)
 OVS_CHECK_LINUX
 OVS_CHECK_DPDK
+OVS_CHECK_PRAGMA_MESSAGE
 
 AC_CONFIG_FILES(Makefile)
 AC_CONFIG_FILES(datapath/Makefile)
diff --git a/lib/compiler.h b/lib/compiler.h
index cfe9066..50a4739 100644
--- a/lib/compiler.h
+++ b/lib/compiler.h
@@ -220,4 +220,14 @@
 #define OVS_PREFETCH_WRITE(addr)
 #endif
 
+/* Output a message (not an error) while compiling without failing the
+ * compilation process */
+#if HAVE_PRAGMA_MESSAGE
+#define DO_PRAGMA(x) _Pragma(#x)
+#define BUILD_MESSAGE(x) \
+    DO_PRAGMA(message(x))
+#else
+#define BUILD_MESSAGE(x)
+#endif
+
 #endif /* compiler.h */
diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4
index 26b8058..8d6ec27 100644
--- a/m4/openvswitch.m4
+++ b/m4/openvswitch.m4
@@ -429,3 +429,12 @@ dnl OVS_CHECK_INCLUDE_NEXT
 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
   [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
    gl_CHECK_NEXT_HEADERS([$1])])
+
+dnl OVS_CHECK_PRAGMA_MESSAGE
+AC_DEFUN([OVS_CHECK_PRAGMA_MESSAGE],
+  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+   [[_Pragma("message(\"Checking for pragma message\")")
+   ]])],
+     [AC_DEFINE(HAVE_PRAGMA_MESSAGE,1,[Define if compiler supports #pragma
+     message directive])])
+  ])
-- 
2.0.1




More information about the dev mailing list