more cleanups to boot-9/psyntax
[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))
d4876cb4
AW
82 (else (display-line-error
83 (format #f "error: ~s exited with non-zero error code ~A"
84 (cons "pkg-config" args) (status:exit-val ret)))
85 ;; assume pkg-config sent diagnostics to stdout
86 (exit (status:exit-val ret))))))
275baf01 87
9a56cb24 88(define (show-version args)
275baf01
AW
89 (format (current-error-port) "~A - Guile version ~A"
90 program-name (pkg-config "--modversion" guile-module)))
204c26b9
JB
91
92(define (help-version)
93 (let ((dle display-line-error))
94 (dle "Usage: " program-name " --version")
95 (dle "Show the version of this script. This is also the version of")
96 (dle "Guile this script was installed with.")))
97
98(define (usage-version)
99 (display-line-error
100 " " program-name " --version - show installed script and Guile version"))
9a56cb24
JB
101
102\f
103;;;; the "link" subcommand
104
105;;; Write a set of linker flags to standard output to include the
106;;; libraries that libguile needs to link against.
107;;;
108;;; In the long run, we want to derive these flags from Guile module
109;;; declarations files that are installed along the load path. For
110;;; now, we're just going to reach into Guile's configuration info and
111;;; hack it out.
112(define (build-link args)
275baf01 113 (display (apply pkg-config "--libs" guile-module args)))
17b85401 114
9a56cb24
JB
115(define (help-link)
116 (let ((dle display-line-error))
117 (dle "Usage: " program-name " link")
118 (dle "Print linker flags for building the `guile' executable.")
204c26b9
JB
119 (dle "Print the linker command-line flags necessary to link against")
120 (dle "the Guile library, and any other libraries it requires.")))
9a56cb24 121
204c26b9
JB
122(define (usage-link)
123 (display-line-error
124 " " program-name " link - print libraries to link with"))
9a56cb24 125
9a56cb24 126
204c26b9
JB
127\f
128;;;; The "compile" subcommand
9a56cb24 129
817e0769 130(define (build-compile args)
275baf01 131 (display (apply pkg-config "--cflags" guile-module args)))
817e0769
JB
132
133(define (help-compile)
134 (let ((dle display-line-error))
135 (dle "Usage: " program-name " compile")
136 (dle "Print C compiler flags for compiling code that uses Guile.")
137 (dle "This includes any `-I' flags needed to find Guile's header files.")))
138
139(define (usage-compile)
140 (display-line-error
141 " " program-name " compile - print C compiler flags to compile with"))
9a56cb24
JB
142
143\f
144;;;; The "info" subcommand
145
146(define (build-info args)
147 (cond
275baf01
AW
148 ((null? args)
149 (display-line-error "guile-config info with no args has been removed")
150 (quit 2))
151 ((null? (cdr args))
152 (cond
153 ((string=? (car args) "guileversion")
154 (display (pkg-config "--modversion" guile-module)))
155 (else
807da880
AW
156 (display (pkg-config (format #f "--variable=~A" (car args))
157 guile-module)))))
275baf01 158 (else (display-line-error "Usage: " program-name " info VAR")
9a56cb24
JB
159 (quit 2))))
160
9a56cb24 161(define (help-info)
204c26b9 162 (let ((d display-line-error))
275baf01
AW
163 (d "Usage: " program-name " info VAR")
164 (d "Display the value of the pkg-config variable VAR used when Guile")
165 (d "was built.\n")
204c26b9
JB
166 (d "Use this command to find out where Guile was installed,")
167 (d "where it will look for Scheme code at run-time, and so on.")))
9a56cb24 168
204c26b9
JB
169(define (usage-info)
170 (display-line-error
275baf01 171 " " program-name " info VAR - print Guile build directories"))
9a56cb24
JB
172
173\f
174;;;; trivial utilities
175
9a56cb24
JB
176(define (display-line . args)
177 (apply display-line-port (current-output-port) args))
178
179(define (display-line-error . args)
180 (apply display-line-port (current-error-port) args))
181
182(define (display-line-port port . args)
183 (for-each (lambda (arg) (display arg port))
184 args)
709a308d 185 (newline port))
9a56cb24 186
9a56cb24
JB
187\f
188;;;; the command table
189
190;;; We define this down here, so Guile builds the list after all the
191;;; functions have been defined.
192(define command-table
193 (list
204c26b9
JB
194 (list "--version" show-version help-version usage-version)
195 (list "--help" show-help show-help-overview usage-help)
196 (list "link" build-link help-link usage-link)
197 (list "compile" build-compile help-compile usage-compile)
198 (list "info" build-info help-info usage-info)))
9a56cb24
JB
199
200\f
201;;; Local Variables:
202;;; mode: scheme
203;;; End: