mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 05:39:17 +02:00
Issue #365 - Added (c-compiler-options) expression for libs
This commit is contained in:
parent
4b13c6a95a
commit
eb3250c0f1
3 changed files with 56 additions and 4 deletions
21
cyclone.scm
21
cyclone.scm
|
@ -704,6 +704,7 @@
|
|||
(cond
|
||||
(program?
|
||||
(Cyc-add-feature! 'program) ;; Load special feature
|
||||
;; TODO: what about top-level cond-expands in the program?
|
||||
in-prog-raw)
|
||||
(else
|
||||
;; Account for any cond-expand declarations in the library
|
||||
|
@ -716,8 +717,19 @@
|
|||
(not (null? (car program:imports/code))))
|
||||
(lib:get-all-import-deps (car program:imports/code) append-dirs prepend-dirs expander)
|
||||
'()))
|
||||
;; Read all linker options from dependent libs
|
||||
;; TODO: also read from program if applicable
|
||||
(c-linker-options
|
||||
(lib:get-all-c-linker-options lib-deps append-dirs prepend-dirs))
|
||||
;; Only read C compiler options from module being compiled
|
||||
;; TODO: allow these to be read from a program
|
||||
(cc-opts*
|
||||
(cond
|
||||
(program? "") ; TODO
|
||||
(else
|
||||
(string-join
|
||||
(lib:c-compiler-options (car in-prog))
|
||||
""))))
|
||||
(exec-file (basename in-file))
|
||||
(src-file (string-append exec-file ".c"))
|
||||
(meta-file (string-append exec-file ".meta"))
|
||||
|
@ -780,7 +792,8 @@
|
|||
"~exec-file~" exec-file)
|
||||
" "
|
||||
cc-opts
|
||||
" "))
|
||||
" "
|
||||
cc-opts*))
|
||||
(comp-objs-cmd
|
||||
(string-append
|
||||
(string-replace-all
|
||||
|
@ -825,7 +838,8 @@
|
|||
"~exec-file~" exec-file)
|
||||
" "
|
||||
cc-opts
|
||||
" "))
|
||||
" "
|
||||
cc-opts*))
|
||||
(comp-so-cmd
|
||||
(string-append
|
||||
(string-replace-all
|
||||
|
@ -835,7 +849,8 @@
|
|||
"~exec-file~" exec-file)
|
||||
" "
|
||||
cc-opts
|
||||
" "))
|
||||
" "
|
||||
cc-opts*))
|
||||
)
|
||||
(cond
|
||||
(cc?
|
||||
|
|
|
@ -238,6 +238,14 @@ Or as part of a program (add any includes immediately after the `import` express
|
|||
|
||||
By default this will generate an `#include` preprocessor directive with the name of the header file in double quotes. However, if `include-c-header` is passed a text string with angle brackets (EG: `"<stdio.h>"`), the generated C code will use angle brackets instead.
|
||||
|
||||
## C Compiler Options
|
||||
|
||||
A Cyclone library may use the `c-compiler-options expression to pass options directly to the C compiler. For example:
|
||||
|
||||
(define-library (my-lib)
|
||||
(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:
|
||||
|
|
|
@ -58,6 +58,9 @@
|
|||
lib:c-linker-options
|
||||
lib:read-c-linker-options
|
||||
lib:get-all-c-linker-options
|
||||
lib:c-compiler-options
|
||||
lib:read-c-compiler-options
|
||||
lib:get-all-c-compiler-options
|
||||
;; Import Database "idb" oriented functions
|
||||
;;
|
||||
;; These functions perform operations for a "database" created from
|
||||
|
@ -201,6 +204,15 @@
|
|||
(tagged-list? 'c-linker-options code))
|
||||
(cddr ast))))
|
||||
|
||||
(define (lib:c-compiler-options ast)
|
||||
(map
|
||||
(lambda (inc-lst)
|
||||
(cadr inc-lst))
|
||||
(filter
|
||||
(lambda (code)
|
||||
(tagged-list? 'c-compiler-options code))
|
||||
(cddr ast))))
|
||||
|
||||
(define (lib:include-c-headers ast)
|
||||
(map
|
||||
(lambda (inc-lst)
|
||||
|
@ -268,7 +280,7 @@
|
|||
(cond
|
||||
((and (pair? expr)
|
||||
(not (member (car expr)
|
||||
'(import export c-linker-options include-c-header))))
|
||||
'(import export c-linker-options c-compiler-options include-c-header))))
|
||||
`(begin ,expr))
|
||||
(else
|
||||
expr)))
|
||||
|
@ -439,6 +451,23 @@
|
|||
imports)
|
||||
" "))
|
||||
|
||||
(define (lib:read-c-compiler-options import append-dirs prepend-dirs)
|
||||
(let* ((lib-name (lib:import->library-name import))
|
||||
(dir (lib:import->filename lib-name ".sld" append-dirs prepend-dirs))
|
||||
(fp (open-input-file dir))
|
||||
(lib (read-all fp))
|
||||
(options (lib:c-compiler-options (car lib))))
|
||||
(close-input-port fp)
|
||||
(string-join options " ")))
|
||||
|
||||
(define (lib:get-all-c-compiler-options imports append-dirs prepend-dirs)
|
||||
(string-join
|
||||
(map
|
||||
(lambda (import)
|
||||
(lib:read-c-compiler-options import append-dirs prepend-dirs))
|
||||
imports)
|
||||
" "))
|
||||
|
||||
;; Read export list for a given import
|
||||
(define (lib:import->export-list import append-dirs prepend-dirs expander)
|
||||
(let* ((lib-name (lib:import->library-name import))
|
||||
|
|
Loading…
Add table
Reference in a new issue