Merge branch 'syncase'
[bpt/guile.git] / meta / guile-config
CommitLineData
7f864744 1#!/bin/sh
275baf01 2exec guile -e main -s $0 "$@"
9a56cb24
JB
3!#
4;;;; guile-config --- utility for linking programs with Guile
5;;;; Jim Blandy <jim@red-bean.com> --- September 1997
093d0179 6;;;;
589d9eb8 7;;;; Copyright (C) 1998, 2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
093d0179 8;;;;
73be1d9e
MV
9;;;; This library is free software; you can redistribute it and/or
10;;;; modify it under the terms of the GNU Lesser General Public
11;;;; License as published by the Free Software Foundation; either
12;;;; version 2.1 of the License, or (at your option) any later version.
093d0179 13;;;;
73be1d9e 14;;;; This library is distributed in the hope that it will be useful,
093d0179 15;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
16;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17;;;; Lesser General Public License for more details.
093d0179 18;;;;
73be1d9e
MV
19;;;; You should have received a copy of the GNU Lesser General Public
20;;;; License along with this library; if not, write to the Free Software
92205699 21;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
9a56cb24 22
275baf01 23;;; This script has been deprecated. Just use pkg-config.
9a56cb24 24
275baf01
AW
25(use-modules (ice-9 popen)
26 (ice-9 rdelim))
9a56cb24
JB
27
28\f
29;;;; main function, command-line processing
30
31;;; The script's entry point.
32(define (main args)
33 (set-program-name! (car args))
34 (let ((args (cdr args)))
35 (cond
36 ((null? args) (show-help '())
37 (quit 1))
38 ((assoc (car args) command-table)
39 => (lambda (row)
40 (set! subcommand-name (car args))
41 ((cadr row) (cdr args))))
42 (else (show-help '())
43 (quit 1)))))
44
45(define program-name #f)
46(define subcommand-name #f)
9a56cb24
JB
47
48;;; Given an executable path PATH, set program-name to something
49;;; appropriate f or use in error messages (i.e., with leading
50;;; directory names stripped).
51(define (set-program-name! path)
da509974 52 (set! program-name (basename path)))
9a56cb24
JB
53
54(define (show-help args)
55 (cond
56 ((null? args) (show-help-overview))
57 ((assoc (car args) command-table)
58 => (lambda (row) ((caddr row))))
59 (else
60 (show-help-overview))))
61
62(define (show-help-overview)
204c26b9
JB
63 (display-line-error "Usage: ")
64 (for-each (lambda (row) ((cadddr row)))
65 command-table))
66
67(define (usage-help)
68 (let ((dle display-line-error)
69 (p program-name))
70 (dle " " p " --help - show usage info (this message)")
71 (dle " " p " --help SUBCOMMAND - show help for SUBCOMMAND")))
9a56cb24 72
275baf01
AW
73(define guile-module "guile-1.8")
74
75(define (pkg-config . args)
76 (let* ((real-args (cons "pkg-config" args))
77 (pipe (apply open-pipe* OPEN_READ real-args))
78 (output (read-delimited "" pipe))
79 (ret (close-pipe pipe)))
80 (case (status:exit-val ret)
81 ((0) (if (eof-object? output) "" output))
82 (else (error "error calling pkg-config: ~A" output)))))
83
9a56cb24 84(define (show-version args)
275baf01
AW
85 (format (current-error-port) "~A - Guile version ~A"
86 program-name (pkg-config "--modversion" guile-module)))
204c26b9
JB
87
88(define (help-version)
89 (let ((dle display-line-error))
90 (dle "Usage: " program-name " --version")
91 (dle "Show the version of this script. This is also the version of")
92 (dle "Guile this script was installed with.")))
93
94(define (usage-version)
95 (display-line-error
96 " " program-name " --version - show installed script and Guile version"))
9a56cb24
JB
97
98\f
99;;;; the "link" subcommand
100
101;;; Write a set of linker flags to standard output to include the
102;;; libraries that libguile needs to link against.
103;;;
104;;; In the long run, we want to derive these flags from Guile module
105;;; declarations files that are installed along the load path. For
106;;; now, we're just going to reach into Guile's configuration info and
107;;; hack it out.
108(define (build-link args)
275baf01 109 (display (apply pkg-config "--libs" guile-module args)))
17b85401 110
9a56cb24
JB
111(define (help-link)
112 (let ((dle display-line-error))
113 (dle "Usage: " program-name " link")
114 (dle "Print linker flags for building the `guile' executable.")
204c26b9
JB
115 (dle "Print the linker command-line flags necessary to link against")
116 (dle "the Guile library, and any other libraries it requires.")))
9a56cb24 117
204c26b9
JB
118(define (usage-link)
119 (display-line-error
120 " " program-name " link - print libraries to link with"))
9a56cb24 121
9a56cb24 122
204c26b9
JB
123\f
124;;;; The "compile" subcommand
9a56cb24 125
817e0769 126(define (build-compile args)
275baf01 127 (display (apply pkg-config "--cflags" guile-module args)))
817e0769
JB
128
129(define (help-compile)
130 (let ((dle display-line-error))
131 (dle "Usage: " program-name " compile")
132 (dle "Print C compiler flags for compiling code that uses Guile.")
133 (dle "This includes any `-I' flags needed to find Guile's header files.")))
134
135(define (usage-compile)
136 (display-line-error
137 " " program-name " compile - print C compiler flags to compile with"))
9a56cb24
JB
138
139\f
140;;;; The "info" subcommand
141
142(define (build-info args)
143 (cond
275baf01
AW
144 ((null? args)
145 (display-line-error "guile-config info with no args has been removed")
146 (quit 2))
147 ((null? (cdr args))
148 (cond
149 ((string=? (car args) "guileversion")
150 (display (pkg-config "--modversion" guile-module)))
151 (else
807da880
AW
152 (display (pkg-config (format #f "--variable=~A" (car args))
153 guile-module)))))
275baf01 154 (else (display-line-error "Usage: " program-name " info VAR")
9a56cb24
JB
155 (quit 2))))
156
9a56cb24 157(define (help-info)
204c26b9 158 (let ((d display-line-error))
275baf01
AW
159 (d "Usage: " program-name " info VAR")
160 (d "Display the value of the pkg-config variable VAR used when Guile")
161 (d "was built.\n")
204c26b9
JB
162 (d "Use this command to find out where Guile was installed,")
163 (d "where it will look for Scheme code at run-time, and so on.")))
9a56cb24 164
204c26b9
JB
165(define (usage-info)
166 (display-line-error
275baf01 167 " " program-name " info VAR - print Guile build directories"))
9a56cb24
JB
168
169\f
170;;;; trivial utilities
171
9a56cb24
JB
172(define (display-line . args)
173 (apply display-line-port (current-output-port) args))
174
175(define (display-line-error . args)
176 (apply display-line-port (current-error-port) args))
177
178(define (display-line-port port . args)
179 (for-each (lambda (arg) (display arg port))
180 args)
709a308d 181 (newline port))
9a56cb24 182
9a56cb24
JB
183\f
184;;;; the command table
185
186;;; We define this down here, so Guile builds the list after all the
187;;; functions have been defined.
188(define command-table
189 (list
204c26b9
JB
190 (list "--version" show-version help-version usage-version)
191 (list "--help" show-help show-help-overview usage-help)
192 (list "link" build-link help-link usage-link)
193 (list "compile" build-compile help-compile usage-compile)
194 (list "info" build-info help-info usage-info)))
9a56cb24
JB
195
196\f
197;;; Local Variables:
198;;; mode: scheme
199;;; End: