-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsundials.setup
96 lines (77 loc) · 3.15 KB
/
sundials.setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;; -*- 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 <stdlib.h>\n"
"#include <stdio.h>\n"
"#include <math.h>\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
#<<EOF
#include <sundials/sundials_config.h>
#include <ida/ida.h>
#include <ida/ida_dense.h>
#include <cvode/cvode.h>
#include <cvode/cvode_band.h>
#include <nvector/nvector_serial.h>
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)
))