diff --git a/CHANGELOG.md b/CHANGELOG.md index 19523cdb..273e17d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cyclone.scm b/cyclone.scm index 9eddf27f..97b967f5 100644 --- a/cyclone.scm +++ b/cyclone.scm @@ -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)) diff --git a/docs/User-Manual.md b/docs/User-Manual.md index 74cd4e7b..dac0a41f 100644 --- a/docs/User-Manual.md +++ b/docs/User-Manual.md @@ -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: