aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Vanni <vannilla@firemail.cc>2021-07-23 18:20:33 +0200
committerAlessio Vanni <vannilla@firemail.cc>2021-07-24 22:28:04 +0200
commitfd1bcccb9b6063d0501c81323eef81c0dd7a6340 (patch)
treecac2c551ef0cab8671546afa0190d02e13f2c895
parent31eae6bbe16302d2593b806ef3d2ac2ca9c2d8de (diff)
downloadgnunet-fd1bcccb9b6063d0501c81323eef81c0dd7a6340.tar.gz
gnunet-fd1bcccb9b6063d0501c81323eef81c0dd7a6340.zip
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)
-rw-r--r--src/util/Makefile.am5
-rw-r--r--src/util/gnunet-config.c47
2 files changed, 52 insertions, 0 deletions
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 = \
227gnunet_config_LDADD = \ 227gnunet_config_LDADD = \
228 libgnunetutil.la \ 228 libgnunetutil.la \
229 $(GN_LIBINTL) 229 $(GN_LIBINTL)
230gnunet_config_CPPFLAGS = \
231 -DINCLUDEDIR=\"$(includedir)\" \
232 -DLIBDIR=\"$(libdir)\" \
233 -DPREFIX=\"$(prefix)\" \
234 $(AM_CPPFLAGS)
230 235
231gnunet_uri_SOURCES = \ 236gnunet_uri_SOURCES = \
232 gnunet-uri.c 237 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;
74 */ 74 */
75static int full; 75static int full;
76 76
77/**
78 * If printing the value of CFLAGS has been requested.
79 */
80static int cflags;
81
82/**
83 * If printing the value of LIBS has been requested.
84 */
85static int libs;
86
87/**
88 * If printing the value of PREFIX has been requested.
89 */
90static int prefix;
91
77 92
78/** 93/**
79 * Print each option in a given section. 94 * Print each option in a given section.
@@ -150,6 +165,23 @@ run (void *cls,
150 165
151 (void) cls; 166 (void) cls;
152 (void) args; 167 (void) args;
168 if (1 == cflags || 1 == libs || 1 == prefix)
169 {
170 /* These values are defined in the makefile */
171 if (1 == cflags)
172 {
173 fprintf (stdout, "%s\n", "-I"INCLUDEDIR);
174 }
175 if (1 == libs)
176 {
177 fprintf (stdout, "%s\n", "-L"LIBDIR" -lgnunetutil");
178 }
179 if (1 == prefix)
180 {
181 fprintf (stdout, "%s\n", PREFIX);
182 }
183 return;
184 }
153 if (NULL != backend_check) 185 if (NULL != backend_check)
154 { 186 {
155 char *name; 187 char *name;
@@ -364,6 +396,21 @@ main (int argc, char *const *argv)
364 "VALUE", 396 "VALUE",
365 gettext_noop ("value to set"), 397 gettext_noop ("value to set"),
366 &value), 398 &value),
399 GNUNET_GETOPT_option_flag ('C',
400 "cflags",
401 gettext_noop (
402 "Provide an appropriate value for CFLAGS to applications building on top of GNUnet"),
403 &cflags),
404 GNUNET_GETOPT_option_flag ('j',
405 "libs",
406 gettext_noop (
407 "Provide an appropriate value for LIBS to applications building on top of GNUnet"),
408 &libs),
409 GNUNET_GETOPT_option_flag ('p',
410 "prefix",
411 gettext_noop (
412 "Provide the path under which GNUnet was installed"),
413 &prefix),
367 GNUNET_GETOPT_OPTION_END 414 GNUNET_GETOPT_OPTION_END
368 }; 415 };
369 int ret; 416 int ret;