3 exec $bindir/guile
-e main
-s $0 "$@"
5 ;;;; guile-config
--- utility
for linking programs with Guile
6 ;;;; Jim Blandy
<jim@red-bean.com
> --- September
1997
8 ;;;; Copyright
(C
) 1998, 2001, 2004, 2005, 2006, 2008 Free Software Foundation
, Inc.
10 ;;;; This library is free software
; you can redistribute it and
/or
11 ;;;; modify it under the terms of the GNU Lesser General Public
12 ;;;; License as published by the Free Software Foundation
; either
13 ;;;; version
2.1 of the License
, or
(at your option
) any later version.
15 ;;;; This library is distributed
in the hope that it will be useful
,
16 ;;;; but WITHOUT ANY WARRANTY
; without even the implied warranty of
17 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;;;; Lesser General Public License
for more details.
20 ;;;; You should have received a copy of the GNU Lesser General Public
21 ;;;; License along with this library
; if not
, write to the Free Software
22 ;;;; Foundation
, Inc.
, 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301 USA
25 ;;; * Add some plausible structure
for returning the right
exit status
,
26 ;;; just something that encourages people to
do the correct thing.
27 ;;; * Implement the static library support. This requires that
28 ;;; some portion of the module system be
done.
30 (use-modules
(ice-9 string-fun
))
33 ;;;; main
function, command-line processing
35 ;;; The
script's entry point.
37 (set-program-name! (car args))
38 (let ((args (cdr args)))
40 ((null? args) (show-help '())
42 ((assoc
(car args
) command-table
)
44 (set! subcommand-name
(car args
))
45 ((cadr row
) (cdr args
))))
49 (define program-name #f)
50 (define subcommand-name #f)
51 (define program-version "@GUILE_VERSION@")
53 ;;; Given an executable path PATH, set program-name to something
54 ;;; appropriate f or use in error messages (i.e., with leading
55 ;;; directory names stripped).
56 (define (set-program-name! path)
57 (set! program-name (basename path)))
59 (define (show-help args)
61 ((null? args) (show-help-overview))
62 ((assoc (car args) command-table)
63 => (lambda (row) ((caddr row))))
65 (show-help-overview))))
67 (define (show-help-overview)
68 (display-line-error "Usage: ")
69 (for-each (lambda (row) ((cadddr row)))
73 (let ((dle display-line-error)
75 (dle " " p " --help - show usage info (this message)")
76 (dle " " p " --help SUBCOMMAND - show help for SUBCOMMAND")))
78 (define (show-version args)
79 (display-line-error program-name " - Guile version " program-version))
81 (define (help-version)
82 (let ((dle display-line-error))
83 (dle "Usage: " program-name " --version")
84 (dle "Show the version of this script. This is also the version of")
85 (dle "Guile this script was installed with.")))
87 (define (usage-version)
89 " " program-name " --version - show installed script and Guile version"))
92 ;;;; the "link" subcommand
94 ;;; Write a set of linker flags to standard output to include the
95 ;;; libraries that libguile needs to link against.
97 ;;; In the long run, we want to derive these flags from Guile module
98 ;;; declarations files that are installed along the load path. For
99 ;;; now, we're just going to reach into Guile
's configuration info and
101 (define (build-link args)
103 ;; If PATH has the form FOO/libBAR.a, return the substring
104 ;; BAR, otherwise return #f.
105 (define (match-lib path)
106 (let* ((base (basename path))
107 (len (string-length base)))
109 (string=? (substring base 0 3) "lib")
110 (string=? (substring base (- len 2)) ".a"))
111 (substring base 3 (- len 2))
114 (if (> (length args) 0)
116 (string-append program-name
117 " link: arguments to subcommand not yet implemented")))
119 (let ((libdir (get-build-info 'libdir
))
122 ;; Get the string of linker flags we used to build
123 ;; Guile
, and
break it up into a list.
124 (separate-fields-discarding-char
#\space
125 (get-build-info
'LIBS)
131 ;; Turn any
"FOO/libBAR.a" elements into
"-lBAR".
132 ((match-lib
(car libs
))
134 (cons
(string-append
"-l" bar
)
137 ;; Remove any empty
strings that may have seeped
in there.
138 ((string
=?
(car libs
) "") (loop
(cdr libs
)))
140 (else (cons
(car libs
) (loop
(cdr libs
))))))))
142 ;; Include libguile itself
in the list
, along with the directory
143 ;; it was installed
in, but
do *not
* add
/usr
/lib since that may
144 ;; prevent other programs from specifying non
-/usr
/lib versions
145 ;; via their foo-config scripts. If
*any
* app puts
-L/usr
/lib
in
146 ;; the output of its foo-config
script then it may prevent the use
147 ;; a non
-/usr
/lib
install of anything that also has a
/usr
/lib
148 ;; install. For now we hard-code
/usr
/lib
, but later maybe we can
149 ;; do something
more dynamic
(i.e. what
do we need.
151 ;; Display the flags
, separated by spaces.
152 (display
(string-join
154 (get-build-info
'CFLAGS)
155 (if (or (string=? libdir "/usr/lib")
156 (string=? libdir "/usr/lib/"))
158 (string-append "-L" (get-build-info 'libdir
)))
160 (string-join other-flags
)
167 (let ((dle display-line-error
))
168 (dle
"Usage: " program-name
" link")
169 (dle
"Print linker flags for building the `guile' executable.")
170 (dle
"Print the linker command-line flags necessary to link against")
171 (dle
"the Guile library, and any other libraries it requires.")))
175 " " program-name
" link - print libraries to link with"))
179 ;;;; The
"compile" subcommand
181 (define
(build-compile args
)
182 (if (> (length args
) 0)
184 (string-append program-name
185 " compile: no arguments expected")))
187 ;; See gcc manual wrt fixincludes. Search
for "Use of
188 ;; `-I/usr/include' may cause trouble." For now we hard-code this.
189 ;; Later maybe we can
do something
more dynamic.
192 (if (not
(string
=?
(get-build-info
'includedir) "/usr/include"))
193 (string-append "-I" (get-build-info 'includedir
) " ")
196 (get-build-info
'CFLAGS)
200 (define (help-compile)
201 (let ((dle display-line-error))
202 (dle "Usage: " program-name " compile")
203 (dle "Print C compiler flags for compiling code that uses Guile.")
204 (dle "This includes any `-I' flags needed to
find Guile
's header files.")))
206 (define (usage-compile)
208 " " program-name " compile - print C compiler flags to compile with"))
211 ;;;; The "info" subcommand
213 (define (build-info args)
215 ((null? args) (show-all-vars))
216 ((null? (cdr args)) (show-var (car args)))
217 (else (display-line-error "Usage: " program-name " info [VAR]")
220 (define (show-all-vars)
221 (for-each (lambda (binding)
222 (display-line (car binding) " = " (cdr binding)))
225 (define (show-var var)
226 (display (get-build-info (string->symbol var)))
230 (let ((d display-line-error))
231 (d "Usage: " program-name " info [VAR]")
232 (d "Display the value of the Makefile variable VAR used when Guile")
233 (d "was built. If VAR is omitted, display all Makefile variables.")
234 (d "Use this command to find out where Guile was installed,")
235 (d "where it will look for Scheme code at run-time, and so on.")))
239 " " program-name " info [VAR] - print Guile build directories"))
242 ;;;; trivial utilities
244 (define (get-build-info name)
245 (let ((val (assq name %guile-build-info)))
246 (if (not (pair? val))
249 program-name " " subcommand-name ": no such build-info: " name)
253 (define (display-line . args)
254 (apply display-line-port (current-output-port) args))
256 (define (display-line-error . args)
257 (apply display-line-port (current-error-port) args))
259 (define (display-line-port port . args)
260 (for-each (lambda (arg) (display arg port))
265 ;;;; the command table
267 ;;; We define this down here, so Guile builds the list after all the
268 ;;; functions have been defined.
269 (define command-table
271 (list "--version" show-version help-version usage-version)
272 (list "--help" show-help show-help-overview usage-help)
273 (list "link" build-link help-link usage-link)
274 (list "compile" build-compile help-compile usage-compile)
275 (list "info" build-info help-info usage-info)))