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 string-fun))
16 ;;;; main function, command-line processing
18 ;;; The script's entry point.
20 (set-program-name! (car args))
21 (let ((args (cdr args)))
23 ((null? args) (show-help '())
25 ((assoc (car args) command-table)
27 (set! subcommand-name (car args))
28 ((cadr row) (cdr args))))
32 (define program-name #f)
33 (define subcommand-name #f)
34 (define program-version "@-GUILE_VERSION-@")
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)
40 (set! program-name (basename path)))
42 (define (show-help args)
44 ((null? args) (show-help-overview))
45 ((assoc (car args) command-table)
46 => (lambda (row) ((caddr row))))
48 (show-help-overview))))
50 (define (show-help-overview)
51 (display-line-error "Usage: ")
52 (for-each (lambda (row) ((cadddr row)))
56 (let ((dle display-line-error)
58 (dle " " p " --help - show usage info (this message)")
59 (dle " " p " --help SUBCOMMAND - show help for SUBCOMMAND")))
61 (define (show-version args)
62 (display-line-error program-name " - Guile version " program-version))
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.")))
70 (define (usage-version)
72 " " program-name " --version - show installed script and Guile version"))
75 ;;;; the "link" subcommand
77 ;;; Write a set of linker flags to standard output to include the
78 ;;; libraries that libguile needs to link against.
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
84 (define (build-link args)
85 (if (> (length args) 0)
87 (string-append program-name
88 " link: arguments to subcommand not yet implemented")))
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)))
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))
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)
112 ;; Turn any "FOO/libBAR.a" elements into "-lBAR".
113 ((match-lib (car libs))
115 (cons (string-append "-l" bar)
118 ;; Remove any empty strings that may have seeped in there.
119 ((string=? (car libs) "") (loop (cdr libs)))
121 (else (cons (car libs) (loop (cdr libs)))))))
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))
126 (cons "-lguile" flags))))
128 ;; Display the flags, separated by spaces.
129 (display-separated flags)
133 (let ((dle display-line-error))
134 (dle "Usage: " program-name " link")
135 (dle "Print linker flags for building the `guile' executable.")
136 (dle "Print the linker command-line flags necessary to link against")
137 (dle "the Guile library, and any other libraries it requires.")))
141 " " program-name " link - print libraries to link with"))
145 ;;;; The "compile" subcommand
147 (define (build-compile args)
148 (if (> (length args) 0)
150 (string-append program-name
151 " compile: no arguments expected")))
152 (display-line "-I" (get-build-info 'includedir)))
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.")))
160 (define (usage-compile)
162 " " program-name " compile - print C compiler flags to compile with"))
165 ;;;; The "info" subcommand
167 (define (build-info args)
169 ((null? args) (show-all-vars))
170 ((null? (cdr args)) (show-var (car args)))
171 (else (display-line-error "Usage: " program-name " info [VAR]")
174 (define (show-all-vars)
175 (for-each (lambda (binding)
176 (display-line (car binding) " = " (cdr binding)))
179 (define (show-var var)
180 (display (get-build-info (string->symbol var)))
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.")))
193 " " program-name " info [VAR] - print Guile build directories"))
196 ;;;; trivial utilities
198 (define (get-build-info name)
199 (let ((val (assq name %guile-build-info)))
200 (if (not (pair? val))
203 program-name " " subcommand-name ": no such build-info: " name)
207 (define (display-line . args)
208 (apply display-line-port (current-output-port) args))
210 (define (display-line-error . args)
211 (apply display-line-port (current-error-port) args))
213 (define (display-line-port port . args)
214 (for-each (lambda (arg) (display arg port))
218 (define (display-separated args)
219 (let loop ((args args))
221 ((null? (cdr args)) (display (car args)))
222 (else (display (car args))
224 (loop (cdr args))))))
227 ;;;; the command table
229 ;;; We define this down here, so Guile builds the list after all the
230 ;;; functions have been defined.
231 (define command-table
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)))