Issue #365 - Allow c-compiler-options to be used by programs

This commit is contained in:
Justin Ethier 2021-01-18 15:03:27 -05:00
parent eb3250c0f1
commit 065a8bdd15
3 changed files with 22 additions and 2 deletions

View file

@ -5,7 +5,7 @@ TODO: consider creating a revised overview of our GC that unifies the original w
Features
- Added the `-COPT` compiler option to allow specifying options for the C compiler.
- Added the `c-compiler-options` expression and `-COPT` Cyclone compiler option to allow specifying options for the C compiler.
Bug Fixes

View file

@ -692,6 +692,18 @@
(lambda (port)
(read-all/source port filename))))
(define (program-c-compiler-opts! in-prog)
(foldl
(lambda (expr acc)
(cond
((tagged-list? 'c-compiler-options expr)
(set-car! expr (string->symbol "quote"))
(cons (cadr expr) acc))
(else
acc)))
'()
in-prog))
;; Compile and emit:
(define (run-compiler args cc? cc-prog cc-exec cc-lib cc-so
cc-opts cc-prog-linker-opts cc-prog-linker-objs
@ -725,7 +737,10 @@
;; TODO: allow these to be read from a program
(cc-opts*
(cond
(program? "") ; TODO
(program?
(string-join
(program-c-compiler-opts! in-prog)
""))
(else
(string-join
(lib:c-compiler-options (car in-prog))

View file

@ -17,6 +17,7 @@
- [Writing a Scheme Function in C](#writing-a-scheme-function-in-c)
- [Foreign Library](#foreign-library)
- [Including a C Header File](#including-a-c-header-file)
- [C Compiler Options](#c-compiler-options)
- [Linking to a C Library](#linking-to-a-c-library)
- [Calling Scheme Functions from C](#calling-scheme-functions-from-c)
- [Licensing](#licensing)
@ -246,6 +247,10 @@ A Cyclone library may use the `c-compiler-options expression to pass options dir
(c-compiler-options "-Imy-dir/include")
...
This expression may also be used at the top level of a program, EG:
(c-compiler-options "-Imy-dir/include")
## Linking to a C Library
A Cyclone library may use the `c-linker-options` expression to instruct the compiler to include linker options when building an executable. For example: