File: guile-config.in

package info (click to toggle)
lilypond 2.19.83-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 76,396 kB
  • sloc: cpp: 79,385; ansic: 75,071; lisp: 59,263; xml: 31,196; python: 22,406; sh: 8,159; yacc: 3,872; perl: 3,507; asm: 1,587; lex: 1,408; makefile: 1,048; tcl: 457; awk: 199; php: 53; csh: 50
file content (280 lines) | stat: -rw-r--r-- 9,235 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!@-bindir-@/guile \
-e main -s
!#
;;;; guile-config --- utility for linking programs with Guile
;;;; Jim Blandy <jim@red-bean.com> --- September 1997
;;;; 
;;;; 	Copyright (C) 1998, 2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
;;;; 
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 2.1 of the License, or (at your option) any later version.
;;;; 
;;;; This library 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
;;;; Lesser General Public License for more details.
;;;; 
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

;;; TODO:
;;; * Add some plausible structure for returning the right exit status,
;;;   just something that encourages people to do the correct thing.
;;; * Implement the static library support.  This requires that
;;;   some portion of the module system be done.

(use-modules (ice-9 string-fun))


;;;; main function, command-line processing

;;; The script's entry point.
(define (main args)
  (set-program-name! (car args))
  (let ((args (cdr args)))
    (cond
     ((null? args) (show-help '())
		   (quit 1))
     ((assoc (car args) command-table)
      => (lambda (row)
	   (set! subcommand-name (car args))
	   ((cadr row) (cdr args))))
     (else (show-help '())
	   (quit 1)))))

(define program-name #f)
(define subcommand-name #f)
(define program-version "@-GUILE_VERSION-@")

;;; Given an executable path PATH, set program-name to something
;;; appropriate f or use in error messages (i.e., with leading
;;; directory names stripped).
(define (set-program-name! path)
  (set! program-name (basename path)))

(define (show-help args)
  (cond
   ((null? args) (show-help-overview))
   ((assoc (car args) command-table)
    => (lambda (row) ((caddr row))))
   (else
    (show-help-overview))))

(define (show-help-overview)
  (display-line-error "Usage: ")
  (for-each (lambda (row) ((cadddr row)))
	    command-table))

(define (usage-help)
  (let ((dle display-line-error)
	(p program-name))
    (dle "  " p " --help      - show usage info (this message)")
    (dle "  " p " --help SUBCOMMAND - show help for SUBCOMMAND")))

(define (show-version args)
  (display-line-error program-name " - Guile version " program-version))

(define (help-version)
  (let ((dle display-line-error))
    (dle "Usage: " program-name " --version")
    (dle "Show the version of this script.  This is also the version of")
    (dle "Guile this script was installed with.")))

(define (usage-version)
  (display-line-error
   "  " program-name " --version   - show installed script and Guile version"))


;;;; the "link" subcommand

;;; Write a set of linker flags to standard output to include the
;;; libraries that libguile needs to link against.
;;;
;;; In the long run, we want to derive these flags from Guile module
;;; declarations files that are installed along the load path.  For
;;; now, we're just going to reach into Guile's configuration info and
;;; hack it out.
(define (build-link args)

  ;; If PATH has the form FOO/libBAR.a, return the substring
  ;; BAR, otherwise return #f.
  (define (match-lib path)
    (let* ((base (basename path))
	   (len (string-length base)))
      (if (and (> len 5)
	       (string=? (substring base 0 3) "lib")
	       (string=? (substring base (- len 2)) ".a"))
	  (substring base 3 (- len 2))
	  #f)))

  (if (> (length args) 0)
      (error
       (string-append program-name
		      " link: arguments to subcommand not yet implemented")))

  (let ((libdir (get-build-info 'libdir))
        (other-flags
         (let loop ((libs
                     ;; Get the string of linker flags we used to build
                     ;; Guile, and break it up into a list.
                     (separate-fields-discarding-char #\space
                                                      (get-build-info 'LIBS)
                                                      list)))
            
           (cond
            ((null? libs) '())
            
            ;; Turn any "FOO/libBAR.a" elements into "-lBAR".
            ((match-lib (car libs))
             => (lambda (bar)
                  (cons (string-append "-l" bar)
                        (loop (cdr libs)))))
            
            ;; Remove any empty strings that may have seeped in there.
            ((string=? (car libs) "") (loop (cdr libs)))
            
            (else (cons (car libs) (loop (cdr libs))))))))
    
    ;; Include libguile itself in the list, along with the directory
    ;; it was installed in, but do *not* add /usr/lib since that may
    ;; prevent other programs from specifying non-/usr/lib versions
    ;; via their foo-config scripts.  If *any* app puts -L/usr/lib in
    ;; the output of its foo-config script then it may prevent the use
    ;; a non-/usr/lib install of anything that also has a /usr/lib
    ;; install. For now we hard-code /usr/lib, but later maybe we can
    ;; do something more dynamic (i.e. what do we need.
    
    ;; Display the flags, separated by spaces.
    (display (string-join
	      (list
	       (get-build-info 'CFLAGS)
               (if (or (string=? libdir "/usr/lib")
                       (string=? libdir "/usr/lib/"))
		   ""
		   (string-append "-L" (get-build-info 'libdir)))
		   (string-append "-L" (getcwd) "/guile18/libguile/.libs")
               "-lguile -lltdl"
	       (string-join other-flags)

	       )))
    (newline)))


(define (help-link)
  (let ((dle display-line-error))
    (dle "Usage: " program-name " link")
    (dle "Print linker flags for building the `guile' executable.")
    (dle "Print the linker command-line flags necessary to link against")
    (dle "the Guile library, and any other libraries it requires.")))

(define (usage-link)
  (display-line-error
   "  " program-name " link        - print libraries to link with"))



;;;; The "compile" subcommand

(define (build-compile args)
  (if (> (length args) 0)
      (error
       (string-append program-name
		      " compile: no arguments expected")))

  ;; See gcc manual wrt fixincludes.  Search for "Use of
  ;; `-I/usr/include' may cause trouble."  For now we hard-code this.
  ;; Later maybe we can do something more dynamic.
  (display
   (string-append
    (if (not (string=? (get-build-info 'includedir) "/usr/include"))
	 (string-append "-I" (get-build-info 'includedir) " ")
	 " ")
    (string-append "-I" (getcwd) "/guile18" " ")
    (get-build-info 'CFLAGS)
    "\n"
    )))

(define (help-compile)
  (let ((dle display-line-error))
    (dle "Usage: " program-name " compile")
    (dle "Print C compiler flags for compiling code that uses Guile.")
    (dle "This includes any `-I' flags needed to find Guile's header files.")))

(define (usage-compile)
  (display-line-error
   "  " program-name " compile     - print C compiler flags to compile with"))


;;;; The "info" subcommand

(define (build-info args)
  (cond
   ((null? args) (show-all-vars))
   ((null? (cdr args)) (show-var (car args)))
   (else (display-line-error "Usage: " program-name " info [VAR]")
	 (quit 2))))

(define (show-all-vars)
  (for-each (lambda (binding)
	      (display-line (car binding) " = " (cdr binding)))
	    %guile-build-info))

(define (show-var var)
  (display (get-build-info (string->symbol var)))
  (newline))

(define (help-info)
  (let ((d display-line-error))
    (d "Usage: " program-name " info [VAR]")
    (d "Display the value of the Makefile variable VAR used when Guile")
    (d "was built.  If VAR is omitted, display all Makefile variables.")
    (d "Use this command to find out where Guile was installed,")
    (d "where it will look for Scheme code at run-time, and so on.")))

(define (usage-info)
  (display-line-error
   "  " program-name " info [VAR]  - print Guile build directories"))


;;;; trivial utilities

(define (get-build-info name)
  (let ((val (assq name %guile-build-info)))
    (if (not (pair? val))
	(begin
	  (display-line-error
	   program-name " " subcommand-name ": no such build-info: " name)
	  (quit 2)))
    (cdr val)))

(define (display-line . args)
  (apply display-line-port (current-output-port) args))

(define (display-line-error . args)
  (apply display-line-port (current-error-port) args))

(define (display-line-port port . args)
  (for-each (lambda (arg) (display arg port))
	    args)
  (newline port))


;;;; the command table

;;; We define this down here, so Guile builds the list after all the
;;; functions have been defined.
(define command-table
  (list
   (list "--version" show-version help-version usage-version)
   (list "--help" show-help show-help-overview usage-help)
   (list "link" build-link help-link usage-link)
   (list "compile" build-compile help-compile usage-compile)
   (list "info" build-info help-info usage-info)))


;;; Local Variables:
;;; mode: scheme
;;; End: