build: add --with-mini-gmp switch to disable linking libgmp
PATCH v3 1/1 build: add --with-mini-gmp switch to disable linking libgmp
This allows to disable linking the >400 KB big libgmp and replace it with the builtin mini-gmp which only increases size by ~30KB.
Enabling this selectively decreases debugging verbosity (pr_debug).
Signed-off-by Steven Barth <[email protected]>
--- INSTALL | 7 + configure.ac | 12 +- include/expression.h | 2 +- include/gmputil.h | 10 + include/mini-gmp.h | 294 ++++ include/utils.h | 6 +- src/Makefile.am | 4 + src/gmputil.c | 57 +- src/mini-gmp.c | 4386 ++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 4769 insertions(+), 9 deletions(-) create mode 100644 include/mini-gmp.h create mode 100644 src/mini-gmp.c
INSTALL +7 -0
@@ -44,6 +44,13 @@ Installation instructions for nftables Disable debugging + --with-mini-gmp + + Use builtin mini-gmp instead of linking with a shared libgmp. + This is useful for embedded platforms optimizing for size and + having no other use for libgmp. + Note: This decreases the debugging verbosity in some files. + Suggested configuration options: --prefix=/ --datarootdir=/usr/share Run "make" to compile nftables, "make install" to install it in the
configure.ac +9 -3
@@ -73,8 +73,13 @@ AM_CONDITIONAL([BUILD_PDF], [test "$DBLATEX" == "found"]) PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3]) PKG_CHECK_MODULES([LIBNFTNL], [libnftnl >= 1.0.2]) -AC_CHECK_LIB([gmp], [__gmpz_init], , - AC_MSG_ERROR([No suitable version of libgmp found])) +AC_ARG_WITH([mini-gmp], [AS_HELP_STRING([--with-mini-gmp], + [Use builtin mini-gmp (for embedded builds)])], [], + [with_mini_gmp=no]) +AS_IF([test "x$with_mini_gmp" != xyes], [ +AC_CHECK_LIB([gmp],[__gmpz_init], , AC_MSG_ERROR([No suitable version of libgmp found])) +]) +AM_CONDITIONAL([BUILD_MINIGMP], [test "x$with_mini_gmp" == xyes]) AC_ARG_WITH([cli], [AS_HELP_STRING([--without-cli], [disable interactive CLI (libreadline support)])],
@@ -130,4 +135,5 @@ AC_OUTPUT echo " nft configuration: cli support: ${with_cli} - enable debugging: ${with_debug}" + enable debugging: ${with_debug} + use mini-gmp: ${with_mini_gmp}"
include/expression.h +1 -1
@@ -2,7 +2,7 @@#define NFTABLES_EXPRESSION_H #include <stdbool.h> -#include <gmp.h> +#include <gmputil.h> #include <linux/netfilter/nf_tables.h> #include <nftables.h>
include/gmputil.h +10 -0
@@ -1,7 +1,17 @@#ifndef NFTABLES_GMPUTIL_H #define NFTABLES_GMPUTIL_H +#include <config.h> + +#ifdef HAVE_LIBGMP #include <gmp.h> +#else +#include <mini-gmp.h> +/* mini-gmp doesn't come with gmp_printf, so we use our own minimal variant */ +extern int mpz_printf (const char *format,const mpz_t value); +#define gmp_printf mpz_printf +#endif +#include <asm/byteorder.h> enum mpz_word_order {
include/mini-gmp.h new file +294 -0
294 lines not on this page · raw message
include/utils.h +3 -3
@@ -9,14 +9,14 @@#include <unistd.h> #include <assert.h> #include <list.h> -#include <gmp.h> +#include <gmputil.h> #define BITS_PER_BYTE 8 -#ifdef DEBUG +#if defined(DEBUG ) && defined(HAVE_LIBGMP ) #define pr_debug(fmt, arg...) gmp_printf(fmt, ##arg)#else -#define pr_debug(fmt, arg...) ({ if (false) gmp_printf(fmt, ##arg); 0; }) +#define pr_debug(fmt, arg...) ({ if (false) {}; 0; })#endif #define __fmtstring (x, y) __attribute__((format(printf, x, y)))
src/Makefile.am +4 -0
@@ -51,4 +51,8 @@ if BUILD_CLI nft_SOURCES += cli.c endif +if BUILD_MINIGMP +nft_SOURCES += mini-gmp.c +endif + nft_LDADD = ${LIBMNL_LIBS} ${LIBNFTNL_LIBS}
src/gmputil.c +55 -2
72 lines not on this page · raw message
src/mini-gmp.c new file +4386 -0
2,550 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Part of the diff is not shown here. View the raw message.
Quoted 4 lines · Steven Barth
This allows to disable linking the >400 KB big libgmp and replace it with the builtin mini-gmp which only increases size by ~30KB.
Enabling this selectively decreases debugging verbosity (
pr_debug).
Applied, thanks Steven.