Subject: [bug#43654] [PATCH] Add perl-opengl

From: Malte Frank Gerdes <[email-masked]>
Date: Wed, 07 Oct 2020 20:20:51 +0200

Forgot to Cc the list...

Andreas Enge <[email-masked]> writes:

> On Fri, Oct 02, 2020 at 09:33:04PM +0200, Malte Frank Gerdes wrote:
>> I just tried to build with those variables set to arbitrary values:
>> 
>> --8<---------------cut here---------------start------------->8---
>> GLUT=99999
>> VERSION=3.0 Mesa 99.99.99
>> VENDOR=NoVendor
>> RENDERER=MesaRenderer
>> --8<---------------cut here---------------end--------------->8---
>
> Actually I just went further:
> FREEGLUT=
> GLUT=
> VERSION=
> VENDOR=
> RENDERER=
> EXTENSIONS=

Nice! (I didn't even think of leaving them empty ...)

> The package compiles, but running test.pl (which showed just a blank square
> before) now fails with this message:
> Goto undefined subroutine &AutoLoader::AUTOLOAD at
> /home/andreas/.guix-profile/lib/perl5/site_perl/5.30.2/x86_64-linux-thread-multi/OpenGL.pm
> line 6178.
>
> However, I tried several of the examples, and they work.
>
> So one option would be to disable the test ("#:tests? #f") and create the
> essentially empty glversion.txt file above inside a phase. There would not
> even be a need to store it as a an auxiliary file; see the use of
> "call-with-output-file" in guix/tests.scm, for instance.
>
> What do you think?
>
> Andreas
>

IMHO disabling the tests is the best solution then - it didn't /really/
test the libraries functionality it seems, because the examples do much
more different things. 

> Something like this:
>          (add-before 'configure 'glversion
>            ;; Building utils/glversion.txt fails, and is probably
>            ;; dependent on the graphics card in the build system.
>            ;; Replace it by a content-free file; while this breaks
>            ;; the test, the examples in the examples/ subdirectory
>            ;; can be run.
>            (lambda _
>              (substitute* "Makefile.PL"
>                (("unlink") "# unlink") ; prevent utils/glversion.txt
>                                        ; from being deleted once...
>                (("\\.\"\\$make_ver clean\"") "")) ; ...and twice...
>              (substitute* "utils/Makefile"
>                (("all: glversion.txt") "all: ")) ; ...and thrice.
>              (call-with-output-file "utils/glversion.txt"
>                (lambda (port)
>                  (display (string-append "FREEGLUT=\nGLUT=\nVERSION=\n"
>                                          "VENDOR=\nRENDERER=\n"
>                                          "EXTENSIONS=\n")
>                           port)))
>              #t))
> 
> I tried to add the following instead of patching Makefile.PL:
>          (add-before 'configure 'fix-interface
>            ;; Libraries are not found in default locations, so force
>            ;; an interface.
>            (lambda _
>              (substitute* "Makefile.PL"
>                (("die \"FreeGLUT or GLUT libraries")
>                 "$interface_lib = 'FREEGLUT'; #"))
>              #t))
> 
> But it fails during compilation with error messages such as this one:
> /gnu/store/1qmd9achfkm1njzxf8hi86q53pmy9sxk-mesa-20.0.7/include/GL/glxext.h:530:169: error: unknown type name ‘GLintptr’; did you mean ‘GLint’?
> From some search engine results, I surmise that I am missing the
>   $DEFS .= " -DGL_GLEXT_LEGACY";
> from line 525 of Makefile.PL.
> 
> So maybe we will have to replace the "-L/what/ever" as you do it in your
> cdr/match phase; but instead of adding a patch that drops the "-L" in
> favour of some "@@libpaths@@" text, only to replace the new text again
> in a phase, I would use just a phase. For instance, instead of replacing
> "^@@libdirs@@", just replace "-L/usr/local/freeglut/lib".

Makes sense that it's pointless to replace the text twice.

> On Tue, Oct 06, 2020 at 12:35:43AM +0200, Andreas Enge wrote:
> > But it is already tomorrow, time to stop.
> 
> Did I mention that Guix is addictive?

I feel you 😂. It just makes fun to do things in Guix.

> If you feel like it, you could replace "cdr" by "match", and maybe test
> if all of the inputs are actually needed.

After all it seems glu and mesa are not necessary as inputs because
freeglut propagates them anyway. Is it ok to rely on propagated inputs?
They still need to be added to the library search dir though.

Attached is a updated version of your patch :)

Malte

> From 1fdc8885e04bdad9fee886c58dea9c8c712b5848 Mon Sep 17 00:00:00 2001
From: Andreas Enge <[email-masked]>
Date: Tue, 6 Oct 2020 00:43:45 +0200
Subject: [PATCH] gnu: Add perl-opengl.

* gnu/packages/perl.scm (perl-opengl): New variable.

Co-authored-by: Malte Frank Gerdes <[email-masked]>
---
 gnu/packages/perl.scm | 64 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 62 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/perl.scm b/gnu/packages/perl.scm
index 1c3d999d79..9916c579e4 100644
--- a/gnu/packages/perl.scm
+++ b/gnu/packages/perl.scm
@@ -1,6 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <[email-masked]>
-;;; Copyright © 2013, 2019 Andreas Enge <[email-masked]>
+;;; Copyright © 2013, 2019, 2020 Andreas Enge <[email-masked]>
 ;;; Copyright © 2015, 2016, 2017, 2019 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2015, 2016, 2017, 2019, 2020 Eric Bavier <[email-masked]>
 ;;; Copyright © 2015 Eric Dvorsak <[email-masked]>
@@ -27,6 +27,7 @@
 ;;; Copyright © 2020 Vincent Legoll <[email-masked]>
 ;;; Copyright © 2020 Paul Garlick <[email-masked]>
 ;;; Copyright © 2020 Nicolas Goaziou <[email-masked]>
+;;; Copyright © 2020 Malte Frank Gerdes <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -74,7 +75,8 @@
   #:use-module (gnu packages sdl)
   #:use-module (gnu packages textutils)
   #:use-module (gnu packages video)
-  #:use-module (gnu packages web))
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xorg))
 
 ;;;
 ;;; Please: Try to add new module packages in alphabetic order.
@@ -7870,6 +7872,64 @@ technology to store hierarchical information such as links to other
 documents within a single file.")
     (license (package-license perl))))
 
+(define-public perl-opengl
+  (package
+    (name "perl-opengl")
+    (version "0.70")
+    (source
+      (origin
+        (method url-fetch)
+        (uri (string-append
+               "mirror://cpan/authors/id/C/CH/CHM/OpenGL-"
+               version
+               ".tar.gz"))
+        (sha256
+          (base32
+            "1q3lz168q081iwl9jg21fbzhp9la79gav9mv6nmh2jab83s2l3mj"))))
+    (build-system perl-build-system)
+    (inputs `(("freeglut" ,freeglut)
+              ("libxi" ,libxi)
+              ("libxmu" ,libxmu)))
+    (arguments
+     '(#:tests? #f ; test.pl fails with our empty glversion.txt, while
+                   ; the package still seems to work on the examples
+       #:phases
+       (modify-phases %standard-phases
+         (add-before 'configure 'glversion
+           ;; Building utils/glversion.txt fails, and is probably
+           ;; dependent on the graphics card in the build system.
+           ;; Replace it by a content-free file; while this breaks
+           ;; the tests, the examples in the examples/ subdirectory
+           ;; can be run.
+           (lambda _
+             (substitute* "Makefile.PL"
+               (("unlink") "# unlink") ; prevent utils/glversion.txt
+                                       ; from being deleted once...
+               (("\\.\"\\$make_ver clean\"") "")) ; ...and twice...
+             (substitute* "utils/Makefile"
+               (("all: glversion.txt") "all: ")) ; ...and thrice.
+             (call-with-output-file "utils/glversion.txt"
+               (lambda (port)
+                 (display (string-append "FREEGLUT=\nGLUT=\nVERSION=\n"
+                                         "VENDOR=\nRENDERER=\n"
+                                         "EXTENSIONS=\n")
+                          port)))
+             #t))
+         (add-before 'configure 'fix-library-flags
+           (lambda* (#:key inputs #:allow-other-keys)
+             (substitute* "Makefile.PL"
+               (("-L/usr/local/freeglut/lib")
+                (string-append "-L" (assoc-ref inputs "freeglut") "/lib\n"
+                               "-L" (assoc-ref inputs "glu") "/lib\n"
+                               "-L" (assoc-ref inputs "mesa") "/lib\n")))
+             #t)))))
+    (home-page "https://metacpan.org/release/OpenGL")
+    (synopsis
+      "Perl bindings to the OpenGL API, GLU, and GLUT/FreeGLUT")
+    (description "The package provides Perl bindings to OpenGL, GLU
+and FreeGLUT.")
+    (license (package-license perl))))
+
 (define-public perl-package-anon
   (package
     (name "perl-package-anon")
-- 

2.28.0