]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: split off compiler magic into its own file
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 23 Aug 2017 18:22:31 +0000 (20:22 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 23 Aug 2017 22:18:53 +0000 (00:18 +0200)
Also make timed notices available via CONFDATE.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Makefile.am
lib/compiler.h [new file with mode: 0644]
lib/memory.h
lib/prefix.h
lib/subdir.am
lib/vty.h

index 48f4e50daa04886470e347ddf7b8723298d654a4..f204f8a724b7b0f4e248a7a27dbcf7e096339aed 100644 (file)
@@ -5,7 +5,7 @@ include common.am
 
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir) -I$(top_builddir)/lib
 AM_CFLAGS = $(WERROR)
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
+DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DCONFDATE=$(CONFDATE)
 LIBCAP = @LIBCAP@
 
 EXTRA_DIST =
diff --git a/lib/compiler.h b/lib/compiler.h
new file mode 100644 (file)
index 0000000..49a2f2a
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2015-2017  David Lamparter, for NetDEF, Inc.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _FRR_COMPILER_H
+#define _FRR_COMPILER_H
+
+/* function attributes, use like
+ *   void prototype(void) __attribute__((_CONSTRUCTOR(100)));
+ */
+#if defined(__clang__)
+# if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 5)
+#  define _RET_NONNULL    , returns_nonnull
+# endif
+# define _CONSTRUCTOR(x)  constructor(x)
+#elif defined(__GNUC__)
+# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
+#  define _RET_NONNULL    , returns_nonnull
+# endif
+# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#  define _CONSTRUCTOR(x) constructor(x)
+#  define _DESTRUCTOR(x)  destructor(x)
+#  define _ALLOC_SIZE(x)  alloc_size(x)
+# endif
+#endif
+
+#ifdef __sun
+/* Solaris doesn't do constructor priorities due to linker restrictions */
+# undef _CONSTRUCTOR
+# undef _DESTRUCTOR
+#endif
+
+/* fallback versions */
+#ifndef _RET_NONNULL
+# define _RET_NONNULL
+#endif
+#ifndef _CONSTRUCTOR
+# define _CONSTRUCTOR(x) constructor
+#endif
+#ifndef _DESTRUCTOR
+# define _DESTRUCTOR(x) destructor
+#endif
+#ifndef _ALLOC_SIZE
+# define _ALLOC_SIZE(x)
+#endif
+
+/*
+ * for warnings on macros, put in the macro content like this:
+ *   #define MACRO BLA CPP_WARN("MACRO has been deprecated")
+ */
+#define CPP_STR(X) #X
+
+#if defined(__ICC)
+#define CPP_NOTICE(text) _Pragma(CPP_STR(message __FILE__ ": " text))
+#define CPP_WARN(text) CPP_NOTICE(text)
+
+#elif (defined(__GNUC__)                                                       \
+       && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))           \
+       || (defined(__clang__)                                                 \
+           && (__clang_major__ >= 4                                           \
+               || (__clang_major__ == 3 && __clang_minor__ >= 5)))
+#define CPP_WARN(text) _Pragma(CPP_STR(GCC warning text))
+#define CPP_NOTICE(text) _Pragma(CPP_STR(message text))
+
+#else
+#define CPP_WARN(text)
+#endif
+
+#endif /* _FRR_COMPILER_H */
index 132d4abd3035336a9cdcb26e196534b225ee666a..6de370514abe47c361cbebdfa3e144cb6fd89c36 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <frratomic.h>
+#include "compiler.h"
 
 #define array_size(ar) (sizeof(ar) / sizeof(ar[0]))
 
@@ -37,41 +38,6 @@ struct memgroup {
        const char *name;
 };
 
