4 ;;;; guile-config --- utility for linking programs with Guile
5 ;;;; Jim Blandy <jim@red-bean.com> --- September 1997
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.
13 (use-modules (ice-9 regex)
17 ;;;; main function, command-line processing
19 ;;; The script's entry point.
21 (set-program-name! (car args))
22 (let ((args (cdr args)))
24 ((null? args) (show-help '())
26 ((assoc (car args) command-table)
28 (set! subcommand-name (car args))
29 ((cadr row) (cdr args))))
33 (define program-name #f)
34 (define subcommand-name #f)
35 (define program-version "@-GUILE_VERSION-@")
37 ;;; Given an executable path PATH, set program-name to something
38 ;;; appropriate f or use in error messages (i.e., with leading
39 ;;; directory names stripped).
40 (define (set-program-name! path)
43 ((string-match "/([^/]+)$" path)
44 => (lambda (match) (match:substring match 1)))
47 (define (show-help args)
49 ((null? args) (show-help-overview))
50 ((assoc (car args) command-table)
51 => (lambda (row) ((caddr row))))
53 (show-help-overview))))
55 (define (show-help-overview)
56 (let ((dl display-line-error))
58 (dl " " program-name " link - print libraries to link with")
59 ;; Not yet implemented.
60 ;; (dl " " program-name " main - generate initialization code")
61 (dl " " program-name " info [VAR] - print Guile build directories")
62 (dl " " program-name " --help - show usage info (this message)")
63 (dl " " program-name " --help SUBCOMMAND - show help for SUBCOMMAND")
64 (dl " " program-name " --version - show running version")))
66 (define (show-version args)
67 (display-line program-name " - Guile version " program-version))
70 ;;;; the "link" subcommand
72 ;;; Write a set of linker flags to standard output to include the
73 ;;; libraries that libguile needs to link against.
75 ;;; In the long run, we want to derive these flags from Guile module
76 ;;; declarations files that are installed along the load path. For
77 ;;; now, we're just going to reach into Guile's configuration info and
79 (define (build-link args)
80 (if (> (length args) 0)
82 (string-append program-name
83 " link: arguments to subcommand not yet implemented")))
87 ;; Get the string of linker flags we used to build
88 ;; Guile, and break it up into a list.
89 (separate-fields-discarding-char #\space
90 (get-build-info 'LIBS)
95 ;; Turn any "FOO/libBAR.a" elements into "-lBAR".
96 ((string-match "^.*/lib([^./]+).a$" (car libs))
98 (cons (string-append "-l" (match:substring match 1))
101 ;; Remove any empty strings that may have seeped in there.
102 ((string=? (car libs) "") (loop (cdr libs)))
104 (else (cons (car libs) (loop (cdr libs)))))))
106 ;; Don't omit -lguile itself from the list of flags.
107 (flags (cons "-lguile" flags)))
109 ;; Display the flags, separated by spaces.
110 (display-separated flags)
114 (let ((dle display-line-error))
115 (dle "Usage: " program-name " link")
116 (dle "Print linker flags for building the `guile' executable.")
117 (dle "Print the linker command-line flags necessary to link against the")
118 (dle "Guile library, and any other libraries it requires.")))
122 ;;;; The "main" subcommand
124 ;;; We haven't implemented this yet, because we don't have the
125 ;;; mechanisms in place to discover the installed static link
126 ;;; libraries. When we do implement this, remember to fix the message
127 ;;; in show-help-overview.
128 (define (build-main args)
129 (display-line-error program-name ": `main' subcommand not yet implemented")
133 (let ((dle display-line-error))
134 (dle "Usage: " program-name " main")
135 (dle "This subcommand is not yet implemented.")))
138 ;;;; The "info" subcommand
140 (define (build-info args)
142 ((null? args) (show-all-vars))
143 ((null? (cdr args)) (show-var (car args)))
144 (else (display-line-error "Usage: " program-name " info [VAR]")
147 (define (show-all-vars)
148 (for-each (lambda (binding)
149 (display-line (car binding) " = " (cdr binding)))
152 (define (show-var var)
153 (display (get-build-info (string->symbol var)))
157 (let ((dle display-line-error))
158 (dle "Usage: " program-name " info [VAR]")
159 (dle "Display the value of the Makefile variable VAR used when Guile")
160 (dle "was built. If VAR is omitted, display all Makefile variables.")
161 (dle "Use this command to find out where Guile was installed,")
162 (dle "where it will look for Scheme code at run-time, and so on.")))
166 ;;;; trivial utilities
168 (define (get-build-info name)
169 (let ((val (assq name %guile-build-info)))
170 (if (not (pair? val))
173 program-name " " subcommand-name ": no such build-info: " name)
177 (define (display-line . args)
178 (apply display-line-port (current-output-port) args))
180 (define (display-line-error . args)
181 (apply display-line-port (current-error-port) args))
183 (define (display-line-port port . args)
184 (for-each (lambda (arg) (display arg port))
188 (define (display-separated args)
189 (let loop ((args args))
191 ((null? (cdr args)) (display (car args)))
192 (else (display (car args))
194 (loop (cdr args))))))
197 ;;;; the command table
199 ;;; We define this down here, so Guile builds the list after all the
200 ;;; functions have been defined.
201 (define command-table
203 (list "--version" show-version show-help-overview)
204 (list "--help" show-help show-help-overview)
205 (list "link" build-link help-link)
206 (list "main" build-main help-main)
207 (list "info" build-info help-info)))