Changeset 35670 in project
- Timestamp:
- 06/22/18 02:27:13 (3 years ago)
- Location:
- release/5/compile-file/trunk
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
release/5/compile-file/trunk/compile-file.scm
r35590 r35670 6 6 7 7 (module compile-file 8 (compile-file compile-file-options )8 (compile-file compile-file-options try-compile) 9 9 10 10 (import (chicken base) … … 54 54 (load-file f) 55 55 f)))) 56 (else #f)))))))) 56 (else #f))))))) 57 58 (define default-cxx (foreign-value "C_TARGET_CXX" c-string)) 59 (define default-cc (foreign-value "C_TARGET_CC" c-string)) 60 (define default-cflags (foreign-value "C_TARGET_CFLAGS" c-string)) 61 (define default-ldflags (foreign-value "C_TARGET_LDFLAGS" c-string)) 62 (define default-libdir (foreign-value "C_TARGET_LIB_HOME" c-string)) 63 (define default-libs (foreign-value "C_TARGET_MORE_LIBS" c-string)) 64 65 (define remove-file-command 66 (case (software-type) 67 ((unix) "rm -f") 68 ((windows) "del /f /q") 69 (else "rm -f"))) 70 71 (define (shellpath str) 72 (qs (normalize-pathname str))) 73 74 (define (try-compile code #!key c++ (cc (if c++ default-cxx default-cc)) (cflags "") (ldflags "") 75 (verbose #f) (compile-only #f)) 76 (let* ((fname (create-temporary-file "c")) 77 (oname (pathname-replace-extension fname "o")) 78 (r (begin 79 (with-output-to-file fname (cut display code)) 80 (system 81 (let ((cmd (conc 82 cc " " 83 (if compile-only "-c" "") " " 84 cflags " " default-cflags " " 85 (shellpath fname) " -o " (shellpath oname) " " 86 (if compile-only 87 "" 88 (conc "-L" default-libdir " " ldflags " " default-libs) ) 89 (case (software-type) ((windows) " >nul: " " >/dev/null ") (else "")) 90 (if verbose "" "2>&1") ) ) ) 91 (when verbose (print cmd " ...")) 92 cmd) ) ) ) ) 93 (when verbose (print (if (zero? r) "succeeded." "failed."))) 94 (system (sprintf "~A ~A" remove-file-command (shellpath fname))) 95 (system (sprintf "~A ~A" remove-file-command (shellpath oname))) 96 (zero? r) ) ) 97 98 ) -
release/5/compile-file/trunk/compile-file.wiki
r33882 r35670 5 5 [[toc:]] 6 6 7 {{compile-file}} provides a way to compile Scheme files 8 programmatically. 7 {{compile-file}} provides a way to compile Scheme and C/C++ files programmatically. 9 8 10 9 ==== compile-file … … 40 39 default options are {{-O2 -d2}}. 41 40 41 ==== try-compile 42 43 <procedure>(try-compile CODE #!key cc cflags ldflags compile-only c++)</procedure> 44 45 Returns {{#t}} if the C code in {{CODE}} compiles and links successfully, or {{#f}} otherwise. 46 The keyword parameters {{cc}} (compiler name, defaults to the C compiler used to build this system), 47 {{cflags}} and {{ldflags}} accept additional compilation and 48 linking options. If {{compile-only}} is true, then no linking step takes place. 49 If the keyword argument {{c++}} is given and true, then the code will be compiled in C++ mode. 50 42 51 === Author 43 52 … … 46 55 === License 47 56 48 Copyright (c) 2017 , The CHICKEN Team57 Copyright (c) 2017-2018, The CHICKEN Team 49 58 All rights reserved. 50 59
Note: See TracChangeset
for help on using the changeset viewer.