From fd1bcccb9b6063d0501c81323eef81c0dd7a6340 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Fri, 23 Jul 2021 18:20:33 +0200 Subject: 5708: allow gnunet-config to output build config informations With this commit, `gnunet-config' is now able to print some informations about how GNUnet was built through some additional flags (here `--cflags', `--libs' and `--prefix'.) These flags allow `gnunet-config' to behave like other `*-config' tools provided by other applications/libraries, which are used by third-party applications, especially when the tool is provided by a library, to properly compile using the flags recommended by the library/application. In terms of GNUnet, any client or service connecting to any GNUnet service can now be built using some variation of the following: cc $(gnunet-config --cflags) -o my-client client.c $(gnunet-config --libs) --- src/util/Makefile.am | 5 +++++ src/util/gnunet-config.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/util/Makefile.am b/src/util/Makefile.am index e720112be..ab66756b4 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -227,6 +227,11 @@ gnunet_config_SOURCES = \ gnunet_config_LDADD = \ libgnunetutil.la \ $(GN_LIBINTL) +gnunet_config_CPPFLAGS = \ + -DINCLUDEDIR=\"$(includedir)\" \ + -DLIBDIR=\"$(libdir)\" \ + -DPREFIX=\"$(prefix)\" \ + $(AM_CPPFLAGS) gnunet_uri_SOURCES = \ gnunet-uri.c diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index 3932ff1bf..0a5c0712b 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c @@ -74,6 +74,21 @@ static int rewrite; */ static int full; +/** + * If printing the value of CFLAGS has been requested. + */ +static int cflags; + +/** + * If printing the value of LIBS has been requested. + */ +static int libs; + +/** + * If printing the value of PREFIX has been requested. + */ +static int prefix; + /** * Print each option in a given section. @@ -150,6 +165,23 @@ run (void *cls, (void) cls; (void) args; + if (1 == cflags || 1 == libs || 1 == prefix) + { + /* These values are defined in the makefile */ + if (1 == cflags) + { + fprintf (stdout, "%s\n", "-I"INCLUDEDIR); + } + if (1 == libs) + { + fprintf (stdout, "%s\n", "-L"LIBDIR" -lgnunetutil"); + } + if (1 == prefix) + { + fprintf (stdout, "%s\n", PREFIX); + } + return; + } if (NULL != backend_check) { char *name; @@ -364,6 +396,21 @@ main (int argc, char *const *argv) "VALUE", gettext_noop ("value to set"), &value), + GNUNET_GETOPT_option_flag ('C', + "cflags", + gettext_noop ( + "Provide an appropriate value for CFLAGS to applications building on top of GNUnet"), + &cflags), + GNUNET_GETOPT_option_flag ('j', + "libs", + gettext_noop ( + "Provide an appropriate value for LIBS to applications building on top of GNUnet"), + &libs), + GNUNET_GETOPT_option_flag ('p', + "prefix", + gettext_noop ( + "Provide the path under which GNUnet was installed"), + &prefix), GNUNET_GETOPT_OPTION_END }; int ret; -- cgit v1.2.3 From 9bdfda437e180ee9fe6d1e54b201c538086d2c48 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Sat, 24 Jul 2021 16:15:10 +0200 Subject: gnunet-config manpage: Document the new flags --- doc/man/gnunet-config.1 | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/doc/man/gnunet-config.1 b/doc/man/gnunet-config.1 index 03f180c29..c749c03b5 100644 --- a/doc/man/gnunet-config.1 +++ b/doc/man/gnunet-config.1 @@ -26,33 +26,44 @@ .Os .Sh NAME .Nm gnunet-config -.Nd manipulate GNUnet configuration files +.Nd manipulate GNUnet configuration files and provide informations on how GNUnet was built .Sh SYNOPSIS .Nm .Op Fl b Ar BACKEND | Fl -supported-backend= Ns Ar BACKEND +.Op Fl C | -cflags .Op Fl c Ar FILENAME | Fl -config= Ns Ar FILENAME +.Op Fl F | -full .Op Fl f | -filename .Op Fl h | -help +.Op Fl j | -libs .Op Fl L Ar LOGLEVEL | Fl -loglevel= Ns Ar LOGLEVEL .Op Fl o Ar OPTION | Fl -option= Ns Ar OPTION +.Op Fl p | -prefix +.Op Fl r | -rewrite .Op Fl S |-list-sections .Op Fl s Ar SECTION | Fl -section= Ns Ar SECTION .Op Fl V Ar VALUE | Fl -value Ar VALUE .Op Fl v | -version -.Op Fl r | -rewrite -.Op Fl F | -full .Sh DESCRIPTION .Nm can be used to read or modify GNUnet configuration files. +It can also provide informations to properly build applications on top of +GNUnet, like appropriate values for CFLAGS or the installation prefix. .Bl -tag -width indent .It Fl b Ar BACKEND | Fl -supported-backend= Ns Ar BACKEND Tests whether the specified BACKEND is supported by the current installation. The backend must match the name of a plugin, e.g. "namestore_postgres" for the Postgres database backend of the "NAMESTORE" service. If the BACKEND is supported, gnunet-config will return a status code of 0 (success), otherwise 77 (unsupported). When this option is specified, no other options may be specified. Specifying this option together with other options will cause gnunet-config to return a status code of 1 (error). +.It Fl C | -cflags +Print an appropriate value for CFLAGS to compile applications on top of GNUnet. .It Fl c Ar FILENAME | Fl -config= Ns Ar FILENAME Use the configuration file FILENAME. +.It Fl F | -full +Write the full configuration, not just the deltas to the defaults. .It Fl f | -filename Try to perform expansions as if the option values represent filenames (will also be applied even if the option is not really a filename). .It Fl h | -help Print short help on options. +.It Fl j | -libs +Print an appropriate value for LIBS to compile applications on top of GNUnet. .It Fl L Ar LOGLEVEL | Fl -loglevel= Ns Ar LOGLEVEL Use LOGLEVEL for logging. Valid values are DEBUG, INFO, WARNING and ERROR. @@ -60,6 +71,10 @@ Valid values are DEBUG, INFO, WARNING and ERROR. Which configuration option should be accessed or edited. Required to set a value. If not given, all values of a given section will be printed in the format "OPTION = VALUE". +.It Fl p | -prefix +Print GNUnet's installation prefix (for example /usr/local.) +.It Fl r | -rewrite +Write the configuration to file, even if it did not change. .It Fl S |-list-sections List available configuration sections for use with --section. .It Fl s Ar SECTION | Fl -section= Ns Ar SECTION @@ -70,10 +85,6 @@ Configuration value to store in the given section under the given option. Must only be given together with -s and -o options. .It Fl v | -version Print GNUnet version number. -.It Fl r | -rewrite -Write the configuration to file, even if it did not change. -.It Fl F | -full -Write the full configuration, not just the deltas to the defaults. .El .Sh SEE ALSO The full documentation for gnunet is maintained as a Texinfo manual. -- cgit v1.2.3 From b474cdc0baffa55b700008d55cded7f11126a063 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Sun, 25 Jul 2021 15:00:51 +0200 Subject: - Do not hardcode values in gnunet-config --- src/util/Makefile.am | 5 ----- src/util/gnunet-config.c | 11 +++++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/util/Makefile.am b/src/util/Makefile.am index ab66756b4..e720112be 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -227,11 +227,6 @@ gnunet_config_SOURCES = \ gnunet_config_LDADD = \ libgnunetutil.la \ $(GN_LIBINTL) -gnunet_config_CPPFLAGS = \ - -DINCLUDEDIR=\"$(includedir)\" \ - -DLIBDIR=\"$(libdir)\" \ - -DPREFIX=\"$(prefix)\" \ - $(AM_CPPFLAGS) gnunet_uri_SOURCES = \ gnunet-uri.c diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index 0a5c0712b..11682daea 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c @@ -167,19 +167,22 @@ run (void *cls, (void) args; if (1 == cflags || 1 == libs || 1 == prefix) { - /* These values are defined in the makefile */ + char *prefixdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_PREFIX); + char *libdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); if (1 == cflags) { - fprintf (stdout, "%s\n", "-I"INCLUDEDIR); + fprintf (stdout, "-I%sinclude\n", prefixdir); } if (1 == libs) { - fprintf (stdout, "%s\n", "-L"LIBDIR" -lgnunetutil"); + fprintf (stdout, "-L%s -lgnunetutil\n", libdir); } if (1 == prefix) { - fprintf (stdout, "%s\n", PREFIX); + fprintf (stdout, "%s\n", prefixdir); } + GNUNET_free (prefixdir); + GNUNET_free (libdir); return; } if (NULL != backend_check) -- cgit v1.2.3 From 649d10b2756bda49694d380e82154a96dde98670 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Tue, 27 Jul 2021 16:27:14 +0200 Subject: Autoconf macro to detect GNUnet installations --- contrib/Makefile.am | 4 ++++ contrib/gnunet.m4 | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 contrib/gnunet.m4 diff --git a/contrib/Makefile.am b/contrib/Makefile.am index f42fb684d..150e47ff0 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -53,6 +53,7 @@ EXTRA_DIST = \ conf/gnunet/gnunet-user.conf \ conf/nss/nssswitch.conf \ conf/wireshark/wireshark.lua \ + gnunet.m4 \ $(PACKAGES_FILES) \ $(INITD_FILES) \ Makefile.inc \ @@ -77,3 +78,6 @@ test_gnunet_prefix_LDADD = \ $(LTLIBICONV) \ $(GN_LIBINTL) \ $(LIBLTDL) -lunistring $(XLIB) + +aclocaldir = $(datadir)/aclocal +aclocal_DATA = gnunet.m4 diff --git a/contrib/gnunet.m4 b/contrib/gnunet.m4 new file mode 100644 index 000000000..fe70fbde1 --- /dev/null +++ b/contrib/gnunet.m4 @@ -0,0 +1,63 @@ +# Autoconf macro for working with GNUnet +# This file is in the public domain. +# +# AM_PATH_GNUNET([MINIMUM-VERSION = 0.14.2, [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]]]) +# Find the GNUnet installation, either automatically or through the +# --with-gnunet-prefix flag +# +# This macro runs the pkg-config and, if needed, the gnunet-config tool +# provided by GNUnet itself. +# +# The gnunet-config tool can be overridden by setting the GNUNET_CONFIG +# variable before executing the configure script. +# +# The variables GNUNET_CFLAGS and GNUNET_LIBS will be set to appropriate +# values and are made available to Automake. +AC_DEFUN([AM_PATH_GNUNET], +[AC_ARG_WITH([gnunet-prefix], + [AS_HELP_STRING([--with-gnunet-prefix=PATH], + [PATH to the GNUnet installation])], + [gnunet_prefix="$withval"], + [gnunet_prefix=""]) + AC_ARG_VAR([GNUNET_CONFIG],[The gnunet-config tool]) + min_gnunet_version=m4_if([$1], ,0.14.2,$1) + # Make sure the specified version is at least the version with + # the features required to use this macro + AS_VERSION_COMPARE([$min_gnunet_version],[0.14.2], + [AC_MSG_WARN([The specified GNUnet version $min_gnunet_version is too old.]) + AC_MSG_WARN([The minimum version has been set to 0.14.2]) + min_gnunet_version="0.14.2"]) + AS_IF([test "x${GNUNET_CONFIG+set}" != "xset"], + [PKG_CHECK_MODULES([GNUNET],[gnunetutil >= $min_gnunet_version], + [gnunet_pkgconfig=yes],[gnunet_pkgconfig=no]) + AS_IF([test "x$gnunet_pkgconfig" = "xno" && test "x$gnunet_prefix" != "x"], + [gnunet_PATH="$PATH" + AS_IF([test "x$prefix" != "xNONE"], + [gnunet_PATH="$prefix/bin${PATH_SEPARATOR}$prefix/usr/bin"]) + AC_PATH_PROG([GNUNET_CONFIG],[gnunet-config],[no],[$gnunet_PATH]) + AS_UNSET([gnunet_PATH])], + [GNUNET_CONFIG="pkg-config gnunetutil"])]) + AC_MSG_CHECKING([if GNUnet version is >= $min_gnunet_version]) + gnunet_result=no + AS_IF([test "x$GNUNET_CONFIG" != "xno" && test -n "$GNUNET_CONFIG"], + [gnunet_version=`$GNUNET_CONFIG --version | tr ' ' '\n' | sed -n '2p'` + AS_VERSION_COMPARE([$gnunet_version],[$min_gnunet_version], + [gnunet_result=no], + [gnunet_result=yes], + [gnunet_result=yes]) + AS_UNSET([gnunet_version])]) + AS_IF([test "x$gnunet_result" != "xyes"], + [AC_MSG_RESULT([no]) + m4_if([$3], ,:,[$3])], + [AC_MSG_RESULT([yes]) + m4_if([$2], ,:,[$2]) + AC_CHECK_HEADERS([sys/socket.h netinet/in.h byteswap.h]) + AS_IF([test "x${GNUNET_CFLAGS+set}" != "xset"], + [GNUNET_CFLAGS=`$GNUNET_CONFIG --cflags` + AC_SUBST([GNUNET_CFLAGS])]) + AS_IF([test "x${GNUNET_LIBS+set}" != "xset"], + [GNUNET_LIBS=`$GNUNET_CONFIG --libs` + AC_SUBST([GNUNET_LIBS])])]) + AS_UNSET([gnunet_result]) + AS_UNSET([min_gnunet_version]) +]) -- cgit v1.2.3 From 382fc8faaf4ccccd870dc7e746a9f002f3f6cfd1 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Tue, 31 Aug 2021 15:54:43 +0200 Subject: gnunet.m4: add flag to disable debug messages --- contrib/gnunet.m4 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/contrib/gnunet.m4 b/contrib/gnunet.m4 index fe70fbde1..6d9332db3 100644 --- a/contrib/gnunet.m4 +++ b/contrib/gnunet.m4 @@ -1,7 +1,7 @@ # Autoconf macro for working with GNUnet # This file is in the public domain. # -# AM_PATH_GNUNET([MINIMUM-VERSION = 0.14.2, [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]]]) +# AM_PATH_GNUNET([MINIMUM-VERSION = 0.15.3, [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]]]) # Find the GNUnet installation, either automatically or through the # --with-gnunet-prefix flag # @@ -19,14 +19,19 @@ AC_DEFUN([AM_PATH_GNUNET], [PATH to the GNUnet installation])], [gnunet_prefix="$withval"], [gnunet_prefix=""]) + AC_ARG_ENABLE([debug-log], + [AS_HELP_STRING([--disable-debug-log], + [Disable all DEBUG-level logging])], + [], + [enable_debug_log=yes]) AC_ARG_VAR([GNUNET_CONFIG],[The gnunet-config tool]) - min_gnunet_version=m4_if([$1], ,0.14.2,$1) + min_gnunet_version=m4_if([$1], ,0.15.3,$1) # Make sure the specified version is at least the version with # the features required to use this macro - AS_VERSION_COMPARE([$min_gnunet_version],[0.14.2], + AS_VERSION_COMPARE([$min_gnunet_version],[0.15.3], [AC_MSG_WARN([The specified GNUnet version $min_gnunet_version is too old.]) - AC_MSG_WARN([The minimum version has been set to 0.14.2]) - min_gnunet_version="0.14.2"]) + AC_MSG_WARN([The minimum version has been set to 0.15.3]) + min_gnunet_version="0.15.3"]) AS_IF([test "x${GNUNET_CONFIG+set}" != "xset"], [PKG_CHECK_MODULES([GNUNET],[gnunetutil >= $min_gnunet_version], [gnunet_pkgconfig=yes],[gnunet_pkgconfig=no]) @@ -57,7 +62,11 @@ AC_DEFUN([AM_PATH_GNUNET], AC_SUBST([GNUNET_CFLAGS])]) AS_IF([test "x${GNUNET_LIBS+set}" != "xset"], [GNUNET_LIBS=`$GNUNET_CONFIG --libs` - AC_SUBST([GNUNET_LIBS])])]) + AC_SUBST([GNUNET_LIBS])]) + AS_IF([test "x$enable_debug_log" = "xno"], + [AC_DEFINE([GNUNET_EXTRA_LOGGING], + [0], + [0 if debug messages should be culled])])]) AS_UNSET([gnunet_result]) AS_UNSET([min_gnunet_version]) ]) -- cgit v1.2.3 From d832ad808672dadcf94e02899525cca31054e9bf Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Tue, 7 Sep 2021 14:52:36 +0200 Subject: -indentation --- src/util/gnunet-config.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index a195d6014..b81b3b6a7 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c @@ -134,21 +134,24 @@ main (int argc, gettext_noop ( "test if the current installation supports the specified BACKEND"), &backend_check)), - GNUNET_GETOPT_option_flag ('C', - "cflags", - gettext_noop ( - "Provide an appropriate value for CFLAGS to applications building on top of GNUnet"), - &cflags), - GNUNET_GETOPT_option_flag ('j', - "libs", - gettext_noop ( - "Provide an appropriate value for LIBS to applications building on top of GNUnet"), - &libs), - GNUNET_GETOPT_option_flag ('p', - "prefix", - gettext_noop ( - "Provide the path under which GNUnet was installed"), - &prefix), + GNUNET_GETOPT_option_flag ( + 'C', + "cflags", + gettext_noop ( + "Provide an appropriate value for CFLAGS to applications building on top of GNUnet"), + &cflags), + GNUNET_GETOPT_option_flag ( + 'j', + "libs", + gettext_noop ( + "Provide an appropriate value for LIBS to applications building on top of GNUnet"), + &libs), + GNUNET_GETOPT_option_flag ( + 'p', + "prefix", + gettext_noop ( + "Provide the path under which GNUnet was installed"), + &prefix), GNUNET_CONFIGURATION_CONFIG_OPTIONS (&cs), GNUNET_GETOPT_OPTION_END }; -- cgit v1.2.3 From c7ed99ce83e15bab7fc7240a77da703d98a06edd Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Tue, 7 Sep 2021 14:57:10 +0200 Subject: -set return value following the current API --- src/util/gnunet-config.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index b81b3b6a7..2ca78577e 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c @@ -40,11 +40,13 @@ static char *backend_check; */ static int cflags; + /** * If printing the value of LIBS has been requested. */ static int libs; + /** * If printing the value of PREFIX has been requested. */ @@ -75,6 +77,7 @@ run (void *cls, { char *prefixdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_PREFIX); char *libdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); + if (1 == cflags) { fprintf (stdout, "-I%sinclude\n", prefixdir); @@ -87,6 +90,7 @@ run (void *cls, { fprintf (stdout, "%s\n", prefixdir); } + cs->global_ret = 0; GNUNET_free (prefixdir); GNUNET_free (libdir); return; -- cgit v1.2.3