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(+) (limited to 'src') 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 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(-) (limited to 'src') 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 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(-) (limited to 'src') 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(+) (limited to 'src') 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