unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Autoconf macros provided by Guile
@ 2023-07-08 18:26 Miguel Ángel Arruga Vivas
  0 siblings, 0 replies; only message in thread
From: Miguel Ángel Arruga Vivas @ 2023-07-08 18:26 UTC (permalink / raw)
  To: Guile Devel

[-- Attachment #1: Type: text/plain, Size: 1419 bytes --]

Hello, Guilers,

These days I'm working on a C library with Guile bindings[1], but common
idioms for optional features and external dependencies[2] are not
possible with the provided macros.

Let's say a project wants to automatically build certain feature if
library libfoo is available.  Autoconf manual suggests something along
the following lines:
---
AC_ARG_ENABLE([libfoo],
  [AS_HELP_STRING([--enable-libfoo], [...])],
  [],
  [: m4_divert_text([DEFAULTS], [enable_libfoo=check])])
AS_IF([test "x$enable_libfoo" != xno],
 [AC_CHECK_LIB([foo], [foo_init],
   [AC_SUBST([LIBFOO_LIBS], ["-lfoo"])],
   [AS_IF([test "x$enable_libfoo" != xcheck],
     [AC_MSG_FAILURE([requested libfoo but not found])])
   ])
 ])
---

Nonetheless, this fails when using Guile macros and guile itself cannot
be found:
---
AC_ARG_ENABLE([guile],
  [AS_HELP_STRING([--enable-guile], [...])],
  [],
  [: m4_divert_text([DEFAULTS], [enable_guile=check])])
AS_IF([test "x$enable_guile" != xno],
 [GUILE_PKG([3.0])
  dnl check is not useful, configure exits with error
  ...
 ])
---

Is the current behavior a desired feature?

The attached patch is compatible with old code, as the default values
are the ones used before. The failure when pkg-config cannot be found
has not been removed, as it can be checked beforehand if needed.

What do you think?  Let me know any issues, ideas or anything I could
have missed.

Best regards,
Miguel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: GUILE_PKG extension --]
[-- Type: text/x-patch, Size: 2328 bytes --]

From ae12c01377b32d6e01c59eed373f7b3050255962 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Sat, 8 Jul 2023 19:09:12 +0200
Subject: [PATCH] Add parameters to GUILE_PKG

* meta/guile.m4 (serial): Increment number.
(GUILE_PKG): Add parameters.
---
 meta/guile.m4 | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/meta/guile.m4 b/meta/guile.m4
index 48642f027..fe842468c 100644
--- a/meta/guile.m4
+++ b/meta/guile.m4
@@ -17,7 +17,7 @@
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 ## 02110-1301 USA
 
-# serial 11
+# serial 12
 
 ## Index
 ## -----
@@ -41,7 +41,7 @@
 
 # GUILE_PKG -- find Guile development files
 #
-# Usage: GUILE_PKG([VERSIONS])
+# Usage: GUILE_PKG([VERSIONS], [IF-FOUND], [IF-NOT-FOUND])
 #
 # This macro runs the @code{pkg-config} tool to find development files
 # for an available version of Guile.
@@ -49,8 +49,10 @@
 # By default, this macro will search for the latest stable version of
 # Guile (e.g. 3.0), falling back to the previous stable version
 # (e.g. 2.2) if it is available.  If no guile-@var{VERSION}.pc file is
-# found, an error is signalled.  The found version is stored in
-# @var{GUILE_EFFECTIVE_VERSION}.
+# found, an error is signalled when action @var{IF-NOT-FOUND} is not
+# provided.  Otherwise @var{IF-NOT-FOUND} is executed.  The found
+# version is stored in @var{GUILE_EFFECTIVE_VERSION} before
+# @var{IF-FOUND} is executed.
 #
 # If @code{GUILE_PROGS} was already invoked, this macro ensures that the
 # development files have the same effective version as the Guile
@@ -87,17 +89,18 @@ AC_DEFUN([GUILE_PKG],
   done
 
   if test -z "$GUILE_EFFECTIVE_VERSION"; then
-    AC_MSG_ERROR([
+    m4_default([$3], [AC_MSG_ERROR([
 No Guile development packages were found.
 
 Please verify that you have Guile installed.  If you installed Guile
 from a binary distribution, please verify that you have also installed
 the development packages.  If you installed it yourself, you might need
 to adjust your PKG_CONFIG_PATH; see the pkg-config man page for more.
-])
+])])
   fi
   AC_MSG_NOTICE([found guile $GUILE_EFFECTIVE_VERSION])
   AC_SUBST([GUILE_EFFECTIVE_VERSION])
+  $2
  ])
 
 # GUILE_FLAGS -- set flags for compiling and linking with Guile
-- 
2.40.1


[-- Attachment #3: Type: text/plain, Size: 173 bytes --]



[1] Mandatory self insert: https://www.nongnu.org/mbenchmark
[2] https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.71/html_node/External-Software.html

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-08 18:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-08 18:26 Autoconf macros provided by Guile Miguel Ángel Arruga Vivas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).