Subject: [bug#76246] [PATCH 1/2] gnu: Add guile-cairo-next.

From: Florian Pelz <[email-masked]>
Date: Thu, 13 Feb 2025 03:55:11 +0100

From: "pelzflorian (Florian Pelz)" <[email-masked]>

* gnu/packages/patches/guile-cairo-fix-make-check.patch: New patch.
* gnu/local.mk (dist_patch_DATA): Register patch.
* gnu/packages/gtk.scm (guile-cairo-next): New variable.

Change-Id: I328afe58d46e60243e075edead12afc0d1c4a98a
---
 gnu/local.mk                                  |   1 +
 gnu/packages/gtk.scm                          |  23 ++
 .../patches/guile-cairo-fix-make-check.patch  | 352 ++++++++++++++++++
 3 files changed, 376 insertions(+)
 create mode 100644 gnu/packages/patches/guile-cairo-fix-make-check.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 9e192f1e4f..70cc51152f 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1535,6 +1535,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/guile-linux-syscalls.patch		\
   %D%/packages/patches/guile-3.0-linux-syscalls.patch		\
   %D%/packages/patches/guile-ac-d-bus-fix-tests.patch		\
+  %D%/packages/patches/guile-cairo-fix-make-check.patch	\
   %D%/packages/patches/guile-lib-fix-tests-for-guile2.2.patch		\
   %D%/packages/patches/guile-fibers-cross-build-fix.patch 	\
   %D%/packages/patches/guile-fibers-destroy-peer-schedulers.patch \
diff --git a/gnu/packages/gtk.scm b/gnu/packages/gtk.scm
index 7ed7d7b7df..4d2356d8cf 100644
--- a/gnu/packages/gtk.scm
+++ b/gnu/packages/gtk.scm
@@ -37,6 +37,7 @@
 ;;; Copyright © 2023, 2024 Zheng Junjie <[email-masked]>
 ;;; Copyright © 2023 Janneke Nieuwenhuizen <[email-masked]>
 ;;; Copyright © 2024 John Kehayias <[email-masked]>
+;;; Copyright © 2025 Florian Pelz <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1495,6 +1496,28 @@ (define-public guile2.2-cairo
        ,@(fold alist-delete (package-inputs guile-cairo)
                '("guile" "guile-lib"))))))
 
+(define-public guile-cairo-next
+  (package
+    (inherit guile-cairo)
+    (name "guile-cairo-next")
+    ;; A commit with cairo-pointer->context, missing from [email-masked]
+    ;; and needed by animated-paintable from g-golf-gtk-4-examples.
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "git://git.savannah.nongnu.org/guile-cairo.git")
+                    (commit "30da459d7a4380174ff243b1560d5512a4bca86e")))
+              (sha256
+               (base32
+                "0dslfldzgxis8g0g3xaffcqnd1njzz23fjy0v3lc0r2694ra4ny4"))
+              ;; A patch to allow running the check phase before install.
+              (patches (search-patches "guile-cairo-fix-make-check.patch"))
+              (file-name (string-append "guile-cairo-next"))))
+    (inputs
+     (list guile-lib guile-3.0 gettext-minimal))
+    (native-inputs
+     (list autoconf-2.71 automake libtool pkg-config texinfo))))
+
 (define-public guile-rsvg
   ;; Use a recent snapshot that supports Guile 2.2 and beyond.
   (let ((commit "05c6a2fd67e4fea1a7c3ff776729dc931bae6678")
diff --git a/gnu/packages/patches/guile-cairo-fix-make-check.patch b/gnu/packages/patches/guile-cairo-fix-make-check.patch
new file mode 100644
index 0000000000..d14de7717e
--- /dev/null
+++ b/gnu/packages/patches/guile-cairo-fix-make-check.patch
@@ -0,0 +1,352 @@
+From 1de7b5e994fd99e20849d9372963c2aadf782ed1 Mon Sep 17 00:00:00 2001
+From: David Pirotte <[email-masked]>
+Date: Tue, 21 Mar 2023 01:54:04 -0300
+Subject: [PATCH] Fixing make check and make distcheck
+
+  Notes: the main goal of this patch is to remove the hard coded
+  libguile-cairo path, which makes it impossible to run 'make check',
+  unless you actualy first install the version you are working
+  on/checking [which is 'none sense'].
+
+  Also, even with the above problem fixed, there were still a few
+  nitpick things to solve so that make distcheck pass.
+
+  Finally, while workig on this patch, I also made a few cosmetic
+  changes, mostly adding a space before and after '=' in Makefile.am
+  targets, as well as having each filename on its own line for targets
+  that requires filenames. Those changes are not commented here below.
+
+* Makefile.am: (1) removing the env target, as we update env.in
+  this is not only not necessary anymore, but would actually
+  raise an error; (2) the CLEANFILES target misses $(GOBJECTS);
+  (3) using $(AM_V_GEN) in .scm.go target; (4) the EXTRA_DIST
+  target misses $(SOURCES), and does not need to ship autogen.sh
+  nor build-aux/git-version-gen.
+
+* cairo.scm: Call (dynamic-link "libguile-cairo"),
+  not (dynamic-link *cairo-lib-path*).
+
+* cairo/Makefile.am: (1) using $(AM_V_GEN) in .scm.go target; (2) in the
+  config.scm target, removing the @cairolibpath@ substitution; (3) the
+  EXTRA_DIST target misses vector-types.scm and $(NOCOMP_SOURCES).
+
+* cairo/config.scm.in: Removing the *cairo-lib-path* definition.
+
+* env.in: (1) define and use abs_top_srcdir and abs_top_builddir; (2)
+  define and export GUILE_LOAD_PATH, GUILE_LOAD_COMPILED_PATH and
+  LTDL_LIBRARY_PATH.
+
+* tests/unit-tests/Makefile.am: (1) add context-pointer.scm to the TESTS
+  target; (2) add a TEST_EXTENSIONS = .scm target; (3) update the
+  TESTS_ENVIRONMENT to use $(abs_top_builddir); (4) remove the %.check
+  target (unecessary in 'modern' autotools).
+---
+ Makefile.am                  | 26 ++++++++-----
+ cairo.scm                    |  4 +-
+ cairo/Makefile.am            | 30 ++++++++++-----
+ cairo/config.scm.in          |  8 ++--
+ env.in                       | 75 +++++++++++++++++++++++++++++++++---
+ tests/unit-tests/Makefile.am | 21 +++++-----
+ 6 files changed, 125 insertions(+), 39 deletions(-)
+
+diff --git a/Makefile.am b/Makefile.am
+index 82e41b2..514b758 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -1,5 +1,6 @@
+ # guile-cairo
+ # Copyright (C) 2007,2011  Andy Wingo <[email-masked]>
++# Copyright (C) 2023  David Pirotte <[email-masked]>
+ #
+ # This program is free software: you can redistribute it and/or modify
+ # it under the terms of the GNU Lesser General Public License as
+@@ -15,18 +16,20 @@
+ # License along with this program.  If not, see
+ # <http://www.gnu.org/licenses/>.
+ 
+-SUBDIRS = guile-cairo cairo examples tests doc
+-
+-env: Makefile env.in
+-	sed -e "s|@top_srcdir\@|$(shell cd $(top_srcdir) && pwd)|" \
+-	    $(srcdir)/env.in > env
+-	chmod +x env
++SUBDIRS = \
++	guile-cairo	\
++	cairo		\
++	examples	\
++	tests		\
++	doc
+ 
+ BUILT_SOURCES = env
+ 
+ ACLOCAL_AMFLAGS = -I m4
+ 
+-CLEANFILES = env
++CLEANFILES = \
++	env	\
++	$(GOBJECTS)
+ 
+ GOBJECTS = $(SOURCES:%.scm=%.go)
+ 
+@@ -39,7 +42,8 @@ nobase_nodist_obj_DATA = $(GOBJECTS)
+ GUILE_WARNINGS = -Wunbound-variable -Warity-mismatch -Wformat
+ SUFFIXES = .scm .go
+ .scm.go:
+-	$(top_builddir)/env $(GUILD) compile $(GUILE_TARGET) $(GUILE_WARNINGS) -o "$@" "$<"
++	$(AM_V_GEN) $(top_builddir)/env \
++	$(GUILD) compile $(GUILE_TARGET) $(GUILE_WARNINGS) -o "$@" "$<"
+ 
+ SOURCES = cairo.scm
+ 
+@@ -58,4 +62,8 @@ gen-ChangeLog:
+ 	  mv $(distdir)/cl-t $(distdir)/ChangeLog;			\
+ 	fi
+ 
+-EXTRA_DIST = env.in autogen.sh build-aux/git-version-gen HACKING COPYING.LESSER $(scm_DATA)
++EXTRA_DIST = \
++	env.in				\
++	HACKING				\
++	COPYING.LESSER			\
++	$(SOURCES)
+diff --git a/cairo.scm b/cairo.scm
+index 1361d85..2cb2793 100644
+--- a/cairo.scm
++++ b/cairo.scm
+@@ -1,5 +1,6 @@
+ ;; guile-cairo
+ ;; Copyright (C) 2007, 2011 Andy Wingo <wingo at pobox dot com>
++;; Copyright (C) 2023  David Pirotte <[email-masked]>
+ 
+ ;; This program is free software; you can redistribute it and/or modify
+ ;; it under the terms of the GNU Lesser General Public License as
+@@ -31,9 +32,10 @@
+ (module-use! (module-public-interface (current-module))
+              (resolve-interface '(cairo vector-types)))
+ 
++
+ ;; This will export many things
+ (dynamic-call "scm_init_cairo"
+-              (dynamic-link *cairo-lib-path*))
++              (dynamic-link "libguile-cairo"))
+ 
+ (if (not (member *cairo-documentation-path* documentation-files))
+     (set! documentation-files (cons *cairo-documentation-path*
+diff --git a/cairo/Makefile.am b/cairo/Makefile.am
+index 05b5973..0299d34 100644
+--- a/cairo/Makefile.am
++++ b/cairo/Makefile.am
+@@ -1,5 +1,6 @@
+ # guile-cairo
+ # Copyright (C) 2007,2011  Andy Wingo <[email-masked]>
++# Copyright (C) 2023  David Pirotte <[email-masked]>
+ #
+ # This program is free software: you can redistribute it and/or modify
+ # it under the terms of the GNU Lesser General Public License as
+@@ -15,11 +16,15 @@
+ # License along with this program.  If not, see
+ # <http://www.gnu.org/licenses/>.
+ 
+-moddir=$(datadir)/guile/site/$(GUILE_EFFECTIVE_VERSION)/cairo
+-objdir=$(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache/cairo
++moddir = $(datadir)/guile/site/$(GUILE_EFFECTIVE_VERSION)/cairo
++objdir = $(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache/cairo
+ 
+-SOURCES = config.scm vector-types.scm
+-NOCOMP_SOURCES = cairo-procedures.txt
++SOURCES = \
++	config.scm	\
++	vector-types.scm
++
++NOCOMP_SOURCES = \
++	cairo-procedures.txt
+ 
+ GOBJECTS = $(SOURCES:%.scm=%.go)
+ 
+@@ -29,12 +34,12 @@ nobase_nodist_obj_DATA = $(GOBJECTS)
+ GUILE_WARNINGS = -Wunbound-variable -Warity-mismatch -Wformat
+ SUFFIXES = .scm .go
+ .scm.go:
+-	$(top_builddir)/env $(GUILD) compile $(GUILE_TARGET) $(GUILE_WARNINGS) -o "$@" "$<"
++	$(AM_V_GEN) $(top_builddir)/env	\
++	$(GUILD) compile $(GUILE_TARGET) $(GUILE_WARNINGS) -o "$@" "$<"
+ 
+ config.scm: Makefile config.scm.in
+-	sed -e "s|@cairolibpath\@|$(libdir)/libguile-cairo|" \
+-	    -e "s|@cairodocumentationpath\@|$(moddir)/cairo-procedures.txt|" \
+-	    $(srcdir)/config.scm.in > config.scm
++	sed -e "s|\@cairodocumentationpath\@|$(moddir)/cairo-procedures.txt|" \
++		$(srcdir)/config.scm.in > config.scm
+ 
+ cairo-procedures.txt.update:
+ 	echo "Generated from upstream documentation; see COPYING.docs for info." \
+@@ -42,6 +47,11 @@ cairo-procedures.txt.update:
+ 	$(top_srcdir)/doc/docbook-to-guile-doc $(CAIRO_XML_DIR)/*.xml \
+ 	  >> $(srcdir)/cairo-procedures.txt
+ 
+-CLEANFILES = config.scm $(GOBJECTS)
++CLEANFILES = \
++	config.scm	\
++	$(GOBJECTS)
+ 
+-EXTRA_DIST = config.scm.in
++EXTRA_DIST = \
++	config.scm.in		\
++	vector-types.scm	\
++	$(NOCOMP_SOURCES)
+diff --git a/cairo/config.scm.in b/cairo/config.scm.in
+index ab008fb..92895b9 100644
+--- a/cairo/config.scm.in
++++ b/cairo/config.scm.in
+@@ -1,5 +1,6 @@
+ ;; guile-cairo
+ ;; Copyright (C) 2007, 2011 Andy Wingo <wingo pobox.com>
++;; Copyright (C) 2023  David Pirotte <[email-masked]>
+ 
+ ;; This program is free software; you can redistribute it and/or modify
+ ;; it under the terms of the GNU Lesser General Public License as
+@@ -22,8 +23,7 @@
+ ;;; Code:
+ 
+ (define-module (cairo config)
+-  :export     (*cairo-lib-path*
+-               *cairo-documentation-path*))
++  :export (*cairo-documentation-path*))
+ 
+-(define *cairo-lib-path* "@cairolibpath@")
+-(define *cairo-documentation-path* "@cairodocumentationpath@")
++(define *cairo-documentation-path*
++  "@cairodocumentationpath@")
+diff --git a/env.in b/env.in
+index eb9d020..e93d212 100644
+--- a/env.in
++++ b/env.in
+@@ -2,6 +2,7 @@
+ 
+ # guile-cairo
+ # Copyright (C) 2007,2011  Andy Wingo <[email-masked]>
++# Copyright (C) 2023  David Pirotte <[email-masked]>
+ #
+ # This program is free software: you can redistribute it and/or modify
+ # it under the terms of the GNU Lesser General Public License as
+@@ -17,15 +18,77 @@
+ # License along with this program.  If not, see
+ # <http://www.gnu.org/licenses/>.
+ 
+-this_dir=$(cd $(dirname $0) && pwd)
+-src_dir="@top_srcdir@"
+ 
+-if [ "$src_dir" != "$this_dir" ]; then
+-  GUILE_LOAD_PATH=$src_dir/$pkg:$this_dir/$pkg:$GUILE_LOAD_PATH
++abs_top_srcdir="@abs_top_srcdir@"
++abs_top_builddir="@abs_top_builddir@"
++
++[ x"$abs_top_srcdir"   = x -o ! -d "$abs_top_srcdir" -o \
++  x"$abs_top_builddir" = x -o ! -d "$abs_top_builddir" ] && {
++    echo $0: bad environment
++    echo abs_top_srcdir=$abs_top_srcdir
++    echo abs_top_builddir=$abs_top_builddir
++    exit 1
++}
++
++
++###
++### GUILE_LOAD_PATH
++###
++
++if [ x"$GUILE_LOAD_PATH" = x ]
++then
++    GUILE_LOAD_PATH="${abs_top_srcdir}"
++    if test "${abs_top_srcdir}" != "${abs_top_builddir}"; then
++        GUILE_LOAD_PATH="${abs_top_builddir}:$GUILE_LOAD_PATH"
++    fi
+ else
+-  GUILE_LOAD_PATH=$this_dir/$pkg:$GUILE_LOAD_PATH
++    GUILE_LOAD_PATH="${abs_top_srcdir}:$GUILE_LOAD_PATH"
++    if test "${abs_top_srcdir}" != "${abs_top_builddir}"; then
++        GUILE_LOAD_PATH="${abs_top_builddir}:$GUILE_LOAD_PATH"
++    fi
+ fi
+-
++## echo $GUILE_LOAD_PATH
+ export GUILE_LOAD_PATH
+ 
++
++###
++### GUILE_LOAD_COMPILED_PATH
++###
++
++if [ x"$GUILE_LOAD_COMPILED_PATH" = x ]
++then
++    GUILE_LOAD_COMPILED_PATH="${abs_top_srcdir}"
++    if test "${abs_top_srcdir}" != "${abs_top_builddir}"; then
++        GUILE_LOAD_COMPILED_PATH="${abs_top_builddir}:$GUILE_LOAD_COMPILED_PATH"
++    fi
++else
++    GUILE_LOAD_COMPILED_PATH="${abs_top_srcdir}:$GUILE_LOAD_COMPILED_PATH"
++    if test "${abs_top_srcdir}" != "${abs_top_builddir}"; then
++        GUILE_LOAD_COMPILED_PATH="${abs_top_builddir}:$GUILE_LOAD_COMPILED_PATH"
++    fi
++fi
++
++## echo $GUILE_LOAD_COMPILED_PATH
++export GUILE_LOAD_COMPILED_PATH
++
++
++###
++### LTDL_LIBRARY_PATH
++###
++
++if [ x"$LTDL_LIBRARY_PATH" = x ]
++then
++    LTDL_LIBRARY_PATH="${abs_top_srcdir}/guile-cairo:${abs_top_srcdir}/guile-cairo/.libs"
++    if test "${abs_top_srcdir}" != "${abs_top_builddir}"; then
++        LTDL_LIBRARY_PATH="${abs_top_builddir}/guile-cairo:${abs_top_builddir}/guile-cairo/.libs:$LTDL_LIBRARY_PATH"
++    fi
++else
++    LTDL_LIBRARY_PATH="${abs_top_srcdir}/guile-cairo:${abs_top_srcdir}/guile-cairo/.libs:$LTDL_LIBRARY_PATH"
++    if test "${abs_top_srcdir}" != "${abs_top_builddir}"; then
++        LTDL_LIBRARY_PATH="${abs_top_builddir}/guile-cairo:${abs_top_builddir}/guile-cairo/.libs:$LTDL_LIBRARY_PATH"
++    fi
++fi
++## echo $LTDL_LIBRARY_PATH
++export LTDL_LIBRARY_PATH
++
+ exec "$@"
+diff --git a/tests/unit-tests/Makefile.am b/tests/unit-tests/Makefile.am
+index 3ba6af9..9b13bbd 100644
+--- a/tests/unit-tests/Makefile.am
++++ b/tests/unit-tests/Makefile.am
+@@ -16,18 +16,21 @@
+ # License along with this program.  If not, see
+ # <http://www.gnu.org/licenses/>.
+ 
+-TESTS= \
+-	context-pointer.scm \
++TESTS = \
+ 	api-stability.scm	\
++	context-pointer.scm	\
+ 	version.scm
+ 
+-TESTS_ENVIRONMENT=\
+-	API_FILE=$(srcdir)/cairo.api $(top_builddir)/env guile -s
++TEST_EXTENSIONS = .scm
+ 
+-%.api.update:
+-	$(top_builddir)/env $(srcdir)/update-api $(subst ., ,$*) > $(srcdir)/$*.api
++TESTS_ENVIRONMENT = \
++	API_FILE=$(srcdir)/cairo.api		\
++	$(abs_top_builddir)/env	$(GUILE) --no-auto-compile
+ 
+-%.check: %
+-	$(TESTS_ENVIRONMENT) $*
++%.api.update:
++	$(abs_top_builddir)/env 			\
++	$(srcdir)/update-api $(subst ., ,$*) > $(srcdir)/$*.api
+ 
+-EXTRA_DIST=$(TESTS) cairo.api
++EXTRA_DIST = \
++	$(TESTS)	\
++	cairo.api
+-- 
+2.39.2
+
-- 
2.48.1