Mention that the #/ syntax now causes warnings.
[bpt/guile.git] / guile-config / guile-config.in
CommitLineData
9a56cb24
JB
1#!@-bindir-@/guile \
2-e main -s
3!#
4;;;; guile-config --- utility for linking programs with Guile
5;;;; Jim Blandy <jim@red-bean.com> --- September 1997
6
7;;; TODO:
8;;; * Add some plausible structure for returning the right exit status,
9;;; just something that encourages people to do the correct thing.
10;;; * Implement the static library support. This requires that
11;;; some portion of the module system be done.
12
da509974 13(use-modules (ice-9 string-fun))
9a56cb24
JB
14
15\f
16;;;; main function, command-line processing
17
18;;; The script's entry point.
19(define (main args)
20 (set-program-name! (car args))
21 (let ((args (cdr args)))
22 (cond
23 ((null? args) (show-help '())
24 (quit 1))
25 ((assoc (car args) command-table)
26 => (lambda (row)
27 (set! subcommand-name (car args))
28 ((cadr row) (cdr args))))
29 (else (show-help '())
30 (quit 1)))))
31
32(define program-name #f)
33(define subcommand-name #f)
34(define program-version "@-GUILE_VERSION-@")
35
36;;; Given an executable path PATH, set program-name to something
37;;; appropriate f or use in error messages (i.e., with leading
38;;; directory names stripped).
39(define (set-program-name! path)
da509974 40 (set! program-name (basename path)))
9a56cb24
JB
41
42(define (show-help args)
43 (cond
44 ((null? args) (show-help-overview))
45 ((assoc (car args) command-table)
46 => (lambda (row) ((caddr row))))
47 (else
48 (show-help-overview))))
49
50(define (show-help-overview)
204c26b9
JB
51 (display-line-error "Usage: ")
52 (for-each (lambda (row) ((cadddr row)))
53 command-table))
54
55(define (usage-help)
56 (let ((dle display-line-error)
57 (p program-name))
58 (dle " " p " --help - show usage info (this message)")
59 (dle " " p " --help SUBCOMMAND - show help for SUBCOMMAND")))
9a56cb24
JB
60
61(define (show-version args)
204c26b9
JB
62 (display-line-error program-name " - Guile version " program-version))
63
64(define (help-version)
65 (let ((dle display-line-error))
66 (dle "Usage: " program-name " --version")
67 (dle "Show the version of this script. This is also the version of")
68 (dle "Guile this script was installed with.")))
69
70(define (usage-version)
71 (display-line-error
72 " " program-name " --version - show installed script and Guile version"))
9a56cb24
JB
73
74\f
75;;;; the "link" subcommand
76
77;;; Write a set of linker flags to standard output to include the
78;;; libraries that libguile needs to link against.
79;;;
80;;; In the long run, we want to derive these flags from Guile module
81;;; declarations files that are installed along the load path. For
82;;; now, we're just going to reach into Guile's configuration info and
83;;; hack it out.
84(define (build-link args)
85 (if (> (length args) 0)
86 (error
87 (string-append program-name
88 " link: arguments to subcommand not yet implemented")))
89
da509974
JB
90 ;; If PATH has the form FOO/libBAR.a, return the substring
91 ;; BAR, otherwise return #f.
92 (define (match-lib path)
93 (let* ((base (basename path))
94 (len (string-length base)))
95 (if (and (> len 5)
96 (string=? (make-shared-substring base 0 3) "lib")
97 (string=? (make-shared-substring base (- len 2)) ".a"))
98 (make-shared-substring base 3 (- len 2))
99 #f)))
100
9a56cb24
JB
101 (let* ((flags
102 (let loop ((libs
103 ;; Get the string of linker flags we used to build
104 ;; Guile, and break it up into a list.
105 (separate-fields-discarding-char #\space
106 (get-build-info 'LIBS)
107 list)))
da509974 108
9a56cb24
JB
109 (cond
110 ((null? libs) '())
111
112 ;; Turn any "FOO/libBAR.a" elements into "-lBAR".
da509974
JB
113 ((match-lib (car libs))
114 => (lambda (bar)
115 (cons (string-append "-l" bar)
9a56cb24
JB
116 (loop (cdr libs)))))
117
118 ;; Remove any empty strings that may have seeped in there.
119 ((string=? (car libs) "") (loop (cdr libs)))
120
121 (else (cons (car libs) (loop (cdr libs)))))))
122
008112c1
JB
123 ;; Include libguile itself in the list, along with the
124 ;; directory it was installed in.
125 (flags (cons (string-append "-L" (get-build-info 'libdir))
4a276136 126 (cons "-lguile" flags))))
9a56cb24
JB
127
128 ;; Display the flags, separated by spaces.
129 (display-separated flags)
130 (newline)))
131
132(define (help-link)
133 (let ((dle display-line-error))
134 (dle "Usage: " program-name " link")
135 (dle "Print linker flags for building the `guile' executable.")
204c26b9
JB
136 (dle "Print the linker command-line flags necessary to link against")
137 (dle "the Guile library, and any other libraries it requires.")))
9a56cb24 138
204c26b9
JB
139(define (usage-link)
140 (display-line-error
141 " " program-name " link - print libraries to link with"))
9a56cb24 142
9a56cb24 143
204c26b9
JB
144\f
145;;;; The "compile" subcommand
9a56cb24 146
817e0769
JB
147(define (build-compile args)
148 (if (> (length args) 0)
149 (error
150 (string-append program-name
151 " compile: no arguments expected")))
152 (display-line "-I" (get-build-info 'includedir)))
153
154(define (help-compile)
155 (let ((dle display-line-error))
156 (dle "Usage: " program-name " compile")
157 (dle "Print C compiler flags for compiling code that uses Guile.")
158 (dle "This includes any `-I' flags needed to find Guile's header files.")))
159
160(define (usage-compile)
161 (display-line-error
162 " " program-name " compile - print C compiler flags to compile with"))
9a56cb24
JB
163
164\f
165;;;; The "info" subcommand
166
167(define (build-info args)
168 (cond
169 ((null? args) (show-all-vars))
170 ((null? (cdr args)) (show-var (car args)))
171 (else (display-line-error "Usage: " program-name " info [VAR]")
172 (quit 2))))
173
174(define (show-all-vars)
175 (for-each (lambda (binding)
176 (display-line (car binding) " = " (cdr binding)))
177 %guile-build-info))
178
179(define (show-var var)
180 (display (get-build-info (string->symbol var)))
181 (newline))
182
183(define (help-info)
204c26b9
JB
184 (let ((d display-line-error))
185 (d "Usage: " program-name " info [VAR]")
186 (d "Display the value of the Makefile variable VAR used when Guile")
187 (d "was built. If VAR is omitted, display all Makefile variables.")
188 (d "Use this command to find out where Guile was installed,")
189 (d "where it will look for Scheme code at run-time, and so on.")))
9a56cb24 190
204c26b9
JB
191(define (usage-info)
192 (display-line-error
193 " " program-name " info [VAR] - print Guile build directories"))
9a56cb24
JB
194
195\f
196;;;; trivial utilities
197
198(define (get-build-info name)
199 (let ((val (assq name %guile-build-info)))
200 (if (not (pair? val))
201 (begin
202 (display-line-error
203 program-name " " subcommand-name ": no such build-info: " name)
204 (quit 2)))
205 (cdr val)))
206
207(define (display-line . args)
208 (apply display-line-port (current-output-port) args))
209
210(define (display-line-error . args)
211 (apply display-line-port (current-error-port) args))
212
213(define (display-line-port port . args)
214 (for-each (lambda (arg) (display arg port))
215 args)
216 (newline))
217
218(define (display-separated args)
219 (let loop ((args args))
220 (cond ((null? args))
221 ((null? (cdr args)) (display (car args)))
222 (else (display (car args))
223 (display " ")
224 (loop (cdr args))))))
225
226\f
227;;;; the command table
228
229;;; We define this down here, so Guile builds the list after all the
230;;; functions have been defined.
231(define command-table
232 (list
204c26b9
JB
233 (list "--version" show-version help-version usage-version)
234 (list "--help" show-help show-help-overview usage-help)
235 (list "link" build-link help-link usage-link)
236 (list "compile" build-compile help-compile usage-compile)
237 (list "info" build-info help-info usage-info)))
9a56cb24
JB
238
239\f
240;;; Local Variables:
241;;; mode: scheme
242;;; End: