source: project/release/4/sql-de-lite/trunk/sql-de-lite.setup @ 31100

Last change on this file since 31100 was 31100, checked in by Jim Ursetto, 6 years ago

sql-de-lite 0.6.3: Remove pathname expansion from open-database; please use pathname-expand egg instead

File size: 3.7 KB
Line 
1;; -*- scheme -*-
2
3;; Optional arguments to chicken-install (requires Chicken 4.5.1):
4;; -D sql-de-lite-internal-lib: Force linking with included SQLite library.
5;; -D sql-de-lite-external-lib: Force linking with system SQLite library.
6
7;; Use CSC_OPTIONS="-I<incdir> -L<libdir>" chicken-install
8;; if you want to look for an external SQLite3 library in a non-standard location.
9
10(define extension-version "0.6.3")
11
12;; Minimum SQLite version to accept when choosing whether to use external library.
13;; There's also a minimum legal version that we can even use, but we just let the
14;; linker error out if too old.
15(define +min-sqlite3-libversion+ 3007011)   ;; 3007011 is included with egg
16
17(define sqlite3-options
18  '(-C -DSQLITE_ENABLE_FTS3
19    -C -DSQLITE_ENABLE_FTS3_PARENTHESIS
20    -C -DSQLITE_THREADSAFE=0                ;; otherwise, pthreads required
21    ))
22
23;; Options are pulled from (extra-features), i.e. the -D option to chicken-install.
24;; (extra-features) requires Chicken 4.5.1; otherwise, options are set to empty.
25(define sql-de-lite-options
26  (handle-exceptions exn '() (extra-features)))
27(define force-internal-lib?
28  (memq 'sql-de-lite-internal-lib sql-de-lite-options))
29(define force-external-lib?
30  (memq 'sql-de-lite-external-lib sql-de-lite-options))
31(when (and force-internal-lib?
32           force-external-lib?)
33  (error 'sql-de-lite "cannot force both external and internal SQLite lib"))
34
35(define-syntax compile/error
36  ;; Required for Chicken < 4.6, which calls (reset) on (compile) error.
37  (syntax-rules ()
38    ((compile/error args ...)
39     (let ((old-reset (reset-handler)))
40       (parameterize ((reset-handler
41                       (lambda ()
42                         (parameterize ((reset-handler old-reset))
43                           (error 'compile "compilation error")))))
44         (compile args ...))))))
45
46;; Returns sqlite3 libversion number (e.g. 3006021) or #f if unable to obtain.
47(define (get-sqlite3-libversion)
48  (let ((exe (cond-expand (windows ".\\version-check.exe")  ;; stupid, but make-pathname can't do \ anymore
49                          (else "./version-check"))))
50    (and (handle-exceptions e #f
51           (compile/error -o ,exe version-check.scm -lsqlite3))
52         (and (let ((version (with-input-from-pipe exe read))) ;; never errors
53                (and (number? version) version))))))
54
55(define (build/internal)
56  (print "\n+++ SQLite3 version >= " +min-sqlite3-libversion+ " not found, using bundled version\n")
57  (compile -s -O2 -d2 -inline -local sql-de-lite.scm -j sql-de-lite
58           -Isqlite3 sqlite3/sqlite3.c
59           ,@sqlite3-options)
60  ;; Using Chicken to compile the shell may link to extraneous libraries,
61  ;; but it's easier than figuring out the compilation process ourselves.
62  (compile -O2 -o chicken-sqlite3 -Isqlite3
63           sqlite3/shell.c sqlite3/sqlite3.c
64           ,@sqlite3-options
65           -C -DSQLITE_THREADSAFE=0      ;; Shell is single-threaded.
66           )
67  (install-library)
68  (install-shell))
69
70(define (build/external ver)
71  (when ver
72    (print "\n+++ SQLite3 version " ver " found\n"))
73  (compile -s -O2 -d2 -inline -local sql-de-lite.scm -j sql-de-lite -lsqlite3)
74  (install-library))
75
76(define (install-library)
77  (compile -s -O2 -d0 sql-de-lite.import.scm)
78  (install-extension
79   'sql-de-lite 
80   `("sql-de-lite.so" "sql-de-lite.import.so")
81   `((version ,extension-version))))
82
83(define (install-shell)
84  (install-program
85   'sql-de-lite-shell
86   `("chicken-sqlite3")
87   `((version ,extension-version))))
88
89;;; Main logic
90
91(cond (force-internal-lib?
92       (build/internal))
93      (force-external-lib?
94       (build/external #f))
95      (else
96       (let ((ver (get-sqlite3-libversion)))
97         (if (and ver (>= ver +min-sqlite3-libversion+))
98             (build/external ver)
99             (build/internal)))))
100
Note: See TracBrowser for help on using the repository browser.