;; -*- Hen -*- (define (dynld-name fn) (make-pathname #f fn ##sys#load-dynamic-extension)) (define (sundials-try-compile header ldflags cppflags) (and (try-compile (string-append "#include \n" "#include \n" "#include \n" header "\n" "int main(int argc, char **argv) { void *x; x = NULL; CVodeFree(&x); IDAFree(&x); return 0; }\n") ldflags: ldflags cflags: cppflags) (cons ldflags cppflags) )) (define-syntax sundials-test (syntax-rules () ((_ (flags ...)) (condition-case (sundials-try-compile flags ...) (t () #f))))) (define sundials-headers #< #include #include #include #include #include EOF ) (define ld+cpp-options (or (sundials-test (sundials-headers "-lsundials_ida -lsundials_cvode -lsundials_nvecserial -lblas -llapack " "")) (sundials-test (sundials-headers "-lsundials_ida -lsundials_cvode -lsundials_nvecserial -lblas -llapack" "-I/usr/include/ida -I/usr/include/cvode")) (sundials-test (sundials-headers "-lsundials_ida -lsundials_cvode -lsundials_nvecserial -lblas -llapack" "-I/usr/include/sundials")) (sundials-test (sundials-headers "-lsundials_ida -lsundials_cvode -lsundials_nvecserial -lblas -llapack" "-I/opt/local/include")) (error "unable to figure out location of SUNDIALS"))) (define (detect-sundials-version ldflags) (let ((version-env (get-environment-variable "SUNDIALS_VERSION"))) (cond (version-env (string-split version-env ".")) (else (if (feature? 'cross-chicken) (begin (warning "Unable to figure out version of SUNDIALS: ") (warning "Assuming version 2.5.0 or later;") (warning "please set SUNDIALS_VERSION environment variable to the correct version.") (string-split "2.5.0" ".")) (begin (compile -L ,ldflags detect-sundials-version.scm) (let ((version-str (condition-case (call-with-input-pipe "./detect-sundials-version" (lambda (port) (->string (read port)))) [var () #f]))) (string-split version-str "."))) )) )) ) (define sundials-version (detect-sundials-version (car ld+cpp-options))) (print "SUNDIALS version is " sundials-version) (compile -O3 -d0 -S -s sundials.scm -j sundials -I. -L "\"" ,(car ld+cpp-options) "\"" -C "\"" ,(cdr ld+cpp-options) -D ,(string-append "SUNDIALS_VERSION_MAJOR=" (car sundials-version)) -D ,(string-append "SUNDIALS_VERSION_MINOR=" (cadr sundials-version)) "\"") (compile -O3 -d0 -s sundials.import.scm) (install-extension ; Name of your extension: 'sundials ; Files to install for your extension: `(,(dynld-name "sundials") ,(dynld-name "sundials.import") ) ; Assoc list with properties for your extension: `((version 2.15) ))