1 | ;;;; csc.scm - Driver program for the CHICKEN compiler - felix -*- Scheme -*- |
---|
2 | ; |
---|
3 | ; Copyright (c) 2000-2007, Felix L. Winkelmann |
---|
4 | ; Copyright (c) 2008, The Chicken Team |
---|
5 | ; All rights reserved. |
---|
6 | ; |
---|
7 | ; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following |
---|
8 | ; conditions are met: |
---|
9 | ; |
---|
10 | ; Redistributions of source code must retain the above copyright notice, this list of conditions and the following |
---|
11 | ; disclaimer. |
---|
12 | ; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following |
---|
13 | ; disclaimer in the documentation and/or other materials provided with the distribution. |
---|
14 | ; Neither the name of the author nor the names of its contributors may be used to endorse or promote |
---|
15 | ; products derived from this software without specific prior written permission. |
---|
16 | ; |
---|
17 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS |
---|
18 | ; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
---|
19 | ; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR |
---|
20 | ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
21 | ; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
---|
22 | ; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
23 | ; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
---|
24 | ; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
25 | ; POSSIBILITY OF SUCH DAMAGE. |
---|
26 | |
---|
27 | |
---|
28 | (declare |
---|
29 | (block) |
---|
30 | (uses data-structures ports srfi-1 srfi-13 utils files extras )) |
---|
31 | |
---|
32 | #> |
---|
33 | #ifndef C_TARGET_CC |
---|
34 | # define C_TARGET_CC C_INSTALL_CC |
---|
35 | #endif |
---|
36 | |
---|
37 | #ifndef C_TARGET_CXX |
---|
38 | # define C_TARGET_CXX C_INSTALL_CXX |
---|
39 | #endif |
---|
40 | |
---|
41 | #ifndef C_TARGET_CFLAGS |
---|
42 | # define C_TARGET_CFLAGS C_INSTALL_CFLAGS |
---|
43 | #endif |
---|
44 | |
---|
45 | #ifndef C_TARGET_LDFLAGS |
---|
46 | # define C_TARGET_LDFLAGS C_INSTALL_LDFLAGS |
---|
47 | #endif |
---|
48 | |
---|
49 | #ifndef C_TARGET_BIN_HOME |
---|
50 | # define C_TARGET_BIN_HOME C_INSTALL_BIN_HOME |
---|
51 | #endif |
---|
52 | |
---|
53 | #ifndef C_TARGET_LIB_HOME |
---|
54 | # define C_TARGET_LIB_HOME C_INSTALL_LIB_HOME |
---|
55 | #endif |
---|
56 | |
---|
57 | #ifndef C_TARGET_STATIC_LIB_HOME |
---|
58 | # define C_TARGET_STATIC_LIB_HOME C_INSTALL_STATIC_LIB_HOME |
---|
59 | #endif |
---|
60 | |
---|
61 | #ifndef C_TARGET_INCLUDE_HOME |
---|
62 | # define C_TARGET_INCLUDE_HOME C_INSTALL_INCLUDE_HOME |
---|
63 | #endif |
---|
64 | |
---|
65 | #ifndef C_TARGET_SHARE_HOME |
---|
66 | # define C_TARGET_SHARE_HOME C_INSTALL_SHARE_HOME |
---|
67 | #endif |
---|
68 | |
---|
69 | #ifndef C_TARGET_RUN_LIB_HOME |
---|
70 | # define C_TARGET_RUN_LIB_HOME C_TARGET_LIB_HOME |
---|
71 | #endif |
---|
72 | |
---|
73 | #ifndef C_CHICKEN_PROGRAM |
---|
74 | # define C_CHICKEN_PROGRAM "chicken" |
---|
75 | #endif |
---|
76 | <# |
---|
77 | |
---|
78 | (define-foreign-variable INSTALL_BIN_HOME c-string "C_INSTALL_BIN_HOME") |
---|
79 | (define-foreign-variable INSTALL_CC c-string "C_INSTALL_CC") |
---|
80 | (define-foreign-variable INSTALL_CXX c-string "C_INSTALL_CXX") |
---|
81 | (define-foreign-variable TARGET_CC c-string "C_TARGET_CC") |
---|
82 | (define-foreign-variable TARGET_CXX c-string "C_TARGET_CXX") |
---|
83 | (define-foreign-variable TARGET_CFLAGS c-string "C_TARGET_CFLAGS") |
---|
84 | (define-foreign-variable INSTALL_CFLAGS c-string "C_INSTALL_CFLAGS") |
---|
85 | (define-foreign-variable TARGET_LDFLAGS c-string "C_TARGET_LDFLAGS") |
---|
86 | (define-foreign-variable INSTALL_LDFLAGS c-string "C_INSTALL_LDFLAGS") |
---|
87 | (define-foreign-variable INSTALL_MORE_LIBS c-string "C_INSTALL_MORE_LIBS") |
---|
88 | (define-foreign-variable INSTALL_MORE_STATIC_LIBS c-string "C_INSTALL_MORE_STATIC_LIBS") |
---|
89 | (define-foreign-variable INSTALL_SHARE_HOME c-string "C_INSTALL_SHARE_HOME") |
---|
90 | (define-foreign-variable INSTALL_LIB_HOME c-string "C_INSTALL_LIB_HOME") |
---|
91 | (define-foreign-variable INSTALL_INCLUDE_HOME c-string "C_INSTALL_INCLUDE_HOME") |
---|
92 | (define-foreign-variable INSTALL_STATIC_LIB_HOME c-string "C_INSTALL_STATIC_LIB_HOME") |
---|
93 | (define-foreign-variable TARGET_MORE_LIBS c-string "C_TARGET_MORE_LIBS") |
---|
94 | (define-foreign-variable TARGET_MORE_STATIC_LIBS c-string "C_TARGET_MORE_STATIC_LIBS") |
---|
95 | (define-foreign-variable TARGET_BIN_HOME c-string "C_TARGET_BIN_HOME") |
---|
96 | (define-foreign-variable TARGET_SHARE_HOME c-string "C_TARGET_SHARE_HOME") |
---|
97 | (define-foreign-variable TARGET_LIB_HOME c-string "C_TARGET_LIB_HOME") |
---|
98 | (define-foreign-variable TARGET_INCLUDE_HOME c-string "C_TARGET_INCLUDE_HOME") |
---|
99 | (define-foreign-variable TARGET_STATIC_LIB_HOME c-string "C_TARGET_STATIC_LIB_HOME") |
---|
100 | (define-foreign-variable TARGET_RUN_LIB_HOME c-string "C_TARGET_RUN_LIB_HOME") |
---|
101 | (define-foreign-variable CHICKEN_PROGRAM c-string "C_CHICKEN_PROGRAM") |
---|
102 | |
---|
103 | |
---|
104 | ;;; Parameters: |
---|
105 | |
---|
106 | (define mingw (eq? (build-platform) 'mingw32)) |
---|
107 | (define msvc (eq? (build-platform) 'msvc)) |
---|
108 | (define osx (eq? (software-version) 'macosx)) |
---|
109 | (define hpux-hppa (and (eq? (software-version) 'hpux) |
---|
110 | (eq? (machine-type) 'hppa))) |
---|
111 | |
---|
112 | (define (quit msg . args) |
---|
113 | (fprintf (current-error-port) "csc: ~?~%" msg args) |
---|
114 | (exit 64) ) |
---|
115 | |
---|
116 | (define chicken-prefix (getenv "CHICKEN_PREFIX")) |
---|
117 | (define arguments (command-line-arguments)) |
---|
118 | (define host-mode (member "-host" arguments)) |
---|
119 | (define cross-chicken (##sys#fudge 39)) |
---|
120 | |
---|
121 | (define (prefix str dir default) |
---|
122 | (if chicken-prefix |
---|
123 | (make-pathname (list chicken-prefix dir) str) |
---|
124 | default) ) |
---|
125 | |
---|
126 | (define (quotewrap str) |
---|
127 | (if (string-any char-whitespace? str) |
---|
128 | (string-append "\"" str "\"") |
---|
129 | str) ) |
---|
130 | |
---|
131 | (define home |
---|
132 | (quotewrap |
---|
133 | (prefix "" "share" (if host-mode INSTALL_SHARE_HOME TARGET_SHARE_HOME)))) |
---|
134 | |
---|
135 | (define translator |
---|
136 | (quotewrap |
---|
137 | (prefix "chicken" "bin" |
---|
138 | (make-pathname |
---|
139 | (if host-mode INSTALL_BIN_HOME TARGET_BIN_HOME) |
---|
140 | CHICKEN_PROGRAM)))) |
---|
141 | |
---|
142 | (define compiler (quotewrap (if host-mode INSTALL_CC TARGET_CC))) |
---|
143 | (define c++-compiler (quotewrap (if host-mode INSTALL_CXX TARGET_CXX))) |
---|
144 | (define linker (quotewrap (if msvc "link" (if host-mode INSTALL_CC TARGET_CC)))) |
---|
145 | (define c++-linker (quotewrap (if msvc "link" (if host-mode INSTALL_CXX TARGET_CXX)))) |
---|
146 | (define object-extension (if msvc "obj" "o")) |
---|
147 | (define library-extension (if msvc "lib" "a")) |
---|
148 | (define link-output-flag (if msvc "-out:" "-o ")) |
---|
149 | (define executable-extension (if msvc "exe" "")) |
---|
150 | (define compile-output-flag (if msvc "-Fo" "-o ")) |
---|
151 | (define nonstatic-compilation-options '()) |
---|
152 | (define shared-library-extension ##sys#load-dynamic-extension) |
---|
153 | (define default-translation-optimization-options '()) |
---|
154 | (define pic-options (if (or mingw msvc) '("-DPIC") '("-fPIC" "-DPIC"))) |
---|
155 | |
---|
156 | (define default-library (string-append |
---|
157 | (if msvc "libchicken-static." "libchicken.") |
---|
158 | library-extension)) |
---|
159 | (define default-unsafe-library (string-append |
---|
160 | (if msvc "libuchicken-static." "libuchicken.") |
---|
161 | library-extension)) |
---|
162 | |
---|
163 | (define cleanup-filename |
---|
164 | (if (not mingw) |
---|
165 | (lambda (s) (quotewrap s)) ; allow filenames w/ whitespace |
---|
166 | (lambda (s) s))) |
---|
167 | |
---|
168 | (define default-compilation-optimization-options (string-split (if host-mode INSTALL_CFLAGS TARGET_CFLAGS))) |
---|
169 | (define best-compilation-optimization-options default-compilation-optimization-options) |
---|
170 | (define default-linking-optimization-options (string-split (if host-mode INSTALL_LDFLAGS TARGET_LDFLAGS))) |
---|
171 | (define best-linking-optimization-options default-linking-optimization-options) |
---|
172 | |
---|
173 | (define-constant simple-options |
---|
174 | '(-explicit-use -no-trace -no-warnings -no-usual-integrations -optimize-leaf-routines -unsafe |
---|
175 | -block -disable-interrupts -fixnum-arithmetic -to-stdout -profile -raw -accumulate-profile |
---|
176 | -check-syntax -case-insensitive -benchmark-mode -shared -compile-syntax -no-lambda-info |
---|
177 | -lambda-lift -dynamic -disable-stack-overflow-checks -local |
---|
178 | -emit-external-prototypes-first -inline -extension -release -static-extensions |
---|
179 | -analyze-only -keep-shadowed-macros -inline-global) -ignore-repository) |
---|
180 | |
---|
181 | (define-constant complex-options |
---|
182 | '(-debug -output-file -heap-size -nursery -stack-size -compiler -unit -uses -keyword-style |
---|
183 | -optimize-level -include-path -database-size -extend -prelude -postlude -prologue -epilogue |
---|
184 | -inline-limit -profile-name -disable-warning |
---|
185 | -require-static-extension -emit-inline-file |
---|
186 | -feature -debug-level -heap-growth -heap-shrinkage -heap-initial-size |
---|
187 | -emit-import-library)) |
---|
188 | |
---|
189 | (define-constant shortcuts |
---|
190 | '((-h "-help") |
---|
191 | (-s "-shared") |
---|
192 | (|-E| "-extension") |
---|
193 | (|-P| "-check-syntax") |
---|
194 | (|-V| "-version") |
---|
195 | (|-Ob| "-benchmark-mode") |
---|
196 | (-f "-fixnum-arithmetic") |
---|
197 | (|-D| "-feature") |
---|
198 | (-i "-case-insensitive") |
---|
199 | (|-K| "-keyword-style") |
---|
200 | (|-X| "-extend") |
---|
201 | (|-N| "-no-usual-integrations") |
---|
202 | (-x "-explicit-use") |
---|
203 | (-u "-unsafe") |
---|
204 | (-j "-emit-import-library") |
---|
205 | (-n "-emit-inline-file") |
---|
206 | (-b "-block") ) ) |
---|
207 | |
---|
208 | (define short-options |
---|
209 | (string->list "PHhsfiENxubvwAOeWkctgG") ) |
---|
210 | |
---|
211 | |
---|
212 | ;;; Variables: |
---|
213 | |
---|
214 | (define scheme-files '()) |
---|
215 | (define generated-scheme-files '()) |
---|
216 | (define c-files '()) |
---|
217 | (define generated-c-files '()) |
---|
218 | (define object-files '()) |
---|
219 | (define generated-object-files '()) |
---|
220 | (define cpp-mode #f) |
---|
221 | (define objc-mode #f) |
---|
222 | (define embedded #f) |
---|
223 | (define inquiry-only #f) |
---|
224 | (define show-cflags #f) |
---|
225 | (define show-ldflags #f) |
---|
226 | (define show-libs #f) |
---|
227 | (define dry-run #f) |
---|
228 | |
---|
229 | (define extra-libraries |
---|
230 | (if host-mode |
---|
231 | INSTALL_MORE_STATIC_LIBS |
---|
232 | TARGET_MORE_STATIC_LIBS)) |
---|
233 | (define extra-shared-libraries |
---|
234 | (if host-mode |
---|
235 | INSTALL_MORE_LIBS |
---|
236 | TARGET_MORE_LIBS)) |
---|
237 | (define default-library-files |
---|
238 | (list |
---|
239 | (quotewrap |
---|
240 | (prefix default-library "lib" |
---|
241 | (string-append |
---|
242 | (if host-mode INSTALL_LIB_HOME TARGET_LIB_HOME) |
---|
243 | (string-append "/" default-library)))) )) |
---|
244 | (define default-shared-library-files (if msvc |
---|
245 | (list (string-append "libchicken." library-extension)) |
---|
246 | '("-lchicken"))) |
---|
247 | (define unsafe-library-files |
---|
248 | (list |
---|
249 | (quotewrap |
---|
250 | (prefix default-unsafe-library "lib" |
---|
251 | (string-append |
---|
252 | (if host-mode INSTALL_LIB_HOME TARGET_LIB_HOME) |
---|
253 | (string-append "/" default-unsafe-library)))) )) |
---|
254 | (define unsafe-shared-library-files (if msvc |
---|
255 | (list (string-append "libuchicken." library-extension)) |
---|
256 | '("-luchicken"))) |
---|
257 | (define gui-library-files default-library-files) |
---|
258 | (define gui-shared-library-files default-shared-library-files) |
---|
259 | (define library-files default-library-files) |
---|
260 | (define shared-library-files default-shared-library-files) |
---|
261 | |
---|
262 | (define translate-options '()) |
---|
263 | |
---|
264 | (define include-dir |
---|
265 | (let ((id (prefix "" "include" |
---|
266 | (if host-mode INSTALL_INCLUDE_HOME TARGET_INCLUDE_HOME)))) |
---|
267 | (and (not (member id '("/usr/include" ""))) |
---|
268 | id) ) ) |
---|
269 | |
---|
270 | (define compile-options '()) |
---|
271 | (define builtin-compile-options |
---|
272 | (if include-dir (list (conc "-I" (quotewrap include-dir))) '())) |
---|
273 | |
---|
274 | (define compile-only-flag "-c") |
---|
275 | (define translation-optimization-options default-translation-optimization-options) |
---|
276 | (define compilation-optimization-options default-compilation-optimization-options) |
---|
277 | (define linking-optimization-options default-linking-optimization-options) |
---|
278 | |
---|
279 | (define library-dir |
---|
280 | (prefix "" "lib" |
---|
281 | (if host-mode |
---|
282 | INSTALL_LIB_HOME |
---|
283 | TARGET_LIB_HOME)) ) |
---|
284 | |
---|
285 | (define link-options '()) |
---|
286 | (define builtin-link-options |
---|
287 | (cond ((or osx hpux-hppa mingw) |
---|
288 | (list (conc "-L" (quotewrap library-dir)))) |
---|
289 | (msvc |
---|
290 | (list (conc "-LIBPATH:" (quotewrap library-dir)))) |
---|
291 | (else |
---|
292 | (list |
---|
293 | (conc "-L" (quotewrap library-dir)) |
---|
294 | (conc " -Wl,-R" (quotewrap (prefix "" "lib" |
---|
295 | (if host-mode |
---|
296 | INSTALL_LIB_HOME |
---|
297 | TARGET_RUN_LIB_HOME)))) ) ) ) ) |
---|
298 | |
---|
299 | (define target-filename #f) |
---|
300 | (define verbose #f) |
---|
301 | (define keep-files #f) |
---|
302 | (define translate-only #f) |
---|
303 | (define compile-only #f) |
---|
304 | (define to-stdout #f) |
---|
305 | (define shared #f) |
---|
306 | (define static #f) |
---|
307 | (define static-libs #f) |
---|
308 | (define static-extensions #f) |
---|
309 | (define required-extensions '()) |
---|
310 | (define gui #f) |
---|
311 | |
---|
312 | |
---|
313 | ;;; Display usage information: |
---|
314 | |
---|
315 | (define (usage) |
---|
316 | (display |
---|
317 | "Usage: csc FILENAME | OPTION ... |
---|
318 | |
---|
319 | `csc' is a driver program for the CHICKEN compiler. Any Scheme, C or object |
---|
320 | files and all libraries given on the command line are translated, compiled or |
---|
321 | linked as needed. |
---|
322 | |
---|
323 | General options: |
---|
324 | |
---|
325 | -h -help display this text and exit |
---|
326 | -v show intermediate compilation stages |
---|
327 | -v2 -verbose display information about translation progress |
---|
328 | -v3 display information about all compilation stages |
---|
329 | -V -version display Scheme compiler version and exit |
---|
330 | -release display release number and exit |
---|
331 | |
---|
332 | File and pathname options: |
---|
333 | |
---|
334 | -o -output-file FILENAME specifies target executable name |
---|
335 | -I -include-path PATHNAME specifies alternative path for included files |
---|
336 | -to-stdout write compiler to stdout (implies -t) |
---|
337 | -s -shared -dynamic generate dynamically loadable shared object file |
---|
338 | |
---|
339 | Language options: |
---|
340 | |
---|
341 | -D -DSYMBOL -feature SYMBOL |
---|
342 | register feature identifier |
---|
343 | -c++ Compile via a C++ source file (.cpp) |
---|
344 | -objc Compile via Objective-C source file (.m) |
---|
345 | |
---|
346 | Syntax related options: |
---|
347 | |
---|
348 | -i -case-insensitive don't preserve case of read symbols |
---|
349 | -K -keyword-style STYLE allow alternative keyword syntax (prefix, suffix or none) |
---|
350 | -compile-syntax macros are made available at run-time |
---|
351 | -j -emit-import-library MODULE |
---|
352 | write compile-time module information into separate file |
---|
353 | |
---|
354 | Translation options: |
---|
355 | |
---|
356 | -x -explicit-use do not use units `library' and `eval' by default |
---|
357 | -P -check-syntax stop compilation after macro-expansion |
---|
358 | -A -analyze-only stop compilation after first analysis pass |
---|
359 | |
---|
360 | Debugging options: |
---|
361 | |
---|
362 | -w -no-warnings disable warnings |
---|
363 | -disable-warning CLASS disable specific class of warnings |
---|
364 | -d0 -d1 -d2 -debug-level NUMBER |
---|
365 | set level of available debugging information |
---|
366 | -no-trace disable rudimentary debugging information |
---|
367 | -profile executable emits profiling information |
---|
368 | -accumulate-profile executable emits profiling information in append mode |
---|
369 | -profile-name FILENAME name of the generated profile information file |
---|
370 | |
---|
371 | Optimization options: |
---|
372 | |
---|
373 | -O -O1 -O2 -O3 -O4 -optimize-level NUMBER |
---|
374 | enable certain sets of optimization options |
---|
375 | -optimize-leaf-routines enable leaf routine optimization |
---|
376 | -N -no-usual-integrations standard procedures may be redefined |
---|
377 | -u -unsafe disable safety checks |
---|
378 | -local assume globals are only modified in current file |
---|
379 | -b -block enable block-compilation |
---|
380 | -disable-interrupts disable interrupts in compiled code |
---|
381 | -f -fixnum-arithmetic assume all numbers are fixnums |
---|
382 | -Ob -benchmark-mode equivalent to '-block -optimize-level 4 |
---|
383 | -debug-level 0 -fixnum-arithmetic -lambda-lift |
---|
384 | -disable-interrupts -inline' |
---|
385 | -lambda-lift perform lambda-lifting |
---|
386 | -unsafe-libraries link with unsafe runtime system |
---|
387 | -disable-stack-overflow-checks disables detection of stack-overflows |
---|
388 | -inline enable inlining |
---|
389 | -inline-limit set inlining threshold |
---|
390 | -inline-global enable cross-module inlining |
---|
391 | -n -emit-inline-file FILENAME |
---|
392 | generate file with globally inlinable procedures |
---|
393 | (implies -inline -local) |
---|
394 | |
---|
395 | Configuration options: |
---|
396 | |
---|
397 | -unit NAME compile file as a library unit |
---|
398 | -uses NAME declare library unit as used. |
---|
399 | -heap-size NUMBER specifies heap-size of compiled executable |
---|
400 | -heap-initial-size NUMBER specifies heap-size at startup time |
---|
401 | -heap-growth PERCENTAGE specifies growth-rate of expanding heap |
---|
402 | -heap-shrinkage PERCENTAGE specifies shrink-rate of contracting heap |
---|
403 | -nursery NUMBER -stack-size NUMBER |
---|
404 | specifies nursery size of compiled executable |
---|
405 | -X -extend FILENAME load file before compilation commences |
---|
406 | -prelude EXPRESSION add expression to beginning of source file |
---|
407 | -postlude EXPRESSION add expression to end of source file |
---|
408 | -prologue FILENAME include file before main source file |
---|
409 | -epilogue FILENAME include file after main source file |
---|
410 | -ignore-repository do not refer to repository for extensions |
---|
411 | |
---|
412 | -e -embedded compile as embedded (don't generate `main()') |
---|
413 | -W -windows compile as Windows GUI application (MSVC only) |
---|
414 | -R -require-extension NAME require extension and import in compiled code |
---|
415 | -E -extension compile as extension (dynamic or static) |
---|
416 | -dll -library compile multiple units into a dynamic library |
---|
417 | |
---|
418 | Options to other passes: |
---|
419 | |
---|
420 | -C OPTION pass option to C compiler |
---|
421 | -L OPTION pass option to linker |
---|
422 | -I<DIR> pass \"-I<DIR>\" to C compiler (add include path) |
---|
423 | -L<DIR> pass \"-L<DIR>\" to linker (add library path) |
---|
424 | -k keep intermediate files |
---|
425 | -c stop after compilation to object files |
---|
426 | -t stop after translation to C |
---|
427 | -cc COMPILER select other C compiler than the default one |
---|
428 | -cxx COMPILER select other C++ compiler than the default one |
---|
429 | -ld COMPILER select other linker than the default one |
---|
430 | -lLIBNAME link with given library (`libLIBNAME' on UNIX, |
---|
431 | `LIBNAME.lib' on Windows) |
---|
432 | -static-libs link with static CHICKEN libraries |
---|
433 | -static generate completely statically linked executable |
---|
434 | -static-extensions link with static extensions (if available) |
---|
435 | -F<DIR> pass \"-F<DIR>\" to C compiler (add framework |
---|
436 | header path on Mac OS X) |
---|
437 | -framework NAME passed to linker on Mac OS X |
---|
438 | -rpath PATHNAME add directory to runtime library search path |
---|
439 | -Wl,... pass linker options |
---|
440 | -strip strip resulting binary |
---|
441 | |
---|
442 | Inquiry options: |
---|
443 | |
---|
444 | -home show home-directory (where support files go) |
---|
445 | -cflags show required C-compiler flags and exit |
---|
446 | -ldflags show required linker flags and exit |
---|
447 | -libs show required libraries and exit |
---|
448 | -cc-name show name of default C compiler used |
---|
449 | -cxx-name show name of default C++ compiler used |
---|
450 | -ld-name show name of default linker used |
---|
451 | -dry-run just show commands executed, don't run them |
---|
452 | (implies `-v') |
---|
453 | |
---|
454 | Obscure options: |
---|
455 | |
---|
456 | -debug MODES display debugging output for the given modes |
---|
457 | -compiler PATHNAME use other compiler than default `chicken' |
---|
458 | -disable-c-syntax-checks disable syntax checks of C code fragments |
---|
459 | -raw do not generate implicit init- and exit code |
---|
460 | -emit-external-prototypes-first emit protoypes for callbacks before foreign |
---|
461 | declarations |
---|
462 | -keep-shadowed-macros do not remove shadowed macro |
---|
463 | -host compile for host when configured for cross-compiling |
---|
464 | |
---|
465 | Options can be collapsed if unambiguous, so |
---|
466 | |
---|
467 | -vkfO |
---|
468 | |
---|
469 | is the same as |
---|
470 | |
---|
471 | -v -k -fixnum-arithmetic -optimize |
---|
472 | |
---|
473 | The contents of the environment variable CSC_OPTIONS are implicitly |
---|
474 | passed to every invocation of `csc'. |
---|
475 | " |
---|
476 | ) ) |
---|
477 | |
---|
478 | |
---|
479 | ;;; Parse arguments: |
---|
480 | |
---|
481 | (define (run args) |
---|
482 | |
---|
483 | (define (t-options . os) |
---|
484 | (set! translate-options (append translate-options os)) ) |
---|
485 | |
---|
486 | (define (check o r . n) |
---|
487 | (unless (>= (length r) (optional n 1)) |
---|
488 | (quit "not enough arguments to option `~A'" o) ) ) |
---|
489 | |
---|
490 | (define (shared-build lib) |
---|
491 | (set! translate-options (cons* "-feature" "chicken-compile-shared" translate-options)) |
---|
492 | (set! compile-options (append pic-options '("-DC_SHARED") compile-options)) |
---|
493 | (set! link-options |
---|
494 | (cons (cond |
---|
495 | (osx (if lib "-dynamiclib" "-bundle")) |
---|
496 | (msvc "-dll") |
---|
497 | (else "-shared")) link-options)) |
---|
498 | (set! shared #t) ) |
---|
499 | |
---|
500 | (let loop ([args args]) |
---|
501 | (cond [(null? args) |
---|
502 | ;Builtin search directory options do not override explict options |
---|
503 | (set! compile-options (append compile-options builtin-compile-options)) |
---|
504 | (set! link-options (append link-options builtin-link-options)) |
---|
505 | ; |
---|
506 | (when inquiry-only |
---|
507 | (when show-cflags (print* (compiler-options) #\space)) |
---|
508 | (when show-ldflags (print* (linker-options) #\space)) |
---|
509 | (when show-libs (print* (linker-libraries #t) #\space)) |
---|
510 | (newline) |
---|
511 | (exit) ) |
---|
512 | #;(when (null? scheme-files) |
---|
513 | (set! scheme-files c-files) |
---|
514 | (set! c-files '()) ) |
---|
515 | (cond [(null? scheme-files) |
---|
516 | (when (and (null? c-files) (null? object-files)) |
---|
517 | (quit "no source files specified") ) |
---|
518 | (let ((f0 (last (if (null? c-files) object-files c-files)))) |
---|
519 | (unless target-filename |
---|
520 | (set! target-filename |
---|
521 | (if shared |
---|
522 | (pathname-replace-extension f0 shared-library-extension) |
---|
523 | (pathname-replace-extension f0 executable-extension) ) ) ) ) ] |
---|
524 | [else |
---|
525 | (when (and shared (not embedded)) |
---|
526 | (set! translate-options (cons "-dynamic" translate-options)) ) |
---|
527 | (unless target-filename |
---|
528 | (set! target-filename |
---|
529 | (if shared |
---|
530 | (pathname-replace-extension (first scheme-files) shared-library-extension) |
---|
531 | (pathname-replace-extension (first scheme-files) executable-extension) ) ) ) |
---|
532 | (run-translation) ] ) |
---|
533 | (unless translate-only |
---|
534 | (run-compilation) |
---|
535 | (unless compile-only |
---|
536 | (when (member target-filename scheme-files) |
---|
537 | (printf "Warning: output file will overwrite source file `~A' - renaming source to `~A.old'~%" |
---|
538 | target-filename target-filename) |
---|
539 | (unless (zero? ($system (sprintf "mv ~A ~A.old" target-filename target-filename))) |
---|
540 | (exit last-exit-code) ) ) |
---|
541 | (run-linking)) ) ] |
---|
542 | [else |
---|
543 | (let* ([arg (car args)] |
---|
544 | [rest (cdr args)] |
---|
545 | [s (string->symbol arg)] ) |
---|
546 | (case s |
---|
547 | [(-help --help) |
---|
548 | (usage) |
---|
549 | (exit) ] |
---|
550 | [(-release) |
---|
551 | (print (chicken-version)) |
---|
552 | (exit) ] |
---|
553 | [(-version) |
---|
554 | (system (sprintf translator " -version")) |
---|
555 | (exit) ] |
---|
556 | [(-c++) |
---|
557 | (set! cpp-mode #t) |
---|
558 | (when osx (set! compile-options (cons "-no-cpp-precomp" compile-options))) ] |
---|
559 | [(-objc) |
---|
560 | (set! objc-mode #t) ] |
---|
561 | [(-static) |
---|
562 | (set! translate-options (cons* "-feature" "chicken-compile-static" translate-options)) |
---|
563 | (set! static #t) ] |
---|
564 | [(-static-libs) |
---|
565 | (set! translate-options (cons* "-feature" "chicken-compile-static" translate-options)) |
---|
566 | (set! static-libs #t) ] |
---|
567 | [(-static-extensions) |
---|
568 | (set! static-extensions #t) ] |
---|
569 | [(-cflags) |
---|
570 | (set! inquiry-only #t) |
---|
571 | (set! show-cflags #t) ] |
---|
572 | [(-ldflags) |
---|
573 | (set! inquiry-only #t) |
---|
574 | (set! show-ldflags #t) ] |
---|
575 | [(-cc-name) (print compiler) (exit 0)] |
---|
576 | [(-cxx-name) (print c++-compiler) (exit 0)] |
---|
577 | [(-ld-name) (print linker) (exit 0)] |
---|
578 | [(-home) (print home) (exit 0)] |
---|
579 | [(-libs) |
---|
580 | (set! inquiry-only #t) |
---|
581 | (set! show-libs #t) ] |
---|
582 | [(-v) |
---|
583 | (set! verbose #t) ] |
---|
584 | [(-v2 -verbose) |
---|
585 | (set! verbose #t) |
---|
586 | (t-options "-verbose") ] |
---|
587 | [(-w -no-warnings) |
---|
588 | (set! compile-options (cons "-w" compile-options)) |
---|
589 | (t-options "-no-warnings") ] |
---|
590 | [(-v3) |
---|
591 | (set! verbose #t) |
---|
592 | (t-options "-verbose") |
---|
593 | (if (not msvc) |
---|
594 | (set! compile-options (cons* "-v" "-Q" compile-options))) |
---|
595 | (set! link-options (cons (if msvc "-VERBOSE" "-v") link-options)) ] |
---|
596 | [(|-A| -analyze-only) |
---|
597 | (set! translate-only #t) |
---|
598 | (t-options "-analyze-only") ] |
---|
599 | [(|-P| -check-syntax) |
---|
600 | (set! translate-only #t) |
---|
601 | (t-options "-check-syntax") ] |
---|
602 | [(-k) (set! keep-files #t)] |
---|
603 | [(-c) (set! compile-only #t)] |
---|
604 | [(-t) (set! translate-only #t)] |
---|
605 | [(-e -embedded) |
---|
606 | (set! embedded #t) |
---|
607 | (set! compile-options (cons "-DC_EMBEDDED" compile-options)) ] |
---|
608 | [(-require-extension -R) |
---|
609 | (check s rest) |
---|
610 | (set! required-extensions (append required-extensions (list (car rest)))) |
---|
611 | (t-options "-require-extension" (car rest)) |
---|
612 | (set! rest (cdr rest)) ] |
---|
613 | [(-windows |-W|) |
---|
614 | (set! gui #t) |
---|
615 | (cond |
---|
616 | (mingw |
---|
617 | (set! link-options |
---|
618 | (cons* "-lkernel32" "-luser32" "-lgdi32" "-mwindows" |
---|
619 | link-options)) |
---|
620 | (set! compile-options (cons "-DC_WINDOWS_GUI" compile-options))) |
---|
621 | (msvc |
---|
622 | (set! link-options |
---|
623 | (cons* "kernel32.lib" "user32.lib" "gdi32.lib" link-options)) |
---|
624 | (set! compile-options (cons "-DC_WINDOWS_GUI" compile-options)))) ] |
---|
625 | [(-framework) |
---|
626 | (check s rest) |
---|
627 | (when osx |
---|
628 | (set! link-options (cons* "-framework" (car rest) link-options)) ) |
---|
629 | (set! rest (cdr rest)) ] |
---|
630 | [(-o) |
---|
631 | (check s rest) |
---|
632 | (let ([fn (car rest)]) |
---|
633 | (set! rest (cdr rest)) |
---|
634 | (set! target-filename fn) ) ] |
---|
635 | [(|-O| |-O1|) (set! rest (cons* "-optimize-level" "1" rest))] |
---|
636 | [(|-O2|) (set! rest (cons* "-optimize-level" "2" rest))] |
---|
637 | [(|-O3|) (set! rest (cons* "-optimize-level" "3" rest))] |
---|
638 | [(|-O4|) (set! rest (cons* "-optimize-level" "4" rest))] |
---|
639 | [(-d0) (set! rest (cons* "-debug-level" "0" rest))] |
---|
640 | [(-d1) (set! rest (cons* "-debug-level" "1" rest))] |
---|
641 | [(-d2) (set! rest (cons* "-debug-level" "2" rest))] |
---|
642 | [(-dry-run) |
---|
643 | (set! verbose #t) |
---|
644 | (set! dry-run #t)] |
---|
645 | [(-s -shared -dynamic) |
---|
646 | (shared-build #f) ] |
---|
647 | [(-dll -library) |
---|
648 | (shared-build #t) ] |
---|
649 | [(-compiler) |
---|
650 | (check s rest) |
---|
651 | (set! translator (car rest)) |
---|
652 | (set! rest (cdr rest)) ] |
---|
653 | [(-cc) |
---|
654 | (check s rest) |
---|
655 | (set! compiler (car rest)) |
---|
656 | (set! rest (cdr rest)) ] |
---|
657 | [(-cxx) |
---|
658 | (check s rest) |
---|
659 | (set! c++-compiler (car rest)) |
---|
660 | (set! rest (cdr rest)) ] |
---|
661 | [(-ld) |
---|
662 | (check s rest) |
---|
663 | (set! linker (car rest)) |
---|
664 | (set! rest (cdr rest)) ] |
---|
665 | [(|-I|) |
---|
666 | (check s rest) |
---|
667 | (set! rest (cons* "-include-path" (car rest) (cdr rest))) ] |
---|
668 | [(|-C|) |
---|
669 | (check s rest) |
---|
670 | (set! compile-options (append compile-options (string-split (car rest)))) |
---|
671 | (set! rest (cdr rest)) ] |
---|
672 | [(-strip) |
---|
673 | (set! link-options (append link-options (list "-s")))] |
---|
674 | [(|-L|) |
---|
675 | (check s rest) |
---|
676 | (set! link-options (append link-options (string-split (car rest)))) |
---|
677 | (set! rest (cdr rest)) ] |
---|
678 | [(-unsafe-libraries) |
---|
679 | (t-options arg) |
---|
680 | (set! library-files unsafe-library-files) |
---|
681 | (set! shared-library-files unsafe-shared-library-files) ] |
---|
682 | [(-rpath) |
---|
683 | (check s rest) |
---|
684 | (when (eq? 'gnu (build-platform)) |
---|
685 | (set! link-options (append link-options (list (string-append "-Wl,-R" (car rest))))) |
---|
686 | (set! rest (cdr rest)) ) ] |
---|
687 | [(-host) #f] |
---|
688 | [(-) |
---|
689 | (set! target-filename (make-pathname #f "a" executable-extension)) |
---|
690 | (set! scheme-files (append scheme-files '("-")))] |
---|
691 | [else |
---|
692 | (when (memq s '(-unsafe -benchmark-mode)) |
---|
693 | (when (eq? s '-benchmark-mode) |
---|
694 | (set! library-files unsafe-library-files) |
---|
695 | (set! shared-library-files unsafe-shared-library-files) ) ) |
---|
696 | (when (eq? s '-to-stdout) |
---|
697 | (set! to-stdout #t) |
---|
698 | (set! translate-only #t) ) |
---|
699 | (when (memq s '(-optimize-level -benchmark-mode)) |
---|
700 | (set! compilation-optimization-options best-compilation-optimization-options) |
---|
701 | (set! linking-optimization-options best-linking-optimization-options) ) |
---|
702 | (cond [(assq s shortcuts) => (lambda (a) (set! rest (cons (cadr a) rest)))] |
---|
703 | [(memq s simple-options) (t-options arg)] |
---|
704 | [(memq s complex-options) |
---|
705 | (check s rest) |
---|
706 | (let* ([n (car rest)] |
---|
707 | [ns (string->number n)] ) |
---|
708 | (t-options arg n) |
---|
709 | (set! rest (cdr rest)) ) ] |
---|
710 | [(and (> (string-length arg) 2) (string=? "-:" (substring arg 0 2))) |
---|
711 | (t-options arg) ] |
---|
712 | [(and (> (string-length arg) 1) |
---|
713 | (char=? #\- (string-ref arg 0)) ) |
---|
714 | (cond [(char=? #\l (string-ref arg 1)) |
---|
715 | (set! link-options (append link-options (list arg))) ] |
---|
716 | [(char=? #\L (string-ref arg 1)) |
---|
717 | (set! link-options (append link-options (list arg))) ] |
---|
718 | [(char=? #\I (string-ref arg 1)) |
---|
719 | (set! compile-options (append compile-options (list arg))) ] |
---|
720 | [(char=? #\D (string-ref arg 1)) |
---|
721 | (t-options "-feature" (substring arg 2)) ] |
---|
722 | [(char=? #\F (string-ref arg 1)) |
---|
723 | (when osx |
---|
724 | (set! compile-options (append compile-options (list arg))) ) ] |
---|
725 | [(and (> (string-length arg) 3) (string=? "-Wl," (substring arg 0 4))) |
---|
726 | (set! link-options (append link-options (list arg))) ] |
---|
727 | [(> (string-length arg) 2) |
---|
728 | (let ([opts (cdr (string->list arg))]) |
---|
729 | (if (null? (lset-difference char=? opts short-options)) |
---|
730 | (set! rest |
---|
731 | (append (map (lambda (o) (string-append "-" (string o))) opts) rest) ) |
---|
732 | (quit "invalid option `~A'" arg) ) ) ] |
---|
733 | [else (quit "invalid option `~A'" s)] ) ] |
---|
734 | [(file-exists? arg) |
---|
735 | (let-values ([(dirs name ext) (decompose-pathname arg)]) |
---|
736 | (cond [(not ext) (set! scheme-files (append scheme-files (list arg)))] |
---|
737 | [(member ext '("h" "c")) |
---|
738 | (set! c-files (append c-files (list arg))) ] |
---|
739 | [(member ext '("cpp" "C" "cc" "cxx" "hpp")) |
---|
740 | (when osx (set! compile-options (cons "-no-cpp-precomp" compile-options))) |
---|
741 | (set! cpp-mode #t) |
---|
742 | (set! c-files (append c-files (list arg))) ] |
---|
743 | [(member ext '("m" "M" "mm")) |
---|
744 | (set! objc-mode #t) |
---|
745 | (set! c-files (append c-files (list arg))) ] |
---|
746 | [(or (string=? ext object-extension) |
---|
747 | (string=? ext library-extension) ) |
---|
748 | (set! object-files (append object-files (list arg))) ] |
---|
749 | [else (set! scheme-files (append scheme-files (list arg)))] ) ) ] |
---|
750 | [else |
---|
751 | (let ([f2 (string-append arg ".scm")]) |
---|
752 | (if (file-exists? f2) |
---|
753 | (set! rest (cons f2 rest)) |
---|
754 | (quit "file `~A' does not exist" arg) ) ) ] ) ] ) |
---|
755 | (loop rest) ) ] ) ) ) |
---|
756 | |
---|
757 | |
---|
758 | ;;; Translate all Scheme files: |
---|
759 | |
---|
760 | (define (run-translation) |
---|
761 | (for-each |
---|
762 | (lambda (f) |
---|
763 | (let ([fc (pathname-replace-extension |
---|
764 | (if (= 1 (length scheme-files)) |
---|
765 | target-filename |
---|
766 | f) |
---|
767 | (cond (cpp-mode "cpp") |
---|
768 | (objc-mode "m") |
---|
769 | (else "c") ) ) ] ) |
---|
770 | (unless (zero? |
---|
771 | ($system |
---|
772 | (string-intersperse |
---|
773 | (cons* translator (cleanup-filename f) |
---|
774 | (append |
---|
775 | (if to-stdout |
---|
776 | '("-to-stdout") |
---|
777 | `("-output-file" ,(cleanup-filename fc)) ) |
---|
778 | (if (or static static-libs static-extensions) |
---|
779 | (map (lambda (e) (conc "-uses " e)) required-extensions) |
---|
780 | '() ) |
---|
781 | (map quote-option (append translate-options translation-optimization-options)) ) ) |
---|
782 | " ") ) ) |
---|
783 | (exit last-exit-code) ) |
---|
784 | (set! c-files (append (list fc) c-files)) |
---|
785 | (set! generated-c-files (append (list fc) generated-c-files)))) |
---|
786 | scheme-files) |
---|
787 | (unless keep-files (for-each $delete-file generated-scheme-files)) ) |
---|
788 | |
---|
789 | |
---|
790 | ;;; Compile all C files: |
---|
791 | |
---|
792 | (define (run-compilation) |
---|
793 | (let ((ofiles '())) |
---|
794 | (for-each |
---|
795 | (lambda (f) |
---|
796 | (let ([fo (pathname-replace-extension f object-extension)]) |
---|
797 | (unless (zero? |
---|
798 | ($system |
---|
799 | (string-intersperse |
---|
800 | (list (cond (cpp-mode c++-compiler) |
---|
801 | (else compiler) ) |
---|
802 | (cleanup-filename f) |
---|
803 | (string-append compile-output-flag (cleanup-filename fo)) |
---|
804 | compile-only-flag |
---|
805 | (compiler-options) ) ) ) ) |
---|
806 | (exit last-exit-code) ) |
---|
807 | (set! generated-object-files (cons fo generated-object-files)) |
---|
808 | (set! ofiles (cons fo ofiles)))) |
---|
809 | c-files) |
---|
810 | (set! object-files (append (reverse ofiles) object-files)) ; put generated object files first |
---|
811 | (unless keep-files (for-each $delete-file generated-c-files)) ) ) |
---|
812 | |
---|
813 | (define (compiler-options) |
---|
814 | (string-intersperse |
---|
815 | (map quote-option |
---|
816 | (append |
---|
817 | (if (or static static-libs) '() nonstatic-compilation-options) |
---|
818 | compilation-optimization-options |
---|
819 | compile-options) ) ) ) |
---|
820 | |
---|
821 | |
---|
822 | ;;; Link object files and libraries: |
---|
823 | |
---|
824 | (define (run-linking) |
---|
825 | (let ((files (map cleanup-filename |
---|
826 | (append object-files |
---|
827 | (nth-value 0 (static-extension-info)) ) ) ) |
---|
828 | (target (cleanup-filename target-filename))) |
---|
829 | (unless (zero? |
---|
830 | ($system |
---|
831 | (string-intersperse |
---|
832 | (cons* (cond (cpp-mode c++-linker) |
---|
833 | (else linker) ) |
---|
834 | (append |
---|
835 | files |
---|
836 | (list (string-append link-output-flag target) |
---|
837 | (linker-options) |
---|
838 | (linker-libraries #f) ) ) ) ) ) ) |
---|
839 | (exit last-exit-code) ) |
---|
840 | (when (and osx (or (not cross-chicken) host-mode)) |
---|
841 | (unless (zero? ($system |
---|
842 | (string-append |
---|
843 | "install_name_tool -change libchicken.dylib " |
---|
844 | (quotewrap |
---|
845 | (make-pathname |
---|
846 | (prefix "" "lib" |
---|
847 | (if host-mode |
---|
848 | INSTALL_LIB_HOME |
---|
849 | TARGET_RUN_LIB_HOME)) |
---|
850 | "libchicken.dylib") ) |
---|
851 | " " |
---|
852 | target) ) ) |
---|
853 | (exit last-exit-code) ) ) |
---|
854 | (unless keep-files (for-each $delete-file generated-object-files)) ) ) |
---|
855 | |
---|
856 | (define (static-extension-info) |
---|
857 | (let ((rpath (repository-path))) |
---|
858 | (if (and rpath (or static static-libs static-extensions)) |
---|
859 | (let loop ((exts required-extensions) (libs '()) (opts '())) |
---|
860 | (if (null? exts) |
---|
861 | (values (reverse libs) (reverse opts)) |
---|
862 | (let ((info (extension-information (car exts)))) |
---|
863 | (if info |
---|
864 | (let ((a (assq 'static info)) |
---|
865 | (o (assq 'static-options info)) ) |
---|
866 | (loop (cdr exts) |
---|
867 | (if a (cons (make-pathname rpath (cadr a)) libs) libs) |
---|
868 | (if o (cons (cadr o) opts) opts) ) ) |
---|
869 | (loop (cdr exts) libs opts)) ) ) ) |
---|
870 | (values '() '()) ) ) ) |
---|
871 | |
---|
872 | (define (linker-options) |
---|
873 | (string-append |
---|
874 | (string-intersperse |
---|
875 | (append linking-optimization-options link-options |
---|
876 | (nth-value 1 (static-extension-info)) ) ) |
---|
877 | (if (and static (not mingw) (not msvc) (not osx)) " -static" "") ) ) |
---|
878 | |
---|
879 | (define (linker-libraries #!optional staticexts) |
---|
880 | (string-intersperse |
---|
881 | (append |
---|
882 | (if staticexts (nth-value 0 (static-extension-info)) '()) |
---|
883 | (if (or static static-libs) |
---|
884 | (if gui gui-library-files library-files) |
---|
885 | (if gui gui-shared-library-files shared-library-files)) |
---|
886 | (if (or static static-libs) |
---|
887 | (list extra-libraries) |
---|
888 | (list extra-shared-libraries))))) |
---|
889 | |
---|
890 | |
---|
891 | ;;; Helper procedures: |
---|
892 | |
---|
893 | (define-constant +hairy-chars+ '(#\\ #\#)) |
---|
894 | |
---|
895 | (define (cleanup s) |
---|
896 | (let* ((q #f) |
---|
897 | (s (list->string |
---|
898 | (let fold ([s (string->list s)]) |
---|
899 | (if (null? s) |
---|
900 | '() |
---|
901 | (let ([c (car s)]) |
---|
902 | (cond ((memq c +hairy-chars+) (cons* #\\ c (fold (cdr s)))) |
---|
903 | (else |
---|
904 | (when (char-whitespace? c) (set! q #t)) |
---|
905 | (cons c (fold (cdr s))) ) ) ) ) ) ) ) ) |
---|
906 | (if q |
---|
907 | (string-append "\"" (string-translate* s '(("\"" . "\\\""))) "\"") |
---|
908 | s) ) ) |
---|
909 | |
---|
910 | (define (quote-option x) |
---|
911 | (if (any (lambda (c) |
---|
912 | (or (char-whitespace? c) (memq c +hairy-chars+)) ) |
---|
913 | (string->list x) ) |
---|
914 | (cleanup x) |
---|
915 | x) ) |
---|
916 | |
---|
917 | (define last-exit-code #f) |
---|
918 | |
---|
919 | (define ($system str) |
---|
920 | (when verbose (print str)) |
---|
921 | (set! last-exit-code |
---|
922 | (if dry-run |
---|
923 | 0 |
---|
924 | (if (zero? (system str)) |
---|
925 | 0 |
---|
926 | 1))) |
---|
927 | (unless (zero? last-exit-code) |
---|
928 | (printf "*** Shell command terminated with exit status ~S: ~A~%" last-exit-code str) ) |
---|
929 | last-exit-code) |
---|
930 | |
---|
931 | (define ($delete-file str) |
---|
932 | (when verbose |
---|
933 | (print "rm " str) ) |
---|
934 | (unless dry-run (delete-file str) )) |
---|
935 | |
---|
936 | |
---|
937 | ;;; Run it: |
---|
938 | |
---|
939 | (run (append (string-split (or (getenv "CSC_OPTIONS") "")) arguments)) |
---|