-#if defined(__clang__)
-#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 5)
-#  define _RET_NONNULL  , returns_nonnull
-#endif
-# define _CONSTRUCTOR(x) constructor(x)
-#elif defined(__GNUC__)
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
-#  define _RET_NONNULL  , returns_nonnull
-#endif
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
-#  define _CONSTRUCTOR(x) constructor(x)
-#  define _DESTRUCTOR(x)  destructor(x)
-#  define _ALLOC_SIZE(x)  alloc_size(x)
-#endif
-#endif
-
-#ifdef __sun
-/* Solaris doesn't do constructor priorities due to linker restrictions */
-#undef _CONSTRUCTOR
-#undef _DESTRUCTOR
-#endif
-
-#ifndef _RET_NONNULL
-# define _RET_NONNULL
-#endif
-#ifndef _CONSTRUCTOR
-# define _CONSTRUCTOR(x) constructor
-#endif
-#ifndef _DESTRUCTOR
-# define _DESTRUCTOR(x) destructor
-#endif
-#ifndef _ALLOC_SIZE
-# define _ALLOC_SIZE(x)
-#endif
-
 /* macro usage:
  *
  *  mydaemon.h
index bc4abb492a0cca31e59c61838ecb3901eed35d20..eab4ac2bb73d8ebe6e9a02d3df11dae3fce4aca6 100644 (file)
 #endif
 #include "sockunion.h"
 #include "ipaddr.h"
+#include "compiler.h"
 
 #ifndef ETH_ALEN
 #define ETH_ALEN 6
 #endif
 
 /* for compatibility */
-#if defined(__ICC)
-#define CPP_WARN_STR(X) #X
-#define CPP_WARN(text) _Pragma(CPP_WARN_STR(message __FILE__ ": " text))
-
-#elif (defined(__GNUC__)                                                       \
-       && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))           \
-       || (defined(__clang__)                                                 \
-           && (__clang_major__ >= 4                                           \
-               || (__clang_major__ == 3 && __clang_minor__ >= 5)))
-#define CPP_WARN_STR(X) #X
-#define CPP_WARN(text) _Pragma(CPP_WARN_STR(GCC warning text))
-
-#else
-#define CPP_WARN(text)
-#endif
-
 #ifdef ETHER_ADDR_LEN
 #undef ETHER_ADDR_LEN
 #endif
index 85451842286f00484df104c1967b07a1299d6020..d6349ba22df2f2b0646460482a6e6d4e982ac5e6 100644 (file)
@@ -85,6 +85,7 @@ pkginclude_HEADERS += \
        lib/command.h \
        lib/command_graph.h \
        lib/command_match.h \
+       lib/compiler.h \
        lib/csv.h \
        lib/distribute.h \
        lib/event_counter.h \
index dcb8da225d2fadede770f699831dc5bbd64a3147..9acd62af3cb1a6268cff82bef12495d42e2af73a 100644 (file)
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -25,6 +25,7 @@
 #include "log.h"
 #include "sockunion.h"
 #include "qobj.h"
+#include "compiler.h"
 
 #define VTY_BUFSIZ 4096
 #define VTY_MAXHIST 20
@@ -182,23 +183,11 @@ struct vty_arg {
 /* Integrated configuration file. */
 #define INTEGRATE_DEFAULT_CONFIG "frr.conf"
 
-/* for compatibility */
-#if defined(__ICC)
-#define CPP_WARN_STR(X) #X
-#define CPP_WARN(text) _Pragma(CPP_WARN_STR(message __FILE__ ": " text))
-
-#elif (defined(__GNUC__)                                                       \
-       && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))           \
-       || (defined(__clang__)                                                 \
-           && (__clang_major__ >= 4                                           \
-               || (__clang_major__ == 3 && __clang_minor__ >= 5)))
-#define CPP_WARN_STR(X) #X
-#define CPP_WARN(text) _Pragma(CPP_WARN_STR(GCC warning text))
-
-#else
-#define CPP_WARN(text)
+#if CONFDATE > 20180401
+CPP_NOTICE("It's probably time to remove VTY_NEWLINE compatibility foo.")
 #endif
 
+/* for compatibility */
 #define VNL "\n" CPP_WARN("VNL has been replaced with \\n.")
 #define VTYNL "\n" CPP_WARN("VTYNL has been replaced with \\n.")
 #define VTY_NEWLINE "\n" CPP_WARN("VTY_NEWLINE has been replaced with \\n.")