bug-guile-sdl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (Guile-SDL) Build system woes


From: Thien-Thi Nguyen
Subject: Re: (Guile-SDL) Build system woes
Date: Tue, 14 Oct 2014 11:45:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

() David Thompson <address@hidden>
() Mon, 13 Oct 2014 20:45:42 -0400

   Guix automatically sets environment variables [...] to the
   right values.  The 'configure' script successfully detects
   the libraries.

Thanks for reporting these problems.

Could you please post the config.log file?  In particular, i'm
interested in seeing where all the ‘-I DIR’ values end up.

   However, during 'make', things go south.
   Here is one such error:

     [problems w/ k2c and #include]

   I can see that the -I flag only has the path to the core SDL
   headers, but not the extension libraries.  I tried passing
   the proper CFLAGS into 'make' but to no avail.

Right, k2c invocation uses a non-standard variable ‘SDLMINUSI’
(for "SDL -I"); see configure.ac:75 and src/k/Makefile.am:64.

   Is it possible for the build system to work with such a
   configuration right now?

Unfortunately no.

   If not, would it be easy to patch?

Moderately so.  In build-aux/guile-baux/k2c, we will need to
parameterize proc ‘sorted’ (line 244) to add the same ‘-I DIR’
that proc ‘k2c/qop’ groks (evidenced by var ‘linear’, line 369).

On second thought, that can only provide a single ‘-I DIR’,
which is still insufficient for this configuration... hmmm.

I think the proper design fix would be to avoid special var
‘SDLMINUSI’ and use ‘snarfcppopts’ (src/Makefile.am:94) directly,
perhaps mining out its ‘-I DIR’ components as necessary.

I just added module ‘(guile-baux minus-i-dirs)’ to Guile-BAUX:

 http://www.gnuvola.org/software/guile-baux/

and have pushed ephemeral branch ‘q-fix-k2c’ towards that end.
Here is a patch that you can try to apply against a freshly
unpacked 0.5.1 tarball to see how these changes fare:

diff -urN guile-sdl-0.5.1 guile-sdl.NEW
diff -urN guile-sdl-0.5.1/build-aux/guile-baux/c-tsar 
guile-sdl.NEW/build-aux/guile-baux/c-tsar
--- guile-sdl-0.5.1/build-aux/guile-baux/c-tsar 2013-06-10 12:34:09.000000000 
+0200
+++ guile-sdl.NEW/build-aux/guile-baux/c-tsar   2014-10-14 07:28:50.000000000 
+0200
@@ -463,26 +463,25 @@
            (cond ((not jam)
                   (cons* r o v (normal-arglist)))
                  ((eq? '- (car jam))
-                  (apply-to-args
-                   (cdr jam)
-                   (lambda (o v . names)
-                     (check-names! names)
-                     ;; TODO: Add more checks.
-                     (cons* r o v (append! (take (normal-arglist) r)
-                                           names)))))
+                  (apply (lambda (o v . names)
+                           (check-names! names)
+                           ;; TODO: Add more checks.
+                           (cons* r o v (append! (take (normal-arglist) r)
+                                                 names)))
+                         (cdr jam)))
                  ((integer? (car jam))
-                  (apply-to-args
-                   jam (lambda (r o v . rest)
-                         (let ((count (length rest))
-                               (ro (+ r o)))
-                           (or (<= ro count)
-                               (bad-name-count (if (null? rest)
-                                                   "missing"
-                                                   "too few")))
-                           (and (zero? v)
-                                (< ro count)
-                                (bad-name-count "too many")))
-                         (check-names! rest)))
+                  (apply (lambda (r o v . rest)
+                           (let ((count (length rest))
+                                 (ro (+ r o)))
+                             (or (<= ro count)
+                                 (bad-name-count (if (null? rest)
+                                                     "missing"
+                                                     "too few")))
+                             (and (zero? v)
+                                  (< ro count)
+                                  (bad-name-count "too many")))
+                           (check-names! rest))
+                         jam)
                   ;; TODO: Add more checks.
                   jam)
                  (else
diff -urN guile-sdl-0.5.1/build-aux/guile-baux/c2x 
guile-sdl.NEW/build-aux/guile-baux/c2x
--- guile-sdl-0.5.1/build-aux/guile-baux/c2x    2012-11-08 00:16:42.000000000 
+0100
+++ guile-sdl.NEW/build-aux/guile-baux/c2x      2014-10-14 07:28:50.000000000 
+0200
@@ -288,14 +288,14 @@
              (if all-v-zero? "char" "short")
              count)
          (map (lambda (rov i)
-                (apply-to-args
-                 rov (lambda (r o v)
-                       (fs "  /* ~A */ 0x~A~A~A~A"
-                           rov
-                           (if all-v-zero? "" (number->string v 16))
-                           (number->string o 16)
-                           (number->string r 16)
-                           (if (= i (1- count)) "" ",")))))
+                (apply (lambda (r o v)
+                         (fs "  /* ~A */ 0x~A~A~A~A"
+                             rov
+                             (if all-v-zero? "" (number->string v 16))
+                             (number->string o 16)
+                             (number->string r 16)
+                             (if (= i (1- count)) "" ",")))
+                       rov))
               rovs (iota count))
          (fs "};")
          (fs "for (d = def, r = rov; r < rov + ~A; d++, r++)" count)
diff -urN guile-sdl-0.5.1/build-aux/guile-baux/k2c 
guile-sdl.NEW/build-aux/guile-baux/k2c
--- guile-sdl-0.5.1/build-aux/guile-baux/k2c    2013-09-02 12:56:33.000000000 
+0200
+++ guile-sdl.NEW/build-aux/guile-baux/k2c      2014-10-14 11:16:38.000000000 
+0200
@@ -22,7 +22,7 @@
 
 ;;; Commentary:
 
-;; Usage: k2c [OPTIONS] KSPEC
+;; Usage: k2c [OPTIONS] KSPEC [-- [CFLAGS...]]
 ;;
 ;; Write C fragment to stdout derived from the constants scanned from
 ;; the header as specified in file KSPEC.  OPTIONS are zero or more of:
@@ -30,6 +30,8 @@
 ;;  -o, --output FILE    -- write to FILE instead of stdout
 ;;  -I, --include DIR    -- look in DIR instead of /usr/include
 ;;
+;; If CFLAGS is specified, it takes precedence over ‘-I DIR’.
+;;
 ;; If output FILE is specified, as a side effect, k2c also writes
 ;; to FILE.list (thus producing two files) the form:
 ;;  ((NAME COUNT TYPE) SYMBOL ...)
@@ -105,6 +107,8 @@
 (define-module (guile-baux k2c)
   #:export (main)
   #:use-module ((guile-baux common) #:select (fs fse die check-hv qop<-args))
+  #:use-module ((guile-baux a-dash-dash-b) #:select (a-dash-dash-b))
+  #:use-module ((guile-baux minus-i-dirs) #:select (minus-i-dirs))
   #:use-module ((guile-baux forms-from) #:select (forms<-file
                                                   forms<-port))
   #:use-module ((guile-baux temporary-file) #:select (unique-i/o-file-port))
