;; -*- 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); printf (\"%s\\n\",SUNDIALS_PACKAGE_VERSION); return 0; }\n") ldflags: ldflags cflags: (string-append cppflags " -o ./testsundials ")) (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 sundials-version (let ( (version-env (get-environment-variable "SUNDIALS_VERSION")) (version-str (condition-case (call-with-input-pipe "./testsundials" (lambda (port) (->string (read port)))) [var () #f])) ) (cond (version-env (string-split version-env ".")) (version-str (string-split version-str ".")) (else (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" "."))) )) ) (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.14) ))