Subject: [PATCH] gnu: plan9port: Fix fontsrv and font substitutes.

From: Homo <[email-masked]>
Date: Mon, 30 Dec 2024 04:48:39 +0200

src/libdraw/openfont.c already substitutes "/lib/font/bit/" to "$PLAN9/font/",
so it's not necessary to do that in [arguments].

* gnu/packages/patches/plan9port-fontsrv.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/plan9.scm (plan9port)[source]: Use it.
[arguments] Remove "/lib/font/bit" substitute and substitute more fonts.

Change-Id: Ic99b5ed29e13bcdfde62e065fb189a9c6b5a9580
---
 gnu/local.mk                                 |  1 +
 gnu/packages/patches/plan9port-fontsrv.patch | 30 ++++++++++++++++
 gnu/packages/plan9.scm                       | 36 +++++++++++++++-----
 3 files changed, 58 insertions(+), 9 deletions(-)
 create mode 100644 gnu/packages/patches/plan9port-fontsrv.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 84160f407a..5e37af1d8a 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1959,6 +1959,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/pdfpc-build-with-vala-0.56.patch         \
   %D%/packages/patches/pdl-2.019-glut-bitmap-fonts.patch	\
   %D%/packages/patches/petri-foo-0.1.87-fix-recent-file-not-exist.patch			\
+  %D%/packages/patches/plan9port-fontsrv.patch			\
   %D%/packages/patches/plasma-framework-fix-KF5PlasmaMacros.cmake.patch \
   %D%/packages/patches/plasp-fix-normalization.patch \
   %D%/packages/patches/plasp-include-iostream.patch \
diff --git a/gnu/packages/patches/plan9port-fontsrv.patch b/gnu/packages/patches/plan9port-fontsrv.patch
new file mode 100644
index 0000000000..60620508f4
--- /dev/null
+++ b/gnu/packages/patches/plan9port-fontsrv.patch
@@ -0,0 +1,30 @@
+Remove unnecessary check that prevents fontsrv from building.
+
+diff --git a/INSTALL b/INSTALL
+index bfc08d52..c84e750c 100755
+--- a/INSTALL
++++ b/INSTALL
+@@ -112,23 +112,6 @@ if [ `uname` = Darwin ]; then
+ 	rm -f ./a.out
+ fi
+ 
+-if [ `uname` != Darwin ]; then
+-	# Determine whether fontsrv X11 files are available.
+-	rm -f a.out
+-	cc -o a.out -c -Iinclude -I/usr/include -I/usr/local/include -I/usr/include/freetype2 -I/usr/local/include/freetype2 \
+-	    -I/usr/X11R7/include -I/usr/X11R7/include/freetype2 \
+-	    -I/usr/X11R6/include -I/usr/X11R6/include/freetype2 src/cmd/fontsrv/x11.c >/dev/null 2>&1
+-	if [ -f a.out ]; then
+-		echo "	fontsrv dependencies found."
+-		echo "FONTSRV=fontsrv" >>$PLAN9/config
+-	else
+-		echo "	fontsrv dependencies not found."
+-		echo "FONTSRV=" >>$PLAN9/config
+-		rm -f bin/fontsrv
+-	fi
+-	rm -f a.out
+-fi
+-
+ if [ -f LOCAL.config ]; then
+ 	echo Using LOCAL.config options:
+ 	sed 's/^/	/' LOCAL.config
diff --git a/gnu/packages/plan9.scm b/gnu/packages/plan9.scm
index 5f6a47d5a7..f83e8c62bf 100644
--- a/gnu/packages/plan9.scm
+++ b/gnu/packages/plan9.scm
@@ -24,6 +24,7 @@ (define-module (gnu packages plan9)
   #:use-module (guix gexp)
   #:use-module (guix utils)
   #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (gnu packages)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages fontutils)
@@ -104,6 +105,7 @@ (define-public plan9port
                 (sha256
                  (base32
                   "01343jvn8kr63i78h8xlgscn6wihdsr44xzh1cylvhigjbqw8n2x"))
+                (patches (search-patches "plan9port-fontsrv.patch"))
                 (modules '((guix build utils)))
                 (snippet #~(for-each delete-file-recursively
                                      '("font/luc" ;nonfree
@@ -118,16 +120,32 @@ (define-public plan9port
                    (lambda _
                      (let ((dest (string-append #$output "/plan9")))
                        (delete-file "src/cmd/mk/mk.pdf")
+                       ;; TODO: substitute font in src/cmd/venti/srv/graph.c
                        (substitute* "src/cmd/acme/acme.c"
-                         (("/lib/font/bit/lucsans/euro.8.font")
-                          (string-append dest
-                                         "/font/fixed/unicode.5x8.font"))
-                         (("/lib/font/bit/lucm/unicode.9.font")
-                          (string-append dest
-                                         "/font/fixed/unicode.6x9.font")))
-                       (substitute* (find-files "src")
-                         (("/lib/font/bit")
-                          (string-append dest "/font")))
+                         (("lucsans/euro.8.font")
+                           "fixed/unicode.8x13.font")
+                         (("lucm/unicode.9.font")
+                           "fixed/unicode.9x15B.font"))
+                       (substitute* "src/cmd/mnihongo/mnihongo.c"
+                         (("pelm/unicode.9x24.font")
+                           "fixed/unicode.10x20.font"))
+                       (substitute* "src/cmd/rio/winwatch.c"
+                         (("lucsans/unicode.8.font")
+                           "fixed/unicode.8x13.font"))
+                       (substitute* "src/cmd/draw/stats.c"
+                         (("pelm/latin1.8.font")
+                           "fixed/unicode.8x13.font"))
+                       (substitute* "src/cmd/faces/main.c"
+                         (("pelm/latin1.8.font")
+                           "fixed/unicode.8x13.font"))
+                       (substitute* "src/cmd/fossil/view.c"
+                         (("lucsans/unicode.8.font")
+                           "fixed/unicode.8x13.font")
+                         (("lucidasans/unicode.8.font")
+                           "fixed/unicode.8x13.font"))
+                       (substitute* "src/cmd/scat/plot.c"
+                         (("luc/unicode.6.font")
+                           "fixed/unicode.6x9.font"))
                        (substitute* "bin/9c"
                          (("which")
                           (which "which")))
-- 
2.47.1