;; -*- Hen -*- (define (dynld-name fn) (make-pathname #f fn ##sys#load-dynamic-extension)) (define (gts-try-compile header ldflags cppflags) (and (try-compile (string-append header "\n" "int main(int argc, char **argv) { gts_finalize(); return 0; }\n") ldflags: ldflags cflags: cppflags ) (cons ldflags cppflags))) (define-syntax gts-test (syntax-rules () ((_ (flags ...)) (condition-case (gts-try-compile flags ...) (t () #f))))) (define (ipipe:execute lam cmd) (define (smooth lst) (let ((slst (map ->string lst))) (string-intersperse (cons (car slst) (cdr slst)) " "))) ((lambda (cmd) (with-input-from-pipe (sprintf "~a" cmd) lam)) (smooth cmd))) (define-syntax ipipe (syntax-rules () ((_ lam exp) (ipipe:execute lam `exp )))) (define gts-pkg-cflags (ipipe read-line (pkg-config --cflags gts))) (define gts-pkg-libs (ipipe read-line (pkg-config --libs gts))) (define gts-cflags (ipipe read-line (gts-config --cflags))) (define gts-libs (ipipe read-line (gts-config --libs))) (define ld+cpp-options (or (and (not (eof-object? gts-pkg-cflags)) (not (eof-object? gts-pkg-libs)) (gts-test ("#include " gts-pkg-libs gts-pkg-cflags))) (and (not (eof-object? gts-cflags)) (not (eof-object? gts-libs)) (gts-test ("#include " gts-libs gts-cflags))) (gts-test ("#include " gts-libs "")) (gts-test ("#include " gts-libs "-I/usr/include/gts")) (gts-test ("#include " gts-libs "-I/usr/lib/gts/include")) (gts-test ("#include " (string-append "-L/opt/local/lib " gts-libs) "-I/opt/local/include")) (error "unable to figure out location of GTS library"))) (compile -O -d2 -I. -s gts.scm -j gts -L "\"" ,(car ld+cpp-options) "\"" -C "\"" ,(cdr ld+cpp-options) "\"") (compile -O2 -d0 -s gts.import.scm) (install-extension ; Name of your extension: 'gts ; Files to install for your extension: `(,(dynld-name "gts") ,(dynld-name "gts.import") ) ; Assoc list with properties for your extension: `((version 1.4) ))