@@ -241,12 +245,13 @@
     (sort ls (lambda (a b)
                (more (car a) (car b))))))
 
-(define (sorted type who header found qspec)
+(define (sorted type who header cflags found qspec)
   (let* ((p (unique-i/o-file-port (fs "./~A.vals-" (basename who))))
          (exe (port-filename p))
          (rv #f))
     (close-port p)
-    (let ((p (open-output-pipe (fs "gcc -o ~A -x c -pipe -" exe))))
+    (let ((p (open-output-pipe (fs "gcc -o ~A -x c ~A -Wno-format -pipe -"
+                                   exe cflags))))
       (display (C-program type header found qspec) p)
       (close-pipe p))
     (let ((p (open-input-pipe exe)))
@@ -334,7 +339,7 @@
                   (apply join ",\n  " elems))
                 "};"))))
 
-(define (k2c/qop qop)
+(define (k2c/qop qop cflags)
   (let* ((specfile (if (null? (qop '()))
                        (die #f "missing input file")
                        (car (qop '()))))
@@ -357,18 +362,25 @@
                                    (map cdr raw)))))
 
     (define (from-file header)
-      (sorted type specfile header
+      (sorted type specfile header cflags
               (scan-file header
                          (qspec #:symrgx)
                          (qspec #:region))
               qspec))
 
+    (define (find-header filename)
+      (if (not (string-null? cflags))
+          (search-path
+           (minus-i-dirs cflags)
+                       filename)
+          (in-vicinity (or (qop 'include)
+                           "/usr/include")
+                       filename)))
+
     (let ((linear (cond ((qspec #:direct)
                          => directly)
                         (else
-                         (from-file (in-vicinity (or (qop 'include)
-                                                     "/usr/include")
-                                                 (qspec #:infile)))))))
+                         (from-file (find-header (qspec #:infile)))))))
 
       (define (btw!)
         (let ((head (list (string->symbol (cadr partial))
@@ -409,6 +421,10 @@
                    (help . commentary)))
   (k2c/qop
    (qop<-args args '((output  (single-char #\o) (value #t))
-                     (include (single-char #\I) (value #t))))))
+                     (include (single-char #\I) (value #t))))
+   (call-with-values (lambda ()
+                       (a-dash-dash-b args))
+     (lambda (L R)
+       (string-join R)))))
 
 ;;; k2c ends here
diff -urN guile-sdl-0.5.1/build-aux/guile-baux/minus-i-dirs.scm 
guile-sdl.NEW/build-aux/guile-baux/minus-i-dirs.scm
--- guile-sdl-0.5.1/build-aux/guile-baux/minus-i-dirs.scm       1970-01-01 
01:00:00.000000000 +0100
+++ guile-sdl.NEW/build-aux/guile-baux/minus-i-dirs.scm 2014-10-14 
07:28:50.000000000 +0200
@@ -0,0 +1,46 @@
+;;; minus-i-dirs.scm
+
+;; Copyright (C) 2014 Thien-Thi Nguyen
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 3, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this software; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Code:
+
+(define-module (guile-baux minus-i-dirs)
+  #:export (minus-i-dirs)
+  #:use-module ((ice-9 regex) #:select (match:substring
+                                        fold-matches)))
+
+(define MINUS-I (make-regexp "-I *([^ ]+)"))
+
+;; Return a list of @code{-I} directories extracted from @var{string}.
+;; Directory names must not contain whitespace.
+;; For example:
+;;
+;; @example
+;; (minus-i-dirs "-DDEBUG -I/tmp/headers -I /usr/include -I .")
+;; @result{} ("/tmp/headers" "/usr/include" ".")
+;; @end example
+;;
+;; Note that the result maintains input order.
+;;
+(define (minus-i-dirs string)
+  (reverse! (fold-matches MINUS-I string '()
+                          (lambda (m acc)
+                            (cons (match:substring m 1)
+                                  acc)))))
+
+;;; minus-i-dirs.scm ends here
diff -urN guile-sdl-0.5.1/build-aux/guile-baux/tsar 
guile-sdl.NEW/build-aux/guile-baux/tsar
--- guile-sdl-0.5.1/build-aux/guile-baux/tsar   2012-11-08 00:16:42.000000000 
+0100
+++ guile-sdl.NEW/build-aux/guile-baux/tsar     2014-10-14 07:28:50.000000000 
+0200
@@ -455,15 +455,14 @@
                             (bad-override!))))
           (or (vector? was)
               (bad-override!))
-          (apply-to-args
-           (vector->list was)
-           (lambda (r o v . was-names)
-             ;; TODO: Sanity check ‘o’, ‘v’.
-             (set-car! rov r)
-             (set! names (append (take was-names r)
-                                 (if (null? names)
-                                     (drop was-names r)
-                                     names))))))
+          (apply (lambda (r o v . was-names)
+                   ;; TODO: Sanity check ‘o’, ‘v’.
+                   (set-car! rov r)
+                   (set! names (append (take was-names r)
+                                       (if (null? names)
+                                           (drop was-names r)
+                                           names))))
+                 (vector->list was)))
         ;; Add more names if necessary.
         (and-let* ((tot (apply + rov))
                    (got (length names))
diff -urN guile-sdl-0.5.1/src/k/Makefile.am guile-sdl.NEW/src/k/Makefile.am
--- guile-sdl-0.5.1/src/k/Makefile.am   2013-08-24 11:32:36.000000000 +0200
+++ guile-sdl.NEW/src/k/Makefile.am     2014-10-14 11:14:45.000000000 +0200
@@ -61,11 +61,13 @@
 
 gx = $(top_srcdir)/build-aux/guile-baux/gbaux-do
 
+cppopts = $(DEFS) $(SDL_CFLAGS) $(SDLMINUSI)
+
 .kf.c:
-       $(gx) k2c -o $@ $< $(SDLMINUSI)
+       $(gx) k2c -o $@ $< -- $(cppopts)
 
 .kp.c:
-       $(gx) k2c -o $@ $< $(SDLMINUSI)
+       $(gx) k2c -o $@ $< -- $(cppopts)
 
 CLEANFILES = $(BUILT_SOURCES)
 CLEANFILES += *.list
diff -urN guile-sdl-0.5.1/src/k/Makefile.in guile-sdl.NEW/src/k/Makefile.in
--- guile-sdl-0.5.1/src/k/Makefile.in   2013-09-04 11:49:35.000000000 +0200
+++ guile-sdl.NEW/src/k/Makefile.in     2014-10-14 11:19:26.000000000 +0200
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.13.4 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994-2013 Free Software Foundation, Inc.
@@ -276,6 +276,7 @@
 EXTRA_DIST = $(stdf) $(stdp) $(am__append_2) $(am__append_4)
 SUFFIXES = .c .kf .kp
 gx = $(top_srcdir)/build-aux/guile-baux/gbaux-do
+cppopts = $(DEFS) $(SDL_CFLAGS) $(SDLMINUSI)
 CLEANFILES = $(BUILT_SOURCES) *.list
 all: $(BUILT_SOURCES)
        $(MAKE) $(AM_MAKEFLAGS) all-am
@@ -475,10 +476,10 @@
 
 
 .kf.c:
-       $(gx) k2c -o $@ $< $(SDLMINUSI)
+       $(gx) k2c -o $@ $< -- $(cppopts)
 
 .kp.c:
-       $(gx) k2c -o $@ $< $(SDLMINUSI)
+       $(gx) k2c -o $@ $< -- $(cppopts)
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
(The patch includes some unrelated stuff: Scheme portability
fixes that can be safely ignored for the current problem, but
anyway are required for Guile 2, which i assume you are using.)

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]