split the C compiler's name from its options
SEX_CC="ccache cc" went looking for an executable of that whole name; it is read as make reads CC now.
This commit is contained in:
@@ -90,7 +90,8 @@ sexc ./examples/hello-world.sex -o hello
|
||||
That's it. Now you should have executable named ~hello~ in your
|
||||
directory. Sex uses C under the hood, the default C compiler is ~cc~,
|
||||
but you can pass any using ~--c-compiler~ option, or by setting
|
||||
~SEX_CC~ environment variable.
|
||||
~SEX_CC~ environment variable. Either may carry the compiler's own
|
||||
options, as ~make~'s ~CC~ does: ~SEX_CC="ccache cc"~.
|
||||
|
||||
Everything after ~--~ is handed to the C compiler exactly as written:
|
||||
|
||||
|
||||
22
sexc.scm
22
sexc.scm
@@ -217,9 +217,11 @@
|
||||
(define (compile-to-file sex-forms output args cc-args)
|
||||
"Hand the generated C to the C compiler. Returns the compiler's exit
|
||||
status, which is ours to pass on."
|
||||
(let ((compiler (or (get-arg args 'c-compiler #f)
|
||||
(get-env-var "SEX_CC")
|
||||
"cc"))
|
||||
;; named with its own options, as make's CC is: "ccache cc", "cc -O2"
|
||||
(let ((compiler (let ((words (string-split (or (get-arg args 'c-compiler #f)
|
||||
(get-env-var "SEX_CC")
|
||||
"cc"))))
|
||||
(if (null? words) (list "cc") words)))
|
||||
(out-file (if (eq? output 'default)
|
||||
"a.out"
|
||||
output))
|
||||
@@ -233,12 +235,14 @@ status, which is ours to pass on."
|
||||
(begin (delete-file* c-file) (abort exn))
|
||||
(with-output-to-file c-file
|
||||
(lambda () (emit-c sex-forms)))
|
||||
(let ((proc (process compiler (append (list "-o" out-file)
|
||||
(if (get-arg args 'compile-object #f)
|
||||
(list "-c")
|
||||
(list))
|
||||
(list c-file)
|
||||
cc-args))))
|
||||
(let ((proc (process (car compiler)
|
||||
(append (cdr compiler)
|
||||
(list "-o" out-file)
|
||||
(if (get-arg args 'compile-object #f)
|
||||
(list "-c")
|
||||
(list))
|
||||
(list c-file)
|
||||
cc-args))))
|
||||
(call-with-values (lambda () (process-wait proc))
|
||||
(lambda (pid normal-exit? status)
|
||||
(delete-file* c-file)
|
||||
|
||||
@@ -47,6 +47,14 @@
|
||||
(process-wait proc)
|
||||
(list (process-exit-status proc) out err))))
|
||||
|
||||
;;; (status) of PROGRAM run on its own
|
||||
(define (sexc-run-program program)
|
||||
(let ((proc (process* program (list))))
|
||||
(close-output-port (process-input-port proc))
|
||||
(read-string #f (process-output-port proc))
|
||||
(process-wait proc)
|
||||
(list (process-exit-status proc))))
|
||||
|
||||
;;; Whether sexc exits 0 when run with ARGS, saying nothing of it
|
||||
(define (sexc-succeeds? . args)
|
||||
(zero? (system (string-append (string-intersperse (map qs (cons sexc args)))
|
||||
@@ -108,6 +116,17 @@
|
||||
(test "and the source is as it was" hello-source
|
||||
(call-with-input-file "victim.sex" (lambda (p) (read-string #f p))))
|
||||
|
||||
;;; A compiler is named with its own options, as make's CC is: SEX_CC
|
||||
;;; "cc -DCODE=7" went looking for an executable of that whole name
|
||||
(call-with-output-file "code.sex" (lambda (p) (display "(pub fn main () int (return CODE))" p)))
|
||||
(test "a compiler given with options takes them"
|
||||
7
|
||||
(begin
|
||||
(set-environment-variable! "SEX_CC" "cc -DCODE=7")
|
||||
(let ((built (sexc-succeeds? "code.sex" "-o" "code")))
|
||||
(unset-environment-variable! "SEX_CC")
|
||||
(and built (car (sexc-run-program "./code"))))))
|
||||
|
||||
;;; An error is its message: CHICKEN's call history after it is for
|
||||
;;; working on sexc itself, and asked for by SEXC_DEBUG
|
||||
(test-assert "a missing input says so"
|
||||
|
||||
Reference in New Issue
Block a user